source: trunk/install.php @ 483

Last change on this file since 483 was 483, checked in by z0rglub, 20 years ago

change default langage

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 12.1 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// |                              install.php                              |
4// +-----------------------------------------------------------------------+
5// | application   : PhpWebGallery <http://phpwebgallery.net>              |
6// | branch        : BSF (Best So Far)                                     |
7// +-----------------------------------------------------------------------+
8// | file          : $RCSfile$
9// | last update   : $Date: 2004-08-12 18:29:06 +0000 (Thu, 12 Aug 2004) $
10// | last modifier : $Author: z0rglub $
11// | revision      : $Revision: 483 $
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
28//----------------------------------------------------------- include
29define('PHPWG_ROOT_PATH','./');
30
31// Guess an initial language ...
32function guess_lang()
33{
34  return 'en_UK.iso-8859-1';
35  global $_SERVER;
36  $languages = array();
37  $i = 0;
38  if ( $opendir = opendir ( PHPWG_ROOT_PATH.'language/' ) )
39  {
40    while ( $file = readdir ( $opendir ) )
41    {
42      if ( is_dir ( PHPWG_ROOT_PATH.'language/'.$file )&& !substr_count($file,'.'))
43      {
44        $languages[$i++] =$file;
45      }
46    }
47  }
48
49  if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE']))
50  {
51        $accept_lang_ary = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
52        for ($i = 0; $i < sizeof($accept_lang_ary); $i++)
53        {
54          for ($j=0; $j<sizeof($languages); $j++)
55          {
56                if (preg_match('#' . substr($languages[$j],0,2) . '#i', substr(trim($accept_lang_ary[$i]),0,2)))
57                {
58                  if (file_exists(PHPWG_ROOT_PATH . 'language/' . $languages[$j].'/install.lang.php'))
59                  {
60                        return $languages[$j];
61                  }
62                }
63          }
64        }
65  }
66  return 'en_EN';
67}
68
69function execute_sqlfile( $filepath, $replaced, $replacing )
70{
71  $sql_lines = file( $filepath );
72  $query = '';
73  foreach ( $sql_lines as $sql_line ) {
74    $sql_line = trim( $sql_line );
75    if ( preg_match( '/(^--|^$)/', $sql_line ) ) continue;
76    $query.= ' '.$sql_line;
77    // if we reached the end of query, we execute it and reinitialize the
78    // variable "query"
79    if ( preg_match( '/;$/', $sql_line ) )
80    {
81      $query = trim( $query );
82      $query = str_replace( $replaced, $replacing, $query );
83      // we don't execute "DROP TABLE" queries
84      if ( !preg_match( '/^DROP TABLE/i', $query ) ) mysql_query( $query );
85      $query = '';
86    }
87  }
88}
89
90set_magic_quotes_runtime(0); // Disable magic_quotes_runtime
91//
92// addslashes to vars if magic_quotes_gpc is off this is a security
93// precaution to prevent someone trying to break out of a SQL statement.
94//
95if( !get_magic_quotes_gpc() )
96{
97  if( is_array($_POST) )
98  {
99    while( list($k, $v) = each($_POST) )
100    {
101      if( is_array($_POST[$k]) )
102      {
103        while( list($k2, $v2) = each($_POST[$k]) )
104        {
105          $_POST[$k][$k2] = addslashes($v2);
106        }
107        @reset($_POST[$k]);
108      }
109      else
110      {
111        $_POST[$k] = addslashes($v);
112      }
113    }
114    @reset($_POST);
115  }
116
117  if( is_array($_COOKIE) )
118  {
119    while( list($k, $v) = each($_COOKIE) )
120    {
121      if( is_array($_COOKIE[$k]) )
122      {
123        while( list($k2, $v2) = each($_COOKIE[$k]) )
124        {
125          $_COOKIE[$k][$k2] = addslashes($v2);
126        }
127        @reset($_COOKIE[$k]);
128      }
129      else
130      {
131        $_COOKIE[$k] = addslashes($v);
132      }
133    }
134    @reset($_COOKIE);
135  }
136}
137
138//----------------------------------------------------- variable initialization
139$install_style = 'default';
140$release_version = '1.4';
141if ( isset( $_POST['language'] ))
142{
143  $language = strip_tags($_POST['language']);
144}
145else 
146{
147  $language = guess_lang();
148}
149
150if ( !file_exists(@realpath(PHPWG_ROOT_PATH . 'language/' . $language . '/install.lang.php')) )
151{
152  $language = 'en_UK.iso-8859-1';
153}
154
155include( './language/'.$language.'/common.lang.php' );
156include( './language/'.$language.'/install.lang.php' );
157include( './language/'.$language.'/admin.lang.php' );
158
159// Obtain various vars
160$dbhost = (!empty($_POST['dbhost'])) ? $_POST['dbhost'] : 'localhost';
161$dbuser = (!empty($_POST['dbuser'])) ? $_POST['dbuser'] : '';
162$dbpasswd = (!empty($_POST['dbpasswd'])) ? $_POST['dbpasswd'] : '';
163$dbname = (!empty($_POST['dbname'])) ? $_POST['dbname'] : '';
164
165$table_prefix = (!empty($_POST['prefix'])) ? $_POST['prefix'] : 'phpwg_';
166
167$admin_name = (!empty($_POST['admin_name'])) ? $_POST['admin_name'] : '';
168$admin_pass1 = (!empty($_POST['admin_pass1'])) ? $_POST['admin_pass1'] : '';
169$admin_pass2 = (!empty($_POST['admin_pass2'])) ? $_POST['admin_pass2'] : '';
170$admin_mail = (!empty($_POST['admin_mail'])) ? $_POST['admin_mail'] : '';
171
172$infos = array();
173$errors = array();
174
175// Open config.php ... if it exists
176$config_file = PHPWG_ROOT_PATH.'include/mysql.inc.php';
177if (@file_exists($config_file))
178{
179        include($config_file);
180}
181
182// Is phpBB already installed? Yes? Redirect to the index
183if (defined("PHPWG_INSTALLED"))
184{
185  die( 'PhpWebGallery is already installed' );
186}
187
188include(PHPWG_ROOT_PATH . 'include/constants.php');
189include(PHPWG_ROOT_PATH . 'include/functions.inc.php');
190include(PHPWG_ROOT_PATH . 'include/template.php');
191//----------------------------------------------------- template initialization
192$template=setup_style($install_style);
193$template->set_filenames( array('install'=>'install.tpl') );
194$step = 1;
195//----------------------------------------------------- form analyze
196if ( isset( $_POST['install'] ))
197{
198  if ( @mysql_connect( $_POST['dbhost'],
199                       $_POST['dbuser'],
200                       $_POST['dbpasswd'] ) )
201  {
202    if ( @mysql_select_db($_POST['dbname'] ) )
203    {
204      array_push( $infos, $lang['step1_confirmation'] );
205    }
206    else
207    {
208      array_push( $errors, $lang['step1_err_db'] );
209    }
210  }
211  else
212  {
213    array_push( $errors, $lang['step1_err_server'] );
214  }
215 
216  $webmaster = trim(preg_replace( '/\s{2,}/', ' ', $admin_name ));
217  if ( empty($webmaster))
218    array_push( $errors, $lang['step2_err_login1'] );
219  else if ( preg_match( '/[\'"]/', $webmaster ) )
220    array_push( $errors, $lang['step2_err_login3'] );
221  if ( $admin_pass1 != $admin_pass2 || empty($admin_pass1) )
222    array_push( $errors, $lang['step2_err_pass'] );
223  if ( empty($admin_mail))
224    array_push( $errors, $lang['reg_err_mail_address'] );
225  else 
226  {
227    $error_mail_address = validate_mail_address($admin_mail);
228    if (!empty($error_mail_address))
229      array_push( $errors, $error_mail_address );
230  }
231 
232  if ( count( $errors ) == 0 )
233  {
234    $step = 2;
235    $file_content = "<?php";
236    $file_content.= "\n\$dbname = '".     $dbname."';";
237    $file_content.= "\n\$dbuser = '".     $dbuser."';";
238    $file_content.= "\n\$dbpasswd = '". $dbpasswd."';";
239    $file_content.= "\n\$dbhost = '".     $dbhost."';";
240    $file_content.= "\n";
241    $file_content.= "\n\$table_prefix = '".$table_prefix."';";
242    $file_content.= "\n";
243    $file_content.= "\ndefine('PHPWG_INSTALLED', true);";
244    $file_content.= "\n?".">";
245   
246    @umask(0111);
247    // writing the configuration file
248    if ( !($fp = @fopen( $config_file, 'w' )))
249    {
250      $html_content = htmlentities( $file_content, ENT_QUOTES );
251      $html_content = nl2br( $html_content );
252      $template->assign_block_vars('error_copy',
253                                   array('FILE_CONTENT'=>$html_content));
254    }
255    @fputs($fp, $file_content, strlen($file_content));
256    @fclose($fp);
257   
258    // tables creation, based on phpwebgallery_structure.sql
259    execute_sqlfile( PHPWG_ROOT_PATH.'install/phpwebgallery_structure.sql'
260                     , 'phpwebgallery_'
261                     , $table_prefix );
262    // We fill the tables with basic informations
263    execute_sqlfile( PHPWG_ROOT_PATH.'install/config.sql'
264                     , 'phpwebgallery_'
265                     , $table_prefix );
266
267    $query = 'UPDATE '.CONFIG_TABLE;
268    $query.= " SET value = '".$admin_name."'";
269    $query.= " WHERE param = 'webmaster'";
270    $query.= ';';
271    mysql_query( $query );
272
273    $query = 'UPDATE '.CONFIG_TABLE;
274    $query.= " SET value = '".$admin_mail."'";
275    $query.= " WHERE param = 'mail_webmaster'";
276    $query.= ';';
277    mysql_query( $query );
278       
279        $query = 'UPDATE '.CONFIG_TABLE;
280    $query.= " SET value = '".$language."'";
281    $query.= " WHERE param = 'default_lang'";
282    $query.= ';';
283    mysql_query( $query );
284   
285    $query = 'INSERT INTO '.SITES_TABLE;
286    $query.= " (id,galleries_url) VALUES (1, '".PHPWG_ROOT_PATH."galleries/');";
287    mysql_query( $query );
288   
289    // webmaster admin user
290    $query = 'INSERT INTO '.USERS_TABLE;
291    $query.= ' (id,username,password,status,language,mail_address) VALUES ';
292    $query.= "(1,'".$admin_name."','".md5( $admin_pass1 )."'";
293    $query.= ",'admin','".$language."'";
294    $query.= ",'".$admin_mail."');";
295    mysql_query($query);
296   
297    // guest user
298    $query = 'INSERT INTO '.USERS_TABLE;
299    $query.= '(id,username,password,status,language) VALUES ';
300    $query.= "(2,'guest','','guest','".$language."')";
301    $query.= ';';
302    mysql_query( $query );
303  }
304}
305
306$template->assign_vars(array(
307  'RELEASE'=>$release_version,
308 
309  'L_BASE_TITLE'=>$lang['Initial_config'],
310  'L_LANG_TITLE'=>$lang['Default_lang'],
311  'L_DB_TITLE'=>$lang['step1_title'],
312  'L_DB_HOST'=>$lang['step1_host'],
313  'L_DB_HOST_INFO'=>$lang['step1_host_info'],
314  'L_DB_USER'=>$lang['step1_user'],
315  'L_DB_USER_INFO'=>$lang['step1_user_info'],
316  'L_DB_PASS'=>$lang['step1_pass'],
317  'L_DB_PASS_INFO'=>$lang['step1_pass_info'],
318  'L_DB_NAME'=>$lang['step1_database'],
319  'L_DB_NAME_INFO'=>$lang['step1_database_info'],
320  'L_DB_PREFIX'=>$lang['step1_prefix'],
321  'L_DB_PREFIX_INFO'=>$lang['step1_prefix_info'],
322  'L_ADMIN_TITLE'=>$lang['step2_title'],
323  'L_ADMIN'=>$lang['conf_general_webmaster'],
324  'L_ADMIN_INFO'=>$lang['conf_general_webmaster_info'],
325  'L_ADMIN_PASSWORD'=>$lang['step2_pwd'],
326  'L_ADMIN_PASSWORD_INFO'=>$lang['step2_pwd_info'],
327  'L_ADMIN_CONFIRM_PASSWORD'=>$lang['step2_pwd_conf'],
328  'L_ADMIN_CONFIRM_PASSWORD_INFO'=>$lang['step2_pwd_conf_info'],
329  'L_ADMIN_EMAIL'=>$lang['conf_general_mail'],
330  'L_ADMIN_EMAIL_INFO'=>$lang['conf_general_mail_info'],
331  'L_SUBMIT'=>$lang['Start_Install'],
332  'L_HELP'=>$lang['install_help'],
333  'L_ERR_COPY'=>$lang['step1_err_copy'],
334  'L_END_TITLE'=>$lang['install_end_title'],
335  'L_END_MESSAGE'=>$lang['install_end_message'],
336 
337  'F_ACTION'=>add_session_id( 'install.php' ),
338  'F_DB_HOST'=>$dbhost,
339  'F_DB_USER'=>$dbuser,
340  'F_DB_NAME'=>$dbname,
341  'F_DB_PREFIX'=>$table_prefix,
342  'F_ADMIN'=>$admin_name,
343  'F_ADMIN_EMAIL'=>$admin_mail,
344  'F_LANG_SELECT'=>language_select($language),
345 
346  'T_CONTENT_ENCODING' => $lang_info['charset']
347        ));
348       
349//-------------------------------------------------------- errors & infos display
350if ( sizeof( $errors ) != 0 )
351{
352  $template->assign_block_vars('errors',array());
353  for ( $i = 0; $i < sizeof( $errors ); $i++ )
354  {
355    $template->assign_block_vars('errors.error',array('ERROR'=>$errors[$i]));
356  }
357}
358
359if ( sizeof( $infos ) != 0 )
360{
361  $template->assign_block_vars('infos',array());
362  for ( $i = 0; $i < sizeof( $infos ); $i++ )
363  {
364    $template->assign_block_vars('infos.info',array('INFO'=>$infos[$i]));
365  }
366}
367
368if ($step ==1)
369{
370  $template->assign_block_vars('install',array());
371}
372else
373{
374  $template->assign_block_vars('install_end',array());
375}
376
377//----------------------------------------------------------- html code display
378$template->pparse('install');
379?>
Note: See TracBrowser for help on using the repository browser.