mirror of
https://github.com/lissy93/networking-toolbox.git
synced 2026-11-28 16:19:49 +03:00
Feat: DHCP kea-isc snippet, and updates port numbers
This commit is contained in:
1 parent
3d1c2fd6cd
commit
b0f8d84730
9 files changed
+1474
-3
No files matched your search
@@ -41,7 +41,7 @@
|
||||
<li>
|
||||
<strong>Option #3 - Docker:</strong><br />
|
||||
Build the Docker image, with <code>docker build -t networking-toolbox .</code>
|
||||
then run <code>docker run -p 8080:300080 networking-toolbox</code>
|
||||
then run <code>docker run -p 8080:3000 networking-toolbox</code>
|
||||
</li>
|
||||
</ul> -->
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
<h3>Option #1 - Docker</h3>
|
||||
<p>With Docker installed, just run the following command:</p>
|
||||
<div class="code">
|
||||
<code>docker run -p 8080:300080 lissy93/networking-toolbox</code>
|
||||
<code>docker run -p 8080:3000 lissy93/networking-toolbox</code>
|
||||
</div>
|
||||
<p>
|
||||
You can also checkout our
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
{site.title} can be easily deployed to your own server. Just run the following command:
|
||||
</p>
|
||||
<div class="code">
|
||||
<code>docker run -p 8080:300080 lissy93/networking-toolbox</code>
|
||||
<code>docker run -p 8080:3000 lissy93/networking-toolbox</code>
|
||||
</div>
|
||||
<p>
|
||||
You can also checkout our <a href="https://github.com/Lissy93/networking-toolbox/blob/main/docker-compose.yml"
|
||||
|
||||
@@ -0,0 +1,532 @@
|
||||
<script lang="ts">
|
||||
import Icon from '$lib/components/global/Icon.svelte';
|
||||
import { useClipboard } from '$lib/composables';
|
||||
import {
|
||||
generateSnippets,
|
||||
getDefaultSnippetConfig,
|
||||
type SnippetConfig,
|
||||
type SnippetResult,
|
||||
type DhcpTarget,
|
||||
type PoolRange,
|
||||
} from '$lib/utils/dhcp-snippets.js';
|
||||
|
||||
let config = $state<SnippetConfig>(getDefaultSnippetConfig());
|
||||
let result = $state<SnippetResult | null>(null);
|
||||
|
||||
const clipboard = useClipboard();
|
||||
|
||||
const targetOptions: Array<{ value: DhcpTarget; label: string }> = [
|
||||
{ value: 'isc-dhcpd', label: 'ISC dhcpd' },
|
||||
{ value: 'kea-dhcp4', label: 'Kea DHCPv4' },
|
||||
{ value: 'kea-dhcp6', label: 'Kea DHCPv6' },
|
||||
];
|
||||
|
||||
// Reactive generation
|
||||
$effect(() => {
|
||||
generate();
|
||||
});
|
||||
|
||||
function generate() {
|
||||
result = generateSnippets(config);
|
||||
}
|
||||
|
||||
function addPool() {
|
||||
const lastPool = config.pools[config.pools.length - 1];
|
||||
const newPool: PoolRange = { start: lastPool.end, end: lastPool.end };
|
||||
config.pools = [...config.pools, newPool];
|
||||
}
|
||||
|
||||
function removePool(index: number) {
|
||||
if (config.pools.length > 1) {
|
||||
config.pools = config.pools.filter((_, i) => i !== index);
|
||||
}
|
||||
}
|
||||
|
||||
function toggleTarget(target: DhcpTarget) {
|
||||
if (config.targets.includes(target)) {
|
||||
config.targets = config.targets.filter((t) => t !== target);
|
||||
} else {
|
||||
config.targets = [...config.targets, target];
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="card input-card">
|
||||
<div class="card-header">
|
||||
<h3>Configuration</h3>
|
||||
</div>
|
||||
<div class="card-content">
|
||||
<!-- Target selection -->
|
||||
<div class="input-group">
|
||||
<label>
|
||||
<Icon name="server" size="sm" />
|
||||
Target Servers
|
||||
</label>
|
||||
<div class="checkbox-group">
|
||||
{#each targetOptions as option (option.value)}
|
||||
<label class="checkbox-label">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={config.targets.includes(option.value)}
|
||||
onchange={() => toggleTarget(option.value)}
|
||||
/>
|
||||
{option.label}
|
||||
</label>
|
||||
{/each}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Mode -->
|
||||
<div class="input-group">
|
||||
<label for="mode">
|
||||
<Icon name="network" size="sm" />
|
||||
IP Mode
|
||||
</label>
|
||||
<select id="mode" bind:value={config.mode}>
|
||||
<option value="dhcp4">DHCPv4 (IPv4)</option>
|
||||
<option value="dhcp6">DHCPv6 (IPv6)</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<!-- Subnet -->
|
||||
<div class="input-group">
|
||||
<label for="subnet">
|
||||
<Icon name="network" size="sm" />
|
||||
Subnet (CIDR)
|
||||
</label>
|
||||
<input
|
||||
id="subnet"
|
||||
type="text"
|
||||
bind:value={config.subnet}
|
||||
placeholder={config.mode === 'dhcp6' ? '2001:db8::/64' : '192.168.1.0/24'}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<!-- Pools -->
|
||||
<div class="input-group">
|
||||
<label>
|
||||
<Icon name="layers" size="sm" />
|
||||
Address Pools
|
||||
</label>
|
||||
{#each config.pools as pool, i (i)}
|
||||
<div class="pool-row">
|
||||
<input type="text" bind:value={pool.start} placeholder="Start IP" />
|
||||
<span>-</span>
|
||||
<input type="text" bind:value={pool.end} placeholder="End IP" />
|
||||
{#if config.pools.length > 1}
|
||||
<button type="button" class="btn-icon" onclick={() => removePool(i)}>
|
||||
<Icon name="x" size="sm" />
|
||||
</button>
|
||||
{/if}
|
||||
</div>
|
||||
{/each}
|
||||
<button type="button" class="btn-add" onclick={addPool}>
|
||||
<Icon name="plus" size="sm" />
|
||||
Add Pool
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<!-- Gateway -->
|
||||
<div class="input-group">
|
||||
<label for="gateway">
|
||||
<Icon name="arrow-right" size="sm" />
|
||||
Gateway (Router)
|
||||
</label>
|
||||
<input
|
||||
id="gateway"
|
||||
type="text"
|
||||
bind:value={config.gateway}
|
||||
placeholder={config.mode === 'dhcp6' ? 'fe80::1' : '192.168.1.1'}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<!-- DNS -->
|
||||
<div class="input-group">
|
||||
<label for="dns">
|
||||
<Icon name="globe" size="sm" />
|
||||
DNS Servers (comma-separated)
|
||||
</label>
|
||||
<input
|
||||
id="dns"
|
||||
type="text"
|
||||
value={config.dnsServers?.join(', ') || ''}
|
||||
oninput={(e) => (config.dnsServers = e.currentTarget.value.split(',').map((s) => s.trim()))}
|
||||
placeholder="8.8.8.8, 8.8.4.4"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<!-- Domain -->
|
||||
<div class="input-group">
|
||||
<label for="domain">
|
||||
<Icon name="globe" size="sm" />
|
||||
Domain Name
|
||||
</label>
|
||||
<input id="domain" type="text" bind:value={config.domainName} placeholder="example.com" />
|
||||
</div>
|
||||
|
||||
<!-- Lease times -->
|
||||
<div class="input-row">
|
||||
<div class="input-group">
|
||||
<label for="defaultLease">
|
||||
<Icon name="clock" size="sm" />
|
||||
Default Lease (seconds)
|
||||
</label>
|
||||
<input id="defaultLease" type="number" bind:value={config.defaultLeaseTime} placeholder="86400" />
|
||||
</div>
|
||||
<div class="input-group">
|
||||
<label for="maxLease">
|
||||
<Icon name="clock" size="sm" />
|
||||
Max Lease (seconds)
|
||||
</label>
|
||||
<input id="maxLease" type="number" bind:value={config.maxLeaseTime} placeholder="604800" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Options -->
|
||||
<div class="input-row">
|
||||
<label class="checkbox-label">
|
||||
<input type="checkbox" bind:checked={config.emitOptionNames} />
|
||||
Use option names (ISC)
|
||||
</label>
|
||||
<label class="checkbox-label">
|
||||
<input type="checkbox" bind:checked={config.prettyJson} />
|
||||
Pretty JSON (Kea)
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{#if result}
|
||||
{#if result.validations.length > 0}
|
||||
<div class="card errors-card">
|
||||
<h3>Validation Errors</h3>
|
||||
{#each result.validations as error (error.field)}
|
||||
<div class="error-message">
|
||||
<Icon name="alert-triangle" size="sm" />
|
||||
<strong>{error.field}:</strong>
|
||||
{error.message}
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
{:else}
|
||||
<div class="card summary-card">
|
||||
<Icon name="info" size="sm" />
|
||||
<p>{result.summary}</p>
|
||||
</div>
|
||||
|
||||
<div class="card results">
|
||||
<h3>Generated Snippets</h3>
|
||||
|
||||
{#if result.iscDhcpdSnippet}
|
||||
<div class="output-group">
|
||||
<div class="output-header">
|
||||
<h4>ISC dhcpd.conf</h4>
|
||||
<button
|
||||
type="button"
|
||||
class="copy-btn"
|
||||
class:copied={clipboard.isCopied('isc')}
|
||||
onclick={() => clipboard.copy(result!.iscDhcpdSnippet!, 'isc')}
|
||||
>
|
||||
<Icon name={clipboard.isCopied('isc') ? 'check' : 'copy'} size="xs" />
|
||||
{clipboard.isCopied('isc') ? 'Copied' : 'Copy'}
|
||||
</button>
|
||||
</div>
|
||||
<pre class="output-value code-block">{result.iscDhcpdSnippet}</pre>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
{#if result.keaDhcp4Snippet}
|
||||
<div class="output-group">
|
||||
<div class="output-header">
|
||||
<h4>Kea DHCPv4 JSON</h4>
|
||||
<button
|
||||
type="button"
|
||||
class="copy-btn"
|
||||
class:copied={clipboard.isCopied('kea4')}
|
||||
onclick={() => clipboard.copy(result!.keaDhcp4Snippet!, 'kea4')}
|
||||
>
|
||||
<Icon name={clipboard.isCopied('kea4') ? 'check' : 'copy'} size="xs" />
|
||||
{clipboard.isCopied('kea4') ? 'Copied' : 'Copy'}
|
||||
</button>
|
||||
</div>
|
||||
<pre class="output-value code-block">{result.keaDhcp4Snippet}</pre>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
{#if result.keaDhcp6Snippet}
|
||||
<div class="output-group">
|
||||
<div class="output-header">
|
||||
<h4>Kea DHCPv6 JSON</h4>
|
||||
<button
|
||||
type="button"
|
||||
class="copy-btn"
|
||||
class:copied={clipboard.isCopied('kea6')}
|
||||
onclick={() => clipboard.copy(result!.keaDhcp6Snippet!, 'kea6')}
|
||||
>
|
||||
<Icon name={clipboard.isCopied('kea6') ? 'check' : 'copy'} size="xs" />
|
||||
{clipboard.isCopied('kea6') ? 'Copied' : 'Copy'}
|
||||
</button>
|
||||
</div>
|
||||
<pre class="output-value code-block">{result.keaDhcp6Snippet}</pre>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
{/if}
|
||||
|
||||
<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-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;
|
||||
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%);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.input-row {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 1fr;
|
||||
gap: var(--spacing-md);
|
||||
|
||||
@media (max-width: 768px) {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
}
|
||||
|
||||
.checkbox-group {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
gap: var(--spacing-md);
|
||||
|
||||
@media (max-width: 768px) {
|
||||
flex-direction: column;
|
||||
gap: var(--spacing-xs);
|
||||
}
|
||||
|
||||
.checkbox-label {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--spacing-sm);
|
||||
font-weight: normal;
|
||||
cursor: pointer;
|
||||
font-size: var(--font-size-sm);
|
||||
|
||||
input[type='checkbox'] {
|
||||
width: auto;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.pool-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--spacing-sm);
|
||||
|
||||
input {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
span {
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
}
|
||||
|
||||
.btn-icon {
|
||||
padding: var(--spacing-xs);
|
||||
background: transparent;
|
||||
border: 1px solid var(--border-secondary);
|
||||
border-radius: var(--radius-sm);
|
||||
color: var(--color-error);
|
||||
cursor: pointer;
|
||||
transition: all 0.2s ease;
|
||||
|
||||
&:hover {
|
||||
background: color-mix(in srgb, var(--color-error), transparent 90%);
|
||||
border-color: var(--color-error);
|
||||
}
|
||||
}
|
||||
|
||||
.btn-add {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--spacing-xs);
|
||||
padding: var(--spacing-sm);
|
||||
background: transparent;
|
||||
border: 1px dashed var(--border-secondary);
|
||||
border-radius: var(--radius-md);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
.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;
|
||||
}
|
||||
|
||||
.summary-card {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--spacing-sm);
|
||||
background: color-mix(in srgb, var(--color-info), transparent 95%);
|
||||
border-color: var(--color-info);
|
||||
|
||||
p {
|
||||
margin: 0;
|
||||
color: var(--text-primary);
|
||||
font-size: 0.9375rem;
|
||||
}
|
||||
}
|
||||
|
||||
.results {
|
||||
background: var(--bg-tertiary);
|
||||
animation: slideIn 0.3s ease-out;
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
</style>
|
||||
@@ -309,6 +309,7 @@ export const iconMap: Record<string, string> = {
|
||||
dhcp: `<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="M139.2 212C132.6 223.5 136.5 238.2 148 244.8C159.5 251.4 174.2 247.5 180.8 236C187.4 224.5 183.5 209.8 172 203.2C160.5 196.6 145.8 200.5 139.2 212zM139.2 428C145.8 439.5 160.5 443.4 172 436.8C183.5 430.2 187.4 415.5 180.8 404C174.2 392.5 159.5 388.6 148 395.2C136.5 401.8 132.6 416.5 139.2 428zM296 128C296 141.3 306.7 152 320 152C333.3 152 344 141.3 344 128C344 114.7 333.3 104 320 104C306.7 104 296 114.7 296 128zM296 320C296 333.3 306.7 344 320 344C333.3 344 344 333.3 344 320C344 306.7 333.3 296 320 296C306.7 296 296 306.7 296 320zM296 512C296 525.3 306.7 536 320 536C333.3 536 344 525.3 344 512C344 498.7 333.3 488 320 488C306.7 488 296 498.7 296 512zM459.2 236C465.8 247.5 480.5 251.4 492 244.8C503.5 238.2 507.4 223.5 500.8 212C494.2 200.5 479.5 196.6 468 203.2C456.5 209.8 452.6 224.5 459.2 236zM459.2 404C452.6 415.5 456.5 430.2 468 436.8C479.5 443.4 494.2 439.5 500.8 428C507.4 416.5 503.5 401.8 492 395.2C480.5 388.6 465.8 392.5 459.2 404z"/><path d="M320 152C333.3 152 344 141.3 344 128C344 114.7 333.3 104 320 104C306.7 104 296 114.7 296 128C296 141.3 306.7 152 320 152zM384 128C384 154.9 367.5 177.9 344 187.3L344 260.6C367.5 270.1 384 293.1 384 319.9C384 323.3 383.7 326.6 383.2 329.9L441.4 364.8C445.9 361.4 450.8 358.7 455.9 356.6L455.9 283.3C450.7 281.2 445.9 278.5 441.4 275.1L412 292.7C407.3 276.9 398.7 262.8 387.3 251.6L416.7 234C412.7 208.6 424.4 182.3 447.9 168.6C478.5 150.9 517.7 161.4 535.3 192C552.9 222.6 542.5 261.8 511.9 279.4C509.3 280.9 506.6 282.2 503.9 283.3L503.9 356.6C506.6 357.7 509.3 359 511.9 360.5C542.5 378.2 553 417.3 535.3 447.9C517.6 478.5 478.5 489 447.9 471.3C424.3 457.7 412.7 431.3 416.7 405.9L358.5 371C354.1 374.3 349.2 377.1 344 379.2L344 452.5C367.5 462 384 485 384 511.8C384 547.1 355.3 575.8 320 575.8C284.7 575.8 256 547.1 256 511.8C256 484.9 272.5 461.9 296 452.5L296 379.2C272.5 369.7 256 346.7 256 319.9C256 316.5 256.3 313.2 256.8 309.9L198.6 275C194.1 278.4 189.2 281.1 184 283.2L184 356.5C189.1 358.6 194 361.3 198.5 364.7L227.9 347.1C232.6 362.9 241.2 377 252.6 388.2L223.2 406C227.2 431.4 215.6 457.8 192 471.4C161.4 489.1 122.3 478.6 104.6 448C86.9 417.4 97.4 378.3 128 360.6C130.6 359.1 133.3 357.8 136 356.7L136 283.4C133.3 282.3 130.6 281 128 279.5C97.4 261.8 86.9 222.6 104.6 192C122.3 161.4 161.4 150.9 192 168.6C215.6 182.2 227.2 208.6 223.2 234L281.4 268.9C285.8 265.6 290.7 262.8 295.9 260.7L295.9 187.4C272.4 177.9 255.9 154.9 255.9 128.1C255.9 92.8 284.6 64.1 319.9 64.1C355.2 64.1 383.9 92.8 383.9 128.1zM320 344C333.3 344 344 333.3 344 320C344 306.7 333.3 296 320 296C306.7 296 296 306.7 296 320C296 333.3 306.7 344 320 344zM492 244.8C503.5 238.2 507.4 223.5 500.8 212C494.2 200.5 479.5 196.6 468 203.2C456.5 209.8 452.6 224.5 459.2 236C465.8 247.5 480.5 251.4 492 244.8zM180.8 236C187.4 224.5 183.5 209.8 172 203.2C160.5 196.6 145.8 200.5 139.2 212C132.6 223.5 136.5 238.2 148 244.8C159.5 251.4 174.2 247.5 180.8 236zM344 512C344 498.7 333.3 488 320 488C306.7 488 296 498.7 296 512C296 525.3 306.7 536 320 536C333.3 536 344 525.3 344 512zM139.2 428C145.8 439.5 160.5 443.4 172 436.8C183.5 430.2 187.4 415.5 180.8 404C174.2 392.5 159.5 388.6 148 395.2C136.5 401.8 132.6 416.5 139.2 428zM492 395.2C480.5 388.6 465.8 392.5 459.2 404C452.6 415.5 456.5 430.2 468 436.8C479.5 443.4 494.2 439.5 500.8 428C507.4 416.5 503.5 401.8 492 395.2z"/></svg>`,
|
||||
router: `<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.2 416L112.2 480C112.2 488.8 119.4 496 128.2 496L512.2 496C521 496 528.2 488.8 528.2 480L528.2 416C528.2 407.2 521 400 512.2 400L128.2 400C119.4 400 112.2 407.2 112.2 416zM208.2 448C208.2 461.3 197.5 472 184.2 472C170.9 472 160.2 461.3 160.2 448C160.2 434.7 170.9 424 184.2 424C197.5 424 208.2 434.7 208.2 448zM304.2 448C304.2 461.3 293.5 472 280.2 472C266.9 472 256.2 461.3 256.2 448C256.2 434.7 266.9 424 280.2 424C293.5 424 304.2 434.7 304.2 448z"/><path d="M384.2 112C443 112 496.7 133.8 537.6 169.9C547.5 178.7 562.7 177.7 571.5 167.8C580.3 157.9 579.3 142.7 569.4 133.9C520 90.4 455.2 64 384.2 64C313.2 64 248.5 90.4 199.1 133.9C189.2 142.7 188.2 157.8 197 167.8C205.8 177.8 220.9 178.7 230.9 169.9C271.8 133.8 325.4 112 384.2 112zM408.2 312C408.2 298.7 397.5 288 384.2 288C370.9 288 360.2 298.7 360.2 312L360.2 352L128.2 352C92.9 352 64.2 380.7 64.2 416L64.2 480C64.2 515.3 92.9 544 128.2 544L512.2 544C547.5 544 576.2 515.3 576.2 480L576.2 416C576.2 380.7 547.5 352 512.2 352L408.2 352L408.2 312zM128.2 400L512.2 400C521 400 528.2 407.2 528.2 416L528.2 480C528.2 488.8 521 496 512.2 496L128.2 496C119.4 496 112.2 488.8 112.2 480L112.2 416C112.2 407.2 119.4 400 128.2 400zM308.7 250.7C329.4 234 355.6 224 384.2 224C412.8 224 439.1 234 459.7 250.7C470 259 485.1 257.5 493.5 247.2C501.9 236.9 500.3 221.8 490 213.4C461.1 190 424.2 176 384.2 176C344.2 176 307.4 190 278.5 213.4C268.2 221.7 266.6 236.9 275 247.2C283.4 257.5 298.5 259.1 308.8 250.7zM160.2 448C160.2 461.3 170.9 472 184.2 472C197.5 472 208.2 461.3 208.2 448C208.2 434.7 197.5 424 184.2 424C170.9 424 160.2 434.7 160.2 448zM280.2 424C266.9 424 256.2 434.7 256.2 448C256.2 461.3 266.9 472 280.2 472C293.5 472 304.2 461.3 304.2 448C304.2 434.7 293.5 424 280.2 424z"/></svg>`,
|
||||
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>`,
|
||||
// 'mail-check': ``,
|
||||
// 'eye': ``,
|
||||
// 'star': ``,
|
||||
|
||||
@@ -862,6 +862,32 @@ export const SUB_NAV: Record<string, (NavItem | NavGroup)[]> = {
|
||||
'scopes',
|
||||
],
|
||||
},
|
||||
{
|
||||
href: makePath('/dhcp/kea-isc-snippets'),
|
||||
label: 'Kea/ISC Snippets Generator',
|
||||
description:
|
||||
'Generate complete subnet configurations for ISC dhcpd and Kea DHCP servers with pools, options, and reservations',
|
||||
icon: 'code-file',
|
||||
keywords: [
|
||||
'dhcp',
|
||||
'isc',
|
||||
'kea',
|
||||
'snippets',
|
||||
'generator',
|
||||
'subnet',
|
||||
'configuration',
|
||||
'dhcpd.conf',
|
||||
'pools',
|
||||
'options',
|
||||
'reservations',
|
||||
'static',
|
||||
'lease',
|
||||
'classes',
|
||||
'json',
|
||||
'dhcp4',
|
||||
'dhcp6',
|
||||
],
|
||||
},
|
||||
],
|
||||
'/dns': [
|
||||
{
|
||||
|
||||
@@ -0,0 +1,449 @@
|
||||
/**
|
||||
* DHCP Kea/ISC Snippets Generator
|
||||
* Generates complete subnet configurations for ISC dhcpd and Kea DHCP servers
|
||||
*/
|
||||
|
||||
export type DhcpTarget = 'isc-dhcpd' | 'kea-dhcp4' | 'kea-dhcp6';
|
||||
export type DhcpMode = 'dhcp4' | 'dhcp6';
|
||||
export type Option43Container = 'tlv' | 'ascii' | 'rawhex';
|
||||
export type VendorPreset43 = 'cisco-capwap' | 'aruba' | 'ruckus' | 'generic-tlv' | 'custom';
|
||||
export type RenderLocation = 'global' | 'class-match' | 'pool-only';
|
||||
|
||||
export interface PoolRange {
|
||||
start: string;
|
||||
end: string;
|
||||
}
|
||||
|
||||
export interface ClientClass {
|
||||
name: string;
|
||||
matchRule: string; // ISC expression
|
||||
keaTest?: string; // Kea client-class test expression
|
||||
options?: {
|
||||
option43?: string;
|
||||
dns?: string[];
|
||||
leaseTime?: number;
|
||||
};
|
||||
pools?: PoolRange[];
|
||||
}
|
||||
|
||||
export interface StaticReservation {
|
||||
identifier: string; // MAC/DUID/client-id
|
||||
ipAddress: string;
|
||||
hostname?: string;
|
||||
clientClasses?: string[];
|
||||
}
|
||||
|
||||
export interface VendorDiscovery {
|
||||
preset: VendorPreset43;
|
||||
option60?: string;
|
||||
option43Container: Option43Container;
|
||||
suboption?: number;
|
||||
controllerAddresses: string[];
|
||||
renderLocation: RenderLocation;
|
||||
}
|
||||
|
||||
export interface SnippetConfig {
|
||||
targets: DhcpTarget[];
|
||||
mode: DhcpMode;
|
||||
subnet: string; // CIDR
|
||||
pools: PoolRange[];
|
||||
gateway?: string;
|
||||
dnsServers?: string[];
|
||||
domainName?: string;
|
||||
defaultLeaseTime?: number;
|
||||
maxLeaseTime?: number;
|
||||
preferredLifetime?: number; // v6
|
||||
validLifetime?: number; // v6
|
||||
vendorDiscovery?: VendorDiscovery;
|
||||
classes?: ClientClass[];
|
||||
reservations?: StaticReservation[];
|
||||
emitOptionNames?: boolean;
|
||||
prettyJson?: boolean;
|
||||
}
|
||||
|
||||
export interface ValidationError {
|
||||
field: string;
|
||||
message: string;
|
||||
}
|
||||
|
||||
export interface SnippetResult {
|
||||
iscDhcpdSnippet?: string;
|
||||
keaDhcp4Snippet?: string;
|
||||
keaDhcp6Snippet?: string;
|
||||
summary: string;
|
||||
validations: ValidationError[];
|
||||
}
|
||||
|
||||
const VENDOR_PRESETS_43: Record<VendorPreset43, { name: string; defaultSuboption: number; defaultOption60: string }> = {
|
||||
'cisco-capwap': { name: 'Cisco CAPWAP', defaultSuboption: 241, defaultOption60: 'Cisco AP' },
|
||||
aruba: { name: 'Aruba APs', defaultSuboption: 1, defaultOption60: 'ArubaAP' },
|
||||
ruckus: { name: 'Ruckus APs', defaultSuboption: 3, defaultOption60: 'Ruckus CPE' },
|
||||
'generic-tlv': { name: 'Generic TLV', defaultSuboption: 1, defaultOption60: '' },
|
||||
custom: { name: 'Custom', defaultSuboption: 1, defaultOption60: '' },
|
||||
};
|
||||
|
||||
/**
|
||||
* Parse CIDR into network and netmask
|
||||
*/
|
||||
function parseCIDR(cidr: string): { network: string; netmask: string; prefix: number } {
|
||||
const [network, prefixStr] = cidr.split('/');
|
||||
const prefix = parseInt(prefixStr, 10);
|
||||
|
||||
if (cidr.includes(':')) {
|
||||
// IPv6 - return prefix as-is
|
||||
return { network, netmask: '', prefix };
|
||||
}
|
||||
|
||||
// IPv4 - convert to dotted netmask
|
||||
const mask = (0xffffffff << (32 - prefix)) >>> 0;
|
||||
const netmask = [(mask >>> 24) & 0xff, (mask >>> 16) & 0xff, (mask >>> 8) & 0xff, mask & 0xff].join('.');
|
||||
|
||||
return { network, netmask, prefix };
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if IP is within subnet
|
||||
*/
|
||||
function isIPInSubnet(ip: string, subnet: string): boolean {
|
||||
const { network, prefix } = parseCIDR(subnet);
|
||||
|
||||
if (ip.includes(':') || network.includes(':')) {
|
||||
// IPv6 - simplified check
|
||||
return ip.startsWith(network.split('::')[0]);
|
||||
}
|
||||
|
||||
// IPv4
|
||||
const ipNum = ip.split('.').reduce((acc, octet) => (acc << 8) + parseInt(octet, 10), 0) >>> 0;
|
||||
const netNum = network.split('.').reduce((acc, octet) => (acc << 8) + parseInt(octet, 10), 0) >>> 0;
|
||||
const maskNum = (0xffffffff << (32 - prefix)) >>> 0;
|
||||
|
||||
return (ipNum & maskNum) === (netNum & maskNum);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate configuration
|
||||
*/
|
||||
export function validateConfig(config: SnippetConfig): ValidationError[] {
|
||||
const errors: ValidationError[] = [];
|
||||
|
||||
// Validate CIDR
|
||||
if (!config.subnet.match(/^[\da-f:.]+\/\d+$/i)) {
|
||||
errors.push({ field: 'subnet', message: 'Invalid CIDR notation' });
|
||||
return errors;
|
||||
}
|
||||
|
||||
const isV6 = config.subnet.includes(':');
|
||||
const expectedMode = isV6 ? 'dhcp6' : 'dhcp4';
|
||||
|
||||
if (config.mode !== expectedMode) {
|
||||
errors.push({
|
||||
field: 'mode',
|
||||
message: `Mode mismatch: ${isV6 ? 'IPv6' : 'IPv4'} subnet requires ${expectedMode}`,
|
||||
});
|
||||
}
|
||||
|
||||
// Validate pools are within subnet
|
||||
config.pools.forEach((pool, i) => {
|
||||
if (!isIPInSubnet(pool.start, config.subnet)) {
|
||||
errors.push({ field: `pools[${i}].start`, message: 'Pool start IP outside subnet' });
|
||||
}
|
||||
if (!isIPInSubnet(pool.end, config.subnet)) {
|
||||
errors.push({ field: `pools[${i}].end`, message: 'Pool end IP outside subnet' });
|
||||
}
|
||||
});
|
||||
|
||||
// Validate gateway is within subnet
|
||||
if (config.gateway && !isIPInSubnet(config.gateway, config.subnet)) {
|
||||
errors.push({ field: 'gateway', message: 'Gateway IP outside subnet' });
|
||||
}
|
||||
|
||||
// Validate reservations
|
||||
config.reservations?.forEach((res, i) => {
|
||||
if (!isIPInSubnet(res.ipAddress, config.subnet)) {
|
||||
errors.push({
|
||||
field: `reservations[${i}].ipAddress`,
|
||||
message: 'Reservation IP outside subnet',
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
return errors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Encode Option 43 data
|
||||
*/
|
||||
function encodeOption43(addresses: string[], container: Option43Container, suboption: number): string {
|
||||
if (container === 'ascii') {
|
||||
// ASCII: comma-separated list
|
||||
return addresses.join(',');
|
||||
}
|
||||
|
||||
if (container === 'rawhex') {
|
||||
// Raw hex - user provides it
|
||||
return addresses[0] || '';
|
||||
}
|
||||
|
||||
// TLV encoding: suboption code (1 byte) + length (1 byte) + data
|
||||
const parts: string[] = [];
|
||||
addresses.forEach((addr) => {
|
||||
const octets = addr.split('.').map((o) => parseInt(o, 10));
|
||||
const dataHex = octets.map((o) => o.toString(16).padStart(2, '0')).join(':');
|
||||
const length = octets.length;
|
||||
const suboptHex = suboption.toString(16).padStart(2, '0');
|
||||
const lengthHex = length.toString(16).padStart(2, '0');
|
||||
parts.push(`${suboptHex}:${lengthHex}:${dataHex}`);
|
||||
});
|
||||
|
||||
return parts.join(':');
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate ISC dhcpd.conf snippet
|
||||
*/
|
||||
function generateISCSnippet(config: SnippetConfig): string {
|
||||
const { network, netmask } = parseCIDR(config.subnet);
|
||||
const lines: string[] = [];
|
||||
|
||||
lines.push(`# Subnet: ${config.subnet}`);
|
||||
lines.push(`subnet ${network} netmask ${netmask} {`);
|
||||
|
||||
// Options
|
||||
if (config.gateway) {
|
||||
lines.push(` option routers ${config.gateway};`);
|
||||
}
|
||||
if (config.dnsServers && config.dnsServers.length > 0) {
|
||||
lines.push(` option domain-name-servers ${config.dnsServers.join(', ')};`);
|
||||
}
|
||||
if (config.domainName) {
|
||||
lines.push(` option domain-name "${config.domainName}";`);
|
||||
}
|
||||
|
||||
// Lease times
|
||||
if (config.defaultLeaseTime) {
|
||||
lines.push(` default-lease-time ${config.defaultLeaseTime};`);
|
||||
}
|
||||
if (config.maxLeaseTime) {
|
||||
lines.push(` max-lease-time ${config.maxLeaseTime};`);
|
||||
}
|
||||
|
||||
lines.push('');
|
||||
|
||||
// Vendor discovery (global)
|
||||
if (
|
||||
config.vendorDiscovery &&
|
||||
config.vendorDiscovery.renderLocation === 'global' &&
|
||||
config.vendorDiscovery.controllerAddresses.length > 0
|
||||
) {
|
||||
const vd = config.vendorDiscovery;
|
||||
const option43 = encodeOption43(vd.controllerAddresses, vd.option43Container, vd.suboption || 1);
|
||||
|
||||
lines.push(` # Vendor discovery - ${VENDOR_PRESETS_43[vd.preset].name}`);
|
||||
if (vd.option60) {
|
||||
lines.push(` option vendor-class-identifier "${vd.option60}";`);
|
||||
}
|
||||
if (vd.option43Container === 'ascii') {
|
||||
lines.push(` option vendor-encapsulated-options "${option43}";`);
|
||||
} else {
|
||||
lines.push(` option vendor-encapsulated-options ${option43};`);
|
||||
}
|
||||
lines.push(` # Controllers: ${vd.controllerAddresses.join(', ')}`);
|
||||
lines.push('');
|
||||
}
|
||||
|
||||
// Pools
|
||||
config.pools.forEach((pool, i) => {
|
||||
lines.push(` # Pool ${i + 1}`);
|
||||
lines.push(` pool {`);
|
||||
lines.push(` range ${pool.start} ${pool.end};`);
|
||||
lines.push(` }`);
|
||||
lines.push('');
|
||||
});
|
||||
|
||||
lines.push(`}`);
|
||||
lines.push('');
|
||||
|
||||
// Client classes
|
||||
if (config.classes && config.classes.length > 0) {
|
||||
lines.push(`# Client classes`);
|
||||
config.classes.forEach((cls) => {
|
||||
lines.push(`class "${cls.name}" {`);
|
||||
lines.push(` match if ${cls.matchRule};`);
|
||||
if (cls.options?.option43) {
|
||||
lines.push(` option vendor-encapsulated-options ${cls.options.option43};`);
|
||||
}
|
||||
if (cls.options?.dns) {
|
||||
lines.push(` option domain-name-servers ${cls.options.dns.join(', ')};`);
|
||||
}
|
||||
lines.push(`}`);
|
||||
lines.push('');
|
||||
});
|
||||
}
|
||||
|
||||
// Host reservations
|
||||
if (config.reservations && config.reservations.length > 0) {
|
||||
lines.push(`# Static reservations`);
|
||||
config.reservations.forEach((res) => {
|
||||
const hostname = res.hostname || `host-${res.ipAddress.replace(/[.:]/g, '-')}`;
|
||||
lines.push(`host ${hostname} {`);
|
||||
lines.push(` hardware ethernet ${res.identifier};`);
|
||||
lines.push(` fixed-address ${res.ipAddress};`);
|
||||
if (res.hostname) {
|
||||
lines.push(` option host-name "${res.hostname}";`);
|
||||
}
|
||||
lines.push(`}`);
|
||||
lines.push('');
|
||||
});
|
||||
}
|
||||
|
||||
return lines.join('\n');
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate Kea DHCP snippet (JSON)
|
||||
*/
|
||||
function generateKeaSnippet(config: SnippetConfig, isV6: boolean): string {
|
||||
const obj: any = {
|
||||
subnet: config.subnet,
|
||||
pools: config.pools.map((p) => ({ pool: `${p.start} - ${p.end}` })),
|
||||
};
|
||||
|
||||
// Options
|
||||
const optionData: any[] = [];
|
||||
|
||||
if (config.gateway) {
|
||||
optionData.push({
|
||||
name: isV6 ? 'unicast' : 'routers',
|
||||
data: config.gateway,
|
||||
});
|
||||
}
|
||||
|
||||
if (config.dnsServers && config.dnsServers.length > 0) {
|
||||
optionData.push({
|
||||
name: 'dns-servers',
|
||||
data: config.dnsServers.join(', '),
|
||||
});
|
||||
}
|
||||
|
||||
if (config.domainName) {
|
||||
optionData.push({
|
||||
name: 'domain-name',
|
||||
data: config.domainName,
|
||||
});
|
||||
}
|
||||
|
||||
if (optionData.length > 0) {
|
||||
obj['option-data'] = optionData;
|
||||
}
|
||||
|
||||
// Lease times
|
||||
if (!isV6) {
|
||||
if (config.defaultLeaseTime) obj['valid-lifetime'] = config.defaultLeaseTime;
|
||||
if (config.maxLeaseTime) obj['max-valid-lifetime'] = config.maxLeaseTime;
|
||||
} else {
|
||||
if (config.preferredLifetime) obj['preferred-lifetime'] = config.preferredLifetime;
|
||||
if (config.validLifetime) obj['valid-lifetime'] = config.validLifetime;
|
||||
}
|
||||
|
||||
// Client classes
|
||||
if (config.classes && config.classes.length > 0) {
|
||||
obj['client-classes'] = config.classes.map((cls) => ({
|
||||
name: cls.name,
|
||||
test: cls.keaTest || cls.matchRule,
|
||||
}));
|
||||
}
|
||||
|
||||
// Reservations
|
||||
if (config.reservations && config.reservations.length > 0) {
|
||||
obj.reservations = config.reservations.map((res) => ({
|
||||
[isV6 ? 'duid' : 'hw-address']: res.identifier,
|
||||
'ip-address': res.ipAddress,
|
||||
hostname: res.hostname,
|
||||
}));
|
||||
}
|
||||
|
||||
return JSON.stringify(obj, null, config.prettyJson ? 2 : 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate summary text
|
||||
*/
|
||||
function generateSummary(config: SnippetConfig): string {
|
||||
const parts: string[] = [];
|
||||
|
||||
parts.push(`Subnet: ${config.subnet}`);
|
||||
parts.push(`Pools: ${config.pools.length} range(s)`);
|
||||
|
||||
if (config.gateway) parts.push(`Gateway: ${config.gateway}`);
|
||||
if (config.dnsServers && config.dnsServers.length > 0) {
|
||||
parts.push(`DNS: ${config.dnsServers.join(', ')}`);
|
||||
}
|
||||
|
||||
if (config.vendorDiscovery && config.vendorDiscovery.controllerAddresses.length > 0) {
|
||||
const vd = config.vendorDiscovery;
|
||||
parts.push(
|
||||
`Vendor discovery: ${VENDOR_PRESETS_43[vd.preset].name} (${vd.controllerAddresses.length} controller(s))`,
|
||||
);
|
||||
}
|
||||
|
||||
if (config.classes && config.classes.length > 0) {
|
||||
parts.push(`Client classes: ${config.classes.length}`);
|
||||
}
|
||||
|
||||
if (config.reservations && config.reservations.length > 0) {
|
||||
parts.push(`Static reservations: ${config.reservations.length}`);
|
||||
}
|
||||
|
||||
return parts.join(' • ');
|
||||
}
|
||||
|
||||
/**
|
||||
* Main generator function
|
||||
*/
|
||||
export function generateSnippets(config: SnippetConfig): SnippetResult {
|
||||
const validations = validateConfig(config);
|
||||
const result: SnippetResult = {
|
||||
validations,
|
||||
summary: generateSummary(config),
|
||||
};
|
||||
|
||||
if (validations.length > 0) {
|
||||
return result;
|
||||
}
|
||||
|
||||
const isV6 = config.mode === 'dhcp6';
|
||||
|
||||
if (config.targets.includes('isc-dhcpd')) {
|
||||
result.iscDhcpdSnippet = generateISCSnippet(config);
|
||||
}
|
||||
|
||||
if (config.targets.includes('kea-dhcp4') && !isV6) {
|
||||
result.keaDhcp4Snippet = generateKeaSnippet(config, false);
|
||||
}
|
||||
|
||||
if (config.targets.includes('kea-dhcp6') && isV6) {
|
||||
result.keaDhcp6Snippet = generateKeaSnippet(config, true);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get default configuration
|
||||
*/
|
||||
export function getDefaultSnippetConfig(): SnippetConfig {
|
||||
return {
|
||||
targets: ['isc-dhcpd', 'kea-dhcp4'],
|
||||
mode: 'dhcp4',
|
||||
subnet: '192.168.1.0/24',
|
||||
pools: [{ start: '192.168.1.100', end: '192.168.1.200' }],
|
||||
gateway: '192.168.1.1',
|
||||
dnsServers: ['8.8.8.8', '8.8.4.4'],
|
||||
defaultLeaseTime: 86400,
|
||||
maxLeaseTime: 604800,
|
||||
emitOptionNames: true,
|
||||
prettyJson: true,
|
||||
};
|
||||
}
|
||||
|
||||
export { VENDOR_PRESETS_43 };
|
||||
@@ -0,0 +1,11 @@
|
||||
<script lang="ts">
|
||||
import DHCPSnippetsGenerator from '$lib/components/tools/DHCPSnippetsGenerator.svelte';
|
||||
import ToolContentContainer from '$lib/components/global/ToolContentContainer.svelte';
|
||||
</script>
|
||||
|
||||
<ToolContentContainer
|
||||
title="DHCP Kea/ISC Snippets Generator"
|
||||
description="Generate complete subnet configurations for ISC dhcpd and Kea DHCP servers with vendor discovery options (Option 43/60), client classes, and static reservations."
|
||||
>
|
||||
<DHCPSnippetsGenerator />
|
||||
</ToolContentContainer>
|
||||
@@ -0,0 +1,452 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import {
|
||||
generateSnippets,
|
||||
validateConfig,
|
||||
getDefaultSnippetConfig,
|
||||
type SnippetConfig,
|
||||
type ValidationError,
|
||||
} from '$lib/utils/dhcp-snippets.js';
|
||||
|
||||
describe('DHCP Snippets Generator', () => {
|
||||
describe('getDefaultSnippetConfig', () => {
|
||||
it('should return valid default configuration', () => {
|
||||
const config = getDefaultSnippetConfig();
|
||||
|
||||
expect(config.targets).toEqual(['isc-dhcpd', 'kea-dhcp4']);
|
||||
expect(config.mode).toBe('dhcp4');
|
||||
expect(config.subnet).toBe('192.168.1.0/24');
|
||||
expect(config.pools).toHaveLength(1);
|
||||
expect(config.pools[0].start).toBe('192.168.1.100');
|
||||
expect(config.pools[0].end).toBe('192.168.1.200');
|
||||
expect(config.gateway).toBe('192.168.1.1');
|
||||
expect(config.dnsServers).toEqual(['8.8.8.8', '8.8.4.4']);
|
||||
expect(config.defaultLeaseTime).toBe(86400);
|
||||
expect(config.maxLeaseTime).toBe(604800);
|
||||
});
|
||||
});
|
||||
|
||||
describe('validateConfig', () => {
|
||||
it('should validate correct IPv4 configuration', () => {
|
||||
const config = getDefaultSnippetConfig();
|
||||
const errors = validateConfig(config);
|
||||
|
||||
expect(errors).toHaveLength(0);
|
||||
});
|
||||
|
||||
it('should detect invalid CIDR notation', () => {
|
||||
const config = getDefaultSnippetConfig();
|
||||
config.subnet = 'invalid';
|
||||
|
||||
const errors = validateConfig(config);
|
||||
|
||||
expect(errors).toHaveLength(1);
|
||||
expect(errors[0].field).toBe('subnet');
|
||||
expect(errors[0].message).toContain('Invalid CIDR notation');
|
||||
});
|
||||
|
||||
it('should detect mode mismatch for IPv4', () => {
|
||||
const config = getDefaultSnippetConfig();
|
||||
config.mode = 'dhcp6'; // IPv6 mode with IPv4 subnet
|
||||
|
||||
const errors = validateConfig(config);
|
||||
|
||||
expect(errors.some((e) => e.field === 'mode')).toBe(true);
|
||||
});
|
||||
|
||||
it('should detect mode mismatch for IPv6', () => {
|
||||
const config = getDefaultSnippetConfig();
|
||||
config.subnet = '2001:db8::/64';
|
||||
config.mode = 'dhcp4'; // IPv4 mode with IPv6 subnet
|
||||
|
||||
const errors = validateConfig(config);
|
||||
|
||||
expect(errors.some((e) => e.field === 'mode')).toBe(true);
|
||||
});
|
||||
|
||||
it('should detect pool start IP outside subnet', () => {
|
||||
const config = getDefaultSnippetConfig();
|
||||
config.pools[0].start = '10.0.0.1'; // Outside 192.168.1.0/24
|
||||
|
||||
const errors = validateConfig(config);
|
||||
|
||||
expect(errors.some((e) => e.field === 'pools[0].start')).toBe(true);
|
||||
});
|
||||
|
||||
it('should detect pool end IP outside subnet', () => {
|
||||
const config = getDefaultSnippetConfig();
|
||||
config.pools[0].end = '10.0.0.254'; // Outside 192.168.1.0/24
|
||||
|
||||
const errors = validateConfig(config);
|
||||
|
||||
expect(errors.some((e) => e.field === 'pools[0].end')).toBe(true);
|
||||
});
|
||||
|
||||
it('should detect gateway outside subnet', () => {
|
||||
const config = getDefaultSnippetConfig();
|
||||
config.gateway = '10.0.0.1'; // Outside 192.168.1.0/24
|
||||
|
||||
const errors = validateConfig(config);
|
||||
|
||||
expect(errors.some((e) => e.field === 'gateway')).toBe(true);
|
||||
});
|
||||
|
||||
it('should validate IPv6 configuration', () => {
|
||||
const config = getDefaultSnippetConfig();
|
||||
config.mode = 'dhcp6';
|
||||
config.subnet = '2001:db8::/64';
|
||||
config.pools = [{ start: '2001:db8::100', end: '2001:db8::200' }];
|
||||
config.gateway = '2001:db8::1';
|
||||
|
||||
const errors = validateConfig(config);
|
||||
|
||||
expect(errors).toHaveLength(0);
|
||||
});
|
||||
|
||||
it('should validate multiple pools', () => {
|
||||
const config = getDefaultSnippetConfig();
|
||||
config.pools = [
|
||||
{ start: '192.168.1.10', end: '192.168.1.50' },
|
||||
{ start: '192.168.1.100', end: '192.168.1.200' },
|
||||
];
|
||||
|
||||
const errors = validateConfig(config);
|
||||
|
||||
expect(errors).toHaveLength(0);
|
||||
});
|
||||
|
||||
it('should detect multiple validation errors', () => {
|
||||
const config = getDefaultSnippetConfig();
|
||||
config.pools[0].start = '10.0.0.1';
|
||||
config.pools[0].end = '10.0.0.254';
|
||||
config.gateway = '172.16.0.1';
|
||||
|
||||
const errors = validateConfig(config);
|
||||
|
||||
expect(errors.length).toBeGreaterThan(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('generateSnippets', () => {
|
||||
it('should generate ISC dhcpd snippet', () => {
|
||||
const config = getDefaultSnippetConfig();
|
||||
const result = generateSnippets(config);
|
||||
|
||||
expect(result.iscDhcpdSnippet).toBeDefined();
|
||||
expect(result.iscDhcpdSnippet).toContain('subnet 192.168.1.0 netmask 255.255.255.0');
|
||||
expect(result.iscDhcpdSnippet).toContain('option routers 192.168.1.1');
|
||||
expect(result.iscDhcpdSnippet).toContain('option domain-name-servers 8.8.8.8, 8.8.4.4');
|
||||
expect(result.iscDhcpdSnippet).toContain('range 192.168.1.100 192.168.1.200');
|
||||
expect(result.iscDhcpdSnippet).toContain('default-lease-time 86400');
|
||||
expect(result.iscDhcpdSnippet).toContain('max-lease-time 604800');
|
||||
});
|
||||
|
||||
it('should generate Kea DHCPv4 snippet', () => {
|
||||
const config = getDefaultSnippetConfig();
|
||||
const result = generateSnippets(config);
|
||||
|
||||
expect(result.keaDhcp4Snippet).toBeDefined();
|
||||
|
||||
const keaConfig = JSON.parse(result.keaDhcp4Snippet!);
|
||||
expect(keaConfig.subnet).toBe('192.168.1.0/24');
|
||||
expect(keaConfig.pools).toHaveLength(1);
|
||||
expect(keaConfig.pools[0].pool).toBe('192.168.1.100 - 192.168.1.200');
|
||||
expect(keaConfig['option-data']).toBeDefined();
|
||||
expect(keaConfig['valid-lifetime']).toBe(86400);
|
||||
});
|
||||
|
||||
it('should generate Kea DHCPv6 snippet', () => {
|
||||
const config = getDefaultSnippetConfig();
|
||||
config.mode = 'dhcp6';
|
||||
config.subnet = '2001:db8::/64';
|
||||
config.pools = [{ start: '2001:db8::100', end: '2001:db8::200' }];
|
||||
config.gateway = '2001:db8::1';
|
||||
config.targets = ['kea-dhcp6'];
|
||||
config.preferredLifetime = 3600;
|
||||
config.validLifetime = 7200;
|
||||
|
||||
const result = generateSnippets(config);
|
||||
|
||||
expect(result.keaDhcp6Snippet).toBeDefined();
|
||||
|
||||
const keaConfig = JSON.parse(result.keaDhcp6Snippet!);
|
||||
expect(keaConfig.subnet).toBe('2001:db8::/64');
|
||||
expect(keaConfig['preferred-lifetime']).toBe(3600);
|
||||
expect(keaConfig['valid-lifetime']).toBe(7200);
|
||||
});
|
||||
|
||||
it('should generate summary', () => {
|
||||
const config = getDefaultSnippetConfig();
|
||||
const result = generateSnippets(config);
|
||||
|
||||
expect(result.summary).toContain('Subnet: 192.168.1.0/24');
|
||||
expect(result.summary).toContain('Pools: 1 range(s)');
|
||||
expect(result.summary).toContain('Gateway: 192.168.1.1');
|
||||
expect(result.summary).toContain('DNS: 8.8.8.8, 8.8.4.4');
|
||||
});
|
||||
|
||||
it('should not generate snippets when validation fails', () => {
|
||||
const config = getDefaultSnippetConfig();
|
||||
config.subnet = 'invalid';
|
||||
|
||||
const result = generateSnippets(config);
|
||||
|
||||
expect(result.validations).toHaveLength(1);
|
||||
expect(result.iscDhcpdSnippet).toBeUndefined();
|
||||
expect(result.keaDhcp4Snippet).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should handle multiple pools in ISC snippet', () => {
|
||||
const config = getDefaultSnippetConfig();
|
||||
config.pools = [
|
||||
{ start: '192.168.1.10', end: '192.168.1.50' },
|
||||
{ start: '192.168.1.100', end: '192.168.1.200' },
|
||||
];
|
||||
|
||||
const result = generateSnippets(config);
|
||||
|
||||
expect(result.iscDhcpdSnippet).toContain('# Pool 1');
|
||||
expect(result.iscDhcpdSnippet).toContain('# Pool 2');
|
||||
expect(result.iscDhcpdSnippet).toContain('range 192.168.1.10 192.168.1.50');
|
||||
expect(result.iscDhcpdSnippet).toContain('range 192.168.1.100 192.168.1.200');
|
||||
});
|
||||
|
||||
it('should include domain name when provided', () => {
|
||||
const config = getDefaultSnippetConfig();
|
||||
config.domainName = 'example.com';
|
||||
|
||||
const result = generateSnippets(config);
|
||||
|
||||
expect(result.iscDhcpdSnippet).toContain('option domain-name "example.com"');
|
||||
});
|
||||
|
||||
it('should generate only selected target snippets', () => {
|
||||
const config = getDefaultSnippetConfig();
|
||||
config.targets = ['isc-dhcpd'];
|
||||
|
||||
const result = generateSnippets(config);
|
||||
|
||||
expect(result.iscDhcpdSnippet).toBeDefined();
|
||||
expect(result.keaDhcp4Snippet).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should handle pretty JSON formatting', () => {
|
||||
const config = getDefaultSnippetConfig();
|
||||
config.prettyJson = true;
|
||||
|
||||
const result = generateSnippets(config);
|
||||
|
||||
expect(result.keaDhcp4Snippet).toContain('\n');
|
||||
expect(result.keaDhcp4Snippet).toContain(' ');
|
||||
});
|
||||
|
||||
it('should handle compact JSON formatting', () => {
|
||||
const config = getDefaultSnippetConfig();
|
||||
config.prettyJson = false;
|
||||
|
||||
const result = generateSnippets(config);
|
||||
|
||||
expect(result.keaDhcp4Snippet).not.toContain('\n ');
|
||||
});
|
||||
});
|
||||
|
||||
describe('ISC DHCP specific features', () => {
|
||||
it('should correctly convert /24 to netmask', () => {
|
||||
const config = getDefaultSnippetConfig();
|
||||
config.subnet = '192.168.1.0/24';
|
||||
|
||||
const result = generateSnippets(config);
|
||||
|
||||
expect(result.iscDhcpdSnippet).toContain('netmask 255.255.255.0');
|
||||
});
|
||||
|
||||
it('should correctly convert /16 to netmask', () => {
|
||||
const config = getDefaultSnippetConfig();
|
||||
config.subnet = '172.16.0.0/16';
|
||||
config.pools = [{ start: '172.16.1.1', end: '172.16.1.254' }];
|
||||
config.gateway = '172.16.0.1';
|
||||
|
||||
const result = generateSnippets(config);
|
||||
|
||||
expect(result.iscDhcpdSnippet).toContain('netmask 255.255.0.0');
|
||||
});
|
||||
|
||||
it('should correctly convert /8 to netmask', () => {
|
||||
const config = getDefaultSnippetConfig();
|
||||
config.subnet = '10.0.0.0/8';
|
||||
config.pools = [{ start: '10.0.1.1', end: '10.0.1.254' }];
|
||||
config.gateway = '10.0.0.1';
|
||||
|
||||
const result = generateSnippets(config);
|
||||
|
||||
expect(result.iscDhcpdSnippet).toContain('netmask 255.0.0.0');
|
||||
});
|
||||
|
||||
it('should handle non-standard subnet masks', () => {
|
||||
const config = getDefaultSnippetConfig();
|
||||
config.subnet = '192.168.1.0/25';
|
||||
config.pools = [{ start: '192.168.1.1', end: '192.168.1.126' }];
|
||||
config.gateway = '192.168.1.127';
|
||||
|
||||
const result = generateSnippets(config);
|
||||
|
||||
expect(result.iscDhcpdSnippet).toContain('netmask 255.255.255.128');
|
||||
});
|
||||
});
|
||||
|
||||
describe('Kea DHCP specific features', () => {
|
||||
it('should use correct option names for IPv4', () => {
|
||||
const config = getDefaultSnippetConfig();
|
||||
const result = generateSnippets(config);
|
||||
|
||||
const keaConfig = JSON.parse(result.keaDhcp4Snippet!);
|
||||
const routerOption = keaConfig['option-data'].find((opt: any) => opt.name === 'routers');
|
||||
|
||||
expect(routerOption).toBeDefined();
|
||||
expect(routerOption.data).toBe('192.168.1.1');
|
||||
});
|
||||
|
||||
it('should include DNS servers in option-data', () => {
|
||||
const config = getDefaultSnippetConfig();
|
||||
const result = generateSnippets(config);
|
||||
|
||||
const keaConfig = JSON.parse(result.keaDhcp4Snippet!);
|
||||
const dnsOption = keaConfig['option-data'].find((opt: any) => opt.name === 'dns-servers');
|
||||
|
||||
expect(dnsOption).toBeDefined();
|
||||
expect(dnsOption.data).toBe('8.8.8.8, 8.8.4.4');
|
||||
});
|
||||
|
||||
it('should not generate IPv4 snippet when mode is IPv6', () => {
|
||||
const config = getDefaultSnippetConfig();
|
||||
config.mode = 'dhcp6';
|
||||
config.subnet = '2001:db8::/64';
|
||||
config.pools = [{ start: '2001:db8::100', end: '2001:db8::200' }];
|
||||
|
||||
const result = generateSnippets(config);
|
||||
|
||||
expect(result.keaDhcp4Snippet).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should not generate IPv6 snippet when mode is IPv4', () => {
|
||||
const config = getDefaultSnippetConfig();
|
||||
config.targets = ['kea-dhcp6'];
|
||||
|
||||
const result = generateSnippets(config);
|
||||
|
||||
expect(result.keaDhcp6Snippet).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe('Edge cases', () => {
|
||||
it('should handle empty DNS servers', () => {
|
||||
const config = getDefaultSnippetConfig();
|
||||
config.dnsServers = [];
|
||||
|
||||
const result = generateSnippets(config);
|
||||
|
||||
expect(result.iscDhcpdSnippet).not.toContain('option domain-name-servers');
|
||||
});
|
||||
|
||||
it('should handle missing gateway', () => {
|
||||
const config = getDefaultSnippetConfig();
|
||||
config.gateway = undefined;
|
||||
|
||||
const result = generateSnippets(config);
|
||||
|
||||
expect(result.iscDhcpdSnippet).not.toContain('option routers');
|
||||
});
|
||||
|
||||
it('should handle missing domain name', () => {
|
||||
const config = getDefaultSnippetConfig();
|
||||
config.domainName = undefined;
|
||||
|
||||
const result = generateSnippets(config);
|
||||
|
||||
expect(result.iscDhcpdSnippet).not.toContain('option domain-name "');
|
||||
});
|
||||
|
||||
it('should handle /32 subnet', () => {
|
||||
const config = getDefaultSnippetConfig();
|
||||
config.subnet = '192.168.1.1/32';
|
||||
config.pools = [{ start: '192.168.1.1', end: '192.168.1.1' }];
|
||||
config.gateway = '192.168.1.1';
|
||||
|
||||
const result = generateSnippets(config);
|
||||
|
||||
expect(result.iscDhcpdSnippet).toContain('netmask 255.255.255.255');
|
||||
});
|
||||
|
||||
it('should handle large subnet (/8)', () => {
|
||||
const config = getDefaultSnippetConfig();
|
||||
config.subnet = '10.0.0.0/8';
|
||||
config.pools = [{ start: '10.1.1.1', end: '10.1.1.254' }];
|
||||
config.gateway = '10.0.0.1';
|
||||
|
||||
const errors = validateConfig(config);
|
||||
|
||||
expect(errors).toHaveLength(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Summary generation', () => {
|
||||
it('should include all configured options in summary', () => {
|
||||
const config = getDefaultSnippetConfig();
|
||||
config.domainName = 'test.local';
|
||||
|
||||
const result = generateSnippets(config);
|
||||
|
||||
expect(result.summary).toContain('Subnet');
|
||||
expect(result.summary).toContain('Pools');
|
||||
expect(result.summary).toContain('Gateway');
|
||||
expect(result.summary).toContain('DNS');
|
||||
});
|
||||
|
||||
it('should handle summary with multiple pools', () => {
|
||||
const config = getDefaultSnippetConfig();
|
||||
config.pools = [
|
||||
{ start: '192.168.1.10', end: '192.168.1.50' },
|
||||
{ start: '192.168.1.100', end: '192.168.1.200' },
|
||||
{ start: '192.168.1.210', end: '192.168.1.250' },
|
||||
];
|
||||
|
||||
const result = generateSnippets(config);
|
||||
|
||||
expect(result.summary).toContain('Pools: 3 range(s)');
|
||||
});
|
||||
});
|
||||
|
||||
describe('Validation error messages', () => {
|
||||
it('should provide clear error for pool outside subnet', () => {
|
||||
const config = getDefaultSnippetConfig();
|
||||
config.pools[0].start = '10.0.0.1';
|
||||
|
||||
const errors = validateConfig(config);
|
||||
const poolError = errors.find((e) => e.field === 'pools[0].start');
|
||||
|
||||
expect(poolError).toBeDefined();
|
||||
expect(poolError?.message).toBe('Pool start IP outside subnet');
|
||||
});
|
||||
|
||||
it('should provide clear error for gateway outside subnet', () => {
|
||||
const config = getDefaultSnippetConfig();
|
||||
config.gateway = '10.0.0.1';
|
||||
|
||||
const errors = validateConfig(config);
|
||||
const gatewayError = errors.find((e) => e.field === 'gateway');
|
||||
|
||||
expect(gatewayError).toBeDefined();
|
||||
expect(gatewayError?.message).toBe('Gateway IP outside subnet');
|
||||
});
|
||||
|
||||
it('should provide clear error for mode mismatch', () => {
|
||||
const config = getDefaultSnippetConfig();
|
||||
config.mode = 'dhcp6';
|
||||
|
||||
const errors = validateConfig(config);
|
||||
const modeError = errors.find((e) => e.field === 'mode');
|
||||
|
||||
expect(modeError).toBeDefined();
|
||||
expect(modeError?.message).toContain('Mode mismatch');
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user