Files
RouterOS/RouterOSAssistant/Core/Services/FactoryResetService.swift
T
KayandClaude Sonnet 5 a93a61c84f Werkseinstellungen wiederherstellen (Gefahrenzone im Sicherungen-Tab)
RouterOS bringt eine eigene Standardkonfiguration mit, wiederherstellbar
über /system reset-configuration no-defaults=no -- restauriert die vom
Hersteller ausgelieferte Konfiguration (nicht eine leere), RouterOS legt
dabei selbst zusätzlich ein Backup an (skip-backup=no, Standard).

FactoryResetService läuft wie BackupService immer über eine eigene
SSH-Verbindung (kein verifiziertes REST-Äquivalent, passt nicht ins
add/set-Modell von RouterOSCommand). Vor dem Zurücksetzen erstellt die
App zusätzlich selbst ein Backup (best-effort). Verbindung zum Router
bricht durch den Reboot erwartungsgemäß ab -- wird nicht als Fehler
behandelt, ConnectionService trennt sich danach selbst.

UI: rot markierte "Gefahrenzone" im Sicherungen-Tab, destruktiver
Bestätigungsdialog vor dem Ausführen, klarer Hinweistext was verloren
geht.

Außerdem .gitignore um /Backups/ und *.rsc ergänzt -- beim Testen des
wählbaren Backup-Ordners landete ein echter Router-Export im
Projektordner, gehört nicht ins Repo.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HReLXMbmPvtQ23p1iWiJNW
2026-09-12 20:52:23 +02:00

22 lines
1.3 KiB
Swift

import Foundation
/// Restores the router's own vendor-default configuration via RouterOS' built-in
/// `/system reset-configuration` — not a restore of one of our own backup files, the actual
/// factory default the device shipped with. Always runs over a dedicated SSH connection, same
/// reasoning as BackupService: this is a one-shot system action, not a menu item to add/set,
/// so it doesn't fit the REST-mirrors-menu-items model RouterOSCommand assumes, and there's no
/// verified REST equivalent to fall back on.
final class FactoryResetService {
/// `no-defaults=no` restores the vendor default config (not a blank slate); RouterOS'
/// own `skip-backup=no` default already saves an automatic backup on the router itself
/// right before resetting, on top of whatever backup this app already made.
func resetToVendorDefaults(for credentials: RouterOSCredentials) async throws {
let transport = SSHTransport(credentials: credentials)
try await transport.connect()
// The router reboots immediately after this command; the connection dying mid-command
// instead of returning a clean response is the expected outcome here, not a failure.
try? await transport.resetToFactoryDefaults()
await transport.disconnect()
}
}