Compare commits
11 Commits
15d9f97693
...
259b4bdb40
Author | SHA1 | Date |
---|---|---|
|
259b4bdb40 | |
|
7343cbfa57 | |
|
807b3be94f | |
|
930bdc941b | |
|
82b5717f48 | |
|
e5319cd50e | |
|
5e9f1591ca | |
|
de051d06f3 | |
|
cefe15539f | |
|
53fbb4cb85 | |
|
0148cec0b2 |
66
args.go
66
args.go
|
@ -22,62 +22,32 @@ var NOW log.LogFlag
|
|||
var INFO log.LogFlag
|
||||
var NET log.LogFlag
|
||||
var DNS log.LogFlag
|
||||
var PROC log.LogFlag
|
||||
var WARN log.LogFlag
|
||||
var SPEW log.LogFlag
|
||||
var CHANGE log.LogFlag
|
||||
var STATUS log.LogFlag
|
||||
|
||||
func myreg(f *log.LogFlag, b bool, name string, desc string) {
|
||||
f.B = b
|
||||
f.Subsystem = "go.wit.com/control-panels/dns"
|
||||
f.Short = "cpdns"
|
||||
f.Desc = desc
|
||||
f.Name = name
|
||||
f.Register()
|
||||
}
|
||||
|
||||
func init() {
|
||||
arg.MustParse(&args)
|
||||
// fmt.Println(args.Foo, args.Bar, args.User)
|
||||
|
||||
NOW.B = false
|
||||
NOW.Name = "NOW"
|
||||
NOW.Subsystem = "cpdns"
|
||||
NOW.Desc = "temp debugging stuff"
|
||||
NOW.Register()
|
||||
|
||||
INFO.B = false
|
||||
INFO.Name = "INFO"
|
||||
INFO.Subsystem = "cpdns"
|
||||
INFO.Desc = "normal debugging stuff"
|
||||
INFO.Register()
|
||||
|
||||
NET.B = false
|
||||
NET.Name = "NET"
|
||||
NET.Subsystem = "cpdns"
|
||||
NET.Desc = "Network logging"
|
||||
NET.Register()
|
||||
|
||||
DNS.B = false
|
||||
DNS.Name = "DNS"
|
||||
DNS.Subsystem = "cpdns"
|
||||
DNS.Desc = "dnsStatus.update()"
|
||||
DNS.Register()
|
||||
|
||||
PROC.B = false
|
||||
PROC.Name = "PROC"
|
||||
PROC.Subsystem = "cpdns"
|
||||
PROC.Desc = "/proc logging"
|
||||
PROC.Register()
|
||||
|
||||
SPEW.B = false
|
||||
SPEW.Name = "SPEW"
|
||||
SPEW.Subsystem = "cpdns"
|
||||
SPEW.Desc = "spew logging"
|
||||
SPEW.Register()
|
||||
|
||||
CHANGE.B = true
|
||||
CHANGE.Name = "CHANGE"
|
||||
CHANGE.Subsystem = "cpdns"
|
||||
CHANGE.Desc = "show droplet state changes"
|
||||
CHANGE.Register()
|
||||
|
||||
STATUS.B = false
|
||||
STATUS.Name = "STATUS"
|
||||
STATUS.Subsystem = "cpdns"
|
||||
STATUS.Desc = "updateStatus()"
|
||||
STATUS.Register()
|
||||
myreg(&NOW, true, "NOW", "temp debugging stuff")
|
||||
myreg(&INFO, false, "INFO", "normal debugging stuff")
|
||||
myreg(&NET, false, "NET", "Network logging")
|
||||
myreg(&DNS, false, "DNS", "dnsStatus.update()")
|
||||
myreg(&WARN, true, "WARN", "bad things")
|
||||
myreg(&SPEW, false, "SPEW", "spew stuff")
|
||||
myreg(&CHANGE, true, "CHANGE", "when host or dns change")
|
||||
myreg(&STATUS, false, "STATUS", "updateStatus()")
|
||||
|
||||
if debugger.ArgDebug() {
|
||||
log.Log(true, "INIT() gui debug == true")
|
||||
|
|
|
@ -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() {
|
||||
|
|
8
dns.go
8
dns.go
|
@ -40,6 +40,7 @@ func (h *Host) setIPv4(ipv4s map[string]*IPtype) {
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
func (h *Host) checkDNS() {
|
||||
var ip4 bool = false
|
||||
var ip6 bool = false
|
||||
|
@ -74,6 +75,7 @@ func (h *Host) checkDNS() {
|
|||
log.Println(args.VerboseDNS, "IPv6 is broken. Need to fix it here.")
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
// nsLookup performs an NS lookup on the given domain name.
|
||||
func lookupNS(domain string) {
|
||||
|
@ -111,10 +113,10 @@ func lookupNS(domain string) {
|
|||
}
|
||||
tmp = shell.Chomp(tmp)
|
||||
|
||||
if (tmp != me.status.NSrr.Get()) {
|
||||
if (tmp != me.statusDNS.NSrr.Get()) {
|
||||
me.changed = true
|
||||
log.Log(CHANGE, "lookupNS() setting me.NSrr =", tmp)
|
||||
me.status.NSrr.Set(tmp)
|
||||
log.Log(CHANGE, "lookupNS() setting changed to me.NSrr =", tmp)
|
||||
me.statusDNS.NSrr.Set(tmp)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,47 @@
|
|||
/*
|
||||
Show a box for a configuration error
|
||||
*/
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"go.wit.com/log"
|
||||
"go.wit.com/gui/gui"
|
||||
"go.wit.com/gui/gadgets"
|
||||
)
|
||||
|
||||
type errorBox struct {
|
||||
name string // the problem name
|
||||
|
||||
parent *gui.Node
|
||||
group *gui.Node
|
||||
grid *gui.Node
|
||||
|
||||
l *gui.Node
|
||||
b *gui.Node
|
||||
|
||||
something *gadgets.OneLiner
|
||||
}
|
||||
|
||||
func NewErrorBox(p *gui.Node, name string) *errorBox {
|
||||
var eb *errorBox
|
||||
eb = new(errorBox)
|
||||
eb.parent = p
|
||||
// eb.group = p.NewGroup("eg")
|
||||
// eb.grid = eb.group.NewGrid("labels", 2, 1)
|
||||
|
||||
eb.l = p.NewLabel("click to fix")
|
||||
eb.b = p.NewButton("fix", func() {
|
||||
log.Log(WARN, "should try to fix here")
|
||||
})
|
||||
eb.something = gadgets.NewOneLiner(eb.grid, "something")
|
||||
|
||||
return eb
|
||||
}
|
||||
|
||||
func (eb *errorBox) update() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (eb *errorBox) toggle() {
|
||||
}
|
135
fix.go
135
fix.go
|
@ -3,42 +3,141 @@ package main
|
|||
|
||||
import (
|
||||
"go.wit.com/log"
|
||||
"go.wit.com/gui/cloudflare"
|
||||
"go.wit.com/control-panels/dns/smartwindow"
|
||||
)
|
||||
|
||||
func fix() bool {
|
||||
log.Warn("")
|
||||
if ! me.status.Ready() {
|
||||
log.Warn("The IPv6 Control Panel is not Ready() yet")
|
||||
log.Log(CHANGE, "")
|
||||
if ! me.statusDNS.Ready() {
|
||||
log.Log(CHANGE, "The IPv6 Control Panel is not Ready() yet")
|
||||
return false
|
||||
}
|
||||
if me.statusOS.ValidHostname() {
|
||||
log.Warn("Your hostname is VALID:", me.statusOS.GetHostname())
|
||||
log.Log(CHANGE, "GOOD Your hostname is VALID:", me.statusOS.GetHostname())
|
||||
} else {
|
||||
log.Warn("You must first fix your hostname:", me.statusOS.GetHostname())
|
||||
log.Log(CHANGE, "You must first fix your hostname:", me.statusOS.GetHostname())
|
||||
return false
|
||||
}
|
||||
if me.digStatus.IPv4() {
|
||||
log.Warn("IPv4 addresses are resolving")
|
||||
log.Log(CHANGE, "GOOD IPv4 addresses are resolving")
|
||||
} else {
|
||||
log.Warn("You must first figure out why you can't look up IPv4 addresses")
|
||||
log.Warn("Are you on the internet at all?")
|
||||
log.Log(CHANGE, "You must first figure out why you can't look up IPv4 addresses")
|
||||
log.Log(CHANGE, "Are you on the internet at all?")
|
||||
return false
|
||||
}
|
||||
if me.digStatus.IPv6() {
|
||||
log.Warn("IPv6 addresses are resolving")
|
||||
log.Log(CHANGE, "GOOD IPv6 addresses are resolving")
|
||||
} else {
|
||||
log.Warn("You must first figure out why you can't look up IPv6 addresses")
|
||||
log.Log(CHANGE, "You must first figure out why you can't look up IPv6 addresses")
|
||||
return false
|
||||
}
|
||||
if ! me.status.IPv4() {
|
||||
log.Warn("You do not have real IPv4 addresses. Nothing to fix here")
|
||||
if ! me.statusDNS.IPv4() {
|
||||
log.Log(CHANGE, "OK You do not have real IPv4 addresses. Nothing to fix here")
|
||||
}
|
||||
if ! me.status.IPv6() {
|
||||
log.Warn("IPv6 DNS is broken. Check what is broken here")
|
||||
log.Warn("What are my IPv6 addresses?")
|
||||
log.Warn("What are the AAAA resource records in DNS?")
|
||||
return false
|
||||
if ! me.statusDNS.IPv6() {
|
||||
if fixIPv6dns() {
|
||||
log.Log(CHANGE, "IPv6 DNS Repair is underway")
|
||||
return false
|
||||
}
|
||||
log.Log(CHANGE, "GOOD IPv6 DNS is working!")
|
||||
}
|
||||
log.Warn("YOU SHOULD BE IN IPv6 BLISS")
|
||||
log.Log(CHANGE, "GOOD YOU SHOULD BE IN IPv6 BLISS")
|
||||
return true
|
||||
}
|
||||
|
||||
func fixIPv6dns() bool {
|
||||
log.Log(INFO, "What are my IPv6 addresses?")
|
||||
var broken bool = false
|
||||
osAAAA := make(map[string]string)
|
||||
dnsAAAA := make(map[string]string)
|
||||
|
||||
for _, aaaa := range me.statusOS.GetIPv6() {
|
||||
log.Log(INFO, "FOUND OS AAAA ip", aaaa)
|
||||
osAAAA[aaaa] = "os"
|
||||
}
|
||||
|
||||
log.Log(INFO, "What are the AAAA resource records in DNS?")
|
||||
for _, aaaa := range me.statusDNS.GetIPv6() {
|
||||
log.Log(INFO, "FOUND DNS AAAA ip", aaaa)
|
||||
dnsAAAA[aaaa] = "dns"
|
||||
}
|
||||
|
||||
// remove old DNS entries first
|
||||
for aaaa, _ := range dnsAAAA {
|
||||
if osAAAA[aaaa] == "dns" {
|
||||
broken = true
|
||||
log.Log(INFO, "DNS AAAA is not in OS", aaaa)
|
||||
addToFixWindow("DELETE", aaaa)
|
||||
/*
|
||||
if deleteFromDNS(aaaa) {
|
||||
log.Log(INFO, "Delete AAAA", aaaa, "Worked")
|
||||
} else {
|
||||
log.Log(INFO, "Delete AAAA", aaaa, "Failed")
|
||||
}
|
||||
*/
|
||||
} else {
|
||||
log.Log(INFO, "DNS AAAA is in OS", aaaa)
|
||||
}
|
||||
}
|
||||
|
||||
// now add new DNS entries
|
||||
for aaaa, _ := range osAAAA {
|
||||
if dnsAAAA[aaaa] == "dns" {
|
||||
log.Log(INFO, "OS AAAA is in DNS", aaaa)
|
||||
} else {
|
||||
broken = true
|
||||
log.Log(INFO, "OS AAAA is not in DNS", aaaa)
|
||||
addToFixWindow("CREATE", aaaa)
|
||||
/*
|
||||
if addToDNS(aaaa) {
|
||||
log.Log(INFO, "Add AAAA", aaaa, "Worked")
|
||||
} else {
|
||||
log.Log(INFO, "Add AAAA", aaaa, "Failed")
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
// if anything doesn't match, return false
|
||||
return broken
|
||||
}
|
||||
|
||||
func deleteFromDNS(aaaa string) bool {
|
||||
log.Log(CHANGE, "deleteFromDNS", aaaa)
|
||||
return false
|
||||
}
|
||||
|
||||
func addToDNS(aaaa string) bool {
|
||||
log.Log(CHANGE, "TODO: Add this to DNS !!!!", aaaa)
|
||||
api := me.statusDNS.API()
|
||||
log.Log(CHANGE, "what is your API provider?", api)
|
||||
if api == "cloudflare" {
|
||||
log.Log(CHANGE, "Let's try an ADD via the Cloudflare API")
|
||||
hostname := me.statusOS.GetHostname()
|
||||
return cloudflare.Create("wit.com", hostname, aaaa)
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func exists(m map[string]bool, s string) bool {
|
||||
if _, ok := m[s]; ok {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func addToFixWindow(t string, ip string) {
|
||||
if me.fixWindow == nil {
|
||||
me.fixWindow = smartwindow.New()
|
||||
me.fixWindow.SetParent(me.myGui)
|
||||
me.fixWindow.InitWindow()
|
||||
me.fixWindow.Title("fix window")
|
||||
me.fixWindow.SetDraw(drawFixWindow)
|
||||
me.fixWindow.Make()
|
||||
}
|
||||
}
|
||||
|
||||
func drawFixWindow(sw *smartwindow.SmartWindow) {
|
||||
log.Log(WARN, "drawFixWindow() START")
|
||||
}
|
||||
|
|
126
gui.go
126
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 := getProcessNameByPort(53)
|
||||
log.Info("Process with port 53:", processName)
|
||||
})
|
||||
|
||||
g2 = me.debug.Box().NewGroup("debugging options")
|
||||
|
||||
// makes a slider widget
|
||||
|
@ -70,30 +60,6 @@ func debugTab(title string) {
|
|||
me.debug.Hide()
|
||||
}
|
||||
|
||||
// will return a AAAA value that needs to be deleted
|
||||
func deleteAAA() string {
|
||||
var aaaa []string
|
||||
aaaa = dhcpAAAA() // your AAAA IP addresses right now
|
||||
for _, s := range aaaa {
|
||||
log.Log(NOW, "DNS AAAA =", s)
|
||||
if ( me.ipmap[s] == nil) {
|
||||
return s
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// will return a AAAA value that needs to be added
|
||||
func missingAAAA() string {
|
||||
var aaaa []string
|
||||
aaaa = dhcpAAAA() // your AAAA IP addresses right now
|
||||
for _, s := range aaaa {
|
||||
log.Log(NOW, "missing AAAA =", s)
|
||||
return s
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// doesn't actually do any network traffic
|
||||
// it just updates the GUI
|
||||
func displayDNS() string {
|
||||
|
@ -116,8 +82,9 @@ func displayDNS() string {
|
|||
}
|
||||
|
||||
var a []string
|
||||
a = realA()
|
||||
all = sortLines(strings.Join(a, "\n"))
|
||||
a = append(a, "fixme")
|
||||
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"
|
||||
|
@ -149,8 +116,18 @@ func mainWindow(title string) {
|
|||
me.DnsA = grid.NewLabel("?")
|
||||
|
||||
// This is where you figure out what to do next to fix the problems
|
||||
gr.NewButton("fix", func () {
|
||||
fix()
|
||||
me.fixButton = gr.NewButton("fix", func () {
|
||||
if ! fix() {
|
||||
log.Log(CHANGE, "boo. IPv6 isn't working yet")
|
||||
return
|
||||
}
|
||||
log.Log(CHANGE, "IPv6 WORKED")
|
||||
// update everything here visually for the user
|
||||
hostname := me.statusOS.GetHostname()
|
||||
me.hostname.Set(hostname)
|
||||
me.hostnameStatus.Set("WORKING")
|
||||
me.DnsStatus.Set("WORKING")
|
||||
me.fixButton.Disable()
|
||||
})
|
||||
|
||||
grid.Margin()
|
||||
|
@ -159,29 +136,9 @@ func mainWindow(title string) {
|
|||
statusGrid(me.window.Box())
|
||||
|
||||
gr = me.window.Box().NewGroup("debugging")
|
||||
gr.NewButton("hostname status", func () {
|
||||
if ! me.status.Ready() {return}
|
||||
me.status.window.Toggle()
|
||||
})
|
||||
|
||||
gr.NewButton("linuxstatus.New()", func () {
|
||||
if (me.statusOS == nil) {
|
||||
me.statusOS = linuxstatus.New()
|
||||
}
|
||||
me.statusOS.SetParent(me.myGui)
|
||||
me.statusOS.InitWindow()
|
||||
me.statusOS.Make()
|
||||
me.statusOS.Draw2()
|
||||
})
|
||||
gr.NewButton("statusOS.Ready()", func () {
|
||||
me.statusOS.Ready()
|
||||
})
|
||||
gr.NewButton("statusOS.Draw()", func () {
|
||||
me.statusOS.Draw()
|
||||
me.statusOS.Draw2()
|
||||
})
|
||||
gr.NewButton("statusOS.Update()", func () {
|
||||
me.statusOS.Update()
|
||||
me.statusDNSbutton = gr.NewButton("hostname status", func () {
|
||||
if ! me.statusDNS.Ready() {return}
|
||||
me.statusDNS.window.Toggle()
|
||||
})
|
||||
gr.NewButton("Linux Status", func () {
|
||||
me.statusOS.Toggle()
|
||||
|
@ -191,7 +148,10 @@ func mainWindow(title string) {
|
|||
me.digStatus.window.Toggle()
|
||||
})
|
||||
gr.NewButton("cloudflare wit.com", func () {
|
||||
cloudflare.CreateRR(me.myGui, "wit.com", "3777302ac4a78cd7fa4f6d3f72086d06")
|
||||
if me.witcom != nil {
|
||||
me.witcom.Toggle()
|
||||
}
|
||||
me.witcom = cloudflare.CreateRR(me.myGui, "wit.com", "3777302ac4a78cd7fa4f6d3f72086d06")
|
||||
})
|
||||
gr.NewButton("Debug", func () {
|
||||
me.debug.Toggle()
|
||||
|
@ -243,7 +203,7 @@ func statusGrid(n *gui.Node) {
|
|||
// run everything because something has changed
|
||||
func updateDNS() {
|
||||
me.digStatus.Update()
|
||||
me.status.Update()
|
||||
me.statusDNS.Update()
|
||||
|
||||
// log.Println("digAAAA()")
|
||||
|
||||
|
@ -251,7 +211,7 @@ func updateDNS() {
|
|||
var aaaa []string
|
||||
h := me.statusOS.GetHostname()
|
||||
aaaa = digAAAA(h)
|
||||
log.Log(NOW, "digAAAA() for", h, "=", aaaa)
|
||||
log.Log(INFO, "digAAAA() for", h, "=", aaaa)
|
||||
|
||||
// log.Println(SPEW, me)
|
||||
if (aaaa == nil) {
|
||||
|
@ -265,28 +225,30 @@ func updateDNS() {
|
|||
cloudflare.CFdialog.NameNode.SetText(h)
|
||||
}
|
||||
|
||||
/*
|
||||
d := deleteAAA()
|
||||
if (d != "") {
|
||||
if (cloudflare.CFdialog.ValueNode != nil) {
|
||||
cloudflare.CFdialog.ValueNode.SetText(d)
|
||||
}
|
||||
}
|
||||
m := missingAAAA()
|
||||
if (m != "") {
|
||||
if (cloudflare.CFdialog.ValueNode != nil) {
|
||||
cloudflare.CFdialog.ValueNode.SetText(m)
|
||||
}
|
||||
/*
|
||||
rr := &cloudflare.RRT{
|
||||
Type: "AAAA",
|
||||
Name: me.hostname,
|
||||
Ttl: "Auto",
|
||||
Proxied: false,
|
||||
Content: m,
|
||||
}
|
||||
cloudflare.Update(rr)
|
||||
*/
|
||||
}
|
||||
*/
|
||||
// m := missingAAAA()
|
||||
// if (m != "") {
|
||||
// if (cloudflare.CFdialog.ValueNode != nil) {
|
||||
// cloudflare.CFdialog.ValueNode.SetText(m)
|
||||
// }
|
||||
// /*
|
||||
// rr := &cloudflare.RRT{
|
||||
// Type: "AAAA",
|
||||
// Name: me.hostname,
|
||||
// Ttl: "Auto",
|
||||
// Proxied: false,
|
||||
// Content: m,
|
||||
// }
|
||||
// cloudflare.Update(rr)
|
||||
// */
|
||||
// }
|
||||
}
|
||||
}
|
||||
status := displayDNS() // update the GUI based on dig results
|
||||
|
|
|
@ -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,11 +33,10 @@ 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
|
||||
|
||||
|
@ -80,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")
|
||||
|
@ -120,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()
|
||||
|
@ -136,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 {
|
||||
|
@ -279,15 +244,38 @@ func (hs *hostnameStatus) missingAAAA() bool {
|
|||
}
|
||||
*/
|
||||
|
||||
func (hs *hostnameStatus) GetIPv6() []string {
|
||||
if ! hs.Ready() { return nil}
|
||||
return strings.Split(hs.dnsAAAA.Get(), "\n")
|
||||
}
|
||||
|
||||
func (hs *hostnameStatus) updateStatus() {
|
||||
if ! hs.Ready() { return }
|
||||
var s string
|
||||
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")
|
||||
|
||||
|
@ -309,7 +297,8 @@ func (hs *hostnameStatus) updateStatus() {
|
|||
// hs.dnsAction.SetText("DELETE")
|
||||
}
|
||||
}
|
||||
hs.set(hs.dnsAAAA, s)
|
||||
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)
|
||||
|
@ -328,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 {
|
||||
|
|
|
@ -29,6 +29,7 @@ func myreg(f *log.LogFlag, b bool, name string, desc string) {
|
|||
|
||||
func init() {
|
||||
myreg(&NOW, true, "NOW", "temp debugging stuff")
|
||||
myreg(&INFO, false, "INFO", "normal debugging stuff")
|
||||
myreg(&NET, false, "NET", "Network Logging")
|
||||
myreg(&DNS, false, "DNS", "dnsStatus.update()")
|
||||
myreg(&PROC, false, "PROC", "/proc logging")
|
||||
|
|
|
@ -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 =")
|
||||
|
||||
|
|
|
@ -3,8 +3,8 @@
|
|||
package linuxstatus
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"go.wit.com/log"
|
||||
"go.wit.com/shell"
|
||||
|
||||
// will try to get this hosts FQDN
|
||||
"github.com/Showmax/go-fqdn"
|
||||
|
@ -117,7 +117,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")
|
||||
|
|
|
@ -1,38 +1,88 @@
|
|||
// 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 (
|
||||
"os"
|
||||
"os/user"
|
||||
"io/ioutil"
|
||||
"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)
|
||||
}
|
||||
|
||||
content, _ := ioutil.ReadFile("/etc/resolv.conf")
|
||||
var ns []string
|
||||
for _, line := range strings.Split(string(content), "\n") {
|
||||
parts := strings.Split(line, " ")
|
||||
if len(parts) > 1 {
|
||||
if parts[0] == "nameserver" {
|
||||
ns = append(ns, parts[1])
|
||||
}
|
||||
}
|
||||
}
|
||||
sort.Strings(ns)
|
||||
newNS := strings.Join(ns, "\n")
|
||||
if newNS != me.resolver.Get() {
|
||||
log.Log(CHANGE, "resolver changed in /etc/resolv.conf to", ns)
|
||||
me.changed = true
|
||||
me.resolver.Set(newNS)
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -269,3 +269,21 @@ func deleteChanges() bool {
|
|||
|
||||
return changed
|
||||
}
|
||||
|
||||
func (ls *LinuxStatus) GetIPv6() []string {
|
||||
if ! me.Ready() {return nil}
|
||||
tmp := me.workingIPv6.Get()
|
||||
return strings.Split(tmp, "\n")
|
||||
}
|
||||
|
||||
func (ls *LinuxStatus) GetIPv4() []string {
|
||||
if ! me.Ready() {return nil}
|
||||
tmp := me.workingIPv4.Get()
|
||||
return strings.Split(tmp, "\n")
|
||||
}
|
||||
|
||||
func (ls *LinuxStatus) GetNameservers() []string {
|
||||
if ! me.Ready() {return nil}
|
||||
tmp := me.resolver.Get()
|
||||
return strings.Split(tmp, "\n")
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package main
|
|||
|
||||
// Watches for changes to a directory. Works cross-platform
|
||||
|
||||
/*
|
||||
import (
|
||||
"go.wit.com/log"
|
||||
"github.com/fsnotify/fsnotify"
|
||||
|
@ -77,3 +78,4 @@ func fsnotifyNetworkInterfaceChanges() error {
|
|||
}
|
||||
}
|
||||
|
||||
*/
|
|
@ -6,9 +6,6 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"go.wit.com/log"
|
||||
)
|
||||
|
||||
// ./go-nsupdate \
|
||||
|
@ -16,6 +13,7 @@ import (
|
|||
// --tsig-secret="OWh5/ZHIyaz7B8J9m9ZDqZ8448Pke0PTpkYbZmFcOf5a6rEzgmcwrG91u1BHi1/4us+mKKEobDPLw1x6sD+ZJw==" \
|
||||
// -i eno2 farm001.lab.wit.com
|
||||
|
||||
/*
|
||||
func nsupdate() {
|
||||
var tsigSecret string
|
||||
log.Log(NET, "nsupdate() START")
|
||||
|
@ -33,3 +31,4 @@ func nsupdate() {
|
|||
}
|
||||
}
|
||||
}
|
||||
*/
|
|
@ -1,4 +1,4 @@
|
|||
package main
|
||||
package linuxstatus
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
|
@ -10,7 +10,7 @@ import (
|
|||
"go.wit.com/log"
|
||||
)
|
||||
|
||||
func getProcessNameByPort(port int) string {
|
||||
func GetProcessNameByPort(port int) string {
|
||||
// Convert port to hex string
|
||||
portHex := strconv.FormatInt(int64(port), 16)
|
||||
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
28
main.go
28
main.go
|
@ -6,8 +6,6 @@ package main
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"sort"
|
||||
"runtime"
|
||||
"time"
|
||||
"embed"
|
||||
|
@ -46,9 +44,14 @@ func main() {
|
|||
setupControlPanelWindow()
|
||||
|
||||
me.digStatus = NewDigStatusWindow(me.myGui)
|
||||
me.status = NewHostnameStatusWindow(me.myGui)
|
||||
me.statusDNS = NewHostnameStatusWindow(me.myGui)
|
||||
|
||||
linuxstatus.New()
|
||||
me.statusOS = linuxstatus.New()
|
||||
me.statusOS.SetParent(me.myGui)
|
||||
me.statusOS.InitWindow()
|
||||
me.statusOS.Make()
|
||||
me.statusOS.Draw()
|
||||
me.statusOS.Draw2()
|
||||
|
||||
if debugger.ArgDebug() {
|
||||
log.Sleep(2)
|
||||
|
@ -177,20 +180,3 @@ func timeFunction(f func()) time.Duration {
|
|||
f() // Execute the function
|
||||
return time.Since(startTime) // Calculate the elapsed time
|
||||
}
|
||||
|
||||
// sortLines takes a string, splits it on newlines, sorts the lines,
|
||||
// and rejoins them with newlines.
|
||||
func sortLines(input string) string {
|
||||
lines := strings.Split(input, "\n")
|
||||
|
||||
// Trim leading and trailing whitespace from each line
|
||||
for i, line := range lines {
|
||||
lines[i] = strings.TrimSpace(line)
|
||||
}
|
||||
|
||||
sort.Strings(lines)
|
||||
tmp := strings.Join(lines, "\n")
|
||||
tmp = strings.TrimLeft(tmp, "\n")
|
||||
tmp = strings.TrimRight(tmp, "\n")
|
||||
return tmp
|
||||
}
|
||||
|
|
91
net.go
91
net.go
|
@ -1,91 +0,0 @@
|
|||
// This creates a simple hello world window
|
||||
package main
|
||||
|
||||
import (
|
||||
// "log"
|
||||
"net"
|
||||
"strings"
|
||||
|
||||
"go.wit.com/log"
|
||||
)
|
||||
|
||||
func IsIPv6(address string) bool {
|
||||
return strings.Count(address, ":") >= 2
|
||||
}
|
||||
|
||||
func (t *IPtype) IsReal() bool {
|
||||
if (t.ip.IsPrivate() || t.ip.IsLoopback() || t.ip.IsLinkLocalUnicast()) {
|
||||
log.Log(NET, "\t\tIP is Real = false")
|
||||
return false
|
||||
} else {
|
||||
log.Log(NET, "\t\tIP is Real = true")
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
func IsReal(ip *net.IP) bool {
|
||||
if (ip.IsPrivate() || ip.IsLoopback() || ip.IsLinkLocalUnicast()) {
|
||||
log.Log(NET, "\t\tIP is Real = false")
|
||||
return false
|
||||
} else {
|
||||
log.Log(NET, "\t\tIP is Real = true")
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
These are the real IP address you have been
|
||||
given from DHCP
|
||||
*/
|
||||
func dhcpAAAA() []string {
|
||||
var aaaa []string
|
||||
|
||||
for s, t := range me.ipmap {
|
||||
if (t.IsReal()) {
|
||||
if (t.ipv6) {
|
||||
aaaa = append(aaaa, s)
|
||||
}
|
||||
}
|
||||
}
|
||||
return aaaa
|
||||
}
|
||||
|
||||
func realA() []string {
|
||||
var a []string
|
||||
|
||||
for s, t := range me.ipmap {
|
||||
if (t.IsReal()) {
|
||||
if (t.ipv4) {
|
||||
a = append(a, s)
|
||||
}
|
||||
}
|
||||
}
|
||||
return a
|
||||
}
|
||||
|
||||
func checkDNS() (map[string]*IPtype, map[string]*IPtype) {
|
||||
var ipv4s map[string]*IPtype
|
||||
var ipv6s map[string]*IPtype
|
||||
|
||||
ipv4s = make(map[string]*IPtype)
|
||||
ipv6s = make(map[string]*IPtype)
|
||||
|
||||
for s, t := range me.ipmap {
|
||||
i := t.iface
|
||||
ipt := "IPv4"
|
||||
if (t.ipv6) {
|
||||
ipt = "IPv6"
|
||||
}
|
||||
if (t.IsReal()) {
|
||||
log.Info("\tIP is Real ", ipt, i.Index, i.Name, s)
|
||||
if (t.ipv6) {
|
||||
ipv6s[s] = t
|
||||
} else {
|
||||
ipv4s[s] = t
|
||||
}
|
||||
} else {
|
||||
log.Info("\tIP is not Real", ipt, i.Index, i.Name, s)
|
||||
}
|
||||
}
|
||||
return ipv6s, ipv4s
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
package smartwindow
|
||||
|
||||
/*
|
||||
this enables command line options from other packages like 'gui' and 'log'
|
||||
*/
|
||||
|
||||
import (
|
||||
"go.wit.com/log"
|
||||
)
|
||||
|
||||
var NOW log.LogFlag
|
||||
var INFO log.LogFlag
|
||||
var SPEW log.LogFlag
|
||||
var WARN log.LogFlag
|
||||
|
||||
func myreg(f *log.LogFlag, b bool, name string, desc string) {
|
||||
f.B = b
|
||||
f.Subsystem = "go.wit.com/gadgets/smartwindow"
|
||||
f.Short = "smartWin"
|
||||
f.Desc = desc
|
||||
f.Name = name
|
||||
f.Register()
|
||||
}
|
||||
|
||||
func init() {
|
||||
myreg(&NOW, true, "NOW", "temp debugging stuff")
|
||||
myreg(&INFO, false, "INFO", "normal debugging stuff")
|
||||
myreg(&SPEW, false, "SPEW", "spew stuff")
|
||||
myreg(&WARN, true, "WARN", "bad things")
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
// This creates a 'smart window'
|
||||
// it should work even when it is hidden
|
||||
// from the gui toolkit plugins
|
||||
package smartwindow
|
||||
|
||||
import (
|
||||
"go.wit.com/log"
|
||||
)
|
||||
|
||||
func (sw *SmartWindow) Ready() bool {
|
||||
log.Log(WARN, "Ready() maybe not ready? sw =", sw)
|
||||
if sw == nil {return false}
|
||||
if sw == nil {return false}
|
||||
if sw.window == nil {return false}
|
||||
return sw.ready
|
||||
}
|
||||
|
||||
func (sw *SmartWindow) Initialized() bool {
|
||||
log.Log(WARN, "checking Initialized()")
|
||||
if sw == nil {return false}
|
||||
if sw == nil {return false}
|
||||
if sw.parent == nil {return false}
|
||||
return true
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
package smartwindow
|
||||
|
||||
import (
|
||||
"go.wit.com/log"
|
||||
|
||||
"go.wit.com/gui/gadgets"
|
||||
)
|
||||
|
||||
func New() *SmartWindow {
|
||||
sw := SmartWindow {
|
||||
hidden: true,
|
||||
ready: false,
|
||||
}
|
||||
|
||||
return &sw
|
||||
}
|
||||
|
||||
func (sw *SmartWindow) InitWindow() {
|
||||
if sw == nil {
|
||||
log.Log(WARN, "not initalized yet (no parent for the window?)")
|
||||
return
|
||||
}
|
||||
if sw.window != nil {
|
||||
log.Log(WARN, "You already have a SmartWindow")
|
||||
sw.ready = true
|
||||
return
|
||||
}
|
||||
|
||||
log.Log(WARN, "Creating the Window")
|
||||
sw.window = gadgets.NewBasicWindow(sw.parent, sw.title)
|
||||
sw.ready = true
|
||||
}
|
|
@ -0,0 +1,59 @@
|
|||
// This creates a 'smart window'
|
||||
// it should work even when it is hidden
|
||||
// from the gui toolkit plugins
|
||||
package smartwindow
|
||||
|
||||
import (
|
||||
"go.wit.com/log"
|
||||
"go.wit.com/gui/gui"
|
||||
)
|
||||
|
||||
/*
|
||||
all these functions run after the window is Ready()
|
||||
so they should all start with that check
|
||||
*/
|
||||
|
||||
// reports externally if something has changed
|
||||
// since the last time it was asked about it
|
||||
func (sw *SmartWindow) Changed() bool {
|
||||
if ! sw.Ready() {return false}
|
||||
|
||||
if sw.changed {
|
||||
sw.changed = false
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (sw *SmartWindow) Show() {
|
||||
if ! sw.Ready() {return}
|
||||
|
||||
log.Log(WARN, "Show() window ready =", sw.ready)
|
||||
sw.window.Show()
|
||||
sw.hidden = false
|
||||
}
|
||||
|
||||
func (sw *SmartWindow) Hide() {
|
||||
if ! sw.Ready() {return}
|
||||
|
||||
log.Log(WARN, "Hide() window ready =", sw.ready)
|
||||
sw.window.Hide()
|
||||
sw.hidden = true
|
||||
}
|
||||
|
||||
func (sw *SmartWindow) Toggle() {
|
||||
if ! sw.Ready() {return}
|
||||
|
||||
log.Log(WARN, "Toggle() window ready =", sw.ready)
|
||||
if sw.hidden {
|
||||
sw.Show()
|
||||
} else {
|
||||
sw.Hide()
|
||||
}
|
||||
}
|
||||
|
||||
func (sw *SmartWindow) Box() *gui.Node {
|
||||
if ! sw.Ready() {return nil}
|
||||
|
||||
return sw.window.Box()
|
||||
}
|
|
@ -0,0 +1,84 @@
|
|||
// these are things you can config
|
||||
package smartwindow
|
||||
|
||||
import (
|
||||
"go.wit.com/log"
|
||||
"go.wit.com/gui/gui"
|
||||
)
|
||||
|
||||
/* for now, run these before the window is ready
|
||||
That is, they all start with:
|
||||
|
||||
if ! sw.Initialized() {return}
|
||||
if sw.Ready() {return}
|
||||
*/
|
||||
|
||||
func (sw *SmartWindow) Title(title string) {
|
||||
if ! sw.Initialized() {return}
|
||||
if sw.Ready() {return}
|
||||
|
||||
log.Log(WARN, "Title() =", title)
|
||||
sw.title = title
|
||||
}
|
||||
|
||||
func (sw *SmartWindow) SetParent(p *gui.Node) {
|
||||
if ! sw.Initialized() {return}
|
||||
if sw.Ready() {return}
|
||||
|
||||
log.Log(WARN, "SetParent")
|
||||
if sw.parent == nil {
|
||||
log.Log(WARN, "SetParent =", p)
|
||||
sw.parent = p
|
||||
return
|
||||
} else {
|
||||
log.Log(WARN, "SetParent was already set. TODO: Move to new parent")
|
||||
}
|
||||
}
|
||||
|
||||
func (sw *SmartWindow) SetDraw(f func(*SmartWindow)) {
|
||||
if ! sw.Initialized() {return}
|
||||
if sw.Ready() {return}
|
||||
|
||||
sw.populate = f
|
||||
}
|
||||
|
||||
func (sw *SmartWindow) Make() {
|
||||
if ! sw.Initialized() {return}
|
||||
if sw.Ready() {return}
|
||||
|
||||
log.Log(WARN, "Make() window ready =", sw.ready)
|
||||
sw.window.Make()
|
||||
if (sw.populate != nil) {
|
||||
log.Log(WARN, "Make() trying to run Custom sw.populate() here")
|
||||
sw.populate(sw)
|
||||
}
|
||||
sw.ready = true
|
||||
}
|
||||
|
||||
func (sw *SmartWindow) Draw() {
|
||||
if ! sw.Initialized() {return}
|
||||
if sw.Ready() {return}
|
||||
|
||||
log.Log(WARN, "Draw() window ready =", sw.ready)
|
||||
sw.window.Draw()
|
||||
if (sw.populate != nil) {
|
||||
log.Log(WARN, "Make() trying to run Custom sw.populate() here")
|
||||
sw.populate(sw)
|
||||
}
|
||||
sw.ready = true
|
||||
}
|
||||
|
||||
|
||||
func (sw *SmartWindow) Vertical() {
|
||||
if ! sw.Initialized() {return}
|
||||
if sw.Ready() {return}
|
||||
|
||||
log.Log(WARN, "Draw() window ready =", sw.ready)
|
||||
sw.window.Draw()
|
||||
if (sw.populate != nil) {
|
||||
log.Log(WARN, "Make() trying to run Custom sw.populate() here")
|
||||
sw.populate(sw)
|
||||
}
|
||||
sw.ready = true
|
||||
}
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
package smartwindow
|
||||
|
||||
import (
|
||||
"go.wit.com/gui/gui"
|
||||
"go.wit.com/gui/gadgets"
|
||||
)
|
||||
|
||||
type SmartWindow struct {
|
||||
ready bool // track if the window is ready
|
||||
hidden bool // track if the window is hidden from the toolkits
|
||||
changed bool // track if something changed in the window
|
||||
|
||||
title string // what the user sees as the name
|
||||
name string // the programatic name aka: "CALANDAR"
|
||||
|
||||
parent *gui.Node // where to place the window if you try to draw it
|
||||
window *gadgets.BasicWindow // the underlying BasicWindow
|
||||
box *gui.Node // the box inside the window // get this from BasicWindow() ?
|
||||
|
||||
populate func(*SmartWindow) // the function to generate the widgets
|
||||
}
|
36
structs.go
36
structs.go
|
@ -6,7 +6,9 @@ import (
|
|||
"time"
|
||||
"go.wit.com/gui/gui"
|
||||
"go.wit.com/gui/gadgets"
|
||||
// "go.wit.com/gui/cloudflare"
|
||||
"go.wit.com/control-panels/dns/linuxstatus"
|
||||
"go.wit.com/control-panels/dns/smartwindow"
|
||||
|
||||
"github.com/miekg/dns"
|
||||
)
|
||||
|
@ -15,8 +17,14 @@ import (
|
|||
var me Host
|
||||
|
||||
type Host struct {
|
||||
status *hostnameStatus // keeps track of the hostname and it's status
|
||||
myGui *gui.Node // the 'gui' binary tree root node
|
||||
|
||||
window *gadgets.BasicWindow // the main window
|
||||
debug *gadgets.BasicWindow // the debug window
|
||||
|
||||
statusDNS *hostnameStatus // keeps track of the hostname and it's status
|
||||
statusOS *linuxstatus.LinuxStatus // what the Linux OS sees
|
||||
digStatus *digStatus // window of the results of DNS lookups
|
||||
|
||||
hostnameStatus *gui.Node // a summary for the user of where things are
|
||||
hostname *gadgets.OneLiner // the hostname grabbed from gadget.linuxStatus
|
||||
|
@ -30,7 +38,6 @@ type Host struct {
|
|||
localSleep time.Duration
|
||||
|
||||
changed bool // set to true if things changed
|
||||
user string // name of the user
|
||||
|
||||
ipmap map[string]*IPtype // the current ip addresses
|
||||
dnsmap map[string]*IPtype // the current dns addresses
|
||||
|
@ -41,17 +48,6 @@ type Host struct {
|
|||
ipv4s map[string]dns.RR
|
||||
ipv6s map[string]dns.RR
|
||||
|
||||
window *gadgets.BasicWindow // the main window
|
||||
debug *gadgets.BasicWindow // more attempts to debug the DNS state
|
||||
|
||||
tab *gui.Node // the main dns tab
|
||||
notes *gui.Node // using this to put notes here
|
||||
|
||||
// local OS settings, network interfaces, etc
|
||||
// fqdn *gui.Node // display the full hostname
|
||||
// Interfaces *gui.Node // Interfaces
|
||||
// LocalSpeedActual *gui.Node // the time it takes to check each network interface
|
||||
|
||||
// DNS stuff
|
||||
DnsAPI *gui.Node // what DNS API to use?
|
||||
DnsAAAA *gadgets.OneLiner // the actual DNS AAAA results
|
||||
|
@ -61,18 +57,12 @@ type Host struct {
|
|||
DnsSpeedActual *gui.Node // the last actual duration
|
||||
DnsSpeedLast string // the last state 'FAST', 'OK', etc
|
||||
|
||||
// fix *gui.Node // button for the user to click
|
||||
// fixProc *gui.Node // button for the user to click
|
||||
|
||||
// mainStatus *gui.Node // group for the main display of stuff
|
||||
// cloudflareB *gui.Node // cloudflare button
|
||||
|
||||
digStatus *digStatus
|
||||
statusIPv6 *gadgets.OneLiner
|
||||
digStatusButton *gui.Node
|
||||
|
||||
myDebug *gui.Node
|
||||
myGui *gui.Node
|
||||
statusDNSbutton *gui.Node
|
||||
witcom *gadgets.BasicWindow
|
||||
fixButton *gui.Node
|
||||
fixWindow *smartwindow.SmartWindow
|
||||
}
|
||||
|
||||
type IPtype struct {
|
||||
|
|
Loading…
Reference in New Issue