summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--digStatus.go8
-rw-r--r--gui.go19
-rw-r--r--hostnameStatus.go74
-rw-r--r--linuxstatus/draw.go1
-rw-r--r--linuxstatus/hostname.go11
-rw-r--r--linuxstatus/linuxloop.go51
-rw-r--r--linuxstatus/net.go7
-rw-r--r--linuxstatus/structs.go1
-rw-r--r--linuxstatus/unix.go4
-rw-r--r--structs.go1
10 files changed, 101 insertions, 76 deletions
diff --git a/digStatus.go b/digStatus.go
index d23d8a4..af72227 100644
--- a/digStatus.go
+++ b/digStatus.go
@@ -245,6 +245,14 @@ func (ds *digStatus) updateDnsStatus() {
out = shell.Run(cmd)
log.Log(DNS, "makeDnsStatusGrid() dig", out)
me.digStatus.set(ds.DnsDigTCP, out)
+
+ /*
+ g2.NewButton("dig +trace", func () {
+ log.Log(NOW, "TODO: redo this")
+ // o := shell.Run("dig +trace +noadditional DS " + me.hostname + " @8.8.8.8")
+ // log.Println(o)
+ })
+ */
}
func (ds *digStatus) makeHttpStatusGrid() {
diff --git a/gui.go b/gui.go
index 40a6ffe..8e5b639 100644
--- a/gui.go
+++ b/gui.go
@@ -5,6 +5,7 @@ import (
"time"
"os"
"strings"
+ "sort"
"go.wit.com/log"
@@ -12,7 +13,7 @@ import (
"go.wit.com/gui/gadgets"
"go.wit.com/gui/cloudflare"
"go.wit.com/gui/debugger"
- "go.wit.com/control-panels/dns/linuxstatus"
+ // "go.wit.com/control-panels/dns/linuxstatus"
)
// This setups up the dns control panel window
@@ -43,17 +44,6 @@ func debugTab(title string) {
updateDNS()
})
- g2.NewButton("dig +trace", func () {
- log.Log(NOW, "TODO: redo this")
- // o := shell.Run("dig +trace +noadditional DS " + me.hostname + " @8.8.8.8")
- // log.Println(o)
- })
-
- g2.NewButton("getProcessNameByPort()", func () {
- processName := linuxstatus.GetProcessNameByPort(53)
- log.Info("Process with port 53:", processName)
- })
-
g2 = me.debug.Box().NewGroup("debugging options")
// makes a slider widget
@@ -93,7 +83,8 @@ func displayDNS() string {
var a []string
a = append(a, "fixme")
- all = sortLines(strings.Join(a, "\n"))
+ sort.Strings(a)
+ all = strings.Join(a, "\n")
if (all == "") {
log.Log(NOW, "THERE IS NOT a real A DNS ENTRY")
all = "CNAME ipv6.wit.com"
@@ -145,7 +136,7 @@ func mainWindow(title string) {
statusGrid(me.window.Box())
gr = me.window.Box().NewGroup("debugging")
- gr.NewButton("hostname status", func () {
+ me.statusDNSbutton = gr.NewButton("hostname status", func () {
if ! me.statusDNS.Ready() {return}
me.statusDNS.window.Toggle()
})
diff --git a/hostnameStatus.go b/hostnameStatus.go
index d7568aa..f84fbea 100644
--- a/hostnameStatus.go
+++ b/hostnameStatus.go
@@ -11,6 +11,7 @@ import (
"time"
"reflect"
"strings"
+ "sort"
"errors"
"go.wit.com/log"
@@ -22,7 +23,6 @@ type hostnameStatus struct {
ready bool
hidden bool
- // hostname string // my hostname. Example: "test.wit.com"
lastname string // used to watch for changes in the hostname
window *gadgets.BasicWindow
@@ -33,14 +33,12 @@ type hostnameStatus struct {
statusIPv4 *gadgets.OneLiner
statusIPv6 *gadgets.OneLiner
- // Details Group
- hostShort *gadgets.OneLiner
+ hostname *gadgets.OneLiner
domainname *gadgets.OneLiner
- // what the current IP address your network has given you
+ // what the current IP addresses your network has given you
currentIPv4 *gadgets.OneLiner
currentIPv6 *gadgets.OneLiner
- currentAAAA string
// what the DNS servers have
NSrr *gadgets.OneLiner
@@ -81,7 +79,7 @@ func NewHostnameStatusWindow(p *gui.Node) *hostnameStatus {
group = hs.window.Box().NewGroup("Details")
grid = group.NewGrid("LookupDetails", 2, 2)
- hs.hostShort = gadgets.NewOneLiner(grid, "hostname -s")
+ 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")
@@ -121,12 +119,6 @@ func NewHostnameStatusWindow(p *gui.Node) *hostnameStatus {
return hs
}
-/*
-func (hs *hostnameStatus) ValidHostname() bool {
- return goodHostname()
-}
-*/
-
func (hs *hostnameStatus) Domain() string {
if ! hs.Ready() {return ""}
return hs.domainname.Get()
@@ -137,34 +129,6 @@ func (hs *hostnameStatus) API() string {
return hs.dnsAPI.Get()
}
-/*
-func (hs *hostnameStatus) deleteDNSrecord(value string) bool {
- log.Info("deleteDNSrecord() START for", value)
- log.Info("deleteDNSrecord() hostname =", me.status.GetHostname())
- log.Info("deleteDNSrecord() domain =", hs.Domain())
- log.Info("deleteDNSrecord() DNS API Provider =", hs.API())
-
- if (hs.API() == "cloudflare") {
- log.Info("deleteDNSrecord() Try to delete via cloudflare")
- return cloudflare.Delete(hs.Domain(), me.status.GetHostname(), value)
- }
- return false
-}
-
-func (hs *hostnameStatus) createDNSrecord(value string) bool {
- log.Info("createDNSrecord() START for", value)
- log.Info("createDNSrecord() hostname =", me.status.GetHostname())
- log.Info("createDNSrecord() domain =", hs.Domain())
- log.Info("createDNSrecord() DNS API Provider =", hs.API())
-
- if (hs.API() == "cloudflare") {
- log.Warn("createDNSrecord() Try to create via cloudflare:", me.status.GetHostname(), value)
- return cloudflare.Create(hs.Domain(), me.status.GetHostname(), value)
- }
- return false
-}
-*/
-
func (hs *hostnameStatus) Update() {
log.Info("hostnameStatus() Update() START")
if hs == nil {
@@ -282,7 +246,7 @@ func (hs *hostnameStatus) missingAAAA() bool {
func (hs *hostnameStatus) GetIPv6() []string {
if ! hs.Ready() { return nil}
- return strings.Split(hs.currentAAAA, "\n")
+ return strings.Split(hs.dnsAAAA.Get(), "\n")
}
func (hs *hostnameStatus) updateStatus() {
@@ -291,9 +255,27 @@ func (hs *hostnameStatus) updateStatus() {
var vals []string
log.Log(STATUS, "updateStatus() START")
- hs.hostShort.Set(me.statusOS.GetHostShort())
+ // copy the OS status over
+ lasthostname := hs.hostname.Get()
+ 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.domainname.Set(me.statusOS.GetDomainName())
+ tmp := me.statusOS.GetIPv4()
+ sort.Strings(tmp)
+ hs.currentIPv4.Set(strings.Join(tmp, "\n"))
+
+ tmp = me.statusOS.GetIPv6()
+ sort.Strings(tmp)
+ hs.currentIPv6.Set(strings.Join(tmp, "\n"))
+
if me.statusOS.ValidHostname() {
vals = lookupDoH(me.statusOS.GetHostname(), "AAAA")
@@ -315,7 +297,8 @@ func (hs *hostnameStatus) updateStatus() {
// hs.dnsAction.SetText("DELETE")
}
}
- hs.currentAAAA = strings.Join(vals, "\n")
+ sort.Strings(vals)
+ hs.dnsAAAA.Set(strings.Join(vals, "\n"))
vals = lookupDoH(me.statusOS.GetHostname(), "A")
log.Log(STATUS, "IPv4 Addresses for ", me.statusOS.GetHostname(), "=", vals)
@@ -334,11 +317,6 @@ func (hs *hostnameStatus) updateStatus() {
}
}
- // hs.currentIPv4.Set(me.IPv4.S)
- // hs.currentIPv6.Set(me.IPv6.S)
- hs.currentIPv4.Set("get this from linuxStatus")
- hs.currentIPv6.Set("get this from linuxStatus")
-
if hs.IPv4() && hs.IPv6() {
hs.status.Set("GOOD")
} else {
diff --git a/linuxstatus/draw.go b/linuxstatus/draw.go
index 5b76b49..6b7d6bd 100644
--- a/linuxstatus/draw.go
+++ b/linuxstatus/draw.go
@@ -24,6 +24,7 @@ func draw(ls *LinuxStatus) {
ls.uid = gadgets.NewOneLiner(ls.grid, "UID =")
ls.IPv4 = gadgets.NewOneLiner(ls.grid, "Current IPv4 =")
ls.IPv6 = gadgets.NewOneLiner(ls.grid, "Current IPv6 =")
+ ls.workingIPv4 = gadgets.NewOneLiner(ls.grid, "Real IPv4 =")
ls.workingIPv6 = gadgets.NewOneLiner(ls.grid, "Real IPv6 =")
// ls.nics = gadgets.NewOneLiner(ls.grid, "network intefaces =")
diff --git a/linuxstatus/hostname.go b/linuxstatus/hostname.go
index d31299f..184e593 100644
--- a/linuxstatus/hostname.go
+++ b/linuxstatus/hostname.go
@@ -4,8 +4,8 @@ package linuxstatus
import (
"strings"
+ "io/ioutil"
"go.wit.com/log"
- "go.wit.com/shell"
// will try to get this hosts FQDN
"github.com/Showmax/go-fqdn"
@@ -124,7 +124,14 @@ func lookupHostname() {
// On Linux, /etc/hosts, /etc/hostname
// and domainname and hostname
func goodHostname() bool {
- hostname := shell.Chomp(shell.Cat("/etc/hostname"))
+ content, err := ioutil.ReadFile("/etc/hostname")
+ if err != nil {
+ // this needs to be a fixWindow() error
+ log.Error(err)
+ }
+
+ hostname := string(content)
+
log.Log(NOW, "hostname =", hostname)
hs := run("hostname -s")
diff --git a/linuxstatus/linuxloop.go b/linuxstatus/linuxloop.go
index b2572d1..9127206 100644
--- a/linuxstatus/linuxloop.go
+++ b/linuxstatus/linuxloop.go
@@ -1,7 +1,13 @@
// GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007
// Copyright (c) 2023 WIT.COM, Inc.
+
// This is a control panel for DNS
+// This is the main Linux kernel / OS code
+// to check your network settings are correct
+// This does (and should do) no network or external checking
+// This is just the state of your OS
+
package linuxstatus
import (
@@ -9,30 +15,55 @@ import (
"os/user"
"strconv"
"strings"
+ "sort"
"go.wit.com/log"
)
func linuxLoop() {
me.changed = false
- duration := timeFunction(lookupHostname)
- log.Log(INFO, "getHostname() execution Time: ", duration, "me.changed =", me.changed)
- duration = timeFunction(scanInterfaces)
- log.Log(NET, "scanInterfaces() execution Time: ", duration)
+ // checks for a VALID hostname
+ lookupHostname()
+ if me.changed {
+ log.Log(CHANGE, "lookupHostname() detected a change")
+ }
+
+ // scans the linux network intefaces for your available IPv4 & IPv6 addresses
+ scanInterfaces()
+ if me.changed {
+ log.Log(CHANGE, "scanInterfaces() detected a change")
+ }
for i, t := range me.ifmap {
log.Log(NET, strconv.Itoa(i) + " iface = " + t.iface.Name)
}
+ // get all the real A records from all the network interfaces linux can see
+ a := realA()
+ sort.Strings(a)
+ tmp := strings.Join(a, "\n")
+ if tmp != me.workingIPv4.Get() {
+ log.Log(CHANGE, "realAAAA() your real IPv6 addresses changed")
+ me.changed = true
+ me.workingIPv4.Set(tmp)
+ }
+
// get all the real AAAA records from all the network interfaces linux can see
- tmp := strings.Join(realAAAA(), "\n")
- tmp = sortLines(tmp)
- me.workingIPv6.Set(tmp)
+ aaaa := realAAAA()
+ sort.Strings(aaaa)
+ tmp = strings.Join(aaaa, "\n")
+ if tmp != me.workingIPv6.Get() {
+ log.Log(CHANGE, "realAAAA() your real IPv6 addresses changed")
+ me.changed = true
+ me.workingIPv6.Set(tmp)
+ }
user, _ := user.Current()
- log.Log(INFO, "os.Getuid =", user.Username, os.Getuid())
- if (me.uid != nil) {
- me.uid.Set(user.Username + " (" + strconv.Itoa(os.Getuid()) + ")")
+ tmp = user.Username + " (" + strconv.Itoa(os.Getuid()) + ")"
+ if tmp != me.uid.Get() {
+ log.Log(CHANGE, "os.Getuid =", user.Username, os.Getuid())
+ me.changed = true
+ me.uid.Set(tmp)
}
/*
diff --git a/linuxstatus/net.go b/linuxstatus/net.go
index 2926946..7170765 100644
--- a/linuxstatus/net.go
+++ b/linuxstatus/net.go
@@ -269,3 +269,10 @@ func deleteChanges() bool {
return changed
}
+
+func (ls *LinuxStatus) GetIPv4() []string {
+ if ! me.Ready() {return nil}
+ tmp := "(none) fixme"
+ return strings.Split(tmp, "\n")
+}
+
diff --git a/linuxstatus/structs.go b/linuxstatus/structs.go
index de9936d..42fd420 100644
--- a/linuxstatus/structs.go
+++ b/linuxstatus/structs.go
@@ -35,6 +35,7 @@ type LinuxStatus struct {
uid *gadgets.OneLiner
IPv4 *gadgets.OneLiner
IPv6 *gadgets.OneLiner
+ workingIPv4 *gadgets.OneLiner
workingIPv6 *gadgets.OneLiner
Interfaces *gui.Node
speed *gadgets.OneLiner
diff --git a/linuxstatus/unix.go b/linuxstatus/unix.go
index 99509c0..88f64ec 100644
--- a/linuxstatus/unix.go
+++ b/linuxstatus/unix.go
@@ -13,7 +13,6 @@ import (
"strings"
"go.wit.com/log"
- "go.wit.com/shell"
)
func CheckSuperuser() bool {
@@ -89,7 +88,8 @@ func run(s string) string {
return ""
}
- tmp := shell.Chomp(out.String())
+ // Trim leading and trailing whitespace from each line
+ tmp := strings.TrimSpace(out.String())
// Output the results
log.Info("Command Output:", tmp)
diff --git a/structs.go b/structs.go
index 0e2a52c..f7f6411 100644
--- a/structs.go
+++ b/structs.go
@@ -59,6 +59,7 @@ type Host struct {
statusIPv6 *gadgets.OneLiner
digStatusButton *gui.Node
+ statusDNSbutton *gui.Node
witcom *gadgets.BasicWindow
fixButton *gui.Node
fixWindow *smartwindow.SmartWindow