Discuz无法访问站点解决方案

如果你的discuz因为非系统业务逻辑或系统运行环境配置问题导致的访问不了,均可参考该文章。

文章不小心写好了电脑突然异常没了,直接简单点说这种情况大部分是由于管理员在后台设置了指定ip可访问,指定ip不可访问、用户组之类的。

修改数据库

  1. 检查数据表 pre_common_setting 搜索ipaccess 是否设置了允许访问的ip 如果有将其置空;

  2. 检查数据表 pre_common_usergroup,是否将 allowvisit设置了为0(禁止访问),1是允许访问;

  3. 检查 pre_common_failedlogin 将其中有对应的ip记录删除掉;

  4. 如果是非管理员,请检查该用户所在用户组“访问站点权限”是否设置了禁止访问

  5. 找到 pre_common_setting 表,搜索 skey=ipaccess 这是允许访问站点前台的IP列表,key=adminipaccess这是允许访问后台的IP列表,一般清空即可。

清除缓存

有些文章真是误人子弟,让登录后台进行清除缓存,我要能进后台还用到这一步。

使用工具包

使用工具包,toolsuctools,这两个文件第一个可以清除缓存、改密码、插件之类的一些功能,uctools侧重于数据库语句执行。

两个文件均放在根目录即可,别听有些文章讲的,要放在uc_server中,执行方式:域名+工具名

牵涉到作者版权请联系本人进行删除

tools.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
<?php
/**
* [Discuz!] (C)2001-2099 Comsenz Inc.
* This is NOT a freeware, use is subject to license terms
*
* $Id: tools.php 111 2013-03-18 02:43:43Z xujiakun $
*/

/**
* 密码要求:1、必须且只能包含大写字母、小写字母、数字
* 2、密码长度大于6
* 修改下面的 $password = '',单引号中按照密码要求写入你的密码,举例 $password = 'DiscuzX3' ,注意:请不要把密码设置成 DiscuzX3,以免被人获知。
*/
$tpassword = 'DiscuzX3';
/**
* 修复者: 天外飘仙
* 插件定制,discuz技术支持,云服务器购买 联系QQ 860855665
* 主页:https://addon.dismall.com/developer-99821.html
*/
/*************************************以下部分为tools工具箱的核心代码,请不要随意修改**************************************/

error_reporting(0);
// error_reporting(E_ALL ^ E_NOTICE);
define('TMAGIC_QUOTES_GPC', function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc());

define('TOOLS_ROOT', dirname(__FILE__).'/');
define('TOOLS_VERSION', 'Tools 3.0.0');
define('TOOLS_DISCUZ_VERSION', 'Discuz! X2.5,X3.0,X3.1,X3.2,X3.3,X3.4,X3.5');

define('TDISCUZ_ROOT', dirname(__FILE__).'/');

$tools_versions = TOOLS_VERSION;
$tools_discuz_version = TOOLS_DISCUZ_VERSION;

if(!TMAGIC_QUOTES_GPC) {
$_GET = taddslashes($_GET);
$_POST = taddslashes($_POST);
$_COOKIE = taddslashes($_COOKIE);
}

if (isset($_GET['GLOBALS']) || isset($_POST['GLOBALS']) || isset($_COOKIE['GLOBALS']) || isset($_FILES['GLOBALS'])) {
show_msg('您当前的访问请求当中含有非法字符,已经被系统拒绝');
}

if($_SERVER['REQUEST_METHOD'] == 'POST' && !empty($_POST)) {
$_GET = array_merge($_GET, $_POST);
}

$actionarray = array('index', 'setadmin', 'closesite', 'closeplugin', 'repairdb', 'restoredb', 'updatecache', 'login', 'logout');
$_GET['action'] = htmlspecialchars($_GET['action']);
$action = in_array($_GET['action'], $actionarray) ? $_GET['action'] : 'index';

if(!is_login()) {
login_page();
exit;
}

$t = new T();
$t->init();
$config = $t->config;

if($action == 'index') {
//首页
show_header();
print<<<END
<p>欢迎使用 Tools 之 Discuz! 急诊箱功能!我们致力于为您解决 Discuz! 站点的紧急故障,欢迎各位站长朋友们使用。</p>
<tr><td>
<h5>适用版本:</h5>
<ul>
<li>{$tools_discuz_version}</li>
</ul>
<h5>主要功能:</h5>
<ul>
<li>重置管理员账号:将把您指定的会员设置为管理员</li>
<li>开启关闭站点: 此处可以进行站点“关闭/打开”的操作</li>
<li>一键关闭插件: 一键关闭应用中心开启的所有插件</li>
<li>修复数据库: 对所有数据表进行检查修复工作</li>
<li>恢复数据库: 一次性导入论坛数据备份</li>
<li>更新缓存: 一键更新论坛的数据缓存与模板缓存</li>
</ul>
END;
show_footer();

}elseif($action == 'setadmin') {
//找回管理员
$t->connect_db();
$founders = @explode(',',$t->config['admincp']['founder']);
$foundernames = array();
foreach($founders as $userid) {
$sql = "SELECT username FROM ".$t->dbconfig['tablepre']."common_member WHERE `uid`='$userid'";
$foundernames[] = mysqli_result(mysqli_query($t->db, $sql), 0);
}
$foundernames = implode(',', $foundernames);
// print_r($foundernames);
$sql = "SELECT username FROM ".$t->dbconfig['tablepre']."common_member WHERE `adminid`='1'";
$query = mysqli_query($t->db, $sql) or dir(mysqli_error($t->db));
$adminnames = array();
while($row = mysqli_fetch_row($query)) {
$adminnames[] = $row[0];
}
$adminnames = implode(',', $adminnames);

if(!empty($_POST['setadminsubmit'])) {
if($_GET['username'] == NULL) {
show_msg('请输入用户名', 'tools.php?action='.$action, 2000);
}

if($_GET['loginfield'] == 'username') {
$_GET['username'] = addslashes($_GET['username']);
$sql = "SELECT uid FROM ".$t->dbconfig['tablepre']."common_member WHERE `username`='".$_GET['username']."'";
$uid = mysqli_result(mysqli_query($t->db, $sql), 0);
$username = $_GET['username'];
} elseif($_GET['loginfield'] == 'uid') {
$_GET['username'] = addslashes($_GET['username']);
$uid = $_GET['username'];
$sql = "SELECT username FROM ".$t->dbconfig['tablepre']."common_member WHERE `uid`='".$_GET['username']."'";
$username = mysqli_result(mysqli_query($t->db, $sql), 0);
}

if($uid && $username) {
$sql = "UPDATE ".$t->dbconfig['tablepre']."common_member SET `groupid`='1', `adminid`='1' WHERE `uid`='$uid'";
@mysqli_query($t->db, $sql);
if(!in_array($uid,$founders)) {
$sql = "REPLACE INTO ".$t->dbconfig['tablepre']. "common_admincp_member (`uid`, `cpgroupid`, `customperm`) VALUES ('$uid', '0', '')";
@mysqli_query($t->db, $sql);
}
} else {
show_msg('没有这个用户', 'tools.php?action='.$action, 2000);
}

$t->connect_db('ucdb');
if($_GET['password'] != NULL) {
$sql = "SELECT salt FROM ".$t->ucdbconfig['tablepre']."members WHERE `uid`='$uid'";
$salt = mysqli_result(mysqli_query($t->db, $sql), 0);
$newpassword = md5(md5(trim($_GET['password'])).$salt);
$sql = "UPDATE ".$t->ucdbconfig['tablepre']."members SET `password`='$newpassword' WHERE `uid`='$uid'";
mysqli_query($t->db, $sql);
}
if($_GET['issecques'] == 1) {
$sql = "UPDATE ".$t->ucdbconfig['tablepre']."members SET `secques`='' WHERE `uid`='$uid'";
mysqli_query($t->db, $sql);
}
$t->close_db();
show_msg('管理员找回成功!', 'tools.php?action='.$action, 2000);

} else {
show_header();
echo "<p>现有创始人:$foundernames</p>";
echo "<p>现有管理员:$adminnames</p>";
print<<<END
<form action="?action={$action}" method="post">
<h5>{$info}</h5>
<table id="setadmin">
<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>
<tr><th width="30%">请输入密码</th><td width="70%"><input class="textinput" type="text" name="password" size="25"></td></tr>
<tr><th width="30%">是否清除安全提问</th><td width="70%">
<input class="radio" type="radio" name="issecques" value="1">是&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input class="radio" type="radio" name="issecques" value="0" class="radio" checked>否</td></tr>
</table>
<input type="submit" name="setadminsubmit" value="提 &nbsp; 交">
</form>
END;
print<<<END
<br/>
恢复步骤:
重置管理员<br/>
<ul>
<li>选择用户名或者UID。</li>
<li>输入用户名或者UID。</li>
<li>如果需要重置密码,输入密码。</li>
<li>如果需要清除安全提问,请在是否清除安全提问处选择是。</li>
</ul>
<br/>
重置创始人<br/>
<ul>
<li>重置用户为创始人。</li>
<li>修改config_global.php 中 \$_config[\'admincp\'][\'founder\'] = \'管理员的ID\',多个以半角逗号分割。</li>
</ul>
END;
show_footer();
}

}elseif($action == 'closesite') {
//一键开关站点
$t->connect_db();
$sql = "SELECT svalue FROM ".$t->dbconfig['tablepre']."common_setting WHERE skey='bbclosed'";
$bbclosed = mysqli_result(mysqli_query($t->db, $sql), 0);

if(empty($bbclosed)) {
$closed = '';
$opened = 'checked';
} else {
$closed = 'checked';
$opened = '';
}
$sql = "SELECT svalue FROM ".$t->dbconfig['tablepre']."common_setting WHERE `skey`='closedreason'";
$closedreason = mysqli_result(mysqli_query($t->db, $sql), 0);
if(!empty($_GET['closesitesubmit'])) {
if($_GET['close'] == 1) {
$sql = "UPDATE ".$t->dbconfig['tablepre']."common_setting SET `svalue`='1' WHERE `skey`='bbclosed'";
mysqli_query($t->db, $sql);
$sql = "UPDATE ".$t->dbconfig['tablepre']."common_setting SET `svalue`='tools.php closed' WHERE `skey`='closedreason'";
mysqli_query($t->db, $sql);
} else {
$sql = "UPDATE ".$t->dbconfig['tablepre']."common_setting SET `svalue`='0' WHERE `skey`='bbclosed'";
mysqli_query($t->db, $sql);
$sql = "UPDATE ".$t->dbconfig['tablepre']."common_setting SET `svalue`='' WHERE `skey`='closedreason'";
mysqli_query($t->db, $sql);
}
show_msg('关闭/打开站点操作成功,正在更新缓存...', 'tools.php?action=updatecache',2000);
} else {
show_header();
print<<<END
<h4>关闭/打开站点</h4>
此处可以进行站点“关闭/打开”的操作。
<p>
<form action="?action=closesite" method="post">
站点当前状态
<input class="radio" type="radio" name="close" value="0" {$opened} class="radio">打开
<input class="radio" type="radio" name="close" value="1" {$closed} class="radio">关闭
</p>
<p>
<input type="submit" name="closesitesubmit" value="提 &nbsp; 交">
</p>
</form>
END;
show_footer();
}

}elseif($action == 'closeplugin') {
//一键关闭插件
include_once(TDISCUZ_ROOT.'source/class/class_core.php');
include_once(TDISCUZ_ROOT.'source/function/function_core.php');

$cachelist = array();
$discuz = & discuz_core::instance();
$discuz->cachelist = $cachelist;
$discuz->init_cron = false;
$discuz->init_setting = false;
$discuz->init_user = false;
$discuz->init_session = false;
$discuz->init_misc = false;

$discuz->init();
require_once libfile('function/plugin');
require_once libfile('function/cache');
DB::query("UPDATE ".DB::table('common_plugin')." SET available='0'");
updatecache(array('plugin', 'setting', 'styles'));
cleartemplatecache();
show_msg('成功关闭所有插件', 'tools.php?action=index',2000);

}elseif($action == 'repairdb') {
//修复数据库
show_header();
$t->connect_db();
$typearray = array('index', 'repair', 'repairtables', 'allrepair', 'check', 'detail');
$type = in_array($_GET['type'], $typearray) ? $_GET['type'] : 'index';

if($type == 'index') {
print<<<END
<div class=\"bm\">
<table id="menu">
<tr>
<!--<td><a href="?action=repairdb&type=allcheck">一键检查</a></td>--!>
<td><a href="?action=repairdb&type=allrepair">一键修复</a></td>
<td><a href="?action=repairdb&type=detail">进入详细页面检查或修复</a></td>
</tr>
</table>
说明 & 提示:
<ul>
<!--<li>一键检查: 对数据库中所有表进行 CHECK TABLE 操作,列出损坏的数据表。</li>--!>
<li>一键修复: 先执行 CHECK TABLE 操作,然后按照检查的结果对有错误的数据表执行REPAIR TABLE 操作。</li>
<li>进入详细页面检查或修复: 列出详细表,对单表进行检查或修复。</li>
<li><span style="color:red">提示1:数据表比较大的情况下,mysql可能会花费比较长的时间进行检查和修复操作。</span></li>
<li><span style="color:red">提示2:REPAIR TABLE 操作不能修复所有情况,如果修复不了数据表,请登录服务器使用myisamchk进行数据表修复。</span></li>
</ul>
</div>
END;
} elseif ($type == 'allrepair' || $type == 'allcheck' || $type == 'detail' || $type == 'check' || $type == 'repair' || $type == 'repairtables') {
$sql = "SHOW TABLE STATUS";
$tablelist = mysqli_query($t->db, $sql);
while($list = mysqli_fetch_array($tablelist, MYSQLI_ASSOC)) {
if($type == 'allcheck' || $type == 'allrepair') {
if($list['Engine'] != 'MEMORY' && $list['Engine'] != 'HEAP') {
$sql = 'CHECK TABLE '.$list['Name'];
$query = mysqli_query($t->db, $sql);
$checkresult = mysqli_fetch_array($query, MYSQLI_ASSOC);

if( $checkresult['Msg_text'] != 'OK') {
$tablelists[$list['Name']]['statu'] = $checkresult['Msg_text'];
$tablelists[$list['Name']]['size'] = round(($list['Data_length'] + $list['Index_length'])/1024,2);
}
}
} else {
$tablelists[$list['Name']]['size'] = round(($list['Data_length'] + $list['Index_length'])/1024,2);
}
}
if($type == 'allrepair') {
foreach($tablelists as $table => $value) {
$sql = "REPAIR TABLE `".$table."`";
$query = mysqli_query($t->db, $sql);
$repairresult = mysqli_fetch_array($query, MYSQLI_ASSOC);
$resulttable[$table]['statu'] = $repairresult['Msg_text'];
$resulttable[$table]['size'] = '未检查';
}
$tablelists = $resulttable;
}

if($type == 'check') {
$_GET['table'] = addslashes($_GET['table']);
$sql = 'CHECK TABLE '.$_GET['table'];
$query = mysqli_query($t->db, $sql);
$checkresult = mysqli_fetch_array($query, MYSQLI_ASSOC);
$tablelists[$_GET['table']]['statu'] = $checkresult['Msg_text'];
}
if($type == 'repair') {
$_GET['table'] = addslashes($_GET['table']);
$sql = "REPAIR TABLE `".$_GET['table']."`";
$query = mysqli_query($t->db, $sql);
$repairresult = mysqli_fetch_array($query, MYSQLI_ASSOC);
echo '<div style="background:red">';
show_msg_body('修复表单 '.$_GET['table'].' 结果:'.$repairresult['Msg_text'], "tools.php?action=$action&type=detail", 3000);
echo '</div>';
}
if($type == 'repairtables') {
if($_POST['optimizesubmit']){
$repairtables = addslashes($_POST['repairtables']);
foreach ($repairtables as $value) {
$sql = "REPAIR TABLE `".$value."`";
$query = mysqli_query($t->db, $sql);
$repairresult = mysqli_fetch_array($query, MYSQLI_ASSOC);
echo '<div style="background:red">';
show_msg_body('修复表单 '.$value.' 结果:'.$repairresult['Msg_text'], '', 3000);
echo '</div>';
}
echo '<div style="background:red">';
show_msg_body('复选修复表单完成', "tools.php?action=$action&type=detail", 3000);
echo '</div>';
}
}
echo '
<script type="text/javascript">
var BROWSER = {};
var USERAGENT = navigator.userAgent.toLowerCase();
browserVersion({\'ie\':\'msie\',\'firefox\':\'\',\'chrome\':\'\',\'opera\':\'\',\'safari\':\'\',\'mozilla\':\'\',\'webkit\':\'\',\'maxthon\':\'\',\'qq\':\'qqbrowser\'});
function browserVersion(types) {
var other = 1;
for(i in types) {
var v = types[i] ? types[i] : i;
if(USERAGENT.indexOf(v) != -1) {
var re = new RegExp(v + \'(\\/|\\s)([\\d\\.]+)\', \'ig\');
var matches = re.exec(USERAGENT);
var ver = matches != null ? matches[2] : 0;
other = ver !== 0 && v != \'mozilla\' ? 0 : other;
} else {
var ver = 0;
}
eval(\'BROWSER.\' + i + \'= ver\');
}
BROWSER.other = other;
}
function jumpurl(url,nw) {
if(BROWSER.ie) url += (url.indexOf(\'?\') != -1 ? \'&\' : \'?\') + \'referer=\' + escape(location.href);
if(nw == 1) {
window.open(url);
} else {
location.href = url;
}
return false;
}
</script>';
echo '
<script type="text/javascript">
function checkAll(type, form, value, checkall, changestyle) {
var checkall = checkall ? checkall : \'chkall\';
for(var i = 0; i < form.elements.length; i++) {
var e = form.elements[i];
if(type == \'option\' && e.type == \'radio\' && e.value == value && e.disabled != true) {
e.checked = true;
} else if(type == \'value\' && e.type == \'checkbox\' && e.getAttribute(\'chkvalue\') == value) {
e.checked = form.elements[checkall].checked;
if(changestyle) {
multiupdate(e);
}
} else if(type == \'prefix\' && e.name && e.name != checkall && (!value || (value && e.name.match(value)))) {
e.checked = form.elements[checkall].checked;
if(changestyle) {
if(e.parentNode && e.parentNode.tagName.toLowerCase() == \'li\') {
e.parentNode.className = e.checked ? \'checked\' : \'\';
}
if(e.parentNode.parentNode && e.parentNode.parentNode.tagName.toLowerCase() == \'div\') {
e.parentNode.parentNode.className = e.checked ? \'item checked\' : \'item\';
}
}
}
}
}
</script>';
print<<<END
<div class=\"bm\">
<table class=\"tb\">
<tbody>
<form name="cpform" method="post" autocomplete="on" action="tools.php?action=repairdb&type=repairtables" id="cpform">
<tr>
<th></th>
<th width="350px">表名</th>
<th width="80px">大小</th>
<th></th>
<th width="80px"></th>
</tr>
END;
foreach($tablelists as $name => $value) {
if($value['size'] < 1024) {
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>';
} elseif(1024 < $value['size'] && $value['size']< 1048576 ) {
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>';
} elseif(1048576 < $value['size']){
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>';
}

if(!isset($value['statu'])) {
echo "<button type=\"button\" class=\"pn vm\" onclick=\"jumpurl('tools.php?action=repairdb&type=check&table=".$name."')\"><strong>检查</button>";
} elseif($value['statu']!='OK') {
echo '<span class=\"red\">'.$value['statu'].'</span>';
} else {
echo $value['statu'];
}

echo '</td><td>';
if($value['statu']!='OK' && $value['statu']!='Not Support CHECK') {
echo "<button type=\"button\" class=\"pn vm\" onclick=\"jumpurl('tools.php?action=repairdb&type=repair&table=".$name."')\"><strong>修复</button></strong>";
}
echo '</td></tr>';
}

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>";
echo '</tbody></table></div>';
if( count($tablelists) == 0) {
echo '<div style="background:#00cc66;">没有需要修复的表</div>';
}
} elseif ($type == 'allrepair') {
show_msg("操作成功", "tools.php?action=$action");
}
show_footer();

}elseif($action == 'restoredb') {
//恢复数据
$backfiledir = TDISCUZ_ROOT.'data/';
$detailarray = array();
$t->connect_db();

if(!mysqli_select_db($t->dbconfig['name'], $t->db)) {
$dbname = $t->dbconfig['name'];
mysqli_query($t->db, "CREATE DATABASE $dbname");
}

if(!$_GET['importbak'] && !$_GET['nextfile']) {
//检测是否关闭站点
$sql = "SELECT svalue FROM ".$t->dbconfig['tablepre']."common_setting WHERE skey='bbclosed'";
$closed = mysqli_result(mysqli_query($t->db, $sql), 0);
if($closed != '1') {
show_msg('恢复数据前,请先关闭站点!', 'tools.php?action=closesite', 3000);
}
$exportlog = array();
$dir = dir($backfiledir);
while($entry = $dir->read()) {
$entry = $backfiledir."/$entry";
$num = 0;
if(is_dir($entry) && preg_match("/backup\_/i", $entry)) {
$bakdir = dir($entry);
while($bakentry = $bakdir->read()) {
$bakentry = "$entry/$bakentry";
if(is_file($bakentry) && preg_match("/(.*)\-(\d)\.sql/i", $bakentry,$match)) {
if($_GET['detail']) {
$detailarray[] = $match['1'];
}
$num++;
}
if(is_file($bakentry) && preg_match("/\-1\.sql/i", $bakentry)) {
$fp = fopen($bakentry, 'rb');
$bakidentify = explode(',', base64_decode(preg_replace("/^# Identify:\s*(\w+).*/s", "\\1", fgets($fp, 256))));
fclose ($fp);

if(preg_match("/\-1\.sql/i", $bakentry) || $bakidentify[3] == 'shell') {
$identify['bakentry'] = $bakentry;
}
}
}
$detailarray = array_reverse(array_unique($detailarray));

if($num != 0) {
$exportlog[$entry] = array(
'dateline' => date('Y-m-d H:i:s',$bakidentify[0]),
'version' => $bakidentify[1],
'type' => $bakidentify[2],
'method' => $bakidentify[3],
'volume' => $num,
'bakentry' => $identify['bakentry'],
'filename' => str_replace($backfiledir.'/','',$entry));
}
}
}
}else{
$bakfile = $_GET['nextfile'] ? $_GET['nextfile'] : $_GET['importbak'];
if(!file_exists($bakfile)) {
if($_GET['nextfile']) {
$tpl = dir(TDISCUZ_ROOT.'data/template');
while($entry = $tpl->read()) {
if(preg_match("/\.tpl\.php$/", $entry)) {
@unlink(TDISCUZ_ROOT.'data/template/'.$entry);
}
}
$tpl->close();
show_msg('恢复备份成功,请查看论坛,如果数据不同步,请检查数据库前缀。正在更新缓存...', 'tools.php?action=updatecache',2000);
}
show_msg('备份文件不存在。');
}
if(!is_readable($bakfile)) {
show_msg('备份文件不可读取。');
} else {
@$fp = fopen($bakfile, "r");
@flock($fp, 3);
$sqldump = @fread($fp, filesize($bakfile));
@fclose($fp);
}
@$bakidentify = explode(',', base64_decode(preg_replace("/^# Identify:\s*(\w+).*/s", "\\1", substr($sqldump, 0, 256))));
if(!defined('IN_DISCUZ')) {
define('IN_DISCUZ', TRUE);
}
include_once(TDISCUZ_ROOT.'source/discuz_version.php');
if($bakidentify[1] != DISCUZ_VERSION) {
show_msg('备份文件版本错误,不能恢复。');
}
$vol = $bakidentify[4];

$nextfile = taddslashes(str_replace("-$vol.sql","-".($vol+1).'.sql',$bakfile));
$result = $t->db_runquery($sqldump);
if($result) {
show_msg('正在恢复分卷:'.$vol,"tools.php?action=$action&nextfile=$nextfile", 2000);
}
}
$t->close_db();
show_header();
print<<<END
<div class="bm">
<form action="tools.php?action={$action}" method="post">
<table class="tdat"><tbody>
<tr class=\'alt h\'><th>备份项目</th><th>版本</th><th>时间</th><th>类型</th><th>文件总数</th><th>导入</th></tr>
END;
foreach( $exportlog as $value) {
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>';
}
if (count($detailarray)>0) {
foreach($detailarray as $value) {
echo '<tr><td colspan="5">'.$value.'</td><td><a href="tools.php?action='.$action.'&importbak='.$value.'-1.sql"><font color="blue">导入</font></a></td></tr>';
}
}
echo '</tbody></table></form></div>';
show_footer();

}elseif($action == 'updatecache') {
//更新缓存
include_once(TDISCUZ_ROOT.'source/class/class_core.php');
include_once(TDISCUZ_ROOT.'source/function/function_core.php');

$cachelist = array();
$discuz = & discuz_core::instance();
$discuz->cachelist = $cachelist;
$discuz->init_cron = false;
$discuz->init_setting = false;
$discuz->init_user = false;
$discuz->init_session = false;
$discuz->init_misc = false;

$discuz->init();

require_once libfile('function/cache');
updatecache();
include_once libfile('function/block');
blockclass_cache();
//note 清除群组缓存
require_once libfile('function/group');
$groupindex['randgroupdata'] = $randgroupdata = grouplist('lastupdate', array('ff.membernum', 'ff.icon'), 80);
$groupindex['topgrouplist'] = $topgrouplist = grouplist('activity', array('f.commoncredits', 'ff.membernum', 'ff.icon'), 10);
$groupindex['updateline'] = TIMESTAMP;
$groupdata = DB::fetch_first("SELECT SUM(todayposts) AS todayposts, COUNT(fid) AS groupnum FROM ".DB::table('forum_forum')." WHERE status='3' AND type='sub'");
$groupindex['todayposts'] = $groupdata['todayposts'];
$groupindex['groupnum'] = $groupdata['groupnum'];
save_syscache('groupindex', $groupindex);
DB::query("TRUNCATE ".DB::table('forum_groupfield'));

$tpl = dir(DISCUZ_ROOT.'./data/template');
while($entry = $tpl->read()) {
if(preg_match("/\.tpl\.php$/", $entry)) {
@unlink(DISCUZ_ROOT.'./data/template/'.$entry);
}
}
$tpl->close();
show_msg('更新数据缓存模板缓存成功!', 'tools.php?action=index', 2000);

}elseif($action == 'logout') {
//登出
tsetcookie('toolsauth', '', -1, '', false, '', '');
@header('Location: tools.php');

}else{

}
//大的分支 结束

/**********************************************************************************
*
* tools.php 通用函数部分
*
*
**********************************************************************************/

/*
checkpassword 函数
判断密码强度,大小写字母加数字,长度大于6位。
return flase 或者 errormsg
*/
function checkpassword($password){
$errormsg = array(
0 => '您设置的密码只能使用数字和大小写字母组成,请修改!',
1 => 'tools.php密码少于6位,请重新修改tools.php中密码。',
2 => '密码中必须含有数字,请重新修改tools.php中密码。',
3 => '密码中必须含有字母,请重新修改tools.php中密码。',
4 => '密码中必须含有大写字母,请重新修改tools.php中密码。',
5 => '密码中必须含有小写字母,请重新修改tools.php中密码。',
6 => '没有设置密码,请使用FTP或者直接编辑论坛根目录下的 tools.php 文件,并根据文件中的说明设置密码',
7 => '不能使用密码示范中的的 DiscuzX3 为密码',
);
if(empty($password))
return $errormsg[6];
if(!ctype_alnum($password))
return $errormsg[0];
if(strlen($password) < 6)
return $errormsg[1];
if($password === 'DiscuzX3'){
return $errormsg[7];
}
$pw_array = str_split($password);

$is_upper = false;
$is_lower = false;
$is_char = false;
$is_digit = false;
foreach( $pw_array as $a) {
if(ctype_digit($a)) {
$is_digit = true;
} else {
$is_char = true;
if(ctype_lower($a))
$is_lower = true;
if(ctype_upper($a))
$is_upper = true;
}
}

if(!$is_digit)
return $errormsg[2];

if(!$is_char)
return $errormsg[3];

if(!$is_upper)
return $errormsg[4];

if(!$is_lower)
return $errormsg[5];
return false;
}

//去掉slassh
function tstripslashes($string) {
if(empty($string)) return $string;
if(is_array($string)) {
foreach($string as $key => $val) {
$string[$key] = tstripslashes($val);
}
} else {
$string = stripslashes($string);
}
return $string;
}

function thash() {
return substr(md5(substr(time(), 0, -4).TDISCUZ_ROOT), 16);
}

function taddslashes($string, $force = 1) {
if(is_array($string)) {
foreach($string as $key => $val) {
$string[$key] = taddslashes($val, $force);
}
} else {
$string = addslashes($string);
}
return $string;
}

//显示
function show_msg($message, $url_forward='', $time = 1, $noexit = 0) {
show_header();
show_msg_body($message, $url_forward, $time, $noexit);
show_footer();
!$noexit && exit();
}

function show_msg_body($message, $url_forward='', $time = 1, $noexit = 0) {
if($url_forward) {
$url_forward = $_GET['from'] ? $url_forward.'&from='.rawurlencode($_GET['from']) : $url_forward;
$message = "<a href=\"$url_forward\">$message (跳转中...)</a><script>setTimeout(\"window.location.href ='$url_forward';\", $time);</script>";
}else{
$message = "<a href=\"$url_forward\">$message </a>";
}
print<<<END
<table>
<tr><td>$message</td></tr>
</table>
END;
}

function login_page() {
show_header();
$formhash = thash();
print<<<END
<span>急诊箱登录</span>
<form action="tools.php?action=login" method="post">
<table class="specialtable">
<tr>
<td width="20%"><input class="textinput" type="password" name="toolpassword"></input></td>
<td><input class="specialsubmit" type="submit" value="登 录"></input></td>
</tr>
</table>
<input type="hidden" name="action" value="login">
<input type="hidden" name="formhash" value="{$formhash}">
</form>
END;
show_footer();
}

function show_header() {
$_GET['action'] = htmlspecialchars($_GET['action']);
$nowarr = array($_GET['action'] => ' class="current"');
print<<<END
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf8" />
<title>Discuz! X3 急诊箱</title>
<style type="text/css">
* {font-size:12px; font-family: Verdana, Arial, Helvetica, sans-serif; line-height: 1.5em; word-break: break-all; }
body { text-align:center; margin: 0; padding: 0; background: #F5FBFF; }
.bodydiv { margin: 40px auto 0; width:820px; text-align:left; border: solid #86B9D6; border-width: 5px 1px 1px; background: #FFF; }
h1 { font-size: 18px; margin: 1px 0 0; line-height: 50px; height: 50px; background: #E8F7FC; color: #5086A5; padding-left: 10px; }
#menu {width: 100%; margin: 10px auto; text-align: center; }
#menu td { height: 30px; line-height: 30px; color: #999; border-bottom: 3px solid #EEE; }
.current { font-weight: bold; color: #090 !important; border-bottom-color: #F90 !important; }
input { border: 1px solid #B2C9D3; padding: 5px; background: #F5FCFF; }
#footer { font-size: 10px; line-height: 40px; background: #E8F7FC; text-align: center; height: 38px; overflow: hidden; color: #5086A5; margin-top: 20px; }
table {width:100%;font-size:12px;margin-top:5px;}
table.specialtable,table.specialtable td {border:0;}
td,th {padding:5px;text-align:left;}
caption {font-weight:bold;padding:8px 0;color:#3544FF;text-align:left;}
th {background:#E8F7FC;font-weight:600;}
td.specialtd {text-align:left;}
#setadmin {margin: 0px;}
.textarea {height: 80px;width: 400px;padding: 3px;margin: 5px;}
</style>
</head>
<body>
<div class="bodydiv">
<h1>Discuz! X3 急诊箱</h1><br/>
<div style="width:90%;margin:0 auto;">
<table id="menu">
<tr>
<td{$nowarr['index']}><a href="?action=index">首页</a></td>
<td{$nowarr['setadmin']}><a href="?action=setadmin">重置管理员帐号</a></td>
<td{$nowarr['closesite']}><a href="?action=closesite">开启关闭站点</a></td>
<td{$nowarr['closeplugin']}><a href="?action=closeplugin">一键关闭插件</a></td>
<td{$nowarr['repairdb']}><a href="?action=repairdb">修复数据库</a></td>
<td{$nowarr['restoredb']}><a href="?action=restoredb">恢复数据库</a></td>
<td{$nowarr['updatecache']}><a href="?action=updatecache">更新缓存</a></td>
<td{$nowarr['logout']}><a href="?action=logout">退出</a></td>
</tr>
</table>
<br>
END;
}

//页面顶部
function show_footer() {
global $tools_versions;
print<<<END
</div>
<div id="footer">Powered by {$tools_versions} &copy; Comsenz Inc. 2001-2013 <a href="http://www.comsenz.com" target="_blank">http://www.comsenz.com</a></div>
</div>
<br>
</body>
</html>
END;
}

//登录判断函数
function is_login() {
$error = false;
$errormsg = array();
global $tpassword;

if($errormsg = checkpassword($tpassword)) {
show_msg($errormsg);
}

if(isset($_COOKIE['toolsauth'])) {
if($_COOKIE['toolsauth'] === md5($tpassword.thash())) {
return TRUE;
}
}

$lockfile = TDISCUZ_ROOT.'data/tools.lock';
if(@file_exists($lockfile)) {
$errormsg = "急救箱已经锁定,请您先登录服务器ftp,手工删除 ./data/tools.lock 文件,再次重新使用急救箱。";
show_msg($errormsg);
}

if ( $_GET['action'] === 'login') {
$formhash = $_GET['formhash'];
if($formhash !== thash()) {
show_msg('您的请求来路不正或者输入密码超时,请刷新页面后重新输入正确密码!');
}
$toolsmd5 = md5($tpassword.thash());
if(md5($_GET['toolpassword'].thash()) == $toolsmd5) {
tsetcookie('toolsauth', $toolsmd5, time()+'3600', '', false, '','');
$lockfile = TDISCUZ_ROOT.'data/tools.lock';
if(@$fp = fopen($lockfile, 'w')) {
fwrite($fp, ' ');
fclose($fp);
}
show_msg('登陆成功!', 'tools.php?action=index', 2000);
} else {
show_msg( '您输入的密码不正确,请重新输入正确密码!', 'tools.php', 2000);
}
} else {
return FALSE;
}
}

//登录成功设置cookie
function tsetcookie($var, $value = '', $life = 0, $prefix = '', $httponly = false, $cookiepath, $cookiedomain) {
$var = (empty($prefix) ? '' : $prefix).$var;
$_COOKIE[$var] = $value;

if($value == '' || $life < 0) {
$value = '';
$life = -1;
}
$path = $httponly && PHP_VERSION < '5.2.0' ? $cookiepath.'; HttpOnly' : $cookiepath;
$secure = $_SERVER['SERVER_PORT'] == 443 ? 1 : 0;

if(PHP_VERSION < '5.2.0') {
$r = setcookie($var, $value, $life);
} else {
$r = setcookie($var, $value, $life);
}
}

/*
T 类
tools.php 主要类
*/
class T{
var $dbconfig = null;
var $ucdbconfig = null;
var $db = null;
var $ucdb = null;
// 是否已经初始化
var $initated = false;

public function init() {
if(!$this->initated) {
$this->_init_config();
$this->_init_db();
}
$this->initated = true;
}

public function db_runquery($sql) {
$tablepre = $this->dbconfig['tablepre'];
$dbcharset = $this->dbconfig['charset'];

if(!isset($sql) || empty($sql)) return;

$sql = str_replace("\r", "\n", str_replace(array(' {tablepre}', ' cdb_', ' `cdb_', ' pre_', ' `pre_'), array(' '.$tablepre, ' '.$tablepre, ' `'.$tablepre, ' '.$tablepre, ' `'.$tablepre), $sql));

$ret = array();
$num = 0;
foreach(explode(";\n", trim($sql)) as $query) {
$ret[$num] = '';
$queries = explode("\n", trim($query));
foreach($queries as $query) {
$ret[$num] .= (isset($query[0]) && $query[0] == '#') || (isset($query[1]) && isset($query[1]) && $query[0].$query[1] == '--') ? '' : $query;
}
$num++;
}
unset($sql);
$this->connect_db();
foreach($ret as $query) {
$query = trim($query);
if($query) {
if(substr($query, 0, 12) == 'CREATE TABLE') {
$name = preg_replace("/CREATE TABLE ([a-z0-9_]+) .*/is", "\\1", $query);
mysqli_query($this->db, $this->db_createtable($query, $dbcharset));
} else {
mysqli_query($this->db, $query);
}
}
}
return 1;
}

public function db_createtable($sql, $dbcharset) {
$type = strtoupper(preg_replace("/^\s*CREATE TABLE\s+.+\s+\(.+?\).*(ENGINE|TYPE)\s*=\s*([a-z]+?).*$/isU", "\\2", $sql));
$type = in_array($type, array('MYISAM', 'HEAP')) ? $type : 'MYISAM';
return preg_replace("/^\s*(CREATE TABLE\s+.+\s+\(.+?\)).*$/isU", "\\1", $sql).(mysqli_get_server_info($this->db) > '4.1' ? " ENGINE=$type DEFAULT CHARSET=$dbcharset" : " TYPE=$type");
}

public function connect_db($type = 'db') {
if($type == 'db') {
$dbhost = $this->dbconfig['host'];
$dbuser = $this->dbconfig['user'];
$dbpw = $this->dbconfig['pw'];
$dbname = $this->dbconfig['name'];
$dbcharset = $this->dbconfig['charset'];
} else {
$dbhost = $this->ucdbconfig['host'];
$dbuser = $this->ucdbconfig['user'];
$dbpw = $this->ucdbconfig['pw'];
$dbname = $this->ucdbconfig['name'];
$dbcharset = $this->ucdbconfig['charset'];
}
if(!$this->db = mysqli_connect($dbhost, $dbuser, $dbpw, $dbname))
show_msg('Discuz! X数据库连接出错,请检查config_global.php中数据库相关信息是否正确,与数据库服务器网络连接是否正常');
$dbversion = mysqli_get_server_info($this->db);
if($dbversion > '4.1') {
if($dbcharset) {
mysqli_query($this->db, "SET character_set_connection=".$dbcharset.", character_set_results=".$dbcharset.", character_set_client=binary");
}
if($dbversion > '5.0.1') {
mysqli_query($this->db, "SET sql_mode=''");
}
}
@mysqli_select_db($dbname, $this->db);
}

public function close_db() {
mysqli_close($this->db);
}

private function _init_config() {
$error = false;
$_config = array();

global $tpassword;
if($errormsg = checkpassword($tpassword)) {
$error = true;
}

@include TOOLS_ROOT.'config/config_global.php';
if(empty($_config)) {
$error = true;
$errormsg = '没有找到config文件,请检查 /config/config_global.php 是否存在或有读权限!';
}

$uc_config_file = TOOLS_ROOT.'config/config_ucenter.php';
// debug($uc_config_file);
if(!@file_exists($uc_config_file)) {
$error = true;
$errormsg = '没有找到uc config文件,请检查 /config/config_ucenter.php 是否存在或有读权限!';
}
@include $uc_config_file;

if($error) {
show_msg($errormsg);
}

$this->config = & $_config;
$this->config['dbcharset'] = $_config['db']['1']['dbcharset'];
$this->config['charset'] = $_config['output']['charset'];
}

private function _init_db() {
$this->dbconfig['host'] = $this->config['db']['1']['dbhost'];
$this->dbconfig['user'] = $this->config['db']['1']['dbuser'];
$this->dbconfig['pw'] = $this->config['db']['1']['dbpw'];
$this->dbconfig['name'] = $this->config['db']['1']['dbname'];
$this->dbconfig['charset'] = $this->config['db']['1']['dbcharset'];
$this->dbconfig['tablepre'] = $this->config['db']['1']['tablepre'];

$this->ucdbconfig['host'] = UC_DBHOST;
$this->ucdbconfig['user'] = UC_DBUSER;
$this->ucdbconfig['pw'] = UC_DBPW;
$this->ucdbconfig['name'] = UC_DBNAME;
$this->ucdbconfig['charset'] = UC_DBCHARSET;
$this->ucdbconfig['tablepre'] = UC_DBTABLEPRE;

$this->connect_db();
$sql = "SHOW FULL PROCESSLIST";
$query = mysqli_query($this->db, $sql);
$waiting = false;
$waiting_msg = '';
while($l = mysqli_fetch_array($query, MYSQLI_ASSOC)) {
if($l['State'] == 'Checking table') {
$this->close_db();
$waiting = true;
$waiting_msg = '正在检查表,请稍后...';
} elseif($l['State'] == 'Repair by sorting') {
$this->close_db();
$waiting = true;
$waiting_msg = '正在修复表,请稍后...';
}
}
if($waiting) {
show_msg($waiting_msg, 'tools.php?action=repairdb', 3000);
}
}
}


/**
* 自定义mysqli_result()替代mysql_result()
*/
function mysqli_result($res,$n){
$arr = mysqli_fetch_array($res);
return $arr[$n];
}
//T class 结束
/**
* End of the tools.php
*/

uctools.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
<?php
/*
[Discuz!] Tools (C)2001-2008 Comsenz Inc.
This is NOT a freeware, use is subject to license terms

$Id: uctools.php 1193 2010-01-20 09:35:41Z songlixin $
*/
/**
* 修复者: 天外飘仙
* 插件定制,discuz技术支持,云服务器购买 联系QQ 860855665
* 主页:https://addon.dismall.com/developer-99821.html
*/
/********************** 密码配置区 开始*******************************/
$tool_password = '11111'; // ☆★☆★☆★ 请您设置一个工具包的高强度密码,不能为空!☆★☆★☆★
/********************** 密码配置区 结束*******************************/
error_reporting(E_ERROR | E_PARSE); //E_ERROR | E_WARNING | E_PARSE | E_ALL
@set_time_limit(0);
define('TOOLS_ROOT', dirname(__FILE__)."/");
define('VERSION', '2009');
define('Release','100120');
$functionall = array(
array('all', 'all_repair', '检查或修复数据库', '对所有数据表进行检查修复工作。'),
array('all', 'all_runquery', '快速设置(SQL)', '可以运行任意SQL语句,请慎用。'),
array('all', 'all_restore', '恢复数据库备份', '恢复论坛数据备份。'),
array('all', 'all_setadmin', '重置创始人密码', '重置 UCenter 的创始人密码'),
);
$toolbar = array(
array('phpinfo','INFO'),
array('datago','转码'),
array('all_logout','退出'),
);
//初始化
$plustitle = '';
$lockfile = '';
//临时文件放置的目录,getplace()函数中设置
$docdir = '';
$action = '';
$target_fsockopen = '0';
$alertmsg = ' onclick="alert(\'点击确定开始运行,可能需要一段时间,请稍候\');"';
foreach(array('_COOKIE', '_POST', '_GET') as $_request) {
foreach($$_request as $_key => $_value) {
($_key{0} != '_' && $_key != 'tool_password' && $_key != 'lockfile') && $$_key = taddslashes($_value);
}
}
$whereis = getplace();

require_once $cfgfile;

if($whereis && !in_array($whereis, array('is_uc'))) {
$alertmsg = '';
errorpage('<ul><li>工具箱(UCenter专用版)必须放在 UCenter 的根目录下才能正常使用。</li><li>如果你确实放在了上述程序目录下,请检查上述程序运配置文件(config)的可读写权限是否正确</li>');
}
if(@file_exists($lockfile)) {
$alertmsg = '';
errorpage("<h6>工具箱(UCenter专用版)已关闭,如需开启只要通过 FTP 删除 $lockfile 文件即可! </h6>");
} elseif($tool_password == '') {
$alertmsg = '';
errorpage('<h6>工具箱(UCenter专用版)密码默认为空,第一次使用前请您修改本文件中$tool_password设置密码!</h6>');
}
if($action == 'login') {
setcookie('toolpassword',md5($toolpassword), 0);
echo '<meta http-equiv="refresh" content="2 url=?">';
errorpage("<h6>请稍等,程序登录中!</h6>");
}
if(isset($toolpassword)) {
if($toolpassword != md5($tool_password)) {
$alertmsg = '';
errorpage("login");
}
} else {
$alertmsg = '';
errorpage("login");
}
getdbcfg();
$mysql = mysqli_connect($dbhost, $dbuser, $dbpw,$dbname);
// mysql_select_db($dbname);
$my_version = mysqli_get_server_info($mysql);
if($my_version > '4.1') {
$serverset = $dbcharset ? 'character_set_connection='.$dbcharset.', character_set_results='.$dbcharset.', character_set_client=binary' : '';
$serverset .= $my_version > '5.0.1' ? ((empty($serverset))? '' : ',').'sql_mode=\'\'' : '';
$serverset && mysqli_query($mysql,"SET $serverset");
}
//流程开始
if($action == 'all_repair') {
$counttables = $oktables = $errortables = $rapirtables = 0;
$doc = $docdir.'/repaireport.txt';
if($check) {
$tables = mysqli_query($mysql,"SHOW TABLES");
if($iterations) {
$iterations --;
}
while($table = mysqli_fetch_row($tables)) {
$counttables += 1;
$answer = checktable($table[0],$iterations,$doc);
}
if($simple) {
htmlheader();
echo '<h4>检查修复数据库</h4>
<h5>检查结果:</h5>
<table>
<tr><th>检查表(张)</th><th>正常表(张)</th><th>修复的表(张)</th><th>出错(个)</th></tr>
<tr><td>'.$counttables.'</td><td>'.$oktables.'</td><td>'.$rapirtables.'</td><td>'.$errortables.'</td></tr>
</table>
<p>检查结果没有错误后请返回工具箱(UCenter专用版)首页反之则继续修复</p>
<p><b><a href="uctools.php?action=all_repair">继续修复</a>&nbsp;&nbsp;&nbsp;&nbsp;<b><a href="'.$doc.'">修复报告</a>&nbsp;&nbsp;&nbsp;&nbsp;<a href="uctools.php">返回首页</a></b></p>
</td></tr></table>';
specialdiv();
}
} else {
htmlheader();
@unlink($doc);
echo "<h4>检查修复数据库</h4>
<div class='specialdiv'>
操作提示:
<ul>
<li>您可以通过下面的方式修复已经损坏的数据库。点击后请耐心等待修复结果!</li>
<li>本程序可以修复常见的数据库错误,但无法保证可以修复所有的数据库错误。(需要 MySQL 3.23+)</li>
</ul>
</div>
<h5>操作:</h5>
<ul>
<li><a href=\"?action=all_repair&check=1&simple=1\">检查并尝试修复数据库1次</a>
<li><a href=\"?action=all_repair&check=1&iterations=5&simple=1\">检查并尝试修复数据库5次</a> (因为数据库读写关系可能有时需要多修复几次才能完全修复成功)
</ul>";
specialdiv();
}
htmlfooter();
} elseif($action == 'all_restore') {//导入数据库备份
ob_implicit_flush();
$backdirarray = array( //不同的程序存放备份文件的目录是不同的
'is_dz' => 'forumdata',
'is_uc' => 'data/backup',
'is_uch' => 'data',
'is_ss' => 'data'
);
if(!get_cfg_var('register_globals')) {
@extract($HTTP_GET_VARS);
}
$sqldump = '';
htmlheader();
?><h4>数据库恢复实用工具 </h4><?php
echo "<div class=\"specialdiv\">操作提示:<ul>
<li>只能恢复存放在服务器(远程或本地)上的数据文件,如果您的数据不在服务器上,请用 FTP 上传</li>
<li>数据文件必须为 Discuz! 导出格式,并设置相应属性使 PHP 能够读取</li>
<li>请尽量选择服务器空闲时段操作,以避免超时.如程序长久(超过 10 分钟)不反应,请刷新</li></ul></div>";
if($file) {
if(!mysqli_select_db($mysql,$dbname)) {
mysqli_query($mysql,"CREATE DATABASE $dbname;");
}
if(strtolower(substr($file, 0, 7)) == "http://") {
echo "从远程数据库恢复数据 - 读取远程数据:<br><br>";
echo "从远程服务器读取文件 ... ";
$sqldump = @fread($fp, 99999999);
@fclose($fp);
if($sqldump) {
echo "成功<br><br>";
} elseif(!$multivol) {
cexit("失败<br><br><b>无法恢复数据</b>");
}
} else {
echo "<div class=\"specialtext\">从本地恢复数据 - 检查数据文件:<br><br>";
if(file_exists($file)) {
echo "数据文件 $file 存在检查 ... 成功<br><br>";
} elseif(!$multivol) {
cexit("数据文件 $file 存在检查 ... 失败<br><br><br><b>无法恢复数据</b></div>");
}
if(is_readable($file)) {
echo "数据文件 $file 可读检查 ... 成功<br><br>";
@$fp = fopen($file, "r");
@flock($fp, 3);
$sqldump = @fread($fp, filesize($file));
@fclose($fp);
echo "从本地读取数据 ... 成功<br><br>";
} elseif(!$multivol) {
cexit("数据文件 $file 可读检查 ... 失败<br><br><br><b>无法恢复数据</b></div>");
}
}
if($multivol && !$sqldump) {
cexit("分卷备份范围检查 ... 成功<br><br><b>恭喜您,数据已经全部成功恢复!安全起见,请务必删除本程序.</b></div>");
}
echo "数据文件 $file 格式检查 ... ";
if($whereis == 'is_uc') {

$identify = explode(',', base64_decode(preg_replace("/^# Identify:\s*(\w+).*/s", "\\1", substr($sqldump, 0, 256))));
$method = 'multivol';
$volume = $identify[4];
} else {
@list(,,,$method, $volume) = explode(',', base64_decode(preg_replace("/^# Identify:\s*(\w+).*/s", "\\1", preg_replace("/^(.+)/", "\\1", substr($sqldump, 0, 256)))));
}
if($method == 'multivol' && is_numeric($volume)) {
echo "成功<br><br>";
} else {
cexit("失败<br><br><b>数据非 Discuz! 分卷备份格式,无法恢复</b></div>");
}
if($onlysave == "yes") {
echo "将数据文件保存到本地服务器 ... ";
$filename = TOOLS_ROOT.'./'.$backdirarray[$whereis].strrchr($file, "/");
@$filehandle = fopen($filename, "w");
@flock($filehandle, 3);
if(@fwrite($filehandle, $sqldump)) {
@fclose($filehandle);
echo "成功<br><br>";
} else {
@fclose($filehandle);
die("失败<br><br><b>无法保存数据</b>");
}
echo "成功<br><br><b>恭喜您,数据已经成功保存到本地服务器 <a href=\"".strstr($filename, "/")."\">$filename</a>.安全起见,请务必删除本程序.</b></div>";
} else {
$sqlquery = splitsql($sqldump);
echo "拆分操作语句 ... 成功<br><br>";
unset($sqldump);

echo "正在恢复数据,请等待 ... </div>";
foreach($sqlquery as $sql) {
$dbversion = mysqli_get_server_info($mysql);
$sql = syntablestruct(trim($sql), $dbversion > '4.1', $dbcharset);
if(trim($sql)) {
@mysqli_query($mysql,$sql);
}
}
if($auto == 'off') {
$nextfile = str_replace("-$volume.sql", '-'.($volume + 1).'.sql', $file);
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>");
} else {
$nextfile = str_replace("-$volume.sql", '-'.($volume + 1).'.sql', $file);
echo "<ul><li>数据文件 <b>$volume#</b> 恢复成功,现在将自动导入其他分卷备份数据.</li><li><b>请勿关闭浏览器或中断本程序运行</b></li></ul>";
redirect("?action=all_restore&file=$nextfile&multivol=yes");
}
}
} else {
$exportlog = array();
if(is_dir(TOOLS_ROOT.'./'.$backdirarray[$whereis])) {
$dir = dir(TOOLS_ROOT.'./'.$backdirarray[$whereis]);
while($entry = $dir->read()) {
$entry = "./".$backdirarray[$whereis]."/$entry";
if(is_file($entry) && preg_match("/\.sql/i", $entry)) {
$filesize = filesize($entry);
$fp = @fopen($entry, 'rb');
@$identify = explode(',', base64_decode(preg_replace("/^# Identify:\s*(\w+).*/s", "\\1", fgets($fp, 256))));
@fclose ($fp);
if(preg_match("/\-1.sql/i", $entry) || $identify[3] == 'shell') {
$exportlog[$identify[0]] = array( 'version' => $identify[1],
'type' => $identify[2],
'method' => $identify[3],
'volume' => $identify[4],
'filename' => $entry,
'size' => $filesize);
}
} elseif(is_dir($entry) && preg_match("/backup\_/i", $entry)) {
$bakdir = dir($entry);
while($bakentry = $bakdir->read()) {
$bakentry = "$entry/$bakentry";
if(is_file($bakentry)) {
@$fp = fopen($bakentry, 'rb');
@$bakidentify = explode(',', base64_decode(preg_replace("/^# Identify:\s*(\w+).*/s", "\\1", fgets($fp, 256))));
@fclose ($fp);
if(preg_match("/\-1\.sql/i", $bakentry) || $bakidentify[3] == 'shell') {
$identify['bakentry'] = $bakentry;
}
}
}
if(preg_match("/backup\_/i", $entry)) {
$exportlog[filemtime($entry)] = array( 'version' => $bakidentify[1],
'type' => $bakidentify[2],
'method' => $bakidentify[3],
'volume' => $bakidentify[4],
'bakentry' => $identify['bakentry'],
'filename' => $entry);
}
}
}
$dir->close();
} else {
echo 'error';
}
krsort($exportlog);
reset($exportlog);

$title = '<h5><a href="?action=all_restore">【恢复数据】</a>';
if($dz_version >= 700 || $whereis == 'is_uc' || $whereis == 'is_uch' || $ss_version >= 70) {
$title .= '&nbsp;&nbsp;&nbsp;<a href="?action=all_backup&begin=1">【备份数据】</a></h5>';
} else {
$title .= '</h5>';
}
$exportinfo = $title.'<table><caption>&nbsp;&nbsp;&nbsp;数据库文件夹</caption><tr><th>备份项目</th><th>版本</th><th>时间</th><th>类型</th><th>查看</th><th>操作</th></tr>';
foreach($exportlog as $dateline => $info) {
$info['dateline'] = is_int($dateline) ? gmdate("Y-m-d H:i", $dateline + 8*3600) : '未知';
switch($info['type']) {
case 'full':
$info['type'] = '全部备份';
break;
case 'standard':
$info['type'] = '标准备份(推荐)';
break;
case 'mini':
$info['type'] = '最小备份';
break;
case 'custom':
$info['type'] = '自定义备份';
break;
}
$info['volume'] = $info['method'] == 'multivol' ? $info['volume'] : '';
$info['method'] = $info['method'] == 'multivol' ? '多卷' : 'shell';
$info['url'] = str_replace(".sql", '', str_replace("-$info[volume].sql", '', substr(strrchr($info['filename'], "/"), 1)));
$exportinfo .= "<tr>\n".
"<td>".$info['url']."</td>\n".
"<td>$info[version]</td>\n".
"<td>$info[dateline]</td>\n".
"<td>$info[type]</td>\n";
if($info['bakentry']) {
$exportinfo .= "<td><a href=\"?action=all_restore&bakdirname=".$info['url']."\">查看</a></td>\n".
"<td><a href=\"?action=all_restore&file=$info[bakentry]&importsubmit=yes\">[全部导入]</a></td>\n</tr>\n";
} else {
$exportinfo .= "<td><a href=\"?action=all_restore&filedirname=".$info['url']."\">查看</a></td>\n".
"<td><a href=\"?action=all_restore&file=$info[filename]&importsubmit=yes\">[全部导入]</a></td>\n</tr>\n";
}
}
$exportinfo .= '</table>';
echo $exportinfo;
unset($exportlog);
unset($exportinfo);
echo "<br>";
//查看目录里的备份文件列表,一级目录下
if(!empty($filedirname)) {
$exportlog = array();
if(is_dir(TOOLS_ROOT.'./'.$backdirarray[$whereis])) {
$dir = dir(TOOLS_ROOT.'./'.$backdirarray[$whereis]);
while($entry = $dir->read()) {
$entry = "./".$backdirarray[$whereis]."/$entry";
if(is_file($entry) && preg_match("/\.sql/i", $entry) && preg_match("/$filedirname/i", $entry)) {
$filesize = filesize($entry);
@$fp = fopen($entry, 'rb');
@$identify = explode(',', base64_decode(preg_replace("/^# Identify:\s*(\w+).*/s", "\\1", fgets($fp, 256))));
@fclose ($fp);

$exportlog[$identify[0]] = array( 'version' => $identify[1],
'type' => $identify[2],
'method' => $identify[3],
'volume' => $identify[4],
'filename' => $entry,
'size' => $filesize);
}
}
$dir->close();
}
krsort($exportlog);
reset($exportlog);

$exportinfo = '<table>
<caption>&nbsp;&nbsp;&nbsp;数据库文件列表</caption>
<tr>
<th>文件名</th><th>版本</th>
<th>时间</th><th>类型</thd>
<th>大小</th><td>方式</th>
<th>卷号</th><th>操作</th></tr>';
foreach($exportlog as $dateline => $info) {
$info['dateline'] = is_int($dateline) ? gmdate("Y-m-d H:i", $dateline + 8*3600) : '未知';
switch($info['type']) {
case 'full':
$info['type'] = '全部备份';
break;
case 'standard':
$info['type'] = '标准备份(推荐)';
break;
case 'mini':
$info['type'] = '最小备份';
break;
case 'custom':
$info['type'] = '自定义备份';
break;
}
$info['volume'] = $info['method'] == 'multivol' ? $info['volume'] : '';
$info['method'] = $info['method'] == 'multivol' ? '多卷' : 'shell';
$exportinfo .= "<tr>\n".
"<td><a href=\"$info[filename]\" name=\"".substr(strrchr($info['filename'], "/"), 1)."\">".substr(strrchr($info['filename'], "/"), 1)."</a></td>\n".
"<td>$info[version]</td>\n".
"<td>$info[dateline]</td>\n".
"<td>$info[type]</td>\n".
"<td>".get_real_size($info[size])."</td>\n".
"<td>$info[method]</td>\n".
"<td>$info[volume]</td>\n".
"<td><a href=\"?action=all_restore&file=$info[filename]&importsubmit=yes&auto=off\">[导入]</a></td>\n</tr>\n";
}
$exportinfo .= '</table>';
echo $exportinfo;
}
// 查看目录里的备份文件列表, 二级目录下,其中二级目录是随机产生的
if(!empty($bakdirname)) {
$exportlog = array();
$filedirname = TOOLS_ROOT.'./'.$backdirarray[$whereis].'/'.$bakdirname;
if(is_dir($filedirname)) {
$dir = dir($filedirname);
while($entry = $dir->read()) {
$entry = $filedirname.'/'.$entry;
if(is_file($entry) && preg_match("/\.sql/i", $entry)) {
$filesize = filesize($entry);
@$fp = fopen($entry, 'rb');
@$identify = explode(',', base64_decode(preg_replace("/^# Identify:\s*(\w+).*/s", "\\1", fgets($fp, 256))));
@fclose ($fp);

$exportlog[$identify[0]] = array(
'version' => $identify[1],
'type' => $identify[2],
'method' => $identify[3],
'volume' => $identify[4],
'filename' => $entry,
'size' => $filesize);
}
}
$dir->close();
}
krsort($exportlog);
reset($exportlog);

$exportinfo = '<table>
<caption>&nbsp;&nbsp;&nbsp;数据库文件列表</caption>
<tr>
<th>文件名</th><th>版本</th>
<th>时间</th><th>类型</th>
<th>大小</th><th>方式</th>
<th>卷号</th><th>操作</th></tr>';
foreach($exportlog as $dateline => $info) {
$info['dateline'] = is_int($dateline) ? gmdate("Y-m-d H:i", $dateline + 8*3600) : '未知';
switch($info['type']) {
case 'full':
$info['type'] = '全部备份';
break;
case 'standard':
$info['type'] = '标准备份(推荐)';
break;
case 'mini':
$info['type'] = '最小备份';
break;
case 'custom':
$info['type'] = '自定义备份';
break;
}
$info['volume'] = $info['method'] == 'multivol' ? $info['volume'] : '';
$info['method'] = $info['method'] == 'multivol' ? '多卷' : 'shell';
$exportinfo .= "<tr>\n".
"<td><a href=\"$info[filename]\" name=\"".substr(strrchr($info['filename'], "/"), 1)."\">".substr(strrchr($info['filename'], "/"), 1)."</a></td>\n".
"<td>$info[version]</td>\n".
"<td>$info[dateline]</td>\n".
"<td>$info[type]</td>\n".
"<td>".get_real_size($info['size'])."</td>\n".
"<td>$info[method]</td>\n".
"<td>$info[volume]</td>\n".
"<td><a href=\"?action=all_restore&file=$info[filename]&importsubmit=yes&auto=off\">[导入]</a></td>\n</tr>\n";
}
$exportinfo .= '</table>';
echo $exportinfo;
}
echo "<br>";
cexit("");
}
} elseif($action == 'all_runquery') {//运行sql
if(!empty($_POST['sqlsubmit']) && $_POST['queries']) {
runquery($queries);
}
htmlheader();
runquery_html();
htmlfooter();
} elseif($action == 'all_setadmin') {//重置管理员帐号密码,
$sql_findadmin = '';
$sql_select = '';
$sql_update = '';
$sql_rspw = '';
$secq = '';
$rspw = '';
$username = '';
$uid = '';
all_setadmin_set($tablepre,$whereis);
$info = '';
$info_uc = '';
htmlheader();
?>
<h4>重置创始人密码</h4>
<?php
//查询已经存在的管理
if(!empty($_POST['loginsubmit'])) {
if($whereis == 'is_uc') {
define(ROOT_DIR,dirname(__FILE__)."/"); //定义uc根目录常量
$configfile = ROOT_DIR."./data/config.inc.php";
$uc_password = $_POST["password"];
$salt = substr(uniqid(rand()), 0, 6);
if(!$uc_password) {
$info = "密码不能为空";
} else {
$md5_uc_password = md5(md5($uc_password).$salt);
$config = file_get_contents($configfile);
$config = preg_replace("/define\('UC_FOUNDERSALT',\s*'.*?'\);/i", "define('UC_FOUNDERSALT', '$salt');", $config);
$config = preg_replace("/define\('UC_FOUNDERPW',\s*'.*?'\);/i", "define('UC_FOUNDERPW', '$md5_uc_password');", $config);
$fp = @fopen($configfile, 'w');
@fwrite($fp, $config);
@fclose($fp);
$info = "UCenter创始人密码更改成功为:$uc_password";
}
}
errorpage($info,'重置管理员帐号',0,0);
} else {
?>
<form action="?action=all_setadmin" method="post">
<table>

<?php
if($rspw) {
?>
<tr>
<th width="30%">请输入密码</th>
<td width="70%"><input class="textinput" type="text" name="password" size="25"></td>
</tr>
<?php
} else {
?>
<tr>
<th width="30%">密码修改提示</th>
<td width="70%">管理员密码请登录UC后台去改。<a href=11 target='_blank'>点击进入UC后台</a> </td>
</tr>
<?php
}
if($secq) {
?>
<tr>
<th width="30%">是否清除安全提问</th>
<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>
</tr>
<?php
}
?>
</table>
<input type="submit" name="loginsubmit" value="提 &nbsp; 交">
</form>
<?php
}
specialdiv();
htmlfooter();
} elseif($action == 'all_setlock') {//锁定工具箱
touch($lockfile);
if(file_exists($lockfile)) {
echo '<meta http-equiv="refresh" content="3 url=?">';
errorpage("<h6>成功关闭工具箱(UCenter专用版)!强烈建议您在不需要本程序的时候及时进行删除</h6>",'锁定工具箱(UCenter专用版)');
} else {
errorpage('注意您的目录没有写入权限,我们无法给您提供安全保障,请删除论坛根目录下的tool.php文件!','锁定工具箱(UCenter专用版)');
}
} elseif($action == 'all_logout') {//退出登陆
setcookie('toolpassword', '', -86400 * 365);
errorpage("<h6>您已成功退出,欢迎下次使用.强烈建议您在不使用时删除此文件.</h6>");
} elseif($action == 'phpinfo') {
echo phpinfo(13);exit;
} elseif($action == 'datago') {
htmlheader();
!$tableno && $tableno = 0;
!$do && $do = 'create';
!$start && $start = 0;
$limit = 2000;
echo '<h4>数据库编码转换</h4>';
echo "<div class=\"specialdiv\">操作提示:<ul>
<li><font color=red>转换后请自行修改配置文件中的数据库前缀、页面编码、数据库编码</font></li>
<li>详细转换教程:<a href='http://www.discuz.net/thread-1460873-1-1.html'><font color=red>使用Tools转换数据库编码教程</font></a></li>
<li>如果数据库过大,可能需要过多时间</li>
</ul></div>";
if($submit) {
do_datago($mysql,$tableno,$do,$start,$limit);
} elseif($my_version > '4.1') {
datago_output();
} else {
echo '数据库版本不支持数据库编码';
}
htmlfooter();
} elseif($action == 'all_backup') {
htmlheader();
echo "<script type='text/javascript'>
function jumpurl(url){
location.href = url;
return false;
}
</script>";
if($begin == '1') {
echo "<h4>数据库备份</h4><div class=\"specialdiv\">操作提示:<ul>
<li>数据库备份通过api/dbbak.php来执行,请确保这个文件存在</li>
<li>备份前请关闭论坛访问,以免备份数据不完整</li>
<li>请尽量选择服务器空闲时段操作,以避免超时。如程序长久(超过 10 分钟)不反应,请刷新</li></ul></div>";
$title = '<h5><a href="?action=all_restore">【恢复数据】</a>';
$title .= '&nbsp;&nbsp;&nbsp;<a href="?action=all_backup&begin=1">【备份数据】</a></h5>';
echo $title;
$begin = '<button style="margin:0px;" onclick=jumpurl("uctools.php?action=all_backup")>开始备份</button>';
cexit($begin);
}
$notice = "<div class=\"specialdiv\">操作提示:<ul>
<li>接口文件不存在!</li>
</ul></div>";
if(!file_exists('./api/dbbak.php')) {
cexit($notice);
}
if($nexturl) {
$url = $nexturl;
} else {
$url = getbakurl($whereis);
}
dobak($url,$num);
htmlfooter();
} else {
htmlheader();
echo '<h4>欢迎您使用 Comsenz 系统维护工具箱(UCenter专用版)</h4>
<tr><td><br>';
echo '<h5>Comsenz 系统维护工具箱(UCenter专用版)功能简介:</h5><ul>';
foreach($functionall as $value) {
$apps = explode('_', $value['0']);
if(in_array(substr($whereis, 3), $apps) || $value['0'] == 'all') {
echo '<li>'.$value[2].':'.$value[3].'</li>';
}
}
echo '</ul>';
htmlfooter();
}
//函数区
function cexit($message) {
echo $message;
specialdiv();
htmlfooter();
}


function get_real_size($size){
$kb = 1024;
$mb = 1024 * $kb;
$gb = 1024 * $mb;
$tb = 1024 * $gb;

if($size < $kb) {
return $size.' Byte';
} elseif($size < $mb) {
return round($size/$kb,2).' KB';
} elseif($size < $gb) {
return round($size/$mb,2).' MB';
} elseif($size < $tb) {
return round($size/$gb,2).' GB';
} else {
return round($size/$tb,2).' TB';
}
}

function htmlheader() {
global $uch_version,$alertmsg, $whereis, $functionall,$dz_version,$ss_version,$toolpassword,$tool_password,$toolbar,$plustitle;
echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GBK">
<title>Comsenz 系统维护工具箱(UCenter专用版) '.VERSION.'-New</title>
<style type="text/css"><!--
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;}
a:hover {color:#60F;}
ul {padding:2px 0 10px 0;margin:0;}
textarea,table,td,th,select{border:1px solid #868CFF;border-collapse:collapse;}
table li {margin-left:10px;}
input{margin:10px 0 0px 30px;border-width:1px;border-style:solid;border-color:#FFF #64A7DD #64A7DD #FFF;padding:2px 8px;background:#E3EFF9;}
input.radio,input.checkbox,input.textinput,input.specialsubmit {margin:0;padding:0;border:0;padding:0;background:none;}
input.textinput,input.specialsubmit {border:1px solid #AFD2ED;background:#FFF;}
input.textinput {padding:4px 0;} input.specialsubmit {border-color:#FFF #64A7DD #64A7DD #FFF;background:#E3EFF9;padding:0 5px;}
option {background:#FFF;}
select {background:#F0F1FF;}
#header {border-top:4px solid #86B9D6;height:60px;width:100%;padding:0;margin:0;}
h2 {font-size:20px;font-weight:normal;position:absolute;top:20px;left:20px;padding:10px;margin:0;}
h3 {font-size:14px;position:absolute;top:28px;right:20px;padding:10px;margin:0;}
#content {height:510px;background:#F0F1FF;overflow-x:hidden;z-index:1000;}
#nav {top:60px;left:0;height:510px;width:180px;border-right:1px solid #DDE0FF;position:absolute;z-index:2000;}
#nav ul {padding:0 10px;padding-top:30px;}
#nav li {list-style:none;}
#nav li a {font-size:14px;line-height:180%;font-weight:400;color:#000;}
#nav li a:hover {color:#60F;}
#textcontent {padding-left:200px;height:510px;width:80%;*width:100%;line-height:160%;overflow-y:auto;overflow-x:hidden;}
h4,h5,h6 {padding:4px;font-size:16px;font-weight:bold;margin-top:20px;margin-bottom:5px;color:#006;}
h5,h6 {font-size:14px;color:#000;}
h6 {color:#F00;padding-top:5px;margin-top:0;}
.specialdiv {width:70%;border:1px dashed #C8CCFF;padding:0 5px;margin-top:20px;background:#F9F9FF;}
.specialdiv2 {height:240px;width:60%;border:1px dashed #C8CCFF;padding:15px;margin-top:20px;background:#F9F9FF;overflow-y:scroll;}
#textcontent ul {margin-left:30px;}
textarea {width:78%;height:300px;text-align:left;border-color:#AFD2ED;}
select {border-color:#AFD2ED;}
table {width:74%;font-size:12px;margin-left:18px;margin-top:10px;}
table.specialtable,table.specialtable td {border:0;}
td,th {padding:5px;text-align:left;}
caption {font-weight:bold;padding:8px 0;color:#3544FF;text-align:left;}
th {background:#D9DCFF;font-weight:600;}
td.specialtd {text-align:left;}
.specialtext {background:#FCFBFF;margin-top:20px;padding:5px 40px;width:64.5%;margin-bottom:10px;color:#006;}
#footer p {padding:0 5px;text-align:center;}
#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;}
.button {margin-top:20px;}
.infobox {background:#FFF;border-bottom:4px solid #868CFF;border-top:4px solid #868CFF;margin-bottom:10px;padding:30px;text-align:center;width:90%;}
pre {*margin-top:10px;}
.current { font-weight: bold; color: #090 !important; border-bottom-color: #F90 !important; }
-->
</style>
</head>
<script>function $(id) {return document.getElementById(id);}
function menuclose(){
$(\'jsmenu\').style.display = \'none\';
}
</script>
<body>
<div id = "jsmenu" style="display:none">
<h6>提示:</h6>
提示:在进行此操作前建议备份数据库,以免处理过程中出现错误造成数据丢失!!<br/>
<input class=button onclick=menuclose() type=button value=我知道了></input>
</div>
<div id="header">
<h2>< Comsenz Tools '.VERSION.' > Ucenter 专版</h2>
<h3>[ <a href="?" target="_self">首页</a> ]&nbsp;
[ <a href="?action=all_setlock" target="_self">锁定</a> ]&nbsp;';
if($toolpassword == md5($tool_password)) {
foreach($toolbar as $value) {
echo '[ <a href="?action='.$value[0].'" target="_self">'.$value[1].'</a> ]&nbsp';
}
}
echo '</h3></div>
<div id="nav">';
echo '<ul>';//导航菜单中根据不同的目录显示不同
if($toolpassword == md5($tool_password)) {
foreach($functionall as $value) {
$apps = explode('_', $value['0']);
if(in_array(substr($whereis, 3), $apps) || $value['0'] == 'all') {
if($whereis == 'is_ss' && $value[1] == 'all_setadmin' && $ss_version<70 ) {
continue;
}
echo '<li>[ <a href="?action='.$value[1].'" target="_self">'.$value[2].'</a> ]</li>';
}
}
} else {
echo '<li>[ <a href="uctools.php" target="_self">使用前请登录</a> ]</li>';
}
echo '</ul>';
echo '</div>
<div id="content">
<div id="textcontent">';
}
//页面底部
function htmlfooter(){
echo '</div></div>
<div id="footer"><p>Comsenz 系统维护工具箱(UCenter专用版) &nbsp;Release:'.Release.'&nbsp;
&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">
</p></div>
</body>
</html>';
exit;
}
//错误信息
function errorpage($message,$title = '',$isheader = 1,$isfooter = 1){
if($isheader) {
htmlheader();
}
!$isheader && $title = '';
if($message == 'login') {
$message ='<h4>工具箱登录</h4>
<form action="?" method="post">
<table class="specialtable"><tr>
<td width="20%"><input class="textinput" type="password" name="toolpassword"></input></td>
<td><input class="specialsubmit" type="submit" value="登 录"></input></td></tr></table>
<input type="hidden" name="action" value="login">
</form>';
} else {
$message = "<h4>$title</h4><br><br><table><tr><th>提示信息</th></tr><tr><td>$message</td></tr></table>";
}
echo $message;
if($isfooter) {
htmlfooter();
}
}
//跳转
function redirect($url) {
echo "<script>";
echo "function redirect() {window.location.replace('$url');}\n";
echo "setTimeout('redirect();', 2000);\n";
echo "</script>";
echo "<br><br><a href=\"$url\">如果您的浏览器没有自动跳转,请点击这里</a>";
cexit("");
}
/**
* 检查目录里下的文件权限函数
* @param unknown_type $directory
*/

//检查sql语句
function splitsql($sql){
$sql = str_replace("\r", "\n", $sql);
$ret = array();
$num = 0;
$queriesarray = explode(";\n", trim($sql));
unset($sql);
foreach($queriesarray as $query) {
$queries = explode("\n", trim($query));
foreach($queries as $query) {
$ret[$num] .= $query[0] == "#" ? NULL : $query;
}
$num++;
}
return($ret);
}

function syntablestruct($sql, $version, $dbcharset) {

if(strpos(trim(substr($sql, 0, 18)), 'CREATE TABLE') === FALSE) {
return $sql;
}
if(substr(trim($sql), 0, 9) == 'SET NAMES' && !$version) {
return '';
}
$sqlversion = strpos($sql, 'ENGINE=') === FALSE ? FALSE : TRUE;

if($sqlversion === $version) {

return $sqlversion && $dbcharset ? preg_replace(array('/ character set \w+/i', '/ collate \w+/i', "/DEFAULT CHARSET=\w+/is"), array('', '', "DEFAULT CHARSET=$dbcharset"), $sql) : $sql;
}

if($version) {
return preg_replace(array('/TYPE=HEAP/i', '/TYPE=(\w+)/is'), array("ENGINE=MEMORY DEFAULT CHARSET=$dbcharset", "ENGINE=\\1 DEFAULT CHARSET=$dbcharset"), $sql);

} else {
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);
}
}
function stay_redirect() {
global $action, $actionnow, $step, $stay, $convertedrows, $allconvertedrows;
$nextstep = $step + 1;
echo '<h4>数据库冗余数据清理</h4><table>
<tr><th>正在进行'.$actionnow.'</th></tr><tr>
<td>';
if($stay) {
$actions = isset($action[$nextstep]) ? $action[$nextstep] : '结束';
echo "$actionnow 操作完毕.共处理<font color=red>{$convertedrows}</font>条数据.".($stay == 1 ? "&nbsp;&nbsp;&nbsp;&nbsp;" : '').'<br><br>';
echo "<a href='?action=dz_mysqlclear&step=".$nextstep."&stay=1'>( $actions ),请点击这里!</a><br>";
} else {
if(isset($action[$nextstep])) {
echo '即将进入:'.$action[$nextstep].'......';
}
$allconvertedrows = $allconvertedrows + $convertedrows;
$timeout = $GLOBALS['debug'] ? 5000 : 2000;
echo "<script>\r\n";
echo "<!--\r\n";
echo "function redirect() {\r\n";
echo " window.location.replace('?action=dz_mysqlclear&step=".$nextstep."&allconvertedrows=".$allconvertedrows."');\r\n";
echo "}\r\n";
echo "setTimeout('redirect();', $timeout);\r\n";
echo "-->\r\n";
echo "</script>\r\n";
echo "[<a href='?action=dz_mysqlclear' style='color:red'>停止运行</a>]<br><br><a href=\"".$scriptname."?step=".$nextstep."\">如果您的浏览器长时间没有自动跳转,请点击这里!</a>";
}
echo '</td></tr></table>';
}
//检查数据库表字段
function loadtable($table, $force = 0) {
global $carray,$mysql;
$discuz_tablepre = $carray['tablepre'];
static $tables = array();

if(!isset($tables[$table])) {
if(mysqli_get_server_info($mysql) > '4.1') {
$query = @mysqli_query($mysql,"SHOW FULL COLUMNS FROM {$discuz_tablepre}$table");
} else {
$query = @mysqli_query($mysql,"SHOW COLUMNS FROM {$discuz_tablepre}$table");
}
while($field = @mysqli_fetch_assoc($query)) {
$tables[$table][$field['Field']] = $field;
}
}
return $tables[$table];
}

//获得数据表的最大和最小 id 值
function validid($id, $table) {
global $start, $maxid, $mysql, $tablepre,$mysql;
$sql = mysqli_query($mysql,"SELECT MIN($id) AS minid, MAX($id) AS maxid FROM {$tablepre}$table");
$result = mysqli_fetch_array($sql);
$start = $result['minid'] ? $result['minid'] - 1 : 0;
$maxid = $result['maxid'];
}
//提示
function specialdiv() {
echo '<div class="specialdiv">
<h6>注意:</h6>
<ul>
<li>当您使用完毕Comsenz 系统维护工具箱(UCenter专用版)后,请点击锁定工具箱以确保系统的安全!下次使用前只需要在/data目录下删除tool.lock文件即可开始使用。</li></ul></div>';
}
//判断目录
function getplace() {
global $lockfile, $cfgfile, $docdir;
$whereis = false;
if(is_writeable('./config.inc.php') && is_writeable('./forumdata')) {//判断Discuz!目录
$whereis = 'is_dz';
$lockfile = './forumdata/tools.lock';
$cfgfile = './config.inc.php';
$docdir = './forumdata';
}
if(is_writeable('./data/config.inc.php') && is_dir('./control')) {//判断UCenter目录
$whereis = 'is_uc';
$lockfile = './data/tools.lock';
$cfgfile = './data/config.inc.php';
$docdir = './data';
}
if(is_writeable('./config.php') && is_dir('source')) {//判断UCenter Home目录
$whereis = 'is_uch';
$lockfile = './data/tools.lock';
$cfgfile = './config.php';
$docdir = './data';
}
if(is_writeable('./config.php') && file_exists('./batch.common.php')) {//判断SupeSite目录
$whereis = 'is_ss';
$lockfile = './data/tools.lock';
$cfgfile = './config.php';
$docdir = './data';
}
return $whereis;
}
//获得数据库配置信息
function getdbcfg(){
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;
if(@!include($cfgfile)) {
htmlheader();
cexit("<h4>请先上传config文件以保证您的数据库能正常链接!</h4>");
}
if(UC_DBHOST) {
$uc_dbhost = UC_DBHOST;
$uc_dbuser = UC_DBUSER;
$uc_dbpw = UC_DBPW;
$uc_dbname = UC_DBNAME;
$uc_tablepre = UC_DBTABLEPRE;
$uc_dbcharset = UC_DBCHARSET;
}
switch($whereis) {
case 'is_dz':
$dbhost = $dbhost;
$dbuser = $dbuser;
$dbpw = $dbpw;
$dbname = $dbname;
$tablepre = $tablepre;
$dbcharset = !$dbcharset ? (strtolower($charset) == 'utf-8' ? 'utf8' : $charset): $dbcharset;
define('IN_DISCUZ',true);
@require_once "./discuz_version.php";
$dz_version = DISCUZ_VERSION;
if($dz_version >= '7.1') {
$dz_version = intval(str_replace('.','',$dz_version)).'0';
} else {
$dz_version = intval(str_replace('.','',$dz_version));
}
break;
case 'is_uc':
$dbhost = UC_DBHOST;
$dbuser = UC_DBUSER;
$dbpw = UC_DBPW;
$dbname = UC_DBNAME;
$tablepre = UC_DBTABLEPRE;
$dbcharset = !UC_DBCHARSET ? (strtolower(UC_CHARSET) == 'utf-8' ? 'utf8' : UC_CHARSET) : UC_DBCHARSET;
break;
case 'is_uch':
$dbhost = $_SC["dbhost"];
$dbuser = $_SC["dbuser"];
$dbpw = $_SC["dbpw"];
$dbname = $_SC["dbname"];
$tablepre = $_SC["tablepre"];
if(file_exists("./ver.php")) {
require './ver.php';
$uch_version = X_VER;
} else {
$common = 'common.php';
$version = fopen($common,'r');
$version = fread($version,filesize($common));
$len = strpos($version,'define(\'D_BUG\')');
$version = substr($version,0,$len);
$cache = fopen('./data/version.php','w');
fwrite($cache,$version);
fclose($cache);
require_once './data/version.php';
$uch_version = intval(str_replace('.','',X_VER));
unlink('./data/version.php');
}
$uch_version = intval(str_replace('.','',$uch_version));
$dbcharset = !$_SC['dbcharset'] ? (strtolower($_SC["charset"]) == 'utf-8' ? 'utf8' : $_SC["charset"]) : $_SC['dbcharset'] ;
break;
case 'is_ss':
$dbhost = $dbhost ? $dbhos : $_SC['dbhost'];
$dbuser = $dbuser ? $dbuser : $_SC['dbuser'];
$dbpw = $dbpw ? $dbpw : $_SC['dbpw'];
$dbname = $dbname ? $dbname : $_SC['dbname'];
$tablepre = $tablepre ? $tablepre : $_SC['tablepre'];
$dbcharset = !$dbcharset ? (strtolower($charset) == 'utf-8' ? 'utf8' : $charset) : $dbcharset;
if(!$dbcharset) {
$dbcharset = !$_SC['dbcharset'] ? (strtolower($_SC['charset']) == 'utf-8' ? 'utf8' : $_SC['charset']) : $_SC['dbcharset'];
}
if($_SC['dbhost'] || $_SC['dbuser']) {
$common = 'common.php';
$version = fopen($common,'r');
$version = fread($version,filesize($common));
$len = strpos($version,'define(\'S_RELEASE\'');
$version = substr($version,0,$len);
$cache = fopen('./data/version.php','w');
fwrite($cache,$version);
fclose($cache);
require_once './data/version.php';
$ss_version = intval(str_replace('.','',S_VER));
unlink('./data/version.php');
}
break;
default:
$dbhost = $dbuser = $dbpw = $dbname = $tablepre = $dbcharset = '';
break;
}
}

function taddslashes($string, $force = 0) {
!defined('MAGIC_QUOTES_GPC') && define('MAGIC_QUOTES_GPC', get_magic_quotes_gpc());
if(!MAGIC_QUOTES_GPC || $force) {
if(is_array($string)) {
foreach($string as $key => $val) {
$string[$key] = taddslashes($val, $force);
}
} else {
$string = addslashes($string);
}
}
return $string;
}

function pregcharset($charset,$color = 0) {
if(strpos('..'.strtolower($charset), 'gbk')) {
if($color) {
return '<font color="#0000CC">gbk</font>';
} else {
return 'gbk';
}
} elseif(strpos('..'.strtolower($charset), 'latin1')) {
if($color) {
return '<font color="#993399">latin1</font>';
} else {
return 'latin1';
}
} elseif(strpos('..'.strtolower($charset), 'utf8')) {
if($color) {
return '<font color="#993300">utf8</font>';
} else {
return 'utf8';
}
} elseif(strpos('..'.strtolower($charset), 'big5')) {
if($color) {
return '<font color="#006699">big5</font>';
} else {
return 'big5';
}
} else {
return $charset;
}
}

function show_tools_message($message, $url = 'uctools.php',$time = '2000') {
echo "<script>";
echo "function redirect() {window.location.replace('$url');}\n";
echo "setTimeout('redirect();', $time);\n";
echo "</script>";
echo "<h4>$title</h4><br><br><table><tr><th>提示信息</th></tr><tr><td>$message<br><a href=\"$url\">如果您的浏览器没有自动跳转,请点击这里</a></td></tr></table>";
exit;
}

function fileext($filename) {
return trim(substr(strrchr($filename, '.'), 1, 10));
}
function cutstr($string, $length, $dot = ' ...') {
global $charset;
if(strlen($string) <= $length) {
return $string;
}
$string = str_replace(array('&amp;', '&quot;', '&lt;', '&gt;'), array('&', '"', '<', '>'), $string);
$strcut = '';
if(strtolower($charset) == 'utf-8') {
$n = $tn = $noc = 0;
while($n < strlen($string)) {

$t = ord($string[$n]);
if($t == 9 || $t == 10 || (32 <= $t && $t <= 126)) {
$tn = 1; $n++; $noc++;
} elseif(194 <= $t && $t <= 223) {
$tn = 2; $n += 2; $noc += 2;
} elseif(224 <= $t && $t < 239) {
$tn = 3; $n += 3; $noc += 2;
} elseif(240 <= $t && $t <= 247) {
$tn = 4; $n += 4; $noc += 2;
} elseif(248 <= $t && $t <= 251) {
$tn = 5; $n += 5; $noc += 2;
} elseif($t == 252 || $t == 253) {
$tn = 6; $n += 6; $noc += 2;
} else {
$n++;
}
if($noc >= $length) {
break;
}
}
if($noc > $length) {
$n -= $tn;
}
$strcut = substr($string, 0, $n);
} else {
for($i = 0; $i < $length; $i++) {
$strcut .= ord($string[$i]) > 127 ? $string[$i].$string[++$i] : $string[$i];
}
}
$strcut = str_replace(array('&', '"', '<', '>'), array('&amp;', '&quot;', '&lt;', '&gt;'), $strcut);
return $strcut.$dot;
}

function checkfiles($currentdir, $ext = '', $sub = 1, $skip = '') {
global $md5data, $dz_files;
$dir = @opendir($currentdir);
$exts = '/('.$ext.')$/i';
$skips = explode(',', $skip);

while($entry = @readdir($dir)) {
$file = $currentdir.$entry;
if($entry != '.' && $entry != '..' && (preg_match($exts, $entry) || $sub && is_dir($file)) && !in_array($entry, $skips)) {
if($sub && is_dir($file)) {
checkfiles($file.'/', $ext, $sub, $skip);
} else {
$md5data[$file] = md5_file($file);
}
}
}
}

function loadtable_ucenter($table, $force = 0) {
global $carray,$mysql;
$discuz_tablepre = $carray['UC_DBTABLEPRE'];
static $tables = array();

if(!isset($tables[$table])) {
if(mysqli_get_server_info($mysql) > '4.1') {
$query = @mysqli_query($mysql,"SHOW FULL COLUMNS FROM {$discuz_tablepre}$table");
} else {
$query = @mysqli_query($mysql,"SHOW COLUMNS FROM {$discuz_tablepre}$table");
}
while($field = @mysqli_fetch_assoc($query)) {
$tables[$table][$field['Field']] = $field;
}
}
return $tables[$table];
}

function runquery($queries){//执行sql语句
global $tablepre,$whereis,$mysql;
$sqlquery = splitsql(str_replace(array(' cdb_', ' {tablepre}', ' `cdb_'), array(' '.$tablepre, ' '.$tablepre, ' `'.$tablepre), $queries));
$affected_rows = 0;
foreach($sqlquery as $sql) {
$sql = syntablestruct(trim($sql), $my_version > '4.1', $dbcharset);
if(trim($sql) != '') {
mysqli_query($mysql,stripslashes($sql));
if($sqlerror = mysqli_error($mysql)) {
break;
} else {
$affected_rows += intval(mysqli_affected_rows($mysql));
}
}
}
if(strpos($queries,'seccodestatus') && $whereis == 'is_dz') {
dz_updatecache();
}
if(strpos($queries,'bbclosed') && $whereis == 'is_dz') {
dz_updatecache();
}
if(strpos($queries,'template') && $whereis == 'is_uch') {
uch_updatecache();
}
if(strpos($queries,'seccode_login') && $whereis == 'is_uch') {
uch_updatecache();
}
if(strpos($queries,'close') && $whereis == 'is_uch') {
uch_updatecache();
}
errorpage($sqlerror? $sqlerror : "数据库升级成功,影响行数: &nbsp;$affected_rows",'数据库升级');

if(strpos($queries,'settings') && $whereis == 'is_dz') {
require_once './include/cache.func.php';
updatecache('settings');
}
}

function runquery_html(){ //输出快速设置的所有选项
global $whereis,$tablepre;
echo "<h4>快速设置(SQL)</h4>
<form method=\"post\" action=\"uctools.php?action=all_runquery\">
<h5>请下拉选择程序内置的快速设置</h4>
<font color=red>提示:</font>也可以自己书写SQL执行,不过请确保您知道该SQL的用途,以免造成不必要的损失.<br/><br/>";
if($whereis == 'is_uc') {
echo "<select name=\"queryselect\" onChange=\"queries.value = this.value\">
<option value = ''>可选择TOOLS内置升级语句</option>
<option value = \"TRUNCATE TABLE ".$tablepre."notelist;\">清空通知列表</option>
</select>";
}
echo "<br />
<br /><textarea name=\"queries\">$queries</textarea><br />
<input type=\"submit\" name=\"sqlsubmit\" value=\"提 &nbsp; 交\">
</form>";
}

function topattern_array($source_array) { //将数组正则化
$source_array = preg_replace("/\{(\d+)\}/",".{0,\\1}",$source_array);
foreach($source_array as $key => $value) {
$source_array[$key] = '/'.$value.'/i';
}
return $source_array;
}

function all_setadmin_set($tablepre,$whereis){ //重设管理员根据程序生成各种变量
global $ss_version,$dz_version,$sql_findadmin,$sql_select,$sql_update,$sql_rspw,$secq,$rspw,$username,$uid;
if($whereis == 'is_uc') {
$secq = 0;
$rspw = 1;
}
}

function datago_output($whereis){
global $dbhost, $dbuser, $dbpw, $dbname, $dbcfg;
$charsets=array('gbk','latin1','utf8');
$options="<option value=''>";
foreach($charsets as $value){
$options.="<option value=\"$value\">$value";
}
echo '<h5>数据库编码转换</h5>';
echo '<form method=get action=uctools.php?action=datago><table>
<tbody>
<input name=action type=hidden value=datago>
<tr><th width=20%>源数据库</th><td><input class=textinput name=fromdbname value='.$dbname.'></input>&nbsp;&nbsp;默认为tools所在程序的数据库,如果不知道其作用请不要修改</td></tr>
<tr><th width=20%>目的编码</th><td><select name=todbcharset>'.$options.'</select>&nbsp;&nbsp;转换允许:\'latin1\'<=>\'gbk\',\'gbk\'<=>\'utf8\'</td></tr></tbody></table>
<input name=submit type=submit value=转换></input>
</form>';
}

function do_datago($mysql,$tableno,$do,$start,$limit){
global $whereis, $dbhost, $dbuser, $dbpw, $tablepre,$fromdbname, $todbcharset, $dbcfg,$dbcharset;
$allowcharset = array('latin1' => 'gbk','gbk' => 'utf8','utf8' => 'latin1');
$tablename = 'Tables_in_'.strtolower($fromdbname).' ('.$tablepre.'%)';
$mysql = mysqli_connect($dbhost, $dbuser, $dbpw,$fromdbname);
// mysql_select_db($fromdbname);
mysqli_query($mysql,"SET sql_mode=''");
$query = mysqli_query($mysql,'SHOW TABLES LIKE \''.$tablepre.'%\'');
while($t = mysqli_fetch_array($query,MYSQLI_ASSOC)) {
$tablearray[] = $t[$tablename];
}
$table = $tablearray["$tableno"];
$query = mysqlI_query($mysql,'SHOW TABLE STATUS LIKE '.'\''.$table.'\'');
$tableinfo = array();

while($t = mysqli_fetch_array($query,MYSQLI_ASSOC)) {
$charset = explode('_',$t['Collation']);
$t['Collation'] = $charset[0];
$tableinfo = $t;
}
if($allowcharset[$tableinfo['Collation']] != $todbcharset && $allowcharset[$todbcharset] != $tableinfo['Collation']){
if(strpos($tableinfo['Name'],$todbcharset) == 0) {
$table = '';
} else {
echo "<h4>$title</h4><br><br><table><tr><th>提示信息</th></tr><tr><td>$tableinfo[Name] 表数据库编码出错</td></tr></table>";
exit;
}
}
mysqli_query($mysql,"SET NAMES '$tableinfo[Collation]'");

if($do == 'create') {
$tablecreate=array();
foreach ($tablearray as $key => $value){
$query=mysqli_query($mysql,"SHOW CREATE TABLE $value");
while($t = mysqli_fetch_array($query,MYSQLI_ASSOC)){
$t['Create Table'] = str_replace($tablepre,$whereis.'_',$t['Create Table']);
$t['Create Table'] = str_replace("$tableinfo[Collation]","$todbcharset",$t['Create Table']);
$t['Create Table'] = str_replace($whereis.'_',$todbcharset.$whereis.'_',$t['Create Table']);
$t['Table'] = str_replace($tablepre,$todbcharset.$whereis.'_',$t['Table']);
$tablecreate[]=$t;
}
}
mysqli_query($mysql,'SET NAMES \''.$todbcharset.'\'');
if(mysqli_get_server_info($todbcharset) > '5.0'){
mysqli_query($mysql,"SET sql_mode=''");
}
foreach ($tablecreate as $key => $value){
mysqli_query($mysql,"DROP TABLE IF EXISTS `$value[Table]`");
mysqli_query($mysql,$value['Create Table']);
$count++;
}
$toolstip .= '所有的表创建完成,数据库共有 '.$count.' 个表!<br>';
show_tools_message($toolstip,"uctools.php?action=datago&do=data&fromdbname=$fromdbname&todbcharset=$todbcharset&submit=%D7%AA%BB%BB");

} elseif($do == 'data') {
$count = 0;
$data = array();
$newtable = str_replace($tablepre,$todbcharset.$whereis.'_',$table);
if($table) {
mysqli_query($mysql,"SET NAMES '$tableinfo[Collation]'");
$query = mysqli_query($mysql,"SELECT * FROM $table LIMIT $start,$limit");

while($t = mysqli_fetch_array($query,MYSQLI_ASSOC)) {
$data[] = $t;
}
unset($t);
$todbcharset2 = $todbcharset;
if($tableinfo['Collation'] == 'utf8' || $todbcharset=='utf8'){
$todbcharset2 = $tableinfo['Collation'];
}
mysqli_query($mysql,'SET NAMES \''.$todbcharset2.'\'');
if(mysqli_get_server_info($mysql) > '5.0'){
mysqli_query($mysql,"SET sql_mode=''");
}
if($start == 0){
mysqli_query($mysql,"TRUNCATE TABLE $newtable");
}

foreach($data as $key => $value){
$sql='';
foreach($value as $tokey => $tovalue){
$tovalue = addslashes($tovalue);
$sql = $sql ? $sql.",'".$tovalue."'" : "'".$tovalue."'";
}
mysqli_query($mysql,"INSERT INTO $newtable VALUES($sql)") or mysqli_errno($mysql);
$count++;
}
if($count == $limit) {
$start += $count;
show_tools_message("正在转移 $table 表的从 $start 条记录开始的后 $limit 条记录","uctools.php?action=datago&do=data&fromdbname=$fromdbname&todbcharset=$todbcharset&tableno=$tableno&start=$start&submit=%D7%AA%BB%BB");
} else {
$tableno ++;
show_tools_message("正在转移 $table 表的从 $start 条记录开始的后 $limit 条记录","uctools.php?action=datago&do=data&fromdbname=$fromdbname&todbcharset=$todbcharset&tableno=$tableno&submit=%D7%AA%BB%BB",$time='1000');
}
} elseif($dbcharset == 'latin1' || $todbcharset == 'latin1') {
echo "<div class=\"specialdiv2\" id=\"serialize\">转换提示:<ul>
</ul></div>";
echo '<script>$("serialize").innerHTML+="<li>转换完成!转换后的数据库前缀为:<font color=red>'.$todbcharset.$whereis.'_ </font></li>";
$("serialize").scrollTop=$("serialize").scrollHeight;</script>';
} else {
$toolstip = '数据编码转换完毕,修复序列化数据。';
show_tools_message($toolstip,"uctools.php?action=datago&do=serialize&fromdbname=$fromdbname&todbcharset=$todbcharset&submit=%D7%AA%BB%BB");
}

} elseif($do == 'serialize' && $dbcharset!='latin1' && $todbcharset!='latin1') {
if($whereis == 'is_ss') {
$a = array('0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f');
foreach($a as $num) {
mysqli_query($mysql,"TRUNCATE TABLE ".$todbcharset.$whereis.'_'."cache_".$num);
}
}
$arr = getlistarray($whereis,'datago');
$limit = '3000';
echo "<div class=\"specialdiv2\" id=\"serialize\">转换提示:<ul>
</ul></div>";
foreach($arr as $field) {
$stable = $todbcharset.$whereis.'_'.$field[0];
$sfield = $field[1];
$sid = $field[2];
$query = mysqli_query($mysql,"SELECT $sid,$sfield FROM $stable ORDER BY $sid DESC LIMIT $limit");
while($values = mysqli_fetch_array($query,MYSQLI_ASSOC)) {
$data = $values[$sfield];
$id = $values[$sid];
$data = preg_replace_callback('/s:([0-9]+?):"([\s\S]*?)";/','_serialize',$data);
$data = taddslashes($data);
if(mysqli_query($mysql,"update `$stable` set `$sfield`='$data' where `$sid`='$id'")) {
$toolstip = $stable.' 表的 '.$sid.' 为 '.$id.' 的 '.$sfield.' 字段,修复成功<br/>';
} else {
$toolstip = $stable.' 表的 '.$sid.' 为 '.$id.' 的 '.$sfield.' 字段,<font color=red>修复失败</font><br/>';
}
echo '<script>$("serialize").innerHTML+="'.$toolstip.'";
$("serialize").scrollTop=$("serialize").scrollHeight;</script>';
}
}
mysqli_close($mysql);
echo '<script>$("serialize").innerHTML+="<li>转换完成!请检查修复记录。转换后的数据库前缀为:<font color=red>'.$todbcharset.$whereis.'_ </font></li>";
$("serialize").scrollTop=$("serialize").scrollHeight;</script>';
}
}

function _config_form($title = '',$varname = '',$end = '1') {
global $$varname;
$ucapi = UC_API;
$ucip = UC_IP;
$form = '';
$form .= "<th width=20%>$title</th>";
if($$varname || isset($$varname)) {
$form .= "<td><input class=textinput name=".$varname."2 value=".$$varname."></input></td>";
} else {
$form .= "<td></td>";
}
if($end == '1') {
$form .= '';
} elseif ($end == '2') {
$form .= '</tr>';
} elseif ($end == '3') {
$form .= '</tr><tr>';
}
echo $form;
}

function writefile($filename, $writetext, $openmod='w') {
if(@$fp = fopen($filename, $openmod)) {
flock($fp, 2);
fwrite($fp, $writetext);
fclose($fp);
return true;
} else {
return false;
}
}

function xml2array($xml) {
$arr = xml_unserialize($xml, 1);
preg_match('/<error errorCode="(\d+)" errorMessage="([^\/]+)" \/>/', $xml, $match);
$arr['error'] = array('errorcode' => $match[1], 'errormessage' => $match[2]);
return $arr;
}

function getbakurl($whereis,$action) {
if ($whereis != 'is_uc') {
require_once './uc_client/client.php';
require_once './uc_client/model/base.php';
} else {
define('IN_UC',TRUE);
define('UC_ROOT','./');
require_once './model/base.php';
}

$base = new base();
$salt = substr(uniqid(rand()), -6);
$action = !empty($action) ? $action : 'export';
$url = 'http://'.$_SERVER['HTTP_HOST'].str_replace('uctools.php', 'api/dbbak.php', $_SERVER['PHP_SELF']);
if($whereis == 'is_dz') {
$apptype = 'discuz';
} elseif ($whereis == 'is_uc') {
$apptype = 'ucenter';
} elseif ($whereis == 'is_uch') {
$apptype = 'uchome';
} elseif ($whereis == 'is_ss') {
$apptype = 'supesite';
}
$url .= '?apptype='.$apptype;
$code = $base -> authcode('&method='.$action.'&time='.time(), 'ENCODE', UC_KEY);
$url .= '&code='.urlencode($code);
return $url;
}

function dobak($url,$num = '1') {
global $whereis;
$num = !empty($num) ? $num : '0';
$return = file_get_contents($url);
if($whereis != 'is_uc') {
require_once './uc_client/lib/xml.class.php';
} else {
require_once './lib/xml.class.php';
}
$arr = xml2array($return);

if($arr['error']['errormessage'] == 'explor_success') {
echo "<div class=\"specialdiv\">备份提示:<ul>
<li>>>>>>>>>备份完成<<<<<<<<</li>
<li>>>>>>>>>共:".$num."个文件<<<<<<<<</li>
</ul></div>";
} else {
$num ++;
echo "<div class=\"specialdiv\">备份提示:<ul>
<li>".$arr['fileinfo']['file_name']."......".$arr['error']['errormessage']."</li>
</ul></div>";
}
if($arr['nexturl']) {
$url = './uctools.php?action=all_backup&nexturl='.urlencode($arr['nexturl']).'&num='.$num;
show_tools_message($arr['fileinfo']['file_name'],$url,$time = 2000);
}
}

function getgpc($k, $var='G') {
switch($var) {
case 'G': $var = &$_GET; break;
case 'P': $var = &$_POST; break;
case 'C': $var = &$_COOKIE; break;
case 'R': $var = &$_REQUEST; break;
}
return isset($var[$k]) ? $var[$k] : NULL;
}

function getlistarray($whereis,$type) {
global $dz_version,$ss_version,$uch_version;
if($whereis == 'is_dz' && $dz_version >= '710') {
if($type == 'datago') {
$list = array(
array('advertisements','parameters','advid'),
array('request','value','variable'),
array('settings','value','variable'),
);
}
} elseif($whereis == 'is_uch' && $uch_version >= '15') {
if($type == 'datago') {
$list = array(
array('ad','adcode','adid'),
array('blogfield','tag','blogid'),
array('blogfield','related','blogid'),
array('feed','title_data','feedid'),
array('feed','body_data','feedid'),
array('share','body_data','sid'),
);
}
} elseif($whereis == 'is_uc') {
if($type == 'datago') {
$list = array(
array('feed','title_data','feedid'),
array('feed','body_data','feedid'),
array('settings','v','k'),
);
}
} elseif($whereis == 'is_ss' && $ss_version >=70) {
if($type == 'datago') {
$list = array(
array('ads','parameters','adid'),
array('blocks','blocktext','blockid'),
);
}
}
return $list;
}

function _serialize($str) {
global $dbcharset,$todbcharset;
$charset = $dbcharset == 'utf8' ? 'utf-8':$dbcharset;
$tempdbcharset = $todbcharset == 'utf8' ? 'utf-8':$todbcharset;
$charset = strtoupper($charset);
$tempdbcharset = strtoupper($tempdbcharset);
$temp = iconv($charset,$tempdbcharset,$str[2]);
$l = strlen($temp);
return 's:'.$l.':"'.$str[2].'";';
}

function infobox($str,$link) {
if($link) {
$button = "<input class='button' type='submit' onclick=\"location.href='".$link."'\" value='开始' name='submit'/>";
}
echo "<div class='infobox'><p>$str</p>$button</div>";
}

//检查数据表
function checktable($table, $loops = 0,$doc) {
global $db, $nohtml, $simple, $counttables, $oktables, $errortables, $rapirtables,$mysql;
$query = mysqli_query($mysql,"show create table $table");
if($createarray = mysqli_fetch_array($query)) {
if(strpos($createarray[1], 'TYPE=HEAP')) {
$counttables --;
return ;
}
}
$result = mysqli_query($mysql,"CHECK TABLE $table");
if(!$result) {
$counttables --;
return ;
}
$message = "\n>>>>>>>>>>>>>Checking Table $table\r\n---------------------------------\r\n";
@writefile($doc,$message,'a');
$error = 0;
while($r = mysqli_fetch_row($result)) {
if($r[2] == 'error') {
if($r[3] == "The handler for the table doesn't support check/repair") {
$r[2] = 'status';
$r[3] = 'This table does not support check/repair/optimize';
unset($bgcolor);
$nooptimize = 1;
} else {
$error = 1;
$bgcolor = 'red';
unset($nooptimize);
}
$view = '错误';
$errortables += 1;
} else {
unset($bgcolor);
unset($nooptimize);
$view = '正常';
if($r[3] == 'OK') {
$oktables += 1;
} elseif($r[3] == 'The storage engine for the table doesn\'t support check') {
$oktables += 1;
}
}
$message = "$r[0] | $r[1] | $r[2] | $r[3]\r\n";
@writefile($doc,$message,'a');
}
if($error) {
$message = ">>>>>>>>正在修复中 / Repairing Table $table\r\n";
@writefile($doc,$message,'a');
$result2=mysqli_query($mysql,"REPAIR TABLE $table");
while($r2 = mysqli_fetch_row($result2)) {
if($r2[3] == 'OK') {
$bgcolor='blue';
$rapirtables += 1;
} else {
unset($bgcolor);
}
$message = "$r2[0] | $r2[1] | $r2[2] | $r2[3]\r\n";
@writefile($doc,$message,'a');
}
}
if(($result2[3] == 'OK'||!$error)&&!$nooptimize) {
$message = ">>>>>>>>>>>>>Optimizing Table $table\r\n";
@writefile($doc,$message,'a');
$result3 = mysqli_query($mysql,"OPTIMIZE TABLE $table");
$error = 0;
while($r3 = mysqli_fetch_row($result3)) {
if($r3[2] == 'error') {
$error = 1;
$bgcolor = 'red';
} else {
unset($bgcolor);
}
$message = "$r3[0] | $r3[1] | $r3[2] | $r3[3]\r\n\r\n";
@writefile($doc,$message,'a');
}
}
if($error && $loops) {
checktable($table,($loops-1),$doc);
}
}
?>

运用程序自带的PHP文件清理缓存

首先下载在utility,出于安全考虑,自 X3.4 20211231 开始,安装包内不再包含 utility 文件夹,有需要这个文件夹的用户,请单独下载使用,下载地址:https://www.dismall.com/thread-11309-1-1.html

找到在utility目录中的update.php文件,然后使用FTP工具连接到主机空间,把update.php文件上传到install这个安装目录中,然后再找到data目录下有个update.lock文件。删除该文件,下面也是直接运行网站的域名/install/update.php?step=cache就可以清理掉缓存了。

伸手党,我连包都给你准备好了,接招吧:https://img.diandian100.cn/202206231119025.zip

做完以上操作相信你的论坛就能访问了,如果没有样式可以登录后台,更新下css缓存就行了。