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