|
|
|
@ -13,12 +13,18 @@ var (
|
|
|
|
|
// WithinCGIDir returns whether a path is within the server's specified CGI scripts directory
|
|
|
|
|
WithinCGIDir func(*Path) bool
|
|
|
|
|
|
|
|
|
|
// RestrictedPaths is the global slice of restricted paths
|
|
|
|
|
// restrictedPaths is the global slice of restricted paths
|
|
|
|
|
restrictedPaths []*regexp.Regexp
|
|
|
|
|
|
|
|
|
|
// IsRestrictedPath is the global function to check against restricted paths
|
|
|
|
|
IsRestrictedPath func(*Path) bool
|
|
|
|
|
|
|
|
|
|
// hiddenPaths is the global slice of hidden (from dir view) paths
|
|
|
|
|
hiddenPaths []*regexp.Regexp
|
|
|
|
|
|
|
|
|
|
// IsHiddenPath is the global function to check against hidden paths
|
|
|
|
|
IsHiddenPath func(*Path) bool
|
|
|
|
|
|
|
|
|
|
// requestRemaps is the global slice of remapped paths
|
|
|
|
|
requestRemaps []*RequestRemap
|
|
|
|
|
|
|
|
|
@ -73,6 +79,31 @@ func compileRestrictedPathsRegex(restrictions string) []*regexp.Regexp {
|
|
|
|
|
return regexes
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// compileRestrictedPathsRegex turns a string of hidden paths into a slice of compiled regular expressions
|
|
|
|
|
func compileHiddenPathsRegex(hidden string) []*regexp.Regexp {
|
|
|
|
|
regexes := make([]*regexp.Regexp, 0)
|
|
|
|
|
|
|
|
|
|
// Split restrictions string by new lines
|
|
|
|
|
for _, expr := range strings.Split(hidden, "\n") {
|
|
|
|
|
// Skip empty expressions
|
|
|
|
|
if len(expr) == 0 {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Compile the regular expression
|
|
|
|
|
regex, err := regexp.Compile("(?m)" + expr + "$")
|
|
|
|
|
if err != nil {
|
|
|
|
|
SystemLog.Fatal(pathHidingRegexCompileFailStr, expr)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Append compiled regex and log
|
|
|
|
|
regexes = append(regexes, regex)
|
|
|
|
|
SystemLog.Info(pathHidingRegexCompiledStr, expr)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return regexes
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// compil RequestRemapRegex turns a string of remapped paths into a slice of compiled RequestRemap structures
|
|
|
|
|
func compileRequestRemapRegex(remaps string) []*RequestRemap {
|
|
|
|
|
requestRemaps := make([]*RequestRemap, 0)
|
|
|
|
@ -129,6 +160,21 @@ func isRestrictedPathDisabled(p *Path) bool {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// isHiddenPathEnabled returns whether a Path's relative value should be hidden
|
|
|
|
|
func isHiddenPathEnabled(p *Path) bool {
|
|
|
|
|
for _, regex := range hiddenPaths {
|
|
|
|
|
if regex.MatchString(p.Selector()) {
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// isHiddenPathDisabled always returns false, there are no hidden paths
|
|
|
|
|
func isHiddenPathDisabled(p *Path) bool {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// remapRequestEnabled tries to remap a request, returning bool as to success
|
|
|
|
|
func remapRequestEnabled(request *Request) bool {
|
|
|
|
|
for _, remap := range requestRemaps {
|
|
|
|
|