From: Urban Wallasch Date: Fri, 5 Apr 2019 14:55:23 +0000 (+0200) Subject: * Added option to show dotfiles which are now hidden by default. X-Git-Tag: v0.2~9 X-Git-Url: https://git.packet-gain.de/?a=commitdiff_plain;h=ddb8201f33fa30a2652e4de7b786f084cf29ef05;p=gogopherd.git * Added option to show dotfiles which are now hidden by default. --- diff --git a/config.go b/config.go index 5453033..9fd4001 100644 --- a/config.go +++ b/config.go @@ -21,6 +21,7 @@ var cfg = struct { docRoot string message string fsymln bool + showdot bool verbose bool }{ iface: "localhost", @@ -29,6 +30,7 @@ var cfg = struct { docRoot: ".", message: "", fsymln: false, + showdot: false, verbose: false, } @@ -41,6 +43,7 @@ func initialize() { flag.StringVar(&cfg.message, "M", cfg.message, "index greeter message") flag.BoolVar(&help, "h", help, "show this help page") flag.BoolVar(&cfg.fsymln, "s", cfg.fsymln, "follow symbolic links") + flag.BoolVar(&cfg.showdot, "d", cfg.showdot, "allow access to dotfiles") flag.BoolVar(&cfg.verbose, "v", cfg.verbose, "produce verbose output") flag.Parse() if help { @@ -70,6 +73,7 @@ func initialize() { tracer.Print("TCP port: ", cfg.port) tracer.Print("doc root: ", cfg.docRoot) tracer.Print("fsymlinks: ", cfg.fsymln) + tracer.Print("showdot: ", cfg.showdot) tracer.Print("fqdn: ", cfg.fqdn) tracer.Print("message: ", cfg.message) tracer.Print("verbose: ", cfg.verbose) diff --git a/gogopherd.go b/gogopherd.go index b193b23..1f8c786 100644 --- a/gogopherd.go +++ b/gogopherd.go @@ -39,6 +39,9 @@ func createIndex(selector string) (string, error) { list += "1..\t" + updir + loc } for _, fi := range fi { + if !cfg.showdot && isDotfile(fi.Name()) { + continue + } fmode := fi.Mode() if fmode.IsDir() { // create a directory reference @@ -89,6 +92,10 @@ func handleRequest(conn net.Conn) { return } tracer.Print("request path: '", path, "'") + if !cfg.showdot && isDotfile(path) { + tracer.Print("skip dotfile") + return + } // check for symbolic link if cfg.fsymln == false { fi, err := os.Lstat(path) diff --git a/util.go b/util.go index f648755..e790c0c 100644 --- a/util.go +++ b/util.go @@ -69,6 +69,11 @@ func validatePath(root string, path string) (string, error) { return cpath, err } +func isDotfile(path string) bool { + base := filepath.Base(path) + return base[:1] == "." +} + func guessFiletype(path string) (string, error) { // Open File f, err := os.Open(path)