2023-02-09 19:47:52 -06:00
|
|
|
// Various Linux/Unix'y things
|
|
|
|
|
|
|
|
// https://wiki.archlinux.org/title/Dynamic_DNS
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net"
|
2023-12-20 03:13:43 -06:00
|
|
|
"strings"
|
|
|
|
|
2024-01-03 19:33:13 -06:00
|
|
|
"go.wit.com/log"
|
2023-12-20 15:12:26 -06:00
|
|
|
"go.wit.com/shell"
|
2023-02-09 19:47:52 -06:00
|
|
|
)
|
|
|
|
|
|
|
|
/*
|
|
|
|
Check a bunch of things. If they don't work right, then things are not correctly configured
|
|
|
|
They are things like:
|
|
|
|
/etc/hosts
|
|
|
|
hostname
|
|
|
|
hostname -f
|
|
|
|
domainname
|
|
|
|
*/
|
|
|
|
func (h *Host) verifyETC() bool {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *Host) updateIPs(host string) {
|
|
|
|
ips, err := net.LookupIP(host)
|
|
|
|
if err != nil {
|
2024-01-03 19:33:13 -06:00
|
|
|
log.Error(err, "updateIPs failed")
|
2023-02-09 19:47:52 -06:00
|
|
|
}
|
|
|
|
for _, ip := range ips {
|
2023-12-16 09:02:59 -06:00
|
|
|
log.Println(host, ip)
|
2023-02-18 23:37:11 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *Host) setIPv4(ipv4s map[string]*IPtype) {
|
|
|
|
for ip, t := range ipv4s {
|
2023-12-16 09:02:59 -06:00
|
|
|
log.Println("IPv4", ip, t)
|
2023-02-09 19:47:52 -06:00
|
|
|
}
|
|
|
|
}
|
2023-02-18 23:37:11 -06:00
|
|
|
|
2024-01-06 17:51:41 -06:00
|
|
|
/*
|
2023-02-18 23:37:11 -06:00
|
|
|
func (h *Host) checkDNS() {
|
|
|
|
var ip4 bool = false
|
|
|
|
var ip6 bool = false
|
|
|
|
|
|
|
|
for s, t := range h.ipmap {
|
|
|
|
i := t.iface
|
|
|
|
ipt := "IPv4"
|
|
|
|
if (t.ipv6) {
|
|
|
|
ipt = "IPv6"
|
|
|
|
}
|
|
|
|
if (! t.IsReal()) {
|
2023-12-16 09:02:59 -06:00
|
|
|
log.Println(args.VerboseDNS, "\tIP is not Real", ipt, i.Index, i.Name, s)
|
2023-02-18 23:37:11 -06:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2023-12-16 09:02:59 -06:00
|
|
|
log.Println(args.VerboseDNS, "\tIP is Real ", ipt, i.Index, i.Name, s)
|
2023-02-18 23:37:11 -06:00
|
|
|
if (t.ipv6) {
|
|
|
|
ip6 = true
|
|
|
|
} else {
|
|
|
|
ip4 = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ip4 == true) {
|
2023-12-16 09:02:59 -06:00
|
|
|
log.Println(args.VerboseDNS, "IPv4 should work. Wow. You actually have a real IPv4 address")
|
2023-02-18 23:37:11 -06:00
|
|
|
} else {
|
2023-12-16 09:02:59 -06:00
|
|
|
log.Println(args.VerboseDNS, "IPv4 is broken. (be nice and setup ipv4-only.wit.com)")
|
2023-02-18 23:37:11 -06:00
|
|
|
}
|
|
|
|
if (ip6 == true) {
|
2023-12-16 09:02:59 -06:00
|
|
|
log.Println(args.VerboseDNS, "IPv6 should be working. Need to test it here.")
|
2023-02-18 23:37:11 -06:00
|
|
|
} else {
|
2023-12-16 09:02:59 -06:00
|
|
|
log.Println(args.VerboseDNS, "IPv6 is broken. Need to fix it here.")
|
2023-02-18 23:37:11 -06:00
|
|
|
}
|
|
|
|
}
|
2024-01-06 17:51:41 -06:00
|
|
|
*/
|
2023-12-20 03:13:43 -06:00
|
|
|
|
|
|
|
// nsLookup performs an NS lookup on the given domain name.
|
|
|
|
func lookupNS(domain string) {
|
|
|
|
var domains string
|
|
|
|
|
|
|
|
nsRecords, err := net.LookupNS(domain)
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
var servers []string
|
|
|
|
for _, ns := range nsRecords {
|
|
|
|
servers = append(servers, ns.Host)
|
|
|
|
}
|
|
|
|
|
|
|
|
// checks to see if the NS records change
|
|
|
|
for _, server := range servers {
|
|
|
|
server = strings.TrimRight(server, ".")
|
|
|
|
if (me.nsmap[server] != domain) {
|
2024-01-03 19:33:13 -06:00
|
|
|
log.Log(CHANGE, "lookupNS() domain", domain, "has NS", server)
|
2023-12-20 03:13:43 -06:00
|
|
|
me.nsmap[server] = domain
|
|
|
|
domains += server + "\n"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var tmp string
|
|
|
|
// checks to see if the NS records change
|
|
|
|
for s, d := range me.nsmap {
|
2024-01-03 19:33:13 -06:00
|
|
|
log.Log(CHANGE, "lookupNS() domain =", d, "server =", s)
|
2023-12-20 03:13:43 -06:00
|
|
|
if (domain == d) {
|
|
|
|
tmp += s + "\n"
|
|
|
|
// figure out the provider (google, cloudflare, etc)
|
|
|
|
setProvider(s)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
tmp = shell.Chomp(tmp)
|
|
|
|
|
2024-01-06 19:58:58 -06:00
|
|
|
if (tmp != me.statusDNS.NSrr.Get()) {
|
2023-12-20 03:13:43 -06:00
|
|
|
me.changed = true
|
2024-01-06 17:51:41 -06:00
|
|
|
log.Log(CHANGE, "lookupNS() setting changed to me.NSrr =", tmp)
|
2024-01-06 19:58:58 -06:00
|
|
|
me.statusDNS.NSrr.Set(tmp)
|
2023-12-20 03:13:43 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// getDomain returns the second-to-last part of a domain name.
|
|
|
|
func setProvider(hostname string) {
|
|
|
|
var provider string = ""
|
|
|
|
parts := strings.Split(hostname, ".")
|
|
|
|
if len(parts) >= 2 {
|
|
|
|
provider = parts[len(parts)-2]
|
|
|
|
}
|
|
|
|
if (me.DnsAPI.S != provider) {
|
|
|
|
me.changed = true
|
2024-01-03 19:33:13 -06:00
|
|
|
log.Log(CHANGE, "setProvider() changed to =", provider)
|
2023-12-20 03:13:43 -06:00
|
|
|
me.DnsAPI.SetText(provider)
|
|
|
|
}
|
|
|
|
}
|