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-20 03:13:43 -06:00
|
|
|
"fmt"
|
2024-01-07 14:11:15 -06:00
|
|
|
// "runtime"
|
2023-03-26 16:17:32 -05:00
|
|
|
"time"
|
2023-12-16 09:02:59 -06:00
|
|
|
"embed"
|
2023-12-20 03:13:43 -06:00
|
|
|
|
2023-12-28 15:36:05 -06:00
|
|
|
"go.wit.com/log"
|
2024-01-03 12:40:31 -06:00
|
|
|
"go.wit.com/gui/gui"
|
|
|
|
"go.wit.com/gui/debugger"
|
|
|
|
|
2024-01-07 16:52:23 -06:00
|
|
|
"go.wit.com/apps/control-panel-dns/linuxstatus"
|
2024-01-06 05:24:11 -06:00
|
|
|
|
2023-12-20 03:13:43 -06:00
|
|
|
"github.com/miekg/dns"
|
2023-02-08 11:04:04 -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-20 03:13:43 -06:00
|
|
|
me.nsmap = make(map[string]string)
|
|
|
|
|
|
|
|
// initialize maps for the returned DNS records
|
|
|
|
me.ipv4s = make(map[string]dns.RR)
|
|
|
|
me.ipv6s = make(map[string]dns.RR)
|
2023-02-09 09:07:00 -06:00
|
|
|
|
2024-01-08 11:55:56 -06:00
|
|
|
if args.TmpLog {
|
|
|
|
// send all log() output to a file in /tmp
|
|
|
|
log.SetTmp()
|
|
|
|
}
|
|
|
|
|
|
|
|
me.myGui = gui.New()
|
|
|
|
me.myGui.InitEmbed(resToolkit)
|
|
|
|
me.myGui.Default()
|
2023-12-20 03:13:43 -06:00
|
|
|
|
2024-01-03 19:33:13 -06:00
|
|
|
log.Sleep(me.artificialSleep)
|
2023-04-07 11:23:47 -05:00
|
|
|
setupControlPanelWindow()
|
2023-12-20 03:13:43 -06:00
|
|
|
|
2024-01-06 02:21:56 -06:00
|
|
|
me.digStatus = NewDigStatusWindow(me.myGui)
|
2024-01-06 19:58:58 -06:00
|
|
|
me.statusDNS = NewHostnameStatusWindow(me.myGui)
|
2024-01-06 02:21:56 -06:00
|
|
|
|
2024-01-07 05:46:59 -06:00
|
|
|
me.statusOS = linuxstatus.New()
|
|
|
|
me.statusOS.SetParent(me.myGui)
|
|
|
|
me.statusOS.InitWindow()
|
|
|
|
me.statusOS.Make()
|
|
|
|
me.statusOS.Draw()
|
|
|
|
me.statusOS.Draw2()
|
2024-01-06 05:24:11 -06:00
|
|
|
|
2024-01-03 13:25:07 -06:00
|
|
|
if debugger.ArgDebug() {
|
2024-01-07 13:03:48 -06:00
|
|
|
go func() {
|
|
|
|
log.Sleep(2)
|
|
|
|
debugger.DebugWindow(me.myGui)
|
|
|
|
}()
|
2024-01-03 12:40:31 -06:00
|
|
|
}
|
|
|
|
|
2024-01-03 19:33:13 -06:00
|
|
|
log.Sleep(me.artificialSleep)
|
2023-12-28 15:36:05 -06:00
|
|
|
|
2024-01-07 14:11:15 -06:00
|
|
|
// TCP & UDP port 53 lookups + DNS over HTTP lookups + os.Exec(dig)
|
|
|
|
go myTicker(60 * time.Second, "DNSloop", func() {
|
|
|
|
me.digStatus.Update()
|
|
|
|
|
|
|
|
if me.digStatus.Ready() {
|
|
|
|
current := me.statusIPv6.Get()
|
|
|
|
if me.digStatus.IPv6() {
|
|
|
|
if current != "WORKING" {
|
|
|
|
log.Log(CHANGE, "IPv6 resolution is WORKING")
|
|
|
|
me.statusIPv6.Set("WORKING")
|
|
|
|
}
|
2023-03-01 11:21:47 -06:00
|
|
|
} else {
|
2024-01-07 14:11:15 -06:00
|
|
|
if current != "Need VPN" {
|
|
|
|
log.Log(CHANGE, "IPv6 resolution seems to have broken")
|
|
|
|
me.statusIPv6.Set("Need VPN")
|
|
|
|
}
|
2023-03-01 11:21:47 -06:00
|
|
|
}
|
2023-12-20 03:13:43 -06:00
|
|
|
}
|
2024-01-07 14:11:15 -06:00
|
|
|
})
|
|
|
|
|
|
|
|
// checks if your DNS records are still broken
|
|
|
|
// if everything is working, then it just ignores
|
|
|
|
// things until the timeout happens
|
2024-01-07 14:19:57 -06:00
|
|
|
|
|
|
|
lastProvider := "unknown"
|
2024-01-07 14:11:15 -06:00
|
|
|
go myTicker(10 * time.Second, "DNSloop", func() {
|
2024-01-07 15:27:44 -06:00
|
|
|
log.Log(INFO, "me.statusDNS.Update() START")
|
2024-01-07 14:11:15 -06:00
|
|
|
me.statusDNS.Update()
|
2024-01-07 14:19:57 -06:00
|
|
|
|
|
|
|
provider := me.statusDNS.GetDNSapi()
|
|
|
|
if provider != lastProvider {
|
|
|
|
log.Log(CHANGE, "Your DNS API provider appears to have changed to", provider)
|
|
|
|
lastProvider = provider
|
2024-01-07 14:43:17 -06:00
|
|
|
me.apiButton.SetText(provider + " wit.com")
|
2024-01-07 14:19:57 -06:00
|
|
|
}
|
|
|
|
if provider == "cloudflare" {
|
|
|
|
me.DnsAPIstatus.Set("WORKING")
|
|
|
|
}
|
2024-01-07 14:11:15 -06:00
|
|
|
})
|
|
|
|
|
|
|
|
// probes the OS network settings
|
2024-01-07 14:43:17 -06:00
|
|
|
go myTicker(500 * time.Millisecond, "me.statusOS,Update()", func() {
|
2024-01-07 14:11:15 -06:00
|
|
|
duration := timeFunction( func() {
|
|
|
|
me.statusOS.Update()
|
|
|
|
|
|
|
|
if me.statusOS.ValidHostname() {
|
|
|
|
if me.hostnameStatus.GetText() != "WORKING" {
|
|
|
|
me.hostnameStatus.Set("WORKING")
|
|
|
|
me.changed = true
|
|
|
|
}
|
|
|
|
}
|
2023-12-21 17:56:56 -06:00
|
|
|
|
2024-01-07 14:11:15 -06:00
|
|
|
// re-check DNS API provider
|
|
|
|
if (me.statusOS.Changed()) {
|
|
|
|
// lookup the NS records for your domain
|
|
|
|
// if your host is test.wit.com, find the NS resource records for wit.com
|
|
|
|
lookupNS(me.statusOS.GetDomainName())
|
2024-01-10 20:22:25 -06:00
|
|
|
log.Log(CHANGE, "lookupNS() RUNNING NOW. this will determine your DNS API provider")
|
|
|
|
}
|
|
|
|
if me.statusDNS.GetDNSapi() == "unknown" {
|
|
|
|
lookupNS(me.statusOS.GetDomainName())
|
|
|
|
log.Log(CHANGE, "lookupNS() RUNNING NOW. this will determine your DNS API provider")
|
2024-01-07 14:11:15 -06:00
|
|
|
}
|
|
|
|
})
|
|
|
|
s := fmt.Sprint(duration)
|
|
|
|
me.statusOS.SetSpeedActual(s)
|
|
|
|
})
|
2024-01-07 14:43:17 -06:00
|
|
|
|
|
|
|
// check the four known things to see if they are all WORKING
|
2024-01-07 15:27:44 -06:00
|
|
|
myTicker(10 * time.Second, "MAIN LOOP", func() {
|
2024-01-08 11:05:40 -06:00
|
|
|
var working bool = true
|
2024-01-07 14:43:17 -06:00
|
|
|
if me.hostnameStatus.GetText() != "WORKING" {
|
|
|
|
log.Log(CHANGE, "The hostname is not WORKING yet", me.hostnameStatus.GetText())
|
2024-01-08 11:05:40 -06:00
|
|
|
working = false
|
2024-01-07 14:43:17 -06:00
|
|
|
}
|
|
|
|
if me.statusIPv6.Get() != "WORKING" {
|
|
|
|
log.Log(CHANGE, "IPv6 DNS lookup has not been confirmed yet", me.statusIPv6.Get())
|
2024-01-08 11:05:40 -06:00
|
|
|
working = false
|
2024-01-07 14:43:17 -06:00
|
|
|
}
|
|
|
|
if me.DnsStatus.GetText() != "WORKING" {
|
|
|
|
log.Log(CHANGE, "Your IPv6 DNS settings have not been confirmed yet", me.DnsStatus.GetText())
|
2024-01-08 11:05:40 -06:00
|
|
|
working = false
|
2024-01-07 14:43:17 -06:00
|
|
|
}
|
|
|
|
if me.DnsAPIstatus.GetText() != "WORKING" {
|
|
|
|
log.Log(CHANGE, "The DNS API provider is not yet working", me.DnsAPIstatus.GetText())
|
2024-01-08 11:05:40 -06:00
|
|
|
working = false
|
|
|
|
}
|
|
|
|
if working {
|
|
|
|
log.Log(CHANGE, "EVERYTHING IS WORKING. YOU HAVE IPv6 BLISS. TODO: don't check so often now")
|
|
|
|
} else {
|
2024-01-08 12:55:23 -06:00
|
|
|
log.Log(CHANGE, "EVERYTHING IS NOT WORKING. scanning errors:")
|
|
|
|
me.problems.Scan()
|
2024-01-07 14:43:17 -06:00
|
|
|
}
|
|
|
|
})
|
2023-12-20 03:13:43 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
// Example usage
|
|
|
|
duration := timeFunction(FunctionToTime)
|
|
|
|
log.Println("Execution Time: ", duration)
|
|
|
|
*/
|
|
|
|
|
|
|
|
// timeFunction takes a function as an argument and returns the execution time.
|
|
|
|
func timeFunction(f func()) time.Duration {
|
|
|
|
startTime := time.Now() // Record the start time
|
|
|
|
f() // Execute the function
|
|
|
|
return time.Since(startTime) // Calculate the elapsed time
|
|
|
|
}
|
2024-01-07 14:11:15 -06:00
|
|
|
|
|
|
|
func timeStamp() string {
|
|
|
|
stamp := time.Now().Format("2006/01/02 15:04:05")
|
|
|
|
log.Log(CHANGE, "Network things changed on", stamp)
|
|
|
|
return stamp
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func myTicker(t time.Duration, name string, f func()) {
|
|
|
|
ticker := time.NewTicker(t)
|
|
|
|
defer ticker.Stop()
|
|
|
|
done := make(chan bool)
|
|
|
|
/*
|
|
|
|
go func() {
|
|
|
|
time.Sleep(10 * time.Second)
|
|
|
|
done <- true
|
|
|
|
}()
|
|
|
|
*/
|
|
|
|
for {
|
|
|
|
select {
|
|
|
|
case <-done:
|
|
|
|
fmt.Println("Done!")
|
|
|
|
return
|
|
|
|
case t := <-ticker.C:
|
|
|
|
log.Log(INFO, name, "Current time: ", t)
|
|
|
|
f()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|