X-Git-Url: http://www.git.cypherpunks.ru/?a=blobdiff_plain;ds=sidebyside;f=main.go;h=46be5259f871b8bb6fb6fa1f9926608f6443bbd2;hb=4a6954050e174bf8b851c82bc2476409a4d78eea;hp=cc30de23dfc84596f7980a2fef81fc370827521c;hpb=adfee4423269bf180abab3131a171f34931d7037;p=gocheese.git diff --git a/main.go b/main.go index cc30de2..46be525 100644 --- a/main.go +++ b/main.go @@ -90,22 +90,29 @@ var ( HashAlgoMD5, } - root = flag.String("root", "./packages", "Path to packages directory") - bind = flag.String("bind", "[::]:8080", "Address to bind to") - tlsCert = flag.String("tls-cert", "", "Path to TLS X.509 certificate") - tlsKey = flag.String("tls-key", "", "Path to TLS X.509 private key") + root = flag.String("root", "./packages", "Path to packages directory") + bind = flag.String("bind", "[::]:8080", "Address to bind to") + maxClients = flag.Int("maxclients", 128, "Maximal amount of simultaneous clients") + doUCSPI = flag.Bool("ucspi", false, "Work as UCSPI-TCP service") + + tlsCert = flag.String("tls-cert", "", "Path to TLS X.509 certificate") + tlsKey = flag.String("tls-key", "", "Path to TLS X.509 private key") + norefreshURLPath = flag.String("norefresh", "/norefresh/", "Non-refreshing URL path") refreshURLPath = flag.String("refresh", "/simple/", "Auto-refreshing URL path") gpgUpdateURLPath = flag.String("gpgupdate", "/gpgupdate/", "GPG forceful refreshing URL path") - 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") - logTimestamped = flag.Bool("log-timestamped", false, "Prepend timestmap to log messages") - passwdPath = flag.String("passwd", "", "Path to FIFO for upload authentication") - passwdCheck = flag.Bool("passwd-check", false, "Run password checker") - fsck = flag.Bool("fsck", false, "Check integrity of all packages (errors are in stderr)") - maxClients = flag.Int("maxclients", 128, "Maximal amount of simultaneous clients") - version = flag.Bool("version", false, "Print version information") - warranty = flag.Bool("warranty", false, "Print warranty information") + + 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") + 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)") + version = flag.Bool("version", false, "Print version information") + warranty = flag.Bool("warranty", false, "Print warranty information") killed bool pypiURLParsed *url.URL @@ -278,7 +285,9 @@ func main() { } else { log.SetFlags(log.Lshortfile) } - log.SetOutput(os.Stdout) + if !*doUCSPI { + log.SetOutput(os.Stdout) + } if *fsck { if !goodIntegrity() { @@ -298,7 +307,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) } @@ -307,6 +320,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") @@ -340,11 +369,6 @@ func main() { } } - ln, err := net.Listen("tcp", *bind) - if err != nil { - log.Fatal(err) - } - ln = netutil.LimitListener(ln, *maxClients) server := &http.Server{ ReadTimeout: time.Minute, WriteTimeout: time.Minute, @@ -355,6 +379,24 @@ func main() { http.HandleFunc(*gpgUpdateURLPath, handler) } + if *doUCSPI { + server.SetKeepAlivesEnabled(false) + ln := &UCSPI{} + server.ConnState = connStater + err := server.Serve(ln) + if _, ok := err.(UCSPIAlreadyAccepted); !ok { + log.Fatalln(err) + } + UCSPIJob.Wait() + return + } + + ln, err := net.Listen("tcp", *bind) + if err != nil { + log.Fatal(err) + } + ln = netutil.LimitListener(ln, *maxClients) + needsShutdown := make(chan os.Signal, 0) exitErr := make(chan error, 0) signal.Notify(needsShutdown, syscall.SIGTERM, syscall.SIGINT)