diff options
Diffstat (limited to 'modules-available/minilinux/inc/linuxbootentryhook.inc.php')
-rw-r--r-- | modules-available/minilinux/inc/linuxbootentryhook.inc.php | 64 |
1 files changed, 37 insertions, 27 deletions
diff --git a/modules-available/minilinux/inc/linuxbootentryhook.inc.php b/modules-available/minilinux/inc/linuxbootentryhook.inc.php index e3090054..1424b6b9 100644 --- a/modules-available/minilinux/inc/linuxbootentryhook.inc.php +++ b/modules-available/minilinux/inc/linuxbootentryhook.inc.php @@ -10,29 +10,31 @@ class LinuxBootEntryHook extends BootEntryHook { - public function name() + public function name(): string { - return Dictionary::translateFileModule('minilinux', 'module', 'module_name', true); + return Dictionary::translateFileModule('minilinux', 'module', 'module_name'); } - public function extraFields() + public function extraFields(): array { /* For translate module: * Dictionary::translate('ipxe-kcl-extra'); * Dictionary::translate('ipxe-debug'); * Dictionary::translate('ipxe-insecure-cpu'); + * Dictionary::translate('ipxe-force-init-dhcp'); */ return [ new HookExtraField('kcl-extra', 'string', ''), new HookExtraField('debug', 'bool', false), new HookExtraField('insecure-cpu', 'bool', false), + new HookExtraField('force-init-dhcp', 'bool', false), ]; } /** * @return HookEntryGroup[] */ - protected function groupsInternal() + protected function groupsInternal(): array { /* * Dictionary::translate('default_boot_entry'); @@ -42,7 +44,7 @@ class LinuxBootEntryHook extends BootEntryHook $array = []; $array[] = new HookEntryGroup($this->name(), [ new HookEntry('default', - Dictionary::translateFileModule('minilinux', 'module', 'default_boot_entry', true), + Dictionary::translateFileModule('minilinux', 'module', 'default_boot_entry'), MiniLinux::updateCurrentBootSetting()) ]); $branches = Database::queryAll('SELECT sourceid, branchid, title FROM minilinux_branch ORDER BY title'); @@ -54,29 +56,28 @@ class LinuxBootEntryHook extends BootEntryHook new HookEntry($branch['branchid'], $branch['branchid'] . ' ' . Dictionary::translateFileModule('minilinux', 'module', - 'latest_of_branch', true), + 'latest_of_branch'), true), ]; foreach ($versions[$branch['branchid']] as $version) { - $valid = $version['installed'] != 0; + $valid = $version['installed'] != MiniLinux::INSTALL_MISSING; $title = $version['versionid'] . ' ' . $version['title']; if (!$valid) { $title .= ' ' . Dictionary::translateFileModule('minilinux', 'module', - 'not_installed_hint', true); + 'not_installed_hint'); } $group[] = new HookEntry($version['versionid'], $title, $valid); } - $array[] = new HookEntryGroup($branch['title'] ? $branch['title'] : $branch['branchid'], $group); + $array[] = new HookEntryGroup($branch['title'] ?: $branch['branchid'], $group); } } return $array; } /** - * @param $localData - * @return BootEntry the actual boot entry instance for given entry, false if invalid id + * @return ?BootEntry the actual boot entry instance for given entry, false if invalid id */ - public function getBootEntryInternal($localData) + public function getBootEntryInternal(array $localData): ?BootEntry { $id = $localData['id']; if ($id === 'default') { // Special case @@ -88,14 +89,12 @@ class LinuxBootEntryHook extends BootEntryHook ['id' => $effectiveId]); if ($res === false) { // Maybe this is a branchid, which means latest from according branch (installed only) - $res = Database::queryFirst('SELECT versionid, installed, data FROM minilinux_version WHERE branchid = :id - ORDER BY installed DESC, dateline DESC LIMIT 1', // Order by installed instead of WHERE for better errormsg - ['id' => $effectiveId]); + $res = Database::queryFirst('SELECT versionid, installed, data FROM minilinux_version + WHERE branchid = :id AND installed = :ok + ORDER BY dateline DESC LIMIT 1', + ['id' => $effectiveId, 'ok' => MiniLinux::INSTALL_OK]); } if ($res === false) { - return BootEntry::newCustomBootEntry(['script' => 'prompt Invalid minilinux boot entry id: ' . $id]); - } - if ($res['installed'] == 0) { return BootEntry::newCustomBootEntry(['script' => 'prompt Selected version not currently installed on server: ' . $effectiveId]); } $effectiveId = $res['versionid']; // In case we selected from a branchid, so above message doesn't show versionid @@ -122,10 +121,10 @@ class LinuxBootEntryHook extends BootEntryHook $arch = BootEntry::EFI; } } - return BootEntry::newStandardBootEntry($bios, $efi, $arch); + return BootEntry::newStandardBootEntry($bios, $efi, $arch, 'ml-' . $id); } - private function generateExecData($effectiveId, $remoteData, $localData) + private function generateExecData($effectiveId, $remoteData, $localData): ExecData { $exec = new ExecData(); // Defaults @@ -146,23 +145,34 @@ class LinuxBootEntryHook extends BootEntryHook if (!empty($localData['debug'])) { // Debug boot enabled $exec->commandLine = IPxe::modifyCommandLine($exec->commandLine, - isset($remoteData['debugCommandLineModifier']) - ? $remoteData['debugCommandLineModifier'] - : '-vga -quiet -splash -loglevel loglevel=7' + $remoteData['debugCommandLineModifier'] ?? '-vga -quiet -splash -loglevel loglevel=7' ); } // disable all CPU sidechannel attack mitigations etc. if (!empty($localData['insecure-cpu'])) { $exec->commandLine = IPxe::modifyCommandLine($exec->commandLine, - 'noibrs noibpb nopti nospectre_v2 nospectre_v1 l1tf=off nospec_store_bypass_disable no_stf_barrier mds=off mitigations=off'); + 'noibrs noibpb nopti nospectre_v2 nospectre_v1 l1tf=off nospec_store_bypass_disable no_stf_barrier mds=off mitigations=off i915.mitigations=off'); + } + // force that we + if (!empty($localData['force-init-dhcp'])) { + $exec->commandLine = IPxe::modifyCommandLine($exec->commandLine, + '-ipv4.router -ipv4.dns -ipv4.subnet'); + } + // GVT, PCI Pass-thru etc. + if (Module::isAvailable('statistics')) { + $hwextra = HardwareInfo::getKclModifications(); + if (!empty($hwextra)) { + $exec->commandLine = IPxe::modifyCommandLine($exec->commandLine, $hwextra); + } } + // User-supplied modifications if (!empty($localData['kcl-extra'])) { $exec->commandLine = IPxe::modifyCommandLine($exec->commandLine, $localData['kcl-extra']); } $exec->commandLine = str_replace('%ID%', $effectiveId, $exec->commandLine); $exec->executable = $root . $exec->executable; foreach ($exec->initRd as &$rd) { - if ($rd{0} !== '/') { + if ($rd[0] !== '/') { $rd = $root . $rd; } } @@ -170,12 +180,12 @@ class LinuxBootEntryHook extends BootEntryHook return $exec; } - public function isValidId($id) + public function isValidId(string $id): bool { if ($id === 'default') return true; // Meta-version that links to whatever the default is set to $res = Database::queryFirst('SELECT installed FROM minilinux_version WHERE versionid = :id', ['id' => $id]); - if ($res !== false && $res['installed']) + if ($res !== false && $res['installed'] != MiniLinux::INSTALL_MISSING) return true; $res = Database::queryFirst('SELECT branchid FROM minilinux_branch WHERE branchid = :id', ['id' => $id]); return $res !== false; |