mirror of
https://github.com/db9979/sshtermy.git
synced 2026-12-06 12:44:08 +01:00
* Debug-Protokoll für Fehlerberichte, Barrierearm-Modus und Farbenblind-Themes - internal/debuglog: Ereignisse (SSH-Aufbau, Abbrüche, Updates, KI-Anfragen, Sync), Rotation 4 MiB - Schalter in Einstellungen, --debug, bereinigte Kopie (crash.Clean) nach Downloads - Barrierearm: keine Animationen, × für nicht erreichbar, Startanimation aus; geht mit dem Sync - Themes Farbenblind dunkel/hell (Okabe-Ito) - README, README.de, Webseite, Kurzreferenz Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018i4GUifSEzjZLFvqVjcUxz * Release-Signatur: Schlüssel tolerant lesen, klare Fehlermeldung, Abgleich mit UPDATE_PUBKEY Der Release-Lauf nach #81 brach mit „UPDATE_SIGNING_KEY fehlt oder ist ungültig“ ab. sshtermy-sign ignoriert jetzt Zeilenumbrüche, Leerzeichen, Anführungszeichen und die keygen-Überschrift, nennt bei Fehlern die gefundene Länge (nie den Schlüssel) und prüft, dass der private Schlüssel zu UPDATE_PUBKEY passt. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018i4GUifSEzjZLFvqVjcUxz * Gesamtsicherung/Umzug und KI-Datenschutz - Gesamtsicherung: ganzer Datenordner als eine mit dem Master-Passwort verschlüsselte Datei (.sshtbak, Argon2id + AES-256-GCM in Blöcken); Einstellungen › Import / Export oder sshtermy backup / restore. Einspielen nach Rückfrage beim Neustart, der alte Ordner bleibt als <ordner>.vorher-<zeit> - KI-Datenschutz (Einstellungen › KI): alle Anbieter / nur lokale KI / KI aus, pro Verbindung per Tag ki-lokal / ki-aus (no-ai, ai-local); strengere Stufe gilt - „Letzte KI-Anfrage ansehen“: was zuletzt an welchen Host/welches Modell ging - Doku: README DE/EN, Webseite, Handout Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018i4GUifSEzjZLFvqVjcUxz * Audit-Protokoll und Herstellerprofile Juniper, MikroTik, Fortinet - internal/audit: fälschungssicheres Protokoll (HMAC-Kette mit Schlüssel aus dem Store, signierter Kopf gegen abgeschnittene Enden), Monatsdateien im Datenordner - Einstellungen › Sicherheit: Audit-Protokoll an/aus (nur dieser Rechner), prüfen und speichern; erfasst Verbindungen, Befehle (Agent/Broadcast markiert, private nur als „(privat)“), Übertragungen, Config-Sicherungen, Verbindungen, Master-Passwort, Gesamtsicherungen, KI-Anfragen (Host/Modell) - Host-Übersicht und Config-Sicherung für Juniper Junos, MikroTik RouterOS, FortiGate: eigene Befehle und Parser, Prompts „[admin@MikroTik] >“ / „FGT #“, Blättern „---(more)---“ / „-- [Q quit|D dump|down]“; geplante Sicherung nimmt den passenden Befehl - Schnellbefehle Juniper und FortiGate; „nur lesen“ kennt get …, /… print, /export - Doku: README DE/EN, Webseite, Handout Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018i4GUifSEzjZLFvqVjcUxz --------- Co-authored-by: Claude <noreply@anthropic.com>
150 lines
4.1 KiB
Go
150 lines
4.1 KiB
Go
package hostinfo
|
|
|
|
import (
|
|
"regexp"
|
|
"strings"
|
|
)
|
|
|
|
var (
|
|
csiRe = regexp.MustCompile(`\x1b\[[0-?]*[ -/]*[@-~]`)
|
|
oscRe = regexp.MustCompile(`\x1b\][^\x07\x1b]*(?:\x07|\x1b\\)`)
|
|
escRe = regexp.MustCompile(`\x1b[()][0-9A-Za-z]|\x1b[0-9=>A-DF-Za-z]`)
|
|
moreRe = regexp.MustCompile(`(?i)-+\s*more\s*-+(?:[^\n]*?control-c)?|--more--|<--- more --->|---\(more[^)\n]*\)---|-- \[Q quit\|D dump\|down\]`)
|
|
)
|
|
|
|
// Clean macht aus dem rohen PTY-Strom Klartextzeilen: ANSI-Sequenzen raus
|
|
// (ProCurve positioniert den Cursor bei jeder Zeile), "\eE" als Zeilenumbruch,
|
|
// Rückschritte angewandt, Blätter-Hinweise ("-- MORE --") entfernt, leere
|
|
// Zeilen und Leerzeichen am Ende weg.
|
|
func Clean(raw string) []string {
|
|
s := strings.ReplaceAll(raw, "\x1bE", "\n")
|
|
s = oscRe.ReplaceAllString(s, "")
|
|
s = csiRe.ReplaceAllString(s, "")
|
|
s = escRe.ReplaceAllString(s, "")
|
|
s = moreRe.ReplaceAllString(s, "")
|
|
s = strings.ReplaceAll(s, "\r\n", "\n")
|
|
var out []string
|
|
for _, l := range strings.Split(s, "\n") {
|
|
// "\r" ohne "\n": die Zeile wurde von vorn überschrieben.
|
|
if i := strings.LastIndex(l, "\r"); i >= 0 {
|
|
if rest := l[i+1:]; strings.TrimSpace(rest) != "" {
|
|
l = rest
|
|
} else {
|
|
l = strings.ReplaceAll(l, "\r", "")
|
|
}
|
|
}
|
|
l = applyBackspace(l)
|
|
l = strings.Map(func(r rune) rune {
|
|
if r < 0x20 && r != '\t' {
|
|
return -1
|
|
}
|
|
return r
|
|
}, l)
|
|
l = strings.TrimRight(l, " \t")
|
|
if l != "" {
|
|
out = append(out, l)
|
|
}
|
|
}
|
|
return out
|
|
}
|
|
|
|
func applyBackspace(s string) string {
|
|
if !strings.Contains(s, "\b") {
|
|
return s
|
|
}
|
|
r := []rune{}
|
|
for _, c := range s {
|
|
if c == '\b' {
|
|
if len(r) > 0 {
|
|
r = r[:len(r)-1]
|
|
}
|
|
continue
|
|
}
|
|
r = append(r, c)
|
|
}
|
|
return string(r)
|
|
}
|
|
|
|
// HasMore: wartet das Gerät am Ende der Ausgabe auf eine Taste zum Blättern?
|
|
func HasMore(raw string) bool {
|
|
tail := raw
|
|
if len(tail) > 300 {
|
|
tail = tail[len(tail)-300:]
|
|
}
|
|
tail = csiRe.ReplaceAllString(tail, "")
|
|
loc := moreRe.FindAllStringIndex(tail, -1)
|
|
if len(loc) == 0 {
|
|
return false
|
|
}
|
|
// Nach dem letzten Hinweis darf nichts Sichtbares mehr kommen.
|
|
return strings.TrimSpace(tail[loc[len(loc)-1][1]:]) == ""
|
|
}
|
|
|
|
// IsPrompt: sieht die Zeile wie ein Geräte-Prompt aus ("switch#", "sw01>",
|
|
// "core(config)#")?
|
|
func IsPrompt(line string) bool {
|
|
l := strings.TrimSpace(line)
|
|
if l == "" || len(l) > 80 {
|
|
return false
|
|
}
|
|
end := l[len(l)-1]
|
|
if (end == '#' || end == '>') && !strings.ContainsAny(l[:len(l)-1], " \t#>") {
|
|
return true
|
|
}
|
|
// RouterOS „[admin@MikroTik] >“ / „[admin@MikroTik] /interface>“,
|
|
// FortiOS „FGT60F #“ / „FGT60F (root) #“
|
|
return vendorPrompt.MatchString(l)
|
|
}
|
|
|
|
var vendorPrompt = regexp.MustCompile(`^\[[\w.@-]+\]\s*(/[\w/-]*)?>$|^[\w.-]+(\s+\([\w.-]+\))?\s+#$`)
|
|
|
|
// Output: Ausgabe eines Befehls ohne Echo der Befehlszeile und ohne den
|
|
// abschließenden Prompt. done meldet, ob der Prompt schon wieder da ist.
|
|
func Output(raw, cmd, prompt string) (lines []string, done bool) {
|
|
ls := Clean(raw)
|
|
// Echo: erste Zeile, die den Befehl enthält (oft "switch# show vlans").
|
|
for i, l := range ls {
|
|
if i > 2 {
|
|
break
|
|
}
|
|
if strings.Contains(l, cmd) {
|
|
ls = ls[i+1:]
|
|
break
|
|
}
|
|
}
|
|
if n := len(ls); n > 0 && strings.TrimSpace(ls[n-1]) == prompt {
|
|
return ls[:n-1], true
|
|
}
|
|
return ls, false
|
|
}
|
|
|
|
// volatile: Zeilen, die sich bei jedem Abruf ändern, ohne dass jemand die
|
|
// Konfiguration angefasst hat. Für Vergleich und Diff ignoriert.
|
|
var volatile = regexp.MustCompile(`(?i)^\s*(?:!\s*last configuration change|!\s*nvram config last updated|!\s*time:|current configuration\s*:|building configuration|ntp clock-period|running configuration:\s*$)`)
|
|
|
|
// ConfigLines: Konfiguration ohne flüchtige Zeilen.
|
|
func ConfigLines(cfg string) []string {
|
|
var out []string
|
|
for _, l := range strings.Split(strings.ReplaceAll(cfg, "\r", ""), "\n") {
|
|
if strings.TrimSpace(l) == "" || volatile.MatchString(l) {
|
|
continue
|
|
}
|
|
out = append(out, strings.TrimRight(l, " \t"))
|
|
}
|
|
return out
|
|
}
|
|
|
|
// SameConfig: inhaltlich gleich (flüchtige Zeilen ausgenommen)?
|
|
func SameConfig(a, b string) bool {
|
|
x, y := ConfigLines(a), ConfigLines(b)
|
|
if len(x) != len(y) {
|
|
return false
|
|
}
|
|
for i := range x {
|
|
if x[i] != y[i] {
|
|
return false
|
|
}
|
|
}
|
|
return true
|
|
}
|