local-ip.sh/main.go

39 lines
657 B
Go
Raw Normal View History

2022-10-27 21:19:23 +00:00
package main
import (
2022-10-28 21:36:57 +00:00
"flag"
2022-10-27 21:19:23 +00:00
"strings"
2023-02-26 13:06:15 +00:00
"time"
2022-10-27 21:19:23 +00:00
2023-02-26 13:06:15 +00:00
"local-ip.sh/certs"
"local-ip.sh/xip"
2022-10-27 21:19:23 +00:00
)
2022-10-28 21:36:57 +00:00
const (
2022-10-29 08:12:05 +00:00
zone = "local-ip.sh."
nameservers = "ns1.local-ip.sh.,ns2.local-ip.sh."
2022-10-28 21:36:57 +00:00
)
2022-10-27 21:19:23 +00:00
func main() {
2022-10-28 21:36:57 +00:00
var port = flag.Int("port", 53, "port the DNS server should bind to")
flag.Parse()
2022-10-27 21:19:23 +00:00
2022-10-28 21:36:57 +00:00
n := xip.NewXip(zone, strings.Split(nameservers, ","), *port)
2023-02-26 13:06:15 +00:00
go func() {
account := certs.LoadAccount()
2023-02-26 13:06:15 +00:00
certsClient := certs.NewCertsClient(n, account)
time.Sleep(5 * time.Second)
2023-02-26 13:06:15 +00:00
certsClient.RequestCertificate()
for {
2023-12-12 21:25:39 +00:00
// try to renew certificate every day
time.Sleep(24 * time.Hour)
2023-02-26 13:35:07 +00:00
certsClient.RequestCertificate()
2023-02-26 13:06:15 +00:00
}
}()
2022-10-28 21:36:57 +00:00
n.StartServer()
2022-10-27 21:19:23 +00:00
}