source: trunk/install.php @ 367

Last change on this file since 367 was 367, checked in by gweltas, 20 years ago

Migration of installation procedure

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