From 0148cec0b28d88f348b88b54ddd9dcbc7c71c823 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Sat, 6 Jan 2024 17:51:41 -0600 Subject: purge years of old test code Signed-off-by: Jeff Carr --- bash.go | 61 -------------------- dns.go | 4 +- dynamic-dns-update.go | 32 ----------- fsnotify.go | 79 -------------------------- gui.go | 40 ++++++++------ linuxstatus/old/bash.go | 61 ++++++++++++++++++++ linuxstatus/old/dynamic-dns-update.go | 32 +++++++++++ linuxstatus/old/fsnotify.go | 81 +++++++++++++++++++++++++++ linuxstatus/old/nsupdate.go | 34 ++++++++++++ linuxstatus/old/rtnetlink.go | 26 +++++++++ linuxstatus/old/unix.go | 97 ++++++++++++++++++++++++++++++++ linuxstatus/proc.go | 101 ++++++++++++++++++++++++++++++++++ net.go | 91 ------------------------------ nsupdate.go | 35 ------------ proc.go | 101 ---------------------------------- rtnetlink.go | 26 --------- structs.go | 27 ++------- unix.go | 97 -------------------------------- 18 files changed, 463 insertions(+), 562 deletions(-) delete mode 100644 bash.go delete mode 100644 dynamic-dns-update.go delete mode 100644 fsnotify.go create mode 100644 linuxstatus/old/bash.go create mode 100644 linuxstatus/old/dynamic-dns-update.go create mode 100644 linuxstatus/old/fsnotify.go create mode 100644 linuxstatus/old/nsupdate.go create mode 100644 linuxstatus/old/rtnetlink.go create mode 100644 linuxstatus/old/unix.go create mode 100644 linuxstatus/proc.go delete mode 100644 net.go delete mode 100644 nsupdate.go delete mode 100644 proc.go delete mode 100644 rtnetlink.go delete mode 100644 unix.go diff --git a/bash.go b/bash.go deleted file mode 100644 index 7143c1f..0000000 --- a/bash.go +++ /dev/null @@ -1,61 +0,0 @@ -package main - -import ( - "io" - "os" - "os/exec" - "os/signal" - "syscall" - - "github.com/creack/pty" - "golang.org/x/term" - - "go.wit.com/log" -) - -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.Println("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.Error(err, "exit in mainBash()") - log.Exit(err) - } -} diff --git a/dns.go b/dns.go index ac4f35d..2f2f3ae 100644 --- a/dns.go +++ b/dns.go @@ -40,6 +40,7 @@ func (h *Host) setIPv4(ipv4s map[string]*IPtype) { } } +/* func (h *Host) checkDNS() { var ip4 bool = false var ip6 bool = false @@ -74,6 +75,7 @@ func (h *Host) checkDNS() { log.Println(args.VerboseDNS, "IPv6 is broken. Need to fix it here.") } } +*/ // nsLookup performs an NS lookup on the given domain name. func lookupNS(domain string) { @@ -113,7 +115,7 @@ func lookupNS(domain string) { if (tmp != me.status.NSrr.Get()) { me.changed = true - log.Log(CHANGE, "lookupNS() setting me.NSrr =", tmp) + log.Log(CHANGE, "lookupNS() setting changed to me.NSrr =", tmp) me.status.NSrr.Set(tmp) } } diff --git a/dynamic-dns-update.go b/dynamic-dns-update.go deleted file mode 100644 index 371a374..0000000 --- a/dynamic-dns-update.go +++ /dev/null @@ -1,32 +0,0 @@ -package main - -/* - https://pkg.go.dev/github.com/miekg/dns#section-readme - -DYNAMIC UPDATES - -Dynamic updates reuses the DNS message format, but renames three of the sections. Question is Zone, Answer is Prerequisite, Authority is Update, only the Additional is not renamed. See RFC 2136 for the gory details. - -You can set a rather complex set of rules for the existence of absence of certain resource records or names in a zone to specify if resource records should be added or removed. The table from RFC 2136 supplemented with the Go DNS function shows which functions exist to specify the prerequisites. - -3.2.4 - Table Of Metavalues Used In Prerequisite Section - - CLASS TYPE RDATA Meaning Function - -------------------------------------------------------------- - ANY ANY empty Name is in use dns.NameUsed - ANY rrset empty RRset exists (value indep) dns.RRsetUsed - NONE ANY empty Name is not in use dns.NameNotUsed - NONE rrset empty RRset does not exist dns.RRsetNotUsed - zone rrset rr RRset exists (value dep) dns.Used - -The prerequisite section can also be left empty. If you have decided on the prerequisites you can tell what RRs should be added or deleted. The next table shows the options you have and what functions to call. - -3.4.2.6 - Table Of Metavalues Used In Update Section - - CLASS TYPE RDATA Meaning Function - --------------------------------------------------------------- - ANY ANY empty Delete all RRsets from name dns.RemoveName - ANY rrset empty Delete an RRset dns.RemoveRRset - NONE rrset rr Delete an RR from RRset dns.Remove - zone rrset rr Add to an RRset dns.Insert -*/ diff --git a/fsnotify.go b/fsnotify.go deleted file mode 100644 index cf38b50..0000000 --- a/fsnotify.go +++ /dev/null @@ -1,79 +0,0 @@ -package main - -// Watches for changes to a directory. Works cross-platform - -import ( - "go.wit.com/log" - "github.com/fsnotify/fsnotify" -) - -// This would be a really dumb way to watch for new network interfaces -// since it then watches a linux only directory /sys/class/net for changes - -func watchSysClassNet() { - // Create new watcher. - watcher, err := fsnotify.NewWatcher() - if err != nil { - log.Error(err, "watchSysClassNet() failed") - return - } - defer watcher.Close() - - // Start listening for events. - go func() { - for { - select { - case event, ok := <-watcher.Events: - if !ok { - return - } - log.Println("event:", event) - if event.Has(fsnotify.Write) { - log.Println("modified file:", event.Name) - } - case err, ok := <-watcher.Errors: - if !ok { - return - } - log.Println("error:", err) - } - } - }() - - // Add a path. - err = watcher.Add("/tmp") - if err != nil { - log.Error(err, "watchSysClassNet() watcher.Add() failed") - return - } - - // Block main goroutine forever. - <-make(chan struct{}) -} - -func fsnotifyNetworkInterfaceChanges() error { - watcher, err := fsnotify.NewWatcher() - if err != nil { - return err - } - defer watcher.Close() - - // Watch for network interface changes - err = watcher.Add("/sys/class/net") - if err != nil { - return err - } - for { - select { - case event := <-watcher.Events: - log.Println("fsnotifyNetworkInterfaceChanges() event =", event) - if event.Op&fsnotify.Create == fsnotify.Create { - // Do something on network interface creation - } - case err := <-watcher.Errors: - log.Println("fsnotifyNetworkInterfaceChanges() event err =", err) - return err - } - } -} - diff --git a/gui.go b/gui.go index 8f7838e..9413deb 100644 --- a/gui.go +++ b/gui.go @@ -50,7 +50,7 @@ func debugTab(title string) { }) g2.NewButton("getProcessNameByPort()", func () { - processName := getProcessNameByPort(53) + processName := linuxstatus.GetProcessNameByPort(53) log.Info("Process with port 53:", processName) }) @@ -70,6 +70,7 @@ func debugTab(title string) { me.debug.Hide() } +/* // will return a AAAA value that needs to be deleted func deleteAAA() string { var aaaa []string @@ -93,6 +94,7 @@ func missingAAAA() string { } return "" } +*/ // doesn't actually do any network traffic // it just updates the GUI @@ -116,7 +118,7 @@ func displayDNS() string { } var a []string - a = realA() + a = append(a, "fixme") all = sortLines(strings.Join(a, "\n")) if (all == "") { log.Log(NOW, "THERE IS NOT a real A DNS ENTRY") @@ -265,28 +267,30 @@ func updateDNS() { cloudflare.CFdialog.NameNode.SetText(h) } + /* d := deleteAAA() if (d != "") { if (cloudflare.CFdialog.ValueNode != nil) { cloudflare.CFdialog.ValueNode.SetText(d) } } - m := missingAAAA() - if (m != "") { - if (cloudflare.CFdialog.ValueNode != nil) { - cloudflare.CFdialog.ValueNode.SetText(m) - } - /* - rr := &cloudflare.RRT{ - Type: "AAAA", - Name: me.hostname, - Ttl: "Auto", - Proxied: false, - Content: m, - } - cloudflare.Update(rr) - */ - } + */ +// m := missingAAAA() +// if (m != "") { +// if (cloudflare.CFdialog.ValueNode != nil) { +// cloudflare.CFdialog.ValueNode.SetText(m) +// } +// /* +// rr := &cloudflare.RRT{ +// Type: "AAAA", +// Name: me.hostname, +// Ttl: "Auto", +// Proxied: false, +// Content: m, +// } +// cloudflare.Update(rr) +// */ +// } } } status := displayDNS() // update the GUI based on dig results diff --git a/linuxstatus/old/bash.go b/linuxstatus/old/bash.go new file mode 100644 index 0000000..7143c1f --- /dev/null +++ b/linuxstatus/old/bash.go @@ -0,0 +1,61 @@ +package main + +import ( + "io" + "os" + "os/exec" + "os/signal" + "syscall" + + "github.com/creack/pty" + "golang.org/x/term" + + "go.wit.com/log" +) + +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.Println("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.Error(err, "exit in mainBash()") + log.Exit(err) + } +} diff --git a/linuxstatus/old/dynamic-dns-update.go b/linuxstatus/old/dynamic-dns-update.go new file mode 100644 index 0000000..371a374 --- /dev/null +++ b/linuxstatus/old/dynamic-dns-update.go @@ -0,0 +1,32 @@ +package main + +/* + https://pkg.go.dev/github.com/miekg/dns#section-readme + +DYNAMIC UPDATES + +Dynamic updates reuses the DNS message format, but renames three of the sections. Question is Zone, Answer is Prerequisite, Authority is Update, only the Additional is not renamed. See RFC 2136 for the gory details. + +You can set a rather complex set of rules for the existence of absence of certain resource records or names in a zone to specify if resource records should be added or removed. The table from RFC 2136 supplemented with the Go DNS function shows which functions exist to specify the prerequisites. + +3.2.4 - Table Of Metavalues Used In Prerequisite Section + + CLASS TYPE RDATA Meaning Function + -------------------------------------------------------------- + ANY ANY empty Name is in use dns.NameUsed + ANY rrset empty RRset exists (value indep) dns.RRsetUsed + NONE ANY empty Name is not in use dns.NameNotUsed + NONE rrset empty RRset does not exist dns.RRsetNotUsed + zone rrset rr RRset exists (value dep) dns.Used + +The prerequisite section can also be left empty. If you have decided on the prerequisites you can tell what RRs should be added or deleted. The next table shows the options you have and what functions to call. + +3.4.2.6 - Table Of Metavalues Used In Update Section + + CLASS TYPE RDATA Meaning Function + --------------------------------------------------------------- + ANY ANY empty Delete all RRsets from name dns.RemoveName + ANY rrset empty Delete an RRset dns.RemoveRRset + NONE rrset rr Delete an RR from RRset dns.Remove + zone rrset rr Add to an RRset dns.Insert +*/ diff --git a/linuxstatus/old/fsnotify.go b/linuxstatus/old/fsnotify.go new file mode 100644 index 0000000..ba40c94 --- /dev/null +++ b/linuxstatus/old/fsnotify.go @@ -0,0 +1,81 @@ +package main + +// Watches for changes to a directory. Works cross-platform + +/* +import ( + "go.wit.com/log" + "github.com/fsnotify/fsnotify" +) + +// This would be a really dumb way to watch for new network interfaces +// since it then watches a linux only directory /sys/class/net for changes + +func watchSysClassNet() { + // Create new watcher. + watcher, err := fsnotify.NewWatcher() + if err != nil { + log.Error(err, "watchSysClassNet() failed") + return + } + defer watcher.Close() + + // Start listening for events. + go func() { + for { + select { + case event, ok := <-watcher.Events: + if !ok { + return + } + log.Println("event:", event) + if event.Has(fsnotify.Write) { + log.Println("modified file:", event.Name) + } + case err, ok := <-watcher.Errors: + if !ok { + return + } + log.Println("error:", err) + } + } + }() + + // Add a path. + err = watcher.Add("/tmp") + if err != nil { + log.Error(err, "watchSysClassNet() watcher.Add() failed") + return + } + + // Block main goroutine forever. + <-make(chan struct{}) +} + +func fsnotifyNetworkInterfaceChanges() error { + watcher, err := fsnotify.NewWatcher() + if err != nil { + return err + } + defer watcher.Close() + + // Watch for network interface changes + err = watcher.Add("/sys/class/net") + if err != nil { + return err + } + for { + select { + case event := <-watcher.Events: + log.Println("fsnotifyNetworkInterfaceChanges() event =", event) + if event.Op&fsnotify.Create == fsnotify.Create { + // Do something on network interface creation + } + case err := <-watcher.Errors: + log.Println("fsnotifyNetworkInterfaceChanges() event err =", err) + return err + } + } +} + +*/ diff --git a/linuxstatus/old/nsupdate.go b/linuxstatus/old/nsupdate.go new file mode 100644 index 0000000..635de4c --- /dev/null +++ b/linuxstatus/old/nsupdate.go @@ -0,0 +1,34 @@ +// inspired from: +// https://github.com/mactsouk/opensource.com.git +// and +// https://coderwall.com/p/wohavg/creating-a-simple-tcp-server-in-go + +package main + +import ( +) + +// ./go-nsupdate \ +// --tsig-algorithm=hmac-sha512 \ +// --tsig-secret="OWh5/ZHIyaz7B8J9m9ZDqZ8448Pke0PTpkYbZmFcOf5a6rEzgmcwrG91u1BHi1/4us+mKKEobDPLw1x6sD+ZJw==" \ +// -i eno2 farm001.lab.wit.com + +/* +func nsupdate() { + var tsigSecret string + 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.statusOS.GetHostname() + log.Log(NET, "nsupdate() RUN:", cmd) + + for s, t := range me.ipmap { + if (t.IsReal()) { + if (t.ipv6) { + log.Log(NET, "nsupdate() found real AAAA =", s, "on iface", t.iface.Name) + } + } + } +} +*/ diff --git a/linuxstatus/old/rtnetlink.go b/linuxstatus/old/rtnetlink.go new file mode 100644 index 0000000..29f1153 --- /dev/null +++ b/linuxstatus/old/rtnetlink.go @@ -0,0 +1,26 @@ +package main + +import ( + "github.com/jsimonetti/rtnetlink" + "go.wit.com/log" +) + +// List all interfaces +func Example_listLink() { + // Dial a connection to the rtnetlink socket + conn, err := rtnetlink.Dial(nil) + if err != nil { + log.Error(err, "Example_listLink() failed") + return + } + defer conn.Close() + + // Request a list of interfaces + msg, err := conn.Link.List() + if err != nil { + log.Println(err) + } + + log.Println("%#v", msg) + log.Println(SPEW, msg) +} diff --git a/linuxstatus/old/unix.go b/linuxstatus/old/unix.go new file mode 100644 index 0000000..b09481a --- /dev/null +++ b/linuxstatus/old/unix.go @@ -0,0 +1,97 @@ +// Various Linux/Unix'y things + +// https://wiki.archlinux.org/title/Dynamic_DNS + +package main + +import ( + "os" + "os/exec" + "net" + "bytes" + "fmt" + "strings" + + "go.wit.com/log" + "go.wit.com/shell" +) + +func CheckSuperuser() bool { + return os.Getuid() == 0 +} + +func Escalate() { + if os.Getuid() != 0 { + cmd := exec.Command("sudo", "./control-panel-dns") // TODO: get the actual path + cmd.Stdin = os.Stdin + cmd.Stdout = os.Stdout + cmd.Stderr = os.Stderr + err := cmd.Run() + if err != nil { + log.Error(err, "exit in Escalate()") + log.Exit(err) + } + } +} + +// You need permission to do a zone transfer. Otherwise: +// dig +noall +answer +multiline lab.wit.com any +// dig +all +multiline fire.lab.wit.com # gives the zonefile header (ttl vals) +func DumpPublicDNSZone(zone string) { + entries, err := net.LookupHost(zone) + if err != nil { + panic(err) + } + for _, entry := range entries { + log.Println(entry) + } +} + +func dumpIPs(host string) { + ips, err := net.LookupIP(host) + if err != nil { + log.Error(err, "dumpIPs() failed") + } + for _, ip := range ips { + log.Println(host, ip) + } +} + +/* + check if ddclient is installed, working, and/or configured + https://github.com/ddclient/ddclient +*/ +func ddclient() { +} + +/* + check if ddupdate is installed, working, and/or configured +*/ +func ddupdate() { +} + +func run(s string) string { + cmdArgs := strings.Fields(s) + // Define the command you want to run + // cmd := exec.Command(cmdArgs) + cmd := exec.Command(cmdArgs[0], cmdArgs[1:len(cmdArgs)]...) + + // Create a buffer to capture the output + var out bytes.Buffer + + // Set the output of the command to the buffer + cmd.Stdout = &out + + // Run the command + err := cmd.Run() + if err != nil { + fmt.Println("Error running command:", err) + return "" + } + + tmp := shell.Chomp(out.String()) + // Output the results + log.Info("Command Output:", tmp) + + return tmp +} diff --git a/linuxstatus/proc.go b/linuxstatus/proc.go new file mode 100644 index 0000000..b7720e0 --- /dev/null +++ b/linuxstatus/proc.go @@ -0,0 +1,101 @@ +package linuxstatus + +import ( + "io/ioutil" + "os" + "path/filepath" + "strconv" + "strings" + + "go.wit.com/log" +) + +func GetProcessNameByPort(port int) string { + // Convert port to hex string + portHex := strconv.FormatInt(int64(port), 16) + + // Function to search /proc/net/tcp or /proc/net/udp + searchProcNet := func(file string) string { + data, err := ioutil.ReadFile(file) + if err != nil { + return "" + } + // log.Log(PROC, "searchProcNet() data:", string(data)) + + lines := strings.Split(string(data), "\n") + for _, line := range lines { + fields := strings.Fields(line) + log.Log(PROC, "searchProcNet() portHex:", portHex) + if (len(fields) > 9) { + log.Log(PROC, "searchProcNet() fields[9]", fields[9]) + } + 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) + log.Log(PROC, "searchProcNet() value, port =", value, port, "parts[1] =", parts[1]) + if (port == int(value)) { + log.Log(PROC, "searchProcNet() THIS IS THE LINE:", fields) + return fields[9] + } + } + } + } + + return "" + } + + // Search TCP and then UDP + inode := searchProcNet("/proc/net/tcp") + if inode == "" { + inode = searchProcNet("/proc/net/udp") + } + log.Log(PROC, "searchProcNet() inode =", inode) + + // Search for process with the inode + procs, _ := ioutil.ReadDir("/proc") + for _, proc := range procs { + if !proc.IsDir() { + continue + } + + fdPath := filepath.Join("/proc", proc.Name(), "fd") + fds, err := ioutil.ReadDir(fdPath) + if err != nil { + continue // Process might have exited; skip it + } + + for _, fd := range fds { + fdLink, _ := os.Readlink(filepath.Join(fdPath, fd.Name())) + var s string + s = "socket:["+inode+"]" + if strings.Contains(fdLink, "socket:[") { + log.Log(PROC, "searchProcNet() fdLink has socket:", fdLink) + log.Log(PROC, "searchProcNet() proc.Name() =", proc.Name(), "s =", s) + } + if strings.Contains(fdLink, "socket:[35452]") { + log.Log(PROC, "searchProcNet() found proc.Name() =", proc.Name(), fdLink) + return proc.Name() + } + if strings.Contains(fdLink, "socket:[35450]") { + log.Log(PROC, "searchProcNet() found proc.Name() =", proc.Name(), fdLink) + return proc.Name() + } + if strings.Contains(fdLink, "socket:[35440]") { + log.Log(PROC, "searchProcNet() found proc.Name() =", proc.Name(), fdLink) + return proc.Name() + } + if strings.Contains(fdLink, "socket:[21303]") { + log.Log(PROC, "searchProcNet() found proc.Name() =", proc.Name(), fdLink) + // return proc.Name() + } + if strings.Contains(fdLink, "socket:["+inode+"]") { + return proc.Name() + } + } + } + + return "" +} diff --git a/net.go b/net.go deleted file mode 100644 index a3ebefd..0000000 --- a/net.go +++ /dev/null @@ -1,91 +0,0 @@ -// This creates a simple hello world window -package main - -import ( - // "log" - "net" - "strings" - - "go.wit.com/log" -) - -func IsIPv6(address string) bool { - return strings.Count(address, ":") >= 2 -} - -func (t *IPtype) IsReal() bool { - if (t.ip.IsPrivate() || t.ip.IsLoopback() || t.ip.IsLinkLocalUnicast()) { - log.Log(NET, "\t\tIP is Real = false") - return false - } else { - log.Log(NET, "\t\tIP is Real = true") - return true - } -} - -func IsReal(ip *net.IP) bool { - if (ip.IsPrivate() || ip.IsLoopback() || ip.IsLinkLocalUnicast()) { - log.Log(NET, "\t\tIP is Real = false") - return false - } else { - log.Log(NET, "\t\tIP is Real = true") - return true - } -} - -/* - These are the real IP address you have been - given from DHCP -*/ -func dhcpAAAA() []string { - var aaaa []string - - for s, t := range me.ipmap { - if (t.IsReal()) { - if (t.ipv6) { - aaaa = append(aaaa, s) - } - } - } - return aaaa -} - -func realA() []string { - var a []string - - for s, t := range me.ipmap { - if (t.IsReal()) { - if (t.ipv4) { - a = append(a, s) - } - } - } - return a -} - -func checkDNS() (map[string]*IPtype, map[string]*IPtype) { - var ipv4s map[string]*IPtype - var ipv6s map[string]*IPtype - - ipv4s = make(map[string]*IPtype) - ipv6s = make(map[string]*IPtype) - - for s, t := range me.ipmap { - i := t.iface - ipt := "IPv4" - if (t.ipv6) { - ipt = "IPv6" - } - if (t.IsReal()) { - log.Info("\tIP is Real ", ipt, i.Index, i.Name, s) - if (t.ipv6) { - ipv6s[s] = t - } else { - ipv4s[s] = t - } - } else { - log.Info("\tIP is not Real", ipt, i.Index, i.Name, s) - } - } - return ipv6s, ipv4s -} diff --git a/nsupdate.go b/nsupdate.go deleted file mode 100644 index add2c94..0000000 --- a/nsupdate.go +++ /dev/null @@ -1,35 +0,0 @@ -// inspired from: -// https://github.com/mactsouk/opensource.com.git -// and -// https://coderwall.com/p/wohavg/creating-a-simple-tcp-server-in-go - -package main - -import ( - "os" - - "go.wit.com/log" -) - -// ./go-nsupdate \ -// --tsig-algorithm=hmac-sha512 \ -// --tsig-secret="OWh5/ZHIyaz7B8J9m9ZDqZ8448Pke0PTpkYbZmFcOf5a6rEzgmcwrG91u1BHi1/4us+mKKEobDPLw1x6sD+ZJw==" \ -// -i eno2 farm001.lab.wit.com - -func nsupdate() { - var tsigSecret string - 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.statusOS.GetHostname() - log.Log(NET, "nsupdate() RUN:", cmd) - - for s, t := range me.ipmap { - if (t.IsReal()) { - if (t.ipv6) { - log.Log(NET, "nsupdate() found real AAAA =", s, "on iface", t.iface.Name) - } - } - } -} diff --git a/proc.go b/proc.go deleted file mode 100644 index adc8576..0000000 --- a/proc.go +++ /dev/null @@ -1,101 +0,0 @@ -package main - -import ( - "io/ioutil" - "os" - "path/filepath" - "strconv" - "strings" - - "go.wit.com/log" -) - -func getProcessNameByPort(port int) string { - // Convert port to hex string - portHex := strconv.FormatInt(int64(port), 16) - - // Function to search /proc/net/tcp or /proc/net/udp - searchProcNet := func(file string) string { - data, err := ioutil.ReadFile(file) - if err != nil { - return "" - } - // log.Log(PROC, "searchProcNet() data:", string(data)) - - lines := strings.Split(string(data), "\n") - for _, line := range lines { - fields := strings.Fields(line) - log.Log(PROC, "searchProcNet() portHex:", portHex) - if (len(fields) > 9) { - log.Log(PROC, "searchProcNet() fields[9]", fields[9]) - } - 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) - log.Log(PROC, "searchProcNet() value, port =", value, port, "parts[1] =", parts[1]) - if (port == int(value)) { - log.Log(PROC, "searchProcNet() THIS IS THE LINE:", fields) - return fields[9] - } - } - } - } - - return "" - } - - // Search TCP and then UDP - inode := searchProcNet("/proc/net/tcp") - if inode == "" { - inode = searchProcNet("/proc/net/udp") - } - log.Log(PROC, "searchProcNet() inode =", inode) - - // Search for process with the inode - procs, _ := ioutil.ReadDir("/proc") - for _, proc := range procs { - if !proc.IsDir() { - continue - } - - fdPath := filepath.Join("/proc", proc.Name(), "fd") - fds, err := ioutil.ReadDir(fdPath) - if err != nil { - continue // Process might have exited; skip it - } - - for _, fd := range fds { - fdLink, _ := os.Readlink(filepath.Join(fdPath, fd.Name())) - var s string - s = "socket:["+inode+"]" - if strings.Contains(fdLink, "socket:[") { - log.Log(PROC, "searchProcNet() fdLink has socket:", fdLink) - log.Log(PROC, "searchProcNet() proc.Name() =", proc.Name(), "s =", s) - } - if strings.Contains(fdLink, "socket:[35452]") { - log.Log(PROC, "searchProcNet() found proc.Name() =", proc.Name(), fdLink) - return proc.Name() - } - if strings.Contains(fdLink, "socket:[35450]") { - log.Log(PROC, "searchProcNet() found proc.Name() =", proc.Name(), fdLink) - return proc.Name() - } - if strings.Contains(fdLink, "socket:[35440]") { - log.Log(PROC, "searchProcNet() found proc.Name() =", proc.Name(), fdLink) - return proc.Name() - } - if strings.Contains(fdLink, "socket:[21303]") { - log.Log(PROC, "searchProcNet() found proc.Name() =", proc.Name(), fdLink) - // return proc.Name() - } - if strings.Contains(fdLink, "socket:["+inode+"]") { - return proc.Name() - } - } - } - - return "" -} diff --git a/rtnetlink.go b/rtnetlink.go deleted file mode 100644 index 29f1153..0000000 --- a/rtnetlink.go +++ /dev/null @@ -1,26 +0,0 @@ -package main - -import ( - "github.com/jsimonetti/rtnetlink" - "go.wit.com/log" -) - -// List all interfaces -func Example_listLink() { - // Dial a connection to the rtnetlink socket - conn, err := rtnetlink.Dial(nil) - if err != nil { - log.Error(err, "Example_listLink() failed") - return - } - defer conn.Close() - - // Request a list of interfaces - msg, err := conn.Link.List() - if err != nil { - log.Println(err) - } - - log.Println("%#v", msg) - log.Println(SPEW, msg) -} diff --git a/structs.go b/structs.go index 1d311d6..30103d3 100644 --- a/structs.go +++ b/structs.go @@ -15,8 +15,14 @@ import ( var me Host type Host struct { + myGui *gui.Node // the 'gui' binary tree root node + + window *gadgets.BasicWindow // the main window + debug *gadgets.BasicWindow // the debug window + status *hostnameStatus // keeps track of the hostname and it's status statusOS *linuxstatus.LinuxStatus // what the Linux OS sees + digStatus *digStatus // window of the results of DNS lookups hostnameStatus *gui.Node // a summary for the user of where things are hostname *gadgets.OneLiner // the hostname grabbed from gadget.linuxStatus @@ -30,7 +36,6 @@ type Host struct { localSleep time.Duration 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 @@ -41,16 +46,6 @@ type Host struct { ipv4s map[string]dns.RR ipv6s map[string]dns.RR - window *gadgets.BasicWindow // the main window - debug *gadgets.BasicWindow // more attempts to debug the DNS state - - tab *gui.Node // the main dns tab - notes *gui.Node // using this to put notes here - - // local OS settings, network interfaces, etc -// fqdn *gui.Node // display the full hostname -// Interfaces *gui.Node // Interfaces -// LocalSpeedActual *gui.Node // the time it takes to check each network interface // DNS stuff DnsAPI *gui.Node // what DNS API to use? @@ -61,18 +56,8 @@ type Host struct { DnsSpeedActual *gui.Node // the last actual duration DnsSpeedLast string // the last state 'FAST', 'OK', etc - // fix *gui.Node // button for the user to click - // fixProc *gui.Node // button for the user to click - - // mainStatus *gui.Node // group for the main display of stuff - // cloudflareB *gui.Node // cloudflare button - - digStatus *digStatus statusIPv6 *gadgets.OneLiner digStatusButton *gui.Node - - myDebug *gui.Node - myGui *gui.Node } type IPtype struct { diff --git a/unix.go b/unix.go deleted file mode 100644 index b09481a..0000000 --- a/unix.go +++ /dev/null @@ -1,97 +0,0 @@ -// Various Linux/Unix'y things - -// https://wiki.archlinux.org/title/Dynamic_DNS - -package main - -import ( - "os" - "os/exec" - "net" - "bytes" - "fmt" - "strings" - - "go.wit.com/log" - "go.wit.com/shell" -) - -func CheckSuperuser() bool { - return os.Getuid() == 0 -} - -func Escalate() { - if os.Getuid() != 0 { - cmd := exec.Command("sudo", "./control-panel-dns") // TODO: get the actual path - cmd.Stdin = os.Stdin - cmd.Stdout = os.Stdout - cmd.Stderr = os.Stderr - err := cmd.Run() - if err != nil { - log.Error(err, "exit in Escalate()") - log.Exit(err) - } - } -} - -// You need permission to do a zone transfer. Otherwise: -// dig +noall +answer +multiline lab.wit.com any -// dig +all +multiline fire.lab.wit.com # gives the zonefile header (ttl vals) -func DumpPublicDNSZone(zone string) { - entries, err := net.LookupHost(zone) - if err != nil { - panic(err) - } - for _, entry := range entries { - log.Println(entry) - } -} - -func dumpIPs(host string) { - ips, err := net.LookupIP(host) - if err != nil { - log.Error(err, "dumpIPs() failed") - } - for _, ip := range ips { - log.Println(host, ip) - } -} - -/* - check if ddclient is installed, working, and/or configured - https://github.com/ddclient/ddclient -*/ -func ddclient() { -} - -/* - check if ddupdate is installed, working, and/or configured -*/ -func ddupdate() { -} - -func run(s string) string { - cmdArgs := strings.Fields(s) - // Define the command you want to run - // cmd := exec.Command(cmdArgs) - cmd := exec.Command(cmdArgs[0], cmdArgs[1:len(cmdArgs)]...) - - // Create a buffer to capture the output - var out bytes.Buffer - - // Set the output of the command to the buffer - cmd.Stdout = &out - - // Run the command - err := cmd.Run() - if err != nil { - fmt.Println("Error running command:", err) - return "" - } - - tmp := shell.Chomp(out.String()) - // Output the results - log.Info("Command Output:", tmp) - - return tmp -} -- cgit v1.2.3