85 lines
2.3 KiB
Go
85 lines
2.3 KiB
Go
//go:build standalone
|
|
|
|
package checker
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"net/http"
|
|
"strings"
|
|
|
|
sdk "git.happydns.org/checker-sdk-go/checker"
|
|
)
|
|
|
|
// RenderForm describes the standalone /check page inputs.
|
|
func (p *autoconfigProvider) RenderForm() []sdk.CheckerOptionField {
|
|
return []sdk.CheckerOptionField{
|
|
{
|
|
Id: sdk.AutoFillDomainName,
|
|
Type: "string",
|
|
Label: "Domain name",
|
|
Placeholder: "example.com",
|
|
Required: true,
|
|
Description: "Domain to probe for email autoconfiguration.",
|
|
},
|
|
{
|
|
Id: "probeEmail",
|
|
Type: "string",
|
|
Label: "Local-part used in probes",
|
|
Placeholder: "test",
|
|
Default: "test",
|
|
Description: "Local part sent in the autoconfig URL query string (before @).",
|
|
},
|
|
{
|
|
Id: "tryISPDB",
|
|
Type: "bool",
|
|
Label: "Try Mozilla ISPDB fallback",
|
|
Default: true,
|
|
Description: "Probe Mozilla's public Thunderbird ISPDB when the domain itself does not publish autoconfig.",
|
|
},
|
|
{
|
|
Id: "tryHTTPAutoconfig",
|
|
Type: "bool",
|
|
Label: "Allow plain-HTTP fallback probe",
|
|
Default: false,
|
|
Description: "Also attempt the plain-HTTP variant of autoconfig.<domain>.",
|
|
},
|
|
{
|
|
Id: "tryAutodiscoverPost",
|
|
Type: "bool",
|
|
Label: "Probe Microsoft Autodiscover (POST)",
|
|
Default: true,
|
|
Description: "Exercise Exchange/Outlook Autodiscover endpoints as well.",
|
|
},
|
|
}
|
|
}
|
|
|
|
// ParseForm builds CheckerOptions from the submitted form. All probing is
|
|
// deferred to Collect, so we only validate the domain shape here.
|
|
func (p *autoconfigProvider) ParseForm(r *http.Request) (sdk.CheckerOptions, error) {
|
|
if err := r.ParseForm(); err != nil {
|
|
return nil, fmt.Errorf("parse form: %w", err)
|
|
}
|
|
|
|
domain := strings.TrimSuffix(strings.TrimSpace(r.FormValue(sdk.AutoFillDomainName)), ".")
|
|
if domain == "" {
|
|
return nil, errors.New("domain name is required")
|
|
}
|
|
|
|
opts := sdk.CheckerOptions{
|
|
sdk.AutoFillDomainName: domain,
|
|
}
|
|
if v := strings.TrimSpace(r.FormValue("probeEmail")); v != "" {
|
|
opts["probeEmail"] = v
|
|
}
|
|
|
|
// HTML omits unchecked boxes; treat absence as "use the documented default".
|
|
for _, key := range []string{"tryISPDB", "tryHTTPAutoconfig", "tryAutodiscoverPost"} {
|
|
if _, ok := r.Form[key]; !ok {
|
|
continue
|
|
}
|
|
opts[key] = r.FormValue(key) == "true"
|
|
}
|
|
|
|
return opts, nil
|
|
}
|