From 5ba745982e53d4a406b1226484189cb4cfd17d1c Mon Sep 17 00:00:00 2001 From: Pierre-Olivier Mercier Date: Sun, 26 Apr 2026 17:19:20 +0700 Subject: [PATCH] checker: add standalone interactive form and test target Implement RenderForm/ParseForm for the zonemasterProvider under the standalone build tag, enabling browser-based interactive use. Also add a `make test` target that builds with the same tag. --- Makefile | 7 +++-- checker/interactive.go | 69 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+), 2 deletions(-) create mode 100644 checker/interactive.go diff --git a/Makefile b/Makefile index 002307b..ae3f98c 100644 --- a/Makefile +++ b/Makefile @@ -6,12 +6,12 @@ CHECKER_SOURCES := main.go $(wildcard checker/*.go) GO_LDFLAGS := -X main.Version=$(CHECKER_VERSION) -.PHONY: all plugin docker clean +.PHONY: all plugin docker test clean all: $(CHECKER_NAME) $(CHECKER_NAME): $(CHECKER_SOURCES) - go build -ldflags "$(GO_LDFLAGS)" -o $@ . + go build -tags standalone -ldflags "$(GO_LDFLAGS)" -o $@ . plugin: $(CHECKER_NAME).so @@ -21,5 +21,8 @@ $(CHECKER_NAME).so: $(CHECKER_SOURCES) $(wildcard plugin/*.go) docker: docker build --build-arg CHECKER_VERSION=$(CHECKER_VERSION) -t $(CHECKER_IMAGE) . +test: + go test -tags standalone ./... + clean: rm -f $(CHECKER_NAME) $(CHECKER_NAME).so diff --git a/checker/interactive.go b/checker/interactive.go new file mode 100644 index 0000000..95dcca6 --- /dev/null +++ b/checker/interactive.go @@ -0,0 +1,69 @@ +//go:build standalone + +package checker + +import ( + "errors" + "net/http" + "strings" + + sdk "git.happydns.org/checker-sdk-go/checker" +) + +func (p *zonemasterProvider) RenderForm() []sdk.CheckerOptionField { + return []sdk.CheckerOptionField{ + { + Id: "domainName", + Type: "string", + Label: "Domain name to check", + Placeholder: "example.com", + Required: true, + Description: "Fully-qualified domain name to submit to the Zonemaster engine.", + }, + { + Id: "profile", + Type: "string", + Label: "Profile", + Placeholder: "default", + Description: "Zonemaster test profile to apply (engine-defined; usually \"default\").", + }, + { + Id: "language", + Type: "string", + Label: "Result language", + Placeholder: "en", + Description: "Language for human-readable test messages (en, fr, de, es, sv, da, fi, nb, nl, pt).", + }, + { + Id: "zonemasterAPIURL", + Type: "string", + Label: "Zonemaster API URL", + Placeholder: "https://zonemaster.net/api", + Description: "JSON-RPC endpoint of the Zonemaster backend to query.", + }, + } +} + +func (p *zonemasterProvider) ParseForm(r *http.Request) (sdk.CheckerOptions, error) { + domainName := strings.TrimSpace(r.FormValue("domainName")) + if domainName == "" { + return nil, errors.New("domainName is required") + } + domainName = strings.TrimSuffix(domainName, ".") + + opts := sdk.CheckerOptions{ + "domainName": domainName, + } + + if v := strings.TrimSpace(r.FormValue("profile")); v != "" { + opts["profile"] = v + } + if v := strings.TrimSpace(r.FormValue("language")); v != "" { + opts["language"] = v + } + if v := strings.TrimSpace(r.FormValue("zonemasterAPIURL")); v != "" { + opts["zonemasterAPIURL"] = strings.TrimSuffix(v, "/") + } + + return opts, nil +}