Compare commits

...

6 Commits

Author SHA1 Message Date
Jeff Carr 259b4bdb40 finds and reports OS nameservers
Signed-off-by: Jeff Carr <jcarr@wit.com>
2024-01-07 07:34:12 -06:00
Jeff Carr 7343cbfa57 fix real IPv4 display
Signed-off-by: Jeff Carr <jcarr@wit.com>
2024-01-07 07:21:36 -06:00
Jeff Carr 807b3be94f window titles update to correct values
Signed-off-by: Jeff Carr <jcarr@wit.com>
2024-01-07 07:09:59 -06:00
Jeff Carr 930bdc941b remove debugging options
Signed-off-by: Jeff Carr <jcarr@wit.com>
2024-01-07 05:46:59 -06:00
Jeff Carr 82b5717f48 minor fix 2024-01-06 22:21:13 -06:00
Jeff Carr e5319cd50e status changes to working if it's working
Signed-off-by: Jeff Carr <jcarr@wit.com>
2024-01-06 21:17:06 -06:00
19 changed files with 474 additions and 154 deletions

View File

@ -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() {

47
errorBox.go Normal file
View File

@ -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() {
}

26
fix.go
View File

@ -4,6 +4,7 @@ package main
import (
"go.wit.com/log"
"go.wit.com/gui/cloudflare"
"go.wit.com/control-panels/dns/smartwindow"
)
func fix() bool {
@ -35,11 +36,11 @@ func fix() bool {
log.Log(CHANGE, "OK You do not have real IPv4 addresses. Nothing to fix here")
}
if ! me.statusDNS.IPv6() {
log.Log(CHANGE, "IPv6 DNS is broken. Check what is broken here")
if fixIPv6dns() {
log.Log(CHANGE, "IPv6 DNS Repair is underway")
return false
}
log.Log(CHANGE, "GOOD IPv6 DNS is working!")
}
log.Log(CHANGE, "GOOD YOU SHOULD BE IN IPv6 BLISS")
return true
@ -65,13 +66,16 @@ func fixIPv6dns() bool {
// remove old DNS entries first
for aaaa, _ := range dnsAAAA {
if osAAAA[aaaa] == "dns" {
log.Log(INFO, "DNS AAAA is not in OS", aaaa)
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)
}
@ -84,11 +88,14 @@ func fixIPv6dns() bool {
} 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")
}
*/
}
}
@ -119,3 +126,18 @@ func exists(m map[string]bool, s string) bool {
}
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")
}

81
gui.go
View File

@ -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
@ -70,32 +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 {
@ -119,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"
@ -151,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()
@ -161,30 +136,10 @@ 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()
})
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()
})
gr.NewButton("Linux Status", func () {
me.statusOS.Toggle()
})
@ -256,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) {

View File

@ -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 {

View File

@ -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 =")

View File

@ -3,9 +3,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"
@ -65,12 +64,6 @@ func (ls *LinuxStatus) setHostShort() {
}
}
func (ls *LinuxStatus) GetIPv6() []string {
if ! me.Ready() {return nil}
tmp := me.workingIPv6.Get()
return strings.Split(tmp, "\n")
}
func lookupHostname() {
if ! me.Ready() {return}
var err error
@ -124,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")

View File

@ -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)
}
/*

View File

@ -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")
}

View File

@ -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

View File

@ -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)

26
main.go
View File

@ -6,8 +6,6 @@ package main
import (
"fmt"
"strings"
"sort"
"runtime"
"time"
"embed"
@ -48,7 +46,12 @@ func main() {
me.digStatus = NewDigStatusWindow(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
}

30
smartwindow/args.go Normal file
View File

@ -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")
}

24
smartwindow/common.go Normal file
View File

@ -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
}

32
smartwindow/new.go Normal file
View File

@ -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
}

59
smartwindow/postReady.go Normal file
View File

@ -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()
}

84
smartwindow/preReady.go Normal file
View File

@ -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
}

21
smartwindow/structs.go Normal file
View File

@ -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
}

View File

@ -8,6 +8,7 @@ import (
"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"
)
@ -58,7 +59,10 @@ type Host struct {
statusIPv6 *gadgets.OneLiner
digStatusButton *gui.Node
statusDNSbutton *gui.Node
witcom *gadgets.BasicWindow
fixButton *gui.Node
fixWindow *smartwindow.SmartWindow
}
type IPtype struct {