From 2d49c621abeff1909b7f4c90d5273157a4f70286 Mon Sep 17 00:00:00 2001 From: Christian Hofmaier Date: Thu, 3 Dec 2020 12:58:52 +0100 Subject: [locations] Add scheduler to openingtimes modal - only load/safe without further functionality - add backend to rebootcontrol --- .../locations/lang/de/template-tags.json | 6 ++- .../locations/lang/en/template-tags.json | 6 ++- modules-available/locations/pages/details.inc.php | 42 ++++++++++++++++ .../locations/templates/ajax-opening-location.html | 43 +++++++++++++++- .../locations/templates/location-subnets.html | 2 +- .../rebootcontrol/inc/scheduler.inc.php | 58 ++++++++++++++++++++++ modules-available/rebootcontrol/install.inc.php | 9 ++++ 7 files changed, 162 insertions(+), 4 deletions(-) create mode 100644 modules-available/rebootcontrol/inc/scheduler.inc.php diff --git a/modules-available/locations/lang/de/template-tags.json b/modules-available/locations/lang/de/template-tags.json index 18176278..94f95ded 100644 --- a/modules-available/locations/lang/de/template-tags.json +++ b/modules-available/locations/lang/de/template-tags.json @@ -37,6 +37,8 @@ "lang_moveable": "Verschiebbar", "lang_name": "Name", "lang_numMachinesWithOverrides": "Anzahl Rechner, bei denen mindestens eine Konfigurationsvariable \u00fcberschrieben wird", + "lang_offsetEarly": "Min. vorher", + "lang_offsetLate": "Min. danach", "lang_openingTime": "\u00d6ffnungszeit", "lang_overridenVarsForLocation": "Anzahl Variablen, die an diesem Ort \u00fcberschrieben werden", "lang_parentLocation": "\u00dcbergeordneter Ort", @@ -51,11 +53,13 @@ "lang_shortTuesday": "Di", "lang_shortWednesday": "Mi", "lang_showRoomplan": "Raumplan anzeigen", + "lang_shutdown": "Herunterfahren", "lang_startAddress": "Startadresse", "lang_subnet": "IP-Bereich", "lang_sunday": "Sonntag", "lang_sysConfig": "Lokalisierung", "lang_thisListByLocation": "Orte", "lang_thisListBySubnet": "Subnetze", - "lang_unassignedMachines": "Rechner, die in keinen definierten Ort fallen" + "lang_unassignedMachines": "Rechner, die in keinen definierten Ort fallen", + "lang_wakeonlan": "WakeOnLan" } \ No newline at end of file diff --git a/modules-available/locations/lang/en/template-tags.json b/modules-available/locations/lang/en/template-tags.json index c4fabdb0..467af8e1 100644 --- a/modules-available/locations/lang/en/template-tags.json +++ b/modules-available/locations/lang/en/template-tags.json @@ -37,6 +37,8 @@ "lang_moveable": "Moveable", "lang_name": "Name", "lang_numMachinesWithOverrides": "Number of clients where at least one variable is overridden", + "lang_offsetEarly": "min. before", + "lang_offsetLate": "min. after", "lang_openingTime": "Opening Time", "lang_overridenVarsForLocation": "Number of variables that get overridden for this location", "lang_parentLocation": "Parent location", @@ -51,11 +53,13 @@ "lang_shortTuesday": "Tue", "lang_shortWednesday": "Wed", "lang_showRoomplan": "Show room plan", + "lang_shutdown": "Shutdown", "lang_startAddress": "Start address", "lang_subnet": "IP range", "lang_sunday": "Sunday", "lang_sysConfig": "Localization\/Integration", "lang_thisListByLocation": "Locations", "lang_thisListBySubnet": "Subnets", - "lang_unassignedMachines": "Machines not matching any location" + "lang_unassignedMachines": "Machines not matching any location", + "lang_wakeonlan": "WakeOnLan" } \ No newline at end of file diff --git a/modules-available/locations/pages/details.inc.php b/modules-available/locations/pages/details.inc.php index a55460cf..81c2f2fa 100644 --- a/modules-available/locations/pages/details.inc.php +++ b/modules-available/locations/pages/details.inc.php @@ -36,6 +36,10 @@ class SubPage private static function updateOpeningTimes() { $openingTimes = Request::post('openingtimes', '', 'string'); $locationid = Request::post('locationid', false, 'int'); + $wol = Request::post('wol', false, 'bool'); + $woloffset = Request::post('wol-offset', 0, 'int'); + $sd = Request::post('sd', false, 'bool'); + $sdoffset = Request::post('sd-offset', 0, 'int'); User::assertPermission('location.edit', $locationid); @@ -83,6 +87,29 @@ class SubPage Database::exec('UPDATE location SET openingtime = :openingtime WHERE locationid = :locationid', array('locationid' => $locationid, 'openingtime' => $openingTimes)); + if (Module::isAvailable('rebootcontrol')) { + if ($wol) { + $options = array(); + // Sanity checks + if ($woloffset > 15) $woloffset = 15; + else if ($woloffset < 0) $woloffset = 0; + $options['wol-offset'] = $woloffset; + Scheduler::updateSchedule($locationid, 'wol', $options, $openingTimes); + } else { + Scheduler::deleteSchedule($locationid, 'wol'); + } + if ($sd) { + $options = array(); + // Sanity checks + if ($sdoffset > 15) $sdoffset = 15; + else if ($sdoffset < 0) $sdoffset = 0; + $options['sd-offset'] = $sdoffset; + Scheduler::updateSchedule($locationid, 'sd', $options, $openingTimes); + } else { + Scheduler::deleteSchedule($locationid, 'sd'); + } + } + return true; } @@ -394,6 +421,21 @@ class SubPage $data['expertMode'] = !self::isSimpleMode($openingTimes); $data['schedule_data'] = json_encode($openingTimes); + $rebootcontrol = Module::isAvailable('rebootcontrol'); + $data['rebootcontrol'] = $rebootcontrol; + if ($rebootcontrol) { + $wol = Database::queryFirst("SELECT options FROM `scheduler` WHERE locationid = :id AND action = 'wol'", array('id' => $id)); + if ($wol !== false) { + $data['wol'] = true; + $data['wol-options'] = json_decode($wol['options']); + } + $sd = Database::queryFirst("SELECT options FROM `scheduler` WHERE locationid = :id AND action = 'sd'", array('id' => $id)); + if ($sd !== false) { + $data['sd'] = true; + $data['sd-options'] = json_decode($sd['options']); + } + } + echo Render::parse('ajax-opening-location', $data); } diff --git a/modules-available/locations/templates/ajax-opening-location.html b/modules-available/locations/templates/ajax-opening-location.html index 09fe7869..3b2ea7ae 100644 --- a/modules-available/locations/templates/ajax-opening-location.html +++ b/modules-available/locations/templates/ajax-opening-location.html @@ -124,7 +124,49 @@ +{{#rebootcontrol}} +
+
+
+
+ + +
+
+
+ + +
+
+
+ + +
+
+
+ + +
+
+{{/rebootcontrol}} + diff --git a/modules-available/locations/templates/location-subnets.html b/modules-available/locations/templates/location-subnets.html index b85ddbec..f88e2908 100644 --- a/modules-available/locations/templates/location-subnets.html +++ b/modules-available/locations/templates/location-subnets.html @@ -151,7 +151,7 @@