Skip to content
This repository has been archived by the owner on Apr 7, 2024. It is now read-only.

Commit

Permalink
Wake on Lan by @leiweibau
Browse files Browse the repository at this point in the history
  • Loading branch information
jokob-sk committed Mar 11, 2023
1 parent 40615cf commit 73c779c
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 3 deletions.
61 changes: 58 additions & 3 deletions front/deviceDetails.php
Original file line number Diff line number Diff line change
Expand Up @@ -441,9 +441,32 @@
<i class="fa fa-info-circle"></i> </a>
</div>
</div>
</div>
</div>

<div class="col-lg-4 col-sm-6 col-xs-12">
<h4 class="bottom-border-aqua"><?= lang('DevDetail_Run_Actions_Title');?></h4>
<div class="box-body form-horizontal">
<label class="col-sm-3 control-label">
<?= lang('Gen_Action');?>
</label>
<div class="col-sm-9">
<div class="input-group">
<input class="form-control" title="<?= lang('DevDetail_Icon_Descr');?>" id="txtAction" type="text" value="--">
<span class="input-group-addon" title='<?= lang('Gen_Run');?>'><i class="fa fa-play pointer" onclick="askRunAction();"></i></span>

<div class="input-group-btn">
<button type="button" class="btn btn-info dropdown-toggle" data-toggle="dropdown" aria-expanded="false">
<span class="fa fa-caret-down"></span>
</button>
<ul id="dropdownAction" class="dropdown-menu dropdown-menu-right">
</ul>
</div>
</div>
</div>

</div>
</div>

<!-- Buttons -->
<div class="col-xs-12">
Expand Down Expand Up @@ -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 ();
Expand Down Expand Up @@ -1547,8 +1571,6 @@ function setDeviceData (direction='', refreshCallback='') {
});
}



// -----------------------------------------------------------------------------
function askSkipNotifications () {
// Check MAC
Expand Down Expand Up @@ -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 () {
Expand Down
35 changes: 35 additions & 0 deletions front/php/server/devices.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
//------------------------------------------------------------------------------
Expand Down
12 changes: 12 additions & 0 deletions front/php/templates/language/en_us.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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 <code>pialert_front.log</code> 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' => '<i class="fa fa-power-off"></i> Wake-on-LAN',
'DevDetail_Run_Actions_Title' => '<i class="fa fa-play"></i> Run action on device',

//////////////////////////////////////////////////////////////////
// Maintenance Page
Expand Down

0 comments on commit 73c779c

Please sign in to comment.