2023-02-08 11:04:04 -06:00
|
|
|
// This creates a simple hello world window
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2023-12-21 17:56:56 -06:00
|
|
|
"time"
|
2023-02-08 11:04:04 -06:00
|
|
|
"os"
|
2023-12-20 03:13:43 -06:00
|
|
|
"strings"
|
|
|
|
|
2023-12-28 15:36:05 -06:00
|
|
|
"go.wit.com/log"
|
2024-01-03 12:40:31 -06:00
|
|
|
|
|
|
|
"go.wit.com/gui/gui"
|
|
|
|
"go.wit.com/gui/gadgets"
|
|
|
|
"go.wit.com/gui/cloudflare"
|
2024-01-04 22:01:39 -06:00
|
|
|
"go.wit.com/gui/debugger"
|
2024-01-06 05:32:52 -06:00
|
|
|
"go.wit.com/control-panels/dns/linuxstatus"
|
2023-02-08 11:04:04 -06:00
|
|
|
)
|
|
|
|
|
2023-04-07 11:23:47 -05:00
|
|
|
// This setups up the dns control panel window
|
|
|
|
func setupControlPanelWindow() {
|
2024-01-03 19:33:13 -06:00
|
|
|
log.Info("artificial sleep of:", me.artificialSleep)
|
|
|
|
log.Sleep(me.artificialSleep)
|
2023-12-28 09:43:45 -06:00
|
|
|
|
|
|
|
// setup the main tab
|
2024-01-05 00:07:13 -06:00
|
|
|
mainWindow("DNS and IPv6 Control Panel")
|
2024-01-05 01:07:34 -06:00
|
|
|
detailsTab("OS Details")
|
2023-12-16 09:02:59 -06:00
|
|
|
debugTab("Debug")
|
2023-12-20 03:13:43 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
func detailsTab(title string) {
|
|
|
|
var g2 *gui.Node
|
|
|
|
|
2024-01-05 00:07:13 -06:00
|
|
|
me.details = gadgets.NewBasicWindow(me.myGui, title)
|
2024-01-05 14:49:42 -06:00
|
|
|
me.details.Draw()
|
|
|
|
me.details.Hide()
|
|
|
|
|
2024-01-05 00:07:13 -06:00
|
|
|
g2 = me.details.Box().NewGroup("Real Stuff")
|
2023-12-20 03:13:43 -06:00
|
|
|
|
|
|
|
grid := g2.NewGrid("gridnuts", 2, 2)
|
|
|
|
|
|
|
|
grid.SetNext(1,1)
|
|
|
|
|
|
|
|
grid.NewLabel("domainname =")
|
2024-01-06 05:24:11 -06:00
|
|
|
grid.NewLabel("DEPRECATED")
|
|
|
|
// me.domainname = grid.NewLabel("domainname")
|
2023-02-08 11:04:04 -06:00
|
|
|
|
2023-12-20 03:13:43 -06:00
|
|
|
grid.NewLabel("hostname -s =")
|
|
|
|
me.hostshort = grid.NewLabel("hostname -s")
|
|
|
|
|
|
|
|
grid.NewLabel("NS records =")
|
|
|
|
me.NSrr = grid.NewLabel("NS RR's")
|
|
|
|
|
|
|
|
grid.NewLabel("UID =")
|
2024-01-06 05:32:52 -06:00
|
|
|
grid.NewLabel("DEPRECATED")
|
2023-12-20 03:13:43 -06:00
|
|
|
|
|
|
|
grid.NewLabel("Current IPv4 =")
|
|
|
|
me.IPv4 = grid.NewLabel("?")
|
|
|
|
|
|
|
|
grid.NewLabel("Current IPv6 =")
|
|
|
|
me.IPv6 = grid.NewLabel("?")
|
|
|
|
|
2023-12-28 09:43:45 -06:00
|
|
|
grid.NewLabel("Working Real IPv6 =")
|
|
|
|
me.workingIPv6 = grid.NewLabel("?")
|
|
|
|
|
2023-12-20 03:13:43 -06:00
|
|
|
grid.NewLabel("interfaces =")
|
|
|
|
me.Interfaces = grid.NewCombobox("Interfaces")
|
|
|
|
|
|
|
|
grid.NewLabel("refresh speed")
|
|
|
|
me.LocalSpeedActual = grid.NewLabel("unknown")
|
|
|
|
|
|
|
|
grid.Margin()
|
|
|
|
grid.Pad()
|
2024-01-05 00:11:48 -06:00
|
|
|
|
|
|
|
me.details.Hide()
|
2023-02-08 11:04:04 -06:00
|
|
|
}
|
|
|
|
|
2023-12-16 09:02:59 -06:00
|
|
|
func debugTab(title string) {
|
2023-03-01 11:21:47 -06:00
|
|
|
var g2 *gui.Node
|
2023-02-08 11:04:04 -06:00
|
|
|
|
2024-01-05 00:11:48 -06:00
|
|
|
me.debug = gadgets.NewBasicWindow(me.myGui, title)
|
2024-01-05 14:49:42 -06:00
|
|
|
me.debug.Draw()
|
|
|
|
me.debug.Hide()
|
2023-02-08 11:04:04 -06:00
|
|
|
|
2024-01-05 00:11:48 -06:00
|
|
|
g2 = me.debug.Box().NewGroup("Real Stuff")
|
2023-02-08 11:04:04 -06:00
|
|
|
|
2024-01-04 22:01:39 -06:00
|
|
|
g2.NewButton("GO GUI Debug Window", func () {
|
2024-01-05 00:07:13 -06:00
|
|
|
debugger.DebugWindow(me.myGui)
|
2023-02-09 09:07:00 -06:00
|
|
|
})
|
2023-12-20 03:13:43 -06:00
|
|
|
|
2024-01-04 22:01:39 -06:00
|
|
|
g2.NewButton("getHostname() looks at the OS settings", func () {
|
2023-02-18 23:37:11 -06:00
|
|
|
getHostname()
|
|
|
|
})
|
2023-12-20 03:13:43 -06:00
|
|
|
|
|
|
|
g2.NewButton("dig A & AAAA DNS records", func () {
|
2023-12-16 09:02:59 -06:00
|
|
|
log.Println("updateDNS()")
|
2023-04-13 07:49:13 -05:00
|
|
|
updateDNS()
|
|
|
|
})
|
|
|
|
|
2023-03-25 16:19:44 -05:00
|
|
|
g2.NewButton("dig +trace", func () {
|
2024-01-06 01:41:33 -06:00
|
|
|
log.Log(NOW, "TODO: redo this")
|
|
|
|
// o := shell.Run("dig +trace +noadditional DS " + me.hostname + " @8.8.8.8")
|
|
|
|
// log.Println(o)
|
2023-03-25 16:19:44 -05:00
|
|
|
})
|
2023-12-20 03:13:43 -06:00
|
|
|
|
2024-01-06 02:21:56 -06:00
|
|
|
g2.NewButton("getProcessNameByPort()", func () {
|
|
|
|
processName := getProcessNameByPort(53)
|
|
|
|
log.Info("Process with port 53:", processName)
|
|
|
|
})
|
|
|
|
|
2024-01-05 00:11:48 -06:00
|
|
|
g2 = me.debug.Box().NewGroup("debugging options")
|
2023-12-20 03:13:43 -06:00
|
|
|
|
2023-12-21 17:56:56 -06:00
|
|
|
// makes a slider widget
|
2023-12-29 02:43:00 -06:00
|
|
|
me.ttl = gadgets.NewDurationSlider(g2, "Loop Timeout", 10 * time.Millisecond, 5 * time.Second)
|
2023-12-21 17:56:56 -06:00
|
|
|
me.ttl.Set(300 * time.Millisecond)
|
2023-12-16 12:59:18 -06:00
|
|
|
|
2023-12-21 17:56:56 -06:00
|
|
|
// makes a slider widget
|
2023-12-29 02:43:00 -06:00
|
|
|
me.dnsTtl = gadgets.NewDurationSlider(g2, "DNS Timeout", 800 * time.Millisecond, 300 * time.Second)
|
2023-12-21 17:56:56 -06:00
|
|
|
me.dnsTtl.Set(60 * time.Second)
|
2023-12-20 03:13:43 -06:00
|
|
|
|
|
|
|
g2.Margin()
|
|
|
|
g2.Pad()
|
2024-01-05 00:11:48 -06:00
|
|
|
|
|
|
|
me.debug.Hide()
|
2023-12-20 03:13:43 -06:00
|
|
|
}
|
|
|
|
|
2023-12-28 09:43:45 -06:00
|
|
|
// 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 {
|
2024-01-03 19:33:13 -06:00
|
|
|
log.Log(NOW, "DNS AAAA =", s)
|
2023-12-28 09:43:45 -06:00
|
|
|
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 {
|
2024-01-03 19:33:13 -06:00
|
|
|
log.Log(NOW, "missing AAAA =", s)
|
2023-12-28 09:43:45 -06:00
|
|
|
return s
|
|
|
|
}
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
2023-12-20 03:13:43 -06:00
|
|
|
// doesn't actually do any network traffic
|
|
|
|
// it just updates the GUI
|
2023-12-28 09:43:45 -06:00
|
|
|
func displayDNS() string {
|
2023-12-20 03:13:43 -06:00
|
|
|
var aaaa []string
|
2023-12-28 09:43:45 -06:00
|
|
|
aaaa = dhcpAAAA() // your AAAA records right now
|
2024-01-06 01:41:33 -06:00
|
|
|
// h := me.hostname
|
2023-12-20 03:13:43 -06:00
|
|
|
var all string
|
2023-12-28 09:43:45 -06:00
|
|
|
var broken string = "unknown"
|
2023-12-20 03:13:43 -06:00
|
|
|
for _, s := range aaaa {
|
2024-01-06 01:41:33 -06:00
|
|
|
log.Log(STATUS, "host", "fixme", "DNS AAAA =", s, "ipmap[s] =", me.ipmap[s])
|
2023-12-20 03:13:43 -06:00
|
|
|
all += s + "\n"
|
|
|
|
if ( me.ipmap[s] == nil) {
|
2024-01-06 01:41:33 -06:00
|
|
|
log.Warn("THIS IS THE WRONG AAAA DNS ENTRY: host", "fixme", "DNS AAAA =", s)
|
2023-12-28 09:43:45 -06:00
|
|
|
broken = "wrong AAAA entry"
|
2023-12-20 03:13:43 -06:00
|
|
|
} else {
|
2023-12-28 09:43:45 -06:00
|
|
|
if (broken == "unknown") {
|
|
|
|
broken = "needs update"
|
2023-12-20 03:13:43 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
all = sortLines(all)
|
2023-12-28 09:43:45 -06:00
|
|
|
if (me.workingIPv6.S != all) {
|
2024-01-06 01:41:33 -06:00
|
|
|
log.Log(NOW, "workingIPv6.SetText() to:", all)
|
2023-12-28 09:43:45 -06:00
|
|
|
me.workingIPv6.SetText(all)
|
2023-12-20 03:13:43 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
var a []string
|
|
|
|
a = realA()
|
|
|
|
all = sortLines(strings.Join(a, "\n"))
|
|
|
|
if (all == "") {
|
2024-01-06 01:41:33 -06:00
|
|
|
log.Log(NOW, "THERE IS NOT a real A DNS ENTRY")
|
2023-12-20 03:13:43 -06:00
|
|
|
all = "CNAME ipv6.wit.com"
|
|
|
|
}
|
|
|
|
if (me.DnsA.S != all) {
|
2024-01-06 01:41:33 -06:00
|
|
|
log.Log(NOW, "DnsA.SetText() to:", all)
|
2023-12-20 03:13:43 -06:00
|
|
|
me.DnsA.SetText(all)
|
|
|
|
}
|
|
|
|
return broken
|
2023-02-08 11:04:04 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
func myDefaultExit(n *gui.Node) {
|
2023-12-16 09:02:59 -06:00
|
|
|
log.Println("You can Do exit() things here")
|
2023-02-08 11:04:04 -06:00
|
|
|
os.Exit(0)
|
|
|
|
}
|
2023-03-01 11:21:47 -06:00
|
|
|
|
2024-01-05 00:07:13 -06:00
|
|
|
func mainWindow(title string) {
|
|
|
|
me.window = gadgets.NewBasicWindow(me.myGui, title)
|
2023-03-25 08:09:34 -05:00
|
|
|
|
2024-01-06 02:21:56 -06:00
|
|
|
gr := me.window.Box().NewGroup("dns update")
|
|
|
|
grid := gr.NewGrid("gridnuts", 2, 2)
|
2023-03-25 08:09:34 -05:00
|
|
|
|
|
|
|
grid.SetNext(1,1)
|
2023-12-20 03:13:43 -06:00
|
|
|
|
2023-03-25 08:09:34 -05:00
|
|
|
grid.NewLabel("hostname =")
|
2023-03-25 16:19:44 -05:00
|
|
|
me.fqdn = grid.NewLabel("?")
|
2023-03-25 08:09:34 -05:00
|
|
|
|
2024-01-06 01:41:33 -06:00
|
|
|
me.DnsAAAA = gadgets.NewOneLiner(grid, "DNS AAAA =").Set("unknown")
|
2023-03-25 16:19:44 -05:00
|
|
|
|
|
|
|
grid.NewLabel("DNS A =")
|
|
|
|
me.DnsA = grid.NewLabel("?")
|
|
|
|
|
2024-01-06 02:21:56 -06:00
|
|
|
// This is where you figure out what to do next to fix the problems
|
|
|
|
gr.NewButton("fix", func () {
|
2024-01-06 05:24:11 -06:00
|
|
|
fix()
|
2023-12-28 15:36:05 -06:00
|
|
|
})
|
|
|
|
|
2023-12-20 03:13:43 -06:00
|
|
|
grid.Margin()
|
|
|
|
grid.Pad()
|
|
|
|
|
2024-01-05 00:07:13 -06:00
|
|
|
statusGrid(me.window.Box())
|
2023-12-16 09:02:59 -06:00
|
|
|
|
2024-01-06 02:21:56 -06:00
|
|
|
gr = me.window.Box().NewGroup("debugging")
|
|
|
|
gr.NewButton("hostname status", func () {
|
|
|
|
if ! me.status.Ready() {return}
|
|
|
|
me.status.window.Toggle()
|
|
|
|
})
|
|
|
|
|
|
|
|
gr.NewButton("OS details", func () {
|
2024-01-05 00:07:13 -06:00
|
|
|
me.details.Toggle()
|
|
|
|
})
|
2024-01-06 05:32:52 -06:00
|
|
|
gr.NewButton("linuxstatus.New()", func () {
|
|
|
|
me.statusOS = linuxstatus.New()
|
2024-01-06 11:12:10 -06:00
|
|
|
me.statusOS.SetParent(me.myGui)
|
|
|
|
me.statusOS.InitWindow()
|
2024-01-06 05:32:52 -06:00
|
|
|
})
|
2024-01-06 13:55:46 -06:00
|
|
|
gr.NewButton("statusOS.Ready()", func () {
|
|
|
|
me.statusOS.Ready()
|
2024-01-06 11:12:10 -06:00
|
|
|
})
|
2024-01-06 13:55:46 -06:00
|
|
|
gr.NewButton("statusOS.Make()", func () {
|
|
|
|
me.statusOS.Make()
|
2024-01-06 11:12:10 -06:00
|
|
|
me.statusOS.Draw2()
|
|
|
|
})
|
2024-01-06 13:55:46 -06:00
|
|
|
gr.NewButton("statusOS.Draw()", func () {
|
|
|
|
me.statusOS.Draw()
|
|
|
|
me.statusOS.Draw2()
|
2024-01-06 05:32:52 -06:00
|
|
|
})
|
|
|
|
gr.NewButton("statusOS.Update()", func () {
|
2024-01-06 05:24:11 -06:00
|
|
|
me.statusOS.Update()
|
|
|
|
})
|
2024-01-06 11:12:10 -06:00
|
|
|
gr.NewButton("Linux Status", func () {
|
2024-01-06 05:32:52 -06:00
|
|
|
me.statusOS.Toggle()
|
|
|
|
})
|
2024-01-06 02:21:56 -06:00
|
|
|
gr.NewButton("resolver status", func () {
|
2024-01-05 00:30:58 -06:00
|
|
|
if ! me.digStatus.Ready() {return}
|
|
|
|
me.digStatus.window.Toggle()
|
|
|
|
})
|
2024-01-06 02:21:56 -06:00
|
|
|
gr.NewButton("cloudflare wit.com", func () {
|
|
|
|
cloudflare.CreateRR(me.myGui, "wit.com", "3777302ac4a78cd7fa4f6d3f72086d06")
|
|
|
|
})
|
|
|
|
gr.NewButton("Debug", func () {
|
2024-01-06 01:41:33 -06:00
|
|
|
me.debug.Toggle()
|
|
|
|
})
|
2023-12-16 09:02:59 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
func statusGrid(n *gui.Node) {
|
|
|
|
problems := n.NewGroup("status")
|
|
|
|
|
|
|
|
gridP := problems.NewGrid("nuts", 2, 2)
|
|
|
|
|
2024-01-06 01:41:33 -06:00
|
|
|
gridP.NewLabel("hostname =")
|
|
|
|
me.hostnameStatus = gridP.NewLabel("invalid")
|
|
|
|
|
2023-12-16 09:02:59 -06:00
|
|
|
gridP.NewLabel("DNS Status =")
|
2023-12-20 03:13:43 -06:00
|
|
|
me.DnsStatus = gridP.NewLabel("unknown")
|
2023-12-16 09:02:59 -06:00
|
|
|
|
2023-12-29 02:43:00 -06:00
|
|
|
me.statusIPv6 = gadgets.NewOneLiner(gridP, "IPv6 working")
|
2023-12-28 09:43:45 -06:00
|
|
|
me.statusIPv6.Set("known")
|
|
|
|
|
2023-12-20 03:13:43 -06:00
|
|
|
gridP.NewLabel("dns resolution")
|
|
|
|
me.DnsSpeed = gridP.NewLabel("unknown")
|
|
|
|
|
|
|
|
gridP.NewLabel("dns resolution speed")
|
|
|
|
me.DnsSpeedActual = gridP.NewLabel("unknown")
|
|
|
|
|
|
|
|
gridP.NewLabel("dns API provider =")
|
|
|
|
me.DnsAPI = gridP.NewLabel("unknown")
|
|
|
|
|
|
|
|
gridP.Margin()
|
|
|
|
gridP.Pad()
|
|
|
|
|
|
|
|
// TODO: these are notes for me things to figure out
|
|
|
|
ng := n.NewGroup("TODO:")
|
|
|
|
gridP = ng.NewGrid("nut2", 2, 2)
|
2023-12-16 09:02:59 -06:00
|
|
|
|
2023-12-20 03:13:43 -06:00
|
|
|
gridP.NewLabel("ping.wit.com =")
|
2023-12-16 09:02:59 -06:00
|
|
|
gridP.NewLabel("unknown")
|
2023-03-01 11:21:47 -06:00
|
|
|
|
2023-12-20 03:13:43 -06:00
|
|
|
gridP.NewLabel("ping6.wit.com =")
|
|
|
|
gridP.NewLabel("unknown")
|
|
|
|
|
|
|
|
problems.Margin()
|
|
|
|
problems.Pad()
|
|
|
|
gridP.Margin()
|
|
|
|
gridP.Pad()
|
2023-03-01 11:21:47 -06:00
|
|
|
}
|
2023-03-26 16:17:32 -05:00
|
|
|
|
2023-12-20 03:13:43 -06:00
|
|
|
// run everything because something has changed
|
2023-03-26 16:17:32 -05:00
|
|
|
func updateDNS() {
|
2023-12-28 09:43:45 -06:00
|
|
|
me.digStatus.Update()
|
2024-01-06 01:41:33 -06:00
|
|
|
me.status.Update()
|
2023-12-28 09:43:45 -06:00
|
|
|
|
2023-12-20 03:13:43 -06:00
|
|
|
// log.Println("digAAAA()")
|
2023-12-28 09:43:45 -06:00
|
|
|
|
2024-01-06 01:41:33 -06:00
|
|
|
if me.status.ValidHostname() {
|
|
|
|
var aaaa []string
|
|
|
|
h := me.status.GetHostname()
|
|
|
|
aaaa = digAAAA(h)
|
|
|
|
log.Log(NOW, "digAAAA() for", h, "=", aaaa)
|
|
|
|
|
|
|
|
// log.Println(SPEW, me)
|
|
|
|
if (aaaa == nil) {
|
|
|
|
log.Warn("There are no DNS AAAA records for hostname: ", h)
|
|
|
|
me.DnsAAAA.Set("(none)")
|
|
|
|
if (cloudflare.CFdialog.TypeNode != nil) {
|
|
|
|
cloudflare.CFdialog.TypeNode.SetText("AAAA new")
|
2023-12-28 09:43:45 -06:00
|
|
|
}
|
2024-01-06 01:41:33 -06:00
|
|
|
|
|
|
|
if (cloudflare.CFdialog.NameNode != nil) {
|
|
|
|
cloudflare.CFdialog.NameNode.SetText(h)
|
|
|
|
}
|
|
|
|
|
|
|
|
d := deleteAAA()
|
|
|
|
if (d != "") {
|
|
|
|
if (cloudflare.CFdialog.ValueNode != nil) {
|
|
|
|
cloudflare.CFdialog.ValueNode.SetText(d)
|
|
|
|
}
|
2023-12-28 09:43:45 -06:00
|
|
|
}
|
2024-01-06 01:41:33 -06:00
|
|
|
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)
|
|
|
|
*/
|
2023-12-28 09:43:45 -06:00
|
|
|
}
|
|
|
|
}
|
2023-03-26 16:17:32 -05:00
|
|
|
}
|
2023-12-28 09:43:45 -06:00
|
|
|
status := displayDNS() // update the GUI based on dig results
|
|
|
|
me.DnsStatus.SetText(status)
|
|
|
|
|
|
|
|
if me.digStatus.Ready() {
|
|
|
|
if me.digStatus.IPv6() {
|
|
|
|
me.statusIPv6.Set("IPv6 WORKING")
|
|
|
|
} else {
|
|
|
|
me.statusIPv6.Set("Need VPN")
|
|
|
|
}
|
2023-03-26 16:17:32 -05:00
|
|
|
}
|
|
|
|
|
2023-12-28 09:43:45 -06:00
|
|
|
|
|
|
|
// me.fix.Enable()
|
|
|
|
|
2023-12-20 03:13:43 -06:00
|
|
|
|
|
|
|
// lookup the NS records for your domain
|
|
|
|
// if your host is test.wit.com, find the NS resource records for wit.com
|
2024-01-06 05:24:11 -06:00
|
|
|
lookupNS(me.statusOS.GetDomainName())
|
2023-12-20 03:13:43 -06:00
|
|
|
|
2023-12-16 09:02:59 -06:00
|
|
|
log.Println("updateDNS() END")
|
2023-03-26 16:17:32 -05:00
|
|
|
}
|