summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Hofmaier2020-12-03 12:58:52 +0100
committerChristian Hofmaier2020-12-03 12:58:52 +0100
commit2d49c621abeff1909b7f4c90d5273157a4f70286 (patch)
tree5bf548871469c1309f4fa9d43cfd63ec52f89a43
parent[statistics_reporting/statistics] Include system/runmode total counts (diff)
downloadslx-admin-2d49c621abeff1909b7f4c90d5273157a4f70286.tar.gz
slx-admin-2d49c621abeff1909b7f4c90d5273157a4f70286.tar.xz
slx-admin-2d49c621abeff1909b7f4c90d5273157a4f70286.zip
[locations] Add scheduler to openingtimes modal
- only load/safe without further functionality - add backend to rebootcontrol
-rw-r--r--modules-available/locations/lang/de/template-tags.json6
-rw-r--r--modules-available/locations/lang/en/template-tags.json6
-rw-r--r--modules-available/locations/pages/details.inc.php42
-rw-r--r--modules-available/locations/templates/ajax-opening-location.html43
-rw-r--r--modules-available/locations/templates/location-subnets.html2
-rw-r--r--modules-available/rebootcontrol/inc/scheduler.inc.php58
-rw-r--r--modules-available/rebootcontrol/install.inc.php9
7 files changed, 162 insertions, 4 deletions
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 @@
</div>
</div>
+{{#rebootcontrol}}
+<hr>
+<div class="row">
+ <div class="col-sm-4">
+ <div class="checkbox checkbox-inline">
+ <input id="wol" name="wol" class="wol" type="checkbox">
+ <label for="wol">{{lang_wakeonlan}}</label>
+ </div>
+ </div>
+ <div class="col-sm-8">
+ <input disabled type="number" id="wol-offset" name="wol-offset" class="wol-offset" value="{{wol-options.wol-offset}}" placeholder="0" min="0" max="15">
+ <label for="wol-offset">{{lang_offsetEarly}}</label>
+ </div>
+ <div class="col-sm-4">
+ <div class="checkbox checkbox-inline">
+ <input id="sd" name="sd" class="sd" type="checkbox">
+ <label for="sd">{{lang_shutdown}}</label>
+ </div>
+ </div>
+ <div class="col-sm-8">
+ <input disabled type="number" id="sd-offset" name="sd-offset" class="sd-offset" value="{{sd-options.sd-offset}}" placeholder="0" min="0" max="15">
+ <label for="sd-offset">{{lang_offsetLate}}</label>
+ </div>
+</div>
+{{/rebootcontrol}}
+
<script type="application/javascript"><!--
+ let wol = $('#wol');
+ let sd = $('#sd');
+
+ wol.attr('checked',{{wol}});
+ sd.attr('checked',{{sd}});
+ $('#wol-offset').attr('disabled', !$('#wol').is(':checked'));
+ $('#sd-offset').attr('disabled', !$('#sd').is(':checked'));
+
+ wol.on('click', function(){
+ $('#wol-offset').attr('disabled', !$(this).is(':checked'));
+ });
+
+ sd.on('click', function(){
+ $('#sd-offset').attr('disabled', !$(this).is(':checked'));
+ });
+
(function() {
var scheduleData = {{{schedule_data}}};
@@ -167,7 +209,6 @@
$('#simple-mode').remove();
$('#expert-mode').show();
});
-
})();
//--></script>
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 @@
<div class="modal-header">{{locationname}}</div>
<div class="modal-body"></div>
<div class="modal-footer">
- <button type="button" class="btn btn-default" data-dismiss="modal">{{lang_close}}</button>
+ <button type="button" class="btn btn-default" data-dismiss="modal" onclick="$('#openingTimesModal{{locationid}} .modal-body').html('')">{{lang_close}}</button>
<button type="submit" class="btn btn-primary">
<span class="glyphicon glyphicon-floppy-disk"></span>
{{lang_save}}
diff --git a/modules-available/rebootcontrol/inc/scheduler.inc.php b/modules-available/rebootcontrol/inc/scheduler.inc.php
new file mode 100644
index 00000000..839d7d81
--- /dev/null
+++ b/modules-available/rebootcontrol/inc/scheduler.inc.php
@@ -0,0 +1,58 @@
+<?php
+
+class Scheduler
+{
+
+ public static function updateSchedule($locationid, $action, $options, $openingTimes) {
+ if ($openingTimes == '') {
+ self::deleteSchedule($locationid, $action);
+ return false;
+ }
+ $nextwake = self::calcNextwake($action, $openingTimes);
+ $json_options = json_encode($options);
+ self::upsert($locationid, $action, $nextwake, $json_options);
+ return true;
+ }
+
+ public static function deleteSchedule($locationid, $action) {
+ Database::exec("DELETE FROM `scheduler`
+ WHERE locationid = :lid AND action = :act", array(
+ 'lid' => $locationid,
+ 'act' => $action
+ ));
+ }
+
+ private static function calcNextwake($action, $openingTimes) {
+ //TODO: Calculate nextWake based on openingTimes. Needs action to know if openTimes or closingTimes are used.
+ return 0;
+ }
+
+ private static function upsert($locationid, $action, $nextwake, $options) {
+ $schedule = Database::queryFirst("SELECT locationid, action
+ FROM `scheduler`
+ WHERE locationid = :lid AND action = :act", array(
+ 'lid' => $locationid,
+ 'act' => $action
+ ));
+ if ($schedule === false) {
+ Database::exec("INSERT INTO `scheduler` (locationid, action, nextwake, options)
+ VALUES (:lid, :act, :next, :opt)", array(
+ 'lid' => $locationid,
+ 'act' => $action,
+ 'next' => $nextwake,
+ 'opt' => $options
+ ));
+ } else {
+ Database::exec("UPDATE `scheduler`
+ SET nextwake = :next, options = :opt
+ WHERE locationid = :lid AND action = :act", array(
+ 'next' => $nextwake,
+ 'opt' => $options,
+ 'lid' => $locationid,
+ 'act' => $action
+ ));
+ }
+ return true;
+ }
+
+} \ No newline at end of file
diff --git a/modules-available/rebootcontrol/install.inc.php b/modules-available/rebootcontrol/install.inc.php
index 0aedfa20..6fe040ad 100644
--- a/modules-available/rebootcontrol/install.inc.php
+++ b/modules-available/rebootcontrol/install.inc.php
@@ -37,6 +37,13 @@ $output[] = tableCreate('reboot_subnet_x_subnet', "
PRIMARY KEY (`srcid`, `dstid`),
KEY `nextcheck` (`nextcheck`)");
+$output[] = tableCreate('scheduler', "
+ `locationid` INT(11) NOT NULL,
+ `action` ENUM('wol', 'sd'),
+ `nextwake` INT(10) UNSIGNED NOT NULL DEFAULT 0,
+ `options` BLOB,
+ PRIMARY KEY (`locationid`, `action`)");
+
$output[] = tableAddConstraint('reboot_jumphost_x_subnet', 'hostid', 'reboot_jumphost', 'hostid',
'ON UPDATE CASCADE ON DELETE CASCADE');
$output[] = tableAddConstraint('reboot_jumphost_x_subnet', 'subnetid', 'reboot_subnet', 'subnetid',
@@ -45,5 +52,7 @@ $output[] = tableAddConstraint('reboot_subnet_x_subnet', 'srcid', 'reboot_subnet
'ON UPDATE CASCADE ON DELETE CASCADE');
$output[] = tableAddConstraint('reboot_subnet_x_subnet', 'dstid', 'reboot_subnet', 'subnetid',
'ON UPDATE CASCADE ON DELETE CASCADE');
+$output[] = tableAddConstraint('scheduler', 'locationid', 'location', 'locationid',
+ 'ON UPDATE CASCADE ON DELETE CASCADE');
responseFromArray($output); \ No newline at end of file