76 lines
1.7 KiB
Go
76 lines
1.7 KiB
Go
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 a domain name
|
|
// is the only required field.
|
|
func (p *sipProvider) RenderForm() []sdk.CheckerOptionField {
|
|
return []sdk.CheckerOptionField{
|
|
{
|
|
Id: "domain",
|
|
Type: "string",
|
|
Label: "SIP domain",
|
|
Placeholder: "example.com",
|
|
Required: true,
|
|
},
|
|
{
|
|
Id: "timeout",
|
|
Type: "number",
|
|
Label: "Per-endpoint timeout (seconds)",
|
|
Default: 5,
|
|
},
|
|
{
|
|
Id: "probeUDP",
|
|
Type: "bool",
|
|
Label: "Probe _sip._udp",
|
|
Default: true,
|
|
},
|
|
{
|
|
Id: "probeTCP",
|
|
Type: "bool",
|
|
Label: "Probe _sip._tcp",
|
|
Default: true,
|
|
},
|
|
{
|
|
Id: "probeTLS",
|
|
Type: "bool",
|
|
Label: "Probe _sips._tcp (TLS)",
|
|
Default: true,
|
|
},
|
|
}
|
|
}
|
|
|
|
// 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
|
|
}
|