Files
RouterOS/RouterOSAssistant/Core/Models/DhcpServerCommandBuilder.swift
T
KayandClaude Sonnet 5 016f57f613 M5: WLAN-Schritt + echte set-Operation im Befehlsmodell
RouterOSCommand unterstützt jetzt neben .add auch .set (bestehenden
Eintrag ändern statt neuen anzulegen) — nötig, weil WLAN-Interfaces
schon vor jeder Konfiguration existieren. SSH löst das per CLI-eigenem
"set [find field=value] ..." inline auf; REST hat dafür keine
Entsprechung und muss den Eintrag erst per GET suchen (matchField/
matchValue), seine .id auslesen, dann PATCH auf restPath/<id> senden
(RestTransport.findItemID). Mit dem Nutzer abgestimmte Entscheidung
gegen die einfachere "WLAN nur über SSH"-Variante.

WifiNetworkConfig: pro erkanntem Legacy-Wireless-Interface
(/interface wireless, type=wlan) eine SSID/Passwort-Konfiguration,
Sicherheitsprofil (WPA2) wird zuerst angelegt, dann per set mit dem
Interface verknüpft. Geräte ohne WLAN zeigen einen Hinweistext statt
des Formulars (User-Anforderung: muss berücksichtigt werden). Geräte
mit dem neueren "wifi"-Treiber (type=wifi, wifiwave2/802.11ax) werden
erkannt, aber bewusst nicht unterstützt -- anderes Menü, eigener
Umbau nötig, dazu Hinweistext.

cliPath wurde in allen bisherigen Command-Buildern (Wan/Lan/Vlan) zu
menuPath + .add migriert, da RouterOSCommand jetzt operation-basiert
ist statt den Aktionswort im Pfad-String zu verstecken.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HReLXMbmPvtQ23p1iWiJNW
2026-09-12 13:41:25 +02:00

58 lines
2.2 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import Foundation
/// Shared command set for "IP address + DHCP pool + DHCP server + DHCP network on one
/// interface" — used by the LAN step directly and, per entry, by the VLAN step.
enum DhcpServerCommandBuilder {
static func buildCommands(
interfaceName: String,
routerAddress: String,
networkAddress: String,
poolRangeStart: String,
poolRangeEnd: String,
leaseTimeHours: Int,
dnsServers: String,
context: String
) -> [RouterOSCommand] {
let poolName = "dhcp_pool_\(interfaceName)"
let serverName = "dhcp_\(interfaceName)"
let routerIP = routerAddress.components(separatedBy: "/").first ?? routerAddress
return [
RouterOSCommand.add(
menuPath: "/ip address",
restPath: "ip/address",
arguments: ["address": routerAddress, "interface": interfaceName],
summary: "IP-Adresse \(routerAddress) \(context) setzen"
),
RouterOSCommand.add(
menuPath: "/ip pool",
restPath: "ip/pool",
arguments: ["name": poolName, "ranges": "\(poolRangeStart)-\(poolRangeEnd)"],
summary: "Adressbereich \(poolRangeStart)\(poolRangeEnd) \(context) anlegen"
),
RouterOSCommand.add(
menuPath: "/ip dhcp-server",
restPath: "ip/dhcp-server",
arguments: [
"name": serverName,
"interface": interfaceName,
"address-pool": poolName,
"lease-time": "\(leaseTimeHours)h",
"disabled": "no"
],
summary: "DHCP-Server \(context) aktivieren"
),
RouterOSCommand.add(
menuPath: "/ip dhcp-server network",
restPath: "ip/dhcp-server/network",
arguments: [
"address": networkAddress,
"gateway": routerIP,
"dns-server": dnsServers
],
summary: "DHCP-Netzwerk \(networkAddress) \(context) konfigurieren"
)
]
}
}