summaryrefslogtreecommitdiff
path: root/hostname.go
diff options
context:
space:
mode:
Diffstat (limited to 'hostname.go')
-rw-r--r--hostname.go71
1 files changed, 59 insertions, 12 deletions
diff --git a/hostname.go b/hostname.go
index 62803c1..06e2ce7 100644
--- a/hostname.go
+++ b/hostname.go
@@ -6,8 +6,12 @@
package main
import (
- "log"
"git.wit.org/wit/shell"
+
+ // dnssec IPv6 socket library
+ "git.wit.org/jcarr/dnssecsocket"
+
+ "git.wit.org/jcarr/control-panel-dns/cloudflare"
)
// will try to get this hosts FQDN
@@ -16,15 +20,13 @@ import "github.com/Showmax/go-fqdn"
// this is the king of dns libraries
import "github.com/miekg/dns"
-// dnssec IPv6 socket library
-import "git.wit.org/jcarr/dnssecsocket"
func getHostname() {
var err error
var s string = "gui.Label == nil"
s, err = fqdn.FqdnHostname()
if (err != nil) {
- log.Println("FQDN hostname error =", err)
+ debug(LogError, "FQDN hostname error =", err)
return
}
if (me.fqdn != nil) {
@@ -34,7 +36,47 @@ func getHostname() {
me.changed = true
}
}
- log.Println("FQDN =", s)
+ 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)
+ if (me.hostnameStatus.S != "BROKEN") {
+ debug(LogChange, "me.hostname", me.hostname, "does not equal", test)
+ me.changed = true
+ me.hostnameStatus.SetText("BROKEN")
+ }
+ } else {
+ if (me.hostnameStatus.S != "VALID") {
+ debug(LogChange, "me.hostname", me.hostname, "is valid")
+ me.hostnameStatus.SetText("VALID")
+ 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")
+ })
+ }
+ }
+ }
}
// returns true if the hostname is good
@@ -43,31 +85,36 @@ func getHostname() {
// and domainname and hostname
func goodHostname(h string) bool {
hostname := shell.Chomp(shell.Cat("/etc/hostname"))
- log.Println("hostname =", hostname)
+ debug(true, "hostname =", hostname)
hs := run("hostname -s")
dn := run("domainname")
- log.Println("hostname short =", hs, "domainname =", dn)
+ debug(true, "hostname short =", hs, "domainname =", dn)
tmp := hs + "." + dn
if (hostname == tmp) {
- log.Println("hostname seems to be good", hostname)
+ debug(true, "hostname seems to be good", hostname)
return true
}
return false
}
-func dnsAAAA(s string) []string {
+func digAAAA(s string) []string {
var aaaa []string
// lookup the IP address from DNS
rrset := dnssecsocket.Dnstrace(s, "AAAA")
- log.Println(args.VerboseDNS, SPEW, rrset)
+ // debug(true, args.VerboseDNS, SPEW, rrset)
for i, rr := range rrset {
- log.Println(args.VerboseDNS, "r.Answer =", i, rr)
ipaddr := dns.Field(rr, 1)
+ // how the hell do you detect a RRSIG AAAA record here?
+ if (ipaddr == "28") {
+ continue
+ }
+ debug(LogNow, "r.Answer =", i, "rr =", rr, "ipaddr =", ipaddr)
aaaa = append(aaaa, ipaddr)
+ me.ipv6s[ipaddr] = rr
}
- log.Println(args.VerboseDNS, "aaaa =", aaaa)
+ debug(true, args.VerboseDNS, "aaaa =", aaaa)
return aaaa
}