added superuser ips whitelist
This commit is contained in:
@@ -120,6 +120,10 @@ var (
|
||||
)
|
||||
|
||||
type settings struct {
|
||||
// SuperuserIPs defines an optional list of the superuser allowed
|
||||
// individual IPs and subnets (in CIDR notation).
|
||||
SuperuserIPs []string `form:"superuserIPs" json:"superuserIPs"`
|
||||
|
||||
SMTP SMTPConfig `form:"smtp" json:"smtp"`
|
||||
Backups BackupsConfig `form:"backups" json:"backups"`
|
||||
S3 S3Config `form:"s3" json:"s3"`
|
||||
@@ -253,6 +257,12 @@ func (s *Settings) DBExport(app App) (map[string]any, error) {
|
||||
}
|
||||
result["updated"] = now
|
||||
|
||||
// @todo remove with encoding/json/2
|
||||
// serialize as empty array
|
||||
if s.settings.SuperuserIPs == nil {
|
||||
s.settings.SuperuserIPs = []string{}
|
||||
}
|
||||
|
||||
encoded, err := json.Marshal(s.settings)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -280,6 +290,7 @@ func (s *Settings) PostValidate(ctx context.Context, app App) error {
|
||||
defer s.mu.RUnlock()
|
||||
|
||||
return validation.ValidateStructWithContext(ctx, s,
|
||||
validation.Field(&s.SuperuserIPs, validation.Each(validation.By(validators.IPOrSubnet))),
|
||||
validation.Field(&s.Meta),
|
||||
validation.Field(&s.Logs),
|
||||
validation.Field(&s.SMTP),
|
||||
@@ -343,6 +354,12 @@ func (s *Settings) MarshalJSON() ([]byte, error) {
|
||||
}
|
||||
}
|
||||
|
||||
// @todo remove with encoding/json/2
|
||||
// serialize as empty array
|
||||
if copy.SuperuserIPs == nil {
|
||||
copy.SuperuserIPs = []string{}
|
||||
}
|
||||
|
||||
return json.Marshal(copy)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user