forked from kay/RouterOS
Neuer "Einrichten"-Tab führt durch Internet-Anschluss (DHCP/statisch/ PPPoE) und Heimnetzwerk+DHCP-Server, zeigt vor dem Anwenden eine Klartext-Übersicht (optional mit den exakten RouterOS-Befehlen) und erstellt automatisch eine Sicherung, bevor Änderungen geschrieben werden. Änderungen laufen über beide Transporte: CLI-Zeile für SSH, JSON-POST für REST — beide aus einem gemeinsamen RouterOSCommand gebaut. RouterOS-CLI-Syntax ist Standard und langjährig stabil, aber nicht gegen ein echtes Gerät verifiziert; deshalb die Detailanzeige im Übersichtsschritt vor dem Anwenden. ConnectionService ist jetzt der einzige App-weite Zustand (ersetzt SessionStore) und wird explizit an alle drei Tabs durchgereicht. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HReLXMbmPvtQ23p1iWiJNW
78 lines
2.7 KiB
Swift
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(
|
|
cliPath: "/ip dhcp-client add",
|
|
restPath: "ip/dhcp-client",
|
|
arguments: ["interface": interfaceName, "disabled": "no"],
|
|
summary: "Internetadresse auf \(interfaceName) automatisch beziehen (DHCP-Client)"
|
|
)
|
|
]
|
|
case .staticIP:
|
|
var commands = [
|
|
RouterOSCommand(
|
|
cliPath: "/ip address add",
|
|
restPath: "ip/address",
|
|
arguments: ["address": staticAddress, "interface": interfaceName],
|
|
summary: "Statische IP-Adresse \(staticAddress) auf \(interfaceName) setzen"
|
|
)
|
|
]
|
|
if !staticGateway.isEmpty {
|
|
commands.append(
|
|
RouterOSCommand(
|
|
cliPath: "/ip route add",
|
|
restPath: "ip/route",
|
|
arguments: ["gateway": staticGateway],
|
|
summary: "Standard-Route über \(staticGateway) einrichten"
|
|
)
|
|
)
|
|
}
|
|
return commands
|
|
case .pppoe:
|
|
return [
|
|
RouterOSCommand(
|
|
cliPath: "/interface pppoe-client add",
|
|
restPath: "interface/pppoe-client",
|
|
arguments: [
|
|
"interface": interfaceName,
|
|
"user": pppoeUsername,
|
|
"password": pppoePassword,
|
|
"disabled": "no"
|
|
],
|
|
summary: "PPPoE-Internetverbindung auf \(interfaceName) mit Zugangsdaten deines Anbieters einrichten"
|
|
)
|
|
]
|
|
}
|
|
}
|
|
}
|