From 1191d1548470a7ed1049f1d78de6f17b77e0d36d 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 --- linuxstatus/old/unix.go | 97 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 linuxstatus/old/unix.go (limited to 'linuxstatus/old/unix.go') 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 +} -- cgit v1.2.3