Compare commits
No commits in common. "bbf96ee7fa67a6d50ea1d1b3a23a3f44f136a30e" and "c16bb5b088ce71fd6d032228b505cb5e133fcb3c" have entirely different histories.
bbf96ee7fa
...
c16bb5b088
|
@ -2,4 +2,3 @@ control-panel-dns
|
|||
/files/*
|
||||
/*.deb
|
||||
*.swp
|
||||
/plugins/*
|
||||
|
|
12
Makefile
12
Makefile
|
@ -1,16 +1,10 @@
|
|||
.PHONY: debian
|
||||
|
||||
run: build
|
||||
# ./control-panel-dns >/tmp/witgui.log.stderr 2>&1
|
||||
./control-panel-dns
|
||||
./control-panel-dns >/tmp/witgui.log.stderr 2>&1
|
||||
|
||||
install:
|
||||
go install -v go.wit.com/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
|
||||
./control-panel-dns --verbose --verbose-net --gui-debug
|
||||
|
||||
|
@ -24,8 +18,6 @@ build-release:
|
|||
|
||||
build:
|
||||
reset
|
||||
-mkdir -p plugins/
|
||||
-cp ~/go/src/git.wit.org/wit/gui/toolkit/*.so plugins/
|
||||
# GO111MODULE="off" go get -v -x .
|
||||
GO111MODULE="off" go build -v -o control-panel-dns
|
||||
|
||||
|
@ -46,7 +38,7 @@ clean:
|
|||
-rm -rf files/
|
||||
-rm *.deb
|
||||
|
||||
debian:
|
||||
deb:
|
||||
cd debian && make
|
||||
-wit mirrors
|
||||
|
||||
|
|
88
args.go
88
args.go
|
@ -1,96 +1,26 @@
|
|||
// This creates a simple hello world window
|
||||
package main
|
||||
|
||||
/*
|
||||
this parses the command line arguements
|
||||
*/
|
||||
|
||||
import (
|
||||
"log"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"strconv"
|
||||
arg "github.com/alexflint/go-arg"
|
||||
"git.wit.org/wit/gui"
|
||||
// log "git.wit.org/wit/gui/log"
|
||||
"git.wit.org/jcarr/dnssecsocket"
|
||||
)
|
||||
|
||||
|
||||
var args struct {
|
||||
type LogOptions struct {
|
||||
Verbose bool
|
||||
VerboseNet bool `arg:"--verbose-net" help:"debug your local OS network settings"`
|
||||
VerboseDNS bool `arg:"--verbose-dns" help:"debug your dns settings"`
|
||||
LogFile string `help:"write all output to a file"`
|
||||
// User string `arg:"env:USER"`
|
||||
Display string `arg:"env:DISPLAY"`
|
||||
}
|
||||
|
||||
Foo string
|
||||
Bar bool
|
||||
User string `arg:"env:USER"`
|
||||
Demo bool `help:"run a demo"`
|
||||
var args struct {
|
||||
LogOptions
|
||||
dnssecsocket.Args
|
||||
gui.GuiArgs
|
||||
// log.LogArgs
|
||||
}
|
||||
|
||||
func init() {
|
||||
arg.MustParse(&args)
|
||||
fmt.Println(args.Foo, args.Bar, args.User)
|
||||
|
||||
if (args.Gui != "") {
|
||||
gui.GuiArg.Gui = args.Gui
|
||||
}
|
||||
log.Println(true, "INIT() args.GuiArg.Gui =", gui.GuiArg.Gui)
|
||||
|
||||
Set(&me, "default")
|
||||
log.Println("init() me.artificialSleep =", me.artificialSleep)
|
||||
log.Println("init() me.artificialS =", me.artificialS)
|
||||
me.artificialSleep = 2.3
|
||||
log.Println("init() me.artificialSleep =", me.artificialSleep)
|
||||
sleep(me.artificialSleep)
|
||||
}
|
||||
|
||||
func Set(ptr interface{}, tag string) error {
|
||||
if reflect.TypeOf(ptr).Kind() != reflect.Ptr {
|
||||
log.Println(logError, "Set() Not a pointer", ptr, "with tag =", tag)
|
||||
return fmt.Errorf("Not a pointer")
|
||||
}
|
||||
|
||||
v := reflect.ValueOf(ptr).Elem()
|
||||
t := v.Type()
|
||||
|
||||
for i := 0; i < t.NumField(); i++ {
|
||||
defaultVal := t.Field(i).Tag.Get(tag)
|
||||
name := t.Field(i).Name
|
||||
// log("Set() try name =", name, "defaultVal =", defaultVal)
|
||||
setField(v.Field(i), defaultVal, name)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func setField(field reflect.Value, defaultVal string, name string) error {
|
||||
|
||||
if !field.CanSet() {
|
||||
// log("setField() Can't set value", field, defaultVal)
|
||||
return fmt.Errorf("Can't set value\n")
|
||||
} else {
|
||||
log.Println("setField() Can set value", name, defaultVal)
|
||||
}
|
||||
|
||||
switch field.Kind() {
|
||||
case reflect.Int:
|
||||
val, _ := strconv.Atoi(defaultVal)
|
||||
field.Set(reflect.ValueOf(int(val)).Convert(field.Type()))
|
||||
case reflect.Float64:
|
||||
val, _ := strconv.ParseFloat(defaultVal, 64)
|
||||
field.Set(reflect.ValueOf(float64(val)).Convert(field.Type()))
|
||||
case reflect.String:
|
||||
field.Set(reflect.ValueOf(defaultVal).Convert(field.Type()))
|
||||
case reflect.Bool:
|
||||
if defaultVal == "true" {
|
||||
field.Set(reflect.ValueOf(true))
|
||||
} else {
|
||||
field.Set(reflect.ValueOf(false))
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
func parsedown () {
|
||||
dnssecsocket.Parse(args.VerboseDnssec)
|
||||
}
|
||||
|
|
5
bash.go
5
bash.go
|
@ -2,7 +2,6 @@ package main
|
|||
|
||||
import (
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
"os/signal"
|
||||
|
@ -30,7 +29,7 @@ func test() error {
|
|||
go func() {
|
||||
for range ch {
|
||||
if err := pty.InheritSize(os.Stdin, ptmx); err != nil {
|
||||
log.Println("error resizing pty: %s", err)
|
||||
log("error resizing pty: %s", err)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
@ -54,7 +53,7 @@ func test() error {
|
|||
|
||||
func mainBash() {
|
||||
if err := test(); err != nil {
|
||||
log.Println(logError, "exit in mainBash()")
|
||||
log(logError, "exit in mainBash()")
|
||||
exit(err)
|
||||
}
|
||||
}
|
||||
|
|
19
dns.go
19
dns.go
|
@ -5,7 +5,6 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"net"
|
||||
)
|
||||
|
||||
|
@ -24,16 +23,16 @@ func (h *Host) verifyETC() bool {
|
|||
func (h *Host) updateIPs(host string) {
|
||||
ips, err := net.LookupIP(host)
|
||||
if err != nil {
|
||||
log.Println(logError, "updateIPs failed", err)
|
||||
log(logError, "updateIPs failed", err)
|
||||
}
|
||||
for _, ip := range ips {
|
||||
log.Println(host, ip)
|
||||
log(host, ip)
|
||||
}
|
||||
}
|
||||
|
||||
func (h *Host) setIPv4(ipv4s map[string]*IPtype) {
|
||||
for ip, t := range ipv4s {
|
||||
log.Println("IPv4", ip, t)
|
||||
log("IPv4", ip, t)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -48,11 +47,11 @@ func (h *Host) checkDNS() {
|
|||
ipt = "IPv6"
|
||||
}
|
||||
if (! t.IsReal()) {
|
||||
log.Println(args.VerboseDNS, "\tIP is not Real", ipt, i.Index, i.Name, s)
|
||||
log(args.VerboseDNS, "\tIP is not Real", ipt, i.Index, i.Name, s)
|
||||
continue
|
||||
}
|
||||
|
||||
log.Println(args.VerboseDNS, "\tIP is Real ", ipt, i.Index, i.Name, s)
|
||||
log(args.VerboseDNS, "\tIP is Real ", ipt, i.Index, i.Name, s)
|
||||
if (t.ipv6) {
|
||||
ip6 = true
|
||||
} else {
|
||||
|
@ -61,13 +60,13 @@ func (h *Host) checkDNS() {
|
|||
}
|
||||
|
||||
if (ip4 == true) {
|
||||
log.Println(args.VerboseDNS, "IPv4 should work. Wow. You actually have a real IPv4 address")
|
||||
log(args.VerboseDNS, "IPv4 should work. Wow. You actually have a real IPv4 address")
|
||||
} else {
|
||||
log.Println(args.VerboseDNS, "IPv4 is broken. (be nice and setup ipv4-only.wit.com)")
|
||||
log(args.VerboseDNS, "IPv4 is broken. (be nice and setup ipv4-only.wit.com)")
|
||||
}
|
||||
if (ip6 == true) {
|
||||
log.Println(args.VerboseDNS, "IPv6 should be working. Need to test it here.")
|
||||
log(args.VerboseDNS, "IPv6 should be working. Need to test it here.")
|
||||
} else {
|
||||
log.Println(args.VerboseDNS, "IPv6 is broken. Need to fix it here.")
|
||||
log(args.VerboseDNS, "IPv6 is broken. Need to fix it here.")
|
||||
}
|
||||
}
|
||||
|
|
15
fsnotify.go
15
fsnotify.go
|
@ -3,7 +3,6 @@ package main
|
|||
// Watches for changes to a directory. Works cross-platform
|
||||
|
||||
import (
|
||||
"log"
|
||||
"github.com/fsnotify/fsnotify"
|
||||
)
|
||||
|
||||
|
@ -14,7 +13,7 @@ func watchSysClassNet() {
|
|||
// Create new watcher.
|
||||
watcher, err := fsnotify.NewWatcher()
|
||||
if err != nil {
|
||||
log.Println(logError, "watchSysClassNet() failed:", err)
|
||||
log(logError, "watchSysClassNet() failed:", err)
|
||||
return
|
||||
}
|
||||
defer watcher.Close()
|
||||
|
@ -27,15 +26,15 @@ func watchSysClassNet() {
|
|||
if !ok {
|
||||
return
|
||||
}
|
||||
log.Println("event:", event)
|
||||
log("event:", event)
|
||||
if event.Has(fsnotify.Write) {
|
||||
log.Println("modified file:", event.Name)
|
||||
log("modified file:", event.Name)
|
||||
}
|
||||
case err, ok := <-watcher.Errors:
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
log.Println("error:", err)
|
||||
log("error:", err)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
@ -43,7 +42,7 @@ func watchSysClassNet() {
|
|||
// Add a path.
|
||||
err = watcher.Add("/tmp")
|
||||
if err != nil {
|
||||
log.Println(logError, "watchSysClassNet() watcher.Add() failed:", err)
|
||||
log(logError, "watchSysClassNet() watcher.Add() failed:", err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -66,12 +65,12 @@ func fsnotifyNetworkInterfaceChanges() error {
|
|||
for {
|
||||
select {
|
||||
case event := <-watcher.Events:
|
||||
log.Println("fsnotifyNetworkInterfaceChanges() event =", event)
|
||||
log("fsnotifyNetworkInterfaceChanges() event =", event)
|
||||
if event.Op&fsnotify.Create == fsnotify.Create {
|
||||
// Do something on network interface creation
|
||||
}
|
||||
case err := <-watcher.Errors:
|
||||
log.Println("fsnotifyNetworkInterfaceChanges() event err =", err)
|
||||
log("fsnotifyNetworkInterfaceChanges() event err =", err)
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
|
135
gui.go
135
gui.go
|
@ -2,7 +2,6 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/user"
|
||||
|
@ -16,22 +15,24 @@ import (
|
|||
|
||||
// This setups up the dns control panel window
|
||||
func setupControlPanelWindow() {
|
||||
// me.window = myGui.New2().Window("DNS and IPv6 Control Panel").Standard()
|
||||
me.window = myGui.NewWindow("DNS and IPv6 Control Panel").Standard()
|
||||
me.window.Dump()
|
||||
me.window = myGui.New2().Window("DNS and IPv6 Control Panel").Standard()
|
||||
me.window.Dump(true)
|
||||
|
||||
sleep(me.artificialSleep)
|
||||
dnsTab("DNS")
|
||||
debugTab("Debug")
|
||||
sleep(1)
|
||||
addDNSTab("DNS")
|
||||
|
||||
if (args.GuiDebug) {
|
||||
gui.DebugWindow()
|
||||
}
|
||||
gui.ShowDebugValues()
|
||||
}
|
||||
|
||||
func debugTab(title string) {
|
||||
func addDNSTab(title string) {
|
||||
var g2 *gui.Node
|
||||
|
||||
tab := me.window.NewTab(title)
|
||||
me.tab = me.window.NewTab(title)
|
||||
|
||||
g2 = tab.NewGroup("Real Stuff")
|
||||
g2 = me.tab.NewGroup("Real Stuff")
|
||||
|
||||
g2.NewButton("gui.DebugWindow()", func () {
|
||||
gui.DebugWindow()
|
||||
|
@ -40,14 +41,15 @@ func debugTab(title string) {
|
|||
g2.NewButton("Load 'gocui'", func () {
|
||||
// this set the xterm and mate-terminal window title. maybe works generally?
|
||||
fmt.Println("\033]0;" + title + "blah \007")
|
||||
myGui.LoadToolkit("gocui")
|
||||
gui.StartS("gocui")
|
||||
gui.Redraw("gocui")
|
||||
})
|
||||
|
||||
g2.NewButton("Network Interfaces", func () {
|
||||
for i, t := range me.ifmap {
|
||||
log.Println("name =", t.iface.Name)
|
||||
log.Println("int =", i, "name =", t.name, t.iface)
|
||||
log.Println("iface = " + t.iface.Name)
|
||||
log("name =", t.iface.Name)
|
||||
log("int =", i, "name =", t.name, t.iface)
|
||||
log("iface = " + t.iface.Name)
|
||||
}
|
||||
})
|
||||
g2.NewButton("Hostname", func () {
|
||||
|
@ -57,30 +59,25 @@ func debugTab(title string) {
|
|||
var aaaa []string
|
||||
aaaa = realAAAA()
|
||||
for _, s := range aaaa {
|
||||
log.Println("my actual AAAA = ", s)
|
||||
log("my actual AAAA = ", s)
|
||||
}
|
||||
})
|
||||
|
||||
g2.NewButton("Update DNS", func () {
|
||||
log.Println("updateDNS()")
|
||||
updateDNS()
|
||||
})
|
||||
|
||||
g2.NewButton("checkDNS()", func () {
|
||||
checkDNS()
|
||||
})
|
||||
g2.NewButton("os.User()", func () {
|
||||
user, _ := user.Current()
|
||||
spew.Dump(user)
|
||||
log.Println("os.Getuid =", user.Username, os.Getuid())
|
||||
log("os.Getuid =", user.Username, os.Getuid())
|
||||
if (me.uid != nil) {
|
||||
me.uid.SetText(user.Username + " (" + strconv.Itoa(os.Getuid()) + ")")
|
||||
}
|
||||
})
|
||||
g2.NewButton("dig +trace", func () {
|
||||
o := shell.Run("dig +trace +noadditional DS " + me.hostname + " @8.8.8.8")
|
||||
log.Println(o)
|
||||
// log.Println(o)
|
||||
log(o)
|
||||
// log(o)
|
||||
})
|
||||
g2.NewButton("Example_listLink()", func () {
|
||||
Example_listLink()
|
||||
|
@ -93,39 +90,30 @@ func debugTab(title string) {
|
|||
if err != nil {
|
||||
return
|
||||
}
|
||||
log.Println("host =", host)
|
||||
log("host =", host)
|
||||
})
|
||||
g2.NewButton("DumpPublicDNSZone(apple.com)", func () {
|
||||
DumpPublicDNSZone("apple.com")
|
||||
dumpIPs("www.apple.com")
|
||||
})
|
||||
|
||||
g2.NewLabel("control panel TTL (in tenths of seconds)")
|
||||
ttl := g2.NewSlider("dnsTTL", 1, 100)
|
||||
ttl.Set(me.dnsTTL * 10)
|
||||
ttl.Custom = func () {
|
||||
me.dnsTTL = ttl.I / 10
|
||||
log.Println("dnsTTL =", me.dnsTTL)
|
||||
}
|
||||
nsupdateGroup(me.tab)
|
||||
|
||||
g2.NewLabel("control panel loop delay (in tenths of seconds)")
|
||||
ttl2 := g2.NewSlider("dnsTTL", 1, 100)
|
||||
ttl2.Set(me.dnsTTLsleep)
|
||||
ttl2.Custom = func () {
|
||||
me.dnsTTLsleep = float64(ttl2.I) / 10
|
||||
log.Println("dnsTTLsleep =", me.dnsTTLsleep)
|
||||
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) {
|
||||
log.Println("You can Do exit() things here")
|
||||
log("You can Do exit() things here")
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
func dnsTab(title string) {
|
||||
tab := me.window.NewTab(title)
|
||||
|
||||
g := tab.NewGroup("dns update")
|
||||
func nsupdateGroup(w *gui.Node) {
|
||||
g := w.NewGroup("dns update")
|
||||
|
||||
grid := g.NewGrid("gridnuts", 2, 2)
|
||||
|
||||
|
@ -155,43 +143,15 @@ func dnsTab(title string) {
|
|||
grid.NewLabel("DNS Status =")
|
||||
me.DnsStatus = grid.NewLabel("unknown")
|
||||
|
||||
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()
|
||||
g.NewButton("Update DNS", func () {
|
||||
log("updateDNS()")
|
||||
updateDNS()
|
||||
me.tab.Margin()
|
||||
me.tab.Pad()
|
||||
grid.Pad()
|
||||
})
|
||||
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")
|
||||
}
|
||||
|
||||
/*
|
||||
var outJunk string
|
||||
func output(s string, a bool) {
|
||||
if (a) {
|
||||
|
@ -200,9 +160,8 @@ func output(s string, a bool) {
|
|||
outJunk = s
|
||||
}
|
||||
me.output.SetText(outJunk)
|
||||
log.Println(outJunk)
|
||||
log(outJunk)
|
||||
}
|
||||
*/
|
||||
|
||||
func updateDNS() {
|
||||
var aaaa []string
|
||||
|
@ -211,20 +170,20 @@ func updateDNS() {
|
|||
h = "unknown.lab.wit.org"
|
||||
// h = "hpdevone.lab.wit.org"
|
||||
}
|
||||
log.Println("dnsAAAA()()")
|
||||
log("dnsAAAA()()")
|
||||
aaaa = dnsAAAA(h)
|
||||
log.Println("dnsAAAA()()")
|
||||
log.Println(SPEW, me)
|
||||
log("dnsAAAA()()")
|
||||
log(SPEW, me)
|
||||
if (aaaa == nil) {
|
||||
log.Println("There are no DNS AAAA records for hostname: ", h)
|
||||
log("There are no DNS AAAA records for hostname: ", h)
|
||||
}
|
||||
var broken int = 0
|
||||
var all string
|
||||
for _, s := range aaaa {
|
||||
log.Println("host", h, "DNS AAAA =", s)
|
||||
log("host", h, "DNS AAAA =", s)
|
||||
all += s + "\n"
|
||||
if ( me.ipmap[s] == nil) {
|
||||
log.Println("THIS IS THE WRONG AAAA DNS ENTRY: host", h, "DNS AAAA =", s)
|
||||
log("THIS IS THE WRONG AAAA DNS ENTRY: host", h, "DNS AAAA =", s)
|
||||
broken = 2
|
||||
} else {
|
||||
if (broken == 0) {
|
||||
|
@ -238,16 +197,14 @@ func updateDNS() {
|
|||
me.DnsStatus.SetText("WORKING")
|
||||
} else {
|
||||
me.DnsStatus.SetText("BROKEN")
|
||||
me.fix.Enable()
|
||||
log.Println("Need to run go-nsupdate here")
|
||||
nsupdate()
|
||||
log("Need to run go-nsupdate here")
|
||||
}
|
||||
|
||||
user, _ := user.Current()
|
||||
spew.Dump(user)
|
||||
log.Println("os.Getuid =", user.Username, os.Getuid())
|
||||
log("os.Getuid =", user.Username, os.Getuid())
|
||||
if (me.uid != nil) {
|
||||
me.uid.SetText(user.Username + " (" + strconv.Itoa(os.Getuid()) + ")")
|
||||
}
|
||||
log.Println("updateDNS() END")
|
||||
log("updateDNS() END")
|
||||
}
|
||||
|
|
36
hostname.go
36
hostname.go
|
@ -5,10 +5,7 @@
|
|||
|
||||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"git.wit.org/wit/shell"
|
||||
)
|
||||
// import "net"
|
||||
|
||||
// will try to get this hosts FQDN
|
||||
import "github.com/Showmax/go-fqdn"
|
||||
|
@ -24,7 +21,7 @@ func getHostname() {
|
|||
var s string = "gui.Label == nil"
|
||||
s, err = fqdn.FqdnHostname()
|
||||
if (err != nil) {
|
||||
log.Println("FQDN hostname error =", err)
|
||||
log("FQDN hostname error =", err)
|
||||
return
|
||||
}
|
||||
if (me.fqdn != nil) {
|
||||
|
@ -34,40 +31,19 @@ func getHostname() {
|
|||
me.changed = true
|
||||
}
|
||||
}
|
||||
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.Chomp(shell.Cat("/etc/hostname"))
|
||||
log.Println("hostname =", hostname)
|
||||
|
||||
hs := run("hostname -s")
|
||||
dn := run("domainname")
|
||||
log.Println("hostname short =", hs, "domainname =", dn)
|
||||
|
||||
tmp := hs + "." + dn
|
||||
if (hostname == tmp) {
|
||||
log.Println("hostname seems to be good", hostname)
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
log("FQDN =", s)
|
||||
}
|
||||
|
||||
func dnsAAAA(s string) []string {
|
||||
var aaaa []string
|
||||
// lookup the IP address from DNS
|
||||
rrset := dnssecsocket.Dnstrace(s, "AAAA")
|
||||
log.Println(args.VerboseDNS, SPEW, rrset)
|
||||
log(args.VerboseDNS, SPEW, rrset)
|
||||
for i, rr := range rrset {
|
||||
log.Println(args.VerboseDNS, "r.Answer =", i, rr)
|
||||
log(args.VerboseDNS, "r.Answer =", i, rr)
|
||||
ipaddr := dns.Field(rr, 1)
|
||||
aaaa = append(aaaa, ipaddr)
|
||||
}
|
||||
log.Println(args.VerboseDNS, "aaaa =", aaaa)
|
||||
log(args.VerboseDNS, "aaaa =", aaaa)
|
||||
return aaaa
|
||||
}
|
||||
|
|
5
log.go
5
log.go
|
@ -1,7 +1,6 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
witlog "git.wit.org/wit/gui/log"
|
||||
)
|
||||
|
||||
|
@ -16,18 +15,16 @@ var SPEW witlog.Spewt
|
|||
|
||||
// var log interface{}
|
||||
|
||||
/*
|
||||
func log(a ...any) {
|
||||
witlog.Where = "wit/gui"
|
||||
witlog.Log(a...)
|
||||
}
|
||||
*/
|
||||
|
||||
func sleep(a ...any) {
|
||||
witlog.Sleep(a...)
|
||||
}
|
||||
|
||||
func exit(a ...any) {
|
||||
log.Println(logError, "got to log() exit")
|
||||
log(logError, "got to log() exit")
|
||||
witlog.Exit(a...)
|
||||
}
|
||||
|
|
63
main.go
63
main.go
|
@ -5,42 +5,48 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"strconv"
|
||||
"runtime"
|
||||
"time"
|
||||
"embed"
|
||||
arg "github.com/alexflint/go-arg"
|
||||
"git.wit.org/wit/gui"
|
||||
)
|
||||
|
||||
var p *arg.Parser
|
||||
var myGui *gui.Node
|
||||
|
||||
//go:embed plugins/*.so
|
||||
var resToolkit embed.FS
|
||||
|
||||
func main() {
|
||||
// parsedown()
|
||||
p = arg.MustParse(&args)
|
||||
parsedown()
|
||||
|
||||
// initialize the maps to track IP addresses and network interfaces
|
||||
me.ipmap = make(map[string]*IPtype)
|
||||
me.dnsmap = make(map[string]*IPtype)
|
||||
me.ifmap = make(map[int]*IFtype)
|
||||
me.dnsTTL = 2 // 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?
|
||||
|
||||
// will set all debugging flags
|
||||
|
||||
log()
|
||||
log(true, "this is true")
|
||||
log(false, "this is false")
|
||||
sleep(.4)
|
||||
sleep(.3)
|
||||
sleep(.2)
|
||||
sleep("done scanning net")
|
||||
|
||||
// Example_listLink()
|
||||
|
||||
log("Toolkit = ", args.Toolkit)
|
||||
// gui.InitPlugins([]string{"andlabs"})
|
||||
// gui.SetDebug(true)
|
||||
|
||||
// myGui = gui.New().InitEmbed(resToolkit).LoadToolkit("gocui")
|
||||
myGui = gui.New().Default()
|
||||
sleep(me.artificialSleep)
|
||||
// myGui = gui.Main(initGUI)
|
||||
myGui = gui.Start()
|
||||
sleep(1)
|
||||
setupControlPanelWindow()
|
||||
sleep(me.artificialSleep)
|
||||
if (args.GuiDebug) {
|
||||
gui.DebugWindow()
|
||||
}
|
||||
gui.ShowDebugValues()
|
||||
|
||||
// forever monitor for network and dns changes
|
||||
sleep(1)
|
||||
myGui.LoadPlugin("gocui")
|
||||
// gui.Redraw("gocui")
|
||||
sleep(1)
|
||||
checkNetworkChanges()
|
||||
}
|
||||
|
||||
|
@ -49,43 +55,46 @@ func main() {
|
|||
*/
|
||||
func checkNetworkChanges() {
|
||||
var ttl int = 0
|
||||
var ttlsleep int = 5
|
||||
for {
|
||||
sleep(me.dnsTTLsleep)
|
||||
sleep(ttlsleep)
|
||||
ttl -= 1
|
||||
if (ttl < 0) {
|
||||
if (runtime.GOOS == "linux") {
|
||||
dnsTTL()
|
||||
} else {
|
||||
log.Println("Windows and MacOS don't work yet")
|
||||
log("Windows and MacOS don't work yet")
|
||||
}
|
||||
ttl = me.dnsTTL
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// This checks for changes to the network settings
|
||||
// and verifies that DNS is working or not working
|
||||
// Run this every once and a while
|
||||
func dnsTTL() {
|
||||
me.changed = false
|
||||
log.Println("FQDN =", me.fqdn.GetText())
|
||||
log("FQDN =", me.fqdn.GetText())
|
||||
getHostname()
|
||||
scanInterfaces()
|
||||
for i, t := range me.ifmap {
|
||||
log.Println(strconv.Itoa(i) + " iface = " + t.iface.Name)
|
||||
log(strconv.Itoa(i) + " iface = " + t.iface.Name)
|
||||
}
|
||||
|
||||
var aaaa []string
|
||||
aaaa = realAAAA()
|
||||
var all string
|
||||
for _, s := range aaaa {
|
||||
log.Println("my actual AAAA = ",s)
|
||||
log("my actual AAAA = ",s)
|
||||
all += s + "\n"
|
||||
}
|
||||
// me.IPv6.SetText(all)
|
||||
|
||||
if (me.changed) {
|
||||
stamp := time.Now().Format("2006/01/02 15:04:05")
|
||||
log.Println(logError, "Network things changed on", stamp)
|
||||
s := stamp + " Network things changed"
|
||||
log(logError, "Network things changed on", stamp)
|
||||
updateDNS()
|
||||
me.output.SetText(s)
|
||||
|
||||
}
|
||||
}
|
||||
|
|
86
net.go
86
net.go
|
@ -2,9 +2,9 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"net"
|
||||
"strings"
|
||||
// "git.wit.org/wit/gui"
|
||||
)
|
||||
|
||||
var DEBUGNET bool = false
|
||||
|
@ -18,21 +18,21 @@ func watchNetworkInterfaces() {
|
|||
// Set up a notification channel
|
||||
notification := make(chan net.Interface)
|
||||
|
||||
log.Println(DEBUGNET, "watchNet()")
|
||||
log(DEBUGNET, "watchNet()")
|
||||
// Start goroutine to watch for changes
|
||||
go func() {
|
||||
log.Println(DEBUGNET, "watchNet() func")
|
||||
log(DEBUGNET, "watchNet() func")
|
||||
for {
|
||||
log.Println(DEBUGNET, "forever loop start")
|
||||
log(DEBUGNET, "forever loop start")
|
||||
// Check for changes in each interface
|
||||
for _, i := range interfaces {
|
||||
log.Println(DEBUGNET, "something on i =", i)
|
||||
log(DEBUGNET, "something on i =", i)
|
||||
if status := i.Flags & net.FlagUp; status != 0 {
|
||||
notification <- i
|
||||
log.Println(DEBUGNET, "something on i =", i)
|
||||
log(DEBUGNET, "something on i =", i)
|
||||
}
|
||||
}
|
||||
log.Println(DEBUGNET, "forever loop end")
|
||||
log(DEBUGNET, "forever loop end")
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
@ -44,20 +44,20 @@ func IsIPv6(address string) bool {
|
|||
|
||||
func (t *IPtype) IsReal() bool {
|
||||
if (t.ip.IsPrivate() || t.ip.IsLoopback() || t.ip.IsLinkLocalUnicast()) {
|
||||
log.Println(DEBUGNET, "\t\tIP is Real = false")
|
||||
log(DEBUGNET, "\t\tIP is Real = false")
|
||||
return false
|
||||
} else {
|
||||
log.Println(DEBUGNET, "\t\tIP is Real = true")
|
||||
log(DEBUGNET, "\t\tIP is Real = true")
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
func IsReal(ip *net.IP) bool {
|
||||
if (ip.IsPrivate() || ip.IsLoopback() || ip.IsLinkLocalUnicast()) {
|
||||
log.Println(DEBUGNET, "\t\tIP is Real = false")
|
||||
log(DEBUGNET, "\t\tIP is Real = false")
|
||||
return false
|
||||
} else {
|
||||
log.Println(DEBUGNET, "\t\tIP is Real = true")
|
||||
log(DEBUGNET, "\t\tIP is Real = true")
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
@ -74,7 +74,7 @@ func renameInterface(i *net.Interface) {
|
|||
func checkInterface(i net.Interface) {
|
||||
val, ok := me.ifmap[i.Index]
|
||||
if ! ok {
|
||||
log.Println(i.Name, "is a new network interface. The linux kernel index =", i.Index)
|
||||
log(i.Name, "is a new network interface. The linux kernel index =", i.Index)
|
||||
me.ifmap[i.Index] = new(IFtype)
|
||||
me.ifmap[i.Index].gone = false
|
||||
me.ifmap[i.Index].iface = &i
|
||||
|
@ -86,9 +86,9 @@ func checkInterface(i net.Interface) {
|
|||
return
|
||||
}
|
||||
me.ifmap[i.Index].gone = false
|
||||
log.Println(args.VerboseNet, "me.ifmap[i] does exist. Need to compare everything.", i.Index, i.Name, val.iface.Index, val.iface.Name)
|
||||
log(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) {
|
||||
log.Println(val.iface.Name, "has changed to it's name to", i.Name)
|
||||
log(val.iface.Name, "has changed to it's name to", i.Name)
|
||||
me.ifmap[i.Index].iface = &i
|
||||
me.changed = true
|
||||
if (me.Interfaces != nil) {
|
||||
|
@ -126,14 +126,14 @@ func checkDNS() (map[string]*IPtype, map[string]*IPtype) {
|
|||
ipt = "IPv6"
|
||||
}
|
||||
if (t.IsReal()) {
|
||||
log.Println("\tIP is Real ", ipt, i.Index, i.Name, s)
|
||||
log("\tIP is Real ", ipt, i.Index, i.Name, s)
|
||||
if (t.ipv6) {
|
||||
ipv6s[s] = t
|
||||
} else {
|
||||
ipv4s[s] = t
|
||||
}
|
||||
} else {
|
||||
log.Println("\tIP is not Real", ipt, i.Index, i.Name, s)
|
||||
log("\tIP is not Real", ipt, i.Index, i.Name, s)
|
||||
}
|
||||
}
|
||||
return ipv6s, ipv4s
|
||||
|
@ -141,14 +141,14 @@ func checkDNS() (map[string]*IPtype, map[string]*IPtype) {
|
|||
|
||||
// Will figure out if an IP address is new
|
||||
func checkIP(ip *net.IPNet, i net.Interface) bool {
|
||||
log.Println(args.VerboseNet, "\t\taddr.(type) = *net.IPNet")
|
||||
log.Println(args.VerboseNet, "\t\taddr.(type) =", ip)
|
||||
log(args.VerboseNet, "\t\taddr.(type) = *net.IPNet")
|
||||
log(args.VerboseNet, "\t\taddr.(type) =", ip)
|
||||
var realip string
|
||||
realip = ip.IP.String()
|
||||
|
||||
val, ok := me.ipmap[realip]
|
||||
if ok {
|
||||
log.Println(args.VerboseNet, val.ipnet.IP.String(), "is already a defined IP address")
|
||||
log(args.VerboseNet, val.ipnet.IP.String(), "is already a defined IP address")
|
||||
me.ipmap[realip].gone = false
|
||||
return false
|
||||
}
|
||||
|
@ -175,14 +175,14 @@ func checkIP(ip *net.IPNet, i net.Interface) bool {
|
|||
}
|
||||
}
|
||||
if (IsReal(&ip.IP)) {
|
||||
log.Println("\tIP is Real ", t, i.Index, i.Name, realip)
|
||||
log("\tIP is Real ", t, i.Index, i.Name, realip)
|
||||
} else {
|
||||
log.Println("\tIP is not Real", t, i.Index, i.Name, realip)
|
||||
log("\tIP is not Real", t, i.Index, i.Name, realip)
|
||||
}
|
||||
log.Println(args.VerboseNet, "\t\tIP is IsPrivate() =", ip.IP.IsPrivate())
|
||||
log.Println(args.VerboseNet, "\t\tIP is IsLoopback() =", ip.IP.IsLoopback())
|
||||
log.Println(args.VerboseNet, "\t\tIP is IsLinkLocalUnicast() =", ip.IP.IsLinkLocalUnicast())
|
||||
// log.Println("HERE HERE", "realip =", realip, "me.ip[realip]=", me.ipmap[realip])
|
||||
log(args.VerboseNet, "\t\tIP is IsPrivate() =", ip.IP.IsPrivate())
|
||||
log(args.VerboseNet, "\t\tIP is IsLoopback() =", ip.IP.IsLoopback())
|
||||
log(args.VerboseNet, "\t\tIP is IsLinkLocalUnicast() =", ip.IP.IsLinkLocalUnicast())
|
||||
// log("HERE HERE", "realip =", realip, "me.ip[realip]=", me.ipmap[realip])
|
||||
return true
|
||||
}
|
||||
|
||||
|
@ -190,25 +190,25 @@ func scanInterfaces() {
|
|||
me.changed = false
|
||||
ifaces, _ := net.Interfaces()
|
||||
// me.ifnew = ifaces
|
||||
log.Println(DEBUGNET, SPEW, ifaces)
|
||||
log(DEBUGNET, SPEW, ifaces)
|
||||
for _, i := range ifaces {
|
||||
addrs, _ := i.Addrs()
|
||||
// log.Println("range ifaces = ", i)
|
||||
// log("range ifaces = ", i)
|
||||
checkInterface(i)
|
||||
log.Println(args.VerboseNet, "*net.Interface.Name = ", i.Name, i.Index)
|
||||
log.Println(args.VerboseNet, SPEW, i)
|
||||
log.Println(DEBUGNET, SPEW, addrs)
|
||||
log(args.VerboseNet, "*net.Interface.Name = ", i.Name, i.Index)
|
||||
log(args.VerboseNet, SPEW, i)
|
||||
log(DEBUGNET, SPEW, addrs)
|
||||
for _, addr := range addrs {
|
||||
log.Println(DEBUGNET, "\taddr =", addr)
|
||||
log.Println(DEBUGNET, SPEW, addrs)
|
||||
log(DEBUGNET, "\taddr =", addr)
|
||||
log(DEBUGNET, SPEW, addrs)
|
||||
ips, _ := net.LookupIP(addr.String())
|
||||
log.Println(DEBUGNET, "\tLookupIP(addr) =", ips)
|
||||
log(DEBUGNET, "\tLookupIP(addr) =", ips)
|
||||
switch v := addr.(type) {
|
||||
case *net.IPNet:
|
||||
checkIP(v, i)
|
||||
// log.Println("\t\tIP is () =", ip.())
|
||||
// log("\t\tIP is () =", ip.())
|
||||
default:
|
||||
log.Println(DEBUGNET, "\t\taddr.(type) = NO IDEA WHAT TO DO HERE v =", v)
|
||||
log(DEBUGNET, "\t\taddr.(type) = NO IDEA WHAT TO DO HERE v =", v)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -218,12 +218,12 @@ func scanInterfaces() {
|
|||
for s, t := range me.ipmap {
|
||||
if (t.ipv4) {
|
||||
all4 += s + "\n"
|
||||
log.Println("IPv4 =", s)
|
||||
log("IPv4 =", s)
|
||||
} else if (t.ipv6) {
|
||||
all6 += s + "\n"
|
||||
log.Println("IPv6 =", s)
|
||||
log("IPv6 =", s)
|
||||
} else {
|
||||
log.Println("???? =", s)
|
||||
log("???? =", s)
|
||||
}
|
||||
}
|
||||
all4 = strings.TrimSpace(all4)
|
||||
|
@ -236,7 +236,7 @@ func scanInterfaces() {
|
|||
func deleteChanges() {
|
||||
for i, t := range me.ifmap {
|
||||
if (t.gone) {
|
||||
log.Println("DELETE int =", i, "name =", t.name, t.iface)
|
||||
log("DELETE int =", i, "name =", t.name, t.iface)
|
||||
delete(me.ifmap, i)
|
||||
me.changed = true
|
||||
}
|
||||
|
@ -244,10 +244,10 @@ func deleteChanges() {
|
|||
}
|
||||
for s, t := range me.ipmap {
|
||||
if (t.gone) {
|
||||
log.Println("DELETE name =", s, "IPv4 =", t.ipv4)
|
||||
log.Println("DELETE name =", s, "IPv6 =", t.ipv6)
|
||||
log.Println("DELETE name =", s, "iface =", t.iface)
|
||||
log.Println("DELETE name =", s, "ip =", t.ip)
|
||||
log("DELETE name =", s, "IPv4 =", t.ipv4)
|
||||
log("DELETE name =", s, "IPv6 =", t.ipv6)
|
||||
log("DELETE name =", s, "iface =", t.iface)
|
||||
log("DELETE name =", s, "ip =", t.ip)
|
||||
delete(me.ipmap, s)
|
||||
me.changed = true
|
||||
}
|
||||
|
|
|
@ -0,0 +1,66 @@
|
|||
package main
|
||||
|
||||
// examples of what ifconfig does
|
||||
// example of AF_NETLINK change:
|
||||
// https://stackoverflow.com/questions/579783/how-to-detect-ip-address-change-programmatically-in-linux/2353441#2353441
|
||||
// from that page, a link to watch for any ip event:
|
||||
// https://github.com/angt/ipevent/blob/master/ipevent.c
|
||||
|
||||
// https://github.com/mdlayher/talks : Linux, Netlink, and Go in 7 minutes or less! (GopherCon 2018, lightning talk)
|
||||
|
||||
/*
|
||||
c example from ipevent.c :
|
||||
int fd = socket(PF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
|
||||
|
||||
struct sockaddr_nl snl = {
|
||||
.nl_family = AF_NETLINK,
|
||||
.nl_groups = RTMGRP_IPV4_IFADDR | RTMGRP_IPV6_IFADDR,
|
||||
};
|
||||
*/
|
||||
|
||||
/*
|
||||
import (
|
||||
// "os"
|
||||
// "os/exec"
|
||||
// "log"
|
||||
// "net"
|
||||
// "unix"
|
||||
"github.com/vishvananda/netlink"
|
||||
"github.com/jsimonetti/rtnetlink"
|
||||
// "git.wit.org/wit/gui"
|
||||
// "github.com/davecgh/go-spew/spew"
|
||||
)
|
||||
|
||||
// In golang, write a function to register with netlink to detect changes to any network interface Use tab indentation. Do not include example usage.
|
||||
|
||||
func registerNetlink() error {
|
||||
// Create netlink socket
|
||||
sock, err := netlink.Socket(rtnetlink.NETLINK_ROUTE, 0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// Register for interface change events
|
||||
err = netlink.AddMembership(sock, netlink.RTNLGRP_LINK)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// Close the socket
|
||||
defer sock.Close()
|
||||
// Handle incoming notifications
|
||||
for {
|
||||
msgs, _, err := sock.Receive()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, msg := range msgs {
|
||||
switch msg.Header.Type {
|
||||
case unix.RTM_NEWLINK:
|
||||
// Do something with new link
|
||||
case unix.RTM_DELLINK:
|
||||
// Do something with deleted link
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
*/
|
34
nsupdate.go
34
nsupdate.go
|
@ -1,34 +0,0 @@
|
|||
// inspired from:
|
||||
// https://github.com/mactsouk/opensource.com.git
|
||||
// and
|
||||
// https://coderwall.com/p/wohavg/creating-a-simple-tcp-server-in-go
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
)
|
||||
|
||||
// ./go-nsupdate \
|
||||
// --tsig-algorithm=hmac-sha512 \
|
||||
// --tsig-secret="OWh5/ZHIyaz7B8J9m9ZDqZ8448Pke0PTpkYbZmFcOf5a6rEzgmcwrG91u1BHi1/4us+mKKEobDPLw1x6sD+ZJw==" \
|
||||
// -i eno2 farm001.lab.wit.org
|
||||
|
||||
func nsupdate() {
|
||||
var tsigSecret string
|
||||
log.Println(true, "nsupdate() START")
|
||||
cmd := "go-nsupdate --tsig-algorithm=hmac-sha512"
|
||||
tsigSecret = os.Getenv("TIG_SECRET")
|
||||
cmd += " --tig-secret=\"" + tsigSecret + "\""
|
||||
cmd += " -i wlo1 " + me.hostname
|
||||
log.Println(true, "nsupdate() RUN:", cmd)
|
||||
|
||||
for s, t := range me.ipmap {
|
||||
if (t.IsReal()) {
|
||||
if (t.ipv6) {
|
||||
log.Println(true, "nsupdate() found real AAAA =", s, "on iface", t.iface.Name)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,7 +1,6 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"github.com/jsimonetti/rtnetlink"
|
||||
)
|
||||
|
||||
|
@ -10,7 +9,7 @@ func Example_listLink() {
|
|||
// Dial a connection to the rtnetlink socket
|
||||
conn, err := rtnetlink.Dial(nil)
|
||||
if err != nil {
|
||||
log.Println(logError, "Example_listLink() failed", err)
|
||||
log(logError, "Example_listLink() failed", err)
|
||||
return
|
||||
}
|
||||
defer conn.Close()
|
||||
|
@ -18,9 +17,9 @@ func Example_listLink() {
|
|||
// Request a list of interfaces
|
||||
msg, err := conn.Link.List()
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
log(err)
|
||||
}
|
||||
|
||||
log.Println("%#v", msg)
|
||||
log.Println(SPEW, msg)
|
||||
log("%#v", msg)
|
||||
log(SPEW, msg)
|
||||
}
|
||||
|
|
37
run.go
37
run.go
|
@ -1,37 +0,0 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"strings"
|
||||
"os/exec"
|
||||
|
||||
"git.wit.org/wit/shell"
|
||||
)
|
||||
|
||||
func run(s string) string {
|
||||
cmdArgs := strings.Fields(s)
|
||||
// Define the command you want to run
|
||||
// cmd := exec.Command(cmdArgs)
|
||||
cmd := exec.Command(cmdArgs[0], cmdArgs[1:len(cmdArgs)]...)
|
||||
|
||||
// Create a buffer to capture the output
|
||||
var out bytes.Buffer
|
||||
|
||||
// Set the output of the command to the buffer
|
||||
cmd.Stdout = &out
|
||||
|
||||
// Run the command
|
||||
err := cmd.Run()
|
||||
if err != nil {
|
||||
fmt.Println("Error running command:", err)
|
||||
return ""
|
||||
}
|
||||
|
||||
tmp := shell.Chomp(out.String())
|
||||
// Output the results
|
||||
fmt.Println("Command Output:", tmp)
|
||||
|
||||
return tmp
|
||||
}
|
||||
|
11
structs.go
11
structs.go
|
@ -13,22 +13,16 @@ type Host struct {
|
|||
hostname string // mirrors
|
||||
domainname string // kernel.org
|
||||
// fqdn string // mirrors.kernel.org
|
||||
|
||||
dnsTTL int `default:3` // Recheck DNS is working every TTL (in seconds)
|
||||
dnsTTLsleep float64 // sleep between loops
|
||||
artificialSleep float64 `default:0.7` // artificial sleep on startup
|
||||
artificialS string `default:0.7` // artificial sleep on startup
|
||||
|
||||
dnsTTL int // Recheck DNS is working every TTL (in seconds)
|
||||
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
|
||||
ifmap map[int]*IFtype // the current interfaces
|
||||
|
||||
window *gui.Node // the main window
|
||||
tab *gui.Node // the main dns tab
|
||||
notes *gui.Node // using this to put notes here
|
||||
output *gui.Node // Textbox for dumping output
|
||||
uid *gui.Node // user
|
||||
fqdn *gui.Node // display the full hostname
|
||||
IPv4 *gui.Node // show valid IPv4 addresses
|
||||
|
@ -37,7 +31,6 @@ type Host struct {
|
|||
DnsAAAA *gui.Node // the actual DNS AAAA results
|
||||
DnsA *gui.Node // the actual DNS A results (ignore for status since mostly never happens?)
|
||||
DnsStatus *gui.Node // the current state of DNS
|
||||
fix *gui.Node // button for the user to click
|
||||
}
|
||||
|
||||
type IPtype struct {
|
||||
|
|
11
unix.go
11
unix.go
|
@ -5,10 +5,11 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
"net"
|
||||
// "git.wit.org/wit/gui"
|
||||
// "github.com/davecgh/go-spew/spew"
|
||||
)
|
||||
|
||||
func CheckSuperuser() bool {
|
||||
|
@ -23,7 +24,7 @@ func Escalate() {
|
|||
cmd.Stderr = os.Stderr
|
||||
err := cmd.Run()
|
||||
if err != nil {
|
||||
log.Println(logError, "exit in Escalate()")
|
||||
log(logError, "exit in Escalate()")
|
||||
exit(err)
|
||||
}
|
||||
}
|
||||
|
@ -38,17 +39,17 @@ func DumpPublicDNSZone(zone string) {
|
|||
panic(err)
|
||||
}
|
||||
for _, entry := range entries {
|
||||
log.Println(entry)
|
||||
log(entry)
|
||||
}
|
||||
}
|
||||
|
||||
func dumpIPs(host string) {
|
||||
ips, err := net.LookupIP(host)
|
||||
if err != nil {
|
||||
log.Println(logError, "dumpIPs() failed:", err)
|
||||
log(logError, "dumpIPs() failed:", err)
|
||||
}
|
||||
for _, ip := range ips {
|
||||
log.Println(host, ip)
|
||||
log(host, ip)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue