mirror of
https://github.com/MarekWojt/gertdns.git
synced 2025-12-15 12:59:53 +01:00
Merge pull request #5 from MarekWojt/feature/update-both
update ipv6 + ipv4 at once
This commit is contained in:
35
web/web.go
35
web/web.go
@@ -28,6 +28,7 @@ func Init(debugMode bool) {
|
|||||||
r.GET("/", index)
|
r.GET("/", index)
|
||||||
r.GET("/update/{domain}/v4", authenticatedRequest(updateV4))
|
r.GET("/update/{domain}/v4", authenticatedRequest(updateV4))
|
||||||
r.GET("/update/{domain}/v6", authenticatedRequest(updateV6))
|
r.GET("/update/{domain}/v6", authenticatedRequest(updateV6))
|
||||||
|
r.GET("/update/{domain}", authenticatedRequest(update))
|
||||||
}
|
}
|
||||||
|
|
||||||
func RunSocket() error {
|
func RunSocket() error {
|
||||||
@@ -124,6 +125,40 @@ func updateV6(ctx *fasthttp.RequestCtx) {
|
|||||||
ctx.WriteString("OK")
|
ctx.WriteString("OK")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func update(ctx *fasthttp.RequestCtx) {
|
||||||
|
domain := ctx.UserValue("domain").(string)
|
||||||
|
domain = util.ParseDomain(domain)
|
||||||
|
|
||||||
|
ipv4 := string(ctx.QueryArgs().PeekBytes(ipv4Param))
|
||||||
|
ipv6 := string(ctx.QueryArgs().PeekBytes(ipv6Param))
|
||||||
|
|
||||||
|
if ipv4 == "" && ipv6 == "" {
|
||||||
|
ctx.WriteString("Provide at least one these query parameters: ipv4, ipv6")
|
||||||
|
ctx.SetStatusCode(fasthttp.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if ipv4 != "" {
|
||||||
|
err := dns.UpdateIpv4(domain, ipv4)
|
||||||
|
if err != nil {
|
||||||
|
ctx.WriteString(err.Error())
|
||||||
|
ctx.SetStatusCode(fasthttp.StatusNotFound)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ipv6 != "" {
|
||||||
|
err := dns.UpdateIpv4(domain, ipv4)
|
||||||
|
if err != nil {
|
||||||
|
ctx.WriteString(err.Error())
|
||||||
|
ctx.SetStatusCode(fasthttp.StatusNotFound)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx.WriteString("OK")
|
||||||
|
}
|
||||||
|
|
||||||
func authenticatedRequest(request func(ctx *fasthttp.RequestCtx)) func(ctx *fasthttp.RequestCtx) {
|
func authenticatedRequest(request func(ctx *fasthttp.RequestCtx)) func(ctx *fasthttp.RequestCtx) {
|
||||||
return func(ctx *fasthttp.RequestCtx) {
|
return func(ctx *fasthttp.RequestCtx) {
|
||||||
domain, ok := ctx.UserValue("domain").(string)
|
domain, ok := ctx.UserValue("domain").(string)
|
||||||
|
|||||||
Reference in New Issue
Block a user