[ Index ] |
|
Code source de e107 0.7.8 |
1 <?php 2 /* 3 + ----------------------------------------------------------------------------+ 4 | e107 website system 5 | 6 | ?Steve Dunstan 2001-2002 7 | http://e107.org 8 | jalist@e107.org 9 | 10 | Released under the terms and conditions of the 11 | GNU General Public License (http://gnu.org). 12 | 13 | $Source: /cvsroot/e107/e107_0.7/e107_files/resetcore/resetcore.php,v $ 14 | $Revision: 1.15 $ 15 | $Date: 2006/10/24 13:38:05 $ 16 | $Author: mrpete $ 17 +----------------------------------------------------------------------------+ 18 */ 19 20 21 /* #################################################### 22 23 24 To use this file, you must edit the following line, removing the // so it reads: 25 define("ACTIVE", true); 26 If you don't, the script will not be usable. 27 28 When you have finished with resetcore you should swap true for false so it can't be used by 29 people it shouldn't be used by. 30 31 If your site uses a different charset than utf-8, change the CHARSET to reflect the correct encoding. 32 33 */ 34 35 define("ACTIVE", false); 36 define("CHARSET", 'utf-8'); 37 38 /* #################################################### */ 39 40 41 $register_globals = true; 42 if(function_exists('ini_get')) 43 { 44 $register_globals = ini_get('register_globals'); 45 } 46 if($register_globals == true) 47 { 48 while (list($global) = each($GLOBALS)) 49 { 50 if (!preg_match('/^(_POST|_GET|_COOKIE|_SERVER|_FILES|GLOBALS|HTTP.*|_REQUEST|eTimingStart)$/', $global)) 51 { 52 unset($$global); 53 } 54 } 55 unset($global); 56 } 57 58 require_once ("../../e107_config.php"); 59 mysql_connect($mySQLserver, $mySQLuser, $mySQLpassword); 60 mysql_select_db($mySQLdefaultdb); 61 define("MAGIC_QUOTES_GPC", (ini_get('magic_quotes_gpc') ? TRUE : FALSE)); 62 63 define("e107_INIT", TRUE); 64 require_once('../../'.$HANDLERS_DIRECTORY.'arraystorage_class.php'); 65 $eArrayStorage = new ArrayData(); 66 67 echo "<?xml version='1.0' encoding='".CHARSET."' ?>\n"; 68 ?> 69 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> 70 <html xmlns="http://www.w3.org/1999/xhtml"> 71 <head> 72 <title><e107 resetcore></title> 73 <link rel="stylesheet" href="style.css" /> 74 <meta http-equiv="Content-Type" content="text/html; charset=<?php echo CHARSET; ?>" /> 75 <meta http-equiv="content-style-type" content="text/css" /> 76 </head> 77 <body> 78 <div class='mainbox'> 79 <a href="http://e107.org"><img src="../../e107_images/logo_template_large.png" alt="Logo" style="border: 0px; vertical-align: middle;" /></a> <span class='headertext'>e107 Reset Core Utility</span> 80 <br /> 81 <br /> 82 <br /> 83 <br /> 84 <?php 85 86 if(ACTIVE !== true) { 87 echo "<span class='headertext2'>Currently disabled. To enable please open this file in a text editor and follow the instructions to activate.</span>"; 88 exit; 89 } 90 91 if (isset($_POST['usubmit'])) { 92 if (($row = e_verify()) !== FALSE) { 93 extract($row); 94 95 $result = mysql_query("SELECT * FROM ".$mySQLprefix."core WHERE e107_name='pref_backup' "); 96 $bu_exist = ($row = mysql_fetch_array($result) ? TRUE : FALSE); 97 98 $admin_directory = "e107_admin"; 99 100 // <input type='radio' name='mode' value='1' /> <span class='headertext2'>Manually edit core values</span><br /> 101 102 echo "<span class='headertext2'><b>Please select which method you want to use, then click the button to proceed ...</b></span><br /><br /><br /><br /> 103 <table style='width: auto; margin-left:auto; margin-right: auto;'> 104 <tr> 105 <td> 106 <form method='post' action='".$_SERVER['PHP_SELF']."'> 107 <input type='radio' name='mode' value='2' /> <span class='headertext2'>Reset core to default values</span><br />". ($bu_exist ? "<input type='radio' name='mode' value='3' /> <span class='headertext2'>Restore core backup</span>" : "<br />( There is no backed-up core - unable to offer option to restore backup )")."<br /><br /><input class='button' type='submit' name='reset_core_sub' value='Select method then click here to continue' /> 108 109 <input type='hidden' name='a_name' value='".$_POST['a_name']."' /> 110 <input type='hidden' name='a_password' value='".$_POST['a_password']."' /> 111 112 </form> 113 </td> 114 </tr> 115 </table> 116 "; 117 118 $END = TRUE; 119 } else { 120 $message = "<b>Administrator not found in database / incorrect password / insufficient permissions - aborting.</b><br />"; 121 $END = TRUE; 122 } 123 } 124 125 126 if (isset($_POST['reset_core_sub']) && $_POST['mode'] == 2) 127 { 128 if (($at = e_verify()) === FALSE) { 129 exit; 130 } 131 132 $tmpr = substr(str_replace($_SERVER['DOCUMENT_ROOT'], "", $_SERVER['SCRIPT_FILENAME']), 1); 133 $root = "/".substr($tmpr, 0, strpos($tmpr, "/"))."/"; 134 $e_HTTP = $root; 135 $admin_directory = "e107_admin"; 136 $url_prefix = substr($_SERVER['PHP_SELF'], strlen($e_HTTP), strrpos($_SERVER['PHP_SELF'], "/")+1-strlen($e_HTTP)); 137 $num_levels = substr_count($url_prefix, "/"); 138 $link_prefix = ''; 139 for($i = 1; $i <= $num_levels; $i++) { 140 $link_prefix .= "../"; 141 } 142 143 define("e_ADMIN", $e_HTTP.$admin_directory."/"); 144 define("e_SELF", "http://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF']); 145 define("e_QUERY", preg_replace("#&|/?PHPSESSID.*#i", "", $_SERVER['QUERY_STRING'])); 146 define('e_BASE', $link_prefix); 147 $e_path = (!strpos($_SERVER['SCRIPT_FILENAME'], ".php") ? $_SERVER['PATH_TRANSLATED'] : $_SERVER['SCRIPT_FILENAME']); 148 define("e_PATH", $e_path); 149 150 151 $pref_language = "English"; 152 include_once("../../".$LANGUAGES_DIRECTORY."English/lan_prefs.php"); 153 require_once("../../".$FILES_DIRECTORY."def_e107_prefs.php"); 154 155 $PrefOutput = $eArrayStorage->WriteArray($pref); 156 157 mysql_query("DELETE FROM ".$mySQLprefix."core WHERE e107_name='SitePrefs' OR e107_name='SitePrefs_Backup'"); 158 if (!mysql_query("INSERT INTO ".$mySQLprefix."core VALUES ('SitePrefs', '{$PrefOutput}')")) { 159 $message = "Rebuild failed ..."; 160 $END = TRUE; 161 } else { 162 mysql_query("INSERT INTO ".$mySQLprefix."core VALUES ('SitePrefs_Backup', '{$PrefOutput}')"); 163 $message = "Core reset. <br /><br /><a href='../../index.php'>Click here to continue</a>"; 164 $END = TRUE; 165 } 166 } 167 168 function recurse_pref($ppost) { 169 $search = array("\"", "'", "\\", '\"', "\'", "$", "?"); 170 $replace = array(""", "'", "\", """, "'", "$", "©"); 171 foreach ($ppost as $key => $value) { 172 if(!is_array($value)){ 173 $ret[$key] = str_replace($search, $replace, $text); 174 } else { 175 $ret[$key] = recurse_pref($value); 176 } 177 } 178 return $ret; 179 } 180 181 if (isset($_POST['coreedit_sub'])) 182 { 183 if (($at = e_verify()) === FALSE) { 184 exit; 185 } 186 187 $pref = recurse_pref($_POST); 188 189 $PrefOutput = $eArrayStorage->WriteArray($pref); 190 191 mysql_query("DELETE FROM ".$mySQLprefix."core WHERE e107_name='SitePrefs' OR e107_name='SitePrefs_Backup'"); 192 mysql_query("INSERT INTO ".$mySQLprefix."core VALUES ('SitePrefs', '{$PrefOutput}')"); 193 mysql_query("INSERT INTO ".$mySQLprefix."core VALUES ('SitePrefs_Backup', '{$PrefOutput}')"); 194 195 $message = "Core settings successfully updated. <br /><br /><a href='../../index.php'>Click here to continue</a>"; 196 $END = TRUE; 197 } 198 199 if (isset($_POST['reset_core_sub']) && $_POST['mode'] == 3) { 200 if (($at = e_verify()) === FALSE) { 201 exit; 202 } 203 204 $result = mysql_query("SELECT * FROM ".$mySQLprefix."core WHERE e107_name='pref_backup'"); 205 $row = mysql_fetch_array($result); 206 207 $pref = unserialize(base64_decode($row['e107_value'])); 208 209 $PrefOutput = $eArrayStorage->WriteArray($pref); 210 211 mysql_query("DELETE FROM ".$mySQLprefix."core WHERE `e107_name` = 'SitePrefs' OR `e107_name` = 'SitePrefs_Backup'"); 212 mysql_query("INSERT INTO ".$mySQLprefix."core VALUES ('SitePrefs', '{$PrefOutput}')"); 213 mysql_query("INSERT INTO ".$mySQLprefix."core VALUES ('SitePrefs_Backup', '{$PrefOutput}')"); 214 215 $message = "Core backup successfully restored. <br /><br /><a href='../../index.php'>Click here to continue</a>"; 216 $END = TRUE; 217 } 218 219 220 if (isset($_POST['reset_core_sub']) && $_POST['mode'] == 1) 221 { 222 if (($at = e_verify()) === FALSE) { 223 exit; 224 } 225 226 $result = @mysql_query("SELECT * FROM ".$mySQLprefix."core WHERE e107_name='SitePrefs'"); 227 $row = @mysql_fetch_array($result); 228 229 $pref = $eArrayStorage->ReadArray($row['e107_value']); 230 231 echo " 232 <span class='headertext2'><b>Edit your individual core items and click the button to save - <span class='headertext'>use this script with caution</span>.</b></span><br /><br /> 233 <form method='post' action='".$_SERVER['PHP_SELF']."'> 234 <table style='width:95%'>\n"; 235 236 while (list($key, $prefr) = each($pref)) { 237 if (is_array($prefr)) { 238 foreach ($prefr as $akey => $apref) { 239 echo "<tr><td class='headertext2' style='width:50%; text-align:right;'>{$key}[{$akey}] </td> 240 <td style='width:50%'><input type='text' name='{$key}[{$akey}]' value='{$apref}' size='50' maxlength='100' /></td></tr>\n"; 241 242 } 243 } else { 244 echo "<tr><td class='headertext2' style='width:50%; text-align:right;'>{$key} </td> 245 <td style='width:50%'><input type='text' name='{$key}' value='{$prefr}' size='50' maxlength='100' /></td></tr>\n"; 246 } 247 } 248 echo " 249 <tr> 250 <td colspan='2' style='text-align:center'><br /><input class='button' type='submit' name='coreedit_sub' value='Save Core Settings' /></td> 251 </tr> 252 </table> 253 <input type='hidden' name='a_name' value='".$_POST['a_name']."' /> 254 <input type='hidden' name='a_password' value='".preg_replace("/\W/", '', $_POST['a_password'])."' /> 255 </form>"; 256 $END = TRUE; 257 } 258 259 if (isset($message)) { 260 echo "<br /><br /><div style='text-align:center'><span class='headertext2'>{$message}</span></div><br />"; 261 } 262 263 if (isset($END)) { 264 echo "<br /></div></body></html>"; 265 exit; 266 } 267 268 echo "<span class='headertext2'> 269 This is the e107 resetcore utility. It allows you to completely rebuild your core if it becomes corrupt, or to restore a backup. <br />It won't affect your actual content (news posts, forum posts, articles etc).<br /> 270 <b>Only run this utility if your site is failing to load due to a critical core error, or if you need to change a setting and can't log into your admin area.</b></span><br /><br /><br /><br /> 271 272 <span class='headertext'>Please enter your main administrator username and password to continue ...</span><br /><br /> 273 <form method='post' action='".$_SERVER['PHP_SELF']."'> 274 <table style='width:95%'> 275 <tr> 276 <td style='width:50%; text-align:right;' class='mediumtext'>Main administrator name:</td> 277 <td style='width:50%'> 278 <input class='tbox' type='text' name='a_name' size='30' value='' maxlength='100' /> 279 </td> 280 </tr> 281 <tr> 282 <td style='width:50%; text-align:right;' class='mediumtext'>Main administrator Password:</td> 283 <td style='width:50%'> 284 <input class='tbox' type='password' name='a_password' size='30' value='' maxlength='100' /> 285 </td> 286 </tr> 287 <tr> 288 <td colspan='2' style='text-align:center'> 289 <br /> 290 <input class='button' type='submit' name='usubmit' value='Continue' /> 291 </td> 292 </tr> 293 </table> 294 <br /> 295 </div> 296 </body> 297 </html>"; 298 299 function e_verify() { 300 global $mySQLprefix; 301 if (ACTIVE !== TRUE) { 302 exit; 303 } 304 if (MAGIC_QUOTES_GPC == FALSE) { 305 $a_name = addslashes($_POST['a_name']); 306 } 307 else 308 { 309 $a_name = $_POST['a_name']; 310 } 311 312 $a_name = str_replace('/*', '', $a_name); 313 314 $result = mysql_query("SELECT * FROM ".$mySQLprefix."user WHERE user_name='".$a_name."'"); 315 $row = mysql_fetch_array($result); 316 317 if (($row['user_password'] === md5($_POST['a_password'])) && ($row['user_perms'] === '0') && (ACTIVE === TRUE)) { 318 clear_cache(); 319 return $row; 320 } else { 321 return FALSE; 322 } 323 } 324 325 function clear_cache() { 326 $dir = "../cache/"; 327 $pattern = "*.cache.php"; 328 $deleted = false; 329 $pattern = str_replace(array("\*", "\?"), array(".*", "."), preg_quote($pattern)); 330 if (substr($dir, -1) != "/") { 331 $dir .= "/"; 332 } 333 if (is_dir($dir)) { 334 $d = opendir($dir); 335 while ($file = readdir($d)) { 336 if (is_file($dir.$file) && preg_match("/^{$pattern}$/", $file)) { 337 if (unlink($dir.$file)) { 338 $deleted[] = $file; 339 } 340 } 341 } 342 closedir($d); 343 return true; 344 } else { 345 return false; 346 } 347 } 348 349 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sun Apr 1 01:23:32 2007 | par Balluche grâce à PHPXref 0.7 |