2023-02-09 19:47:52 -06:00
|
|
|
// Various Linux/Unix'y things
|
|
|
|
|
|
|
|
// https://wiki.archlinux.org/title/Dynamic_DNS
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
2024-01-21 00:15:20 -06:00
|
|
|
import (
|
2023-02-09 19:47:52 -06:00
|
|
|
"net"
|
2023-12-20 03:13:43 -06:00
|
|
|
"strings"
|
|
|
|
|
2024-01-31 13:34:02 -06:00
|
|
|
"go.wit.com/log"
|
2023-02-09 19:47:52 -06:00
|
|
|
)
|
|
|
|
|
|
|
|
/*
|
2024-01-21 00:15:20 -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
|
2023-02-09 19:47:52 -06:00
|
|
|
*/
|
|
|
|
func (h *Host) verifyETC() bool {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *Host) updateIPs(host string) {
|
2024-01-21 00:15:20 -06:00
|
|
|
ips, err := net.LookupIP(host)
|
|
|
|
if err != nil {
|
|
|
|
log.Error(err, "updateIPs failed")
|
|
|
|
}
|
|
|
|
for _, ip := range ips {
|
|
|
|
log.Println(host, ip)
|
|
|
|
}
|
2023-02-18 23:37:11 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
func (h *Host) setIPv4(ipv4s map[string]*IPtype) {
|
2024-01-21 00:15:20 -06:00
|
|
|
for ip, t := range ipv4s {
|
2023-12-16 09:02:59 -06:00
|
|
|
log.Println("IPv4", ip, t)
|
2024-01-21 00:15:20 -06:00
|
|
|
}
|
2023-02-09 19:47:52 -06:00
|
|
|
}
|
2023-02-18 23:37:11 -06:00
|
|
|
|
2024-01-10 20:22:25 -06:00
|
|
|
/*
|
2024-01-07 12:45:01 -06:00
|
|
|
func lookupNSprovider(domain string) string {
|
|
|
|
for s, d := range me.nsmap {
|
|
|
|
log.Log(CHANGE, "lookupNS() domain =", d, "server =", s)
|
|
|
|
if (domain == d) {
|
|
|
|
// figure out the provider (google, cloudflare, etc)
|
|
|
|
return s + " blah"
|
2023-02-18 23:37:11 -06:00
|
|
|
}
|
|
|
|
}
|
2024-01-07 12:45:01 -06:00
|
|
|
return "blah"
|
2023-02-18 23:37:11 -06:00
|
|
|
}
|
2024-01-10 20:22:25 -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, ".")
|
2024-01-21 00:15:20 -06:00
|
|
|
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)
|
2024-01-21 00:15:20 -06:00
|
|
|
if domain == d {
|
2023-12-20 03:13:43 -06:00
|
|
|
tmp += s + "\n"
|
|
|
|
// figure out the provider (google, cloudflare, etc)
|
|
|
|
setProvider(s)
|
|
|
|
}
|
|
|
|
}
|
2024-11-08 06:42:46 -06:00
|
|
|
tmp = strings.TrimSpace(tmp)
|
2023-12-20 03:13:43 -06:00
|
|
|
|
2024-01-21 00:15:20 -06:00
|
|
|
if tmp != me.statusDNS.NSrr.String() {
|
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-31 12:36:52 -06:00
|
|
|
me.statusDNS.NSrr.SetText(tmp)
|
2023-12-20 03:13:43 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-10 20:22:25 -06:00
|
|
|
// returns the second-to-last part of a domain name.
|
2023-12-20 03:13:43 -06:00
|
|
|
func setProvider(hostname string) {
|
|
|
|
var provider string = ""
|
|
|
|
parts := strings.Split(hostname, ".")
|
|
|
|
if len(parts) >= 2 {
|
|
|
|
provider = parts[len(parts)-2]
|
|
|
|
}
|
2024-01-10 20:22:25 -06:00
|
|
|
if me.statusDNS.GetDNSapi() != provider {
|
2024-01-03 19:33:13 -06:00
|
|
|
log.Log(CHANGE, "setProvider() changed to =", provider)
|
2023-12-20 03:13:43 -06:00
|
|
|
}
|
2024-01-10 20:22:25 -06:00
|
|
|
me.statusDNS.SetDNSapi(provider)
|
2023-12-20 03:13:43 -06:00
|
|
|
}
|