summaryrefslogtreecommitdiff
path: root/web/controllers/manage.go
diff options
context:
space:
mode:
Diffstat (limited to 'web/controllers/manage.go')
-rw-r--r--web/controllers/manage.go61
1 files changed, 61 insertions, 0 deletions
diff --git a/web/controllers/manage.go b/web/controllers/manage.go
new file mode 100644
index 0000000..53a38a6
--- /dev/null
+++ b/web/controllers/manage.go
@@ -0,0 +1,61 @@
1package controllers
2
3import (
4 "net/http"
5
6 "github.com/gin-gonic/gin"
7
8 "code.crute.me/mcrute/frame"
9 "code.crute.me/mcrute/go_ddns_manager/dns"
10 "code.crute.me/mcrute/go_ddns_manager/web/middleware"
11)
12
13type UpdateZone struct {
14 Create []dns.RR
15 Update []dns.RR
16 Delete []dns.RR
17}
18
19func ManageRoot(c *gin.Context) {
20 c.JSON(http.StatusOK, map[string]string{
21 "views_url": frame.MakeURL(c.Request, "/manage/views").String(),
22 })
23}
24
25func ListViews(c *gin.Context) {
26 cfg := middleware.GetServerConfig(c)
27
28 out := map[string]string{}
29
30 for _, vn := range cfg.BindConfig.Views() {
31 out[vn] = frame.MakeURL(c.Request, "/manage/views/%s", vn).String()
32 }
33
34 c.JSON(http.StatusOK, out)
35}
36
37func ListView(c *gin.Context) {
38 cfg := middleware.GetServerConfig(c)
39 view := c.Param("view")
40
41 out := map[string]string{}
42
43 for _, z := range cfg.BindConfig.ZonesInView(view) {
44 out[z.Name] = frame.MakeURL(c.Request, "/manage/views/%s/%s", view, z.Name).String()
45 }
46
47 c.JSON(http.StatusOK, out)
48}
49
50func ListZone(c *gin.Context) {
51 cfg := middleware.GetServerConfig(c)
52 zone := cfg.BindConfig.Zone(c.Param("view"), c.Param("zone"))
53
54 rrs, err := cfg.DNSClient.ReadRemoteZone(zone)
55 if err != nil {
56 c.JSON(http.StatusInternalServerError, err)
57 return
58 }
59
60 c.JSON(http.StatusOK, rrs)
61}