tools.php 37 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027
  1. <?php
  2. /**
  3. * [Discuz!] (C)2001-2099 Comsenz Inc.
  4. * This is NOT a freeware, use is subject to license terms
  5. *
  6. * $Id: tools.php 111 2013-03-18 02:43:43Z xujiakun $
  7. */
  8. /**
  9. * 密码要求:1、必须且只能包含大写字母、小写字母、数字
  10. * 2、密码长度大于6
  11. * 修改下面的 $password = '',单引号中按照密码要求写入你的密码,举例 $password = 'DiscuzX3' ,注意:请不要把密码设置成 DiscuzX3,以免被人获知。
  12. */
  13. $tpassword = 'Qwe12345';
  14. /*************************************以下部分为tools工具箱的核心代码,请不要随意修改**************************************/
  15. error_reporting(0);
  16. define('TMAGIC_QUOTES_GPC', function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc());
  17. define('TOOLS_ROOT', dirname(__FILE__).'/');
  18. define('TOOLS_VERSION', 'Tools 3.0.0');
  19. define('TOOLS_DISCUZ_VERSION', 'Discuz! X3.0');
  20. $tools_versions = TOOLS_VERSION;
  21. $tools_discuz_version = TOOLS_DISCUZ_VERSION;
  22. if(!TMAGIC_QUOTES_GPC) {
  23. $_GET = taddslashes($_GET);
  24. $_POST = taddslashes($_POST);
  25. $_COOKIE = taddslashes($_COOKIE);
  26. }
  27. if (isset($_GET['GLOBALS']) || isset($_POST['GLOBALS']) || isset($_COOKIE['GLOBALS']) || isset($_FILES['GLOBALS'])) {
  28. show_msg('您当前的访问请求当中含有非法字符,已经被系统拒绝');
  29. }
  30. if($_SERVER['REQUEST_METHOD'] == 'POST' && !empty($_POST)) {
  31. $_GET = array_merge($_GET, $_POST);
  32. }
  33. $actionarray = array('index', 'setadmin', 'closesite', 'closeplugin', 'repairdb', 'restoredb', 'updatecache', 'login', 'logout');
  34. $_GET['action'] = htmlspecialchars($_GET['action']);
  35. $action = in_array($_GET['action'], $actionarray) ? $_GET['action'] : 'index';
  36. if(!is_login()) {
  37. login_page();
  38. exit;
  39. }
  40. $t = new T();
  41. $t->init();
  42. $config = $t->config;
  43. if($action == 'index') {
  44. //首页
  45. show_header();
  46. print<<<END
  47. <p>欢迎使用 Tools 之 Discuz! 急诊箱功能!我们致力于为您解决 Discuz! 站点的紧急故障,欢迎各位站长朋友们使用。</p>
  48. <tr><td>
  49. <h5>适用版本:</h5>
  50. <ul>
  51. <li>{$tools_discuz_version}</li>
  52. </ul>
  53. <h5>主要功能:</h5>
  54. <ul>
  55. <li>重置管理员账号:将把您指定的会员设置为管理员</li>
  56. <li>开启关闭站点: 此处可以进行站点“关闭/打开”的操作</li>
  57. <li>一键关闭插件: 一键关闭应用中心开启的所有插件</li>
  58. <li>修复数据库: 对所有数据表进行检查修复工作</li>
  59. <li>恢复数据库: 一次性导入论坛数据备份</li>
  60. <li>更新缓存: 一键更新论坛的数据缓存与模板缓存</li>
  61. </ul>
  62. <h5>问题反馈:</h5>
  63. <p>&nbsp;&nbsp;&nbsp;&nbsp;有关 Tools 工具箱的建议和问题,请反馈到 Discuz! 官方论坛安装使用区(<a href="http://www.discuz.net/forum-2-1.html" target="_blank">http://www.discuz.net/forum-2-1.html</a>),我们会对您的问题进行处理。提交问题时,请注明问题来源于 Discuz! 急诊箱。</p>
  64. END;
  65. show_footer();
  66. }elseif($action == 'setadmin') {
  67. //找回管理员
  68. $t->connect_db();
  69. $founders = @explode(',',$t->config['admincp']['founder']);
  70. $foundernames = array();
  71. foreach($founders as $userid) {
  72. $sql = "SELECT username FROM ".$t->dbconfig['tablepre']."common_member WHERE `uid`='$userid'";
  73. $foundernames[] = mysql_result(mysql_query($sql, $t->db), 0);
  74. }
  75. $foundernames = implode($foundernames, ',');
  76. print_r($foundernames);
  77. $sql = "SELECT username FROM ".$t->dbconfig['tablepre']."common_member WHERE `adminid`='1'";
  78. $query = mysql_query($sql, $t->db) or dir(mysql_error());
  79. $adminnames = array();
  80. while($row = mysql_fetch_row($query)) {
  81. $adminnames[] = $row[0];
  82. }
  83. $adminnames = implode($adminnames, ',');
  84. if(!empty($_POST['setadminsubmit'])) {
  85. if($_GET['username'] == NULL) {
  86. show_msg('请输入用户名', 'tools.php?action='.$action, 2000);
  87. }
  88. if($_GET['loginfield'] == 'username') {
  89. $_GET['username'] = addslashes($_GET['username']);
  90. $sql = "SELECT uid FROM ".$t->dbconfig['tablepre']."common_member WHERE `username`='".$_GET['username']."'";
  91. $uid = mysql_result(mysql_query($sql, $t->db), 0);
  92. $username = $_GET['username'];
  93. } elseif($_GET['loginfield'] == 'uid') {
  94. $_GET['username'] = addslashes($_GET['username']);
  95. $uid = $_GET['username'];
  96. $sql = "SELECT username FROM ".$t->dbconfig['tablepre']."common_member WHERE `uid`='".$_GET['username']."'";
  97. $username = mysql_result(mysql_query($sql, $t->db), 0);
  98. }
  99. if($uid && $username) {
  100. $sql = "UPDATE ".$t->dbconfig['tablepre']."common_member SET `groupid`='1', `adminid`='1' WHERE `uid`='$uid'";
  101. @mysql_query($sql, $t->db);
  102. if(!in_array($uid,$founders)) {
  103. $sql = "REPLACE INTO ".$t->dbconfig['tablepre']. "common_admincp_member (`uid`, `cpgroupid`, `customperm`) VALUES ('$uid', '0', '')";
  104. @mysql_query($sql, $t->db);
  105. }
  106. } else {
  107. show_msg('没有这个用户', 'tools.php?action='.$action, 2000);
  108. }
  109. $t->connect_db('ucdb');
  110. if($_GET['password'] != NULL) {
  111. $sql = "SELECT salt FROM ".$t->ucdbconfig['tablepre']."members WHERE `uid`='$uid'";
  112. $salt = mysql_result(mysql_query($sql, $t->db), 0);
  113. $newpassword = md5(md5(trim($_GET['password'])).$salt);
  114. $sql = "UPDATE ".$t->ucdbconfig['tablepre']."members SET `password`='$newpassword' WHERE `uid`='$uid'";
  115. mysql_query($sql, $t->db);
  116. }
  117. if($_GET['issecques'] == 1) {
  118. $sql = "UPDATE ".$t->ucdbconfig['tablepre']."members SET `secques`='' WHERE `uid`='$uid'";
  119. mysql_query($sql, $t->db);
  120. }
  121. $t->close_db();
  122. show_msg('管理员找回成功!', 'tools.php?action='.$action, 2000);
  123. } else {
  124. show_header();
  125. echo "<p>现有创始人:$foundernames</p>";
  126. echo "<p>现有管理员:$adminnames</p>";
  127. print<<<END
  128. <form action="?action={$action}" method="post">
  129. <h5>{$info}</h5>
  130. <table id="setadmin">
  131. <tr><th width="30%"><input class="radio" type="radio" name="loginfield" value="username" checked class="radio">用户名<input class="radio" type="radio" name="loginfield" value="uid" class="radio">UID</th><td width="70%"><input class="textinput" type="text" name="username" size="25" maxlength="40"></td></tr>
  132. <tr><th width="30%">请输入密码</th><td width="70%"><input class="textinput" type="text" name="password" size="25"></td></tr>
  133. <tr><th width="30%">是否清除安全提问</th><td width="70%">
  134. <input class="radio" type="radio" name="issecques" value="1">是&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  135. <input class="radio" type="radio" name="issecques" value="0" class="radio" checked>否</td></tr>
  136. </table>
  137. <input type="submit" name="setadminsubmit" value="提 &nbsp; 交">
  138. </form>
  139. END;
  140. print<<<END
  141. <br/>
  142. 恢复步骤:
  143. 重置管理员<br/>
  144. <ul>
  145. <li>选择用户名或者UID。</li>
  146. <li>输入用户名或者UID。</li>
  147. <li>如果需要重置密码,输入密码。</li>
  148. <li>如果需要清除安全提问,请在是否清除安全提问处选择是。</li>
  149. </ul>
  150. <br/>
  151. 重置创始人<br/>
  152. <ul>
  153. <li>重置用户为创始人。</li>
  154. <li>修改config_global.php 中 \$_config[\'admincp\'][\'founder\'] = \'管理员的ID\',多个以半角逗号分割。</li>
  155. </ul>
  156. END;
  157. show_footer();
  158. }
  159. }elseif($action == 'closesite') {
  160. //一键开关站点
  161. $t->connect_db();
  162. $sql = "SELECT svalue FROM ".$t->dbconfig['tablepre']."common_setting WHERE skey='bbclosed'";
  163. $bbclosed = mysql_result(mysql_query($sql, $t->db), 0);
  164. if(empty($bbclosed)) {
  165. $closed = '';
  166. $opened = 'checked';
  167. } else {
  168. $closed = 'checked';
  169. $opened = '';
  170. }
  171. $sql = "SELECT svalue FROM ".$t->dbconfig['tablepre']."common_setting WHERE `skey`='closedreason'";
  172. $closedreason = mysql_result(mysql_query($sql, $t->db), 0);
  173. if(!empty($_GET['closesitesubmit'])) {
  174. if($_GET['close'] == 1) {
  175. $sql = "UPDATE ".$t->dbconfig['tablepre']."common_setting SET `svalue`='1' WHERE `skey`='bbclosed'";
  176. mysql_query($sql, $t->db);
  177. $sql = "UPDATE ".$t->dbconfig['tablepre']."common_setting SET `svalue`='tools.php closed' WHERE `skey`='closedreason'";
  178. mysql_query($sql, $t->db);
  179. } else {
  180. $sql = "UPDATE ".$t->dbconfig['tablepre']."common_setting SET `svalue`='0' WHERE `skey`='bbclosed'";
  181. mysql_query($sql, $t->db);
  182. $sql = "UPDATE ".$t->dbconfig['tablepre']."common_setting SET `svalue`='' WHERE `skey`='closedreason'";
  183. mysql_query($sql, $t->db);
  184. }
  185. show_msg('关闭/打开站点操作成功,正在更新缓存...', 'tools.php?action=updatecache',2000);
  186. } else {
  187. show_header();
  188. print<<<END
  189. <h4>关闭/打开站点</h4>
  190. 此处可以进行站点“关闭/打开”的操作。
  191. <p>
  192. <form action="?action=closesite" method="post">
  193. 站点当前状态
  194. <input class="radio" type="radio" name="close" value="0" {$opened} class="radio">打开
  195. <input class="radio" type="radio" name="close" value="1" {$closed} class="radio">关闭
  196. </p>
  197. <p>
  198. <input type="submit" name="closesitesubmit" value="提 &nbsp; 交">
  199. </p>
  200. </form>
  201. END;
  202. show_footer();
  203. }
  204. }elseif($action == 'closeplugin') {
  205. //一键关闭插件
  206. include_once(TOOLS_ROOT.'source/class/class_core.php');
  207. include_once(TOOLS_ROOT.'source/function/function_core.php');
  208. $cachelist = array();
  209. $discuz = & discuz_core::instance();
  210. $discuz->cachelist = $cachelist;
  211. $discuz->init_cron = false;
  212. $discuz->init_setting = false;
  213. $discuz->init_user = false;
  214. $discuz->init_session = false;
  215. $discuz->init_misc = false;
  216. $discuz->init();
  217. require_once libfile('function/plugin');
  218. require_once libfile('function/cache');
  219. DB::query("UPDATE ".DB::table('common_plugin')." SET available='0'");
  220. updatecache(array('plugin', 'setting', 'styles'));
  221. cleartemplatecache();
  222. show_msg('成功关闭所有插件', 'tools.php?action=index',2000);
  223. }elseif($action == 'repairdb') {
  224. //修复数据库
  225. show_header();
  226. $t->connect_db();
  227. $typearray = array('index', 'repair', 'repairtables', 'allrepair', 'check', 'detail');
  228. $type = in_array($_GET['type'], $typearray) ? $_GET['type'] : 'index';
  229. if($type == 'index') {
  230. print<<<END
  231. <div class=\"bm\">
  232. <table id="menu">
  233. <tr>
  234. <!--<td><a href="?action=repairdb&type=allcheck">一键检查</a></td>--!>
  235. <td><a href="?action=repairdb&type=allrepair">一键修复</a></td>
  236. <td><a href="?action=repairdb&type=detail">进入详细页面检查或修复</a></td>
  237. </tr>
  238. </table>
  239. 说明 & 提示:
  240. <ul>
  241. <!--<li>一键检查: 对数据库中所有表进行 CHECK TABLE 操作,列出损坏的数据表。</li>--!>
  242. <li>一键修复: 先执行 CHECK TABLE 操作,然后按照检查的结果对有错误的数据表执行REPAIR TABLE 操作。</li>
  243. <li>进入详细页面检查或修复: 列出详细表,对单表进行检查或修复。</li>
  244. <li><span style="color:red">提示1:数据表比较大的情况下,mysql可能会花费比较长的时间进行检查和修复操作。</span></li>
  245. <li><span style="color:red">提示2:REPAIR TABLE 操作不能修复所有情况,如果修复不了数据表,请登录服务器使用myisamchk进行数据表修复。</span></li>
  246. </ul>
  247. </div>
  248. END;
  249. } elseif ($type == 'allrepair' || $type == 'allcheck' || $type == 'detail' || $type == 'check' || $type == 'repair' || $type == 'repairtables') {
  250. $sql = "SHOW TABLE STATUS";
  251. $tablelist = mysql_query($sql, $t->db);
  252. while($list = mysql_fetch_array($tablelist, MYSQL_ASSOC)) {
  253. if($type == 'allcheck' || $type == 'allrepair') {
  254. if($list['Engine'] != 'MEMORY' && $list['Engine'] != 'HEAP') {
  255. $sql = 'CHECK TABLE '.$list['Name'];
  256. $query = mysql_query($sql, $t->db);
  257. $checkresult = mysql_fetch_array($query, MYSQL_ASSOC);
  258. if( $checkresult['Msg_text'] != 'OK') {
  259. $tablelists[$list['Name']]['statu'] = $checkresult['Msg_text'];
  260. $tablelists[$list['Name']]['size'] = round(($list['Data_length'] + $list['Index_length'])/1024,2);
  261. }
  262. }
  263. } else {
  264. $tablelists[$list['Name']]['size'] = round(($list['Data_length'] + $list['Index_length'])/1024,2);
  265. }
  266. }
  267. if($type == 'allrepair') {
  268. foreach($tablelists as $table => $value) {
  269. $sql = "REPAIR TABLE `".$table."`";
  270. $query = mysql_query($sql, $t->db);
  271. $repairresult = mysql_fetch_array($query, MYSQL_ASSOC);
  272. $resulttable[$table]['statu'] = $repairresult['Msg_text'];
  273. $resulttable[$table]['size'] = '未检查';
  274. }
  275. $tablelists = $resulttable;
  276. }
  277. if($type == 'check') {
  278. $_GET['table'] = addslashes($_GET['table']);
  279. $sql = 'CHECK TABLE '.$_GET['table'];
  280. $query = mysql_query($sql, $t->db);
  281. $checkresult = mysql_fetch_array($query, MYSQL_ASSOC);
  282. $tablelists[$_GET['table']]['statu'] = $checkresult['Msg_text'];
  283. }
  284. if($type == 'repair') {
  285. $_GET['table'] = addslashes($_GET['table']);
  286. $sql = "REPAIR TABLE `".$_GET['table']."`";
  287. $query = mysql_query($sql, $t->db);
  288. $repairresult = mysql_fetch_array($query, MYSQL_ASSOC);
  289. echo '<div style="background:red">';
  290. show_msg_body('修复表单 '.$_GET['table'].' 结果:'.$repairresult['Msg_text'], "tools.php?action=$action&type=detail", 3000);
  291. echo '</div>';
  292. }
  293. if($type == 'repairtables') {
  294. if($_POST['optimizesubmit']){
  295. $repairtables = addslashes($_POST['repairtables']);
  296. foreach ($repairtables as $value) {
  297. $sql = "REPAIR TABLE `".$value."`";
  298. $query = mysql_query($sql, $t->db);
  299. $repairresult = mysql_fetch_array($query, MYSQL_ASSOC);
  300. echo '<div style="background:red">';
  301. show_msg_body('修复表单 '.$value.' 结果:'.$repairresult['Msg_text'], '', 3000);
  302. echo '</div>';
  303. }
  304. echo '<div style="background:red">';
  305. show_msg_body('复选修复表单完成', "tools.php?action=$action&type=detail", 3000);
  306. echo '</div>';
  307. }
  308. }
  309. echo '
  310. <script type="text/javascript">
  311. var BROWSER = {};
  312. var USERAGENT = navigator.userAgent.toLowerCase();
  313. browserVersion({\'ie\':\'msie\',\'firefox\':\'\',\'chrome\':\'\',\'opera\':\'\',\'safari\':\'\',\'mozilla\':\'\',\'webkit\':\'\',\'maxthon\':\'\',\'qq\':\'qqbrowser\'});
  314. function browserVersion(types) {
  315. var other = 1;
  316. for(i in types) {
  317. var v = types[i] ? types[i] : i;
  318. if(USERAGENT.indexOf(v) != -1) {
  319. var re = new RegExp(v + \'(\\/|\\s)([\\d\\.]+)\', \'ig\');
  320. var matches = re.exec(USERAGENT);
  321. var ver = matches != null ? matches[2] : 0;
  322. other = ver !== 0 && v != \'mozilla\' ? 0 : other;
  323. } else {
  324. var ver = 0;
  325. }
  326. eval(\'BROWSER.\' + i + \'= ver\');
  327. }
  328. BROWSER.other = other;
  329. }
  330. function jumpurl(url,nw) {
  331. if(BROWSER.ie) url += (url.indexOf(\'?\') != -1 ? \'&\' : \'?\') + \'referer=\' + escape(location.href);
  332. if(nw == 1) {
  333. window.open(url);
  334. } else {
  335. location.href = url;
  336. }
  337. return false;
  338. }
  339. </script>';
  340. echo '
  341. <script type="text/javascript">
  342. function checkAll(type, form, value, checkall, changestyle) {
  343. var checkall = checkall ? checkall : \'chkall\';
  344. for(var i = 0; i < form.elements.length; i++) {
  345. var e = form.elements[i];
  346. if(type == \'option\' && e.type == \'radio\' && e.value == value && e.disabled != true) {
  347. e.checked = true;
  348. } else if(type == \'value\' && e.type == \'checkbox\' && e.getAttribute(\'chkvalue\') == value) {
  349. e.checked = form.elements[checkall].checked;
  350. if(changestyle) {
  351. multiupdate(e);
  352. }
  353. } else if(type == \'prefix\' && e.name && e.name != checkall && (!value || (value && e.name.match(value)))) {
  354. e.checked = form.elements[checkall].checked;
  355. if(changestyle) {
  356. if(e.parentNode && e.parentNode.tagName.toLowerCase() == \'li\') {
  357. e.parentNode.className = e.checked ? \'checked\' : \'\';
  358. }
  359. if(e.parentNode.parentNode && e.parentNode.parentNode.tagName.toLowerCase() == \'div\') {
  360. e.parentNode.parentNode.className = e.checked ? \'item checked\' : \'item\';
  361. }
  362. }
  363. }
  364. }
  365. }
  366. </script>';
  367. print<<<END
  368. <div class=\"bm\">
  369. <table class=\"tb\">
  370. <tbody>
  371. <form name="cpform" method="post" autocomplete="on" action="tools.php?action=repairdb&type=repairtables" id="cpform">
  372. <tr>
  373. <th></th>
  374. <th width="350px">表名</th>
  375. <th width="80px">大小</th>
  376. <th></th>
  377. <th width="80px"></th>
  378. </tr>
  379. END;
  380. foreach($tablelists as $name => $value) {
  381. if($value['size'] < 1024) {
  382. echo '<tr><th><input class="checkbox" type="checkbox" name="repairtables[]" value="'.$name.'"></th><th>'.$name.'</th><td style="text-align:right;color:#339900"">'.$value['size'] .'KB</td><td>';
  383. } elseif(1024 < $value['size'] && $value['size']< 1048576 ) {
  384. echo '<tr><th><input class="checkbox" type="checkbox" name="repairtables[]" value="'.$name.'"></th><th>'.$name.'</th><td style="text-align:right;color:#3333FF">'.round($value['size']/1024,1) .'MB</td><td>';
  385. } elseif(1048576 < $value['size']){
  386. echo '<tr><th><input class="checkbox" type="checkbox" name="repairtables[]" value="'.$name.'"></th><th>'.$name.'</th><td style="text-align:right;color:#FF0000"">'.round($value['size']/1048576,1) .'GB</td><td>';
  387. }
  388. if(!isset($value['statu'])) {
  389. echo "<button type=\"button\" class=\"pn vm\" onclick=\"jumpurl('tools.php?action=repairdb&type=check&table=".$name."')\"><strong>检查</button>";
  390. } elseif($value['statu']!='OK') {
  391. echo '<span class=\"red\">'.$value['statu'].'</span>';
  392. } else {
  393. echo $value['statu'];
  394. }
  395. echo '</td><td>';
  396. if($value['statu']!='OK' && $value['statu']!='Not Support CHECK') {
  397. echo "<button type=\"button\" class=\"pn vm\" onclick=\"jumpurl('tools.php?action=repairdb&type=repair&table=".$name."')\"><strong>修复</button></strong>";
  398. }
  399. echo '</td></tr>';
  400. }
  401. echo "<tr><th><input name=\"chkall\" id=\"chkall\" class=\"checkbox\" onclick=\"checkAll('prefix', this.form)\" type=\"checkbox\"></th><th><input type=\"submit\" class=\"btn\" id=\"submit_optimizesubmit\" name=\"optimizesubmit\" title=\"复选修复\" value=\"复选修复\"></th><td></td><td></td><td></td></form>";
  402. echo '</tbody></table></div>';
  403. if( count($tablelists) == 0) {
  404. echo '<div style="background:#00cc66;">没有需要修复的表</div>';
  405. }
  406. } elseif ($type == 'allrepair') {
  407. show_msg("操作成功", "tools.php?action=$action");
  408. }
  409. show_footer();
  410. }elseif($action == 'restoredb') {
  411. //恢复数据
  412. $backfiledir = TOOLS_ROOT.'data/';
  413. $detailarray = array();
  414. $t->connect_db();
  415. if(!mysql_select_db($t->dbconfig['name'], $t->db)) {
  416. $dbname = $t->dbconfig['name'];
  417. mysql_query("CREATE DATABASE $dbname");
  418. }
  419. if(!$_GET['importbak'] && !$_GET['nextfile']) {
  420. //检测是否关闭站点
  421. $sql = "SELECT svalue FROM ".$t->dbconfig['tablepre']."common_setting WHERE skey='bbclosed'";
  422. $closed = mysql_result(mysql_query($sql, $t->db), 0);
  423. if($closed != '1') {
  424. show_msg('恢复数据前,请先关闭站点!', 'tools.php?action=closesite', 3000);
  425. }
  426. $exportlog = array();
  427. $dir = dir($backfiledir);
  428. while($entry = $dir->read()) {
  429. $entry = $backfiledir."/$entry";
  430. $num = 0;
  431. if(is_dir($entry) && preg_match("/backup\_/i", $entry)) {
  432. $bakdir = dir($entry);
  433. while($bakentry = $bakdir->read()) {
  434. $bakentry = "$entry/$bakentry";
  435. if(is_file($bakentry) && preg_match("/(.*)\-(\d)\.sql/i", $bakentry,$match)) {
  436. if($_GET['detail']) {
  437. $detailarray[] = $match['1'];
  438. }
  439. $num++;
  440. }
  441. if(is_file($bakentry) && preg_match("/\-1\.sql/i", $bakentry)) {
  442. $fp = fopen($bakentry, 'rb');
  443. $bakidentify = explode(',', base64_decode(preg_replace("/^# Identify:\s*(\w+).*/s", "\\1", fgets($fp, 256))));
  444. fclose ($fp);
  445. if(preg_match("/\-1\.sql/i", $bakentry) || $bakidentify[3] == 'shell') {
  446. $identify['bakentry'] = $bakentry;
  447. }
  448. }
  449. }
  450. $detailarray = array_reverse(array_unique($detailarray));
  451. if($num != 0) {
  452. $exportlog[$entry] = array(
  453. 'dateline' => date('Y-m-d H:i:s',$bakidentify[0]),
  454. 'version' => $bakidentify[1],
  455. 'type' => $bakidentify[2],
  456. 'method' => $bakidentify[3],
  457. 'volume' => $num,
  458. 'bakentry' => $identify['bakentry'],
  459. 'filename' => str_replace($backfiledir.'/','',$entry));
  460. }
  461. }
  462. }
  463. }else{
  464. $bakfile = $_GET['nextfile'] ? $_GET['nextfile'] : $_GET['importbak'];
  465. if(!file_exists($bakfile)) {
  466. if($_GET['nextfile']) {
  467. $tpl = dir(TOOLS_ROOT.'data/template');
  468. while($entry = $tpl->read()) {
  469. if(preg_match("/\.tpl\.php$/", $entry)) {
  470. @unlink(TOOLS_ROOT.'data/template/'.$entry);
  471. }
  472. }
  473. $tpl->close();
  474. show_msg('恢复备份成功,请查看论坛,如果数据不同步,请检查数据库前缀。正在更新缓存...', 'tools.php?action=updatecache',2000);
  475. }
  476. show_msg('备份文件不存在。');
  477. }
  478. if(!is_readable($bakfile)) {
  479. show_msg('备份文件不可读取。');
  480. } else {
  481. @$fp = fopen($bakfile, "r");
  482. @flock($fp, 3);
  483. $sqldump = @fread($fp, filesize($bakfile));
  484. @fclose($fp);
  485. }
  486. @$bakidentify = explode(',', base64_decode(preg_replace("/^# Identify:\s*(\w+).*/s", "\\1", substr($sqldump, 0, 256))));
  487. if(!defined('IN_DISCUZ')) {
  488. define('IN_DISCUZ', TRUE);
  489. }
  490. include_once(TOOLS_ROOT.'source/discuz_version.php');
  491. if($bakidentify[1] != DISCUZ_VERSION) {
  492. show_msg('备份文件版本错误,不能恢复。');
  493. }
  494. $vol = $bakidentify[4];
  495. $nextfile = taddslashes(str_replace("-$vol.sql","-".($vol+1).'.sql',$bakfile));
  496. $result = $t->db_runquery($sqldump);
  497. if($result) {
  498. show_msg('正在恢复分卷:'.$vol,"tools.php?action=$action&nextfile=$nextfile", 2000);
  499. }
  500. }
  501. $t->close_db();
  502. show_header();
  503. print<<<END
  504. <div class="bm">
  505. <form action="tools.php?action={$action}" method="post">
  506. <table class="tdat"><tbody>
  507. <tr class=\'alt h\'><th>备份项目</th><th>版本</th><th>时间</th><th>类型</th><th>文件总数</th><th>导入</th></tr>
  508. END;
  509. foreach( $exportlog as $value) {
  510. echo '<tr><td>'.$value['filename'].'</td><td>'.$value['version'].'</td><td>'.$value['dateline'].'</td><td>'.$value['method'].'</td><td>'.$value['volume'].'</td><td><a href="tools.php?action='.$action.'&detail='.$value['filename'].'"><font color="blue">打开</font></a></td></tr>';
  511. }
  512. if (count($detailarray)>0) {
  513. foreach($detailarray as $value) {
  514. echo '<tr><td colspan="5">'.$value.'</td><td><a href="tools.php?action='.$action.'&importbak='.$value.'-1.sql"><font color="blue">导入</font></a></td></tr>';
  515. }
  516. }
  517. echo '</tbody></table></form></div>';
  518. show_footer();
  519. }elseif($action == 'updatecache') {
  520. //更新缓存
  521. include_once(TOOLS_ROOT.'source/class/class_core.php');
  522. include_once(TOOLS_ROOT.'source/function/function_core.php');
  523. $cachelist = array();
  524. $discuz = & discuz_core::instance();
  525. $discuz->cachelist = $cachelist;
  526. $discuz->init_cron = false;
  527. $discuz->init_setting = false;
  528. $discuz->init_user = false;
  529. $discuz->init_session = false;
  530. $discuz->init_misc = false;
  531. $discuz->init();
  532. require_once libfile('function/cache');
  533. updatecache();
  534. include_once libfile('function/block');
  535. blockclass_cache();
  536. //note 清除群组缓存
  537. require_once libfile('function/group');
  538. $groupindex['randgroupdata'] = $randgroupdata = grouplist('lastupdate', array('ff.membernum', 'ff.icon'), 80);
  539. $groupindex['topgrouplist'] = $topgrouplist = grouplist('activity', array('f.commoncredits', 'ff.membernum', 'ff.icon'), 10);
  540. $groupindex['updateline'] = TIMESTAMP;
  541. $groupdata = DB::fetch_first("SELECT SUM(todayposts) AS todayposts, COUNT(fid) AS groupnum FROM ".DB::table('forum_forum')." WHERE status='3' AND type='sub'");
  542. $groupindex['todayposts'] = $groupdata['todayposts'];
  543. $groupindex['groupnum'] = $groupdata['groupnum'];
  544. save_syscache('groupindex', $groupindex);
  545. DB::query("TRUNCATE ".DB::table('forum_groupfield'));
  546. $tpl = dir(DISCUZ_ROOT.'./data/template');
  547. while($entry = $tpl->read()) {
  548. if(preg_match("/\.tpl\.php$/", $entry)) {
  549. @unlink(DISCUZ_ROOT.'./data/template/'.$entry);
  550. }
  551. }
  552. $tpl->close();
  553. show_msg('更新数据缓存模板缓存成功!', 'tools.php?action=index', 2000);
  554. }elseif($action == 'logout') {
  555. //登出
  556. tsetcookie('toolsauth', '', -1);
  557. @header('Location: tools.php');
  558. }else{
  559. }
  560. //大的分支 结束
  561. /**********************************************************************************
  562. *
  563. * tools.php 通用函数部分
  564. *
  565. *
  566. **********************************************************************************/
  567. /*
  568. checkpassword 函数
  569. 判断密码强度,大小写字母加数字,长度大于6位。
  570. return flase 或者 errormsg
  571. */
  572. function checkpassword($password){
  573. $errormsg = array(
  574. 0 => '您设置的密码只能使用数字和大小写字母组成,请修改!',
  575. 1 => 'tools.php密码少于6位,请重新修改tools.php中密码。',
  576. 2 => '密码中必须含有数字,请重新修改tools.php中密码。',
  577. 3 => '密码中必须含有字母,请重新修改tools.php中密码。',
  578. 4 => '密码中必须含有大写字母,请重新修改tools.php中密码。',
  579. 5 => '密码中必须含有小写字母,请重新修改tools.php中密码。',
  580. 6 => '没有设置密码,请使用FTP或者直接编辑论坛根目录下的 tools.php 文件,并根据文件中的说明设置密码',
  581. 7 => '不能使用密码示范中的的 DiscuzX3 为密码',
  582. );
  583. if(empty($password))
  584. return $errormsg[6];
  585. if(!ctype_alnum($password))
  586. return $errormsg[0];
  587. if(strlen($password) < 6)
  588. return $errormsg[1];
  589. if($password === 'DiscuzX3'){
  590. return $errormsg[7];
  591. }
  592. $pw_array = str_split($password);
  593. $is_upper = false;
  594. $is_lower = false;
  595. $is_char = false;
  596. $is_digit = false;
  597. foreach( $pw_array as $a) {
  598. if(ctype_digit($a)) {
  599. $is_digit = true;
  600. } else {
  601. $is_char = true;
  602. if(ctype_lower($a))
  603. $is_lower = true;
  604. if(ctype_upper($a))
  605. $is_upper = true;
  606. }
  607. }
  608. if(!$is_digit)
  609. return $errormsg[2];
  610. if(!$is_char)
  611. return $errormsg[3];
  612. if(!$is_upper)
  613. return $errormsg[4];
  614. if(!$is_lower)
  615. return $errormsg[5];
  616. return false;
  617. }
  618. //去掉slassh
  619. function tstripslashes($string) {
  620. if(empty($string)) return $string;
  621. if(is_array($string)) {
  622. foreach($string as $key => $val) {
  623. $string[$key] = tstripslashes($val);
  624. }
  625. } else {
  626. $string = stripslashes($string);
  627. }
  628. return $string;
  629. }
  630. function thash() {
  631. return substr(md5(substr(time(), 0, -4).TOOLS_ROOT), 16);
  632. }
  633. function taddslashes($string, $force = 1) {
  634. if(is_array($string)) {
  635. foreach($string as $key => $val) {
  636. $string[$key] = taddslashes($val, $force);
  637. }
  638. } else {
  639. $string = addslashes($string);
  640. }
  641. return $string;
  642. }
  643. //显示
  644. function show_msg($message, $url_forward='', $time = 1, $noexit = 0) {
  645. show_header();
  646. show_msg_body($message, $url_forward, $time, $noexit);
  647. show_footer();
  648. !$noexit && exit();
  649. }
  650. function show_msg_body($message, $url_forward='', $time = 1, $noexit = 0) {
  651. if($url_forward) {
  652. $url_forward = $_GET['from'] ? $url_forward.'&from='.rawurlencode($_GET['from']) : $url_forward;
  653. $message = "<a href=\"$url_forward\">$message (跳转中...)</a><script>setTimeout(\"window.location.href ='$url_forward';\", $time);</script>";
  654. }else{
  655. $message = "<a href=\"$url_forward\">$message </a>";
  656. }
  657. print<<<END
  658. <table>
  659. <tr><td>$message</td></tr>
  660. </table>
  661. END;
  662. }
  663. function login_page() {
  664. show_header();
  665. $formhash = thash();
  666. print<<<END
  667. <span>急诊箱登录</span>
  668. <form action="tools.php?action=login" method="post">
  669. <table class="specialtable">
  670. <tr>
  671. <td width="20%"><input class="textinput" type="password" name="toolpassword"></input></td>
  672. <td><input class="specialsubmit" type="submit" value="登 录"></input></td>
  673. </tr>
  674. </table>
  675. <input type="hidden" name="action" value="login">
  676. <input type="hidden" name="formhash" value="{$formhash}">
  677. </form>
  678. END;
  679. show_footer();
  680. }
  681. function show_header() {
  682. $_GET['action'] = htmlspecialchars($_GET['action']);
  683. $nowarr = array($_GET['action'] => ' class="current"');
  684. print<<<END
  685. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  686. <html xmlns="http://www.w3.org/1999/xhtml">
  687. <head>
  688. <meta http-equiv="Content-Type" content="text/html; charset=gbk" />
  689. <title>Discuz! X3 急诊箱</title>
  690. <style type="text/css">
  691. * {font-size:12px; font-family: Verdana, Arial, Helvetica, sans-serif; line-height: 1.5em; word-break: break-all; }
  692. body { text-align:center; margin: 0; padding: 0; background: #F5FBFF; }
  693. .bodydiv { margin: 40px auto 0; width:820px; text-align:left; border: solid #86B9D6; border-width: 5px 1px 1px; background: #FFF; }
  694. h1 { font-size: 18px; margin: 1px 0 0; line-height: 50px; height: 50px; background: #E8F7FC; color: #5086A5; padding-left: 10px; }
  695. #menu {width: 100%; margin: 10px auto; text-align: center; }
  696. #menu td { height: 30px; line-height: 30px; color: #999; border-bottom: 3px solid #EEE; }
  697. .current { font-weight: bold; color: #090 !important; border-bottom-color: #F90 !important; }
  698. input { border: 1px solid #B2C9D3; padding: 5px; background: #F5FCFF; }
  699. #footer { font-size: 10px; line-height: 40px; background: #E8F7FC; text-align: center; height: 38px; overflow: hidden; color: #5086A5; margin-top: 20px; }
  700. table {width:100%;font-size:12px;margin-top:5px;}
  701. table.specialtable,table.specialtable td {border:0;}
  702. td,th {padding:5px;text-align:left;}
  703. caption {font-weight:bold;padding:8px 0;color:#3544FF;text-align:left;}
  704. th {background:#E8F7FC;font-weight:600;}
  705. td.specialtd {text-align:left;}
  706. #setadmin {margin: 0px;}
  707. .textarea {height: 80px;width: 400px;padding: 3px;margin: 5px;}
  708. </style>
  709. </head>
  710. <body>
  711. <div class="bodydiv">
  712. <h1>Discuz! X3 急诊箱</h1><br/>
  713. <div style="width:90%;margin:0 auto;">
  714. <table id="menu">
  715. <tr>
  716. <td{$nowarr[index]}><a href="?action=index">首页</a></td>
  717. <td{$nowarr[setadmin]}><a href="?action=setadmin">重置管理员帐号</a></td>
  718. <td{$nowarr[closesite]}><a href="?action=closesite">开启关闭站点</a></td>
  719. <td{$nowarr[closeplugin]}><a href="?action=closeplugin">一键关闭插件</a></td>
  720. <td{$nowarr[repairdb]}><a href="?action=repairdb">修复数据库</a></td>
  721. <td{$nowarr[restoredb]}><a href="?action=restoredb">恢复数据库</a></td>
  722. <td{$nowarr[updatecache]}><a href="?action=updatecache">更新缓存</a></td>
  723. <td{$nowarr[logout]}><a href="?action=logout">退出</a></td>
  724. </tr>
  725. </table>
  726. <br>
  727. END;
  728. }
  729. //页面顶部
  730. function show_footer() {
  731. global $tools_versions;
  732. print<<<END
  733. </div>
  734. <div id="footer">Powered by {$tools_versions} &copy; Comsenz Inc. 2001-2013 <a href="http://www.comsenz.com" target="_blank">http://www.comsenz.com</a></div>
  735. </div>
  736. <br>
  737. </body>
  738. </html>
  739. END;
  740. }
  741. //登录判断函数
  742. function is_login() {
  743. $error = false;
  744. $errormsg = array();
  745. global $tpassword;
  746. if($errormsg = checkpassword($tpassword)) {
  747. show_msg($errormsg);
  748. }
  749. if(isset($_COOKIE['toolsauth'])) {
  750. if($_COOKIE['toolsauth'] === md5($tpassword.thash())) {
  751. return TRUE;
  752. }
  753. }
  754. $lockfile = TOOLS_ROOT.'data/tools.lock';
  755. if(@file_exists($lockfile)) {
  756. $errormsg = "急救箱已经锁定,请您先登录服务器ftp,手工删除 ./data/tools.lock 文件,再次重新使用急救箱。";
  757. show_msg($errormsg);
  758. }
  759. if ( $_GET['action'] === 'login') {
  760. $formhash = $_GET['formhash'];
  761. if($formhash !== thash()) {
  762. show_msg('您的请求来路不正或者输入密码超时,请刷新页面后重新输入正确密码!');
  763. }
  764. $toolsmd5 = md5($tpassword.thash());
  765. if(md5($_GET['toolpassword'].thash()) == $toolsmd5) {
  766. tsetcookie('toolsauth', $toolsmd5, time()+'3600', '', false, '','');
  767. $lockfile = TOOLS_ROOT.'data/tools.lock';
  768. if(@$fp = fopen($lockfile, 'w')) {
  769. fwrite($fp, ' ');
  770. fclose($fp);
  771. }
  772. show_msg('登陆成功!', 'tools.php?action=index', 2000);
  773. } else {
  774. show_msg( '您输入的密码不正确,请重新输入正确密码!', 'tools.php', 2000);
  775. }
  776. } else {
  777. return FALSE;
  778. }
  779. }
  780. //登录成功设置cookie
  781. function tsetcookie($var, $value = '', $life = 0, $prefix = '', $httponly = false, $cookiepath, $cookiedomain) {
  782. $var = (empty($prefix) ? '' : $prefix).$var;
  783. $_COOKIE[$var] = $value;
  784. if($value == '' || $life < 0) {
  785. $value = '';
  786. $life = -1;
  787. }
  788. $path = $httponly && PHP_VERSION < '5.2.0' ? $cookiepath.'; HttpOnly' : $cookiepath;
  789. $secure = $_SERVER['SERVER_PORT'] == 443 ? 1 : 0;
  790. if(PHP_VERSION < '5.2.0') {
  791. $r = setcookie($var, $value, $life);
  792. } else {
  793. $r = setcookie($var, $value, $life);
  794. }
  795. }
  796. /*
  797. T 类
  798. tools.php 主要类
  799. */
  800. class T{
  801. var $dbconfig = null;
  802. var $ucdbconfig = null;
  803. var $db = null;
  804. var $ucdb = null;
  805. // 是否已经初始化
  806. var $initated = false;
  807. public function init() {
  808. if(!$this->initated) {
  809. $this->_init_config();
  810. $this->_init_db();
  811. }
  812. $this->initated = true;
  813. }
  814. public function db_runquery($sql) {
  815. $tablepre = $this->dbconfig['tablepre'];
  816. $dbcharset = $this->dbconfig['charset'];
  817. if(!isset($sql) || empty($sql)) return;
  818. $sql = str_replace("\r", "\n", str_replace(array(' {tablepre}', ' cdb_', ' `cdb_', ' pre_', ' `pre_'), array(' '.$tablepre, ' '.$tablepre, ' `'.$tablepre, ' '.$tablepre, ' `'.$tablepre), $sql));
  819. $ret = array();
  820. $num = 0;
  821. foreach(explode(";\n", trim($sql)) as $query) {
  822. $ret[$num] = '';
  823. $queries = explode("\n", trim($query));
  824. foreach($queries as $query) {
  825. $ret[$num] .= (isset($query[0]) && $query[0] == '#') || (isset($query[1]) && isset($query[1]) && $query[0].$query[1] == '--') ? '' : $query;
  826. }
  827. $num++;
  828. }
  829. unset($sql);
  830. $this->connect_db();
  831. foreach($ret as $query) {
  832. $query = trim($query);
  833. if($query) {
  834. if(substr($query, 0, 12) == 'CREATE TABLE') {
  835. $name = preg_replace("/CREATE TABLE ([a-z0-9_]+) .*/is", "\\1", $query);
  836. mysql_query($this->db_createtable($query, $dbcharset), $this->db);
  837. } else {
  838. mysql_query($query, $this->db);
  839. }
  840. }
  841. }
  842. return 1;
  843. }
  844. public function db_createtable($sql, $dbcharset) {
  845. $type = strtoupper(preg_replace("/^\s*CREATE TABLE\s+.+\s+\(.+?\).*(ENGINE|TYPE)\s*=\s*([a-z]+?).*$/isU", "\\2", $sql));
  846. $type = in_array($type, array('MYISAM', 'HEAP')) ? $type : 'MYISAM';
  847. return preg_replace("/^\s*(CREATE TABLE\s+.+\s+\(.+?\)).*$/isU", "\\1", $sql).(mysql_get_server_info() > '4.1' ? " ENGINE=$type DEFAULT CHARSET=$dbcharset" : " TYPE=$type");
  848. }
  849. public function connect_db($type = 'db') {
  850. if($type == 'db') {
  851. $dbhost = $this->dbconfig['host'];
  852. $dbuser = $this->dbconfig['user'];
  853. $dbpw = $this->dbconfig['pw'];
  854. $dbname = $this->dbconfig['name'];
  855. $dbcharset = $this->dbconfig['charset'];
  856. } else {
  857. $dbhost = $this->ucdbconfig['host'];
  858. $dbuser = $this->ucdbconfig['user'];
  859. $dbpw = $this->ucdbconfig['pw'];
  860. $dbname = $this->ucdbconfig['name'];
  861. $dbcharset = $this->ucdbconfig['charset'];
  862. }
  863. if(!$this->db = mysql_connect($dbhost, $dbuser, $dbpw, 1))
  864. show_msg('Discuz! X数据库连接出错,请检查config_global.php中数据库相关信息是否正确,与数据库服务器网络连接是否正常');
  865. $dbversion = mysql_get_server_info($this->db);
  866. if($dbversion > '4.1') {
  867. if($dbcharset) {
  868. mysql_query("SET character_set_connection=".$dbcharset.", character_set_results=".$dbcharset.", character_set_client=binary", $this->db);
  869. }
  870. if($dbversion > '5.0.1') {
  871. mysql_query("SET sql_mode=''", $this->db);
  872. }
  873. }
  874. @mysql_select_db($dbname, $this->db);
  875. }
  876. public function close_db() {
  877. mysql_close($this->db);
  878. }
  879. private function _init_config() {
  880. $error = false;
  881. $_config = array();
  882. global $tpassword;
  883. if($errormsg = checkpassword($tpassword)) {
  884. $error = true;
  885. }
  886. @include TOOLS_ROOT.'config/config_global.php';
  887. if(empty($_config)) {
  888. $error = true;
  889. $errormsg = '没有找到config文件,请检查 /config/config_global.php 是否存在或有读权限!';
  890. }
  891. $uc_config_file = TOOLS_ROOT.'config/config_ucenter.php';
  892. if(!@file_exists($uc_config_file)) {
  893. $error = true;
  894. $errormsg = '没有找到uc config文件,请检查 /config/config_ucenter.php 是否存在或有读权限!';
  895. }
  896. @include $uc_config_file;
  897. if($error) {
  898. show_msg($errormsg);
  899. }
  900. $this->config = & $_config;
  901. $this->config['dbcharset'] = $_config['db']['1']['dbcharset'];
  902. $this->config['charset'] = $_config['output']['charset'];
  903. }
  904. private function _init_db() {
  905. $this->dbconfig['host'] = $this->config['db']['1']['dbhost'];
  906. $this->dbconfig['user'] = $this->config['db']['1']['dbuser'];
  907. $this->dbconfig['pw'] = $this->config['db']['1']['dbpw'];
  908. $this->dbconfig['name'] = $this->config['db']['1']['dbname'];
  909. $this->dbconfig['charset'] = $this->config['db']['1']['dbcharset'];
  910. $this->dbconfig['tablepre'] = $this->config['db']['1']['tablepre'];
  911. $this->ucdbconfig['host'] = UC_DBHOST;
  912. $this->ucdbconfig['user'] = UC_DBUSER;
  913. $this->ucdbconfig['pw'] = UC_DBPW;
  914. $this->ucdbconfig['name'] = UC_DBNAME;
  915. $this->ucdbconfig['charset'] = UC_DBCHARSET;
  916. $this->ucdbconfig['tablepre'] = UC_DBTABLEPRE;
  917. $this->connect_db();
  918. $sql = "SHOW FULL PROCESSLIST";
  919. $query = mysql_query($sql, $this->db);
  920. $waiting = false;
  921. $waiting_msg = '';
  922. while($l = mysql_fetch_array($query, MYSQL_ASSOC)) {
  923. if($l['State'] == 'Checking table') {
  924. $this->close_db();
  925. $waiting = true;
  926. $waiting_msg = '正在检查表,请稍后...';
  927. } elseif($l['State'] == 'Repair by sorting') {
  928. $this->close_db();
  929. $waiting = true;
  930. $waiting_msg = '正在修复表,请稍后...';
  931. }
  932. }
  933. if($waiting) {
  934. show_msg($waiting_msg, 'tools.php?action=repairdb', 3000);
  935. }
  936. }
  937. }
  938. //T class 结束
  939. /**
  940. * End of the tools.php
  941. */