You've already forked directdnsonly-go
Initial Project
This commit is contained in:
34
internal/handlers/DNSAdmin.go
Normal file
34
internal/handlers/DNSAdmin.go
Normal file
@@ -0,0 +1,34 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"io"
|
||||
|
||||
"github.com/guisea/directdnsonly/internal/util"
|
||||
"github.com/labstack/echo/v4"
|
||||
)
|
||||
|
||||
func DNSAdmin(c echo.Context) error {
|
||||
// Implementation still to come
|
||||
if c.Request().Method == "POST" {
|
||||
action := c.QueryParam("action")
|
||||
c.Logger().Debug("Action received via querystring: " + action)
|
||||
body := c.Request().Body
|
||||
respBytes, err := io.ReadAll(body)
|
||||
if err != nil {
|
||||
c.Logger().Error(err)
|
||||
}
|
||||
c.Logger().Debugf("Body of request: %s", respBytes)
|
||||
if action == "" {
|
||||
c.Logger().Debug("Action was not found, check body")
|
||||
decoded_params := util.DecodeParams(string(respBytes))
|
||||
|
||||
c.Logger().Debugf("Parameters decoded: %s", decoded_params)
|
||||
action = decoded_params["action"]
|
||||
}
|
||||
// zone_file := body
|
||||
}
|
||||
if c.Request().Method == "GET" {
|
||||
// Implement some stuff
|
||||
}
|
||||
return nil
|
||||
}
|
||||
20
internal/handlers/LoginTest.go
Normal file
20
internal/handlers/LoginTest.go
Normal file
@@ -0,0 +1,20 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/guisea/directdnsonly/internal/responses"
|
||||
"github.com/guisea/directdnsonly/internal/util"
|
||||
"github.com/labstack/echo/v4"
|
||||
)
|
||||
|
||||
// Login - LoginTest endpoint allows DirectAdmin to check login details
|
||||
// As we have set Basic Auth middleware just returns message
|
||||
func LoginTest(c echo.Context) error {
|
||||
// Construct a response
|
||||
resp := responses.DAResponse{}
|
||||
resp.Error = 0
|
||||
resp.Message = "Login OK"
|
||||
// Returns the response to the client
|
||||
return c.String(http.StatusOK, util.EncodeQueryString(resp))
|
||||
}
|
||||
8
internal/providers/base.go
Normal file
8
internal/providers/base.go
Normal file
@@ -0,0 +1,8 @@
|
||||
package providers
|
||||
|
||||
type Provider struct {
|
||||
Error int32 `url:"error"`
|
||||
Exists int32 `url:"exists,omitempty"`
|
||||
Message string `url:"text,omitempty"`
|
||||
Details string `url:"details,omitempty"`
|
||||
}
|
||||
1
internal/providers/bind.go
Normal file
1
internal/providers/bind.go
Normal file
@@ -0,0 +1 @@
|
||||
package providers
|
||||
1
internal/providers/coredns.go
Normal file
1
internal/providers/coredns.go
Normal file
@@ -0,0 +1 @@
|
||||
package providers
|
||||
9
internal/responses/DAResponse.go
Normal file
9
internal/responses/DAResponse.go
Normal file
@@ -0,0 +1,9 @@
|
||||
package responses
|
||||
|
||||
// Definition of expected fields in response to a DirectAdmin instance
|
||||
type DAResponse struct {
|
||||
Error int32 `url:"error"`
|
||||
Exists int32 `url:"exists,omitempty"`
|
||||
Message string `url:"text,omitempty"`
|
||||
Details string `url:"details,omitempty"`
|
||||
}
|
||||
36
internal/util/util.go
Normal file
36
internal/util/util.go
Normal file
@@ -0,0 +1,36 @@
|
||||
package util
|
||||
|
||||
import (
|
||||
"net/url"
|
||||
|
||||
"github.com/google/go-querystring/query"
|
||||
"github.com/guisea/directdnsonly/internal/responses"
|
||||
)
|
||||
|
||||
func DecodeParams(payload string) map[string]string {
|
||||
// Parse the query string from the payload
|
||||
values, err := url.ParseQuery(payload)
|
||||
if err != nil {
|
||||
// Handle error, e.g., log it or return an error value
|
||||
return nil
|
||||
}
|
||||
|
||||
// Initialize a map to store the decoded parameters
|
||||
params := make(map[string]string)
|
||||
|
||||
// Iterate through the parameters
|
||||
for key, val := range values {
|
||||
// Store the first value of each parameter in the map
|
||||
if len(val) > 0 {
|
||||
params[key] = val[0]
|
||||
}
|
||||
}
|
||||
|
||||
// Return the decoded parameters as a map
|
||||
return params
|
||||
}
|
||||
|
||||
func EncodeQueryString(payload responses.DAResponse) string {
|
||||
QueryStringResponse, _ := query.Values(payload)
|
||||
return QueryStringResponse.Encode()
|
||||
}
|
||||
21
internal/version/version.go
Normal file
21
internal/version/version.go
Normal file
@@ -0,0 +1,21 @@
|
||||
package version
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"runtime"
|
||||
)
|
||||
|
||||
// GitCommit returns the git commit that was compiled. This will be filled in by the compiler.
|
||||
var GitCommit string
|
||||
|
||||
// Version returns the main version number that is being run at the moment.
|
||||
const Version = "0.1.0"
|
||||
|
||||
// BuildDate returns the date the binary was built
|
||||
var BuildDate = ""
|
||||
|
||||
// GoVersion returns the version of the go runtime used to compile the binary
|
||||
var GoVersion = runtime.Version()
|
||||
|
||||
// OsArch returns the os and arch used to build the binary
|
||||
var OsArch = fmt.Sprintf("%s %s", runtime.GOOS, runtime.GOARCH)
|
||||
Reference in New Issue
Block a user