-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
118 lines (113 loc) · 4.12 KB
/
index.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
<?php
require './czkdir/inc.php';
$c = isset($_GET['p'])?trim($_GET['p']):'home';
$x = new DirList();
switch($c){
case 'hash':
if(!checkRefererHost())exit('{"code":403}');
if($conf['file_hash'] != '1')echo_json(['code'=>-1,'msg'=>'没有开启文件hash功能']);
$path = isset($_POST['path'])?trim($_POST['path']):'';
try{
$r = $x->get_file_hash($path);
}catch(Exception $e){
$r = ['code'=>-1, 'msg'=>$e->getMessage()];
}
echo_json($r);
break;
case 'video':
case 'audio':
case 'markdown':
case 'text':
if(!checkRefererHost())exit('Access Denied');
$path = isset($_GET['path'])?trim($_GET['path']):'';
try{
$path = './'.$x->set_dir_path($path, true);
}catch(Exception $e){
$errmsg = $e->getMessage();
sysmsg($errmsg);
}
$name = basename($path);
$ext = $x->get_file_ext($path);
$url = implode('/', array_map('rawurlencode', explode('/', $path)));
include PAGE_ROOT.$c.'.php';
break;
case 'search':
$s = isset($_GET['s'])?trim($_GET['s']):'';
if($s == '') exit("<script language='javascript'>window.location.href='./';</script>");
try{
$list = $x->search_files($s);
$r = ['list'=>$list];
}catch(Exception $e){
$errmsg = $e->getMessage();
}
$s = htmlspecialchars($s);
include PAGE_ROOT.'home.php';
break;
case 'home':
$dir = isset($_GET['dir'])?trim($_GET['dir']):'';
try{
$r = $x->list_dir($dir);
}catch(Exception $e){
$errmsg = $e->getMessage();
$r = $x->list_dir();
}
if(!empty($r['passwd']) && isset($_POST['passwd'])){
if($errmsg) echo_json(['code'=>-1, 'msg'=>$errmsg]);
if(password_verify($_POST['passwd'], $r['passwd'])){
setcookie('dir_passwd', md5($r['passwd']));
echo_json(['code'=>0]);
}else{
echo_json(['code'=>-1, 'msg'=>'出错了,请检查目录密码重试']);
}
}
include PAGE_ROOT.'home.php';
break;
case 'admin':
if(!$islogin) exit("<script language='javascript'>window.location.href='./?p=login';</script>");
include PAGE_ROOT.'admin.php';
break;
case 'upload':
if(!$islogin) exit("<script language='javascript'>window.location.href='./?p=login';</script>");
$path = isset($_GET['path'])?trim($_GET['path']):'';
try{
$path = $x->set_dir_path($path);
}catch(Exception $e){
sysmsg($e->getMessage());
}
include PAGE_ROOT.'upload.php';
break;
case 'filemgr':
if(!$islogin) exit("<script language='javascript'>window.location.href='./?p=login';</script>");
$path = isset($_POST['path'])?trim($_POST['path']):'';
$do = isset($_POST['do'])?trim($_POST['do']):echo_json(['code'=>-1, 'msg'=>'param error']);
try{
$path = $x->set_dir_path($path);
}catch(Exception $e){
echo_json(['code'=>-1, 'msg'=>$e->getMessage()]);
}
$mgr = new FileMgr($path);
if(!method_exists($mgr, $do))echo_json(['code'=>-1, 'msg'=>'action error']);
try{
$result = $mgr->$do();
echo_json(['code'=>0, 'data'=>$result]);
}catch(Exception $e){
echo_json(['code'=>-1, 'msg'=>$e->getMessage()]);
}
break;
case 'editor':
if(!$islogin) exit("<script language='javascript'>window.location.href='./?p=login';</script>");
$path = isset($_GET['path'])?trim($_GET['path']):'';
try{
$path = $x->set_dir_path($path, true);
}catch(Exception $e){
$errmsg = $e->getMessage();
sysmsg($errmsg);
}
include PAGE_ROOT.'editor.php';
break;
case 'login':
include PAGE_ROOT.'login.php';
break;
default:
break;
}