landed IP address ban editing
This commit is contained in:
@@ -14,7 +14,9 @@ import (
|
||||
"embed"
|
||||
"fmt"
|
||||
"math"
|
||||
"net"
|
||||
"net/mail"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -108,6 +110,10 @@ func AmLoadDialog(name string) (*Dialog, error) {
|
||||
d.Fields[i].MaxLength = d.Fields[i].Size
|
||||
}
|
||||
}
|
||||
if fld.Type == "ipaddress" {
|
||||
d.Fields[i].Size = 15 // max IPv4
|
||||
d.Fields[i].MaxLength = 39 // max IPv6
|
||||
}
|
||||
if fld.Type == "dropdown" && len(fld.Choices) == 0 {
|
||||
return nil, fmt.Errorf("dropdown field %s in dialog %s has no choices", fld.Name, name)
|
||||
}
|
||||
@@ -547,6 +553,35 @@ func validateEmailField(fld *DialogItem) error {
|
||||
return err
|
||||
}
|
||||
|
||||
/* validateIPAddressField validates an IP address field.
|
||||
* Parameters:
|
||||
* fld - The field to be validated.
|
||||
* Returns:
|
||||
* Standard Go error status.
|
||||
*/
|
||||
func validateIPAddressField(fld *DialogItem) error {
|
||||
err := validateTextField(fld)
|
||||
if err == nil {
|
||||
if strings.Contains(fld.Param, "mask") {
|
||||
// look for a CIDR mask value like "/24"
|
||||
var ok bool
|
||||
ok, err = regexp.Match("^/[0-9]+$", []byte(fld.Value))
|
||||
if err == nil {
|
||||
if ok {
|
||||
return nil // found it!
|
||||
}
|
||||
}
|
||||
}
|
||||
if err == nil {
|
||||
ip := net.ParseIP(fld.Value)
|
||||
if ip == nil {
|
||||
err = fmt.Errorf("value of field \"%s\" is not a valid IP address", fld.Caption)
|
||||
}
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
/* validateCountryField validates a country code field.
|
||||
* Parameters:
|
||||
* fld - The field to be validated.
|
||||
@@ -613,6 +648,7 @@ var validators = map[string]validatorFunc{
|
||||
"header": nilValidator,
|
||||
"hidden": nilValidator,
|
||||
"integer": validateIntegerField,
|
||||
"ipaddress": validateIPAddressField,
|
||||
"localelist": nilValidator,
|
||||
"password": validateTextField,
|
||||
"rolelist": validateRoleListField,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#
|
||||
# Amsterdam Web Communities System
|
||||
# Copyright (c) 2025 Erbosoft Metaverse Design Solutions, All Rights Reserved
|
||||
# Copyright (c) 2025-2026 Erbosoft Metaverse Design Solutions, All Rights Reserved
|
||||
#
|
||||
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
#
|
||||
# Amsterdam Web Communities System
|
||||
# Copyright (c) 2025-2026 Erbosoft Metaverse Design Solutions, All Rights Reserved
|
||||
#
|
||||
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
#
|
||||
name: "ipban.add"
|
||||
formName: "ipbanform"
|
||||
menuSelector: "nochange"
|
||||
title: "Add IP Address Ban"
|
||||
action: "/sysadmin/ipban/add"
|
||||
fields:
|
||||
- type: "ipaddress"
|
||||
name: "address"
|
||||
caption: "IP address"
|
||||
required: true
|
||||
- type: "ipaddress"
|
||||
name: "mask"
|
||||
caption: "IP address mask"
|
||||
required: true
|
||||
param: "mask"
|
||||
- type: "checkbox"
|
||||
name: "echeck"
|
||||
caption: "IP address ban expires"
|
||||
- type: "integer"
|
||||
name: "etime"
|
||||
caption: "Expires in"
|
||||
param: "1-100000"
|
||||
- type: "dropdown"
|
||||
name: "eunit"
|
||||
caption: "Expires in"
|
||||
subcaption: "(units)"
|
||||
required: true
|
||||
choices:
|
||||
- id: "D"
|
||||
text: "days"
|
||||
- id: "W"
|
||||
text: "weeks"
|
||||
- id: "M"
|
||||
text: "months"
|
||||
- id: "Y"
|
||||
text: "years"
|
||||
- type: "text"
|
||||
name: "msg"
|
||||
caption: "Message to display"
|
||||
size: 64
|
||||
maxlength: 255
|
||||
- type: "button"
|
||||
name: "add"
|
||||
caption: "Add"
|
||||
param: "blue"
|
||||
- type: "button"
|
||||
name: "cancel"
|
||||
caption: "Cancel"
|
||||
param: "red"
|
||||
+1
-1
@@ -37,7 +37,7 @@ menudefs:
|
||||
link: "/sysadmin/globals"
|
||||
permission: "Global.SysAdminAccess"
|
||||
- text: "View/Edit IP Address Bans"
|
||||
link: "/TODO/sysadmin/ip_bans"
|
||||
link: "/sysadmin/ipban"
|
||||
permission: "Global.SysAdminAccess"
|
||||
- text: "View/Edit Banned Users"
|
||||
link: "/TODO/sysadmin/user_bans"
|
||||
|
||||
+1
-1
@@ -61,7 +61,7 @@
|
||||
<div class="bg-gray-50 p-6 rounded-lg">
|
||||
<div class="space-y-4">
|
||||
{{ range __dialog.Fields }}
|
||||
{{ if .Type == "text" || .Type == "ams_id" || .Type == "email" }}
|
||||
{{ if .Type == "text" || .Type == "ams_id" || .Type == "email" || .Type == "ipaddress" }}
|
||||
<div class="flex items-center">
|
||||
<label for="{{ .Name }}"
|
||||
class="w-64 text-right pr-4 {{ if .Disabled }}text-gray-400{{ else }}text-black{{ end }} text-sm">
|
||||
|
||||
@@ -21,6 +21,20 @@
|
||||
</a>
|
||||
</div>
|
||||
|
||||
{{ if isset(errorMessage) }}
|
||||
<!-- Error Message Banner -->
|
||||
<div class="bg-red-100 border border-red-400 text-red-700 px-4 py-3 rounded mb-6" id="error-banner">
|
||||
<div class="flex items-center">
|
||||
<div class="flex-shrink-0">
|
||||
<span class="text-red-500 text-xl">⚠️</span>
|
||||
</div>
|
||||
<div class="ml-3">
|
||||
<p class="text-sm font-medium" id="error-message">{{ CapitalizeString(errorMessage) }}.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{{ end }}
|
||||
|
||||
<!-- Warning Box -->
|
||||
<div class="bg-red-50 border-l-4 border-red-400 p-4 mb-6 rounded max-w-6xl">
|
||||
<div class="flex items-start">
|
||||
@@ -72,10 +86,10 @@
|
||||
{{ end }}
|
||||
</td>
|
||||
<td class="px-4 py-3 text-sm font-mono {{ if ipb.Enable }}text-gray-800{{ else }}text-gray-500{{ end }}">
|
||||
{{ IPtoString(ipb.AddressLow, ipb.AddressHigh) }}
|
||||
{{ IPtoString(ipb.AddressLow, ipb.AddressHigh, ipv4[i]) }}
|
||||
</td>
|
||||
<td class="px-4 py-3 text-sm font-mono {{ if ipb.Enable }}text-gray-600{{ else }}text-gray-400{{ end }}">
|
||||
{{ IPtoString(ipb.MaskLow, ipb.MaskHigh) }}
|
||||
{{ IPtoString(ipb.MaskLow, ipb.MaskHigh, ipv4[i]) }}
|
||||
</td>
|
||||
<td class="px-4 py-3 text-sm {{ if ipb.Enable }}text-gray-700{{ else }}text-gray-500{{ end }} whitespace-nowrap">
|
||||
{{ if isset(ipb.Expires) }}
|
||||
|
||||
Reference in New Issue
Block a user