summaryrefslogtreecommitdiffstats
path: root/inc/trigger.inc.php
diff options
context:
space:
mode:
authorSimon Rettberg2014-06-23 18:08:47 +0200
committerSimon Rettberg2014-06-23 18:08:47 +0200
commit4e64cbc599224273043759e365c0b1495a50de73 (patch)
tree5ec7bf78ee6dc075a1dd89608c196632f49f0a69 /inc/trigger.inc.php
parentGet rid of pxe menu ip tracking, not needed in the future (diff)
downloadslx-admin-4e64cbc599224273043759e365c0b1495a50de73.tar.gz
slx-admin-4e64cbc599224273043759e365c0b1495a50de73.tar.xz
slx-admin-4e64cbc599224273043759e365c0b1495a50de73.zip
Try to autpmatically detect server ip on init-api
Diffstat (limited to 'inc/trigger.inc.php')
-rw-r--r--inc/trigger.inc.php56
1 files changed, 45 insertions, 11 deletions
diff --git a/inc/trigger.inc.php b/inc/trigger.inc.php
index 2fde45ab..7ab7d5b1 100644
--- a/inc/trigger.inc.php
+++ b/inc/trigger.inc.php
@@ -18,26 +18,60 @@ class Trigger
* @param boolean $force force recompilation even if it seems up to date
* @return boolean|string true if already up to date, false if launching task failed, task-id otherwise
*/
- public static function ipxe($force = false)
+ public static function ipxe()
{
- if (!$force && Property::getIPxeIp() === Property::getServerIp())
- return true; // Nothing to do
- $last = Property::getIPxeTaskId();
- if ($last !== false) {
- $status = Taskmanager::status($last);
- if (isset($status['statusCode']) && ($status['statusCode'] === TASK_WAITING || $status['statusCode'] === TASK_PROCESSING))
- return false; // Already compiling
- }
$data = Property::getBootMenu();
- $data['ip'] = Property::getServerIp();
$task = Taskmanager::submit('CompileIPxe', $data);
if (!isset($task['id']))
return false;
- Property::setIPxeTaskId($task['id']);
return $task['id'];
}
/**
+ * Try to automatically determine the primary IP address of the server.
+ * This only works if the server has either one public IPv4 address (and potentially
+ * one or more non-public addresses), or one private address.
+ */
+ public static function autoUpdateServerIp()
+ {
+ $task = Taskmanager::submit('LocalAddressesList');
+ if ($task === false)
+ return;
+ $task = Taskmanager::waitComplete($task, 10000);
+ if (!isset($task['data']['addresses']) || empty($task['data']['addresses']))
+ return;
+
+ $serverIp = Property::getServerIp();
+ $publicCandidate = 'none';
+ $privateCandidate = 'none';
+ foreach ($task['data']['addresses'] as $addr) {
+ if ($addr['ip'] === $serverIp)
+ return;
+ if (substr($addr['ip'], 0, 4) === '127.')
+ continue;
+ if (Util::isPublicIpv4($addr['ip'])) {
+ if ($publicCandidate === 'none')
+ $publicCandidate = $addr['ip'];
+ else
+ $publicCandidate = 'many';
+ } else {
+ if ($privateCandidate === 'none')
+ $privateCandidate = $addr['ip'];
+ else
+ $privateCandidate = 'many';
+ }
+ }
+ if ($publicCandidate !== 'none' && $publicCandidate !== 'many') {
+ Property::setServerIp($publicCandidate);
+ return;
+ }
+ if ($privateCandidate !== 'none' && $privateCandidate !== 'many') {
+ Property::setServerIp($privateCandidate);
+ return;
+ }
+ }
+
+ /**
*
* @return boolean|string false on error, id of task otherwise
*/