[354] | 1 | <?php |
---|
| 2 | // +-----------------------------------------------------------------------+ |
---|
[362] | 3 | // | common.inc.php | |
---|
[354] | 4 | // +-----------------------------------------------------------------------+ |
---|
| 5 | // | application : PhpWebGallery <http://phpwebgallery.net> | |
---|
[362] | 6 | // | branch : BSF (Best So Far) | |
---|
[354] | 7 | // +-----------------------------------------------------------------------+ |
---|
| 8 | // | file : $RCSfile$ |
---|
| 9 | // | last update : $Date: 2004-02-26 18:33:45 +0000 (Thu, 26 Feb 2004) $ |
---|
| 10 | // | last modifier : $Author: gweltas $ |
---|
| 11 | // | revision : $Revision: 375 $ |
---|
| 12 | // +-----------------------------------------------------------------------+ |
---|
| 13 | // | This program is free software; you can redistribute it and/or modify | |
---|
| 14 | // | it under the terms of the GNU General Public License as published by | |
---|
| 15 | // | the Free Software Foundation | |
---|
| 16 | // | | |
---|
| 17 | // | This program is distributed in the hope that it will be useful, but | |
---|
| 18 | // | WITHOUT ANY WARRANTY; without even the implied warranty of | |
---|
| 19 | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
---|
| 20 | // | General Public License for more details. | |
---|
| 21 | // | | |
---|
| 22 | // | You should have received a copy of the GNU General Public License | |
---|
| 23 | // | along with this program; if not, write to the Free Software | |
---|
| 24 | // | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
---|
| 25 | // | USA. | |
---|
| 26 | // +-----------------------------------------------------------------------+ |
---|
[364] | 27 | if( !defined("PHPWG_ROOT_PATH") ) |
---|
| 28 | { |
---|
| 29 | die ("Hacking attempt!"); |
---|
| 30 | } |
---|
| 31 | // determine the initial instant to indicate the generation time of this page |
---|
[354] | 32 | $t1 = explode( ' ', microtime() ); |
---|
| 33 | $t2 = explode( '.', $t1[0] ); |
---|
| 34 | $t2 = $t1[1].'.'.$t2[1]; |
---|
| 35 | |
---|
| 36 | set_magic_quotes_runtime(0); // Disable magic_quotes_runtime |
---|
| 37 | |
---|
| 38 | // |
---|
[359] | 39 | // addslashes to vars if magic_quotes_gpc is off this is a security |
---|
| 40 | // precaution to prevent someone trying to break out of a SQL statement. |
---|
[354] | 41 | // |
---|
| 42 | if( !get_magic_quotes_gpc() ) |
---|
| 43 | { |
---|
[359] | 44 | if( is_array( $_GET ) ) |
---|
[354] | 45 | { |
---|
[359] | 46 | while( list($k, $v) = each($_GET) ) |
---|
[354] | 47 | { |
---|
[359] | 48 | if( is_array($_GET[$k]) ) |
---|
| 49 | { |
---|
| 50 | while( list($k2, $v2) = each($_GET[$k]) ) |
---|
[354] | 51 | { |
---|
[359] | 52 | $_GET[$k][$k2] = addslashes($v2); |
---|
| 53 | } |
---|
| 54 | @reset($_GET[$k]); |
---|
| 55 | } |
---|
| 56 | else |
---|
| 57 | { |
---|
| 58 | $_GET[$k] = addslashes($v); |
---|
| 59 | } |
---|
| 60 | } |
---|
| 61 | @reset($_GET); |
---|
[354] | 62 | } |
---|
| 63 | |
---|
[359] | 64 | if( is_array($_POST) ) |
---|
[354] | 65 | { |
---|
[359] | 66 | while( list($k, $v) = each($_POST) ) |
---|
| 67 | { |
---|
| 68 | if( is_array($_POST[$k]) ) |
---|
| 69 | { |
---|
| 70 | while( list($k2, $v2) = each($_POST[$k]) ) |
---|
| 71 | { |
---|
| 72 | $_POST[$k][$k2] = addslashes($v2); |
---|
| 73 | } |
---|
| 74 | @reset($_POST[$k]); |
---|
| 75 | } |
---|
| 76 | else |
---|
| 77 | { |
---|
| 78 | $_POST[$k] = addslashes($v); |
---|
| 79 | } |
---|
[354] | 80 | } |
---|
[359] | 81 | @reset($_POST); |
---|
[354] | 82 | } |
---|
| 83 | |
---|
[359] | 84 | if( is_array($_COOKIE) ) |
---|
[354] | 85 | { |
---|
[359] | 86 | while( list($k, $v) = each($_COOKIE) ) |
---|
[354] | 87 | { |
---|
[359] | 88 | if( is_array($_COOKIE[$k]) ) |
---|
| 89 | { |
---|
| 90 | while( list($k2, $v2) = each($_COOKIE[$k]) ) |
---|
| 91 | { |
---|
| 92 | $_COOKIE[$k][$k2] = addslashes($v2); |
---|
| 93 | } |
---|
| 94 | @reset($_COOKIE[$k]); |
---|
| 95 | } |
---|
| 96 | else |
---|
| 97 | { |
---|
| 98 | $_COOKIE[$k] = addslashes($v); |
---|
| 99 | } |
---|
[354] | 100 | } |
---|
[359] | 101 | @reset($_COOKIE); |
---|
[354] | 102 | } |
---|
| 103 | } |
---|
| 104 | |
---|
| 105 | // |
---|
[359] | 106 | // Define some basic configuration arrays this also prevents malicious |
---|
| 107 | // rewriting of language and otherarray values via URI params |
---|
[354] | 108 | // |
---|
| 109 | $conf = array(); |
---|
| 110 | $page = array(); |
---|
| 111 | $user = array(); |
---|
| 112 | $lang = array(); |
---|
| 113 | |
---|
[364] | 114 | |
---|
[367] | 115 | include(PHPWG_ROOT_PATH .'include/mysql.inc.php'); |
---|
[354] | 116 | if( !defined("PHPWG_INSTALLED") ) |
---|
| 117 | { |
---|
[359] | 118 | header( 'Location: install.php' ); |
---|
| 119 | exit; |
---|
[354] | 120 | } |
---|
| 121 | |
---|
[375] | 122 | define( 'PREFIX_INCLUDE', '' );// en attendant la migration complète |
---|
[364] | 123 | include(PHPWG_ROOT_PATH . 'include/constants.php'); |
---|
[367] | 124 | include(PHPWG_ROOT_PATH . 'include/config.inc.php'); |
---|
[364] | 125 | include(PHPWG_ROOT_PATH . 'include/functions.inc.php'); |
---|
| 126 | include(PHPWG_ROOT_PATH . 'include/template.php'); |
---|
| 127 | include(PHPWG_ROOT_PATH . 'include/vtemplate.class.php'); |
---|
| 128 | |
---|
[354] | 129 | // |
---|
| 130 | // Database connection |
---|
| 131 | // |
---|
| 132 | |
---|
[367] | 133 | mysql_connect( $dbhost, $dbuser, $dbpasswd ) |
---|
[359] | 134 | or die ( "Could not connect to server" ); |
---|
[367] | 135 | mysql_select_db( $dbname ) |
---|
[359] | 136 | or die ( "Could not connect to database" ); |
---|
[354] | 137 | |
---|
| 138 | // |
---|
| 139 | // Obtain and encode users IP |
---|
| 140 | // |
---|
[359] | 141 | if ( getenv( 'HTTP_X_FORWARDED_FOR' ) != '' ) |
---|
[354] | 142 | { |
---|
[359] | 143 | $client_ip = ( !empty($_SERVER['REMOTE_ADDR']) ) ? $_SERVER['REMOTE_ADDR'] : ( ( !empty($_ENV['REMOTE_ADDR']) ) ? $_ENV['REMOTE_ADDR'] : $REMOTE_ADDR ); |
---|
[354] | 144 | |
---|
[359] | 145 | if ( preg_match("/^([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/", |
---|
| 146 | getenv('HTTP_X_FORWARDED_FOR'), $ip_list) ) |
---|
[354] | 147 | { |
---|
[359] | 148 | $private_ip = array( '/^0\./' |
---|
| 149 | ,'/^127\.0\.0\.1/' |
---|
| 150 | ,'/^192\.168\..*/' |
---|
| 151 | ,'/^172\.16\..*/' |
---|
| 152 | ,'/^10.\.*/' |
---|
| 153 | ,'/^224.\.*/' |
---|
| 154 | ,'/^240.\.*/' |
---|
| 155 | ); |
---|
[354] | 156 | $client_ip = preg_replace($private_ip, $client_ip, $ip_list[1]); |
---|
| 157 | } |
---|
| 158 | } |
---|
| 159 | else |
---|
| 160 | { |
---|
[359] | 161 | $client_ip = ( !empty($_SERVER['REMOTE_ADDR']) ) ? $_SERVER['REMOTE_ADDR'] : ( ( !empty($_ENV['REMOTE_ADDR']) ) ? $_ENV['REMOTE_ADDR'] : $REMOTE_ADDR ); |
---|
[354] | 162 | } |
---|
| 163 | $user_ip = encode_ip($client_ip); |
---|
| 164 | |
---|
| 165 | // |
---|
[359] | 166 | // Setup forum wide options, if this fails then we output a CRITICAL_ERROR |
---|
| 167 | // since basic forum information is not available |
---|
[354] | 168 | // |
---|
[359] | 169 | $sql = 'SELECT * FROM '.CONFIG_TABLE; |
---|
[354] | 170 | if( !($result = mysql_query($sql)) ) |
---|
| 171 | { |
---|
| 172 | die("Could not query config information"); |
---|
| 173 | } |
---|
| 174 | |
---|
| 175 | $row =mysql_fetch_array($result); |
---|
| 176 | // rertieving the configuration informations for site |
---|
| 177 | // $infos array is used to know the fields to retrieve in the table "config" |
---|
| 178 | // Each field becomes an information of the array $conf. |
---|
| 179 | // Example : |
---|
| 180 | // prefix_thumbnail --> $conf['prefix_thumbnail'] |
---|
| 181 | $infos = array( 'prefix_thumbnail', 'webmaster', 'mail_webmaster', 'access', |
---|
| 182 | 'session_id_size', 'session_keyword', 'session_time', |
---|
| 183 | 'max_user_listbox', 'show_comments', 'nb_comment_page', |
---|
| 184 | 'upload_available', 'upload_maxfilesize', 'upload_maxwidth', |
---|
| 185 | 'upload_maxheight', 'upload_maxwidth_thumbnail', |
---|
| 186 | 'upload_maxheight_thumbnail','log','comments_validation', |
---|
| 187 | 'comments_forall','authorize_cookies','mail_notification' ); |
---|
| 188 | // affectation of each field of the table "config" to an information of the |
---|
| 189 | // array $conf. |
---|
| 190 | foreach ( $infos as $info ) { |
---|
| 191 | if ( isset( $row[$info] ) ) $conf[$info] = $row[$info]; |
---|
| 192 | else $conf[$info] = ''; |
---|
| 193 | // If the field is true or false, the variable is transformed into a boolean |
---|
| 194 | // value. |
---|
| 195 | if ( $conf[$info] == 'true' or $conf[$info] == 'false' ) |
---|
| 196 | { |
---|
| 197 | $conf[$info] = get_boolean( $conf[$info] ); |
---|
| 198 | } |
---|
| 199 | } |
---|
| 200 | |
---|
| 201 | //--------------- |
---|
| 202 | // A partir d'ici il faudra dispatcher le code dans d'autres fichiers |
---|
| 203 | //--------------- |
---|
| 204 | |
---|
[364] | 205 | include(PHPWG_ROOT_PATH . 'include/user.inc.php'); |
---|
[354] | 206 | |
---|
| 207 | // displaying the username in the language of the connected user, instead of |
---|
| 208 | // "guest" as you can find in the database |
---|
| 209 | if ( $user['is_the_guest'] ) $user['username'] = $lang['guest']; |
---|
| 210 | include_once( './template/'.$user['template'].'/htmlfunctions.inc.php' ); |
---|
| 211 | define('PREFIX_TABLE', $table_prefix); |
---|
[362] | 212 | ?> |
---|