package controllers import ( "net/http" "github.com/gin-gonic/gin" "github.com/miekg/dns" "code.crute.me/mcrute/go_ddns_manager/bind" "code.crute.me/mcrute/go_ddns_manager/util" "code.crute.me/mcrute/go_ddns_manager/web/middleware" ) func DnsManageRoot(c *gin.Context) { c.IndentedJSON(http.StatusOK, gin.H{ "_rels": gin.H{ "zones": util.MakeURL(c.Request, "/dns/zone").String(), "views": util.MakeURL(c.Request, "/dns/view").String(), }, }) } func DnsViews(c *gin.Context) { cfg := middleware.GetServerConfig(c) out := map[string]map[string]string{} for _, v := range cfg.BindConfig.Views() { k := map[string]string{} out[v] = k for _, z := range cfg.BindConfig.ZonesInView(v) { zn := bind.DeCanonicalize(z.Name) k[zn] = util.MakeURL(c.Request, "/dns/zone/%s/%s", v, zn).String() } } c.IndentedJSON(http.StatusOK, gin.H{"views": out}) } func DnsZones(c *gin.Context) { } func DnsZoneDetails(c *gin.Context) { cfg := middleware.GetServerConfig(c) z := cfg.BindConfig.Zone(c.Param("view"), c.Param("name")) if z == nil { c.JSON(http.StatusNotFound, gin.H{ "error": "Zone not found", }) return } envs := []*dns.Envelope{} ec, err := cfg.DNSClient.AXFR(z) if err != nil { c.JSON(http.StatusInternalServerError, gin.H{ "error": err.Error(), }) return } for e := range ec { envs = append(envs, e) } c.JSON(http.StatusOK, envs) }