seems to compile and run
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
e9f1723dbc
commit
bbf96ee7fa
4
Makefile
4
Makefile
|
@ -1,3 +1,5 @@
|
|||
.PHONY: debian
|
||||
|
||||
run: build
|
||||
# ./control-panel-dns >/tmp/witgui.log.stderr 2>&1
|
||||
./control-panel-dns
|
||||
|
@ -44,7 +46,7 @@ clean:
|
|||
-rm -rf files/
|
||||
-rm *.deb
|
||||
|
||||
deb:
|
||||
debian:
|
||||
cd debian && make
|
||||
-wit mirrors
|
||||
|
||||
|
|
62
args.go
62
args.go
|
@ -5,10 +5,13 @@ package main
|
|||
*/
|
||||
|
||||
import (
|
||||
"log"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"strconv"
|
||||
arg "github.com/alexflint/go-arg"
|
||||
"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"`
|
||||
Demo bool `help:"run a demo"`
|
||||
gui.GuiArgs
|
||||
log.LogArgs
|
||||
// log.LogArgs
|
||||
}
|
||||
|
||||
func init() {
|
||||
|
@ -35,6 +38,59 @@ func init() {
|
|||
if (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
18
gui.go
|
@ -20,7 +20,7 @@ func setupControlPanelWindow() {
|
|||
me.window = myGui.NewWindow("DNS and IPv6 Control Panel").Standard()
|
||||
me.window.Dump()
|
||||
|
||||
sleep(1)
|
||||
sleep(me.artificialSleep)
|
||||
dnsTab("DNS")
|
||||
debugTab("Debug")
|
||||
|
||||
|
@ -99,6 +99,22 @@ func debugTab(title string) {
|
|||
DumpPublicDNSZone("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) {
|
||||
|
|
6
main.go
6
main.go
|
@ -32,9 +32,9 @@ func main() {
|
|||
|
||||
// myGui = gui.New().InitEmbed(resToolkit).LoadToolkit("gocui")
|
||||
myGui = gui.New().Default()
|
||||
sleep(.2)
|
||||
sleep(me.artificialSleep)
|
||||
setupControlPanelWindow()
|
||||
sleep(.2)
|
||||
sleep(me.artificialSleep)
|
||||
if (args.GuiDebug) {
|
||||
gui.DebugWindow()
|
||||
}
|
||||
|
@ -50,7 +50,7 @@ func main() {
|
|||
func checkNetworkChanges() {
|
||||
var ttl int = 0
|
||||
for {
|
||||
sleep(0.5)
|
||||
sleep(me.dnsTTLsleep)
|
||||
ttl -= 1
|
||||
if (ttl < 0) {
|
||||
if (runtime.GOOS == "linux") {
|
||||
|
|
|
@ -13,12 +13,19 @@ type Host struct {
|
|||
hostname string // mirrors
|
||||
domainname string // 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
|
||||
user string // name of the user
|
||||
|
||||
ipmap map[string]*IPtype // the current ip addresses
|
||||
dnsmap map[string]*IPtype // the current dns addresses
|
||||
ifmap map[int]*IFtype // the current interfaces
|
||||
|
||||
window *gui.Node // the main window
|
||||
tab *gui.Node // the main dns tab
|
||||
notes *gui.Node // using this to put notes here
|
||||
|
|
Loading…
Reference in New Issue