seems to compile and run

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2023-12-16 12:59:18 -06:00
parent e9f1723dbc
commit bbf96ee7fa
5 changed files with 90 additions and 9 deletions

View File

@ -1,3 +1,5 @@
.PHONY: debian
run: build run: build
# ./control-panel-dns >/tmp/witgui.log.stderr 2>&1 # ./control-panel-dns >/tmp/witgui.log.stderr 2>&1
./control-panel-dns ./control-panel-dns
@ -44,7 +46,7 @@ clean:
-rm -rf files/ -rm -rf files/
-rm *.deb -rm *.deb
deb: debian:
cd debian && make cd debian && make
-wit mirrors -wit mirrors

62
args.go
View File

@ -5,10 +5,13 @@ package main
*/ */
import ( import (
"log"
"fmt" "fmt"
"reflect"
"strconv"
arg "github.com/alexflint/go-arg" arg "github.com/alexflint/go-arg"
"git.wit.org/wit/gui" "git.wit.org/wit/gui"
log "git.wit.org/wit/gui/log" // log "git.wit.org/wit/gui/log"
) )
@ -25,7 +28,7 @@ var args struct {
User string `arg:"env:USER"` User string `arg:"env:USER"`
Demo bool `help:"run a demo"` Demo bool `help:"run a demo"`
gui.GuiArgs gui.GuiArgs
log.LogArgs // log.LogArgs
} }
func init() { func init() {
@ -35,6 +38,59 @@ func init() {
if (args.Gui != "") { if (args.Gui != "") {
gui.GuiArg.Gui = args.Gui gui.GuiArg.Gui = args.Gui
} }
log.Log(true, "INIT() args.GuiArg.Gui =", gui.GuiArg.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
} }

18
gui.go
View File

@ -20,7 +20,7 @@ func setupControlPanelWindow() {
me.window = myGui.NewWindow("DNS and IPv6 Control Panel").Standard() me.window = myGui.NewWindow("DNS and IPv6 Control Panel").Standard()
me.window.Dump() me.window.Dump()
sleep(1) sleep(me.artificialSleep)
dnsTab("DNS") dnsTab("DNS")
debugTab("Debug") debugTab("Debug")
@ -99,6 +99,22 @@ func debugTab(title string) {
DumpPublicDNSZone("apple.com") DumpPublicDNSZone("apple.com")
dumpIPs("www.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)
}
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)
}
} }
func myDefaultExit(n *gui.Node) { func myDefaultExit(n *gui.Node) {

View File

@ -32,9 +32,9 @@ func main() {
// myGui = gui.New().InitEmbed(resToolkit).LoadToolkit("gocui") // myGui = gui.New().InitEmbed(resToolkit).LoadToolkit("gocui")
myGui = gui.New().Default() myGui = gui.New().Default()
sleep(.2) sleep(me.artificialSleep)
setupControlPanelWindow() setupControlPanelWindow()
sleep(.2) sleep(me.artificialSleep)
if (args.GuiDebug) { if (args.GuiDebug) {
gui.DebugWindow() gui.DebugWindow()
} }
@ -50,7 +50,7 @@ func main() {
func checkNetworkChanges() { func checkNetworkChanges() {
var ttl int = 0 var ttl int = 0
for { for {
sleep(0.5) sleep(me.dnsTTLsleep)
ttl -= 1 ttl -= 1
if (ttl < 0) { if (ttl < 0) {
if (runtime.GOOS == "linux") { if (runtime.GOOS == "linux") {

View File

@ -13,12 +13,19 @@ type Host struct {
hostname string // mirrors hostname string // mirrors
domainname string // kernel.org domainname string // kernel.org
// fqdn string // mirrors.kernel.org // fqdn string // mirrors.kernel.org
dnsTTL int // Recheck DNS is working every TTL (in seconds)
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
changed bool // set to true if things changed changed bool // set to true if things changed
user string // name of the user user string // name of the user
ipmap map[string]*IPtype // the current ip addresses ipmap map[string]*IPtype // the current ip addresses
dnsmap map[string]*IPtype // the current dns addresses dnsmap map[string]*IPtype // the current dns addresses
ifmap map[int]*IFtype // the current interfaces ifmap map[int]*IFtype // the current interfaces
window *gui.Node // the main window window *gui.Node // the main window
tab *gui.Node // the main dns tab tab *gui.Node // the main dns tab
notes *gui.Node // using this to put notes here notes *gui.Node // using this to put notes here