forked from joohoi/acme-dns
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
69 lines (59 loc) · 1.6 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
//+build !test
package main
import (
log "github.com/Sirupsen/logrus"
"github.com/iris-contrib/middleware/cors"
"github.com/kataras/iris"
"os"
)
func main() {
// Read global config
configTmp := readConfig("config.cfg")
DNSConf = configTmp
setupLogging(DNSConf.Logconfig.Format, DNSConf.Logconfig.Level)
// Read the default records in
RR.Parse(DNSConf.General)
// Open database
newDB := new(acmedb)
err := newDB.Init(DNSConf.Database.Engine, DNSConf.Database.Connection)
if err != nil {
log.Errorf("Could not open database [%v]", err)
os.Exit(1)
}
DB = newDB
defer DB.Close()
// DNS server
startDNS(DNSConf.General.Listen, DNSConf.General.Proto)
// HTTP API
startHTTPAPI()
log.Debugf("Shutting down...")
}
func startHTTPAPI() {
api := iris.New()
api.Config.DisableBanner = true
crs := cors.New(cors.Options{
AllowedOrigins: DNSConf.API.CorsOrigins,
AllowedMethods: []string{"GET", "POST"},
OptionsPassthrough: false,
Debug: DNSConf.General.Debug,
})
api.Use(crs)
var ForceAuth = authMiddleware{}
api.Get("/register", webRegisterGet)
api.Post("/register", webRegisterPost)
api.Post("/update", ForceAuth.Serve, webUpdatePost)
switch DNSConf.API.TLS {
case "letsencrypt":
listener, err := iris.LETSENCRYPTPROD(DNSConf.API.Domain)
err = api.Serve(listener)
if err != nil {
log.Errorf("Error in HTTP server [%v]", err)
}
case "cert":
host := DNSConf.API.Domain + ":" + DNSConf.API.Port
api.ListenTLS(host, DNSConf.API.TLSCertFullchain, DNSConf.API.TLSCertPrivkey)
default:
host := DNSConf.API.Domain + ":" + DNSConf.API.Port
api.Listen(host)
}
}