use 'go.wit.com/log'
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
138f72728c
commit
c1a00fcc1a
23
args.go
23
args.go
|
@ -19,24 +19,45 @@ var args struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
var NET log.LogFlag
|
var NET log.LogFlag
|
||||||
|
var NOW log.LogFlag
|
||||||
|
var PROC log.LogFlag
|
||||||
var SPEW log.LogFlag
|
var SPEW log.LogFlag
|
||||||
|
var CHANGE log.LogFlag
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
arg.MustParse(&args)
|
arg.MustParse(&args)
|
||||||
// fmt.Println(args.Foo, args.Bar, args.User)
|
// fmt.Println(args.Foo, args.Bar, args.User)
|
||||||
|
|
||||||
|
NOW.B = false
|
||||||
|
NOW.Name = "NOW"
|
||||||
|
NOW.Subsystem = "cpdns"
|
||||||
|
NOW.Desc = "temp debugging stuff"
|
||||||
|
NOW.Register()
|
||||||
|
|
||||||
NET.B = false
|
NET.B = false
|
||||||
NET.Name = "NET"
|
NET.Name = "NET"
|
||||||
NET.Subsystem = "cpdns"
|
NET.Subsystem = "cpdns"
|
||||||
NET.Desc = "Network logging"
|
NET.Desc = "Network logging"
|
||||||
NET.Register()
|
NET.Register()
|
||||||
|
|
||||||
|
PROC.B = false
|
||||||
|
PROC.Name = "PROC"
|
||||||
|
PROC.Subsystem = "cpdns"
|
||||||
|
PROC.Desc = "/proc logging"
|
||||||
|
PROC.Register()
|
||||||
|
|
||||||
SPEW.B = false
|
SPEW.B = false
|
||||||
SPEW.Name = "SPEW"
|
SPEW.Name = "SPEW"
|
||||||
SPEW.Subsystem = "cpdns"
|
SPEW.Subsystem = "cpdns"
|
||||||
SPEW.Desc = "spew logging"
|
SPEW.Desc = "spew logging"
|
||||||
SPEW.Register()
|
SPEW.Register()
|
||||||
|
|
||||||
|
CHANGE.B = false
|
||||||
|
CHANGE.Name = "CHANGE"
|
||||||
|
CHANGE.Subsystem = "cpdns"
|
||||||
|
CHANGE.Desc = "show droplet state changes"
|
||||||
|
CHANGE.Register()
|
||||||
|
|
||||||
if debugger.ArgDebug() {
|
if debugger.ArgDebug() {
|
||||||
log.Log(true, "INIT() gui debug == true")
|
log.Log(true, "INIT() gui debug == true")
|
||||||
} else {
|
} else {
|
||||||
|
@ -50,5 +71,5 @@ func init() {
|
||||||
me.artificialS = "blah"
|
me.artificialS = "blah"
|
||||||
log.Log(true, "init() me.artificialSleep =", me.artificialSleep)
|
log.Log(true, "init() me.artificialSleep =", me.artificialSleep)
|
||||||
log.Log(true, "init() me.artificialS =", me.artificialS)
|
log.Log(true, "init() me.artificialS =", me.artificialS)
|
||||||
sleep(me.artificialSleep)
|
log.Sleep(me.artificialSleep)
|
||||||
}
|
}
|
||||||
|
|
7
bash.go
7
bash.go
|
@ -2,7 +2,6 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io"
|
"io"
|
||||||
"log"
|
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
|
@ -10,6 +9,8 @@ import (
|
||||||
|
|
||||||
"github.com/creack/pty"
|
"github.com/creack/pty"
|
||||||
"golang.org/x/term"
|
"golang.org/x/term"
|
||||||
|
|
||||||
|
"go.wit.com/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
func test() error {
|
func test() error {
|
||||||
|
@ -54,7 +55,7 @@ func test() error {
|
||||||
|
|
||||||
func mainBash() {
|
func mainBash() {
|
||||||
if err := test(); err != nil {
|
if err := test(); err != nil {
|
||||||
debug(LogError, "exit in mainBash()")
|
log.Error(err, "exit in mainBash()")
|
||||||
exit(err)
|
log.Exit(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
12
dns.go
12
dns.go
|
@ -5,10 +5,10 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"log"
|
|
||||||
"net"
|
"net"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"go.wit.com/log"
|
||||||
"go.wit.com/shell"
|
"go.wit.com/shell"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@ func (h *Host) verifyETC() bool {
|
||||||
func (h *Host) updateIPs(host string) {
|
func (h *Host) updateIPs(host string) {
|
||||||
ips, err := net.LookupIP(host)
|
ips, err := net.LookupIP(host)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
debug(LogError, "updateIPs failed", err)
|
log.Error(err, "updateIPs failed")
|
||||||
}
|
}
|
||||||
for _, ip := range ips {
|
for _, ip := range ips {
|
||||||
log.Println(host, ip)
|
log.Println(host, ip)
|
||||||
|
@ -93,7 +93,7 @@ func lookupNS(domain string) {
|
||||||
for _, server := range servers {
|
for _, server := range servers {
|
||||||
server = strings.TrimRight(server, ".")
|
server = strings.TrimRight(server, ".")
|
||||||
if (me.nsmap[server] != domain) {
|
if (me.nsmap[server] != domain) {
|
||||||
debug(LogChange, "lookupNS() domain", domain, "has NS", server)
|
log.Log(CHANGE, "lookupNS() domain", domain, "has NS", server)
|
||||||
me.nsmap[server] = domain
|
me.nsmap[server] = domain
|
||||||
domains += server + "\n"
|
domains += server + "\n"
|
||||||
}
|
}
|
||||||
|
@ -102,7 +102,7 @@ func lookupNS(domain string) {
|
||||||
var tmp string
|
var tmp string
|
||||||
// checks to see if the NS records change
|
// checks to see if the NS records change
|
||||||
for s, d := range me.nsmap {
|
for s, d := range me.nsmap {
|
||||||
debug(LogChange, "lookupNS() domain =", d, "server =", s)
|
log.Log(CHANGE, "lookupNS() domain =", d, "server =", s)
|
||||||
if (domain == d) {
|
if (domain == d) {
|
||||||
tmp += s + "\n"
|
tmp += s + "\n"
|
||||||
// figure out the provider (google, cloudflare, etc)
|
// figure out the provider (google, cloudflare, etc)
|
||||||
|
@ -113,7 +113,7 @@ func lookupNS(domain string) {
|
||||||
|
|
||||||
if (tmp != me.NSrr.S) {
|
if (tmp != me.NSrr.S) {
|
||||||
me.changed = true
|
me.changed = true
|
||||||
debug(LogChange, "lookupNS() setting me.NSrr =", tmp)
|
log.Log(CHANGE, "lookupNS() setting me.NSrr =", tmp)
|
||||||
me.NSrr.SetText(tmp)
|
me.NSrr.SetText(tmp)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -127,7 +127,7 @@ func setProvider(hostname string) {
|
||||||
}
|
}
|
||||||
if (me.DnsAPI.S != provider) {
|
if (me.DnsAPI.S != provider) {
|
||||||
me.changed = true
|
me.changed = true
|
||||||
debug(LogChange, "setProvider() changed to =", provider)
|
log.Log(CHANGE, "setProvider() changed to =", provider)
|
||||||
me.DnsAPI.SetText(provider)
|
me.DnsAPI.SetText(provider)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@ package main
|
||||||
// Watches for changes to a directory. Works cross-platform
|
// Watches for changes to a directory. Works cross-platform
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"log"
|
"go.wit.com/log"
|
||||||
"github.com/fsnotify/fsnotify"
|
"github.com/fsnotify/fsnotify"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@ func watchSysClassNet() {
|
||||||
// Create new watcher.
|
// Create new watcher.
|
||||||
watcher, err := fsnotify.NewWatcher()
|
watcher, err := fsnotify.NewWatcher()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
debug(LogError, "watchSysClassNet() failed:", err)
|
log.Error(err, "watchSysClassNet() failed")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
defer watcher.Close()
|
defer watcher.Close()
|
||||||
|
@ -43,7 +43,7 @@ func watchSysClassNet() {
|
||||||
// Add a path.
|
// Add a path.
|
||||||
err = watcher.Add("/tmp")
|
err = watcher.Add("/tmp")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
debug(LogError, "watchSysClassNet() watcher.Add() failed:", err)
|
log.Error(err, "watchSysClassNet() watcher.Add() failed")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
45
gui.go
45
gui.go
|
@ -22,8 +22,8 @@ func setupControlPanelWindow() {
|
||||||
me.window = myGui.NewWindow("DNS and IPv6 Control Panel")
|
me.window = myGui.NewWindow("DNS and IPv6 Control Panel")
|
||||||
// me.window.Dump() // will dump out some info
|
// me.window.Dump() // will dump out some info
|
||||||
|
|
||||||
debug("artificial sleep of:", me.artificialSleep)
|
log.Info("artificial sleep of:", me.artificialSleep)
|
||||||
sleep(me.artificialSleep)
|
log.Sleep(me.artificialSleep)
|
||||||
|
|
||||||
// setup the main tab
|
// setup the main tab
|
||||||
dnsTab("DNS")
|
dnsTab("DNS")
|
||||||
|
@ -109,10 +109,10 @@ func debugTab(title string) {
|
||||||
g2.NewButton("checkDNS:", func () {
|
g2.NewButton("checkDNS:", func () {
|
||||||
ipv6s, ipv4s := checkDNS()
|
ipv6s, ipv4s := checkDNS()
|
||||||
for s, _ := range ipv6s {
|
for s, _ := range ipv6s {
|
||||||
debug(LogNow, "check if", s, "is in DNS")
|
log.Log(NOW, "check if", s, "is in DNS")
|
||||||
}
|
}
|
||||||
for s, _ := range ipv4s {
|
for s, _ := range ipv4s {
|
||||||
debug(LogNow, "check if", s, "is in DNS")
|
log.Log(NOW, "check if", s, "is in DNS")
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -153,19 +153,14 @@ func debugTab(title string) {
|
||||||
g2 = tab.NewGroup("debugging options")
|
g2 = tab.NewGroup("debugging options")
|
||||||
|
|
||||||
// DEBUG flags
|
// DEBUG flags
|
||||||
me.dbOn = g2.NewCheckbox("turn on debugging (will override all flags below)")
|
|
||||||
me.dbOn.Custom = func() {
|
|
||||||
DEBUGON = me.dbOn.B
|
|
||||||
}
|
|
||||||
|
|
||||||
me.dbNet = g2.NewCheckbox("turn on network debugging)")
|
me.dbNet = g2.NewCheckbox("turn on network debugging)")
|
||||||
me.dbNet.Custom = func() {
|
me.dbNet.Custom = func() {
|
||||||
LogNet = me.dbNet.B
|
log.Warn("TODO: re-implement")
|
||||||
}
|
}
|
||||||
|
|
||||||
me.dbProc = g2.NewCheckbox("turn on /proc debugging)")
|
me.dbProc = g2.NewCheckbox("turn on /proc debugging)")
|
||||||
me.dbProc.Custom = func() {
|
me.dbProc.Custom = func() {
|
||||||
LogProc = me.dbProc.B
|
log.Warn("TODO: re-implement")
|
||||||
}
|
}
|
||||||
|
|
||||||
// makes a slider widget
|
// makes a slider widget
|
||||||
|
@ -185,7 +180,7 @@ func deleteAAA() string {
|
||||||
var aaaa []string
|
var aaaa []string
|
||||||
aaaa = dhcpAAAA() // your AAAA IP addresses right now
|
aaaa = dhcpAAAA() // your AAAA IP addresses right now
|
||||||
for _, s := range aaaa {
|
for _, s := range aaaa {
|
||||||
debug(LogNow, "DNS AAAA =", s)
|
log.Log(NOW, "DNS AAAA =", s)
|
||||||
if ( me.ipmap[s] == nil) {
|
if ( me.ipmap[s] == nil) {
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
@ -198,7 +193,7 @@ func missingAAAA() string {
|
||||||
var aaaa []string
|
var aaaa []string
|
||||||
aaaa = dhcpAAAA() // your AAAA IP addresses right now
|
aaaa = dhcpAAAA() // your AAAA IP addresses right now
|
||||||
for _, s := range aaaa {
|
for _, s := range aaaa {
|
||||||
debug(LogNow, "missing AAAA =", s)
|
log.Log(NOW, "missing AAAA =", s)
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
return ""
|
return ""
|
||||||
|
@ -213,10 +208,10 @@ func displayDNS() string {
|
||||||
var all string
|
var all string
|
||||||
var broken string = "unknown"
|
var broken string = "unknown"
|
||||||
for _, s := range aaaa {
|
for _, s := range aaaa {
|
||||||
debug(LogNow, "host", h, "DNS AAAA =", s, "ipmap[s] =", me.ipmap[s])
|
log.Log(NOW, "host", h, "DNS AAAA =", s, "ipmap[s] =", me.ipmap[s])
|
||||||
all += s + "\n"
|
all += s + "\n"
|
||||||
if ( me.ipmap[s] == nil) {
|
if ( me.ipmap[s] == nil) {
|
||||||
debug(LogError, "THIS IS THE WRONG AAAA DNS ENTRY: host", h, "DNS AAAA =", s)
|
log.Warn("THIS IS THE WRONG AAAA DNS ENTRY: host", h, "DNS AAAA =", s)
|
||||||
broken = "wrong AAAA entry"
|
broken = "wrong AAAA entry"
|
||||||
} else {
|
} else {
|
||||||
if (broken == "unknown") {
|
if (broken == "unknown") {
|
||||||
|
@ -226,7 +221,7 @@ func displayDNS() string {
|
||||||
}
|
}
|
||||||
all = sortLines(all)
|
all = sortLines(all)
|
||||||
if (me.workingIPv6.S != all) {
|
if (me.workingIPv6.S != all) {
|
||||||
debug(LogError, "workingIPv6.SetText() to:", all)
|
log.Warn("workingIPv6.SetText() to:", all)
|
||||||
me.workingIPv6.SetText(all)
|
me.workingIPv6.SetText(all)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -234,11 +229,11 @@ func displayDNS() string {
|
||||||
a = realA()
|
a = realA()
|
||||||
all = sortLines(strings.Join(a, "\n"))
|
all = sortLines(strings.Join(a, "\n"))
|
||||||
if (all == "") {
|
if (all == "") {
|
||||||
debug(LogInfo, "THERE IS NOT a real A DNS ENTRY")
|
log.Info("THERE IS NOT a real A DNS ENTRY")
|
||||||
all = "CNAME ipv6.wit.com"
|
all = "CNAME ipv6.wit.com"
|
||||||
}
|
}
|
||||||
if (me.DnsA.S != all) {
|
if (me.DnsA.S != all) {
|
||||||
debug(LogError, "DnsA.SetText() to:", all)
|
log.Warn("DnsA.SetText() to:", all)
|
||||||
me.DnsA.SetText(all)
|
me.DnsA.SetText(all)
|
||||||
}
|
}
|
||||||
return broken
|
return broken
|
||||||
|
@ -270,9 +265,9 @@ func dnsTab(title string) {
|
||||||
|
|
||||||
me.fix = me.mainStatus.NewButton("Fix", func () {
|
me.fix = me.mainStatus.NewButton("Fix", func () {
|
||||||
if (goodHostname(me.hostname)) {
|
if (goodHostname(me.hostname)) {
|
||||||
debug(LogInfo, "hostname is good:", me.hostname)
|
log.Info("hostname is good:", me.hostname)
|
||||||
} else {
|
} else {
|
||||||
debug(LogError, "FIX: you need to fix your hostname here", me.hostname)
|
log.Warn("FIX: you need to fix your hostname here", me.hostname)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// check to see if the cloudflare window exists
|
// check to see if the cloudflare window exists
|
||||||
|
@ -396,11 +391,11 @@ func updateDNS() {
|
||||||
|
|
||||||
// log.Println("digAAAA()")
|
// log.Println("digAAAA()")
|
||||||
aaaa = digAAAA(h)
|
aaaa = digAAAA(h)
|
||||||
debug(LogNow, "digAAAA() =", aaaa)
|
log.Log(NOW, "digAAAA() =", aaaa)
|
||||||
|
|
||||||
// log.Println(SPEW, me)
|
// log.Println(SPEW, me)
|
||||||
if (aaaa == nil) {
|
if (aaaa == nil) {
|
||||||
debug(LogError, "There are no DNS AAAA records for hostname: ", h)
|
log.Warn("There are no DNS AAAA records for hostname: ", h)
|
||||||
me.DnsAAAA.SetText("(none)")
|
me.DnsAAAA.SetText("(none)")
|
||||||
if (cloudflare.CFdialog.TypeNode != nil) {
|
if (cloudflare.CFdialog.TypeNode != nil) {
|
||||||
cloudflare.CFdialog.TypeNode.SetText("AAAA new")
|
cloudflare.CFdialog.TypeNode.SetText("AAAA new")
|
||||||
|
@ -467,14 +462,12 @@ func suggestProcDebugging() {
|
||||||
}
|
}
|
||||||
|
|
||||||
me.fixProc = me.mainStatus.NewButton("Try debugging Slow DNS lookups", func () {
|
me.fixProc = me.mainStatus.NewButton("Try debugging Slow DNS lookups", func () {
|
||||||
debug("You're DNS lookups are very slow")
|
log.Warn("You're DNS lookups are very slow")
|
||||||
me.dbOn.Set(true)
|
me.dbOn.Set(true)
|
||||||
me.dbProc.Set(true)
|
me.dbProc.Set(true)
|
||||||
|
|
||||||
DEBUGON = true
|
|
||||||
LogProc = true
|
|
||||||
processName := getProcessNameByPort(53)
|
processName := getProcessNameByPort(53)
|
||||||
log.Println("Process with port 53:", processName)
|
log.Info("Process with port 53:", processName)
|
||||||
})
|
})
|
||||||
// me.fixProc.Disable()
|
// me.fixProc.Disable()
|
||||||
}
|
}
|
||||||
|
|
28
hostname.go
28
hostname.go
|
@ -19,7 +19,7 @@ func getHostname() {
|
||||||
var s string = "gui.Label == nil"
|
var s string = "gui.Label == nil"
|
||||||
s, err = fqdn.FqdnHostname()
|
s, err = fqdn.FqdnHostname()
|
||||||
if (err != nil) {
|
if (err != nil) {
|
||||||
debug(LogError, "FQDN hostname error =", err)
|
log.Error(err, "FQDN hostname error")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (me.fqdn != nil) {
|
if (me.fqdn != nil) {
|
||||||
|
@ -29,18 +29,18 @@ func getHostname() {
|
||||||
me.changed = true
|
me.changed = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
debug(LogNet, "FQDN =", s)
|
log.Log(NET, "FQDN =", s)
|
||||||
|
|
||||||
dn := run("domainname")
|
dn := run("domainname")
|
||||||
if (me.domainname.S != dn) {
|
if (me.domainname.S != dn) {
|
||||||
debug(LogChange, "domainname has changed from", me.domainname.S, "to", dn)
|
log.Log(CHANGE, "domainname has changed from", me.domainname.S, "to", dn)
|
||||||
me.domainname.SetText(dn)
|
me.domainname.SetText(dn)
|
||||||
me.changed = true
|
me.changed = true
|
||||||
}
|
}
|
||||||
|
|
||||||
hshort := run("hostname -s")
|
hshort := run("hostname -s")
|
||||||
if (me.hostshort.S != hshort) {
|
if (me.hostshort.S != hshort) {
|
||||||
debug(LogChange, "hostname -s has changed from", me.hostshort.S, "to", hshort)
|
log.Log(CHANGE, "hostname -s has changed from", me.hostshort.S, "to", hshort)
|
||||||
me.hostshort.SetText(hshort)
|
me.hostshort.SetText(hshort)
|
||||||
me.changed = true
|
me.changed = true
|
||||||
}
|
}
|
||||||
|
@ -48,21 +48,21 @@ func getHostname() {
|
||||||
var test string
|
var test string
|
||||||
test = hshort + "." + dn
|
test = hshort + "." + dn
|
||||||
if (me.hostname != test) {
|
if (me.hostname != test) {
|
||||||
debug(LogInfo, "me.hostname", me.hostname, "does not equal", test)
|
log.Info("me.hostname", me.hostname, "does not equal", test)
|
||||||
if (me.hostnameStatusOLD.S != "BROKEN") {
|
if (me.hostnameStatusOLD.S != "BROKEN") {
|
||||||
debug(LogChange, "me.hostname", me.hostname, "does not equal", test)
|
log.Log(CHANGE, "me.hostname", me.hostname, "does not equal", test)
|
||||||
me.changed = true
|
me.changed = true
|
||||||
me.hostnameStatusOLD.SetText("BROKEN")
|
me.hostnameStatusOLD.SetText("BROKEN")
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (me.hostnameStatusOLD.S != "VALID") {
|
if (me.hostnameStatusOLD.S != "VALID") {
|
||||||
debug(LogChange, "me.hostname", me.hostname, "is valid")
|
log.Log(CHANGE, "me.hostname", me.hostname, "is valid")
|
||||||
me.hostnameStatusOLD.SetText("VALID")
|
me.hostnameStatusOLD.SetText("VALID")
|
||||||
me.changed = true
|
me.changed = true
|
||||||
}
|
}
|
||||||
// enable the cloudflare button if the provider is cloudflare
|
// enable the cloudflare button if the provider is cloudflare
|
||||||
if (me.cloudflareB == nil) {
|
if (me.cloudflareB == nil) {
|
||||||
debug(LogChange, "me.cloudflare == nil; me.DnsAPI.S =", me.DnsAPI.S)
|
log.Log(CHANGE, "me.cloudflare == nil; me.DnsAPI.S =", me.DnsAPI.S)
|
||||||
if (me.DnsAPI.S == "cloudflare") {
|
if (me.DnsAPI.S == "cloudflare") {
|
||||||
me.cloudflareB = me.mainStatus.NewButton("cloudflare wit.com", func () {
|
me.cloudflareB = me.mainStatus.NewButton("cloudflare wit.com", func () {
|
||||||
cloudflare.CreateRR(myGui, "wit.com", "3777302ac4a78cd7fa4f6d3f72086d06")
|
cloudflare.CreateRR(myGui, "wit.com", "3777302ac4a78cd7fa4f6d3f72086d06")
|
||||||
|
@ -78,15 +78,15 @@ func getHostname() {
|
||||||
// and domainname and hostname
|
// and domainname and hostname
|
||||||
func goodHostname(h string) bool {
|
func goodHostname(h string) bool {
|
||||||
hostname := shell.Chomp(shell.Cat("/etc/hostname"))
|
hostname := shell.Chomp(shell.Cat("/etc/hostname"))
|
||||||
debug(true, "hostname =", hostname)
|
log.Log(NOW, "hostname =", hostname)
|
||||||
|
|
||||||
hs := run("hostname -s")
|
hs := run("hostname -s")
|
||||||
dn := run("domainname")
|
dn := run("domainname")
|
||||||
debug(true, "hostname short =", hs, "domainname =", dn)
|
log.Log(NOW, "hostname short =", hs, "domainname =", dn)
|
||||||
|
|
||||||
tmp := hs + "." + dn
|
tmp := hs + "." + dn
|
||||||
if (hostname == tmp) {
|
if (hostname == tmp) {
|
||||||
debug(true, "hostname seems to be good", hostname)
|
log.Log(NOW, "hostname seems to be good", hostname)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,18 +98,18 @@ func digAAAA(s string) []string {
|
||||||
var aaaa []string
|
var aaaa []string
|
||||||
// lookup the IP address from DNS
|
// lookup the IP address from DNS
|
||||||
rrset := dnssecsocket.Dnstrace(s, "AAAA")
|
rrset := dnssecsocket.Dnstrace(s, "AAAA")
|
||||||
// debug(true, args.VerboseDNS, SPEW, rrset)
|
// log.Spew(args.VerboseDNS, SPEW, rrset)
|
||||||
for i, rr := range rrset {
|
for i, rr := range rrset {
|
||||||
ipaddr := dns.Field(rr, 1)
|
ipaddr := dns.Field(rr, 1)
|
||||||
// how the hell do you detect a RRSIG AAAA record here?
|
// how the hell do you detect a RRSIG AAAA record here?
|
||||||
if (ipaddr == "28") {
|
if (ipaddr == "28") {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
debug(LogNow, "r.Answer =", i, "rr =", rr, "ipaddr =", ipaddr)
|
log.Log(NOW, "r.Answer =", i, "rr =", rr, "ipaddr =", ipaddr)
|
||||||
aaaa = append(aaaa, ipaddr)
|
aaaa = append(aaaa, ipaddr)
|
||||||
me.ipv6s[ipaddr] = rr
|
me.ipv6s[ipaddr] = rr
|
||||||
}
|
}
|
||||||
debug(true, args.VerboseDNS, "aaaa =", aaaa)
|
log.Info(args.VerboseDNS, "aaaa =", aaaa)
|
||||||
log.Println("digAAAA() returned =", aaaa)
|
log.Println("digAAAA() returned =", aaaa)
|
||||||
log.Println("digAAAA() me.ipv6s =", me.ipv6s)
|
log.Println("digAAAA() me.ipv6s =", me.ipv6s)
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
|
|
|
@ -247,7 +247,7 @@ func (hs *hostnameStatus) missingAAAA() bool {
|
||||||
var aaaa []string
|
var aaaa []string
|
||||||
aaaa = dhcpAAAA()
|
aaaa = dhcpAAAA()
|
||||||
for _, s := range aaaa {
|
for _, s := range aaaa {
|
||||||
debug(LogNet, "my actual AAAA = ",s)
|
log.Log(NET, "my actual AAAA = ",s)
|
||||||
hs.dnsValue.SetText(s)
|
hs.dnsValue.SetText(s)
|
||||||
hs.dnsAction.SetText("CREATE")
|
hs.dnsAction.SetText("CREATE")
|
||||||
return true
|
return true
|
||||||
|
|
59
log.go
59
log.go
|
@ -1,59 +0,0 @@
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"log"
|
|
||||||
"reflect"
|
|
||||||
witlog "go.wit.com/log"
|
|
||||||
)
|
|
||||||
|
|
||||||
var LogPrefix = "ipv6cp" // ipv6 control panel debugging line
|
|
||||||
|
|
||||||
// various debugging flags
|
|
||||||
var DEBUGON bool = true
|
|
||||||
var LogNow bool = true // useful for active development
|
|
||||||
var LogError bool = true // probably always leave this one
|
|
||||||
var LogChange bool = true // turn on /proc debugging output
|
|
||||||
|
|
||||||
var LogInfo bool = false // general info
|
|
||||||
var LogNet bool = false // general network debugging
|
|
||||||
var LogProc bool = false // turn on /proc debugging output
|
|
||||||
var LogExec bool = false // turn on os.Exec() debugging
|
|
||||||
|
|
||||||
// var SPEW witlog.Spewt
|
|
||||||
|
|
||||||
// var log interface{}
|
|
||||||
|
|
||||||
/*
|
|
||||||
func log(a ...any) {
|
|
||||||
witlog.Where = "wit/gui"
|
|
||||||
witlog.Log(a...)
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
func sleep(a ...any) {
|
|
||||||
witlog.Sleep(a...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func exit(a ...any) {
|
|
||||||
debug(LogError, "got to log() exit")
|
|
||||||
witlog.Exit(a...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func debug(a ...any) {
|
|
||||||
if (! DEBUGON) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if (a == nil) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
var tbool bool
|
|
||||||
if (reflect.TypeOf(a[0]) == reflect.TypeOf(tbool)) {
|
|
||||||
if (a[0] == false) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
a[0] = LogPrefix // ipv6 control panel debugging line
|
|
||||||
}
|
|
||||||
|
|
||||||
log.Println(a...)
|
|
||||||
}
|
|
28
main.go
28
main.go
|
@ -43,16 +43,16 @@ func main() {
|
||||||
|
|
||||||
myGui = gui.New().Default()
|
myGui = gui.New().Default()
|
||||||
|
|
||||||
sleep(me.artificialSleep)
|
log.Sleep(me.artificialSleep)
|
||||||
setupControlPanelWindow()
|
setupControlPanelWindow()
|
||||||
|
|
||||||
if debugger.ArgDebug() {
|
if debugger.ArgDebug() {
|
||||||
sleep(2)
|
log.Sleep(2)
|
||||||
debugger.DebugWindow(myGui)
|
debugger.DebugWindow(myGui)
|
||||||
}
|
}
|
||||||
|
|
||||||
// forever monitor for network and dns changes
|
// forever monitor for network and dns changes
|
||||||
sleep(me.artificialSleep)
|
log.Sleep(me.artificialSleep)
|
||||||
checkNetworkChanges()
|
checkNetworkChanges()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,7 +99,7 @@ func checkNetworkChanges() {
|
||||||
me.LocalSpeedActual.SetText(s)
|
me.LocalSpeedActual.SetText(s)
|
||||||
} else {
|
} else {
|
||||||
// TODO: make windows and macos diagnostics
|
// TODO: make windows and macos diagnostics
|
||||||
debug(LogError, "Windows and MacOS don't work yet")
|
log.Warn("Windows and MacOS don't work yet")
|
||||||
}
|
}
|
||||||
lastLocal = time.Now()
|
lastLocal = time.Now()
|
||||||
}
|
}
|
||||||
|
@ -120,7 +120,7 @@ func checkNetworkChanges() {
|
||||||
// run this on each timeout
|
// run this on each timeout
|
||||||
func DNSloop() {
|
func DNSloop() {
|
||||||
duration := timeFunction(dnsTTL)
|
duration := timeFunction(dnsTTL)
|
||||||
debug(LogInfo, "dnsTTL() execution Time: ", duration)
|
log.Info("dnsTTL() execution Time: ", duration)
|
||||||
var s, newSpeed string
|
var s, newSpeed string
|
||||||
if (duration > 5000 * time.Millisecond ) {
|
if (duration > 5000 * time.Millisecond ) {
|
||||||
newSpeed = "VERY BAD"
|
newSpeed = "VERY BAD"
|
||||||
|
@ -143,8 +143,8 @@ func DNSloop() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (newSpeed != me.DnsSpeedLast) {
|
if (newSpeed != me.DnsSpeedLast) {
|
||||||
debug(LogChange, "dns lookup speed changed =", newSpeed)
|
log.Log(CHANGE, "dns lookup speed changed =", newSpeed)
|
||||||
debug(LogChange, "dnsTTL() execution Time: ", duration)
|
log.Log(CHANGE, "dnsTTL() execution Time: ", duration)
|
||||||
me.DnsSpeed.SetText(newSpeed)
|
me.DnsSpeed.SetText(newSpeed)
|
||||||
me.DnsSpeedLast = newSpeed
|
me.DnsSpeedLast = newSpeed
|
||||||
}
|
}
|
||||||
|
@ -160,30 +160,30 @@ func dnsTTL() {
|
||||||
|
|
||||||
func linuxLoop() {
|
func linuxLoop() {
|
||||||
me.changed = false
|
me.changed = false
|
||||||
debug(LogNet, "FQDN =", me.fqdn.GetText())
|
log.Log(NET, "FQDN =", me.fqdn.GetText())
|
||||||
duration := timeFunction(getHostname)
|
duration := timeFunction(getHostname)
|
||||||
debug(LogInfo, "getHostname() execution Time: ", duration, "me.changed =", me.changed)
|
log.Info("getHostname() execution Time: ", duration, "me.changed =", me.changed)
|
||||||
|
|
||||||
duration = timeFunction(scanInterfaces)
|
duration = timeFunction(scanInterfaces)
|
||||||
debug(LogNet, "scanInterfaces() execution Time: ", duration)
|
log.Log(NET, "scanInterfaces() execution Time: ", duration)
|
||||||
for i, t := range me.ifmap {
|
for i, t := range me.ifmap {
|
||||||
debug(LogNet, strconv.Itoa(i) + " iface = " + t.iface.Name)
|
log.Log(NET, strconv.Itoa(i) + " iface = " + t.iface.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
var aaaa []string
|
var aaaa []string
|
||||||
aaaa = dhcpAAAA()
|
aaaa = dhcpAAAA()
|
||||||
var all string
|
var all string
|
||||||
for _, s := range aaaa {
|
for _, s := range aaaa {
|
||||||
debug(LogNet, "my actual AAAA = ",s)
|
log.Log(NET, "my actual AAAA = ",s)
|
||||||
all += s + "\n"
|
all += s + "\n"
|
||||||
}
|
}
|
||||||
// me.IPv6.SetText(all)
|
// me.IPv6.SetText(all)
|
||||||
|
|
||||||
if (me.changed) {
|
if (me.changed) {
|
||||||
stamp := time.Now().Format("2006/01/02 15:04:05")
|
stamp := time.Now().Format("2006/01/02 15:04:05")
|
||||||
debug(LogChange, "Network things changed on", stamp)
|
log.Log(CHANGE, "Network things changed on", stamp)
|
||||||
duration := timeFunction(updateDNS)
|
duration := timeFunction(updateDNS)
|
||||||
debug(LogChange, "updateDNS() execution Time: ", duration)
|
log.Log(CHANGE, "updateDNS() execution Time: ", duration)
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
10
net.go
10
net.go
|
@ -270,7 +270,7 @@ func deleteChanges() bool {
|
||||||
var changed bool = false
|
var changed bool = false
|
||||||
for i, t := range me.ifmap {
|
for i, t := range me.ifmap {
|
||||||
if (t.gone) {
|
if (t.gone) {
|
||||||
log.Log(LogChange, "DELETE int =", i, "name =", t.name, t.iface)
|
log.Log(CHANGE, "DELETE int =", i, "name =", t.name, t.iface)
|
||||||
delete(me.ifmap, i)
|
delete(me.ifmap, i)
|
||||||
changed = true
|
changed = true
|
||||||
}
|
}
|
||||||
|
@ -278,10 +278,10 @@ func deleteChanges() bool {
|
||||||
}
|
}
|
||||||
for s, t := range me.ipmap {
|
for s, t := range me.ipmap {
|
||||||
if (t.gone) {
|
if (t.gone) {
|
||||||
log.Log(LogChange, "DELETE name =", s, "IPv4 =", t.ipv4)
|
log.Log(CHANGE, "DELETE name =", s, "IPv4 =", t.ipv4)
|
||||||
log.Log(LogChange, "DELETE name =", s, "IPv6 =", t.ipv6)
|
log.Log(CHANGE, "DELETE name =", s, "IPv6 =", t.ipv6)
|
||||||
log.Log(LogChange, "DELETE name =", s, "iface =", t.iface)
|
log.Log(CHANGE, "DELETE name =", s, "iface =", t.iface)
|
||||||
log.Log(LogChange, "DELETE name =", s, "ip =", t.ip)
|
log.Log(CHANGE, "DELETE name =", s, "ip =", t.ip)
|
||||||
delete(me.ipmap, s)
|
delete(me.ipmap, s)
|
||||||
changed = true
|
changed = true
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,8 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
|
"go.wit.com/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ./go-nsupdate \
|
// ./go-nsupdate \
|
||||||
|
@ -16,17 +18,17 @@ import (
|
||||||
|
|
||||||
func nsupdate() {
|
func nsupdate() {
|
||||||
var tsigSecret string
|
var tsigSecret string
|
||||||
debug(true, "nsupdate() START")
|
log.Log(NET, "nsupdate() START")
|
||||||
cmd := "go-nsupdate --tsig-algorithm=hmac-sha512"
|
cmd := "go-nsupdate --tsig-algorithm=hmac-sha512"
|
||||||
tsigSecret = os.Getenv("TIG_SECRET")
|
tsigSecret = os.Getenv("TIG_SECRET")
|
||||||
cmd += " --tig-secret=\"" + tsigSecret + "\""
|
cmd += " --tig-secret=\"" + tsigSecret + "\""
|
||||||
cmd += " -i wlo1 " + me.hostname
|
cmd += " -i wlo1 " + me.hostname
|
||||||
debug(true, "nsupdate() RUN:", cmd)
|
log.Log(NET, "nsupdate() RUN:", cmd)
|
||||||
|
|
||||||
for s, t := range me.ipmap {
|
for s, t := range me.ipmap {
|
||||||
if (t.IsReal()) {
|
if (t.IsReal()) {
|
||||||
if (t.ipv6) {
|
if (t.ipv6) {
|
||||||
debug(true, "nsupdate() found real AAAA =", s, "on iface", t.iface.Name)
|
log.Log(NET, "nsupdate() found real AAAA =", s, "on iface", t.iface.Name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
28
proc.go
28
proc.go
|
@ -6,6 +6,8 @@ import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"go.wit.com/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
func getProcessNameByPort(port int) string {
|
func getProcessNameByPort(port int) string {
|
||||||
|
@ -18,24 +20,24 @@ func getProcessNameByPort(port int) string {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
// debug(LogProc, "searchProcNet() data:", string(data))
|
// log.Log(PROC, "searchProcNet() data:", string(data))
|
||||||
|
|
||||||
lines := strings.Split(string(data), "\n")
|
lines := strings.Split(string(data), "\n")
|
||||||
for _, line := range lines {
|
for _, line := range lines {
|
||||||
fields := strings.Fields(line)
|
fields := strings.Fields(line)
|
||||||
debug(LogProc, "searchProcNet() portHex:", portHex)
|
log.Log(PROC, "searchProcNet() portHex:", portHex)
|
||||||
if (len(fields) > 9) {
|
if (len(fields) > 9) {
|
||||||
debug(LogProc, "searchProcNet() fields[9]", fields[9])
|
log.Log(PROC, "searchProcNet() fields[9]", fields[9])
|
||||||
}
|
}
|
||||||
debug(LogProc, "searchProcNet() lines:", line)
|
log.Log(PROC, "searchProcNet() lines:", line)
|
||||||
if len(fields) > 1 {
|
if len(fields) > 1 {
|
||||||
parts := strings.Split(fields[1], ":")
|
parts := strings.Split(fields[1], ":")
|
||||||
if len(parts) > 1 {
|
if len(parts) > 1 {
|
||||||
// Convert the hexadecimal string to an integer
|
// Convert the hexadecimal string to an integer
|
||||||
value, _ := strconv.ParseInt(parts[1], 16, 64)
|
value, _ := strconv.ParseInt(parts[1], 16, 64)
|
||||||
debug(LogProc, "searchProcNet() value, port =", value, port, "parts[1] =", parts[1])
|
log.Log(PROC, "searchProcNet() value, port =", value, port, "parts[1] =", parts[1])
|
||||||
if (port == int(value)) {
|
if (port == int(value)) {
|
||||||
debug(LogProc, "searchProcNet() THIS IS THE LINE:", fields)
|
log.Log(PROC, "searchProcNet() THIS IS THE LINE:", fields)
|
||||||
return fields[9]
|
return fields[9]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -50,7 +52,7 @@ func getProcessNameByPort(port int) string {
|
||||||
if inode == "" {
|
if inode == "" {
|
||||||
inode = searchProcNet("/proc/net/udp")
|
inode = searchProcNet("/proc/net/udp")
|
||||||
}
|
}
|
||||||
debug(LogProc, "searchProcNet() inode =", inode)
|
log.Log(PROC, "searchProcNet() inode =", inode)
|
||||||
|
|
||||||
// Search for process with the inode
|
// Search for process with the inode
|
||||||
procs, _ := ioutil.ReadDir("/proc")
|
procs, _ := ioutil.ReadDir("/proc")
|
||||||
|
@ -70,23 +72,23 @@ func getProcessNameByPort(port int) string {
|
||||||
var s string
|
var s string
|
||||||
s = "socket:["+inode+"]"
|
s = "socket:["+inode+"]"
|
||||||
if strings.Contains(fdLink, "socket:[") {
|
if strings.Contains(fdLink, "socket:[") {
|
||||||
debug(LogProc, "searchProcNet() fdLink has socket:", fdLink)
|
log.Log(PROC, "searchProcNet() fdLink has socket:", fdLink)
|
||||||
debug(LogProc, "searchProcNet() proc.Name() =", proc.Name(), "s =", s)
|
log.Log(PROC, "searchProcNet() proc.Name() =", proc.Name(), "s =", s)
|
||||||
}
|
}
|
||||||
if strings.Contains(fdLink, "socket:[35452]") {
|
if strings.Contains(fdLink, "socket:[35452]") {
|
||||||
debug(LogProc, "searchProcNet() found proc.Name() =", proc.Name(), fdLink)
|
log.Log(PROC, "searchProcNet() found proc.Name() =", proc.Name(), fdLink)
|
||||||
return proc.Name()
|
return proc.Name()
|
||||||
}
|
}
|
||||||
if strings.Contains(fdLink, "socket:[35450]") {
|
if strings.Contains(fdLink, "socket:[35450]") {
|
||||||
debug(LogProc, "searchProcNet() found proc.Name() =", proc.Name(), fdLink)
|
log.Log(PROC, "searchProcNet() found proc.Name() =", proc.Name(), fdLink)
|
||||||
return proc.Name()
|
return proc.Name()
|
||||||
}
|
}
|
||||||
if strings.Contains(fdLink, "socket:[35440]") {
|
if strings.Contains(fdLink, "socket:[35440]") {
|
||||||
debug(LogProc, "searchProcNet() found proc.Name() =", proc.Name(), fdLink)
|
log.Log(PROC, "searchProcNet() found proc.Name() =", proc.Name(), fdLink)
|
||||||
return proc.Name()
|
return proc.Name()
|
||||||
}
|
}
|
||||||
if strings.Contains(fdLink, "socket:[21303]") {
|
if strings.Contains(fdLink, "socket:[21303]") {
|
||||||
debug(LogProc, "searchProcNet() found proc.Name() =", proc.Name(), fdLink)
|
log.Log(PROC, "searchProcNet() found proc.Name() =", proc.Name(), fdLink)
|
||||||
// return proc.Name()
|
// return proc.Name()
|
||||||
}
|
}
|
||||||
if strings.Contains(fdLink, "socket:["+inode+"]") {
|
if strings.Contains(fdLink, "socket:["+inode+"]") {
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"log"
|
|
||||||
"github.com/jsimonetti/rtnetlink"
|
"github.com/jsimonetti/rtnetlink"
|
||||||
|
"go.wit.com/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
// List all interfaces
|
// List all interfaces
|
||||||
|
@ -10,7 +10,7 @@ func Example_listLink() {
|
||||||
// Dial a connection to the rtnetlink socket
|
// Dial a connection to the rtnetlink socket
|
||||||
conn, err := rtnetlink.Dial(nil)
|
conn, err := rtnetlink.Dial(nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
debug(LogError, "Example_listLink() failed", err)
|
log.Error(err, "Example_listLink() failed")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
defer conn.Close()
|
defer conn.Close()
|
||||||
|
|
10
unix.go
10
unix.go
|
@ -5,7 +5,6 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"log"
|
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"net"
|
"net"
|
||||||
|
@ -13,6 +12,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"go.wit.com/log"
|
||||||
"go.wit.com/shell"
|
"go.wit.com/shell"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -28,8 +28,8 @@ func Escalate() {
|
||||||
cmd.Stderr = os.Stderr
|
cmd.Stderr = os.Stderr
|
||||||
err := cmd.Run()
|
err := cmd.Run()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
debug(LogError, "exit in Escalate()")
|
log.Error(err, "exit in Escalate()")
|
||||||
exit(err)
|
log.Exit(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -50,7 +50,7 @@ func DumpPublicDNSZone(zone string) {
|
||||||
func dumpIPs(host string) {
|
func dumpIPs(host string) {
|
||||||
ips, err := net.LookupIP(host)
|
ips, err := net.LookupIP(host)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
debug(LogError, "dumpIPs() failed:", err)
|
log.Error(err, "dumpIPs() failed")
|
||||||
}
|
}
|
||||||
for _, ip := range ips {
|
for _, ip := range ips {
|
||||||
log.Println(host, ip)
|
log.Println(host, ip)
|
||||||
|
@ -91,7 +91,7 @@ func run(s string) string {
|
||||||
|
|
||||||
tmp := shell.Chomp(out.String())
|
tmp := shell.Chomp(out.String())
|
||||||
// Output the results
|
// Output the results
|
||||||
debug(LogExec, "Command Output:", tmp)
|
log.Info("Command Output:", tmp)
|
||||||
|
|
||||||
return tmp
|
return tmp
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue