forked from kay/RouterOS
M3: WAN + LAN/DHCP-Wizard mit Anwenden-Logik
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
This commit is contained in:
@@ -17,6 +17,7 @@ private final class MockTransport: RouterOSTransport {
|
||||
|
||||
func fetchDeviceInfo() async throws -> RouterDeviceInfo { deviceInfo }
|
||||
func fetchInterfaces() async throws -> [NetworkInterface] { [] }
|
||||
func apply(_ command: RouterOSCommand) async throws {}
|
||||
func disconnect() async {}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
import XCTest
|
||||
@testable import RouterOSAssistant
|
||||
|
||||
final class RouterOSCommandBuilderTests: XCTestCase {
|
||||
func testWanDhcpClientCommand() {
|
||||
let config = WanConfig(interfaceName: "ether1", mode: .dhcpClient)
|
||||
let commands = config.buildCommands()
|
||||
|
||||
XCTAssertEqual(commands.count, 1)
|
||||
XCTAssertEqual(commands[0].cliPath, "/ip dhcp-client add")
|
||||
XCTAssertEqual(commands[0].arguments["interface"], "ether1")
|
||||
}
|
||||
|
||||
func testWanStaticIPCommandsIncludeRouteOnlyWhenGatewayGiven() {
|
||||
var config = WanConfig(interfaceName: "ether1", mode: .staticIP)
|
||||
config.staticAddress = "203.0.113.5/24"
|
||||
|
||||
XCTAssertEqual(config.buildCommands().count, 1)
|
||||
|
||||
config.staticGateway = "203.0.113.1"
|
||||
let commands = config.buildCommands()
|
||||
|
||||
XCTAssertEqual(commands.count, 2)
|
||||
XCTAssertEqual(commands[0].arguments["address"], "203.0.113.5/24")
|
||||
XCTAssertEqual(commands[1].arguments["gateway"], "203.0.113.1")
|
||||
}
|
||||
|
||||
func testWanPppoeCommand() {
|
||||
var config = WanConfig(interfaceName: "ether1", mode: .pppoe)
|
||||
config.pppoeUsername = "user@isp"
|
||||
config.pppoePassword = "secret"
|
||||
|
||||
let commands = config.buildCommands()
|
||||
|
||||
XCTAssertEqual(commands.count, 1)
|
||||
XCTAssertEqual(commands[0].cliPath, "/interface pppoe-client add")
|
||||
XCTAssertEqual(commands[0].arguments["user"], "user@isp")
|
||||
XCTAssertEqual(commands[0].arguments["password"], "secret")
|
||||
}
|
||||
|
||||
func testLanDhcpCommandsCoverAddressPoolServerAndNetwork() {
|
||||
let config = LanDhcpConfig()
|
||||
let commands = config.buildCommands()
|
||||
|
||||
XCTAssertEqual(commands.count, 4)
|
||||
XCTAssertEqual(commands[0].cliPath, "/ip address add")
|
||||
XCTAssertEqual(commands[1].cliPath, "/ip pool add")
|
||||
XCTAssertEqual(commands[2].cliPath, "/ip dhcp-server add")
|
||||
XCTAssertEqual(commands[3].cliPath, "/ip dhcp-server network add")
|
||||
XCTAssertEqual(commands[3].arguments["gateway"], "192.168.88.1")
|
||||
}
|
||||
|
||||
func testCliLineRendersSortedQuotedArguments() {
|
||||
let command = RouterOSCommand(
|
||||
cliPath: "/interface pppoe-client add",
|
||||
restPath: "interface/pppoe-client",
|
||||
arguments: ["user": "user@isp", "password": "a secret"],
|
||||
summary: "test"
|
||||
)
|
||||
|
||||
XCTAssertEqual(command.cliLine, "/interface pppoe-client add password=\"a secret\" user=user@isp")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user