summaryrefslogtreecommitdiff
path: root/web/controllers/dns_manage.go
diff options
context:
space:
mode:
Diffstat (limited to 'web/controllers/dns_manage.go')
-rw-r--r--web/controllers/dns_manage.go68
1 files changed, 68 insertions, 0 deletions
diff --git a/web/controllers/dns_manage.go b/web/controllers/dns_manage.go
new file mode 100644
index 0000000..6db0b13
--- /dev/null
+++ b/web/controllers/dns_manage.go
@@ -0,0 +1,68 @@
1package controllers
2
3import (
4 "net/http"
5
6 "github.com/gin-gonic/gin"
7 "github.com/miekg/dns"
8
9 "code.crute.me/mcrute/go_ddns_manager/bind"
10 "code.crute.me/mcrute/go_ddns_manager/util"
11 "code.crute.me/mcrute/go_ddns_manager/web/middleware"
12)
13
14func DnsManageRoot(c *gin.Context) {
15 c.IndentedJSON(http.StatusOK, gin.H{
16 "_rels": gin.H{
17 "zones": util.MakeURL(c.Request, "/dns/zone").String(),
18 "views": util.MakeURL(c.Request, "/dns/view").String(),
19 },
20 })
21}
22
23func DnsViews(c *gin.Context) {
24 cfg := middleware.GetServerConfig(c)
25 out := map[string]map[string]string{}
26
27 for _, v := range cfg.BindConfig.Views() {
28 k := map[string]string{}
29 out[v] = k
30 for _, z := range cfg.BindConfig.ZonesInView(v) {
31 zn := bind.DeCanonicalize(z.Name)
32 k[zn] = util.MakeURL(c.Request, "/dns/zone/%s/%s", v, zn).String()
33 }
34 }
35
36 c.IndentedJSON(http.StatusOK, gin.H{"views": out})
37}
38
39func DnsZones(c *gin.Context) {
40
41}
42
43func DnsZoneDetails(c *gin.Context) {
44 cfg := middleware.GetServerConfig(c)
45
46 z := cfg.BindConfig.Zone(c.Param("view"), c.Param("name"))
47 if z == nil {
48 c.JSON(http.StatusNotFound, gin.H{
49 "error": "Zone not found",
50 })
51 return
52 }
53
54 envs := []*dns.Envelope{}
55 ec, err := cfg.DNSClient.AXFR(z)
56 if err != nil {
57 c.JSON(http.StatusInternalServerError, gin.H{
58 "error": err.Error(),
59 })
60 return
61 }
62
63 for e := range ec {
64 envs = append(envs, e)
65 }
66
67 c.JSON(http.StatusOK, envs)
68}