tools.php 78 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173
  1. <?php
  2. /**
  3. * [Discuz!] (C)2001-2099 Comsenz Inc.
  4. * This is NOT a freeware, use is subject to license terms
  5. *
  6. * $Id: tools.php 2015-03-12 18:00:43Z Tuesday $
  7. */
  8. /**
  9. * 默认密码: admin, 请不要手工编辑密码 [21232f297a57a5a743894a0e4a801fc3]。
  10. */
  11. define('TPASSWORD', '21232f297a57a5a743894a0e4a801fc3'); // 密码解密md5一层
  12. /*************************************以下部分为tools工具箱的核心代码,请不要随意修改 Tuesday **************************************/
  13. define('PHPS_CHARSET', 'UTF-8');
  14. error_reporting(0);
  15. date_default_timezone_set('UTC');
  16. define('TMAGIC_QUOTES_GPC', function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc());
  17. define('TOOLS_ROOT', rtrim(dirname(__FILE__),'/\\').DIRECTORY_SEPARATOR);
  18. $data = file_get_contents(TOOLS_ROOT.'source/discuz_version.php');
  19. preg_match("/define\('DISCUZ_VERSION.*'([^\']*)'\)/isU", $data, $reg);
  20. !$reg[1] && $reg[1] = 'X3.2';
  21. define('DISCUZ_VERSION', $reg[1]);
  22. define('DISCUZ_DOWN_VERSION', str_ireplace('x','',DISCUZ_VERSION));
  23. define('TOOLS_DISCUZ_VERSION', 'Discuz! '.DISCUZ_VERSION);
  24. define('TOOLS_VERSION', 'Tools '.DISCUZ_VERSION);
  25. $tools_versions = TOOLS_VERSION;
  26. $tools_discuz_version = TOOLS_DISCUZ_VERSION;
  27. if(!TMAGIC_QUOTES_GPC) {
  28. $_GET = taddslashes($_GET);
  29. $_POST = taddslashes($_POST);
  30. $_COOKIE = taddslashes($_COOKIE);
  31. }
  32. if (isset($_GET['GLOBALS']) || isset($_POST['GLOBALS']) || isset($_COOKIE['GLOBALS']) || isset($_FILES['GLOBALS'])) {
  33. show_msg('您当前的访问请求当中含有非法字符,已经被系统拒绝');
  34. }
  35. if($_SERVER['REQUEST_METHOD'] == 'POST' && !empty($_POST)) {
  36. $_GET = array_merge($_GET, $_POST);
  37. }
  38. $actionarray = array('index', 'setadmin', 'closesite', 'closeplugin', 'repairdb', 'reinstall' , 'restoredb', 'updatecache', 'login', 'logout','editpass','serverinfo','happy');
  39. $_GET['action'] = htmlspecialchars($_GET['action']);
  40. $action = in_array($_GET['action'], $actionarray) ? $_GET['action'] : 'index';
  41. $t = new T();
  42. $t->init();
  43. $config = $t->config;
  44. !$config['charset'] && $config['charset'] = PHPS_CHARSET;
  45. define('PHP_CHARSET',$config['charset']);
  46. define('DBNAME', $config['db']['1']['dbname']);
  47. header('Content-type: text/html; charset=utf-8');
  48. if(!is_login()) {
  49. login_page();
  50. exit;
  51. }
  52. define('DB_PRE',$t->dbconfig['tablepre']);
  53. # Tuesday 新增加功能.
  54. switch($action){
  55. case 'serverinfo':
  56. include_once(TOOLS_ROOT.'source/class/class_core.php');
  57. include_once(TOOLS_ROOT.'source/function/function_core.php');
  58. header('Content-type: text/html; charset=utf-8');
  59. $discuz = & discuz_core::instance();
  60. $discuz->init();
  61. $_axtime = microtime(true);
  62. set_time_limit(0);
  63. $fileint = $dirint = 0;
  64. function getBytes($folder = './'){
  65. global $fileint,$dirint;
  66. $totalSize=0;
  67. $handle = @opendir($folder) or die("Cannot open " . $folder);
  68. $dirint ++;
  69. while($file = readdir($handle)){
  70. if($file !== "." && $file !== ".."){
  71. if(is_dir($folder.$file.'/')){
  72. $totalSize += getBytes($folder.$file.'/');
  73. }
  74. if(is_file($folder.$file)){
  75. $totalSize += filesize($folder.$file);
  76. $fileint ++;
  77. }
  78. }
  79. }
  80. closedir($handle);
  81. return $totalSize;
  82. }
  83. $formhash = thash();
  84. $filesize = fun_size(getBytes());
  85. $timezone = date_default_timezone_get();
  86. $datetime = date('Y-m-d H:i:s', time());
  87. $sapiname = php_sapi_name();
  88. $tools_discuz_version =TOOLS_DISCUZ_VERSION;
  89. $dbver = DB::fetch_first("SELECT VERSION() AS ver");
  90. !$dbver['ver'] && $dbver['ver'] = 'empty';
  91. $phpver = 'php/'. phpversion();
  92. if(strpos($sapiname,'apache') !== false)
  93. $sapiname = apache_get_version();
  94. if(is_file('./data/install.lock') && $t = filemtime('./data/install.lock')){
  95. $installtime = date('Y-m-d H:i:s',$t);
  96. $runtime = round((time() - $t) / (3600*24));
  97. }
  98. $databases = DBNAME;
  99. $sql = "SHOW TABLE STATUS FROM `{$databases}`";
  100. $query = DB::query($sql);
  101. $indexcount = $tabcount = $tabsize = 0;
  102. while($row = DB::fetch($query)){
  103. $l = fun_size($row['Data_length']);
  104. $inl = fun_size($row['Index_length']);
  105. $dbsection .= "<option value=\"\">{$row['Name']} - [容量: $l; 索引容量:$inl] </option>";
  106. $tabsize += $row['Data_length'];
  107. $indexcount += $row['Index_length'];
  108. $tabcount += 1;
  109. }
  110. $allcount = fun_size($tabsize+$indexcount);
  111. $tabsize = fun_size($tabsize);
  112. $indexcount =fun_size($indexcount);
  113. $xtime = sprintf('%0.2f', (microtime(true) - $_axtime));
  114. // TODO: 首页显示层.
  115. show_header();
  116. print<<<END
  117. <style type="text/css">
  118. ul.info_list li{height: 24px; line-height: 24px;}
  119. h5{padding: 0;}
  120. </style>
  121. <p>欢迎使用 Tools 之 Discuz! 急诊箱功能!我们致力于为您解决 Discuz! 站点的紧急故障,欢迎各位站长朋友们使用。</p>
  122. <h5>Discuz 版本:</h5>
  123. <ul>
  124. <li>{$tools_discuz_version}</li>
  125. </ul>
  126. <h5>服务器信息:</h5>
  127. <ul class="info_list">
  128. <li>服务器时间: {$datetime} ({$timezone})</li>
  129. <li>服务器API: $sapiname</li>
  130. <li>PHP版本号: $phpver</li>
  131. <li>Mysql版本号: MYSQL {$dbver['ver']}</li>
  132. <li>首次运行时间: {$installtime} 总共 {$runtime} 天</li>
  133. </ul>
  134. <h5>文件信息:</h5>
  135. <ul class="info_list">
  136. <li>站点目录总容量: $filesize</li>
  137. <li>站点文件数量: $fileint 个</li>
  138. <li>站点目录数量: $dirint 个</li>
  139. </ul>
  140. <h5>数据库信息:</h5>
  141. <ul class="info_list">
  142. <li>数据库名: $databases</li>
  143. <li>数据表总数: $tabcount</li>
  144. <li>数据表总容量: $tabsize</li>
  145. <li>数据表索引容量: $indexcount</li>
  146. <li>数据表实际占用容量: $allcount</li>
  147. <li>数据表详细情况列表:<select>
  148. $dbsection</select></li>
  149. </ul>
  150. <h5>性能相关</h5>
  151. <ul class="info_list">
  152. <li>运行时间: $xtime 秒 (小于2秒才算性价比))</li>
  153. </ul>
  154. END;
  155. show_footer();
  156. break;
  157. case 'editpass':
  158. if($_POST['act'] == 'delepluges'){
  159. $pname = trim($_POST['pluname']);
  160. if(!$pname){
  161. show_msg('请输入插件名字或者插件ID');
  162. }
  163. $tem = explode(' ', $pname);
  164. $wherestr = '';
  165. if($tem[0]){
  166. $names = $tem[0];
  167. $wherestr .= "AND `name`='$names' ";
  168. }
  169. if($tem[1]){
  170. $names = $tem[1];
  171. $wherestr .= "AND `version`='$names'";
  172. }
  173. if(is_numeric($pname)){
  174. $pname += 0;
  175. $wherestr = "AND `pluginid`='$pname'";
  176. }
  177. if(strpos($pname, '/') === (strlen($pname)-1)){
  178. $names = $pname;
  179. $wherestr = "AND `directory`='$names'";
  180. }
  181. $t->connect_db();
  182. $sql = "SELECT * FROM ".DB_PRE."common_plugin WHERE 1 {$wherestr} LIMIT 1";
  183. $pludata = mysql_fetch_array(mysql_query($sql,$t->db), MYSQL_ASSOC);
  184. if(!$pludata){
  185. show_msg('未找到插件: '.htmlspecialchars($tem[0]).' 版本号:'.htmlspecialchars($tem[1]) );
  186. }
  187. $is_check = unserialize($pludata['modules']);
  188. if($is_check['system']){
  189. show_msg('系统插件, 请不要删除之!');
  190. }
  191. $pid = $pludata['pluginid']+0;
  192. $pludata['directory'] = strtr($pludata['directory'], array('.'=>''));
  193. $dirs = './source/plugin/'.$pludata['directory'];
  194. if(!is_dir($dirs)){
  195. show_msg('插件目录不存在:'.$dirs.' 请手工创建目录后, 再删除插件');
  196. }
  197. if(!$pludata['directory'] || strlen($pludata['directory']) <= 1){
  198. show_msg('检测到的插件目录非法');
  199. }
  200. function delTree($dir) {
  201. $dir = rtrim($dir,'/');
  202. $files = array_diff(scandir($dir), array('.','..'));
  203. foreach ($files as $file) {
  204. (is_dir("$dir/$file")) ? delTree("$dir/$file") : unlink("$dir/$file");
  205. }
  206. return @rmdir($dir);
  207. }
  208. if($is_check['extra']['uninstallfile']){
  209. $filename = DISCUZ_ROOT.'./source/plugin/'.$pludata['directory'].$is_check['extra']['uninstallfile'];
  210. @include_once($filename);
  211. }
  212. if(!delTree($dirs))
  213. show_msg('插件目录无法删除:'.$dirs.' 请检查权限');
  214. if($pid){
  215. mysql_query("DELETE FROM ".DB_PRE."common_plugin WHERE pluginid='$pid'",$t->db);
  216. mysql_query("DELETE FROM ".DB_PRE."common_pluginvar WHERE pluginid='$pid'",$t->db);
  217. }
  218. if(true)
  219. show_msg(htmlspecialchars($pname).'插件 已经删除成功!');
  220. }
  221. // TODO: 修改密码, 让用户管理这个平台更方便.
  222. if($_POST['oldpass'] && $_POST['newpass']){
  223. $oldpass = trim($_POST['oldpass']);
  224. $newpass = trim($_POST['newpass']);
  225. $thash = $_POST['formhash'];
  226. if($thash !== thash()){
  227. show_msg('你所请求的来路不正常, 请稍候重试!');
  228. }
  229. if($oldpass == $newpass){
  230. show_msg('不能设置相同于旧密码的新密码');
  231. }
  232. if(strlen($oldpass) <5 || strlen($oldpass) < 5){
  233. show_msg('不能设置小于5位的密码');
  234. }
  235. $oldpass = md5($oldpass);
  236. if( $oldpass !== TPASSWORD){
  237. show_msg('你的旧密码错误');
  238. }
  239. $newpass = md5($newpass);
  240. $isfw = 1;
  241. }
  242. #修改当前文件.以便让密码更新进去.
  243. if($isfw === 1){
  244. if(!is_writable(__FILE__)){
  245. show_msg('本文件禁止可写, 请设置可写权限!');
  246. }
  247. $fp = @fopen(__FILE__,'rb+');
  248. while(!feof($fp)){
  249. $t = fgets($fp);
  250. if($newpass && strpos($t,'TPASSWORD')!== false && strpos($t,$oldpass) !== false ){
  251. $rept = strtr($t, array($oldpass=>$newpass));
  252. $fell = ftell($fp);
  253. if($rept !== $t){
  254. fseek($fp,($fell-strlen($t)));
  255. fwrite($fp,$rept);
  256. $isuser = 1;
  257. }
  258. break;
  259. }
  260. }
  261. fclose($fp);
  262. if($isuser){
  263. $toolsmd5 = md5($newpass.thash());
  264. show_msg('密码修改成功,请牢记你的密码!');
  265. }else{
  266. show_msg('密码修改失败,请联系tools技术员!');
  267. }
  268. }
  269. break;
  270. }
  271. if($action == 'index') {
  272. // TODO: 首页
  273. show_header();
  274. $formhash = thash();
  275. $errmsg = ERROR_MSG;
  276. print<<<END
  277. <p>欢迎使用 Tools 之 Discuz! 急诊箱功能!我们致力于为您解决 Discuz! 站点的紧急故障,欢迎各位站长朋友们使用。</p>
  278. <h5>适用版本:</h5>
  279. <ul>
  280. <li>{$tools_discuz_version}</li>
  281. </ul>
  282. <h5>特别注意:</h5>
  283. <ul>
  284. <li style="color:red">{$errmsg}</li>
  285. </ul>
  286. <h5>主要功能:</h5>
  287. <ul>
  288. <li>多种模式在线安装Discuz!, 或者重装</li>
  289. <li>重置管理员账号:将把您指定的会员设置为管理员</li>
  290. <li>关闭功能: 一键关闭/打开 [站点|插件]的操作</li>
  291. <li>清理冗余数据: 清理所有未使用的附件</li>
  292. <li>修复数据库: 对所有数据表进行检查修复工作</li>
  293. <li>恢复数据库: 一次性导入论坛数据备份</li>
  294. <li>更新缓存: 一键更新论坛的数据缓存与模板缓存</li>
  295. </ul>
  296. <h5 style="color:red">Tools 登录密码:</h5>
  297. <p>
  298. <form method="post" action="./tools.php?action=editpass" enctype="application/x-www-form-urlencoded">
  299. <input type="hidden" name="formhash" value="{$formhash}">
  300. 旧密码: <input name="oldpass" type="password"> <strong style="color:green">新密码</strong>: <input name="newpass" type="password">
  301. <input type="submit" style="cursor: pointer;" value="修 改" />
  302. </form>
  303. </p>
  304. <h5 style="color:red">强制删除插件:</h5>
  305. <p>
  306. <form method="post" action="./tools.php?action=editpass" enctype="application/x-www-form-urlencoded">
  307. <input type="hidden" name="formhash" value="{$formhash}">
  308. <input type="hidden" name="act" value="delepluges">
  309. 插件: <input name="pluname" type="text">
  310. <input type="submit" style="cursor: pointer;" value="确认删除" /><br />
  311.    (支持插件名, 插件id, 插件目录后面需要/)
  312. </form>
  313. </p>
  314. END;
  315. show_footer();
  316. }elseif($action == 'reinstall') {
  317. // TODO: 安装discuz x
  318. if(!$_POST)
  319. show_header();
  320. $downlink = 'http://download.comsenz.com/DiscuzX/'.DISCUZ_DOWN_VERSION.'/';
  321. $cachepath = './';
  322. # post 数据
  323. if($_POST){
  324. $chfile = $_POST['chfile'];
  325. define('YESINSTALL', 1);
  326. if(!$chfile)
  327. show_msg('请至少选择一项!', 'tools.php?action='.$action, 2000);
  328. if(!in_array($chfile, array('two','clear'))){
  329. $link = $downlink.$chfile;
  330. set_time_limit(0);
  331. if(!YESINSTALL){
  332. $olddir = scandir('./');
  333. if(count($olddir) >= 20){
  334. show_msg('根目录已经存在discuz文件, 请确认并且勾选强制覆盖文件, 重试一次!', 'tools.php?action='.$action, 2000);
  335. }
  336. }
  337. fun_reinstall('back','./');
  338. $fwint = file_put_contents($cachepath.$chfile, curl_getdata($link));
  339. $zip = new zip();
  340. $b = $zip->Extract($cachepath.$chfile,'./');
  341. $oldfile = sfopen(true);
  342. @unlink($cachepath.$chfile);
  343. if(count($oldfile[1]) > 1000){
  344. show_msg('全新安装过程即将开始....', 'install/', 2000);
  345. }
  346. show_msg('如果你需要全新安装程序, 请先清空目录!'.count($oldfile[1]), 'tools.php?action='.$action, 2000);
  347. }else{
  348. fun_reinstall($_POST['chfile'],'./');
  349. if($_POST['chfile'] !== 'two'){
  350. show_msg('整个discuz目录已经备份完成', 'tools.php?action='.$action, 2000);
  351. }
  352. }
  353. exit();
  354. }
  355. if(!$filelist = curl_getdata($downlink))
  356. echo '请确认你的网络是否通畅!';
  357. if($filelist){
  358. preg_match_all('#<a href="([^"]*).zip">([^"]*).zip</a>.*([0-9]*-[0-9]*-[0-9]* [0-9]*\:[0-9]*).*([0-9.]*)M#isU', $filelist, $regfile);
  359. if(!$regfile[1])
  360. preg_match_all('#<a href="([^"]*).zip">([^"]*).zip</a>#isU', $filelist, $regfile);
  361. foreach($regfile[1] AS $key => $val){
  362. if($regfile[4][$key])
  363. $regfile[4][$key] .= 'M';
  364. $val .= '.zip';
  365. $data .= '<p><input name="chfile" type="radio" value="'.$val.'" /> '.$val.'   '.$regfile[3][$key].'   '.$regfile[4][$key].'</p>';
  366. }
  367. }
  368. $root = TOOLS_ROOT;
  369. echo "<h3 style=\"color: green; font-weight: bolder; margin: 6px; padding: 0;\">全新安装: ".TOOLS_DISCUZ_VERSION."</h3>";
  370. print<<<END
  371. <form action="?action={$action}" method="post">
  372. <table id="setadmin">
  373. <tr><td>{$data}
  374. <span style="color:red"> * 全新安装过程默认会将所有文件备份一次, 请等待完成!</span>
  375. </td></tr>
  376. </table>
  377. <input type="submit" onclick="this.style.display='none'" name="setadminsubmit" value="提 &nbsp; 交">
  378. </form>
  379. <br />
  380. <h3 style="color: green; font-weight: bolder; margin: 6px; padding: 0;">二次安装</h3>
  381. <form action="?action={$action}" method="post">
  382. <table id="setadmin">
  383. <tr><td> <input name="chfile" type="radio" value="two" />确认安装 (<span style="color:red">我已经知道二次重装的风险,并且明确此操作!</span>)</td></tr>
  384. <tr><td> <input name="chfile" type="radio" value="clear" />备份目录 (<span style="color:red">功能将整个discuz目录备份起来</span>)</td></tr>
  385. </table>
  386. <input type="submit" onclick="this.style.display='none'" name="setadminsubmit" value="提 &nbsp; 交"> (非win系统 {$root} 目录需要可写)
  387. </form>
  388. END;
  389. if(!$_POST)
  390. show_footer();
  391. }elseif($action == 'setadmin') {
  392. // TODO: 找回管理员
  393. $t->connect_db();
  394. $founders = @explode(',',$t->config['admincp']['founder']);
  395. $foundernames = array();
  396. foreach($founders as $userid) {
  397. $sql = "SELECT username FROM ".DB_PRE."common_member WHERE `uid`='$userid'";
  398. $foundernames[] = mysql_result(mysql_query($sql, $t->db), 0);
  399. }
  400. $foundernames = implode($foundernames, ',');
  401. $sql = "SELECT username FROM ".DB_PRE."common_member WHERE `adminid`='1'";
  402. $query = mysql_query($sql, $t->db) or dir(mysql_error());
  403. $adminnames = array();
  404. while($row = mysql_fetch_row($query)) {
  405. $adminnames[] = $row[0];
  406. }
  407. $adminnames = implode($adminnames, ',');
  408. if(!empty($_POST['setadminsubmit'])) {
  409. if($_GET['username'] == NULL) {
  410. show_msg('请输入用户名', 'tools.php?action='.$action, 2000);
  411. }
  412. if($_GET['loginfield'] == 'username') {
  413. $_GET['username'] = addslashes($_GET['username']);
  414. $sql = "SELECT uid FROM ".DB_PRE."common_member WHERE `username`='".$_GET['username']."'";
  415. $uid = mysql_result(mysql_query($sql, $t->db), 0);
  416. $username = $_GET['username'];
  417. } elseif($_GET['loginfield'] == 'uid') {
  418. $_GET['username'] = addslashes($_GET['username']);
  419. $uid = $_GET['username'];
  420. $sql = "SELECT username FROM ".DB_PRE."common_member WHERE `uid`='".$_GET['username']."'";
  421. $username = mysql_result(mysql_query($sql, $t->db), 0);
  422. }
  423. if($uid && $username) {
  424. $sql = "UPDATE ".DB_PRE."common_member SET `groupid`='1', `adminid`='1' WHERE `uid`='$uid'";
  425. @mysql_query($sql, $t->db);
  426. if(!in_array($uid,$founders)) {
  427. $sql = "REPLACE INTO ".DB_PRE. "common_admincp_member (`uid`, `cpgroupid`, `customperm`) VALUES ('$uid', '0', '')";
  428. @mysql_query($sql, $t->db);
  429. }
  430. } else {
  431. show_msg('没有这个用户', 'tools.php?action='.$action, 2000);
  432. }
  433. $t->connect_db('ucdb');
  434. if($_GET['password'] != NULL) {
  435. $sql = "SELECT salt FROM ".$t->ucdbconfig['tablepre']."members WHERE `uid`='$uid'";
  436. $salt = mysql_result(mysql_query($sql, $t->db), 0);
  437. $newpassword = md5(md5(trim($_GET['password'])).$salt);
  438. $sql = "UPDATE ".$t->ucdbconfig['tablepre']."members SET `password`='$newpassword' WHERE `uid`='$uid'";
  439. mysql_query($sql, $t->db);
  440. }
  441. if($_GET['issecques'] == 1) {
  442. $sql = "UPDATE ".$t->ucdbconfig['tablepre']."members SET `secques`='' WHERE `uid`='$uid'";
  443. mysql_query($sql, $t->db);
  444. }
  445. $t->close_db();
  446. show_msg('管理员找回成功!', 'tools.php?action='.$action, 2000);
  447. } else {
  448. show_header();
  449. echo "<p>现有创始人:$foundernames</p>";
  450. echo "<p>现有管理员:$adminnames</p>";
  451. print<<<END
  452. <form action="?action={$action}" method="post">
  453. <h5>{$info}</h5>
  454. <table id="setadmin">
  455. <tr><th width="30%"><input class="radio" type="radio" name="loginfield" value="username" checked class="radio">用户名<input class="radio" type="radio" name="loginfield" value="uid" class="radio">UID</th><td width="70%"><input class="textinput" type="text" name="username" size="25" maxlength="40"></td></tr>
  456. <tr><th width="30%">请输入密码</th><td width="70%"><input class="textinput" type="text" name="password" size="25"></td></tr>
  457. <tr><th width="30%">是否清除安全提问</th><td width="70%">
  458. <input class="radio" type="radio" name="issecques" value="1">是&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  459. <input class="radio" type="radio" name="issecques" value="0" class="radio" checked>否</td></tr>
  460. </table>
  461. <input type="submit" name="setadminsubmit" value="提 &nbsp; 交">
  462. </form>
  463. END;
  464. print<<<END
  465. <br/>
  466. 恢复步骤:
  467. 重置管理员<br/>
  468. <ul>
  469. <li>选择用户名或者UID。</li>
  470. <li>输入用户名或者UID。</li>
  471. <li>如果需要重置密码,输入密码。</li>
  472. <li>如果需要清除安全提问,请在是否清除安全提问处选择是。</li>
  473. </ul>
  474. <br/>
  475. 重置创始人<br/>
  476. <ul>
  477. <li>重置用户为创始人。</li>
  478. <li>修改config_global.php 中 \$_config['admincp']['founder'] = '管理员的ID',多个以半角逗号分割。</li>
  479. </ul>
  480. END;
  481. show_footer();
  482. }
  483. }elseif($action == 'closesite') {
  484. //一键开关站点*插件
  485. $t->connect_db();
  486. $sql = "SELECT `available` FROM ".DB_PRE.'common_plugin'." WHERE available='1' LIMIT 1";
  487. $is_available = mysql_result(mysql_query($sql, $t->db), 0);
  488. $closeds = 'checked';
  489. $openeds = '';
  490. if($is_available){
  491. $closeds = '';
  492. $openeds = 'checked';
  493. }
  494. $sql = "SELECT svalue FROM ".DB_PRE."common_setting WHERE skey='bbclosed'";
  495. $bbclosed = mysql_result( $q = mysql_query($sql, $t->db), 0);
  496. $closed = 'checked';
  497. $opened = '';
  498. if(empty($bbclosed)) {
  499. $closed = '';
  500. $opened = 'checked';
  501. }
  502. $sql = "SELECT svalue FROM ".DB_PRE."common_setting WHERE `skey`='closedreason'";
  503. $closedreason = mysql_result(mysql_query($sql, $t->db), 0);
  504. if(!empty($_POST['closesitesubmit'])) {
  505. $close = $_POST['close']+0;
  506. $sql = "UPDATE ".DB_PRE."common_setting SET `svalue`='$close' WHERE `skey`='bbclosed'";
  507. mysql_query($sql, $t->db);
  508. if($close == 1) {
  509. $close = 'tools.php closed';
  510. }else{
  511. $close = '';
  512. }
  513. $sql = "UPDATE ".DB_PRE."common_setting SET `svalue`='$close' WHERE `skey`='closedreason'";
  514. mysql_query($sql, $t->db);
  515. // 插件判断.
  516. include_once(TOOLS_ROOT.'source/class/class_core.php');
  517. include_once(TOOLS_ROOT.'source/function/function_core.php');
  518. header('Content-type: text/html; charset=utf-8');
  519. $cachelist = array();
  520. $discuz = & discuz_core::instance();
  521. $discuz->cachelist = $cachelist;
  522. $discuz->init_cron = false;
  523. $discuz->init_setting = false;
  524. $discuz->init_user = false;
  525. $discuz->init_session = false;
  526. $discuz->init_misc = false;
  527. $discuz->init();
  528. require_once libfile('function/plugin');
  529. require_once libfile('function/cache');
  530. include_once libfile('function/block');
  531. $available = $_POST['pclose']+0;
  532. DB::query("UPDATE ".DB::table('common_plugin')." SET available='{$available}'");
  533. updatecache(array('plugin', 'setting', 'styles'));
  534. cleartemplatecache();
  535. updatecache();
  536. blockclass_cache();
  537. //note 清除群组缓存
  538. require_once libfile('function/group');
  539. $groupindex['randgroupdata'] = $randgroupdata = grouplist('lastupdate', array('ff.membernum', 'ff.icon'), 80);
  540. $groupindex['topgrouplist'] = $topgrouplist = grouplist('activity', array('f.commoncredits', 'ff.membernum', 'ff.icon'), 10);
  541. $groupindex['updateline'] = TIMESTAMP;
  542. $groupdata = DB::fetch_first("SELECT SUM(todayposts) AS todayposts, COUNT(fid) AS groupnum FROM ".DB::table('forum_forum')." WHERE status='3' AND type='sub'");
  543. $groupindex['todayposts'] = $groupdata['todayposts'];
  544. $groupindex['groupnum'] = $groupdata['groupnum'];
  545. save_syscache('groupindex', $groupindex);
  546. DB::query("TRUNCATE ".DB::table('forum_groupfield'));
  547. $tpl = dir(DISCUZ_ROOT.'./data/template');
  548. while($entry = $tpl->read()) {
  549. if(preg_match("/\.tpl\.php$/", $entry)) {
  550. @unlink(DISCUZ_ROOT.'./data/template/'.$entry);
  551. }
  552. }
  553. $tpl->close();
  554. show_msg('功能操作成功', 'tools.php?action=closesite',2000);
  555. } else {
  556. show_header();
  557. print<<<END
  558. <form action="?action=closesite" method="post">
  559. <h4>关闭/打开站点</h4>
  560. <p>
  561. 站点当前状态
  562. <input class="radio" type="radio" name="close" value="0" {$opened} class="radio">打开
  563. <input class="radio" type="radio" name="close" value="1" {$closed} class="radio">关闭
  564. </p>
  565. <h4>关闭/打开插件</h4>
  566. <p>
  567. 所有插件状态: {$plustr}
  568. <input class="radio" type="radio" name="pclose" value="1" {$openeds} class="radio">打开
  569. <input class="radio" type="radio" name="pclose" value="0" {$closeds} class="radio">关闭
  570. </p>
  571. <p>
  572. <input type="submit" name="closesitesubmit" value="提 &nbsp; 交">
  573. </p>
  574. </form>
  575. END;
  576. show_footer();
  577. }
  578. }elseif($action == 'closeplugin') {
  579. // TODO: 清理冗余数据.
  580. include_once(TOOLS_ROOT.'source/class/class_core.php');
  581. include_once(TOOLS_ROOT.'source/function/function_core.php');
  582. header('Content-type: text/html; charset=utf-8');
  583. $discuz = & discuz_core::instance();
  584. $discuz->init();
  585. $type = $_GET['types']?$_GET['types']:'index';
  586. // index
  587. if($type === 'index'){
  588. $sql = $sql = "SELECT `aid`, `uid`, `dateline`, `filename`, `filesize`, `attachment`, `remote`, `isimage`, `width`, `thumb`
  589. FROM ".DB::table('forum_attachment_unused')." ORDER BY aid DESC LIMIT 0, 200";
  590. $t = DB::fetch_all($sql);
  591. $aid_array = array();
  592. $data = '';
  593. foreach ($t AS $K=>$v){
  594. $v['filename'] = htmlspecialchars($v['filename']);
  595. $v['dateline'] = date('Y-m-d H:i:s',$v['dateline']);
  596. $v['filesize'] = sprintf('%0.2f',$v['filesize'] / 1024).'KB';
  597. if(!$_POST){
  598. $data .= "<tr>
  599. <td>{$v['aid']}</td>
  600. <td>{$v['filename']}</td>
  601. <td>{$v['uid']}</td>
  602. <td>{$v['dateline']}</td>
  603. <td>{$v['filesize']}</td>
  604. <tr>";
  605. }else{
  606. $path = './data/attachment/forum/';
  607. $file = $path.$v['attachment'];
  608. $ai = 1;
  609. if(is_file($file)){
  610. $ai = intval(@unlink($file));
  611. $di = 0;
  612. while(true){
  613. $di++;
  614. $file = dirname($file);
  615. $filelist = @scandir($file);
  616. if(count($filelist) <= 3){
  617. if(is_file($file.'/index.html'))
  618. @unlink($file.'/index.html');
  619. rmdir($file);
  620. }
  621. if($di == 2)
  622. break;
  623. }
  624. }
  625. if($ai){
  626. $aid_array[] = $v['aid'];
  627. }
  628. }
  629. }
  630. if(!$data){
  631. $data = "<tr>
  632. <td colspan=\"20\" style=\"text-align: center; color: #444;\">没有冗余信息</td>
  633. </tr>";
  634. }
  635. if($aid_array){
  636. $aidle = implode(',', $aid_array);
  637. DB::query("DELETE FROM ".DB::table('forum_attachment_unused')." WHERE aid IN ($aidle)");
  638. DB::query("DELETE FROM ".DB::table('forum_attachment')." WHERE aid IN ($aidle) AND tid='0'");
  639. show_msg('FROM 附件清理操作成功', 'tools.php?action=closeplugin',1000);
  640. }
  641. // tools.php?action=closeplugin&types=111
  642. show_header();
  643. print<<<END
  644. <form action="" method="post">
  645. <h4><a style="color:red" href="./tools.php?action=closeplugin">附件冗余</a> , <a href="./tools.php?action=closeplugin&types=depth">深度冗余</a> </h4>
  646. <div class=\"bm\">
  647. <table class=\"tb\">
  648. <tbody>
  649. <form name="cpform" method="post" autocomplete="on" action="tools.php?action=repairdb&type=repairtables" id="cpform">
  650. <tr>
  651. <th width="60">附件ID</th>
  652. <th width="200">文件名称</th>
  653. <th width="80">用户ID</th>
  654. <th width="140">上传时间</th>
  655. <th width="80">文件大小</th>
  656. </tr>
  657. {$data}
  658. </tbody>
  659. </table>
  660. * 默认每次清除50条.
  661. <p>
  662. <input type="submit" name="closesitesubmit" value=" 清 除 ">
  663. </p>
  664. </div>
  665. </form>
  666. END;
  667. show_footer();
  668. }else if($type === 'depth'){
  669. function db_get_tid($aid,$attachmentid){
  670. $attachmentid = intval($attachmentid);
  671. if($attachmentid <= 9){
  672. $sql = "SELECT * FROM ".DB::table('forum_attachment_'.$attachmentid)." WHERE `aid` = '{$aid}'";
  673. }else{
  674. $sql = "SELECT * FROM ".DB::table('forum_attachment')." WHERE `aid` = '{$aid}'";
  675. }
  676. $t = DB::fetch_first($sql);
  677. return $t;
  678. }
  679. $sql = DB::query("SELECT `aid`, `tid`, `pid`, `uid`, `tableid`, `downloads` FROM ".DB::table('forum_attachment'));
  680. $path = strtr(getglobal('setting/attachdir'),array('/./'=>'/')).'forum/';
  681. $infolist = array();
  682. while($row = DB::fetch($sql)){
  683. $ada = db_get_tid($row['aid'],$row['tableid']);
  684. if($ada){
  685. $row = array_merge($row, $ada);
  686. $pathfile = $path.$row['attachment'];
  687. // 先装载
  688. $infolist['filelist'][$row['attachment']][$row['aid']] = array('f'=>0);
  689. }else{
  690. $infolist['deledb'][] = $row['aid'];
  691. }
  692. $infolist['deledb'][] = $row['aid'];
  693. }
  694. $dirlist = @scandir($path);
  695. foreach($dirlist AS $val){
  696. if($val === '.' || $val === '..')
  697. continue;
  698. if(is_dir($path.$val.'/')){
  699. $dirlisttem = @scandir($path.$val.'/');
  700. foreach($dirlisttem AS $vals){
  701. if($vals === '.' || $vals === '..')
  702. continue;
  703. if(is_dir($path.$val.'/'.$vals.'/')){
  704. $dirlisttem_tem = @scandir($path.$val.'/'.$vals.'/');
  705. // 重点是这个循环
  706. foreach($dirlisttem_tem AS $fileval){
  707. if($fileval === '.' || $fileval === '..' || $fileval === 'index.html' || $fileval === 'index.htm')
  708. continue;
  709. $checkname = $val.'/'.$vals.'/'.$fileval;
  710. if($infolist['filelist'][$checkname]){
  711. foreach($infolist['filelist'][$checkname] AS $keyss => $valarr){
  712. $valarr['f'] = 1;
  713. $infolist['filelist'][$checkname][$keyss] = $valarr;
  714. }
  715. }else{
  716. $infolist['filelist'][$checkname][] = array('d'=>0);
  717. }
  718. }
  719. }
  720. }
  721. }
  722. }
  723. $data_file = $data_db = $data_notdb = '';
  724. if($infolist['filelist']){
  725. foreach($infolist['filelist'] AS $key => $val){
  726. $fname = $key;
  727. if(!$_POST){
  728. $aidlist = $dbcheck = '';
  729. foreach($val AS $k => $v){
  730. if(isset($v['f'])){
  731. if($v['f'] < 1)
  732. $aidlist .= $k.',';
  733. }
  734. if(isset($v['d'])){
  735. $dbcheck = 1;
  736. }
  737. }
  738. if($aidlist){
  739. $aidlist = trim($aidlist,',');
  740. $data_file .= "aid[$aidlist]: $fname <br />";
  741. }
  742. if($dbcheck){
  743. $data_notdb .= "$fname DB记录不存在 <br />";
  744. }
  745. }else{
  746. $aidlist = $dbcheck = '';
  747. foreach($val AS $k => $v){
  748. if(isset($v['f'])){
  749. if($v['f'] < 1){
  750. $k = intval($k);
  751. // 删除db记录.
  752. $sql = ("DELETE FROM ".DB::table('forum_attachment')." WHERE aid = '$k'");
  753. $one = DB::fetch_first($sql);
  754. $tableid = intval($one['tableid']);
  755. if($tableid <= 9)
  756. DB::query("DELETE FROM ".DB::table('forum_attachment_'.$tableid)." WHERE aid = '$k'");
  757. // 是否对0-9进行删除.
  758. DB::query("DELETE FROM ".DB::table('forum_attachment')." WHERE aid = '$k'");
  759. }
  760. }
  761. if(isset($v['d'])){
  762. // 删除文件
  763. $temname = $path.$fname;
  764. if(is_writable($temname)){
  765. @unlink($temname);
  766. }else{
  767. show_msg('论坛附件清理删除文件失败, 请确认权限是否可写!');
  768. }
  769. }
  770. }
  771. }
  772. # 删除空目录.
  773. $di = 0;
  774. $file = $path.$fname;
  775. while(true){
  776. $di++;
  777. $file = dirname($file);
  778. $filelist = @scandir($file);
  779. if(count($filelist) <= 3){
  780. if(is_file($file.'/index.html'))
  781. @unlink($file.'/index.html');
  782. @rmdir($file);
  783. }
  784. if($di == 2) // 2层目录.
  785. break;
  786. }
  787. }
  788. if($_POST){
  789. show_msg('论坛附件清理删除全部完成, 现在返回!');
  790. }
  791. }
  792. !$data_notdb && $data_notdb = '无异常!';
  793. !$data_db && $data_db = '无异常!';
  794. !$data_file && $data_file = '无异常!';
  795. show_header();
  796. print<<<END
  797. <form action="" method="post">
  798. <h4><a href="./tools.php?action=closeplugin">附件冗余</a> , <a style="color:red" href="./tools.php?action=closeplugin&types=depth">深度冗余</a> </h4>
  799. 附件目录: {$path}
  800. <div class=\"bm\">
  801. <table class=\"tb\">
  802. <tbody>
  803. <form name="cpform" method="post" autocomplete="on" action="tools.php?action=repairdb&type=repairtables" id="cpform">
  804. <!--<tr>
  805. <td colspan="2"><h3>附件数据表不对应列表 (一般不会出现)</h3>
  806. {$data_db}
  807. </td>
  808. </tr>-->
  809. <tr>
  810. <td style="width: 50%;">
  811. <h3 style="color:#0080FF">文件不存在列表: </h3>
  812. {$data_file}
  813. </td>
  814. <td>
  815. <h3 style="color:#0080FF">数据表不存在列表: </h3>
  816. {$data_notdb}
  817. </td>
  818. </tr>
  819. {$data}
  820. </tbody>
  821. </table>
  822. <p><br>
  823. <input type="submit" name="closesitesubmit" value=" 全 部 清 理 ">
  824. </p>
  825. </div>
  826. </form>
  827. END;
  828. show_footer();
  829. }
  830. //show_msg($msg, 'tools.php?action=index',2000);
  831. }elseif($action == 'repairdb') {
  832. // TODO: 修复数据库
  833. show_header();
  834. $t->connect_db();
  835. $typearray = array('index', 'repair', 'repairtables', 'allrepair', 'check', 'detail');
  836. $type = in_array($_GET['type'], $typearray) ? $_GET['type'] : 'index';
  837. set_time_limit(0);
  838. if($type == 'index') {
  839. print<<<END
  840. <div class=\"bm\">
  841. <table id="menu">
  842. <tr>
  843. <!--<td><a style="color: #0080FF;" href="?action=repairdb&type=allcheck">一键检查</a></td>-->
  844. <td><a style="color: #0080FF;" href="?action=repairdb&type=allrepair">一键修复</a></td>
  845. <td><a style="color: #0080FF;" href="?action=repairdb&type=detail">进入详细页面检查或修复</a></td>
  846. </tr>
  847. </table>
  848. 说明 & 提示:
  849. <ul>
  850. <!--<li>一键检查: 对数据库中所有表进行 CHECK TABLE 操作,列出损坏的数据表。</li>--!>
  851. <li>一键修复: 先执行 CHECK TABLE 操作,然后按照检查的结果对有错误的数据表执行REPAIR TABLE 操作。</li>
  852. <li>进入详细页面检查或修复: 列出详细表,对单表进行检查或修复。</li>
  853. <li><span style="color:red">提示1:数据表比较大的情况下,mysql可能会花费比较长的时间进行检查和修复操作。</span></li>
  854. <li><span style="color:red">提示2:REPAIR TABLE 操作不能修复所有情况,如果修复不了数据表,请登录服务器使用myisamchk进行数据表修复。</span></li>
  855. </ul>
  856. </div>
  857. END;
  858. } elseif ($type == 'allrepair' || $type == 'allcheck' || $type == 'detail' || $type == 'check' || $type == 'repair' || $type == 'repairtables') {
  859. $sql = "SHOW TABLE STATUS";
  860. $tablelist = mysql_query($sql, $t->db);
  861. while($list = mysql_fetch_array($tablelist, MYSQL_ASSOC)) {
  862. if($type == 'allcheck' || $type == 'allrepair') {
  863. if($list['Engine'] != 'MEMORY' && $list['Engine'] != 'HEAP') {
  864. $sql = 'CHECK TABLE '.$list['Name'];
  865. $query = mysql_query($sql, $t->db);
  866. $checkresult = mysql_fetch_array($query, MYSQL_ASSOC);
  867. if( $checkresult['Msg_text'] != 'OK') {
  868. $tablelists[$list['Name']]['statu'] = $checkresult['Msg_text'];
  869. $tablelists[$list['Name']]['size'] = round(($list['Data_length'] + $list['Index_length'])/1024,2);
  870. }
  871. }
  872. } else {
  873. $tablelists[$list['Name']]['size'] = round(($list['Data_length'] + $list['Index_length'])/1024,2);
  874. }
  875. }
  876. if($type == 'allrepair') {
  877. foreach($tablelists as $table => $value) {
  878. $sql = "REPAIR TABLE `".$table."`";
  879. $query = mysql_query($sql, $t->db);
  880. $repairresult = mysql_fetch_array($query, MYSQL_ASSOC);
  881. $resulttable[$table]['statu'] = $repairresult['Msg_text'];
  882. $resulttable[$table]['size'] = '未检查';
  883. }
  884. $tablelists = $resulttable;
  885. }
  886. if($type == 'check') {
  887. $_GET['table'] = addslashes($_GET['table']);
  888. $sql = 'CHECK TABLE '.$_GET['table'];
  889. $query = mysql_query($sql, $t->db);
  890. $checkresult = mysql_fetch_array($query, MYSQL_ASSOC);
  891. $tablelists[$_GET['table']]['statu'] = $checkresult['Msg_text'];
  892. }
  893. if($type == 'repair') {
  894. $_GET['table'] = addslashes($_GET['table']);
  895. $sql = "REPAIR TABLE `".$_GET['table']."`";
  896. $query = mysql_query($sql, $t->db);
  897. $repairresult = mysql_fetch_array($query, MYSQL_ASSOC);
  898. echo '<div style="background:red">';
  899. show_msg_body('修复表单 '.$_GET['table'].' 结果:'.$repairresult['Msg_text'], "tools.php?action=$action&type=detail", 3000);
  900. echo '</div>';
  901. }
  902. if($type == 'repairtables') {
  903. if($_POST['optimizesubmit']){
  904. $repairtables = addslashes($_POST['repairtables']);
  905. foreach ($repairtables as $value) {
  906. $sql = "REPAIR TABLE `".$value."`";
  907. $query = mysql_query($sql, $t->db);
  908. $repairresult = mysql_fetch_array($query, MYSQL_ASSOC);
  909. echo '<div style="background:red">';
  910. show_msg_body('修复表单 '.$value.' 结果:'.$repairresult['Msg_text'], '', 3000);
  911. echo '</div>';
  912. }
  913. echo '<div style="background:red">';
  914. show_msg_body('复选修复表单完成', "tools.php?action=$action&type=detail", 3000);
  915. echo '</div>';
  916. }
  917. }
  918. echo '
  919. <script type="text/javascript">
  920. var BROWSER = {};
  921. var USERAGENT = navigator.userAgent.toLowerCase();
  922. browserVersion({\'ie\':\'msie\',\'firefox\':\'\',\'chrome\':\'\',\'opera\':\'\',\'safari\':\'\',\'mozilla\':\'\',\'webkit\':\'\',\'maxthon\':\'\',\'qq\':\'qqbrowser\'});
  923. function browserVersion(types) {
  924. var other = 1;
  925. for(i in types) {
  926. var v = types[i] ? types[i] : i;
  927. if(USERAGENT.indexOf(v) != -1) {
  928. var re = new RegExp(v + \'(\\/|\\s)([\\d\\.]+)\', \'ig\');
  929. var matches = re.exec(USERAGENT);
  930. var ver = matches != null ? matches[2] : 0;
  931. other = ver !== 0 && v != \'mozilla\' ? 0 : other;
  932. } else {
  933. var ver = 0;
  934. }
  935. eval(\'BROWSER.\' + i + \'= ver\');
  936. }
  937. BROWSER.other = other;
  938. }
  939. function jumpurl(url,nw) {
  940. if(BROWSER.ie) url += (url.indexOf(\'?\') != -1 ? \'&\' : \'?\') + \'referer=\' + escape(location.href);
  941. if(nw == 1) {
  942. window.open(url);
  943. } else {
  944. location.href = url;
  945. }
  946. return false;
  947. }
  948. </script>';
  949. echo '
  950. <script type="text/javascript">
  951. function checkAll(type, form, value, checkall, changestyle) {
  952. var checkall = checkall ? checkall : \'chkall\';
  953. for(var i = 0; i < form.elements.length; i++) {
  954. var e = form.elements[i];
  955. if(type == \'option\' && e.type == \'radio\' && e.value == value && e.disabled != true) {
  956. e.checked = true;
  957. } else if(type == \'value\' && e.type == \'checkbox\' && e.getAttribute(\'chkvalue\') == value) {
  958. e.checked = form.elements[checkall].checked;
  959. if(changestyle) {
  960. multiupdate(e);
  961. }
  962. } else if(type == \'prefix\' && e.name && e.name != checkall && (!value || (value && e.name.match(value)))) {
  963. e.checked = form.elements[checkall].checked;
  964. if(changestyle) {
  965. if(e.parentNode && e.parentNode.tagName.toLowerCase() == \'li\') {
  966. e.parentNode.className = e.checked ? \'checked\' : \'\';
  967. }
  968. if(e.parentNode.parentNode && e.parentNode.parentNode.tagName.toLowerCase() == \'div\') {
  969. e.parentNode.parentNode.className = e.checked ? \'item checked\' : \'item\';
  970. }
  971. }
  972. }
  973. }
  974. }
  975. </script>';
  976. print<<<END
  977. <div class=\"bm\">
  978. <table class=\"tb\">
  979. <tbody>
  980. <form name="cpform" method="post" autocomplete="on" action="tools.php?action=repairdb&type=repairtables" id="cpform">
  981. <tr>
  982. <th></th>
  983. <th width="350px">表名</th>
  984. <th width="80px">大小</th>
  985. <th></th>
  986. <th width="80px"></th>
  987. </tr>
  988. END;
  989. foreach($tablelists as $name => $value) {
  990. if($value['size'] < 1024) {
  991. echo '<tr><th><input class="checkbox" type="checkbox" name="repairtables[]" value="'.$name.'"></th><th>'.$name.'</th><td style="text-align:right;color:#339900"">'.$value['size'] .'KB</td><td>';
  992. } elseif(1024 < $value['size'] && $value['size']< 1048576 ) {
  993. echo '<tr><th><input class="checkbox" type="checkbox" name="repairtables[]" value="'.$name.'"></th><th>'.$name.'</th><td style="text-align:right;color:#3333FF">'.round($value['size']/1024,1) .'MB</td><td>';
  994. } elseif(1048576 < $value['size']){
  995. echo '<tr><th><input class="checkbox" type="checkbox" name="repairtables[]" value="'.$name.'"></th><th>'.$name.'</th><td style="text-align:right;color:#FF0000"">'.round($value['size']/1048576,1) .'GB</td><td>';
  996. }
  997. if(!isset($value['statu'])) {
  998. echo "<button type=\"button\" class=\"pn vm\" onclick=\"jumpurl('tools.php?action=repairdb&type=check&table=".$name."')\"><strong>检查</button>";
  999. } elseif($value['statu']!='OK') {
  1000. echo '<span class=\"red\">'.$value['statu'].'</span>';
  1001. } else {
  1002. echo $value['statu'];
  1003. }
  1004. echo '</td><td>';
  1005. if($value['statu']!='OK' && $value['statu']!='Not Support CHECK') {
  1006. echo "<button type=\"button\" class=\"pn vm\" onclick=\"jumpurl('tools.php?action=repairdb&type=repair&table=".$name."')\"><strong>修复</button></strong>";
  1007. }
  1008. echo '</td></tr>';
  1009. }
  1010. echo "<tr><th><input name=\"chkall\" id=\"chkall\" class=\"checkbox\" onclick=\"checkAll('prefix', this.form)\" type=\"checkbox\"></th><th><input type=\"submit\" class=\"btn\" id=\"submit_optimizesubmit\" name=\"optimizesubmit\" title=\"复选修复\" value=\"复选修复\"></th><td></td><td></td><td></td></form>";
  1011. echo '</tbody></table></div>';
  1012. if( count($tablelists) == 0) {
  1013. echo '<div style="background:#00cc66;">没有需要修复的表</div>';
  1014. }
  1015. } elseif ($type == 'allrepair') {
  1016. show_msg("操作成功", "tools.php?action=$action");
  1017. }
  1018. show_footer();
  1019. }elseif($action == 'happy'){
  1020. // TODO: 幸福指数功能.
  1021. include_once(TOOLS_ROOT.'source/class/class_core.php');
  1022. include_once(TOOLS_ROOT.'source/function/function_core.php');
  1023. include_once(TOOLS_ROOT.'source/function/function_forumlist.php');
  1024. header('Content-type: text/html; charset=utf-8');
  1025. $discuz = & discuz_core::instance();
  1026. $discuz->init();
  1027. foreach($_POST AS $key => $val){
  1028. $_POST[$key] = trim($val);
  1029. }
  1030. if($_POST['pid']){
  1031. $fid = intval($_POST['pid']);
  1032. $thcount = intval($_POST['thcount']);
  1033. $postscount = intval($_POST['postscount']);
  1034. $tothcount = intval($_POST['tothcount']);
  1035. $yesterdayposts = intval($_POST['yesterdayposts']);
  1036. $data = '';
  1037. if($_POST['thcount'] !== ''){
  1038. $data .="threads='{$thcount}',";
  1039. }
  1040. if($_POST['postscount'] !== ''){
  1041. $data .="posts='{$postscount}',";
  1042. }
  1043. if($_POST['tothcount'] !== ''){
  1044. $data .="todayposts='$tothcount',";
  1045. }
  1046. if($_POST['yesterdayposts'] !== ''){
  1047. $data .="yesterdayposts='$yesterdayposts',";
  1048. }
  1049. $data = trim($data,' ,');
  1050. if($data){
  1051. $from_list = DB::query("UPDATE ".DB_PRE."forum_forum SET $data WHERE `fid`='$fid' ");
  1052. show_msg('版块数量设置成功!');
  1053. }else{
  1054. show_msg('你未输入任何修改项');
  1055. }
  1056. }
  1057. // 主题.
  1058. if($_POST['TID']){
  1059. $tid = intval($_POST['TID']);
  1060. $vcount = intval($_POST['views']);
  1061. $replies = intval($_POST['replies']);
  1062. $data = '';
  1063. if($_POST['replies'] !== ''){
  1064. $data .="replies='{$replies}',";
  1065. }
  1066. if($_POST['views'] !== ''){
  1067. $data .="views='{$vcount}',";
  1068. }
  1069. $data = trim($data,' ,');
  1070. if($data){
  1071. $from_list = DB::query("UPDATE ".DB_PRE."forum_thread SET $data WHERE `tid`='$tid'");
  1072. show_msg('主题查阅数量设置成功!');
  1073. }else{
  1074. show_msg('你未输入任何修改项');
  1075. }
  1076. }
  1077. // 查询出所有记录.
  1078. $query = DB::query("SELECT * FROM ".DB_PRE."forum_forum WHERE `type` = 'forum'");
  1079. $jsonarr = array();
  1080. while($row = DB::fetch($query)){
  1081. $jsonarr[$row['fid']]['threads'] = $row['threads'];
  1082. $jsonarr[$row['fid']]['posts'] = $row['posts'];
  1083. $jsonarr[$row['fid']]['todayposts'] = $row['todayposts'];
  1084. $jsonarr[$row['fid']]['yesterdayposts'] = $row['yesterdayposts'];
  1085. }
  1086. $jsonarr= json_encode($jsonarr);
  1087. show_header();
  1088. echo '<style type="text/css">
  1089. .cat_sel{ padding: 4px;vertical-align: middle;}
  1090. </style> ';
  1091. echo "<script type=\"text/javascript\">
  1092. var jsonarr = $jsonarr;
  1093. function sel(pid){
  1094. var obj = document.getElementById('thcount');
  1095. obj.value=jsonarr[pid]['threads'];
  1096. obj = document.getElementById('todayposts');
  1097. obj.value=jsonarr[pid]['todayposts'];
  1098. obj = document.getElementById('posts');
  1099. obj.value=jsonarr[pid]['posts'];
  1100. obj = document.getElementById('yesterdayposts');
  1101. obj.value=jsonarr[pid]['yesterdayposts'];
  1102. }
  1103. </script>";
  1104. echo '<table class="tb">
  1105. <tr><td><h4>版本设置数量</h4></td></tr>
  1106. <tr><td><form action="" method="post">';
  1107. echo '<select class="cat_sel" id="cat_sel" onchange="sel(this.value)" name="pid">';
  1108. $list = forumselect();
  1109. // 转换编码.
  1110. if (PHP_CHARSET !== 'utf-8'){
  1111. $list = mb_convert_encoding($list,'utf-8',PHP_CHARSET);
  1112. }
  1113. echo $list;
  1114. echo '</select>';
  1115. echo ' 今日主题数: <input id="thcount" style="width:60px" name="thcount" /> 今日帖题: <input id="todayposts" style="width:60px" name="tothcount" />
  1116. 版块总帖数: <input id="posts" style="width:60px" name="postscount" />
  1117. 昨天帖数: <input id="yesterdayposts" style="width:60px" name="yesterdayposts" />
  1118. <input type="submit" value=" 修 改 " />';
  1119. echo '<div><br>* 昨天帖数 要等到明天才会显示<br />
  1120. </div>';
  1121. echo '</form></td></tr>';
  1122. echo "<script type=\"text/javascript\">
  1123. var obj = document.getElementById('cat_sel');
  1124. sel(obj.value);
  1125. </script>";
  1126. echo '<tr><td><h4>主题设置数量</h4></td></tr>';
  1127. echo '<tr><td><form action="" method="post">';
  1128. echo ' 主题TID: <input style="width:60px" name="TID" /> 查阅数量: <input style="width:60px" name="views" /> 回复数量: <input style="width:60px" name="replies" />
  1129. <input type="submit" value=" 修 改 " />';
  1130. echo '<div><br>     * 查阅数只能大于或者等于回复数量</div>';
  1131. echo '</form></td></tr>';
  1132. echo '</table>';
  1133. show_footer();
  1134. $info = DB::fetch_all("SHOW KEYS FROM `pre_forum_forum`");
  1135. exit();
  1136. }elseif($action == 'restoredb') {
  1137. // TODO: 导入恢复数据库
  1138. $backfiledir = TOOLS_ROOT.'data/';
  1139. $detailarray = array();
  1140. $t->connect_db();
  1141. if(!mysql_select_db($t->dbconfig['name'], $t->db)) {
  1142. $dbname = $t->dbconfig['name'];
  1143. mysql_query("CREATE DATABASE $dbname");
  1144. }
  1145. if(!$_GET['importbak'] && !$_GET['nextfile']) {
  1146. $exportlog = array();
  1147. $dir = dir($backfiledir);
  1148. while($entry = $dir->read()) {
  1149. $entry = $backfiledir."$entry";
  1150. $num = 0;
  1151. if(is_dir($entry) && preg_match("/backup\_/i", $entry)) {
  1152. $bakdir = dir($entry);
  1153. while($bakentry = $bakdir->read()) {
  1154. $bakentry = "$entry/$bakentry";
  1155. if(is_file($bakentry) && preg_match("/(.*)\-(\d)\.sql/i", $bakentry,$match)) {
  1156. if($_GET['detail']) {
  1157. $detailarray[] = $match['1'];
  1158. }
  1159. $num++;
  1160. }
  1161. if(is_file($bakentry) && preg_match("/\-1\.sql/i", $bakentry)) {
  1162. $fp = fopen($bakentry, 'rb');
  1163. $bakidentify = explode(',', base64_decode(preg_replace("/^# Identify:\s*(\w+).*/s", "\\1", fgets($fp, 256))));
  1164. fclose ($fp);
  1165. if(preg_match("/\-1\.sql/i", $bakentry) || $bakidentify[3] == 'shell') {
  1166. $identify['bakentry'] = $bakentry;
  1167. }
  1168. }
  1169. }
  1170. $detailarray = array_reverse(array_unique($detailarray));
  1171. if($num != 0) {
  1172. $exportlog[$entry] = array(
  1173. 'dateline' => date('Y-m-d H:i:s',$bakidentify[0]),
  1174. 'version' => $bakidentify[1],
  1175. 'type' => $bakidentify[2],
  1176. 'method' => $bakidentify[3],
  1177. 'volume' => $num,
  1178. 'bakentry' => $identify['bakentry'],
  1179. 'filename' => str_replace($backfiledir.'/','',$entry));
  1180. }
  1181. }
  1182. }
  1183. }else{
  1184. $fpush = $_GET['fpush']+0;
  1185. //检测是否关闭站点
  1186. $sql = "SELECT svalue FROM ".DB_PRE."common_setting WHERE skey='bbclosed'";
  1187. $closed = mysql_result(mysql_query($sql, $t->db), 0);
  1188. if(!$fpush && !$closed) {
  1189. show_msg('恢复数据前,请先关闭站点!', 'tools.php?action=closesite', 3000);
  1190. }
  1191. $bakfile = $_GET['nextfile'] ? $_GET['nextfile'] : $_GET['importbak'];
  1192. if(!file_exists($bakfile)) {
  1193. if($_GET['nextfile']) {
  1194. $tpl = dir(TOOLS_ROOT.'data/template');
  1195. while($entry = $tpl->read()) {
  1196. if(preg_match("/\.tpl\.php$/", $entry)) {
  1197. @unlink(TOOLS_ROOT.'data/template/'.$entry);
  1198. }
  1199. }
  1200. $tpl->close();
  1201. show_msg('恢复备份成功,请查看论坛,如果数据不同步,请检查数据库前缀。正在更新缓存...', 'tools.php?action=updatecache',2000);
  1202. }
  1203. show_msg('备份文件不存在。');
  1204. }
  1205. if(!is_readable($bakfile)) {
  1206. show_msg('备份文件不可读取。');
  1207. } else {
  1208. @$fp = fopen($bakfile, "rb");
  1209. @flock($fp, 3);
  1210. $sqldump = @fread($fp, filesize($bakfile));
  1211. @fclose($fp);
  1212. }
  1213. @$bakidentify = explode(',', base64_decode(preg_replace("/^# Identify:\s*(\w+).*/s", "\\1", substr($sqldump, 0, 256))));
  1214. if(!$fpush && $bakidentify[1] != DISCUZ_VERSION){
  1215. show_msg('备份文件版本错误,不能恢复。');
  1216. }
  1217. $vol = $bakidentify[4];
  1218. $nextfile = taddslashes(str_replace("-$vol.sql","-".($vol+1).'.sql',$bakfile));
  1219. $result = $t->db_runquery($sqldump);
  1220. if($result) {
  1221. show_msg('正在恢复分卷:'.$vol,"tools.php?action=$action&nextfile=$nextfile&fpush=".$fpush, 2000);
  1222. }
  1223. }
  1224. $t->close_db();
  1225. show_header();
  1226. print<<<END
  1227. <div class="bm">
  1228. <form action="tools.php?action={$action}" method="post">
  1229. <table class="tdat"><tbody>
  1230. <tr class=\'alt h\'><th>备份项目</th><th>版本</th><th>时间</th><th>类型</th><th>文件总数</th><th>导入</th></tr>
  1231. END;
  1232. foreach( $exportlog as $value) {
  1233. echo '<tr><td>'.$value['filename'].'</td><td>'.$value['version'].'</td><td>'.$value['dateline'].'</td><td>'.$value['method'].'</td><td>'.$value['volume'].'</td><td><a href="tools.php?action='.$action.'&detail='.$value['filename'].'"><font color="blue">打开</font></a></td></tr>';
  1234. }
  1235. if (count($detailarray)>0) {
  1236. foreach($detailarray as $k => $value) {
  1237. $k ++;
  1238. echo '<tr><td colspan="5">['.$k.'] - '.$value.'</td><td><a onclick="jumpurl(this);" href="tools.php?action='.$action.'&importbak='.$value.'-1.sql"><font color="blue">导入</font></a></td></tr>';
  1239. }
  1240. }
  1241. if(!$exportlog && !$detailarray){
  1242. echo '<tr><td colspan="20" style="text-align: center; color:#444">./data/目录内未找到有效的备份目录文件</td></tr>';
  1243. }
  1244. echo '
  1245. <tr><td colspan="20" style="color:blue"><br>当前程序版本号: '.TOOLS_DISCUZ_VERSION.' <input onclick="setfpush(this);" type="checkbox" value="1" name="fpush" /> <span style="color: red;">强制导入</span></td>
  1246. </tbody></table></form></div>
  1247. <script type="text/javascript">
  1248. var fpush = 0;
  1249. function setfpush(obj){
  1250. if(obj.checked){
  1251. fpush = 1;
  1252. }else{
  1253. fpush = 0;
  1254. }
  1255. }
  1256. function jumpurl(obj){
  1257. obj.href = obj.href+"&fpush="+fpush;
  1258. }
  1259. </script>';
  1260. show_footer();
  1261. }elseif($action == 'updatecache'){
  1262. //更新缓存
  1263. include_once(TOOLS_ROOT.'source/class/class_core.php');
  1264. include_once(TOOLS_ROOT.'source/function/function_core.php');
  1265. header('Content-type: text/html; charset=utf-8');
  1266. $cachelist = array();
  1267. $discuz = & discuz_core::instance();
  1268. $discuz->cachelist = $cachelist;
  1269. $discuz->init_cron = false;
  1270. $discuz->init_setting = false;
  1271. $discuz->init_user = false;
  1272. $discuz->init_session = false;
  1273. $discuz->init_misc = false;
  1274. $discuz->init();
  1275. require_once libfile('function/cache');
  1276. updatecache();
  1277. include_once libfile('function/block');
  1278. blockclass_cache();
  1279. //note 清除群组缓存
  1280. require_once libfile('function/group');
  1281. $groupindex['randgroupdata'] = $randgroupdata = grouplist('lastupdate', array('ff.membernum', 'ff.icon'), 80);
  1282. $groupindex['topgrouplist'] = $topgrouplist = grouplist('activity', array('f.commoncredits', 'ff.membernum', 'ff.icon'), 10);
  1283. $groupindex['updateline'] = TIMESTAMP;
  1284. $groupdata = DB::fetch_first("SELECT SUM(todayposts) AS todayposts, COUNT(fid) AS groupnum FROM ".DB::table('forum_forum')." WHERE status='3' AND type='sub'");
  1285. $groupindex['todayposts'] = $groupdata['todayposts'];
  1286. $groupindex['groupnum'] = $groupdata['groupnum'];
  1287. save_syscache('groupindex', $groupindex);
  1288. DB::query("TRUNCATE ".DB::table('forum_groupfield'));
  1289. $tpl = dir(DISCUZ_ROOT.'./data/template');
  1290. while($entry = $tpl->read()) {
  1291. if(preg_match("/\.tpl\.php$/", $entry)) {
  1292. @unlink(DISCUZ_ROOT.'./data/template/'.$entry);
  1293. }
  1294. }
  1295. $tpl->close();
  1296. show_msg('更新数据缓存模板缓存成功!', 'tools.php?action=index', 2000);
  1297. }elseif($action == 'logout') {
  1298. // TODO: 退出系统.
  1299. tsetcookie('toolsauth', '', -1);
  1300. @header('Location:'.basename(__FILE__));
  1301. exit();
  1302. }
  1303. //大的分支 结束
  1304. /**********************************************************************************
  1305. *
  1306. * tools.php 通用函数部分
  1307. *
  1308. *
  1309. **********************************************************************************/
  1310. /*
  1311. checkpassword 函数
  1312. 判断密码强度,大小写字母加数字,长度大于6位。
  1313. return flase 或者 errormsg
  1314. */
  1315. function checkpassword($password){
  1316. return false;
  1317. }
  1318. //去掉slassh
  1319. function tstripslashes($string) {
  1320. if(empty($string)) return $string;
  1321. if(is_array($string)) {
  1322. foreach($string as $key => $val) {
  1323. $string[$key] = tstripslashes($val);
  1324. }
  1325. } else {
  1326. $string = stripslashes($string);
  1327. }
  1328. return $string;
  1329. }
  1330. function thash() {
  1331. return substr(md5(substr(time(), 0, -4).TOOLS_ROOT), 16);
  1332. }
  1333. function taddslashes($string, $force = 1) {
  1334. if(is_array($string)) {
  1335. foreach($string as $key => $val) {
  1336. $string[$key] = taddslashes($val, $force);
  1337. }
  1338. } else {
  1339. $string = addslashes($string);
  1340. }
  1341. return $string;
  1342. }
  1343. //显示
  1344. function show_msg($message, $url_forward='', $time = 2000, $noexit = 0) {
  1345. show_header();
  1346. !$url_forward && $url_forward = $_SERVER["HTTP_REFERER"];
  1347. show_msg_body($message, $url_forward, $time, $noexit);
  1348. show_footer();
  1349. !$noexit && exit();
  1350. }
  1351. function show_msg_body($message, $url_forward='', $time = 1, $noexit = 0) {
  1352. if($url_forward) {
  1353. $url_forward = $_GET['from'] ? $url_forward.'&from='.rawurlencode($_GET['from']) : $url_forward;
  1354. $message = "<a href=\"$url_forward\">$message (跳转中...)</a><script>setTimeout(\"window.location.href ='$url_forward';\", $time);</script>";
  1355. }else{
  1356. $message = "<a href=\"$url_forward\">$message </a>";
  1357. }
  1358. print<<<END
  1359. <table>
  1360. <tr><td>$message</td></tr>
  1361. </table>
  1362. END;
  1363. }
  1364. function login_page() {
  1365. show_header();
  1366. $formhash = thash();
  1367. $charset = PHPS_CHARSET;
  1368. $error = ERROR_MSG;
  1369. print<<<END
  1370. <span>急诊箱登录</span>
  1371. <form action="tools.php?action=login" method="post">
  1372. <table class="specialtable">
  1373. <tr>
  1374. <td width="20%"><input class="textinput" type="password" name="toolpassword"></input></td>
  1375. <td><input class="specialsubmit" type="submit" value=" 登 录 "></input>
  1376. </td>
  1377. </tr>
  1378. <tr>
  1379. <td colspan="2" style="color: #FF8040;">* tools 工具用于站点紧急维护 适用于 X3+ 系列 [{$charset}]<br />
  1380. {$error}
  1381. </td>
  1382. <tr>
  1383. </table>
  1384. <input type="hidden" name="action" value="login">
  1385. <input type="hidden" name="formhash" value="{$formhash}">
  1386. </form>
  1387. END;
  1388. show_footer();
  1389. }
  1390. function show_header() {
  1391. // TODO: 头部导航开始
  1392. $_GET['action'] = htmlspecialchars($_GET['action']);
  1393. $nowarr = array($_GET['action'] => ' class="current"');
  1394. $charset = PHP_CHARSET;
  1395. print<<<END
  1396. <!DOCTYPE html>
  1397. <html xmlns="http://www.w3.org/1999/xhtml">
  1398. <head>
  1399. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  1400. <title>Discuz! X3+ 急诊箱</title>
  1401. <style type="text/css">
  1402. input{vertical-align: middle;}
  1403. a:visited,a:link{color: #575757;}
  1404. * {font-size:12px; color: #575757; font-family: Verdana, Arial, Helvetica, sans-serif; line-height: 1.5em; word-break: break-all; }
  1405. body { text-align:center; margin: 0; padding: 0; background: #F5FBFF; }
  1406. .bodydiv { margin: 40px auto 0; width:1000px; text-align:left; border: solid #86B9D6; border-width: 5px 1px 1px; background: #FFF; }
  1407. h1 { font-size: 18px; margin: 1px 0 0; line-height: 50px; height: 50px; background: #E8F7FC; color: #5086A5; padding-left: 10px; }
  1408. #menu {width: 100%; margin: 10px auto; text-align: center; }
  1409. #menu td { height: 30px; line-height: 30px; color: #999; border-bottom: 3px solid #EEE; }
  1410. .current { font-weight: bold; color: #090 !important; border-bottom-color: #F90 !important; }
  1411. input { border: 1px solid #B2C9D3; padding: 5px; background: #F5FCFF; }
  1412. #footer { font-size: 10px; line-height: 40px; background: #E8F7FC; text-align: center; height: 38px; overflow: hidden; color: #5086A5; margin-top: 20px; }
  1413. table {width:100%;font-size:12px;margin-top:5px;}
  1414. table.specialtable,table.specialtable td {border:0;}
  1415. td,th {padding:5px;text-align:left;}
  1416. caption {font-weight:bold;padding:8px 0;color:#3544FF;text-align:left;}
  1417. th {background:#E8F7FC;font-weight:600;}
  1418. td.specialtd {text-align:left;}
  1419. #setadmin {margin: 0px;}
  1420. .textarea {height: 80px;width: 400px;padding: 3px;margin: 5px;}
  1421. </style>
  1422. </head>
  1423. <body>
  1424. <div class="bodydiv">
  1425. <h1>Discuz! X3+ 急诊箱</h1><br/>
  1426. <div style="width:90%;margin:0 auto;">
  1427. <table id="menu">
  1428. <tr>
  1429. <td{$nowarr[index]}><a href="?action=index">首页</a></td>
  1430. <td{$nowarr[serverinfo]}><a href="?action=serverinfo">系统信息</a></td>
  1431. <td{$nowarr[happy]}><a href="?action=happy">幸福指数</a></td>
  1432. <td{$nowarr[reinstall]}><a href="?action=reinstall">安装discuzx</a></td>
  1433. <td{$nowarr[setadmin]}><a href="?action=setadmin">重置管理员帐号</a></td>
  1434. <td{$nowarr[closesite]}><a href="?action=closesite">开启 & 关闭功能</a></td>
  1435. <td{$nowarr[closeplugin]}><a href="?action=closeplugin">清理冗余信息</a></td>
  1436. <td{$nowarr[repairdb]}><a href="?action=repairdb">修复数据库</a></td>
  1437. <td{$nowarr[restoredb]}><a href="?action=restoredb">恢复数据库</a></td>
  1438. <td{$nowarr[updatecache]}><a href="?action=updatecache">更新缓存</a></td>
  1439. <td{$nowarr[logout]}><a href="?action=logout">退出</a></td>
  1440. </tr>
  1441. </table>
  1442. <br>
  1443. END;
  1444. }
  1445. //页面顶部
  1446. function show_footer() {
  1447. global $tools_versions;
  1448. print<<<END
  1449. </div>
  1450. <div id="footer">Powered by {$tools_versions} &copy; Comsenz Inc. 2001-2015 <a href="http://www.comsenz.com" target="_blank">http://www.comsenz.com</a></div>
  1451. </div>
  1452. <br>
  1453. </body>
  1454. </html>
  1455. END;
  1456. }
  1457. //登录判断函数
  1458. function is_login() {
  1459. $error = false;
  1460. $errormsg = array();
  1461. $tpassword = TPASSWORD;
  1462. if(isset($_COOKIE['toolsauth'])) {
  1463. if($_COOKIE['toolsauth'] === md5($tpassword.thash())) {
  1464. return TRUE;
  1465. }
  1466. }
  1467. if ($_GET['action'] === 'login') {
  1468. $formhash = $_GET['formhash'];
  1469. $_GET['toolpassword'] = md5($_GET['toolpassword']);
  1470. if($formhash !== thash()) {
  1471. show_msg('您的请求来路不正或者输入密码超时,请刷新页面后重新输入正确密码!');
  1472. }
  1473. $toolsmd5 = md5($tpassword.thash());
  1474. if(md5($_GET['toolpassword'].thash()) == $toolsmd5) {
  1475. tsetcookie('toolsauth', $toolsmd5, time()+3600);
  1476. show_msg('登陆成功!', './tools.php?action=index', 2000);
  1477. } else {
  1478. show_msg( '您输入的密码不正确,请重新输入正确密码!', './tools.php', 2000);
  1479. }
  1480. } else {
  1481. return FALSE;
  1482. }
  1483. }
  1484. //登录成功设置cookie
  1485. function tsetcookie($var, $value = '', $life = 0, $prefix = '', $httponly = false, $cookiepath, $cookiedomain) {
  1486. $var = (empty($prefix) ? '' : $prefix).$var;
  1487. $_COOKIE[$var] = $value;
  1488. if($value == '' || $life < 0) {
  1489. $value = '';
  1490. $life = -1;
  1491. }
  1492. $path = $httponly && PHP_VERSION < '5.2.0' ? $cookiepath.'; HttpOnly' : $cookiepath;
  1493. $secure = $_SERVER['SERVER_PORT'] == 443 ? 1 : 0;
  1494. if(PHP_VERSION < '5.2.0') {
  1495. $r = setcookie($var, $value, $life);
  1496. } else {
  1497. $r = setcookie($var, $value, $life);
  1498. }
  1499. }
  1500. /*
  1501. T 类
  1502. tools.php 主要类
  1503. */
  1504. class T{
  1505. var $dbconfig = null;
  1506. var $ucdbconfig = null;
  1507. var $db = null;
  1508. var $ucdb = null;
  1509. // 是否已经初始化
  1510. var $initated = false;
  1511. public function init() {
  1512. if(!$this->initated) {
  1513. $this->_init_config();
  1514. $this->_init_db();
  1515. }
  1516. $this->initated = true;
  1517. }
  1518. public function db_runquery($sql) {
  1519. $tablepre = $this->dbconfig['tablepre'];
  1520. $dbcharset = $this->dbconfig['charset'];
  1521. if(!isset($sql) || empty($sql)) return;
  1522. $sql = str_replace("\r", "\n", str_replace(array(' {tablepre}', ' cdb_', ' `cdb_', ' pre_', ' `pre_'), array(' '.$tablepre, ' '.$tablepre, ' `'.$tablepre, ' '.$tablepre, ' `'.$tablepre), $sql));
  1523. $ret = array();
  1524. $num = 0;
  1525. foreach(explode(";\n", trim($sql)) as $query) {
  1526. $ret[$num] = '';
  1527. $queries = explode("\n", trim($query));
  1528. foreach($queries as $query) {
  1529. $ret[$num] .= (isset($query[0]) && $query[0] == '#') || (isset($query[1]) && isset($query[1]) && $query[0].$query[1] == '--') ? '' : $query;
  1530. }
  1531. $num++;
  1532. }
  1533. unset($sql);
  1534. $this->connect_db();
  1535. foreach($ret as $query) {
  1536. $query = trim($query);
  1537. if($query) {
  1538. if(substr($query, 0, 12) == 'CREATE TABLE') {
  1539. $name = preg_replace("/CREATE TABLE ([a-z0-9_]+) .*/is", "\\1", $query);
  1540. mysql_query($this->db_createtable($query, $dbcharset), $this->db);
  1541. } else {
  1542. mysql_query($query, $this->db);
  1543. }
  1544. }
  1545. }
  1546. return 1;
  1547. }
  1548. public function db_createtable($sql, $dbcharset) {
  1549. $type = strtoupper(preg_replace("/^\s*CREATE TABLE\s+.+\s+\(.+?\).*(ENGINE|TYPE)\s*=\s*([a-z]+?).*$/isU", "\\2", $sql));
  1550. $type = in_array($type, array('MYISAM', 'HEAP')) ? $type : 'MYISAM';
  1551. return preg_replace("/^\s*(CREATE TABLE\s+.+\s+\(.+?\)).*$/isU", "\\1", $sql).(mysql_get_server_info() > '4.1' ? " ENGINE=$type DEFAULT CHARSET=$dbcharset" : " TYPE=$type");
  1552. }
  1553. public function connect_db($type = 'db') {
  1554. if($type == 'db') {
  1555. $dbhost = $this->dbconfig['host'];
  1556. $dbuser = $this->dbconfig['user'];
  1557. $dbpw = $this->dbconfig['pw'];
  1558. $dbname = $this->dbconfig['name'];
  1559. $dbcharset = $this->dbconfig['charset'];
  1560. } else {
  1561. $dbhost = $this->ucdbconfig['host'];
  1562. $dbuser = $this->ucdbconfig['user'];
  1563. $dbpw = $this->ucdbconfig['pw'];
  1564. $dbname = $this->ucdbconfig['name'];
  1565. $dbcharset = $this->ucdbconfig['charset'];
  1566. }
  1567. if($dbhost && $dbuser && $dbpw && !$this->db = mysql_connect($dbhost, $dbuser, $dbpw, 1))
  1568. show_msg('Discuz! X数据库连接出错,请检查config_global.php中数据库相关信息是否正确,与数据库服务器网络连接是否正常');
  1569. $dbversion = mysql_get_server_info($this->db);
  1570. if($dbversion > '4.1') {
  1571. if($dbcharset) {
  1572. mysql_query("SET character_set_connection=".$dbcharset.", character_set_results=".$dbcharset.", character_set_client=binary", $this->db);
  1573. }
  1574. if($dbversion > '5.0.1') {
  1575. mysql_query("SET sql_mode=''", $this->db);
  1576. }
  1577. }
  1578. @mysql_select_db($dbname, $this->db);
  1579. }
  1580. public function close_db() {
  1581. mysql_close($this->db);
  1582. }
  1583. private function _init_config() {
  1584. $error = false;
  1585. $_config = array();
  1586. @include TOOLS_ROOT.'config/config_global.php';
  1587. $errormsg = '';
  1588. if(empty($_config)) {
  1589. //$error = true;
  1590. $errormsg .= '没有找到 '.TOOLS_ROOT.'config/config_global.php 文件!';
  1591. }
  1592. $uc_config_file = TOOLS_ROOT.'config/config_ucenter.php';
  1593. if(!@file_exists($uc_config_file)) {
  1594. //$error = true;
  1595. $errormsg .= '没有找到'.$uc_config_file.'文件!';
  1596. }
  1597. @include $uc_config_file;
  1598. !$_GET['action'] && $_GET['action'] = 'index';
  1599. if($error && !in_array($_GET['action'], array('index','reinstall','logout'))) {
  1600. show_msg($errormsg);
  1601. }
  1602. if(!$errormsg)
  1603. $errormsg = '根目录:'.TOOLS_ROOT;
  1604. define('ERROR_MSG','* '.$errormsg);
  1605. $this->config = & $_config;
  1606. $this->config['dbcharset'] = $_config['db']['1']['dbcharset'];
  1607. $this->config['charset'] = $_config['output']['charset'];
  1608. }
  1609. private function _init_db() {
  1610. $this->dbconfig['host'] = $this->config['db']['1']['dbhost'];
  1611. $this->dbconfig['user'] = $this->config['db']['1']['dbuser'];
  1612. $this->dbconfig['pw'] = $this->config['db']['1']['dbpw'];
  1613. $this->dbconfig['name'] = $this->config['db']['1']['dbname'];
  1614. $this->dbconfig['charset'] = $this->config['db']['1']['dbcharset'];
  1615. $this->dbconfig['tablepre'] = $this->config['db']['1']['tablepre'];
  1616. $this->ucdbconfig['host'] = UC_DBHOST;
  1617. $this->ucdbconfig['user'] = UC_DBUSER;
  1618. $this->ucdbconfig['pw'] = UC_DBPW;
  1619. $this->ucdbconfig['name'] = UC_DBNAME;
  1620. $this->ucdbconfig['charset'] = UC_DBCHARSET;
  1621. $this->ucdbconfig['tablepre'] = UC_DBTABLEPRE;
  1622. $this->connect_db();
  1623. $sql = "SHOW FULL PROCESSLIST";
  1624. $query = mysql_query($sql, $this->db);
  1625. $waiting = false;
  1626. $waiting_msg = '';
  1627. while($l = mysql_fetch_array($query, MYSQL_ASSOC)) {
  1628. if($l['State'] == 'Checking table') {
  1629. $this->close_db();
  1630. $waiting = true;
  1631. $waiting_msg = '正在检查表,请稍后...';
  1632. } elseif($l['State'] == 'Repair by sorting') {
  1633. $this->close_db();
  1634. $waiting = true;
  1635. $waiting_msg = '正在修复表,请稍后...';
  1636. }
  1637. }
  1638. if($waiting) {
  1639. show_msg($waiting_msg, 'tools.php?action=repairdb', 3000);
  1640. }
  1641. }
  1642. }
  1643. //T class 结束
  1644. /**
  1645. * End of the tools.php
  1646. */
  1647. class zip{
  1648. public $total_files = 0;
  1649. public $total_folders = 0;
  1650. function Extract( $zn, $to, $index = Array(-1) ){
  1651. $ok = 0; $zip = @fopen($zn,'rb');
  1652. if(!$zip) return(-1);
  1653. $cdir = $this->ReadCentralDir($zip,$zn);
  1654. $pos_entry = $cdir['offset'];
  1655. if(!is_array($index)){ $index = array($index); }
  1656. for($i=0; $index[$i];$i++){
  1657. if(intval($index[$i])!=$index[$i]||$index[$i]>$cdir['entries'])
  1658. return(-1);
  1659. }
  1660. for ($i=0; $i<$cdir['entries']; $i++)
  1661. {
  1662. @fseek($zip, $pos_entry);
  1663. $header = $this->ReadCentralFileHeaders($zip);
  1664. $header['index'] = $i; $pos_entry = ftell($zip);
  1665. @rewind($zip); fseek($zip, $header['offset']);
  1666. if(in_array("-1",$index)||in_array($i,$index))
  1667. $stat[$header['filename']]=$this->ExtractFile($header, $to, $zip);
  1668. }
  1669. fclose($zip);
  1670. return $stat;
  1671. }
  1672. function ReadFileHeader($zip){
  1673. $binary_data = fread($zip, 30);
  1674. $data = unpack('vchk/vid/vversion/vflag/vcompression/vmtime/vmdate/Vcrc/Vcompressed_size/Vsize/vfilename_len/vextra_len', $binary_data);
  1675. $header['filename'] = fread($zip, $data['filename_len']);
  1676. if ($data['extra_len'] != 0) {
  1677. $header['extra'] = fread($zip, $data['extra_len']);
  1678. } else { $header['extra'] = ''; }
  1679. $header['compression'] = $data['compression'];$header['size'] = $data['size'];
  1680. $header['compressed_size'] = $data['compressed_size'];
  1681. $header['crc'] = $data['crc']; $header['flag'] = $data['flag'];
  1682. $header['mdate'] = $data['mdate'];$header['mtime'] = $data['mtime'];
  1683. if ($header['mdate'] && $header['mtime']){
  1684. $hour=($header['mtime']&0xF800)>>11;$minute=($header['mtime']&0x07E0)>>5;
  1685. $seconde=($header['mtime']&0x001F)*2;$year=(($header['mdate']&0xFE00)>>9)+1980;
  1686. $month=($header['mdate']&0x01E0)>>5;$day=$header['mdate']&0x001F;
  1687. $header['mtime'] = mktime($hour, $minute, $seconde, $month, $day, $year);
  1688. }else{$header['mtime'] = time();}
  1689. $header['stored_filename'] = $header['filename'];
  1690. $header['status'] = "ok";
  1691. return $header;
  1692. }
  1693. function ReadCentralFileHeaders($zip){
  1694. $binary_data = fread($zip, 46);
  1695. $header = unpack('vchkid/vid/vversion/vversion_extracted/vflag/vcompression/vmtime/vmdate/Vcrc/Vcompressed_size/Vsize/vfilename_len/vextra_len/vcomment_len/vdisk/vinternal/Vexternal/Voffset', $binary_data);
  1696. if ($header['filename_len'] != 0)
  1697. $header['filename'] = fread($zip,$header['filename_len']);
  1698. else $header['filename'] = '';
  1699. if ($header['extra_len'] != 0)
  1700. $header['extra'] = fread($zip, $header['extra_len']);
  1701. else $header['extra'] = '';
  1702. if ($header['comment_len'] != 0)
  1703. $header['comment'] = fread($zip, $header['comment_len']);
  1704. else $header['comment'] = '';
  1705. if ($header['mdate'] && $header['mtime'])
  1706. {
  1707. $hour = ($header['mtime'] & 0xF800) >> 11;
  1708. $minute = ($header['mtime'] & 0x07E0) >> 5;
  1709. $seconde = ($header['mtime'] & 0x001F)*2;
  1710. $year = (($header['mdate'] & 0xFE00) >> 9) + 1980;
  1711. $month = ($header['mdate'] & 0x01E0) >> 5;
  1712. $day = $header['mdate'] & 0x001F;
  1713. $header['mtime'] = mktime($hour, $minute, $seconde, $month, $day, $year);
  1714. } else {
  1715. $header['mtime'] = time();
  1716. }
  1717. $header['stored_filename'] = $header['filename'];
  1718. $header['status'] = 'ok';
  1719. if (substr($header['filename'], -1) == '/')
  1720. $header['external'] = 0x41FF0010;
  1721. return $header;
  1722. }
  1723. function ReadCentralDir($zip,$zip_name){
  1724. $size = filesize($zip_name);
  1725. if ($size < 277) $maximum_size = $size;
  1726. else $maximum_size=277;
  1727. @fseek($zip, $size-$maximum_size);
  1728. $pos = ftell($zip); $bytes = 0x00000000;
  1729. while ($pos < $size){
  1730. $byte = @fread($zip, 1); $bytes=($bytes << 8) | ord($byte);
  1731. if ($bytes == 0x504b0506 or $bytes == 0x2e706870504b0506){ $pos++;break;} $pos++;
  1732. }
  1733. $fdata=fread($zip,18);
  1734. $data=@unpack('vdisk/vdisk_start/vdisk_entries/ventries/Vsize/Voffset/vcomment_size',$fdata);
  1735. if ($data['comment_size'] != 0) $centd['comment'] = fread($zip, $data['comment_size']);
  1736. else $centd['comment'] = ''; $centd['entries'] = $data['entries'];
  1737. $centd['disk_entries'] = $data['disk_entries'];
  1738. $centd['offset'] = $data['offset'];$centd['disk_start'] = $data['disk_start'];
  1739. $centd['size'] = $data['size']; $centd['disk'] = $data['disk'];
  1740. return $centd;
  1741. }
  1742. function ExtractFile($header,$to,$zip){
  1743. $header = $this->readfileheader($zip);
  1744. if(substr($to,-1)!="/") $to.="/";
  1745. if($to=='./') $to = '';
  1746. $header['filename'] = ltrim(strtr('./'.$header['filename'],array('./upload/'=>'./')),'./');
  1747. $pth = explode("/",$to.$header['filename']);
  1748. $mydir = './';
  1749. if('./utility/' === './'.$pth[0].'/' || './readme/' === './'.$pth[0].'/')
  1750. return true;
  1751. for($i=0;$i<count($pth)-1;$i++){
  1752. if(!$pth[$i]) continue;
  1753. $mydir .= $pth[$i]."/";
  1754. if((!is_dir($mydir) && @mkdir($mydir,0777)) || (($mydir==$to.$header['filename'] || ($mydir==$to && $this->total_folders==0)) && is_dir($mydir)) ){
  1755. @chmod($mydir,0777);
  1756. $this->total_folders ++;
  1757. }
  1758. }
  1759. if(strrchr($header['filename'],'/')=='/') return;
  1760. if (!($header['external']==0x41FF0010)&&!($header['external']==16)){
  1761. if ($header['compression']==0){
  1762. if($to.$header['filename'])
  1763. $fp = @sfopen($to.$header['filename'], 'wb');
  1764. if(!$fp) return(-1);
  1765. $size = $header['compressed_size'];
  1766. while ($size != 0){
  1767. $read_size = ($size < 2048 ? $size : 2048);
  1768. $buffer = fread($zip, $read_size);
  1769. $binary_data = pack('a'.$read_size, $buffer);
  1770. @fwrite($fp, $binary_data, $read_size);
  1771. $size -= $read_size;
  1772. }
  1773. fclose($fp);
  1774. touch($to.$header['filename'], $header['mtime']);
  1775. }else{
  1776. $fp = @fopen($to.$header['filename'].'.gz','wb');
  1777. if(!$fp) return(-1);
  1778. $binary_data = pack('va1a1Va1a1', 0x8b1f, Chr($header['compression']),
  1779. Chr(0x00), time(), Chr(0x00), Chr(3));
  1780. fwrite($fp, $binary_data, 10);
  1781. $size = $header['compressed_size'];
  1782. while ($size != 0){
  1783. $read_size = ($size < 1024 ? $size : 1024);
  1784. $buffer = fread($zip, $read_size);
  1785. $binary_data = pack('a'.$read_size, $buffer);
  1786. @fwrite($fp, $binary_data, $read_size);
  1787. $size -= $read_size;
  1788. }
  1789. $binary_data = pack('VV', $header['crc'], $header['size']);
  1790. fwrite($fp, $binary_data,8); fclose($fp);
  1791. $fp = @sfopen($to.$header['filename'],'wb');
  1792. if(!$fp) return(-1);
  1793. $gzp = @gzopen($to.$header['filename'].'.gz','rb');
  1794. if(!$gzp) return(-2);
  1795. $size = $header['size'];
  1796. while ($size != 0){
  1797. $read_size = ($size < 2048 ? $size : 2048);
  1798. $buffer = gzread($gzp, $read_size);
  1799. $binary_data = pack('a'.$read_size, $buffer);
  1800. @fwrite($fp, $binary_data, $read_size);
  1801. $size -= $read_size;
  1802. }
  1803. fclose($fp); gzclose($gzp);
  1804. touch($to.$header['filename'], $header['mtime']);
  1805. @unlink($to.$header['filename'].'.gz');
  1806. }
  1807. }
  1808. $this->total_files ++;
  1809. return true;
  1810. }
  1811. }
  1812. function sfopen($path, $type='wb'){
  1813. global $gzp;
  1814. static $oldfile = array();
  1815. if($path === true)
  1816. return $oldfile;
  1817. if(is_file($path) && !YESINSTALL){
  1818. if(is_file($path.'.gz')){
  1819. @gzclose($gzp);
  1820. if(!@unlink($path.'.gz'))
  1821. if(!@unlink($path.'.gz'))
  1822. if(!@unlink($path.'.gz'))
  1823. if(!@unlink($path.'.gz'))
  1824. if(!@unlink($path.'.gz'))
  1825. exit('unlink err:'. $path.'.gz');
  1826. }
  1827. $oldfile[0][] = $path;
  1828. return false;
  1829. }
  1830. $oldfile[1][] = $path;
  1831. return @fopen($path,$type);
  1832. }
  1833. function curl_getdata($url) {
  1834. if(!function_exists('curl_init')){
  1835. $opts = array(
  1836. 'http'=>array(
  1837. 'method'=>"GET",
  1838. 'timeout'=>600,
  1839. )
  1840. );
  1841. $context = stream_context_create($opts);
  1842. $html =file_get_contents($url, false, $context);
  1843. return $html;
  1844. }
  1845. $curl = curl_init();
  1846. curl_setopt( $curl, CURLOPT_URL, $url ); // 要访问的地址
  1847. curl_setopt( $curl, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.1.4322)"); // 模拟用户使用的浏览器
  1848. curl_setopt( $curl, CURLOPT_FOLLOWLOCATION, 3); // 使用自动跳转
  1849. curl_setopt( $curl, CURLOPT_REFERER, 'http://www.discuz.net/forum-2-1.html'); // 自动设置Referer
  1850. curl_setopt( $curl, CURLOPT_HTTPGET, 1 ); // 发送一个常规的Post请求
  1851. curl_setopt( $curl, CURLOPT_TIMEOUT, 600); // 设置超时限制防止死循环
  1852. curl_setopt( $curl, CURLOPT_HEADER, 0 ); // 显示返回的Header区域内容
  1853. curl_setopt( $curl, CURLOPT_RETURNTRANSFER, 1 ); // 获取的信息以文件流的形式返回
  1854. $tmpInfo = curl_exec( $curl ); // 执行操作
  1855. curl_close( $curl ); // 关闭CURL会话
  1856. return $tmpInfo; // 返回数据
  1857. }
  1858. function fun_reinstall($type,$path = false){
  1859. $action = $_GET['action'];
  1860. if($type === 'two'){
  1861. if(is_file('./data/install.lock'))
  1862. @unlink('./data/install.lock');
  1863. if(is_file('./data/sendmail.lock'))
  1864. @unlink('./data/sendmail.lock');
  1865. if(is_dir('./install/')){
  1866. show_msg('二次安装过程即将开始....', 'install/', 2000);
  1867. }
  1868. show_msg('找不到所需要的安装目录install, 程序无法安装', 'tools.php?action='.$action, 2000);
  1869. }else{
  1870. static $back_dirs = '';
  1871. if(!$back_dirs)
  1872. $back_dirs = './backs_'.date('Y-m-d_His').'/';
  1873. $back_dir .= $back_dirs.ltrim($path,'./');
  1874. if(!is_dir($back_dir)){
  1875. mkdir($back_dir);
  1876. }
  1877. $list = scandir($path);
  1878. $i = 0;
  1879. foreach($list AS $val){
  1880. if($val == '.' || $val == '..' || $val === basename(__FILE__) || strpos($val,'backs_') !== false)
  1881. continue;
  1882. if(is_dir($path.$val.'/')){
  1883. fun_reinstall($type, $path.$val.'/');
  1884. }else{
  1885. if(!copy($path.$val, $back_dir.$val))
  1886. if(!copy($path.$val, $back_dir.$val))
  1887. if(!copy($path.$val, $back_dir.$val))
  1888. if(!copy($path.$val, $back_dir.$val))
  1889. if(!copy($path.$val, $back_dir.$val))
  1890. $sss = 111;
  1891. $i++;
  1892. @unlink($path.$val);
  1893. }
  1894. }
  1895. if($path !== './'){
  1896. @rmdir($path);
  1897. }else{
  1898. if($i===0){
  1899. if(@rmdir($back_dir) === false)
  1900. if(@rmdir($back_dir) === false)
  1901. if(@rmdir($back_dir) === false)
  1902. if(@rmdir($back_dir) === false)
  1903. if(@rmdir($back_dir) === false)
  1904. $s = 0;
  1905. }
  1906. }
  1907. }
  1908. }
  1909. // TODO: 函数开始
  1910. function fun_char($data){
  1911. global $is_utf8;
  1912. if(!$is_utf8){
  1913. return mb_convert_encoding($data,HTML_CHARSET,THIS_CHARSET);
  1914. }else{
  1915. return $data;
  1916. }
  1917. }
  1918. function fun_size($size) {
  1919. $units = array(' BYT', ' KB', ' MB', ' GB', ' TB');
  1920. for ($i = 0; $size >= 1024 && $i < 4; $i++) $size /= 1024;
  1921. return round($size, 2).$units[$i];
  1922. }