Add option to shutdown for WOL processing.

This commit is contained in:
SimonFair
2024-01-30 20:23:07 +00:00
parent bea6e282ec
commit 89fbe80e9f
5 changed files with 22 additions and 4 deletions

View File

@@ -27,7 +27,7 @@ if (count($_POST)) {
foreach($update_file as $type => $types) {
foreach($types as $name => $details) {
if ($details['user_mac'] == "") $details['user_mac'] = "None Defined";
if ($details['user_mac'] == "None Defined" && $details['enable'] == "enable") unset($update_file[$type][$name]) ;
if ($details['user_mac'] == "None Defined" && ($details['enable'] == "enable" || $details['enable'] == "shutdown")) unset($update_file[$type][$name]) ;
}
}
}

View File

@@ -65,6 +65,14 @@ _(Enable VM actions)_:
:WOL_run_VM_help:
_(Enable Shutdown actions)_:
: <select name="RUNSHUT" >
<?=mk_option($current['RUNSHUT'], "n", _('No'))?>
<?=mk_option($current['RUNSHUT'], "y", _('Yes'))?>
</select>
:WOL_run_shutdown_help:
_(Interface to listern on)_:
: <select id="INTERFACE" name="INTERFACE" >
<?=mk_option(_var($eth0,'INTERFACE'),'eth0','eth0','selected')?>

View File

@@ -90,6 +90,7 @@ case 't1load':
$html .="<select name='$selecttypename' class='audio narrow'>";
$html .= mk_option($macaddr["enable"] , "disable", _("Disabled"));
$html .= mk_option($macaddr["enable"] , "enable", _("Enabled"));
$html .= mk_option($macaddr["enable"] , "shutdown", _("Enabled and Shutdown"));
$html .= "</select></td><td>".$user_mac_str."</td></tr>";
$text = "";
}

View File

@@ -28,6 +28,7 @@ extract(parse_ini_file("/boot/config/wol.cfg")) ;
if (!isset($RUNLXC)) $RUNLXC = "y";
if (!isset($RUNVM)) $RUNVM = "y";
if (!isset($RUNDocker)) $RUNDocker = "y";
if (!isset($RUNSHUT)) $RUNSHUT = "n";
$arrEntries = [] ;
if ($libvirtd_running && $RUNVM == "y") {
@@ -116,8 +117,8 @@ foreach($arrEntries as $type => $detail)
$found = array_key_exists($mac,$mac_list);
if ($found && $mac_list[$mac]['enable'] == "enable") {
echo _("Found "). $mac . " ".$mac_list[$mac]['type']." ".$mac_list[$mac]['name'];
if ($found && $mac_list[$mac]['enable'] != "disable") {
echo _("Found"). " " . $mac . " ".$mac_list[$mac]['type']." ".$mac_list[$mac]['name'];
switch ($mac_list[$mac]['type']) {
case "VM":
@@ -127,6 +128,7 @@ if ($found && $mac_list[$mac]['enable'] == "enable") {
$state = $lv->domain_state_translate($dom['state']);
switch ($state) {
case 'running':
if ($RUNSHUT == "y" && $mac_list[$mac]['enable'] == "shutdown") $lv->domain_shutdown("{$mac_list[$mac]['name']}");
break;
case 'paused':
case 'pmsuspended':
@@ -142,6 +144,7 @@ if ($found && $mac_list[$mac]['enable'] == "enable") {
$state = getContainerStats($mac_list[$mac]['name'], "State");
switch ($state) {
case 'RUNNING':
if ($RUNSHUT == "y" && $mac_list[$mac]['enable'] == "shutdown") shell_exec("lxc-stop {$mac_list[$mac]['name']}");
break;
case 'FROZEN':
shell_exec("lxc-unfreeze {$mac_list[$mac]['name']}");
@@ -155,7 +158,9 @@ if ($found && $mac_list[$mac]['enable'] == "enable") {
if ($dockerd_running && $RUNDOCKER == "y") {
switch ($mac_list[$mac]['state']) {
case "running":
if ($RUNSHUT == "y" && $mac_list[$mac]['enable'] == "shutdown") shell_exec("docker stop {$mac_list[$mac]['name']}");
break;
case "exited":
case "created":
shell_exec("docker start {$mac_list[$mac]['name']}");