wit-debian-gui/window-resolv.go

98 lines
2.1 KiB
Go
Raw Normal View History

2021-11-02 23:44:28 -05:00
package main
import (
"bufio"
"errors"
"os"
"strings"
"go.wit.com/gui"
"go.wit.com/lib/gadgets"
"go.wit.com/log"
)
2021-11-02 23:44:28 -05:00
var filename string = "resolv-1-1-1-1.conf"
var generaloutput *gui.Node
var resWin *gadgets.BasicWindow
2021-11-02 23:44:28 -05:00
func resolvWindow() {
if resWin != nil {
resWin.Toggle()
return
}
resWin = gadgets.NewBasicWindow(myGui, "resolv.conf Window")
2021-11-02 23:44:28 -05:00
////////////// filename /////////////////////////
gNode := resWin.Box().NewGroup("filename")
2021-11-02 23:44:28 -05:00
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)
}
2021-11-02 23:44:28 -05:00
resolvNode.SetText(filename)
resolvNode.Custom = func() {
2021-11-02 23:44:28 -05:00
log.Println("STARTED HOSTNAME")
filename = resolvNode.GetText()
b, _ := packrBox.FindString(filename)
if generaloutput != nil {
generaloutput.SetText(b)
}
2021-11-02 23:44:28 -05:00
log.Println("ENDED GetText() HOSTNAME =", filename)
}
////////////// connect /////////////////////////
gNode = resWin.Box().NewGroup("")
2021-11-02 23:44:28 -05:00
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)
2021-11-02 23:44:28 -05:00
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")
2021-11-02 23:44:28 -05:00
})
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:")
})
2021-11-02 23:44:28 -05:00
}