2016-06-15 13:50:56 +02:00
|
|
|
// Copyright (c) 2012-2014 Jeremy Latt
|
|
|
|
// Copyright (c) 2014-2015 Edmund Huber
|
|
|
|
// Copyright (c) 2016- Daniel Oaks <daniel@danieloaks.net>
|
|
|
|
// released under the MIT license
|
|
|
|
|
2014-02-08 22:18:11 +01:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2014-02-24 07:21:39 +01:00
|
|
|
"fmt"
|
2014-02-09 16:53:42 +01:00
|
|
|
"log"
|
2016-04-12 15:00:09 +02:00
|
|
|
"syscall"
|
2014-03-13 02:57:00 +01:00
|
|
|
|
2016-04-13 00:55:37 +02:00
|
|
|
"github.com/DanielOaks/oragono/irc"
|
2016-08-12 23:40:58 +02:00
|
|
|
"github.com/DanielOaks/oragono/mkcerts"
|
2016-04-12 15:00:09 +02:00
|
|
|
"github.com/docopt/docopt-go"
|
|
|
|
"golang.org/x/crypto/ssh/terminal"
|
|
|
|
)
|
2014-03-13 02:57:00 +01:00
|
|
|
|
2016-04-12 15:00:09 +02:00
|
|
|
func main() {
|
|
|
|
version := irc.SEM_VER
|
2016-04-13 00:55:37 +02:00
|
|
|
usage := `oragono.
|
2016-04-12 15:00:09 +02:00
|
|
|
Usage:
|
2016-04-13 00:55:37 +02:00
|
|
|
oragono initdb [--conf <filename>]
|
|
|
|
oragono upgradedb [--conf <filename>]
|
|
|
|
oragono genpasswd [--conf <filename>]
|
2016-08-13 10:17:40 +02:00
|
|
|
oragono mkcerts [--conf <filename>]
|
2016-04-13 00:55:37 +02:00
|
|
|
oragono run [--conf <filename>]
|
|
|
|
oragono -h | --help
|
|
|
|
oragono --version
|
2016-04-12 15:00:09 +02:00
|
|
|
Options:
|
|
|
|
--conf <filename> Configuration file to use [default: ircd.yaml].
|
|
|
|
-h --help Show this screen.
|
|
|
|
--version Show version.`
|
|
|
|
|
|
|
|
arguments, _ := docopt.Parse(usage, nil, true, version, false)
|
|
|
|
|
|
|
|
configfile := arguments["--conf"].(string)
|
|
|
|
config, err := irc.LoadConfig(configfile)
|
2014-03-13 02:57:00 +01:00
|
|
|
if err != nil {
|
2016-04-12 15:00:09 +02:00
|
|
|
log.Fatal("Config file did not load successfully:", err.Error())
|
2014-03-13 02:57:00 +01:00
|
|
|
}
|
|
|
|
|
2016-04-12 15:00:09 +02:00
|
|
|
if arguments["genpasswd"].(bool) {
|
|
|
|
fmt.Print("Enter Password: ")
|
|
|
|
bytePassword, err := terminal.ReadPassword(int(syscall.Stdin))
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal("Error reading password:", err.Error())
|
|
|
|
}
|
|
|
|
password := string(bytePassword)
|
|
|
|
encoded, err := irc.GenerateEncodedPassword(password)
|
2014-03-02 00:10:04 +01:00
|
|
|
if err != nil {
|
2014-03-13 02:57:00 +01:00
|
|
|
log.Fatalln("encoding error:", err)
|
2014-03-02 00:10:04 +01:00
|
|
|
}
|
2016-04-12 15:00:09 +02:00
|
|
|
fmt.Print("\n")
|
2014-03-02 00:10:04 +01:00
|
|
|
fmt.Println(encoded)
|
2016-04-12 15:00:09 +02:00
|
|
|
} else if arguments["initdb"].(bool) {
|
2016-09-05 10:45:42 +02:00
|
|
|
irc.InitDB(config.Datastore.Path, config.Datastore.SQLitePath)
|
|
|
|
log.Println("databases initialized: ", config.Datastore.Path, config.Datastore.SQLitePath)
|
2016-04-12 15:00:09 +02:00
|
|
|
} else if arguments["upgradedb"].(bool) {
|
2016-08-19 15:21:52 +02:00
|
|
|
irc.UpgradeDB(config.Datastore.SQLitePath)
|
|
|
|
log.Println("database upgraded: ", config.Datastore.SQLitePath)
|
2016-08-13 10:17:40 +02:00
|
|
|
} else if arguments["mkcerts"].(bool) {
|
|
|
|
log.Println("making self-signed certificates")
|
2016-06-15 11:31:39 +02:00
|
|
|
|
|
|
|
for name, conf := range config.Server.TLSListeners {
|
2016-08-13 10:17:40 +02:00
|
|
|
log.Printf(" making cert for %s listener\n", name)
|
2016-06-15 11:31:39 +02:00
|
|
|
host := config.Server.Name
|
2016-08-12 23:40:58 +02:00
|
|
|
err := mkcerts.CreateCert("Oragono", host, conf.Cert, conf.Key)
|
|
|
|
if err == nil {
|
|
|
|
log.Printf(" Certificate created at %s : %s\n", conf.Cert, conf.Key)
|
|
|
|
} else {
|
|
|
|
log.Fatal(" Could not create certificate:", err.Error())
|
2016-06-15 11:31:39 +02:00
|
|
|
}
|
|
|
|
}
|
2016-04-12 15:00:09 +02:00
|
|
|
} else if arguments["run"].(bool) {
|
2014-03-13 02:57:00 +01:00
|
|
|
irc.Log.SetLevel(config.Server.Log)
|
|
|
|
server := irc.NewServer(config)
|
|
|
|
log.Println(irc.SEM_VER, "running")
|
|
|
|
defer log.Println(irc.SEM_VER, "exiting")
|
|
|
|
server.Run()
|
|
|
|
}
|
2014-02-08 22:18:11 +01:00
|
|
|
}
|