local-ip.sh/main.go

41 lines
711 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"
2023-02-26 13:06:15 +00:00
"log"
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()
log.Println(account.Registration.Body.Contact)
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 {
// renew certificate every month
time.Sleep(30 * 24 * time.Hour)
certsClient.RenewCertificate()
}
}()
2022-10-28 21:36:57 +00:00
n.StartServer()
2022-10-27 21:19:23 +00:00
}