mirror of
https://github.com/itdoginfo/podkop.git
synced 2026-01-06 08:38:52 +03:00
feat: implement validateSubnet
This commit is contained in:
@@ -508,23 +508,18 @@ function createConfigSection(section, map, network) {
|
||||
o.rmempty = false;
|
||||
o.ucisection = s.section;
|
||||
o.validate = function (section_id, value) {
|
||||
if (!value || value.length === 0) return true;
|
||||
const subnetRegex = /^(\d{1,3}\.){3}\d{1,3}(\/\d{1,2})?$/;
|
||||
if (!subnetRegex.test(value)) return _('Invalid format. Use format: X.X.X.X or X.X.X.X/Y');
|
||||
const [ip, cidr] = value.split('/');
|
||||
if (ip === "0.0.0.0") {
|
||||
return _('IP address 0.0.0.0 is not allowed');
|
||||
// Optional
|
||||
if (!value || value.length === 0) {
|
||||
return true
|
||||
}
|
||||
const ipParts = ip.split('.');
|
||||
for (const part of ipParts) {
|
||||
const num = parseInt(part);
|
||||
if (num < 0 || num > 255) return _('IP address parts must be between 0 and 255');
|
||||
|
||||
const validation = main.validateSubnet(value);
|
||||
|
||||
if (validation.valid) {
|
||||
return true;
|
||||
}
|
||||
if (cidr !== undefined) {
|
||||
const cidrNum = parseInt(cidr);
|
||||
if (cidrNum < 0 || cidrNum > 32) return _('CIDR must be between 0 and 32');
|
||||
}
|
||||
return true;
|
||||
|
||||
return _(validation.message)
|
||||
};
|
||||
|
||||
o = s.taboption('basic', form.TextValue, 'user_subnets_text', _('User Subnets List'), _('Enter subnets in CIDR notation or single IP addresses, separated by comma, space or newline. You can add comments after //'));
|
||||
|
||||
@@ -80,6 +80,35 @@ function validatePath(value) {
|
||||
};
|
||||
}
|
||||
|
||||
// src/validators/validateSubnet.ts
|
||||
function validateSubnet(value) {
|
||||
const subnetRegex = /^(\d{1,3}\.){3}\d{1,3}(?:\/\d{1,2})?$/;
|
||||
if (!subnetRegex.test(value)) {
|
||||
return {
|
||||
valid: false,
|
||||
message: "Invalid format. Use X.X.X.X or X.X.X.X/Y"
|
||||
};
|
||||
}
|
||||
const [ip, cidr] = value.split("/");
|
||||
if (ip === "0.0.0.0") {
|
||||
return { valid: false, message: "IP address 0.0.0.0 is not allowed" };
|
||||
}
|
||||
const ipCheck = validateIPV4(ip);
|
||||
if (!ipCheck.valid) {
|
||||
return ipCheck;
|
||||
}
|
||||
if (cidr) {
|
||||
const cidrNum = parseInt(cidr, 10);
|
||||
if (cidrNum < 0 || cidrNum > 32) {
|
||||
return {
|
||||
valid: false,
|
||||
message: "CIDR must be between 0 and 32"
|
||||
};
|
||||
}
|
||||
}
|
||||
return { valid: true, message: "Valid" };
|
||||
}
|
||||
|
||||
// src/constants.ts
|
||||
var STATUS_COLORS = {
|
||||
SUCCESS: "#4caf50",
|
||||
@@ -218,5 +247,6 @@ return baseclass.extend({
|
||||
validateDomain,
|
||||
validateIPV4,
|
||||
validatePath,
|
||||
validateSubnet,
|
||||
validateUrl
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user