Codechange: nutze die Tabelle *forum_banned_ips und gebe statistische Daten aus
[wmmkf.git] / update.php
blob95e2c5974dd3bd5bb8dcd8f2b6acf87392c68a9a
1 <?php
3 include_once('functions/include.install.php');
4 #include_once('functions.php');
5 include_once("db_settings.php");
6 include_once("lang/english.php");
7 include_once("lang/english_add.php");
9 # initialisation
10 ini_set('arg_separator.output', '&amp;');
11 header('Content-Type: text/html; charset=UTF-8');
12 if (!extension_loaded('mbstring')) include_once('/functions/funcs.mb_replacements.php');
13 mb_internal_encoding('UTF-8');
15 # for details see: http://de.php.net/manual/en/security.magicquotes.disabling.php
16 if (get_magic_quotes_gpc())
18 $_POST = array_map('stripslashes_deep', $_POST);
19 $_GET = array_map('stripslashes_deep', $_GET);
20 $_COOKIE = array_map('stripslashes_deep', $_COOKIE);
21 $_REQUEST = array_map('stripslashes_deep', $_REQUEST);
25 # number of the new version
26 $newVersion = "1.8";
27 # empty error array
28 $errors = array();
29 # status of the script
30 # 0: initialization status, start of the update procedure
31 # 1: no connect to the database or no data of an existing forum-DB found
32 # 2: update complete
33 $scriptStatus = 0;
34 $statusOutput[1] = "<p>".$lang_add['db_read_settings_error']."</p>
35 <p>The forum seems not to be installed. Please control the existence and name of the settings table or switch to <a href=\"install.php\">Installation</a>.</p>";
36 $statusOutput[2] = "<p>Database tables have been altered, new tables are created.</p>";
37 $statusOutput[3] = "<p>The given data from the form seems to be wrong.</p>";
38 $statusOutput[4] = "<p>An error occured</p>\n";
40 # initialization of the output
41 $output = "";
43 # connect the database (return: [status] resource number or false; [errnbr] error number)
44 $sql = auge_connect_db($db_settings);
46 if ($sql["status"] === false)
48 # no contact to the database server
49 # generate error message
50 $errors[] = "MySQL error: ".$sql["errnbr"]."<br />".$lang_add['db_'.$sql["errnbr"]];
51 # status: no connection to database
52 $scriptStatus = 1;
53 $output .= "<p>The script can not contact the database server. The username, password or database name seems to be wrong.</p>";
55 else
57 # List all versions wich can be updated.
58 $updateVersions = array("1.7");
59 # the database is contacted
60 $connid = $sql["status"];
61 # read the current settings from the settings table
62 $oldSettingsQuery = "SELECT name, value FROM ".$db_settings['settings_table'];
63 $ancientSettings = auge_ask_database($oldSettingsQuery,$connid);
64 if (!is_array($ancientSettings['status']))
66 # status: found no data of an existing installation (empty result or error)
67 $output .= $statusOutput[1];
68 $scriptStatus = 1;
70 else
72 # bring the old settings into the needed format
73 foreach ($ancientSettings['status'] as $ancientSetting)
75 $oldSettings[$ancientSetting['name']] = $ancientSetting['value'];
77 # search version number of the old forum version:
78 if (empty($oldSettings['version']))
80 # the old setting for version string is not present
81 $errors[] = $lang_add['no_version_found'];
83 else
85 # found string for old version
86 $versionCompare = false;
87 # shorten version string to one digit after first point
88 $oldVersionShort = substr($oldSettings['version'],0,3);
89 if ($oldVersionShort == $newVersion)
91 # identic old and new version
92 $errors[] = $lang_add['version_already_installed'];
94 else if (!in_array($oldVersionShort,$updateVersions))
96 # old version is not supported by the update procedure
97 $errors[] = $lang_add['version_not_supported'];
99 else
101 $oldVersion = $oldSettings['version'];
103 } # End: search version number of old forum
104 # include files for the language wich is stored in the old settings
105 include("lang/".$oldSettings['language_file'] );
106 include("lang/".$lang['additional_language_file']);
107 # the form was submitted
108 if (isset($_POST['form_submitted'])) {
109 # $output .= '<pre>';
110 # $output .= print_r($_POST, true);
111 # $output .= '</pre>';
112 # all fields filled out?
113 foreach ($_POST as $postKey=>$postVal)
115 $postVal = trim($postVal);
116 if (empty($postVal)) { $errors[] = $lang['error_form_uncompl']; break; }
118 # try to connect the database with posted access data (deprecated):
119 if (empty($errors))
121 # Umstellung auf meine SQL-Funktionen
122 $tempDBConnData = array('host'=>$db_settings['host'],'user'=>$db_settings['user'],'pw'=>$db_settings['pw'],'db'=>$db_settings['db']);
123 $tempSQL = auge_connect_db($tempDBConnData);
124 if ($tempSQL['status'] === false)
126 # wrong given data
127 # generate error message
128 $errors[] = "MySQL error: ".$tempSQL["errnbr"]."\n".$lang_add['db_'.$tempSQL["errnbr"]];
129 # status: no connection to database
130 # because wrong given data from the form
131 $scriptStatus = 1;
133 else
135 $connid = $tempSQL['status'];
137 } # End: deprecated
139 # overwrite database settings file:
140 if (empty($errors) and empty($_POST['dont_overwrite_settings']))
142 clearstatcache();
143 $chmod = decoct(fileperms("db_settings.php"));
145 $db_settings['usersettings_table'] = $_POST['table_prefix'].'usersettings';
146 $db_settings['us_templates_table'] = $_POST['table_prefix'].'fu_settings';
147 # content of db_settings.php
148 $SetCont = "<?php\n";
149 $SetCont .= "\$db_settings['host'] = \"".$db_settings['host']."\";\n";
150 $SetCont .= "\$db_settings['user'] = \"".$db_settings['user']."\";\n";
151 $SetCont .= "\$db_settings['pw'] = \"".$db_settings['pw']."\";\n";
152 $SetCont .= "\$db_settings['db'] = \"".$db_settings['db']."\";\n";
153 $SetCont .= "\$db_settings['settings_table'] = \"".$db_settings['settings_table']."\";\n";
154 $SetCont .= "\$db_settings['forum_table'] = \"".$db_settings['forum_table']."\";\n";
155 $SetCont .= "\$db_settings['category_table'] = \"".$db_settings['category_table']."\";\n";
156 $SetCont .= "\$db_settings['userdata_table'] = \"".$db_settings['userdata_table']."\";\n";
157 $SetCont .= "\$db_settings['smilies_table'] = \"".$db_settings['smilies_table']."\";\n";
158 $SetCont .= "\$db_settings['banlists_table'] = \"".$db_settings['banlists_table']."\";\n";
159 $SetCont .= "\$db_settings['useronline_table'] = \"".$db_settings['useronline_table']."\";\n";
160 $SetCont .= "\$db_settings['usersettings_table'] = \"".$db_settings['usersettings_table']."\";\n";
161 $SetCont .= "\$db_settings['us_templates_table'] = \"".$db_settings['us_templates_table']."\";\n";
162 $SetCont .= "?>";
163 # Start: debug output
164 # $output .= '<pre>';
165 # $output .= htmlspecialchars(print_r($SetCont, true));
166 # $output .= '</pre>';
167 # End: debug output
169 $db_settings_file = @fopen("db_settings.php", "w") or $errors[] = str_replace("CHMOD",$chmod,$lang_add['no_writing_permission']);
170 flock($db_settings_file, 2);
171 fwrite($db_settings_file, $SetCont);
172 flock($db_settings_file, 3);
173 fclose($db_settings_file);
174 } # End: if (empty($errors) and empty($_POST['dont_overwrite_settings']))
175 # update procedure
176 if (empty($errors))
178 switch($oldVersionShort)
180 case 1.7:
181 $errors = update17to18($oldSettings, $connid);
182 if ($errors === false) {
183 $output .= '<p>errors ist <code>false</code>.</p>';
184 unset($errors);
186 else {
187 $output .= '<p>errors ist nicht <code>false</code>.</p>';
189 break;
190 default:
191 $errors[] = $lang_add['version_not_supported'];
192 break;
193 } # End: switch($oldVersion)
194 } # End: structure update procedure
195 # structure update was successful, set $scriptStatus to 2
196 if (empty($errors))
198 # the update was successful
199 # the database tables was updated, new settings are saved
200 $scriptStatus = 2;
201 $output .= $statusOutput[2];
203 else
205 # an error occured while the update process
206 $output .= $statusOutput[4];
207 if (!empty($errors) and is_array($errors))
209 $output .= errorMessages($errors);
212 } # End: if (isset($_POST['form_submitted']))
213 else
215 # the form was not submitted, standard output with the initial form
216 $passLength = strlen($db_settings['pw']);
217 $prefix = substr($db_settings['settings_table'], 0, -8);
218 $passWord = str_repeat("*", $passLength);
219 $output .= '<p>'.$lang_add['update_instructions'].'</p>'."\n";
220 $output .= '<h2>'.$lang_add['update_current_dbsettings'].'</h2>'."\n";
221 $output .= '<table class="admintab">'."\n";
222 $output .= ' <tr>'."\n";
223 $output .= ' <td class="definition">'.$lang_add['inst_db_host'].'<br />'."\n";
224 $output .= ' <span class="small">'.$lang_add['inst_db_host_d'].'</span></td>'."\n";
225 $output .= ' <td class="description">'.$db_settings['host'].'</td>'."\n";
226 $output .= ' </tr><tr>'."\n";
227 $output .= ' <td class="definition">'.$lang_add['inst_db_name'].'<br />'."\n";
228 $output .= ' <span class="small">'.$lang_add['inst_db_name_d'].'</span></td>'."\n";
229 $output .= ' <td class="description">'.$db_settings['db'].'</td>'."\n";
230 $output .= ' </tr><tr>'."\n";
231 $output .= ' <td class="definition">'.$lang_add['inst_db_user'].'<br />'."\n";
232 $output .= '<span class="small">'.$lang_add['inst_db_user_d'].'</span></td>'."\n";
233 $output .= ' <td class="description">'.$db_settings['user'].'</td>'."\n";
234 $output .= ' </tr><tr>'."\n";
235 $output .= ' <td class="definition">'.$lang_add['inst_db_pw'].'<br />'."\n";
236 $output .= ' <span class="small">'.$lang_add['inst_db_pw_d'].'</span></td>'."\n";
237 $output .= ' <td class="description">'.$passWord.'</td>'."\n";
238 $output .= ' </tr><tr>'."\n";
239 $output .= ' <td class="definition">'.$lang_add['inst_table_prefix'].'<br />'."\n";
240 $output .= ' <span class="small">'.$lang_add['inst_table_prefix_d'].'</span></td>'."\n";
241 $output .= ' <td class="description">'.$prefix.'</td>'."\n";
242 $output .= ' </tr>'."\n";
243 $output .= '</table>'."\n";
244 $output .= '<h2>'.$lang_add['update_current_dbtables'].'</h2>'."\n";
245 $output .= '<ol>'."\n";
246 foreach ($db_settings as $key => $val) {
247 $found = strpos($key, '_table');
248 if ($found !== false) {
249 $output .= ' <li>'.$val.'</li>'."\n";
252 $output .= '</ol>'."\n";
253 if ($oldVersionShort < $settings['version'])
255 $output .= '<h2>'.$lang_add['update_new_dbtables'].'</h2>'."\n";
256 if ($settings['version'] == "1.8")
258 $output .= '<p>'.$lang_add['update_news_message_1.8'].'</p>';
261 $output .= '<form action="update.php" method="post">'."\n";
262 $output .= '<table class="admintab">'."\n";
263 $output .= ' <tr>'."\n";
264 $output .= ' <td class="definition">'.$lang_add["delete_2char_smilies"].'<br />'."\n";
265 $output .= ' <span class="small">'.$lang_add['delete_2char_smilies_d'].'</td>'."\n";
266 $output .= ' <td class="description">'."\n";
267 $output .= ' <input type="radio" id="DeleteSmilies" name="DeleteSmilies" value="delete" checked="checked" /><label for="DeleteSmilies">'.$lang['yes'].'</label>'."\n";
268 $output .= ' <input type="radio" id="StoreSmilies" name="DeleteSmilies" value="store" /><label for="StoreSmilies">'.$lang['no'].'</label></td>'."\n";
269 $output .= ' </tr>'."\n";
270 $output .= '</table>'."\n";
271 # $output .= '<ul>';
272 # $output .= '<li><input type="checkbox" name="dont_overwrite_settings" value="true"';
273 # $output .= isset($_POST['dont_overwrite_settings']) ? ' checked="checked"' : '';
274 # $output .= '>'.$lang_add['dont_overwrite_settings'].'</li>';
275 # $output .= '</ul>';
276 $output .= '<p><input type="submit" name="form_submitted" value="'.$lang_add['forum_update_ok'].'" /></p>'."\n";
277 $output .= '<input type="hidden" name="language" value="'.$lang['language'].'" />'."\n";
278 $output .= '<input type="hidden" name="installation_mode" value="update" />'."\n";
279 $output .= '<input type="hidden" name="table_prefix" value="'.$prefix.'" />'."\n";
280 $output .= '</form>'."\n";
281 } # End: if (isset($_POST['form_submitted'])) (else)
282 } # End: if (!is_array($oldSettings)) (else)
283 } # End: if ($connid === false) (else)
285 ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
286 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php echo $lang['language']; ?>">
287 <head>
288 <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
289 <title><?php echo $settings['forum_name']." - ".$lang_add['install_title']; ?></title>
290 <style type="text/css">
292 body {
293 font-family: sans-serif;
294 color: #000000;
295 font-size: 100.01%;
296 background-color: #fff;
297 margin: 0;
298 padding: 0;
300 #content {
301 margin: 1em;
302 padding: 0;
304 h1 {
305 margin: 0 0 20px 0;
306 font-size: 1.4em;
307 font-weight: bold;
309 h2 {
310 margin: 0 0 20px 0;
311 font-size: 1.3em;
312 font-weight: bold;
314 table.admintab {
315 border: 1px solid #bacbdf;
316 border-collapse: collapse;
317 min-width:600px;
319 table.admintab td {
320 background-color: #f5f5f5;
321 width: 40%;
322 padding: 4px;
323 vertical-align: top;
324 border-right: 1px dotted #bacbdf;
325 border-bottom: 1px solid #bacbdf;
327 table.admintab td:nth-child(n+2):nth-child(n+2) {
328 background-color: #f8f8f8;
329 width: 60%;
330 border-right: none;
332 table.admintab td.definition {
333 font-weight: bold;
335 table.admintab td.definition .small {
336 font-weight: normal;
338 .caution { color: red; font-weight: bold; }
339 .small { font-size: 0.86em; line-height:150%; }
340 a:link { color: #0000cc; text-decoration: none; }
341 a:visited { color: #0000cc; text-decoration: none; }
342 a:focus, a:hover { color: #0000ff; text-decoration: underline; }
343 a:active { color: #ff0000; text-decoration: none; }
345 </style>
346 </head>
347 <body>
348 <div id="content">
349 <h1><?php echo $lang_add['installation_mode_update']; ?></h1>
350 <?php
351 #if (!empty($errors) and is_array($errors)) {
352 # echo errorMessages($errors);
354 echo $output;
356 </div>
357 </body>
358 </html>