1 | <?php |
---|
2 | // +-----------------------------------------------------------------------+ |
---|
3 | // | Piwigo - a PHP based picture gallery | |
---|
4 | // +-----------------------------------------------------------------------+ |
---|
5 | // | Copyright(C) 2008-2009 Piwigo Team http://piwigo.org | |
---|
6 | // | Copyright(C) 2003-2008 PhpWebGallery Team http://phpwebgallery.net | |
---|
7 | // | Copyright(C) 2002-2003 Pierrick LE GALL http://le-gall.net/pierrick | |
---|
8 | // +-----------------------------------------------------------------------+ |
---|
9 | // | This program is free software; you can redistribute it and/or modify | |
---|
10 | // | it under the terms of the GNU General Public License as published by | |
---|
11 | // | the Free Software Foundation | |
---|
12 | // | | |
---|
13 | // | This program is distributed in the hope that it will be useful, but | |
---|
14 | // | WITHOUT ANY WARRANTY; without even the implied warranty of | |
---|
15 | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
---|
16 | // | General Public License for more details. | |
---|
17 | // | | |
---|
18 | // | You should have received a copy of the GNU General Public License | |
---|
19 | // | along with this program; if not, write to the Free Software | |
---|
20 | // | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
---|
21 | // | USA. | |
---|
22 | // +-----------------------------------------------------------------------+ |
---|
23 | |
---|
24 | //----------------------------------------------------------- include |
---|
25 | define('PHPWG_ROOT_PATH','./'); |
---|
26 | |
---|
27 | /** |
---|
28 | * loads an sql file and executes all queries |
---|
29 | * |
---|
30 | * Before executing a query, $replaced is... replaced by $replacing. This is |
---|
31 | * useful when the SQL file contains generic words. Drop table queries are |
---|
32 | * not executed. |
---|
33 | * |
---|
34 | * @param string filepath |
---|
35 | * @param string replaced |
---|
36 | * @param string replacing |
---|
37 | * @return void |
---|
38 | */ |
---|
39 | function execute_sqlfile($filepath, $replaced, $replacing) |
---|
40 | { |
---|
41 | $sql_lines = file($filepath); |
---|
42 | $query = ''; |
---|
43 | foreach ($sql_lines as $sql_line) |
---|
44 | { |
---|
45 | $sql_line = trim($sql_line); |
---|
46 | if (preg_match('/(^--|^$)/', $sql_line)) |
---|
47 | { |
---|
48 | continue; |
---|
49 | } |
---|
50 | $query.= ' '.$sql_line; |
---|
51 | // if we reached the end of query, we execute it and reinitialize the |
---|
52 | // variable "query" |
---|
53 | if (preg_match('/;$/', $sql_line)) |
---|
54 | { |
---|
55 | $query = trim($query); |
---|
56 | $query = str_replace($replaced, $replacing, $query); |
---|
57 | // we don't execute "DROP TABLE" queries |
---|
58 | if (!preg_match('/^DROP TABLE/i', $query)) |
---|
59 | { |
---|
60 | global $install_charset_collate; |
---|
61 | if ( !empty($install_charset_collate) ) |
---|
62 | { |
---|
63 | if ( preg_match('/^(CREATE TABLE .*)[\s]*;[\s]*/im', $query, $matches) ) |
---|
64 | { |
---|
65 | $query = $matches[1].' '.$install_charset_collate.';'; |
---|
66 | } |
---|
67 | } |
---|
68 | pwg_query($query); |
---|
69 | } |
---|
70 | $query = ''; |
---|
71 | } |
---|
72 | } |
---|
73 | } |
---|
74 | |
---|
75 | @set_magic_quotes_runtime(0); // Disable magic_quotes_runtime |
---|
76 | // |
---|
77 | // addslashes to vars if magic_quotes_gpc is off this is a security |
---|
78 | // precaution to prevent someone trying to break out of a SQL statement. |
---|
79 | // |
---|
80 | if( !@get_magic_quotes_gpc() ) |
---|
81 | { |
---|
82 | if( is_array($_POST) ) |
---|
83 | { |
---|
84 | while( list($k, $v) = each($_POST) ) |
---|
85 | { |
---|
86 | if( is_array($_POST[$k]) ) |
---|
87 | { |
---|
88 | while( list($k2, $v2) = each($_POST[$k]) ) |
---|
89 | { |
---|
90 | $_POST[$k][$k2] = addslashes($v2); |
---|
91 | } |
---|
92 | @reset($_POST[$k]); |
---|
93 | } |
---|
94 | else |
---|
95 | { |
---|
96 | $_POST[$k] = addslashes($v); |
---|
97 | } |
---|
98 | } |
---|
99 | @reset($_POST); |
---|
100 | } |
---|
101 | |
---|
102 | if( is_array($_GET) ) |
---|
103 | { |
---|
104 | while( list($k, $v) = each($_GET) ) |
---|
105 | { |
---|
106 | if( is_array($_GET[$k]) ) |
---|
107 | { |
---|
108 | while( list($k2, $v2) = each($_GET[$k]) ) |
---|
109 | { |
---|
110 | $_GET[$k][$k2] = addslashes($v2); |
---|
111 | } |
---|
112 | @reset($_GET[$k]); |
---|
113 | } |
---|
114 | else |
---|
115 | { |
---|
116 | $_GET[$k] = addslashes($v); |
---|
117 | } |
---|
118 | } |
---|
119 | @reset($_GET); |
---|
120 | } |
---|
121 | |
---|
122 | if( is_array($_COOKIE) ) |
---|
123 | { |
---|
124 | while( list($k, $v) = each($_COOKIE) ) |
---|
125 | { |
---|
126 | if( is_array($_COOKIE[$k]) ) |
---|
127 | { |
---|
128 | while( list($k2, $v2) = each($_COOKIE[$k]) ) |
---|
129 | { |
---|
130 | $_COOKIE[$k][$k2] = addslashes($v2); |
---|
131 | } |
---|
132 | @reset($_COOKIE[$k]); |
---|
133 | } |
---|
134 | else |
---|
135 | { |
---|
136 | $_COOKIE[$k] = addslashes($v); |
---|
137 | } |
---|
138 | } |
---|
139 | @reset($_COOKIE); |
---|
140 | } |
---|
141 | } |
---|
142 | |
---|
143 | //----------------------------------------------------- variable initialization |
---|
144 | |
---|
145 | define('DEFAULT_PREFIX_TABLE', 'piwigo_'); |
---|
146 | |
---|
147 | // Obtain various vars |
---|
148 | $dbhost = (!empty($_POST['dbhost'])) ? $_POST['dbhost'] : 'localhost'; |
---|
149 | $dbuser = (!empty($_POST['dbuser'])) ? $_POST['dbuser'] : ''; |
---|
150 | $dbpasswd = (!empty($_POST['dbpasswd'])) ? $_POST['dbpasswd'] : ''; |
---|
151 | $dbname = (!empty($_POST['dbname'])) ? $_POST['dbname'] : ''; |
---|
152 | |
---|
153 | if (isset($_POST['install'])) |
---|
154 | { |
---|
155 | $table_prefix = $_POST['prefix']; |
---|
156 | } |
---|
157 | else |
---|
158 | { |
---|
159 | $table_prefix = DEFAULT_PREFIX_TABLE; |
---|
160 | } |
---|
161 | |
---|
162 | $admin_name = (!empty($_POST['admin_name'])) ? $_POST['admin_name'] : ''; |
---|
163 | $admin_pass1 = (!empty($_POST['admin_pass1'])) ? $_POST['admin_pass1'] : ''; |
---|
164 | $admin_pass2 = (!empty($_POST['admin_pass2'])) ? $_POST['admin_pass2'] : ''; |
---|
165 | $admin_mail = (!empty($_POST['admin_mail'])) ? $_POST['admin_mail'] : ''; |
---|
166 | |
---|
167 | $infos = array(); |
---|
168 | $errors = array(); |
---|
169 | |
---|
170 | // Open config.php ... if it exists |
---|
171 | $config_file = PHPWG_ROOT_PATH.'include/mysql.inc.php'; |
---|
172 | if (@file_exists($config_file)) |
---|
173 | { |
---|
174 | include($config_file); |
---|
175 | // Is Piwigo already installed ? |
---|
176 | if (defined("PHPWG_INSTALLED")) |
---|
177 | { |
---|
178 | die('Piwigo is already installed'); |
---|
179 | } |
---|
180 | } |
---|
181 | |
---|
182 | $prefixeTable = $table_prefix; |
---|
183 | include(PHPWG_ROOT_PATH . 'include/config_default.inc.php'); |
---|
184 | @include(PHPWG_ROOT_PATH. 'include/config_local.inc.php'); |
---|
185 | include(PHPWG_ROOT_PATH . 'include/constants.php'); |
---|
186 | include(PHPWG_ROOT_PATH . 'include/functions.inc.php'); |
---|
187 | include(PHPWG_ROOT_PATH . 'admin/include/functions.php'); |
---|
188 | include(PHPWG_ROOT_PATH . 'admin/include/functions_upgrade.php'); |
---|
189 | |
---|
190 | if (isset($_GET['language'])) |
---|
191 | { |
---|
192 | $language = strip_tags($_GET['language']); |
---|
193 | } |
---|
194 | else |
---|
195 | { |
---|
196 | $language = 'en_UK'; |
---|
197 | // Try to get browser language |
---|
198 | foreach (get_languages('utf-8') as $language_code => $language_name) |
---|
199 | { |
---|
200 | if (substr($language_code,0,2) == @substr($_SERVER["HTTP_ACCEPT_LANGUAGE"],0,2)) |
---|
201 | { |
---|
202 | $language = $language_code; |
---|
203 | break; |
---|
204 | } |
---|
205 | } |
---|
206 | } |
---|
207 | |
---|
208 | if ('fr_FR' == $language) { |
---|
209 | define('PHPWG_DOMAIN', 'fr.piwigo.org'); |
---|
210 | } |
---|
211 | else if ('it_IT' == $language) { |
---|
212 | define('PHPWG_DOMAIN', 'it.piwigo.org'); |
---|
213 | } |
---|
214 | else if ('de_DE' == $language) { |
---|
215 | define('PHPWG_DOMAIN', 'de.piwigo.org'); |
---|
216 | } |
---|
217 | else if ('es_ES' == $language) { |
---|
218 | define('PHPWG_DOMAIN', 'es.piwigo.org'); |
---|
219 | } |
---|
220 | else if ('pl_PL' == $language) { |
---|
221 | define('PHPWG_DOMAIN', 'pl.piwigo.org'); |
---|
222 | } |
---|
223 | else if ('zh_CN' == $language) { |
---|
224 | define('PHPWG_DOMAIN', 'cn.piwigo.org'); |
---|
225 | } |
---|
226 | else if ('hu_HU' == $language) { |
---|
227 | define('PHPWG_DOMAIN', 'hu.piwigo.org'); |
---|
228 | } |
---|
229 | else if ('ru_RU' == $language) { |
---|
230 | define('PHPWG_DOMAIN', 'ru.piwigo.org'); |
---|
231 | } |
---|
232 | else { |
---|
233 | define('PHPWG_DOMAIN', 'piwigo.org'); |
---|
234 | } |
---|
235 | define('PHPWG_URL', 'http://'.PHPWG_DOMAIN); |
---|
236 | |
---|
237 | load_language( 'common.lang', '', array('language'=>$language, 'target_charset'=>'utf-8') ); |
---|
238 | load_language( 'admin.lang', '', array('language'=>$language, 'target_charset'=>'utf-8') ); |
---|
239 | load_language( 'install.lang', '', array('language'=>$language, 'target_charset'=>'utf-8') ); |
---|
240 | header('Content-Type: text/html; charset=UTF-8'); |
---|
241 | //------------------------------------------------- check php version |
---|
242 | if (version_compare(PHP_VERSION, REQUIRED_PHP_VERSION, '<')) |
---|
243 | { |
---|
244 | include(PHPWG_ROOT_PATH.'install/php5_apache_configuration.php'); |
---|
245 | } |
---|
246 | |
---|
247 | //----------------------------------------------------- template initialization |
---|
248 | include( PHPWG_ROOT_PATH .'include/template.class.php'); |
---|
249 | $template=new Template(PHPWG_ROOT_PATH.'admin/template/goto', 'roma'); |
---|
250 | $template->set_filenames( array('install'=>'install.tpl') ); |
---|
251 | $step = 1; |
---|
252 | //---------------------------------------------------------------- form analyze |
---|
253 | if ( isset( $_POST['install'] )) |
---|
254 | { |
---|
255 | if ( @mysql_connect( $_POST['dbhost'], |
---|
256 | $_POST['dbuser'], |
---|
257 | $_POST['dbpasswd'] ) ) |
---|
258 | { |
---|
259 | if ( @mysql_select_db($_POST['dbname'] ) ) |
---|
260 | { |
---|
261 | array_push( $infos, l10n('step1_confirmation') ); |
---|
262 | } |
---|
263 | else |
---|
264 | { |
---|
265 | array_push( $errors, l10n('step1_err_db') ); |
---|
266 | } |
---|
267 | if ( version_compare(mysql_get_server_info(), '4.1.0', '>=') ) |
---|
268 | { |
---|
269 | $pwg_charset='utf-8'; |
---|
270 | $pwg_db_charset='utf8'; |
---|
271 | $install_charset_collate = "DEFAULT CHARACTER SET $pwg_db_charset"; |
---|
272 | } |
---|
273 | else |
---|
274 | { |
---|
275 | $pwg_charset='iso-8859-1'; |
---|
276 | $pwg_db_charset='latin1'; |
---|
277 | $install_charset_collate = ''; |
---|
278 | if ( !array_key_exists($language, get_languages($pwg_charset) ) ) |
---|
279 | { |
---|
280 | $language='en_UK'; |
---|
281 | } |
---|
282 | } |
---|
283 | } |
---|
284 | else |
---|
285 | { |
---|
286 | array_push( $errors, l10n('step1_err_server') ); |
---|
287 | } |
---|
288 | |
---|
289 | $webmaster = trim(preg_replace( '/\s{2,}/', ' ', $admin_name )); |
---|
290 | if ( empty($webmaster)) |
---|
291 | array_push( $errors, l10n('step2_err_login1') ); |
---|
292 | else if ( preg_match( '/[\'"]/', $webmaster ) ) |
---|
293 | array_push( $errors, l10n('step2_err_login3') ); |
---|
294 | if ( $admin_pass1 != $admin_pass2 || empty($admin_pass1) ) |
---|
295 | array_push( $errors, l10n('step2_err_pass') ); |
---|
296 | if ( empty($admin_mail)) |
---|
297 | array_push( $errors, l10n('reg_err_mail_address') ); |
---|
298 | else |
---|
299 | { |
---|
300 | $error_mail_address = validate_mail_address(null, $admin_mail); |
---|
301 | if (!empty($error_mail_address)) |
---|
302 | array_push( $errors, $error_mail_address ); |
---|
303 | } |
---|
304 | |
---|
305 | if ( count( $errors ) == 0 ) |
---|
306 | { |
---|
307 | $step = 2; |
---|
308 | $file_content = '<?php |
---|
309 | $cfgBase = \''.$dbname.'\'; |
---|
310 | $cfgUser = \''.$dbuser.'\'; |
---|
311 | $cfgPassword = \''.$dbpasswd.'\'; |
---|
312 | $cfgHote = \''.$dbhost.'\'; |
---|
313 | |
---|
314 | $prefixeTable = \''.$table_prefix.'\'; |
---|
315 | |
---|
316 | define(\'PHPWG_INSTALLED\', true); |
---|
317 | define(\'PWG_CHARSET\', \''.$pwg_charset.'\'); |
---|
318 | define(\'DB_CHARSET\', \''.$pwg_db_charset.'\'); |
---|
319 | define(\'DB_COLLATE\', \'\'); |
---|
320 | |
---|
321 | ?'.'>'; |
---|
322 | |
---|
323 | @umask(0111); |
---|
324 | // writing the configuration file |
---|
325 | if ( !($fp = @fopen( $config_file, 'w' ))) |
---|
326 | { |
---|
327 | $html_content = htmlentities( $file_content, ENT_QUOTES ); |
---|
328 | $html_content = nl2br( $html_content ); |
---|
329 | $error_copy = l10n('step1_err_copy'); |
---|
330 | $error_copy .= '<br />--------------------------------------------------------------------<br />'; |
---|
331 | $error_copy .= '<span class="sql_content">' . $html_content . '</span>'; |
---|
332 | $error_copy .= '<br />--------------------------------------------------------------------<br />'; |
---|
333 | } |
---|
334 | @fputs($fp, $file_content, strlen($file_content)); |
---|
335 | @fclose($fp); |
---|
336 | |
---|
337 | // Create empty local files to avoid log errors |
---|
338 | create_empty_local_files(); |
---|
339 | |
---|
340 | // tables creation, based on piwigo_structure.sql |
---|
341 | execute_sqlfile( |
---|
342 | PHPWG_ROOT_PATH.'install/piwigo_structure.sql', |
---|
343 | DEFAULT_PREFIX_TABLE, |
---|
344 | $table_prefix |
---|
345 | ); |
---|
346 | // We fill the tables with basic informations |
---|
347 | execute_sqlfile( |
---|
348 | PHPWG_ROOT_PATH.'install/config.sql', |
---|
349 | DEFAULT_PREFIX_TABLE, |
---|
350 | $table_prefix |
---|
351 | ); |
---|
352 | |
---|
353 | // fill $conf global array |
---|
354 | load_conf_from_db(); |
---|
355 | |
---|
356 | $insert = array( |
---|
357 | 'id' => 1, |
---|
358 | 'galleries_url' => PHPWG_ROOT_PATH.'galleries/', |
---|
359 | ); |
---|
360 | mass_inserts(SITES_TABLE, array_keys($insert), array($insert)); |
---|
361 | |
---|
362 | // webmaster admin user |
---|
363 | $inserts = array( |
---|
364 | array( |
---|
365 | 'id' => 1, |
---|
366 | 'username' => $admin_name, |
---|
367 | 'password' => md5($admin_pass1), |
---|
368 | 'mail_address' => $admin_mail, |
---|
369 | ), |
---|
370 | array( |
---|
371 | 'id' => 2, |
---|
372 | 'username' => 'guest', |
---|
373 | ), |
---|
374 | ); |
---|
375 | mass_inserts(USERS_TABLE, array_keys($inserts[0]), $inserts); |
---|
376 | |
---|
377 | create_user_infos(array(1,2), array('language' => $language)); |
---|
378 | |
---|
379 | // Available upgrades must be ignored after a fresh installation. To |
---|
380 | // make PWG avoid upgrading, we must tell it upgrades have already been |
---|
381 | // made. |
---|
382 | list($dbnow) = mysql_fetch_row(pwg_query('SELECT NOW();')); |
---|
383 | define('CURRENT_DATE', $dbnow); |
---|
384 | $datas = array(); |
---|
385 | foreach (get_available_upgrade_ids() as $upgrade_id) |
---|
386 | { |
---|
387 | array_push( |
---|
388 | $datas, |
---|
389 | array( |
---|
390 | 'id' => $upgrade_id, |
---|
391 | 'applied' => CURRENT_DATE, |
---|
392 | 'description' => 'upgrade included in installation', |
---|
393 | ) |
---|
394 | ); |
---|
395 | } |
---|
396 | mass_inserts( |
---|
397 | UPGRADE_TABLE, |
---|
398 | array_keys($datas[0]), |
---|
399 | $datas |
---|
400 | ); |
---|
401 | } |
---|
402 | } |
---|
403 | |
---|
404 | //------------------------------------------------------ start template output |
---|
405 | foreach (get_languages('utf-8') as $language_code => $language_name) |
---|
406 | { |
---|
407 | if ($language == $language_code) |
---|
408 | { |
---|
409 | $template->assign('language_selection', $language_code); |
---|
410 | } |
---|
411 | $languages_options[$language_code] = $language_name; |
---|
412 | } |
---|
413 | $template->assign('language_options', $languages_options); |
---|
414 | |
---|
415 | $template->assign( |
---|
416 | array( |
---|
417 | 'T_CONTENT_ENCODING' => 'utf-8', |
---|
418 | 'RELEASE'=>PHPWG_VERSION, |
---|
419 | 'F_ACTION' => 'install.php?language=' . $language, |
---|
420 | 'F_DB_HOST'=>$dbhost, |
---|
421 | 'F_DB_USER'=>$dbuser, |
---|
422 | 'F_DB_NAME'=>$dbname, |
---|
423 | 'F_DB_PREFIX' => $table_prefix, |
---|
424 | 'F_ADMIN'=>$admin_name, |
---|
425 | 'F_ADMIN_EMAIL'=>$admin_mail, |
---|
426 | 'L_INSTALL_HELP'=>sprintf(l10n('install_help'), PHPWG_URL.'/forum'), |
---|
427 | )); |
---|
428 | |
---|
429 | //------------------------------------------------------ errors & infos display |
---|
430 | if ($step == 1) |
---|
431 | { |
---|
432 | $template->assign('install', true); |
---|
433 | } |
---|
434 | else |
---|
435 | { |
---|
436 | array_push($infos, l10n('install_end_message')); |
---|
437 | |
---|
438 | if (isset($error_copy)) |
---|
439 | { |
---|
440 | array_push($errors, $error_copy); |
---|
441 | } |
---|
442 | else |
---|
443 | { |
---|
444 | session_set_save_handler('pwg_session_open', |
---|
445 | 'pwg_session_close', |
---|
446 | 'pwg_session_read', |
---|
447 | 'pwg_session_write', |
---|
448 | 'pwg_session_destroy', |
---|
449 | 'pwg_session_gc' |
---|
450 | ); |
---|
451 | if ( function_exists('ini_set') ) |
---|
452 | { |
---|
453 | ini_set('session.use_cookies', $conf['session_use_cookies']); |
---|
454 | ini_set('session.use_only_cookies', $conf['session_use_only_cookies']); |
---|
455 | ini_set('session.use_trans_sid', intval($conf['session_use_trans_sid'])); |
---|
456 | ini_set('session.cookie_httponly', 1); |
---|
457 | } |
---|
458 | session_name($conf['session_name']); |
---|
459 | session_set_cookie_params(0, cookie_path()); |
---|
460 | $user = build_user(1, true); |
---|
461 | log_user($user['id'], false); |
---|
462 | } |
---|
463 | |
---|
464 | $template->assign( |
---|
465 | 'SUBSCRIBE_BASE_URL', |
---|
466 | get_newsletter_subscribe_base_url($language) |
---|
467 | ); |
---|
468 | } |
---|
469 | if (count($errors) != 0) |
---|
470 | { |
---|
471 | $template->assign('errors', $errors); |
---|
472 | } |
---|
473 | |
---|
474 | if (count($infos) != 0 ) |
---|
475 | { |
---|
476 | $template->assign('infos', $infos); |
---|
477 | } |
---|
478 | |
---|
479 | //----------------------------------------------------------- html code display |
---|
480 | $template->pparse('install'); |
---|
481 | ?> |
---|