* Added cfg.xport, used in generated links (easy proxy support). master
authorUrban Wallasch <urban.wallasch@freenet.de>
Sat, 13 Apr 2019 10:23:29 +0000 (12:23 +0200)
committerUrban Wallasch <urban.wallasch@freenet.de>
Sat, 13 Apr 2019 10:23:29 +0000 (12:23 +0200)
config.go
gogopherd.cfg.example
gogopherd.go

index 4841c669b6557845b90ac9eca9d1b90c670ad27a..2e0310fb909ae3298a96ab2911f440cc139c0448 100644 (file)
--- a/config.go
+++ b/config.go
@@ -24,6 +24,7 @@ var cfg = struct {
        iface   string
        port    string
        fqdn    string
+       xport   string
        docroot string
        idxpage string
        header  string
@@ -44,6 +45,7 @@ var cfg = struct {
        iface:   "localhost",
        port:    "7070",
        fqdn:    "localhost",
+       xport:   "7070",
        docroot: ".",
        idxpage: "index.goph",
        header:  "",
@@ -85,6 +87,8 @@ func parseConfigFile(filename string) error {
                        cfg.port = val
                case "fqdn":
                        cfg.fqdn = val
+               case "xport":
+                       cfg.xport = val
                case "docroot":
                        cfg.docroot = val
                case "idxpage":
@@ -132,6 +136,7 @@ func initialize() {
        flag.StringVar(&cfg.iface, "i", cfg.iface, "interface to bind to; empty for any")
        flag.StringVar(&cfg.port, "p", cfg.port, "TCP `port` to listen on")
        flag.StringVar(&cfg.fqdn, "f", cfg.fqdn, "fully qualified domain name")
+       flag.StringVar(&cfg.xport, "x", cfg.xport, "TCP port for generated links")
        flag.StringVar(&cfg.docroot, "r", cfg.docroot, "document root `directory`")
        flag.StringVar(&cfg.idxpage, "I", cfg.idxpage, "directory index `file` name")
        flag.StringVar(&cfg.header, "H", cfg.header, "header: prepend contents of `file` to generated pages")
@@ -182,9 +187,10 @@ func initialize() {
        }
 
        tracer.Print("final config:")
-       tracer.Print("fqdn:    ", cfg.fqdn)
        tracer.Print("iface:   ", cfg.iface)
        tracer.Print("port:    ", cfg.port)
+       tracer.Print("fqdn:    ", cfg.fqdn)
+       tracer.Print("xport:   ", cfg.xport)
        tracer.Print("docroot: ", cfg.docroot)
        tracer.Print("idxpage: ", cfg.idxpage)
        tracer.Print("header:  ", cfg.header)
index e4e1d209b8295dfb932c572e9c3cb37a8e76ebe5..e59d5b9df2a5992e6c662b1c8b2d88d9b0ba47cf 100644 (file)
@@ -8,6 +8,8 @@ iface = "localhost"
 port = 7070
 # Fully qualified domain name associated with server.
 fqdn = "localhost"
+# Port to use in generated links (useful for proxy support).
+xport = 7070
 
 # Root directory of document hierarchy.
 docroot = "samplehole"
index 3ccc60938b8ae4d720a6125bed000d1c1215b90a..3ffe16091172cf9a03cb48dcc6806934a5bd0983 100644 (file)
@@ -38,7 +38,7 @@ func createIndex(dirname string, selector string) (string, error) {
        if check(err, "Readdir "+dirname) != nil {
                return "", err
        }
-       loc := "\t" + cfg.fqdn + "\t" + cfg.port + "\r\n"
+       loc := "\t" + cfg.fqdn + "\t" + cfg.xport + "\r\n"
        list := ""
        if dirname != cfg.docroot {
                list += "1..\t" + path.Dir(selector) + loc
@@ -108,7 +108,7 @@ func sendIndex(conn net.Conn, path string, selector string) (int64, error) {
                if selector == "" {
                        selector = "/"
                }
-               page := "iIndex of " + selector + "\tErr\t" + cfg.fqdn + "\t" + cfg.port + "\r\n"
+               page := "iIndex of " + selector + "\tErr\t" + cfg.fqdn + "\t" + cfg.xport + "\r\n"
                page += idxpage
                var nb1 int
                nb1, err = conn.Write([]byte(page))
@@ -158,7 +158,7 @@ func sendError(conn net.Conn, msg string) {
        }
        nbytes, _ := sendHeader(conn)
        tracer.Print("send error page: ", msg)
-       s := "3Gopher Meditation: " + msg + emsg + "\tErr\t" + cfg.fqdn + "\t" + cfg.port + "\r\n"
+       s := "3Gopher Meditation: " + msg + emsg + "\tErr\t" + cfg.fqdn + "\t" + cfg.xport + "\r\n"
        nb1, err := conn.Write([]byte(s))
        if check(err, "sendError Write ") != nil {
                return