PageRenderTime 66ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 1ms

/tools.php

https://bitbucket.org/luxi78/fengyu
PHP | 3204 lines | 3074 code | 88 blank | 42 comment | 667 complexity | f3b68139b43e4fe92263b1622dac3226 MD5 | raw file
Possible License(s): LGPL-2.1

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /*
  3. [Discuz!] Tools (C)2001-2008 Comsenz Inc.
  4. This is NOT a freeware, use is subject to license terms
  5. $Id: tools.php 1193 2010-01-20 09:35:41Z songlixin $
  6. */
  7. /********************** ????? ??*******************************/
  8. $tool_password = ''; // ?????? ???????????????????????????
  9. /********************** ????? ??*******************************/
  10. error_reporting(E_ERROR | E_PARSE); //E_ERROR | E_WARNING | E_PARSE | E_ALL
  11. @set_time_limit(0);
  12. define('TOOLS_ROOT', dirname(__FILE__)."/");
  13. define('VERSION', '2009');
  14. define('Release','100120');
  15. $functionall = array(
  16. array('all', 'all_repair', '????????', '???????????????'),
  17. array('all', 'all_runquery', '????(SQL)', '??????SQL???????'),
  18. array('all', 'all_checkcharset', '??????', '????????????????'),
  19. array('all', 'all_config', '??????', '????????'),
  20. array('all', 'all_restore', '???????', '?????????'),
  21. array('all', 'all_setadmin', '?????', '?????????????????????????'),
  22. array('dz', 'dz_filecheck', '????', '???????????Discuz!?????'),
  23. array('dz', 'dz_rplastpost', '??????', '?????????'),
  24. array('dz', 'dz_rpthreads', '??????', '???????????????????????????????'),
  25. array('dz', 'dz_mysqlclear', '???????', '??????????????????????'),
  26. array('dz', 'dz_moveattach', '??????', '???????????????????????????????'),
  27. array('dz_uch', 'uch_dz_replace', '??????', '??????????????????????????,??????????????'),
  28. array('all', 'all_updatecache', '<font color=red>????</font>', '?????'),
  29. );
  30. $toolbar = array(
  31. array('phpinfo','INFO'),
  32. array('datago','??'),
  33. array('all_logout','??'),
  34. );
  35. //???
  36. $plustitle = '';
  37. $lockfile = '';
  38. //??????????getplace()?????
  39. $docdir = '';
  40. $action = '';
  41. $target_fsockopen = '0';
  42. $alertmsg = ' onclick="alert(\'????????,????????,???\');"';
  43. foreach(array('_COOKIE', '_POST', '_GET') as $_request) {
  44. foreach($$_request as $_key => $_value) {
  45. ($_key{0} != '_' && $_key != 'tool_password' && $_key != 'lockfile') && $$_key = taddslashes($_value);
  46. }
  47. }
  48. $whereis = getplace();
  49. require_once $cfgfile;
  50. if($whereis == 'is_dz' && !defined('DISCUZ_ROOT')) {
  51. define('DISCUZ_ROOT', TOOLS_ROOT);
  52. }
  53. if(!$whereis && !in_array($whereis, array('is_dz', 'is_uc', 'is_uch', 'is_ss'))) {
  54. $alertmsg = '';
  55. errorpage('<ul><li>???????Discuz!?UCenter?UCente Home?SupeSite????????????</li><li>?????????????????????????????config???????????</li>');
  56. }
  57. if(@file_exists($lockfile)) {
  58. $alertmsg = '';
  59. errorpage("<h6>??????????????? FTP ?? $lockfile ????? </h6>");
  60. } elseif($tool_password == '') {
  61. $alertmsg = '';
  62. errorpage('<h6>????????????????????????$tool_password?????</h6>');
  63. }
  64. if($action == 'login') {
  65. setcookie('toolpassword',md5($toolpassword), 0);
  66. echo '<meta http-equiv="refresh" content="2 url=?">';
  67. errorpage("<h6>??????????</h6>");
  68. }
  69. if(isset($toolpassword)) {
  70. if($toolpassword != md5($tool_password)) {
  71. $alertmsg = '';
  72. errorpage("login");
  73. }
  74. } else {
  75. $alertmsg = '';
  76. errorpage("login");
  77. }
  78. getdbcfg();
  79. $mysql = mysql_connect($dbhost, $dbuser, $dbpw);
  80. mysql_select_db($dbname);
  81. $my_version = mysql_get_server_info();
  82. if($my_version > '4.1') {
  83. $serverset = $dbcharset ? 'character_set_connection='.$dbcharset.', character_set_results='.$dbcharset.', character_set_client=binary' : '';
  84. $serverset .= $my_version > '5.0.1' ? ((empty($serverset))? '' : ',').'sql_mode=\'\'' : '';
  85. $serverset && mysql_query("SET $serverset");
  86. }
  87. //????
  88. if($action == 'all_repair') {
  89. $counttables = $oktables = $errortables = $rapirtables = 0;
  90. $doc = $docdir.'/repaireport.txt';
  91. if($check) {
  92. $tables = mysql_query("SHOW TABLES");
  93. if($iterations) {
  94. $iterations --;
  95. }
  96. while($table = mysql_fetch_row($tables)) {
  97. $counttables += 1;
  98. $answer = checktable($table[0],$iterations,$doc);
  99. }
  100. if($simple) {
  101. htmlheader();
  102. echo '<h4>???????</h4>
  103. <h5>????:</h5>
  104. <table>
  105. <tr><th>???(?)</th><th>???(?)</th><th>????(?)</th><th>??(?)</th></tr>
  106. <tr><td>'.$counttables.'</td><td>'.$oktables.'</td><td>'.$rapirtables.'</td><td>'.$errortables.'</td></tr>
  107. </table>
  108. <p>????????????????????????</p>
  109. <p><b><a href="tools.php?action=all_repair">????</a>&nbsp;&nbsp;&nbsp;&nbsp;<b><a href="'.$doc.'">????</a>&nbsp;&nbsp;&nbsp;&nbsp;<a href="tools.php">????</a></b></p>
  110. </td></tr></table>';
  111. specialdiv();
  112. }
  113. } else {
  114. htmlheader();
  115. @unlink($doc);
  116. echo "<h4>???????</h4>
  117. <div class='specialdiv'>
  118. ?????
  119. <ul>
  120. <li>??????????????????????????????????</li>
  121. <li>??????????????????????????????????(?? MySQL 3.23+)</li>
  122. </ul>
  123. </div>
  124. <h5>???</h5>
  125. <ul>
  126. <li><a href=\"?action=all_repair&check=1&simple=1\">??????????1?</a>
  127. <li><a href=\"?action=all_repair&check=1&iterations=5&simple=1\">??????????5?</a> (????????????????????????????)
  128. </ul>";
  129. specialdiv();
  130. }
  131. htmlfooter();
  132. } elseif($action == 'all_restore') {//???????
  133. ob_implicit_flush();
  134. $backdirarray = array( //??????????????????
  135. 'is_dz' => 'forumdata',
  136. 'is_uc' => 'data/backup',
  137. 'is_uch' => 'data',
  138. 'is_ss' => 'data'
  139. );
  140. if(!get_cfg_var('register_globals')) {
  141. @extract($HTTP_GET_VARS);
  142. }
  143. $sqldump = '';
  144. htmlheader();
  145. ?><h4>????????? </h4><?php
  146. echo "<div class=\"specialdiv\">?????<ul>
  147. <li>??????????(?????)??????,????????????,?? FTP ??</li>
  148. <li>??????? Discuz! ????,???????? PHP ????</li>
  149. <li>??????????????,?????.?????(?? 10 ??)???,???</li></ul></div>";
  150. if($file) {
  151. if(!mysql_select_db($dbname)) {
  152. mysql_query("CREATE DATABASE $dbname;");
  153. }
  154. if(strtolower(substr($file, 0, 7)) == "http://") {
  155. echo "?????????? - ??????:<br><br>";
  156. echo "?????????? ... ";
  157. $sqldump = @fread($fp, 99999999);
  158. @fclose($fp);
  159. if($sqldump) {
  160. echo "??<br><br>";
  161. } elseif(!$multivol) {
  162. cexit("??<br><br><b>??????</b>");
  163. }
  164. } else {
  165. echo "<div class=\"specialtext\">??????? - ??????:<br><br>";
  166. if(file_exists($file)) {
  167. echo "???? $file ???? ... ??<br><br>";
  168. } elseif(!$multivol) {
  169. cexit("???? $file ???? ... ??<br><br><br><b>??????</b></div>");
  170. }
  171. if(is_readable($file)) {
  172. echo "???? $file ???? ... ??<br><br>";
  173. @$fp = fopen($file, "r");
  174. @flock($fp, 3);
  175. $sqldump = @fread($fp, filesize($file));
  176. @fclose($fp);
  177. echo "??????? ... ??<br><br>";
  178. } elseif(!$multivol) {
  179. cexit("???? $file ???? ... ??<br><br><br><b>??????</b></div>");
  180. }
  181. }
  182. if($multivol && !$sqldump) {
  183. cexit("???????? ... ??<br><br><b>???,??????????!????,????????.</b></div>");
  184. }
  185. echo "???? $file ???? ... ";
  186. if($whereis == 'is_uc') {
  187. $identify = explode(',', base64_decode(preg_replace("/^# Identify:\s*(\w+).*/s", "\\1", substr($sqldump, 0, 256))));
  188. $method = 'multivol';
  189. $volume = $identify[4];
  190. } else {
  191. @list(,,,$method, $volume) = explode(',', base64_decode(preg_replace("/^# Identify:\s*(\w+).*/s", "\\1", preg_replace("/^(.+)/", "\\1", substr($sqldump, 0, 256)))));
  192. }
  193. if($method == 'multivol' && is_numeric($volume)) {
  194. echo "??<br><br>";
  195. } else {
  196. cexit("??<br><br><b>??? Discuz! ??????,????</b></div>");
  197. }
  198. if($onlysave == "yes") {
  199. echo "????????????? ... ";
  200. $filename = TOOLS_ROOT.'./'.$backdirarray[$whereis].strrchr($file, "/");
  201. @$filehandle = fopen($filename, "w");
  202. @flock($filehandle, 3);
  203. if(@fwrite($filehandle, $sqldump)) {
  204. @fclose($filehandle);
  205. echo "??<br><br>";
  206. } else {
  207. @fclose($filehandle);
  208. die("??<br><br><b>??????</b>");
  209. }
  210. echo "??<br><br><b>???,?????????????? <a href=\"".strstr($filename, "/")."\">$filename</a>.????,????????.</b></div>";
  211. } else {
  212. $sqlquery = splitsql($sqldump);
  213. echo "?????? ... ??<br><br>";
  214. unset($sqldump);
  215. echo "??????,??? ... </div>";
  216. foreach($sqlquery as $sql) {
  217. $dbversion = mysql_get_server_info();
  218. $sql = syntablestruct(trim($sql), $dbversion > '4.1', $dbcharset);
  219. if(trim($sql)) {
  220. @mysql_query($sql);
  221. }
  222. }
  223. if($auto == 'off') {
  224. $nextfile = str_replace("-$volume.sql", '-'.($volume + 1).'.sql', $file);
  225. cexit("<ul><li>???? <b>$volume#</b> ????,?????????????????</li><li>???<b><a href=\"?action=all_restore&file=$nextfile&multivol=yes\">????</a></b> ?????????????<b><a href=\"?action=all_restore&file=$nextfile&multivol=yes&auto=off\">??????????</a></b></li></ul>");
  226. } else {
  227. $nextfile = str_replace("-$volume.sql", '-'.($volume + 1).'.sql', $file);
  228. echo "<ul><li>???? <b>$volume#</b> ????,???????????????.</li><li><b>???????????????</b></li></ul>";
  229. redirect("?action=all_restore&file=$nextfile&multivol=yes");
  230. }
  231. }
  232. } else {
  233. $exportlog = array();
  234. if(is_dir(TOOLS_ROOT.'./'.$backdirarray[$whereis])) {
  235. $dir = dir(TOOLS_ROOT.'./'.$backdirarray[$whereis]);
  236. while($entry = $dir->read()) {
  237. $entry = "./".$backdirarray[$whereis]."/$entry";
  238. if(is_file($entry) && preg_match("/\.sql/i", $entry)) {
  239. $filesize = filesize($entry);
  240. $fp = @fopen($entry, 'rb');
  241. @$identify = explode(',', base64_decode(preg_replace("/^# Identify:\s*(\w+).*/s", "\\1", fgets($fp, 256))));
  242. @fclose ($fp);
  243. if(preg_match("/\-1.sql/i", $entry) || $identify[3] == 'shell') {
  244. $exportlog[$identify[0]] = array( 'version' => $identify[1],
  245. 'type' => $identify[2],
  246. 'method' => $identify[3],
  247. 'volume' => $identify[4],
  248. 'filename' => $entry,
  249. 'size' => $filesize);
  250. }
  251. } elseif(is_dir($entry) && preg_match("/backup\_/i", $entry)) {
  252. $bakdir = dir($entry);
  253. while($bakentry = $bakdir->read()) {
  254. $bakentry = "$entry/$bakentry";
  255. if(is_file($bakentry)) {
  256. @$fp = fopen($bakentry, 'rb');
  257. @$bakidentify = explode(',', base64_decode(preg_replace("/^# Identify:\s*(\w+).*/s", "\\1", fgets($fp, 256))));
  258. @fclose ($fp);
  259. if(preg_match("/\-1\.sql/i", $bakentry) || $bakidentify[3] == 'shell') {
  260. $identify['bakentry'] = $bakentry;
  261. }
  262. }
  263. }
  264. if(preg_match("/backup\_/i", $entry)) {
  265. $exportlog[filemtime($entry)] = array( 'version' => $bakidentify[1],
  266. 'type' => $bakidentify[2],
  267. 'method' => $bakidentify[3],
  268. 'volume' => $bakidentify[4],
  269. 'bakentry' => $identify['bakentry'],
  270. 'filename' => $entry);
  271. }
  272. }
  273. }
  274. $dir->close();
  275. } else {
  276. echo 'error';
  277. }
  278. krsort($exportlog);
  279. reset($exportlog);
  280. $title = '<h5><a href="?action=all_restore">??????</a>';
  281. if($dz_version >= 700 || $whereis == 'is_uc' || $whereis == 'is_uch' || $ss_version >= 70) {
  282. $title .= '&nbsp;&nbsp;&nbsp;<a href="?action=all_backup&begin=1">??????</a></h5>';
  283. } else {
  284. $title .= '</h5>';
  285. }
  286. $exportinfo = $title.'<table><caption>&nbsp;&nbsp;&nbsp;??????</caption><tr><th>????</th><th>??</th><th>??</th><th>??</th><th>??</th><th>??</th></tr>';
  287. foreach($exportlog as $dateline => $info) {
  288. $info['dateline'] = is_int($dateline) ? gmdate("Y-m-d H:i", $dateline + 8*3600) : '??';
  289. switch($info['type']) {
  290. case 'full':
  291. $info['type'] = '????';
  292. break;
  293. case 'standard':
  294. $info['type'] = '????(??)';
  295. break;
  296. case 'mini':
  297. $info['type'] = '????';
  298. break;
  299. case 'custom':
  300. $info['type'] = '?????';
  301. break;
  302. }
  303. $info['volume'] = $info['method'] == 'multivol' ? $info['volume'] : '';
  304. $info['method'] = $info['method'] == 'multivol' ? '??' : 'shell';
  305. $info['url'] = str_replace(".sql", '', str_replace("-$info[volume].sql", '', substr(strrchr($info['filename'], "/"), 1)));
  306. $exportinfo .= "<tr>\n".
  307. "<td>".$info['url']."</td>\n".
  308. "<td>$info[version]</td>\n".
  309. "<td>$info[dateline]</td>\n".
  310. "<td>$info[type]</td>\n";
  311. if($info['bakentry']) {
  312. $exportinfo .= "<td><a href=\"?action=all_restore&bakdirname=".$info['url']."\">??</a></td>\n".
  313. "<td><a href=\"?action=all_restore&file=$info[bakentry]&importsubmit=yes\">[????]</a></td>\n</tr>\n";
  314. } else {
  315. $exportinfo .= "<td><a href=\"?action=all_restore&filedirname=".$info['url']."\">??</a></td>\n".
  316. "<td><a href=\"?action=all_restore&file=$info[filename]&importsubmit=yes\">[????]</a></td>\n</tr>\n";
  317. }
  318. }
  319. $exportinfo .= '</table>';
  320. echo $exportinfo;
  321. unset($exportlog);
  322. unset($exportinfo);
  323. echo "<br>";
  324. //??????????????????
  325. if(!empty($filedirname)) {
  326. $exportlog = array();
  327. if(is_dir(TOOLS_ROOT.'./'.$backdirarray[$whereis])) {
  328. $dir = dir(TOOLS_ROOT.'./'.$backdirarray[$whereis]);
  329. while($entry = $dir->read()) {
  330. $entry = "./".$backdirarray[$whereis]."/$entry";
  331. if(is_file($entry) && preg_match("/\.sql/i", $entry) && preg_match("/$filedirname/i", $entry)) {
  332. $filesize = filesize($entry);
  333. @$fp = fopen($entry, 'rb');
  334. @$identify = explode(',', base64_decode(preg_replace("/^# Identify:\s*(\w+).*/s", "\\1", fgets($fp, 256))));
  335. @fclose ($fp);
  336. $exportlog[$identify[0]] = array( 'version' => $identify[1],
  337. 'type' => $identify[2],
  338. 'method' => $identify[3],
  339. 'volume' => $identify[4],
  340. 'filename' => $entry,
  341. 'size' => $filesize);
  342. }
  343. }
  344. $dir->close();
  345. }
  346. krsort($exportlog);
  347. reset($exportlog);
  348. $exportinfo = '<table>
  349. <caption>&nbsp;&nbsp;&nbsp;???????</caption>
  350. <tr>
  351. <th>???</th><th>??</th>
  352. <th>??</th><th>??</thd>
  353. <th>??</th><td>??</th>
  354. <th>??</th><th>??</th></tr>';
  355. foreach($exportlog as $dateline => $info) {
  356. $info['dateline'] = is_int($dateline) ? gmdate("Y-m-d H:i", $dateline + 8*3600) : '??';
  357. switch($info['type']) {
  358. case 'full':
  359. $info['type'] = '????';
  360. break;
  361. case 'standard':
  362. $info['type'] = '????(??)';
  363. break;
  364. case 'mini':
  365. $info['type'] = '????';
  366. break;
  367. case 'custom':
  368. $info['type'] = '?????';
  369. break;
  370. }
  371. $info['volume'] = $info['method'] == 'multivol' ? $info['volume'] : '';
  372. $info['method'] = $info['method'] == 'multivol' ? '??' : 'shell';
  373. $exportinfo .= "<tr>\n".
  374. "<td><a href=\"$info[filename]\" name=\"".substr(strrchr($info['filename'], "/"), 1)."\">".substr(strrchr($info['filename'], "/"), 1)."</a></td>\n".
  375. "<td>$info[version]</td>\n".
  376. "<td>$info[dateline]</td>\n".
  377. "<td>$info[type]</td>\n".
  378. "<td>".get_real_size($info[size])."</td>\n".
  379. "<td>$info[method]</td>\n".
  380. "<td>$info[volume]</td>\n".
  381. "<td><a href=\"?action=all_restore&file=$info[filename]&importsubmit=yes&auto=off\">[??]</a></td>\n</tr>\n";
  382. }
  383. $exportinfo .= '</table>';
  384. echo $exportinfo;
  385. }
  386. // ????????????? ??????????????????
  387. if(!empty($bakdirname)) {
  388. $exportlog = array();
  389. $filedirname = TOOLS_ROOT.'./'.$backdirarray[$whereis].'/'.$bakdirname;
  390. if(is_dir($filedirname)) {
  391. $dir = dir($filedirname);
  392. while($entry = $dir->read()) {
  393. $entry = $filedirname.'/'.$entry;
  394. if(is_file($entry) && preg_match("/\.sql/i", $entry)) {
  395. $filesize = filesize($entry);
  396. @$fp = fopen($entry, 'rb');
  397. @$identify = explode(',', base64_decode(preg_replace("/^# Identify:\s*(\w+).*/s", "\\1", fgets($fp, 256))));
  398. @fclose ($fp);
  399. $exportlog[$identify[0]] = array(
  400. 'version' => $identify[1],
  401. 'type' => $identify[2],
  402. 'method' => $identify[3],
  403. 'volume' => $identify[4],
  404. 'filename' => $entry,
  405. 'size' => $filesize);
  406. }
  407. }
  408. $dir->close();
  409. }
  410. krsort($exportlog);
  411. reset($exportlog);
  412. $exportinfo = '<table>
  413. <caption>&nbsp;&nbsp;&nbsp;???????</caption>
  414. <tr>
  415. <th>???</th><th>??</th>
  416. <th>??</th><th>??</th>
  417. <th>??</th><th>??</th>
  418. <th>??</th><th>??</th></tr>';
  419. foreach($exportlog as $dateline => $info) {
  420. $info['dateline'] = is_int($dateline) ? gmdate("Y-m-d H:i", $dateline + 8*3600) : '??';
  421. switch($info['type']) {
  422. case 'full':
  423. $info['type'] = '????';
  424. break;
  425. case 'standard':
  426. $info['type'] = '????(??)';
  427. break;
  428. case 'mini':
  429. $info['type'] = '????';
  430. break;
  431. case 'custom':
  432. $info['type'] = '?????';
  433. break;
  434. }
  435. $info['volume'] = $info['method'] == 'multivol' ? $info['volume'] : '';
  436. $info['method'] = $info['method'] == 'multivol' ? '??' : 'shell';
  437. $exportinfo .= "<tr>\n".
  438. "<td><a href=\"$info[filename]\" name=\"".substr(strrchr($info['filename'], "/"), 1)."\">".substr(strrchr($info['filename'], "/"), 1)."</a></td>\n".
  439. "<td>$info[version]</td>\n".
  440. "<td>$info[dateline]</td>\n".
  441. "<td>$info[type]</td>\n".
  442. "<td>".get_real_size($info[size])."</td>\n".
  443. "<td>$info[method]</td>\n".
  444. "<td>$info[volume]</td>\n".
  445. "<td><a href=\"?action=all_restore&file=$info[filename]&importsubmit=yes&auto=off\">[??]</a></td>\n</tr>\n";
  446. }
  447. $exportinfo .= '</table>';
  448. echo $exportinfo;
  449. }
  450. echo "<br>";
  451. cexit("");
  452. }
  453. } elseif($action == 'all_runquery') {//??sql
  454. if(!empty($_POST['sqlsubmit']) && $_POST['queries']) {
  455. runquery($queries);
  456. }
  457. htmlheader();
  458. runquery_html();
  459. htmlfooter();
  460. } elseif($action == 'all_checkcharset') {//????
  461. $maincharset = $dbcharset;
  462. $tooltip = '<h4>????</h4>'."<div class=\"specialdiv\">?????<ul>
  463. <li>MySQL???4.1????????????????4.1????????????</li>
  464. <li>????????????????????????????????????????????????</li>
  465. <li>??MySQL???????? <a href='http://www.discuz.net/viewthread.php?tid=1022673' target='_blank'>????</a></li>
  466. <li>????MySQL?????<a href='http://www.discuz.net/viewthread.php?tid=1070306' target='_blank'>??</a></li>
  467. <li><font color=red>??????????????????????????????????????????????????????????????????????????????????</font></li>
  468. <li><font color=red>??????????????????<a href='?action=datago'>??</a>??</font></li>
  469. </ul></div>";
  470. if($my_version > '4.1') {
  471. if($repairsubmit) {
  472. htmlheader();
  473. echo $tooltip;
  474. if(!is_array($repair)) {
  475. $repair=array();
  476. show_tools_message('????????', 'tools.php?action=all_checkcharset');
  477. htmlfooter();
  478. exit;
  479. }
  480. foreach($repair as $key=>$value) {
  481. $tableinfo = '';
  482. $tableinfo = explode('|', $value);
  483. $tablename = $tableinfo[0];
  484. $collation = $tableinfo[1];
  485. $maincharset = $tableinfo[2];
  486. $query = mysql_query("SHOW CREATE TABLE $tablename");
  487. while($createsql = mysql_fetch_array($query)) {
  488. $colationsql = explode(",\n",$createsql[1]);
  489. foreach($colationsql as $numkey => $collsql) {
  490. if(strpos($collsql,'`'.$collation.'`')) {
  491. if(strpos($collsql,'character set') > 0){
  492. $collsql = substr($collsql,0,strpos($collsql,'character set'));
  493. } else {
  494. $collsql = substr($collsql,0,strpos($collsql,'NOT NULL'));
  495. }
  496. $collsql = $collsql." character set $maincharset NOT NULL";
  497. $changesql = 'alter table '.$tablename.' change `'.$collation.'` '.$collsql;
  498. mysql_query($changesql);
  499. }
  500. }
  501. }
  502. }
  503. show_tools_message('????', 'tools.php?action=all_checkcharset');
  504. htmlfooter();
  505. exit;
  506. } else {
  507. $sql = "SELECT `TABLE_NAME` AS `Name`, `TABLE_COLLATION` AS `Collation` FROM `information_schema`.`TABLES` WHERE ".(strpos("php".PHP_OS,"WIN")?"":"BINARY")."`TABLE_SCHEMA` IN ('$dbname') AND TABLE_NAME like '$tablepre%'";
  508. $query = @mysql_query($sql);
  509. $dbtable = array();
  510. $chars = array('gbk' => 0,'big5' => 0,'utf8' => 0,'latin1' => 0);
  511. if(!$query) {
  512. htmlheader();
  513. errorpage('?????????????????????????????????????', '', 0, 0);
  514. htmlfooter();
  515. exit;
  516. }
  517. while($dbdetail = mysql_fetch_array($query)) {
  518. $dbtable[$dbdetail["Name"]]["Collation"] = pregcharset($dbdetail["Collation"],1);
  519. $dbtable[$dbdetail["Name"]]["tablename"] = $dbdetail["Name"];
  520. $tablequery = mysql_query("SHOW FULL FIELDS FROM `".$dbdetail["Name"]."`");
  521. while($tables= mysql_fetch_array($tablequery)) {
  522. if(!empty($tables["Collation"])) {
  523. $collcharset = pregcharset($tables["Collation"], 0);
  524. $tableschar[$collcharset][$dbdetail["Name"]][] = $tables["Field"];
  525. $chars[pregcharset($tables["Collation"], 0)]++;
  526. }
  527. }
  528. }
  529. }
  530. }
  531. htmlheader();
  532. echo $tooltip;
  533. if($my_version > '4.1') {
  534. echo'<div class="tabbody">
  535. <style>.tabbody p em { color:#09C; padding:0 10px;} .char_div { margin-top:30px; margin-bottom:30px;} .char_div h4, .notice h4 { font-weight:600; font-size:16px; margin:0; padding:0; margin-bottom:10px;}</style>
  536. <div class="char_div"><h5>???('.$dbname.')???????</h5>
  537. <table style="width:40%; margin:0; margin-bottom:20px;"><tr><th>gbk??</th><th>big5??</th><th>utf8??</th><th>latin1??</th></tr><tr><td>'.$chars[gbk].'&nbsp;</td><td>'.$chars[big5].'&nbsp;</td><td>'.$chars[utf8].'&nbsp;</td><td>'.$chars[latin1].'&nbsp;</td></tr></table>
  538. <div class="notice">
  539. <h5>???????????????</h5>';
  540. ?>
  541. <script type="text/JavaScript">
  542. function setrepaircheck(obj, form, table, char) {
  543. eval('var rem = /^' + table + '\\|.+?\\|.+?\\|' + char + '$/;');
  544. eval('var rechar = /latin1/;');
  545. for(var i = 0; i < form.elements.length; i++) {
  546. var e = form.elements[i];
  547. if(e.type == 'checkbox' && e.name == 'repair[]') {
  548. if(rem.exec(e.value) != null) {
  549. if(obj.checked) {
  550. if(rechar.exec(e.value) != null) {
  551. e.checked = true;
  552. } else {
  553. e.checked = true;
  554. }
  555. } else {
  556. e.checked = false;
  557. }
  558. }
  559. }
  560. }
  561. }
  562. </script>
  563. <?php
  564. foreach($chars as $char => $num) {
  565. if($char != $maincharset) {
  566. if(is_array($tableschar[$char])) {
  567. echo '<form name="form" action="" method="post">';
  568. foreach($tableschar[$char] as $tablename => $fields) {
  569. echo '<table style="margin-left:0; width:40%;">
  570. <tr>
  571. <th><input type="checkbox" id="tables[]" style="border-style:none;" name="chkall" onclick="setrepaircheck(this, this.form, \''.$tablename.'\', \''.$char.'\');" value="'.$tablename.'">??</th>
  572. <th width=60%><strong>'.$tablename.'</strong> <font color="red">??????</font></th>
  573. <th>??</th>
  574. </tr>';
  575. foreach($fields as $collation) {
  576. echo'<tr><td><input type="checkbox" style="border-style:none;"';
  577. echo 'id="fields['.$tablename.'][]"';
  578. echo 'name=repair[] value="'.$tablename.'|'.$collation.'|'.$maincharset.'|'.$char.'">';
  579. echo '</td><td>'.$collation.'</td><td><font color="red">'.$char.'</font></td></tr>';
  580. }
  581. echo '</table>';
  582. }
  583. }
  584. }
  585. }
  586. echo '<input type="submit" value="???????????'.$maincharset.'" name="repairsubmit" onclick="javascript:if(confirm(\'Tools???????????????????????????????????????????????????????????????????\'));else return false;"></form>';
  587. echo '<br /><br /><br /></div> </div>';
  588. } else {
  589. errorpage('MySQL??????4.1???????????????', '', 0, 0);
  590. }
  591. htmlfooter();
  592. } elseif($action == 'dz_filecheck') {//??????
  593. htmlheader();
  594. if($begin != 1) {
  595. echo '<h4>????</h4>';
  596. infobox('??????? Discuz! ????????????????????????????','tools.php?action=dz_filecheck&begin=1');
  597. htmlfooter();
  598. exit;
  599. }
  600. $md5data = array();
  601. if(!$dz_files = @file(TOOLS_ROOT.'./admin/discuzfiles.md5')) {
  602. errorpage('????md5??');
  603. }
  604. checkfiles('./', '\.php', 0, 'config.inc.php');
  605. checkfiles('api/', '\.php');
  606. checkfiles('admin/', '\.php');
  607. checkfiles('archiver/', '\.php');
  608. checkfiles('include/', '\.php|\.js|\.htm');
  609. checkfiles('modcp/', '\.php');
  610. checkfiles('plugins/', '\.php');
  611. checkfiles('templates/default/', '\.htm|\.php');
  612. checkfiles('uc_client/', '\.php',0);
  613. checkfiles('uc_client/control/', '\.php',0);
  614. checkfiles('uc_client/lib/', '\.php',0);
  615. checkfiles('uc_client/model/', '\.php',0);
  616. checkfiles('wap/', '\.php');
  617. $modifylists = $deletedfiles = $unknownfiles = array();
  618. docheckfiles($dz_files,$md5data);
  619. checkfilesoutput($modifylists,$deletedfiles,$unknownfiles);
  620. htmlfooter();
  621. } elseif($action == 'dz_mysqlclear') {//?????
  622. ob_implicit_flush();
  623. define('IN_DISCUZ', TRUE);
  624. if(@!include("./config.inc.php")) {
  625. if(@!include("./config.php")) {
  626. htmlheader();
  627. cexit("<h4>????config????????????????</h4>");
  628. }
  629. }
  630. require './include/db_'.$database.'.class.php';
  631. $db = new dbstuff;
  632. $db->connect($dbhost, $dbuser, $dbpw, $dbname, $pconnect);
  633. $db->select_db($dbname);
  634. if(!get_cfg_var('register_globals')) {
  635. @extract($_GET, EXTR_SKIP);
  636. }
  637. $rpp = "1000"; //?????????
  638. $totalrows = isset($totalrows) ? $totalrows : 0;
  639. $convertedrows = isset($convertedrows) ? $convertedrows : 0;
  640. $start = isset($start) && $start > 0 ? $start : 0;
  641. $sqlstart = isset($start) && $start > $convertedrows ? $start - $convertedrows : 0;
  642. $end = $start + $rpp - 1;
  643. $stay = isset($stay) ? $stay : 0;
  644. $converted = 0;
  645. $step = isset($step) ? $step : 0;
  646. $info = isset($info) ? $info : '';
  647. $action = array(
  648. '1'=>'????????',
  649. '2'=>'????????',
  650. '3'=>'????????',
  651. '4'=>'????????',
  652. '5'=>'??????',
  653. '6'=>'????????'
  654. );
  655. $steps = count($action);
  656. $actionnow = isset($action[$step]) ? $action[$step] : '??';
  657. $maxid = isset($maxid) ? $maxid : 0;
  658. $tableid = isset($tableid) ? $tableid : 1;
  659. htmlheader();
  660. if($step == 0) {
  661. ?>
  662. <h4>?????????</h4>
  663. <h5>????????</h5>
  664. <table>
  665. <tr><th width="30%">Posts????</th><td>[<a href="?action=dz_mysqlclear&step=1&stay=1">????</a>]</td></tr>
  666. <tr><th width="30%">Attachments????</th><td>[<a href="?action=dz_mysqlclear&step=2&stay=1">????</a>]</td></tr>
  667. <tr><th width="30%">Members????</th><td>[<a href="?action=dz_mysqlclear&step=3&stay=1">????</a>]</td></tr>
  668. <tr><th width="30%">Forums????</th><td>[<a href="?action=dz_mysqlclear&step=4&stay=1">????</a>]</td></tr>
  669. <tr><th width="30%">Threads????</th><td>[<a href="?action=dz_mysqlclear&step=5&stay=1">????</a>]</td></tr>
  670. <tr><th width="30%">??????</th><td>[<a href="?action=dz_mysqlclear&step=1&stay=0">????</a>]</td></tr>
  671. </table>
  672. <?php
  673. specialdiv();
  674. echo "<script>$('jsmenu').style.display='inline';</script>";
  675. } elseif($step == '1') {
  676. if($start == 0) {
  677. validid('pid','posts');
  678. }
  679. $query = "SELECT pid, tid FROM {$tablepre}posts WHERE pid >= $start AND pid <= $end";
  680. $posts = $db->query($query);
  681. while ($post = $db->fetch_array($posts)) {
  682. $query = $db->query("SELECT tid FROM {$tablepre}threads WHERE tid='".$post['tid']."'");
  683. if($db->result($query, 0)) {
  684. } else {
  685. $convertedrows ++;
  686. $db->query("DELETE FROM {$tablepre}posts WHERE pid='".$post['pid']."'");
  687. }
  688. $converted = 1;
  689. $totalrows ++;
  690. }
  691. if($converted || $end < $maxid) {
  692. continue_redirect();
  693. } else {
  694. stay_redirect();
  695. }
  696. } elseif($step == '2') {
  697. if($start == 0) {
  698. validid('aid','attachments');
  699. }
  700. $query = "SELECT aid,pid,attachment FROM {$tablepre}attachments WHERE aid >= $start AND aid <= $end";
  701. $posts = $db->query($query);
  702. while ($post = $db->fetch_array($posts)) {
  703. $query = $db->query("SELECT pid FROM {$tablepre}posts WHERE pid='".$post['pid']."'");
  704. if($db->result($query, 0)) {
  705. } else {
  706. $convertedrows ++;
  707. $db->query("DELETE FROM {$tablepre}attachments WHERE aid='".$post['aid']."'");
  708. $attachmentdir = TOOLS_ROOT.'./attachments/';
  709. @unlink($attachmentdir.$post['attachment']);
  710. }
  711. $converted = 1;
  712. $totalrows ++;
  713. }
  714. if($converted || $end < $maxid) {
  715. continue_redirect();
  716. } else {
  717. stay_redirect();
  718. }
  719. } elseif($step == '3') {
  720. if($start == 0) {
  721. validid('uid','memberfields');
  722. }
  723. $query = "SELECT uid FROM {$tablepre}memberfields WHERE uid >= $start AND uid <= $end";
  724. $posts = $db->query($query);
  725. while ($post = $db->fetch_array($posts)) {
  726. $query = $db->query("SELECT uid FROM {$tablepre}members WHERE uid='".$post['uid']."'");
  727. if($db->result($query, 0)) {
  728. } else {
  729. $convertedrows ++;
  730. $db->query("DELETE FROM {$tablepre}memberfields WHERE uid='".$post['uid']."'");
  731. }
  732. $converted = 1;
  733. $totalrows ++;
  734. }
  735. if($converted || $end < $maxid) {
  736. continue_redirect();
  737. } else {
  738. stay_redirect();
  739. }
  740. } elseif($step == '4') {
  741. if($start == 0) {
  742. validid('fid','forumfields');
  743. }
  744. $query = "SELECT fid FROM {$tablepre}forumfields WHERE fid >= $start AND fid <= $end";
  745. $posts = $db->query($query);
  746. while ($post = $db->fetch_array($posts)) {
  747. $query = $db->query("SELECT fid FROM {$tablepre}forums WHERE fid='".$post['fid']."'");
  748. if($db->result($query, 0)) {
  749. } else {
  750. $convertedrows ++;
  751. $db->query("DELETE FROM {$tablepre}forumfields WHERE fid='".$post['fid']."'");
  752. }
  753. $converted = 1;
  754. $totalrows ++;
  755. }
  756. if($converted || $end < $maxid) {
  757. continue_redirect();
  758. } else {
  759. stay_redirect();
  760. }
  761. } elseif($step == '5') {
  762. if($start == 0) {
  763. validid('tid','threads');
  764. }
  765. $query = "SELECT tid, subject FROM {$tablepre}threads WHERE tid >= $start AND tid <= $end";
  766. $posts = $db->query($query);
  767. while ($threads = $db->fetch_array($posts)) {
  768. $query = $db->query("SELECT COUNT(*) FROM {$tablepre}posts WHERE tid='".$threads['tid']."' AND invisible='0'");
  769. $replynum = $db->result($query, 0) - 1;
  770. if($replynum < 0) {
  771. $db->query("DELETE FROM {$tablepre}threads WHERE tid='".$threads['tid']."'");
  772. } else {
  773. $query = $db->query("SELECT a.aid FROM {$tablepre}posts p, {$tablepre}attachments a WHERE a.tid='".$threads['tid']."' AND a.pid=p.pid AND p.invisible='0' LIMIT 1");
  774. $attachment = $db->num_rows($query) ? 1 : 0;//????
  775. $query = $db->query("SELECT pid, subject, rate FROM {$tablepre}posts WHERE tid='".$threads['tid']."' AND invisible='0' ORDER BY dateline LIMIT 1");
  776. $firstpost = $db->fetch_array($query);
  777. $firstpost['subject'] = trim($firstpost['subject']) ? $firstpost['subject'] : $threads['subject']; //??????????????
  778. $firstpost['subject'] = addslashes($firstpost['subject']);
  779. @$firstpost['rate'] = $firstpost['rate'] / abs($firstpost['rate']);//????
  780. $query = $db->query("SELECT author, dateline FROM {$tablepre}posts WHERE tid='".$threads['tid']."' AND invisible='0' ORDER BY dateline DESC LIMIT 1");
  781. $lastpost = $db->fetch_array($query);//??????
  782. $db->query("UPDATE {$tablepre}threads SET subject='".$firstpost['subject']."', replies='$replynum', lastpost='".$lastpost['dateline']."', lastposter='".addslashes($lastpost['author'])."', rate='".$firstpost['rate']."', attachment='$attachment' WHERE tid='".$threads['tid']."'", 'UNBUFFERED');
  783. $db->query("UPDATE {$tablepre}posts SET first='1', subject='".$firstpost['subject']."' WHERE pid='".$firstpost['pid']."'", 'UNBUFFERED');
  784. $db->query("UPDATE {$tablepre}posts SET first='0' WHERE tid='".$threads['tid']."' AND pid<>'".$firstpost['pid']."'", 'UNBUFFERED');
  785. $convertedrows ++;
  786. }
  787. $converted = 1;
  788. $totalrows ++;
  789. }
  790. if($converted || $end < $maxid) {
  791. continue_redirect();
  792. } else {
  793. stay_redirect();
  794. }
  795. } elseif($step == '6') {
  796. echo '<h4>?????????</h4><table>
  797. <tr><th>????????</th></tr><tr>
  798. <td><br>??????????.&nbsp;???<font color=red>'.$allconvertedrows.'</font>???.<br><br></td></tr></table>';
  799. }
  800. htmlfooter();
  801. } elseif($action == 'uch_dz_replace') {//????s
  802. htmlheader();
  803. $rpp = "500"; //?????????
  804. $totalrows = isset($totalrows) ? $totalrows : 0;
  805. $convertedrows = isset($convertedrows) ? $convertedrows : 0;
  806. $convertedtrows = isset($convertedtrows) ? $convertedtrows : 0;
  807. $start = isset($start) && $start > 0 ? $start : 0;
  808. $end = $start + $rpp - 1;
  809. $converted = 0;
  810. $maxid = isset($maxid) ? $maxid : 0;
  811. $threads_mod = isset($threads_mod) ? $threads_mod : 0;
  812. $threads_banned = isset($threads_banned) ? $threads_banned : 0;
  813. $posts_mod = isset($posts_mod) ? $posts_mod : 0;
  814. if($stop == 1) {
  815. echo "<h4>??????</h4><table>
  816. <tr>
  817. <th>????</th>
  818. </tr>";
  819. $threads_banned > 0 && print("<tr><td><br><li>".$threads_banned."?????????.</li></td></tr>");
  820. $threads_mod > 0 && print("<tr><td><br><li>".$threads_mod."??????????.</li></td></tr>");
  821. $posts_mod > 0 && print("<tr><td><br><li>".$posts_mod."??????????.</li></td></tr>");
  822. echo "<tr><td><li>???".$convertedrows."???</li></td></tr>";
  823. echo "<tr><td><a href='?action=uch_dz_replace&step=".$step."&start=".($end + 1 - $rpp * 2)."&stay=$stay&totalrows=$totalrows&convertedrows=$convertedrows&maxid=$maxid&replacesubmit=1&threads_banned=$threads_banned&threads_mod=$threads_mod&posts_mod=$posts_mod'>??</a></td></tr>";
  824. echo "</table>";
  825. htmlfooter();
  826. }
  827. ob_implicit_flush();
  828. if($whereis == 'is_uch') {
  829. $selectwords_cache = './data/selectwords_cache.php';
  830. } elseif($whereis == 'is_dz') {
  831. $selectwords_cache = './forumdata/cache/selectwords_cache.php';
  832. }
  833. if(isset($replacesubmit) || $start > 0) {
  834. if(!file_exists($selectwords_cache) || is_array($selectwords)) {
  835. if(count($selectwords) < 1) {
  836. echo "<h4>??????</h4><table><tr><th>????</th></tr><tr><td>????????????. &nbsp [<a href=tools.php?action=uch_dz_replace>??</a>]</td></tr></table>";
  837. htmlfooter();
  838. } else {
  839. $fp = @fopen($selectwords_cache,w);
  840. $content = "<?php \n";
  841. $selectwords = implode(',',$selectwords);
  842. $content .= "\$selectwords = '$selectwords';\n?>";
  843. if(!@fwrite($fp,$content)) {
  844. echo "??????$selectwords_cache ??,?????????. &nbsp [<a href=tools.php?action=uch_dz_replace>??</a>]";
  845. htmlfooter();
  846. } else {
  847. require_once "$selectwords_cache";
  848. }
  849. @fclose($fp);
  850. }
  851. } else {
  852. require_once "$selectwords_cache";
  853. }
  854. $array_find = $array_replace = $array_findmod = $array_findbanned = array();
  855. if($whereis == 'is_dz') {
  856. $query = mysql_query("SELECT find,replacement from {$tablepre}words where id in($selectwords)");//??????{BANNED}???? {MOD}??????
  857. while($row = mysql_fetch_array($query)) {
  858. $find = preg_quote($row['find'], '/');
  859. $replacement = $row['replacement'];
  860. if($replacement == '{BANNED}') {
  861. $array_findbanned[] = $find;
  862. } elseif($replacement == '{MOD}') {
  863. $array_findmod[] = $find;
  864. } else {
  865. $array_find[] = $find;
  866. $array_replace[] = $replacement;
  867. }
  868. }
  869. } elseif($whereis == 'is_uch') {
  870. $query = mysql_query("SELECT datavalue FROM `uchome_data` WHERE `var` = 'censor'");
  871. $query = mysql_fetch_array($query);
  872. $censor = explode("\n",$query[datavalue]);
  873. foreach($censor as $key => $value) {
  874. if(in_array($key,explode(',',$selectwords))){
  875. $rows = explode('=',$value);
  876. $row[] = $rows;
  877. }
  878. }
  879. foreach($row as $value) {
  880. $find = preg_quote($value[0], '/');
  881. $replacement = $value[1];
  882. if($replacement == '{BANNED}') {
  883. $array_findbanned[] = $find;
  884. } else {
  885. $array_find[] = $find;
  886. $array_replace[] = $replacement;
  887. }
  888. }
  889. }
  890. $array_find = topattern_array($array_find);
  891. $array_findmod = topattern_array($array_findmod);
  892. $array_findbanned = topattern_array($array_findbanned);
  893. if($whereis == 'is_dz'){
  894. if($maxid == 0) {
  895. validid('pid','posts');
  896. }
  897. //??posts?????
  898. $sql = "SELECT pid, tid, first, subject, message from {$tablepre}posts where pid >= $start and pid <= $end";
  899. $query = mysql_query($sql);
  900. while($row = mysql_fetch_array($query)) {
  901. $pid = $row['pid'];
  902. $tid = $row['tid'];
  903. $subject = $row['subject'];
  904. $message = $row['message'];
  905. $first = $row['first'];
  906. $displayorder = 0;// -2?? -1???
  907. if(count($array_findmod) > 0) {
  908. foreach($array_findmod as $value) {
  909. if(preg_match($value,$subject.$message)) {
  910. $displayorder = '-2';
  911. break;
  912. }
  913. }
  914. }
  915. if(count($array_findbanned) > 0) {
  916. foreach($array_findbanned as $value) {
  917. if(preg_match($value,$subject.$message)) {
  918. $displayorder = '-1';
  919. break;
  920. }
  921. }
  922. }
  923. if($displayorder < 0) {
  924. if($displayorder == '-2' && $first == 0) {//??????????
  925. $posts_mod ++;
  926. mysql_query("UPDATE {$tablepre}posts SET invisible = '$displayorder' WHERE pid = $pid");
  927. } else {
  928. if($db->affected_rows($db->query("UPDATE {$tablepre}threads SET displayorder = '$displayorder' WHERE tid = $tid and displayorder >= 0")) > 0) {
  929. $displayorder == '-2' && $threads_mod ++;
  930. $displayorder == '-1' && $threads_banned ++;
  931. }
  932. }
  933. }
  934. $subject = preg_replace($array_find,$array_replace,addslashes($subject));
  935. $message = preg_replace($array_find,$array_replace,addslashes($message));
  936. if($subject != addslashes($row['subject']) || $message != addslashes($row['message'])) {
  937. if(mysql_query("UPDATE {$tablepre}posts SET subject = '$subject', message = '$message' WHERE pid = $pid")) {
  938. $convertedrows ++;
  939. }
  940. }
  941. $converted = 1;
  942. }
  943. //??threads?
  944. $sql2 = "SELECT tid,subject from {$tablepre}threads where tid >= $start and tid <= $end";
  945. $query2 = mysql_query($sql2);
  946. while($row2 = mysql_fetch_array($query2)) {
  947. $tid = $row2['tid'];
  948. $subject = $row2['subject'];
  949. $subject = preg_replace($array_find,$array_replace,addslashes($subject));
  950. if($subject != addslashes($row2['subject'])) {
  951. if(mysql_query("UPDATE {$tablepre}threads SET subject = '$subject' WHERE tid = $tid")) {
  952. $convertedrows ++;
  953. }
  954. }
  955. $converted = 1;
  956. }
  957. } elseif ($whereis == 'is_uch') {
  958. if($maxid == 0) {
  959. validid('blogid','blog');
  960. $temp = $maxid;
  961. validid('cid','comment');
  962. $temp = max($temp,$maxid);
  963. validid('oid','polloption');
  964. $temp = max($temp,$maxid);
  965. validid('pid','post');
  966. $temp = max($temp,$maxid);
  967. validid('doid','doing');
  968. $temp = max($temp,$maxid);
  969. $maxid = $temp;
  970. }
  971. //blog??
  972. $sql = "SELECT b.blogid,b.subject,f.message from {$tablepre}blog b,{$tablepre}blogfield f where b.blogid=f.blogid AND b.blogid >= $start and b.blogid <= $end";
  973. $query = mysql_query($sql);
  974. while($row = mysql_fetch_array($query)) {
  975. $blogid = $row['blogid'];
  976. $subject = $row['subject'];
  977. $subject = preg_replace($array_find,$array_replace,addslashes($subject));
  978. if($subject != addslashes($row['subject']) || $message != addslashes($row['message'])) {
  979. if(mysql_query("UPDATE {$tablepre}blog SET subject = '$subject' WHERE blogid = $blogid")) {
  980. mysql_query("UPDATE {$tablepre}blogfield SET message = '$message' WHERE blogid = $blogid");
  981. $convertedrows ++;
  982. }
  983. }
  984. $converted = 1;
  985. }
  986. //comment??
  987. $sql = "SELECT cid,message from {$tablepre}comment where cid >= $start and cid <= $end";
  988. $query = mysql_query($sql);
  989. while($row = mysql_fetch_array($query)) {
  990. $cid = $row['cid'];
  991. $message = $row['message'];
  992. $message = preg_replace($array_find,$array_replace,addslashes($message));
  993. if($message != addslashes($row['message'])) {
  994. if(mysql_query("UPDATE {$tablepre}coment SET message = '$message' WHERE cid = $cid")) {
  995. $convertedrows ++;
  996. }
  997. }
  998. $converted = 1;
  999. }
  1000. //poll??
  1001. $sql = "SELECT p.pid,p.subject,f.message,f.option from {$tablepre}poll p,{$tablepre}pollfield f where p.pid=f.pid AND p.pid >= $start and p.pid <= $end";
  1002. $query = mysql_query($sql);
  1003. while($row = mysql_fetch_array($query)) {
  1004. $pid = $row['pid'];
  1005. $subject = $row['subject'];
  1006. $message = $row['message'];
  1007. $option = unserialize($row['option']);
  1008. $subject = preg_replace($array_find,$array_replace,addslashes($subject));
  1009. $message = preg_replace($array_find,$array_replace,addslashes($message));
  1010. $option = addslashes(serialize(preg_replace($array_find,$array_replace,$option)));
  1011. if($message != addslashes($row['message']) || $subject != addslashes($row['subject']) || $option != addslashes($row['option'])) {
  1012. if(mysql_query("UPDATE {$tablepre}poll SET subject = '$subject' WHERE pid = $pid")) {
  1013. mysql_query("UPDATE {$tablepre}pollfield SET `message` = '$message' WHERE pid = $pid");
  1014. mysql_query("UPDATE {$tablepre}pollfield SET `option` = '$option' WHERE pid = $pid");
  1015. $convertedrows ++;
  1016. }
  1017. }
  1018. $converted = 1;
  1019. }
  1020. //polloption??
  1021. $sql = "SELECT oid,option from {$tablepre}polloption where oid >= $start and oid <= $end";
  1022. $query = mysql_query($sql);
  1023. while($row = mysql_fetch_array($query)) {
  1024. $oid = $row['oid'];
  1025. $option = $row['option'];
  1026. $option = preg_replace($array_find,$array_replace,addslashes($option));
  1027. if($option != addslashes($row['option'])) {
  1028. if(mysql_query("UPDATE {$tablepre}polloption SET option = '$option' WHERE oid = $oid")) {
  1029. $convertedrows ++;
  1030. }
  1031. }
  1032. $converted = 1;
  1033. }
  1034. //polloption??
  1035. $sql = "SELECT oid,option from {$tablepre}polloption where oid >= $start and oid <= $end";
  1036. $query = mysql_query($sql);
  1037. while($row = mysql_fetch_array($query)) {
  1038. $oid = $row['oid'];
  1039. $option = $row['option'];
  1040. $option = preg_replace($array_find,$array_replace,addslashes($option));
  1041. if($option != addslashes($row['option'])) {
  1042. if(mysql_query("UPDATE {$tablepre}polloption SET option = '$option' WHERE oid = $oid")) {
  1043. $convertedrows ++;
  1044. }
  1045. }
  1046. $converted = 1;
  1047. }
  1048. //post??
  1049. $sql = "SELECT pid,message from {$tablepre}post where pid >= $start and pid <= $end";
  1050. $query = mysql_query($sql);
  1051. while($row = mysql_fetch_array($query)) {
  1052. $pid = $row['pid'];
  1053. $message = $row['message'];
  1054. $message = preg_replace($array_find,$array_replace,addslashes($message));
  1055. if($message != addslashes($row['message'])) {
  1056. if(mysql_query("UPDATE {$tablepre}post SET message = '$message' WHERE pid = $pid")) {
  1057. $convertedrows ++;
  1058. }
  1059. }
  1060. $converted = 1;
  1061. }
  1062. //doing??
  1063. $sql = "SELECT doid,message from {$tablepre}doing where doid >= $start and doid <= $end";
  1064. $query = mysql_query($sql);
  1065. while($row = mysql_fetch_array($query)) {
  1066. $doid = $row['doid'];
  1067. $message = $row['message'];
  1068. $message = preg_replace($array_find,$array_replace,addslashes($message));
  1069. if($message != addslashes($row['message'])) {
  1070. if(mysql_query("UPDATE {$tablepre}doing SET message = '$message' WHERE doid = $doid")) {
  1071. $convertedrows ++;
  1072. }
  1073. }
  1074. $converted = 1;
  1075. }
  1076. //spacefield??
  1077. $sql = "SELECT uid,note,spacenote from {$tablepre}spacefield where uid >= $start and uid <= $end";
  1078. $query = mysql_query($sql);
  1079. while($row = mysql_fetch_array($query)) {
  1080. $uid = $row['uid'];
  1081. $note = $row['note'];
  1082. $spacenote = $row['spacenote'];
  1083. $note = preg_replace($array_find,$array_replace,addslashes($note));
  1084. $spacenote = preg_replace($array_find,$array_replace,addslashes($spacenote));
  1085. if($note != addslashes($row['note']) || $spacenote != addslashes($row['spacenote'])) {
  1086. if(mysql_query("UPDATE {$tablepre}spacefield SET note = '$note' WHERE uid = $uid")) {
  1087. mysql_query("UPDATE {$tablepre}spacefield SET spacenote = '$spacenote' WHERE uid = $uid");
  1088. $convertedrows ++;
  1089. }
  1090. }
  1091. $converted = 1;
  1092. }
  1093. }
  1094. //??
  1095. if($converted || $end < $maxid) {
  1096. continue_redirect('uch_dz_replace',"&replacesubmit=1&threads_banned=$threads_banned&threads_mod=$threads_mod&posts_mod=$posts_mod");
  1097. } else {
  1098. echo "<h4>??????</h4><table>
  1099. <tr>
  1100. <th>????????</th>
  1101. </tr>";
  1102. if($threads_banned > 0) { echo "<tr><td><li>".$threads_banned."?????????.</li></td></tr>";}
  1103. if($threads_mod > 0) {echo "<tr><td><li>".$threads_mod."??????????.</li></td></tr>";}
  1104. if($posts_mod > 0) {echo "<tr><td><li>".$posts_mod."??????????.</li></td></tr>";}
  1105. echo "<tr><td><li>???".$convertedrows."???</li></td></tr>";
  1106. echo "</table>";
  1107. @unlink($selectwords_cache);
  1108. }
  1109. } else {
  1110. if(mysql_get_server_info > '4.1') {
  1111. $serverset = 'character_set_connection=gbk, character_set_results=gbk, character_set_client=binary';
  1112. $serverset && mysql_query("SET $serverset");
  1113. }
  1114. $i = 1;
  1115. if ($whereis == 'is_dz') {
  1116. define('IN_DISCUZ',TRUE);
  1117. require_once "./forumdata/cache/cache_censor.php";
  1118. $censorarray = $_DCACHE['censor'];
  1119. $query = mysql_query("select * from {$tablepre}words");
  1120. } elseif($whereis == 'is_uch') {
  1121. define('IN_UCHOME',TRUE);
  1122. require_once "./data/data_censor.php";
  1123. $censorarray = $_SGLOBAL['censor'];
  1124. $query = mysql_query("SELECT datavalue FROM `uchome_data` WHERE `var` = 'censor'");
  1125. $query = mysql_fetch_array($query);
  1126. $censor = explode("\n",$query[datavalue]);
  1127. foreach($censor as $key => $value) {
  1128. $rows = explode('=',$value);
  1129. $row[] = $rows;
  1130. }
  1131. }
  1132. if(count($censorarray) < 1) {
  1133. echo "<h4>??????</h4><table><tr><th>????</th></tr><tr><td><br>???,?????????,???????????.<br><br></td></tr></table>";
  1134. htmlfooter();
  1135. }
  1136. echo '<form method="post" action="tools.php?action=uch_dz_replace">
  1137. <script language="javascript">
  1138. function checkall(form, prefix, checkall) {
  1139. var checkall = checkall ? checkall : \'chkall\';
  1140. for(var i = 0; i < form.elements.length; i++) {
  1141. var e = form.elements[i];
  1142. if(e.name != checkall && (!prefix || (prefix && e.name.match(prefix)))) {
  1143. e.checked = form.elements[checkall].checked;
  1144. }
  1145. }
  1146. }
  1147. </script>
  1148. <h4>??????</h4>
  1149. <table>
  1150. <tr>
  1151. <th><input class="checkbox" name="chkall" onclick="checkall(this.form)" type="checkbox" checked>??</th>
  1152. <th>????</th>
  1153. <th>???</th></tr>';
  1154. if($whereis == 'is_dz') {
  1155. while($row = mysql_fetch_array($query)) {
  1156. echo'<tr>
  1157. <td><input class="checkbox" name="selectwords[]" value="'.$row['id'].'" type="checkbox" checked>&nbsp '.$i++.'</td>
  1158. <td>&nbsp '.$row['find'].'</td>
  1159. <td>&nbsp '.stripslashes($row['replacement']).'</td>
  1160. </tr>';
  1161. }
  1162. } elseif($whereis == 'is_uch') {
  1163. foreach($row as $key => $rowvalue) {
  1164. echo'<tr>
  1165. <td><input class="checkbox" name="selectwords[]" value="'.$key.'" type="checkbox" checked>&nbsp '.$i++.'</td>
  1166. <td>&nbsp '.$rowvalue[0].'</td>
  1167. <td>&nbsp '.stripslashes($rowvalue[1]).'</td>
  1168. </tr>';
  1169. }
  1170. }
  1171. echo '</table>
  1172. <input type="submit" name=replacesubmit value="????">
  1173. </form>
  1174. <div class="specialdiv">
  1175. <h6>???</h6>
  1176. <ul>
  1177. <li>??????????????????????.?????<a href="./admincp.php?action=censor" target=\'_blank\'>?????</a>?</li>
  1178. <li>???????????????.</li>
  1179. </ul></div><br><br>';
  1180. }
  1181. htmlfooter();
  1182. } elseif($action == 'all_updatecache') {//????
  1183. if($whereis =='is_dz') {
  1184. $clearmsg = dz_updatecache();
  1185. } elseif($whereis == 'is_uch') {
  1186. $clearmsg = uch_updatecache();
  1187. } elseif($whereis == 'is_ss') {
  1188. $clearmsg = ss_updatecache();
  1189. }
  1190. htmlheader();
  1191. echo '<h4>????</h4><table><tr><th>????</th></tr><tr><td>';
  1192. if($clearmsg == '') $clearmsg = '??????.';
  1193. echo $clearmsg.'</td></tr></table>';
  1194. htmlfooter();
  1195. } elseif($action == 'all_setadmin') {//??????????
  1196. $sql_findadmin = '';
  1197. $sql_select = '';
  1198. $sql_update = '';
  1199. $sql_rspw = '';
  1200. $secq = '';
  1201. $rspw = '';
  1202. $username = '';
  1203. $uid = '';
  1204. all_setadmin_set($tablepre,$whereis);
  1205. $info = '';
  1206. $info_uc = '';
  1207. htmlheader();
  1208. ?>
  1209. <h4>?????</h4>
  1210. <?php
  1211. //??????????
  1212. if($whereis != 'is_uc') {
  1213. $findadmin_query = mysql_query($sql_findadmin);
  1214. $admins = '';
  1215. while($findadmins = mysql_fetch_array($findadmin_query)) {
  1216. $admins .= ' '.$findadmins[$username];
  1217. }
  1218. }
  1219. if(!empty($_POST['loginsubmit'])) {
  1220. if($whereis == 'is_uc') {
  1221. define(ROOT_DIR,dirname(__FILE__)."/");
  1222. $configfile = ROOT_DIR."./data/config.inc.php";
  1223. $uc_password = $_POST["password"];
  1224. $salt = substr(uniqid(rand()), 0, 6);
  1225. if(!$uc_password) {
  1226. $info = "??????";
  1227. } else {
  1228. $md5_uc_password = md5(md5($uc_password).$salt);
  1229. $config = file_get_contents($configfile);
  1230. $config = preg_replace("/define\('UC_FOUNDERSALT',\s*'.*?'\);/i", "define('UC_FOUNDERSALT', '$salt');", $config);
  1231. $config = preg_replace("/define\('UC_FOUNDERPW',\s*'.*?'\);/i", "define('UC_FOUNDERPW', '$md5_uc_password');", $config);
  1232. $fp = @fopen($configfile, 'w');
  1233. @fwrite($fp, $config);
  1234. @fclose($fp);
  1235. $info = "UCenter???????????$uc_password";
  1236. }
  1237. } else {
  1238. if(@mysql_num_rows(mysql_query($sql_select)) < 1) {
  1239. $info = '<font color="red">????????????????</font>?<a href="?action=all_setadmin">????</a> ??????.<br><br>';
  1240. } else {
  1241. if($whereis == 'is_dz') {
  1242. $sql_update1 = "UPDATE {$tablepre}members SET adminid='1', groupid='1' WHERE $_POST[loginfield] = '$_POST[where]' limit 1";
  1243. $sql_update2 = "UPDATE {$tablepre}members SET adminid='1', groupid='1',secques='' WHERE $_POST[loginfield] = '$_POST[where]' limit 1";
  1244. $sql_update = $_POST['issecques'] ? $sql_update2 : $sql_update1;
  1245. }
  1246. if($whereis == 'is_ss') {
  1247. $sql_update1 = "UPDATE {$tablepre}members SET groupid='1' WHERE $_POST[loginfield] = '$_POST[where]' limit 1";
  1248. $sql_update = $sql_update1;
  1249. }
  1250. if(mysql_query($sql_update)&& !$rspw) {
  1251. $_POST[loginfield] = $_POST[loginfield] == $username ? '???' : 'UID??';
  1252. $info = "??$_POST[loginfield]? $_POST[where] ??????????<br><br>";
  1253. }
  1254. if($rspw) {
  1255. if($whereis == 'is_dz') {
  1256. if($dz_version < 610) {
  1257. $psw = md5($_POST['password']);
  1258. mysql_query("update {$tablepre}members set password='$psw' where $_POST[loginfield] = '$_POST[where]' limit 1");
  1259. } else {
  1260. //???dz???????uc??????$sql_rspw????
  1261. $salt = substr(md5(time()), 0, 6);
  1262. $psw = md5(md5($_POST['password']).$salt);
  1263. mysql_connect(UC_DBHOST, U…

Large files files are truncated, but you can click here to view the full file