-/*
-GoCheese -- Python private package repository and caching proxy
-Copyright (C) 2019-2023 Sergey Matveev <stargrave@stargrave.org>
- 2019-2023 Elena Balakhonova <balakhonova_e@riseup.net>
-
-This program is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, version 3 of the License.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program. If not, see <http://www.gnu.org/licenses/>.
-*/
+// GoCheese -- Python private package repository and caching proxy
+// Copyright (C) 2019-2024 Sergey Matveev <stargrave@stargrave.org>
+// 2019-2024 Elena Balakhonova <balakhonova_e@riseup.net>
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, version 3 of the License.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
// Python private package repository and caching proxy
package main
)
const (
- Version = "4.0.0"
+ Version = "4.2.0"
UserAgent = "GoCheese/" + Version
)
PasswdPath = flag.String("passwd", "", "")
PasswdListPath = flag.String("passwd-list", "", "")
PasswdCheck = flag.Bool("passwd-check", false, "")
+ AuthRequired = flag.Bool("auth-required", false, "")
LogTimestamped = flag.Bool("log-timestamped", false, "")
FSCK = flag.Bool("fsck", false, "")
}
Root = flag.Args()[0]
if _, err := os.Stat(Root); err != nil {
- log.Fatalln(err)
+ log.Fatal(err)
}
if *FSCK {
os.FileMode(0666),
)
if err != nil {
- log.Fatalln(err)
+ log.Fatal(err)
}
passwdReader(fd)
fd.Close()
os.FileMode(0666),
)
if err != nil {
- log.Fatalln(err)
+ log.Fatal(err)
}
passwdLister(fd)
fd.Close()
}
if (*TLSCert != "" && *TLSKey == "") || (*TLSCert == "" && *TLSKey != "") {
- log.Fatalln("Both -tls-cert and -tls-key are required")
+ log.Fatal("Both -tls-cert and -tls-key are required")
}
UmaskCur = syscall.Umask(0)
var err error
PyPIURLParsed, err = url.Parse(*PyPIURL)
if err != nil {
- log.Fatalln(err)
+ log.Fatal(err)
}
tlsConfig := tls.Config{
ClientSessionCache: tls.NewLRUClientSessionCache(16),
if *PyPICertHash != "" {
ourDgst, err := hex.DecodeString(*PyPICertHash)
if err != nil {
- log.Fatalln(err)
+ log.Fatal(err)
}
tlsConfig.VerifyConnection = func(s tls.ConnectionState) error {
spki := s.VerifiedChains[0][0].RawSubjectPublicKeyInfo
ReadTimeout: time.Minute,
WriteTimeout: time.Minute,
}
- http.HandleFunc("/", serveHRRoot)
- http.HandleFunc("/hr/", serveHRPkg)
- http.HandleFunc(*JSONURLPath, serveJSON)
- http.HandleFunc(*NoRefreshURLPath, handler)
- http.HandleFunc(*RefreshURLPath, handler)
+ http.HandleFunc("/", checkAuth(serveHRRoot))
+ http.HandleFunc("/hr/", checkAuth(serveHRPkg))
+ http.HandleFunc(*JSONURLPath, checkAuth(serveJSON))
+ http.HandleFunc(*NoRefreshURLPath, checkAuth(handler))
+ http.HandleFunc(*RefreshURLPath, checkAuth(handler))
if *DoUCSPI {
server.SetKeepAlivesEnabled(false)
server.ConnState = connStater
err := server.Serve(ln)
if _, ok := err.(UCSPIAlreadyAccepted); !ok {
- log.Fatalln(err)
+ log.Fatal(err)
}
UCSPIJob.Wait()
return