From bd72cb3a16f1697491250e714694125e306c813c Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Wed, 23 Mar 2022 17:05:25 +0100 Subject: [rebootcontrol] Add option to override destination broadcast address --- .../rebootcontrol/inc/rebootcontrol.inc.php | 19 ++++++-- .../rebootcontrol/lang/de/template-tags.json | 3 ++ .../rebootcontrol/lang/en/template-tags.json | 3 ++ modules-available/rebootcontrol/page.inc.php | 3 ++ .../rebootcontrol/templates/header.html | 51 +++++++++++++--------- 5 files changed, 55 insertions(+), 24 deletions(-) (limited to 'modules-available/rebootcontrol') diff --git a/modules-available/rebootcontrol/inc/rebootcontrol.inc.php b/modules-available/rebootcontrol/inc/rebootcontrol.inc.php index 99e8a4cf..b5f47c1d 100644 --- a/modules-available/rebootcontrol/inc/rebootcontrol.inc.php +++ b/modules-available/rebootcontrol/inc/rebootcontrol.inc.php @@ -11,6 +11,8 @@ class RebootControl const KEY_UDP_PORT = 'rebootcontrol.port'; + const KEY_BROADCAST_ADDRESS = 'rebootcontrol.broadcast-addr'; + const REBOOT = 'REBOOT'; const KEXEC_REBOOT = 'KEXEC_REBOOT'; const SHUTDOWN = 'SHUTDOWN'; @@ -332,6 +334,10 @@ class RebootControl // Determine method for all clients $taskClients = []; // array of arrays with keys [ip, mac, methods] $taskSsh = []; // SSH configs for task, array of arrays with keys [username, sshkey, ip, port, command] + $overrideBroadcast = Property::get(self::KEY_BROADCAST_ADDRESS); + if (empty($overrideBroadcast)) { + $overrideBroadcast = false; + } foreach ($clientList as $client) { $ip = sprintf('%u', ip2long($client['clientip'])); // 32Bit snprintf unset($subnet); @@ -351,6 +357,12 @@ class RebootControl 'mac' => $client['macaddr'], 'methods' => [], ]; + // If we have an override broadcast address, unconditionally add this as the + // first method + if ($overrideBroadcast !== false) { + $c['ip'] = $overrideBroadcast; + $c['methods'][] = 'DIRECT'; + } self::findMachinesForSubnet($subnet); // Highest priority - clients in same subnet, no directed broadcast // required, should be most reliable @@ -361,8 +373,9 @@ class RebootControl self::addSshMethodUsingClient($subnet['iclients'], $c['methods'], $taskSsh); // Jumphosts in other subnets, determined to be able to reach destination subnet self::addSshMethodUsingJumphost($subnet['ijumphosts'], true, $c['methods'], $taskSsh); - // If directly reachable from server, prefer this now - if ($subnet['isdirect']) { + // If directly reachable from server, prefer this now over the questionable approaches below, + // but only if we didn't already add this above because of override + if ($overrideBroadcast === false && $subnet['isdirect']) { $c['methods'][] = 'DIRECT'; } if (empty($c['methods'])) { @@ -370,7 +383,7 @@ class RebootControl } else { // TODO: Remember WOL was attempted } - // Only other fallback is jumphosts that were not reachable when last checked, this is really a last resort + // Last fallback is jumphosts that were not reachable when last checked, this is really a last resort self::addSshMethodUsingJumphost($subnet['djumphosts'], false, $c['methods'], $taskSsh); self::addSshMethodUsingJumphost($subnet['ijumphosts'], false, $c['methods'], $taskSsh); diff --git a/modules-available/rebootcontrol/lang/de/template-tags.json b/modules-available/rebootcontrol/lang/de/template-tags.json index 9db3d0a1..5ced0dec 100644 --- a/modules-available/rebootcontrol/lang/de/template-tags.json +++ b/modules-available/rebootcontrol/lang/de/template-tags.json @@ -13,6 +13,9 @@ "lang_clientCount": "# Clients", "lang_confirmDeleteSubnet": "Dieses Subnetz wirklich l\u00f6schen?", "lang_connecting": "Verbinde...", + "lang_directedBroadcastAddress": "Ziel-Adresse", + "lang_directedBroadcastDescription": "Diese Adresse wird als Ziel-Adresse zum Wecken s\u00e4mtlicher Clients benutzt. Dies ist bei Verwendung von WOL-Proxies sinnvoll. Wenn das Feld leer ist, wird die Directed Broadcast Adresse des Zielnetzes verwendet.", + "lang_directedBroadcastOverrideHeading": "Directed Broadcast Adresse \u00fcberschreiben", "lang_editJumpHost": "Sprung-Host bearbeiten", "lang_editSubnet": "Subnetz bearbeiten", "lang_enterCommand": "Auszuf\u00fchrende Befehle", diff --git a/modules-available/rebootcontrol/lang/en/template-tags.json b/modules-available/rebootcontrol/lang/en/template-tags.json index a50ba7fe..e29e2d6a 100644 --- a/modules-available/rebootcontrol/lang/en/template-tags.json +++ b/modules-available/rebootcontrol/lang/en/template-tags.json @@ -13,6 +13,9 @@ "lang_clientCount": "# clients", "lang_confirmDeleteSubnet": "Delete this subnet?", "lang_connecting": "Connecting...", + "lang_directedBroadcastAddress": "Destination address", + "lang_directedBroadcastDescription": "This address will be used as the destination address for wake on LAN. This is useful if you want to use a WOL-proxy that does the actual waking. If you leave this field empty, the broadcast address of the destination network will be used.", + "lang_directedBroadcastOverrideHeading": "Override directed broadcast address", "lang_editJumpHost": "Edit jump host", "lang_editSubnet": "Edit subnet", "lang_enterCommand": "Command(s) to execute", diff --git a/modules-available/rebootcontrol/page.inc.php b/modules-available/rebootcontrol/page.inc.php index 571e92e0..b84b4d9a 100644 --- a/modules-available/rebootcontrol/page.inc.php +++ b/modules-available/rebootcontrol/page.inc.php @@ -48,9 +48,11 @@ class Page_RebootControl extends Page $enabled = Request::post('enabled', false); $c2c = Request::post('enabled-c2c', false); $port = Request::post('port', 9, 'int'); + $dbcast = Request::post('dbcast', '', 'string'); Property::set(RebootControl::KEY_AUTOSCAN_DISABLED, !$enabled); Property::set(RebootControl::KEY_SCAN_CLIENT_TO_CLIENT, $c2c); Property::set(RebootControl::KEY_UDP_PORT, $port); + Property::set(RebootControl::KEY_BROADCAST_ADDRESS, $dbcast); if ($enabled) { Message::addInfo('woldiscover-enabled'); } else { @@ -112,6 +114,7 @@ class Page_RebootControl extends Page 'wol_auto_checked' => Property::get(RebootControl::KEY_AUTOSCAN_DISABLED) ? '' : 'checked', 'wol_c2c_checked' => Property::get(RebootControl::KEY_SCAN_CLIENT_TO_CLIENT) ? 'checked' : '', 'port' => $port, + 'dbcast' => Property::get(RebootControl::KEY_BROADCAST_ADDRESS), ]; Permission::addGlobalTags($data['perms'], null, ['newkeypair', 'woldiscover']); Render::addTemplate('header', $data); diff --git a/modules-available/rebootcontrol/templates/header.html b/modules-available/rebootcontrol/templates/header.html index d5e79a14..47d97714 100644 --- a/modules-available/rebootcontrol/templates/header.html +++ b/modules-available/rebootcontrol/templates/header.html @@ -42,28 +42,37 @@ + + - @@ -98,4 +107,4 @@ document.addEventListener('DOMContentLoaded', function() { }); - \ No newline at end of file + -- cgit v1.2.3-55-g7522