Initial Project

This commit is contained in:
2024-01-17 15:56:44 +13:00
parent 196e17cd29
commit 1e5f136257
14 changed files with 307 additions and 244 deletions

View File

@@ -30,7 +30,7 @@ help:
build: build:
@echo "building ${BIN_NAME} ${VERSION}" @echo "building ${BIN_NAME} ${VERSION}"
@echo "GOPATH=${GOPATH}" @echo "GOPATH=${GOPATH}"
go build -ldflags "-X github.com/guisea/directdnsonly/version.GitCommit=${GIT_COMMIT}${GIT_DIRTY} -X github.com/guisea/directdnsonly/version.BuildDate=${BUILD_DATE}" -o bin/${BIN_NAME} go build -o bin/directdnsonly -ldflags "-X github.com/guisea/directdnsonly/version.GitCommit=196e17cd2963ed5724cf76c29c491a17f44b48de+CHANGES -X github.com/guisea/directdnsonly/version.BuildDate=${BUILD_DATE}" cmd/directdnsonly/main.go
get-deps: get-deps:
dep ensure dep ensure

58
cmd/directdnsonly/main.go Normal file
View File

@@ -0,0 +1,58 @@
package main
import (
"crypto/subtle"
"net/http"
"os"
"time"
"github.com/guisea/directdnsonly/internal/handlers"
"github.com/guisea/directdnsonly/internal/version"
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
echoLog "github.com/labstack/gommon/log"
EchoLogrusMiddleware "github.com/neko-neko/echo-logrus/v2"
"github.com/neko-neko/echo-logrus/v2/log"
"github.com/sirupsen/logrus"
)
func main() {
e := echo.New()
e.HideBanner = true
e.HidePort = true
e.Debug = true
// Logger Handler
log.Logger().SetOutput(os.Stdout)
log.Logger().SetLevel(echoLog.INFO)
log.Logger().SetFormatter(&logrus.JSONFormatter{
TimestampFormat: time.RFC3339,
})
e.Logger = log.Logger()
e.Use(middleware.Recover(),
EchoLogrusMiddleware.Logger(),
middleware.RequestID(),
middleware.BasicAuth(func(username, password string, c echo.Context) (bool, error) {
// Be careful to use constant time comparison to prevent timing attacks
if subtle.ConstantTimeCompare([]byte(username), []byte("test")) == 1 &&
subtle.ConstantTimeCompare([]byte(password), []byte("test")) == 1 {
return true, nil
}
return false, nil
}))
e.GET("/", func(c echo.Context) error {
return c.String(http.StatusOK, "Hello, World!")
})
e.GET("/CMD_API_LOGIN_TEST", handlers.LoginTest)
e.Match([]string{"GET", "POST"}, "/CMD_API_DNS_ADMIN", handlers.DNSAdmin)
log.Info("Directdnsonly Version: " + version.Version + " Started!!")
log.Info("Build Date: ", version.BuildDate)
log.Info("Go Version: ", version.GoVersion)
log.Info("OS / Arch: ", version.OsArch)
e.Logger.Fatal(e.Start(":1323"))
}

32
go.mod
View File

@@ -1,7 +1,37 @@
module github.com/guisea/directdnsonly module github.com/guisea/directdnsonly
go 1.20
require ( require (
github.com/labstack/echo/v4 v4.11.4
github.com/labstack/gommon v0.4.2
github.com/neko-neko/echo-logrus/v2 v2.0.2
github.com/sirupsen/logrus v1.4.1 github.com/sirupsen/logrus v1.4.1
github.com/spf13/viper v1.3.2 github.com/spf13/viper v1.3.2
) )
require (
github.com/BurntSushi/toml v1.3.2 // indirect
github.com/fsnotify/fsnotify v1.4.7 // indirect
github.com/golang-jwt/jwt v3.2.2+incompatible // indirect
github.com/google/go-querystring v1.1.0 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/konsorten/go-windows-terminal-sequences v1.0.1 // indirect
github.com/magiconair/properties v1.8.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mitchellh/mapstructure v1.1.2 // indirect
github.com/pelletier/go-toml v1.2.0 // indirect
github.com/spf13/afero v1.1.2 // indirect
github.com/spf13/cast v1.3.0 // indirect
github.com/spf13/jwalterweatherman v1.0.0 // indirect
github.com/spf13/pflag v1.0.3 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasttemplate v1.2.2 // indirect
golang.org/x/crypto v0.17.0 // indirect
golang.org/x/net v0.19.0 // indirect
golang.org/x/sys v0.15.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/time v0.5.0 // indirect
gopkg.in/yaml.v2 v2.2.2 // indirect
)

108
go.sum Normal file
View File

@@ -0,0 +1,108 @@
github.com/BurntSushi/toml v1.3.2 h1:o7IhLm0Msx3BaB+n3Ag7L8EVlByGnpq14C4YWiu/gL8=
github.com/BurntSushi/toml v1.3.2/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8=
github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=
github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8NzMklzPG4d5KIOhIy30Tk=
github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/golang-jwt/jwt v3.2.2+incompatible h1:IfV12K8xAKAnZqdXVzCZ+TOjboZ2keLg81eXfW3O+oY=
github.com/golang-jwt/jwt v3.2.2+incompatible/go.mod h1:8pz2t5EyA70fFQQSrl6XZXzqecmYZeUEB8OUGHkxJ+I=
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/labstack/echo/v4 v4.9.0/go.mod h1:xkCDAdFCIf8jsFQ5NnbK7oqaF/yU1A1X20Ltm0OvSks=
github.com/labstack/echo/v4 v4.11.4 h1:vDZmA+qNeh1pd/cCkEicDMrjtrnMGQ1QFI9gWN1zGq8=
github.com/labstack/echo/v4 v4.11.4/go.mod h1:noh7EvLwqDsmh/X/HWKPUl1AjzJrhyptRyEbQJfxen8=
github.com/labstack/gommon v0.3.1/go.mod h1:uW6kP17uPlLJsD3ijUYn3/M5bAxtlZhMI6m3MFxTMTM=
github.com/labstack/gommon v0.4.2 h1:F8qTUNXgG1+6WQmqoUWnz8WiEU60mXVVw0P4ht1WRA0=
github.com/labstack/gommon v0.4.2/go.mod h1:QlUFxVM+SNXhDL/Z7YhocGIBYOiwB0mXm1+1bAPHPyU=
github.com/magiconair/properties v1.8.0 h1:LLgXmsheXeRoUOBOjtwPQCWIYqM/LU1ayDtDePerRcY=
github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
github.com/mattn/go-colorable v0.1.11/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mitchellh/mapstructure v1.1.2 h1:fmNYVwqnSfB9mZU6OS2O6GsXM+wcskZDuKQzvN1EDeE=
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
github.com/neko-neko/echo-logrus/v2 v2.0.2 h1:K3U1JuozTyr14i2K8WlsLVsOHVvgaMJ3Dinj2MQWhZA=
github.com/neko-neko/echo-logrus/v2 v2.0.2/go.mod h1:AdodA1LU71JAxHBzs1NxoHbrys9iiX9HuEFEAUJ2ybQ=
github.com/pelletier/go-toml v1.2.0 h1:T5zMGML61Wp+FlcbWjRDT7yAxhJNAiPPLOFECq181zc=
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/sirupsen/logrus v1.3.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
github.com/sirupsen/logrus v1.4.1 h1:GL2rEmy6nsikmW0r8opw9JIRScdMF5hA8cOYLH7In1k=
github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q=
github.com/spf13/afero v1.1.2 h1:m8/z1t7/fwjysjQRYbP0RD+bUIF/8tJwPdEZsI83ACI=
github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ=
github.com/spf13/cast v1.3.0 h1:oget//CVOEoFewqQxwr0Ej5yjygnqGkvggSE/gB35Q8=
github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
github.com/spf13/jwalterweatherman v1.0.0 h1:XHEdyB+EcvlqZamSM4ZOMGlc93t6AcsBEu9Gc1vn7yk=
github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo=
github.com/spf13/pflag v1.0.3 h1:zPAT6CGy6wXeQ7NtTnaTerfKOsV6V6F8agHXFiazDkg=
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/spf13/viper v1.3.2 h1:VUFqw5KcqRf7i70GOzW7N+Q7+gxVBkSSqiXB12+JQ4M=
github.com/spf13/viper v1.3.2/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DMA2s=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0=
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
github.com/valyala/fasttemplate v1.2.1/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ=
github.com/valyala/fasttemplate v1.2.2 h1:lxLXG0uE3Qnshl9QyaK6XJxMXlQZELvChBOCmQD0Loo=
github.com/valyala/fasttemplate v1.2.2/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ=
github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q=
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.17.0 h1:r8bRNjWL3GshPW3gkd+RpvzWrZAwPS49OmTGZ/uhM4k=
golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.19.0 h1:zTwKpTd2XuCqf8huc7Fo2iSy+4RHPd10s4KzeTnVr1c=
golang.org/x/net v0.19.0/go.mod h1:CfAk/cbD4CthTvqiEl8NpboMuiuOYsAr/7NOjZJtv1U=
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20181205085412-a5c9d58dba9a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211103235746-7861aae1554b/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc=
golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/time v0.0.0-20201208040808-7e3f01d25324/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.5.0 h1:o7cqy6amK/52YcAKIPlM3a+Fpj35zvRj2TP+e1xFSfk=
golang.org/x/time v0.5.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=

View 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
}

View 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))
}

View 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"`
}

View File

@@ -0,0 +1 @@
package providers

View File

@@ -0,0 +1 @@
package providers

View 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
View 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()
}

View File

@@ -1,216 +0,0 @@
package log
import (
"os"
"github.com/sirupsen/logrus"
"github.com/guisea/directdnsonly/config"
)
// Logger defines a set of methods for writing application logs. Derived from and
// inspired by logrus.Entry.
type Logger interface {
Debug(args ...interface{})
Debugf(format string, args ...interface{})
Debugln(args ...interface{})
Error(args ...interface{})
Errorf(format string, args ...interface{})
Errorln(args ...interface{})
Fatal(args ...interface{})
Fatalf(format string, args ...interface{})
Fatalln(args ...interface{})
Info(args ...interface{})
Infof(format string, args ...interface{})
Infoln(args ...interface{})
Panic(args ...interface{})
Panicf(format string, args ...interface{})
Panicln(args ...interface{})
Print(args ...interface{})
Printf(format string, args ...interface{})
Println(args ...interface{})
Warn(args ...interface{})
Warnf(format string, args ...interface{})
Warning(args ...interface{})
Warningf(format string, args ...interface{})
Warningln(args ...interface{})
Warnln(args ...interface{})
}
var defaultLogger *logrus.Logger
func init() {
defaultLogger = newLogrusLogger(config.Config())
}
// NewLogger returns a configured logrus instance
func NewLogger(cfg config.Provider) *logrus.Logger {
return newLogrusLogger(cfg)
}
func newLogrusLogger(cfg config.Provider) *logrus.Logger {
l := logrus.New()
if cfg.GetBool("json_logs") {
l.Formatter = new(logrus.JSONFormatter)
}
l.Out = os.Stderr
switch cfg.GetString("loglevel") {
case "debug":
l.Level = logrus.DebugLevel
case "warning":
l.Level = logrus.WarnLevel
case "info":
l.Level = logrus.InfoLevel
default:
l.Level = logrus.DebugLevel
}
return l
}
// Fields is a map string interface to define fields in the structured log
type Fields map[string]interface{}
// With allow us to define fields in out structured logs
func (f Fields) With(k string, v interface{}) Fields {
f[k] = v
return f
}
// WithFields allow us to define fields in out structured logs
func (f Fields) WithFields(f2 Fields) Fields {
for k, v := range f2 {
f[k] = v
}
return f
}
// WithFields allow us to define fields in out structured logs
func WithFields(fields Fields) Logger {
return defaultLogger.WithFields(logrus.Fields(fields))
}
// Debug package-level convenience method.
func Debug(args ...interface{}) {
defaultLogger.Debug(args...)
}
// Debugf package-level convenience method.
func Debugf(format string, args ...interface{}) {
defaultLogger.Debugf(format, args...)
}
// Debugln package-level convenience method.
func Debugln(args ...interface{}) {
defaultLogger.Debugln(args...)
}
// Error package-level convenience method.
func Error(args ...interface{}) {
defaultLogger.Error(args...)
}
// Errorf package-level convenience method.
func Errorf(format string, args ...interface{}) {
defaultLogger.Errorf(format, args...)
}
// Errorln package-level convenience method.
func Errorln(args ...interface{}) {
defaultLogger.Errorln(args...)
}
// Fatal package-level convenience method.
func Fatal(args ...interface{}) {
defaultLogger.Fatal(args...)
}
// Fatalf package-level convenience method.
func Fatalf(format string, args ...interface{}) {
defaultLogger.Fatalf(format, args...)
}
// Fatalln package-level convenience method.
func Fatalln(args ...interface{}) {
defaultLogger.Fatalln(args...)
}
// Info package-level convenience method.
func Info(args ...interface{}) {
defaultLogger.Info(args...)
}
// Infof package-level convenience method.
func Infof(format string, args ...interface{}) {
defaultLogger.Infof(format, args...)
}
// Infoln package-level convenience method.
func Infoln(args ...interface{}) {
defaultLogger.Infoln(args...)
}
// Panic package-level convenience method.
func Panic(args ...interface{}) {
defaultLogger.Panic(args...)
}
// Panicf package-level convenience method.
func Panicf(format string, args ...interface{}) {
defaultLogger.Panicf(format, args...)
}
// Panicln package-level convenience method.
func Panicln(args ...interface{}) {
defaultLogger.Panicln(args...)
}
// Print package-level convenience method.
func Print(args ...interface{}) {
defaultLogger.Print(args...)
}
// Printf package-level convenience method.
func Printf(format string, args ...interface{}) {
defaultLogger.Printf(format, args...)
}
// Println package-level convenience method.
func Println(args ...interface{}) {
defaultLogger.Println(args...)
}
// Warn package-level convenience method.
func Warn(args ...interface{}) {
defaultLogger.Warn(args...)
}
// Warnf package-level convenience method.
func Warnf(format string, args ...interface{}) {
defaultLogger.Warnf(format, args...)
}
// Warning package-level convenience method.
func Warning(args ...interface{}) {
defaultLogger.Warning(args...)
}
// Warningf package-level convenience method.
func Warningf(format string, args ...interface{}) {
defaultLogger.Warningf(format, args...)
}
// Warningln package-level convenience method.
func Warningln(args ...interface{}) {
defaultLogger.Warningln(args...)
}
// Warnln package-level convenience method.
func Warnln(args ...interface{}) {
defaultLogger.Warnln(args...)
}

26
main.go
View File

@@ -1,26 +0,0 @@
package main
import (
"flag"
"fmt"
"github.com/guisea/directdnsonly/version"
)
func main() {
versionFlag := flag.Bool("version", false, "Version")
flag.Parse()
if *versionFlag {
fmt.Println("Build Date:", version.BuildDate)
fmt.Println("Git Commit:", version.GitCommit)
fmt.Println("Version:", version.Version)
fmt.Println("Go Version:", version.GoVersion)
fmt.Println("OS / Arch:", version.OsArch)
return
}
fmt.Println("Hello.")
}