2014-07-12 22:37:00 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2014-07-15 21:48:15 +02:00
|
|
|
"flag"
|
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
|
|
|
)
|
|
|
|
|
|
|
|
func HandleErr(err error) {
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-15 23:12:27 +02:00
|
|
|
var (
|
2014-07-15 23:41:54 +02:00
|
|
|
DdnsDomain string
|
|
|
|
DdnsWebListenSocket string
|
2014-07-16 14:14:16 +02:00
|
|
|
DdnsRedisHost string
|
2014-07-29 20:23:45 +02:00
|
|
|
Verbose bool
|
2014-07-15 23:12:27 +02:00
|
|
|
)
|
2014-07-14 23:19:47 +02:00
|
|
|
|
2014-07-15 23:12:27 +02:00
|
|
|
func init() {
|
|
|
|
flag.StringVar(&DdnsDomain, "domain", "",
|
|
|
|
"The subdomain which should be handled by DDNS")
|
2014-07-15 23:41:54 +02:00
|
|
|
|
|
|
|
flag.StringVar(&DdnsWebListenSocket, "listen", ":8080",
|
|
|
|
"Which socket should the web service use to bind itself")
|
2014-07-16 14:14:16 +02:00
|
|
|
|
|
|
|
flag.StringVar(&DdnsRedisHost, "redis", ":6379",
|
|
|
|
"The Redis socket that should be used")
|
2014-07-29 20:23:45 +02:00
|
|
|
|
|
|
|
flag.BoolVar(&Verbose, "verbose", false,
|
|
|
|
"Be more verbose")
|
2014-07-14 23:19:47 +02:00
|
|
|
}
|
|
|
|
|
2014-07-15 21:48:15 +02:00
|
|
|
func ValidateCommandArgs() {
|
|
|
|
if DdnsDomain == "" {
|
|
|
|
log.Fatal("You have to supply the domain via --domain=DOMAIN")
|
|
|
|
} else if !strings.HasPrefix(DdnsDomain, ".") {
|
|
|
|
// get the domain in the right format
|
|
|
|
DdnsDomain = "." + DdnsDomain
|
|
|
|
}
|
|
|
|
}
|
2014-07-15 19:20:11 +02:00
|
|
|
|
2014-07-15 23:12:27 +02:00
|
|
|
func PrepareForExecution() string {
|
2014-07-15 21:48:15 +02:00
|
|
|
flag.Parse()
|
|
|
|
ValidateCommandArgs()
|
2014-07-12 22:37:00 +02:00
|
|
|
|
2014-07-15 21:48:15 +02:00
|
|
|
if len(flag.Args()) != 1 {
|
2014-07-12 22:37:00 +02:00
|
|
|
usage()
|
|
|
|
}
|
2014-07-15 21:48:15 +02:00
|
|
|
cmd := flag.Args()[0]
|
2014-07-12 22:37:00 +02:00
|
|
|
|
2014-07-15 23:12:27 +02:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
2014-07-15 23:41:54 +02:00
|
|
|
cmd := PrepareForExecution()
|
2014-07-15 23:12:27 +02:00
|
|
|
|
2014-07-16 15:03:06 +02:00
|
|
|
conn := OpenConnection(DdnsRedisHost)
|
2014-07-15 23:12:27 +02:00
|
|
|
defer conn.Close()
|
|
|
|
|
2014-07-12 22:37:00 +02:00
|
|
|
switch cmd {
|
|
|
|
case "backend":
|
|
|
|
log.Printf("Starting PDNS Backend\n")
|
2014-07-15 23:12:27 +02:00
|
|
|
RunBackend(conn)
|
2014-07-12 22:37:00 +02:00
|
|
|
case "web":
|
|
|
|
log.Printf("Starting Web Service\n")
|
2014-07-15 23:12:27 +02:00
|
|
|
RunWebService(conn)
|
2014-07-12 22:37:00 +02:00
|
|
|
default:
|
|
|
|
usage()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func usage() {
|
|
|
|
log.Fatal("Usage: ./ddns [backend|web]")
|
|
|
|
}
|