// This is a simple example package cloudflare import ( "os" "go.wit.com/gui" "go.wit.com/lib/gadgets" "go.wit.com/log" ) // This creates a window func MakeCloudflareWindow(n *gui.Node) *gadgets.BasicWindow { CFdialog.rootGui = n log.Log(INFO, "buttonWindow() START") CFdialog.mainWindow = gadgets.NewBasicWindow(n, "Cloudflare Config") // CFdialog.mainWindow.Vertical() CFdialog.mainWindow.Make() CFdialog.mainWindow.Draw() return CFdialog.mainWindow // this tab has the master cloudflare API credentials makeConfigWindow(CFdialog.mainWindow.Box()) win := gadgets.NewBasicWindow(n, "Zones") win.Make() win.Draw() g1 := win.Box().NewGroup("zones") // make dropdown list of zones CFdialog.zonedrop = g1.NewDropdown() CFdialog.zonedrop.AddText("example.org") for d, _ := range Config { CFdialog.zonedrop.AddText(d) } CFdialog.zonedrop.AddText("stablesid.org") CFdialog.zonedrop.Custom = func() { domain := CFdialog.zonedrop.String() log.Log(ZONE, "custom dropdown() zone (domain name) =", CFdialog.zonedrop.String(), domain) if Config[domain] == nil { log.Log(ZONE, "custom dropdown() Config[domain] = nil for domain =", domain) CFdialog.domainWidget.SetText(domain) CFdialog.zoneWidget.SetText("") CFdialog.authWidget.SetText("") CFdialog.emailWidget.SetText("") } else { log.Log(ZONE, "custom dropdown() a =", domain, Config[domain].ZoneID, Config[domain].Auth, Config[domain].Email) CFdialog.domainWidget.SetText(Config[domain].Domain) CFdialog.zoneWidget.SetText(Config[domain].ZoneID) CFdialog.authWidget.SetText(Config[domain].Auth) CFdialog.emailWidget.SetText(Config[domain].Email) } } more := g1.NewGroup("data") showCloudflareCredentials(more) return CFdialog.mainWindow } func makeConfigWindow(vb *gui.Node) { g1 := vb.NewGroup("Cloudflare API Config") g1.NewLabel("If you have an API key with access to list all of /n your zone files, enter it here. \n \n Alternatively, you can set the enviroment variables: \n env $CF_API_KEY \n env $CF_API_EMAIL\n") // make grid to display credentials grid := g1.NewGrid("credsGrid", 2, 4) // width = 2 grid.NewLabel("Auth Key") aw := grid.NewEntryLine("CF_API_KEY") aw.SetText(os.Getenv("CF_API_KEY")) grid.NewLabel("Email") ew := grid.NewEntryLine("CF_API_EMAIL") ew.SetText(os.Getenv("CF_API_EMAIL")) var url string = "https://api.cloudflare.com/client/v4/zones/" grid.NewLabel("Cloudflare API") grid.NewLabel(url) hostname := gadgets.NewBasicEntry(grid, "hostname") zone := gadgets.NewBasicEntry(grid, "domain name") grid.Pad() vb.NewButton("Lookup Hostname", func() { log.Log(INFO, "Find all the Resource Records for hostname:", hostname.String()) log.Log(INFO, "Find all the Resource Records for zone:", zone.String()) GetZones(aw.String(), ew.String()) for d, v := range Config { log.Log(ZONE, "Zone =", d, "v =", v) } }) vb.NewButton("getZones()", func() { log.Log(ZONE, "getZones()") GetZones(aw.String(), ew.String()) for d, _ := range Config { CFdialog.zonedrop.AddText(d) } }) vb.NewButton("cloudflare wit.com", func() { CreateRR(CFdialog.rootGui, "wit.com", "3777302ac4a78cd7fa4f6d3f72086d06") }) vb.Pad() vb.Margin() g1.Pad() g1.Margin() } func showCloudflareCredentials(box *gui.Node) { // make grid to display credentials grid := box.NewGrid("credsGrid", 2, 4) // width = 2 grid.NewLabel("Domain") CFdialog.domainWidget = grid.NewEntryLine("CF_API_DOMAIN") grid.NewLabel("Zone ID") CFdialog.zoneWidget = grid.NewEntryLine("CF_API_ZONEID") grid.NewLabel("Auth Key") CFdialog.authWidget = grid.NewEntryLine("CF_API_KEY") grid.NewLabel("Email") CFdialog.emailWidget = grid.NewEntryLine("CF_API_EMAIL") var url string = "https://api.cloudflare.com/client/v4/zones/" grid.NewLabel("Cloudflare API") grid.NewLabel(url) grid.Pad() CFdialog.loadButton = box.NewButton("Load Cloudflare DNS zonefile", func() { var domain ConfigT domain.Domain = CFdialog.domainWidget.String() domain.ZoneID = CFdialog.zoneWidget.String() domain.Auth = CFdialog.authWidget.String() domain.Email = CFdialog.emailWidget.String() LoadZoneWindow(CFdialog.mainWindow.Box(), &domain) }) }