3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-11-22 20:09:41 +01:00
ergo/cmd/oragono-web/oragono-web.go
2017-06-14 12:12:02 -06:00

68 lines
1.8 KiB
Go

// Copyright (c) 2016- Daniel Oaks <daniel@danieloaks.net>
// released under the MIT license
package main
import (
"fmt"
"log"
"github.com/docopt/docopt-go"
"github.com/oragono/oragono/mkcerts"
"github.com/oragono/oragono/web"
)
func main() {
version := irc.SemVer
usage := `oragono-web.
Usage:
oragono-web mkcerts [--conf <filename>] [--quiet]
oragono-web run [--conf <filename>] [--quiet]
oragono-web -h | --help
oragono-web --version
Options:
--conf <filename> Configuration file to use [default: web.yaml].
--quiet Don't show startup/shutdown lines.
-h --help Show this screen.
--version Show version.`
arguments, _ := docopt.Parse(usage, nil, true, version, false)
configfile := arguments["--conf"].(string)
config, err := web.LoadConfig(configfile)
if err != nil {
log.Fatal("Config file did not load successfully:", err.Error())
}
if arguments["mkcerts"].(bool) {
if !arguments["--quiet"].(bool) {
log.Println("making self-signed certificates")
}
for name, conf := range config.TLSListenersConf {
log.Printf(" making cert for %s listener\n", name)
host := config.Host
err := mkcerts.CreateCert("Oragono web interface", host, conf.Cert, conf.Key)
if err == nil {
if !arguments["--quiet"].(bool) {
log.Printf(" Certificate created at %s : %s\n", conf.Cert, conf.Key)
}
} else {
log.Fatal(" Could not create certificate:", err.Error())
}
}
} else if arguments["run"].(bool) {
irc.Log.SetLevel(config.Log)
server := web.NewServer(config)
if server == nil {
log.Println("Could not load server")
return
}
if !arguments["--quiet"].(bool) {
log.Println(fmt.Sprintf("Oragono web interface v%s running", irc.SemVer))
defer log.Println(irc.SemVer, "exiting")
}
server.Run()
}
}