Files
acme-dns/main.go

64 lines
1.5 KiB
Go
Raw Normal View History

//+build !test
2016-11-11 16:48:00 +02:00
package main
import (
"os"
2017-01-30 12:19:22 +02:00
"github.com/iris-contrib/middleware/cors"
"github.com/kataras/iris"
log "github.com/sirupsen/logrus"
2016-11-11 16:48:00 +02:00
)
func main() {
2016-11-13 14:50:44 +02:00
// Read global config
2016-11-27 23:21:46 +02:00
configTmp := readConfig("config.cfg")
2016-11-16 19:15:36 +02:00
DNSConf = configTmp
2016-11-23 17:11:31 +02:00
2016-11-27 21:21:38 +02:00
setupLogging(DNSConf.Logconfig.Format, DNSConf.Logconfig.Level)
2016-11-13 14:50:44 +02:00
// Read the default records in
RR.Parse(DNSConf.General)
2016-11-11 16:48:00 +02:00
// Open database
2016-11-27 23:21:46 +02:00
newDB := new(acmedb)
err := newDB.Init(DNSConf.Database.Engine, DNSConf.Database.Connection)
2016-11-11 16:48:00 +02:00
if err != nil {
log.Errorf("Could not open database [%v]", err)
os.Exit(1)
}
2016-11-27 23:21:46 +02:00
DB = newDB
defer DB.Close()
2016-11-11 16:48:00 +02:00
2016-11-27 21:21:38 +02:00
// DNS server
2016-11-28 22:46:24 +02:00
startDNS(DNSConf.General.Listen, DNSConf.General.Proto)
2016-11-11 16:48:00 +02:00
2016-11-27 22:09:13 +02:00
// HTTP API
startHTTPAPI()
2016-11-11 16:48:00 +02:00
log.Debugf("Shutting down...")
}
2016-11-28 13:09:10 +02:00
func startHTTPAPI() {
api := iris.New()
api.Use(cors.New(cors.Options{
2016-11-28 13:09:10 +02:00
AllowedOrigins: DNSConf.API.CorsOrigins,
AllowedMethods: []string{"GET", "POST"},
OptionsPassthrough: false,
Debug: DNSConf.General.Debug,
}))
2016-11-28 13:09:10 +02:00
var ForceAuth = authMiddleware{}
api.Post("/register", webRegisterPost)
api.Post("/update", ForceAuth.Serve, webUpdatePost)
host := DNSConf.API.Domain + ":" + DNSConf.API.Port
2016-11-28 13:09:10 +02:00
switch DNSConf.API.TLS {
case "letsencrypt":
api.Run(iris.AutoTLS(host, DNSConf.API.Domain, DNSConf.API.LEmail), iris.WithoutBodyConsumptionOnUnmarshal)
2016-11-28 13:09:10 +02:00
case "cert":
api.Run(iris.TLS(host, DNSConf.API.TLSCertFullchain, DNSConf.API.TLSCertPrivkey), iris.WithoutBodyConsumptionOnUnmarshal)
2016-11-28 13:09:10 +02:00
default:
api.Run(iris.Addr(host), iris.WithoutBodyConsumptionOnUnmarshal)
2016-11-28 13:09:10 +02:00
}
}