1 | <?php |
---|
2 | // +-----------------------------------------------------------------------+ |
---|
3 | // | PhpWebGallery - a PHP based picture gallery | |
---|
4 | // | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net | |
---|
5 | // | Copyright (C) 2003-2005 PhpWebGallery Team - http://phpwebgallery.net | |
---|
6 | // +-----------------------------------------------------------------------+ |
---|
7 | // | branch : BSF (Best So Far) |
---|
8 | // | file : $RCSfile$ |
---|
9 | // | last update : $Date: 2006-02-06 21:52:16 +0000 (Mon, 06 Feb 2006) $ |
---|
10 | // | last modifier : $Author: plg $ |
---|
11 | // | revision : $Revision: 1027 $ |
---|
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 |
---|
29 | define('PHPWG_ROOT_PATH','./'); |
---|
30 | |
---|
31 | // Guess an initial language ... |
---|
32 | function guess_lang() |
---|
33 | { |
---|
34 | return 'en_UK.iso-8859-1'; |
---|
35 | |
---|
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 | |
---|
69 | /** |
---|
70 | * loads an sql file and executes all queries |
---|
71 | * |
---|
72 | * Before executing a query, $replaced is... replaced by $replacing. This is |
---|
73 | * useful when the SQL file contains generic words. Drop table queries are |
---|
74 | * not executed. |
---|
75 | * |
---|
76 | * @param string filepath |
---|
77 | * @param string replaced |
---|
78 | * @param string replacing |
---|
79 | * @return void |
---|
80 | */ |
---|
81 | function execute_sqlfile($filepath, $replaced, $replacing) |
---|
82 | { |
---|
83 | $sql_lines = file($filepath); |
---|
84 | $query = ''; |
---|
85 | foreach ($sql_lines as $sql_line) |
---|
86 | { |
---|
87 | $sql_line = trim($sql_line); |
---|
88 | if (preg_match('/(^--|^$)/', $sql_line)) |
---|
89 | { |
---|
90 | continue; |
---|
91 | } |
---|
92 | $query.= ' '.$sql_line; |
---|
93 | // if we reached the end of query, we execute it and reinitialize the |
---|
94 | // variable "query" |
---|
95 | if (preg_match('/;$/', $sql_line)) |
---|
96 | { |
---|
97 | $query = trim($query); |
---|
98 | $query = str_replace($replaced, $replacing, $query); |
---|
99 | // we don't execute "DROP TABLE" queries |
---|
100 | if (!preg_match('/^DROP TABLE/i', $query)) |
---|
101 | { |
---|
102 | mysql_query($query); |
---|
103 | } |
---|
104 | $query = ''; |
---|
105 | } |
---|
106 | } |
---|
107 | } |
---|
108 | |
---|
109 | set_magic_quotes_runtime(0); // Disable magic_quotes_runtime |
---|
110 | // |
---|
111 | // addslashes to vars if magic_quotes_gpc is off this is a security |
---|
112 | // precaution to prevent someone trying to break out of a SQL statement. |
---|
113 | // |
---|
114 | if( !get_magic_quotes_gpc() ) |
---|
115 | { |
---|
116 | if( is_array($_POST) ) |
---|
117 | { |
---|
118 | while( list($k, $v) = each($_POST) ) |
---|
119 | { |
---|
120 | if( is_array($_POST[$k]) ) |
---|
121 | { |
---|
122 | while( list($k2, $v2) = each($_POST[$k]) ) |
---|
123 | { |
---|
124 | $_POST[$k][$k2] = addslashes($v2); |
---|
125 | } |
---|
126 | @reset($_POST[$k]); |
---|
127 | } |
---|
128 | else |
---|
129 | { |
---|
130 | $_POST[$k] = addslashes($v); |
---|
131 | } |
---|
132 | } |
---|
133 | @reset($_POST); |
---|
134 | } |
---|
135 | |
---|
136 | if( is_array($_COOKIE) ) |
---|
137 | { |
---|
138 | while( list($k, $v) = each($_COOKIE) ) |
---|
139 | { |
---|
140 | if( is_array($_COOKIE[$k]) ) |
---|
141 | { |
---|
142 | while( list($k2, $v2) = each($_COOKIE[$k]) ) |
---|
143 | { |
---|
144 | $_COOKIE[$k][$k2] = addslashes($v2); |
---|
145 | } |
---|
146 | @reset($_COOKIE[$k]); |
---|
147 | } |
---|
148 | else |
---|
149 | { |
---|
150 | $_COOKIE[$k] = addslashes($v); |
---|
151 | } |
---|
152 | } |
---|
153 | @reset($_COOKIE); |
---|
154 | } |
---|
155 | } |
---|
156 | |
---|
157 | //----------------------------------------------------- variable initialization |
---|
158 | // Obtain various vars |
---|
159 | $dbhost = (!empty($_POST['dbhost'])) ? $_POST['dbhost'] : 'localhost'; |
---|
160 | $dbuser = (!empty($_POST['dbuser'])) ? $_POST['dbuser'] : ''; |
---|
161 | $dbpasswd = (!empty($_POST['dbpasswd'])) ? $_POST['dbpasswd'] : ''; |
---|
162 | $dbname = (!empty($_POST['dbname'])) ? $_POST['dbname'] : ''; |
---|
163 | |
---|
164 | $table_prefix = (!empty($_POST['prefix'])) ? $_POST['prefix'] : 'phpwebgallery_'; |
---|
165 | |
---|
166 | $admin_name = (!empty($_POST['admin_name'])) ? $_POST['admin_name'] : ''; |
---|
167 | $admin_pass1 = (!empty($_POST['admin_pass1'])) ? $_POST['admin_pass1'] : ''; |
---|
168 | $admin_pass2 = (!empty($_POST['admin_pass2'])) ? $_POST['admin_pass2'] : ''; |
---|
169 | $admin_mail = (!empty($_POST['admin_mail'])) ? $_POST['admin_mail'] : ''; |
---|
170 | |
---|
171 | $infos = array(); |
---|
172 | $errors = array(); |
---|
173 | |
---|
174 | // Open config.php ... if it exists |
---|
175 | $config_file = PHPWG_ROOT_PATH.'include/mysql.inc.php'; |
---|
176 | if (@file_exists($config_file)) |
---|
177 | { |
---|
178 | include($config_file); |
---|
179 | // Is PhpWebGallery already installed ? |
---|
180 | if (defined("PHPWG_INSTALLED")) |
---|
181 | { |
---|
182 | die('PhpWebGallery is already installed'); |
---|
183 | } |
---|
184 | } |
---|
185 | |
---|
186 | $prefixeTable = $table_prefix; |
---|
187 | include(PHPWG_ROOT_PATH . 'include/config_default.inc.php'); |
---|
188 | include(PHPWG_ROOT_PATH . 'include/constants.php'); |
---|
189 | include(PHPWG_ROOT_PATH . 'include/functions.inc.php'); |
---|
190 | include(PHPWG_ROOT_PATH . 'include/template.php'); |
---|
191 | |
---|
192 | if ( isset( $_POST['language'] )) |
---|
193 | { |
---|
194 | $language = strip_tags($_POST['language']); |
---|
195 | } |
---|
196 | else |
---|
197 | { |
---|
198 | $language = guess_lang(); |
---|
199 | } |
---|
200 | |
---|
201 | if (!file_exists(PHPWG_ROOT_PATH.'language/'.$language.'/install.lang.php')) |
---|
202 | { |
---|
203 | $language = 'en_UK.iso-8859-1'; |
---|
204 | } |
---|
205 | |
---|
206 | include( './language/'.$language.'/common.lang.php' ); |
---|
207 | include( './language/'.$language.'/admin.lang.php' ); |
---|
208 | include( './language/'.$language.'/install.lang.php' ); |
---|
209 | //----------------------------------------------------- template initialization |
---|
210 | $template=setup_style('yoga'); |
---|
211 | $template->set_filenames( array('install'=>'install.tpl') ); |
---|
212 | $step = 1; |
---|
213 | //---------------------------------------------------------------- form analyze |
---|
214 | if ( isset( $_POST['install'] )) |
---|
215 | { |
---|
216 | if ( @mysql_connect( $_POST['dbhost'], |
---|
217 | $_POST['dbuser'], |
---|
218 | $_POST['dbpasswd'] ) ) |
---|
219 | { |
---|
220 | if ( @mysql_select_db($_POST['dbname'] ) ) |
---|
221 | { |
---|
222 | array_push( $infos, $lang['step1_confirmation'] ); |
---|
223 | } |
---|
224 | else |
---|
225 | { |
---|
226 | array_push( $errors, $lang['step1_err_db'] ); |
---|
227 | } |
---|
228 | } |
---|
229 | else |
---|
230 | { |
---|
231 | array_push( $errors, $lang['step1_err_server'] ); |
---|
232 | } |
---|
233 | |
---|
234 | $webmaster = trim(preg_replace( '/\s{2,}/', ' ', $admin_name )); |
---|
235 | if ( empty($webmaster)) |
---|
236 | array_push( $errors, $lang['step2_err_login1'] ); |
---|
237 | else if ( preg_match( '/[\'"]/', $webmaster ) ) |
---|
238 | array_push( $errors, $lang['step2_err_login3'] ); |
---|
239 | if ( $admin_pass1 != $admin_pass2 || empty($admin_pass1) ) |
---|
240 | array_push( $errors, $lang['step2_err_pass'] ); |
---|
241 | if ( empty($admin_mail)) |
---|
242 | array_push( $errors, $lang['reg_err_mail_address'] ); |
---|
243 | else |
---|
244 | { |
---|
245 | $error_mail_address = validate_mail_address($admin_mail); |
---|
246 | if (!empty($error_mail_address)) |
---|
247 | array_push( $errors, $error_mail_address ); |
---|
248 | } |
---|
249 | |
---|
250 | if ( count( $errors ) == 0 ) |
---|
251 | { |
---|
252 | $step = 2; |
---|
253 | $file_content = "<?php"; |
---|
254 | $file_content.= "\n\$cfgBase = '". $dbname."';"; |
---|
255 | $file_content.= "\n\$cfgUser = '". $dbuser."';"; |
---|
256 | $file_content.= "\n\$cfgPassword = '". $dbpasswd."';"; |
---|
257 | $file_content.= "\n\$cfgHote = '". $dbhost."';"; |
---|
258 | $file_content.= "\n"; |
---|
259 | $file_content.= "\n\$prefixeTable = '".$table_prefix."';"; |
---|
260 | $file_content.= "\n"; |
---|
261 | $file_content.= "\ndefine('PHPWG_INSTALLED', true);"; |
---|
262 | $file_content.= "\n?".">"; |
---|
263 | |
---|
264 | @umask(0111); |
---|
265 | // writing the configuration file |
---|
266 | if ( !($fp = @fopen( $config_file, 'w' ))) |
---|
267 | { |
---|
268 | $html_content = htmlentities( $file_content, ENT_QUOTES ); |
---|
269 | $html_content = nl2br( $html_content ); |
---|
270 | $template->assign_block_vars('error_copy', |
---|
271 | array('FILE_CONTENT'=>$html_content)); |
---|
272 | } |
---|
273 | @fputs($fp, $file_content, strlen($file_content)); |
---|
274 | @fclose($fp); |
---|
275 | |
---|
276 | // tables creation, based on phpwebgallery_structure.sql |
---|
277 | execute_sqlfile( PHPWG_ROOT_PATH.'install/phpwebgallery_structure.sql' |
---|
278 | , 'phpwebgallery_' |
---|
279 | , $table_prefix ); |
---|
280 | // We fill the tables with basic informations |
---|
281 | execute_sqlfile( PHPWG_ROOT_PATH.'install/config.sql' |
---|
282 | , 'phpwebgallery_' |
---|
283 | , $table_prefix ); |
---|
284 | |
---|
285 | $query = 'UPDATE '.CONFIG_TABLE; |
---|
286 | $query.= " SET value = '".$admin_mail."'"; |
---|
287 | $query.= " WHERE param = 'mail_webmaster'"; |
---|
288 | $query.= ';'; |
---|
289 | mysql_query( $query ); |
---|
290 | |
---|
291 | $query = 'UPDATE '.CONFIG_TABLE; |
---|
292 | $query.= " SET value = '".$language."'"; |
---|
293 | $query.= " WHERE param = 'default_language'"; |
---|
294 | $query.= ';'; |
---|
295 | mysql_query( $query ); |
---|
296 | |
---|
297 | $query = 'INSERT INTO '.SITES_TABLE; |
---|
298 | $query.= " (id,galleries_url) VALUES (1, '".PHPWG_ROOT_PATH."galleries/');"; |
---|
299 | mysql_query( $query ); |
---|
300 | |
---|
301 | // webmaster admin user |
---|
302 | $query = ' |
---|
303 | INSERT INTO '.USERS_TABLE.' |
---|
304 | (id,username,password,mail_address) |
---|
305 | VALUES |
---|
306 | (1,\''.$admin_name.'\',\''.md5($admin_pass1).'\',\''.$admin_mail.'\') |
---|
307 | ;'; |
---|
308 | mysql_query($query); |
---|
309 | |
---|
310 | $query = ' |
---|
311 | INSERT INTO '.USER_INFOS_TABLE.' |
---|
312 | (user_id,status,language) |
---|
313 | VALUES |
---|
314 | (1, \'admin\', \''.$language.'\') |
---|
315 | ;'; |
---|
316 | mysql_query($query); |
---|
317 | |
---|
318 | $query = ' |
---|
319 | UPDATE '.USER_INFOS_TABLE.' |
---|
320 | SET feed_id = \''.find_available_feed_id().'\' |
---|
321 | WHERE user_id = 1 |
---|
322 | ;'; |
---|
323 | mysql_query($query); |
---|
324 | |
---|
325 | // guest user |
---|
326 | $query = ' |
---|
327 | INSERT INTO '.USERS_TABLE.' |
---|
328 | (id,username,password,mail_address) |
---|
329 | VALUES |
---|
330 | (2,\'guest\',\'\',\'\') |
---|
331 | ;'; |
---|
332 | mysql_query($query); |
---|
333 | |
---|
334 | $query = ' |
---|
335 | INSERT INTO '.USER_INFOS_TABLE.' |
---|
336 | (user_id,status,language) |
---|
337 | VALUES |
---|
338 | (2, \'guest\', \''.$language.'\') |
---|
339 | ;'; |
---|
340 | mysql_query($query); |
---|
341 | |
---|
342 | // Available upgrades must be ignored after a fresh installation. To |
---|
343 | // make PWG avoid upgrading, we must tell it upgrades have already been |
---|
344 | // made. |
---|
345 | foreach (get_available_upgrade_ids() as $upgrade_id) |
---|
346 | { |
---|
347 | $query = ' |
---|
348 | INSERT INTO '.UPGRADE_TABLE.' |
---|
349 | (id, applied, description) |
---|
350 | VALUES |
---|
351 | ('.$upgrade_id.', NOW(), \'upgrade included in installation\') |
---|
352 | '; |
---|
353 | mysql_query($query); |
---|
354 | } |
---|
355 | } |
---|
356 | } |
---|
357 | |
---|
358 | $template->assign_vars( |
---|
359 | array( |
---|
360 | 'RELEASE'=>PHPWG_VERSION, |
---|
361 | |
---|
362 | 'L_BASE_TITLE'=>$lang['Initial_config'], |
---|
363 | 'L_LANG_TITLE'=>$lang['Default_lang'], |
---|
364 | 'L_DB_TITLE'=>$lang['step1_title'], |
---|
365 | 'L_DB_HOST'=>$lang['step1_host'], |
---|
366 | 'L_DB_HOST_INFO'=>$lang['step1_host_info'], |
---|
367 | 'L_DB_USER'=>$lang['step1_user'], |
---|
368 | 'L_DB_USER_INFO'=>$lang['step1_user_info'], |
---|
369 | 'L_DB_PASS'=>$lang['step1_pass'], |
---|
370 | 'L_DB_PASS_INFO'=>$lang['step1_pass_info'], |
---|
371 | 'L_DB_NAME'=>$lang['step1_database'], |
---|
372 | 'L_DB_NAME_INFO'=>$lang['step1_database_info'], |
---|
373 | 'L_DB_PREFIX'=>$lang['step1_prefix'], |
---|
374 | 'L_DB_PREFIX_INFO'=>$lang['step1_prefix_info'], |
---|
375 | 'L_ADMIN_TITLE'=>$lang['step2_title'], |
---|
376 | 'L_ADMIN'=>$lang['install_webmaster'], |
---|
377 | 'L_ADMIN_INFO'=>$lang['install_webmaster_info'], |
---|
378 | 'L_ADMIN_PASSWORD'=>$lang['step2_pwd'], |
---|
379 | 'L_ADMIN_PASSWORD_INFO'=>$lang['step2_pwd_info'], |
---|
380 | 'L_ADMIN_CONFIRM_PASSWORD'=>$lang['step2_pwd_conf'], |
---|
381 | 'L_ADMIN_CONFIRM_PASSWORD_INFO'=>$lang['step2_pwd_conf_info'], |
---|
382 | 'L_ADMIN_EMAIL'=>$lang['conf_mail_webmaster'], |
---|
383 | 'L_ADMIN_EMAIL_INFO'=>$lang['conf_mail_webmaster_info'], |
---|
384 | 'L_SUBMIT'=>$lang['Start_Install'], |
---|
385 | 'L_HELP'=>$lang['install_help'], |
---|
386 | 'L_ERR_COPY'=>$lang['step1_err_copy'], |
---|
387 | 'L_END_TITLE'=>$lang['install_end_title'], |
---|
388 | 'L_END_MESSAGE'=>$lang['install_end_message'], |
---|
389 | |
---|
390 | 'F_ACTION'=>'install.php', |
---|
391 | 'F_DB_HOST'=>$dbhost, |
---|
392 | 'F_DB_USER'=>$dbuser, |
---|
393 | 'F_DB_NAME'=>$dbname, |
---|
394 | 'F_DB_PREFIX'=>$table_prefix, |
---|
395 | 'F_ADMIN'=>$admin_name, |
---|
396 | 'F_ADMIN_EMAIL'=>$admin_mail, |
---|
397 | 'F_LANG_SELECT'=>language_select($language), |
---|
398 | |
---|
399 | 'T_CONTENT_ENCODING' => $lang_info['charset'] |
---|
400 | )); |
---|
401 | |
---|
402 | //------------------------------------------------------ errors & infos display |
---|
403 | if ( sizeof( $errors ) != 0 ) |
---|
404 | { |
---|
405 | $template->assign_block_vars('errors',array()); |
---|
406 | for ( $i = 0; $i < sizeof( $errors ); $i++ ) |
---|
407 | { |
---|
408 | $template->assign_block_vars('errors.error',array('ERROR'=>$errors[$i])); |
---|
409 | } |
---|
410 | } |
---|
411 | |
---|
412 | if ( sizeof( $infos ) != 0 ) |
---|
413 | { |
---|
414 | $template->assign_block_vars('infos',array()); |
---|
415 | for ( $i = 0; $i < sizeof( $infos ); $i++ ) |
---|
416 | { |
---|
417 | $template->assign_block_vars('infos.info',array('INFO'=>$infos[$i])); |
---|
418 | } |
---|
419 | } |
---|
420 | |
---|
421 | if ($step ==1) |
---|
422 | { |
---|
423 | $template->assign_block_vars('install',array()); |
---|
424 | } |
---|
425 | else |
---|
426 | { |
---|
427 | $template->assign_block_vars('install_end',array()); |
---|
428 | } |
---|
429 | |
---|
430 | //----------------------------------------------------------- html code display |
---|
431 | $template->pparse('install'); |
---|
432 | ?> |
---|