summaryrefslogtreecommitdiff
path: root/loadZoneWindow.go
blob: 6342ecaa423c11b11e263fd74a53c59e2dbc014f (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
// This is a simple example
package cloudflare

import 	(
	"strconv"

	"go.wit.com/log"
	"go.wit.com/gui/gui"
	"go.wit.com/gui/gadgets"
)

func LoadZoneWindow(n *gui.Node, c *ConfigT) {
	hostname := c.Domain
	zoneID := c.ZoneID
	log.Log(INFO, "adding DNS record", hostname)

	newW := gadgets.NewBasicWindow(n, hostname)
	newg := newW.Box().NewGroup("more zoneID = " + zoneID)

	// make a grid 6 things wide
	grid := newg.NewGrid("gridnuts", 6, 1)

//	grid.NewButton("Type", func () {
//		log.Log(INFO, "sort by Type")
//	})
	grid.NewLabel("RR type")
	grid.NewLabel("hostname")

	grid.NewLabel("Proxy")
	grid.NewLabel("TTL")
	grid.NewLabel("Value")
	grid.NewLabel("Save")

	records := GetZonefile(c)
	for _, record := range records.Result {
		var rr RRT // dns zonefile resource record

		// copy all the JSON values into the row record.
		rr.ID = record.ID
		rr.Type = record.Type
		rr.Name = record.Name
		rr.Content = record.Content
		rr.Proxied = record.Proxied
		rr.Proxiable = record.Proxiable
		rr.ZoneID = zoneID
		// rr.Ttl = record.TTL

		rr.Domain = hostname
		rr.ZoneID = zoneID
		rr.Auth = c.Auth
		rr.Email = c.Email

		grid.NewLabel(record.Type)
		grid.NewLabel(record.Name)

		proxy := grid.NewLabel("proxy")
		if (record.Proxied) {
			proxy.SetText("On")
		} else {
			proxy.SetText("Off")
		}

		var ttl  string
		if (record.TTL == 1) {
			ttl = "Auto"
		} else {
			ttl = strconv.Itoa(record.TTL)
		}
		grid.NewLabel(ttl)

		val := grid.NewLabel("Value")
		val.SetText(record.Content)

		load := grid.NewButton("Load", nil)
		load.Custom = func () {
			name := "save stuff to cloudflare for " + rr.ID
			log.Log(INFO, name)

			/*
			rr.Domain = domainWidget.S
			rr.ZoneID = zoneWidget.S
			rr.Auth = authWidget.S
			rr.Email = emailWidget.S
			*/

			SetRow(&rr)
		}
	}

	grid.Pad()
}