29 $db_root_user =& $_POST['db_root_user']; |
29 $db_root_user =& $_POST['db_root_user']; |
30 $db_root_pass =& $_POST['db_root_pass']; |
30 $db_root_pass =& $_POST['db_root_pass']; |
31 |
31 |
32 if ( !preg_match('/^[a-z0-9_]*$/', $db_prefix) ) |
32 if ( !preg_match('/^[a-z0-9_]*$/', $db_prefix) ) |
33 { |
33 { |
34 $ui->show_header(); |
34 $ui->show_header(); |
35 echo '<p>That table prefix isn\'t going to work.</p>'; |
35 echo '<p>That table prefix isn\'t going to work.</p>'; |
36 return true; |
36 return true; |
37 } |
37 } |
38 |
38 |
39 $result = $dbal->connect(true, $db_host, $db_user, $db_pass, $db_name, $db_port); |
39 $result = $dbal->connect(true, $db_host, $db_user, $db_pass, $db_name, $db_port); |
40 |
40 |
41 // If connection failed, we have the root login, AND we're on MySQL, try to force our way in |
41 // If connection failed, we have the root login, AND we're on MySQL, try to force our way in |
42 if ( !$result && !empty($_POST['db_root_user']) && !empty($_POST['db_root_pass']) && $driver == 'mysql' ) |
42 if ( !$result && !empty($_POST['db_root_user']) && !empty($_POST['db_root_pass']) && $driver == 'mysql' ) |
43 { |
43 { |
44 // Allow a jump / breakout |
44 // Allow a jump / breakout |
45 switch ( 'foo' ) { case 'foo': |
45 switch ( 'foo' ) { case 'foo': |
46 |
46 |
47 // Try to connect to the DB as root |
47 // Try to connect to the DB as root |
48 $result_root = $dbal->connect(true, $db_host, $db_root_user, $db_root_pass, 'mysql', $db_port); |
48 $result_root = $dbal->connect(true, $db_host, $db_root_user, $db_root_pass, 'mysql', $db_port); |
49 if ( !$result_root ) |
49 if ( !$result_root ) |
50 break; |
50 break; |
51 |
51 |
52 $q = $dbal->sql_query('CREATE DATABASE IF NOT EXISTS `' . $dbal->escape($db_name) . '`;'); |
52 $q = $dbal->sql_query('CREATE DATABASE IF NOT EXISTS `' . $dbal->escape($db_name) . '`;'); |
53 if ( !$q ) |
53 if ( !$q ) |
54 break; |
54 break; |
55 |
55 |
56 if ( $db_host == 'localhost' || $db_host == '127.0.0.1' ) |
56 if ( $db_host == 'localhost' || $db_host == '127.0.0.1' ) |
57 { |
57 { |
58 $q = $dbal->sql_query('GRANT ALL PRIVILEGES ON `' . $dbal->escape($db_name) . '`.* TO \'' . $dbal->escape($db_user) . '\'@\'localhost\'' . "\n" . |
58 $q = $dbal->sql_query('GRANT ALL PRIVILEGES ON `' . $dbal->escape($db_name) . '`.* TO \'' . $dbal->escape($db_user) . '\'@\'localhost\'' . "\n" . |
59 ' IDENTIFIED BY \'' . $dbal->escape($db_pass) . '\' WITH GRANT OPTION'); |
59 ' IDENTIFIED BY \'' . $dbal->escape($db_pass) . '\' WITH GRANT OPTION'); |
60 } |
60 } |
61 else |
61 else |
62 { |
62 { |
63 $q = $dbal->sql_query('GRANT ALL PRIVILEGES ON `' . $dbal->escape($db_name) . '`.* TO \'' . $dbal->escape($db_user) . '\'@\'%\'' . "\n" . |
63 $q = $dbal->sql_query('GRANT ALL PRIVILEGES ON `' . $dbal->escape($db_name) . '`.* TO \'' . $dbal->escape($db_user) . '\'@\'%\'' . "\n" . |
64 ' IDENTIFIED BY \'' . $dbal->escape($db_pass) . '\' WITH GRANT OPTION'); |
64 ' IDENTIFIED BY \'' . $dbal->escape($db_pass) . '\' WITH GRANT OPTION'); |
65 } |
65 } |
66 |
66 |
67 if ( !$q ) |
67 if ( !$q ) |
68 break; |
68 break; |
69 |
69 |
70 $dbal->close(); |
70 $dbal->close(); |
71 $result = $dbal->connect(true, $db_host, $db_user, $db_pass, $db_name, $db_port); |
71 $result = $dbal->connect(true, $db_host, $db_user, $db_pass, $db_name, $db_port); |
72 |
72 |
73 break; |
73 break; |
74 } |
74 } |
75 } |
75 } |
76 |
76 |
77 $ui->show_header(); |
77 $ui->show_header(); |
78 |
78 |
79 if ( $result ) |
79 if ( $result ) |
80 { |
80 { |
81 // We're good, do table drop if requested |
81 // We're good, do table drop if requested |
82 if ( isset($_POST['drop_tables']) ) |
82 if ( isset($_POST['drop_tables']) ) |
83 { |
83 { |
84 global $system_table_list; |
84 global $system_table_list; |
85 foreach ( $system_table_list as $table ) |
85 foreach ( $system_table_list as $table ) |
86 { |
86 { |
87 $dbal->sql_query("DROP TABLE {$db_prefix}$table"); |
87 $dbal->sql_query("DROP TABLE {$db_prefix}$table"); |
88 } |
88 } |
89 } |
89 } |
90 // Write out a config file |
90 // Write out a config file |
91 $ch = @fopen( ENANO_ROOT . '/config.new.php', 'w' ); |
91 $ch = @fopen( ENANO_ROOT . '/config.new.php', 'w' ); |
92 if ( !$ch ) |
92 if ( !$ch ) |
93 { |
93 { |
94 ?> |
94 ?> |
95 <form action="install.php?stage=database" method="post" name="database_info"> |
95 <form action="install.php?stage=database" method="post" name="database_info"> |
96 <h3>Configuration file generation failed.</h3> |
96 <h3>Configuration file generation failed.</h3> |
97 <p>Couldn't open the configuration file to write out database settings. Check your file permissions.</p> |
97 <p>Couldn't open the configuration file to write out database settings. Check your file permissions.</p> |
98 <p> |
98 <p> |
99 <input type="submit" name="_cont" value="<?php echo $lang->get('database_btn_go_back'); ?>" /> |
99 <input type="submit" name="_cont" value="<?php echo $lang->get('database_btn_go_back'); ?>" /> |
100 </p> |
100 </p> |
101 </form> |
101 </form> |
102 <?php |
102 <?php |
103 return true; |
103 return true; |
104 } |
104 } |
105 $db_host = str_replace("'", "\\'", $db_host); |
105 $db_host = str_replace("'", "\\'", $db_host); |
106 $db_user = str_replace("'", "\\'", $db_user); |
106 $db_user = str_replace("'", "\\'", $db_user); |
107 $db_pass = str_replace("'", "\\'", $db_pass); |
107 $db_pass = str_replace("'", "\\'", $db_pass); |
108 $db_name = str_replace("'", "\\'", $db_name); |
108 $db_name = str_replace("'", "\\'", $db_name); |
109 $db_prefix = str_replace("'", "\\'", $db_prefix); |
109 $db_prefix = str_replace("'", "\\'", $db_prefix); |
110 if ( !preg_match('/^[a-z0-9_]*$/', $db_prefix) ) |
110 if ( !preg_match('/^[a-z0-9_]*$/', $db_prefix) ) |
111 { |
111 { |
112 echo '<p>That table prefix isn\'t going to work.</p>'; |
112 echo '<p>That table prefix isn\'t going to work.</p>'; |
113 return true; |
113 return true; |
114 } |
114 } |
115 if ( !preg_match('/^[0-9]*$/', $db_port) ) |
115 if ( !preg_match('/^[0-9]*$/', $db_port) ) |
116 { |
116 { |
117 echo '<p>That port isn\'t going to work.</p>'; |
117 echo '<p>That port isn\'t going to work.</p>'; |
118 return true; |
118 return true; |
119 } |
119 } |
120 fwrite($ch, "<?php |
120 fwrite($ch, "<?php |
121 // Enano temporary configuration file, will be OVERWRITTEN after installation. |
121 // Enano temporary configuration file, will be OVERWRITTEN after installation. |
122 |
122 |
123 \$dbdriver = '$driver'; |
123 \$dbdriver = '$driver'; |
124 \$dbhost = '$db_host'; |
124 \$dbhost = '$db_host'; |
125 \$dbport = $db_port; |
125 \$dbport = $db_port; |
128 \$dbpasswd = '$db_pass'; |
128 \$dbpasswd = '$db_pass'; |
129 @define('table_prefix', '$db_prefix'); |
129 @define('table_prefix', '$db_prefix'); |
130 |
130 |
131 @define('ENANO_INSTALL_HAVE_CONFIG', 1); |
131 @define('ENANO_INSTALL_HAVE_CONFIG', 1); |
132 "); |
132 "); |
133 fclose($ch); |
133 fclose($ch); |
134 // Create the config table |
134 // Create the config table |
135 try |
135 try |
136 { |
136 { |
137 $sql_parser = new SQL_Parser( ENANO_ROOT . "/install/schemas/{$driver}_stage1.sql" ); |
137 $sql_parser = new SQL_Parser( ENANO_ROOT . "/install/schemas/{$driver}_stage1.sql" ); |
138 } |
138 } |
139 catch ( Exception $e ) |
139 catch ( Exception $e ) |
140 { |
140 { |
141 ?> |
141 ?> |
142 <h3>Can't load schema file</h3> |
142 <h3>Can't load schema file</h3> |
143 <p>The SQL schema file couldn't be loaded.</p> |
143 <p>The SQL schema file couldn't be loaded.</p> |
144 <?php echo "<pre>$e</pre>"; ?> |
144 <?php echo "<pre>$e</pre>"; ?> |
145 <?php |
145 <?php |
146 return true; |
146 return true; |
147 } |
147 } |
148 // Check to see if the config table already exists |
148 // Check to see if the config table already exists |
149 $q = $dbal->sql_query('SELECT config_name, config_value FROM ' . $db_prefix . 'config LIMIT 1;'); |
149 $q = $dbal->sql_query('SELECT config_name, config_value FROM ' . $db_prefix . 'config LIMIT 1;'); |
150 if ( !$q ) |
150 if ( !$q ) |
151 { |
151 { |
152 $sql_parser->assign_vars(array( |
152 $sql_parser->assign_vars(array( |
153 'TABLE_PREFIX' => $db_prefix |
153 'TABLE_PREFIX' => $db_prefix |
154 )); |
154 )); |
155 $sql = $sql_parser->parse(); |
155 $sql = $sql_parser->parse(); |
156 foreach ( $sql as $q ) |
156 foreach ( $sql as $q ) |
157 { |
157 { |
158 if ( !$dbal->sql_query($q) ) |
158 if ( !$dbal->sql_query($q) ) |
159 { |
159 { |
160 ?> |
160 ?> |
161 <form action="install.php?stage=database" method="post" name="database_info"> |
161 <form action="install.php?stage=database" method="post" name="database_info"> |
162 <input type="hidden" name="language" value="<?php echo $lang_id; ?>" /> |
162 <input type="hidden" name="language" value="<?php echo $lang_id; ?>" /> |
163 <input type="hidden" name="driver" value="<?php echo $driver; ?>" /> |
163 <input type="hidden" name="driver" value="<?php echo $driver; ?>" /> |
164 <h3><?php echo $lang->get('database_msg_sql_fail_title'); ?></h3> |
164 <h3><?php echo $lang->get('database_msg_sql_fail_title'); ?></h3> |
165 <p><?php echo $lang->get('database_msg_sql_fail_body'); ?></p> |
165 <p><?php echo $lang->get('database_msg_sql_fail_body'); ?></p> |
166 <p><?php echo $lang->get('database_msg_post_fail_desc'); ?> |
166 <p><?php echo $lang->get('database_msg_post_fail_desc'); ?> |
167 <?php |
167 <?php |
168 echo $dbal->sql_error(); |
168 echo $dbal->sql_error(); |
169 ?> |
169 ?> |
170 </p> |
170 </p> |
171 <p> |
171 <p> |
172 <input type="submit" name="_cont" value="<?php echo $lang->get('database_btn_go_back'); ?>" /> |
172 <input type="submit" name="_cont" value="<?php echo $lang->get('database_btn_go_back'); ?>" /> |
173 </p> |
173 </p> |
174 </form> |
174 </form> |
175 <?php |
175 <?php |
176 return true; |
176 return true; |
177 } |
177 } |
178 } |
178 } |
179 } |
179 } |
180 else |
180 else |
181 { |
181 { |
182 $dbal->free_result(); |
182 $dbal->free_result(); |
183 if ( !$dbal->sql_query('DELETE FROM ' . $db_prefix . 'config WHERE config_name = \'install_aes_key\';') ) |
183 if ( !$dbal->sql_query('DELETE FROM ' . $db_prefix . 'config WHERE config_name = \'install_aes_key\';') ) |
184 { |
184 { |
185 $dbal->_die('install database_post.php trying to remove old AES installer key'); |
185 $dbal->_die('install database_post.php trying to remove old AES installer key'); |
186 } |
186 } |
187 } |
187 } |
188 $dbal->close(); |
188 $dbal->close(); |
189 ?> |
189 ?> |
190 <form action="install.php?stage=website" method="post" name="install_db_post" onsubmit="return verify();"> |
190 <form action="install.php?stage=website" method="post" name="install_db_post" onsubmit="return verify();"> |
191 <input type="hidden" name="language" value="<?php echo $lang_id; ?>" /> |
191 <input type="hidden" name="language" value="<?php echo $lang_id; ?>" /> |
192 <?php |
192 <?php |
193 ?> |
193 ?> |
194 <h3><?php echo $lang->get('database_msg_success_title'); ?></h3> |
194 <h3><?php echo $lang->get('database_msg_success_title'); ?></h3> |
195 <p><?php echo $lang->get('database_msg_success_body'); ?></p> |
195 <p><?php echo $lang->get('database_msg_success_body'); ?></p> |
196 <p><input type="submit" name="_cont" value="<?php echo $lang->get('meta_btn_continue'); ?>" /> <?php echo $lang->get('database_msg_success_redirect'); ?></p> |
196 <p><input type="submit" name="_cont" value="<?php echo $lang->get('meta_btn_continue'); ?>" /> <?php echo $lang->get('database_msg_success_redirect'); ?></p> |
197 </form> |
197 </form> |
198 <script type="text/javascript"> |
198 <script type="text/javascript"> |
199 setTimeout(function() |
199 setTimeout(function() |
200 { |
200 { |
201 var frm = document.forms.install_db_post; |
201 var frm = document.forms.install_db_post; |
202 frm.submit(); |
202 frm.submit(); |
203 }, 200); |
203 }, 200); |
204 </script> |
204 </script> |
205 <?php |
205 <?php |
206 } |
206 } |
207 else |
207 else |
208 { |
208 { |
209 ?> |
209 ?> |
210 <form action="install.php?stage=database" method="post" name="database_info"> |
210 <form action="install.php?stage=database" method="post" name="database_info"> |
211 <input type="hidden" name="language" value="<?php echo $lang_id; ?>" /> |
211 <input type="hidden" name="language" value="<?php echo $lang_id; ?>" /> |
212 <input type="hidden" name="driver" value="<?php echo $driver; ?>" /> |
212 <input type="hidden" name="driver" value="<?php echo $driver; ?>" /> |
213 <h3><?php echo $lang->get('database_msg_post_fail_title'); ?></h3> |
213 <h3><?php echo $lang->get('database_msg_post_fail_title'); ?></h3> |
214 <p><?php echo $lang->get('database_msg_post_fail_body'); ?></p> |
214 <p><?php echo $lang->get('database_msg_post_fail_body'); ?></p> |
215 <p><?php echo $lang->get('database_msg_post_fail_desc'); ?> |
215 <p><?php echo $lang->get('database_msg_post_fail_desc'); ?> |
216 <?php |
216 <?php |
217 echo $dbal->sql_error(); |
217 echo $dbal->sql_error(); |
218 ?> |
218 ?> |
219 </p> |
219 </p> |
220 <p> |
220 <p> |
221 <input type="submit" name="_cont" value="<?php echo $lang->get('database_btn_go_back'); ?>" /> |
221 <input type="submit" name="_cont" value="<?php echo $lang->get('database_btn_go_back'); ?>" /> |
222 </p> |
222 </p> |
223 </form> |
223 </form> |
224 <?php |
224 <?php |
225 } |
225 } |
226 |
226 |