2021-11-02 23:44:28 -05:00
|
|
|
package main
|
|
|
|
|
2024-01-05 12:13:21 -06:00
|
|
|
import (
|
|
|
|
"bufio"
|
|
|
|
"errors"
|
2024-01-24 18:24:38 -06:00
|
|
|
"os"
|
|
|
|
"strings"
|
2024-01-05 12:13:21 -06:00
|
|
|
|
2024-01-24 18:24:38 -06:00
|
|
|
"go.wit.com/gui"
|
|
|
|
"go.wit.com/lib/gadgets"
|
2024-01-05 12:13:21 -06:00
|
|
|
"go.wit.com/log"
|
|
|
|
)
|
2021-11-02 23:44:28 -05:00
|
|
|
|
2021-11-03 22:41:01 -05:00
|
|
|
var filename string = "resolv-1-1-1-1.conf"
|
2021-11-04 01:13:13 -05:00
|
|
|
var generaloutput *gui.Node
|
2021-11-03 22:20:49 -05:00
|
|
|
|
2024-01-05 12:13:21 -06:00
|
|
|
var resWin *gadgets.BasicWindow
|
2021-11-02 23:44:28 -05:00
|
|
|
|
2024-01-05 12:13:21 -06:00
|
|
|
func resolvWindow() {
|
2024-01-24 18:24:38 -06:00
|
|
|
if resWin != nil {
|
2024-01-05 12:13:21 -06:00
|
|
|
resWin.Toggle()
|
|
|
|
return
|
|
|
|
}
|
2024-01-24 18:24:38 -06:00
|
|
|
resWin = gadgets.NewBasicWindow(myGui, "resolv.conf Window")
|
2021-11-02 23:44:28 -05:00
|
|
|
|
2024-01-24 18:24:38 -06:00
|
|
|
////////////// filename /////////////////////////
|
2024-01-05 12:13:21 -06:00
|
|
|
gNode := resWin.Box().NewGroup("filename")
|
2021-11-02 23:44:28 -05:00
|
|
|
|
2021-11-03 22:20:49 -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")
|
|
|
|
|
2024-01-05 12:13:21 -06:00
|
|
|
resolvNode := gNode.NewCombobox("test")
|
|
|
|
for _, thing := range tmp {
|
|
|
|
resolvNode.AddText(thing)
|
|
|
|
}
|
2021-11-02 23:44:28 -05:00
|
|
|
|
2021-11-03 22:41:01 -05:00
|
|
|
resolvNode.SetText(filename)
|
2024-01-24 18:24:38 -06:00
|
|
|
resolvNode.Custom = func() {
|
2021-11-02 23:44:28 -05:00
|
|
|
log.Println("STARTED HOSTNAME")
|
2021-11-03 22:20:49 -05:00
|
|
|
filename = resolvNode.GetText()
|
2021-11-04 02:49:12 -05:00
|
|
|
b, _ := packrBox.FindString(filename)
|
2024-01-24 18:24:38 -06:00
|
|
|
if generaloutput != nil {
|
2021-11-04 02:49:12 -05:00
|
|
|
generaloutput.SetText(b)
|
|
|
|
}
|
2021-11-02 23:44:28 -05:00
|
|
|
log.Println("ENDED GetText() HOSTNAME =", filename)
|
|
|
|
}
|
|
|
|
|
2024-01-24 18:24:38 -06:00
|
|
|
////////////// connect /////////////////////////
|
2024-01-05 12:13:21 -06:00
|
|
|
gNode = resWin.Box().NewGroup("")
|
2021-11-02 23:44:28 -05:00
|
|
|
|
2024-01-24 18:24:38 -06:00
|
|
|
gNode.NewButton("Update /etc/resolv.conf", func() {
|
|
|
|
sudo(func() error {
|
|
|
|
log.Println("set resolv.conf to", filename)
|
2021-11-03 22:20:49 -05:00
|
|
|
b, _ := packrBox.FindString(filename)
|
|
|
|
// spew.Dump(b)
|
2021-11-04 02:49:12 -05:00
|
|
|
b = generaloutput.GetText()
|
|
|
|
|
|
|
|
log.Println("Setting /etc/resolv.conf to:\n\n" + b)
|
2021-11-02 23:44:28 -05:00
|
|
|
|
2021-11-03 22:20:49 -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
|
|
|
|
})
|
|
|
|
})
|
2024-01-24 18:24:38 -06:00
|
|
|
gNode.NewButton("test ping ipv4", func() {
|
2021-11-04 02:49:12 -05:00
|
|
|
bash("ping -c 3 -4 google.com")
|
2021-11-03 22:20:49 -05:00
|
|
|
})
|
2024-01-24 18:24:38 -06:00
|
|
|
gNode.NewButton("test ping ipv6", func() {
|
2021-11-04 02:49:12 -05:00
|
|
|
bash("ping -c 3 -6 google.com")
|
2021-11-02 23:44:28 -05:00
|
|
|
})
|
2021-11-04 01:13:13 -05:00
|
|
|
|
2024-01-24 18:24:38 -06:00
|
|
|
gNode.NewButton("set output", func() {
|
|
|
|
if generaloutput != nil {
|
2021-11-04 01:13:13 -05:00
|
|
|
generaloutput.SetText("wow")
|
2024-01-05 12:13:21 -06:00
|
|
|
generaloutput.Margin()
|
2021-11-04 01:13:13 -05:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2024-01-05 12:13:21 -06:00
|
|
|
gNode = resWin.Box().NewGroup("Update")
|
2024-01-24 18:24:38 -06:00
|
|
|
gNode.NewButton("MakeGroupEdit()", func() {
|
2024-01-05 12:13:21 -06:00
|
|
|
log.Warn("recreate a gadget for editing the resolv.conf")
|
|
|
|
//generaloutput = gNode.MakeGroupEdit("resolv.conf:")
|
|
|
|
})
|
2021-11-02 23:44:28 -05:00
|
|
|
}
|