Initial commit
This commit is contained in:
commit
96854b566a
23 changed files with 2402 additions and 0 deletions
56
checker/interactive.go
Normal file
56
checker/interactive.go
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
//go:build standalone
|
||||
|
||||
package checker
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
sdk "git.happydns.org/checker-sdk-go/checker"
|
||||
)
|
||||
|
||||
// RenderForm exposes the minimal human-facing inputs needed to run a SIP
|
||||
// check standalone. Collect resolves NAPTR/SRV itself, so the fields
|
||||
// come straight from the canonical option documentation in
|
||||
// Definition() (RunOpts then AdminOpts), keeping the two in lock-step.
|
||||
func (p *sipProvider) RenderForm() []sdk.CheckerOptionField {
|
||||
def := p.Definition()
|
||||
fields := make([]sdk.CheckerOptionField, 0, len(def.Options.RunOpts)+len(def.Options.AdminOpts))
|
||||
fields = append(fields, def.Options.RunOpts...)
|
||||
fields = append(fields, def.Options.AdminOpts...)
|
||||
for i := range fields {
|
||||
if fields[i].Id == "domain" && fields[i].Placeholder == "" {
|
||||
fields[i].Placeholder = "example.com"
|
||||
}
|
||||
}
|
||||
return fields
|
||||
}
|
||||
|
||||
// ParseForm turns the submitted form into a CheckerOptions. The SIP
|
||||
// Collect path performs its own DNS lookups, so there is nothing to
|
||||
// pre-resolve here.
|
||||
func (p *sipProvider) ParseForm(r *http.Request) (sdk.CheckerOptions, error) {
|
||||
domain := strings.TrimSpace(r.FormValue("domain"))
|
||||
if domain == "" {
|
||||
return nil, errors.New("domain is required")
|
||||
}
|
||||
|
||||
opts := sdk.CheckerOptions{
|
||||
"domain": domain,
|
||||
"probeUDP": r.FormValue("probeUDP") == "true",
|
||||
"probeTCP": r.FormValue("probeTCP") == "true",
|
||||
"probeTLS": r.FormValue("probeTLS") == "true",
|
||||
}
|
||||
|
||||
if v := strings.TrimSpace(r.FormValue("timeout")); v != "" {
|
||||
f, err := strconv.ParseFloat(v, 64)
|
||||
if err != nil {
|
||||
return nil, errors.New("timeout must be a number")
|
||||
}
|
||||
opts["timeout"] = f
|
||||
}
|
||||
|
||||
return opts, nil
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue