gocui mode works again

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2023-12-16 09:02:59 -06:00
parent dbd81e9462
commit 27696b9764
15 changed files with 211 additions and 143 deletions

1
.gitignore vendored
View File

@ -2,3 +2,4 @@ control-panel-dns
/files/* /files/*
/*.deb /*.deb
*.swp *.swp
/plugins/*

View File

@ -1,10 +1,14 @@
run: build run: build
./control-panel-dns >/tmp/witgui.log.stderr 2>&1 # ./control-panel-dns >/tmp/witgui.log.stderr 2>&1
./control-panel-dns
install: install:
go install -v go.wit.com/control-panel-dns@latest go install -v go.wit.com/control-panel-dns@latest
# go install -v git.wit.com/wit/control-panel-dns@latest # go install -v git.wit.com/wit/control-panel-dns@latest
gocui:
./control-panel-dns -gui gocui >/tmp/witgui.log.stderr 2>&1
debug: build debug: build
./control-panel-dns --verbose --verbose-net --gui-debug ./control-panel-dns --verbose --verbose-net --gui-debug
@ -18,6 +22,8 @@ build-release:
build: build:
reset reset
-mkdir -p plugins/
-cp ~/go/src/git.wit.org/wit/gui/toolkit/*.so plugins/
# GO111MODULE="off" go get -v -x . # GO111MODULE="off" go get -v -x .
GO111MODULE="off" go build -v -o control-panel-dns GO111MODULE="off" go build -v -o control-panel-dns

32
args.go
View File

@ -1,26 +1,40 @@
// This creates a simple hello world window
package main package main
/*
this parses the command line arguements
*/
import ( import (
"fmt"
arg "github.com/alexflint/go-arg"
"git.wit.org/wit/gui" "git.wit.org/wit/gui"
// "git.wit.org/jcarr/dnssecsocket" log "git.wit.org/wit/gui/log"
) )
type LogOptions struct {
var args struct {
Verbose bool Verbose bool
VerboseNet bool `arg:"--verbose-net" help:"debug your local OS network settings"` VerboseNet bool `arg:"--verbose-net" help:"debug your local OS network settings"`
VerboseDNS bool `arg:"--verbose-dns" help:"debug your dns settings"` VerboseDNS bool `arg:"--verbose-dns" help:"debug your dns settings"`
LogFile string `help:"write all output to a file"` LogFile string `help:"write all output to a file"`
// User string `arg:"env:USER"` // User string `arg:"env:USER"`
Display string `arg:"env:DISPLAY"` Display string `arg:"env:DISPLAY"`
}
var args struct { Foo string
LogOptions Bar bool
// dnssecsocket.Args User string `arg:"env:USER"`
Demo bool `help:"run a demo"`
gui.GuiArgs gui.GuiArgs
log.LogArgs
} }
func parsedown () { func init() {
// dnssecsocket.Parse(args.VerboseDnssec) arg.MustParse(&args)
fmt.Println(args.Foo, args.Bar, args.User)
if (args.Gui != "") {
gui.GuiArg.Gui = args.Gui
}
log.Log(true, "INIT() args.GuiArg.Gui =", gui.GuiArg.Gui)
} }

View File

@ -2,6 +2,7 @@ package main
import ( import (
"io" "io"
"log"
"os" "os"
"os/exec" "os/exec"
"os/signal" "os/signal"
@ -29,7 +30,7 @@ func test() error {
go func() { go func() {
for range ch { for range ch {
if err := pty.InheritSize(os.Stdin, ptmx); err != nil { if err := pty.InheritSize(os.Stdin, ptmx); err != nil {
log("error resizing pty: %s", err) log.Println("error resizing pty: %s", err)
} }
} }
}() }()
@ -53,7 +54,7 @@ func test() error {
func mainBash() { func mainBash() {
if err := test(); err != nil { if err := test(); err != nil {
log(logError, "exit in mainBash()") log.Println(logError, "exit in mainBash()")
exit(err) exit(err)
} }
} }

19
dns.go
View File

@ -5,6 +5,7 @@
package main package main
import ( import (
"log"
"net" "net"
) )
@ -23,16 +24,16 @@ func (h *Host) verifyETC() bool {
func (h *Host) updateIPs(host string) { func (h *Host) updateIPs(host string) {
ips, err := net.LookupIP(host) ips, err := net.LookupIP(host)
if err != nil { if err != nil {
log(logError, "updateIPs failed", err) log.Println(logError, "updateIPs failed", err)
} }
for _, ip := range ips { for _, ip := range ips {
log(host, ip) log.Println(host, ip)
} }
} }
func (h *Host) setIPv4(ipv4s map[string]*IPtype) { func (h *Host) setIPv4(ipv4s map[string]*IPtype) {
for ip, t := range ipv4s { for ip, t := range ipv4s {
log("IPv4", ip, t) log.Println("IPv4", ip, t)
} }
} }
@ -47,11 +48,11 @@ func (h *Host) checkDNS() {
ipt = "IPv6" ipt = "IPv6"
} }
if (! t.IsReal()) { if (! t.IsReal()) {
log(args.VerboseDNS, "\tIP is not Real", ipt, i.Index, i.Name, s) log.Println(args.VerboseDNS, "\tIP is not Real", ipt, i.Index, i.Name, s)
continue continue
} }
log(args.VerboseDNS, "\tIP is Real ", ipt, i.Index, i.Name, s) log.Println(args.VerboseDNS, "\tIP is Real ", ipt, i.Index, i.Name, s)
if (t.ipv6) { if (t.ipv6) {
ip6 = true ip6 = true
} else { } else {
@ -60,13 +61,13 @@ func (h *Host) checkDNS() {
} }
if (ip4 == true) { if (ip4 == true) {
log(args.VerboseDNS, "IPv4 should work. Wow. You actually have a real IPv4 address") log.Println(args.VerboseDNS, "IPv4 should work. Wow. You actually have a real IPv4 address")
} else { } else {
log(args.VerboseDNS, "IPv4 is broken. (be nice and setup ipv4-only.wit.com)") log.Println(args.VerboseDNS, "IPv4 is broken. (be nice and setup ipv4-only.wit.com)")
} }
if (ip6 == true) { if (ip6 == true) {
log(args.VerboseDNS, "IPv6 should be working. Need to test it here.") log.Println(args.VerboseDNS, "IPv6 should be working. Need to test it here.")
} else { } else {
log(args.VerboseDNS, "IPv6 is broken. Need to fix it here.") log.Println(args.VerboseDNS, "IPv6 is broken. Need to fix it here.")
} }
} }

View File

@ -3,6 +3,7 @@ package main
// Watches for changes to a directory. Works cross-platform // Watches for changes to a directory. Works cross-platform
import ( import (
"log"
"github.com/fsnotify/fsnotify" "github.com/fsnotify/fsnotify"
) )
@ -13,7 +14,7 @@ func watchSysClassNet() {
// Create new watcher. // Create new watcher.
watcher, err := fsnotify.NewWatcher() watcher, err := fsnotify.NewWatcher()
if err != nil { if err != nil {
log(logError, "watchSysClassNet() failed:", err) log.Println(logError, "watchSysClassNet() failed:", err)
return return
} }
defer watcher.Close() defer watcher.Close()
@ -26,15 +27,15 @@ func watchSysClassNet() {
if !ok { if !ok {
return return
} }
log("event:", event) log.Println("event:", event)
if event.Has(fsnotify.Write) { if event.Has(fsnotify.Write) {
log("modified file:", event.Name) log.Println("modified file:", event.Name)
} }
case err, ok := <-watcher.Errors: case err, ok := <-watcher.Errors:
if !ok { if !ok {
return return
} }
log("error:", err) log.Println("error:", err)
} }
} }
}() }()
@ -42,7 +43,7 @@ func watchSysClassNet() {
// Add a path. // Add a path.
err = watcher.Add("/tmp") err = watcher.Add("/tmp")
if err != nil { if err != nil {
log(logError, "watchSysClassNet() watcher.Add() failed:", err) log.Println(logError, "watchSysClassNet() watcher.Add() failed:", err)
return return
} }
@ -65,12 +66,12 @@ func fsnotifyNetworkInterfaceChanges() error {
for { for {
select { select {
case event := <-watcher.Events: case event := <-watcher.Events:
log("fsnotifyNetworkInterfaceChanges() event =", event) log.Println("fsnotifyNetworkInterfaceChanges() event =", event)
if event.Op&fsnotify.Create == fsnotify.Create { if event.Op&fsnotify.Create == fsnotify.Create {
// Do something on network interface creation // Do something on network interface creation
} }
case err := <-watcher.Errors: case err := <-watcher.Errors:
log("fsnotifyNetworkInterfaceChanges() event err =", err) log.Println("fsnotifyNetworkInterfaceChanges() event err =", err)
return err return err
} }
} }

101
gui.go
View File

@ -2,6 +2,7 @@
package main package main
import ( import (
"log"
"fmt" "fmt"
"os" "os"
"os/user" "os/user"
@ -20,16 +21,17 @@ func setupControlPanelWindow() {
me.window.Dump() me.window.Dump()
sleep(1) sleep(1)
addDNSTab("DNS") dnsTab("DNS")
debugTab("Debug")
} }
func addDNSTab(title string) { func debugTab(title string) {
var g2 *gui.Node var g2 *gui.Node
me.tab = me.window.NewTab(title) tab := me.window.NewTab(title)
g2 = me.tab.NewGroup("Real Stuff") g2 = tab.NewGroup("Real Stuff")
g2.NewButton("gui.DebugWindow()", func () { g2.NewButton("gui.DebugWindow()", func () {
gui.DebugWindow() gui.DebugWindow()
@ -43,9 +45,9 @@ func addDNSTab(title string) {
g2.NewButton("Network Interfaces", func () { g2.NewButton("Network Interfaces", func () {
for i, t := range me.ifmap { for i, t := range me.ifmap {
log("name =", t.iface.Name) log.Println("name =", t.iface.Name)
log("int =", i, "name =", t.name, t.iface) log.Println("int =", i, "name =", t.name, t.iface)
log("iface = " + t.iface.Name) log.Println("iface = " + t.iface.Name)
} }
}) })
g2.NewButton("Hostname", func () { g2.NewButton("Hostname", func () {
@ -55,12 +57,12 @@ func addDNSTab(title string) {
var aaaa []string var aaaa []string
aaaa = realAAAA() aaaa = realAAAA()
for _, s := range aaaa { for _, s := range aaaa {
log("my actual AAAA = ", s) log.Println("my actual AAAA = ", s)
} }
}) })
g2.NewButton("Update DNS", func () { g2.NewButton("Update DNS", func () {
log("updateDNS()") log.Println("updateDNS()")
updateDNS() updateDNS()
}) })
@ -70,15 +72,15 @@ func addDNSTab(title string) {
g2.NewButton("os.User()", func () { g2.NewButton("os.User()", func () {
user, _ := user.Current() user, _ := user.Current()
spew.Dump(user) spew.Dump(user)
log("os.Getuid =", user.Username, os.Getuid()) log.Println("os.Getuid =", user.Username, os.Getuid())
if (me.uid != nil) { if (me.uid != nil) {
me.uid.SetText(user.Username + " (" + strconv.Itoa(os.Getuid()) + ")") me.uid.SetText(user.Username + " (" + strconv.Itoa(os.Getuid()) + ")")
} }
}) })
g2.NewButton("dig +trace", func () { g2.NewButton("dig +trace", func () {
o := shell.Run("dig +trace +noadditional DS " + me.hostname + " @8.8.8.8") o := shell.Run("dig +trace +noadditional DS " + me.hostname + " @8.8.8.8")
log(o) log.Println(o)
// log(o) // log.Println(o)
}) })
g2.NewButton("Example_listLink()", func () { g2.NewButton("Example_listLink()", func () {
Example_listLink() Example_listLink()
@ -91,32 +93,23 @@ func addDNSTab(title string) {
if err != nil { if err != nil {
return return
} }
log("host =", host) log.Println("host =", host)
}) })
g2.NewButton("DumpPublicDNSZone(apple.com)", func () { g2.NewButton("DumpPublicDNSZone(apple.com)", func () {
DumpPublicDNSZone("apple.com") DumpPublicDNSZone("apple.com")
dumpIPs("www.apple.com") dumpIPs("www.apple.com")
}) })
nsupdateGroup(me.tab)
/*
tmp := me.tab.NewGroup("output")
me.output = tmp.NewTextbox("some output")
me.output.Custom = func() {
s := me.output.GetText()
log("output text =", s)
}
*/
} }
func myDefaultExit(n *gui.Node) { func myDefaultExit(n *gui.Node) {
log("You can Do exit() things here") log.Println("You can Do exit() things here")
os.Exit(0) os.Exit(0)
} }
func nsupdateGroup(w *gui.Node) { func dnsTab(title string) {
g := w.NewGroup("dns update") tab := me.window.NewTab(title)
g := tab.NewGroup("dns update")
grid := g.NewGrid("gridnuts", 2, 2) grid := g.NewGrid("gridnuts", 2, 2)
@ -146,9 +139,40 @@ func nsupdateGroup(w *gui.Node) {
grid.NewLabel("DNS Status =") grid.NewLabel("DNS Status =")
me.DnsStatus = grid.NewLabel("unknown") me.DnsStatus = grid.NewLabel("unknown")
g.NewButton("go-nsupdate", func () { 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
}
nsupdate() nsupdate()
}) })
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")
} }
/* /*
@ -160,7 +184,7 @@ func output(s string, a bool) {
outJunk = s outJunk = s
} }
me.output.SetText(outJunk) me.output.SetText(outJunk)
log(outJunk) log.Println(outJunk)
} }
*/ */
@ -171,20 +195,20 @@ func updateDNS() {
h = "unknown.lab.wit.org" h = "unknown.lab.wit.org"
// h = "hpdevone.lab.wit.org" // h = "hpdevone.lab.wit.org"
} }
log("dnsAAAA()()") log.Println("dnsAAAA()()")
aaaa = dnsAAAA(h) aaaa = dnsAAAA(h)
log("dnsAAAA()()") log.Println("dnsAAAA()()")
log(SPEW, me) log.Println(SPEW, me)
if (aaaa == nil) { if (aaaa == nil) {
log("There are no DNS AAAA records for hostname: ", h) log.Println("There are no DNS AAAA records for hostname: ", h)
} }
var broken int = 0 var broken int = 0
var all string var all string
for _, s := range aaaa { for _, s := range aaaa {
log("host", h, "DNS AAAA =", s) log.Println("host", h, "DNS AAAA =", s)
all += s + "\n" all += s + "\n"
if ( me.ipmap[s] == nil) { if ( me.ipmap[s] == nil) {
log("THIS IS THE WRONG AAAA DNS ENTRY: host", h, "DNS AAAA =", s) log.Println("THIS IS THE WRONG AAAA DNS ENTRY: host", h, "DNS AAAA =", s)
broken = 2 broken = 2
} else { } else {
if (broken == 0) { if (broken == 0) {
@ -198,15 +222,16 @@ func updateDNS() {
me.DnsStatus.SetText("WORKING") me.DnsStatus.SetText("WORKING")
} else { } else {
me.DnsStatus.SetText("BROKEN") me.DnsStatus.SetText("BROKEN")
log("Need to run go-nsupdate here") me.fix.Enable()
log.Println("Need to run go-nsupdate here")
nsupdate() nsupdate()
} }
user, _ := user.Current() user, _ := user.Current()
spew.Dump(user) spew.Dump(user)
log("os.Getuid =", user.Username, os.Getuid()) log.Println("os.Getuid =", user.Username, os.Getuid())
if (me.uid != nil) { if (me.uid != nil) {
me.uid.SetText(user.Username + " (" + strconv.Itoa(os.Getuid()) + ")") me.uid.SetText(user.Username + " (" + strconv.Itoa(os.Getuid()) + ")")
} }
log("updateDNS() END") log.Println("updateDNS() END")
} }

View File

@ -5,7 +5,10 @@
package main package main
// import "net" import (
"log"
"git.wit.org/wit/shell"
)
// will try to get this hosts FQDN // will try to get this hosts FQDN
import "github.com/Showmax/go-fqdn" import "github.com/Showmax/go-fqdn"
@ -21,7 +24,7 @@ func getHostname() {
var s string = "gui.Label == nil" var s string = "gui.Label == nil"
s, err = fqdn.FqdnHostname() s, err = fqdn.FqdnHostname()
if (err != nil) { if (err != nil) {
log("FQDN hostname error =", err) log.Println("FQDN hostname error =", err)
return return
} }
if (me.fqdn != nil) { if (me.fqdn != nil) {
@ -31,19 +34,30 @@ func getHostname() {
me.changed = true me.changed = true
} }
} }
log("FQDN =", s) log.Println("FQDN =", s)
}
// returns true if the hostname is good
// check that all the OS settings are correct here
// On Linux, /etc/hosts, /etc/hostname
// and domainname and hostname
func goodHostname(h string) bool {
hostname := shell.Cat("/etc/hostname")
log.Println("hostname =", hostname)
return false
} }
func dnsAAAA(s string) []string { func dnsAAAA(s string) []string {
var aaaa []string var aaaa []string
// lookup the IP address from DNS // lookup the IP address from DNS
rrset := dnssecsocket.Dnstrace(s, "AAAA") rrset := dnssecsocket.Dnstrace(s, "AAAA")
log(args.VerboseDNS, SPEW, rrset) log.Println(args.VerboseDNS, SPEW, rrset)
for i, rr := range rrset { for i, rr := range rrset {
log(args.VerboseDNS, "r.Answer =", i, rr) log.Println(args.VerboseDNS, "r.Answer =", i, rr)
ipaddr := dns.Field(rr, 1) ipaddr := dns.Field(rr, 1)
aaaa = append(aaaa, ipaddr) aaaa = append(aaaa, ipaddr)
} }
log(args.VerboseDNS, "aaaa =", aaaa) log.Println(args.VerboseDNS, "aaaa =", aaaa)
return aaaa return aaaa
} }

5
log.go
View File

@ -1,6 +1,7 @@
package main package main
import ( import (
"log"
witlog "git.wit.org/wit/gui/log" witlog "git.wit.org/wit/gui/log"
) )
@ -15,16 +16,18 @@ var SPEW witlog.Spewt
// var log interface{} // var log interface{}
/*
func log(a ...any) { func log(a ...any) {
witlog.Where = "wit/gui" witlog.Where = "wit/gui"
witlog.Log(a...) witlog.Log(a...)
} }
*/
func sleep(a ...any) { func sleep(a ...any) {
witlog.Sleep(a...) witlog.Sleep(a...)
} }
func exit(a ...any) { func exit(a ...any) {
log(logError, "got to log() exit") log.Println(logError, "got to log() exit")
witlog.Exit(a...) witlog.Exit(a...)
} }

29
main.go
View File

@ -5,19 +5,21 @@
package main package main
import ( import (
"log"
"strconv" "strconv"
"runtime" "runtime"
"time" "time"
arg "github.com/alexflint/go-arg" "embed"
"git.wit.org/wit/gui" "git.wit.org/wit/gui"
) )
var p *arg.Parser
var myGui *gui.Node var myGui *gui.Node
//go:embed plugins/*.so
var resToolkit embed.FS
func main() { func main() {
p = arg.MustParse(&args) // parsedown()
parsedown()
// initialize the maps to track IP addresses and network interfaces // initialize the maps to track IP addresses and network interfaces
me.ipmap = make(map[string]*IPtype) me.ipmap = make(map[string]*IPtype)
@ -25,16 +27,11 @@ func main() {
me.ifmap = make(map[int]*IFtype) me.ifmap = make(map[int]*IFtype)
me.dnsTTL = 5 // recheck DNS is working every 2 minutes // TODO: watch rx packets? me.dnsTTL = 5 // recheck DNS is working every 2 minutes // TODO: watch rx packets?
log("Toolkit = ", args.GuiToolkit)
for i, t := range args.GuiToolkit {
log("trying to load plugin", i, t)
myGui.LoadToolkit(t)
}
// will set all debugging flags // will set all debugging flags
// gui.SetDebug(true) // gui.SetDebug(true)
myGui = gui.New().LoadToolkit("gocui") // myGui = gui.New().InitEmbed(resToolkit).LoadToolkit("gocui")
myGui = gui.New().Default()
sleep(1) sleep(1)
setupControlPanelWindow() setupControlPanelWindow()
sleep(1) sleep(1)
@ -60,7 +57,7 @@ func checkNetworkChanges() {
if (runtime.GOOS == "linux") { if (runtime.GOOS == "linux") {
dnsTTL() dnsTTL()
} else { } else {
log("Windows and MacOS don't work yet") log.Println("Windows and MacOS don't work yet")
} }
ttl = me.dnsTTL ttl = me.dnsTTL
} }
@ -71,25 +68,25 @@ func checkNetworkChanges() {
// and verifies that DNS is working or not working // and verifies that DNS is working or not working
func dnsTTL() { func dnsTTL() {
me.changed = false me.changed = false
log("FQDN =", me.fqdn.GetText()) log.Println("FQDN =", me.fqdn.GetText())
getHostname() getHostname()
scanInterfaces() scanInterfaces()
for i, t := range me.ifmap { for i, t := range me.ifmap {
log(strconv.Itoa(i) + " iface = " + t.iface.Name) log.Println(strconv.Itoa(i) + " iface = " + t.iface.Name)
} }
var aaaa []string var aaaa []string
aaaa = realAAAA() aaaa = realAAAA()
var all string var all string
for _, s := range aaaa { for _, s := range aaaa {
log("my actual AAAA = ",s) log.Println("my actual AAAA = ",s)
all += s + "\n" all += s + "\n"
} }
// me.IPv6.SetText(all) // me.IPv6.SetText(all)
if (me.changed) { if (me.changed) {
stamp := time.Now().Format("2006/01/02 15:04:05") stamp := time.Now().Format("2006/01/02 15:04:05")
log(logError, "Network things changed on", stamp) log.Println(logError, "Network things changed on", stamp)
updateDNS() updateDNS()
} }
} }

85
net.go
View File

@ -2,6 +2,7 @@
package main package main
import ( import (
"log"
"net" "net"
"strings" "strings"
) )
@ -17,21 +18,21 @@ func watchNetworkInterfaces() {
// Set up a notification channel // Set up a notification channel
notification := make(chan net.Interface) notification := make(chan net.Interface)
log(DEBUGNET, "watchNet()") log.Println(DEBUGNET, "watchNet()")
// Start goroutine to watch for changes // Start goroutine to watch for changes
go func() { go func() {
log(DEBUGNET, "watchNet() func") log.Println(DEBUGNET, "watchNet() func")
for { for {
log(DEBUGNET, "forever loop start") log.Println(DEBUGNET, "forever loop start")
// Check for changes in each interface // Check for changes in each interface
for _, i := range interfaces { for _, i := range interfaces {
log(DEBUGNET, "something on i =", i) log.Println(DEBUGNET, "something on i =", i)
if status := i.Flags & net.FlagUp; status != 0 { if status := i.Flags & net.FlagUp; status != 0 {
notification <- i notification <- i
log(DEBUGNET, "something on i =", i) log.Println(DEBUGNET, "something on i =", i)
} }
} }
log(DEBUGNET, "forever loop end") log.Println(DEBUGNET, "forever loop end")
} }
}() }()
} }
@ -43,20 +44,20 @@ func IsIPv6(address string) bool {
func (t *IPtype) IsReal() bool { func (t *IPtype) IsReal() bool {
if (t.ip.IsPrivate() || t.ip.IsLoopback() || t.ip.IsLinkLocalUnicast()) { if (t.ip.IsPrivate() || t.ip.IsLoopback() || t.ip.IsLinkLocalUnicast()) {
log(DEBUGNET, "\t\tIP is Real = false") log.Println(DEBUGNET, "\t\tIP is Real = false")
return false return false
} else { } else {
log(DEBUGNET, "\t\tIP is Real = true") log.Println(DEBUGNET, "\t\tIP is Real = true")
return true return true
} }
} }
func IsReal(ip *net.IP) bool { func IsReal(ip *net.IP) bool {
if (ip.IsPrivate() || ip.IsLoopback() || ip.IsLinkLocalUnicast()) { if (ip.IsPrivate() || ip.IsLoopback() || ip.IsLinkLocalUnicast()) {
log(DEBUGNET, "\t\tIP is Real = false") log.Println(DEBUGNET, "\t\tIP is Real = false")
return false return false
} else { } else {
log(DEBUGNET, "\t\tIP is Real = true") log.Println(DEBUGNET, "\t\tIP is Real = true")
return true return true
} }
} }
@ -73,7 +74,7 @@ func renameInterface(i *net.Interface) {
func checkInterface(i net.Interface) { func checkInterface(i net.Interface) {
val, ok := me.ifmap[i.Index] val, ok := me.ifmap[i.Index]
if ! ok { if ! ok {
log(i.Name, "is a new network interface. The linux kernel index =", i.Index) log.Println(i.Name, "is a new network interface. The linux kernel index =", i.Index)
me.ifmap[i.Index] = new(IFtype) me.ifmap[i.Index] = new(IFtype)
me.ifmap[i.Index].gone = false me.ifmap[i.Index].gone = false
me.ifmap[i.Index].iface = &i me.ifmap[i.Index].iface = &i
@ -85,9 +86,9 @@ func checkInterface(i net.Interface) {
return return
} }
me.ifmap[i.Index].gone = false me.ifmap[i.Index].gone = false
log(args.VerboseNet, "me.ifmap[i] does exist. Need to compare everything.", i.Index, i.Name, val.iface.Index, val.iface.Name) log.Println(args.VerboseNet, "me.ifmap[i] does exist. Need to compare everything.", i.Index, i.Name, val.iface.Index, val.iface.Name)
if (val.iface.Name != i.Name) { if (val.iface.Name != i.Name) {
log(val.iface.Name, "has changed to it's name to", i.Name) log.Println(val.iface.Name, "has changed to it's name to", i.Name)
me.ifmap[i.Index].iface = &i me.ifmap[i.Index].iface = &i
me.changed = true me.changed = true
if (me.Interfaces != nil) { if (me.Interfaces != nil) {
@ -125,14 +126,14 @@ func checkDNS() (map[string]*IPtype, map[string]*IPtype) {
ipt = "IPv6" ipt = "IPv6"
} }
if (t.IsReal()) { if (t.IsReal()) {
log("\tIP is Real ", ipt, i.Index, i.Name, s) log.Println("\tIP is Real ", ipt, i.Index, i.Name, s)
if (t.ipv6) { if (t.ipv6) {
ipv6s[s] = t ipv6s[s] = t
} else { } else {
ipv4s[s] = t ipv4s[s] = t
} }
} else { } else {
log("\tIP is not Real", ipt, i.Index, i.Name, s) log.Println("\tIP is not Real", ipt, i.Index, i.Name, s)
} }
} }
return ipv6s, ipv4s return ipv6s, ipv4s
@ -140,14 +141,14 @@ func checkDNS() (map[string]*IPtype, map[string]*IPtype) {
// Will figure out if an IP address is new // Will figure out if an IP address is new
func checkIP(ip *net.IPNet, i net.Interface) bool { func checkIP(ip *net.IPNet, i net.Interface) bool {
log(args.VerboseNet, "\t\taddr.(type) = *net.IPNet") log.Println(args.VerboseNet, "\t\taddr.(type) = *net.IPNet")
log(args.VerboseNet, "\t\taddr.(type) =", ip) log.Println(args.VerboseNet, "\t\taddr.(type) =", ip)
var realip string var realip string
realip = ip.IP.String() realip = ip.IP.String()
val, ok := me.ipmap[realip] val, ok := me.ipmap[realip]
if ok { if ok {
log(args.VerboseNet, val.ipnet.IP.String(), "is already a defined IP address") log.Println(args.VerboseNet, val.ipnet.IP.String(), "is already a defined IP address")
me.ipmap[realip].gone = false me.ipmap[realip].gone = false
return false return false
} }
@ -174,14 +175,14 @@ func checkIP(ip *net.IPNet, i net.Interface) bool {
} }
} }
if (IsReal(&ip.IP)) { if (IsReal(&ip.IP)) {
log("\tIP is Real ", t, i.Index, i.Name, realip) log.Println("\tIP is Real ", t, i.Index, i.Name, realip)
} else { } else {
log("\tIP is not Real", t, i.Index, i.Name, realip) log.Println("\tIP is not Real", t, i.Index, i.Name, realip)
} }
log(args.VerboseNet, "\t\tIP is IsPrivate() =", ip.IP.IsPrivate()) log.Println(args.VerboseNet, "\t\tIP is IsPrivate() =", ip.IP.IsPrivate())
log(args.VerboseNet, "\t\tIP is IsLoopback() =", ip.IP.IsLoopback()) log.Println(args.VerboseNet, "\t\tIP is IsLoopback() =", ip.IP.IsLoopback())
log(args.VerboseNet, "\t\tIP is IsLinkLocalUnicast() =", ip.IP.IsLinkLocalUnicast()) log.Println(args.VerboseNet, "\t\tIP is IsLinkLocalUnicast() =", ip.IP.IsLinkLocalUnicast())
// log("HERE HERE", "realip =", realip, "me.ip[realip]=", me.ipmap[realip]) // log.Println("HERE HERE", "realip =", realip, "me.ip[realip]=", me.ipmap[realip])
return true return true
} }
@ -189,25 +190,25 @@ func scanInterfaces() {
me.changed = false me.changed = false
ifaces, _ := net.Interfaces() ifaces, _ := net.Interfaces()
// me.ifnew = ifaces // me.ifnew = ifaces
log(DEBUGNET, SPEW, ifaces) log.Println(DEBUGNET, SPEW, ifaces)
for _, i := range ifaces { for _, i := range ifaces {
addrs, _ := i.Addrs() addrs, _ := i.Addrs()
// log("range ifaces = ", i) // log.Println("range ifaces = ", i)
checkInterface(i) checkInterface(i)
log(args.VerboseNet, "*net.Interface.Name = ", i.Name, i.Index) log.Println(args.VerboseNet, "*net.Interface.Name = ", i.Name, i.Index)
log(args.VerboseNet, SPEW, i) log.Println(args.VerboseNet, SPEW, i)
log(DEBUGNET, SPEW, addrs) log.Println(DEBUGNET, SPEW, addrs)
for _, addr := range addrs { for _, addr := range addrs {
log(DEBUGNET, "\taddr =", addr) log.Println(DEBUGNET, "\taddr =", addr)
log(DEBUGNET, SPEW, addrs) log.Println(DEBUGNET, SPEW, addrs)
ips, _ := net.LookupIP(addr.String()) ips, _ := net.LookupIP(addr.String())
log(DEBUGNET, "\tLookupIP(addr) =", ips) log.Println(DEBUGNET, "\tLookupIP(addr) =", ips)
switch v := addr.(type) { switch v := addr.(type) {
case *net.IPNet: case *net.IPNet:
checkIP(v, i) checkIP(v, i)
// log("\t\tIP is () =", ip.()) // log.Println("\t\tIP is () =", ip.())
default: default:
log(DEBUGNET, "\t\taddr.(type) = NO IDEA WHAT TO DO HERE v =", v) log.Println(DEBUGNET, "\t\taddr.(type) = NO IDEA WHAT TO DO HERE v =", v)
} }
} }
} }
@ -217,12 +218,12 @@ func scanInterfaces() {
for s, t := range me.ipmap { for s, t := range me.ipmap {
if (t.ipv4) { if (t.ipv4) {
all4 += s + "\n" all4 += s + "\n"
log("IPv4 =", s) log.Println("IPv4 =", s)
} else if (t.ipv6) { } else if (t.ipv6) {
all6 += s + "\n" all6 += s + "\n"
log("IPv6 =", s) log.Println("IPv6 =", s)
} else { } else {
log("???? =", s) log.Println("???? =", s)
} }
} }
all4 = strings.TrimSpace(all4) all4 = strings.TrimSpace(all4)
@ -235,7 +236,7 @@ func scanInterfaces() {
func deleteChanges() { func deleteChanges() {
for i, t := range me.ifmap { for i, t := range me.ifmap {
if (t.gone) { if (t.gone) {
log("DELETE int =", i, "name =", t.name, t.iface) log.Println("DELETE int =", i, "name =", t.name, t.iface)
delete(me.ifmap, i) delete(me.ifmap, i)
me.changed = true me.changed = true
} }
@ -243,10 +244,10 @@ func deleteChanges() {
} }
for s, t := range me.ipmap { for s, t := range me.ipmap {
if (t.gone) { if (t.gone) {
log("DELETE name =", s, "IPv4 =", t.ipv4) log.Println("DELETE name =", s, "IPv4 =", t.ipv4)
log("DELETE name =", s, "IPv6 =", t.ipv6) log.Println("DELETE name =", s, "IPv6 =", t.ipv6)
log("DELETE name =", s, "iface =", t.iface) log.Println("DELETE name =", s, "iface =", t.iface)
log("DELETE name =", s, "ip =", t.ip) log.Println("DELETE name =", s, "ip =", t.ip)
delete(me.ipmap, s) delete(me.ipmap, s)
me.changed = true me.changed = true
} }

View File

@ -6,6 +6,7 @@
package main package main
import ( import (
"log"
"os" "os"
) )
@ -16,17 +17,17 @@ import (
func nsupdate() { func nsupdate() {
var tsigSecret string var tsigSecret string
log(true, "nsupdate() START") log.Println(true, "nsupdate() START")
cmd := "go-nsupdate --tsig-algorithm=hmac-sha512" cmd := "go-nsupdate --tsig-algorithm=hmac-sha512"
tsigSecret = os.Getenv("TIG_SECRET") tsigSecret = os.Getenv("TIG_SECRET")
cmd += " --tig-secret=\"" + tsigSecret + "\"" cmd += " --tig-secret=\"" + tsigSecret + "\""
cmd += " -i wlo1 " + me.hostname cmd += " -i wlo1 " + me.hostname
log(true, "nsupdate() RUN:", cmd) log.Println(true, "nsupdate() RUN:", cmd)
for s, t := range me.ipmap { for s, t := range me.ipmap {
if (t.IsReal()) { if (t.IsReal()) {
if (t.ipv6) { if (t.ipv6) {
log(true, "nsupdate() found real AAAA =", s, "on iface", t.iface.Name) log.Println(true, "nsupdate() found real AAAA =", s, "on iface", t.iface.Name)
} }
} }
} }

View File

@ -1,6 +1,7 @@
package main package main
import ( import (
"log"
"github.com/jsimonetti/rtnetlink" "github.com/jsimonetti/rtnetlink"
) )
@ -9,7 +10,7 @@ func Example_listLink() {
// Dial a connection to the rtnetlink socket // Dial a connection to the rtnetlink socket
conn, err := rtnetlink.Dial(nil) conn, err := rtnetlink.Dial(nil)
if err != nil { if err != nil {
log(logError, "Example_listLink() failed", err) log.Println(logError, "Example_listLink() failed", err)
return return
} }
defer conn.Close() defer conn.Close()
@ -17,9 +18,9 @@ func Example_listLink() {
// Request a list of interfaces // Request a list of interfaces
msg, err := conn.Link.List() msg, err := conn.Link.List()
if err != nil { if err != nil {
log(err) log.Println(err)
} }
log("%#v", msg) log.Println("%#v", msg)
log(SPEW, msg) log.Println(SPEW, msg)
} }

View File

@ -30,6 +30,7 @@ type Host struct {
DnsAAAA *gui.Node // the actual DNS AAAA results DnsAAAA *gui.Node // the actual DNS AAAA results
DnsA *gui.Node // the actual DNS A results (ignore for status since mostly never happens?) DnsA *gui.Node // the actual DNS A results (ignore for status since mostly never happens?)
DnsStatus *gui.Node // the current state of DNS DnsStatus *gui.Node // the current state of DNS
fix *gui.Node // button for the user to click
} }
type IPtype struct { type IPtype struct {

View File

@ -5,6 +5,7 @@
package main package main
import ( import (
"log"
"os" "os"
"os/exec" "os/exec"
"net" "net"
@ -22,7 +23,7 @@ func Escalate() {
cmd.Stderr = os.Stderr cmd.Stderr = os.Stderr
err := cmd.Run() err := cmd.Run()
if err != nil { if err != nil {
log(logError, "exit in Escalate()") log.Println(logError, "exit in Escalate()")
exit(err) exit(err)
} }
} }
@ -37,17 +38,17 @@ func DumpPublicDNSZone(zone string) {
panic(err) panic(err)
} }
for _, entry := range entries { for _, entry := range entries {
log(entry) log.Println(entry)
} }
} }
func dumpIPs(host string) { func dumpIPs(host string) {
ips, err := net.LookupIP(host) ips, err := net.LookupIP(host)
if err != nil { if err != nil {
log(logError, "dumpIPs() failed:", err) log.Println(logError, "dumpIPs() failed:", err)
} }
for _, ip := range ips { for _, ip := range ips {
log(host, ip) log.Println(host, ip)
} }
} }