diff options
author | Mike Crute <mike@crute.us> | 2020-02-13 23:14:18 +0000 |
---|---|---|
committer | Mike Crute <mike@crute.us> | 2020-08-11 02:56:10 +0000 |
commit | fa346cbe0ab89b3a3c02d8fae85dc5aa471b62a3 (patch) | |
tree | fbd2d45cdaab047ed93733399f9048716b479217 /web/middleware/dns_manage.go | |
parent | 1010edcba255040f8e4140f45f9113969d79effb (diff) | |
download | go_ddns_manager-fa346cbe0ab89b3a3c02d8fae85dc5aa471b62a3.tar.bz2 go_ddns_manager-fa346cbe0ab89b3a3c02d8fae85dc5aa471b62a3.tar.xz go_ddns_manager-fa346cbe0ab89b3a3c02d8fae85dc5aa471b62a3.zip |
WIP: Add more management controllerswip-more-management
Diffstat (limited to 'web/middleware/dns_manage.go')
-rw-r--r-- | web/middleware/dns_manage.go | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/web/middleware/dns_manage.go b/web/middleware/dns_manage.go new file mode 100644 index 0000000..d3b420b --- /dev/null +++ b/web/middleware/dns_manage.go | |||
@@ -0,0 +1,33 @@ | |||
1 | package middleware | ||
2 | |||
3 | import ( | ||
4 | "net/http" | ||
5 | |||
6 | "github.com/gin-gonic/gin" | ||
7 | ) | ||
8 | |||
9 | const dnsUserId = "DNSManageUserID" | ||
10 | |||
11 | func DnsManageAuthMiddleware(c *gin.Context) { | ||
12 | cfg := GetServerConfig(c) | ||
13 | |||
14 | user, pwd, ok := c.Request.BasicAuth() | ||
15 | if !ok { | ||
16 | c.Request.Header.Set("WWW-Authenticate", `Basic realm="closed site"`) | ||
17 | c.AbortWithStatus(http.StatusUnauthorized) | ||
18 | return | ||
19 | } | ||
20 | |||
21 | if !cfg.DNSUserAuth(user, pwd) { | ||
22 | c.AbortWithStatus(http.StatusForbidden) | ||
23 | return | ||
24 | } else { | ||
25 | c.Set(dnsUserId, user) | ||
26 | } | ||
27 | |||
28 | c.Next() | ||
29 | } | ||
30 | |||
31 | func GetDnsAuthContext(c *gin.Context) string { | ||
32 | return c.GetString(dnsUserId) | ||
33 | } | ||