source: trunk/include/common.inc.php @ 486

Last change on this file since 486 was 394, checked in by gweltas, 20 years ago
  • Template migration
  • Admin Control Panel migration
  • Category management
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.0 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// |                            common.inc.php                             |
4// +-----------------------------------------------------------------------+
5// | application   : PhpWebGallery <http://phpwebgallery.net>              |
6// | branch        : BSF (Best So Far)                                     |
7// +-----------------------------------------------------------------------+
8// | file          : $RCSfile$
9// | last update   : $Date: 2004-03-26 17:08:09 +0000 (Fri, 26 Mar 2004) $
10// | last modifier : $Author: gweltas $
11// | revision      : $Revision: 394 $
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// +-----------------------------------------------------------------------+
27
28if( !defined("PHPWG_ROOT_PATH") )
29{
30        die ("Hacking attempt!");
31}
32// determine the initial instant to indicate the generation time of this page
33$t1 = explode( ' ', microtime() );
34$t2 = explode( '.', $t1[0] );
35$t2 = $t1[1].'.'.$t2[1];
36
37set_magic_quotes_runtime(0); // Disable magic_quotes_runtime
38
39//
40// addslashes to vars if magic_quotes_gpc is off this is a security
41// precaution to prevent someone trying to break out of a SQL statement.
42//
43if( !get_magic_quotes_gpc() )
44{
45  if( is_array( $_GET ) )
46  {
47    while( list($k, $v) = each($_GET) )
48    {
49      if( is_array($_GET[$k]) )
50      {
51        while( list($k2, $v2) = each($_GET[$k]) )
52        {
53          $_GET[$k][$k2] = addslashes($v2);
54        }
55        @reset($_GET[$k]);
56      }
57      else
58      {
59        $_GET[$k] = addslashes($v);
60      }
61    }
62    @reset($_GET);
63  }
64 
65  if( is_array($_POST) )
66  {
67    while( list($k, $v) = each($_POST) )
68    {
69      if( is_array($_POST[$k]) )
70      {
71        while( list($k2, $v2) = each($_POST[$k]) )
72        {
73          $_POST[$k][$k2] = addslashes($v2);
74        }
75        @reset($_POST[$k]);
76      }
77      else
78      {
79        $_POST[$k] = addslashes($v);
80      }
81    }
82    @reset($_POST);
83  }
84
85  if( is_array($_COOKIE) )
86  {
87    while( list($k, $v) = each($_COOKIE) )
88    {
89      if( is_array($_COOKIE[$k]) )
90      {
91        while( list($k2, $v2) = each($_COOKIE[$k]) )
92        {
93          $_COOKIE[$k][$k2] = addslashes($v2);
94        }
95        @reset($_COOKIE[$k]);
96      }
97      else
98      {
99        $_COOKIE[$k] = addslashes($v);
100      }
101    }
102    @reset($_COOKIE);
103  }
104}
105
106//
107// Define some basic configuration arrays this also prevents malicious
108// rewriting of language and otherarray values via URI params
109//
110$conf = array();
111$page = array();
112$user = array();
113$lang = array();
114
115
116include(PHPWG_ROOT_PATH .'include/mysql.inc.php');
117if( !defined("PHPWG_INSTALLED") )
118{
119  header( 'Location: install.php' );
120  exit;
121}
122
123include(PHPWG_ROOT_PATH . 'include/constants.php');
124include(PHPWG_ROOT_PATH . 'include/config.inc.php');
125include(PHPWG_ROOT_PATH . 'include/functions.inc.php');
126include(PHPWG_ROOT_PATH . 'include/template.php');
127
128//
129// Database connection
130//
131
132mysql_connect( $dbhost, $dbuser, $dbpasswd )
133or die ( "Could not connect to server" );
134mysql_select_db( $dbname )
135or die ( "Could not connect to database" );
136       
137//
138// Obtain and encode users IP
139//
140if ( getenv( 'HTTP_X_FORWARDED_FOR' ) != '' )
141{
142  $client_ip = ( !empty($_SERVER['REMOTE_ADDR']) ) ? 
143    $_SERVER['REMOTE_ADDR'] : ( ( !empty($_ENV['REMOTE_ADDR']) ) ? $_ENV['REMOTE_ADDR'] : $REMOTE_ADDR );
144
145  if ( preg_match("/^([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/",
146                  getenv('HTTP_X_FORWARDED_FOR'), $ip_list) )
147  {
148    $private_ip = array( '/^0\./'
149                         ,'/^127\.0\.0\.1/'
150                         ,'/^192\.168\..*/'
151                         ,'/^172\.16\..*/'
152                         ,'/^10.\.*/'
153                         ,'/^224.\.*/'
154                         ,'/^240.\.*/'
155      );
156    $client_ip = preg_replace($private_ip, $client_ip, $ip_list[1]);
157  }
158}
159else
160{
161  $client_ip = ( !empty($_SERVER['REMOTE_ADDR']) ) ? 
162    $_SERVER['REMOTE_ADDR'] : ( ( !empty($_ENV['REMOTE_ADDR']) ) ? $_ENV['REMOTE_ADDR'] : $REMOTE_ADDR );
163}
164$user_ip = encode_ip($client_ip);
165
166//
167// Setup gallery wide options, if this fails then we output a CRITICAL_ERROR
168// since basic gallery information is not available
169//
170$query = 'SELECT param,value';
171$query.= ' FROM '.CONFIG_TABLE;
172$query.= ';';
173if( !( $result = mysql_query( $query ) ) )
174{
175  die("Could not query config information");
176}
177
178while ( $row =mysql_fetch_array( $result ) )
179{
180  if ( isset( $row['value'] ) )
181  {
182    $conf[$row['param']] = $row['value'];
183  }
184  else
185  {
186    $conf[$row['param']] = '';
187  }
188  // If the field is true or false, the variable is transformed into a
189  // boolean value.
190  if ( $conf[$row['param']] == 'true' or $conf[$row['param']] == 'false' )
191  {
192    $conf[$row['param']] = get_boolean( $conf[$row['param']] );
193  }
194}
195
196//---------------
197// A partir d'ici il faudra dispatcher le code dans d'autres fichiers
198//---------------
199
200include(PHPWG_ROOT_PATH . 'include/user.inc.php');
201
202// displaying the username in the language of the connected user, instead of
203// "guest" as you can find in the database
204if ( $user['is_the_guest'] ) $user['username'] = $lang['guest'];
205define('PREFIX_TABLE', $table_prefix);
206?>
Note: See TracBrowser for help on using the repository browser.