2023-02-08 11:04:04 -06:00
|
|
|
// This creates a simple hello world window
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2023-12-16 09:02:59 -06:00
|
|
|
"log"
|
2023-04-07 11:23:47 -05:00
|
|
|
"fmt"
|
2023-02-08 11:04:04 -06:00
|
|
|
"os"
|
2023-02-09 09:07:00 -06:00
|
|
|
"os/user"
|
2023-03-25 08:40:48 -05:00
|
|
|
"strconv"
|
2023-03-25 16:19:44 -05:00
|
|
|
"strings"
|
2023-02-09 09:07:00 -06:00
|
|
|
"net"
|
2023-02-08 11:04:04 -06:00
|
|
|
"git.wit.org/wit/gui"
|
2023-03-01 11:21:47 -06:00
|
|
|
"git.wit.org/wit/shell"
|
2023-02-09 09:07:00 -06:00
|
|
|
"github.com/davecgh/go-spew/spew"
|
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() {
|
2023-04-11 15:24:43 -05:00
|
|
|
// me.window = myGui.New2().Window("DNS and IPv6 Control Panel").Standard()
|
|
|
|
me.window = myGui.NewWindow("DNS and IPv6 Control Panel").Standard()
|
2023-05-22 16:23:55 -05:00
|
|
|
me.window.Dump()
|
2023-03-25 22:45:48 -05:00
|
|
|
|
|
|
|
sleep(1)
|
2023-12-16 09:02:59 -06:00
|
|
|
dnsTab("DNS")
|
|
|
|
debugTab("Debug")
|
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
|
|
|
|
2023-12-16 09:02:59 -06:00
|
|
|
tab := me.window.NewTab(title)
|
2023-02-08 11:04:04 -06:00
|
|
|
|
2023-12-16 09:02:59 -06:00
|
|
|
g2 = tab.NewGroup("Real Stuff")
|
2023-02-08 11:04:04 -06:00
|
|
|
|
2023-03-26 16:17:32 -05:00
|
|
|
g2.NewButton("gui.DebugWindow()", func () {
|
|
|
|
gui.DebugWindow()
|
|
|
|
})
|
2023-04-07 11:23:47 -05:00
|
|
|
|
|
|
|
g2.NewButton("Load 'gocui'", func () {
|
|
|
|
// this set the xterm and mate-terminal window title. maybe works generally?
|
|
|
|
fmt.Println("\033]0;" + title + "blah \007")
|
2023-04-13 07:49:13 -05:00
|
|
|
myGui.LoadToolkit("gocui")
|
2023-04-07 11:23:47 -05:00
|
|
|
})
|
|
|
|
|
2023-02-18 23:37:11 -06:00
|
|
|
g2.NewButton("Network Interfaces", func () {
|
|
|
|
for i, t := range me.ifmap {
|
2023-12-16 09:02:59 -06:00
|
|
|
log.Println("name =", t.iface.Name)
|
|
|
|
log.Println("int =", i, "name =", t.name, t.iface)
|
|
|
|
log.Println("iface = " + t.iface.Name)
|
2023-02-18 23:37:11 -06:00
|
|
|
}
|
2023-02-09 09:07:00 -06:00
|
|
|
})
|
2023-02-18 23:37:11 -06:00
|
|
|
g2.NewButton("Hostname", func () {
|
|
|
|
getHostname()
|
|
|
|
})
|
|
|
|
g2.NewButton("Actual AAAA", func () {
|
|
|
|
var aaaa []string
|
|
|
|
aaaa = realAAAA()
|
|
|
|
for _, s := range aaaa {
|
2023-12-16 09:02:59 -06:00
|
|
|
log.Println("my actual AAAA = ", s)
|
2023-02-18 23:37:11 -06:00
|
|
|
}
|
|
|
|
})
|
2023-03-01 11:21:47 -06:00
|
|
|
|
2023-04-13 07:49:13 -05:00
|
|
|
g2.NewButton("Update DNS", func () {
|
2023-12-16 09:02:59 -06:00
|
|
|
log.Println("updateDNS()")
|
2023-04-13 07:49:13 -05:00
|
|
|
updateDNS()
|
|
|
|
})
|
|
|
|
|
2023-02-18 23:37:11 -06:00
|
|
|
g2.NewButton("checkDNS()", func () {
|
|
|
|
checkDNS()
|
2023-02-09 09:07:00 -06:00
|
|
|
})
|
|
|
|
g2.NewButton("os.User()", func () {
|
|
|
|
user, _ := user.Current()
|
|
|
|
spew.Dump(user)
|
2023-12-16 09:02:59 -06:00
|
|
|
log.Println("os.Getuid =", user.Username, os.Getuid())
|
2023-03-25 08:40:48 -05:00
|
|
|
if (me.uid != nil) {
|
|
|
|
me.uid.SetText(user.Username + " (" + strconv.Itoa(os.Getuid()) + ")")
|
|
|
|
}
|
2023-02-18 23:37:11 -06:00
|
|
|
})
|
2023-03-25 16:19:44 -05:00
|
|
|
g2.NewButton("dig +trace", func () {
|
|
|
|
o := shell.Run("dig +trace +noadditional DS " + me.hostname + " @8.8.8.8")
|
2023-12-16 09:02:59 -06:00
|
|
|
log.Println(o)
|
|
|
|
// log.Println(o)
|
2023-03-25 16:19:44 -05:00
|
|
|
})
|
2023-02-18 23:37:11 -06:00
|
|
|
g2.NewButton("Example_listLink()", func () {
|
|
|
|
Example_listLink()
|
2023-02-09 09:07:00 -06:00
|
|
|
})
|
|
|
|
g2.NewButton("Escalate()", func () {
|
|
|
|
Escalate()
|
|
|
|
})
|
|
|
|
g2.NewButton("LookupAddr(<raw ipv6>) == fire from /etc/hosts", func () {
|
|
|
|
host, err := net.LookupAddr("2600:1700:afd5:6000:b26e:bfff:fe80:3c52")
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
2023-12-16 09:02:59 -06:00
|
|
|
log.Println("host =", host)
|
2023-02-09 09:07:00 -06:00
|
|
|
})
|
|
|
|
g2.NewButton("DumpPublicDNSZone(apple.com)", func () {
|
|
|
|
DumpPublicDNSZone("apple.com")
|
2023-02-09 19:47:52 -06:00
|
|
|
dumpIPs("www.apple.com")
|
2023-02-09 09:07:00 -06:00
|
|
|
})
|
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
|
|
|
|
2023-12-16 09:02:59 -06:00
|
|
|
func dnsTab(title string) {
|
|
|
|
tab := me.window.NewTab(title)
|
|
|
|
|
|
|
|
g := tab.NewGroup("dns update")
|
2023-03-25 08:09:34 -05:00
|
|
|
|
2023-04-07 11:23:47 -05:00
|
|
|
grid := g.NewGrid("gridnuts", 2, 2)
|
2023-03-25 08:09:34 -05:00
|
|
|
|
|
|
|
grid.SetNext(1,1)
|
|
|
|
grid.NewLabel("hostname =")
|
2023-03-25 16:19:44 -05:00
|
|
|
me.fqdn = grid.NewLabel("?")
|
|
|
|
me.hostname = ""
|
2023-03-25 08:09:34 -05:00
|
|
|
|
|
|
|
grid.NewLabel("UID =")
|
2023-03-25 16:19:44 -05:00
|
|
|
me.uid = grid.NewLabel("?")
|
|
|
|
|
|
|
|
grid.NewLabel("DNS AAAA =")
|
|
|
|
me.DnsAAAA = grid.NewLabel("?")
|
|
|
|
|
|
|
|
grid.NewLabel("DNS A =")
|
|
|
|
me.DnsA = grid.NewLabel("?")
|
|
|
|
|
2023-03-25 08:09:34 -05:00
|
|
|
grid.NewLabel("IPv4 =")
|
2023-03-26 16:17:32 -05:00
|
|
|
me.IPv4 = grid.NewLabel("?")
|
2023-03-25 08:09:34 -05:00
|
|
|
|
|
|
|
grid.NewLabel("IPv6 =")
|
2023-03-26 16:17:32 -05:00
|
|
|
me.IPv6 = grid.NewLabel("?")
|
2023-03-25 08:09:34 -05:00
|
|
|
|
|
|
|
grid.NewLabel("interfaces =")
|
2023-03-26 16:17:32 -05:00
|
|
|
me.Interfaces = grid.NewCombobox("Interfaces")
|
2023-03-25 08:09:34 -05:00
|
|
|
|
2023-03-26 16:17:32 -05:00
|
|
|
grid.NewLabel("DNS Status =")
|
|
|
|
me.DnsStatus = grid.NewLabel("unknown")
|
2023-03-25 16:19:44 -05:00
|
|
|
|
2023-12-16 09:02:59 -06:00
|
|
|
me.fix = g.NewButton("Fix", func () {
|
|
|
|
if (goodHostname(me.hostname)) {
|
|
|
|
log.Println("hostname is good:", me.hostname)
|
|
|
|
} else {
|
|
|
|
log.Println("you need to fix your hostname here", me.hostname)
|
|
|
|
return
|
|
|
|
}
|
2023-04-13 07:49:13 -05:00
|
|
|
nsupdate()
|
2023-03-01 11:21:47 -06:00
|
|
|
})
|
2023-12-16 09:02:59 -06:00
|
|
|
me.fix.Disable()
|
|
|
|
|
|
|
|
statusGrid(tab)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func statusGrid(n *gui.Node) {
|
|
|
|
problems := n.NewGroup("status")
|
|
|
|
|
|
|
|
gridP := problems.NewGrid("nuts", 2, 2)
|
|
|
|
|
|
|
|
gridP.NewLabel("DNS Status =")
|
|
|
|
gridP.NewLabel("unknown")
|
|
|
|
|
|
|
|
gridP.NewLabel("hostname =")
|
|
|
|
gridP.NewLabel("invalid")
|
|
|
|
|
|
|
|
gridP.NewLabel("dns provider =")
|
|
|
|
gridP.NewLabel("unknown")
|
|
|
|
|
|
|
|
gridP.NewLabel("IPv6 working =")
|
|
|
|
gridP.NewLabel("unknown")
|
|
|
|
|
|
|
|
gridP.NewLabel("dns resolution =")
|
|
|
|
gridP.NewLabel("unknown")
|
2023-03-01 11:21:47 -06:00
|
|
|
}
|
|
|
|
|
2023-05-22 16:23:55 -05:00
|
|
|
/*
|
2023-03-01 11:21:47 -06:00
|
|
|
var outJunk string
|
|
|
|
func output(s string, a bool) {
|
|
|
|
if (a) {
|
|
|
|
outJunk += s
|
|
|
|
} else {
|
|
|
|
outJunk = s
|
|
|
|
}
|
|
|
|
me.output.SetText(outJunk)
|
2023-12-16 09:02:59 -06:00
|
|
|
log.Println(outJunk)
|
2023-03-01 11:21:47 -06:00
|
|
|
}
|
2023-05-22 16:23:55 -05:00
|
|
|
*/
|
2023-03-26 16:17:32 -05:00
|
|
|
|
|
|
|
func updateDNS() {
|
|
|
|
var aaaa []string
|
|
|
|
h := me.hostname
|
|
|
|
if (h == "") {
|
|
|
|
h = "unknown.lab.wit.org"
|
|
|
|
// h = "hpdevone.lab.wit.org"
|
|
|
|
}
|
2023-12-16 09:02:59 -06:00
|
|
|
log.Println("dnsAAAA()()")
|
2023-03-26 16:17:32 -05:00
|
|
|
aaaa = dnsAAAA(h)
|
2023-12-16 09:02:59 -06:00
|
|
|
log.Println("dnsAAAA()()")
|
|
|
|
log.Println(SPEW, me)
|
2023-03-26 16:17:32 -05:00
|
|
|
if (aaaa == nil) {
|
2023-12-16 09:02:59 -06:00
|
|
|
log.Println("There are no DNS AAAA records for hostname: ", h)
|
2023-03-26 16:17:32 -05:00
|
|
|
}
|
|
|
|
var broken int = 0
|
|
|
|
var all string
|
|
|
|
for _, s := range aaaa {
|
2023-12-16 09:02:59 -06:00
|
|
|
log.Println("host", h, "DNS AAAA =", s)
|
2023-03-26 16:17:32 -05:00
|
|
|
all += s + "\n"
|
|
|
|
if ( me.ipmap[s] == nil) {
|
2023-12-16 09:02:59 -06:00
|
|
|
log.Println("THIS IS THE WRONG AAAA DNS ENTRY: host", h, "DNS AAAA =", s)
|
2023-03-26 16:17:32 -05:00
|
|
|
broken = 2
|
|
|
|
} else {
|
|
|
|
if (broken == 0) {
|
|
|
|
broken = 1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-03-26 16:56:09 -05:00
|
|
|
all = strings.TrimSpace(all)
|
2023-03-26 16:17:32 -05:00
|
|
|
me.DnsAAAA.SetText(all)
|
|
|
|
if (broken == 1) {
|
|
|
|
me.DnsStatus.SetText("WORKING")
|
|
|
|
} else {
|
|
|
|
me.DnsStatus.SetText("BROKEN")
|
2023-12-16 09:02:59 -06:00
|
|
|
me.fix.Enable()
|
|
|
|
log.Println("Need to run go-nsupdate here")
|
2023-04-13 07:49:13 -05:00
|
|
|
nsupdate()
|
2023-03-26 16:17:32 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
user, _ := user.Current()
|
|
|
|
spew.Dump(user)
|
2023-12-16 09:02:59 -06:00
|
|
|
log.Println("os.Getuid =", user.Username, os.Getuid())
|
2023-03-26 16:17:32 -05:00
|
|
|
if (me.uid != nil) {
|
|
|
|
me.uid.SetText(user.Username + " (" + strconv.Itoa(os.Getuid()) + ")")
|
|
|
|
}
|
2023-12-16 09:02:59 -06:00
|
|
|
log.Println("updateDNS() END")
|
2023-03-26 16:17:32 -05:00
|
|
|
}
|