-
Notifications
You must be signed in to change notification settings - Fork 10
/
FTP.php
1308 lines (1168 loc) · 47.8 KB
/
FTP.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
<?php
error_reporting(0);
header('Content-Type: text/html; charset=utf-8');
$SCRIPT_NAME = "";
$adminfile = $SCRIPT_NAME;
$tbcolor1 = "#bacaee";
$tbcolor2 = "#daeaff";
$tbcolor3 = "#7080dd";
$bgcolor1 = "#ffffff";
$bgcolor2 = "#a6a6a6";
$bgcolor3 = "#003399";
$txtcolor1 = "#000000";
$txtcolor2 = "#003399";
$filefolder = "./";
$sitetitle = 'ftp文件管理系统';
$user = 'admin';
$pass = 'admin';
$meurl = $_SERVER['PHP_SELF'];
$me = end(explode('/',$meurl));
$op = $_REQUEST['op'];
$folder = $_REQUEST['folder'];
while (preg_match('/\.\.\//',$folder)) $folder = preg_replace('/\.\.\//','/',$folder);
while (preg_match('/\/\//',$folder)) $folder = preg_replace('/\/\//','/',$folder);
if ($folder == '') {
$folder = $filefolder;
} elseif ($filefolder != '') {
if (!ereg($filefolder,$folder)) {
$folder = $filefolder;
}
}
/****************************************************************/
/* User identification */
/* */
/* Looks for cookies. Yum. */
/****************************************************************/
if ($_COOKIE['user'] != $user || $_COOKIE['pass'] != md5($pass)) {
if ($_REQUEST['user'] == $user && $_REQUEST['pass'] == $pass) {
setcookie('user',$user,time()+60*60*24*1);
setcookie('pass',md5($pass),time()+60*60*24*1);
} else {
if ($_REQUEST['user'] == $user || $_REQUEST['pass']) $er = true;
login($er);
}
}
/****************************************************************/
/* function maintop() */
/* */
/* Controls the style and look of the site. */
/* Recieves $title and displayes it in the title and top. */
/****************************************************************/
function maintop($title,$showtop = true) {
global $me,$sitetitle, $lastsess, $login, $viewing, $iftop, $bgcolor1, $bgcolor2, $bgcolor3, $txtcolor1, $txtcolor2, $user, $pass, $password, $debug, $issuper;
echo "<html>\n<head>\n"
."<title>$sitetitle :: $title</title>\n"
."</head>\n"
."<body bgcolor=\"#ffffff\">\n"
."<style>\n"
."td { font-size : 80%;font-family : tahoma;color: $txtcolor1;font-weight: 700;}\n"
."A:visited {color: \"$txtcolor2\";font-weight: bold;text-decoration: underline;}\n"
."A:hover {color: \"$txtcolor1\";font-weight: bold;text-decoration: underline;}\n"
."A:link {color: \"$txtcolor2\";font-weight: bold;text-decoration: underline;}\n"
."A:active {color: \"$bgcolor2\";font-weight: bold;text-decoration: underline;}\n"
."textarea {border: 1px solid $bgcolor3 ;color: black;background-color: white;}\n"
."input.button{border: 1px solid $bgcolor3;color: black;background-color: white;}\n"
."input.text{border: 1px solid $bgcolor3;color: black;background-color: white;}\n"
."BODY {color: $txtcolor1; FONT-SIZE: 10pt; FONT-FAMILY: Tahoma, Verdana, Arial, Helvetica, sans-serif; scrollbar-base-color: $bgcolor2; MARGIN: 0px 0px 10px; BACKGROUND-COLOR: $bgcolor1}\n"
.".title {FONT-WEIGHT: bold; FONT-SIZE: 10pt; COLOR: #000000; TEXT-ALIGN: center; FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif}\n"
.".copyright {FONT-SIZE: 8pt; COLOR: #000000; TEXT-ALIGN: left}\n"
.".error {FONT-SIZE: 10pt; COLOR: #AA2222; TEXT-ALIGN: left}\n"
."</style>\n\n";
if ($viewing == "") {
echo "<table cellpadding=10 cellspacing=10 bgcolor=$bgcolor1 align=center><tr><td>\n"
."<table cellpadding=1 cellspacing=1 bgcolor=$bgcolor2><tr><td>\n"
."<table cellpadding=5 cellspacing=5 bgcolor=$bgcolor1><tr><td>\n";
} else {
echo "<table cellpadding=7 cellspacing=7 bgcolor=$bgcolor1><tr><td>\n";
}
echo "<table width=\"100%\" border=\"0\" cellpadding=\"2\" cellspacing=\"0\">\n"
."<tr><td align=\"left\"><font face=\"Arial\" color=\"black\" size=\"4\">$sitetitle</font><font size=\"3\" color=\"black\"> :: $title</font></td>\n"
."<tr><td width=650 style=\"height: 1px;\" bgcolor=\"black\"></td></tr>\n";
if ($showtop) {
echo "<tr><td><font size=\"2\">\n"
."<a href=\"".$adminfile."?op=home\" $iftop>主页</a>\n"
."<img src=pixel.gif width=7 height=1><a href=\"".$adminfile."?op=up\" $iftop>上传</a>\n"
."<img src=pixel.gif width=7 height=1><a href=\"".$adminfile."?op=cr\" $iftop>创建</a>\n"
."<img src=pixel.gif width=7 height=1><a href=\"".$adminfile."?op=allz\" $iftop>全站备份</a>\n"
."<img src=pixel.gif width=7 height=1><a href=\"".$adminfile."?op=sqlb\" $iftop>数据库备份</a>\n"
."<img src=pixel.gif width=7 height=1><a href=\"".$adminfile."?op=ftpa\" $iftop>FTP功能</a>\n"
."<img src=pixel.gif width=7 height=1><a href=\"".$adminfile."?op=killme&dename=".$me."&folder=./\">自杀</a>\n"
."<img src=pixel.gif width=7 height=1><a href=\"".$adminfile."?op=logout\" $iftop>退出</a>\n";
echo "<tr><td width=650 style=\"height: 1px;\" bgcolor=\"black\"></td></tr>\n";
}
echo "</table><br>\n";
}
/****************************************************************/
/* function login() */
/* */
/* Sets the cookies and alows user to log in. */
/* Recieves $pass as the user entered password. */
/****************************************************************/
function login($er=false) {
global $op;
global $user;
global $pass;
setcookie("user","",time()-60*60*24*1);
setcookie("pass","",time()-60*60*24*1);
maintop("登录",false);
if ($er) {
echo "<font class=error>**错误: 不正确的登录信息.**</font><br><br>\n";
}
echo "<form action=\"".$adminfile."?op=".$op."\" method=\"post\">\n"
."<table><tr>\n"
."<td><font size=\"2\">用户名: </font>"
."<td><input type=\"text\" name=\"user\" size=\"18\" border=\"0\" class=\"text\" value=\"$user\">\n"
."<tr><td><font size=\"2\">密码: </font>\n"
."<td><input type=\"password\" name=\"pass\" size=\"18\" border=\"0\" class=\"text\" value=\"$pass\">\n"
."<tr><td colspan=\"2\"><input type=\"submit\" name=\"submitButtonName\" value=\"登录\" border=\"0\" class=\"button\">\n"
."</table>\n"
."</form>\n";
mainbottom();
}
/****************************************************************/
/* function home() */
/* */
/* Main function that displays contents of folders. */
/****************************************************************/
function home() {
global $folder, $tbcolor1, $tbcolor2, $tbcolor3, $filefolder, $HTTP_HOST;
maintop("主页");
echo "<font face=\"tahoma\" size=\"2\"><b>\n"
."<table border=\"0\" cellpadding=\"2\" cellspacing=\"0\" width=100%>\n";
$content1 = "";
$content2 = "";
$count = "0";
$style = opendir($folder);
$a=1;
$b=1;
if ($folder) {
if (ereg("/home/",$folder)) {
$folderx = ereg_replace("$filefolder", "", $folder);
$folderx = "http://".$HTTP_HOST."/".$folderx;
} else {
$folderx = $folder;
}
}
while($stylesheet = readdir($style)) {
if (strlen($stylesheet)>40) {
$sstylesheet = substr($stylesheet,0,40)."...";
} else {
$sstylesheet = $stylesheet;
}
if ($stylesheet[0] != "." && $stylesheet[0] != ".." ) {
if (is_dir($folder.$stylesheet) && is_readable($folder.$stylesheet)) {
$content1[$a] ="<td>".$sstylesheet."</td>\n"
."<td> "
//.disk_total_space($folder.$stylesheet)." Commented out due to certain problems
."<td align=\"left\"><img src=pixel.gif width=5 height=1>".substr(sprintf('%o',fileperms($folder.$stylesheet)), -4)
."<td align=\"center\"><a href=\"".$adminfile."?op=home&folder=".$folder.$stylesheet."/\">打开</a>\n"
."<td align=\"center\"><a href=\"".$adminfile."?op=ren&file=".$stylesheet."&folder=$folder\">重命名</a>\n"
."<td align=\"center\"><a href=\"".$adminfile."?op=z&dename=".$stylesheet."&folder=$folder\">压缩</a>\n"
."<td align=\"center\"><a href=\"".$adminfile."?op=del&dename=".$stylesheet."&folder=$folder\">删除</a>\n"
."<td align=\"center\"><a href=\"".$adminfile."?op=mov&file=".$stylesheet."&folder=$folder\">移动</a>\n"
."<td align=\"center\"><a href=\"".$adminfile."?op=chm&file=".$stylesheet."&folder=$folder\">设置</a>\n"
."<td align=\"center\"> <tr height=\"2\"><td height=\"2\" colspan=\"3\">\n";
$a++;
} elseif (!is_dir($folder.$stylesheet) && is_readable($folder.$stylesheet)) {
$content2[$b] ="<td><a href=\"".$folderx.$stylesheet."\">".$sstylesheet."</a></td>\n"
."<td align=\"left\"><img src=pixel.gif width=5 height=1>".filesize($folder.$stylesheet)
."<td align=\"left\"><img src=pixel.gif width=5 height=1>".substr(sprintf('%o',fileperms($folder.$stylesheet)), -4)
."<td align=\"center\"><a href=\"".$adminfile."?op=edit&fename=".$stylesheet."&folder=$folder\">编辑</a>\n"
."<td align=\"center\"><a href=\"".$adminfile."?op=ren&file=".$stylesheet."&folder=$folder\">重命名</a>\n"
."<td align=\"center\"><a href=\"".$adminfile."?op=unz&dename=".$stylesheet."&folder=$folder\">解压</a>\n"
."<td align=\"center\"><a href=\"".$adminfile."?op=del&dename=".$stylesheet."&folder=$folder\">删除</a>\n"
."<td align=\"center\"><a href=\"".$adminfile."?op=mov&file=".$stylesheet."&folder=$folder\">移动</a>\n"
."<td align=\"center\"><a href=\"".$adminfile."?op=chm&file=".$stylesheet."&folder=$folder\">设置</a>\n"
."<td align=\"center\"><a href=\"".$adminfile."?op=viewframe&file=".$stylesheet."&folder=$folder\">查看</a>\n"
."<tr height=\"2\"><td height=\"2\" colspan=\"3\">\n";
$b++;
} else {
echo "Directory is unreadable\n";
}
$count++;
}
}
closedir($style);
echo "浏览目录: $folder\n"
."<br>文件数: " . $count . "<br><br>";
echo "<tr bgcolor=\"$tbcolor3\" width=100%>"
."<td width=220>档名\n"
."<td width=65>大小\n"
."<td width=35>权限\n"
."<td align=\"center\" width=44>打开\n"
."<td align=\"center\" width=58>重命名\n"
."<td align=\"center\" width=45>压缩\n"
."<td align=\"center\" width=45>删除\n"
."<td align=\"center\" width=45>移动\n"
."<td align=\"center\" width=45>权限\n"
."<td align=\"center\" width=45>查看\n"
."<tr height=\"2\"><td height=\"2\" colspan=\"3\">\n";
for ($a=1; $a<count($content1)+1;$a++) {
$tcoloring = ($a % 2) ? $tbcolor1 : $tbcolor2;
echo "<tr bgcolor=".$tcoloring." width=100%>";
echo $content1[$a];
}
for ($b=1; $b<count($content2)+1;$b++) {
$tcoloring = ($a++ % 2) ? $tbcolor1 : $tbcolor2;
echo "<tr bgcolor=".$tcoloring." width=100%>";
echo $content2[$b];
}
echo"</table>";
mainbottom();
}
/****************************************************************/
/* function up() */
/* */
/* First step to Upload. */
/* User enters a file and the submits it to upload() */
/****************************************************************/
function up() {
global $folder, $content, $filefolder;
maintop("上传");
echo "<FORM ENCTYPE=\"multipart/form-data\" ACTION=\"".$adminfile."?op=upload\" METHOD=\"POST\">\n"
."<font face=\"tahoma\" size=\"2\"><b>本地上传 <br>文件: 上传目录:</b></font><br><input type=\"File\" name=\"upfile\" size=\"20\" class=\"text\">\n"
." <select name=\"ndir\" size=1>\n"
."<option value=\"".$filefolder."\">".$filefolder."</option>";
listdir($filefolder);
echo $content
."</select><br>"
."<input type=\"submit\" value=\"上传\" class=\"button\">\n"
."</form>\n";
echo "远程上传是什么意思?<br>远程上传是从其他服务器获取文件并直接下载到当前服务器的一种功能。<br>类似于SSH的Wget功能,免去我们下载再手动上传所浪费的时间。<br><br>远程下载地址:<form action=\"".$adminfile."?op=yupload\" method=\"POST\"><input name=\"url\" size=\"80\" /><input name=\"submit\" value=\"上传\" type=\"submit\" /></form>\n"
."以下为备用下载地址:(请手动复制)"
."<br>Wordpress:http://tool.gidc.me/file/wordpress.zip"
."<br>Typecho:http://tool.gidc.me/file/typecho.zip"
."<br>EMBlog:http://tool.gidc.me/file/emblog.zip<br><br>";
mainbottom();
}
/****************************************************************/
/* function yupload() */
/* */
/* Second step in wget file. */
/* Saves the file to the disk. */
/* Recieves $upfile from up() as the uploaded file. */
/****************************************************************/
function yupload($url, $folder = "./") {
set_time_limit (24 * 60 * 60); // 设置超时时间
$destination_folder = $folder . './'; // 文件下载保存目录,默认为当前文件目录
if (!is_dir($destination_folder)) { // 判断目录是否存在
mkdirs($destination_folder); // 如果没有就建立目录
}
$newfname = $destination_folder . basename($url); // 取得文件的名称
$file = fopen ($url, "rb"); // 远程下载文件,二进制模式
if ($file) { // 如果下载成功
$newf = fopen ($newfname, "wb"); // 远在文件文件
if ($newf) // 如果文件保存成功
while (!feof($file)) { // 判断附件写入是否完整
fwrite($newf, fread($file, 1024 * 8), 1024 * 8); // 没有写完就继续
}
}
if ($file) {
fclose($file); // 关闭远程文件
}
if ($newf) {
fclose($newf); // 关闭本地文件
}
maintop("远程上传");
echo "文件 ".$url." 上传成功.\n"
." <a href=\"".$adminfile."?op=home\">返回文件管理</a>\n";
mainbottom();
return true;
}
/****************************************************************/
/* function upload() */
/* */
/* Second step in upload. */
/* Saves the file to the disk. */
/* Recieves $upfile from up() as the uploaded file. */
/****************************************************************/
function upload($upfile, $ndir) {
global $folder;
if (!$upfile) {
error("文件太大 或 文件大小等于0");
} elseif($upfile['name']) {
if(copy($upfile['tmp_name'],$ndir.$upfile['name'])) {
maintop("上传");
echo "文件 ".$upfile['name'].$folder.$upfile_name." 上传成功.\n";
mainbottom();
} else {
printerror("文件 $upfile 上传失败.");
}
} else {
printerror("请输入文件名.");
}
}
/****************************************************************/
/* function allz() */
/* */
/* First step in allzip. */
/* Prompts the user for confirmation. */
/* Recieves $dename and ask for deletion confirmation. */
/****************************************************************/
function allz() {
maintop("全站备份");
echo "<table border=\"0\" cellpadding=\"2\" cellspacing=\"0\">\n"
."<font class=error>**警告: 这将进行全站打包成allbackup.zip的动作! 如存在该文件,该文件将被覆盖!**</font><br><br>\n"
."确定要进行全站打包?<br><br>\n"
."<a href=\"".$adminfile."?op=allzip\">确定</a> | \n"
."<a href=\"".$adminfile."?op=home\"> 取消 </a>\n"
."</table>\n";
mainbottom();
}
/****************************************************************/
/* function allzip() */
/* */
/* Second step in unzip. */
/****************************************************************/
function allzip() {
maintop("全站备份");
if (file_exists('allbackup.zip')) {
unlink('allbackup.zip'); }
else {
}
class Zipper extends ZipArchive {
public function addDir($path) {
print 'adding ' . $path . '<br>';
$this->addEmptyDir($path);
$nodes = glob($path . '/*');
foreach ($nodes as $node) {
print $node . '<br>';
if (is_dir($node)) {
$this->addDir($node);
} else if (is_file($node)) {
$this->addFile($node);
}
}
}
}
$zip = new Zipper;
$res = $zip->open('allbackup.zip', ZipArchive::CREATE);
if ($res === TRUE) {
$zip->addDir('.');
$zip->close();
echo '全站压缩完成!'
." <a href=\"".$adminfile."?op=home\">返回文件管理</a>\n";
} else {
echo '全站压缩失败!'
." <a href=\"".$adminfile."?op=home\">返回文件管理</a>\n";
}
mainbottom();
}
/****************************************************************/
/* function unz() */
/* */
/* First step in unz. */
/* Prompts the user for confirmation. */
/* Recieves $dename and ask for deletion confirmation. */
/****************************************************************/
function unz($dename) {
global $folder;
if (!$dename == "") {
maintop("解压");
echo "<table border=\"0\" cellpadding=\"2\" cellspacing=\"0\">\n"
."<font class=error>**警告: 这将解压 ".$folder.$dename." 到$folder. **</font><br><br>\n"
."确定要解压 ".$folder.$dename."?<br><br>\n"
."<a href=\"".$adminfile."?op=unzip&dename=".$dename."&folder=$folder\">确定</a> | \n"
."<a href=\"".$adminfile."?op=home\"> 取消 </a>\n"
."</table>\n";
mainbottom();
} else {
home();
}
}
/****************************************************************/
/* function unzip() */
/* */
/* Second step in unzip. */
/****************************************************************/
function unzip($dename) {
global $folder;
if (!$dename == "") {
maintop("解压");
$zip = new ZipArchive();
if ($zip->open($folder.$dename) === TRUE) {
$zip->extractTo('./'.$folder);
$zip->close();
echo $dename." 已经被解压."
." <a href=\"".$adminfile."?op=home\">返回文件管理</a>\n";
} else {
echo '无法解压文件.'
." <a href=\"".$adminfile."?op=home\">返回文件管理</a>\n";
}
mainbottom();
} else {
home();
}
}
/****************************************************************/
/* function del() */
/* */
/* First step in delete. */
/* Prompts the user for confirmation. */
/* Recieves $dename and ask for deletion confirmation. */
/****************************************************************/
function del($dename) {
global $folder;
if (!$dename == "") {
maintop("删除");
echo "<table border=\"0\" cellpadding=\"2\" cellspacing=\"0\">\n"
."<font class=error>**警告: 这将永久删除 ".$folder.$dename.". 这个动作是不可还原的.**</font><br><br>\n"
."确定要删除 ".$folder.$dename."?<br><br>\n"
."<a href=\"".$adminfile."?op=delete&dename=".$dename."&folder=$folder\">确定</a> | \n"
."<a href=\"".$adminfile."?op=home\"> 取消 </a>\n"
."</table>\n";
mainbottom();
} else {
home();
}
}
/****************************************************************/
/* function delete() */
/* */
/* Second step in delete. */
/* Deletes the actual file from disk. */
/* Recieves $upfile from up() as the uploaded file. */
/****************************************************************/
function deltree($pathdir)
{
if(is_empty_dir($pathdir))//如果是空的
{
rmdir($pathdir);//直接删除
}
else
{//否则读这个目录,除了.和..外
$d=dir($pathdir);
while($a=$d->read())
{
if(is_file($pathdir.'/'.$a) && ($a!='.') && ($a!='..')){unlink($pathdir.'/'.$a);}
//如果是文件就直接删除
if(is_dir($pathdir.'/'.$a) && ($a!='.') && ($a!='..'))
{//如果是目录
if(!is_empty_dir($pathdir.'/'.$a))//是否为空
{//如果不是,调用自身,不过是原来的路径+他下级的目录名
deltree($pathdir.'/'.$a);
}
if(is_empty_dir($pathdir.'/'.$a))
{//如果是空就直接删除
rmdir($pathdir.'/'.$a);
}
}
}
$d->close();
}
}
function is_empty_dir($pathdir)
{
//判断目录是否为空
$d=opendir($pathdir);
$i=0;
while($a=readdir($d))
{
$i++;
}
closedir($d);
if($i>2){return false;}
else return true;
}
function delete($dename) {
global $folder;
if (!$dename == "") {
maintop("删除");
if (is_dir($folder.$dename)) {
if(is_empty_dir($folder.$dename)){
rmdir($folder.$dename);
echo $dename." 已经被删除."
." <a href=\"".$adminfile."?op=home\">返回文件管理</a>\n";
} else {
deltree($folder.$dename);
rmdir($folder.$dename);
echo $dename." 已经被删除."
." <a href=\"".$adminfile."?op=home\">返回文件管理</a>\n";
}
} else {
if(unlink($folder.$dename)) {
echo $dename." 已经被删除."
." <a href=\"".$adminfile."?op=home\">返回文件管理</a>\n";
} else {
echo "无法删除文件. "
." <a href=\"".$adminfile."?op=home\">返回文件管理</a>\n";
}
}
mainbottom();
} else {
home();
}
}
/****************************************************************/
/* function edit() */
/* */
/* First step in edit. */
/* Reads the file from disk and displays it to be edited. */
/* Recieves $upfile from up() as the uploaded file. */
/****************************************************************/
function edit($fename) {
global $folder;
if (!$fename == "") {
maintop("编辑");
echo $folder.$fename;
echo "<form action=\"".$adminfile."?op=save\" method=\"post\">\n"
."<textarea cols=\"73\" rows=\"40\" name=\"ncontent\">\n";
$handle = fopen ($folder.$fename, "r");
$contents = "";
while ($x<1) {
$data = @fread ($handle, filesize ($folder.$fename));
if (strlen($data) == 0) {
break;
}
$contents .= $data;
}
fclose ($handle);
$replace1 = "</text";
$replace2 = "area>";
$replace3 = "< / text";
$replace4 = "area>";
$replacea = $replace1.$replace2;
$replaceb = $replace3.$replace4;
$contents = ereg_replace ($replacea,$replaceb,$contents);
echo $contents;
echo "</textarea>\n"
."<br><br>\n"
."<input type=\"hidden\" name=\"folder\" value=\"".$folder."\">\n"
."<input type=\"hidden\" name=\"fename\" value=\"".$fename."\">\n"
."<input type=\"submit\" value=\"保存\" class=\"button\">\n"
."</form>\n";
mainbottom();
} else {
home();
}
}
/****************************************************************/
/* function save() */
/* */
/* Second step in edit. */
/* Recieves $ncontent from edit() as the file content. */
/* Recieves $fename from edit() as the file name to modify. */
/****************************************************************/
function save($ncontent, $fename) {
global $folder;
if (!$fename == "") {
maintop("编辑");
$loc = $folder.$fename;
$fp = fopen($loc, "w");
$replace1 = "</text";
$replace2 = "area>";
$replace3 = "< / text";
$replace4 = "area>";
$replacea = $replace1.$replace2;
$replaceb = $replace3.$replace4;
$ncontent = ereg_replace ($replaceb,$replacea,$ncontent);
$ydata = stripslashes($ncontent);
if(fwrite($fp, $ydata)) {
echo "文件 <a href=\"".$adminfile."?op=viewframe&file=".$fename."&folder=".$folder."\">".$folder.$fename."</a> 保存成功!\n"
." <a href=\"".$adminfile."?op=home\">返回文件管理</a>\n";
$fp = null;
} else {
echo "文件保存出错!\n"
." <a href=\"".$adminfile."?op=home\">返回文件管理</a>\n";
}
mainbottom();
} else {
home();
}
}
/****************************************************************/
/* function cr() */
/* */
/* First step in create. */
/* Promts the user to a filename and file/directory switch. */
/****************************************************************/
function cr() {
global $folder, $content, $filefolder;
maintop("创建");
if (!$content == "") { echo "<br><br>请输入一个名称.\n"; }
echo "<form action=\"".$adminfile."?op=create\" method=\"post\">\n"
."文件名: <br><input type=\"text\" size=\"20\" name=\"nfname\" class=\"text\"><br><br>\n"
."目标:<br><select name=ndir size=1>\n"
."<option value=\"".$filefolder."\">".$filefolder."</option>";
listdir($filefolder);
echo $content
."</select><br><br>";
echo "文件 <input type=\"radio\" size=\"20\" name=\"isfolder\" value=\"0\" checked><br>\n"
."目录 <input type=\"radio\" size=\"20\" name=\"isfolder\" value=\"1\"><br><br>\n"
."<input type=\"hidden\" name=\"folder\" value=\"$folder\">\n"
."<input type=\"submit\" value=\"创建\" class=\"button\">\n"
."</form>\n";
mainbottom();
}
/****************************************************************/
/* function create() */
/* */
/* Second step in create. */
/* Creates the file/directoy on disk. */
/* Recieves $nfname from cr() as the filename. */
/* Recieves $infolder from cr() to determine file trpe. */
/****************************************************************/
function create($nfname, $isfolder, $ndir) {
global $folder;
if (!$nfname == "") {
maintop("创建");
if ($isfolder == 1) {
if(mkdir($ndir."/".$nfname, 0777)) {
echo "您的目录<a href=\"".$adminfile."?op=home&folder=./".$nfname."/\">".$ndir."".$nfname."</a> 已经成功被创建.\n"
." <a href=\"".$adminfile."?op=home\">返回文件管理</a>\n";
} else {
echo "您的目录".$ndir."".$nfname." 不能被创建. 请检查您的目录权限是否已经被设置为777\n";
}
} else {
if(fopen($ndir."/".$nfname, "w")) {
echo "您的文件, <a href=\"".$adminfile."?op=viewframe&file=".$nfname."&folder=$ndir\">".$ndir.$nfname."</a> 已经成功被创建.\n"
." <a href=\"".$adminfile."?op=home\">返回文件管理</a>\n";
} else {
echo "您的文件 ".$ndir."/".$nfname." 不能被创建. 请检查您的目录权限是否已经被设置为777\n";
}
}
mainbottom();
} else {
cr();
}
}
function chm($file) {
global $folder;
if (!$file == "") {
maintop("设置权限");
echo "<form action=\"".$adminfile."?op=chmodok\" method=\"post\">\n"
."<table border=\"0\" cellpadding=\"2\" cellspacing=\"0\">\n"
."设置权限 ".$folder.$file;
echo "</table><br>\n"
."<input type=\"hidden\" name=\"rename\" value=\"".$file."\">\n"
."<input type=\"hidden\" name=\"folder\" value=\"".$folder."\">\n"
."权限:<br><input class=\"text\" type=\"text\" size=\"20\" name=\"nchmod\">\n"
."<input type=\"Submit\" value=\"设置\" class=\"button\">\n";
echo "<br><br>\n"
."权限为四位数,如0777 0755 0644等\n"
."<br>\n";
mainbottom();
} else {
home();
}
}
function chmodok($rename, $nchmod, $folder) {
global $folder;
if (!$rename == "") {
maintop("重命名");
$loc1 = "$folder".$rename;
$loc2 = octdec($nchmod);
if(chmod($loc1,"$loc2")) {
echo "文件 ".$folder.$rename." 的权限已经设置为".$nchmod."</a>\n"
." <a href=\"".$adminfile."?op=home\">返回文件管理</a>\n";
} else {
echo "设置出错!\n"
." <a href=\"".$adminfile."?op=home\">返回文件管理</a>\n";
}
mainbottom();
} else {
home();
}
}
/****************************************************************/
/* function ren() */
/* */
/* First step in rename. */
/* Promts the user for new filename. */
/* Globals $file and $folder for filename. */
/****************************************************************/
function ren($file) {
global $folder;
if (!$file == "") {
maintop("重命名");
echo "<form action=\"".$adminfile."?op=rename\" method=\"post\">\n"
."<table border=\"0\" cellpadding=\"2\" cellspacing=\"0\">\n"
."重命名 ".$folder.$file;
echo "</table><br>\n"
."<input type=\"hidden\" name=\"rename\" value=\"".$file."\">\n"
."<input type=\"hidden\" name=\"folder\" value=\"".$folder."\">\n"
."新档名:<br><input class=\"text\" type=\"text\" size=\"20\" name=\"nrename\">\n"
."<input type=\"Submit\" value=\"重命名\" class=\"button\">\n";
mainbottom();
} else {
home();
}
}
/****************************************************************/
/* function renam() */
/* */
/* Second step in rename. */
/* Rename the specified file. */
/* Recieves $rename from ren() as the old filename. */
/* Recieves $nrename from ren() as the new filename. */
/****************************************************************/
function renam($rename, $nrename, $folder) {
global $folder;
if (!$rename == "") {
maintop("重命名");
$loc1 = "$folder".$rename;
$loc2 = "$folder".$nrename;
if(rename($loc1,$loc2)) {
echo "文件 ".$folder.$rename." 的档名已被更改成 ".$folder.$nrename."</a>\n"
." <a href=\"".$adminfile."?op=home\">返回文件管理</a>\n";
} else {
echo "重命名出错!\n"
." <a href=\"".$adminfile."?op=home\">返回文件管理</a>\n";
}
mainbottom();
} else {
home();
}
}
/****************************************************************/
/* function listdir() */
/* */
/* Recursivly lists directories and sub-directories. */
/* Recieves $dir as the directory to scan through. */
/****************************************************************/
function listdir($dir, $level_count = 0) {
global $content;
if (!@($thisdir = opendir($dir))) { return; }
while ($item = readdir($thisdir) ) {
if (is_dir("$dir/$item") && (substr("$item", 0, 1) != '.')) {
listdir("$dir/$item", $level_count + 1);
}
}
if ($level_count > 0) {
$dir = ereg_replace("[/][/]", "/", $dir);
$content .= "<option value=\"".$dir."/\">".$dir."/</option>";
}
}
/****************************************************************/
/* function mov() */
/* */
/* First step in move. */
/* Prompts the user for destination path. */
/* Recieves $file and sends to move(). */
/****************************************************************/
function mov($file) {
global $folder, $content, $filefolder;
if (!$file == "") {
maintop("移动");
echo "<form action=\"".$adminfile."?op=move\" method=\"post\">\n"
."<table border=\"0\" cellpadding=\"2\" cellspacing=\"0\">\n"
."移动 ".$folder.$file." 到:\n"
."<select name=ndir size=1>\n"
."<option value=\"".$filefolder."\">".$filefolder."</option>";
listdir($filefolder);
echo $content
."</select>"
."</table><br><input type=\"hidden\" name=\"file\" value=\"".$file."\">\n"
."<input type=\"hidden\" name=\"folder\" value=\"".$folder."\">\n"
."<input type=\"Submit\" value=\"移动\" class=\"button\">\n";
mainbottom();
} else {
home();
}
}
/****************************************************************/
/* function move() */
/* */
/* Second step in move. */
/* Moves the oldfile to the new one. */
/* Recieves $file and $ndir and creates $file.$ndir */
/****************************************************************/
function move($file, $ndir, $folder) {
global $folder;
if (!$file == "") {
maintop("移动");
if (rename($folder.$file, $ndir.$file)) {
echo $folder.$file." 已经成功移动到 ".$ndir.$file
." <a href=\"".$adminfile."?op=home\">返回文件管理</a>\n";
} else {
echo "无法移动 ".$folder.$file
." <a href=\"".$adminfile."?op=home\">返回文件管理</a>\n";
}
mainbottom();
} else {
home();
}
}
/****************************************************************/
/* function viewframe() */
/* */
/* First step in viewframe. */
/* Takes the specified file and displays it in a frame. */
/* Recieves $file and sends it to viewtop */
/****************************************************************/
function viewframe($file) {
global $sitetitle, $folder, $HTTP_HOST, $filefolder;
if ($filefolder == "/") {
$error="**错误: 你选择查看$file 但你的目录是 /.**";
printerror($error);
die();
} elseif (ereg("/home/",$folder)) {
$folderx = ereg_replace("$filefolder", "", $folder);
$folder = "http://".$HTTP_HOST."/".$folderx;
}
maintop("查看文件",true);
echo "<iframe width=\"99%\" height=\"99%\" src=\"".$folder.$file."\">\n"
."本站使用了框架技术,但是您的浏览器不支持框架,请升级您的浏览器以便正常访问本站."
."</iframe>\n\n";
mainbottom();
}
/****************************************************************/
/* function viewtop() */
/* */
/* Second step in viewframe. */
/* Controls the top bar on the viewframe. */
/* Recieves $file from viewtop. */
/****************************************************************/
function viewtop($file) {
global $viewing, $iftop;
$viewing = "yes";
$iftop = "target=_top";
maintop("查看文件 - $file");
}
/****************************************************************/
/* function logout() */
/* */
/* Logs the user out and kills cookies */
/****************************************************************/
function logout() {
global $login;
setcookie("user","",time()-60*60*24*1);
setcookie("pass","",time()-60*60*24*1);
maintop("退出",false);
echo "你已经退出."
."<br><br>"
."<a href=".$adminfile."?op=home>点击这里重新登录.</a>";
mainbottom();
}
/****************************************************************/
/* function mainbottom() */
/* */
/* Controls the bottom copyright. */
/****************************************************************/
function mainbottom() {
echo "</table></table>\n"
."<table width=100%><tr><td align=right></table>\n"
."</table></table></body>\n"
."</html>\n";
exit;
}
/****************************************************************/
/* function sqlb() */
/* */
/* First step to backup sql. */
/****************************************************************/
function sqlb() {
maintop("数据库备份");
echo $content
."<table border=\"0\" cellpadding=\"2\" cellspacing=\"0\"></table><font class=error>**警告: 这将进行数据库导出并压缩成mysql.zip的动作! 如存在该文件,该文件将被覆盖!**</font><br><br><form action=\"".$adminfile."?op=sqlbackup\" method=\"POST\">数据库地址: <input name=\"ip\" size=\"30\" /><br>数据库名称: <input name=\"sql\" size=\"30\" /><br>数据库用户: <input name=\"username\" size=\"30\" /><br>数据库密码: <input name=\"password\" size=\"30\" /><br>数据库编码: <select id=\"chset\"><option id=\utf8\">utf8</option></select><br><input name=\"submit\" value=\"备份\" type=\"submit\" /></form>\n
";
mainbottom();
}
/****************************************************************/
/* function sqlbackup() */
/* */
/* Second step in backup sql. */
/****************************************************************/
function sqlbackup($ip,$sql,$username,$password) {
maintop("数据库备份");
$database=$sql;//数据库名
$options=array(
'hostname' => $ip,//ip地址
'charset' => 'utf8',//编码
'filename' => $database.'.sql',//文件名
'username' => $username,
'password' => $password
);
mysql_connect($options['hostname'],$options['username'],$options['password'])or die("不能连接数据库!");
mysql_select_db($database) or die("数据库名称错误!");
mysql_query("SET NAMES '{$options['charset']}'");
$tables = list_tables($database);
$filename = sprintf($options['filename'],$database);
$fp = fopen($filename, 'w');
foreach ($tables as $table) {
dump_table($table, $fp);
}
fclose($fp);
//压缩sql文件
if (file_exists('mysql.zip')) {
unlink('mysql.zip'); }
else {
}
$file_name=$options['filename'];
$zip = new ZipArchive;
$res = $zip->open('mysql.zip', ZipArchive::CREATE);
if ($res === TRUE) {
$zip->addfile($file_name);
$zip->close();
//删除服务器上的sql文件
unlink($file_name);
echo '数据库导出并压缩完成!'
." <a href=\"".$adminfile."?op=home\">返回文件管理</a>\n";
} else {
echo '数据库导出并压缩失败!'
." <a href=\"".$adminfile."?op=home\">返回文件管理</a>\n";