summaryrefslogtreecommitdiff
path: root/linuxstatus/hostname.go
blob: 08c7971585404e6ecb60298130daf398f48d8392 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
// figures out if your hostname is valid
// then checks if your DNS is setup correctly
package linuxstatus

import (
	"errors"

	"go.wit.com/log"
	"go.wit.com/shell"

	// will try to get this hosts FQDN
	"github.com/Showmax/go-fqdn"
)

func (ls *LinuxStatus) GetDomainName() string {
	if ! me.Ready() {return ""}
	if me.window == nil {
		log.Log(NOW, "me.window == nil")
	} else {
		log.Log(NOW, "me.window exists, but has not been drawn")
	}
	return me.domainname.Get()
}

func (ls *LinuxStatus) setDomainName() {
	if ! me.Ready() {return}

	dn := run("domainname")
	if me.window == nil {
		log.Log(NOW, "me.window == nil")
	} else {
		log.Log(NOW, "me.window exists, but has not been drawn")
		log.Log(NOW, "me.window.Draw() =")
	}
	if (me.domainname.Get() != dn) {
		log.Log(CHANGE, "domainname has changed from", me.GetDomainName(), "to", dn)
		me.domainname.Set(dn)
		me.changed = true
	}
}

func (ls *LinuxStatus) GetHostShort() string {
	if ! me.Ready() {return ""}
	if me.window == nil {
		log.Log(NOW, "me.window == nil")
	} else {
		log.Log(NOW, "me.window exists, but has not been drawn")
	}
	return me.hostshort.Get()
}

func (ls *LinuxStatus) setHostShort() {
	if ! me.Ready() {return ""}
	hshort := run("hostname -s")
	if (me.hostshort.Get() != hshort) {
		log.Log(CHANGE, "hostname -s has changed from", me.hostshort.Get(), "to", hshort)
		me.hostshort.Set(hshort)
		me.changed = true
	}
}

func lookupHostname() {
	if ! me.Ready() {return}
	var err error
	var s string = "gui.Label == nil"
	s, err = fqdn.FqdnHostname()
	if (err != nil) {
		log.Error(err, "FQDN hostname error")
		return
	}
	log.Error(errors.New("full hostname should be: " + s))

	me.setDomainName()


	/*
	var test string
	test = hshort + "." + dn
	if (me.status.GetHostname() != test) {
		log.Log(CHANGE, "me.hostname", me.status.GetHostname(), "does not equal", test)
		if (me.hostnameStatus.S != "BROKEN") {
			log.Log(CHANGE, "me.hostname", me.status.GetHostname(), "does not equal", test)
			me.changed = true
			me.hostnameStatus.SetText("BROKEN")
		}
	} else {
		if (me.hostnameStatus.S != "VALID") {
			log.Log(CHANGE, "me.hostname", me.status.GetHostname(), "is valid")
			me.hostnameStatus.SetText("VALID")
			me.changed = true
		}
	}
	*/
}

// returns true if the hostname is good
// check that all the OS settings are correct here
// On Linux, /etc/hosts, /etc/hostname
//      and domainname and hostname
func goodHostname() bool {
	hostname := shell.Chomp(shell.Cat("/etc/hostname"))
	log.Log(NOW, "hostname =", hostname)

	hs := run("hostname -s")
	dn := run("domainname")
	log.Log(NOW, "hostname short =", hs, "domainname =", dn)

	tmp := hs + "." + dn
	if (hostname == tmp) {
		log.Log(NOW, "hostname seems to be good", hostname)
		return true
	}

	return false
}