use 'go.wit.com/log'
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
3be643036f
commit
c420145c2e
7
bash.go
7
bash.go
|
@ -2,7 +2,6 @@ package main
|
|||
|
||||
import (
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
"os/signal"
|
||||
|
@ -10,6 +9,8 @@ import (
|
|||
|
||||
"github.com/creack/pty"
|
||||
"golang.org/x/term"
|
||||
|
||||
"go.wit.com/log"
|
||||
)
|
||||
|
||||
func test() error {
|
||||
|
@ -54,7 +55,7 @@ func test() error {
|
|||
|
||||
func mainBash() {
|
||||
if err := test(); err != nil {
|
||||
debug(LogError, "exit in mainBash()")
|
||||
exit(err)
|
||||
log.Error(err, "exit in mainBash()")
|
||||
log.Exit(err)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ package main
|
|||
// Watches for changes to a directory. Works cross-platform
|
||||
|
||||
import (
|
||||
"log"
|
||||
"go.wit.com/log"
|
||||
"github.com/fsnotify/fsnotify"
|
||||
)
|
||||
|
||||
|
@ -14,7 +14,7 @@ func watchSysClassNet() {
|
|||
// Create new watcher.
|
||||
watcher, err := fsnotify.NewWatcher()
|
||||
if err != nil {
|
||||
debug(LogError, "watchSysClassNet() failed:", err)
|
||||
log.Error(err, "watchSysClassNet() failed")
|
||||
return
|
||||
}
|
||||
defer watcher.Close()
|
||||
|
@ -43,7 +43,7 @@ func watchSysClassNet() {
|
|||
// Add a path.
|
||||
err = watcher.Add("/tmp")
|
||||
if err != nil {
|
||||
debug(LogError, "watchSysClassNet() watcher.Add() failed:", err)
|
||||
log.Error(err, "watchSysClassNet() watcher.Add() failed")
|
||||
return
|
||||
}
|
||||
|
||||
|
|
28
hostname.go
28
hostname.go
|
@ -19,7 +19,7 @@ func getHostname() {
|
|||
var s string = "gui.Label == nil"
|
||||
s, err = fqdn.FqdnHostname()
|
||||
if (err != nil) {
|
||||
debug(LogError, "FQDN hostname error =", err)
|
||||
log.Error(err, "FQDN hostname error")
|
||||
return
|
||||
}
|
||||
if (me.fqdn != nil) {
|
||||
|
@ -29,18 +29,18 @@ func getHostname() {
|
|||
me.changed = true
|
||||
}
|
||||
}
|
||||
debug(LogNet, "FQDN =", s)
|
||||
log.Log(NET, "FQDN =", s)
|
||||
|
||||
dn := run("domainname")
|
||||
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.changed = true
|
||||
}
|
||||
|
||||
hshort := run("hostname -s")
|
||||
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.changed = true
|
||||
}
|
||||
|
@ -48,21 +48,21 @@ func getHostname() {
|
|||
var test string
|
||||
test = hshort + "." + dn
|
||||
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") {
|
||||
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.hostnameStatusOLD.SetText("BROKEN")
|
||||
}
|
||||
} else {
|
||||
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.changed = true
|
||||
}
|
||||
// enable the cloudflare button if the provider is cloudflare
|
||||
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") {
|
||||
me.cloudflareB = me.mainStatus.NewButton("cloudflare wit.com", func () {
|
||||
cloudflare.CreateRR(myGui, "wit.com", "3777302ac4a78cd7fa4f6d3f72086d06")
|
||||
|
@ -78,15 +78,15 @@ func getHostname() {
|
|||
// and domainname and hostname
|
||||
func goodHostname(h string) bool {
|
||||
hostname := shell.Chomp(shell.Cat("/etc/hostname"))
|
||||
debug(true, "hostname =", hostname)
|
||||
log.Log(NOW, "hostname =", hostname)
|
||||
|
||||
hs := run("hostname -s")
|
||||
dn := run("domainname")
|
||||
debug(true, "hostname short =", hs, "domainname =", dn)
|
||||
log.Log(NOW, "hostname short =", hs, "domainname =", dn)
|
||||
|
||||
tmp := hs + "." + dn
|
||||
if (hostname == tmp) {
|
||||
debug(true, "hostname seems to be good", hostname)
|
||||
log.Log(NOW, "hostname seems to be good", hostname)
|
||||
return true
|
||||
}
|
||||
|
||||
|
@ -98,18 +98,18 @@ func digAAAA(s string) []string {
|
|||
var aaaa []string
|
||||
// lookup the IP address from DNS
|
||||
rrset := dnssecsocket.Dnstrace(s, "AAAA")
|
||||
// debug(true, args.VerboseDNS, SPEW, rrset)
|
||||
// log.Spew(args.VerboseDNS, SPEW, rrset)
|
||||
for i, rr := range rrset {
|
||||
ipaddr := dns.Field(rr, 1)
|
||||
// how the hell do you detect a RRSIG AAAA record here?
|
||||
if (ipaddr == "28") {
|
||||
continue
|
||||
}
|
||||
debug(LogNow, "r.Answer =", i, "rr =", rr, "ipaddr =", ipaddr)
|
||||
log.Log(NOW, "r.Answer =", i, "rr =", rr, "ipaddr =", ipaddr)
|
||||
aaaa = append(aaaa, ipaddr)
|
||||
me.ipv6s[ipaddr] = rr
|
||||
}
|
||||
debug(true, args.VerboseDNS, "aaaa =", aaaa)
|
||||
log.Info(args.VerboseDNS, "aaaa =", aaaa)
|
||||
log.Println("digAAAA() returned =", aaaa)
|
||||
log.Println("digAAAA() me.ipv6s =", me.ipv6s)
|
||||
os.Exit(0)
|
||||
|
|
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...)
|
||||
}
|
10
net.go
10
net.go
|
@ -270,7 +270,7 @@ func deleteChanges() bool {
|
|||
var changed bool = false
|
||||
for i, t := range me.ifmap {
|
||||
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)
|
||||
changed = true
|
||||
}
|
||||
|
@ -278,10 +278,10 @@ func deleteChanges() bool {
|
|||
}
|
||||
for s, t := range me.ipmap {
|
||||
if (t.gone) {
|
||||
log.Log(LogChange, "DELETE name =", s, "IPv4 =", t.ipv4)
|
||||
log.Log(LogChange, "DELETE name =", s, "IPv6 =", t.ipv6)
|
||||
log.Log(LogChange, "DELETE name =", s, "iface =", t.iface)
|
||||
log.Log(LogChange, "DELETE name =", s, "ip =", t.ip)
|
||||
log.Log(CHANGE, "DELETE name =", s, "IPv4 =", t.ipv4)
|
||||
log.Log(CHANGE, "DELETE name =", s, "IPv6 =", t.ipv6)
|
||||
log.Log(CHANGE, "DELETE name =", s, "iface =", t.iface)
|
||||
log.Log(CHANGE, "DELETE name =", s, "ip =", t.ip)
|
||||
delete(me.ipmap, s)
|
||||
changed = true
|
||||
}
|
||||
|
|
|
@ -7,6 +7,8 @@ package main
|
|||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"go.wit.com/log"
|
||||
)
|
||||
|
||||
// ./go-nsupdate \
|
||||
|
@ -16,17 +18,17 @@ import (
|
|||
|
||||
func nsupdate() {
|
||||
var tsigSecret string
|
||||
debug(true, "nsupdate() START")
|
||||
log.Log(NET, "nsupdate() START")
|
||||
cmd := "go-nsupdate --tsig-algorithm=hmac-sha512"
|
||||
tsigSecret = os.Getenv("TIG_SECRET")
|
||||
cmd += " --tig-secret=\"" + tsigSecret + "\""
|
||||
cmd += " -i wlo1 " + me.hostname
|
||||
debug(true, "nsupdate() RUN:", cmd)
|
||||
log.Log(NET, "nsupdate() RUN:", cmd)
|
||||
|
||||
for s, t := range me.ipmap {
|
||||
if (t.IsReal()) {
|
||||
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"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"go.wit.com/log"
|
||||
)
|
||||
|
||||
func getProcessNameByPort(port int) string {
|
||||
|
@ -18,24 +20,24 @@ func getProcessNameByPort(port int) string {
|
|||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
// debug(LogProc, "searchProcNet() data:", string(data))
|
||||
// log.Log(PROC, "searchProcNet() data:", string(data))
|
||||
|
||||
lines := strings.Split(string(data), "\n")
|
||||
for _, line := range lines {
|
||||
fields := strings.Fields(line)
|
||||
debug(LogProc, "searchProcNet() portHex:", portHex)
|
||||
log.Log(PROC, "searchProcNet() portHex:", portHex)
|
||||
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 {
|
||||
parts := strings.Split(fields[1], ":")
|
||||
if len(parts) > 1 {
|
||||
// Convert the hexadecimal string to an integer
|
||||
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)) {
|
||||
debug(LogProc, "searchProcNet() THIS IS THE LINE:", fields)
|
||||
log.Log(PROC, "searchProcNet() THIS IS THE LINE:", fields)
|
||||
return fields[9]
|
||||
}
|
||||
}
|
||||
|
@ -50,7 +52,7 @@ func getProcessNameByPort(port int) string {
|
|||
if inode == "" {
|
||||
inode = searchProcNet("/proc/net/udp")
|
||||
}
|
||||
debug(LogProc, "searchProcNet() inode =", inode)
|
||||
log.Log(PROC, "searchProcNet() inode =", inode)
|
||||
|
||||
// Search for process with the inode
|
||||
procs, _ := ioutil.ReadDir("/proc")
|
||||
|
@ -70,23 +72,23 @@ func getProcessNameByPort(port int) string {
|
|||
var s string
|
||||
s = "socket:["+inode+"]"
|
||||
if strings.Contains(fdLink, "socket:[") {
|
||||
debug(LogProc, "searchProcNet() fdLink has socket:", fdLink)
|
||||
debug(LogProc, "searchProcNet() proc.Name() =", proc.Name(), "s =", s)
|
||||
log.Log(PROC, "searchProcNet() fdLink has socket:", fdLink)
|
||||
log.Log(PROC, "searchProcNet() proc.Name() =", proc.Name(), "s =", s)
|
||||
}
|
||||
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()
|
||||
}
|
||||
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()
|
||||
}
|
||||
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()
|
||||
}
|
||||
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()
|
||||
}
|
||||
if strings.Contains(fdLink, "socket:["+inode+"]") {
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"github.com/jsimonetti/rtnetlink"
|
||||
"go.wit.com/log"
|
||||
)
|
||||
|
||||
// List all interfaces
|
||||
|
@ -10,7 +10,7 @@ func Example_listLink() {
|
|||
// Dial a connection to the rtnetlink socket
|
||||
conn, err := rtnetlink.Dial(nil)
|
||||
if err != nil {
|
||||
debug(LogError, "Example_listLink() failed", err)
|
||||
log.Error(err, "Example_listLink() failed")
|
||||
return
|
||||
}
|
||||
defer conn.Close()
|
||||
|
|
10
unix.go
10
unix.go
|
@ -5,7 +5,6 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
"net"
|
||||
|
@ -13,6 +12,7 @@ import (
|
|||
"fmt"
|
||||
"strings"
|
||||
|
||||
"go.wit.com/log"
|
||||
"go.wit.com/shell"
|
||||
)
|
||||
|
||||
|
@ -28,8 +28,8 @@ func Escalate() {
|
|||
cmd.Stderr = os.Stderr
|
||||
err := cmd.Run()
|
||||
if err != nil {
|
||||
debug(LogError, "exit in Escalate()")
|
||||
exit(err)
|
||||
log.Error(err, "exit in Escalate()")
|
||||
log.Exit(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -50,7 +50,7 @@ func DumpPublicDNSZone(zone string) {
|
|||
func dumpIPs(host string) {
|
||||
ips, err := net.LookupIP(host)
|
||||
if err != nil {
|
||||
debug(LogError, "dumpIPs() failed:", err)
|
||||
log.Error(err, "dumpIPs() failed")
|
||||
}
|
||||
for _, ip := range ips {
|
||||
log.Println(host, ip)
|
||||
|
@ -91,7 +91,7 @@ func run(s string) string {
|
|||
|
||||
tmp := shell.Chomp(out.String())
|
||||
// Output the results
|
||||
debug(LogExec, "Command Output:", tmp)
|
||||
log.Info("Command Output:", tmp)
|
||||
|
||||
return tmp
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue