mirror of
https://git.proxmox.com/git/pve-manager
synced 2025-08-07 02:13:29 +00:00
Move globally defined regexpes into PVE.Utils
Those globally defined regexpes were only used in Toolkit.js
This commit is contained in:
parent
9fa2e36d3a
commit
c15c61d3e8
@ -1,5 +1,3 @@
|
|||||||
/*global IP4_match, IP4_cidr_match, IP6_match, IP6_cidr_match, IP64_match, DnsName_match, DnsName_REGEXP, IPV4_REGEXP, IPV6_REGEXP*/
|
|
||||||
/*global HostPort_match, HostPortBrackets_match, IP6_dotnotation_match*/
|
|
||||||
// ExtJS related things
|
// ExtJS related things
|
||||||
|
|
||||||
PVE.Utils.toolkit = 'extjs';
|
PVE.Utils.toolkit = 'extjs';
|
||||||
@ -10,13 +8,13 @@ Ext.Ajax.disableCaching = false;
|
|||||||
// custom Vtypes
|
// custom Vtypes
|
||||||
Ext.apply(Ext.form.field.VTypes, {
|
Ext.apply(Ext.form.field.VTypes, {
|
||||||
IPAddress: function(v) {
|
IPAddress: function(v) {
|
||||||
return IP4_match.test(v);
|
return PVE.Utils.IP4_match.test(v);
|
||||||
},
|
},
|
||||||
IPAddressText: gettext('Example') + ': 192.168.1.1',
|
IPAddressText: gettext('Example') + ': 192.168.1.1',
|
||||||
IPAddressMask: /[\d\.]/i,
|
IPAddressMask: /[\d\.]/i,
|
||||||
|
|
||||||
IPCIDRAddress: function(v) {
|
IPCIDRAddress: function(v) {
|
||||||
var result = IP4_cidr_match.exec(v);
|
var result = PVE.Utils.IP4_cidr_match.exec(v);
|
||||||
// limits according to JSON Schema see
|
// limits according to JSON Schema see
|
||||||
// pve-common/src/PVE/JSONSchema.pm
|
// pve-common/src/PVE/JSONSchema.pm
|
||||||
return (result !== null && result[1] >= 8 && result[1] <= 32);
|
return (result !== null && result[1] >= 8 && result[1] <= 32);
|
||||||
@ -25,13 +23,13 @@ Ext.apply(Ext.form.field.VTypes, {
|
|||||||
IPCIDRAddressMask: /[\d\.\/]/i,
|
IPCIDRAddressMask: /[\d\.\/]/i,
|
||||||
|
|
||||||
IP6Address: function(v) {
|
IP6Address: function(v) {
|
||||||
return IP6_match.test(v);
|
return PVE.Utils.IP6_match.test(v);
|
||||||
},
|
},
|
||||||
IP6AddressText: gettext('Example') + ': 2001:DB8::42',
|
IP6AddressText: gettext('Example') + ': 2001:DB8::42',
|
||||||
IP6AddressMask: /[A-Fa-f0-9:]/,
|
IP6AddressMask: /[A-Fa-f0-9:]/,
|
||||||
|
|
||||||
IP6CIDRAddress: function(v) {
|
IP6CIDRAddress: function(v) {
|
||||||
var result = IP6_cidr_match.exec(v);
|
var result = PVE.Utils.IP6_cidr_match.exec(v);
|
||||||
// limits according to JSON Schema see
|
// limits according to JSON Schema see
|
||||||
// pve-common/src/PVE/JSONSchema.pm
|
// pve-common/src/PVE/JSONSchema.pm
|
||||||
return (result !== null && result[1] >= 8 && result[1] <= 120);
|
return (result !== null && result[1] >= 8 && result[1] <= 120);
|
||||||
@ -46,7 +44,7 @@ Ext.apply(Ext.form.field.VTypes, {
|
|||||||
IP6PrefixLengthMask: /[0-9]/,
|
IP6PrefixLengthMask: /[0-9]/,
|
||||||
|
|
||||||
IP64Address: function(v) {
|
IP64Address: function(v) {
|
||||||
return IP64_match.test(v);
|
return PVE.Utils.IP64_match.test(v);
|
||||||
},
|
},
|
||||||
IP64AddressText: gettext('Example') + ': 192.168.1.1 2001:DB8::42',
|
IP64AddressText: gettext('Example') + ': 192.168.1.1 2001:DB8::42',
|
||||||
IP64AddressMask: /[A-Fa-f0-9\.:]/,
|
IP64AddressMask: /[A-Fa-f0-9\.:]/,
|
||||||
@ -94,7 +92,7 @@ Ext.apply(Ext.form.field.VTypes, {
|
|||||||
HttpProxyText: gettext('Example') + ": http://username:password@host:port/",
|
HttpProxyText: gettext('Example') + ": http://username:password@host:port/",
|
||||||
|
|
||||||
DnsName: function(v) {
|
DnsName: function(v) {
|
||||||
return DnsName_match.test(v);
|
return PVE.Utils.DnsName_match.test(v);
|
||||||
},
|
},
|
||||||
DnsNameText: gettext('This is not a valid DNS name'),
|
DnsNameText: gettext('This is not a valid DNS name'),
|
||||||
|
|
||||||
@ -112,9 +110,9 @@ Ext.apply(Ext.form.field.VTypes, {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!HostPort_match.test(list[i]) &&
|
if (!PVE.Utils.HostPort_match.test(list[i]) &&
|
||||||
!HostPortBrackets_match.test(list[i]) &&
|
!PVE.Utils.HostPortBrackets_match.test(list[i]) &&
|
||||||
!IP6_dotnotation_match.test(list[i])) {
|
!PVE.Utils.IP6_dotnotation_match.test(list[i])) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -29,40 +29,6 @@ Ext.Ajax.on('beforerequest', function(conn, options) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
var IPV4_OCTET = "(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])";
|
|
||||||
var IPV4_REGEXP = "(?:(?:" + IPV4_OCTET + "\\.){3}" + IPV4_OCTET + ")";
|
|
||||||
var IPV6_H16 = "(?:[0-9a-fA-F]{1,4})";
|
|
||||||
var IPV6_LS32 = "(?:(?:" + IPV6_H16 + ":" + IPV6_H16 + ")|" + IPV4_REGEXP + ")";
|
|
||||||
|
|
||||||
|
|
||||||
var IP4_match = new RegExp("^(?:" + IPV4_REGEXP + ")$");
|
|
||||||
var IP4_cidr_match = new RegExp("^(?:" + IPV4_REGEXP + ")\/([0-9]{1,2})$");
|
|
||||||
|
|
||||||
var IPV6_REGEXP = "(?:" +
|
|
||||||
"(?:(?:" + "(?:" + IPV6_H16 + ":){6})" + IPV6_LS32 + ")|" +
|
|
||||||
"(?:(?:" + "::" + "(?:" + IPV6_H16 + ":){5})" + IPV6_LS32 + ")|" +
|
|
||||||
"(?:(?:(?:" + IPV6_H16 + ")?::" + "(?:" + IPV6_H16 + ":){4})" + IPV6_LS32 + ")|" +
|
|
||||||
"(?:(?:(?:(?:" + IPV6_H16 + ":){0,1}" + IPV6_H16 + ")?::" + "(?:" + IPV6_H16 + ":){3})" + IPV6_LS32 + ")|" +
|
|
||||||
"(?:(?:(?:(?:" + IPV6_H16 + ":){0,2}" + IPV6_H16 + ")?::" + "(?:" + IPV6_H16 + ":){2})" + IPV6_LS32 + ")|" +
|
|
||||||
"(?:(?:(?:(?:" + IPV6_H16 + ":){0,3}" + IPV6_H16 + ")?::" + "(?:" + IPV6_H16 + ":){1})" + IPV6_LS32 + ")|" +
|
|
||||||
"(?:(?:(?:(?:" + IPV6_H16 + ":){0,4}" + IPV6_H16 + ")?::" + ")" + IPV6_LS32 + ")|" +
|
|
||||||
"(?:(?:(?:(?:" + IPV6_H16 + ":){0,5}" + IPV6_H16 + ")?::" + ")" + IPV6_H16 + ")|" +
|
|
||||||
"(?:(?:(?:(?:" + IPV6_H16 + ":){0,7}" + IPV6_H16 + ")?::" + ")" + ")" +
|
|
||||||
")";
|
|
||||||
|
|
||||||
var IP6_match = new RegExp("^(?:" + IPV6_REGEXP + ")$");
|
|
||||||
var IP6_cidr_match = new RegExp("^(?:" + IPV6_REGEXP + ")\/([0-9]{1,3})$");
|
|
||||||
var IP6_bracket_match = new RegExp("^\\[(" + IPV6_REGEXP + ")\\]");
|
|
||||||
|
|
||||||
var IP64_match = new RegExp("^(?:" + IPV6_REGEXP + "|" + IPV4_REGEXP + ")$");
|
|
||||||
|
|
||||||
var DnsName_REGEXP = "(?:(([a-zA-Z0-9]([a-zA-Z0-9\\-]*[a-zA-Z0-9])?)\\.)*([A-Za-z0-9]([A-Za-z0-9\\-]*[A-Za-z0-9])?))";
|
|
||||||
var DnsName_match = new RegExp("^" + DnsName_REGEXP + "$");
|
|
||||||
|
|
||||||
var HostPort_match = new RegExp("^(" + IPV4_REGEXP + "|" + DnsName_REGEXP + ")(:\\d+)?$");
|
|
||||||
var HostPortBrackets_match = new RegExp("^\\[(?:" + IPV6_REGEXP + "|" + IPV4_REGEXP + "|" + DnsName_REGEXP + ")\\](:\\d+)?$");
|
|
||||||
var IP6_dotnotation_match = new RegExp("^" + IPV6_REGEXP + "(\\.\\d+)?$");
|
|
||||||
|
|
||||||
Ext.define('PVE.Utils', { utilities: {
|
Ext.define('PVE.Utils', { utilities: {
|
||||||
|
|
||||||
// this singleton contains miscellaneous utilities
|
// this singleton contains miscellaneous utilities
|
||||||
@ -1065,7 +1031,7 @@ Ext.define('PVE.Utils', { utilities: {
|
|||||||
},
|
},
|
||||||
|
|
||||||
windowHostname: function() {
|
windowHostname: function() {
|
||||||
return window.location.hostname.replace(IP6_bracket_match,
|
return window.location.hostname.replace(PVE.Utils.IP6_bracket_match,
|
||||||
function(m, addr, offset, original) { return addr; });
|
function(m, addr, offset, original) { return addr; });
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -1283,6 +1249,40 @@ Ext.define('PVE.Utils', { utilities: {
|
|||||||
constructor: function() {
|
constructor: function() {
|
||||||
var me = this;
|
var me = this;
|
||||||
Ext.apply(me, me.utilities);
|
Ext.apply(me, me.utilities);
|
||||||
|
|
||||||
|
var IPV4_OCTET = "(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])";
|
||||||
|
var IPV4_REGEXP = "(?:(?:" + IPV4_OCTET + "\\.){3}" + IPV4_OCTET + ")";
|
||||||
|
var IPV6_H16 = "(?:[0-9a-fA-F]{1,4})";
|
||||||
|
var IPV6_LS32 = "(?:(?:" + IPV6_H16 + ":" + IPV6_H16 + ")|" + IPV4_REGEXP + ")";
|
||||||
|
|
||||||
|
|
||||||
|
me.IP4_match = new RegExp("^(?:" + IPV4_REGEXP + ")$");
|
||||||
|
me.IP4_cidr_match = new RegExp("^(?:" + IPV4_REGEXP + ")\/([0-9]{1,2})$");
|
||||||
|
|
||||||
|
var IPV6_REGEXP = "(?:" +
|
||||||
|
"(?:(?:" + "(?:" + IPV6_H16 + ":){6})" + IPV6_LS32 + ")|" +
|
||||||
|
"(?:(?:" + "::" + "(?:" + IPV6_H16 + ":){5})" + IPV6_LS32 + ")|" +
|
||||||
|
"(?:(?:(?:" + IPV6_H16 + ")?::" + "(?:" + IPV6_H16 + ":){4})" + IPV6_LS32 + ")|" +
|
||||||
|
"(?:(?:(?:(?:" + IPV6_H16 + ":){0,1}" + IPV6_H16 + ")?::" + "(?:" + IPV6_H16 + ":){3})" + IPV6_LS32 + ")|" +
|
||||||
|
"(?:(?:(?:(?:" + IPV6_H16 + ":){0,2}" + IPV6_H16 + ")?::" + "(?:" + IPV6_H16 + ":){2})" + IPV6_LS32 + ")|" +
|
||||||
|
"(?:(?:(?:(?:" + IPV6_H16 + ":){0,3}" + IPV6_H16 + ")?::" + "(?:" + IPV6_H16 + ":){1})" + IPV6_LS32 + ")|" +
|
||||||
|
"(?:(?:(?:(?:" + IPV6_H16 + ":){0,4}" + IPV6_H16 + ")?::" + ")" + IPV6_LS32 + ")|" +
|
||||||
|
"(?:(?:(?:(?:" + IPV6_H16 + ":){0,5}" + IPV6_H16 + ")?::" + ")" + IPV6_H16 + ")|" +
|
||||||
|
"(?:(?:(?:(?:" + IPV6_H16 + ":){0,7}" + IPV6_H16 + ")?::" + ")" + ")" +
|
||||||
|
")";
|
||||||
|
|
||||||
|
me.IP6_match = new RegExp("^(?:" + IPV6_REGEXP + ")$");
|
||||||
|
me.IP6_cidr_match = new RegExp("^(?:" + IPV6_REGEXP + ")\/([0-9]{1,3})$");
|
||||||
|
me.IP6_bracket_match = new RegExp("^\\[(" + IPV6_REGEXP + ")\\]");
|
||||||
|
|
||||||
|
me.IP64_match = new RegExp("^(?:" + IPV6_REGEXP + "|" + IPV4_REGEXP + ")$");
|
||||||
|
|
||||||
|
var DnsName_REGEXP = "(?:(([a-zA-Z0-9]([a-zA-Z0-9\\-]*[a-zA-Z0-9])?)\\.)*([A-Za-z0-9]([A-Za-z0-9\\-]*[A-Za-z0-9])?))";
|
||||||
|
me.DnsName_match = new RegExp("^" + DnsName_REGEXP + "$");
|
||||||
|
|
||||||
|
me.HostPort_match = new RegExp("^(" + IPV4_REGEXP + "|" + DnsName_REGEXP + ")(:\\d+)?$");
|
||||||
|
me.HostPortBrackets_match = new RegExp("^\\[(?:" + IPV6_REGEXP + "|" + IPV4_REGEXP + "|" + DnsName_REGEXP + ")\\](:\\d+)?$");
|
||||||
|
me.IP6_dotnotation_match = new RegExp("^" + IPV6_REGEXP + "(\\.\\d+)?$");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user