iconia/main.go

67 lines
1.7 KiB
Go

package main
import (
"flag"
"log"
"net/http"
"sync"
"github.com/facebookarchive/flagenv"
"github.com/hashicorp/yamux"
"go.chromium.org/luci/common/flag/stringmapflag"
"golang.org/x/crypto/acme/autocert"
"within.website/confyg/flagconfyg"
"within.website/x/localca"
)
var (
httpPort = flag.String("http-port", "3043", "HTTP port")
httpsPort = flag.String("https-port", "3044", "HTTPS port")
yamuxPort = flag.String("yamux-port", "3045", "yamux port")
statusPort = flag.String("status-port", "3046", "status server port")
// TLS certificate configuration
domainSuffix = flag.String("domain-suffix", ".local.cetacean.club", "allowed domain suffix for certificate generation")
certFile = flag.String("cert-file", "./var/minica.pem", "TLS certificate authority public certificate")
keyFile = flag.String("key-file", "./var/minica-key.pem", "TLS certificate authority private key")
certFolder = flag.String("cert-folder", "./var/certs", "TLS certificate storage folder")
// hosts -> tokens
hostsToTokens = new(stringmapflag.Value)
)
func init() {
flag.Var(hostsToTokens, "host-token", "accepted pairs of hostname -> token mappings")
}
func main() {
flagenv.Parse()
flagconfyg.CmdParse("./iconia.confyg")
flag.Parse()
flag.VisitAll(func(fl *flag.Flag) {
log.Printf("%s: %s", fl.Name, fl.Value)
})
cfg := Config{
HTTPPort: *httpPort,
HTTPSPort: *httpsPort,
YamuxPort: *yamuxPort,
StatusPort: *statusPort,
DomainSuffix: *domainSuffix,
}
s := &Server{
Config: cfg,
clients: map[string][]*yamux.Session{},
clientsLock: &sync.RWMutex{},
certManager: localca.New(*certFile, *keyFile, *domainSuffix, autocert.DirCache(*certFolder)),
plainServer: &http.Server{
Addr: ":" + *httpPort,
},
}
}