diff --git a/front/deviceDetails.php b/front/deviceDetails.php
index 133a8d0e..ec1cdfb7 100755
--- a/front/deviceDetails.php
+++ b/front/deviceDetails.php
@@ -441,9 +441,32 @@
+
+
+
+
= lang('DevDetail_Run_Actions_Title');?>
+
+
+
+
+
@@ -924,7 +947,8 @@ function initializeCombos () {
initializeCombo ( '#dropdownGroup', 'getGroups', 'txtGroup', true);
initializeCombo ( '#dropdownLocation', 'getLocations', 'txtLocation', true);
initializeCombo ( '#dropdownNetworkNodeMac', 'getNetworkNodes', 'txtNetworkNodeMac', false);
- initializeCombo ( '#dropdownIcon', 'getIcons', 'txtIcon', false);
+ initializeCombo ( '#dropdownIcon', 'getIcons', 'txtIcon', false);
+ initializeCombo ( '#dropdownAction', 'getActions', 'txtAction', false);
// Initialize static combos
initializeComboSkipRepeated ();
@@ -1547,8 +1571,6 @@ function setDeviceData (direction='', refreshCallback='') {
});
}
-
-
// -----------------------------------------------------------------------------
function askSkipNotifications () {
// Check MAC
@@ -1601,6 +1623,39 @@ function deleteDeviceEvents () {
$('#panDetails :input').attr('disabled', true);
}
+// -----------------------------------------------------------------------------
+function askRunAction() {
+ // Ask
+ showModalWarning('= lang('BackDevDetail_Actions_Title_Run');?>', '= lang('BackDevDetail_Actions_Ask_Run');?>',
+ '= lang('Gen_Cancel');?>', '= lang('Gen_Run');?>', 'runAction');
+}
+
+function runAction() {
+
+ action = $('#txtAction').val();
+
+ switch(action)
+ {
+ case 'wake-on-lan':
+ wakeonlan();
+ break;
+ default:
+ showMessage (`= lang('BackDevDetail_Actions_Not_Registered');?> ${action} `);
+ break;
+ }
+
+}
+
+function wakeonlan() {
+ // Execute
+ $.get('php/server/devices.php?action=wakeonlan&'
+ + '&mac=' + $('#txtMAC').val()
+ + '&ip=' + $('#txtLastIP').val()
+ , function(msg) {
+ showMessage (msg);
+ });
+}
+
// -----------------------------------------------------------------------------
// Overwrite all devices of the same type with the currently selected icon
function askOverwriteIconType () {
diff --git a/front/php/server/devices.php b/front/php/server/devices.php
index 618cf10c..64060e78 100755
--- a/front/php/server/devices.php
+++ b/front/php/server/devices.php
@@ -57,6 +57,8 @@
case 'updateNetworkLeaf': updateNetworkLeaf(); break;
case 'overwriteIconType': overwriteIconType(); break;
case 'getIcons': getIcons(); break;
+ case 'getActions': getActions(); break;
+ case 'wakeonlan': wakeonlan(); break;
default: logServerConsole ('Action: '. $action); break;
}
@@ -869,6 +871,18 @@ function getIcons() {
echo (json_encode ($tableData));
}
+//------------------------------------------------------------------------------
+function getActions() {
+
+ $tableData = array(
+ array('id' => 'wake-on-lan',
+ 'name' => lang('DevDetail_WOL_Title'))
+ );
+
+ // Return json
+ echo (json_encode ($tableData));
+}
+
//------------------------------------------------------------------------------
// Query the List of types
@@ -1198,6 +1212,27 @@ function overwriteIconType()
}
+//------------------------------------------------------------------------------
+// Wake-on-LAN
+// Inspired by @leiweibau: https://github.com/leiweibau/Pi.Alert/commit/30427c7fea180670c71a2b790699e5d9e9e88ffd
+//------------------------------------------------------------------------------
+function wakeonlan() {
+
+ $WOL_HOST_IP = $_REQUEST['ip'];
+ $WOL_HOST_MAC = $_REQUEST['mac'];
+
+ if (!filter_var($WOL_HOST_IP, FILTER_VALIDATE_IP)) {
+ echo "Invalid IP! ". lang('BackDevDetail_Tools_WOL_error'); exit;
+ }
+ elseif (!filter_var($WOL_HOST_MAC, FILTER_VALIDATE_MAC)) {
+ echo "Invalid MAC! ". lang('BackDevDetail_Tools_WOL_error'); exit;
+ }
+
+ exec('wakeonlan '.$WOL_HOST_MAC , $output);
+
+ echo lang('BackDevDetail_Tools_WOL_okay');
+}
+
//------------------------------------------------------------------------------
// Status Where conditions
//------------------------------------------------------------------------------
diff --git a/front/php/templates/language/en_us.php b/front/php/templates/language/en_us.php
index 95b38683..fce146f2 100755
--- a/front/php/templates/language/en_us.php
+++ b/front/php/templates/language/en_us.php
@@ -18,6 +18,8 @@
'Gen_Okay' => 'Ok',
'Gen_Save' => 'Save',
'Gen_Saved' => 'Saved',
+'Gen_Run' => 'Run',
+'Gen_Action' => 'Action',
'Gen_Purge' => 'Purge',
'Gen_Backup' => 'Run Backup',
'Gen_Restore' => 'Run Restore',
@@ -230,6 +232,16 @@
'DevDetail_Nmap_buttonSkipDiscovery' => 'Skip host discovery',
'DevDetail_Nmap_buttonSkipDiscovery_text' => 'Skip host discovery (-Pn option): Default scan without host discovery',
'DevDetail_Nmap_resultsLink' => 'You can leave this page after starting a scan. Results will be also available in the pialert_front.log
file.',
+'BackDevDetail_Actions_Title_Run' => 'Run action',
+'BackDevDetail_Actions_Not_Registered' => 'Action not registered: ',
+'BackDevDetail_Actions_Ask_Run' => 'Do you want to execute the action?',
+'BackDevDetail_Tools_WOL_okay' => 'The command was executed.',
+'BackDevDetail_Tools_WOL_error' => 'The command was NOT executed.',
+'DevDetail_Tools_WOL_noti' => 'Wake-on-LAN',
+'DevDetail_Tools_WOL_noti_text' => 'The Wake-on-LAN command is sent to the broadcast address. If the target is not in the subnet/vlan of Pi.Alert, the target device will not respond.',
+'DevDetail_Tools_WOL' => 'Send Wol command to ',
+'DevDetail_WOL_Title' => ' Wake-on-LAN',
+'DevDetail_Run_Actions_Title' => ' Run action on device',
//////////////////////////////////////////////////////////////////
// Maintenance Page