PXE Profile Generator

This commit is contained in:
Alicia Sykes committed 2025-10-19 23:24:07 +01:00
1 parent 5e953e2dbf
commit 1277349157
6 files changed
+1659

No files matched your search

@@ -0,0 +1,714 @@
<script lang="ts">
import { untrack } from 'svelte';
import Icon from '$lib/components/global/Icon.svelte';
import ToolContentContainer from '$lib/components/global/ToolContentContainer.svelte';
import ExamplesCard from '$lib/components/common/ExamplesCard.svelte';
import { useClipboard } from '$lib/composables';
import {
type PXEProfile,
type PXEResult,
generatePXEProfile,
getDefaultPXEProfile,
validatePXEProfile,
validateNetworkSettings,
PXE_PRESETS,
} from '$lib/utils/dhcp-pxe-profile';
let profile = $state<PXEProfile>({
...getDefaultPXEProfile(),
network: {
subnet: '',
netmask: '',
rangeStart: '',
rangeEnd: '',
gateway: '',
dns: '',
},
});
let result = $state<PXEResult | null>(null);
let validationErrors = $state<string[]>([]);
let networkValidationErrors = $state<string[]>([]);
let selectedExampleIndex = $state<number | null>(null);
const clipboard = useClipboard();
interface PresetExample {
label: string;
profile: PXEProfile;
description: string;
}
const presetExamples: PresetExample[] = PXE_PRESETS.map((preset) => ({
label: preset.name,
profile: preset,
description: `${preset.architecture === 'auto' ? 'Auto-detect UEFI/BIOS' : preset.architecture.toUpperCase()} - ${preset.tftpServer}`,
}));
const architectureOptions = [
{ value: 'auto', label: 'Auto-detect' },
{ value: 'bios', label: 'BIOS only' },
{ value: 'uefi-x64', label: 'UEFI x64' },
{ value: 'uefi-x86', label: 'UEFI x86' },
{ value: 'uefi-arm64', label: 'UEFI ARM64' },
{ value: 'uefi-arm32', label: 'UEFI ARM32' },
];
function validateAndGenerate(currentProfile: PXEProfile): void {
validationErrors = validatePXEProfile(currentProfile);
networkValidationErrors = validateNetworkSettings(currentProfile.network);
if (validationErrors.length === 0 && networkValidationErrors.length === 0) {
try {
result = generatePXEProfile(currentProfile);
} catch (e) {
validationErrors = [e instanceof Error ? e.message : String(e)];
result = null;
}
} else {
result = null;
}
}
function loadPresetExample(example: PresetExample, index: number): void {
profile = {
...example.profile,
network: profile.network,
};
selectedExampleIndex = index;
}
function checkIfExampleStillMatches(): void {
if (selectedExampleIndex === null) return;
const example = presetExamples[selectedExampleIndex];
if (!example) {
selectedExampleIndex = null;
return;
}
const matches =
profile.name === example.profile.name &&
profile.architecture === example.profile.architecture &&
profile.tftpServer === example.profile.tftpServer &&
profile.biosBootfile === example.profile.biosBootfile &&
profile.uefiX64Bootfile === example.profile.uefiX64Bootfile &&
profile.uefiX86Bootfile === example.profile.uefiX86Bootfile &&
profile.uefiArm64Bootfile === example.profile.uefiArm64Bootfile &&
profile.uefiArm32Bootfile === example.profile.uefiArm32Bootfile;
if (!matches) {
selectedExampleIndex = null;
}
}
$effect(() => {
const currentProfile = {
...profile,
network: profile.network ? { ...profile.network } : undefined,
};
untrack(() => {
validateAndGenerate(currentProfile);
checkIfExampleStillMatches();
});
});
</script>
<ToolContentContainer
title="PXE Profile Generator"
description="Generate PXE boot profiles with automatic UEFI/BIOS detection using DHCP Options 93/94. Configure bootfiles for different architectures and generate dhcpd/Kea configuration snippets."
>
<ExamplesCard
examples={presetExamples}
onSelect={loadPresetExample}
getLabel={(ex) => ex.label}
getDescription={(ex) => ex.description}
selectedIndex={selectedExampleIndex}
/>
<div class="card input-card">
<div class="card-header">
<h3>Profile Configuration</h3>
</div>
<div class="card-content">
<div class="input-group">
<label for="profile-name">
<Icon name="tag" size="sm" />
Profile Name
<span class="required">*</span>
</label>
<input id="profile-name" type="text" bind:value={profile.name} placeholder="e.g., Production PXE" />
</div>
<div class="input-group">
<label for="tftp-server">
<Icon name="server" size="sm" />
TFTP Server (Option 66)
<span class="required">*</span>
</label>
<input
id="tftp-server"
type="text"
bind:value={profile.tftpServer}
placeholder="e.g., pxe.example.com or 192.168.1.10"
/>
<span class="help-text">Hostname or IP address of the TFTP server</span>
</div>
<div class="input-group">
<label for="architecture">
<Icon name="cpu" size="sm" />
Architecture Mode
</label>
<select id="architecture" bind:value={profile.architecture}>
{#each architectureOptions as option (option.value)}
<option value={option.value}>{option.label}</option>
{/each}
</select>
<span class="help-text">
Auto-detect uses Option 93 to serve different bootfiles based on client firmware
</span>
</div>
</div>
</div>
<div class="card input-card">
<div class="card-header">
<h3>Bootfiles (Option 67)</h3>
<p class="help-text">
Configure bootfile names for different client architectures. At least one bootfile is required.
</p>
</div>
<div class="card-content">
{#if profile.architecture === 'bios' || profile.architecture === 'auto'}
<div class="input-group">
<label for="bios-bootfile">
<Icon name="hard-drive" size="sm" />
BIOS Bootfile
{#if profile.architecture === 'bios' || profile.architecture === 'auto'}
<span class="recommended">(recommended)</span>
{/if}
</label>
<input
id="bios-bootfile"
type="text"
bind:value={profile.biosBootfile}
placeholder="e.g., pxelinux.0 or undionly.kpxe"
/>
<span class="help-text">For legacy BIOS systems (Arch Type 0x0000)</span>
</div>
{/if}
{#if profile.architecture === 'uefi-x64' || profile.architecture === 'auto'}
<div class="input-group">
<label for="uefi-x64-bootfile">
<Icon name="hard-drive" size="sm" />
UEFI x64 Bootfile
{#if profile.architecture === 'uefi-x64' || profile.architecture === 'auto'}
<span class="recommended">(recommended)</span>
{/if}
</label>
<input
id="uefi-x64-bootfile"
type="text"
bind:value={profile.uefiX64Bootfile}
placeholder="e.g., bootx64.efi or ipxe-x64.efi"
/>
<span class="help-text">For UEFI x86-64 systems (Arch Type 0x0007)</span>
</div>
{/if}
{#if profile.architecture === 'uefi-x86' || profile.architecture === 'auto'}
<div class="input-group">
<label for="uefi-x86-bootfile">
<Icon name="hard-drive" size="sm" />
UEFI x86 Bootfile
</label>
<input
id="uefi-x86-bootfile"
type="text"
bind:value={profile.uefiX86Bootfile}
placeholder="e.g., bootia32.efi"
/>
<span class="help-text">For UEFI IA32 systems (Arch Type 0x0006)</span>
</div>
{/if}
{#if profile.architecture === 'uefi-arm64' || profile.architecture === 'auto'}
<div class="input-group">
<label for="uefi-arm64-bootfile">
<Icon name="hard-drive" size="sm" />
UEFI ARM64 Bootfile
</label>
<input
id="uefi-arm64-bootfile"
type="text"
bind:value={profile.uefiArm64Bootfile}
placeholder="e.g., bootaa64.efi"
/>
<span class="help-text">For UEFI ARM 64-bit systems (Arch Type 0x000b)</span>
</div>
{/if}
{#if profile.architecture === 'uefi-arm32' || profile.architecture === 'auto'}
<div class="input-group">
<label for="uefi-arm32-bootfile">
<Icon name="hard-drive" size="sm" />
UEFI ARM32 Bootfile
</label>
<input
id="uefi-arm32-bootfile"
type="text"
bind:value={profile.uefiArm32Bootfile}
placeholder="e.g., bootarm.efi"
/>
<span class="help-text">For UEFI ARM 32-bit systems (Arch Type 0x000a)</span>
</div>
{/if}
</div>
</div>
{#if validationErrors.length > 0}
<div class="card errors-card">
<h3>Validation Errors</h3>
{#each validationErrors as error, i (i)}
<div class="error-message">
<Icon name="alert-triangle" size="sm" />
{error}
</div>
{/each}
</div>
{/if}
{#if result}
<hr />
<div class="card input-card">
<div class="card-header">
<h3>Network Settings (Optional)</h3>
<p class="help-text">Customize network values for configuration examples below</p>
</div>
<div class="card-content">
<div class="input-row">
<div class="input-group">
<label for="subnet">
<Icon name="network" size="sm" />
Subnet
</label>
<input id="subnet" type="text" bind:value={profile.network!.subnet} placeholder="192.168.1.0" />
</div>
<div class="input-group">
<label for="netmask">
<Icon name="network" size="sm" />
Netmask
</label>
<input id="netmask" type="text" bind:value={profile.network!.netmask} placeholder="255.255.255.0" />
</div>
</div>
<div class="input-row">
<div class="input-group">
<label for="range-start">
<Icon name="arrow-right" size="sm" />
Range Start
</label>
<input id="range-start" type="text" bind:value={profile.network!.rangeStart} placeholder="192.168.1.100" />
</div>
<div class="input-group">
<label for="range-end">
<Icon name="arrow-right" size="sm" />
Range End
</label>
<input id="range-end" type="text" bind:value={profile.network!.rangeEnd} placeholder="192.168.1.200" />
</div>
</div>
<div class="input-row">
<div class="input-group">
<label for="gateway">
<Icon name="arrow-right" size="sm" />
Gateway
</label>
<input id="gateway" type="text" bind:value={profile.network!.gateway} placeholder="192.168.1.1" />
</div>
<div class="input-group">
<label for="dns">
<Icon name="globe" size="sm" />
DNS Server
</label>
<input id="dns" type="text" bind:value={profile.network!.dns} placeholder="8.8.8.8" />
</div>
</div>
</div>
{#if networkValidationErrors.length > 0}
<div class="network-errors">
<h4>Network Settings Errors</h4>
{#each networkValidationErrors as error, i (i)}
<div class="network-error-item">
<Icon name="alert-triangle" size="sm" />
{error}
</div>
{/each}
</div>
{/if}
</div>
{/if}
{#if result && networkValidationErrors.length === 0}
<div class="card results">
<h3>Profile Summary</h3>
<div class="summary-card">
<div><strong>Profile Name:</strong> {result.profile.name}</div>
<div><strong>Architecture Mode:</strong> {result.profile.architecture}</div>
<div><strong>TFTP Server:</strong> {result.profile.tftpServer}</div>
{#if result.profile.biosBootfile}
<div><strong>BIOS Bootfile:</strong> {result.profile.biosBootfile}</div>
{/if}
{#if result.profile.uefiX64Bootfile}
<div><strong>UEFI x64 Bootfile:</strong> {result.profile.uefiX64Bootfile}</div>
{/if}
{#if result.profile.uefiX86Bootfile}
<div><strong>UEFI x86 Bootfile:</strong> {result.profile.uefiX86Bootfile}</div>
{/if}
{#if result.profile.uefiArm64Bootfile}
<div><strong>UEFI ARM64 Bootfile:</strong> {result.profile.uefiArm64Bootfile}</div>
{/if}
{#if result.profile.uefiArm32Bootfile}
<div><strong>UEFI ARM32 Bootfile:</strong> {result.profile.uefiArm32Bootfile}</div>
{/if}
</div>
</div>
<div class="card results">
<h3>DHCP Server Configuration</h3>
{#if result.examples.iscDhcpd}
<div class="output-group">
<div class="output-header">
<h4>ISC dhcpd Configuration</h4>
<button
type="button"
class="copy-btn"
class:copied={clipboard.isCopied('isc')}
onclick={() => clipboard.copy(result!.examples.iscDhcpd!, 'isc')}
>
<Icon name={clipboard.isCopied('isc') ? 'check' : 'copy'} size="xs" />
{clipboard.isCopied('isc') ? 'Copied' : 'Copy'}
</button>
</div>
<pre class="output-value code-block">{result.examples.iscDhcpd}</pre>
</div>
{/if}
{#if result.examples.keaDhcp4}
<div class="output-group">
<div class="output-header">
<h4>Kea DHCPv4 Configuration</h4>
<button
type="button"
class="copy-btn"
class:copied={clipboard.isCopied('kea')}
onclick={() => clipboard.copy(result!.examples.keaDhcp4!, 'kea')}
>
<Icon name={clipboard.isCopied('kea') ? 'check' : 'copy'} size="xs" />
{clipboard.isCopied('kea') ? 'Copied' : 'Copy'}
</button>
</div>
<pre class="output-value code-block">{result.examples.keaDhcp4}</pre>
</div>
{/if}
</div>
<div class="card results">
<h3>PXE Boot Architecture Detection</h3>
<p>
DHCP Option 93 (Client System Architecture Type) allows the DHCP server to detect the client's firmware type and
serve the appropriate bootfile. Common architecture types:
</p>
<ul>
<li><strong>0x0000</strong> - Intel x86PC (Legacy BIOS)</li>
<li><strong>0x0006</strong> - EFI IA32 (32-bit UEFI)</li>
<li><strong>0x0007</strong> - EFI BC (64-bit UEFI, most common)</li>
<li><strong>0x000a</strong> - EFI ARM 32-bit</li>
<li><strong>0x000b</strong> - EFI ARM 64-bit</li>
</ul>
<p>
When using auto-detect mode, the DHCP server will examine Option 93 in the client's DHCPDISCOVER message and
respond with the appropriate bootfile for that architecture.
</p>
</div>
{/if}
</ToolContentContainer>
<style lang="scss">
.card {
background: var(--bg-secondary);
border-radius: var(--radius-lg);
padding: var(--spacing-lg);
border: 1px solid var(--border-primary);
margin-bottom: var(--spacing-lg);
&.input-card {
background: var(--bg-tertiary);
.card-header {
margin-bottom: var(--spacing-sm);
}
}
h3 {
display: flex;
align-items: center;
gap: var(--spacing-sm);
margin: 0 0 var(--spacing-sm);
font-size: 1.25rem;
color: var(--text-primary);
}
}
.card-header {
.help-text {
margin: var(--spacing-xs) 0 0;
font-size: 0.875rem;
color: var(--text-secondary);
font-style: italic;
}
}
.card-content {
display: flex;
flex-direction: column;
gap: var(--spacing-md);
}
.input-group {
display: flex;
flex-direction: column;
gap: var(--spacing-xs);
label {
display: flex;
align-items: center;
gap: var(--spacing-xs);
font-weight: 500;
font-size: 0.875rem;
color: var(--text-primary);
}
input,
select {
padding: var(--spacing-sm);
background: var(--bg-primary);
border: 1px solid var(--border-primary);
border-radius: var(--radius-md);
color: var(--text-primary);
font-family: inherit;
font-size: 0.9375rem;
transition: all 0.2s ease;
&:focus {
outline: none;
border-color: var(--color-primary);
box-shadow: 0 0 0 3px color-mix(in srgb, var(--color-primary), transparent 90%);
}
}
select {
cursor: pointer;
}
}
.input-row {
display: grid;
grid-template-columns: 1fr 1fr;
gap: var(--spacing-md);
@media (max-width: 768px) {
grid-template-columns: 1fr;
}
}
.required {
color: var(--color-error);
}
.recommended {
color: var(--color-success);
font-weight: var(--font-weight-normal);
font-size: 0.75rem;
}
.help-text {
font-size: 0.75rem;
color: var(--text-tertiary);
font-style: italic;
}
.errors-card {
background: color-mix(in srgb, var(--color-error), transparent 95%);
border-color: var(--color-error);
}
.error-message {
display: flex;
align-items: center;
gap: var(--spacing-sm);
padding: var(--spacing-sm);
color: var(--color-error);
font-size: 0.9375rem;
}
.results {
background: var(--bg-tertiary);
animation: slideIn 0.3s ease-out;
p {
color: var(--text-secondary);
line-height: 1.6;
margin: var(--spacing-sm) 0;
}
ul {
margin: var(--spacing-md) 0;
padding-left: var(--spacing-xl);
color: var(--text-secondary);
line-height: 1.8;
li {
margin: var(--spacing-xs) 0;
strong {
font-family: var(--font-mono);
color: var(--text-primary);
}
}
}
}
@keyframes slideIn {
from {
opacity: 0;
transform: translateY(-10px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
.output-group {
display: flex;
flex-direction: column;
gap: var(--spacing-xs);
margin-bottom: var(--spacing-lg);
&:last-child {
margin-bottom: 0;
}
}
.output-header {
display: flex;
align-items: center;
justify-content: space-between;
h4 {
margin: 0;
font-size: 1rem;
font-weight: 600;
color: var(--text-primary);
}
}
.copy-btn {
display: flex;
align-items: center;
gap: var(--spacing-xs);
padding: var(--spacing-xs) var(--spacing-sm);
background: transparent;
border: 1px solid var(--border-secondary);
border-radius: var(--radius-sm);
color: var(--text-secondary);
font-size: 0.875rem;
cursor: pointer;
transition: all 0.2s ease;
&:hover {
background: var(--surface-hover);
border-color: var(--color-primary);
color: var(--color-primary);
}
&.copied {
background: color-mix(in srgb, var(--color-success), transparent 90%);
border-color: var(--color-success);
color: var(--color-success);
}
}
.output-value {
padding: var(--spacing-md);
background: var(--bg-primary);
border: 1px solid var(--border-primary);
border-radius: var(--radius-md);
font-family: var(--font-mono);
font-size: 0.875rem;
color: var(--color-primary);
overflow-x: auto;
}
.code-block {
white-space: pre;
word-break: normal;
}
.summary-card {
display: flex;
gap: var(--spacing-lg);
flex-wrap: wrap;
padding: var(--spacing-md);
background: color-mix(in srgb, var(--color-info), transparent 95%);
border: 1px solid var(--color-info);
border-radius: var(--radius-md);
margin-bottom: var(--spacing-lg);
font-size: 0.9375rem;
div {
strong {
color: var(--text-primary);
}
}
@media (max-width: 768px) {
flex-direction: column;
gap: var(--spacing-xs);
}
}
.network-errors {
margin-top: var(--spacing-md);
padding: var(--spacing-md);
background: color-mix(in srgb, var(--color-error), transparent 95%);
border: 1px solid var(--color-error);
border-radius: var(--radius-md);
h4 {
margin: 0 0 var(--spacing-sm);
font-size: 0.875rem;
font-weight: 600;
color: var(--color-error);
}
}
.network-error-item {
display: flex;
align-items: center;
gap: var(--spacing-xs);
padding: var(--spacing-xs) 0;
color: var(--color-error);
font-size: 0.875rem;
}
</style>
+2
View File
@@ -311,6 +311,8 @@ export const iconMap: Record<string, string> = {
tools: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 640"><!--!Font Awesome Pro v7.1.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license (Commercial License) Copyright 2025 Fonticons, Inc.--><path opacity=".4" d="M105.4 489.4C92.9 501.9 92.9 522.2 105.4 534.7C117.9 547.2 138.2 547.2 150.7 534.7L253.8 431.4C244.4 405.6 243 377.7 249.4 351.2C248.4 350.2 247.4 349.2 246.4 348.2L105.4 489.4zM109.8 118.1L169.7 208L208 208L208 169.7L118.1 109.8L109.8 118.1zM304 172.1C304 182.1 304 192.2 304 202.2L351.2 249.4C356.7 248.1 362.3 247.1 368 246.4L368 184C368 177.6 370.5 171.5 375 167L428.3 113.7C421.7 112.6 414.9 112 408 112C363.5 112 324.7 136.2 304 172.1zM353.9 353.9C337.3 370.5 337.3 397.4 353.9 414L480 540.1L540.1 480L414.1 353.9C397.5 337.3 370.6 337.3 354 353.9zM463.7 270.7C470.1 275.2 476.2 280.3 481.9 286C488.7 292.8 495.4 299.5 502.2 306.3C518.3 285.9 528 260 528 232C528 225.1 527.4 218.3 526.3 211.7L473 265C470.4 267.6 467.2 269.6 463.8 270.7z"/><path d="M102.7 57.3C108.1 51.9 116.5 51.1 122.9 55.3L241.7 134.5C250.6 140.4 255.9 150.4 255.9 161.1L255.9 222L339.1 305.2C373.6 285.5 418.4 290.4 447.9 319.9L574.1 446.1C592.8 464.8 592.8 495.2 574.1 514L514 574.1C495.3 592.8 464.9 592.8 446.1 574.1L320 448C290.5 418.5 285.6 373.8 305.3 339.2L222.1 256L161.2 256C150.5 256 140.5 250.7 134.6 241.8L55.3 122.9C51.1 116.6 51.9 108.1 57.3 102.7L102.7 57.3zM208 208L208 169.7L118.1 109.8L109.8 118.1L169.7 208L208 208zM480 540.1L540.1 480L414.1 353.9C397.5 337.3 370.6 337.3 354 353.9C337.4 370.5 337.4 397.4 354 414L480 540.1zM71.4 455.4L212.5 314.3L246.4 348.2L105.3 489.3L105.3 489.3C92.8 501.8 92.8 522.1 105.3 534.6C117.8 547.1 138.1 547.1 150.6 534.6L253.8 431.4C259.4 446.7 267.7 461.2 278.9 474.2L184.6 568.5C153.4 599.7 102.7 599.7 71.5 568.5C40.3 537.3 40.3 486.6 71.5 455.4zM304 161.1C304 143.9 298.5 127.4 288.5 113.8C319 83 361.2 63.9 408 63.9C435.1 63.9 460.8 70.3 483.5 81.8C490.4 85.3 495.2 91.8 496.4 99.4C497.6 107 495.1 114.7 489.7 120.2L416 193.9L416 224L446.1 224L519.8 150.3C525.2 144.9 533 142.4 540.6 143.6C548.2 144.8 554.8 149.6 558.2 156.5C569.6 179.2 576.1 204.9 576.1 232C576.1 273.3 561.2 311.2 536.4 340.4L502.3 306.3C518.4 285.9 528.1 260 528.1 232C528.1 225.1 527.5 218.3 526.4 211.7L473 265C470.4 267.6 467.2 269.6 463.8 270.7C435.4 250.7 401.2 242.6 368.1 246.4L368.1 184C368.1 177.6 370.6 171.5 375.1 167L428.4 113.7C421.8 112.6 415 112 408.1 112C363.6 112 324.8 136.2 304.1 172.1L304.1 161.1z"/></svg>`,
'code-file': `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 640"><!--!Font Awesome Pro v7.1.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license (Commercial License) Copyright 2025 Fonticons, Inc.--><path opacity=".4" d="M176 128L176 512C176 520.8 183.2 528 192 528L448 528C456.8 528 464 520.8 464 512L464 272L376 272C336.2 272 304 239.8 304 200L304 112L192 112C183.2 112 176 119.2 176 128zM213.8 384.4L261.8 328.4C270.4 318.3 285.6 317.2 295.6 325.8C305.6 334.4 306.8 349.6 298.2 359.6L263.6 400L298.2 440.4C306.8 450.5 305.7 465.6 295.6 474.2C285.5 482.8 270.4 481.7 261.8 471.6L213.8 415.6C206.1 406.6 206.1 393.4 213.8 384.4zM341.8 359.6C333.2 349.5 334.3 334.4 344.4 325.8C354.5 317.2 369.6 318.3 378.2 328.4L426.2 384.4C433.9 393.4 433.9 406.6 426.2 415.6L378.2 471.6C369.6 481.7 354.4 482.8 344.4 474.2C334.4 465.6 333.2 450.4 341.8 440.4L376.4 400L341.8 359.6z"/><path d="M192 112L304 112L304 200C304 239.8 336.2 272 376 272L464 272L464 512C464 520.8 456.8 528 448 528L192 528C183.2 528 176 520.8 176 512L176 128C176 119.2 183.2 112 192 112zM352 131.9L444.1 224L376 224C362.7 224 352 213.3 352 200L352 131.9zM192 64C156.7 64 128 92.7 128 128L128 512C128 547.3 156.7 576 192 576L448 576C483.3 576 512 547.3 512 512L512 250.5C512 233.5 505.3 217.2 493.3 205.2L370.7 82.7C358.7 70.7 342.5 64 325.5 64L192 64zM298.2 359.6C306.8 349.5 305.7 334.4 295.6 325.8C285.5 317.2 270.4 318.3 261.8 328.4L213.8 384.4C206.1 393.4 206.1 406.6 213.8 415.6L261.8 471.6C270.4 481.7 285.6 482.8 295.6 474.2C305.6 465.6 306.8 450.4 298.2 440.4L263.6 400L298.2 359.6zM378.2 328.4C369.6 318.3 354.4 317.2 344.4 325.8C334.4 334.4 333.2 349.6 341.8 359.6L376.4 400L341.8 440.4C333.2 450.5 334.3 465.6 344.4 474.2C354.5 482.8 369.6 481.7 378.2 471.6L426.2 415.6C433.9 406.6 433.9 393.4 426.2 384.4L378.2 328.4z"/></svg>`,
compass: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 640"><!--!Font Awesome Pro v7.1.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license (Commercial License) Copyright 2025 Fonticons, Inc.--><path opacity=".4" d="M112 320C112 434.9 205.1 528 320 528C434.9 528 528 434.9 528 320C528 205.1 434.9 112 320 112C205.1 112 112 205.1 112 320zM195.4 413.6L250.9 269.3C254.2 260.8 260.8 254.2 269.3 250.9L413.6 195.4C433 187.9 452.1 207 444.6 226.4L389.1 370.7C385.8 379.2 379.2 385.8 370.7 389.1L226.4 444.6C207 452.1 187.9 433 195.4 413.6z"/><path d="M528 320C528 205.1 434.9 112 320 112C205.1 112 112 205.1 112 320C112 434.9 205.1 528 320 528C434.9 528 528 434.9 528 320zM64 320C64 178.6 178.6 64 320 64C461.4 64 576 178.6 576 320C576 461.4 461.4 576 320 576C178.6 576 64 461.4 64 320zM370.7 389.1L226.4 444.6C207 452.1 187.9 433 195.4 413.6L250.9 269.3C254.2 260.8 260.8 254.2 269.3 250.9L413.6 195.4C433 187.9 452.1 207 444.6 226.4L389.1 370.7C385.8 379.2 379.2 385.8 370.7 389.1zM352 320C352 302.3 337.7 288 320 288C302.3 288 288 302.3 288 320C288 337.7 302.3 352 320 352C337.7 352 352 337.7 352 320z"/></svg>`,
'hard-drive': `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 640"><!--!Font Awesome Pro v7.1.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license (Commercial License) Copyright 2025 Fonticons, Inc.--><path opacity=".4" d="M144 160L144 322C149.1 320.7 154.5 320 160 320L480 320C485.5 320 490.9 320.7 496 322L496 160C496 151.2 488.8 144 480 144L160 144C151.2 144 144 151.2 144 160zM144 384L144 480C144 488.8 151.2 496 160 496L480 496C488.8 496 496 488.8 496 480L496 384C496 375.2 488.8 368 480 368L160 368C151.2 368 144 375.2 144 384zM360 432C360 445.3 349.3 456 336 456C322.7 456 312 445.3 312 432C312 418.7 322.7 408 336 408C349.3 408 360 418.7 360 432zM456 432C456 445.3 445.3 456 432 456C418.7 456 408 445.3 408 432C408 418.7 418.7 408 432 408C445.3 408 456 418.7 456 432z"/><path d="M160 144C151.2 144 144 151.2 144 160L144 322C149.1 320.7 154.5 320 160 320L480 320C485.5 320 490.9 320.7 496 322L496 160C496 151.2 488.8 144 480 144L160 144zM144 384L144 480C144 488.8 151.2 496 160 496L480 496C488.8 496 496 488.8 496 480L496 384C496 375.2 488.8 368 480 368L160 368C151.2 368 144 375.2 144 384zM96 384L96 160C96 124.7 124.7 96 160 96L480 96C515.3 96 544 124.7 544 160L544 480C544 515.3 515.3 544 480 544L160 544C124.7 544 96 515.3 96 480L96 384zM312 432C312 418.7 322.7 408 336 408C349.3 408 360 418.7 360 432C360 445.3 349.3 456 336 456C322.7 456 312 445.3 312 432zM432 408C445.3 408 456 418.7 456 432C456 445.3 445.3 456 432 456C418.7 456 408 445.3 408 432C408 418.7 418.7 408 432 408z"/></svg>`,
cpu: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 640"><!--!Font Awesome Pro v7.1.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license (Commercial License) Copyright 2025 Fonticons, Inc.--><path opacity=".4" d="M272 272L368 272L368 368L272 368L272 272z"/><path d="M240 88C240 74.7 229.3 64 216 64C202.7 64 192 74.7 192 88L192 128C156.7 128 128 156.7 128 192L88 192C74.7 192 64 202.7 64 216C64 229.3 74.7 240 88 240L128 240L128 296L88 296C74.7 296 64 306.7 64 320C64 333.3 74.7 344 88 344L128 344L128 400L88 400C74.7 400 64 410.7 64 424C64 437.3 74.7 448 88 448L128 448C128 483.3 156.7 512 192 512L192 552C192 565.3 202.7 576 216 576C229.3 576 240 565.3 240 552L240 512L296 512L296 552C296 565.3 306.7 576 320 576C333.3 576 344 565.3 344 552L344 512L400 512L400 552C400 565.3 410.7 576 424 576C437.3 576 448 565.3 448 552L448 512C483.3 512 512 483.3 512 448L552 448C565.3 448 576 437.3 576 424C576 410.7 565.3 400 552 400L512 400L512 344L552 344C565.3 344 576 333.3 576 320C576 306.7 565.3 296 552 296L512 296L512 240L552 240C565.3 240 576 229.3 576 216C576 202.7 565.3 192 552 192L512 192C512 156.7 483.3 128 448 128L448 88C448 74.7 437.3 64 424 64C410.7 64 400 74.7 400 88L400 128L344 128L344 88C344 74.7 333.3 64 320 64C306.7 64 296 74.7 296 88L296 128L240 128L240 88zM464 192L464 448C464 456.8 456.8 464 448 464L192 464C183.2 464 176 456.8 176 448L176 192C176 183.2 183.2 176 192 176L448 176C456.8 176 464 183.2 464 192zM256 224C238.3 224 224 238.3 224 256L224 384C224 401.7 238.3 416 256 416L384 416C401.7 416 416 401.7 416 384L416 256C416 238.3 401.7 224 384 224L256 224zM272 272L368 272L368 368L272 368L272 272z"/></svg>`,
// 'mail-check': ``,
// 'eye': ``,
// 'star': ``,
+36
View File
@@ -1013,6 +1013,42 @@ export const SUB_NAV: Record<string, (NavItem | NavGroup)[]> = {
'configuration',
],
},
{
href: makePath('/dhcp/options/pxe-profile'),
label: 'PXE Profile Generator',
description:
'Generate PXE boot profiles with automatic UEFI/BIOS detection using Options 93/94 for architecture-aware bootfile selection',
icon: 'tools',
keywords: [
'dhcp',
'pxe',
'profile',
'boot',
'uefi',
'bios',
'option',
'93',
'94',
'66',
'67',
'architecture',
'detection',
'bootfile',
'tftp',
'network',
'generator',
'isc',
'dhcpd',
'kea',
'configuration',
'preset',
'ipxe',
'wds',
'windows',
'deployment',
'firmware',
],
},
],
'/dns': [
{
+451
View File
@@ -0,0 +1,451 @@
/**
* DHCP PXE Profile Generator
* Generates PXE boot profiles with UEFI/BIOS detection using Options 93/94
* - Option 93: Client System Architecture Type
* - Option 94: Client Network Interface Identifier
* - Option 66: TFTP Server Name
* - Option 67: Bootfile Name
* Utilities for generating conditional PXE configurations
*/
export type ArchitectureType = 'bios' | 'uefi-x64' | 'uefi-x86' | 'uefi-arm64' | 'uefi-arm32' | 'auto';
export interface PXEProfile {
name: string;
tftpServer?: string; // Option 66
architecture: ArchitectureType;
biosBootfile?: string; // Bootfile for BIOS (Option 67)
uefiX64Bootfile?: string; // Bootfile for UEFI x64
uefiX86Bootfile?: string; // Bootfile for UEFI x86
uefiArm64Bootfile?: string; // Bootfile for UEFI ARM64
uefiArm32Bootfile?: string; // Bootfile for UEFI ARM32
network?: {
subnet?: string;
netmask?: string;
rangeStart?: string;
rangeEnd?: string;
gateway?: string;
dns?: string;
};
}
export interface PXEResult {
profile: PXEProfile;
examples: {
iscDhcpd?: string;
keaDhcp4?: string;
};
}
/**
* Architecture type codes from RFC 4578
*/
export const ARCH_CODES = {
BIOS: 0x0000, // Intel x86PC
UEFI_X64: 0x0007, // EFI BC (x86-64)
UEFI_X86: 0x0006, // EFI IA32
UEFI_ARM64: 0x000b, // EFI ARM 64-bit
UEFI_ARM32: 0x000a, // EFI ARM 32-bit
} as const;
/**
* Preset PXE profiles
*/
export const PXE_PRESETS: PXEProfile[] = [
{
name: 'Standard PXE (BIOS only)',
architecture: 'bios',
tftpServer: 'pxe.example.com',
biosBootfile: 'pxelinux.0',
},
{
name: 'UEFI x64 only',
architecture: 'uefi-x64',
tftpServer: 'pxe.example.com',
uefiX64Bootfile: 'bootx64.efi',
},
{
name: 'Auto-detect (BIOS + UEFI x64)',
architecture: 'auto',
tftpServer: 'pxe.example.com',
biosBootfile: 'pxelinux.0',
uefiX64Bootfile: 'bootx64.efi',
},
{
name: 'Full Multi-Architecture',
architecture: 'auto',
tftpServer: 'pxe.example.com',
biosBootfile: 'pxelinux.0',
uefiX64Bootfile: 'bootx64.efi',
uefiX86Bootfile: 'bootia32.efi',
uefiArm64Bootfile: 'bootaa64.efi',
uefiArm32Bootfile: 'bootarm.efi',
},
{
name: 'iPXE Chain Loading',
architecture: 'auto',
tftpServer: '192.168.1.10',
biosBootfile: 'undionly.kpxe',
uefiX64Bootfile: 'ipxe-x64.efi',
},
{
name: 'Windows Deployment (WDS)',
architecture: 'auto',
tftpServer: 'wds.example.com',
biosBootfile: 'boot\\x86\\wdsnbp.com',
uefiX64Bootfile: 'boot\\x64\\wdsmgfw.efi',
},
];
/**
* Validate PXE profile
*/
export function validatePXEProfile(profile: PXEProfile): string[] {
const errors: string[] = [];
if (!profile.name?.trim()) {
errors.push('Profile name is required');
}
if (!profile.tftpServer?.trim()) {
errors.push('TFTP server is required');
}
// Check that at least one bootfile is configured
const hasBootfile =
profile.biosBootfile?.trim() ||
profile.uefiX64Bootfile?.trim() ||
profile.uefiX86Bootfile?.trim() ||
profile.uefiArm64Bootfile?.trim() ||
profile.uefiArm32Bootfile?.trim();
if (!hasBootfile) {
errors.push('At least one bootfile must be configured');
}
// Validate architecture-specific requirements
if (profile.architecture === 'bios' && !profile.biosBootfile?.trim()) {
errors.push('BIOS bootfile is required for BIOS architecture');
}
if (profile.architecture === 'uefi-x64' && !profile.uefiX64Bootfile?.trim()) {
errors.push('UEFI x64 bootfile is required for UEFI x64 architecture');
}
if (profile.architecture === 'uefi-x86' && !profile.uefiX86Bootfile?.trim()) {
errors.push('UEFI x86 bootfile is required for UEFI x86 architecture');
}
if (profile.architecture === 'uefi-arm64' && !profile.uefiArm64Bootfile?.trim()) {
errors.push('UEFI ARM64 bootfile is required for UEFI ARM64 architecture');
}
if (profile.architecture === 'uefi-arm32' && !profile.uefiArm32Bootfile?.trim()) {
errors.push('UEFI ARM32 bootfile is required for UEFI ARM32 architecture');
}
return errors;
}
/**
* Validate network settings
*/
export function validateNetworkSettings(network?: PXEProfile['network']): string[] {
if (!network) return [];
const errors: string[] = [];
// Basic IPv4 validation
const ipv4Regex = /^(\d{1,3}\.){3}\d{1,3}$/;
if (network.subnet && !ipv4Regex.test(network.subnet)) {
errors.push('Invalid subnet format');
}
if (network.netmask && !ipv4Regex.test(network.netmask)) {
errors.push('Invalid netmask format');
}
if (network.rangeStart && !ipv4Regex.test(network.rangeStart)) {
errors.push('Invalid range start format');
}
if (network.rangeEnd && !ipv4Regex.test(network.rangeEnd)) {
errors.push('Invalid range end format');
}
if (network.gateway && !ipv4Regex.test(network.gateway)) {
errors.push('Invalid gateway format');
}
if (network.dns && !ipv4Regex.test(network.dns)) {
errors.push('Invalid DNS server format');
}
return errors;
}
/**
* Generate ISC dhcpd configuration
*/
function generateIscDhcpdConfig(profile: PXEProfile): string {
const lines: string[] = [];
// Use network settings or defaults
const subnet = profile.network?.subnet?.trim() || '192.168.1.0';
const netmask = profile.network?.netmask?.trim() || '255.255.255.0';
const rangeStart = profile.network?.rangeStart?.trim() || '192.168.1.100';
const rangeEnd = profile.network?.rangeEnd?.trim() || '192.168.1.200';
const gateway = profile.network?.gateway?.trim() || '192.168.1.1';
const dns = profile.network?.dns?.trim() || '8.8.8.8';
lines.push(`# PXE Profile: ${profile.name}`);
lines.push('# ISC dhcpd configuration for PXE boot with architecture detection');
lines.push('');
lines.push('# Define option space for PXE');
lines.push('option space PXE;');
lines.push('option PXE.mtftp-ip code 1 = ip-address;');
lines.push('option PXE.mtftp-cport code 2 = unsigned integer 16;');
lines.push('option PXE.mtftp-sport code 3 = unsigned integer 16;');
lines.push('option PXE.mtftp-tmout code 4 = unsigned integer 8;');
lines.push('option PXE.mtftp-delay code 5 = unsigned integer 8;');
lines.push('option arch code 93 = unsigned integer 16;');
lines.push('');
lines.push(`subnet ${subnet} netmask ${netmask} {`);
lines.push(` range ${rangeStart} ${rangeEnd};`);
lines.push(` option routers ${gateway};`);
lines.push(` option domain-name-servers ${dns};`);
lines.push(' ');
if (profile.architecture === 'auto') {
lines.push(' # Auto-detect architecture and set bootfile accordingly');
lines.push(' class "pxeclients" {');
lines.push(' match if substring (option vendor-class-identifier, 0, 9) = "PXEClient";');
lines.push(` next-server ${profile.tftpServer};`);
lines.push(' ');
const bootfiles: { arch: string; code: number; file?: string }[] = [];
if (profile.biosBootfile) {
bootfiles.push({ arch: 'BIOS (x86)', code: ARCH_CODES.BIOS, file: profile.biosBootfile });
}
if (profile.uefiX64Bootfile) {
bootfiles.push({
arch: 'UEFI x64',
code: ARCH_CODES.UEFI_X64,
file: profile.uefiX64Bootfile,
});
}
if (profile.uefiX86Bootfile) {
bootfiles.push({
arch: 'UEFI x86',
code: ARCH_CODES.UEFI_X86,
file: profile.uefiX86Bootfile,
});
}
if (profile.uefiArm64Bootfile) {
bootfiles.push({
arch: 'UEFI ARM64',
code: ARCH_CODES.UEFI_ARM64,
file: profile.uefiArm64Bootfile,
});
}
if (profile.uefiArm32Bootfile) {
bootfiles.push({
arch: 'UEFI ARM32',
code: ARCH_CODES.UEFI_ARM32,
file: profile.uefiArm32Bootfile,
});
}
bootfiles.forEach((bf, idx) => {
if (idx === 0) {
lines.push(` if option arch = ${bf.code.toString(16).padStart(2, '0')} {`);
} else {
lines.push(` } elsif option arch = ${bf.code.toString(16).padStart(2, '0')} {`);
}
lines.push(` # ${bf.arch}`);
lines.push(` filename "${bf.file}";`);
});
if (bootfiles.length > 0) {
lines.push(' } else {');
lines.push(' # Default to BIOS if architecture not recognized');
lines.push(` filename "${profile.biosBootfile || 'pxelinux.0'}";`);
lines.push(' }');
}
lines.push(' }');
} else {
// Single architecture mode
lines.push(' class "pxeclients" {');
lines.push(' match if substring (option vendor-class-identifier, 0, 9) = "PXEClient";');
lines.push(` next-server ${profile.tftpServer};`);
let bootfile = '';
if (profile.architecture === 'bios') bootfile = profile.biosBootfile || '';
else if (profile.architecture === 'uefi-x64') bootfile = profile.uefiX64Bootfile || '';
else if (profile.architecture === 'uefi-x86') bootfile = profile.uefiX86Bootfile || '';
else if (profile.architecture === 'uefi-arm64') bootfile = profile.uefiArm64Bootfile || '';
else if (profile.architecture === 'uefi-arm32') bootfile = profile.uefiArm32Bootfile || '';
lines.push(` filename "${bootfile}";`);
lines.push(' }');
}
lines.push('}');
return lines.join('\n');
}
/**
* Generate Kea DHCPv4 configuration
*/
function generateKeaDhcp4Config(profile: PXEProfile): string {
const lines: string[] = [];
// Use network settings or defaults
const subnet = profile.network?.subnet?.trim() || '192.168.1.0';
const netmask = profile.network?.netmask?.trim() || '255.255.255.0';
const rangeStart = profile.network?.rangeStart?.trim() || '192.168.1.100';
const rangeEnd = profile.network?.rangeEnd?.trim() || '192.168.1.200';
const gateway = profile.network?.gateway?.trim() || '192.168.1.1';
const dns = profile.network?.dns?.trim() || '8.8.8.8';
// Calculate CIDR notation from netmask
const cidrBits =
netmask
.split('.')
.map((octet) => parseInt(octet, 10).toString(2).padStart(8, '0'))
.join('')
.split('1').length - 1;
const cidr = `${subnet}/${cidrBits}`;
lines.push(`// PXE Profile: ${profile.name}`);
lines.push('// Kea DHCPv4 configuration for PXE boot with architecture detection');
lines.push('{');
lines.push(' "Dhcp4": {');
lines.push(' "client-classes": [');
if (profile.architecture === 'auto') {
const classes: { name: string; test: string; bootfile?: string }[] = [];
if (profile.biosBootfile) {
classes.push({
name: 'BIOS',
test: 'option[93].hex == 0x0000',
bootfile: profile.biosBootfile,
});
}
if (profile.uefiX64Bootfile) {
classes.push({
name: 'UEFI_X64',
test: 'option[93].hex == 0x0007',
bootfile: profile.uefiX64Bootfile,
});
}
if (profile.uefiX86Bootfile) {
classes.push({
name: 'UEFI_X86',
test: 'option[93].hex == 0x0006',
bootfile: profile.uefiX86Bootfile,
});
}
if (profile.uefiArm64Bootfile) {
classes.push({
name: 'UEFI_ARM64',
test: 'option[93].hex == 0x000b',
bootfile: profile.uefiArm64Bootfile,
});
}
if (profile.uefiArm32Bootfile) {
classes.push({
name: 'UEFI_ARM32',
test: 'option[93].hex == 0x000a',
bootfile: profile.uefiArm32Bootfile,
});
}
classes.forEach((cls, idx) => {
lines.push(' {');
lines.push(` "name": "${cls.name}",`);
lines.push(` "test": "${cls.test}",`);
lines.push(` "boot-file-name": "${cls.bootfile}"`);
lines.push(idx < classes.length - 1 ? ' },' : ' }');
});
}
lines.push(' ],');
lines.push(' "subnet4": [');
lines.push(' {');
lines.push(` "subnet": "${cidr}",`);
lines.push(' "pools": [');
lines.push(' {');
lines.push(` "pool": "${rangeStart} - ${rangeEnd}"`);
lines.push(' }');
lines.push(' ],');
lines.push(` "next-server": "${profile.tftpServer}",`);
if (profile.architecture !== 'auto') {
let bootfile = '';
if (profile.architecture === 'bios') bootfile = profile.biosBootfile || '';
else if (profile.architecture === 'uefi-x64') bootfile = profile.uefiX64Bootfile || '';
else if (profile.architecture === 'uefi-x86') bootfile = profile.uefiX86Bootfile || '';
else if (profile.architecture === 'uefi-arm64') bootfile = profile.uefiArm64Bootfile || '';
else if (profile.architecture === 'uefi-arm32') bootfile = profile.uefiArm32Bootfile || '';
lines.push(` "boot-file-name": "${bootfile}",`);
}
lines.push(' "option-data": [');
lines.push(' {');
lines.push(' "name": "routers",');
lines.push(` "data": "${gateway}"`);
lines.push(' },');
lines.push(' {');
lines.push(' "name": "domain-name-servers",');
lines.push(` "data": "${dns}"`);
lines.push(' }');
lines.push(' ]');
lines.push(' }');
lines.push(' ]');
lines.push(' }');
lines.push('}');
return lines.join('\n');
}
/**
* Generate PXE profile configuration
*/
export function generatePXEProfile(profile: PXEProfile): PXEResult {
const profileErrors = validatePXEProfile(profile);
if (profileErrors.length > 0) {
throw new Error(profileErrors.join('; '));
}
const networkErrors = validateNetworkSettings(profile.network);
if (networkErrors.length > 0) {
throw new Error(networkErrors.join('; '));
}
return {
profile,
examples: {
iscDhcpd: generateIscDhcpdConfig(profile),
keaDhcp4: generateKeaDhcp4Config(profile),
},
};
}
/**
* Get default PXE profile
*/
export function getDefaultPXEProfile(): PXEProfile {
return {
name: 'Standard PXE Profile',
architecture: 'auto',
tftpServer: 'pxe.example.com',
biosBootfile: 'pxelinux.0',
uefiX64Bootfile: 'bootx64.efi',
};
}
@@ -0,0 +1,5 @@
<script lang="ts">
import PXEProfileBuilder from '$lib/components/tools/PXEProfileBuilder.svelte';
</script>
<PXEProfileBuilder />
+451
View File
@@ -0,0 +1,451 @@
import { describe, it, expect } from 'vitest';
import {
type PXEProfile,
generatePXEProfile,
validatePXEProfile,
validateNetworkSettings,
PXE_PRESETS,
getDefaultPXEProfile,
ARCH_CODES,
} from '$lib/utils/dhcp-pxe-profile';
describe('PXE Profile Generator', () => {
describe('validatePXEProfile', () => {
it('should validate a correct profile', () => {
const profile: PXEProfile = {
name: 'Test Profile',
tftpServer: '192.168.1.10',
architecture: 'auto',
biosBootfile: 'pxelinux.0',
uefiX64Bootfile: 'bootx64.efi',
};
const errors = validatePXEProfile(profile);
expect(errors).toEqual([]);
});
it('should require profile name', () => {
const profile: PXEProfile = {
name: '',
tftpServer: '192.168.1.10',
architecture: 'bios',
biosBootfile: 'pxelinux.0',
};
const errors = validatePXEProfile(profile);
expect(errors).toContain('Profile name is required');
});
it('should require TFTP server', () => {
const profile: PXEProfile = {
name: 'Test',
tftpServer: '',
architecture: 'bios',
biosBootfile: 'pxelinux.0',
};
const errors = validatePXEProfile(profile);
expect(errors).toContain('TFTP server is required');
});
it('should require at least one bootfile', () => {
const profile: PXEProfile = {
name: 'Test',
tftpServer: '192.168.1.10',
architecture: 'auto',
};
const errors = validatePXEProfile(profile);
expect(errors).toContain('At least one bootfile must be configured');
});
it('should validate BIOS architecture requires BIOS bootfile', () => {
const profile: PXEProfile = {
name: 'Test',
tftpServer: '192.168.1.10',
architecture: 'bios',
};
const errors = validatePXEProfile(profile);
expect(errors).toContain('BIOS bootfile is required for BIOS architecture');
});
it('should validate UEFI x64 architecture requires UEFI x64 bootfile', () => {
const profile: PXEProfile = {
name: 'Test',
tftpServer: '192.168.1.10',
architecture: 'uefi-x64',
};
const errors = validatePXEProfile(profile);
expect(errors).toContain('UEFI x64 bootfile is required for UEFI x64 architecture');
});
it('should validate UEFI x86 architecture requires UEFI x86 bootfile', () => {
const profile: PXEProfile = {
name: 'Test',
tftpServer: '192.168.1.10',
architecture: 'uefi-x86',
};
const errors = validatePXEProfile(profile);
expect(errors).toContain('UEFI x86 bootfile is required for UEFI x86 architecture');
});
it('should validate UEFI ARM64 architecture requires UEFI ARM64 bootfile', () => {
const profile: PXEProfile = {
name: 'Test',
tftpServer: '192.168.1.10',
architecture: 'uefi-arm64',
};
const errors = validatePXEProfile(profile);
expect(errors).toContain('UEFI ARM64 bootfile is required for UEFI ARM64 architecture');
});
it('should validate UEFI ARM32 architecture requires UEFI ARM32 bootfile', () => {
const profile: PXEProfile = {
name: 'Test',
tftpServer: '192.168.1.10',
architecture: 'uefi-arm32',
};
const errors = validatePXEProfile(profile);
expect(errors).toContain('UEFI ARM32 bootfile is required for UEFI ARM32 architecture');
});
});
describe('validateNetworkSettings', () => {
it('should accept undefined network settings', () => {
const errors = validateNetworkSettings(undefined);
expect(errors).toEqual([]);
});
it('should accept valid network settings', () => {
const network = {
subnet: '192.168.1.0',
netmask: '255.255.255.0',
rangeStart: '192.168.1.100',
rangeEnd: '192.168.1.200',
gateway: '192.168.1.1',
dns: '8.8.8.8',
};
const errors = validateNetworkSettings(network);
expect(errors).toEqual([]);
});
it('should validate subnet format', () => {
const network = {
subnet: 'invalid',
};
const errors = validateNetworkSettings(network);
expect(errors).toContain('Invalid subnet format');
});
it('should validate netmask format', () => {
const network = {
netmask: 'invalid',
};
const errors = validateNetworkSettings(network);
expect(errors).toContain('Invalid netmask format');
});
it('should validate range start format', () => {
const network = {
rangeStart: 'invalid',
};
const errors = validateNetworkSettings(network);
expect(errors).toContain('Invalid range start format');
});
it('should validate range end format', () => {
const network = {
rangeEnd: 'invalid',
};
const errors = validateNetworkSettings(network);
expect(errors).toContain('Invalid range end format');
});
it('should validate gateway format', () => {
const network = {
gateway: 'invalid',
};
const errors = validateNetworkSettings(network);
expect(errors).toContain('Invalid gateway format');
});
it('should validate DNS server format', () => {
const network = {
dns: 'invalid',
};
const errors = validateNetworkSettings(network);
expect(errors).toContain('Invalid DNS server format');
});
});
describe('generatePXEProfile', () => {
it('should generate ISC dhcpd configuration for BIOS only', () => {
const profile: PXEProfile = {
name: 'BIOS Only',
tftpServer: 'pxe.example.com',
architecture: 'bios',
biosBootfile: 'pxelinux.0',
};
const result = generatePXEProfile(profile);
expect(result.profile).toEqual(profile);
expect(result.examples.iscDhcpd).toBeDefined();
expect(result.examples.iscDhcpd).toContain('next-server pxe.example.com');
expect(result.examples.iscDhcpd).toContain('filename "pxelinux.0"');
});
it('should generate ISC dhcpd configuration for UEFI only', () => {
const profile: PXEProfile = {
name: 'UEFI Only',
tftpServer: 'pxe.example.com',
architecture: 'uefi-x64',
uefiX64Bootfile: 'bootx64.efi',
};
const result = generatePXEProfile(profile);
expect(result.profile).toEqual(profile);
expect(result.examples.iscDhcpd).toBeDefined();
expect(result.examples.iscDhcpd).toContain('next-server pxe.example.com');
expect(result.examples.iscDhcpd).toContain('filename "bootx64.efi"');
});
it('should generate ISC dhcpd configuration with auto-detection', () => {
const profile: PXEProfile = {
name: 'Auto-detect',
tftpServer: 'pxe.example.com',
architecture: 'auto',
biosBootfile: 'pxelinux.0',
uefiX64Bootfile: 'bootx64.efi',
};
const result = generatePXEProfile(profile);
expect(result.profile).toEqual(profile);
expect(result.examples.iscDhcpd).toBeDefined();
expect(result.examples.iscDhcpd).toContain('option arch code 93');
expect(result.examples.iscDhcpd).toContain('if option arch = 00 {');
expect(result.examples.iscDhcpd).toContain('filename "pxelinux.0"');
expect(result.examples.iscDhcpd).toContain('} elsif option arch = 07 {');
expect(result.examples.iscDhcpd).toContain('filename "bootx64.efi"');
});
it('should generate Kea DHCPv4 configuration for BIOS only', () => {
const profile: PXEProfile = {
name: 'BIOS Only',
tftpServer: 'pxe.example.com',
architecture: 'bios',
biosBootfile: 'pxelinux.0',
};
const result = generatePXEProfile(profile);
expect(result.examples.keaDhcp4).toBeDefined();
expect(result.examples.keaDhcp4).toContain('"next-server": "pxe.example.com"');
expect(result.examples.keaDhcp4).toContain('"boot-file-name": "pxelinux.0"');
});
it('should generate Kea DHCPv4 configuration with auto-detection', () => {
const profile: PXEProfile = {
name: 'Auto-detect',
tftpServer: 'pxe.example.com',
architecture: 'auto',
biosBootfile: 'pxelinux.0',
uefiX64Bootfile: 'bootx64.efi',
};
const result = generatePXEProfile(profile);
expect(result.examples.keaDhcp4).toBeDefined();
expect(result.examples.keaDhcp4).toContain('"client-classes"');
expect(result.examples.keaDhcp4).toContain('"name": "BIOS"');
expect(result.examples.keaDhcp4).toContain('"test": "option[93].hex == 0x0000"');
expect(result.examples.keaDhcp4).toContain('"boot-file-name": "pxelinux.0"');
expect(result.examples.keaDhcp4).toContain('"name": "UEFI_X64"');
expect(result.examples.keaDhcp4).toContain('"test": "option[93].hex == 0x0007"');
expect(result.examples.keaDhcp4).toContain('"boot-file-name": "bootx64.efi"');
});
it('should use custom network settings', () => {
const profile: PXEProfile = {
name: 'Custom Network',
tftpServer: 'pxe.example.com',
architecture: 'bios',
biosBootfile: 'pxelinux.0',
network: {
subnet: '10.0.0.0',
netmask: '255.255.255.0',
rangeStart: '10.0.0.50',
rangeEnd: '10.0.0.100',
gateway: '10.0.0.1',
dns: '1.1.1.1',
},
};
const result = generatePXEProfile(profile);
expect(result.examples.iscDhcpd).toContain('subnet 10.0.0.0 netmask 255.255.255.0');
expect(result.examples.iscDhcpd).toContain('range 10.0.0.50 10.0.0.100');
expect(result.examples.iscDhcpd).toContain('option routers 10.0.0.1');
expect(result.examples.iscDhcpd).toContain('option domain-name-servers 1.1.1.1');
expect(result.examples.keaDhcp4).toContain('"subnet": "10.0.0.0/24"');
expect(result.examples.keaDhcp4).toContain('"pool": "10.0.0.50 - 10.0.0.100"');
expect(result.examples.keaDhcp4).toContain('"data": "10.0.0.1"');
expect(result.examples.keaDhcp4).toContain('"data": "1.1.1.1"');
});
it('should support all architecture types in auto mode', () => {
const profile: PXEProfile = {
name: 'Full Multi-Architecture',
tftpServer: 'pxe.example.com',
architecture: 'auto',
biosBootfile: 'pxelinux.0',
uefiX64Bootfile: 'bootx64.efi',
uefiX86Bootfile: 'bootia32.efi',
uefiArm64Bootfile: 'bootaa64.efi',
uefiArm32Bootfile: 'bootarm.efi',
};
const result = generatePXEProfile(profile);
// ISC dhcpd should have all architectures
expect(result.examples.iscDhcpd).toContain('filename "pxelinux.0"');
expect(result.examples.iscDhcpd).toContain('filename "bootx64.efi"');
expect(result.examples.iscDhcpd).toContain('filename "bootia32.efi"');
expect(result.examples.iscDhcpd).toContain('filename "bootaa64.efi"');
expect(result.examples.iscDhcpd).toContain('filename "bootarm.efi"');
// Kea should have all client classes
expect(result.examples.keaDhcp4).toContain('"name": "BIOS"');
expect(result.examples.keaDhcp4).toContain('"name": "UEFI_X64"');
expect(result.examples.keaDhcp4).toContain('"name": "UEFI_X86"');
expect(result.examples.keaDhcp4).toContain('"name": "UEFI_ARM64"');
expect(result.examples.keaDhcp4).toContain('"name": "UEFI_ARM32"');
});
it('should throw error for invalid profile', () => {
const profile: PXEProfile = {
name: '',
tftpServer: '192.168.1.10',
architecture: 'bios',
};
expect(() => generatePXEProfile(profile)).toThrow();
});
it('should throw error for invalid network settings', () => {
const profile: PXEProfile = {
name: 'Test',
tftpServer: '192.168.1.10',
architecture: 'bios',
biosBootfile: 'pxelinux.0',
network: {
subnet: 'invalid',
},
};
expect(() => generatePXEProfile(profile)).toThrow();
});
});
describe('getDefaultPXEProfile', () => {
it('should return a valid default profile', () => {
const profile = getDefaultPXEProfile();
expect(profile.name).toBe('Standard PXE Profile');
expect(profile.architecture).toBe('auto');
expect(profile.tftpServer).toBe('pxe.example.com');
expect(profile.biosBootfile).toBe('pxelinux.0');
expect(profile.uefiX64Bootfile).toBe('bootx64.efi');
const errors = validatePXEProfile(profile);
expect(errors).toEqual([]);
});
});
describe('PXE_PRESETS', () => {
it('should have valid presets', () => {
expect(PXE_PRESETS.length).toBeGreaterThan(0);
for (const preset of PXE_PRESETS) {
expect(preset.name).toBeTruthy();
expect(preset.tftpServer).toBeTruthy();
expect(preset.architecture).toBeTruthy();
const errors = validatePXEProfile(preset);
expect(errors).toEqual([]);
}
});
it('should include Standard PXE (BIOS only)', () => {
const preset = PXE_PRESETS.find((p) => p.name === 'Standard PXE (BIOS only)');
expect(preset).toBeDefined();
expect(preset?.architecture).toBe('bios');
expect(preset?.biosBootfile).toBe('pxelinux.0');
});
it('should include UEFI x64 only', () => {
const preset = PXE_PRESETS.find((p) => p.name === 'UEFI x64 only');
expect(preset).toBeDefined();
expect(preset?.architecture).toBe('uefi-x64');
expect(preset?.uefiX64Bootfile).toBe('bootx64.efi');
});
it('should include Auto-detect preset', () => {
const preset = PXE_PRESETS.find((p) => p.name === 'Auto-detect (BIOS + UEFI x64)');
expect(preset).toBeDefined();
expect(preset?.architecture).toBe('auto');
expect(preset?.biosBootfile).toBe('pxelinux.0');
expect(preset?.uefiX64Bootfile).toBe('bootx64.efi');
});
it('should include Full Multi-Architecture preset', () => {
const preset = PXE_PRESETS.find((p) => p.name === 'Full Multi-Architecture');
expect(preset).toBeDefined();
expect(preset?.architecture).toBe('auto');
expect(preset?.biosBootfile).toBe('pxelinux.0');
expect(preset?.uefiX64Bootfile).toBe('bootx64.efi');
expect(preset?.uefiX86Bootfile).toBe('bootia32.efi');
expect(preset?.uefiArm64Bootfile).toBe('bootaa64.efi');
expect(preset?.uefiArm32Bootfile).toBe('bootarm.efi');
});
it('should include iPXE Chain Loading preset', () => {
const preset = PXE_PRESETS.find((p) => p.name === 'iPXE Chain Loading');
expect(preset).toBeDefined();
expect(preset?.biosBootfile).toBe('undionly.kpxe');
expect(preset?.uefiX64Bootfile).toBe('ipxe-x64.efi');
});
it('should include Windows Deployment preset', () => {
const preset = PXE_PRESETS.find((p) => p.name === 'Windows Deployment (WDS)');
expect(preset).toBeDefined();
expect(preset?.biosBootfile).toContain('wdsnbp.com');
expect(preset?.uefiX64Bootfile).toContain('wdsmgfw.efi');
});
});
describe('ARCH_CODES', () => {
it('should have correct architecture codes', () => {
expect(ARCH_CODES.BIOS).toBe(0x0000);
expect(ARCH_CODES.UEFI_X64).toBe(0x0007);
expect(ARCH_CODES.UEFI_X86).toBe(0x0006);
expect(ARCH_CODES.UEFI_ARM64).toBe(0x000b);
expect(ARCH_CODES.UEFI_ARM32).toBe(0x000a);
});
});
});