2023-03-01 11:21:47 -06:00
|
|
|
// GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007
|
|
|
|
// Copyright (c) 2023 WIT.COM, Inc.
|
2023-02-18 23:37:11 -06:00
|
|
|
// This is a control panel for DNS
|
2023-03-09 14:21:34 -06:00
|
|
|
|
2023-02-08 11:04:04 -06:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2023-03-01 11:21:47 -06:00
|
|
|
"strconv"
|
2023-02-18 23:37:11 -06:00
|
|
|
"runtime"
|
2023-03-26 16:17:32 -05:00
|
|
|
"time"
|
2023-02-08 11:04:04 -06:00
|
|
|
arg "github.com/alexflint/go-arg"
|
2023-03-01 11:21:47 -06:00
|
|
|
"git.wit.org/wit/gui"
|
2023-02-08 11:04:04 -06:00
|
|
|
)
|
|
|
|
|
2023-03-01 11:21:47 -06:00
|
|
|
var p *arg.Parser
|
2023-03-25 19:02:49 -05:00
|
|
|
var myGui *gui.Node
|
2023-03-01 11:21:47 -06:00
|
|
|
|
2023-02-08 11:04:04 -06:00
|
|
|
func main() {
|
2023-03-01 11:21:47 -06:00
|
|
|
p = arg.MustParse(&args)
|
|
|
|
parsedown()
|
2023-02-09 19:47:52 -06:00
|
|
|
|
2023-02-18 23:37:11 -06:00
|
|
|
// initialize the maps to track IP addresses and network interfaces
|
|
|
|
me.ipmap = make(map[string]*IPtype)
|
2023-03-01 11:21:47 -06:00
|
|
|
me.dnsmap = make(map[string]*IPtype)
|
2023-02-18 23:37:11 -06:00
|
|
|
me.ifmap = make(map[int]*IFtype)
|
2023-03-01 11:21:47 -06:00
|
|
|
me.dnsTTL = 5 // recheck DNS is working every 2 minutes // TODO: watch rx packets?
|
2023-02-09 09:07:00 -06:00
|
|
|
|
|
|
|
|
2023-02-18 23:37:11 -06:00
|
|
|
log()
|
|
|
|
log(true, "this is true")
|
|
|
|
log(false, "this is false")
|
|
|
|
sleep(.4)
|
|
|
|
sleep(.3)
|
|
|
|
sleep(.2)
|
|
|
|
sleep("done scanning net")
|
|
|
|
// exit("done scanning net")
|
2023-02-09 09:07:00 -06:00
|
|
|
|
2023-02-18 23:37:11 -06:00
|
|
|
// Example_listLink()
|
|
|
|
// exit()
|
2023-02-09 09:07:00 -06:00
|
|
|
|
2023-02-18 23:37:11 -06:00
|
|
|
log("Toolkit = ", args.Toolkit)
|
|
|
|
// gui.InitPlugins([]string{"andlabs"})
|
2023-03-25 08:40:48 -05:00
|
|
|
// gui.SetDebug(true)
|
2023-03-25 19:02:49 -05:00
|
|
|
// myGui = gui.Main(initGUI)
|
|
|
|
myGui = gui.Start()
|
|
|
|
sleep(1)
|
|
|
|
initGUI()
|
|
|
|
sleep(1)
|
|
|
|
checkNetworkChanges()
|
2023-02-09 09:07:00 -06:00
|
|
|
}
|
|
|
|
|
2023-02-18 23:37:11 -06:00
|
|
|
/*
|
|
|
|
Poll for changes to the networking settings
|
|
|
|
*/
|
|
|
|
func checkNetworkChanges() {
|
2023-03-25 15:43:24 -05:00
|
|
|
var ttl int = 0
|
|
|
|
var ttlsleep int = 5
|
2023-02-09 09:07:00 -06:00
|
|
|
for {
|
2023-03-25 15:43:24 -05:00
|
|
|
sleep(ttlsleep)
|
2023-03-01 11:21:47 -06:00
|
|
|
ttl -= 1
|
|
|
|
if (ttl < 0) {
|
|
|
|
if (runtime.GOOS == "linux") {
|
|
|
|
dnsTTL()
|
|
|
|
} else {
|
|
|
|
log("Windows and MacOS don't work yet")
|
|
|
|
}
|
|
|
|
ttl = me.dnsTTL
|
2023-02-09 09:07:00 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-03-01 11:21:47 -06:00
|
|
|
|
|
|
|
// Run this every once and a while
|
|
|
|
func dnsTTL() {
|
2023-03-26 16:17:32 -05:00
|
|
|
me.changed = false
|
2023-03-25 08:40:48 -05:00
|
|
|
log("FQDN =", me.fqdn.GetText())
|
2023-03-01 11:21:47 -06:00
|
|
|
getHostname()
|
|
|
|
scanInterfaces()
|
|
|
|
for i, t := range me.ifmap {
|
2023-03-25 08:40:48 -05:00
|
|
|
log(strconv.Itoa(i) + " iface = " + t.iface.Name)
|
2023-03-01 11:21:47 -06:00
|
|
|
}
|
2023-03-26 16:17:32 -05:00
|
|
|
|
2023-03-01 11:21:47 -06:00
|
|
|
var aaaa []string
|
|
|
|
aaaa = realAAAA()
|
2023-03-26 16:17:32 -05:00
|
|
|
var all string
|
2023-03-01 11:21:47 -06:00
|
|
|
for _, s := range aaaa {
|
2023-03-25 08:40:48 -05:00
|
|
|
log("my actual AAAA = ",s)
|
2023-03-26 16:17:32 -05:00
|
|
|
all += s + "\n"
|
|
|
|
}
|
|
|
|
me.IPv6.SetText(all)
|
|
|
|
|
|
|
|
if (me.changed) {
|
|
|
|
stamp := time.Now().Format("2006/01/02 15:04:05")
|
|
|
|
s := stamp + " Network things changed"
|
|
|
|
log(logError, "Network things changed on", stamp)
|
|
|
|
updateDNS()
|
|
|
|
me.output.SetText(s)
|
|
|
|
|
2023-03-01 11:21:47 -06:00
|
|
|
}
|
|
|
|
}
|