- Timestamp:
- Mar 5, 2004, 12:55:40 AM (21 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/install.php
r367 r382 66 66 } 67 67 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 68 89 set_magic_quotes_runtime(0); // Disable magic_quotes_runtime 69 90 // … … 183 204 if ( isset( $_POST['install'] )) 184 205 { 185 if ( @mysql_connect( $_POST['dbhost'], 186 $_POST['dbuser'], 187 $_POST['dbpasswd'] ) ) 188 { 189 if ( @mysql_select_db($_POST['dbname'] ) ) 190 { 191 array_push( $infos, $lang['step1_confirmation'] ); 192 } 193 else 194 { 195 array_push( $errors, $lang['step1_err_db'] ); 196 } 206 if ( @mysql_connect( $_POST['dbhost'], 207 $_POST['dbuser'], 208 $_POST['dbpasswd'] ) ) 209 { 210 if ( @mysql_select_db($_POST['dbname'] ) ) 211 { 212 array_push( $infos, $lang['step1_confirmation'] ); 197 213 } 198 214 else 199 215 { 200 array_push( $errors, $lang['step1_err_server'] ); 201 } 202 203 $webmaster = trim(preg_replace( '/\s{2,}/', ' ', $admin_name )); 204 if ( empty($webmaster)) 205 array_push( $errors, $lang['step2_err_login1'] ); 206 else if ( preg_match( '/[\'"]/', $webmaster ) ) 207 array_push( $errors, $lang['step2_err_login3'] ); 208 if ( $admin_pass1 != $admin_pass2 || empty($admin_pass1) ) 209 array_push( $errors, $lang['step2_err_pass'] ); 210 if ( empty($admin_mail)) 211 array_push( $errors, $lang['reg_err_mail_address'] ); 212 else 213 { 214 $error_mail_address = validate_mail_address($admin_mail); 215 if (!empty($error_mail_address)) array_push( $errors, $error_mail_address ); 216 } 217 218 if ( count( $errors ) == 0 ) 219 { 220 $step = 2; 221 $file_content = "<?php"; 222 $file_content.= "\n\$dbname = '". $dbname."';"; 223 $file_content.= "\n\$dbuser = '". $dbuser."';"; 224 $file_content.= "\n\$dbpasswd = '". $dbpasswd."';"; 225 $file_content.= "\n\$dbhost = '". $dbhost."';"; 226 $file_content.= "\n"; 227 $file_content.= "\n\$table_prefix = '".$table_prefix."';"; 228 $file_content.= "\n"; 229 $file_content.= "\ndefine('PHPWG_INSTALLED', true);"; 230 $file_content.= "\n?".">"; 231 232 @umask(0111); 233 // writing the configuration file 234 if ( !($fp = @fopen( $config_file, 'w' ))) 235 { 236 $html_content = htmlentities( $file_content, ENT_QUOTES ); 237 $html_content = nl2br( $html_content ); 238 $template->assign_block_vars('error_copy',array('FILE_CONTENT'=>$html_content)); 239 } 240 @fputs($fp, $file_content, strlen($file_content)); 241 @fclose($fp); 242 243 // tables creation, based on phpwebgallery_structure.sql 244 $sql_lines = file( './admin/phpwebgallery_structure.sql' ); 245 $query = ''; 246 foreach ( $sql_lines as $sql_line ) 247 { 248 $sql_line = trim( $sql_line ); 249 if ( preg_match( '/(^--|^$)/', $sql_line ) ) continue; 250 $query.= ' '.$sql_line; 251 // if we reached the end of query, we execute it and reinitialize the 252 // variable "query" 253 if ( preg_match( '/;$/', $sql_line ) ) 254 { 255 $query = trim( $query ); 256 $query = str_replace( 'phpwebgallery_', $table_prefix, $query ); 257 // we don't execute "DROP TABLE" queries 258 if ( !preg_match( '/^DROP TABLE/i', $query ) ) mysql_query( $query ); 259 $query = ''; 260 } 261 } 262 263 // We fill the tables with basic informations 264 $query = 'DELETE FROM '.CONFIG_TABLE; 265 mysql_query( $query ); 266 267 $query = 'INSERT INTO '.CONFIG_TABLE; 268 $query.= ' (webmaster,mail_webmaster) VALUES '; 269 $query.= " ('".$admin_name."','".$admin_mail."');"; 270 mysql_query( $query ); 271 272 $query = 'INSERT INTO '.SITES_TABLE; 273 $query.= " (id,galleries_url) VALUES (1, './galleries/');"; 274 mysql_query( $query ); 275 276 // webmaster admin user 277 $query = 'INSERT INTO '.USERS_TABLE; 278 $query.= ' (id,username,password,status,language,mail_address) VALUES '; 279 $query.= "(1,'".$admin_name."','".md5( $admin_pass1 )."'"; 280 $query.= ",'admin','".$language."'"; 281 $query.= ",'".$admin_mail."');"; 282 mysql_query($query); 283 284 // guest user 285 $query = 'INSERT INTO '.USERS_TABLE; 286 $query.= '(id,username,password,status,language) VALUES '; 287 $query.= "(2,'guest','','guest','".$language."')"; 288 $query.= ';'; 289 mysql_query( $query ); 290 } 216 array_push( $errors, $lang['step1_err_db'] ); 217 } 218 } 219 else 220 { 221 array_push( $errors, $lang['step1_err_server'] ); 222 } 223 224 $webmaster = trim(preg_replace( '/\s{2,}/', ' ', $admin_name )); 225 if ( empty($webmaster)) 226 array_push( $errors, $lang['step2_err_login1'] ); 227 else if ( preg_match( '/[\'"]/', $webmaster ) ) 228 array_push( $errors, $lang['step2_err_login3'] ); 229 if ( $admin_pass1 != $admin_pass2 || empty($admin_pass1) ) 230 array_push( $errors, $lang['step2_err_pass'] ); 231 if ( empty($admin_mail)) 232 array_push( $errors, $lang['reg_err_mail_address'] ); 233 else 234 { 235 $error_mail_address = validate_mail_address($admin_mail); 236 if (!empty($error_mail_address)) 237 array_push( $errors, $error_mail_address ); 238 } 239 240 if ( count( $errors ) == 0 ) 241 { 242 $step = 2; 243 $file_content = "<?php"; 244 $file_content.= "\n\$dbname = '". $dbname."';"; 245 $file_content.= "\n\$dbuser = '". $dbuser."';"; 246 $file_content.= "\n\$dbpasswd = '". $dbpasswd."';"; 247 $file_content.= "\n\$dbhost = '". $dbhost."';"; 248 $file_content.= "\n"; 249 $file_content.= "\n\$table_prefix = '".$table_prefix."';"; 250 $file_content.= "\n"; 251 $file_content.= "\ndefine('PHPWG_INSTALLED', true);"; 252 $file_content.= "\n?".">"; 253 254 @umask(0111); 255 // writing the configuration file 256 if ( !($fp = @fopen( $config_file, 'w' ))) 257 { 258 $html_content = htmlentities( $file_content, ENT_QUOTES ); 259 $html_content = nl2br( $html_content ); 260 $template->assign_block_vars('error_copy', 261 array('FILE_CONTENT'=>$html_content)); 262 } 263 @fputs($fp, $file_content, strlen($file_content)); 264 @fclose($fp); 265 266 // tables creation, based on phpwebgallery_structure.sql 267 execute_sqlfile( './install/phpwebgallery_structure.sql' 268 , 'phpwebgallery_' 269 , $table_prefix ); 270 // We fill the tables with basic informations 271 execute_sqlfile( './install/config.sql' 272 , 'phpwebgallery_' 273 , $table_prefix ); 274 275 $query = 'UPDATE '.CONFIG_TABLE; 276 $query.= " SET value = '".$admin_name."'"; 277 $query.= " WHERE param = 'webmaster'"; 278 $query.= ';'; 279 mysql_query( $query ); 280 281 $query = 'UPDATE '.CONFIG_TABLE; 282 $query.= " SET value = '".$admin_mail."'"; 283 $query.= " WHERE param = 'mail_webmaster'"; 284 $query.= ';'; 285 mysql_query( $query ); 286 287 $query = 'INSERT INTO '.SITES_TABLE; 288 $query.= " (id,galleries_url) VALUES (1, './galleries/');"; 289 mysql_query( $query ); 290 291 // webmaster admin user 292 $query = 'INSERT INTO '.USERS_TABLE; 293 $query.= ' (id,username,password,status,language,mail_address) VALUES '; 294 $query.= "(1,'".$admin_name."','".md5( $admin_pass1 )."'"; 295 $query.= ",'admin','".$language."'"; 296 $query.= ",'".$admin_mail."');"; 297 mysql_query($query); 298 299 // guest user 300 $query = 'INSERT INTO '.USERS_TABLE; 301 $query.= '(id,username,password,status,language) VALUES '; 302 $query.= "(2,'guest','','guest','".$language."')"; 303 $query.= ';'; 304 mysql_query( $query ); 305 } 291 306 } 292 307
Note: See TracChangeset
for help on using the changeset viewer.