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-12-16 09:02:59 -06:00
|
|
|
"log"
|
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-12-16 09:02:59 -06:00
|
|
|
"embed"
|
2023-03-01 11:21:47 -06:00
|
|
|
"git.wit.org/wit/gui"
|
2023-02-08 11:04:04 -06:00
|
|
|
)
|
|
|
|
|
2023-03-25 19:02:49 -05:00
|
|
|
var myGui *gui.Node
|
2023-03-01 11:21:47 -06:00
|
|
|
|
2023-12-16 09:02:59 -06:00
|
|
|
//go:embed plugins/*.so
|
|
|
|
var resToolkit embed.FS
|
|
|
|
|
2023-02-08 11:04:04 -06:00
|
|
|
func main() {
|
2023-12-16 09:02:59 -06:00
|
|
|
// 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-12-16 09:36:40 -06:00
|
|
|
me.dnsTTL = 2 // recheck DNS is working every 2 minutes // TODO: watch rx packets?
|
2023-02-09 09:07:00 -06:00
|
|
|
|
2023-04-11 15:24:43 -05:00
|
|
|
// will set all debugging flags
|
2023-05-22 16:23:55 -05:00
|
|
|
// gui.SetDebug(true)
|
2023-04-11 15:24:43 -05:00
|
|
|
|
2023-12-16 09:02:59 -06:00
|
|
|
// myGui = gui.New().InitEmbed(resToolkit).LoadToolkit("gocui")
|
|
|
|
myGui = gui.New().Default()
|
2023-12-16 09:36:40 -06:00
|
|
|
sleep(.2)
|
2023-04-07 11:23:47 -05:00
|
|
|
setupControlPanelWindow()
|
2023-12-16 09:36:40 -06:00
|
|
|
sleep(.2)
|
2023-04-11 15:24:43 -05:00
|
|
|
if (args.GuiDebug) {
|
|
|
|
gui.DebugWindow()
|
|
|
|
}
|
|
|
|
gui.ShowDebugValues()
|
|
|
|
|
|
|
|
// forever monitor for network and dns changes
|
2023-03-25 19:02:49 -05:00
|
|
|
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
|
2023-02-09 09:07:00 -06:00
|
|
|
for {
|
2023-12-16 09:36:40 -06:00
|
|
|
sleep(0.5)
|
2023-03-01 11:21:47 -06:00
|
|
|
ttl -= 1
|
|
|
|
if (ttl < 0) {
|
|
|
|
if (runtime.GOOS == "linux") {
|
|
|
|
dnsTTL()
|
|
|
|
} else {
|
2023-12-16 09:02:59 -06:00
|
|
|
log.Println("Windows and MacOS don't work yet")
|
2023-03-01 11:21:47 -06:00
|
|
|
}
|
|
|
|
ttl = me.dnsTTL
|
2023-02-09 09:07:00 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-03-01 11:21:47 -06:00
|
|
|
|
2023-04-11 15:24:43 -05:00
|
|
|
// This checks for changes to the network settings
|
|
|
|
// and verifies that DNS is working or not working
|
2023-03-01 11:21:47 -06:00
|
|
|
func dnsTTL() {
|
2023-03-26 16:17:32 -05:00
|
|
|
me.changed = false
|
2023-12-16 09:02:59 -06:00
|
|
|
log.Println("FQDN =", me.fqdn.GetText())
|
2023-03-01 11:21:47 -06:00
|
|
|
getHostname()
|
|
|
|
scanInterfaces()
|
|
|
|
for i, t := range me.ifmap {
|
2023-12-16 09:02:59 -06:00
|
|
|
log.Println(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-12-16 09:02:59 -06:00
|
|
|
log.Println("my actual AAAA = ",s)
|
2023-03-26 16:17:32 -05:00
|
|
|
all += s + "\n"
|
|
|
|
}
|
2023-03-26 16:49:56 -05:00
|
|
|
// me.IPv6.SetText(all)
|
2023-03-26 16:17:32 -05:00
|
|
|
|
|
|
|
if (me.changed) {
|
|
|
|
stamp := time.Now().Format("2006/01/02 15:04:05")
|
2023-12-16 09:02:59 -06:00
|
|
|
log.Println(logError, "Network things changed on", stamp)
|
2023-03-26 16:17:32 -05:00
|
|
|
updateDNS()
|
2023-03-01 11:21:47 -06:00
|
|
|
}
|
|
|
|
}
|