mirror of https://github.com/jetkvm/kvm.git
feat(ui): update IPv6 static configuration to use CIDR notation for address
This commit is contained in:
parent
1099f56054
commit
9d0e62f80e
|
@ -407,6 +407,10 @@ func (f *FieldConfig) validateSingleValue(val string, index int) error {
|
||||||
if _, err := url.Parse(val); err != nil {
|
if _, err := url.Parse(val); err != nil {
|
||||||
return fmt.Errorf("%s is not a valid URL: %s", fieldRef, val)
|
return fmt.Errorf("%s is not a valid URL: %s", fieldRef, val)
|
||||||
}
|
}
|
||||||
|
case "cidr":
|
||||||
|
if _, _, err := net.ParseCIDR(val); err != nil {
|
||||||
|
return fmt.Errorf("%s is not a valid CIDR notation: %s", fieldRef, val)
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
return fmt.Errorf("field `%s` cannot use validate_type: unsupported validator: %s", f.Name, validateType)
|
return fmt.Errorf("field `%s` cannot use validate_type: unsupported validator: %s", f.Name, validateType)
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,8 +28,7 @@ type IPv4StaticConfig struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type IPv6StaticConfig struct {
|
type IPv6StaticConfig struct {
|
||||||
Address null.String `json:"address,omitempty" validate_type:"ipv6" required:"true"`
|
Address null.String `json:"address,omitempty" validate_type:"cidr" required:"true"`
|
||||||
Prefix null.String `json:"prefix,omitempty" required:"true"`
|
|
||||||
Gateway null.String `json:"gateway,omitempty" validate_type:"ipv6" required:"true"`
|
Gateway null.String `json:"gateway,omitempty" validate_type:"ipv6" required:"true"`
|
||||||
DNS []string `json:"dns,omitempty" validate_type:"ipv6" required:"true"`
|
DNS []string `json:"dns,omitempty" validate_type:"ipv6" required:"true"`
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,23 +26,29 @@ export default function StaticIpv6Card() {
|
||||||
Static IPv6 Configuration
|
Static IPv6 Configuration
|
||||||
</h3>
|
</h3>
|
||||||
|
|
||||||
<div className="grid grid-cols-1 gap-4 md:grid-cols-2">
|
<InputFieldWithLabel
|
||||||
<InputFieldWithLabel
|
label="IP Address/Prefix"
|
||||||
label="IP Address"
|
type="text"
|
||||||
type="text"
|
size="SM"
|
||||||
size="SM"
|
placeholder="2001:db8::1/64"
|
||||||
placeholder="2001:db8::1"
|
{...register("ipv6_static.address", {
|
||||||
{...register("ipv6_static.address")}
|
validate: (value: string) => {
|
||||||
/>
|
if (value === "") return true;
|
||||||
|
// Check if it's a valid IPv6 address with CIDR notation
|
||||||
<InputFieldWithLabel
|
const parts = value.split("/");
|
||||||
label="Prefix"
|
if (parts.length !== 2)
|
||||||
type="text"
|
return "Please use CIDR notation (e.g., 2001:db8::1/64)";
|
||||||
size="SM"
|
const [address, prefix] = parts;
|
||||||
placeholder="64"
|
if (!validator.isIP(address, 6)) return "Invalid IPv6 address";
|
||||||
{...register("ipv6_static.prefix")}
|
const prefixNum = parseInt(prefix);
|
||||||
/>
|
if (isNaN(prefixNum) || prefixNum < 0 || prefixNum > 128) {
|
||||||
</div>
|
return "Prefix must be between 0 and 128";
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
},
|
||||||
|
})}
|
||||||
|
error={formState.errors.ipv6_static?.address?.message}
|
||||||
|
/>
|
||||||
|
|
||||||
<InputFieldWithLabel
|
<InputFieldWithLabel
|
||||||
label="Gateway"
|
label="Gateway"
|
||||||
|
@ -63,7 +69,7 @@ export default function StaticIpv6Card() {
|
||||||
label={index === 0 ? "DNS Server" : null}
|
label={index === 0 ? "DNS Server" : null}
|
||||||
type="text"
|
type="text"
|
||||||
size="SM"
|
size="SM"
|
||||||
placeholder="1.1.1.1"
|
placeholder="2001:4860:4860::8888"
|
||||||
{...register(`ipv6_static.dns.${index}`, {
|
{...register(`ipv6_static.dns.${index}`, {
|
||||||
validate: (value: string) => {
|
validate: (value: string) => {
|
||||||
if (value === "") return true;
|
if (value === "") return true;
|
||||||
|
|
Loading…
Reference in New Issue