diff options
author | Mike Crute <mike@crute.us> | 2020-11-10 02:36:04 +0000 |
---|---|---|
committer | Mike Crute <mike@crute.us> | 2020-11-10 02:36:04 +0000 |
commit | 150abd9e30c17aa45b50de9ff178ccf3443b0b20 (patch) | |
tree | 20c5a244722184283173a3822f380c0db675ee6e /web | |
parent | 52eb9dc9fc1e0472aea4fd5bd0bb7ea259431d41 (diff) | |
download | go_ddns_manager-150abd9e30c17aa45b50de9ff178ccf3443b0b20.tar.bz2 go_ddns_manager-150abd9e30c17aa45b50de9ff178ccf3443b0b20.tar.xz go_ddns_manager-150abd9e30c17aa45b50de9ff178ccf3443b0b20.zip |
Extract web framework
Diffstat (limited to 'web')
-rw-r--r-- | web/config.go | 27 | ||||
-rw-r--r-- | web/controllers/acme.go | 4 | ||||
-rw-r--r-- | web/controllers/ddns.go | 4 | ||||
-rw-r--r-- | web/controllers/reflect_ip.go | 4 |
4 files changed, 6 insertions, 33 deletions
diff --git a/web/config.go b/web/config.go index 2479e38..b307425 100644 --- a/web/config.go +++ b/web/config.go | |||
@@ -1,8 +1,6 @@ | |||
1 | package web | 1 | package web |
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | "encoding/json" | ||
5 | "io/ioutil" | ||
6 | "strings" | 4 | "strings" |
7 | 5 | ||
8 | "code.crute.me/mcrute/go_ddns_manager/bind" | 6 | "code.crute.me/mcrute/go_ddns_manager/bind" |
@@ -18,31 +16,6 @@ type ServerConfig struct { | |||
18 | AcmeSecrets map[string]map[string]int `json:"ACME"` | 16 | AcmeSecrets map[string]map[string]int `json:"ACME"` |
19 | } | 17 | } |
20 | 18 | ||
21 | func LoadServerConfig(zonesFile, secretsFile, server, view string) (*ServerConfig, error) { | ||
22 | scfg := &ServerConfig{ | ||
23 | DNSClient: &dns.DNSClient{Server: server}, | ||
24 | AcmeView: view, | ||
25 | DynamicDnsView: view, | ||
26 | } | ||
27 | |||
28 | cfg, err := bind.ParseBINDConfig(zonesFile) | ||
29 | if err != nil { | ||
30 | return nil, err | ||
31 | } | ||
32 | scfg.BindConfig = cfg | ||
33 | |||
34 | fd, err := ioutil.ReadFile(secretsFile) | ||
35 | if err != nil { | ||
36 | return nil, err | ||
37 | } | ||
38 | |||
39 | if err = json.Unmarshal(fd, scfg); err != nil { | ||
40 | return nil, err | ||
41 | } | ||
42 | |||
43 | return scfg, nil | ||
44 | } | ||
45 | |||
46 | func (s *ServerConfig) GetDDNSZoneName(k string) string { | 19 | func (s *ServerConfig) GetDDNSZoneName(k string) string { |
47 | v, _ := s.DDNSSecrets[k] | 20 | v, _ := s.DDNSSecrets[k] |
48 | return v | 21 | return v |
diff --git a/web/controllers/acme.go b/web/controllers/acme.go index 5090b70..457bee6 100644 --- a/web/controllers/acme.go +++ b/web/controllers/acme.go | |||
@@ -9,8 +9,8 @@ import ( | |||
9 | 9 | ||
10 | "github.com/gin-gonic/gin" | 10 | "github.com/gin-gonic/gin" |
11 | 11 | ||
12 | "code.crute.me/mcrute/frame" | ||
12 | "code.crute.me/mcrute/go_ddns_manager/dns" | 13 | "code.crute.me/mcrute/go_ddns_manager/dns" |
13 | "code.crute.me/mcrute/go_ddns_manager/util" | ||
14 | "code.crute.me/mcrute/go_ddns_manager/web/middleware" | 14 | "code.crute.me/mcrute/go_ddns_manager/web/middleware" |
15 | ) | 15 | ) |
16 | 16 | ||
@@ -103,7 +103,7 @@ func CreateAcmeChallenge(c *gin.Context) { | |||
103 | return | 103 | return |
104 | } | 104 | } |
105 | 105 | ||
106 | url := util.MakeURL(c.Request, "/acme/%s", AcmeChallengeID{ | 106 | url := frame.MakeURL(c.Request, "/acme/%s", AcmeChallengeID{ |
107 | Zone: zone.Name, | 107 | Zone: zone.Name, |
108 | Prefix: prefix, | 108 | Prefix: prefix, |
109 | Challenge: ch.Challenge, | 109 | Challenge: ch.Challenge, |
diff --git a/web/controllers/ddns.go b/web/controllers/ddns.go index d476255..201ee0d 100644 --- a/web/controllers/ddns.go +++ b/web/controllers/ddns.go | |||
@@ -7,8 +7,8 @@ import ( | |||
7 | "github.com/gin-gonic/gin" | 7 | "github.com/gin-gonic/gin" |
8 | godns "github.com/miekg/dns" | 8 | godns "github.com/miekg/dns" |
9 | 9 | ||
10 | "code.crute.me/mcrute/frame" | ||
10 | "code.crute.me/mcrute/go_ddns_manager/dns" | 11 | "code.crute.me/mcrute/go_ddns_manager/dns" |
11 | "code.crute.me/mcrute/go_ddns_manager/util" | ||
12 | "code.crute.me/mcrute/go_ddns_manager/web/middleware" | 12 | "code.crute.me/mcrute/go_ddns_manager/web/middleware" |
13 | ) | 13 | ) |
14 | 14 | ||
@@ -29,7 +29,7 @@ func UpdateDynamicDNS(c *gin.Context) { | |||
29 | return | 29 | return |
30 | } | 30 | } |
31 | 31 | ||
32 | inip := util.GetRequestIP(c) | 32 | inip := frame.GetRequestIP(c) |
33 | if inip == nil { | 33 | if inip == nil { |
34 | log.Println("ddns: Unable to parse IP") | 34 | log.Println("ddns: Unable to parse IP") |
35 | c.AbortWithStatus(http.StatusInternalServerError) | 35 | c.AbortWithStatus(http.StatusInternalServerError) |
diff --git a/web/controllers/reflect_ip.go b/web/controllers/reflect_ip.go index 199d736..556f15b 100644 --- a/web/controllers/reflect_ip.go +++ b/web/controllers/reflect_ip.go | |||
@@ -5,11 +5,11 @@ import ( | |||
5 | 5 | ||
6 | "github.com/gin-gonic/gin" | 6 | "github.com/gin-gonic/gin" |
7 | 7 | ||
8 | "code.crute.me/mcrute/go_ddns_manager/util" | 8 | "code.crute.me/mcrute/frame" |
9 | ) | 9 | ) |
10 | 10 | ||
11 | func ReflectIP(c *gin.Context) { | 11 | func ReflectIP(c *gin.Context) { |
12 | ip := util.GetRequestIP(c) | 12 | ip := frame.GetRequestIP(c) |
13 | if ip == nil { | 13 | if ip == nil { |
14 | c.String(http.StatusInternalServerError, "") | 14 | c.String(http.StatusInternalServerError, "") |
15 | return | 15 | return |