Compare commits

...

8 Commits

Author SHA1 Message Date
Jeff Carr 406472ecb2 move this code to go.wit.com/lib/hostname 2025-03-23 10:18:04 -05:00
Jeff Carr 3185270746 use go-cmd/cmd 2024-11-08 06:43:57 -06:00
Jeff Carr 7e1460f9f6 getDomainname()
Signed-off-by: Jeff Carr <jcarr@wit.com>
2024-11-01 21:41:46 -05:00
Jeff Carr 40e811b3b3 Init() is a better function name here 2024-02-25 18:39:27 -06:00
Jeff Carr 4641eceda8 remove testing code
Signed-off-by: Jeff Carr <jcarr@wit.com>
2024-01-31 13:34:13 -06:00
Jeff Carr 1a9b13dda5 use SetText() not SetValue()
Signed-off-by: Jeff Carr <jcarr@wit.com>
2024-01-31 12:41:28 -06:00
Jeff Carr 513c38922b new release
Signed-off-by: Jeff Carr <jcarr@wit.com>
2024-01-28 22:53:43 -06:00
Jeff Carr e15bf07c7c release automation
Signed-off-by: Jeff Carr <jcarr@wit.com>
2024-01-27 13:22:19 -06:00
14 changed files with 82 additions and 137 deletions

5
.gitignore vendored
View File

@ -1,7 +1,10 @@
*.swp
go.sum
go.mod
control-panel-dns
/files/*
/*.deb
*.swp
/plugins/*
control-panel-dns

View File

@ -1,8 +1,7 @@
all:
@echo
@echo Run: make redomod
@echo
@# ./myrepos >/tmp/myrepos.stderr 2>&1
all: goimports vet
vet:
GO111MODULE=off go vet
goimports:
goimports -w *.go
@ -13,3 +12,6 @@ redomod:
GO111MODULE= go mod init
GO111MODULE= go mod tidy
clean:
-rm -f go.*
-go-mod-clean --purge

3
README.md Normal file
View File

@ -0,0 +1,3 @@
# linuxstatus
this is being moved to go.wit.com/lib/hostname

View File

@ -2,7 +2,6 @@
package linuxstatus
import (
"go.wit.com/gui"
"go.wit.com/log"
)
@ -19,30 +18,6 @@ func (ls *LinuxStatus) Changed() bool {
return false
}
func (ls *LinuxStatus) Make() {
if !ls.Ready() {
return
}
log.Log(CHANGE, "Make() window ready =", ls.ready)
ls.window.Make()
ls.ready = true
}
func (ls *LinuxStatus) Draw() {
if !ls.Ready() {
return
}
log.Log(CHANGE, "Draw() window ready =", ls.ready)
ls.window.Draw()
ls.ready = true
}
func (ls *LinuxStatus) Draw2() {
if !ls.Ready() {
return
}
log.Log(CHANGE, "draw(ls) ready =", ls.ready)
draw(ls)
}
func (ls *LinuxStatus) Show() {
if !ls.Ready() {
return
@ -86,34 +61,3 @@ func (ls *LinuxStatus) Ready() bool {
}
return me.ready
}
func (ls *LinuxStatus) Initialized() bool {
log.Log(CHANGE, "checking Initialized()")
if me == nil {
return false
}
if ls == nil {
return false
}
if ls.parent == nil {
return false
}
return true
}
func (ls *LinuxStatus) SetParent(p *gui.Node) {
log.Log(CHANGE, "Attempting SetParent")
if me == nil {
return
}
if ls == nil {
return
}
if ls.parent == nil {
log.Log(CHANGE, "SetParent =", p)
ls.parent = p
return
} else {
log.Log(CHANGE, "SetParent was already set to =", ls.parent)
}
}

View File

@ -8,9 +8,6 @@ import (
// creates the actual widgets.
// it's assumed you are always passing in a box
func draw(ls *LinuxStatus) {
if !ls.Ready() {
return
}
ls.group = ls.window.Box().NewGroup("What Linux Knows It Is")
ls.grid = ls.group.NewGrid("gridnuts", 2, 2)
@ -20,7 +17,7 @@ func draw(ls *LinuxStatus) {
ls.hostshort = gadgets.NewOneLiner(ls.grid, "hostname -s")
ls.domainname = gadgets.NewOneLiner(ls.grid, "domain name")
ls.resolver = gadgets.NewOneLiner(ls.grid, "nameservers =")
ls.resolver.SetValue("TODO")
ls.resolver.SetText("TODO")
ls.uid = gadgets.NewOneLiner(ls.grid, "UID =")
ls.IPv4 = gadgets.NewOneLiner(ls.grid, "Current IPv4 =")
ls.IPv6 = gadgets.NewOneLiner(ls.grid, "Current IPv6 =")

17
go.mod
View File

@ -1,17 +0,0 @@
module go.wit.com/lib/gui/linuxstatus
go 1.21.4
require (
github.com/Showmax/go-fqdn v1.0.0
go.wit.com/gui v0.13.14
go.wit.com/lib/gadgets v0.13.16
go.wit.com/log v0.13.0
)
require (
go.wit.com/dev/alexflint/arg v1.4.5 // indirect
go.wit.com/dev/alexflint/scalar v1.2.1 // indirect
go.wit.com/dev/davecgh/spew v1.1.4 // indirect
go.wit.com/widget v1.1.8 // indirect
)

16
go.sum
View File

@ -1,16 +0,0 @@
github.com/Showmax/go-fqdn v1.0.0 h1:0rG5IbmVliNT5O19Mfuvna9LL7zlHyRfsSvBPZmF9tM=
github.com/Showmax/go-fqdn v1.0.0/go.mod h1:SfrFBzmDCtCGrnHhoDjuvFnKsWjEQX/Q9ARZvOrJAko=
go.wit.com/dev/alexflint/arg v1.4.5 h1:asDx5f9IlfpknKjPBqqb2qndE91Pbo7ZDkWUgddfMhY=
go.wit.com/dev/alexflint/arg v1.4.5/go.mod h1:wnWc+c6z8kSdDKYriMf6RpM+FiXmo5RYp/t4FNi0MU0=
go.wit.com/dev/alexflint/scalar v1.2.1 h1:loXOcbVnd+8YeJRLey+XXidecBiedMDO00zQ26TvKNs=
go.wit.com/dev/alexflint/scalar v1.2.1/go.mod h1:+rYsfxqdI2cwA8kJ7GCMwWbNJvfvWUurOCXLiwdTtSs=
go.wit.com/dev/davecgh/spew v1.1.4 h1:C9hj/rjlUpdK+E6aroyLjCbS5MFcyNUOuP1ICLWdNek=
go.wit.com/dev/davecgh/spew v1.1.4/go.mod h1:sihvWmnQ/09FWplnEmozt90CCVqBtGuPXM811tgfhFA=
go.wit.com/gui v0.13.14 h1:tJMCtZ8fJNmNB7oq4GQkciTA5aKUYlHL7U2tULIzwKU=
go.wit.com/gui v0.13.14/go.mod h1:mrITA5sK/wdrUKP33B1cJ8IJ7WGda9iGHEFmxPhxGCE=
go.wit.com/lib/gadgets v0.13.16 h1:ljW/hL+9jmndGs6ctDugqyTE6xOxmUlL5PcCw5pL+GQ=
go.wit.com/lib/gadgets v0.13.16/go.mod h1:5DHlhVpm09nfO0ZdwlfrMQt/6d+qm8c5ysR2ghT99/o=
go.wit.com/log v0.13.0 h1:0vyW3mHwDww3wCsyGnmQuX2P4V7aBMoJgxCy0GfA20g=
go.wit.com/log v0.13.0/go.mod h1:BaJBfHFqcJSJLXGQ9RHi3XVhPgsStxSMZRlaRxW4kAo=
go.wit.com/widget v1.1.8 h1:5cHcmfgwCyHjf02Af/9UMrbLhBR7Z/LFAjPuCx4dx5A=
go.wit.com/widget v1.1.8/go.mod h1:I8tnD3x3ECbB/CRNnLCdC+uoyk7rK0AEkzK1bQYSqoQ=

View File

@ -3,8 +3,11 @@
package linuxstatus
import (
"fmt"
"io/ioutil"
"strings"
"go.wit.com/lib/gui/shell"
"go.wit.com/log"
// will try to get this hosts FQDN
@ -26,7 +29,7 @@ func (ls *LinuxStatus) setDomainName() {
dn := run("domainname")
if me.domainname.String() != dn {
log.Log(CHANGE, "domainname has changed from", me.GetDomainName(), "to", dn)
me.domainname.SetValue(dn)
me.domainname.SetText(dn)
me.changed = true
}
}
@ -40,6 +43,7 @@ func (ls *LinuxStatus) GetHostname() string {
func (ls *LinuxStatus) ValidHostname() bool {
if !me.Ready() {
log.Info("ValidHostname() not ready")
return false
}
if me.hostnameStatus.String() == "WORKING" {
@ -56,7 +60,7 @@ func (ls *LinuxStatus) setHostname(newname string) {
return
}
log.Log(CHANGE, "hostname has changed from", me.GetHostname(), "to", newname)
me.hostname.SetValue(newname)
me.hostname.SetText(newname)
me.changed = true
}
@ -74,11 +78,22 @@ func (ls *LinuxStatus) setHostShort() {
hshort := run("hostname -s")
if me.hostshort.String() != hshort {
log.Log(CHANGE, "hostname -s has changed from", me.hostshort.String(), "to", hshort)
me.hostshort.SetValue(hshort)
me.hostshort.SetText(hshort)
me.changed = true
}
}
// getDomainName extracts the domain name from a given hostname
func getDomainName(hostname string) (string, error) {
parts := strings.Split(hostname, ".")
if len(parts) < 3 {
return "", fmt.Errorf("hostname '%s' is too short to extract a domain name", hostname)
}
// Join all parts except the first one, which is assumed to be a subdomain
domain := strings.Join(parts[1:], ".")
return domain, nil
}
func lookupHostname() {
if !me.Ready() {
return
@ -106,6 +121,27 @@ func lookupHostname() {
if hostfqdn != hostname {
log.Log(WARN, "hostname", hostname, "does not equal fqdn.FqdnHostname()", hostfqdn)
// TODO: figure out what is wrong
if dn == "(none)" {
realdn, err := getDomainName(hostfqdn)
if err == nil {
log.Log(WARN, "need to run: 'domainname", realdn, "' here")
me.changed = true
me.hostnameStatus.SetText("FIXING")
shell.Run([]string{"domainname", realdn})
return
} else {
log.Log(WARN, "getDomainName() err =", err)
log.Log(WARN, "/etc/hostname is too short. let the user set the name here.")
// me.changed = true
me.hostnameStatus.SetText("INVALID DOMAIN NAME")
// return
}
}
log.Log(WARN, "don't know what to do here with domainname")
log.Log(WARN, "check that /etc/hostname is valid?")
// me.changed = true
me.hostnameStatus.SetText("UNKNOWN")
// return
}
var test string
@ -118,12 +154,12 @@ func lookupHostname() {
if me.hostnameStatus.String() != "BROKEN" {
log.Log(CHANGE, "hostname", hostname, "does not equal", test)
me.changed = true
me.hostnameStatus.SetValue("BROKEN")
me.hostnameStatus.SetText("BROKEN")
}
} else {
if me.hostnameStatus.String() != "WORKING" {
log.Log(CHANGE, "hostname", hostname, "is valid")
me.hostnameStatus.SetValue("WORKING")
me.hostnameStatus.SetText("WORKING")
me.changed = true
}
}

View File

@ -44,9 +44,9 @@ func linuxLoop() {
sort.Strings(a)
tmp := strings.Join(a, "\n")
if tmp != me.workingIPv4.String() {
log.Log(CHANGE, "realAAAA() your real IPv6 addresses changed")
log.Log(CHANGE, "realA() your real IPv6 addresses changed")
me.changed = true
me.workingIPv4.SetValue(tmp)
me.workingIPv4.SetText(tmp)
}
// get all the real AAAA records from all the network interfaces linux can see
@ -56,7 +56,7 @@ func linuxLoop() {
if tmp != me.workingIPv6.String() {
log.Log(CHANGE, "realAAAA() your real IPv6 addresses changed")
me.changed = true
me.workingIPv6.SetValue(tmp)
me.workingIPv6.SetText(tmp)
}
user, _ := user.Current()
@ -64,7 +64,7 @@ func linuxLoop() {
if tmp != me.uid.String() {
log.Log(CHANGE, "os.Getuid =", user.Username, os.Getuid())
me.changed = true
me.uid.SetValue(tmp)
me.uid.SetText(tmp)
}
content, _ := ioutil.ReadFile("/etc/resolv.conf")
@ -82,7 +82,7 @@ func linuxLoop() {
if newNS != me.resolver.String() {
log.Log(CHANGE, "resolver changed in /etc/resolv.conf to", ns)
me.changed = true
me.resolver.SetValue(newNS)
me.resolver.SetText(newNS)
}
/*

10
net.go
View File

@ -101,7 +101,7 @@ func realA() []string {
return a
}
func checkDNS() (map[string]*IPtype, map[string]*IPtype) {
func checkDNSOld() (map[string]*IPtype, map[string]*IPtype) {
var ipv4s map[string]*IPtype
var ipv6s map[string]*IPtype
@ -154,13 +154,13 @@ func checkIP(ip *net.IPNet, i net.Interface) bool {
me.ipmap[realip].ipv4 = false
t = "IPv6"
if me.IPv6 != nil {
me.IPv6.SetValue(realip)
me.IPv6.SetText(realip)
}
} else {
me.ipmap[realip].ipv6 = false
me.ipmap[realip].ipv4 = true
if me.IPv4 != nil {
me.IPv4.SetValue(realip)
me.IPv4.SetText(realip)
}
}
if IsReal(&ip.IP) {
@ -234,12 +234,12 @@ func updateRealAAAA() {
if me.IPv4.String() != s4 {
log.Log(CHANGE, "IPv4 addresses have changed", s4)
me.IPv4.SetValue(s4)
me.IPv4.SetText(s4)
me.changed = true
}
if me.IPv6.String() != s6 {
log.Log(CHANGE, "IPv6 addresses have changed", s6)
me.IPv6.SetValue(s6)
me.IPv6.SetText(s6)
me.changed = true
}
}

24
new.go
View File

@ -7,7 +7,7 @@ import (
"go.wit.com/lib/gadgets"
)
func New() *LinuxStatus {
func InitLinuxStatus() *LinuxStatus {
if me != nil {
log.Log(WARN, "You have done New() twice. You can only do this once")
return me
@ -19,21 +19,11 @@ func New() *LinuxStatus {
me.ifmap = make(map[int]*IFtype)
me.ipmap = make(map[string]*IPtype)
log.Log(WARN, "Creating the Window")
me.window = gadgets.RawBasicWindow("OS Hostname Details")
me.window.Make()
draw(me)
me.ready = true
return me
}
func (ls *LinuxStatus) InitWindow() {
if !ls.Initialized() {
log.Log(WARN, "not initalized yet (no parent for the window?)")
return
}
if ls.window != nil {
log.Log(WARN, "You already have a window")
ls.ready = true
return
}
log.Log(WARN, "Creating the Window")
ls.window = gadgets.NewBasicWindow(ls.parent, "Linux OS Details")
ls.ready = true
}

View File

@ -34,5 +34,5 @@ func (ls *LinuxStatus) SetSpeedActual(s string) {
if !ls.Ready() {
return
}
ls.speedActual.SetValue(s)
ls.speedActual.SetText(s)
}

View File

@ -91,7 +91,7 @@ func run(s string) string {
// Trim leading and trailing whitespace from each line
tmp := strings.TrimSpace(out.String())
// Output the results
log.Info("Command Output:", tmp)
log.Verbose("Command Output:", tmp)
return tmp
}

View File

@ -9,6 +9,9 @@ import (
)
func (ls *LinuxStatus) Update() {
if ls == nil {
return
}
if !ls.Ready() {
log.Log(WARN, "can't update yet. ready is false")
log.Error(errors.New("Update() is not ready yet"))
@ -28,13 +31,13 @@ func (ls *LinuxStatus) setSpeed(duration time.Duration) {
log.Log(WARN, "can't actually warn")
return
}
ls.speedActual.SetValue(s)
ls.speedActual.SetText(s)
if duration > 500*time.Millisecond {
ls.speed.SetValue("SLOW")
ls.speed.SetText("SLOW")
} else if duration > 100*time.Millisecond {
ls.speed.SetValue("OK")
ls.speed.SetText("OK")
} else {
ls.speed.SetValue("FAST")
ls.speed.SetText("FAST")
}
}