mirror of
https://github.com/superseriousbusiness/gotosocial
synced 2025-06-05 21:59:39 +02:00
[chore] Validate/set account domain (#619)
* add miekg/dns dependency * set/validate accountDomain
This commit is contained in:
@@ -23,6 +23,7 @@ import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/miekg/dns"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
@@ -31,10 +32,23 @@ func Validate() error {
|
||||
errs := []error{}
|
||||
|
||||
// host
|
||||
if GetHost() == "" {
|
||||
host := GetHost()
|
||||
if host == "" {
|
||||
errs = append(errs, fmt.Errorf("%s must be set", HostFlag()))
|
||||
}
|
||||
|
||||
// accountDomain; only check if host was set, otherwise there's no point
|
||||
if host != "" {
|
||||
switch ad := GetAccountDomain(); ad {
|
||||
case "":
|
||||
SetAccountDomain(GetHost())
|
||||
default:
|
||||
if !dns.IsSubDomain(ad, host) {
|
||||
errs = append(errs, fmt.Errorf("%s was %s and %s was %s, but %s is not a valid subdomain of %s", HostFlag(), host, AccountDomainFlag(), ad, host, ad))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// protocol
|
||||
switch proto := GetProtocol(); proto {
|
||||
case "https":
|
||||
|
Reference in New Issue
Block a user