wit-debian-gui/window-resolv.go

98 lines
2.1 KiB
Go

package main
import (
"bufio"
"errors"
"os"
"strings"
"go.wit.com/gui"
"go.wit.com/lib/gadgets"
"go.wit.com/log"
)
var filename string = "resolv-1-1-1-1.conf"
var generaloutput *gui.Node
var resWin *gadgets.BasicWindow
func resolvWindow() {
if resWin != nil {
resWin.Toggle()
return
}
resWin = gadgets.NewBasicWindow(myGui, "resolv.conf Window")
////////////// filename /////////////////////////
gNode := resWin.Box().NewGroup("filename")
var tmp []string
for i, s := range packrBox.List() {
log.Println("i, s =", i, s)
if strings.HasPrefix(s, "resolv/") {
tmp = append(tmp, s)
}
}
// panic("junk")
resolvNode := gNode.NewCombobox("test")
for _, thing := range tmp {
resolvNode.AddText(thing)
}
resolvNode.SetText(filename)
resolvNode.Custom = func() {
log.Println("STARTED HOSTNAME")
filename = resolvNode.GetText()
b, _ := packrBox.FindString(filename)
if generaloutput != nil {
generaloutput.SetText(b)
}
log.Println("ENDED GetText() HOSTNAME =", filename)
}
////////////// connect /////////////////////////
gNode = resWin.Box().NewGroup("")
gNode.NewButton("Update /etc/resolv.conf", func() {
sudo(func() error {
log.Println("set resolv.conf to", filename)
b, _ := packrBox.FindString(filename)
// spew.Dump(b)
b = generaloutput.GetText()
log.Println("Setting /etc/resolv.conf to:\n\n" + b)
f, err := os.Create("/etc/resolv.conf")
if err != nil {
return errors.New("os.Create() /etc/resolv.conf failed")
}
defer f.Close()
w := bufio.NewWriter(f)
n4, err := w.WriteString(b)
log.Println("n4 =", n4)
w.Flush()
return nil
})
})
gNode.NewButton("test ping ipv4", func() {
bash("ping -c 3 -4 google.com")
})
gNode.NewButton("test ping ipv6", func() {
bash("ping -c 3 -6 google.com")
})
gNode.NewButton("set output", func() {
if generaloutput != nil {
generaloutput.SetText("wow")
generaloutput.Margin()
}
})
gNode = resWin.Box().NewGroup("Update")
gNode.NewButton("MakeGroupEdit()", func() {
log.Warn("recreate a gadget for editing the resolv.conf")
//generaloutput = gNode.MakeGroupEdit("resolv.conf:")
})
}