2014-07-12 22:37:00 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2017-07-02 22:58:07 +02:00
|
|
|
"flag"
|
2017-07-02 22:27:41 +02:00
|
|
|
"github.com/pboehm/ddns/backend"
|
2017-12-03 22:42:25 +01:00
|
|
|
"github.com/pboehm/ddns/frontend"
|
|
|
|
"github.com/pboehm/ddns/shared"
|
2014-07-12 22:37:00 +02:00
|
|
|
"log"
|
2014-07-12 23:37:01 +02:00
|
|
|
"strings"
|
2014-07-12 22:37:00 +02:00
|
|
|
)
|
|
|
|
|
2017-12-03 22:42:25 +01:00
|
|
|
var serviceConfig *shared.Config = &shared.Config{}
|
2014-07-14 23:19:47 +02:00
|
|
|
|
2014-07-15 23:12:27 +02:00
|
|
|
func init() {
|
2017-01-29 19:02:14 +01:00
|
|
|
flag.StringVar(&serviceConfig.Domain, "domain", "",
|
2014-07-15 23:12:27 +02:00
|
|
|
"The subdomain which should be handled by DDNS")
|
2014-07-15 23:41:54 +02:00
|
|
|
|
2017-01-29 19:02:14 +01:00
|
|
|
flag.StringVar(&serviceConfig.Listen, "listen", ":8080",
|
2014-07-15 23:41:54 +02:00
|
|
|
"Which socket should the web service use to bind itself")
|
2014-07-16 14:14:16 +02:00
|
|
|
|
2017-01-29 19:02:14 +01:00
|
|
|
flag.StringVar(&serviceConfig.RedisHost, "redis", ":6379",
|
2014-07-16 14:14:16 +02:00
|
|
|
"The Redis socket that should be used")
|
2014-07-29 20:23:45 +02:00
|
|
|
|
2017-01-29 19:02:14 +01:00
|
|
|
flag.StringVar(&serviceConfig.SOAFqdn, "soa_fqdn", "",
|
2014-09-21 17:27:26 +02:00
|
|
|
"The FQDN of the DNS server which is returned as a SOA record")
|
|
|
|
|
2017-01-29 19:02:14 +01:00
|
|
|
flag.IntVar(&serviceConfig.HostExpirationDays, "expiration-days", 10,
|
|
|
|
"The number of days after a host is released when it is not updated")
|
|
|
|
|
|
|
|
flag.BoolVar(&serviceConfig.Verbose, "verbose", false,
|
2014-07-29 20:23:45 +02:00
|
|
|
"Be more verbose")
|
2014-07-14 23:19:47 +02:00
|
|
|
}
|
|
|
|
|
2017-11-29 00:43:00 +01:00
|
|
|
func validateCommandArgs() {
|
2017-01-29 19:02:14 +01:00
|
|
|
if serviceConfig.Domain == "" {
|
2014-07-15 21:48:15 +02:00
|
|
|
log.Fatal("You have to supply the domain via --domain=DOMAIN")
|
2017-01-29 19:02:14 +01:00
|
|
|
} else if !strings.HasPrefix(serviceConfig.Domain, ".") {
|
2014-07-15 21:48:15 +02:00
|
|
|
// get the domain in the right format
|
2017-01-29 19:02:14 +01:00
|
|
|
serviceConfig.Domain = "." + serviceConfig.Domain
|
2014-07-15 21:48:15 +02:00
|
|
|
}
|
2014-09-21 17:27:26 +02:00
|
|
|
|
2017-11-29 00:43:00 +01:00
|
|
|
if serviceConfig.SOAFqdn == "" {
|
|
|
|
log.Fatal("You have to supply the server FQDN via --soa_fqdn=FQDN")
|
2014-09-21 17:27:26 +02:00
|
|
|
}
|
2014-07-15 21:48:15 +02:00
|
|
|
}
|
2014-07-15 19:20:11 +02:00
|
|
|
|
2014-07-15 23:12:27 +02:00
|
|
|
func main() {
|
2017-11-29 00:43:00 +01:00
|
|
|
flag.Parse()
|
|
|
|
validateCommandArgs()
|
2014-07-15 23:12:27 +02:00
|
|
|
|
2017-12-03 22:42:25 +01:00
|
|
|
redis := shared.NewRedisBackend(serviceConfig)
|
2017-01-29 19:02:14 +01:00
|
|
|
defer redis.Close()
|
2014-07-15 23:12:27 +02:00
|
|
|
|
2017-11-29 00:43:00 +01:00
|
|
|
lookup := backend.NewHostLookup(serviceConfig, redis)
|
2017-01-29 19:02:14 +01:00
|
|
|
|
2017-12-03 22:42:25 +01:00
|
|
|
frontend.NewWebService(serviceConfig, redis, lookup).Run()
|
2014-07-12 22:37:00 +02:00
|
|
|
}
|