forked from kay/RouterOS
XcodeGen-basiertes SwiftUI-Projekt für den RouterOS-Interview-Assistenten. Erster Wizard-Schritt: Verbindung zu Mikrotik-Geräten per REST-API (RouterOS >=7.1) mit SSH-CLI-Fallback für ältere Firmware, Zertifikats- TOFU-Bestätigung, Zugangsdaten im Keychain. Unit-Tests für CLI-Parser und Fallback-Logik. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HReLXMbmPvtQ23p1iWiJNW
35 lines
1017 B
Swift
35 lines
1017 B
Swift
import Foundation
|
|
|
|
@MainActor
|
|
final class ConnectViewModel: ObservableObject {
|
|
@Published var host: String = "192.168.88.1"
|
|
@Published var username: String = "admin"
|
|
@Published var password: String = ""
|
|
@Published var rememberPassword: Bool = true
|
|
|
|
let connectionService = ConnectionService()
|
|
private let keychain = KeychainService()
|
|
|
|
func onAppear() {
|
|
if let saved = keychain.loadPassword(forHost: host, username: username) {
|
|
password = saved
|
|
}
|
|
}
|
|
|
|
func connect() {
|
|
let credentials = RouterOSCredentials(host: host, username: username, password: password)
|
|
if rememberPassword {
|
|
keychain.save(password: password, forHost: host, username: username)
|
|
}
|
|
Task {
|
|
await connectionService.connect(with: credentials)
|
|
}
|
|
}
|
|
|
|
func trustAndRetry(fingerprint: String) {
|
|
Task {
|
|
await connectionService.trustCurrentCertificateAndRetry(fingerprint: fingerprint)
|
|
}
|
|
}
|
|
}
|