summaryrefslogtreecommitdiff
path: root/gui.go
blob: 7dffc9545c6f64254fe26923782d987f5111d52d (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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
// This creates a simple hello world window
package main

import 	(
	"os"
	"os/user"
	"net"
	"git.wit.org/wit/gui"
	"git.wit.org/wit/shell"
	"github.com/davecgh/go-spew/spew"
)

// This initializes the first window
func initGUI() {
	gui.Config.Title = "DNS and IPv6 Control Panel"
	gui.Config.Width = 640
	gui.Config.Height = 480
	gui.Config.Exit = myDefaultExit

	me.window = gui.NewWindow()
	me.window.Dump()
	addDNSTab("DNS")

	if (args.GuiDebug) {
		gui.DebugWindow()
	}
}

func addDNSTab(title string) {
	var g2 *gui.Node

	me.tab = me.window.NewTab(title)
        // 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 () {
		for i, t := range me.ifmap {
			log("name =", t.iface.Name)
			log("int =", i, "name =", t.name, t.iface)
			output("iface = " + t.iface.Name + "\n", true)
		}
	})
	g2.NewButton("Hostname", func () {
		getHostname()
		output("FQDN = " + me.fqdn + "\n", true)
	})
	g2.NewButton("Actual AAAA", func () {
		var aaaa []string
		aaaa = realAAAA()
		for _, s := range aaaa {
			output("my actual AAAA = " + s + "\n", true)
		}
	})

	g2.NewButton("checkDNS()", func () {
		checkDNS()
	})
	g2.NewButton("os.User()", func () {
		user, _ := user.Current()
		spew.Dump(user)
		log("os.Getuid =", os.Getuid())
	})
	g2.NewButton("Example_listLink()", func () {
		Example_listLink()
	})
	g2.NewButton("Escalate()", func () {
		Escalate()
	})
	g2.NewButton("pprof(goroutine)", func () {
		loggo()
		// panic("correctly inside of gui goroutine (goroutine 1?)")
	})
	g2.NewButton("gui.DebugWindow()", func () {
		gui.DebugWindow()
	})
	g2.NewButton("NewCheckbox(test)", func () {
		me.notes.NewCheckbox("test")
	})
	g2.NewButton("LookupAddr(<raw ipv6>) == fire from /etc/hosts", func () {
		host, err := net.LookupAddr("2600:1700:afd5:6000:b26e:bfff:fe80:3c52")
		if err != nil {
			return
		}
		log("host =", host)
	})
	g2.NewButton("DumpPublicDNSZone(apple.com)", func () {
		DumpPublicDNSZone("apple.com")
		dumpIPs("www.apple.com")
	})

	nsupdateGroup(me.tab)

	tmp := me.tab.NewGroup("output")
	me.output = tmp.NewTextbox("some output")
	me.output.Custom = func() {
		s := me.output.GetText()
		log("output text =", s)
	}
}

func myDefaultExit(n *gui.Node) {
        log("You can Do exit() things here")
	os.Exit(0)
}

func nsupdateGroup(w *gui.Node) {
	g := w.NewGroup("dns update")
	g.NewLabel("UID = " + me.user)
	g.NewButton("DNS AAAA", func () {
		var aaaa []string
		var out string
		h := me.fqdn
		// h := "fire.lab.wit.org"
		aaaa = dnsAAAA(h)
		log(SPEW, me)
		if (aaaa == nil) {
			out += "There are no DNS AAAA records for hostname: " + h + "\n"
		}
		for _, s := range aaaa {
			out += "host " + h + " DNS AAAA = " + s + "\n"
		}
	})
	g.NewButton("dig +trace", func () {
		o := shell.Run("dig +trace +noadditional DS " + me.fqdn + " @8.8.8.8")
		output(o, false)
		// log(o)
	})
}

var outJunk string
func output(s string, a bool) {
	if (a) {
		outJunk += s
	} else {
		outJunk = s
	}
	me.output.SetText(outJunk)
	//log(outJunk)
}