-
Notifications
You must be signed in to change notification settings - Fork 56
/
perm.go
86 lines (66 loc) · 1.69 KB
/
perm.go
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
package serverHandler
import (
"../util"
"os"
)
func hasUrlOrDirPrefix(urls []string, reqUrl string, dirs []string, reqDir string) bool {
for _, url := range urls {
if util.HasUrlPrefixDir(reqUrl, url) {
return true
}
}
for _, dir := range dirs {
if util.HasFsPrefixDir(reqDir, dir) {
return true
}
}
return false
}
func (h *handler) getCanUpload(info os.FileInfo, rawReqPath, reqFsPath string) bool {
if info == nil || !info.IsDir() {
return false
}
if h.globalUpload {
return true
}
return hasUrlOrDirPrefix(h.uploadUrls, rawReqPath, h.uploadDirs, reqFsPath)
}
func (h *handler) getCanMkdir(info os.FileInfo, rawReqPath, reqFsPath string) bool {
if info == nil || !info.IsDir() {
return false
}
if h.globalMkdir {
return true
}
return hasUrlOrDirPrefix(h.mkdirUrls, rawReqPath, h.mkdirDirs, reqFsPath)
}
func (h *handler) getCanDelete(info os.FileInfo, rawReqPath, reqFsPath string) bool {
if info == nil || !info.IsDir() {
return false
}
if h.globalDelete {
return true
}
return hasUrlOrDirPrefix(h.deleteUrls, rawReqPath, h.deleteDirs, reqFsPath)
}
func (h *handler) getCanArchive(subInfos []os.FileInfo, rawReqPath, reqFsPath string) bool {
if len(subInfos) == 0 {
return false
}
if h.globalArchive {
return true
}
return hasUrlOrDirPrefix(h.archiveUrls, rawReqPath, h.archiveDirs, reqFsPath)
}
func (h *handler) getCanCors(rawReqPath, reqFsPath string) bool {
if h.globalCors {
return true
}
return hasUrlOrDirPrefix(h.corsUrls, rawReqPath, h.corsDirs, reqFsPath)
}
func (h *handler) getNeedAuth(rawReqPath, reqFsPath string) bool {
if h.globalAuth {
return true
}
return hasUrlOrDirPrefix(h.authUrls, rawReqPath, h.authDirs, reqFsPath)
}