* Added option to show dotfiles which are now hidden by default.
authorUrban Wallasch <urban.wallasch@freenet.de>
Fri, 5 Apr 2019 14:55:23 +0000 (16:55 +0200)
committerUrban Wallasch <urban.wallasch@freenet.de>
Fri, 5 Apr 2019 14:55:23 +0000 (16:55 +0200)
config.go
gogopherd.go
util.go

index 545303323d4a7c4592e3abffac3102570cd7dd53..9fd4001562d1f8ea1463eef9b506dc358a9f1705 100644 (file)
--- 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)
index b193b23770c272688a524b5cc099f83e2ffa5035..1f8c786bb8ee779302c6bebfbd16ce31ccac52c1 100644 (file)
@@ -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 f64875594729d07ee672c7e4268735a792236d29..e790c0cf81c042baae2c00bf861b24677b8c8298 100644 (file)
--- 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)