mirror of
https://github.com/jokob-sk/NetAlertX.git
synced 2025-12-07 01:26:11 -08:00
Wake on Lan by @leiweibau
This commit is contained in:
@@ -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">
|
||||
@@ -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 () {
|
||||
|
||||
@@ -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
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
@@ -18,6 +18,8 @@ $lang['en_us'] = array(
|
||||
'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 @@ $lang['en_us'] = array(
|
||||
'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
|
||||
|
||||
Reference in New Issue
Block a user