Skip to content

Commit b74adc5

Browse files
committed
fix(providers): accept CIDR subnets and surface host validation errors
The additional-host regex in provider-base-modify.js used \d inside a single-backslash string literal, so JS compiled it as the bare letter d. CIDR masks like /21 silently failed validation. On rejection the input only shake-animated with no explanation, leaving users guessing. - Escape \d/\/ properly so the CIDR group matches /0../32 - Drop g/m regex flags (irrelevant for ^...$ single-line tests) - Replace silent shake with a Fomantic pointing red label under the input, auto-hidden after 5s, role="alert" for a11y - Switch .html(value) to .text(value) for host rows (defense in depth even though the regex already excludes < and >) - Add pr_InvalidHostAddress translation across 26 languages
1 parent 3603720 commit b74adc5

30 files changed

Lines changed: 111 additions & 16 deletions

sites/admin-cabinet/assets/js/pbx/Providers/provider-base-modify.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sites/admin-cabinet/assets/js/pbx/Providers/provider-sip-modify.js

Lines changed: 39 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sites/admin-cabinet/assets/js/src/Providers/provider-base-modify.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,12 @@ class ProviderBase {
5656
// Track if form is fully initialized
5757
this.formInitialized = false;
5858

59-
// Host input validation regex
59+
// Host input validation regex: IPv4 address, IPv4 CIDR (/0-/32), or hostname
6060
this.hostInputValidation = new RegExp(
6161
'^(((\\d|[1-9]\\d|1\\d{2}|2[0-4]\\d|25[0-5])\\.){3}'
6262
+ '(\\d|[1-9]\\d|1\\d{2}|2[0-4]\\d|25[0-5])'
63-
+ '(\\/(\d|[1-2]\d|3[0-2]))?'
64-
+ '|[a-zA-Z0-9-]{0,61}[a-zA-Z0-9](?:\\.[a-zA-Z]{2,})+)$',
65-
'gm'
63+
+ '(\\/(\\d|[1-2]\\d|3[0-2]))?'
64+
+ '|[a-zA-Z0-9-]{0,61}[a-zA-Z0-9](?:\\.[a-zA-Z]{2,})+)$'
6665
);
6766
}
6867

sites/admin-cabinet/assets/js/src/Providers/provider-sip-modify.js

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -894,6 +894,39 @@ class ProviderSIP extends ProviderBase {
894894
}
895895
}
896896

897+
/**
898+
* Show inline validation error on the additional-host input.
899+
* Pairs the existing shake animation with a Fomantic pointing label
900+
* placed directly under the input, since shake alone leaves the user
901+
* wondering why their input was rejected.
902+
*/
903+
showHostInputError() {
904+
const message = (typeof globalTranslate !== 'undefined' && globalTranslate.pr_InvalidHostAddress)
905+
? globalTranslate.pr_InvalidHostAddress
906+
: 'Введите корректный IP адрес, подсеть в нотации CIDR (например 10.0.0.0/8) или имя хоста';
907+
908+
const $wrapper = this.$additionalHostInput.parent();
909+
// Always recreate the label so we never inherit stale Fomantic transition state
910+
$wrapper.parent().find('.host-input-error').remove();
911+
912+
const $label = $('<div class="ui pointing red basic label host-input-error" role="alert"></div>')
913+
.text(message);
914+
$wrapper.after($label);
915+
916+
clearTimeout(this._hostErrorTimer);
917+
this._hostErrorTimer = setTimeout(() => $label.remove(), 5000);
918+
919+
this.$additionalHostInput.transition('shake');
920+
}
921+
922+
/**
923+
* Hide the inline validation error, if any.
924+
*/
925+
hideHostInputError() {
926+
clearTimeout(this._hostErrorTimer);
927+
this.$additionalHostInput.parent().parent().find('.host-input-error').remove();
928+
}
929+
897930
/**
898931
* Handle completion of host address input
899932
*/
@@ -905,10 +938,13 @@ class ProviderSIP extends ProviderBase {
905938

906939
// Validate the input value
907940
if (validation === null || validation.length === 0) {
908-
this.$additionalHostInput.transition('shake');
941+
this.showHostInputError();
909942
return;
910943
}
911-
944+
945+
// Hide any previous validation error on successful input
946+
this.hideHostInputError();
947+
912948
// Check if the host address already exists
913949
if ($(`.host-row[data-value=\"${value}\"]`).length === 0) {
914950
const $tr = this.$additionalHostsTemplate.last();
@@ -918,7 +954,7 @@ class ProviderSIP extends ProviderBase {
918954
.addClass('host-row')
919955
.show();
920956
$clone.attr('data-value', value);
921-
$clone.find('.address').html(value);
957+
$clone.find('.address').text(value);
922958
const $existingHostRows = this.$formObj.find(ProviderSIP.SIP_SELECTORS.HOST_ROW);
923959
if ($existingHostRows.last().length === 0) {
924960
$tr.after($clone);
@@ -970,7 +1006,7 @@ class ProviderSIP extends ProviderBase {
9701006
.addClass('host-row')
9711007
.show();
9721008
$clone.attr('data-value', hostAddress);
973-
$clone.find('.address').html(hostAddress);
1009+
$clone.find('.address').text(hostAddress);
9741010

9751011
// Insert the cloned row
9761012
const $existingHostRows = this.$formObj.find(ProviderSIP.SIP_SELECTORS.HOST_ROW);

src/Common/Messages/az/Providers.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@
183183
'pr_EnableCallerIdDidDebug' => 'CallerID/DID debug-ını aktivləşdirin',
184184
'pr_EnterHostOrIp' => 'Provayderin əlavə ünvanları',
185185
'pr_EnterHostOrIpPlaceholder' => 'IP ünvanını və ya alt şəbəkəni daxil edin və Enter düyməsini basın',
186+
'pr_InvalidHostAddress' => 'Düzgün IP ünvanı, CIDR alt şəbəkəsi (məs. 10.0.0.0/8) və ya host adı daxil edin',
186187
'pr_Event' => 'Hadisə',
187188
'pr_EventHistory' => 'Hadisələr tarixi',
188189
'pr_EventTypeError' => 'Xəta',

src/Common/Messages/cs/Providers.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@
183183
'pr_EnableCallerIdDidDebug' => 'Zapnout ladění CallerID/DID',
184184
'pr_EnterHostOrIp' => 'Další adresy poskytovatele',
185185
'pr_EnterHostOrIpPlaceholder' => 'Zadejte IP adresu nebo podsíť a stiskněte Enter',
186+
'pr_InvalidHostAddress' => 'Zadejte platnou IP adresu, podsíť CIDR (např. 10.0.0.0/8) nebo název hostitele',
186187
'pr_Event' => 'Událost',
187188
'pr_EventHistory' => 'Historie událostí',
188189
'pr_EventTypeError' => 'Chyba',

src/Common/Messages/da/Providers.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@
183183
'pr_EnableCallerIdDidDebug' => 'Aktivér CallerID/DID debug',
184184
'pr_EnterHostOrIp' => 'Yderligere udbyderadresser',
185185
'pr_EnterHostOrIpPlaceholder' => 'Indtast IP-adresse eller subnet og tryk Enter',
186+
'pr_InvalidHostAddress' => 'Indtast en gyldig IP-adresse, CIDR-subnet (f.eks. 10.0.0.0/8) eller værtsnavn',
186187
'pr_Event' => 'Begivenhed',
187188
'pr_EventHistory' => 'Begivenhedshistorik',
188189
'pr_EventTypeError' => 'Fejl',

src/Common/Messages/de/Providers.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@
183183
'pr_EnableCallerIdDidDebug' => 'CallerID/DID-Debug aktivieren',
184184
'pr_EnterHostOrIp' => 'Zusätzliche Provider-Adressen',
185185
'pr_EnterHostOrIpPlaceholder' => 'Geben Sie IP-Adresse oder Subnetz ein und drücken Sie Enter',
186+
'pr_InvalidHostAddress' => 'Geben Sie eine gültige IP-Adresse, ein CIDR-Subnetz (z.B. 10.0.0.0/8) oder einen Hostnamen ein',
186187
'pr_Event' => 'Ereignis',
187188
'pr_EventHistory' => 'Ereignisverlauf',
188189
'pr_EventTypeError' => 'Fehler',

src/Common/Messages/el/Providers.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@
183183
'pr_EnableCallerIdDidDebug' => 'Ενεργοποίηση εντοπισμού σφαλμάτων CallerID/DID',
184184
'pr_EnterHostOrIp' => 'Πρόσθετες διευθύνσεις παρόχου',
185185
'pr_EnterHostOrIpPlaceholder' => 'Εισαγάγετε τη διεύθυνση IP ή το υποδίκτυο και πατήστε Enter',
186+
'pr_InvalidHostAddress' => 'Εισαγάγετε έγκυρη διεύθυνση IP, υποδίκτυο CIDR (π.χ. 10.0.0.0/8) ή όνομα κεντρικού υπολογιστή',
186187
'pr_Event' => 'Συμβάν',
187188
'pr_EventHistory' => 'Ιστορικό συμβάντων',
188189
'pr_EventTypeError' => 'Σφάλμα',

src/Common/Messages/en/Providers.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@
200200
'pr_EnableCallerIdDidDebug' => 'Enable CallerID/DID debug',
201201
'pr_EnterHostOrIp' => 'Additional provider addresses',
202202
'pr_EnterHostOrIpPlaceholder' => 'Enter IP address or subnet and press Enter',
203+
'pr_InvalidHostAddress' => 'Enter a valid IP address, CIDR subnet (e.g. 10.0.0.0/8), or hostname',
203204
'pr_Event' => 'Event',
204205
'pr_EventHistory' => 'Event history',
205206
'pr_EventTypeError' => 'Error',

0 commit comments

Comments
 (0)