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-2007 PhpWebGallery Team - http://phpwebgallery.net | |
---|
6 | // +-----------------------------------------------------------------------+ |
---|
7 | // | file : $Id: install.php 1855 2007-02-25 11:42:25Z rub $ |
---|
8 | // | last update : $Date: 2007-02-25 11:42:25 +0000 (Sun, 25 Feb 2007) $ |
---|
9 | // | last modifier : $Author: rub $ |
---|
10 | // | revision : $Revision: 1855 $ |
---|
11 | // +-----------------------------------------------------------------------+ |
---|
12 | // | This program is free software; you can redistribute it and/or modify | |
---|
13 | // | it under the terms of the GNU General Public License as published by | |
---|
14 | // | the Free Software Foundation | |
---|
15 | // | | |
---|
16 | // | This program is distributed in the hope that it will be useful, but | |
---|
17 | // | WITHOUT ANY WARRANTY; without even the implied warranty of | |
---|
18 | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
---|
19 | // | General Public License for more details. | |
---|
20 | // | | |
---|
21 | // | You should have received a copy of the GNU General Public License | |
---|
22 | // | along with this program; if not, write to the Free Software | |
---|
23 | // | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
---|
24 | // | USA. | |
---|
25 | // +-----------------------------------------------------------------------+ |
---|
26 | |
---|
27 | //----------------------------------------------------------- include |
---|
28 | define('PHPWG_ROOT_PATH','./'); |
---|
29 | |
---|
30 | // Guess an initial language ... |
---|
31 | function guess_lang() |
---|
32 | { |
---|
33 | return 'en_UK.iso-8859-1'; |
---|
34 | } |
---|
35 | |
---|
36 | // |
---|
37 | // Pick a language, any language ... |
---|
38 | // |
---|
39 | function language_select($default, $select_name = "language") |
---|
40 | { |
---|
41 | $available_lang = get_languages(); |
---|
42 | |
---|
43 | $lang_select = '<select name="' . $select_name . '" onchange="document.location = \''.PHPWG_ROOT_PATH.'install.php?language=\'+this.options[this.selectedIndex].value;">'; |
---|
44 | foreach ($available_lang as $code => $displayname) |
---|
45 | { |
---|
46 | $selected = ( strtolower($default) == strtolower($code) ) ? ' selected="selected"' : ''; |
---|
47 | $lang_select .= '<option value="'.$code.'" ' . $selected . '>' . ucwords($displayname) . '</option>'; |
---|
48 | } |
---|
49 | $lang_select .= '</select>'; |
---|
50 | |
---|
51 | return $lang_select; |
---|
52 | } |
---|
53 | |
---|
54 | /** |
---|
55 | * loads an sql file and executes all queries |
---|
56 | * |
---|
57 | * Before executing a query, $replaced is... replaced by $replacing. This is |
---|
58 | * useful when the SQL file contains generic words. Drop table queries are |
---|
59 | * not executed. |
---|
60 | * |
---|
61 | * @param string filepath |
---|
62 | * @param string replaced |
---|
63 | * @param string replacing |
---|
64 | * @return void |
---|
65 | */ |
---|
66 | function execute_sqlfile($filepath, $replaced, $replacing) |
---|
67 | { |
---|
68 | $sql_lines = file($filepath); |
---|
69 | $query = ''; |
---|
70 | foreach ($sql_lines as $sql_line) |
---|
71 | { |
---|
72 | $sql_line = trim($sql_line); |
---|
73 | if (preg_match('/(^--|^$)/', $sql_line)) |
---|
74 | { |
---|
75 | continue; |
---|
76 | } |
---|
77 | $query.= ' '.$sql_line; |
---|
78 | // if we reached the end of query, we execute it and reinitialize the |
---|
79 | // variable "query" |
---|
80 | if (preg_match('/;$/', $sql_line)) |
---|
81 | { |
---|
82 | $query = trim($query); |
---|
83 | $query = str_replace($replaced, $replacing, $query); |
---|
84 | // we don't execute "DROP TABLE" queries |
---|
85 | if (!preg_match('/^DROP TABLE/i', $query)) |
---|
86 | { |
---|
87 | mysql_query($query); |
---|
88 | } |
---|
89 | $query = ''; |
---|
90 | } |
---|
91 | } |
---|
92 | } |
---|
93 | |
---|
94 | set_magic_quotes_runtime(0); // Disable magic_quotes_runtime |
---|
95 | // |
---|
96 | // addslashes to vars if magic_quotes_gpc is off this is a security |
---|
97 | // precaution to prevent someone trying to break out of a SQL statement. |
---|
98 | // |
---|
99 | if( !get_magic_quotes_gpc() ) |
---|
100 | { |
---|
101 | if( is_array($_POST) ) |
---|
102 | { |
---|
103 | while( list($k, $v) = each($_POST) ) |
---|
104 | { |
---|
105 | if( is_array($_POST[$k]) ) |
---|
106 | { |
---|
107 | while( list($k2, $v2) = each($_POST[$k]) ) |
---|
108 | { |
---|
109 | $_POST[$k][$k2] = addslashes($v2); |
---|
110 | } |
---|
111 | @reset($_POST[$k]); |
---|
112 | } |
---|
113 | else |
---|
114 | { |
---|
115 | $_POST[$k] = addslashes($v); |
---|
116 | } |
---|
117 | } |
---|
118 | @reset($_POST); |
---|
119 | } |
---|
120 | |
---|
121 | if( is_array($_GET) ) |
---|
122 | { |
---|
123 | while( list($k, $v) = each($_GET) ) |
---|
124 | { |
---|
125 | if( is_array($_GET[$k]) ) |
---|
126 | { |
---|
127 | while( list($k2, $v2) = each($_GET[$k]) ) |
---|
128 | { |
---|
129 | $_GET[$k][$k2] = addslashes($v2); |
---|
130 | } |
---|
131 | @reset($_GET[$k]); |
---|
132 | } |
---|
133 | else |
---|
134 | { |
---|
135 | $_GET[$k] = addslashes($v); |
---|
136 | } |
---|
137 | } |
---|
138 | @reset($_GET); |
---|
139 | } |
---|
140 | |
---|
141 | if( is_array($_COOKIE) ) |
---|
142 | { |
---|
143 | while( list($k, $v) = each($_COOKIE) ) |
---|
144 | { |
---|
145 | if( is_array($_COOKIE[$k]) ) |
---|
146 | { |
---|
147 | while( list($k2, $v2) = each($_COOKIE[$k]) ) |
---|
148 | { |
---|
149 | $_COOKIE[$k][$k2] = addslashes($v2); |
---|
150 | } |
---|
151 | @reset($_COOKIE[$k]); |
---|
152 | } |
---|
153 | else |
---|
154 | { |
---|
155 | $_COOKIE[$k] = addslashes($v); |
---|
156 | } |
---|
157 | } |
---|
158 | @reset($_COOKIE); |
---|
159 | } |
---|
160 | } |
---|
161 | |
---|
162 | //----------------------------------------------------- variable initialization |
---|
163 | |
---|
164 | define('DEFAULT_PREFIX_TABLE', 'phpwebgallery_'); |
---|
165 | |
---|
166 | // Obtain various vars |
---|
167 | $dbhost = (!empty($_POST['dbhost'])) ? $_POST['dbhost'] : 'localhost'; |
---|
168 | $dbuser = (!empty($_POST['dbuser'])) ? $_POST['dbuser'] : ''; |
---|
169 | $dbpasswd = (!empty($_POST['dbpasswd'])) ? $_POST['dbpasswd'] : ''; |
---|
170 | $dbname = (!empty($_POST['dbname'])) ? $_POST['dbname'] : ''; |
---|
171 | |
---|
172 | if (isset($_POST['install'])) |
---|
173 | { |
---|
174 | $table_prefix = $_POST['prefix']; |
---|
175 | } |
---|
176 | else |
---|
177 | { |
---|
178 | $table_prefix = DEFAULT_PREFIX_TABLE; |
---|
179 | } |
---|
180 | |
---|
181 | $admin_name = (!empty($_POST['admin_name'])) ? $_POST['admin_name'] : ''; |
---|
182 | $admin_pass1 = (!empty($_POST['admin_pass1'])) ? $_POST['admin_pass1'] : ''; |
---|
183 | $admin_pass2 = (!empty($_POST['admin_pass2'])) ? $_POST['admin_pass2'] : ''; |
---|
184 | $admin_mail = (!empty($_POST['admin_mail'])) ? $_POST['admin_mail'] : ''; |
---|
185 | |
---|
186 | $infos = array(); |
---|
187 | $errors = array(); |
---|
188 | |
---|
189 | // Open config.php ... if it exists |
---|
190 | $config_file = PHPWG_ROOT_PATH.'include/mysql.inc.php'; |
---|
191 | if (@file_exists($config_file)) |
---|
192 | { |
---|
193 | include($config_file); |
---|
194 | // Is PhpWebGallery already installed ? |
---|
195 | if (defined("PHPWG_INSTALLED")) |
---|
196 | { |
---|
197 | die('PhpWebGallery is already installed'); |
---|
198 | } |
---|
199 | } |
---|
200 | |
---|
201 | $prefixeTable = $table_prefix; |
---|
202 | include(PHPWG_ROOT_PATH . 'include/config_default.inc.php'); |
---|
203 | @include(PHPWG_ROOT_PATH. 'include/config_local.inc.php'); |
---|
204 | include(PHPWG_ROOT_PATH . 'include/constants.php'); |
---|
205 | include(PHPWG_ROOT_PATH . 'include/functions.inc.php'); |
---|
206 | include(PHPWG_ROOT_PATH . 'admin/include/functions.php'); |
---|
207 | include(PHPWG_ROOT_PATH . 'include/template.php'); |
---|
208 | |
---|
209 | if ( isset( $_POST['language'] )) |
---|
210 | { |
---|
211 | $language = strip_tags($_POST['language']); |
---|
212 | } |
---|
213 | elseif ( isset( $_GET['language'] )) |
---|
214 | { |
---|
215 | $language = strip_tags($_GET['language']); |
---|
216 | } |
---|
217 | else |
---|
218 | { |
---|
219 | $language = guess_lang(); |
---|
220 | } |
---|
221 | |
---|
222 | if (!file_exists(PHPWG_ROOT_PATH.'language/'.$language.'/install.lang.php')) |
---|
223 | { |
---|
224 | $language = 'en_UK.iso-8859-1'; |
---|
225 | } |
---|
226 | |
---|
227 | include( './language/'.$language.'/common.lang.php' ); |
---|
228 | // Never: @include( './language/'.$language.'/local.lang.php' ); |
---|
229 | include( './language/'.$language.'/admin.lang.php' ); |
---|
230 | include( './language/'.$language.'/install.lang.php' ); |
---|
231 | //----------------------------------------------------- template initialization |
---|
232 | $template=setup_style('yoga'); |
---|
233 | $template->set_filenames( array('install'=>'install.tpl') ); |
---|
234 | $step = 1; |
---|
235 | //---------------------------------------------------------------- form analyze |
---|
236 | if ( isset( $_POST['install'] )) |
---|
237 | { |
---|
238 | if ( @mysql_connect( $_POST['dbhost'], |
---|
239 | $_POST['dbuser'], |
---|
240 | $_POST['dbpasswd'] ) ) |
---|
241 | { |
---|
242 | if ( @mysql_select_db($_POST['dbname'] ) ) |
---|
243 | { |
---|
244 | array_push( $infos, $lang['step1_confirmation'] ); |
---|
245 | } |
---|
246 | else |
---|
247 | { |
---|
248 | array_push( $errors, $lang['step1_err_db'] ); |
---|
249 | } |
---|
250 | } |
---|
251 | else |
---|
252 | { |
---|
253 | array_push( $errors, $lang['step1_err_server'] ); |
---|
254 | } |
---|
255 | |
---|
256 | $webmaster = trim(preg_replace( '/\s{2,}/', ' ', $admin_name )); |
---|
257 | if ( empty($webmaster)) |
---|
258 | array_push( $errors, $lang['step2_err_login1'] ); |
---|
259 | else if ( preg_match( '/[\'"]/', $webmaster ) ) |
---|
260 | array_push( $errors, $lang['step2_err_login3'] ); |
---|
261 | if ( $admin_pass1 != $admin_pass2 || empty($admin_pass1) ) |
---|
262 | array_push( $errors, $lang['step2_err_pass'] ); |
---|
263 | if ( empty($admin_mail)) |
---|
264 | array_push( $errors, $lang['reg_err_mail_address'] ); |
---|
265 | else |
---|
266 | { |
---|
267 | $error_mail_address = validate_mail_address($admin_mail); |
---|
268 | if (!empty($error_mail_address)) |
---|
269 | array_push( $errors, $error_mail_address ); |
---|
270 | } |
---|
271 | |
---|
272 | if ( count( $errors ) == 0 ) |
---|
273 | { |
---|
274 | $step = 2; |
---|
275 | $file_content = '<?php |
---|
276 | $cfgBase = \''.$dbname.'\'; |
---|
277 | $cfgUser = \''.$dbuser.'\'; |
---|
278 | $cfgPassword = \''.$dbpasswd.'\'; |
---|
279 | $cfgHote = \''.$dbhost.'\'; |
---|
280 | |
---|
281 | $prefixeTable = \''.$table_prefix.'\'; |
---|
282 | |
---|
283 | define(\'PHPWG_INSTALLED\', true); |
---|
284 | ?'.'>'; |
---|
285 | |
---|
286 | @umask(0111); |
---|
287 | // writing the configuration file |
---|
288 | if ( !($fp = @fopen( $config_file, 'w' ))) |
---|
289 | { |
---|
290 | $html_content = htmlentities( $file_content, ENT_QUOTES ); |
---|
291 | $html_content = nl2br( $html_content ); |
---|
292 | $template->assign_block_vars( |
---|
293 | 'error_copy', |
---|
294 | array( |
---|
295 | 'FILE_CONTENT' => $html_content, |
---|
296 | ) |
---|
297 | ); |
---|
298 | } |
---|
299 | @fputs($fp, $file_content, strlen($file_content)); |
---|
300 | @fclose($fp); |
---|
301 | |
---|
302 | // tables creation, based on phpwebgallery_structure.sql |
---|
303 | execute_sqlfile( |
---|
304 | PHPWG_ROOT_PATH.'install/phpwebgallery_structure.sql', |
---|
305 | DEFAULT_PREFIX_TABLE, |
---|
306 | $table_prefix |
---|
307 | ); |
---|
308 | // We fill the tables with basic informations |
---|
309 | execute_sqlfile( |
---|
310 | PHPWG_ROOT_PATH.'install/config.sql', |
---|
311 | DEFAULT_PREFIX_TABLE, |
---|
312 | $table_prefix |
---|
313 | ); |
---|
314 | |
---|
315 | $query = ' |
---|
316 | UPDATE '.CONFIG_TABLE.' |
---|
317 | SET value = \''.$language.'\' |
---|
318 | WHERE param = \'default_language\' |
---|
319 | ;'; |
---|
320 | mysql_query($query); |
---|
321 | |
---|
322 | // fill $conf global array |
---|
323 | load_conf_from_db(); |
---|
324 | |
---|
325 | $insert = array( |
---|
326 | 'id' => 1, |
---|
327 | 'galleries_url' => PHPWG_ROOT_PATH.'galleries/', |
---|
328 | ); |
---|
329 | mass_inserts(SITES_TABLE, array_keys($insert), array($insert)); |
---|
330 | |
---|
331 | // webmaster admin user |
---|
332 | $inserts = array( |
---|
333 | array( |
---|
334 | 'id' => 1, |
---|
335 | 'username' => $admin_name, |
---|
336 | 'password' => md5($admin_pass1), |
---|
337 | 'mail_address' => $admin_mail, |
---|
338 | ), |
---|
339 | array( |
---|
340 | 'id' => 2, |
---|
341 | 'username' => 'guest', |
---|
342 | ), |
---|
343 | ); |
---|
344 | mass_inserts(USERS_TABLE, array_keys($inserts[0]), $inserts); |
---|
345 | |
---|
346 | create_user_infos(1); |
---|
347 | create_user_infos(2); |
---|
348 | |
---|
349 | $query = ' |
---|
350 | UPDATE '.USER_INFOS_TABLE.' |
---|
351 | SET language = \''.$language.'\' |
---|
352 | ;'; |
---|
353 | mysql_query($query); |
---|
354 | |
---|
355 | // Available upgrades must be ignored after a fresh installation. To |
---|
356 | // make PWG avoid upgrading, we must tell it upgrades have already been |
---|
357 | // made. |
---|
358 | list($dbnow) = mysql_fetch_row(pwg_query('SELECT NOW();')); |
---|
359 | define('CURRENT_DATE', $dbnow); |
---|
360 | $datas = array(); |
---|
361 | foreach (get_available_upgrade_ids() as $upgrade_id) |
---|
362 | { |
---|
363 | array_push( |
---|
364 | $datas, |
---|
365 | array( |
---|
366 | 'id' => $upgrade_id, |
---|
367 | 'applied' => CURRENT_DATE, |
---|
368 | 'description' => 'upgrade included in installation', |
---|
369 | ) |
---|
370 | ); |
---|
371 | } |
---|
372 | mass_inserts( |
---|
373 | UPGRADE_TABLE, |
---|
374 | array_keys($datas[0]), |
---|
375 | $datas |
---|
376 | ); |
---|
377 | } |
---|
378 | } |
---|
379 | |
---|
380 | $template->assign_vars( |
---|
381 | array( |
---|
382 | 'RELEASE'=>PHPWG_VERSION, |
---|
383 | |
---|
384 | 'L_BASE_TITLE'=>$lang['Initial_config'], |
---|
385 | 'L_LANG_TITLE'=>$lang['Default_lang'], |
---|
386 | 'L_DB_TITLE'=>$lang['step1_title'], |
---|
387 | 'L_DB_HOST'=>$lang['step1_host'], |
---|
388 | 'L_DB_HOST_INFO'=>$lang['step1_host_info'], |
---|
389 | 'L_DB_USER'=>$lang['step1_user'], |
---|
390 | 'L_DB_USER_INFO'=>$lang['step1_user_info'], |
---|
391 | 'L_DB_PASS'=>$lang['step1_pass'], |
---|
392 | 'L_DB_PASS_INFO'=>$lang['step1_pass_info'], |
---|
393 | 'L_DB_NAME'=>$lang['step1_database'], |
---|
394 | 'L_DB_NAME_INFO'=>$lang['step1_database_info'], |
---|
395 | 'L_DB_PREFIX'=>$lang['step1_prefix'], |
---|
396 | 'L_DB_PREFIX_INFO'=>$lang['step1_prefix_info'], |
---|
397 | 'L_ADMIN_TITLE'=>$lang['step2_title'], |
---|
398 | 'L_ADMIN'=>$lang['install_webmaster'], |
---|
399 | 'L_ADMIN_INFO'=>$lang['install_webmaster_info'], |
---|
400 | 'L_ADMIN_PASSWORD'=>$lang['step2_pwd'], |
---|
401 | 'L_ADMIN_PASSWORD_INFO'=>$lang['step2_pwd_info'], |
---|
402 | 'L_ADMIN_CONFIRM_PASSWORD'=>$lang['step2_pwd_conf'], |
---|
403 | 'L_ADMIN_CONFIRM_PASSWORD_INFO'=>$lang['step2_pwd_conf_info'], |
---|
404 | 'L_ADMIN_EMAIL'=>$lang['conf_mail_webmaster'], |
---|
405 | 'L_ADMIN_EMAIL_INFO'=>$lang['conf_mail_webmaster_info'], |
---|
406 | 'L_SUBMIT'=>$lang['Start_Install'], |
---|
407 | 'L_INSTALL_HELP'=>sprintf($lang['install_help'], 'http://forum.'.PHPWG_DOMAIN.'/'), |
---|
408 | 'L_ERR_COPY'=>$lang['step1_err_copy'], |
---|
409 | 'L_END_TITLE'=>$lang['install_end_title'], |
---|
410 | 'L_END_MESSAGE'=>$lang['install_end_message'], |
---|
411 | |
---|
412 | 'F_ACTION'=>'install.php', |
---|
413 | 'F_DB_HOST'=>$dbhost, |
---|
414 | 'F_DB_USER'=>$dbuser, |
---|
415 | 'F_DB_NAME'=>$dbname, |
---|
416 | 'F_DB_PREFIX' => ( |
---|
417 | $table_prefix != DEFAULT_PREFIX_TABLE |
---|
418 | ? $table_prefix |
---|
419 | : DEFAULT_PREFIX_TABLE |
---|
420 | ), |
---|
421 | 'F_ADMIN'=>$admin_name, |
---|
422 | 'F_ADMIN_EMAIL'=>$admin_mail, |
---|
423 | 'F_LANG_SELECT'=>language_select($language), |
---|
424 | |
---|
425 | 'T_CONTENT_ENCODING' => $lang_info['charset'] |
---|
426 | )); |
---|
427 | |
---|
428 | //------------------------------------------------------ errors & infos display |
---|
429 | if ( sizeof( $errors ) != 0 ) |
---|
430 | { |
---|
431 | $template->assign_block_vars('errors',array()); |
---|
432 | for ( $i = 0; $i < sizeof( $errors ); $i++ ) |
---|
433 | { |
---|
434 | $template->assign_block_vars('errors.error',array('ERROR'=>$errors[$i])); |
---|
435 | } |
---|
436 | } |
---|
437 | |
---|
438 | if ( sizeof( $infos ) != 0 ) |
---|
439 | { |
---|
440 | $template->assign_block_vars('infos',array()); |
---|
441 | for ( $i = 0; $i < sizeof( $infos ); $i++ ) |
---|
442 | { |
---|
443 | $template->assign_block_vars('infos.info',array('INFO'=>$infos[$i])); |
---|
444 | } |
---|
445 | } |
---|
446 | |
---|
447 | if ($step ==1) |
---|
448 | { |
---|
449 | $template->assign_block_vars('install',array()); |
---|
450 | } |
---|
451 | else |
---|
452 | { |
---|
453 | $template->assign_block_vars('install_end',array()); |
---|
454 | } |
---|
455 | |
---|
456 | //----------------------------------------------------------- html code display |
---|
457 | $template->pparse('install'); |
---|
458 | ?> |
---|