summaryrefslogtreecommitdiff
path: root/hostnameStatus.go
diff options
context:
space:
mode:
Diffstat (limited to 'hostnameStatus.go')
-rw-r--r--hostnameStatus.go192
1 files changed, 106 insertions, 86 deletions
diff --git a/hostnameStatus.go b/hostnameStatus.go
index 29caee6..cacca3e 100644
--- a/hostnameStatus.go
+++ b/hostnameStatus.go
@@ -1,4 +1,4 @@
-/*
+/*
figures out if your hostname is valid
then checks if your DNS is setup correctly
*/
@@ -6,54 +6,54 @@
package main
import (
- "os"
+ "errors"
"fmt"
- "time"
+ "os"
"reflect"
- "strings"
"sort"
- "errors"
+ "strings"
+ "time"
+ "go.wit.com/lib/gadgets"
+ "go.wit.com/gui"
"go.wit.com/log"
- "go.wit.com/gui/gui"
- "go.wit.com/gui/gadgets"
)
type hostnameStatus struct {
- ready bool
- hidden bool
- changed bool
+ ready bool
+ hidden bool
+ changed bool
- lastname string // used to watch for changes in the hostname
+ lastname string // used to watch for changes in the hostname
- window *gadgets.BasicWindow
+ window *gadgets.BasicWindow
// Primary Directives
- status *gadgets.OneLiner
- summary *gadgets.OneLiner
- statusIPv4 *gadgets.OneLiner
- statusIPv6 *gadgets.OneLiner
+ status *gadgets.OneLiner
+ summary *gadgets.OneLiner
+ statusIPv4 *gadgets.OneLiner
+ statusIPv6 *gadgets.OneLiner
- hostname *gadgets.OneLiner
- domainname *gadgets.OneLiner
+ hostname *gadgets.OneLiner
+ domainname *gadgets.OneLiner
// what the current IP addresses your network has given you
- currentIPv4 *gadgets.OneLiner
- currentIPv6 *gadgets.OneLiner
+ currentIPv4 *gadgets.OneLiner
+ currentIPv6 *gadgets.OneLiner
// what the DNS servers have
- NSrr *gadgets.OneLiner
- dnsA *gadgets.OneLiner
- dnsAAAA *gadgets.OneLiner
- dnsAPI *gadgets.OneLiner
- APIprovider string
+ NSrr *gadgets.OneLiner
+ dnsA *gadgets.OneLiner
+ dnsAAAA *gadgets.OneLiner
+ dnsAPI *gadgets.OneLiner
+ APIprovider string
- speed *gadgets.OneLiner
- speedActual *gadgets.OneLiner
+ speed *gadgets.OneLiner
+ speedActual *gadgets.OneLiner
// Actions
-// dnsValue *gui.Node
-// dnsAction *gui.Node
+ // dnsValue *gui.Node
+ // dnsAction *gui.Node
}
func NewHostnameStatusWindow(p *gui.Node) *hostnameStatus {
@@ -64,7 +64,7 @@ func NewHostnameStatusWindow(p *gui.Node) *hostnameStatus {
hs.hidden = true
// hs.hostname = me.hostname
- hs.window = gadgets.NewBasicWindow(p, "fix hostname here" + " Status")
+ hs.window = gadgets.NewBasicWindow(p, "fix hostname here"+" Status")
hs.window.Make()
// hs.window.Draw()
// hs.window.Hide()
@@ -72,9 +72,9 @@ func NewHostnameStatusWindow(p *gui.Node) *hostnameStatus {
group := hs.window.Box().NewGroup("Summary")
grid := group.NewGrid("LookupStatus", 2, 2)
- hs.status = gadgets.NewOneLiner(grid, "status").Set("unknown")
- hs.statusIPv4 = gadgets.NewOneLiner(grid, "IPv4").Set("unknown")
- hs.statusIPv6 = gadgets.NewOneLiner(grid, "IPv6").Set("unknown")
+ hs.status = gadgets.NewOneLiner(grid, "status").SetValue("unknown")
+ hs.statusIPv4 = gadgets.NewOneLiner(grid, "IPv4").SetValue("unknown")
+ hs.statusIPv6 = gadgets.NewOneLiner(grid, "IPv6").SetValue("unknown")
group.Pad()
grid.Pad()
@@ -82,18 +82,18 @@ func NewHostnameStatusWindow(p *gui.Node) *hostnameStatus {
group = hs.window.Box().NewGroup("Details")
grid = group.NewGrid("LookupDetails", 2, 2)
- hs.hostname = gadgets.NewOneLiner(grid, "hostname")
- hs.domainname = gadgets.NewOneLiner(grid, "domain name")
- hs.currentIPv4 = gadgets.NewOneLiner(grid, "Current IPv4")
- hs.currentIPv6 = gadgets.NewOneLiner(grid, "Current IPv6")
+ hs.hostname = gadgets.NewOneLiner(grid, "hostname")
+ hs.domainname = gadgets.NewOneLiner(grid, "domain name")
+ hs.currentIPv4 = gadgets.NewOneLiner(grid, "Current IPv4")
+ hs.currentIPv6 = gadgets.NewOneLiner(grid, "Current IPv6")
- hs.NSrr = gadgets.NewOneLiner(grid, "dns NS records").Set("unknown")
- hs.dnsAPI = gadgets.NewOneLiner(grid, "dns API provider").Set("unknown")
- hs.dnsA = gadgets.NewOneLiner(grid, "dns IPv4 resource records").Set("unknown")
- hs.dnsAAAA = gadgets.NewOneLiner(grid, "dns IPv6 resource records").Set("unknown")
+ hs.NSrr = gadgets.NewOneLiner(grid, "dns NS records").SetValue("unknown")
+ hs.dnsAPI = gadgets.NewOneLiner(grid, "dns API provider").SetValue("unknown")
+ hs.dnsA = gadgets.NewOneLiner(grid, "dns IPv4 resource records").SetValue("unknown")
+ hs.dnsAAAA = gadgets.NewOneLiner(grid, "dns IPv6 resource records").SetValue("unknown")
- hs.speed = gadgets.NewOneLiner(grid, "speed").Set("unknown")
- hs.speedActual = gadgets.NewOneLiner(grid, "actual").Set("unknown")
+ hs.speed = gadgets.NewOneLiner(grid, "speed").SetValue("unknown")
+ hs.speedActual = gadgets.NewOneLiner(grid, "actual").SetValue("unknown")
group.Pad()
grid.Pad()
@@ -104,13 +104,17 @@ func NewHostnameStatusWindow(p *gui.Node) *hostnameStatus {
}
func (hs *hostnameStatus) Domain() string {
- if ! hs.Ready() {return ""}
- return hs.domainname.Get()
+ if !hs.Ready() {
+ return ""
+ }
+ return hs.domainname.String()
}
func (hs *hostnameStatus) API() string {
- if ! hs.Ready() {return ""}
- return hs.dnsAPI.Get()
+ if !hs.Ready() {
+ return ""
+ }
+ return hs.dnsAPI.String()
}
func (hs *hostnameStatus) Update() {
@@ -119,15 +123,15 @@ func (hs *hostnameStatus) Update() {
log.Error(errors.New("hostnameStatus() Update() hs == nil"))
return
}
- duration := timeFunction(func () {
+ duration := timeFunction(func() {
hs.updateStatus()
})
s := fmt.Sprint(duration)
hs.set(hs.speedActual, s)
- if (duration > 500 * time.Millisecond ) {
+ if duration > 500*time.Millisecond {
hs.set(hs.speed, "SLOW")
- } else if (duration > 100 * time.Millisecond ) {
+ } else if duration > 100*time.Millisecond {
hs.set(hs.speed, "OK")
} else {
hs.set(hs.speed, "FAST")
@@ -137,17 +141,21 @@ func (hs *hostnameStatus) Update() {
// Returns true if the status is valid
func (hs *hostnameStatus) Ready() bool {
- if hs == nil {return false}
+ if hs == nil {
+ return false
+ }
return hs.ready
}
// Returns true if IPv4 is working
func (hs *hostnameStatus) IPv4() bool {
- if ! hs.Ready() {return false}
- if (hs.statusIPv4.Get() == "OK") {
+ if !hs.Ready() {
+ return false
+ }
+ if hs.statusIPv4.String() == "OK" {
return true
}
- if (hs.statusIPv4.Get() == "GOOD") {
+ if hs.statusIPv4.String() == "GOOD" {
return true
}
return false
@@ -155,25 +163,33 @@ func (hs *hostnameStatus) IPv4() bool {
// Returns true if IPv6 is working
func (hs *hostnameStatus) IPv6() bool {
- if ! hs.Ready() {return false}
- if (hs.statusIPv6.Get() == "GOOD") {
+ if !hs.Ready() {
+ return false
+ }
+ if hs.statusIPv6.String() == "GOOD" {
return true
}
return false
}
func (hs *hostnameStatus) setIPv4(s string) {
- if ! hs.Ready() {return}
- hs.statusIPv4.Set(s)
+ if !hs.Ready() {
+ return
+ }
+ hs.statusIPv4.SetValue(s)
}
func (hs *hostnameStatus) setIPv6(s string) {
- if ! hs.Ready() {return}
- hs.statusIPv6.Set(s)
+ if !hs.Ready() {
+ return
+ }
+ hs.statusIPv6.SetValue(s)
}
func (hs *hostnameStatus) set(a any, s string) {
- if ! hs.Ready() {return}
+ if !hs.Ready() {
+ return
+ }
if hs.hidden {
return
}
@@ -194,7 +210,7 @@ func (hs *hostnameStatus) set(a any, s string) {
return
}
// log.Println("SETTING ol:", ol)
- ol.Set(s)
+ ol.SetValue(s)
return
}
log.Warn("unknown type TypeOf(a) =", reflect.TypeOf(a), "a =", a)
@@ -208,45 +224,49 @@ func (hs *hostnameStatus) existsAAAA(s string) bool {
}
func (hs *hostnameStatus) GetIPv6() []string {
- if ! hs.Ready() { return nil}
- return strings.Split(hs.dnsAAAA.Get(), "\n")
+ if !hs.Ready() {
+ return nil
+ }
+ return strings.Split(hs.dnsAAAA.String(), "\n")
}
func (hs *hostnameStatus) updateStatus() {
- if ! hs.Ready() { return }
+ if !hs.Ready() {
+ return
+ }
var s string
var vals []string
log.Log(STATUS, "updateStatus() START")
// copy the OS status over
- lasthostname := hs.hostname.Get()
+ lasthostname := hs.hostname.String()
hostname := me.statusOS.GetHostname()
// hostname changed or was setup for the first time. Set the window title, etc
if lasthostname != hostname {
me.changed = true
- hs.hostname.Set(hostname)
- hs.window.Title(hostname + " Status")
- me.statusDNSbutton.Set(hostname + " status")
+ hs.hostname.SetValue(hostname)
+ hs.window.SetLabel(hostname + " Status")
+ me.statusDNSbutton.SetLabel(hostname + " status")
}
- hs.domainname.Set(me.statusOS.GetDomainName())
+ hs.domainname.SetValue(me.statusOS.GetDomainName())
var tmp []string
tmp = me.statusOS.GetIPv4()
sort.Strings(tmp)
s = strings.Join(tmp, "\n")
- if s != hs.currentIPv4.Get() {
+ if s != hs.currentIPv4.String() {
log.Log(CHANGE, "DNS IPv4 Addresses changed", tmp)
- hs.currentIPv4.Set(s)
+ hs.currentIPv4.SetValue(s)
hs.changed = true
}
tmp = me.statusOS.GetIPv6()
sort.Strings(tmp)
s = strings.Join(tmp, "\n")
- if s != hs.currentIPv6.Get() {
+ if s != hs.currentIPv6.String() {
log.Log(CHANGE, "DNS IPv6 Addresses changed", tmp)
- hs.currentIPv6.Set(s)
+ hs.currentIPv6.SetValue(s)
hs.changed = true
}
@@ -254,12 +274,12 @@ func (hs *hostnameStatus) updateStatus() {
vals = lookupDoH(me.statusOS.GetHostname(), "AAAA")
log.Log(STATUS, "DNS IPv6 Addresses for ", me.statusOS.GetHostname(), "=", vals)
- hs.dnsAAAA.Set(strings.Join(vals, "\n"))
+ hs.dnsAAAA.SetValue(strings.Join(vals, "\n"))
vals = lookupDoH(me.statusOS.GetHostname(), "A")
log.Log(STATUS, "IPv4 Addresses for ", me.statusOS.GetHostname(), "=", vals)
s = strings.Join(vals, "\n")
- if (s == "") {
+ if s == "" {
s = "(none)"
hs.setIPv4("NEEDS CNAME")
}
@@ -267,8 +287,8 @@ func (hs *hostnameStatus) updateStatus() {
vals = lookupDoH(me.statusOS.GetHostname(), "CNAME")
s = strings.Join(vals, "\n")
- if (s != "") {
- hs.set(hs.dnsA, "CNAME " + s)
+ if s != "" {
+ hs.set(hs.dnsA, "CNAME "+s)
hs.setIPv4("GOOD")
}
if hs.changed {
@@ -279,24 +299,24 @@ func (hs *hostnameStatus) updateStatus() {
}
if hs.IPv4() && hs.IPv6() {
- hs.status.Set("GOOD")
+ hs.status.SetValue("GOOD")
} else {
- hs.status.Set("BROKEN")
+ hs.status.SetValue("BROKEN")
}
-
- last := hs.statusIPv6.Get()
+
+ last := hs.statusIPv6.String()
if hs.verifyIPv6() {
if last != "WORKING" {
log.Log(CHANGE, "Your DNS IPv6 has started working.", me.statusOS.GetHostname(), "should now work")
hs.changed = true
- hs.statusIPv6.Set("WORKING")
+ hs.statusIPv6.SetValue("WORKING")
me.DnsStatus.SetText("WORKING")
}
} else {
if last != "BROKEN" {
log.Log(CHANGE, "Your DNS entries for IPv6 have BROKEN")
hs.changed = true
- hs.statusIPv6.Set("BROKEN")
+ hs.statusIPv6.SetValue("BROKEN")
me.DnsStatus.SetText("BROKEN")
}
}
@@ -357,7 +377,7 @@ func (hs *hostnameStatus) Show() {
func (hs *hostnameStatus) Hide() {
log.Log(STATUS, "hostnameStatus.Hide() window")
- if ! hs.hidden {
+ if !hs.hidden {
hs.window.Hide()
}
hs.hidden = true
@@ -372,6 +392,6 @@ func (hs *hostnameStatus) SetDNSapi(api string) {
return
}
hs.APIprovider = api
- hs.dnsAPI.Set(api)
+ hs.dnsAPI.SetValue(api)
hs.changed = true
}