summaryrefslogtreecommitdiffstats
path: root/modules-available/locations/page.inc.php
diff options
context:
space:
mode:
authorSimon Rettberg2016-06-24 17:08:24 +0200
committerSimon Rettberg2016-06-24 17:08:24 +0200
commit3d0cb99c70dd9714655cf26893504e4bd007b036 (patch)
tree8b5cdaee9c0196aedb6a5c3f8138005a18091fa8 /modules-available/locations/page.inc.php
parentmodified the editor toolbar. (diff)
downloadslx-admin-3d0cb99c70dd9714655cf26893504e4bd007b036.tar.gz
slx-admin-3d0cb99c70dd9714655cf26893504e4bd007b036.tar.xz
slx-admin-3d0cb99c70dd9714655cf26893504e4bd007b036.zip
[locations] Support CIDR notion (start field), tweak templates a bit
Diffstat (limited to 'modules-available/locations/page.inc.php')
-rw-r--r--modules-available/locations/page.inc.php72
1 files changed, 60 insertions, 12 deletions
diff --git a/modules-available/locations/page.inc.php b/modules-available/locations/page.inc.php
index de724350..f747592f 100644
--- a/modules-available/locations/page.inc.php
+++ b/modules-available/locations/page.inc.php
@@ -21,8 +21,43 @@ class Page_Locations extends Page
$this->updateLocation();
} elseif ($this->action === 'addlocations') {
$this->addLocations();
+ } elseif ($this->action === 'updatesubnets') {
+ $this->updateSubnets();
}
}
+
+ private function updateSubnets()
+ {
+ $count = 0;
+ $starts = Request::post('startaddr', false);
+ $ends = Request::post('endaddr', false);
+ $locs = Request::post('location', false);
+ if (!is_array($starts) || !is_array($ends) || !is_array($locs)) {
+ Message::addError('main.empty-field');
+ Util::redirect('?do=Locations');
+ }
+ $existingLocs = Location::getLocationsAssoc();
+ $stmt = Database::prepare("UPDATE subnet SET startaddr = :startLong, endaddr = :endLong, locationid = :loc WHERE subnetid = :subnetid");
+ foreach ($starts as $subnetid => $start) {
+ if (!isset($ends[$subnetid]) || !isset($locs[$subnetid]))
+ continue;
+ $loc = (int)$locs[$subnetid];
+ $end = $ends[$subnetid];
+ if (!isset($existingLocs[$loc])) {
+ Message::addError('main.value-invalid', 'locationid', $loc);
+ continue;
+ }
+ $range = $this->rangeToLongVerbose($start, $end);
+ if ($range === false)
+ continue;
+ list($startLong, $endLong) = $range;
+ if ($stmt->execute(compact('startLong', 'endLong', 'loc', 'subnetid'))) {
+ $count += $stmt->rowCount();
+ }
+ }
+ Message::addSuccess('updated-x-entries', $count);
+ Util::redirect('?do=Locations');
+ }
private function addLocations()
{
@@ -147,7 +182,7 @@ class Page_Locations extends Page
Message::addSuccess('location-updated', $newName);
}
}
-
+
private function updateLocationSubnets()
{
// Deletion first
@@ -177,18 +212,10 @@ class Page_Locations extends Page
foreach ($starts as $key => $start) {
if (!isset($ends[$key]) || !is_numeric($key)) continue;
$end = $ends[$key];
- list($startLong, $endLong) = $this->rangeToLong($start, $end);
- if ($startLong === false) {
- Message::addWarning('main.value-invalid', 'start addr', $start);
- }
- if ($endLong === false) {
- Message::addWarning('main.value-invalid', 'end addr', $start);
- }
- if ($startLong === false || $endLong === false) continue;
- if ($startLong > $endLong) {
- Message::addWarning('main.value-invalid', 'range', $start . ' - ' . $end);
+ $range = $this->rangeToLongVerbose($start, $end);
+ if ($range === false)
continue;
- }
+ list($startLong, $endLong) = $range;
if ($stmt->execute(array('id' => $key, 'start' => $startLong, 'end' => $endLong))) {
$count += $stmt->rowCount();
}
@@ -390,6 +417,7 @@ class Page_Locations extends Page
. ' INNER JOIN sat.lecture_x_location ll ON (l.lectureid = ll.lectureid AND ll.locationid = :lid)',
array('lid' => $locationId));
$data['lectures'] = $lectures['cnt'];
+ $data['haveDozmod'] = true;
}
// Get clients matching this location's subnet(s)
$count = $online = $used = 0;
@@ -407,6 +435,7 @@ class Page_Locations extends Page
}
}
}
+ $data['haveStatistics'] = true;
}
$data['machines'] = $count;
$data['machines_online'] = $online;
@@ -432,4 +461,23 @@ class Page_Locations extends Page
return array($startLong, $endLong);
}
+ private function rangeToLongVerbose($start, $end)
+ {
+ $result = $this->rangeToLong($start, $end);
+ list($startLong, $endLong) = $result;
+ if ($startLong === false) {
+ Message::addWarning('main.value-invalid', 'start addr', $start);
+ }
+ if ($endLong === false) {
+ Message::addWarning('main.value-invalid', 'end addr', $start);
+ }
+ if ($startLong === false || $endLong === false)
+ return false;
+ if ($startLong > $endLong) {
+ Message::addWarning('main.value-invalid', 'range', $start . ' - ' . $end);
+ return false;
+ }
+ return $result;
+ }
+
}