-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathfileadmin.php
1879 lines (1736 loc) · 77.9 KB
/
fileadmin.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 $PASSWORD="TYPE-YOUR-PASSWORD-HERE"; $VERSION=7.15;
/* 设置不进行报错以免影响运行 */
error_reporting(0);
/* 扫描目录下全部文件函数 */
function scandirAll($dir,$first=false){
$files = [];
$child_dirs = scandir($dir);
foreach($child_dirs as $child_dir){if($child_dir != '.' && $child_dir != '..'){
if(is_dir($dir."/".$child_dir)){$files=array_merge($files,scandirAll($dir."/".$child_dir));}
else{array_push($files,$dir."/".$child_dir);}
}}
return $files;
}
/* 打包目录函数 */
function create_zip($files=array(),$destination='',$overwrite=false){
if(file_exists($destination)&&!$overwrite){return false;}
$valid_files=array();
if(is_array($files)){foreach($files as $file){if(file_exists($file)&&!is_dir($file)){$valid_files[]=$file;}}}
if(count($valid_files)) {
$zip = new ZipArchive();
if($zip->open($destination,$overwrite ? ZIPARCHIVE::OVERWRITE : ZIPARCHIVE::CREATE) !== true){return false;}
foreach($valid_files as $file){$zip->addFile($file,$file);}
$zip->close();
return file_exists($destination);
}else{return false;}
}
/* 解包.zip文件函数 */
function unzip_file(string $zipName,string $dest){
if(!is_file($zipName)){return '1003';}
if(!is_dir($dest)){return '1002';}
else{
$zip=new ZipArchive();
if($zip->open($zipName)){
$zip->extractTo($dest);
$zip->close();
return '200';
}else{return '1001';}
}
}
/* 删除目录函数 */
function unlinkDir($dir){
$files=scandir($dir);
foreach ($files as $key => $filename) {
if($filename!="."&&$filename!=".."){
if(is_dir($dir."/".$filename)){unlinkDir($dir."/".$filename);}else{unlink($dir."/".$filename);}
}
}
rmdir($dir);
}
/* 支持同时创建多层目录函数 */
function nbMkdir($pathname){
$paths = explode("/", $pathname);
$nowp = "";
foreach($paths as $key=>$value) {
$nowp .= $value . "/";
if ($value == "." || $value == ".." || $value == "") continue;
mkdir($nowp);
}
}
/* 复制文件(夹)函数 */
function copyDir($from,$to){
if(!is_dir($to)){nbMkdir($to);}
echo $from."|md|".$to.PHP_EOL;
$currDir=$from;
$currFiles=scandir($currDir);
foreach($currFiles as $filename){
if($filename!="."&&$filename!=".."){
$trueFileName=$currDir.$filename;
if(is_dir($trueFileName)){copyDir($trueFileName.'/',$to.$filename.'/');}
else{copy($trueFileName,$to.$filename);}
}
}
}
/* 计算目录体积函数 */
function dirsize($dir){
@$dh=opendir($dir);$size=0;
while($file = @readdir($dh)){
if($file!="." && $file!=".."){
$path = $dir."/".$file;
if (is_dir($path)){$size+=dirsize($path);}elseif(is_file($path)){$size += filesize($path);}
}
}
@closedir($dh);return $size;
}
/* 主体 PHP 操作 */
$ACT=$_POST["a"];$PWD=$_POST["pwd"];
if($ACT){
/* 进行登录 */
if($ACT=="login"){
if($_POST["loginPwd"]==$PASSWORD){echo "200||".password_hash($PASSWORD.date("Ymd"),PASSWORD_DEFAULT);}else{echo "1001";}
/* 如果密码验证成功 */
}elseif(password_verify($PASSWORD.date("Ymd"),$PWD)){
/* 页面加载时验证状态,密码正确时始终返回成功 */
if($ACT=="check"){
echo "200";
/* 返回指定目录的文件列表 */
}elseif($ACT=="files"){
/* 阻止用户访问上级目录 */
if(strstr($_POST["name"],"./")){
echo "1002";
/* 如果请求过来的文件夹存在,则输出内容 */
}elseif(is_dir(".".$_POST["name"])){
$fileArray=scandir(".".$_POST["name"]);
$fileArrayModified=[];
/* 先输出目录列表 */
foreach($fileArray as $filename){
$fileisdir=is_dir(".".$_POST["name"].$filename);
if($fileisdir){
$filesize=0;
array_push($fileArrayModified,array("name"=>$filename,"dir"=>$fileisdir,"size"=>$filesize));
}
}
/* 再输出文件列表 */
foreach($fileArray as $filename){
$fileisdir=is_dir(".".$_POST["name"].$filename);
if(!$fileisdir){
$filesize=filesize(".".$_POST["name"].$filename)/1024;
array_push($fileArrayModified,array("name"=>$filename,"dir"=>$fileisdir,"size"=>$filesize));
}
}
/* 此处遍历两次是要按顺序输出,先目录再文件夹,便于管理+美观 */
echo "200||".rawurlencode(json_encode($fileArrayModified));
}else{
echo "1001";
}
/* 输出textEditor需要的文本内容 */
}elseif($ACT=="getfile"){
/* 此处为js加密适配,如果请求的文件有同名的.fajs文件存在,则输出.fajs中没加密的内容便于用户进行编辑,如果没有就直接输出原文件内容 */
if(file_exists(".".$_POST["name"].".fajs")){echo file_get_contents(".".$_POST["name"].".fajs");}else{echo file_get_contents(".".$_POST["name"]);}
/* 使用textEditor保存普通文件 */
}elseif($ACT=="save"){
file_put_contents(".".$_POST["name"],$_POST["data"]);
/* 这里如果有同名fajs文件则进行删除,因为这个方法是没有加密时进行的,如果fajs不删,下次输出的还是老的fajs文件就对不上了 */
if(file_exists(".".$_POST["name"].".fajs")){unlink(".".$_POST["name"].".fajs");}
if(file_exists(".".$_POST["name"]) && file_get_contents(".".$_POST["name"]) == $_POST["data"]){echo "200";}else{echo "1002";}
/* 使用textEditor保存加密的js文件,这里会存俩文件,fa本身没有解密js的能力所以原文件一定要存一份 */
}elseif($ACT=="fajssave"){
/* 这里原文件存进同名fajs,加密文件存进js,这样方便管理而且用不着用户自己去改资源地址 */
file_put_contents(".".$_POST["name"],$_POST["obfuscate"]);
file_put_contents(".".$_POST["name"].".fajs",$_POST["original"]);
if(file_exists((".".$_POST["name"])) && file_get_contents(".".$_POST["name"]) == $_POST["obfuscate"] && file_get_contents(".".$_POST["name"].".fajs") == $_POST["original"]){echo "200";}else{echo "1002";}
/* 对当前目录进行打包 */
}elseif($ACT=="zip"){
$zipResult=create_zip(scandirAll(realpath(".".$_POST["name"]),true),".".$_POST["name"]."FileAdmin_".time().".zip",false);
if($zipResult){echo "200";}else{echo "1001";}
/* 解包压缩包 */
}elseif($ACT=="unzip"){
echo unzip_file(".".$_POST["name"],".".$_POST["dir"],false);
/* 新建目录 */
}elseif($ACT=="mkdir"){
mkdir(".".$_POST["name"]);
if(file_exists(".".$_POST["name"])){echo "200";}else{echo "1002";}
/* 给文件(夹)改名 */
}elseif($ACT=="rename"){
/* 这里判断一下是不是存在同名的文件,否则就直接覆盖掉了,寄 */
if(!file_exists(".".$_POST["dir"].$_POST["new"])){
rename(".".$_POST["dir"].$_POST["old"],".".$_POST["dir"].$_POST["new"]);
if(file_exists(".".$_POST["dir"].$_POST["new"])){
echo "200";
}else{
echo "1003";
}
}else{
echo "1002";
}
/* 删除文件(夹) */
}elseif($ACT=="del"){
$delFiles=json_decode(rawurldecode($_POST["files"]));
foreach($delFiles as $filename){
$trueFileName=".".$_POST["dir"].$filename;
/* 这里进行判断,如果是文件就直接干掉,是目录就用上面的unlinkDir干掉 */
if(is_dir($trueFileName)){unlinkDir($trueFileName);}else{unlink($trueFileName);}
if(file_exists($trueFileName)){echo "1";}
}
echo "200";
/* 检查本体更新 */
}elseif($ACT=="chkupd"){
/* 从我站api服务获取最新版本,如果和当前版本不同就弹更新 */
$latest=file_get_contents("https://api.simsoft.top/fileadmin/latest/?stamp=".time());
if($latest && $latest!=$VERSION){
/* 获取这次版本的内容 */
$updinfo=file_get_contents("https://api.simsoft.top/fileadmin/updateinfo/?stamp=".time());
if($updinfo){
echo $updinfo;
}else{echo "1002";}
}else{echo "1001";}
/* 应用版本更新 */
}elseif($ACT=="applyversion"){
/* 先从我站下载一个FileAdminUpdater.php用于替换主文件,因为自己更新本体试了会出问题 */
$updater=file_get_contents("https://api.simsoft.top/fileadmin/updater/?stamp=".time());
if($updater){
file_put_contents("./FileAdminUpdater.php",$updater);
header("location: ./FileAdminUpdater.php?famain=".end(explode("/",$_SERVER['PHP_SELF'])));
/* 进行一下重定向,更新完updater会自删,基本没有安全隐患 */
}else{echo "1001";}
/* 进行文件复制 */
}elseif($ACT=="copy"){
$operateFiles=json_decode(rawurldecode($_POST["files"]));
foreach($operateFiles as $filename){
$fromfile=".".$_POST["from"].$filename;
$tofile=".".$_POST["to"].$filename;
if(is_dir($fromfile)){copyDir($fromfile.'/',".".$_POST["to"].$filename."/");}else{copy($fromfile,$tofile);}
}
/* 进行文件移动,这个比较简单直接遍历rename就完了 */
}elseif($ACT=="move"){
$operateFiles=json_decode(rawurldecode($_POST["files"]));
foreach($operateFiles as $filename){
$fromfile=".".$_POST["from"].$filename;
$tofile=".".$_POST["to"].$filename;
rename($fromfile,$tofile);
}
/* 通过文件内容搜索文件 */
}elseif($ACT=="find_by_content"){
$trueDirName=".".implode("/",explode("/",$_POST["dir"]));
$filelist=scandirAll($trueDirName);
$searchedFiles=[];
/* 这个地方设置用户填的文件类型,空格分隔的;用textFile这个名字是因为初期只能搜索文本后来懒得改变量名了 */
$textFiles=explode(" ",$_POST["type"]);
/* 文件列表进行遍历 */
foreach($filelist as $filenameFound){
/* 如果post过来type是空的(即用户想搜索所有类型的文件),或者文件类型在允许列表里边,就进行处理,否则不输出 */
if($_POST["type"]=='' || in_array(strtolower(end(explode(".",$filenameFound))),$textFiles)){
$filedata=file_get_contents($filenameFound);
/* 判断文件内容里是否含搜的东西,case用于指定大小写 */
if($_POST["case"]=="1"){$fileInNeed=strstr($filedata,$_POST["find"]);}else{$fileInNeed=stristr($filedata,$_POST["find"]);}
/* 如果文件符合就push到输出的内容里 */
if($fileInNeed){array_push($searchedFiles,str_replace("./","/",$filenameFound));}
}
}
echo "200||".rawurlencode(json_encode($searchedFiles));
/* 通过文件名搜索文件,工作原理和上面的完全一致就不写注释了 */
}elseif($ACT=="find_by_name"){
$trueDirName=".".implode("/",explode("/",$_POST["dir"]));
$filelist=scandirAll($trueDirName);
$textFiles=explode(" ",$_POST["type"]);
$searchedFiles=[];
foreach($filelist as $filenameFound){
if($_POST["type"]=='' || in_array(strtolower(end(explode(".",$filenameFound))),$textFiles)){
if($_POST["case"]=="1"){$fileInNeed=strstr($filenameFound,$_POST["find"]);}else{$fileInNeed=stristr($filenameFound,$_POST["find"]);}
if($fileInNeed){array_push($searchedFiles,str_replace("./","/",$filenameFound));}
}
}
echo "200||".rawurlencode(json_encode($searchedFiles));
/* 进行文件替换,工作原理也差不多 */
}elseif($ACT=="replace"){
$trueDirName=".".implode("/",explode("/",$_POST["dir"]));
$filelist=scandirAll($trueDirName);
$replaceCount=0;
$textFiles=explode(" ",$_POST["type"]);
foreach($filelist as $filenameFound){
if($_POST["type"]=='' || in_array(strtolower(end(explode(".",$filenameFound))),$textFiles)){
$filedata=file_get_contents($filenameFound);
$fileInNeed=strstr($filedata,$_POST["find"]);
if($fileInNeed){
$replaceCount++;
$newFiledata=str_replace($_POST["find"],$_POST["replace"],$filedata);
file_put_contents($filenameFound,$newFiledata);
}
}
}
echo "200||".$replaceCount;
/* 获取当前目录的占用信息 */
}elseif($ACT=="space"){
if(is_dir(".".$_POST["name"])){
$total=disk_total_space(".".$_POST["name"]);
$free=disk_free_space(".".$_POST["name"]);
$used=$total-$free;
$current=dirsize(".".$_POST["name"]);
echo "200||".$total."||".$free."||".$used."||".$current;
}else{echo "1001";}
}
}else{echo "1000";}
/* 下载文件 */
}elseif(password_verify($PASSWORD.date("Ymd"),$_GET["pwd"]) && $_GET["a"]=="down"){
/* 指定大小以便浏览器显示进度条,但是大文件还是会玄学失效,原因未知 */
header("content-length: ".filesize(".".$_GET["name"]));
/* 要求浏览器下载文件 */
header("content-disposition: attachment;filename=".rawurlencode(end(explode("/",$_GET["name"]))));
echo file_get_contents(".".$_GET["name"]);
/* 上传文件 */
}elseif(password_verify($PASSWORD.date("Ymd"),$_GET["pwd"]) && $_GET["a"]=="upload"){
$destDir=".".$_GET["dir"];
if(!is_dir($destDir)){nbMkdir($destDir);}
if(file_exists($destDir.$_FILES["file"]["name"])){echo "1002";}else{
move_uploaded_file($_FILES["file"]["tmp_name"],$destDir.$_FILES["file"]["name"]);
if(file_exists($destDir.$_FILES["file"]["name"])){echo "200";}else{echo "1001";}
}
/* 在加载时获取版本信息 */
}elseif($_GET["a"]=="ver"){
$latest=file_get_contents("https://api.simsoft.top/fileadmin/latest/?stamp=".time());
if($latest && $latest!=$VERSION){echo "1001";}else{echo "v".$VERSION;}
}elseif($_GET["a"]=="css"){
header("content-type: text/css");
?>/* <style> */
#passwordManagerUsername{display:none}
*{box-sizing:border-box;}
body{margin:0;user-select:none;margin-top:45px;font-family:微软雅黑;background:#f5f5f5;min-height:100%;}
::-webkit-scrollbar{display:none;}
.title{position:fixed;top:0;left:0;right:0;height:fit-content;box-shadow:0 0 5px 0 rgba(0,0,0,.4);height:40px;background:white;z-index:5;vertical-align:top;}
.appName{font-size:1.5em;position:absolute;top:0;height:fit-content;bottom:0;left:10px;margin:auto}
.appName b{color:#1e9fff;}
#versionNote{border-radius:10px 10px 10px 0;background:#f5f5f5;display:inline-block;margin-left:5px;color:#ababab;padding:0 5px;font-size:.4em;vertical-align:top}
#versionNote.active{background:#1e9fff;color:white}
.title #logoutBtn{position:absolute;top:0;bottom:0;right:35px;margin:auto;transform:rotate(180deg)}
.title #skinBtn{position:absolute;top:0;bottom:0;right:10px;margin:auto;}
.module{display:none;background:white;}
.module.shown{display:block;animation:showModule .3s ease;}
.loading, .texteditor.shown{animation:none!important;}
@keyframes showModule{from{transform:translateY(15px);opacity:0;}to{transform:none;opacity:1;}}
.login{text-align:center;position:fixed;inset:0;margin:auto;padding:10px;height:fit-content;width:fit-content;background:white;border-radius:5px;}
.loginTitle{font-size:1.7em;margin-bottom:10px;}
#loginPassword{vertical-align:middle;height:35px;border-radius:5px 0 0 5px;border:0;outline:none;padding:5px;border:1px solid rgba(0,0,0,.1);border-right:0;transition:border .2s;}
#loginPassword:focus{border:1px solid #1e9fff;border-right:0;}
.loginBtn{transition:all .2s;height:35px;width:35px;vertical-align:middle;outline:none;border:0;border-radius:0 5px 5px 0;background:#1e9fff;color:white;font-size:1.2em;}
.loginBtn:hover{background:#0092ff;}
.loginBtn:active{color:#bae2ff;}
.addressBar{margin-top:5px;border-radius:5px;background:white;overflow:hidden;display:inline-block;text-align:left;max-width:500px;width:100%}
.addressBar button{font-weight:bold;width:30px;height:32px;border:0;outline:0;background:transparent;border-right:1px solid #f5f5f5;vertical-align:middle;}
.addressBar button:hover{background:rgba(0,0,0,.09);}
.addressBar button:active{background:rgba(0,0,0,.12);}
.addressBar div{vertical-align:middle;display:inline-block;width:calc(100% - 60px);padding:0 10px;overflow-x:scroll;white-space:nowrap}
.files,.search{margin:10px;background:transparent;text-align:center;}
#fileList,#searchOptnArea,#searchResult{margin-top:5px;border-radius:5px;background:white;overflow:hidden;margin-bottom:10px;display:inline-block;text-align:left;max-width:500px;width:100%}
#searchOptnArea{margin-bottom:0;}
#fileList center{padding:30px 0;opacity:.6}
#fileList .file,#searchResult .file{padding:10px;text-align:center;}
#fileList .file:hover,#searchResult .file:hover{background:rgba(0,0,0,.09);}
#fileList .file:active,#searchResult .file:active{background:rgba(0,0,0,.12)}
.file .fileIco{display:inline-block;margin-right:5px;width:23px;height:23px;vertical-align:middle}
.file.selected[data-isdir^=true] .fileIco{fill:black;}
.file.selected .fileIco{filter:invert(1)}
#fileList .file .fileName,#searchResult .fileName{display:inline-block;width:calc(100% - 135px);text-align:left;vertical-align:middle;font-size:1.1em;overflow:hidden;white-space:nowrap;text-overflow:ellipsis}
#searchResult .fileName{width:calc(100% - 40px);}
#fileList .file .size{display:inline-block;width:90px;text-align:right;vertical-align:middle;opacity:.5;}
#fileList .file[data-isdir^=true] .size{opacity:0;}
#fileList .file.selected{background:#1e9fff;color:white;}
.texteditor{margin:10px;}
#textEditor{position:absolute;top:40px;left:0;right:0;height:calc(100% - 40px);}
#textEditor *::-webkit-scrollbar{display:block;width:3px;height:0px;background:#ebebeb;}
#textEditor *::-webkit-scrollbar:hover{width:15px}
#textEditor *::-webkit-scrollbar-thumb{border-radius:2px;background:#bababa;}
contextmenukey{display:none;}
contextmenu{z-index:30;position:fixed;border:1px solid #c1c1c1;width:150px;height:fit-content;background:white;overflow:hidden;box-shadow:1px 1px 2px 0 rgba(0,0,0,.2);}
contextmenu button{outline:none;display:block;border:0;padding:5px 10px;background:white;width:100%;text-align:left;position:relative;}
contextmenu button:hover{background:rgba(0,0,0,.05);}
contextmenu button:active{background:rgba(0,0,0,.1);}
contextmenu button contextmenukey{position:absolute;right:10px;top:0;bottom:0;height:fit-content;margin:auto;display:inline-block;opacity:.5;}
.imgviewer,.vidviewer{background:transparent;}
#vidviewer,#imgviewer{width:calc(100% - 10px);height:calc(100vh - 100px);background:white;margin:5px;border:1px solid rgba(0,0,0,.1);border-radius:5px;object-fit:contain;outline:none;}
.updinfo{margin:10px;padding:10px;}
#updinfo{padding:10px;}
.upload{inset:0;margin:auto;height:fit-content;width:340px;padding:10px;border-radius:5px;position:fixed;overflow:hidden;}
.uploadProgress{height:8px;border-radius:4px;background:#f0f0f0;overflow:hidden;margin:10px 0;}
.uploadText{width:100%;display:block;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
#uploadProgressBar{height:8px;transition:width .2s;background:#1e9fff;width:0;}
.loadingAnimation{position:fixed;inset:0;margin:auto;width:fit-content;height:fit-content;z-index:20}
.loadingAnimationDot{animation:loadingDot .8s linear 0s infinite;font-weight:bold;font-size:2em;display:inline-block;opacity:.1;}
#dot2{animation-delay:.1s!important}
#dot3{animation-delay:.2s!important}
#searchAddrBar{padding:5px;overflow-x:scroll;white-space:nowrap}
#searchOptnArea div span{width:100px;display:inline-block;vertical-align:middle;padding:5px;}
#searchOptnArea div input,#searchOptnArea div select{background:white;padding:3px;padding-left:0;display:inline-block;vertical-align:middle;width:calc(100% - 105px);border:0;border-bottom:1px solid #f5f5f5;outline:none;}
#searchOptnArea div input{padding-left:5px;}
#filesUploadInputContainer{display:none;position:fixed;inset:0;background:rgba(100,100,100,.5);z-index:30;}
#filesUploadInputContainer div{width:250px;height:fit-content;inset:0;margin:auto;position:fixed;padding:20px;border-radius:10px;text-align:center;border:2px dotted white;color:white}
#filesUploadInputContainer span{display:block;font-size:2em;}
#filesUploadInputContainer input{position:fixed;inset:0;width:100%;height:100%;opacity:0;}
@media screen and (max-width:700px) {
.mobileInputAdded #mobileFastInput{bottom:0;}
.mobileInputAdded .menu.shown{bottom:40px}
.mobileInputAdded .title{display:none}
.mobileInputAdded #textEditor{top:0px}
}
#mobileFastInput{position:fixed;bottom:-90px;height:40px;background:white;text-align:center;z-index:15;transition:top .2s;width:100vw;margin:auto;padding:5px 0;}
.mobileInputBtn.mode{background:#fafafa}
.mobileInputBtn{display:inline-block;border-radius:5px;padding:5px 2px;}
#fastInputHtm .mobileInputBtn{width:calc(100% / 8 - 5px);}
#fastInputJs .mobileInputBtn{width:calc(100% / 11 - 5px);}
#fastInputCss .mobileInputBtn{width:calc(100% / 9 - 5px);}
.mobileInputBtn:active{background:#eeeeee;}
contextmenu #saveMenuText{display:none}
.menu #saveContextMenuText{display:none}
@keyframes loadingDot{
0%{transform:translateY(0px)}
15%{transform:translateY(10px)}
30%{transform:translateY(-10px)}
45%{transform:translateY(5px)}
60%{transform:translateY(5px)}
75%{transform:translateY(0)}
}
@media screen and (min-width:701px) {
.menu{top:-30px;transition:top .2s,opacity .2s;opacity:0;position:fixed;z-index:20;right:65px;left:150px;height:24px;text-align:right;}
.menu button{outline:none;border:0;background:#f5f5f5;height:100%;width:45px;border-radius:5px;margin-left:5px;}
.menu button.big{width:70px}
.menu button:hover{background:#f9f9f9}
.menu button:active{background:#f0f0f0}
.menu.shown{top:8px;opacity:1;}
}
@media screen and (max-width:700px) {
body{margin-bottom:50px;}
.menu{bottom:-35px;transition:bottom .2s;box-shadow:0 0 5px 0 rgba(0,0,0,.4);background:white;position:fixed;z-index:10;right:0;left:0;height:30px;text-align:center;overflow-y:scroll;white-space:nowrap}
.menu button{outline:none;border:0;height:100%;width:fit-content;background:transparent;width:30px;padding:0;}
.menu button.big{width:60px}
.menu.shown{bottom:0;}
#textEditor{height:calc(100% - 70px)}
}
.skin{margin:5px;padding:10px;border-radius:5px;}
#themeMain{text-align:center;}
.themeBox{width:300px;background:#f5f5f5;padding:5px;display:inline-block;border-radius:5px;margin:5px;}
.themeBox img{width:100%;height:200px;object-fit:cover;border-radius:5px;}
.themeBox div,.themeBox span{display:block;width:100%;overflow:hidden;white-space:nowrap;text-overflow:ellipsis;text-align:left;}
.themeBox div{font-size:1.2em;}
.themeBox span{opacity:.6;}
.themeBox.selected{background:#1e9fff;color:white;}
.themeBox.selected div::before{content:"✓ "}
/* </style> */
<?php }elseif($_GET["a"]=="js"){header("content-type: text/javascript"); ?>
/* <script> */
/* ==================== 初始化+部分公用函数实现 ==================== */
/* 加载时进行初始化 */
window.onload = function() {
/* 如果url后面有设定目录,就按目录来,否则默认打开根目录,主要用于提升使用中刷新页面后的体验 */
if (location.href.split("#")[1]) {
newdirn = location.href.split("#")[1];
if (newdirn.split("")[0] != "/") {
newdirn = "/" + newdirn;
}
if (newdirn.split("")[newdirn.split("").length - 1] != "/") {
newdirn = newdirn + "/";
}
dirOperating = newdirn;
} else {
dirOperating = "/";
}
/* 设定一些需要的变量 */
forwardFromConfirm = false;
fileHoverSelecting = false;
uploadNotFinished = false;
moveOrCopyMode = null;
/* 检查当前是否登录状态 */
request("check", null, function() {
loadFileList(dirOperating, true);
history.replaceState({
"mode": "fileList",
"dir": dirOperating
}, document.title)
});
/* 设置文件拖过事件 */
document.documentElement.ondragover=function(){
if($(".files.shown")){
ID("filesUploadInputContainer").style.display="block";
}
};
/* 在首次用非Chromium浏览器访问时弹出兼容性提示(官网和视频都明确说明仅兼容Chromium,别的浏览器没试过) */
if (navigator.userAgent.indexOf("Chrome") == -1 && !localStorage.getItem("FileAdmin_Settings_BrowserAlert")) {
alert("FileAdmin 目前仅兼容 Google Chrome 和 Microsoft Edge 的最新版本,使用其他浏览器访问可能导致未知错误。");
localStorage.setItem("FileAdmin_Settings_BrowserAlert", "0");
}
/* 这个是让浏览器保存密码时可以给他一个默认的用户名,否则浏览器会存进去一个“无用户名”,容易被别的密码覆盖掉,用户体验消失 */
ID("passwordManagerUsername").value = "FileAdmin(" + location.host + ")";
/* 加载时检察更新,有更新的话版本标识就变蓝+提示 */
fetch("?a=ver").then(function(d) {
return d.text()
}).then(function(d) {
if (d == "1001") {
ID("versionNote").innerText = "点击更新";
ID("versionNote").classList.add("active")
} else {
ID("versionNote").innerText = d;
}
}).catch(function(err) {
ID("versionNote").innerText = "出错"
});
/* 处理用户前进、后退的事件 */
window.onpopstate = function() {
if (!forwardFromConfirm) {
if ($(".texteditor.shown")) {
if (textEditor.getValue() != lastSaveContent && !confirm("您有内容还没有保存哦,确实要退出嘛?")) {
forwardFromConfirm = true;
history.forward();
return;
}
}
if ($(".upload.shown") && uploadNotFinished) {
history.forward()
} else {
let state = event.state;
if (state && state.mode) {
let mode = state.mode;
if (mode == "fileList") {
dirOperating = state.dir;
loadFileList(dirOperating, true)
} else {
history.back();
}
}
}
} else {
forwardFromConfirm = false;
}
};
/* 初始化颜色设定 */
if(localStorage.FileAdmin_Settings_Theme_Url && localStorage.FileAdmin_Settings_Theme_Url != ""){
let styleEle = document.createElement("link");
styleEle.setAttribute("rel","stylesheet");
styleEle.setAttribute("id","customStylesheet");
styleEle.setAttribute("href",localStorage.FileAdmin_Settings_Theme_Url);
document.body.appendChild(styleEle);
}
};
/* 绑定键盘快捷键 */
window.onkeydown = function() {
if (event.keyCode == 191) {
if ($(".files.shown")) {
editAddressBar();/* 编辑地址栏 */
}
if ($(".login.shown")) {
event.preventDefault();
ID("loginPassword").focus();/* 聚焦登录密码 */
}
} else if ((event.ctrlKey == true || event.metaKey == true) && event.keyCode == 83) {
event.preventDefault();
if ($(".texteditor.shown")) {
saveFile();/* 保存文件 */
}
} else if (event.keyCode == 27) {
if ($(".texteditor.shown")) {
history.back();/* 退出文本编辑器 */
} else if ($(".files.shown")) {
history.back(-1);/* 上级目录 */
}
} else if ((event.ctrlKey == true || event.metaKey == true) && event.keyCode == 65) {
if ($(".files.shown")) {
event.preventDefault();
fileSelected = fileListOperating;
loadFileSelected();/* 全选文件 */
}
} else if (event.keyCode == 46) {
if ($(".files.shown")) {
delFile();/* 删除文件 */
}
} else if ((event.ctrlKey == true || event.metaKey == true) && event.keyCode == 67) {
if ($(".files.shown")) {
setCopyFiles();/* 复制文件 */
}
} else if ((event.ctrlKey == true || event.metaKey == true) && event.keyCode == 88) {
if ($(".files.shown")) {
setMoveFiles();/* 剪切文件 */
}
} else if ((event.ctrlKey == true || event.metaKey == true) && event.keyCode == 86) {
if ($(".files.shown")) {
filePaste();/* 粘贴文件 */
}
} else if (event.keyCode == 116) {
event.preventDefault();
if ($(".files.shown")) {
loadFileList(dirOperating, true);/* 刷新文件列表 */
}
if ($(".texteditor.shown")) {
reloadEditor()/* 刷新编辑器 */
}
} else if (event.keyCode == 113) {
event.preventDefault();
if ($(".files.shown") && fileSelected.length==1) {
renameFile();/* 改名 */
}
}
/* 标题栏星号提示 */
if ($(".texteditor.shown")) {
if(textEditor.getValue() == lastSaveContent){
document.title = fileEditing + " | FileAdmin";
}else{
document.title = "* " + fileEditing + " | FileAdmin";
}
}
};
/* 网络请求函数 */
function request(act, txt, callback) {
if (txt) {
fetchBody = "a=" + act + "&pwd=" + encodeURIComponent(localStorage.getItem("FileAdmin_Password")) + "&" + txt;
} else {
fetchBody = "a=" + act + "&pwd=" + encodeURIComponent(localStorage.getItem("FileAdmin_Password"));
}
fetch('?stamp=' + new Date().getTime(), {
body: fetchBody,
method: "POST",
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
}
})
.then(res => res.text())
.then(txt => {
let parsed = txt.split("||");
let code = Number(parsed[0]);
if (code == 1000) {
showModule("login");
} else {
if (parsed[1]) {
msg = parsed[1];
} else {
msg = null;
}
if (callback) {
callback(code, msg, txt);
}
}
})
.catch(err => {
alert(err);
})
}
/* 加法小游戏(根目录/危险操作确认提示) */
function confirmRootDirAccess(txt){
if(dirOperating=="/"){
let numx = Math.round(Math.random()*5 + 1);
let numy = Math.round(Math.random()*5 + 1);
let answer = numx + numy;
let userAnswer = prompt(txt+"\n请输入计算结果以确认操作:" + numx + " + " + numy);
if(userAnswer && Number(userAnswer) == answer){return true;}
}else{
if(confirm(txt)){return true;}
}
return false;
}
/* 显示模块函数 */
function showModule(name) {
document.title = "FileAdmin | 极致文件管理体验";
hideMenu();
if ($(".module.shown")) {
$(".module.shown").classList.remove("shown");
}
$(".module[data-module^='" + name + "']").classList.remove("hidden");
$(".module[data-module^='" + name + "']").classList.add("shown");
if (name == "login") {
ID("logoutBtn").style.display = "none";
} else {
ID("logoutBtn").style.display = "block";
}
if (name != "login" && name != "files" && name != "loading") {
history.pushState({
'mode': 'other'
}, document.title)
}
if (name != "texteditor" && name != "loading") {
document.body.classList.remove("mobileInputAdded");
}
hideContextMenu();
}
/* 显示菜单函数 */
function showMenu(name) {
if ($(".menu.shown")) {
$(".menu.shown").classList.remove("shown");
}
$(".menu[data-menu^='" + name + "']").classList.add("shown");
}
/* 隐藏菜单函数 */
function hideMenu() {
if ($(".menu.shown")) {
$(".menu.shown").classList.remove("shown");
}
}
/* 文件体积格式化 */
function humanSize(num) {
bytes = num / 102.4;
if (bytes == 0) {
return "0.00B";
}
var e = Math.floor(Math.log(bytes) / Math.log(1024));
return (bytes / Math.pow(1024, e)).toFixed(2) + 'KMGTP'.charAt(e) + 'B';
}
/* getElementById简写 */
function ID(id) {
return document.getElementById(id);
}
/* querySelector简写 */
function $(selector) {
return document.querySelector(selector);
}
/* ==================== 登录部分 ==================== */
/* 监听登录框键盘动作,如果按下了enter就执行登录 */
function loginCheckEnter(eve) {
if (eve.keyCode == 13) {
login()
}
}
/* 登录函数 */
function login() {
showModule("loading");
request("login", "loginPwd=" + ID("loginPassword").value, function(code, msg) {
if (code == 200) {
localStorage.setItem("FileAdmin_Password", msg);
loadFileList(dirOperating, true);
history.replaceState({
"mode": "fileList",
"dir": "/"
}, document.title)
} else {
showModule("login");
alert("密码输入错误 (⊙x⊙;)");
}
})
}
/* 右上角退登按钮 */
function logout() {
if (confirm("您真的要退出登录嘛?>﹏<")) {
localStorage.setItem("FileAdmin_Password", 0);
showModule("login");
}
}
/* ==================== 上传文件 ==================== */
/* 上传文件输入框改变后进行处理 */
function addFilesToUploads(ele) {
ID("filesUploadInputContainer").style="";
waitingToUpload = [];
waitingToUploadCount = 0;
Array.from(ele.files).forEach(addFileToUploadArr);
showModule("upload");
uploadFileFromList(0);
ele.value = '';
uploadNotFinished = true;
}
/* 当检测到粘贴事件后将剪切板内容添加到上传列表(即ctrl+v上传)的实现 */
document.addEventListener('paste', function(event) {
if ($(".files.shown") && !moveOrCopyMode) {
var items = event.clipboardData && event.clipboardData.items;
if (items && items.length) {
waitingToUpload = [];
waitingToUploadCount = 0;
for (var i = 0; i < items.length; i++) {
if (items[i].type !== '') {
if (items[i].getAsFile()) {
addFileToUploadArr(items[i].getAsFile());
}
}
}
showModule("upload");
uploadNotFinished = true;
uploadFileFromList(0);
}
}
});
/* 将【文件】添加到待上传Array的函数 */
function addFileToUploadArr(file) {
waitingToUpload.push({
"file": file,
"dir": dirOperating
});
waitingToUploadCount++;
}
/* 目录上传输入框内容变化处理 */
function addDirToUploads(ele) {
waitingToUpload = [];
waitingToUploadCount = 0;
Array.from(ele.files).forEach(addDirToUploadArr);
showModule("upload");
uploadFileFromList(0);
ele.value = '';
}
/* 将【目录】添加到待上传Array的函数 */
function addDirToUploadArr(file) {
let relativeDir = file.webkitRelativePath.split("/").slice(0, file.webkitRelativePath.split("/").length - 1).join("/") + "/";
waitingToUpload.push({
"file": file,
"dir": dirOperating + relativeDir
});
waitingToUploadCount++;
}
/* 从待上传Array中的第id个文件发送上传请求的函数 */
function uploadFileFromList(id) {
lastUploadTime = new Date().getTime();
lastUploadProgress = 0;
if (!waitingToUpload[id]) {
uploadNotFinished = false;
history.back();
} else {
waitingToUploadCount--;
ID("uploadText-CurrFile").innerText = waitingToUpload[id]["file"]["name"];
ID("uploadText-Waiting").innerText = waitingToUploadCount;
ID("uploadText-DestDir").innerText = waitingToUpload[id]["dir"];
ID("uploadProgressBar").style.display = "none";
setTimeout(function() {
ID("uploadProgressBar").style.width = "0%";
ID("uploadProgressBar").style.display = "block";
}, 50);
ID("uploadText-CurrProg").innerText = "0% (正在连接...)";
xhr = new XMLHttpRequest();
xhr.onload = function() {
if(xhr.responseText == "1002"){alert("目录下已有同名文件存在,上传失败 >︿<");}
else if(xhr.responseText != "200"){alert("文件上传失败,请检查您和服务器的网络状况 >︿<");}
id++;
uploadFileFromList(id)
};
xhr.onerror = function() {
alert("文件上传失败,请检查您和服务器的网络状况 >︿<");
id++;
uploadFileFromList(id)
};
xhr.open("POST", "?a=upload&pwd=" + encodeURIComponent(localStorage.getItem("FileAdmin_Password")) + "&dir=" + encodeURIComponent(waitingToUpload[id]["dir"]), true);
xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest");
var fd = new FormData();
fd.append("file", waitingToUpload[id]["file"]);
xhr.upload.onprogress = function(eve) {
loaded = eve.loaded / eve.total;
percent = Math.round((loaded * 100)) + "%";
ID("uploadProgressBar").style.width = percent;
ID("uploadText-CurrProg").innerText = percent + " (" + humanSize(eve.loaded / 10) + " / " + humanSize(eve.total / 10) + ")";
uploadSpeed = humanSize((eve.loaded - lastUploadProgress) / (new Date().getTime() - lastUploadTime) * 100) + "/S";
ID("uploadText-CurrSpeed").innerText = uploadSpeed;
if (percent == "100%") {
ID("uploadText-CurrProg").innerText = percent + " (正在处理...)";
}
lastUploadTime = new Date().getTime();
lastUploadProgress = eve.loaded;
};
xhr.send(fd);
}
}
/* ==================== 文件浏览器主体部分 ==================== */
/* 获取当前目录的占用信息 */
function getDiskSpaceInfo() {
showModule("loading");
request("space", "name=" + encodeURIComponent(dirOperating), function(c, data, d) {
if (c == 200) {
let returnData = d.split("||");
let total = humanSize(returnData[1] / 10);
let free = humanSize(returnData[2] / 10);
let freepercent = Math.round(returnData[2] / returnData[1] * 10000) / 100;
let used = humanSize(returnData[3] / 10);
let usedpercent = Math.round(returnData[3] / returnData[1] * 10000) / 100;
let current = humanSize(returnData[4] / 10);
let currentpercent = Math.round(returnData[4] / returnData[1] * 10000) / 100;
if (returnData[1] != 0) {
alert("空间信息获取成功啦 ( •̀ ω •́ )✧\n\n磁盘空间合计:" + total + "\n可用磁盘空间:" + free + "(占总空间的" + freepercent + "%)" + "\n已用磁盘空间:" + used + "(占总空间的" + usedpercent + "%)" + "\n当前目录占用:" + current + "(占总空间的" + currentpercent + "%)");
} else {
/* 某些环境(比如kangle虚拟主机)没法获取总空间,这里进行错误处理 */
alert("磁盘总空间获取失败,您使用的环境可能不允许此操作 `(*>﹏<*)′\n当前查看的目录占用" + current + "磁盘空间哦 ( •̀ ω •́ )✧")
}
loadFileList(dirOperating, true);
} else if (c == 1001) {
alert("您当前查看的目录不存在,可能已经被删除惹 /_ \\")
} else {
alert("出现未知错误惹 /_ \\");
}
})
}
/* 从服务器获取文件列表并显示 */
function loadFileList(dir, fromState) {
fileSelected = [];
ID("addressBar").innerText = "根目录" + dir.replaceAll("/", " / ");
showModule("loading");
request("files", "name=" + dir, function(code, data) {
if (code == 200) {
fileListArr = JSON.parse(decodeURIComponent(data));
fileListOperating = [];
fileListHtml = "";
fileListArr.forEach(addToFileListHtml);
ID("fileList").innerHTML = fileListHtml;
if (fileListHtml == "") {
ID("fileList").innerHTML = "<center>请求的目录为空 ヽ(*。>Д<)o゜</center>"
}
} else if (code == "1001") {
ID("fileList").innerHTML = "<center>请求的目录不存在捏 (ノへ ̄、)</center>"
} else if (code = "1002") {
ID("fileList").innerHTML = "<center>目录名称格式有误 (゚Д゚*)ノ</center>"
}
showModule("files");
showMenu("files-noselect");
if (window.offsetBeforeEditing) {
scrollTo(0, offsetBeforeEditing);
offsetBeforeEditing = null;
}
});
if (!fromState) {
history.pushState({
"mode": "fileList",
"dir": dir
}, document.title, "#" + dirOperating)
}
}
/* 用于forEach时将每个文件添加到文件列表的html中 */
function addToFileListHtml(data) {
if (data.name != "." && data.name != "..") {
fileType = data.name.split(".")[data.name.split(".").length - 1].toLowerCase();
fileListOperating.push(data.name);
fileListHtml = fileListHtml + `<div class="file" onmouseover="hoverSelect(this)" data-isdir=` + data.dir + ` data-filename="` + data.name + `" onclick="viewFile(this)" oncontextmenu="fileContextMenu(this)">` + getFileIco(fileType, data.dir) + ` <div class="fileName">` + data.name + `</div> <div class="size">` + humanSize(data.size * 102.4) + `</div></div>`;
}
}
/* 用于按照文件类型获取文件图标的html,在搜索文件的列表显示中也用到这个 */
function getFileIco(type, dir) {
if (dir) {
return `<svg style='padding:2px' viewBox="0 0 16 16" version="1.1" class="fileIco" fill="#1e9fff"><path d="M1.75 1A1.75 1.75 0 000 2.75v10.5C0 14.216.784 15 1.75 15h12.5A1.75 1.75 0 0016 13.25v-8.5A1.75 1.75 0 0014.25 3H7.5a.25.25 0 01-.2-.1l-.9-1.2C6.07 1.26 5.55 1 5 1H1.75z"></path></svg>`;
} else if (type == "fajs") {
return `<img class="fileIco" src="https://asset.simsoft.top/products/fileadmin/filetype/lock.svg">`;
} else if (["html", "htm", "php", "js", "css", "xml", "json", "xaml"].indexOf(type) != -1) {
return `<img class="fileIco" src="https://asset.simsoft.top/products/fileadmin/filetype/code.svg">`;
} else if (["mp3", "wav", "aac", "mid"].indexOf(type) != -1) {
return `<img class="fileIco" src="https://asset.simsoft.top/products/fileadmin/filetype/audio.svg">`;
} else if (["png", "ico", "svg", "jpg", "jpeg", "gif", "webp"].indexOf(type) != -1) {
return `<img class="fileIco" src="https://asset.simsoft.top/products/fileadmin/filetype/image.svg">`;
} else if (["txt", "md", "yml", "log", "ini"].indexOf(type) != -1) {
return `<img class="fileIco" src="https://asset.simsoft.top/products/fileadmin/filetype/text.svg">`;
} else {
return `<img class="fileIco" src="https://asset.simsoft.top/products/fileadmin/filetype/unknown.svg">`
}
}
/* 用于编辑文件地址栏(文件列表顶部的那个)的函数 */
function editAddressBar() {
let newDir = prompt("请输入想转到的路径 (o゜▽゜)o☆", dirOperating);
if (newDir) {
if (newDir.split("")[0] != "/") {
newDir = "/" + newDir;
}
if (newDir.split("")[newDir.split("").length - 1] != "/") {
newDir = newDir + "/";
}
dirOperating = newDir;
loadFileList(dirOperating);
}
}
/* 当鼠标在文件列表开始拖动时,开始进行快速多选操作 */
function startHoverSelect(ele) {