diff options
Diffstat (limited to 'cloudflare')
| -rwxr-xr-x | cloudflare/curl.sh | 23 | ||||
| -rw-r--r-- | cloudflare/durationSlider.go | 81 |
2 files changed, 104 insertions, 0 deletions
diff --git a/cloudflare/curl.sh b/cloudflare/curl.sh new file mode 100755 index 0000000..13a477d --- /dev/null +++ b/cloudflare/curl.sh @@ -0,0 +1,23 @@ +# +# this curl POST will create a new DNS resource record (RR) in zone the wit.com +# In this case it will map www3.wit.com to a IPv6 address +# replace the auth key (e088...) and zone ID (27b9...) with the ones from your cloudflare account +# +curl --request POST \ + --url https://api.cloudflare.com/client/v4/zones/27llxxPutYourZoneIDherexxx497f90/dns_records \ + --header 'Content-Type: application/json' \ + --header 'X-Auth-Key: e08806adxxxPutYourAPIKeyHerexxxxa7d417a7x' \ + --header 'X-Auth-Email: [email protected]' \ + --data '{ + "name": "www3", + "type": "AAAA" + "content": "2001:4860:4860::5555", + "ttl": 3600, + "proxied": false, + "comment": "WIT DNS Control Panel", +}' + +# This will verify an API token +curl -X GET "https://api.cloudflare.com/client/v4/user/tokens/verify" \ + -H "Authorization: Bearer AAAPutYourTokenInHereSoYouCanTestItL5Cl3" \ + -H "Content-Type:application/json" diff --git a/cloudflare/durationSlider.go b/cloudflare/durationSlider.go new file mode 100644 index 0000000..0d9559b --- /dev/null +++ b/cloudflare/durationSlider.go @@ -0,0 +1,81 @@ +// This is a simple example +package cloudflare + +import ( + "log" + "fmt" + "time" + + "go.wit.com/gui" +) + +// ttl := cloudflare.DurationSlider(g2, "control panel TTL (in tenths of seconds)", 10 * time.Millisecond, 5 * time.Second) +// ttl.Set(200 * time.Millisecond) + +// The Node is a binary tree. This is how all GUI elements are stored +// simply the name and the size of whatever GUI element exists +type Duration struct { + p *gui.Node // parent widget + l *gui.Node // label widget + s *gui.Node // slider widget + + Label string + Low time.Duration + High time.Duration + Duration time.Duration + + Custom func() +} + +func (n *Duration) Set(d time.Duration) { + var timeRange, step, offset time.Duration + + if (d > n.High) { + d = n.High + } + if (d < n.Low) { + d = n.Low + } + + // set the duration + n.Duration = d + + // figure out the integer offset for the Slider GUI Widget + timeRange = n.High - n.Low + step = timeRange / 1000 + if (step == 0) { + log.Println("duration.Set() division by step == 0", n.Low, n.High, timeRange, step) + n.s.Set(0) + return + } + offset = d - n.Low + i := int(offset / step) + log.Println("duration.Set() =", n.Low, n.High, d, "i =", i) + n.s.I = i + n.s.Set(i) + n.s.Custom() +} + +func NewDurationSlider(n *gui.Node, label string, low time.Duration, high time.Duration) *Duration { + d := Duration { + p: n, + Label: label, + High: high, + Low: low, + } + + // various timeout settings + d.l = n.NewLabel(label) + d.s = n.NewSlider(label, 0, 1000) + d.s.Custom = func () { + d.Duration = low + (high - low) * time.Duration(d.s.I) / 1000 + log.Println("d.Duration =", d.Duration) + s := fmt.Sprintf("%s (%v)", d.Label, d.Duration) + d.l.SetText(s) + if (d.Custom != nil) { + d.Custom() + } + } + + return &d +} |
