summaryrefslogtreecommitdiffstats
path: root/modules-available/locations/pages/subnets.inc.php
diff options
context:
space:
mode:
authorSimon Rettberg2019-07-31 16:58:14 +0200
committerSimon Rettberg2019-07-31 16:58:14 +0200
commit7c539fd8736b0ff9acafe32d857b2a2021d778e6 (patch)
treeb6a44076cba8443b2840340256b9829451214229 /modules-available/locations/pages/subnets.inc.php
parent[locations] Optimize some functions in Location class (diff)
downloadslx-admin-7c539fd8736b0ff9acafe32d857b2a2021d778e6.tar.gz
slx-admin-7c539fd8736b0ff9acafe32d857b2a2021d778e6.tar.xz
slx-admin-7c539fd8736b0ff9acafe32d857b2a2021d778e6.zip
[locations] Add warnings/cleanup for bad machine to roomplan mappings
Diffstat (limited to 'modules-available/locations/pages/subnets.inc.php')
-rw-r--r--modules-available/locations/pages/subnets.inc.php79
1 files changed, 79 insertions, 0 deletions
diff --git a/modules-available/locations/pages/subnets.inc.php b/modules-available/locations/pages/subnets.inc.php
new file mode 100644
index 00000000..6c37129a
--- /dev/null
+++ b/modules-available/locations/pages/subnets.inc.php
@@ -0,0 +1,79 @@
+<?php
+
+class SubPage
+{
+
+ public static function doPreprocess($action)
+ {
+ if ($action === 'updatesubnets') {
+ self::updateSubnets();
+ return true;
+ }
+ return false;
+ }
+
+ private static function updateSubnets()
+ {
+ User::assertPermission('subnets.edit', NULL, '?do=locations');
+ $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 = LocationUtil::rangeToLongVerbose($start, $end);
+ if ($range === false)
+ continue;
+ list($startLong, $endLong) = $range;
+ if ($stmt->execute(compact('startLong', 'endLong', 'loc', 'subnetid'))) {
+ $count += $stmt->rowCount();
+ }
+ }
+ AutoLocation::rebuildAll();
+ Message::addSuccess('subnets-updated', $count);
+ Util::redirect('?do=Locations');
+ }
+
+ public static function doRender($getAction)
+ {
+ if ($getAction === false) {
+ User::assertPermission('subnets.edit', NULL, '?do=locations');
+ $res = Database::simpleQuery("SELECT subnetid, startaddr, endaddr, locationid FROM subnet");
+ $rows = array();
+ while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ $row['startaddr'] = long2ip($row['startaddr']);
+ $row['endaddr'] = long2ip($row['endaddr']);
+ $row['locations'] = Location::getLocations($row['locationid']);
+ $rows[] = $row;
+ }
+ $data = array('list' => $rows);
+ Permission::addGlobalTags($data['perms'], NULL, ['location.view']);
+ Render::addTemplate('subnets', $data);
+ return true;
+ }
+ return false;
+ }
+
+ public static function doAjax($action)
+ {
+ return false;
+ }
+
+ /*
+ * Helpers
+ */
+
+} \ No newline at end of file