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
57 lines
2.2 KiB
Swift
57 lines
2.2 KiB
Swift
import Foundation
|
|
|
|
/// One additional virtual network: a VLAN interface on top of an existing (typically LAN
|
|
/// bridge) interface, with its own IP range and DHCP server — e.g. a guest or IoT network.
|
|
/// Deliberately not port-based (no access/trunk assignment): that needs RouterOS bridge
|
|
/// VLAN filtering, which requires "set" operations our REST/SSH command model doesn't
|
|
/// support yet (it only ever creates new items). Someone who needs a VLAN on a specific
|
|
/// switch port still has to configure that port as a tagged trunk manually.
|
|
struct VlanEntry: Identifiable, Equatable {
|
|
var id = UUID()
|
|
var name: String
|
|
var vlanID: Int
|
|
var parentInterface: String
|
|
var networkAddress: String
|
|
var routerAddress: String
|
|
var poolRangeStart: String
|
|
var poolRangeEnd: String
|
|
var leaseTimeHours: Int = 24
|
|
var dnsServers: String
|
|
|
|
init(name: String = "Gäste", vlanID: Int, parentInterface: String) {
|
|
self.name = name
|
|
self.vlanID = vlanID
|
|
self.parentInterface = parentInterface
|
|
let octet = vlanID % 256
|
|
self.networkAddress = "192.168.\(octet).0/24"
|
|
self.routerAddress = "192.168.\(octet).1/24"
|
|
self.poolRangeStart = "192.168.\(octet).10"
|
|
self.poolRangeEnd = "192.168.\(octet).254"
|
|
self.dnsServers = "192.168.\(octet).1"
|
|
}
|
|
|
|
var interfaceName: String { "vlan\(vlanID)" }
|
|
|
|
func buildCommands() -> [RouterOSCommand] {
|
|
let createVlan = RouterOSCommand.add(
|
|
menuPath: "/interface vlan",
|
|
restPath: "interface/vlan",
|
|
arguments: ["name": interfaceName, "vlan-id": "\(vlanID)", "interface": parentInterface],
|
|
summary: "VLAN \"\(name)\" (ID \(vlanID)) auf \(parentInterface) anlegen"
|
|
)
|
|
|
|
let dhcpCommands = DhcpServerCommandBuilder.buildCommands(
|
|
interfaceName: interfaceName,
|
|
routerAddress: routerAddress,
|
|
networkAddress: networkAddress,
|
|
poolRangeStart: poolRangeStart,
|
|
poolRangeEnd: poolRangeEnd,
|
|
leaseTimeHours: leaseTimeHours,
|
|
dnsServers: dnsServers,
|
|
context: "für VLAN \"\(name)\""
|
|
)
|
|
|
|
return [createVlan] + dhcpCommands
|
|
}
|
|
}
|