finish up changes to virtual file remapping implementation

Signed-off-by: kim (grufwub) <grufwub@gmail.com>
master
kim (grufwub) 4 years ago
parent 0b8c3b41ba
commit 4bf0e88ac6

@ -114,6 +114,7 @@ func (g *GophermapDirectorySection) Render(responder *Responder) *GophorError {
g.Request,
},
g.Hidden,
false,
)
}
@ -195,15 +196,13 @@ func readGophermap(request *Request) ([]GophermapSection, *GophorError) {
/* Create return slice */
sections := make([]GophermapSection, 0)
/* _Create_ hidden files map now in case dir listing requested */
/* Create hidden files map now in case dir listing requested */
hidden := make(map[string]bool)
hidden[request.RelPath()] = true
/* Keep track of whether we've already come across a title line (only 1 allowed!) */
titleAlready := false
/* Reference directory listing now in case requested */
var dirListing *GophermapDirectorySection
/* Perform buffered scan with our supplied splitter and iterators */
gophorErr := bufferedScan(request.AbsPath(),
func(scanner *bufio.Scanner) bool {
@ -229,7 +228,7 @@ func readGophermap(request *Request) ([]GophermapSection, *GophorError) {
case TypeHiddenFile:
/* Add to hidden files map */
hidden[line[1:]] = true
hidden[request.PathJoinRel(line[1:])] = true
case TypeSubGophermap:
/* Parse new requestPath and parameters (this automatically sanitizes requestPath) */
@ -287,7 +286,7 @@ func readGophermap(request *Request) ([]GophermapSection, *GophorError) {
case TypeEndBeginList:
/* Create GophermapDirListing object then break out at end of loop */
dirRequest := &Request{ NewRequestPath(request.RootDir(), request.PathTrimRelSuffix(GophermapFileStr)), request.Parameters }
dirListing = &GophermapDirectorySection{ dirRequest, hidden }
sections = append(sections, &GophermapDirectorySection{ dirRequest, hidden })
return false
default:

@ -43,7 +43,7 @@ func (fs *FileSystem) RemapRequestPath(requestPath *RequestPath) {
}
func (fs *FileSystem)ReverseRemapRequestPath(requestPath *RequestPath) {
virtualPath, ok := fs.Remap[requestPath.Relative()]
virtualPath, ok := fs.ReverseRemap[requestPath.Relative()]
if ok {
requestPath.RemapVirtual(virtualPath)
}
@ -107,7 +107,7 @@ func (fs *FileSystem) HandleRequest(responder *Responder) *GophorError {
}
} else {
/* No gophermap, serve directory listing */
return listDir(responder, map[string]bool{})
return listDir(responder, map[string]bool{}, true)
}
/* Regular file */

@ -111,7 +111,7 @@ func unixLineEndSplitter(data []byte, atEOF bool) (advance int, token []byte, er
}
/* List the files in a directory, hiding those requested */
func listDir(responder *Responder, hidden map[string]bool) *GophorError {
func listDir(responder *Responder, hidden map[string]bool, includeTitleFooter bool) *GophorError {
/* Open directory file descriptor */
fd, err := os.Open(responder.Request.AbsPath())
if err != nil {
@ -133,11 +133,13 @@ func listDir(responder *Responder, hidden map[string]bool) *GophorError {
dirContents := make([]byte, 0)
/* First add a title + a space */
dirContents = append(dirContents, buildLine(TypeInfo, "[ "+responder.Host.Name()+responder.Request.SelectorPath()+" ]", "TITLE", NullHost, NullPort)...)
dirContents = append(dirContents, buildInfoLine("")...)
if includeTitleFooter {
dirContents = append(dirContents, buildLine(TypeInfo, "[ "+responder.Host.Name()+responder.Request.SelectorPath()+" ]", "TITLE", NullHost, NullPort)...)
dirContents = append(dirContents, buildInfoLine("")...)
/* Add a 'back' entry. GoLang Readdir() seems to miss this */
dirContents = append(dirContents, buildLine(TypeDirectory, "..", responder.Request.PathJoinSelector(".."), responder.Host.Name(), responder.Host.Port())...)
/* Add a 'back' entry. GoLang Readdir() seems to miss this */
dirContents = append(dirContents, buildLine(TypeDirectory, "..", responder.Request.PathJoinSelector(".."), responder.Host.Name(), responder.Host.Port())...)
}
/* Walk through files :D */
var reqPath *RequestPath
@ -145,7 +147,7 @@ func listDir(responder *Responder, hidden map[string]bool) *GophorError {
reqPath = NewRequestPath(responder.Request.RootDir(), file.Name())
/* If hidden file, or restricted file, continue! */
if isHiddenFile(hidden, file.Name()) || isRestrictedFile(reqPath.Relative()) {
if isHiddenFile(hidden, reqPath.Relative()) || isRestrictedFile(reqPath.Relative()) {
continue
}
@ -169,8 +171,12 @@ func listDir(responder *Responder, hidden map[string]bool) *GophorError {
}
}
if includeTitleFooter {
dirContents = append(dirContents, Config.FooterText...)
}
/* Append the footer (including lastline), write and flush! */
return responder.WriteFlush(append(dirContents, Config.FooterText...))
return responder.WriteFlush(dirContents)
}
func isHiddenFile(hiddenMap map[string]bool, fileName string) bool {

@ -149,11 +149,11 @@ func setupServer() []*GophorListener {
Config.CgiEnv = setupInitialCgiEnviron(*safeExecPath)
/* Set executable watchdog */
Config.SysLog.Info("", "Maximum executable time: %s\n", *maxExecRunTime)
Config.SysLog.Info("", "Max executable time: %s\n", *maxExecRunTime)
Config.MaxExecRunTime = *maxExecRunTime
/* Specific to CGI buffer */
Config.SysLog.Info("", "Maximum CGI HTTP header read-ahead: %d bytes\n", *skipPrefixBuf)
Config.SysLog.Info("", "Max CGI HTTP header read-ahead: %d bytes\n", *skipPrefixBuf)
Config.SkipPrefixBufSize = *skipPrefixBuf
}

Loading…
Cancel
Save