summaryrefslogtreecommitdiffstats
path: root/modules-available/rebootcontrol
diff options
context:
space:
mode:
authorSimon Rettberg2022-03-23 17:05:25 +0100
committerSimon Rettberg2022-03-23 17:05:25 +0100
commitbd72cb3a16f1697491250e714694125e306c813c (patch)
treed759f96ac624a38c60216faa5fdc3ea4d856f422 /modules-available/rebootcontrol
parent[passthrough] Fix #hash highlighting of devices (diff)
downloadslx-admin-bd72cb3a16f1697491250e714694125e306c813c.tar.gz
slx-admin-bd72cb3a16f1697491250e714694125e306c813c.tar.xz
slx-admin-bd72cb3a16f1697491250e714694125e306c813c.zip
[rebootcontrol] Add option to override destination broadcast address
Diffstat (limited to 'modules-available/rebootcontrol')
-rw-r--r--modules-available/rebootcontrol/inc/rebootcontrol.inc.php19
-rw-r--r--modules-available/rebootcontrol/lang/de/template-tags.json3
-rw-r--r--modules-available/rebootcontrol/lang/en/template-tags.json3
-rw-r--r--modules-available/rebootcontrol/page.inc.php3
-rw-r--r--modules-available/rebootcontrol/templates/header.html51
5 files changed, 55 insertions, 24 deletions
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 @@
</div>
<div class="modal-body">
<label>{{lang_wolDiscoverHeading}}</label>
- <div class="checkbox">
- <input {{perms.woldiscover.disabled}} id="wol-auto-discover"
- type="checkbox" name="enabled" {{wol_auto_checked}}>
- <label for="wol-auto-discover">{{lang_wolAutoDiscoverCheck}}</label>
- </div>
- <div class="checkbox">
- <input {{perms.woldiscover.disabled}} id="wol-c2c"
- type="checkbox" name="enabled-c2c" {{wol_c2c_checked}}>
- <label for="wol-c2c">{{lang_wolDiscoverClientToClient}}</label>
- </div>
- <div class="slx-space"></div>
- <p>{{lang_wolDiscoverDescription}}</p>
- <button {{perms.woldiscover.disabled}} class="btn btn-primary pull-right"
- onclick="generateNewKeypair()" type="submit">
- <span class="glyphicon glyphicon-floppy-disk"></span>
- {{lang_save}}
- </button>
- <div class="clearfix"></div>
+ <div class="checkbox">
+ <input {{perms.woldiscover.disabled}} id="wol-auto-discover"
+ type="checkbox" name="enabled" {{wol_auto_checked}}>
+ <label for="wol-auto-discover">{{lang_wolAutoDiscoverCheck}}</label>
+ </div>
+ <div class="checkbox">
+ <input {{perms.woldiscover.disabled}} id="wol-c2c"
+ type="checkbox" name="enabled-c2c" {{wol_c2c_checked}}>
+ <label for="wol-c2c">{{lang_wolDiscoverClientToClient}}</label>
+ </div>
+ <div class="slx-space"></div>
+ <p>{{lang_wolDiscoverDescription}}</p>
+ </div>
+ <div class="modal-body">
+ <label for="bcast-input">{{lang_directedBroadcastOverrideHeading}}</label>
+ <div class="input-group">
+ <span class="input-group-addon">{{lang_directedBroadcastAddress}}</span>
+ <input {{perms.woldiscover.disabled}} type="text" pattern="[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+"
+ minlength="7" maxlength="15" class="form-control" name="dbcast" value="{{dbcast}}" id="bcast-input">
+ </div>
+ <p>{{lang_directedBroadcastDescription}}</p>
+ </div>
+ <div class="modal-body">
+ <button {{perms.woldiscover.disabled}} class="btn btn-primary pull-right"
+ onclick="generateNewKeypair()" type="submit">
+ <span class="glyphicon glyphicon-floppy-disk"></span>
+ {{lang_save}}
+ </button>
+ <div class="clearfix"></div>
</div>
</form>
- <div class="modal-body">
- </div>
</div>
</div>
</div>
@@ -98,4 +107,4 @@ document.addEventListener('DOMContentLoaded', function() {
});
-</script> \ No newline at end of file
+</script>