[2] | 1 | <?php |
---|
| 2 | /*************************************************************************** |
---|
[57] | 3 | * install.php * |
---|
[2] | 4 | * ------------------- * |
---|
[57] | 5 | * application : PhpWebGallery 1.3 <http://phpwebgallery.net> * |
---|
| 6 | * author : Pierrick LE GALL <pierrick@z0rglub.com> * |
---|
[2] | 7 | * * |
---|
[57] | 8 | * $Id: install.php 317 2004-01-24 22:55:02Z z0rglub $ |
---|
| 9 | * * |
---|
[2] | 10 | ***************************************************************************/ |
---|
| 11 | |
---|
| 12 | /*************************************************************************** |
---|
| 13 | * * |
---|
| 14 | * This program is free software; you can redistribute it and/or modify * |
---|
| 15 | * it under the terms of the GNU General Public License as published by * |
---|
| 16 | * the Free Software Foundation; * |
---|
| 17 | * * |
---|
| 18 | ***************************************************************************/ |
---|
[91] | 19 | |
---|
| 20 | //-------------------------------------------------------------------- includes |
---|
[274] | 21 | define( 'PREFIX_INCLUDE', '.' ); |
---|
[91] | 22 | include( '../include/vtemplate.class.php' ); |
---|
| 23 | include( '../include/functions.inc.php' ); |
---|
| 24 | //----------------------------------------------------- template initialization |
---|
| 25 | $vtp = new VTemplate; |
---|
| 26 | $handle = $vtp->Open( '../template/default/admin/install.vtp' ); |
---|
| 27 | $vtp->setGlobalVar( $handle, 'release', '1.3' ); |
---|
| 28 | //-------------------------------------------------------------------- language |
---|
| 29 | if ( isset( $_GET['language'] ) ) |
---|
[10] | 30 | { |
---|
| 31 | $isadmin = true; |
---|
| 32 | $lang = array(); |
---|
[91] | 33 | include( '../language/'.$_GET['language'].'.php' ); |
---|
| 34 | $tpl = array( 'step1_err_copy', 'step1_err_copy_2', 'step1_err_copy_next', |
---|
| 35 | 'errors_title', 'step1_title','step1_host','step1_host_info', |
---|
| 36 | 'step1_user','step1_user_info','step1_pass','step1_pass_info', |
---|
| 37 | 'step1_database','step1_database_info','step1_prefix', |
---|
[94] | 38 | 'step1_prefix_info','submit','infos_title','step2_title', |
---|
| 39 | 'conf_general_webmaster','conf_general_webmaster_info', |
---|
| 40 | 'step2_pwd','step2_pwd_info','step2_pwd_conf', |
---|
| 41 | 'step2_pwd_conf_info','conf_general_mail', |
---|
| 42 | 'conf_general_mail_info','install_end_title', |
---|
[199] | 43 | 'install_end_message','install_help'); |
---|
[91] | 44 | templatize_array( $tpl, 'lang', $handle ); |
---|
| 45 | $vtp->setGlobalVar( $handle, 'language', $_GET['language'] ); |
---|
[10] | 46 | } |
---|
[91] | 47 | //---------------------- Step 1 : connection informations, write of config file |
---|
[274] | 48 | if ( isset($_GET['step']) && $_GET['step'] == 1 ) |
---|
[10] | 49 | { |
---|
[91] | 50 | $errors = array(); |
---|
| 51 | $infos = array(); |
---|
| 52 | // creation of ./include/mysql.inc.php : file containing database |
---|
| 53 | // connection informations |
---|
| 54 | if ( isset( $_POST['cfgBase'] ) |
---|
| 55 | and isset( $_POST['cfgUser'] ) |
---|
| 56 | and isset( $_POST['cfgPassword'] ) |
---|
| 57 | and isset( $_POST['cfgHote'] ) ) |
---|
[10] | 58 | { |
---|
[91] | 59 | if ( @mysql_connect( $_POST['cfgHote'], |
---|
| 60 | $_POST['cfgUser'], |
---|
| 61 | $_POST['cfgPassword'] ) ) |
---|
[10] | 62 | { |
---|
[91] | 63 | if ( @mysql_select_db($_POST['cfgBase'] ) ) |
---|
[10] | 64 | { |
---|
[91] | 65 | array_push( $infos, $lang['step1_confirmation'] ); |
---|
[10] | 66 | } |
---|
| 67 | else |
---|
| 68 | { |
---|
[91] | 69 | array_push( $errors, $lang['step1_err_db'] ); |
---|
[10] | 70 | } |
---|
| 71 | } |
---|
| 72 | else |
---|
| 73 | { |
---|
[91] | 74 | array_push( $errors, $lang['step1_err_server'] ); |
---|
[10] | 75 | } |
---|
[317] | 76 | |
---|
| 77 | $config_file = '../include/mysql.inc.php'; |
---|
| 78 | |
---|
[91] | 79 | if ( count( $errors ) == 0 ) |
---|
| 80 | { |
---|
| 81 | $file_content = "<?php"; |
---|
| 82 | $file_content.= "\n\$cfgBase = '". $_POST['cfgBase']."';"; |
---|
| 83 | $file_content.= "\n\$cfgUser = '". $_POST['cfgUser']."';"; |
---|
| 84 | $file_content.= "\n\$cfgPassword = '". $_POST['cfgPassword']."';"; |
---|
| 85 | $file_content.= "\n\$cfgHote = '". $_POST['cfgHote']."';"; |
---|
[156] | 86 | $file_content.= "\n\$prefixeTable = '".$_POST['prefixeTable']."';"; |
---|
[91] | 87 | $file_content.= "\n?>"; |
---|
[94] | 88 | // writting the configuration file |
---|
[317] | 89 | if ( $fp = @fopen( $config_file, 'a+' ) ) |
---|
[10] | 90 | { |
---|
[91] | 91 | fwrite( $fp, $file_content ); |
---|
[10] | 92 | fclose( $fp ); |
---|
| 93 | } |
---|
[91] | 94 | $cfgHote = ''; |
---|
| 95 | $cfgUser = ''; |
---|
| 96 | $cfgPassword = ''; |
---|
| 97 | $cfgBase = ''; |
---|
[317] | 98 | if ( is_file( $config_file ) ) include( $config_file ); |
---|
[91] | 99 | $file_OK = false; |
---|
[10] | 100 | if ( @mysql_connect( $cfgHote, $cfgUser, $cfgPassword ) ) |
---|
| 101 | { |
---|
[91] | 102 | if ( @mysql_select_db( $cfgBase ) ) $file_OK = true; |
---|
[10] | 103 | } |
---|
[91] | 104 | if ( !$file_OK ) |
---|
[10] | 105 | { |
---|
[91] | 106 | $vtp->addSession( $handle, 'error_copy' ); |
---|
| 107 | $html_content = htmlentities( $file_content, ENT_QUOTES ); |
---|
| 108 | $html_content = nl2br( $html_content ); |
---|
| 109 | $vtp->setVar( $handle, 'error_copy.file_content', $html_content ); |
---|
| 110 | $vtp->closeSession( $handle, 'error_copy' ); |
---|
[10] | 111 | } |
---|
| 112 | else |
---|
| 113 | { |
---|
[91] | 114 | $url = 'install.php?step=2&language='.$_GET['language']; |
---|
| 115 | header( 'Request-URI: '.$url ); |
---|
| 116 | header( 'Content-Location: '.$url); |
---|
| 117 | header( 'Location: '.$url ); |
---|
[10] | 118 | exit(); |
---|
| 119 | } |
---|
| 120 | } |
---|
| 121 | } |
---|
[91] | 122 | // errors display |
---|
| 123 | if ( sizeof( $errors ) != 0 ) |
---|
[10] | 124 | { |
---|
[91] | 125 | $vtp->addSession( $handle, 'errors' ); |
---|
| 126 | foreach ( $errors as $error ) { |
---|
| 127 | $vtp->addSession( $handle, 'error' ); |
---|
| 128 | $vtp->setVar( $handle, 'error.content', $error ); |
---|
| 129 | $vtp->closeSession( $handle, 'error' ); |
---|
| 130 | } |
---|
| 131 | $vtp->closeSession( $handle, 'errors' ); |
---|
[10] | 132 | } |
---|
[91] | 133 | // infos display |
---|
| 134 | if ( sizeof( $infos ) != 0 ) |
---|
[10] | 135 | { |
---|
[91] | 136 | $vtp->addSession( $handle, 'infos' ); |
---|
| 137 | foreach ( $infos as $info ) { |
---|
| 138 | $vtp->addSession( $handle, 'info' ); |
---|
| 139 | $vtp->setVar( $handle, 'info.content', $info ); |
---|
| 140 | $vtp->closeSession( $handle, 'info' ); |
---|
| 141 | } |
---|
| 142 | $vtp->closeSession( $handle, 'infos' ); |
---|
| 143 | } |
---|
| 144 | // form display (if necessary) |
---|
| 145 | if ( !isset( $_POST['submit'] ) or sizeof( $errors ) > 0 ) |
---|
| 146 | { |
---|
| 147 | $vtp->addSession( $handle, 'step1' ); |
---|
[94] | 148 | |
---|
[91] | 149 | // host |
---|
| 150 | if ( !isset( $_POST['cfgHote'] ) ) |
---|
| 151 | $vtp->setVar( $handle, 'step1.f_host', 'localhost' ); |
---|
[10] | 152 | else |
---|
[91] | 153 | $vtp->setVar( $handle, 'step1.f_host', $_POST['cfgHote'] ); |
---|
| 154 | // user |
---|
[274] | 155 | if ( isset( $_POST['cfgUser'] ) ) |
---|
| 156 | $vtp->setVar( $handle, 'step1.f_user', $_POST['cfgUser'] ); |
---|
[91] | 157 | // base |
---|
[274] | 158 | if ( isset( $_POST['cfgBase'] ) ) |
---|
| 159 | $vtp->setVar( $handle, 'step1.f_base', $_POST['cfgBase'] ); |
---|
[156] | 160 | // prefixeTable |
---|
| 161 | if ( !isset( $_POST['prefixeTable'] ) ) |
---|
| 162 | $vtp->setVar( $handle, 'step1.f_prefixeTable', 'phpwebgallery_' ); |
---|
[10] | 163 | else |
---|
[156] | 164 | $vtp->setVar( $handle, 'step1.f_prefixeTable', $_POST['prefixeTable'] ); |
---|
[94] | 165 | |
---|
[91] | 166 | $vtp->closeSession( $handle, 'step1' ); |
---|
[10] | 167 | } |
---|
| 168 | } |
---|
[91] | 169 | //------------------------------------- Step 2 : creation of tables in database |
---|
[274] | 170 | else if ( isset($_GET['step']) && $_GET['step'] == 2 ) |
---|
[10] | 171 | { |
---|
[94] | 172 | $errors = array(); |
---|
| 173 | $infos = array(); |
---|
| 174 | |
---|
[91] | 175 | include( '../include/mysql.inc.php' ); |
---|
| 176 | mysql_connect( $cfgHote, $cfgUser, $cfgPassword ) |
---|
| 177 | or die ( "Can't connect to database host" ); |
---|
| 178 | mysql_select_db( $cfgBase ) |
---|
| 179 | or die ( "Connection to host succeeded, but database selection failed" ); |
---|
[2] | 180 | |
---|
[91] | 181 | if ( !isset( $_POST['submit'] ) ) |
---|
[10] | 182 | { |
---|
[91] | 183 | // tables creation, based on phpwebgallery_structure.sql |
---|
[94] | 184 | $sql_lines = file( './phpwebgallery_structure.sql' ); |
---|
| 185 | $query = ''; |
---|
| 186 | foreach ( $sql_lines as $sql_line ) { |
---|
| 187 | $sql_line = trim( $sql_line ); |
---|
| 188 | if ( preg_match( '/(^--|^$)/', $sql_line ) ) continue; |
---|
| 189 | $query.= ' '.$sql_line; |
---|
| 190 | // if we reached the end of query, we execute it and reinitialize the |
---|
| 191 | // variable "query" |
---|
| 192 | if ( preg_match( '/;$/', $sql_line ) ) |
---|
| 193 | { |
---|
| 194 | $query = trim( $query ); |
---|
[156] | 195 | $query = str_replace( 'phpwebgallery_', $prefixeTable, $query ); |
---|
[94] | 196 | // we don't execute "DROP TABLE" queries |
---|
| 197 | if ( !preg_match( '/^DROP TABLE/i', $query ) ) |
---|
| 198 | mysql_query( $query ); |
---|
| 199 | $query = ''; |
---|
| 200 | } |
---|
| 201 | } |
---|
[10] | 202 | } |
---|
[91] | 203 | |
---|
| 204 | if ( isset( $_POST['submit'] ) ) |
---|
[10] | 205 | { |
---|
[94] | 206 | // webmaster login must be |
---|
| 207 | // 1. non empty |
---|
| 208 | // 2. without characters ' or " |
---|
| 209 | $webmaster = preg_replace( '/\s{2,}/', ' ', $_POST['webmaster'] ); |
---|
| 210 | $webmaster = trim( $webmaster ); |
---|
| 211 | if ( $webmaster == '' ) |
---|
| 212 | array_push( $errors, $lang['step2_err_login1'] ); |
---|
| 213 | if ( preg_match( '/[\'"]/', $webmaster ) ) |
---|
| 214 | array_push( $errors, $lang['step2_err_login3'] ); |
---|
| 215 | // the webmaster string must be the same as its confirmation |
---|
[91] | 216 | if ( $_POST['pwdWebmaster'] != $_POST['pwdWebmasterConf'] ) |
---|
[94] | 217 | array_push( $errors, $lang['step2_err_pass'] ); |
---|
| 218 | // mail address must have this format : name@server.com |
---|
| 219 | $error_mail_address = validate_mail_address( $_POST['mail_webmaster'] ); |
---|
| 220 | if ( $error_mail_address != '' ) |
---|
| 221 | array_push( $errors, $error_mail_address ); |
---|
| 222 | if ( $_POST['mail_webmaster'] == '' ) |
---|
| 223 | array_push( $errors, $lang['reg_err_mail_address'] ); |
---|
| 224 | |
---|
| 225 | // if no error found till here : insertion of data in tables |
---|
| 226 | if ( count( $errors ) == 0 ) |
---|
[10] | 227 | { |
---|
[156] | 228 | $query = 'DELETE FROM '.$prefixeTable.'config'; |
---|
[94] | 229 | mysql_query( $query ); |
---|
| 230 | |
---|
[156] | 231 | $query = 'INSERT INTO '.$prefixeTable.'config'; |
---|
[94] | 232 | $query.= ' (webmaster,mail_webmaster) VALUES '; |
---|
| 233 | $query.= " ('".$webmaster."','".$_POST['mail_webmaster']."')"; |
---|
| 234 | $query.= ';'; |
---|
| 235 | mysql_query( $query ); |
---|
| 236 | |
---|
[156] | 237 | $query = 'INSERT INTO '.$prefixeTable.'sites'; |
---|
[94] | 238 | $query.= " (id,galleries_url) VALUES (1, './galleries/')"; |
---|
| 239 | $query.= ';'; |
---|
| 240 | mysql_query( $query ); |
---|
| 241 | |
---|
| 242 | // webmaster admin user |
---|
[156] | 243 | $query = 'INSERT INTO '.$prefixeTable.'users'; |
---|
[317] | 244 | $query.= ' (id,username,password,status,language,mail_address) VALUES '; |
---|
[94] | 245 | $query.= "(1,'".$webmaster."','".md5( $_POST['pwdWebmaster'] )."'"; |
---|
[317] | 246 | $query.= ",'admin','".$_GET['language']."'"; |
---|
| 247 | $query.= ",'".$_POST['mail_webmaster']."')"; |
---|
[94] | 248 | $query.= ';'; |
---|
[10] | 249 | mysql_query($query); |
---|
[94] | 250 | |
---|
| 251 | // guest user |
---|
[156] | 252 | $query = 'INSERT INTO '.$prefixeTable.'users'; |
---|
[94] | 253 | $query.= '(id,username,password,status,language) VALUES '; |
---|
[205] | 254 | $query.= "(2,'guest','','guest','".$_GET['language']."')"; |
---|
[94] | 255 | $query.= ';'; |
---|
| 256 | mysql_query( $query ); |
---|
[10] | 257 | } |
---|
| 258 | } |
---|
[94] | 259 | |
---|
| 260 | // errors display |
---|
| 261 | if ( sizeof( $errors ) != 0 ) |
---|
[10] | 262 | { |
---|
[94] | 263 | $vtp->addSession( $handle, 'errors' ); |
---|
| 264 | foreach ( $errors as $error ) { |
---|
| 265 | $vtp->addSession( $handle, 'error' ); |
---|
| 266 | $vtp->setVar( $handle, 'error.content', $error ); |
---|
| 267 | $vtp->closeSession( $handle, 'error' ); |
---|
| 268 | } |
---|
| 269 | $vtp->closeSession( $handle, 'errors' ); |
---|
[10] | 270 | } |
---|
[94] | 271 | |
---|
| 272 | if ( !isset( $_POST['submit'] ) or sizeof( $errors ) > 0 ) |
---|
[10] | 273 | { |
---|
[94] | 274 | $vtp->addSession( $handle, 'step2' ); |
---|
[274] | 275 | if ( isset( $_POST['webmaster'] )) |
---|
[94] | 276 | $vtp->setVar( $handle, 'step2.f_webmaster', $_POST['webmaster'] ); |
---|
[274] | 277 | if ( isset( $_POST['mail_webmaster'] )) |
---|
[94] | 278 | $vtp->setVar( $handle, 'step2.f_mail_webmaster', $_POST['mail_webmaster']); |
---|
| 279 | $vtp->closeSession( $handle, 'step2' ); |
---|
[10] | 280 | } |
---|
[94] | 281 | |
---|
| 282 | // end of installation message |
---|
| 283 | if ( isset( $_POST['submit'] ) and count( $errors ) == 0 ) |
---|
| 284 | { |
---|
| 285 | $vtp->addSession( $handle, 'install_end' ); |
---|
| 286 | $vtp->closeSession( $handle, 'install_end' ); |
---|
| 287 | } |
---|
[10] | 288 | } |
---|
[91] | 289 | //---------------------------------------------------- Step 0 : language choice |
---|
[10] | 290 | else |
---|
| 291 | { |
---|
[91] | 292 | $vtp->addSession( $handle, 'step0' ); |
---|
| 293 | $languages = get_languages( '../language/' ); |
---|
| 294 | foreach ( $languages as $language ) { |
---|
| 295 | $vtp->addSession( $handle, 'language' ); |
---|
| 296 | $vtp->setVar( $handle, 'language.name', $language ); |
---|
| 297 | $vtp->closeSession( $handle, 'language' ); |
---|
[10] | 298 | } |
---|
[91] | 299 | $vtp->closeSession( $handle, 'step0' ); |
---|
[10] | 300 | } |
---|
[91] | 301 | //----------------------------------------------------------- html code display |
---|
| 302 | $code = $vtp->Display( $handle, 0 ); |
---|
| 303 | echo $code; |
---|
[2] | 304 | ?> |
---|