summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Rettberg2019-11-27 11:22:11 +0100
committerSimon Rettberg2019-11-27 11:22:11 +0100
commit63c02d5082528d9d0c69520e0034cbb52522208d (patch)
tree0db60510494949f368b47d5e8da3986a20eb971a
parent[rebootcontrol] Start adding WOL functionality (diff)
downloadslx-admin-63c02d5082528d9d0c69520e0034cbb52522208d.tar.gz
slx-admin-63c02d5082528d9d0c69520e0034cbb52522208d.tar.xz
slx-admin-63c02d5082528d9d0c69520e0034cbb52522208d.zip
[js_ip/locations] Mode cidr/ip handling to own module
-rw-r--r--modules-available/js_ip/clientscript.js (renamed from modules-available/locations/clientscript.js)19
-rw-r--r--modules-available/js_ip/config.json7
-rw-r--r--modules-available/locations/pages/locations.inc.php1
-rw-r--r--modules-available/locations/templates/locations.html12
4 files changed, 22 insertions, 17 deletions
diff --git a/modules-available/locations/clientscript.js b/modules-available/js_ip/clientscript.js
index ad3e6c43..930292b1 100644
--- a/modules-available/locations/clientscript.js
+++ b/modules-available/js_ip/clientscript.js
@@ -1,3 +1,5 @@
+'use strict';
+
function ip2long(IP) {
var i = 0;
IP = IP.match(/^([1-9]\d*|0[0-7]*|0x[\da-f]+)(?:\.([1-9]\d*|0[0-7]*|0x[\da-f]+))?(?:\.([1-9]\d*|0[0-7]*|0x[\da-f]+))?(?:\.([1-9]\d*|0[0-7]*|0x[\da-f]+))?$/i);
@@ -23,8 +25,10 @@ function long2ip(a) {
}
function cidrToRange(cidr) {
- var range = [2];
+ var range = [];
cidr = cidr.split('/');
+ if (cidr.length !== 2)
+ return false;
var cidr_1 = parseInt(cidr[1]);
if (cidr_1 <= 0 || cidr_1 > 32)
return false;
@@ -50,14 +54,11 @@ function slxAttachCidr() {
return;
t.removeClass('cidrmagic');
s.focusout(function () {
- var val = s.val();
- if (val.match(/^[0-9]+\.[0-9]+(\.[0-9]+(\.[0-9]+)?)?\/[0-9]{2}$/)) {
- var res = cidrToRange(val);
- if (res === false)
- return;
- s.val(res[0]);
- e.val(res[1]);
- }
+ var res = cidrToRange(s.val());
+ if (res === false)
+ return;
+ s.val(res[0]);
+ e.val(res[1]);
});
});
}
diff --git a/modules-available/js_ip/config.json b/modules-available/js_ip/config.json
new file mode 100644
index 00000000..96c02bce
--- /dev/null
+++ b/modules-available/js_ip/config.json
@@ -0,0 +1,7 @@
+{
+ "dependencies": [],
+ "scripts": [
+ "clientscript.js"
+ ],
+ "client-plugin": true
+} \ No newline at end of file
diff --git a/modules-available/locations/pages/locations.inc.php b/modules-available/locations/pages/locations.inc.php
index a8cd2e63..54f44554 100644
--- a/modules-available/locations/pages/locations.inc.php
+++ b/modules-available/locations/pages/locations.inc.php
@@ -242,6 +242,7 @@ class SubPage
// depends on permissions in the according modules, not this one
Permission::addGlobalTags($data['perms'], NULL, ['subnets.edit', 'location.add']);
Render::addTemplate('locations', $data);
+ Module::isAvailable('js_ip'); // For CIDR magic
}
private static function propagateFields(&$locationList, $defaultValue, $name, $class)
diff --git a/modules-available/locations/templates/locations.html b/modules-available/locations/templates/locations.html
index f30ebcab..e2224bc0 100644
--- a/modules-available/locations/templates/locations.html
+++ b/modules-available/locations/templates/locations.html
@@ -209,7 +209,7 @@ function slxOpenLocation(e, lid) {
tr.append(td);
$(e).closest('tr').addClass('active slx-bold').after(tr);
td.load('?do=Locations&page=details&action=showlocation&locationid=' + lid, function() {
- slxAttachCidr();
+ if (slxAttachCidr) slxAttachCidr();
scollIntoView(tr);
});
slxLastLocation = tr;
@@ -230,18 +230,14 @@ function scollIntoView(el) {
function slxAddSubnetRow(e, lid) {
var tr = $('#loc-sub-' + lid);
- tr.before('<tr id="row' + slxAddCounter + '" class="cidrmagic">\
+ tr.before('<tr class="cidrmagic">\
<td>#</td>\
<td><input class="form-control cidrstart" type="text" name="newstartaddr[' + slxAddCounter + ']" pattern="\\d{1,3}\.\\d{1,3}\.\\d{1,3}\.\\d{1,3}"></td>\
<td><input class="form-control cidrend" type="text" name="newendaddr[' + slxAddCounter + ']" pattern="\\d{1,3}\.\\d{1,3}\.\\d{1,3}\.\\d{1,3}"></td>\
- <td class="text-center"><button class="btn btn-default btn-sm" type="button" onclick="removeNewSubnetRow(' + slxAddCounter + ')"><span class="glyphicon glyphicon-remove"></span></button></td>\
+ <td class="text-center"><button class="btn btn-default btn-sm" type="button" onclick="$(this).closest(\'tr\').remove()"><span class="glyphicon glyphicon-remove"></span></button></td>\
</tr>');
slxAddCounter++;
- slxAttachCidr();
-}
-
-function removeNewSubnetRow(r) {
- $("#row"+r).remove();
+ if (slxAttachCidr) slxAttachCidr();
}
function deleteSubnetWarning(locid) {