Files
RouterOS/RouterOSAssistant/Core/Models/WanConfig.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

78 lines
2.7 KiB
Swift

import Foundation
enum WanConnectionMode: String, CaseIterable, Identifiable {
case dhcpClient
case staticIP
case pppoe
var id: String { rawValue }
var label: String {
switch self {
case .dhcpClient: return "Automatisch (DHCP)"
case .staticIP: return "Statische IP-Adresse"
case .pppoe: return "PPPoE (DSL-Zugangsdaten)"
}
}
}
struct WanConfig: Equatable {
var interfaceName: String
var mode: WanConnectionMode = .dhcpClient
var staticAddress: String = ""
var staticGateway: String = ""
var pppoeUsername: String = ""
var pppoePassword: String = ""
/// RouterOS commands for this WAN setup. Standard, long-stable RouterOS CLI syntax —
/// not yet verified against a live device; the Review-step shows every command before
/// it runs so this can be caught before anything is applied.
func buildCommands() -> [RouterOSCommand] {
switch mode {
case .dhcpClient:
return [
RouterOSCommand.add(
menuPath: "/ip dhcp-client",
restPath: "ip/dhcp-client",
arguments: ["interface": interfaceName, "disabled": "no"],
summary: "Internetadresse auf \(interfaceName) automatisch beziehen (DHCP-Client)"
)
]
case .staticIP:
var commands = [
RouterOSCommand.add(
menuPath: "/ip address",
restPath: "ip/address",
arguments: ["address": staticAddress, "interface": interfaceName],
summary: "Statische IP-Adresse \(staticAddress) auf \(interfaceName) setzen"
)
]
if !staticGateway.isEmpty {
commands.append(
RouterOSCommand.add(
menuPath: "/ip route",
restPath: "ip/route",
arguments: ["gateway": staticGateway],
summary: "Standard-Route über \(staticGateway) einrichten"
)
)
}
return commands
case .pppoe:
return [
RouterOSCommand.add(
menuPath: "/interface pppoe-client",
restPath: "interface/pppoe-client",
arguments: [
"interface": interfaceName,
"user": pppoeUsername,
"password": pppoePassword,
"disabled": "no"
],
summary: "PPPoE-Internetverbindung auf \(interfaceName) mit Zugangsdaten deines Anbieters einrichten"
)
]
}
}
}