message string
fsymln bool
showdot bool
+ noidx bool
verbose bool
}{
iface: "localhost",
message: "",
fsymln: false,
showdot: false,
+ noidx: false,
verbose: false,
}
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.noidx, "l", cfg.noidx, "allow directory listings")
flag.BoolVar(&cfg.verbose, "v", cfg.verbose, "produce verbose output")
flag.Parse()
if help {
tracer.Print("doc root: ", cfg.docRoot)
tracer.Print("fsymlinks: ", cfg.fsymln)
tracer.Print("showdot: ", cfg.showdot)
+ tracer.Print("noidx: ", cfg.noidx)
tracer.Print("fqdn: ", cfg.fqdn)
tracer.Print("message: ", cfg.message)
tracer.Print("verbose: ", cfg.verbose)
// create a file reference
ftype, _ := guessFiletype(dirname + pathSep + fi.Name())
list += ftype + fi.Name() + " | " + humanSize(fi.Size()) + " | " + fts + "\t" + selector + pathSep + fi.Name() + loc
- } else if cfg.fsymln == true && fmode&os.ModeSymlink != 0 {
+ } else if cfg.fsymln && fmode&os.ModeSymlink != 0 {
// create a reference with attributes matching the link target
linktarget, _ := os.Readlink(dirname + pathSep + fi.Name())
if linktarget[:1] != pathSep {
if check(err, "canonicalizePath "+path) == nil {
lfi, err := os.Stat(path)
if check(err, "Stat "+path) == nil {
- fmode := fi.Mode()
+ fmode := lfi.Mode()
fts := "[" + humanDate(lfi.ModTime()) + "]"
if fmode.IsDir() {
// link points to a directory
}
func replyErr(conn net.Conn, msg string) {
- tracer.Print("sending error reply:" + msg)
+ tracer.Print("sending error reply: " + msg)
s := "iGopher Meditation: " + msg + "\tErr\t" + cfg.fqdn + "\t" + cfg.port + "\r\n"
nb, err := conn.Write([]byte(s))
if check(err, "replyErr Write ") != nil {
return
}
// check for symbolic link
- if cfg.fsymln == false {
+ if !cfg.fsymln {
fi, err := os.Lstat(path)
if check(err, "request path Lstat "+path) != nil {
replyErr(conn, "404")
tracer.Print("selector: '", selector, "'")
var nbytes int64
if fmode.IsDir() {
+ if cfg.noidx {
+ replyErr(conn, "403")
+ return
+ }
diridx, err := createIndex(selector)
if check(err, "makeIndex "+path) != nil {
replyErr(conn, "404")
return
}
} else {
+ replyErr(conn, "404")
return
}
tracer.Print(strconv.FormatInt(nbytes, 10) + " bytes sent.")