// GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007 // Copyright (c) 2023 WIT.COM, Inc. // This is a control panel for DNS package main import ( "fmt" "log" "strconv" "runtime" "time" "embed" "git.wit.org/wit/gui" ) var myGui *gui.Node //go:embed plugins/*.so var resToolkit embed.FS var tenth time.Duration = 1 // in tenths of seconds func main() { // 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? // will set all debugging flags // gui.SetDebug(true) // myGui = gui.New().InitEmbed(resToolkit).LoadToolkit("gocui") myGui = gui.New().Default() sleep(me.artificialSleep) setupControlPanelWindow() /* if (args.GuiDebug) { gui.DebugWindow() } gui.ShowDebugValues() */ // forever monitor for network and dns changes sleep(me.artificialSleep) checkNetworkChanges() } /* Poll for changes to the networking settings */ func checkNetworkChanges() { var ttl int = 0 for { sleep(me.dnsTTLsleep) ttl -= 1 if (ttl < 0) { if (runtime.GOOS == "linux") { duration := timeFunction(dnsTTL) log.Println("dnsTTL() execution Time: ", duration) var s string if (duration > 50 * tenth) { s = fmt.Sprint("VERY BAD\n", duration) } else if (duration > 20 * tenth) { s = fmt.Sprint("BAD\n", duration) } else if (duration > 5 * tenth) { s = fmt.Sprint("SLOW\n", duration) } else { s = fmt.Sprint("OK\n", duration) } log.Println(true, "getHostname()", s) me.DnsSpeed.SetText(s) } else { log.Println("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 func dnsTTL() { me.changed = false log.Println("FQDN =", me.fqdn.GetText()) duration := timeFunction(getHostname) debug(true, "getHostname() execution Time: ", duration) duration = timeFunction(scanInterfaces) log.Println("scanInterfaces() execution Time: ", duration) for i, t := range me.ifmap { log.Println(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) all += s + "\n" } // me.IPv6.SetText(all) if (me.changed) { stamp := time.Now().Format("2006/01/02 15:04:05") debug(LogError, "Network things changed on", stamp) updateDNS() } processName := getProcessNameByPort(53) fmt.Println("Process with port 53:", processName) /* commPath := filepath.Join("/proc", proc.Name(), "comm") comm, err := ioutil.ReadFile(commPath) if err != nil { return "", err // Error reading the process name } return strings.TrimSpace(string(comm)), nil */ } /* // 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 }