Compare commits
13 Commits
3ce3a39226
...
c16bb5b088
Author | SHA1 | Date |
---|---|---|
|
c16bb5b088 | |
|
5645231c49 | |
|
76699a3102 | |
|
b74c46b031 | |
|
c63132fd4a | |
|
70a7ca6d75 | |
|
53c8c54b15 | |
|
e254a389f1 | |
|
a8285c19c8 | |
|
90f9015ab2 | |
|
058f142127 | |
|
8e2f94c4ac | |
|
0b26e5f1ca |
|
@ -1,3 +1,4 @@
|
|||
control-panel-dns
|
||||
/files/*
|
||||
/*.deb
|
||||
*.swp
|
||||
|
|
40
Makefile
40
Makefile
|
@ -1,5 +1,9 @@
|
|||
run: build
|
||||
./control-panel-dns
|
||||
./control-panel-dns >/tmp/witgui.log.stderr 2>&1
|
||||
|
||||
install:
|
||||
go install -v go.wit.com/control-panel-dns@latest
|
||||
# go install -v git.wit.com/wit/control-panel-dns@latest
|
||||
|
||||
debug: build
|
||||
./control-panel-dns --verbose --verbose-net --gui-debug
|
||||
|
@ -17,6 +21,12 @@ build:
|
|||
# GO111MODULE="off" go get -v -x .
|
||||
GO111MODULE="off" go build -v -o control-panel-dns
|
||||
|
||||
# ./control-panel-dns.v1: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.34' not found (required by ./control-panel-dns.v1)
|
||||
# ./control-panel-dns.v1: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.32' not found (required by ./control-panel-dns.v1)
|
||||
# compiling with CGO disabled means it compiles but then plugins don't load
|
||||
GLIBC_2.34-error:
|
||||
GO111MODULE="off" CGO_ENABLED=0 go build -v -o control-panel-dns
|
||||
|
||||
test:
|
||||
GO111MODULE="off" go test -v
|
||||
|
||||
|
@ -57,3 +67,31 @@ build-with-custom-go.mod:
|
|||
# )
|
||||
# replace github.com/versent/saml2aws/v2 v2.35.0 => github.com/marcottedan/saml2aws/v2 master
|
||||
# replace github.com/versent/saml2aws/v2 => /Users/dmarcotte/git/saml2aws/
|
||||
#
|
||||
check-cert:
|
||||
reset
|
||||
# https://crt.sh/?q=check.lab.wit.org
|
||||
# # https://letsencrypt.org/certificates/
|
||||
# openssl s_client -connect check.lab.wit.org:443 -showcerts
|
||||
openssl s_client -CApath /etc/ssl/certs/ -connect check.lab.wit.org:443 -showcerts
|
||||
# openssl s_client -CApath /etc/ssl/certs/ -connect check.lab.wit.org:443 -showcerts -trace -debug
|
||||
# openssl s_client -CAfile isrgrootx1.pem -connect check.lab.wit.org:443 -showcerts
|
||||
# cat isrgrootx1.pem lets-encrypt-r3.pem > full-chain.pem
|
||||
# full-chain.pem
|
||||
# openssl s_client -CAfile /etc/ssl/certs/wit-full-chain.pem -connect check.lab.wit.org:443 -showcerts
|
||||
|
||||
ssl-cert-hash:
|
||||
openssl x509 -hash -noout -in wit-full-chain.pem
|
||||
# cd /etc/ssl/certs && ln -s wit-full-chain.pem 4042bcee.0
|
||||
openssl x509 -hash -noout -in isrgrootx1.pem
|
||||
openssl x509 -hash -noout -in lets-encrypt-r3.pem
|
||||
|
||||
sudo-cp:
|
||||
sudo cp -a lets-encrypt-r3.pem 8d33f237.0 /etc/ssl/certs/
|
||||
|
||||
go-get:
|
||||
go install -v check.lab.wit.org/gui
|
||||
|
||||
log:
|
||||
reset
|
||||
tail -f /tmp/witgui.* /tmp/guilogfile
|
||||
|
|
1
args.go
1
args.go
|
@ -12,6 +12,7 @@ type LogOptions struct {
|
|||
VerboseDNS bool `arg:"--verbose-dns" help:"debug your dns settings"`
|
||||
LogFile string `help:"write all output to a file"`
|
||||
// User string `arg:"env:USER"`
|
||||
Display string `arg:"env:DISPLAY"`
|
||||
}
|
||||
|
||||
var args struct {
|
||||
|
|
|
@ -0,0 +1,59 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"io"
|
||||
"os"
|
||||
"os/exec"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
|
||||
"github.com/creack/pty"
|
||||
"golang.org/x/term"
|
||||
)
|
||||
|
||||
func test() error {
|
||||
// Create arbitrary command.
|
||||
c := exec.Command("bash")
|
||||
|
||||
// Start the command with a pty.
|
||||
ptmx, err := pty.Start(c)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// Make sure to close the pty at the end.
|
||||
defer func() { _ = ptmx.Close() }() // Best effort.
|
||||
|
||||
// Handle pty size.
|
||||
ch := make(chan os.Signal, 1)
|
||||
signal.Notify(ch, syscall.SIGWINCH)
|
||||
go func() {
|
||||
for range ch {
|
||||
if err := pty.InheritSize(os.Stdin, ptmx); err != nil {
|
||||
log("error resizing pty: %s", err)
|
||||
}
|
||||
}
|
||||
}()
|
||||
ch <- syscall.SIGWINCH // Initial resize.
|
||||
defer func() { signal.Stop(ch); close(ch) }() // Cleanup signals when done.
|
||||
|
||||
// Set stdin in raw mode.
|
||||
oldState, err := term.MakeRaw(int(os.Stdin.Fd()))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer func() { _ = term.Restore(int(os.Stdin.Fd()), oldState) }() // Best effort.
|
||||
|
||||
// Copy stdin to the pty and the pty to stdout.
|
||||
// NOTE: The goroutine will keep reading until the next keystroke before returning.
|
||||
go func() { _, _ = io.Copy(ptmx, os.Stdin) }()
|
||||
_, _ = io.Copy(os.Stdout, ptmx)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func mainBash() {
|
||||
if err := test(); err != nil {
|
||||
log(logError, "exit in mainBash()")
|
||||
exit(err)
|
||||
}
|
||||
}
|
2
dns.go
2
dns.go
|
@ -23,7 +23,7 @@ func (h *Host) verifyETC() bool {
|
|||
func (h *Host) updateIPs(host string) {
|
||||
ips, err := net.LookupIP(host)
|
||||
if err != nil {
|
||||
exit(err)
|
||||
log(logError, "updateIPs failed", err)
|
||||
}
|
||||
for _, ip := range ips {
|
||||
log(host, ip)
|
||||
|
|
|
@ -13,7 +13,8 @@ func watchSysClassNet() {
|
|||
// Create new watcher.
|
||||
watcher, err := fsnotify.NewWatcher()
|
||||
if err != nil {
|
||||
exit(err)
|
||||
log(logError, "watchSysClassNet() failed:", err)
|
||||
return
|
||||
}
|
||||
defer watcher.Close()
|
||||
|
||||
|
@ -41,7 +42,8 @@ func watchSysClassNet() {
|
|||
// Add a path.
|
||||
err = watcher.Add("/tmp")
|
||||
if err != nil {
|
||||
exit(err)
|
||||
log(logError, "watchSysClassNet() watcher.Add() failed:", err)
|
||||
return
|
||||
}
|
||||
|
||||
// Block main goroutine forever.
|
||||
|
|
170
gui.go
170
gui.go
|
@ -2,68 +2,64 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"os/user"
|
||||
"strconv"
|
||||
"strings"
|
||||
"net"
|
||||
"git.wit.org/wit/gui"
|
||||
"git.wit.org/wit/shell"
|
||||
"github.com/davecgh/go-spew/spew"
|
||||
)
|
||||
|
||||
// This initializes the first window
|
||||
func initGUI() {
|
||||
gui.Config.Title = "DNS and IPv6 Control Panel"
|
||||
gui.Config.Width = 640
|
||||
gui.Config.Height = 480
|
||||
gui.Config.Exit = myDefaultExit
|
||||
// This setups up the dns control panel window
|
||||
func setupControlPanelWindow() {
|
||||
me.window = myGui.New2().Window("DNS and IPv6 Control Panel").Standard()
|
||||
me.window.Dump(true)
|
||||
|
||||
me.window = gui.NewWindow()
|
||||
me.window.Dump()
|
||||
sleep(1)
|
||||
addDNSTab("DNS")
|
||||
|
||||
if (args.GuiDebug) {
|
||||
gui.DebugWindow()
|
||||
}
|
||||
gui.ShowDebugValues()
|
||||
}
|
||||
|
||||
func addDNSTab(title string) {
|
||||
var g2 *gui.Node
|
||||
|
||||
me.tab = me.window.NewTab(title)
|
||||
// log("addDemoTab() newNode.Dump")
|
||||
// newNode.Dump()
|
||||
|
||||
me.notes = me.tab.NewGroup("junk")
|
||||
dd := me.notes.NewDropdown("demoCombo2")
|
||||
dd.AddDropdownName("more 1")
|
||||
dd.AddDropdownName("more 2")
|
||||
dd.AddDropdownName("more 3")
|
||||
dd.Custom = func() {
|
||||
s := dd.GetText()
|
||||
output("dd.Custom( dd.GetText() ) =" + s + "\n", true)
|
||||
}
|
||||
me.notes.NewButton("hello", func () {
|
||||
log("world")
|
||||
})
|
||||
|
||||
g2 = me.tab.NewGroup("Real Stuff")
|
||||
|
||||
g2.NewButton("gui.DebugWindow()", func () {
|
||||
gui.DebugWindow()
|
||||
})
|
||||
|
||||
g2.NewButton("Load 'gocui'", func () {
|
||||
// this set the xterm and mate-terminal window title. maybe works generally?
|
||||
fmt.Println("\033]0;" + title + "blah \007")
|
||||
gui.StartS("gocui")
|
||||
gui.Redraw("gocui")
|
||||
})
|
||||
|
||||
g2.NewButton("Network Interfaces", func () {
|
||||
for i, t := range me.ifmap {
|
||||
log("name =", t.iface.Name)
|
||||
log("int =", i, "name =", t.name, t.iface)
|
||||
output("iface = " + t.iface.Name + "\n", true)
|
||||
log("iface = " + t.iface.Name)
|
||||
}
|
||||
})
|
||||
g2.NewButton("Hostname", func () {
|
||||
getHostname()
|
||||
output("FQDN = " + me.fqdn + "\n", true)
|
||||
})
|
||||
g2.NewButton("Actual AAAA", func () {
|
||||
var aaaa []string
|
||||
aaaa = realAAAA()
|
||||
for _, s := range aaaa {
|
||||
output("my actual AAAA = " + s + "\n", true)
|
||||
log("my actual AAAA = ", s)
|
||||
}
|
||||
})
|
||||
|
||||
|
@ -73,7 +69,15 @@ func addDNSTab(title string) {
|
|||
g2.NewButton("os.User()", func () {
|
||||
user, _ := user.Current()
|
||||
spew.Dump(user)
|
||||
log("os.Getuid =", os.Getuid())
|
||||
log("os.Getuid =", user.Username, os.Getuid())
|
||||
if (me.uid != nil) {
|
||||
me.uid.SetText(user.Username + " (" + strconv.Itoa(os.Getuid()) + ")")
|
||||
}
|
||||
})
|
||||
g2.NewButton("dig +trace", func () {
|
||||
o := shell.Run("dig +trace +noadditional DS " + me.hostname + " @8.8.8.8")
|
||||
log(o)
|
||||
// log(o)
|
||||
})
|
||||
g2.NewButton("Example_listLink()", func () {
|
||||
Example_listLink()
|
||||
|
@ -81,16 +85,6 @@ func addDNSTab(title string) {
|
|||
g2.NewButton("Escalate()", func () {
|
||||
Escalate()
|
||||
})
|
||||
g2.NewButton("pprof(goroutine)", func () {
|
||||
loggo()
|
||||
// panic("correctly inside of gui goroutine (goroutine 1?)")
|
||||
})
|
||||
g2.NewButton("gui.DebugWindow()", func () {
|
||||
gui.DebugWindow()
|
||||
})
|
||||
g2.NewButton("NewCheckbox(test)", func () {
|
||||
me.notes.NewCheckbox("test")
|
||||
})
|
||||
g2.NewButton("LookupAddr(<raw ipv6>) == fire from /etc/hosts", func () {
|
||||
host, err := net.LookupAddr("2600:1700:afd5:6000:b26e:bfff:fe80:3c52")
|
||||
if err != nil {
|
||||
|
@ -120,25 +114,41 @@ func myDefaultExit(n *gui.Node) {
|
|||
|
||||
func nsupdateGroup(w *gui.Node) {
|
||||
g := w.NewGroup("dns update")
|
||||
g.NewLabel("UID = " + me.user)
|
||||
g.NewButton("DNS AAAA", func () {
|
||||
var aaaa []string
|
||||
var out string
|
||||
h := me.fqdn
|
||||
// h := "fire.lab.wit.org"
|
||||
aaaa = dnsAAAA(h)
|
||||
log(SPEW, me)
|
||||
if (aaaa == nil) {
|
||||
out += "There are no DNS AAAA records for hostname: " + h + "\n"
|
||||
}
|
||||
for _, s := range aaaa {
|
||||
out += "host " + h + " DNS AAAA = " + s + "\n"
|
||||
}
|
||||
})
|
||||
g.NewButton("dig +trace", func () {
|
||||
o := shell.Run("dig +trace +noadditional DS " + me.fqdn + " @8.8.8.8")
|
||||
output(o, false)
|
||||
// log(o)
|
||||
|
||||
grid := g.NewGrid("gridnuts", 2, 2)
|
||||
|
||||
grid.SetNext(1,1)
|
||||
grid.NewLabel("hostname =")
|
||||
me.fqdn = grid.NewLabel("?")
|
||||
me.hostname = ""
|
||||
|
||||
grid.NewLabel("UID =")
|
||||
me.uid = grid.NewLabel("?")
|
||||
|
||||
grid.NewLabel("DNS AAAA =")
|
||||
me.DnsAAAA = grid.NewLabel("?")
|
||||
|
||||
grid.NewLabel("DNS A =")
|
||||
me.DnsA = grid.NewLabel("?")
|
||||
|
||||
grid.NewLabel("IPv4 =")
|
||||
me.IPv4 = grid.NewLabel("?")
|
||||
|
||||
grid.NewLabel("IPv6 =")
|
||||
me.IPv6 = grid.NewLabel("?")
|
||||
|
||||
grid.NewLabel("interfaces =")
|
||||
me.Interfaces = grid.NewCombobox("Interfaces")
|
||||
|
||||
grid.NewLabel("DNS Status =")
|
||||
me.DnsStatus = grid.NewLabel("unknown")
|
||||
|
||||
g.NewButton("Update DNS", func () {
|
||||
log("updateDNS()")
|
||||
updateDNS()
|
||||
me.tab.Margin()
|
||||
me.tab.Pad()
|
||||
grid.Pad()
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -150,5 +160,51 @@ func output(s string, a bool) {
|
|||
outJunk = s
|
||||
}
|
||||
me.output.SetText(outJunk)
|
||||
//log(outJunk)
|
||||
log(outJunk)
|
||||
}
|
||||
|
||||
func updateDNS() {
|
||||
var aaaa []string
|
||||
h := me.hostname
|
||||
if (h == "") {
|
||||
h = "unknown.lab.wit.org"
|
||||
// h = "hpdevone.lab.wit.org"
|
||||
}
|
||||
log("dnsAAAA()()")
|
||||
aaaa = dnsAAAA(h)
|
||||
log("dnsAAAA()()")
|
||||
log(SPEW, me)
|
||||
if (aaaa == nil) {
|
||||
log("There are no DNS AAAA records for hostname: ", h)
|
||||
}
|
||||
var broken int = 0
|
||||
var all string
|
||||
for _, s := range aaaa {
|
||||
log("host", h, "DNS AAAA =", s)
|
||||
all += s + "\n"
|
||||
if ( me.ipmap[s] == nil) {
|
||||
log("THIS IS THE WRONG AAAA DNS ENTRY: host", h, "DNS AAAA =", s)
|
||||
broken = 2
|
||||
} else {
|
||||
if (broken == 0) {
|
||||
broken = 1
|
||||
}
|
||||
}
|
||||
}
|
||||
all = strings.TrimSpace(all)
|
||||
me.DnsAAAA.SetText(all)
|
||||
if (broken == 1) {
|
||||
me.DnsStatus.SetText("WORKING")
|
||||
} else {
|
||||
me.DnsStatus.SetText("BROKEN")
|
||||
log("Need to run go-nsupdate here")
|
||||
}
|
||||
|
||||
user, _ := user.Current()
|
||||
spew.Dump(user)
|
||||
log("os.Getuid =", user.Username, os.Getuid())
|
||||
if (me.uid != nil) {
|
||||
me.uid.SetText(user.Username + " (" + strconv.Itoa(os.Getuid()) + ")")
|
||||
}
|
||||
log("updateDNS() END")
|
||||
}
|
||||
|
|
|
@ -1,57 +0,0 @@
|
|||
#!/bin/bash -x
|
||||
|
||||
## Tunnel ID: 818143
|
||||
# Creation Date:Feb 12, 2023
|
||||
# Description:
|
||||
# IPv6 Tunnel Endpoints
|
||||
# Server IPv4 Address:184.105.253.14
|
||||
# Server IPv6 Address:2001:470:1f10:2a::1/64
|
||||
# Client IPv4 Address:74.87.91.117
|
||||
# Client IPv6 Address:2001:470:1f10:2a::2/64
|
||||
# Routed IPv6 Prefixes
|
||||
# Routed /64:2001:470:1f11:2a::/64
|
||||
# Routed /48:Assign /48
|
||||
# DNS Resolvers
|
||||
# Anycast IPv6 Caching Nameserver:2001:470:20::2
|
||||
# Anycast IPv4 Caching Nameserver:74.82.42.42
|
||||
# DNS over HTTPS / DNS over TLS:ordns.he.net
|
||||
# rDNS DelegationsEdit
|
||||
# rDNS Delegated NS1:
|
||||
# rDNS Delegated NS2:
|
||||
# rDNS Delegated NS3:
|
||||
# rDNS Delegated NS4:
|
||||
# rDNS Delegated NS5:
|
||||
|
||||
# ifconfig sit0 up
|
||||
# ifconfig sit0 inet6 tunnel ::184.105.253.14
|
||||
# ifconfig sit1 up
|
||||
# ifconfig sit1 inet6 add 2001:470:1f10:2a::2/64
|
||||
# route -A inet6 add ::/0 dev sit1
|
||||
|
||||
if [ "$1" = "down" ]; then
|
||||
ip tunnel del he-ipv6
|
||||
rmmod sit
|
||||
exit
|
||||
fi
|
||||
|
||||
if [ "$1" = "ping" ]; then
|
||||
ping -c 3 2001:470:1f10:13d::1
|
||||
exit
|
||||
fi
|
||||
|
||||
modprobe ipv6
|
||||
ip tunnel add he-ipv6 mode sit remote 184.105.253.14 local 40.132.180.131 ttl 255
|
||||
ip link set he-ipv6 up
|
||||
ip addr add 2001:470:1f10:13d::2/64 dev he-ipv6
|
||||
ip route add ::/0 dev he-ipv6
|
||||
ip -f inet6 addr
|
||||
ifconfig he-ipv6 mtu 1460
|
||||
|
||||
|
||||
# old attempt from the something or pabtz hotel
|
||||
# modprobe ipv6
|
||||
# ip tunnel add he-ipv6 mode sit remote 184.105.253.14 local 74.87.91.117 ttl 255
|
||||
# ip link set he-ipv6 up
|
||||
# ip addr add 2001:470:1f10:2a::2/64 dev he-ipv6
|
||||
# ip route add ::/0 dev he-ipv6
|
||||
# ip -f inet6 addr
|
13
hostname.go
13
hostname.go
|
@ -18,13 +18,20 @@ import "git.wit.org/jcarr/dnssecsocket"
|
|||
|
||||
func getHostname() {
|
||||
var err error
|
||||
me.fqdn, err = fqdn.FqdnHostname()
|
||||
var s string = "gui.Label == nil"
|
||||
s, err = fqdn.FqdnHostname()
|
||||
if (err != nil) {
|
||||
log("FQDN hostname error =", err)
|
||||
exit()
|
||||
return
|
||||
}
|
||||
log("FQDN hostname is", me.fqdn)
|
||||
if (me.fqdn != nil) {
|
||||
if (me.hostname != s) {
|
||||
me.fqdn.SetText(s)
|
||||
me.hostname = s
|
||||
me.changed = true
|
||||
}
|
||||
}
|
||||
log("FQDN =", s)
|
||||
}
|
||||
|
||||
func dnsAAAA(s string) []string {
|
||||
|
|
125
log.go
125
log.go
|
@ -1,123 +1,30 @@
|
|||
//
|
||||
// version v1.1
|
||||
//
|
||||
// I like things to be easy.
|
||||
//
|
||||
// this means all the log settings are in one place. it should allow
|
||||
// things to be over-ridden externally to the library
|
||||
// but still allow command line --args to pass debugging settings
|
||||
//
|
||||
// I also have a generic sleep() and exit() in here because it's simple
|
||||
//
|
||||
// Usage:
|
||||
//
|
||||
// log("something", foo, bar)
|
||||
// var DEBUG bool = true
|
||||
// log(DEBUG, "something else", someOtherVariable) # if DEBUG == false, return doing nothing
|
||||
// log(SPEW, "something else", someOtherVariable) # this get's sent to spew.Dump(). Very useful for debugging!
|
||||
//
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"runtime"
|
||||
"runtime/pprof"
|
||||
golog "log"
|
||||
"time"
|
||||
"reflect"
|
||||
"github.com/davecgh/go-spew/spew"
|
||||
// "net"
|
||||
witlog "git.wit.org/wit/gui/log"
|
||||
)
|
||||
|
||||
var LOGOFF bool = false // turn this off, all logging stops
|
||||
var WARN bool
|
||||
var INFO bool
|
||||
// various debugging flags
|
||||
var logNow bool = true // useful for active development
|
||||
var logError bool = true
|
||||
var logWarn bool = false
|
||||
var logInfo bool = false
|
||||
var logVerbose bool = false
|
||||
|
||||
type spewt struct {
|
||||
a bool
|
||||
}
|
||||
var SPEW witlog.Spewt
|
||||
|
||||
var SPEW spewt
|
||||
|
||||
|
||||
/*
|
||||
sleep() # you know what this does? sleeps for 1 second. yep. dump. easy.
|
||||
sleep(.1) # you know what this does? yes, it sleeps for 1/10th of a second
|
||||
*/
|
||||
func sleep(a ...any) {
|
||||
if (a == nil) {
|
||||
time.Sleep(time.Second)
|
||||
return
|
||||
}
|
||||
|
||||
log(args.Verbose, "sleep", a[0])
|
||||
|
||||
switch a[0].(type) {
|
||||
case int:
|
||||
time.Sleep(time.Duration(a[0].(int)) * time.Second)
|
||||
case float64:
|
||||
time.Sleep(time.Duration(a[0].(float64) * 1000) * time.Millisecond)
|
||||
default:
|
||||
log("sleep a[0], type = ", a[0], reflect.TypeOf(a[0]))
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
exit() # yep. exits. I guess everything must be fine
|
||||
exit(3) # I guess 3 it is then
|
||||
exit("dont like apples") # ok. I'll make a note of that
|
||||
*/
|
||||
func exit(a ...any) {
|
||||
log("exit", a)
|
||||
//if (a) {
|
||||
// os.Exit(a)
|
||||
//}
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
/*
|
||||
I've spent, am spending, too much time thinking about 'logging'. 'log', 'logrus', 'zap', whatever.
|
||||
I'm not twitter. i don't give a fuck about how many nanoseconds it takes to log. Anyway, this
|
||||
implementation is probably faster than all of those because you just set one bool to FALSE
|
||||
and it all stops.
|
||||
Sometimes I need to capture to stdout, sometimes stdout can't
|
||||
work because it doesn't exist for the user. This whole thing is a PITA. Then it's spread
|
||||
over 8 million references in every .go file. I'm tapping out and putting
|
||||
it in one place. here it is. Also, this makes having debug levels really fucking easy.
|
||||
You can define whatever level of logging you want from anywhere (command line) etc.
|
||||
|
||||
log() # doesn't do anything
|
||||
log(stuff) # sends it to whatever log you define in a single place. here is the place
|
||||
*/
|
||||
// var log interface{}
|
||||
|
||||
func log(a ...any) {
|
||||
if (LOGOFF) {
|
||||
return
|
||||
witlog.Where = "wit/gui"
|
||||
witlog.Log(a...)
|
||||
}
|
||||
|
||||
if (a == nil) {
|
||||
return
|
||||
}
|
||||
var blah bool
|
||||
if (reflect.TypeOf(a[0]) == reflect.TypeOf(blah)) {
|
||||
if (a[0] == false) {
|
||||
return
|
||||
}
|
||||
a = a[1:]
|
||||
func sleep(a ...any) {
|
||||
witlog.Sleep(a...)
|
||||
}
|
||||
|
||||
if (reflect.TypeOf(a[0]) == reflect.TypeOf(SPEW)) {
|
||||
a = a[1:]
|
||||
// spew.Dump(a)
|
||||
scs := spew.ConfigState{MaxDepth: 1}
|
||||
scs.Dump(a)
|
||||
return
|
||||
}
|
||||
|
||||
golog.Println(a...)
|
||||
}
|
||||
|
||||
func loggo() {
|
||||
pprof.Lookup("goroutine").WriteTo(os.Stdout, 1)
|
||||
log("runtime.NumGoroutine() = ", runtime.NumGoroutine())
|
||||
func exit(a ...any) {
|
||||
log(logError, "got to log() exit")
|
||||
witlog.Exit(a...)
|
||||
}
|
||||
|
|
45
main.go
45
main.go
|
@ -1,17 +1,19 @@
|
|||
// GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007
|
||||
// Copyright (c) 2023 WIT.COM, Inc.
|
||||
// This is a control panel for DNS
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"runtime"
|
||||
// "net"
|
||||
"time"
|
||||
arg "github.com/alexflint/go-arg"
|
||||
"git.wit.org/wit/gui"
|
||||
)
|
||||
|
||||
var p *arg.Parser
|
||||
var myGui *gui.Node
|
||||
|
||||
func main() {
|
||||
p = arg.MustParse(&args)
|
||||
|
@ -23,7 +25,6 @@ func main() {
|
|||
me.ifmap = make(map[int]*IFtype)
|
||||
me.dnsTTL = 5 // recheck DNS is working every 2 minutes // TODO: watch rx packets?
|
||||
|
||||
go checkNetworkChanges()
|
||||
|
||||
log()
|
||||
log(true, "this is true")
|
||||
|
@ -32,24 +33,31 @@ func main() {
|
|||
sleep(.3)
|
||||
sleep(.2)
|
||||
sleep("done scanning net")
|
||||
// exit("done scanning net")
|
||||
|
||||
// Example_listLink()
|
||||
// exit()
|
||||
|
||||
log("Toolkit = ", args.Toolkit)
|
||||
// gui.InitPlugins([]string{"andlabs"})
|
||||
gui.SetDebug(args.GuiDebug)
|
||||
gui.Main(initGUI)
|
||||
// gui.SetDebug(true)
|
||||
// myGui = gui.Main(initGUI)
|
||||
myGui = gui.Start()
|
||||
sleep(1)
|
||||
setupControlPanelWindow()
|
||||
sleep(1)
|
||||
myGui.LoadPlugin("gocui")
|
||||
// gui.Redraw("gocui")
|
||||
sleep(1)
|
||||
checkNetworkChanges()
|
||||
}
|
||||
|
||||
/*
|
||||
Poll for changes to the networking settings
|
||||
*/
|
||||
func checkNetworkChanges() {
|
||||
var ttl int = 3
|
||||
var ttl int = 0
|
||||
var ttlsleep int = 5
|
||||
for {
|
||||
sleep(1)
|
||||
sleep(ttlsleep)
|
||||
ttl -= 1
|
||||
if (ttl < 0) {
|
||||
if (runtime.GOOS == "linux") {
|
||||
|
@ -64,16 +72,29 @@ func checkNetworkChanges() {
|
|||
|
||||
// Run this every once and a while
|
||||
func dnsTTL() {
|
||||
output("FQDN = " + me.fqdn + "\n", false)
|
||||
me.changed = false
|
||||
log("FQDN =", me.fqdn.GetText())
|
||||
getHostname()
|
||||
scanInterfaces()
|
||||
for i, t := range me.ifmap {
|
||||
output(strconv.Itoa(i) + " iface = " + t.iface.Name + "\n", true)
|
||||
log(strconv.Itoa(i) + " iface = " + t.iface.Name)
|
||||
}
|
||||
|
||||
var aaaa []string
|
||||
aaaa = realAAAA()
|
||||
var all string
|
||||
for _, s := range aaaa {
|
||||
output("my actual AAAA = " + s + "\n", true)
|
||||
log("my actual AAAA = ",s)
|
||||
all += s + "\n"
|
||||
}
|
||||
// me.IPv6.SetText(all)
|
||||
|
||||
if (me.changed) {
|
||||
stamp := time.Now().Format("2006/01/02 15:04:05")
|
||||
s := stamp + " Network things changed"
|
||||
log(logError, "Network things changed on", stamp)
|
||||
updateDNS()
|
||||
me.output.SetText(s)
|
||||
|
||||
}
|
||||
// loggo()
|
||||
}
|
||||
|
|
39
net.go
39
net.go
|
@ -78,7 +78,11 @@ func checkInterface(i net.Interface) {
|
|||
me.ifmap[i.Index] = new(IFtype)
|
||||
me.ifmap[i.Index].gone = false
|
||||
me.ifmap[i.Index].iface = &i
|
||||
me.ipchange = true
|
||||
me.changed = true
|
||||
if (me.Interfaces != nil) {
|
||||
me.Interfaces.AddText(i.Name)
|
||||
me.Interfaces.SetText(i.Name)
|
||||
}
|
||||
return
|
||||
}
|
||||
me.ifmap[i.Index].gone = false
|
||||
|
@ -86,7 +90,11 @@ func checkInterface(i net.Interface) {
|
|||
if (val.iface.Name != i.Name) {
|
||||
log(val.iface.Name, "has changed to it's name to", i.Name)
|
||||
me.ifmap[i.Index].iface = &i
|
||||
me.ipchange = true
|
||||
me.changed = true
|
||||
if (me.Interfaces != nil) {
|
||||
me.Interfaces.AddText(i.Name)
|
||||
me.Interfaces.SetText(i.Name)
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
|
@ -156,9 +164,15 @@ func checkIP(ip *net.IPNet, i net.Interface) bool {
|
|||
me.ipmap[realip].ipv6 = true
|
||||
me.ipmap[realip].ipv4 = false
|
||||
t = "IPv6"
|
||||
if (me.IPv6 != nil) {
|
||||
me.IPv6.SetText(realip)
|
||||
}
|
||||
} else {
|
||||
me.ipmap[realip].ipv6 = false
|
||||
me.ipmap[realip].ipv4 = true
|
||||
if (me.IPv4 != nil) {
|
||||
me.IPv4.SetText(realip)
|
||||
}
|
||||
}
|
||||
if (IsReal(&ip.IP)) {
|
||||
log("\tIP is Real ", t, i.Index, i.Name, realip)
|
||||
|
@ -173,7 +187,7 @@ func checkIP(ip *net.IPNet, i net.Interface) bool {
|
|||
}
|
||||
|
||||
func scanInterfaces() {
|
||||
me.ipchange = false
|
||||
me.changed = false
|
||||
ifaces, _ := net.Interfaces()
|
||||
// me.ifnew = ifaces
|
||||
log(DEBUGNET, SPEW, ifaces)
|
||||
|
@ -199,6 +213,23 @@ func scanInterfaces() {
|
|||
}
|
||||
}
|
||||
deleteChanges()
|
||||
var all4 string
|
||||
var all6 string
|
||||
for s, t := range me.ipmap {
|
||||
if (t.ipv4) {
|
||||
all4 += s + "\n"
|
||||
log("IPv4 =", s)
|
||||
} else if (t.ipv6) {
|
||||
all6 += s + "\n"
|
||||
log("IPv6 =", s)
|
||||
} else {
|
||||
log("???? =", s)
|
||||
}
|
||||
}
|
||||
all4 = strings.TrimSpace(all4)
|
||||
all6 = strings.TrimSpace(all6)
|
||||
me.IPv4.SetText(all4)
|
||||
me.IPv6.SetText(all6)
|
||||
}
|
||||
|
||||
// delete network interfaces and ip addresses from the gui
|
||||
|
@ -207,6 +238,7 @@ func deleteChanges() {
|
|||
if (t.gone) {
|
||||
log("DELETE int =", i, "name =", t.name, t.iface)
|
||||
delete(me.ifmap, i)
|
||||
me.changed = true
|
||||
}
|
||||
t.gone = true
|
||||
}
|
||||
|
@ -217,6 +249,7 @@ func deleteChanges() {
|
|||
log("DELETE name =", s, "iface =", t.iface)
|
||||
log("DELETE name =", s, "ip =", t.ip)
|
||||
delete(me.ipmap, s)
|
||||
me.changed = true
|
||||
}
|
||||
t.gone = true
|
||||
}
|
||||
|
|
|
@ -9,7 +9,8 @@ func Example_listLink() {
|
|||
// Dial a connection to the rtnetlink socket
|
||||
conn, err := rtnetlink.Dial(nil)
|
||||
if err != nil {
|
||||
exit(err)
|
||||
log(logError, "Example_listLink() failed", err)
|
||||
return
|
||||
}
|
||||
defer conn.Close()
|
||||
|
||||
|
|
12
structs.go
12
structs.go
|
@ -12,17 +12,25 @@ var me Host
|
|||
type Host struct {
|
||||
hostname string // mirrors
|
||||
domainname string // kernel.org
|
||||
fqdn string // mirrors.kernel.org
|
||||
// fqdn string // mirrors.kernel.org
|
||||
dnsTTL int // Recheck DNS is working every TTL (in seconds)
|
||||
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
|
||||
ipchange bool // set to true if things change
|
||||
window *gui.Node // the main window
|
||||
tab *gui.Node // the main dns tab
|
||||
notes *gui.Node // using this to put notes here
|
||||
output *gui.Node // Textbox for dumping output
|
||||
uid *gui.Node // user
|
||||
fqdn *gui.Node // display the full hostname
|
||||
IPv4 *gui.Node // show valid IPv4 addresses
|
||||
IPv6 *gui.Node // show valid IPv6 addresses
|
||||
Interfaces *gui.Node // Interfaces
|
||||
DnsAAAA *gui.Node // the actual DNS AAAA results
|
||||
DnsA *gui.Node // the actual DNS A results (ignore for status since mostly never happens?)
|
||||
DnsStatus *gui.Node // the current state of DNS
|
||||
}
|
||||
|
||||
type IPtype struct {
|
||||
|
|
3
unix.go
3
unix.go
|
@ -24,6 +24,7 @@ func Escalate() {
|
|||
cmd.Stderr = os.Stderr
|
||||
err := cmd.Run()
|
||||
if err != nil {
|
||||
log(logError, "exit in Escalate()")
|
||||
exit(err)
|
||||
}
|
||||
}
|
||||
|
@ -45,7 +46,7 @@ func DumpPublicDNSZone(zone string) {
|
|||
func dumpIPs(host string) {
|
||||
ips, err := net.LookupIP(host)
|
||||
if err != nil {
|
||||
exit(err)
|
||||
log(logError, "dumpIPs() failed:", err)
|
||||
}
|
||||
for _, ip := range ips {
|
||||
log(host, ip)
|
||||
|
|
Loading…
Reference in New Issue