hostname actually set

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2023-03-09 14:21:34 -06:00
parent 3ce3a39226
commit 0b26e5f1ca
5 changed files with 80 additions and 22 deletions

58
bash.go Normal file
View File

@ -0,0 +1,58 @@
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 {
exit(err)
}
}

25
gui.go
View File

@ -13,7 +13,7 @@ import (
// This initializes the first window
func initGUI() {
gui.Config.Title = "DNS and IPv6 Control Panel"
gui.Config.Width = 640
gui.Config.Width = 1024
gui.Config.Height = 480
gui.Config.Exit = myDefaultExit
@ -33,19 +33,6 @@ func addDNSTab(title string) {
// 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("Network Interfaces", func () {
@ -57,7 +44,6 @@ func addDNSTab(title string) {
})
g2.NewButton("Hostname", func () {
getHostname()
output("FQDN = " + me.fqdn + "\n", true)
})
g2.NewButton("Actual AAAA", func () {
var aaaa []string
@ -120,11 +106,14 @@ func myDefaultExit(n *gui.Node) {
func nsupdateGroup(w *gui.Node) {
g := w.NewGroup("dns update")
g.NewLabel("UID = " + me.user)
me.uid = g.NewLabel("UID = " + me.user)
me.fqdn = g.NewLabel("fqdn:")
me.IPv4 = g.NewLabel("192.168.2.2")
me.IPv6 = g.NewLabel("fe::02")
g.NewButton("DNS AAAA", func () {
var aaaa []string
var out string
h := me.fqdn
h := me.fqdn.GetText()
// h := "fire.lab.wit.org"
aaaa = dnsAAAA(h)
log(SPEW, me)
@ -136,7 +125,7 @@ func nsupdateGroup(w *gui.Node) {
}
})
g.NewButton("dig +trace", func () {
o := shell.Run("dig +trace +noadditional DS " + me.fqdn + " @8.8.8.8")
o := shell.Run("dig +trace +noadditional DS " + me.fqdn.GetText() + " @8.8.8.8")
output(o, false)
// log(o)
})

View File

@ -18,13 +18,19 @@ 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) {
// s = me.fqdn.GetText()
output("trying to update gui.Label", true)
me.fqdn.SetText(s)
}
output("FQDN = jcarr" + s + "\n", true)
}
func dnsAAAA(s string) []string {

View File

@ -1,6 +1,7 @@
// 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 (
@ -64,7 +65,7 @@ func checkNetworkChanges() {
// Run this every once and a while
func dnsTTL() {
output("FQDN = " + me.fqdn + "\n", false)
output("FQDN = " + me.fqdn.GetText() + "\n", true)
getHostname()
scanInterfaces()
for i, t := range me.ifmap {

View File

@ -12,7 +12,7 @@ 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)
user string // name of the user
ipmap map[string]*IPtype // the current ip addresses
@ -23,6 +23,10 @@ type Host struct {
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
}
type IPtype struct {