2023-12-29 01:36:10 -06:00
|
|
|
// figures out if your hostname is valid
|
|
|
|
// then checks if your DNS is setup correctly
|
2023-02-18 23:37:11 -06:00
|
|
|
package main
|
|
|
|
|
2023-12-16 09:02:59 -06:00
|
|
|
import (
|
2023-12-28 09:43:45 -06:00
|
|
|
"strings"
|
|
|
|
|
2023-12-29 01:36:10 -06:00
|
|
|
"go.wit.com/log"
|
2023-12-20 15:12:26 -06:00
|
|
|
"go.wit.com/shell"
|
|
|
|
"go.wit.com/control-panel-dns/cloudflare"
|
2023-12-28 09:43:45 -06:00
|
|
|
|
|
|
|
"github.com/miekg/dns"
|
2023-12-29 01:36:10 -06:00
|
|
|
// will try to get this hosts FQDN
|
|
|
|
"github.com/Showmax/go-fqdn"
|
2023-12-16 09:02:59 -06:00
|
|
|
)
|
2023-02-18 23:37:11 -06:00
|
|
|
|
|
|
|
func getHostname() {
|
|
|
|
var err error
|
2023-03-09 14:21:34 -06:00
|
|
|
var s string = "gui.Label == nil"
|
|
|
|
s, err = fqdn.FqdnHostname()
|
2023-02-18 23:37:11 -06:00
|
|
|
if (err != nil) {
|
2023-12-20 03:13:43 -06:00
|
|
|
debug(LogError, "FQDN hostname error =", err)
|
2023-02-18 23:37:11 -06:00
|
|
|
return
|
|
|
|
}
|
2023-03-09 14:21:34 -06:00
|
|
|
if (me.fqdn != nil) {
|
2023-03-26 16:17:32 -05:00
|
|
|
if (me.hostname != s) {
|
|
|
|
me.fqdn.SetText(s)
|
|
|
|
me.hostname = s
|
|
|
|
me.changed = true
|
|
|
|
}
|
2023-03-09 14:21:34 -06:00
|
|
|
}
|
2023-12-20 03:13:43 -06:00
|
|
|
debug(LogNet, "FQDN =", s)
|
|
|
|
|
|
|
|
dn := run("domainname")
|
|
|
|
if (me.domainname.S != dn) {
|
|
|
|
debug(LogChange, "domainname has changed from", me.domainname.S, "to", dn)
|
|
|
|
me.domainname.SetText(dn)
|
|
|
|
me.changed = true
|
|
|
|
}
|
|
|
|
|
|
|
|
hshort := run("hostname -s")
|
|
|
|
if (me.hostshort.S != hshort) {
|
|
|
|
debug(LogChange, "hostname -s has changed from", me.hostshort.S, "to", hshort)
|
|
|
|
me.hostshort.SetText(hshort)
|
|
|
|
me.changed = true
|
|
|
|
}
|
|
|
|
|
|
|
|
var test string
|
|
|
|
test = hshort + "." + dn
|
|
|
|
if (me.hostname != test) {
|
|
|
|
debug(LogInfo, "me.hostname", me.hostname, "does not equal", test)
|
2023-12-29 01:36:10 -06:00
|
|
|
if (me.hostnameStatusOLD.S != "BROKEN") {
|
2023-12-20 03:13:43 -06:00
|
|
|
debug(LogChange, "me.hostname", me.hostname, "does not equal", test)
|
|
|
|
me.changed = true
|
2023-12-29 01:36:10 -06:00
|
|
|
me.hostnameStatusOLD.SetText("BROKEN")
|
2023-12-20 03:13:43 -06:00
|
|
|
}
|
|
|
|
} else {
|
2023-12-29 01:36:10 -06:00
|
|
|
if (me.hostnameStatusOLD.S != "VALID") {
|
2023-12-20 03:13:43 -06:00
|
|
|
debug(LogChange, "me.hostname", me.hostname, "is valid")
|
2023-12-29 01:36:10 -06:00
|
|
|
me.hostnameStatusOLD.SetText("VALID")
|
2023-12-20 03:13:43 -06:00
|
|
|
me.changed = true
|
|
|
|
}
|
|
|
|
// enable the cloudflare button if the provider is cloudflare
|
|
|
|
if (me.cloudflareB == nil) {
|
|
|
|
debug(LogChange, "me.cloudflare == nil; me.DnsAPI.S =", me.DnsAPI.S)
|
|
|
|
if (me.DnsAPI.S == "cloudflare") {
|
|
|
|
me.cloudflareB = me.mainStatus.NewButton("cloudflare wit.com", func () {
|
|
|
|
cloudflare.CreateRR(myGui, "wit.com", "3777302ac4a78cd7fa4f6d3f72086d06")
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-12-16 09:02:59 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// returns true if the hostname is good
|
|
|
|
// check that all the OS settings are correct here
|
|
|
|
// On Linux, /etc/hosts, /etc/hostname
|
|
|
|
// and domainname and hostname
|
|
|
|
func goodHostname(h string) bool {
|
2023-12-16 09:36:40 -06:00
|
|
|
hostname := shell.Chomp(shell.Cat("/etc/hostname"))
|
2023-12-20 03:13:43 -06:00
|
|
|
debug(true, "hostname =", hostname)
|
2023-12-16 09:02:59 -06:00
|
|
|
|
2023-12-16 09:36:40 -06:00
|
|
|
hs := run("hostname -s")
|
|
|
|
dn := run("domainname")
|
2023-12-20 03:13:43 -06:00
|
|
|
debug(true, "hostname short =", hs, "domainname =", dn)
|
2023-12-16 09:36:40 -06:00
|
|
|
|
|
|
|
tmp := hs + "." + dn
|
|
|
|
if (hostname == tmp) {
|
2023-12-20 03:13:43 -06:00
|
|
|
debug(true, "hostname seems to be good", hostname)
|
2023-12-16 09:36:40 -06:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2023-12-16 09:02:59 -06:00
|
|
|
return false
|
2023-02-18 23:37:11 -06:00
|
|
|
}
|
|
|
|
|
2023-12-28 09:43:45 -06:00
|
|
|
/*
|
2023-12-20 03:13:43 -06:00
|
|
|
func digAAAA(s string) []string {
|
2023-03-01 11:21:47 -06:00
|
|
|
var aaaa []string
|
2023-02-18 23:37:11 -06:00
|
|
|
// lookup the IP address from DNS
|
2023-03-01 11:21:47 -06:00
|
|
|
rrset := dnssecsocket.Dnstrace(s, "AAAA")
|
2023-12-20 03:13:43 -06:00
|
|
|
// debug(true, args.VerboseDNS, SPEW, rrset)
|
2023-03-01 11:21:47 -06:00
|
|
|
for i, rr := range rrset {
|
|
|
|
ipaddr := dns.Field(rr, 1)
|
2023-12-20 03:13:43 -06:00
|
|
|
// how the hell do you detect a RRSIG AAAA record here?
|
|
|
|
if (ipaddr == "28") {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
debug(LogNow, "r.Answer =", i, "rr =", rr, "ipaddr =", ipaddr)
|
2023-03-01 11:21:47 -06:00
|
|
|
aaaa = append(aaaa, ipaddr)
|
2023-12-20 03:13:43 -06:00
|
|
|
me.ipv6s[ipaddr] = rr
|
2023-02-18 23:37:11 -06:00
|
|
|
}
|
2023-12-20 03:13:43 -06:00
|
|
|
debug(true, args.VerboseDNS, "aaaa =", aaaa)
|
2023-12-28 09:43:45 -06:00
|
|
|
log.Println("digAAAA() returned =", aaaa)
|
|
|
|
log.Println("digAAAA() me.ipv6s =", me.ipv6s)
|
|
|
|
os.Exit(0)
|
2023-03-01 11:21:47 -06:00
|
|
|
return aaaa
|
2023-02-18 23:37:11 -06:00
|
|
|
}
|
2023-12-28 09:43:45 -06:00
|
|
|
*/
|
|
|
|
|
|
|
|
func digAAAA(hostname string) []string {
|
|
|
|
var blah, ipv6Addresses []string
|
|
|
|
// domain := hostname
|
|
|
|
recordType := dns.TypeAAAA // dns.TypeTXT
|
|
|
|
|
|
|
|
// Cloudflare's DNS server
|
|
|
|
blah, _ = dnsUdpLookup("1.1.1.1:53", hostname, recordType)
|
|
|
|
log.Println("digAAAA() has BLAH =", blah)
|
|
|
|
|
|
|
|
if (len(blah) == 0) {
|
2023-12-28 15:36:05 -06:00
|
|
|
log.Println("digAAAA() RUNNING dnsAAAAlookupDoH(domain)")
|
|
|
|
ipv6Addresses, _ = dnsAAAAlookupDoH(hostname)
|
2023-12-28 09:43:45 -06:00
|
|
|
log.Println("digAAAA() has ipv6Addresses =", strings.Join(ipv6Addresses, " "))
|
|
|
|
for _, addr := range ipv6Addresses {
|
|
|
|
log.Println(addr)
|
|
|
|
}
|
|
|
|
return ipv6Addresses
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: check digDoH vs blah, if so, then port 53 TCP and/or UDP is broken or blocked
|
|
|
|
log.Println("digAAAA() has BLAH =", blah)
|
|
|
|
|
|
|
|
return blah
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
func dnsHttpsLookup(domain string, recordType uint16) ([]string, error) {
|
|
|
|
domain := "google.com"
|
|
|
|
dnsLookupDoH(domain string) ([]string, error) {
|
|
|
|
ipv6Addresses, err := dnsLookupDoH(domain)
|
|
|
|
if err != nil {
|
2023-12-28 15:36:05 -06:00
|
|
|
log.Println("Error:", err)
|
2023-12-28 09:43:45 -06:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-12-28 15:36:05 -06:00
|
|
|
log.Printf("IPv6 Addresses for %s:\n", domain)
|
2023-12-28 09:43:45 -06:00
|
|
|
for _, addr := range ipv6Addresses {
|
2023-12-28 15:36:05 -06:00
|
|
|
log.Println(addr)
|
2023-12-28 09:43:45 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
*/
|