PageRenderTime 39ms CodeModel.GetById 23ms 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
  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, UC_DBUSER, UC_DBPW);
  1264. if($_POST['issecques'] && $dz_version >= 700) {
  1265. $sql_rspw = "UPDATE ".UC_DBTABLEPRE."members SET password='".$psw."',salt='".$salt."',secques='' WHERE $_POST[loginfield] = '$_POST[where]' limit 1";
  1266. } else {
  1267. $sql_rspw = "UPDATE ".UC_DBTABLEPRE."members SET password='".$psw."',salt='".$salt."' WHERE username = '$_POST[where]' limit 1";
  1268. }
  1269. mysql_query($sql_rspw);
  1270. }
  1271. $info .= "??$_POST[loginfield]? $_POST[where] ??????????$_POST[password]<br><br>";
  1272. } elseif($whereis == 'is_uch') {
  1273. $salt = substr(md5(time()), 0, 6);
  1274. $psw = md5(md5($_POST['password']).$salt);
  1275. mysql_connect(UC_DBHOST, UC_DBUSER, UC_DBPW);
  1276. $sql_rspw = "UPDATE ".UC_DBTABLEPRE."members SET password='".$psw."',salt='".$salt."' WHERE $_POST[loginfield] = '$_POST[where]' limit 1";
  1277. mysql_query($sql_rspw);
  1278. $info .= "??$_POST[loginfield]? $_POST[where] ??????????$_POST[password]<br><br>";
  1279. } elseif($whereis == 'is_ss') {
  1280. if($ss_version >= 70) {
  1281. $salt = substr(md5(time()), 0, 6);
  1282. $psw = md5(md5($_POST['password']).$salt);
  1283. mysql_connect(UC_DBHOST, UC_DBUSER, UC_DBPW);
  1284. $sql_rspw = "UPDATE ".UC_DBTABLEPRE."members SET password='".$psw."',salt='".$salt."' WHERE $_POST[loginfield] = '$_POST[where]' limit 1";
  1285. mysql_query($sql_rspw);
  1286. }
  1287. $info .= "??$_POST[loginfield]? $_POST[where] ??????????$_POST[password]<br><br>";
  1288. }
  1289. } else {
  1290. $info_rspw = "????????UC????? <a href=11 target='_blank'>????UC??</a>";
  1291. }
  1292. }
  1293. }
  1294. errorpage($info,'???????',0,0);
  1295. } else {
  1296. ?>
  1297. <form action="?action=all_setadmin" method="post">
  1298. <table>
  1299. <?php
  1300. if($whereis != 'is_uc') {
  1301. ?>
  1302. <tr>
  1303. <th>????????</th>
  1304. <td><?php echo $admins; ?></td>
  1305. </tr>
  1306. <tr>
  1307. <th width="30%"><input class="radio" type="radio" name="loginfield" value="<?php echo $username; ?>" checked >???<input class="radio" type="radio" name="loginfield" value="<?php echo $uid; ?>" >UID</th>
  1308. <td width="70%"><input class="textinput" type="" name="where" size="25" maxlength="40">
  1309. <?php if(!$rspw) {
  1310. echo '??????????????';
  1311. }?>
  1312. </td>
  1313. </tr>
  1314. <?php
  1315. } else {
  1316. }
  1317. ?>
  1318. <?php
  1319. if($rspw) {
  1320. ?>
  1321. <tr>
  1322. <th width="30%">?????</th>
  1323. <td width="70%"><input class="textinput" type="text" name="password" size="25"></td>
  1324. </tr>
  1325. <?php
  1326. } else {
  1327. ?>
  1328. <tr>
  1329. <th width="30%">??????</th>
  1330. <td width="70%">????????UC?????<a href=11 target='_blank'>????UC??</a> </td>
  1331. </tr>
  1332. <?php
  1333. }
  1334. if($secq) {
  1335. ?>
  1336. <tr>
  1337. <th width="30%">????????</th>
  1338. <td width="70%"><input class="radio" name="issecques" value="1" checked="checked" type="radio">?&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input name="issecques" value="" class="radio" type="radio">?</td>
  1339. </tr>
  1340. <?php
  1341. }
  1342. ?>
  1343. </table>
  1344. <input type="submit" name="loginsubmit" value="? &nbsp; ?">
  1345. </form>
  1346. <?php
  1347. }
  1348. specialdiv();
  1349. htmlfooter();
  1350. } elseif($action == 'all_setlock') {//?????
  1351. touch($lockfile);
  1352. if(file_exists($lockfile)) {
  1353. echo '<meta http-equiv="refresh" content="3 url=?">';
  1354. errorpage("<h6>?????????????????????????????</h6>",'?????');
  1355. } else {
  1356. errorpage('????????????????????????????????????tool.php???','?????');
  1357. }
  1358. } elseif($action == 'dz_moveattach') {//????????
  1359. define('IN_DISCUZ', TRUE);
  1360. require_once TOOLS_ROOT."./config.inc.php";
  1361. require_once TOOLS_ROOT."./include/db_mysql.class.php";
  1362. $db = new dbstuff;
  1363. $db->connect($dbhost, $dbuser, $dbpw, $dbname, $pconnect, true, $dbcharset);
  1364. $dbuser = $dbpw = $dbname = $pconnect = NULL;
  1365. htmlheader();
  1366. if(!function_exists('mkdir')) {
  1367. echo "<h4>????????mkdir???????????</h4>";
  1368. }
  1369. echo "<h4>??????</h4>";
  1370. $atoption = array(
  1371. '0' => '??(????????)',
  1372. '1' => '?????????',
  1373. '2' => '???????????',
  1374. '3' => '?????????',
  1375. '4' => '????????',
  1376. );
  1377. if(!empty($_POST['moveattsubmit']) || $step == 1) {
  1378. $rpp = "500"; //?????????
  1379. $totalrows = isset($totalrows) ? $totalrows : 0;
  1380. $convertedrows = isset($convertedrows) ? $convertedrows : 0;
  1381. $start = isset($start) && $start > 0 ? $start : 0;
  1382. $end = $start + $rpp - 1;
  1383. $converted = 0;
  1384. $maxid = isset($maxid) ? $maxid : 0;
  1385. $newattachsave = isset($newattachsave) ? $newattachsave : 0;
  1386. $step = 1;
  1387. if($start <= 1) {
  1388. $db->query("UPDATE {$tablepre}settings SET value = '$newattachsave' WHERE variable = 'attachsave'");
  1389. $cattachdir = $db->result($db->query("SELECT value FROM {$tablepre}settings WHERE variable = 'attachdir'"), 0);
  1390. validid('aid', 'attachments');
  1391. }
  1392. $attachpath = isset($cattachdir) ? TOOLS_ROOT.$cattachdir : TOOLS_ROOT.'./attachments';
  1393. $query = $db->query("SELECT aid, tid, dateline, filename, filetype, attachment, isimage, thumb FROM {$tablepre}attachments WHERE aid >= $start AND aid <= $end");
  1394. while ($a = $db->fetch_array($query)) {
  1395. $aid = $a['aid'];
  1396. $tid = $a['tid'];
  1397. $dateline = $a['dateline'];
  1398. $filename = $a['filename'];
  1399. $filetype = $a['filetype'];
  1400. $attachment = $a['attachment'];
  1401. $isimage = $a['isimage'];
  1402. $thumb = $a['thumb'];
  1403. $oldpath = $attachpath.'/'.$attachment;
  1404. if(file_exists($oldpath)) {
  1405. $realname = substr(strrchr('/'.$attachment, '/'), 1);
  1406. if($newattachsave == 1) {
  1407. $fid = $db->result($db->query("SELECT fid FROM {$tablepre}threads WHERE tid = '$tid' LIMIT 1"), 0);
  1408. $fid = $fid ? $fid : 0;
  1409. } elseif($newattachsave == 2) {
  1410. $extension = strtolower(fileext($filename));
  1411. }
  1412. if($newattachsave) {
  1413. switch($newattachsave) {
  1414. case 1: $attach_subdir = 'forumid_'.$fid; break;
  1415. case 2: $attach_subdir = 'ext_'.$extension; break;
  1416. case 3: $attach_subdir = 'month_'.gmdate('ym', $dateline); break;
  1417. case 4: $attach_subdir = 'day_'.gmdate('ymd', $dateline); break;
  1418. }
  1419. $attach_dir = $attachpath.'/'.$attach_subdir;
  1420. if(!is_dir($attach_dir)) {
  1421. mkdir($attach_dir, 0777);
  1422. @fclose(fopen($attach_dir.'/index.htm', 'w'));
  1423. }
  1424. $newattachment = $attach_subdir.'/'.$realname;
  1425. } else {
  1426. $newattachment = $realname;
  1427. }
  1428. $newpath = $attachpath.'/'.$newattachment;
  1429. $asql1 = "UPDATE {$tablepre}attachments SET attachment = '$newattachment' WHERE aid = '$aid'";
  1430. $asql2 = "UPDATE {$tablepre}attachments SET attachment = '$attachment' WHERE aid = '$aid'";
  1431. if($db->query($asql1)) {
  1432. if(rename($oldpath, $newpath)) {
  1433. if($isimage && $thumb) {
  1434. $thumboldpath = $oldpath.'.thumb.jpg';
  1435. $thumbnewpath = $newpath.'.thumb.jpg';
  1436. rename($thumboldpath, $thumbnewpath);
  1437. }
  1438. $convertedrows ++;
  1439. } else {
  1440. $db->query($asql2);
  1441. }
  1442. }
  1443. $totalrows ++;
  1444. }
  1445. }
  1446. if($converted || $end < $maxid) {
  1447. continue_redirect('dz_moveattach', '&newattachsave='.$newattachsave.'&cattachdir='.$cattachdir);
  1448. } else {
  1449. $msg = "$atoption[$newattachsave] ??????<br><li>??".$totalrows."?????</li><br /><li>???".$convertedrows."???</li>";
  1450. errorpage($msg,'',0,0);
  1451. }
  1452. } else {
  1453. $attachsave = $db->result($db->query("SELECT value FROM {$tablepre}settings WHERE variable = 'attachsave' LIMIT 1"), 0);
  1454. $checked[$attachsave] = 'checked';
  1455. echo "<form method=\"post\" action=\"tools.php?action=dz_moveattach\" onSubmit=\"return confirm('??????????????\\n????????????');\">
  1456. <table>
  1457. <tr>
  1458. <th>??????????????????<font color=\"red\">???????????????????????</font></th></tr><tr><td>";
  1459. foreach($atoption as $key => $val) {
  1460. echo "<li style=\"list-style:none;\"><input class=\"radio\" name=\"newattachsave\" type=\"radio\" value=\"$key\" $checked[$key]>&nbsp; $val</input></li><br>";
  1461. }
  1462. echo "
  1463. </td></tr></table>
  1464. <input type=\"hidden\" id=\"oldattachsave\" name=\"oldattachsave\" style=\"display:none;\" value=\"$attachsave\">
  1465. <input type=\"submit\" name=\"moveattsubmit\" value=\"? &nbsp; ?\">
  1466. </form>";
  1467. specialdiv();
  1468. echo "<script>$('jsmenu').style.display='inline';</script>";
  1469. }
  1470. htmlfooter();
  1471. } elseif($action == 'dz_rplastpost') {//?????????
  1472. //??????????
  1473. define('IN_DISCUZ', TRUE);
  1474. require_once TOOLS_ROOT."./config.inc.php";
  1475. require_once TOOLS_ROOT."./include/db_mysql.class.php";
  1476. $db = new dbstuff;
  1477. $db->connect($dbhost, $dbuser, $dbpw, $dbname, $pconnect, true, $dbcharset);
  1478. $dbuser = $dbpw = $dbname = $pconnect = NULL;
  1479. if($db->version > '4.1') {
  1480. $serverset = "character_set_connection=$dbcharset, character_set_results=$dbcharset, character_set_client=binary";
  1481. $serverset && $db->query("SET $serverset");
  1482. }
  1483. $selectfid = $_POST['fid'];
  1484. if($selectfid) {
  1485. $i = 0;
  1486. foreach($selectfid as $fid) {
  1487. $sql = "select t.tid, t.subject, p.subject AS psubject, p.dateline, p.author from {$tablepre}threads t, {$tablepre}posts p where t.fid=$fid and p.tid=t.tid and t.displayorder>=0 and p.invisible=0 and p.status=0 order by p.dateline DESC limit 1";
  1488. $query = $db->query($sql);
  1489. $lastarray = array();
  1490. if($lastarray = $db->fetch_array($query)) {
  1491. $lastarray['subject'] = $lastarray['psubject']?$lastarray['psubject']:$lastarray['subject'];
  1492. $lastpoststr = $lastarray['tid']."\t".$lastarray['subject']."\t".$lastarray['dateline']."\t".$lastarray['author'];
  1493. $db->query("update {$tablepre}forums set lastpost='$lastpoststr' where fid=$fid");
  1494. }
  1495. }
  1496. htmlheader();
  1497. show_tools_message("????", 'tools.php?action=dz_rplastpost');
  1498. htmlfooter();
  1499. } else {
  1500. htmlheader();
  1501. echo '<h4>???????? </h4><div class=\"specialdiv\">?????<ul>
  1502. <li>????????????????????????????????????</li>
  1503. </ul></div>';
  1504. echo '<div class="tabbody">
  1505. <script language="javascript">
  1506. function checkall(form, prefix, checkall) {
  1507. var checkall = checkall ? checkall : \'chkall\';
  1508. for(var i = 0; i < form.elements.length; i++) {
  1509. var e = form.elements[i];
  1510. if(e.name != checkall && (!prefix || (prefix && e.name.match(prefix)))) {
  1511. e.checked = form.elements[checkall].checked;
  1512. }
  1513. }
  1514. }
  1515. </script>
  1516. <form action="tools.php?action=dz_rplastpost" method="post">
  1517. <h4 style="font-size:14px;">??????</h4>
  1518. <style>table.re_forum_list { margin-left:0; width:30%;} .re_forum_list input { margin:0; margin-right:10px; border-style:none;}</style>
  1519. <table class="re_forum_list">
  1520. <tr><th><input class="checkbox re_forum_input" name="chkall" onclick="checkall(this.form)" type="checkbox" ><strong>??</strong></th></tr>';
  1521. $sql = "SELECT fid,name FROM {$tablepre}forums WHERE type='forum' or type='sub'";
  1522. $query = mysql_query($sql);
  1523. $forum_array = array();
  1524. while($forumarray = mysql_fetch_array($query)) {
  1525. echo '<tr><td><input name="fid[]" value="'.$forumarray[fid].'" type="checkbox" >'.$forumarray['name'].'</td></tr>';
  1526. }
  1527. echo '</table>
  1528. <div class="opt">
  1529. <input type="submit" name="submit" value="??" tabindex="3" />
  1530. </div>
  1531. </form>
  1532. </div>';
  1533. specialdiv();
  1534. echo "<script>$('jsmenu').style.display='inline';</script>";
  1535. htmlfooter();
  1536. }
  1537. } elseif($action == 'dz_rpthreads') {//??????
  1538. //??????????
  1539. define('IN_DISCUZ', TRUE);
  1540. require_once TOOLS_ROOT."./config.inc.php";
  1541. require_once TOOLS_ROOT."./include/db_mysql.class.php";
  1542. $db = new dbstuff;
  1543. $db->connect($dbhost, $dbuser, $dbpw, $dbname, $pconnect, true, $dbcharset);
  1544. $dbuser = $dbpw = $dbname = $pconnect = NULL;
  1545. if($db->version > '4.1') {
  1546. $serverset = "character_set_connection=$dbcharset, character_set_results=$dbcharset, character_set_client=binary";
  1547. $serverset && $db->query("SET $serverset");
  1548. }
  1549. if($rpthreadssubmit) {
  1550. if(empty($start)) {
  1551. $start = 0;
  1552. }
  1553. if($fids) {
  1554. if(is_array($fids)) {
  1555. $fidstr = implode(',', $fids);
  1556. } else {
  1557. $fidstr = $fids;
  1558. }
  1559. $sql = "select tid from {$tablepre}threads where fid in (0,$fidstr) and displayorder>='0' limit $start, 500";
  1560. $countsql = "select count(*) from {$tablepre}threads where fid in (0,$fidstr) and displayorder>='0'";
  1561. } else {
  1562. $sql = "select tid from {$tablepre}threads where displayorder>='0' limit $start, 500";
  1563. $countsql = "select count(*) from {$tablepre}threads where displayorder>='0'";
  1564. }
  1565. $query = mysql_query($countsql);
  1566. $threadnum = mysql_result($query,0);
  1567. if($threadnum < $start) {
  1568. htmlheader();
  1569. show_tools_message('????????????', 'tools.php?action=dz_rpthreads');
  1570. htmlfooter();
  1571. exit;
  1572. }
  1573. $query = mysql_query($sql);
  1574. while($thread = mysql_fetch_array($query)) {
  1575. $tid = $thread['tid'];
  1576. $processed = 1;
  1577. $updatequery = mysql_query("SELECT COUNT(*) FROM {$tablepre}posts WHERE tid='$tid' AND invisible='0'");
  1578. $replies = mysql_result($updatequery, 0) - 1;
  1579. $updatequery = mysql_query("SELECT a.aid FROM {$tablepre}posts p, {$tablepre}attachments a WHERE a.tid='$tid' AND a.pid=p.pid AND p.invisible='0' LIMIT 1");
  1580. $attachment = mysql_num_rows($updatequery) ? 1 : 0;
  1581. $updatequery = mysql_query("SELECT pid, subject, rate FROM {$tablepre}posts WHERE tid='$tid' AND invisible='0' ORDER BY dateline LIMIT 1");
  1582. $firstpost = mysql_fetch_array($updatequery);
  1583. $firstpost['subject'] = addslashes(cutstr($firstpost['subject'], 79));
  1584. @$firstpost['rate'] = $firstpost['rate'] / abs($firstpost['rate']);
  1585. $updatequery = mysql_query("SELECT author, dateline FROM {$tablepre}posts WHERE tid='$tid' AND invisible='0' ORDER BY dateline DESC LIMIT 1");
  1586. $lastpost = mysql_fetch_array($updatequery);
  1587. mysql_query("UPDATE {$tablepre}threads SET subject='$firstpost[subject]', replies='$replies', lastpost='$lastpost[dateline]', lastposter='".addslashes($lastpost['author'])."', rate='$firstpost[rate]', attachment='$attachment' WHERE tid='$tid'");
  1588. mysql_query("UPDATE {$tablepre}posts SET first='1', subject='$firstpost[subject]' WHERE pid='$firstpost[pid]'");
  1589. mysql_query("UPDATE {$tablepre}posts SET first='0' WHERE tid='$tid' AND pid<>'$firstpost[pid]'");
  1590. }
  1591. htmlheader();
  1592. show_tools_message('????? '.$start.' ??? '.($start+500).' ???', 'tools.php?action=dz_rpthreads&rpthreadssubmit=true&fids='.$fidstr.'&start='.($start+500));
  1593. htmlfooter();
  1594. } else {
  1595. htmlheader();
  1596. echo '<h4>?????? </h4><div class=\"specialdiv\">?????<ul>
  1597. <li>?????????"?????"???????????????????</li>
  1598. <li>?????????????????????????????</li>
  1599. <li>??????????????????</li>
  1600. </ul></div>';
  1601. echo '<div class="tabbody">
  1602. <script language="javascript">
  1603. function checkall(form, prefix, checkall) {
  1604. var checkall = checkall ? checkall : \'chkall\';
  1605. for(var i = 0; i < form.elements.length; i++) {
  1606. var e = form.elements[i];
  1607. if(e.name != checkall && (!prefix || (prefix && e.name.match(prefix)))) {
  1608. e.checked = form.elements[checkall].checked;
  1609. }
  1610. }
  1611. }
  1612. </script>
  1613. <h4 style="font-size:14px;">??????</h4>
  1614. <style>table.re_forum_list { margin-left:0; width:30%;} .re_forum_list input { margin:0; margin-right:10px; border-style:none;}</style>
  1615. <form id="rpthreads" name="rpthreads" method="post" action="tools.php?action=dz_rpthreads">
  1616. <table class="re_forum_list">
  1617. <tr>
  1618. <th><input type="checkbox" name="chkall" onclick="checkall(this.form)" class="checkbox re_forum_input" name="selectall" value="" />??</th>
  1619. </tr>';
  1620. $sql = "SELECT fid,name FROM {$tablepre}forums WHERE type='forum' or type='sub'";
  1621. $query = mysql_query($sql);
  1622. $forum_array = array();
  1623. while($forumarray = mysql_fetch_array($query)) {
  1624. echo '<tr><td><input name="fids[]" value="'.$forumarray[fid].'" type="checkbox" >'.$forumarray['name'].'</td></tr>';
  1625. }
  1626. echo '</table>
  1627. <div class="opt">
  1628. <input type="submit" name="rpthreadssubmit" value="??" />
  1629. </div>
  1630. </form>
  1631. </div>';
  1632. specialdiv();
  1633. echo "<script>$('jsmenu').style.display='inline';</script>";
  1634. htmlfooter();
  1635. }
  1636. } elseif($action == 'all_logout') {//????
  1637. setcookie('toolpassword', '', -86400 * 365);
  1638. errorpage("<h6>??????,??????.???????????????.</h6>");
  1639. } elseif($action == 'all_config') {
  1640. htmlheader();
  1641. echo '<h4>????????</h4>';
  1642. echo "<div class=\"specialdiv\">?????<ul id=\"ping\">
  1643. <li>??????????????????????????????????????</li>
  1644. </ul></div>";
  1645. if($submit) {
  1646. all_doconfig_modify($whereis);
  1647. }
  1648. ping($whereis);
  1649. all_doconfig_output($whereis);
  1650. htmlfooter();
  1651. } elseif($action == 'phpinfo') {
  1652. echo phpinfo(13);exit;
  1653. } elseif($action == 'datago') {
  1654. htmlheader();
  1655. !$tableno && $tableno = 0;
  1656. !$do && $do = 'create';
  1657. !$start && $start = 0;
  1658. $limit = 2000;
  1659. echo '<h4>???????</h4>';
  1660. echo "<div class=\"specialdiv\">?????<ul>
  1661. <li><font color=red>??????????????????????????????</font></li>
  1662. <li>???????<a href='http://www.discuz.net/thread-1460873-1-1.html'><font color=red>??Tools?????????</font></a></li>
  1663. <li>????????????????</li>
  1664. </ul></div>";
  1665. if($submit) {
  1666. do_datago($mysql,$tableno,$do,$start,$limit);
  1667. } elseif($my_version > '4.1') {
  1668. datago_output();
  1669. } else {
  1670. echo '?????????????';
  1671. }
  1672. htmlfooter();
  1673. } elseif($action == 'all_backup') {
  1674. htmlheader();
  1675. if($begin == '1') {
  1676. echo "<h4>?????</h4><div class=\"specialdiv\">?????<ul>
  1677. <li>???????api/dbbak.php?????????????</li>
  1678. <li>????????????????????</li>
  1679. <li>??????????????,???????????(?? 10 ??)???,???</li></ul></div>";
  1680. $title = '<h5><a href="?action=all_restore">??????</a>';
  1681. $title .= '&nbsp;&nbsp;&nbsp;<a href="?action=all_backup&begin=1">??????</a></h5>';
  1682. echo $title;
  1683. $begin = '<a href="?action=all_backup"><input style="margin:0px;" type="button" value=????></a>';
  1684. cexit($begin);
  1685. }
  1686. $notice = "<div class=\"specialdiv\">?????<ul>
  1687. <li>????????</li>
  1688. </ul></div>";
  1689. if(!file_exists('./api/dbbak.php')) {
  1690. cexit($notice);
  1691. }
  1692. if($nexturl) {
  1693. $url = $nexturl;
  1694. } else {
  1695. $url = getbakurl($whereis);
  1696. }
  1697. dobak($url,$num);
  1698. htmlfooter();
  1699. } else {
  1700. htmlheader();
  1701. echo '<h4>????? Comsenz ???????</h4>
  1702. <tr><td><br>';
  1703. echo '<h5>Comsenz ????????????</h5><ul>';
  1704. foreach($functionall as $value) {
  1705. $apps = explode('_', $value['0']);
  1706. if(in_array(substr($whereis, 3), $apps) || $value['0'] == 'all') {
  1707. echo '<li>'.$value[2].'?'.$value[3].'</li>';
  1708. }
  1709. }
  1710. echo '</ul>';
  1711. htmlfooter();
  1712. }
  1713. //???
  1714. function cexit($message) {
  1715. echo $message;
  1716. specialdiv();
  1717. htmlfooter();
  1718. }
  1719. //?????
  1720. function checktable($table, $loops = 0,$doc) {
  1721. global $db, $nohtml, $simple, $counttables, $oktables, $errortables, $rapirtables;
  1722. $query = mysql_query("show create table $table");
  1723. if($createarray = mysql_fetch_array($query)) {
  1724. if(strpos($createarray[1], 'TYPE=HEAP')) {
  1725. $counttables --;
  1726. return ;
  1727. }
  1728. }
  1729. $result = mysql_query("CHECK TABLE $table");
  1730. if(!$result) {
  1731. $counttables --;
  1732. return ;
  1733. }
  1734. $message = "\n>>>>>>>>>>>>>Checking Table $table\r\n---------------------------------\r\n";
  1735. @writefile($doc,$message,'a');
  1736. $error = 0;
  1737. while($r = mysql_fetch_row($result)) {
  1738. if($r[2] == 'error') {
  1739. if($r[3] == "The handler for the table doesn't support check/repair") {
  1740. $r[2] = 'status';
  1741. $r[3] = 'This table does not support check/repair/optimize';
  1742. unset($bgcolor);
  1743. $nooptimize = 1;
  1744. } else {
  1745. $error = 1;
  1746. $bgcolor = 'red';
  1747. unset($nooptimize);
  1748. }
  1749. $view = '??';
  1750. $errortables += 1;
  1751. } else {
  1752. unset($bgcolor);
  1753. unset($nooptimize);
  1754. $view = '??';
  1755. if($r[3] == 'OK') {
  1756. $oktables += 1;
  1757. } elseif($r[3] == 'The storage engine for the table doesn\'t support check') {
  1758. $oktables += 1;
  1759. }
  1760. }
  1761. $message = "$r[0] | $r[1] | $r[2] | $r[3]\r\n";
  1762. @writefile($doc,$message,'a');
  1763. }
  1764. if($error) {
  1765. $message = ">>>>>>>>????? / Repairing Table $table\r\n";
  1766. @writefile($doc,$message,'a');
  1767. $result2=mysql_query("REPAIR TABLE $table");
  1768. while($r2 = mysql_fetch_row($result2)) {
  1769. if($r2[3] == 'OK') {
  1770. $bgcolor='blue';
  1771. $rapirtables += 1;
  1772. } else {
  1773. unset($bgcolor);
  1774. }
  1775. $message = "$r2[0] | $r2[1] | $r2[2] | $r2[3]\r\n";
  1776. @writefile($doc,$message,'a');
  1777. }
  1778. }
  1779. if(($result2[3] == 'OK'||!$error)&&!$nooptimize) {
  1780. $message = ">>>>>>>>>>>>>Optimizing Table $table\r\n";
  1781. @writefile($doc,$message,'a');
  1782. $result3 = mysql_query("OPTIMIZE TABLE $table");
  1783. $error = 0;
  1784. while($r3 = mysql_fetch_row($result3)) {
  1785. if($r3[2] == 'error') {
  1786. $error = 1;
  1787. $bgcolor = 'red';
  1788. } else {
  1789. unset($bgcolor);
  1790. }
  1791. $message = "$r3[0] | $r3[1] | $r3[2] | $r3[3]\r\n\r\n";
  1792. @writefile($doc,$message,'a');
  1793. }
  1794. }
  1795. if($error && $loops) {
  1796. checktable($table,($loops-1),$doc);
  1797. }
  1798. }
  1799. //????
  1800. function checkcachefiles($currentdir){
  1801. global $authkey;
  1802. $dir = opendir($currentdir);
  1803. $exts = '/\.php$/i';
  1804. $showlist = $modifylist = $addlist = array();
  1805. while($entry = readdir($dir)) {
  1806. $file = $currentdir.$entry;
  1807. if($entry != '.' && $entry != '..' && preg_match($exts, $entry)) {
  1808. @$fp = fopen($file, 'rb');
  1809. @$cachedata = fread($fp, filesize($file));
  1810. @fclose($fp);
  1811. if(preg_match("/^<\?php\n\/\/Discuz! cache file, DO NOT modify me!\n\/\/Created: [\w\s,:]+\n\/\/Identify: (\w{32})\n\n(.+?)\?>$/s", $cachedata, $match)) {
  1812. $showlist[$file] = $md5 = $match[1];
  1813. $cachedata = $match[2];
  1814. if(md5($entry.$cachedata.$authkey) != $md5) {
  1815. $modifylist[$file] = $md5;
  1816. }
  1817. } else {
  1818. $showlist[$file] = $addlist[$file] = '';
  1819. }
  1820. }
  1821. }
  1822. return array($showlist, $modifylist, $addlist);
  1823. }
  1824. function continue_redirect($action = 'dz_mysqlclear', $extra = ''){
  1825. global $scriptname, $step, $actionnow, $start, $end, $stay, $convertedrows, $allconvertedrows, $totalrows, $maxid;
  1826. if($action == 'doctor') {
  1827. $url = "?action=$action{$extra}";
  1828. } else {
  1829. $url = "?action=$action&step=".$step."&start=".($end + 1)."&stay=$stay&totalrows=$totalrows&convertedrows=$convertedrows&maxid=$maxid&allconvertedrows=$allconvertedrows".$extra;
  1830. }
  1831. $timeout = $GLOBALS['debug'] ? 5000 : 2000;
  1832. echo "<script>\r\n";
  1833. echo "<!--\r\n";
  1834. echo "function redirect() {\r\n";
  1835. echo " window.location.replace('".$url."');\r\n";
  1836. echo "}\r\n";
  1837. echo "setTimeout('redirect();', $timeout);\r\n";
  1838. echo "-->\r\n";
  1839. echo "</script>\r\n";
  1840. if($action== 'doctor') {
  1841. echo '<h4>????</h4><br><table>
  1842. <tr><th>??????,???</th></tr><tr><td>';
  1843. echo "<br><a href=\"".$url."\">???????????????????????</a><br><br>";
  1844. echo '</td></tr></table>';
  1845. } elseif($action == 'uch_dz_replace') {
  1846. echo '<h4>?????</h4><table>
  1847. <tr><th>????'.$actionnow.'</th></tr><tr><td>';
  1848. echo "???? $start ---- $end ???[<a href='$url&stop=1' style='color:red'>????</a>]";
  1849. echo "<br><br><a href=\"".$url."\">???????????????????????</a>";
  1850. echo '</td></tr></table>';
  1851. } else {
  1852. echo '<h4>?????</h4><table>
  1853. <tr><th>????'.$actionnow.'</th></tr><tr><td>';
  1854. echo "???? $start ---- $end ???[<a href='?action=$action' style='color:red'>????</a>]";
  1855. echo "<br><br><a href=\"".$url."\">???????????????????????</a>";
  1856. echo '</td></tr></table>';
  1857. }
  1858. }
  1859. function dirsize($dir){
  1860. $dh = @opendir($dir);
  1861. $size = 0;
  1862. while($file = @readdir($dh)) {
  1863. if($file != '.' && $file != '..') {
  1864. $path = $dir.'/'.$file;
  1865. if(@is_dir($path)) {
  1866. $size += dirsize($path);
  1867. } else {
  1868. $size += @filesize($path);
  1869. }
  1870. }
  1871. }
  1872. @closedir($dh);
  1873. return $size;
  1874. }
  1875. function get_real_size($size){
  1876. $kb = 1024;
  1877. $mb = 1024 * $kb;
  1878. $gb = 1024 * $mb;
  1879. $tb = 1024 * $gb;
  1880. if($size < $kb) {
  1881. return $size.' Byte';
  1882. } elseif($size < $mb) {
  1883. return round($size/$kb,2).' KB';
  1884. } elseif($size < $gb) {
  1885. return round($size/$mb,2).' MB';
  1886. } elseif($size < $tb) {
  1887. return round($size/$gb,2).' GB';
  1888. } else {
  1889. return round($size/$tb,2).' TB';
  1890. }
  1891. }
  1892. function htmlheader() {
  1893. global $uch_version,$alertmsg, $whereis, $functionall,$dz_version,$ss_version,$toolpassword,$tool_password,$toolbar,$plustitle;
  1894. switch($whereis) {
  1895. case 'is_dz':
  1896. $plustitle = 'Discuz '.substr($dz_version,0,1).'.'.substr($dz_version,1,1);
  1897. break;
  1898. case 'is_uch':
  1899. $plustitle = 'UCenter Home '.substr($uch_version,0,1).'.'.substr($uch_version,1);
  1900. break;
  1901. case 'is_ss':
  1902. $plustitle = 'SupeSite '.substr($ss_version,0,1).'.'.substr($ss_version,1,1);;
  1903. break;
  1904. case 'is_uc':
  1905. $plustitle = 'UCenter';
  1906. break;
  1907. default:
  1908. $plustitle = '';
  1909. break;
  1910. }
  1911. echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  1912. <html>
  1913. <head>
  1914. <meta http-equiv="Content-Type" content="text/html; charset=GBK">
  1915. <title>Comsenz ??????? '.VERSION.'-New</title>
  1916. <style type="text/css"><!--
  1917. body {font-family: Tahoma,Arial, Helvetica, sans-serif, "??";font-size: 12px;color:#000;line-height: 120%;padding:0;margin:0;background:#DDE0FF;overflow-x:hidden;word-break:break-all;white-space:normal;scrollbar-3d-light-color:#606BFF;scrollbar-highlight-color:#E3EFF9;scrollbar-face-color:#CEE3F4;scrollbar-arrow-color:#509AD8;scrollbar-shadow-color:#F0F1FF;scrollbar-base-color:#CEE3F4;}
  1918. a:hover {color:#60F;}
  1919. ul {padding:2px 0 10px 0;margin:0;}
  1920. textarea,table,td,th,select{border:1px solid #868CFF;border-collapse:collapse;}
  1921. table li {margin-left:10px;}
  1922. input{margin:10px 0 0px 30px;border-width:1px;border-style:solid;border-color:#FFF #64A7DD #64A7DD #FFF;padding:2px 8px;background:#E3EFF9;}
  1923. input.radio,input.checkbox,input.textinput,input.specialsubmit {margin:0;padding:0;border:0;padding:0;background:none;}
  1924. input.textinput,input.specialsubmit {border:1px solid #AFD2ED;background:#FFF;}
  1925. input.textinput {padding:4px 0;} input.specialsubmit {border-color:#FFF #64A7DD #64A7DD #FFF;background:#E3EFF9;padding:0 5px;}
  1926. option {background:#FFF;}
  1927. select {background:#F0F1FF;}
  1928. #header {border-top:4px solid #86B9D6;height:60px;width:100%;padding:0;margin:0;}
  1929. h2 {font-size:20px;font-weight:normal;position:absolute;top:20px;left:20px;padding:10px;margin:0;}
  1930. h3 {font-size:14px;position:absolute;top:28px;right:20px;padding:10px;margin:0;}
  1931. #content {height:510px;background:#F0F1FF;overflow-x:hidden;z-index:1000;}
  1932. #nav {top:60px;left:0;height:510px;width:180px;border-right:1px solid #DDE0FF;position:absolute;z-index:2000;}
  1933. #nav ul {padding:0 10px;padding-top:30px;}
  1934. #nav li {list-style:none;}
  1935. #nav li a {font-size:14px;line-height:180%;font-weight:400;color:#000;}
  1936. #nav li a:hover {color:#60F;}
  1937. #textcontent {padding-left:200px;height:510px;width:80%;*width:100%;line-height:160%;overflow-y:auto;overflow-x:hidden;}
  1938. h4,h5,h6 {padding:4px;font-size:16px;font-weight:bold;margin-top:20px;margin-bottom:5px;color:#006;}
  1939. h5,h6 {font-size:14px;color:#000;}
  1940. h6 {color:#F00;padding-top:5px;margin-top:0;}
  1941. .specialdiv {width:70%;border:1px dashed #C8CCFF;padding:0 5px;margin-top:20px;background:#F9F9FF;}
  1942. .specialdiv2 {height:240px;width:60%;border:1px dashed #C8CCFF;padding:15px;margin-top:20px;background:#F9F9FF;overflow-y:scroll;}
  1943. #textcontent ul {margin-left:30px;}
  1944. textarea {width:78%;height:300px;text-align:left;border-color:#AFD2ED;}
  1945. select {border-color:#AFD2ED;}
  1946. table {width:74%;font-size:12px;margin-left:18px;margin-top:10px;}
  1947. table.specialtable,table.specialtable td {border:0;}
  1948. td,th {padding:5px;text-align:left;}
  1949. caption {font-weight:bold;padding:8px 0;color:#3544FF;text-align:left;}
  1950. th {background:#D9DCFF;font-weight:600;}
  1951. td.specialtd {text-align:left;}
  1952. .specialtext {background:#FCFBFF;margin-top:20px;padding:5px 40px;width:64.5%;margin-bottom:10px;color:#006;}
  1953. #footer p {padding:0 5px;text-align:center;}
  1954. #jsmenu {margin-left:-200px;margin-top:-110px;border:5px solid #868CFF;width:400px;height:140px;padding:4px 10px 0 10px; text-align:left;background:#FFF; left:50%; top:50%; position:absolute; font:12px;zIndex:10001;}
  1955. .button {margin-top:20px;}
  1956. .infobox {background:#FFF;border-bottom:4px solid #868CFF;border-top:4px solid #868CFF;margin-bottom:10px;padding:30px;text-align:center;width:90%;}
  1957. pre {*margin-top:10px;}
  1958. .current { font-weight: bold; color: #090 !important; border-bottom-color: #F90 !important; }
  1959. -->
  1960. </style>
  1961. </head>
  1962. <script>function $(id) {return document.getElementById(id);}
  1963. function menuclose(){
  1964. $(\'jsmenu\').style.display = \'none\';
  1965. }
  1966. </script>
  1967. <body>
  1968. <div id = "jsmenu" style="display:none">
  1969. <h6>???</h6>
  1970. ?????????????????????????????????????<br/>
  1971. <input class=button onclick=menuclose() type=button value=????></input>
  1972. </div>
  1973. <div id="header">
  1974. <h2>< Comsenz Tools '.VERSION.' > Now In: '.$plustitle.'</h2>
  1975. <h3>[ <a href="?" target="_self">??</a> ]&nbsp;
  1976. [ <a href="?action=all_setlock" target="_self">??</a> ]&nbsp;';
  1977. if($toolpassword == md5($tool_password)) {
  1978. foreach($toolbar as $value) {
  1979. echo '[ <a href="?action='.$value[0].'" target="_self">'.$value[1].'</a> ]&nbsp';
  1980. }
  1981. }
  1982. echo '</h3></div>
  1983. <div id="nav">';
  1984. echo '<ul>';//????????????????
  1985. if($toolpassword == md5($tool_password)) {
  1986. foreach($functionall as $value) {
  1987. $apps = explode('_', $value['0']);
  1988. if(in_array(substr($whereis, 3), $apps) || $value['0'] == 'all') {
  1989. if($whereis == 'is_ss' && $value[1] == 'all_setadmin' && $ss_version<70 ) {
  1990. continue;
  1991. }
  1992. echo '<li>[ <a href="?action='.$value[1].'" target="_self">'.$value[2].'</a> ]</li>';
  1993. }
  1994. }
  1995. } else {
  1996. echo '<li>[ <a href="tools.php" target="_self">??????</a> ]</li>';
  1997. }
  1998. echo '</ul>';
  1999. echo '</div>
  2000. <div id="content">
  2001. <div id="textcontent">';
  2002. }
  2003. //????
  2004. function htmlfooter(){
  2005. echo '</div></div>
  2006. <div id="footer"><p>Comsenz ??????? &nbsp;Release:'.Release.'&nbsp;
  2007. &copy; <a href="http://www.comsenz.com" style="color: #000000; text-decoration: none">Comsenz Inc.</a> 2001-2009 </font></td></tr><tr style="font-size: 0px; line-height: 0px; spacing: 0px; padding: 0px; background-color: #698CC3">
  2008. </p></div>
  2009. </body>
  2010. </html>';
  2011. exit;
  2012. }
  2013. //????
  2014. function errorpage($message,$title = '',$isheader = 1,$isfooter = 1){
  2015. if($isheader) {
  2016. htmlheader();
  2017. }
  2018. !$isheader && $title = '';
  2019. if($message == 'login') {
  2020. $message ='<h4>?????</h4>
  2021. <form action="?" method="post">
  2022. <table class="specialtable"><tr>
  2023. <td width="20%"><input class="textinput" type="password" name="toolpassword"></input></td>
  2024. <td><input class="specialsubmit" type="submit" value="? ?"></input></td></tr></table>
  2025. <input type="hidden" name="action" value="login">
  2026. </form>';
  2027. } else {
  2028. $message = "<h4>$title</h4><br><br><table><tr><th>????</th></tr><tr><td>$message</td></tr></table>";
  2029. }
  2030. echo $message;
  2031. if($isfooter) {
  2032. htmlfooter();
  2033. }
  2034. }
  2035. //??
  2036. function redirect($url) {
  2037. echo "<script>";
  2038. echo "function redirect() {window.location.replace('$url');}\n";
  2039. echo "setTimeout('redirect();', 2000);\n";
  2040. echo "</script>";
  2041. echo "<br><br><a href=\"$url\">???????????????????</a>";
  2042. cexit("");
  2043. }
  2044. /**
  2045. * ?????????????
  2046. * @param unknown_type $directory
  2047. */
  2048. //??sql??
  2049. function splitsql($sql){
  2050. $sql = str_replace("\r", "\n", $sql);
  2051. $ret = array();
  2052. $num = 0;
  2053. $queriesarray = explode(";\n", trim($sql));
  2054. unset($sql);
  2055. foreach($queriesarray as $query) {
  2056. $queries = explode("\n", trim($query));
  2057. foreach($queries as $query) {
  2058. $ret[$num] .= $query[0] == "#" ? NULL : $query;
  2059. }
  2060. $num++;
  2061. }
  2062. return($ret);
  2063. }
  2064. function syntablestruct($sql, $version, $dbcharset) {
  2065. if(strpos(trim(substr($sql, 0, 18)), 'CREATE TABLE') === FALSE) {
  2066. return $sql;
  2067. }
  2068. if(substr(trim($sql), 0, 9) == 'SET NAMES' && !$version) {
  2069. return '';
  2070. }
  2071. $sqlversion = strpos($sql, 'ENGINE=') === FALSE ? FALSE : TRUE;
  2072. if($sqlversion === $version) {
  2073. return $sqlversion && $dbcharset ? preg_replace(array('/ character set \w+/i', '/ collate \w+/i', "/DEFAULT CHARSET=\w+/is"), array('', '', "DEFAULT CHARSET=$dbcharset"), $sql) : $sql;
  2074. }
  2075. if($version) {
  2076. return preg_replace(array('/TYPE=HEAP/i', '/TYPE=(\w+)/is'), array("ENGINE=MEMORY DEFAULT CHARSET=$dbcharset", "ENGINE=\\1 DEFAULT CHARSET=$dbcharset"), $sql);
  2077. } else {
  2078. return preg_replace(array('/character set \w+/i', '/collate \w+/i', '/ENGINE=MEMORY/i', '/\s*DEFAULT CHARSET=\w+/is', '/\s*COLLATE=\w+/is', '/ENGINE=(\w+)(.*)/is'), array('', '', 'ENGINE=HEAP', '', '', 'TYPE=\\1\\2'), $sql);
  2079. }
  2080. }
  2081. function stay_redirect() {
  2082. global $action, $actionnow, $step, $stay, $convertedrows, $allconvertedrows;
  2083. $nextstep = $step + 1;
  2084. echo '<h4>?????????</h4><table>
  2085. <tr><th>????'.$actionnow.'</th></tr><tr>
  2086. <td>';
  2087. if($stay) {
  2088. $actions = isset($action[$nextstep]) ? $action[$nextstep] : '??';
  2089. echo "$actionnow ????.???<font color=red>{$convertedrows}</font>???.".($stay == 1 ? "&nbsp;&nbsp;&nbsp;&nbsp;" : '').'<br><br>';
  2090. echo "<a href='?action=dz_mysqlclear&step=".$nextstep."&stay=1'>( $actions )???????</a><br>";
  2091. } else {
  2092. if(isset($action[$nextstep])) {
  2093. echo '?????'.$action[$nextstep].'......';
  2094. }
  2095. $allconvertedrows = $allconvertedrows + $convertedrows;
  2096. $timeout = $GLOBALS['debug'] ? 5000 : 2000;
  2097. echo "<script>\r\n";
  2098. echo "<!--\r\n";
  2099. echo "function redirect() {\r\n";
  2100. echo " window.location.replace('?action=dz_mysqlclear&step=".$nextstep."&allconvertedrows=".$allconvertedrows."');\r\n";
  2101. echo "}\r\n";
  2102. echo "setTimeout('redirect();', $timeout);\r\n";
  2103. echo "-->\r\n";
  2104. echo "</script>\r\n";
  2105. echo "[<a href='?action=dz_mysqlclear' style='color:red'>????</a>]<br><br><a href=\"".$scriptname."?step=".$nextstep."\">???????????????????????</a>";
  2106. }
  2107. echo '</td></tr></table>';
  2108. }
  2109. //????????
  2110. function loadtable($table, $force = 0) {
  2111. global $carray;
  2112. $discuz_tablepre = $carray['tablepre'];
  2113. static $tables = array();
  2114. if(!isset($tables[$table])) {
  2115. if(mysql_get_server_info() > '4.1') {
  2116. $query = @mysql_query("SHOW FULL COLUMNS FROM {$discuz_tablepre}$table");
  2117. } else {
  2118. $query = @mysql_query("SHOW COLUMNS FROM {$discuz_tablepre}$table");
  2119. }
  2120. while($field = @mysql_fetch_assoc($query)) {
  2121. $tables[$table][$field['Field']] = $field;
  2122. }
  2123. }
  2124. return $tables[$table];
  2125. }
  2126. //??????????? id ?
  2127. function validid($id, $table) {
  2128. global $start, $maxid, $mysql, $tablepre;
  2129. $sql = mysql_query("SELECT MIN($id) AS minid, MAX($id) AS maxid FROM {$tablepre}$table");
  2130. $result = mysql_fetch_array($sql);
  2131. $start = $result['minid'] ? $result['minid'] - 1 : 0;
  2132. $maxid = $result['maxid'];
  2133. }
  2134. //??
  2135. function specialdiv() {
  2136. echo '<div class="specialdiv">
  2137. <h6>???</h6>
  2138. <ul>
  2139. <li>??????????????????????????????????????????????????????????????????</li>
  2140. <li>??????Comsenz ???????????????????????????????????/forumdata?????tool.lock?????????</li></ul></div>';
  2141. }
  2142. //????
  2143. function getplace() {
  2144. global $lockfile, $cfgfile, $docdir;
  2145. $whereis = false;
  2146. if(is_writeable('./config.inc.php') && is_writeable('./forumdata')) {//??Discuz!??
  2147. $whereis = 'is_dz';
  2148. $lockfile = './forumdata/tools.lock';
  2149. $cfgfile = './config.inc.php';
  2150. $docdir = './forumdata';
  2151. }
  2152. if(is_writeable('./data/config.inc.php') && is_dir('./control')) {//??UCenter??
  2153. $whereis = 'is_uc';
  2154. $lockfile = './data/tools.lock';
  2155. $cfgfile = './data/config.inc.php';
  2156. $docdir = './data';
  2157. }
  2158. if(is_writeable('./config.php') && is_dir('source')) {//??UCenter Home??
  2159. $whereis = 'is_uch';
  2160. $lockfile = './data/tools.lock';
  2161. $cfgfile = './config.php';
  2162. $docdir = './data';
  2163. }
  2164. if(is_writeable('./config.php') && file_exists('./batch.common.php')) {//??SupeSite??
  2165. $whereis = 'is_ss';
  2166. $lockfile = './data/tools.lock';
  2167. $cfgfile = './config.php';
  2168. $docdir = './data';
  2169. }
  2170. return $whereis;
  2171. }
  2172. //?????????
  2173. function getdbcfg(){
  2174. global $uc_dbcharset,$uc_dbhost,$uc_dbuser,$uc_dbpw,$uc_dbname,$uc_tablepre,$dbhost, $dbuser, $dbpw, $dbname, $dbcfg, $whereis, $cfgfile, $tablepre, $dbcharset,$dz_version,$ss_version,$uch_version;
  2175. if(@!include($cfgfile)) {
  2176. htmlheader();
  2177. cexit("<h4>????config????????????????</h4>");
  2178. }
  2179. if(UC_DBHOST) {
  2180. $uc_dbhost = UC_DBHOST;
  2181. $uc_dbuser = UC_DBUSER;
  2182. $uc_dbpw = UC_DBPW;
  2183. $uc_dbname = UC_DBNAME;
  2184. $uc_tablepre = UC_DBTABLEPRE;
  2185. $uc_dbcharset = UC_DBCHARSET;
  2186. }
  2187. switch($whereis) {
  2188. case 'is_dz':
  2189. $dbhost = $dbhost;
  2190. $dbuser = $dbuser;
  2191. $dbpw = $dbpw;
  2192. $dbname = $dbname;
  2193. $tablepre = $tablepre;
  2194. $dbcharset = !$dbcharset ? (strtolower($charset) == 'utf-8' ? 'utf8' : $charset): $dbcharset;
  2195. define('IN_DISCUZ',true);
  2196. @require_once "./discuz_version.php";
  2197. $dz_version = DISCUZ_VERSION;
  2198. if($dz_version >= '7.1') {
  2199. $dz_version = intval(str_replace('.','',$dz_version)).'0';
  2200. } else {
  2201. $dz_version = intval(str_replace('.','',$dz_version));
  2202. }
  2203. break;
  2204. case 'is_uc':
  2205. $dbhost = UC_DBHOST;
  2206. $dbuser = UC_DBUSER;
  2207. $dbpw = UC_DBPW;
  2208. $dbname = UC_DBNAME;
  2209. $tablepre = UC_DBTABLEPRE;
  2210. $dbcharset = !UC_DBCHARSET ? (strtolower(UC_CHARSET) == 'utf-8' ? 'utf8' : UC_CHARSET) : UC_DBCHARSET;
  2211. break;
  2212. case 'is_uch':
  2213. $dbhost = $_SC["dbhost"];
  2214. $dbuser = $_SC["dbuser"];
  2215. $dbpw = $_SC["dbpw"];
  2216. $dbname = $_SC["dbname"];
  2217. $tablepre = $_SC["tablepre"];
  2218. if(file_exists("./ver.php")) {
  2219. require './ver.php';
  2220. $uch_version = X_VER;
  2221. } else {
  2222. $common = 'common.php';
  2223. $version = fopen($common,'r');
  2224. $version = fread($version,filesize($common));
  2225. $len = strpos($version,'define(\'D_BUG\')');
  2226. $version = substr($version,0,$len);
  2227. $cache = fopen('./data/version.php','w');
  2228. fwrite($cache,$version);
  2229. fclose($cache);
  2230. require_once './data/version.php';
  2231. $uch_version = intval(str_replace('.','',X_VER));
  2232. unlink('./data/version.php');
  2233. }
  2234. $uch_version = intval(str_replace('.','',$uch_version));
  2235. $dbcharset = !$_SC['dbcharset'] ? (strtolower($_SC["charset"]) == 'utf-8' ? 'utf8' : $_SC["charset"]) : $_SC['dbcharset'] ;
  2236. break;
  2237. case 'is_ss':
  2238. $dbhost = $dbhost ? $dbhos : $_SC['dbhost'];
  2239. $dbuser = $dbuser ? $dbuser : $_SC['dbuser'];
  2240. $dbpw = $dbpw ? $dbpw : $_SC['dbpw'];
  2241. $dbname = $dbname ? $dbname : $_SC['dbname'];
  2242. $tablepre = $tablepre ? $tablepre : $_SC['tablepre'];
  2243. $dbcharset = !$dbcharset ? (strtolower($charset) == 'utf-8' ? 'utf8' : $charset) : $dbcharset;
  2244. if(!$dbcharset) {
  2245. $dbcharset = !$_SC['dbcharset'] ? (strtolower($_SC['charset']) == 'utf-8' ? 'utf8' : $_SC['charset']) : $_SC['dbcharset'];
  2246. }
  2247. if($_SC['dbhost'] || $_SC['dbuser']) {
  2248. $common = 'common.php';
  2249. $version = fopen($common,'r');
  2250. $version = fread($version,filesize($common));
  2251. $len = strpos($version,'define(\'S_RELEASE\'');
  2252. $version = substr($version,0,$len);
  2253. $cache = fopen('./data/version.php','w');
  2254. fwrite($cache,$version);
  2255. fclose($cache);
  2256. require_once './data/version.php';
  2257. $ss_version = intval(str_replace('.','',S_VER));
  2258. unlink('./data/version.php');
  2259. }
  2260. break;
  2261. default:
  2262. $dbhost = $dbuser = $dbpw = $dbname = $tablepre = $dbcharset = '';
  2263. break;
  2264. }
  2265. }
  2266. function taddslashes($string, $force = 0) {
  2267. !defined('MAGIC_QUOTES_GPC') && define('MAGIC_QUOTES_GPC', get_magic_quotes_gpc());
  2268. if(!MAGIC_QUOTES_GPC || $force) {
  2269. if(is_array($string)) {
  2270. foreach($string as $key => $val) {
  2271. $string[$key] = taddslashes($val, $force);
  2272. }
  2273. } else {
  2274. $string = addslashes($string);
  2275. }
  2276. }
  2277. return $string;
  2278. }
  2279. function pregcharset($charset,$color = 0) {
  2280. if(strpos('..'.strtolower($charset), 'gbk')) {
  2281. if($color) {
  2282. return '<font color="#0000CC">gbk</font>';
  2283. } else {
  2284. return 'gbk';
  2285. }
  2286. } elseif(strpos('..'.strtolower($charset), 'latin1')) {
  2287. if($color) {
  2288. return '<font color="#993399">latin1</font>';
  2289. } else {
  2290. return 'latin1';
  2291. }
  2292. } elseif(strpos('..'.strtolower($charset), 'utf8')) {
  2293. if($color) {
  2294. return '<font color="#993300">utf8</font>';
  2295. } else {
  2296. return 'utf8';
  2297. }
  2298. } elseif(strpos('..'.strtolower($charset), 'big5')) {
  2299. if($color) {
  2300. return '<font color="#006699">big5</font>';
  2301. } else {
  2302. return 'big5';
  2303. }
  2304. } else {
  2305. return $charset;
  2306. }
  2307. }
  2308. function show_tools_message($message, $url = 'tools.php',$time = '2000') {
  2309. echo "<script>";
  2310. echo "function redirect() {window.location.replace('$url');}\n";
  2311. echo "setTimeout('redirect();', $time);\n";
  2312. echo "</script>";
  2313. echo "<h4>$title</h4><br><br><table><tr><th>????</th></tr><tr><td>$message<br><a href=\"$url\">???????????????????</a></td></tr></table>";
  2314. exit;
  2315. }
  2316. function fileext($filename) {
  2317. return trim(substr(strrchr($filename, '.'), 1, 10));
  2318. }
  2319. function cutstr($string, $length, $dot = ' ...') {
  2320. global $charset;
  2321. if(strlen($string) <= $length) {
  2322. return $string;
  2323. }
  2324. $string = str_replace(array('&amp;', '&quot;', '&lt;', '&gt;'), array('&', '"', '<', '>'), $string);
  2325. $strcut = '';
  2326. if(strtolower($charset) == 'utf-8') {
  2327. $n = $tn = $noc = 0;
  2328. while($n < strlen($string)) {
  2329. $t = ord($string[$n]);
  2330. if($t == 9 || $t == 10 || (32 <= $t && $t <= 126)) {
  2331. $tn = 1; $n++; $noc++;
  2332. } elseif(194 <= $t && $t <= 223) {
  2333. $tn = 2; $n += 2; $noc += 2;
  2334. } elseif(224 <= $t && $t < 239) {
  2335. $tn = 3; $n += 3; $noc += 2;
  2336. } elseif(240 <= $t && $t <= 247) {
  2337. $tn = 4; $n += 4; $noc += 2;
  2338. } elseif(248 <= $t && $t <= 251) {
  2339. $tn = 5; $n += 5; $noc += 2;
  2340. } elseif($t == 252 || $t == 253) {
  2341. $tn = 6; $n += 6; $noc += 2;
  2342. } else {
  2343. $n++;
  2344. }
  2345. if($noc >= $length) {
  2346. break;
  2347. }
  2348. }
  2349. if($noc > $length) {
  2350. $n -= $tn;
  2351. }
  2352. $strcut = substr($string, 0, $n);
  2353. } else {
  2354. for($i = 0; $i < $length; $i++) {
  2355. $strcut .= ord($string[$i]) > 127 ? $string[$i].$string[++$i] : $string[$i];
  2356. }
  2357. }
  2358. $strcut = str_replace(array('&', '"', '<', '>'), array('&amp;', '&quot;', '&lt;', '&gt;'), $strcut);
  2359. return $strcut.$dot;
  2360. }
  2361. function checkfiles($currentdir, $ext = '', $sub = 1, $skip = '') {
  2362. global $md5data, $dz_files;
  2363. $dir = @opendir($currentdir);
  2364. $exts = '/('.$ext.')$/i';
  2365. $skips = explode(',', $skip);
  2366. while($entry = @readdir($dir)) {
  2367. $file = $currentdir.$entry;
  2368. if($entry != '.' && $entry != '..' && (preg_match($exts, $entry) || $sub && is_dir($file)) && !in_array($entry, $skips)) {
  2369. if($sub && is_dir($file)) {
  2370. checkfiles($file.'/', $ext, $sub, $skip);
  2371. } else {
  2372. $md5data[$file] = md5_file($file);
  2373. }
  2374. }
  2375. }
  2376. }
  2377. function loadtable_ucenter($table, $force = 0) {
  2378. global $carray;
  2379. $discuz_tablepre = $carray['UC_DBTABLEPRE'];
  2380. static $tables = array();
  2381. if(!isset($tables[$table])) {
  2382. if(mysql_get_server_info() > '4.1') {
  2383. $query = @mysql_query("SHOW FULL COLUMNS FROM {$discuz_tablepre}$table");
  2384. } else {
  2385. $query = @mysql_query("SHOW COLUMNS FROM {$discuz_tablepre}$table");
  2386. }
  2387. while($field = @mysql_fetch_assoc($query)) {
  2388. $tables[$table][$field['Field']] = $field;
  2389. }
  2390. }
  2391. return $tables[$table];
  2392. }
  2393. function dz_updatecache(){
  2394. global $dz_version;
  2395. if($dz_version < 710) {
  2396. $cachedir = array('cache','templates');
  2397. } else {
  2398. $cachedir = array('cache','templates','feedcaches');
  2399. }
  2400. $clearmsg = '';
  2401. foreach($cachedir as $dir) {
  2402. if($dh = dir('./forumdata/'.$dir)) {
  2403. while (($file = $dh->read()) !== false) {
  2404. if($file != "." && $file != ".." && $file != "index.htm" && !is_dir($file)) {
  2405. unlink('./forumdata/'.$dir.'/'.$file);
  2406. }
  2407. }
  2408. } else {
  2409. $clearmsg .= './forumdata/'.$dir.'????.<br>';
  2410. }
  2411. }
  2412. return $clearmsg;
  2413. }
  2414. function uch_updatecache(){
  2415. $cachedir = array('data','data/tpl_cache');
  2416. $clearmsg = '';
  2417. foreach($cachedir as $dir) {
  2418. if($dh = dir('./'.$dir)) {
  2419. while (($file = $dh->read()) !== false) {
  2420. if(!is_dir($file) && $file != "." && $file != ".." && $file != "index.htm" && $file != "install.lock" && $file != "sendmail.lock" ) {
  2421. unlink('./'.$dir.'/'.$file);
  2422. }
  2423. }
  2424. } else {
  2425. $clearmsg .= './'.$dir.'????.<br>';
  2426. }
  2427. }
  2428. return $clearmsg;
  2429. }
  2430. function ss_updatecache(){
  2431. $cachedir = array('cache/model','cache/tpl');
  2432. $clearmsg = '';
  2433. foreach($cachedir as $dir) {
  2434. if($dh = dir('./'.$dir)) {
  2435. while (($file = $dh->read()) !== false) {
  2436. if(!is_dir($file) && $file != "." && $file != ".." && $file != "index.htm" && $file != "install.lock" && $file != "sendmail.lock" ) {
  2437. unlink('./'.$dir.'/'.$file);
  2438. }
  2439. }
  2440. } else {
  2441. $clearmsg .= './'.$dir.'????.<br>';
  2442. }
  2443. }
  2444. return $clearmsg;
  2445. }
  2446. function runquery($queries){//??sql??
  2447. global $tablepre,$whereis;
  2448. $sqlquery = splitsql(str_replace(array(' cdb_', ' {tablepre}', ' `cdb_'), array(' '.$tablepre, ' '.$tablepre, ' `'.$tablepre), $queries));
  2449. $affected_rows = 0;
  2450. foreach($sqlquery as $sql) {
  2451. $sql = syntablestruct(trim($sql), $my_version > '4.1', $dbcharset);
  2452. if(trim($sql) != '') {
  2453. mysql_query(stripslashes($sql));
  2454. if($sqlerror = mysql_error()) {
  2455. break;
  2456. } else {
  2457. $affected_rows += intval(mysql_affected_rows());
  2458. }
  2459. }
  2460. }
  2461. if(strpos($queries,'seccodestatus') && $whereis == 'is_dz') {
  2462. dz_updatecache();
  2463. }
  2464. if(strpos($queries,'bbclosed') && $whereis == 'is_dz') {
  2465. dz_updatecache();
  2466. }
  2467. if(strpos($queries,'template') && $whereis == 'is_uch') {
  2468. uch_updatecache();
  2469. }
  2470. if(strpos($queries,'seccode_login') && $whereis == 'is_uch') {
  2471. uch_updatecache();
  2472. }
  2473. if(strpos($queries,'close') && $whereis == 'is_uch') {
  2474. uch_updatecache();
  2475. }
  2476. errorpage($sqlerror? $sqlerror : "???????,????: &nbsp;$affected_rows",'?????');
  2477. if(strpos($queries,'settings') && $whereis == 'is_dz') {
  2478. require_once './include/cache.func.php';
  2479. updatecache('settings');
  2480. }
  2481. }
  2482. function runquery_html(){ //???????????
  2483. global $whereis,$tablepre;
  2484. echo "<h4>????(SQL)</h4>
  2485. <form method=\"post\" action=\"tools.php?action=all_runquery\">
  2486. <h5>??????????????</h4>
  2487. <font color=red>???</font>???????SQL????????????SQL??????????????.<br/><br/>";
  2488. if($whereis == 'is_dz') {
  2489. echo "<select name=\"queryselect\" onChange=\"queries.value = this.value\">
  2490. <option value = ''>???TOOLS??????</option>
  2491. <option value = \"REPLACE INTO ".$tablepre."settings (variable, value) VALUES ('bbclosed', '0')\">??????</option>
  2492. <option value = \"REPLACE INTO ".$tablepre."settings (variable, value) VALUES ('seccodestatus', '0')\">?????????</option>
  2493. <option value = \"UPDATE ".$tablepre."usergroups SET allowdirectpost = '1'\">???????????????</option>
  2494. <option value = \"REPLACE INTO ".$tablepre."settings (variable, value) VALUES ('supe_status', '0')\">??????supersite??</option>
  2495. <option value = \"TRUNCATE TABLE ".$tablepre."failedlogins\">????????</option>
  2496. <option value = \"UPDATE ".$tablepre."members SET pmsound=2 WHERE pmsound=1\">?????????????</option>
  2497. <option value = \"UPDATE ".$tablepre."forums f, cdb_posts p SET p.htmlon=p.htmlon|1 WHERE p.fid=f.fid AND f.allowhtml='1';\">????????HTML???????HTML??</option>
  2498. <option value = \"UPDATE ".$tablepre."attachments SET `remote`=1;\">???????????????????</option>
  2499. </select>";
  2500. }
  2501. if($whereis == 'is_uc') {
  2502. echo "<select name=\"queryselect\" onChange=\"queries.value = this.value\">
  2503. <option value = ''>???TOOLS??????</option>
  2504. <option value = \"TRUNCATE TABLE ".$tablepre."notelist;\">??????</option>
  2505. </select>";
  2506. }
  2507. if($whereis == 'is_uch') {
  2508. echo "<select name=\"queryselect\" onChange=\"queries.value = this.value\">
  2509. <option value = ''>???TOOLS??????</option>
  2510. <option value = \"REPLACE INTO ".$tablepre."config (datavalue, var) VALUES ('template','default')\">????????????????</option>
  2511. <option value = \"REPLACE INTO ".$tablepre."config (datavalue, var) VALUES ('seccode_login','0')\">??????????</option>
  2512. <option value = \"REPLACE INTO ".$tablepre."config (datavalue, var) VALUES ('close','0')\">??????</option>
  2513. <option value = \"UPDATE ".$tablepre."pic SET `remote`=1\">?????????????????</option>
  2514. </select>";
  2515. }
  2516. echo "<br />
  2517. <br /><textarea name=\"queries\">$queries</textarea><br />
  2518. <input type=\"submit\" name=\"sqlsubmit\" value=\"? &nbsp; ?\">
  2519. </form>";
  2520. }
  2521. function topattern_array($source_array) { //??????
  2522. $source_array = preg_replace("/\{(\d+)\}/",".{0,\\1}",$source_array);
  2523. foreach($source_array as $key => $value) {
  2524. $source_array[$key] = '/'.$value.'/i';
  2525. }
  2526. return $source_array;
  2527. }
  2528. function all_setadmin_set($tablepre,$whereis){ //???????????????
  2529. global $ss_version,$dz_version,$sql_findadmin,$sql_select,$sql_update,$sql_rspw,$secq,$rspw,$username,$uid;
  2530. if($whereis == 'is_dz') {
  2531. $sql_findadmin = "SELECT * FROM {$tablepre}members WHERE adminid=1";
  2532. $sql_select = "SELECT uid FROM {$tablepre}members WHERE $_POST[loginfield] = '$_POST[where]'"; $username = 'username';
  2533. $uid = 'uid';
  2534. if(UC_CONNECT == 'mysql' || $dz_version < 610) {//????ucenter???????mysql???????????????uc??????
  2535. $rspw = 1;
  2536. } else {
  2537. $rspw = 0;
  2538. }
  2539. if($dz_version<710) {//???????? 7.0?????????????
  2540. $secq = 1;
  2541. } elseif($rspw) {
  2542. $secq = 1;
  2543. } else {
  2544. $secq = 0;
  2545. }
  2546. } elseif($whereis == 'is_uc') {
  2547. $secq = 0;
  2548. $rspw = 1;
  2549. } elseif($whereis == 'is_uch') {
  2550. $sql_findadmin = "SELECT * FROM {$tablepre}space WHERE groupid = 1";
  2551. $sql_select = "SELECT uid FROM {$tablepre}space WHERE $_POST[loginfield] = '$_POST[where]'";
  2552. $sql_update = "UPDATE {$tablepre}space SET groupid='1' WHERE $_POST[loginfield] = '$_POST[where]'";
  2553. $username = 'username';
  2554. $uid = 'uid';
  2555. $secq = 0;
  2556. if(UC_CONNECT == 'mysql') {
  2557. $rspw = 1;
  2558. } else {
  2559. $rspw = 0;
  2560. }
  2561. } elseif($whereis == 'is_ss' && $ss_version >= 70) {
  2562. $sql_findadmin = "SELECT * FROM {$tablepre}members WHERE groupid = 1";
  2563. $sql_select = "SELECT uid FROM {$tablepre}members WHERE $_POST[loginfield] = '$_POST[where]'";
  2564. $sql_update = "UPDATE {$tablepre}members SET groupid='1' WHERE $loginfield = '$where'";
  2565. $username = 'username';
  2566. $uid = 'uid';
  2567. $secq = 0;
  2568. if(UC_CONNECT == 'mysql') {
  2569. $rspw = 1;
  2570. } else {
  2571. $rspw = 0;
  2572. }
  2573. }
  2574. }
  2575. function datago_output($whereis){
  2576. global $dbhost, $dbuser, $dbpw, $dbname, $dbcfg;
  2577. $charsets=array('gbk','latin1','utf8');
  2578. $options="<option value=''>";
  2579. foreach($charsets as $value){
  2580. $options.="<option value=\"$value\">$value";
  2581. }
  2582. echo '<h5>???????</h5>';
  2583. echo '<form method=get action=tools.php?action=datago><table>
  2584. <tbody>
  2585. <input name=action type=hidden value=datago>
  2586. <tr><th width=20%>????</th><td><input class=textinput name=fromdbname value='.$dbname.'></input>&nbsp;&nbsp;???tools????????,?????????????</td></tr>
  2587. <tr><th width=20%>????</th><td><select name=todbcharset>'.$options.'</select>&nbsp;&nbsp;?????\'latin1\'<=>\'gbk\',\'gbk\'<=>\'utf8\'</td></tr></tbody></table>
  2588. <input name=submit type=submit value=??></input>
  2589. </form>';
  2590. }
  2591. function do_datago($mysql,$tableno,$do,$start,$limit){
  2592. global $whereis, $dbhost, $dbuser, $dbpw, $tablepre,$fromdbname, $todbcharset, $dbcfg,$dbcharset;
  2593. $allowcharset = array('latin1' => 'gbk','gbk' => 'utf8','utf8' => 'latin1');
  2594. $tablename = 'Tables_in_'.strtolower($fromdbname).' ('.$tablepre.'%)';
  2595. $mysql = mysql_connect($dbhost, $dbuser, $dbpw);
  2596. mysql_select_db($fromdbname);
  2597. mysql_query("SET sql_mode=''");
  2598. $query = mysql_query('SHOW TABLES LIKE \''.$tablepre.'%\'');
  2599. while($t = mysql_fetch_array($query,MYSQL_ASSOC)) {
  2600. $tablearray[] = $t[$tablename];
  2601. }
  2602. $table = $tablearray["$tableno"];
  2603. $query = mysql_query('SHOW TABLE STATUS LIKE '.'\''.$table.'\'');
  2604. $tableinfo = array();
  2605. while($t = mysql_fetch_array($query,MYSQL_ASSOC)) {
  2606. $charset = explode('_',$t['Collation']);
  2607. $t['Collation'] = $charset[0];
  2608. $tableinfo = $t;
  2609. }
  2610. if($allowcharset[$tableinfo['Collation']] != $todbcharset && $allowcharset[$todbcharset] != $tableinfo['Collation']){
  2611. if(strpos($tableinfo['Name'],$todbcharset) == 0) {
  2612. $table = '';
  2613. } else {
  2614. echo "<h4>$title</h4><br><br><table><tr><th>????</th></tr><tr><td>$tableinfo[Name] ????????</td></tr></table>";
  2615. exit;
  2616. }
  2617. }
  2618. mysql_query("SET NAMES '$tableinfo[Collation]'");
  2619. if($do == 'create') {
  2620. $tablecreate=array();
  2621. foreach ($tablearray as $key => $value){
  2622. $query=mysql_query("SHOW CREATE TABLE $value");
  2623. while($t = mysql_fetch_array($query,MYSQL_ASSOC)){
  2624. $t['Create Table'] = str_replace($tablepre,$whereis.'_',$t['Create Table']);
  2625. $t['Create Table'] = str_replace("$tableinfo[Collation]","$todbcharset",$t['Create Table']);
  2626. $t['Create Table'] = str_replace($whereis.'_',$todbcharset.$whereis.'_',$t['Create Table']);
  2627. $t['Table'] = str_replace($tablepre,$todbcharset.$whereis.'_',$t['Table']);
  2628. $tablecreate[]=$t;
  2629. }
  2630. }
  2631. mysql_query('SET NAMES \''.$todbcharset.'\'');
  2632. if(mysql_get_server_info() > '5.0'){
  2633. mysql_query("SET sql_mode=''");
  2634. }
  2635. foreach ($tablecreate as $key => $value){
  2636. mysql_query("DROP TABLE IF EXISTS `$value[Table]`");
  2637. mysql_query($value['Create Table']);
  2638. $count++;
  2639. }
  2640. $toolstip .= '?????????????? '.$count.' ???<br>';
  2641. show_tools_message($toolstip,"tools.php?action=datago&do=data&fromdbname=$fromdbname&todbcharset=$todbcharset&submit=%D7%AA%BB%BB");
  2642. } elseif($do == 'data') {
  2643. $count = 0;
  2644. $data = array();
  2645. $newtable = str_replace($tablepre,$todbcharset.$whereis.'_',$table);
  2646. if($table) {
  2647. mysql_query("SET NAMES '$tableinfo[Collation]'");
  2648. $query = mysql_query("SELECT * FROM $table LIMIT $start,$limit");
  2649. while($t = mysql_fetch_array($query,MYSQL_ASSOC)) {
  2650. $data[] = $t;
  2651. }
  2652. unset($t);
  2653. $todbcharset2 = $todbcharset;
  2654. if($tableinfo['Collation'] == 'utf8' || $todbcharset=='utf8'){
  2655. $todbcharset2 = $tableinfo['Collation'];
  2656. }
  2657. mysql_query('SET NAMES \''.$todbcharset2.'\'');
  2658. if(mysql_get_server_info() > '5.0'){
  2659. mysql_query("SET sql_mode=''");
  2660. }
  2661. if($start == 0){
  2662. mysql_query("TRUNCATE TABLE $newtable");
  2663. }
  2664. foreach($data as $key => $value){
  2665. $sql='';
  2666. foreach($value as $tokey => $tovalue){
  2667. $tovalue = addslashes($tovalue);
  2668. $sql = $sql ? $sql.",'".$tovalue."'" : "'".$tovalue."'";
  2669. }
  2670. mysql_query("INSERT INTO $newtable VALUES($sql)") or mysql_errno();
  2671. $count++;
  2672. }
  2673. if($count == $limit) {
  2674. $start += $count;
  2675. show_tools_message("???? $table ??? $start ??????? $limit ???","tools.php?action=datago&do=data&fromdbname=$fromdbname&todbcharset=$todbcharset&tableno=$tableno&start=$start&submit=%D7%AA%BB%BB");
  2676. } else {
  2677. $tableno ++;
  2678. show_tools_message("???? $table ??? $start ??????? $limit ???","tools.php?action=datago&do=data&fromdbname=$fromdbname&todbcharset=$todbcharset&tableno=$tableno&submit=%D7%AA%BB%BB",$time='1000');
  2679. }
  2680. } elseif($dbcharset == 'latin1' || $todbcharset == 'latin1') {
  2681. echo "<div class=\"specialdiv2\" id=\"serialize\">?????<ul>
  2682. </ul></div>";
  2683. echo '<script>$("serialize").innerHTML+="<li>????????????????<font color=red>'.$todbcharset.$whereis.'_ </font></li>";
  2684. $("serialize").scrollTop=$("serialize").scrollHeight;</script>';
  2685. } else {
  2686. $toolstip = '?????????????????';
  2687. show_tools_message($toolstip,"tools.php?action=datago&do=serialize&fromdbname=$fromdbname&todbcharset=$todbcharset&submit=%D7%AA%BB%BB");
  2688. }
  2689. } elseif($do == 'serialize' && $dbcharset!='latin1' && $todbcharset!='latin1') {
  2690. if($whereis == 'is_ss') {
  2691. $a = array('0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f');
  2692. foreach($a as $num) {
  2693. mysql_query("TRUNCATE TABLE ".$todbcharset.$whereis.'_'."cache_".$num);
  2694. }
  2695. }
  2696. $arr = getlistarray($whereis,'datago');
  2697. $limit = '3000';
  2698. echo "<div class=\"specialdiv2\" id=\"serialize\">?????<ul>
  2699. </ul></div>";
  2700. foreach($arr as $field) {
  2701. $stable = $todbcharset.$whereis.'_'.$field[0];
  2702. $sfield = $field[1];
  2703. $sid = $field[2];
  2704. $query = mysql_query("SELECT $sid,$sfield FROM $stable ORDER BY $sid DESC LIMIT $limit");
  2705. while($values = mysql_fetch_array($query,MYSQL_ASSOC)) {
  2706. $data = $values[$sfield];
  2707. $id = $values[$sid];
  2708. $data = preg_replace_callback('/s:([0-9]+?):"([\s\S]*?)";/','_serialize',$data);
  2709. $data = taddslashes($data);
  2710. if(mysql_query("update `$stable` set `$sfield`='$data' where `$sid`='$id'")) {
  2711. $toolstip = $stable.' ?? '.$sid.' ? '.$id.' ? '.$sfield.' ???????<br/>';
  2712. } else {
  2713. $toolstip = $stable.' ?? '.$sid.' ? '.$id.' ? '.$sfield.' ???<font color=red>????</font><br/>';
  2714. }
  2715. echo '<script>$("serialize").innerHTML+="'.$toolstip.'";
  2716. $("serialize").scrollTop=$("serialize").scrollHeight;</script>';
  2717. }
  2718. }
  2719. mysql_close($mysql);
  2720. echo '<script>$("serialize").innerHTML+="<li>????????????????????????<font color=red>'.$todbcharset.$whereis.'_ </font></li>";
  2721. $("serialize").scrollTop=$("serialize").scrollHeight;</script>';
  2722. }
  2723. }
  2724. function _config_form($title = '',$varname = '',$end = '1') {
  2725. global $$varname;
  2726. $ucapi = UC_API;
  2727. $ucip = UC_IP;
  2728. $form = '';
  2729. $form .= "<th width=20%>$title</th>";
  2730. if($$varname || isset($$varname)) {
  2731. $form .= "<td><input class=textinput name=".$varname."2 value=".$$varname."></input></td>";
  2732. } else {
  2733. $form .= "<td></td>";
  2734. }
  2735. if($end == '1') {
  2736. $form .= '';
  2737. } elseif ($end == '2') {
  2738. $form .= '</tr>';
  2739. } elseif ($end == '3') {
  2740. $form .= '</tr><tr>';
  2741. }
  2742. echo $form;
  2743. }
  2744. function all_doconfig_output($whereis){
  2745. global $uc_dbhost, $uc_dbuser, $uc_dbpw, $uc_dbname,$uc_tablepre,$dbhost, $dbuser, $dbpw, $dbname, $dbcfg, $tablepre,$dbcharset,$uc_dbcharset;
  2746. echo '<h5>????</h5>';
  2747. echo '<form method=post action=?action=all_config><table>
  2748. <tbody>
  2749. <tr>';
  2750. if($whereis != 'is_uc') {
  2751. _config_form($title = '??????',$varname = 'dbhost');
  2752. }
  2753. _config_form($title = 'UCenter ??????',$varname = 'uc_dbhost',$end = '3');
  2754. if($whereis != 'is_uc') {
  2755. _config_form($title = '???????',$varname = 'dbuser');
  2756. }
  2757. _config_form($title = 'UCenter ???????',$varname = 'uc_dbuser',$end = '3');
  2758. if($whereis != 'is_uc') {
  2759. echo _config_form($title = '??????',$varname = 'dbpw');
  2760. }
  2761. _config_form($title = 'UCenter ??????',$varname = 'uc_dbpw',$end = '3');
  2762. if($whereis != 'is_uc') {
  2763. _config_form($title = '?????',$varname = 'dbname');
  2764. }
  2765. _config_form($title = 'UCenter ?????',$varname = 'uc_dbname',$end = '3');
  2766. if($whereis != 'is_uc') {
  2767. _config_form($title = '??????',$varname = 'tablepre');
  2768. }
  2769. _config_form($title = 'UCenter ??????',$varname = 'uc_tablepre',$end = '3');
  2770. if($whereis != 'is_uc') {
  2771. _config_form($title = '??????',$varname = 'dbcharset');
  2772. }
  2773. _config_form($title = 'UCenter ??????',$varname = 'uc_dbcharset',$end = '3');
  2774. if($whereis != 'is_uc') {
  2775. _config_form();
  2776. _config_form($title = 'UCenter ???',$varname = 'ucapi',$end = '3');
  2777. }
  2778. if($whereis != 'is_uc') {
  2779. _config_form();
  2780. _config_form($title = 'UCenter IP?',$varname = 'ucip',$end = '2');
  2781. }
  2782. echo '</tbody>
  2783. </table>
  2784. <input name=submit type=submit value=??></input>
  2785. </form>';
  2786. }
  2787. function all_doconfig_modify($whereis){
  2788. global $dbhost2, $dbuser2, $dbpw2, $dbname2, $tablepre2,$dbcharset2;
  2789. if($whereis == 'is_dz') {
  2790. // /\$dbhost.+;/i
  2791. if(file_exists('./uc_server/data/config.inc.php')) {
  2792. $config = file_get_contents('./uc_server/data/config.inc.php');
  2793. writefile('./uc_server/data/config.bak.php.'.time(),$config);
  2794. $config = uc_doconfig_modify($config);
  2795. writefile('./uc_server/data/config.inc.php',$config);
  2796. }
  2797. $config = file_get_contents('./config.inc.php');
  2798. writefile('./forumdata/config.bak.php.'.date(ymd,time()),$config);
  2799. $config = preg_replace('/\$dbhost.+;/i','$dbhost = \''.$dbhost2.'\';',$config);
  2800. $config = preg_replace('/\$dbuser.+;/i','$dbuser = \''.$dbuser2.'\';',$config);
  2801. $config = preg_replace('/\$dbpw.+;/i','$dbpw = \''.$dbpw2.'\';',$config);
  2802. $config = preg_replace('/\$dbname.+;/i','$dbname = \''.$dbname2.'\';',$config);
  2803. $config = preg_replace('/\$tablepre.+;/i','$tablepre = \''.$tablepre2.'\';',$config);
  2804. $config = preg_replace('/\$dbcharset.+;/i','$dbcharset = \''.$dbcharset2.'\';',$config);
  2805. $config = uc_doconfig_modify($config);
  2806. if(writefile('./config.inc.php',$config)) {
  2807. show_tools_message('?????????????????????forumdata????','tools.php?action=all_config');
  2808. }
  2809. } elseif($whereis == 'is_uch' || $whereis == 'is_ss') {
  2810. $config = file_get_contents('./config.php');
  2811. writefile('./data/config.bak.php.'.date(ymd,time()),$config);
  2812. $config = preg_replace('/\$_SC\[\'dbhost\'\].+;/i','$_SC[\'dbhost\'] = \''.$dbhost2.'\';',$config);
  2813. $config = preg_replace('/\$_SC\[\'dbuser\'\].+;/i','$_SC[\'dbuser\'] = \''.$dbuser2.'\';',$config);
  2814. $config = preg_replace('/\$_SC\[\'dbpw\'\].+;/i','$_SC[\'dbpw\'] = \''.$dbpw2.'\';',$config);
  2815. $config = preg_replace('/\$_SC\[\'dbname\'\].+;/i','$_SC[\'dbname\'] = \''.$dbname2.'\';',$config);
  2816. $config = preg_replace('/\$_SC\[\'tablepre\'\].+;/i','$_SC[\'tablepre\'] = \''.$tablepre2.'\';',$config);
  2817. $config = preg_replace('/\$_SC\[\'dbcharset\'\].+;/i','$_SC[\'dbcharset\'] = \''.$dbcharset2.'\';',$config);
  2818. $config = uc_doconfig_modify($config);
  2819. if(writefile('./config.php',$config)) {
  2820. show_tools_message('?????????????????????data????','tools.php?action=all_config');
  2821. }
  2822. } elseif($whereis == 'is_uc') {
  2823. $config = file_get_contents('./data/config.inc.php');
  2824. writefile('./data/config.bak.php.'.date(ymd,time()),$config);
  2825. $config = uc_doconfig_modify($config);
  2826. if(writefile('./data/config.inc.php',$config)) {
  2827. show_tools_message('?????????????????????data????','tools.php?action=all_config');
  2828. }
  2829. }
  2830. }
  2831. function uc_doconfig_modify($config='') {
  2832. global $uc_dbhost2, $uc_dbuser2, $uc_dbpw2, $uc_dbname2,$uc_tablepre2,$ucapi2,$ucip2,$uc_dbcharset2;
  2833. $config = preg_replace('/define\(\'UC_DBHOST\'.+;/i','define(\'UC_DBHOST\', \''.$uc_dbhost2.'\');',$config);
  2834. $config = preg_replace('/define\(\'UC_DBUSER\'.+;/i','define(\'UC_DBUSER\', \''.$uc_dbuser2.'\');',$config);
  2835. $config = preg_replace('/define\(\'UC_DBPW\'.+;/i','define(\'UC_DBPW\', \''.$uc_dbpw2.'\');',$config);
  2836. $config = preg_replace('/define\(\'UC_DBNAME\'.+;/i','define(\'UC_DBNAME\', \''.$uc_dbname2.'\');',$config);
  2837. $config = preg_replace('/define\(\'UC_DBTABLEPRE\'.+;/i','define(\'UC_DBTABLEPRE\', \''.$uc_tablepre2.'\');',$config);
  2838. $config = preg_replace('/define\(\'UC_DBCHARSET\'.+;/i','define(\'UC_DBCHARSET\', \''.$uc_dbcharset2.'\');',$config);
  2839. $config = preg_replace('/define\(\'UC_API\'.+;/i','define(\'UC_API\', \''.$ucapi2.'\');',$config);
  2840. $config = preg_replace('/define\(\'UC_IP\'.+;/i','define(\'UC_IP\', \''.$ucip2.'\');',$config);
  2841. return $config;
  2842. }
  2843. function writefile($filename, $writetext, $openmod='w') {
  2844. if(@$fp = fopen($filename, $openmod)) {
  2845. flock($fp, 2);
  2846. fwrite($fp, $writetext);
  2847. fclose($fp);
  2848. return true;
  2849. } else {
  2850. return false;
  2851. }
  2852. }
  2853. function xml2array($xml) {
  2854. $arr = xml_unserialize($xml, 1);
  2855. preg_match('/<error errorCode="(\d+)" errorMessage="([^\/]+)" \/>/', $xml, $match);
  2856. $arr['error'] = array('errorcode' => $match[1], 'errormessage' => $match[2]);
  2857. return $arr;
  2858. }
  2859. function getbakurl($whereis,$action) {
  2860. if ($whereis != 'is_uc') {
  2861. require_once './uc_client/client.php';
  2862. require_once './uc_client/model/base.php';
  2863. } else {
  2864. define('IN_UC',TRUE);
  2865. define('UC_ROOT','./');
  2866. require_once './model/base.php';
  2867. }
  2868. $base = new base();
  2869. $salt = substr(uniqid(rand()), -6);
  2870. $action = !empty($action) ? $action : 'export';
  2871. $url = 'http://'.$_SERVER['HTTP_HOST'].str_replace('tools.php', 'api/dbbak.php', $_SERVER['PHP_SELF']);
  2872. if($whereis == 'is_dz') {
  2873. $apptype = 'discuz';
  2874. } elseif ($whereis == 'is_uc') {
  2875. $apptype = 'ucenter';
  2876. } elseif ($whereis == 'is_uch') {
  2877. $apptype = 'uchome';
  2878. } elseif ($whereis == 'is_ss') {
  2879. $apptype = 'supesite';
  2880. }
  2881. $url .= '?apptype='.$apptype;
  2882. $code = $base -> authcode('&method='.$action.'&time='.time(), 'ENCODE', UC_KEY);
  2883. $url .= '&code='.urlencode($code);
  2884. return $url;
  2885. }
  2886. function dobak($url,$num = '1') {
  2887. global $whereis;
  2888. $num = !empty($num) ? $num : '0';
  2889. $return = file_get_contents($url);
  2890. if($whereis != 'is_uc') {
  2891. require_once './uc_client/lib/xml.class.php';
  2892. } else {
  2893. require_once './lib/xml.class.php';
  2894. }
  2895. $arr = xml2array($return);
  2896. if($arr['error']['errormessage'] == 'explor_success') {
  2897. echo "<div class=\"specialdiv\">?????<ul>
  2898. <li>>>>>>>>>????<<<<<<<<</li>
  2899. <li>>>>>>>>>??".$num."???<<<<<<<<</li>
  2900. </ul></div>";
  2901. } else {
  2902. $num ++;
  2903. echo "<div class=\"specialdiv\">?????<ul>
  2904. <li>".$arr['fileinfo']['file_name']."......".$arr['error']['errormessage']."</li>
  2905. </ul></div>";
  2906. }
  2907. if($arr['nexturl']) {
  2908. $url = './tools.php?action=all_backup&nexturl='.urlencode($arr['nexturl']).'&num='.$num;
  2909. show_tools_message($arr['fileinfo']['file_name'],$url,$time = 2000);
  2910. }
  2911. }
  2912. function getgpc($k, $var='G') {
  2913. switch($var) {
  2914. case 'G': $var = &$_GET; break;
  2915. case 'P': $var = &$_POST; break;
  2916. case 'C': $var = &$_COOKIE; break;
  2917. case 'R': $var = &$_REQUEST; break;
  2918. }
  2919. return isset($var[$k]) ? $var[$k] : NULL;
  2920. }
  2921. function getlistarray($whereis,$type) {
  2922. global $dz_version,$ss_version,$uch_version;
  2923. if($whereis == 'is_dz' && $dz_version >= '710') {
  2924. if($type == 'datago') {
  2925. $list = array(
  2926. array('advertisements','parameters','advid'),
  2927. array('request','value','variable'),
  2928. array('settings','value','variable'),
  2929. );
  2930. }
  2931. } elseif($whereis == 'is_uch' && $uch_version >= '15') {
  2932. if($type == 'datago') {
  2933. $list = array(
  2934. array('ad','adcode','adid'),
  2935. array('blogfield','tag','blogid'),
  2936. array('blogfield','related','blogid'),
  2937. array('feed','title_data','feedid'),
  2938. array('feed','body_data','feedid'),
  2939. array('share','body_data','sid'),
  2940. );
  2941. }
  2942. } elseif($whereis == 'is_uc') {
  2943. if($type == 'datago') {
  2944. $list = array(
  2945. array('feed','title_data','feedid'),
  2946. array('feed','body_data','feedid'),
  2947. array('settings','v','k'),
  2948. );
  2949. }
  2950. } elseif($whereis == 'is_ss' && $ss_version >=70) {
  2951. if($type == 'datago') {
  2952. $list = array(
  2953. array('ads','parameters','adid'),
  2954. array('blocks','blocktext','blockid'),
  2955. );
  2956. }
  2957. }
  2958. return $list;
  2959. }
  2960. function _serialize($str) {
  2961. global $dbcharset,$todbcharset;
  2962. $charset = $dbcharset == 'utf8' ? 'utf-8':$dbcharset;
  2963. $tempdbcharset = $todbcharset == 'utf8' ? 'utf-8':$todbcharset;
  2964. $charset = strtoupper($charset);
  2965. $tempdbcharset = strtoupper($tempdbcharset);
  2966. $temp = iconv($charset,$tempdbcharset,$str[2]);
  2967. $l = strlen($temp);
  2968. return 's:'.$l.':"'.$str[2].'";';
  2969. }
  2970. function ping($whereis) {
  2971. global $plustitle,$dbhost,$dbuser,$dbpw,$dbname,$uc_dbhost,$uc_dbuser,$uc_dbpw,$uc_dbname;
  2972. if($whereis != 'is_uc') {
  2973. $ping = @mysql_connect($dbhost,$dbuser,$dbpw);
  2974. if($ping) {
  2975. $message = "?????:<font color=green>[??]</font>......";
  2976. if (mysql_select_db($dbname,$ping)) {
  2977. $message .= " $dbname ???<font color=green>[??]</font>";
  2978. } else {
  2979. $message .= " $dbname ???<font color=red>[???]</font>";
  2980. }
  2981. mysql_close($ping);
  2982. } else {
  2983. $message = "?????:<font color=red>[??]</font> ";
  2984. }
  2985. $message .= '<br/>';
  2986. if(file_get_contents(UC_API.'/index.php')) {
  2987. $message .= 'UCenter <font color=green>[????]</font>......';
  2988. } else {
  2989. $message .= 'UCenter <font color=red>[????]</font>......';
  2990. }
  2991. }
  2992. $ping = @mysql_connect($uc_dbhost,$uc_dbuser,$uc_dbpw);
  2993. if($ping) {
  2994. $message .= "UCenter ?????:<font color=green>[??]</font>......";
  2995. if (mysql_select_db($uc_dbname,$ping)) {
  2996. $message .= " $uc_dbname ???<font color=green>[??]</font>";
  2997. } else {
  2998. $message .= " $uc_dbname ???<font color=red>[???]</font>";
  2999. }
  3000. mysql_close($ping);
  3001. } else {
  3002. $message .= "UCenter ?????:<font color=red>[??]</font> ";
  3003. }
  3004. $message .= '<br/>';
  3005. echo '<script>$(\'ping\').innerHTML += \''.$plustitle.' '.$message.'\'</script>';
  3006. }
  3007. function checkfilesoutput($modifylists,$deletedfiles,$unknownfiles) {
  3008. $modifystats = (count($modifylists)) > 0 ? '<a href="?action=dz_filecheck&detail=modifytrue&begin=1">????</a>': '';
  3009. $delstats = (count($deletedfiles)) > 0 ? '<a href="?action=dz_filecheck&detail=deltrue&begin=1">????</a>': '';
  3010. $unknowtrue = (count($unknownfiles)) > 0 ? '<a href="?action=dz_filecheck&detail=unknowtrue&begin=1">????</a>': '';
  3011. echo '<pre>';
  3012. echo "?????: ".count($modifylists) .$modifystats."<br />????: ".count($deletedfiles).$delstats."<br />????:".count($unknownfiles).$unknowtrue;
  3013. echo '</pre>';
  3014. echo '----------------------------------------------------------------------------<br>';
  3015. if (!empty($_GET['detail'])){
  3016. $predir = '';
  3017. if ($_GET['detail'] == 'modifytrue'){
  3018. echo'?????:<br />';
  3019. foreach ($modifylists as $value){
  3020. $vdir = explode('/',$value);
  3021. $vdir[0] = $vdir[0] == '.' ? '?' : $vdir[0];
  3022. if($vdir[0] != $predir) {
  3023. $predir = $vdir[0];
  3024. echo "<span class='current'>".$predir."??</span><br/>";
  3025. }
  3026. echo "&nbsp;&nbsp;&nbsp;".$value."<br/>";
  3027. }
  3028. }elseif($_GET['detail'] == 'deltrue'){
  3029. echo '????:<br />';
  3030. foreach ($deletedfiles as $value){
  3031. $vdir = explode('/',$value);
  3032. $vdir[0] = $vdir[0] == '.' ? '?' : $vdir[0];
  3033. if($vdir[0] != $predir) {
  3034. $predir = $vdir[0];
  3035. echo "<span class='current'>".$predir."??</span><br/>";
  3036. }
  3037. echo "&nbsp;&nbsp;&nbsp;".$value."<br/>";
  3038. }
  3039. }elseif($_GET['detail'] == 'unknowtrue'){
  3040. echo '????:<br />';
  3041. foreach ($unknownfiles as $value){
  3042. $vdir = explode('/',$value);
  3043. $vdir[0] = $vdir[0] == '.' ? '?' : $vdir[0];
  3044. if($vdir[0] != $predir) {
  3045. $predir = $vdir[0];
  3046. echo "<span class='current'>".$predir."??</span><br/>";
  3047. }
  3048. echo "&nbsp;&nbsp;&nbsp;".$value."<br/>";
  3049. }
  3050. }
  3051. }
  3052. }
  3053. function docheckfiles($dz_files,$md5data) {
  3054. global $modifylists,$deletedfiles,$unknownfiles;
  3055. foreach($dz_files as $line) {
  3056. $file = trim(substr($line, 34));
  3057. $md5datanew[$file] = substr($line, 0, 32);
  3058. $md5 = substr($line, 34);
  3059. if (empty($md5data[$file]))
  3060. {
  3061. $deletedfiles[] = $file;
  3062. $deltrue = 1;
  3063. continue;
  3064. }
  3065. if($md5datanew[$file] != $md5data[$file]) {
  3066. $modifylists[$file] = $file;
  3067. $modifytrue = 1;
  3068. }
  3069. }
  3070. $addlist = @array_diff_assoc($md5data, $md5datanew);
  3071. if (empty($modifylists)) {
  3072. foreach ($addlist as $file => $value){
  3073. $unknownfiles[$file] = $file;
  3074. }
  3075. } else {
  3076. foreach ($addlist as $file => $value){
  3077. $dir = dirname($file);
  3078. if (!array_key_exists($file, $modifylists)){
  3079. $unknownfiles[$file] = $file;
  3080. $unknowtrue = 1;
  3081. }
  3082. }
  3083. }
  3084. }
  3085. function infobox($str,$link) {
  3086. if($link) {
  3087. $button = "<input class='button' type='submit' onclick=\"location.href='".$link."'\" value='??' name='submit'/>";
  3088. }
  3089. echo "<div class='infobox'><p>$str</p>$button</div>";
  3090. }
  3091. ?>