]> Cypherpunks.ru repositories - gocheese.git/blobdiff - main.go
Update dependencies
[gocheese.git] / main.go
diff --git a/main.go b/main.go
index 12a325a93435af81d330f2ff9e844e31da891e13..f4a4359e677f63e54f5723f6bd06fa5d8fc6a83d 100644 (file)
--- a/main.go
+++ b/main.go
@@ -47,15 +47,17 @@ import (
 
 const (
        Version   = "3.0.0"
+       UserAgent = "GoCheese/" + Version
        HTMLBegin = `<!DOCTYPE html>
 <html>
   <head>
+    <meta name="pypi:repository-version" content="1.0">
     <title>Links for %s</title>
   </head>
   <body>
 `
        HTMLEnd      = "  </body>\n</html>\n"
-       HTMLElement  = "    <a href=\"%s\"%s>%s</a><br/>\n"
+       HTMLElement  = "    <a href=\"%s\"%s>%s</a>\n"
        InternalFlag = ".internal"
        GPGSigExt    = ".asc"
 
@@ -105,8 +107,9 @@ var (
        pypiURL      = flag.String("pypi", "https://pypi.org/simple/", "Upstream (PyPI) URL")
        pypiCertHash = flag.String("pypi-cert-hash", "", "Authenticate upstream by its X.509 certificate's SPKI SHA256 hash")
 
-       passwdPath  = flag.String("passwd", "", "Path to FIFO for upload authentication")
-       passwdCheck = flag.Bool("passwd-check", false, "Run password checker")
+       passwdPath     = flag.String("passwd", "", "Path to FIFO for upload authentication")
+       passwdListPath = flag.String("passwd-list", "", "Path to FIFO for login listing")
+       passwdCheck    = flag.Bool("passwd-check", false, "Run password checker")
 
        logTimestamped = flag.Bool("log-timestamped", false, "Prepend timestmap to log messages")
        fsck           = flag.Bool("fsck", false, "Check integrity of all packages (errors are in stderr)")
@@ -229,6 +232,7 @@ func servePkg(w http.ResponseWriter, r *http.Request, pkgName, filename string)
 }
 
 func handler(w http.ResponseWriter, r *http.Request) {
+       w.Header().Set("Server", UserAgent)
        switch r.Method {
        case "GET":
                var path string
@@ -306,7 +310,11 @@ func main() {
        if *passwdPath != "" {
                go func() {
                        for {
-                               fd, err := os.OpenFile(*passwdPath, os.O_RDONLY, os.FileMode(0666))
+                               fd, err := os.OpenFile(
+                                       *passwdPath,
+                                       os.O_RDONLY,
+                                       os.FileMode(0666),
+                               )
                                if err != nil {
                                        log.Fatalln(err)
                                }
@@ -315,6 +323,22 @@ func main() {
                        }
                }()
        }
+       if *passwdListPath != "" {
+               go func() {
+                       for {
+                               fd, err := os.OpenFile(
+                                       *passwdListPath,
+                                       os.O_WRONLY|os.O_APPEND,
+                                       os.FileMode(0666),
+                               )
+                               if err != nil {
+                                       log.Fatalln(err)
+                               }
+                               passwdLister(fd)
+                               fd.Close()
+                       }
+               }()
+       }
 
        if (*tlsCert != "" && *tlsKey == "") || (*tlsCert == "" && *tlsKey != "") {
                log.Fatalln("Both -tls-cert and -tls-key are required")