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