Initial commit
This commit is contained in:
commit
65859f516d
18 changed files with 1799 additions and 0 deletions
51
checker/interactive.go
Normal file
51
checker/interactive.go
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
package checker
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
sdk "git.happydns.org/checker-sdk-go/checker"
|
||||
)
|
||||
|
||||
// RenderForm exposes a single "name" input for the standalone /check route.
|
||||
func (p *aliasProvider) RenderForm() []sdk.CheckerOptionField {
|
||||
return []sdk.CheckerOptionField{
|
||||
{
|
||||
Id: "name",
|
||||
Type: "string",
|
||||
Label: "Domain name to check",
|
||||
Placeholder: "alias.example.com",
|
||||
Required: true,
|
||||
Description: "Fully-qualified name carrying (or suspected of carrying) a CNAME / DNAME / ALIAS record.",
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// ParseForm turns the submitted name into a minimal CheckerOptions set. We
|
||||
// let the collector discover the apex on its own.
|
||||
func (p *aliasProvider) ParseForm(r *http.Request) (sdk.CheckerOptions, error) {
|
||||
name := strings.TrimSpace(r.FormValue("name"))
|
||||
if name == "" {
|
||||
return nil, errors.New("name is required")
|
||||
}
|
||||
name = strings.TrimSuffix(name, ".")
|
||||
|
||||
// Split into subdomain + parent-like domain_name. The collector accepts
|
||||
// either representation; we hand both keys so rules that autoscope on
|
||||
// domain_name still work.
|
||||
parts := strings.SplitN(name, ".", 2)
|
||||
sub := parts[0]
|
||||
parent := ""
|
||||
if len(parts) == 2 {
|
||||
parent = parts[1]
|
||||
} else {
|
||||
parent = name
|
||||
sub = ""
|
||||
}
|
||||
|
||||
return sdk.CheckerOptions{
|
||||
"domain_name": parent,
|
||||
"subdomain": sub,
|
||||
}, nil
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue