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