diff --git a/README.de.md b/README.de.md index 6ac3cd6..0e2a25b 100644 --- a/README.de.md +++ b/README.de.md @@ -23,6 +23,11 @@ sshTermy ist eine schlanke Terminal-Anwendung (TUI, eine einzige Datei, ~9 MB, k - **Agent-Weiterleitung** pro Verbindung (wie `ssh -A`): `git pull`, `ssh` und `scp` auf dem Server nutzen deine lokalen Keys aus ssh-agent, Pageant oder dem Windows-OpenSSH-Agent, die Keys verlassen deinen Rechner nie - **X11-Weiterleitung** pro Verbindung (wie `ssh -X`): Grafische Programme vom Server öffnen sich hier; braucht lokal einen X-Server (XQuartz, VcXsrv, WSLg), das X-Cookie verlässt deinen Rechner nie - **FIDO2-Sicherheitsschlüssel** (`id_ed25519_sk`, `id_ecdsa_sk`, z. B. YubiKey) werden direkt genutzt; sshTermy sagt dir, wann du den Schlüssel berühren musst (braucht OpenSSH ssh-agent/ssh-add) +- **Passwortmanager statt gespeicherter Passwörter**: Im Verbindungsformular „Passwort aus“ und (unter Erweitert) + „2FA-Code aus“: `op://Tresor/Eintrag/password` (1Password CLI), `bw:Eintrag` (Bitwarden CLI), `keepassxc:Datei.kdbx:Eintrag` + (KeePassXC, fragt das Datenbank-Passwort), `pass:Name` oder `cmd:Befehl`. Fragt ein Server nach einem Einmalcode + („Verification code“), holt sshTermy den TOTP-Code aus derselben Quelle, auch nach einer Anmeldung mit Key. + Gespeichert wird nur der Verweis, nie das Passwort - **Kerberos/GSSAPI-Anmeldung** (Anmeldung `kerberos`): Nutzt das Ticket der Firmen-Domäne aus der Windows-Anmeldung oder `kinit`, ohne Passwort; ohne Ticket fragt sshTermy wie gewohnt nach dem Passwort - **Zwischenablage vom Server (OSC 52)**: Was du in tmux oder vim auf dem Server kopierst, landet in deiner lokalen Zwischenablage. Lesen kann der Server sie nie - **Geteilte Ansicht** (Strg+T): bis zu sechs Sitzungen gleichzeitig in sieben Aufteilungen, Größe per Maus oder Alt+⇧+Pfeil, Zoom auf einen Bereich (Alt+Z), Bereiche per Titel tauschen, andere Bereiche auf Wunsch abdunkeln. Die Aufteilung übersteht Updates; **Arbeitsplätze** (w im Manager) speichern Aufteilung und Verbindungen zum Wiederöffnen mit einem Klick, „Zuletzt“ merkt sich sshTermy beim Beenden selbst, `g` auf einem Ordner öffnet alle Verbindungen darin als Raster @@ -39,6 +44,13 @@ sshTermy ist eine schlanke Terminal-Anwendung (TUI, eine einzige Datei, ~9 MB, k - **Broadcast** (m im Manager): ein Befehl oder Runbook läuft parallel auf einer Gruppe (z. B. alle Aruba-Switches), die Ergebnisse stehen in Spalten nebeneinander. Gefahrenregeln gelten auch hier: Rot braucht zweimal ⏎. Server bekommen jeden Schritt per Exec (mit Exit-Code), Netzwerkgeräte die Befehle in die Shell getippt („-- MORE --“ wird weitergeblättert). +- **Zeitpläne** (z im Manager): Ein Broadcast oder Runbook läuft zu einer Uhrzeit auf einem Ordner oder einzelnen + Verbindungen, täglich, Mo–Fr, am Wochenende oder an einem Wochentag, z. B. „3:00 Mo–Fr `show running-config` auf + allen Switches“. Läuft, solange sshTermy offen ist (auch gesperrt), Verpasstes holt es innerhalb von 12 Stunden nach. + Ohne Aufsicht gibt es keine Rückfragen: unbekannte Host-Keys und fehlende Passwörter lassen den Host scheitern, + Gefährliches und Runbooks mit Variablen lassen sich gar nicht einplanen. Das Ergebnis je Host steht in der Liste + (⏎), dazu eine Einblendung bzw. Desktop-Meldung. Zeitpläne bleiben auf dem Rechner (kein Sync), damit nicht zwei + Rechner denselben Lauf starten - **Runbooks mit Variablen:** `{{vlan}}` oder `{{vlan=20}}` in einem Schritt wird vor dem Start abgefragt, `{{host}}`, `{{alias}}`, `{{user}}`, `{{port}}` setzt sshTermy pro Host ein. Im Broadcast lädt `e` ein Runbook zum Bearbeiten, `Strg+R` speichert, `Strg+D` löscht. Vor dem Start prüft die KI mit `k` gegen das Systemprofil jedes Hosts, ob die @@ -167,7 +179,7 @@ sshtermy --no-intro # ohne Startanimation (dauerhaft: Palette „Startanimatio | Manager | ⏎ / n / e / d / / / t / s / y / l | verbinden / neu / bearbeiten / löschen / suchen / Tunnel / KI-Einstellungen / Sync / Sitzungsprotokolle | | | i / a / b | Verbindungen importieren / Aussehen wechseln / Tastenkürzel anpassen | | | c / q | SSH-Schlüssel erzeugen oder übertragen / Schnellbefehle bearbeiten | -| | m / f | Broadcast an mehrere Hosts / Netzwerk-Scan | +| | m / f / z | Broadcast an mehrere Hosts / Netzwerk-Scan / Zeitpläne (Strg+N neu, Strg+E bearbeiten, Strg+R jetzt, Strg+O an/aus, ⏎ letztes Ergebnis) | | | w / g | Arbeitsplätze (gespeicherte Aufteilungen) / Ordner als Raster öffnen | | Ordner | o / r / v / d | Ordner anlegen („A / B“ verschachtelt) / umbenennen / verschieben / auflösen (Inhalt bleibt) | | | ← → Space / - + | Ordner zu-/aufklappen / alle zu bzw. auf | diff --git a/README.md b/README.md index c0afccf..3f00723 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,11 @@ sshTermy is a lean terminal application (TUI, a single file, ~9 MB, no installer - **Agent forwarding** per connection (like `ssh -A`): `git pull`, `ssh` and `scp` on the server use your local keys from ssh-agent, Pageant or the Windows OpenSSH agent, the keys never leave your computer - **X11 forwarding** per connection (like `ssh -X`): graphical programs from the server open here; needs a local X server (XQuartz, VcXsrv, WSLg), the X cookie never leaves your computer - **FIDO2 security keys** (`id_ed25519_sk`, `id_ecdsa_sk`, e.g. YubiKey) are used directly; sshTermy asks you to touch the key (needs OpenSSH ssh-agent/ssh-add) +- **Password manager instead of stored passwords**: in the connection form „Password from“ and (under Advanced) + „2FA code from“: `op://Vault/Item/password` (1Password CLI), `bw:Item` (Bitwarden CLI), `keepassxc:file.kdbx:Item` + (KeePassXC, asks for the database password), `pass:name` or `cmd:command`. When a server asks for a one-time code + („Verification code“), sshTermy takes the TOTP code from the same source, also after a key login. + Only the reference is stored, never the password - **Kerberos/GSSAPI login** (login `kerberos`): uses the company domain ticket from the Windows sign-in or `kinit`, no password needed; without a ticket it falls back to the password - **Clipboard from the server (OSC 52)**: what you copy in tmux or vim on the server lands in your local clipboard. The server can never read it - **Split view** (Ctrl+T): up to six sessions at once in seven layouts, resize with the mouse or Alt+⇧+arrow, zoom one pane (Alt+Z), swap panes by dragging their title, optionally dim the other panes. The layout survives updates; **workspaces** (w in the manager) save layout and connections to reopen in one go, “Last used” is remembered on quit, `g` on a folder opens all its connections as a grid @@ -39,6 +44,13 @@ sshTermy is a lean terminal application (TUI, a single file, ~9 MB, no installer - **Broadcast** (m in the manager): one command or runbook runs in parallel on a group (e.g. all Aruba switches), the results are shown side by side in columns. The danger rules apply here too: red needs ⏎ twice. Servers get every step via exec (with exit code), network devices get the commands typed into their shell („-- MORE --“ is paged automatically). +- **Schedules** (z in the manager): a broadcast or runbook runs at a set time on a folder or single connections, + daily, Mon–Fri, on weekends or on one weekday, e.g. „3:00 Mon–Fri `show running-config` on all switches“. + Runs while sshTermy is open (also when locked), missed runs are caught up within 12 hours. + Unattended there are no questions: unknown host keys and missing passwords make that host fail, + dangerous steps and runbooks with variables cannot be scheduled at all. The result per host is in the list + (⏎), plus a toast or desktop notification. Schedules stay on this computer (no sync), so two computers never + start the same run - **Runbooks with variables:** `{{vlan}}` or `{{vlan=20}}` in a step is asked before the run, `{{host}}`, `{{alias}}`, `{{user}}`, `{{port}}` are filled in per host. In the broadcast `e` loads a runbook for editing, `Ctrl+R` saves, `Ctrl+D` deletes. Before the run `k` lets the AI check the steps against each host's system profile and suggest @@ -166,7 +178,7 @@ sshtermy --no-intro # without the start animation (permanently: palette „Sta | Manager | ⏎ / n / e / d / / / t / s / y / l | connect / new / edit / delete / search / tunnel / AI settings / sync / session logs | | | i / a / b | import connections / switch appearance / customize shortcuts | | | c / q | create or copy an SSH key / edit quick commands | -| | m / f | broadcast to several hosts / network scan | +| | m / f / z | broadcast to several hosts / network scan / schedules (Ctrl+N new, Ctrl+E edit, Ctrl+R now, Ctrl+O on/off, ⏎ last result) | | | w / g | workspaces (saved split layouts) / open a folder as a grid | | Folders | o / r / v / d | create folder („A / B“ nested) / rename / move / dissolve (content stays) | | | ← → Space / - + | collapse/expand folder / collapse or expand all | diff --git a/internal/domain/model.go b/internal/domain/model.go index 9d7e928..b049804 100644 --- a/internal/domain/model.go +++ b/internal/domain/model.go @@ -9,6 +9,7 @@ package domain import ( "fmt" + "strconv" "strings" "time" @@ -81,6 +82,11 @@ type Connection struct { // Eintrag; der Sync überträgt nur diesen Schalter. Fehlt der Eintrag, // fragt sshTermy beim Verbinden und legt die Antwort dort ab. Keychain bool `json:"keychain,omitempty"` + // PassSource / OTPSource: Passwort bzw. 2FA-Code aus einem + // Passwortmanager holen (pwsource-Schreibweise, z. B. "op://Tresor/web/password", + // "bw:web-01"). Gespeichert wird nur der Verweis, nie das Geheimnis. + PassSource string `json:"pass_source,omitempty"` + OTPSource string `json:"otp_source,omitempty"` JumpHostID string `json:"jump_host_id,omitempty"` // ProxyJump über eine andere Connection // RelayID/RelaySystem: über einen Vermittler (eigener sshtermy @@ -509,6 +515,9 @@ type Settings struct { // Systems). Bleibt auf dem Rechner, nie im Sync. Editor string `json:"editor,omitempty"` + // Schedules: Zeitpläne für Broadcast/Runbooks (nur dieser Rechner). + Schedules []Schedule `json:"schedules,omitempty"` + // Highlight: Farbregeln für die Ausgabe im Terminal (highlight-Paket). Highlight HighlightConfig `json:"highlight,omitempty"` @@ -763,3 +772,76 @@ func (r Runbook) Rev() time.Time { } return r.UpdatedAt } + +// Schedule: Zeitplan für einen Broadcast oder ein Runbook (schedule.go in +// der Oberfläche). Läuft, solange sshTermy offen ist; wurde ein Termin +// verpasst, holt sshTermy ihn innerhalb von ScheduleCatchUp nach. Bleibt auf +// dem Rechner (nie im Sync), damit nicht zwei Rechner denselben Lauf starten. +type Schedule struct { + ID string `json:"id"` + Name string `json:"name"` + At string `json:"at"` // "HH:MM" Ortszeit + Days []int `json:"days,omitempty"` // 0 = Sonntag … 6; leer = täglich + Folder string `json:"folder,omitempty"` + Conns []string `json:"conns,omitempty"` + RunbookID string `json:"runbook_id,omitempty"` + Steps []string `json:"steps,omitempty"` // ohne Runbook + Off bool `json:"off,omitempty"` + LastRun time.Time `json:"last_run,omitempty"` + LastOK int `json:"last_ok,omitempty"` + LastFail int `json:"last_fail,omitempty"` + LastText string `json:"last_text,omitempty"` // Ergebnis je Host, gekürzt +} + +// ScheduleCatchUp: so lange nach dem Termin wird ein verpasster Lauf nachgeholt. +const ScheduleCatchUp = 12 * time.Hour + +// DueAt: Termin des Tages von now (zero, wenn heute kein Lauftag ist oder +// die Zeit unlesbar). +func (s Schedule) DueAt(now time.Time) time.Time { + h, m, ok := ParseClock(s.At) + if !ok { + return time.Time{} + } + if len(s.Days) > 0 { + hit := false + for _, d := range s.Days { + if d == int(now.Weekday()) { + hit = true + } + } + if !hit { + return time.Time{} + } + } + y, mo, d := now.Date() + return time.Date(y, mo, d, h, m, 0, 0, now.Location()) +} + +// Due: jetzt laufen lassen? +func (s Schedule) Due(now time.Time) bool { + if s.Off { + return false + } + t := s.DueAt(now) + return !t.IsZero() && !now.Before(t) && now.Sub(t) < ScheduleCatchUp && s.LastRun.Before(t) +} + +// ParseClock liest "3:00", "03:00" oder "0300". +func ParseClock(v string) (h, m int, ok bool) { + v = strings.TrimSpace(v) + if len(v) == 4 && !strings.Contains(v, ":") { + v = v[:2] + ":" + v[2:] + } + hs, ms, found := strings.Cut(v, ":") + if !found { + return 0, 0, false + } + var err1, err2 error + h, err1 = strconv.Atoi(hs) + m, err2 = strconv.Atoi(ms) + if err1 != nil || err2 != nil || h < 0 || h > 23 || m < 0 || m > 59 || len(ms) != 2 { + return 0, 0, false + } + return h, m, true +} diff --git a/internal/domain/schedule_test.go b/internal/domain/schedule_test.go new file mode 100644 index 0000000..fe5c7f6 --- /dev/null +++ b/internal/domain/schedule_test.go @@ -0,0 +1,41 @@ +package domain + +import ( + "testing" + "time" +) + +func TestScheduleDue(t *testing.T) { + loc := time.Local + mon3 := time.Date(2026, 11, 9, 3, 0, 0, 0, loc) // Montag + s := Schedule{At: "3:00"} + if !s.Due(mon3) || s.Due(mon3.Add(-time.Minute)) { + t.Fatal("pünktlich") + } + if !s.Due(mon3.Add(5 * time.Hour)) { + t.Fatal("nachholen innerhalb 12 h") + } + if s.Due(mon3.Add(13 * time.Hour)) { + t.Fatal("zu spät") + } + s.LastRun = mon3.Add(time.Second) + if s.Due(mon3.Add(time.Hour)) { + t.Fatal("schon gelaufen") + } + s = Schedule{At: "0300", Days: []int{6, 0}} // nur Wochenende + if s.Due(mon3) { + t.Fatal("Montag ist kein Lauftag") + } + if !s.Due(mon3.AddDate(0, 0, -1)) { + t.Fatal("Sonntag") + } + for _, bad := range []string{"25:00", "3", "3:7", "ab:cd"} { + if _, _, ok := ParseClock(bad); ok { + t.Errorf("%q", bad) + } + } + s.Off = true + if s.Due(mon3.AddDate(0, 0, -1)) { + t.Fatal("aus") + } +} diff --git a/internal/i18n/en_features12.go b/internal/i18n/en_features12.go index f86ee09..3ce9fda 100644 --- a/internal/i18n/en_features12.go +++ b/internal/i18n/en_features12.go @@ -67,6 +67,72 @@ var enFeatures12 = map[string]string{ "Farbregeln bearbeiten": "edit color rules", "„log“": "“log”", "„farb“": "“color”", + + // Passwortmanager, Zeitpläne + "%d ok, %d Fehler": "%d ok, %d failed", + "%s ist nicht installiert oder nicht im PATH": "%s is not installed or not in PATH", + "%s lieferte nichts": "%s returned nothing", + "%s · %s · %d ok, %d Fehler": "%s · %s · %d ok, %d failed", + "+ Neuer Zeitplan (Strg+N)": "+ New schedule (Ctrl+N)", + "2FA aus ": "2FA from ", + "2FA-Code aus": "2FA code from", + "Agent-/X11-Weiterleitung, feste tmux-/screen-Sitzung und 2FA-Code · ⏎ klappt auf": "Agent/X11 forwarding, persistent tmux/screen session and 2FA code · ⏎ expands", + "Aliasse durch Komma getrennt (nur ohne Ordner)": "aliases separated by commas (only without a folder)", + "Das Runbook gibt es nicht mehr": "The runbook no longer exists", + "Gefährlicher Befehl läuft nie nach Zeitplan: %s (%s)": "A dangerous command never runs on a schedule: %s (%s)", + "HH:MM, Ortszeit dieses Rechners": "HH:MM, local time of this computer", + "KeePassXC braucht das Datenbank-Passwort": "KeePassXC needs the database password", + "KeePassXC-Datenbank ": "KeePassXC database ", + "Kein Ziel: Ordner wählen oder Verbindungen eintragen": "No target: choose a folder or enter connections", + "Keine Befehle": "No commands", + "Läuft schon: ": "Already running: ", + "Läuft, solange sshTermy offen ist; Verpasstes holt es innerhalb von 12 h nach. Nur Hosts mit gespeichertem Passwort oder Key.": "Runs while sshTermy is open; a missed run is caught up within 12 h. Only hosts with a stored password or key.", + "Name, Zeit oder Ziel": "name, time or target", + "Neuer Zeitplan": "New schedule", + "Noch nie gelaufen · Strg+R führt ihn jetzt aus": "Never ran · Ctrl+R runs it now", + "Passwort aus": "Password from", + "Passwortmanager statt gespeichertem Passwort: op://Tresor/Eintrag/password · bw:Eintrag · keepassxc:Datei.kdbx:Eintrag · pass:Name · cmd:Befehl": "password manager instead of a stored password: op://vault/item/password · bw:item · keepassxc:file.kdbx:entry · pass:name · cmd:command", + "Quelle unbekannt: op://…, bw:Eintrag, keepassxc:Datei:Eintrag, pass:Name oder cmd:Befehl": "Unknown source: op://…, bw:item, keepassxc:file:entry, pass:name or cmd:command", + "Runbooks mit Skripten des Agenten lassen sich nicht einplanen": "Runbooks with agent scripts cannot be scheduled", + "Runbooks ohne Variablen und ohne Skripte": "runbooks without variables and without scripts", + "Tage": "Days", + "Uhrzeit": "Time", + "Uhrzeit als HH:MM, z. B. 03:00": "Time as HH:MM, e.g. 03:00", + "Variable {{%s}} kann ohne Aufsicht niemand ausfüllen": "Nobody can fill in variable {{%s}} unattended", + "Verbindung „%s“ gibt es nicht": "There is no connection “%s”", + "Zeitplan": "Schedule", + "Zeitplan gelöscht: ": "Schedule deleted: ", + "Zeitplan ist gelaufen": "A schedule ran", + "Zeitplan startet: ": "Schedule starting: ", + "Zeitplan „": "Schedule “", + "Zeitplan „%s“ fertig: %d ok, %d Fehler": "Schedule “%s” done: %d ok, %d failed", + "Zeitplan: ": "Schedule: ", + "Zeitpläne": "Schedules", + "Zeitpläne: Broadcast/Runbook nach Uhrzeit": "Schedules: broadcast/runbook at a set time", + "Zeitpläne (Broadcast/Runbook nach Uhrzeit)": "Schedules (broadcast/runbook at a set time)", + "alle Verbindungen darin, auch in Unterordnern": "all connections in it, including subfolders", + "braucht eine Eingabe (%s), Zeitpläne fragen nie": "needs input (%s), schedules never ask", + "für Server, die nach einem Einmalcode fragen · op://Tresor/Eintrag · bw:Eintrag · keepassxc:… · leer = nachfragen": "for servers that ask for a one-time code · op://vault/item · bw:item · keepassxc:… · empty = ask", + "jetzt ausführen": "run now", + "keine SSH-Verbindung im Ziel": "no SSH connection in the target", + "leer = Passwort oben bzw. fragen": "empty = password above or ask", + "leer = beim Verbinden fragen": "empty = ask when connecting", + "letztes Ergebnis": "last result", + "mehrere Schritte mit ;; trennen · {{host}} {{alias}} werden je Host eingesetzt · Gefährliches geht nie": "separate steps with ;; · {{host}} {{alias}} are filled in per host · nothing dangerous", + "noch nie gelaufen": "never ran", + "z. B. „Switch-Configs sichern“": "e.g. “Back up switch configs”", + "— eigene Befehle": "— own commands", + "— einzelne Verbindungen": "— individual connections", + "täglich": "daily", + "Mo–Fr": "Mon–Fri", + "Sa + So": "Sat + Sun", + "Montag": "Monday", + "Dienstag": "Tuesday", + "Mittwoch": "Wednesday", + "Donnerstag": "Thursday", + "Freitag": "Friday", + "Samstag": "Saturday", + "Sonntag": "Sunday", } func init() { diff --git a/internal/pwsource/hide_other.go b/internal/pwsource/hide_other.go new file mode 100644 index 0000000..5782259 --- /dev/null +++ b/internal/pwsource/hide_other.go @@ -0,0 +1,7 @@ +//go:build !windows + +package pwsource + +import "os/exec" + +func hideWindow(*exec.Cmd) {} diff --git a/internal/pwsource/hide_windows.go b/internal/pwsource/hide_windows.go new file mode 100644 index 0000000..7566ed0 --- /dev/null +++ b/internal/pwsource/hide_windows.go @@ -0,0 +1,11 @@ +package pwsource + +import ( + "os/exec" + "syscall" +) + +// hideWindow: kein Konsolenfenster für op.exe, bw.exe & Co. +func hideWindow(cmd *exec.Cmd) { + cmd.SysProcAttr = &syscall.SysProcAttr{HideWindow: true, CreationFlags: 0x08000000} // CREATE_NO_WINDOW +} diff --git a/internal/pwsource/pwsource.go b/internal/pwsource/pwsource.go new file mode 100644 index 0000000..c97cbdb --- /dev/null +++ b/internal/pwsource/pwsource.go @@ -0,0 +1,225 @@ +// Package pwsource holt Passwörter und 2FA-Codes aus einem Passwortmanager, +// statt sie in sshTermy zu speichern. Eine Quelle ist eine Zeile: +// +// op://Tresor/Eintrag/password 1Password CLI (op read) +// bw:Eintrag Bitwarden CLI (bw get password|totp) +// keepassxc:/pfad/db.kdbx:Eintrag KeePassXC CLI (fragt das Datenbank-Passwort) +// pass:pfad/eintrag pass / gopass (erste Zeile) +// cmd:befehl … beliebiger Befehl, erste Zeile der Ausgabe +// +// Für 2FA-Codes (keyboard-interactive „Verification code“) gilt dieselbe +// Schreibweise; op und bw liefern dann den TOTP-Code des Eintrags, +// keepassxc den TOTP-Wert (-t), pass versucht „pass otp“. +package pwsource + +import ( + "bytes" + "context" + "errors" + "fmt" + "os/exec" + "strings" + "time" + + "github.com/db9979/sshtermy/internal/i18n" +) + +// Kind: was gebraucht wird. +type Kind int + +const ( + Password Kind = iota + OTP +) + +// Ask fragt ein Geheimnis interaktiv ab (KeePassXC-Datenbankpasswort). +type Ask func(label string) (string, error) + +// Timeout: so lange darf der Passwortmanager brauchen (bw/op können beim +// ersten Mal nach dem Entsperren fragen, das geschieht in deren eigenem Fenster). +var Timeout = 60 * time.Second + +// run ist austauschbar für Tests. +var run = func(ctx context.Context, stdin string, name string, args ...string) (string, error) { + cmd := exec.CommandContext(ctx, name, args...) + var out, errb bytes.Buffer + cmd.Stdout, cmd.Stderr = &out, &errb + if stdin != "" { + cmd.Stdin = strings.NewReader(stdin + "\n") + } + hideWindow(cmd) + if err := cmd.Run(); err != nil { + msg := strings.TrimSpace(errb.String()) + if errors.Is(err, exec.ErrNotFound) { + return "", fmt.Errorf(i18n.T("%s ist nicht installiert oder nicht im PATH"), name) + } + if msg == "" { + msg = err.Error() + } + if len(msg) > 200 { + msg = msg[:200] + "…" + } + return "", fmt.Errorf("%s: %s", name, msg) + } + return out.String(), nil +} + +// Valid prüft die Schreibweise (für das Formular). +func Valid(spec string) error { + spec = strings.TrimSpace(spec) + if spec == "" { + return nil + } + _, _, err := plan(spec, Password) + return err +} + +// Label: kurze Beschreibung für Hinweise („1Password“, „Bitwarden“ …). +func Label(spec string) string { + switch { + case strings.HasPrefix(spec, "op://"): + return "1Password" + case strings.HasPrefix(spec, "bw:"): + return "Bitwarden" + case strings.HasPrefix(spec, "keepassxc:"): + return "KeePassXC" + case strings.HasPrefix(spec, "pass:"): + return "pass" + case strings.HasPrefix(spec, "cmd:"): + return i18n.T("Befehl") + } + return "" +} + +type step struct { + name string + args []string + askDB string // KeePassXC: Datenbankpasswort abfragen + firstLn bool +} + +func plan(spec string, k Kind) (step, string, error) { + switch { + case strings.HasPrefix(spec, "op://"): + ref := spec + if k == OTP { + // op://Tresor/Eintrag/password → op://Tresor/Eintrag/one-time password?attribute=otp + parts := strings.Split(strings.TrimPrefix(spec, "op://"), "/") + if len(parts) >= 2 { + ref = "op://" + parts[0] + "/" + parts[1] + "/one-time password?attribute=otp" + } + } + return step{name: "op", args: []string{"read", "--no-newline", ref}}, ref, nil + case strings.HasPrefix(spec, "bw:"): + item := strings.TrimSpace(strings.TrimPrefix(spec, "bw:")) + if item == "" { + break + } + what := "password" + if k == OTP { + what = "totp" + } + return step{name: "bw", args: []string{"get", what, item}}, item, nil + case strings.HasPrefix(spec, "keepassxc:"): + rest := strings.TrimPrefix(spec, "keepassxc:") + i := strings.LastIndex(rest, ":") + // Windows-Laufwerk „C:\…“ hat selbst einen Doppelpunkt + if i <= 1 { + break + } + db, entry := rest[:i], rest[i+1:] + if strings.TrimSpace(db) == "" || strings.TrimSpace(entry) == "" { + break + } + args := []string{"show", "-q", "-a", "Password", db, entry} + if k == OTP { + args = []string{"show", "-q", "-t", db, entry} + } + return step{name: "keepassxc-cli", args: args, askDB: db, firstLn: true}, entry, nil + case strings.HasPrefix(spec, "pass:"): + name := strings.TrimSpace(strings.TrimPrefix(spec, "pass:")) + if name == "" { + break + } + if k == OTP { + return step{name: "pass", args: []string{"otp", name}, firstLn: true}, name, nil + } + return step{name: "pass", args: []string{"show", name}, firstLn: true}, name, nil + case strings.HasPrefix(spec, "cmd:"): + line := strings.TrimSpace(strings.TrimPrefix(spec, "cmd:")) + args := splitArgs(line) + if len(args) == 0 { + break + } + return step{name: args[0], args: args[1:], firstLn: true}, line, nil + } + return step{}, "", errors.New(i18n.T("Quelle unbekannt: op://…, bw:Eintrag, keepassxc:Datei:Eintrag, pass:Name oder cmd:Befehl")) +} + +// Get holt das Geheimnis. +func Get(ctx context.Context, spec string, k Kind, ask Ask) (string, error) { + spec = strings.TrimSpace(spec) + st, _, err := plan(spec, k) + if err != nil { + return "", err + } + stdin := "" + if st.askDB != "" { + if ask == nil { + return "", errors.New(i18n.T("KeePassXC braucht das Datenbank-Passwort")) + } + if stdin, err = ask(i18n.T("KeePassXC-Datenbank ") + st.askDB); err != nil { + return "", err + } + } + ctx, cancel := context.WithTimeout(ctx, Timeout) + defer cancel() + out, err := run(ctx, stdin, st.name, st.args...) + if err != nil { + return "", err + } + if st.firstLn { + out, _, _ = strings.Cut(out, "\n") + } + out = strings.TrimRight(out, "\r\n") + if strings.TrimSpace(out) == "" { + return "", fmt.Errorf(i18n.T("%s lieferte nichts"), Label(spec)) + } + return out, nil +} + +// IsOTPQuestion: fragt der Server nach einem Einmalcode? +func IsOTPQuestion(q string) bool { + q = strings.ToLower(q) + for _, w := range []string{"verification code", "one-time", "one time", "otp", "token", "2fa", "two-factor", "authenticator", "code:", "bestätigungscode", "einmal"} { + if strings.Contains(q, w) { + return true + } + } + return false +} + +func splitArgs(s string) []string { + var out []string + var cur strings.Builder + quote, have := false, false + for _, r := range s { + switch { + case r == '"': + quote, have = !quote, true + case (r == ' ' || r == '\t') && !quote: + if have { + out = append(out, cur.String()) + cur.Reset() + have = false + } + default: + cur.WriteRune(r) + have = true + } + } + if have { + out = append(out, cur.String()) + } + return out +} diff --git a/internal/pwsource/pwsource_test.go b/internal/pwsource/pwsource_test.go new file mode 100644 index 0000000..9cbc4a3 --- /dev/null +++ b/internal/pwsource/pwsource_test.go @@ -0,0 +1,64 @@ +package pwsource + +import ( + "context" + "strings" + "testing" +) + +func TestGet(t *testing.T) { + var got []string + var gotIn string + old := run + t.Cleanup(func() { run = old }) + run = func(_ context.Context, stdin, name string, args ...string) (string, error) { + got = append([]string{name}, args...) + gotIn = stdin + return "geheim\nzweite Zeile\n", nil + } + cases := []struct { + spec string + k Kind + want string + out string + }{ + {"op://Server/web-01/password", Password, "op read --no-newline op://Server/web-01/password", "geheim\nzweite Zeile"}, + {"op://Server/web-01/password", OTP, "op read --no-newline op://Server/web-01/one-time password?attribute=otp", "geheim\nzweite Zeile"}, + {"bw:web-01", Password, "bw get password web-01", "geheim\nzweite Zeile"}, + {"bw:web-01", OTP, "bw get totp web-01", "geheim\nzweite Zeile"}, + {"pass:server/web", Password, "pass show server/web", "geheim"}, + {`cmd:"C:\Tools\pw.exe" web`, Password, `C:\Tools\pw.exe web`, "geheim"}, + {`keepassxc:C:\db.kdbx:Server/web`, Password, `keepassxc-cli show -q -a Password C:\db.kdbx Server/web`, "geheim"}, + } + for _, c := range cases { + out, err := Get(context.Background(), c.spec, c.k, func(string) (string, error) { return "dbpw", nil }) + if err != nil { + t.Fatalf("%s: %v", c.spec, err) + } + if strings.Join(got, " ") != c.want || out != c.out { + t.Errorf("%s: %q → %q", c.spec, strings.Join(got, " "), out) + } + } + if gotIn != "dbpw" { + t.Errorf("KeePassXC bekommt das DB-Passwort auf stdin: %q", gotIn) + } + for _, bad := range []string{"bw:", "foo", "keepassxc:db", "cmd: "} { + if Valid(bad) == nil { + t.Errorf("%q müsste ungültig sein", bad) + } + } + if Valid("") != nil { + t.Error("leer ist erlaubt") + } +} + +func TestIsOTPQuestion(t *testing.T) { + for _, q := range []string{"Verification code: ", "OTP:", "Enter your Duo token"} { + if !IsOTPQuestion(q) { + t.Errorf("%q", q) + } + } + if IsOTPQuestion("Password: ") { + t.Error("Passwort ist kein Code") + } +} diff --git a/internal/sshx/auth.go b/internal/sshx/auth.go index ba81ad3..e70e65a 100644 --- a/internal/sshx/auth.go +++ b/internal/sshx/auth.go @@ -8,11 +8,14 @@ import ( "strings" "time" + "context" + "golang.org/x/crypto/ssh" "golang.org/x/crypto/ssh/agent" "github.com/db9979/sshtermy/internal/domain" "github.com/db9979/sshtermy/internal/i18n" + "github.com/db9979/sshtermy/internal/pwsource" ) // SecretPrompt fragt ein fehlendes Geheimnis interaktiv ab (z. B. Passphrase). @@ -55,6 +58,14 @@ func authMethods(c domain.Connection, o Options) ([]ssh.AuthMethod, error) { switch c.Auth { case domain.AuthPassword: pw := c.Password.Reveal() + if pw == "" && c.PassSource != "" { + // aus dem Passwortmanager; klappt das nicht, wie gewohnt fragen + if v, err := pwsource.Get(context.Background(), c.PassSource, pwsource.Password, pwsource.Ask(o.AskSecret)); err == nil { + pw = v + } else if o.Notice != nil { + o.Notice(pwsource.Label(c.PassSource) + ": " + err.Error()) + } + } m := []ssh.AuthMethod{ssh.PasswordCallback(func() (string, error) { if pw == "" && o.AskSecret != nil { return o.AskSecret(PasswordLabel(c)) @@ -69,6 +80,12 @@ func authMethods(c domain.Connection, o Options) ([]ssh.AuthMethod, error) { switch { case pw != "" && isPass: ans[i] = pw + case !isPass && c.OTPSource != "": + a, err := otpAnswer(c, o, q) + if err != nil { + return nil, err + } + ans[i] = a case isPass && o.AskSecret != nil: // gleiche Frage wie beim Passwort-Verfahren: nur einmal // fragen, und die Oberfläche kann die Antwort merken @@ -101,9 +118,9 @@ func authMethods(c domain.Connection, o Options) ([]ssh.AuthMethod, error) { } if cs != signer { // Zertifikat zuerst, der nackte Key als Rückfall (Server ohne CA) - return []ssh.AuthMethod{ssh.PublicKeys(cs, signer)}, nil + return withOTP(c, o, ssh.PublicKeys(cs, signer)), nil } - return []ssh.AuthMethod{ssh.PublicKeys(signer)}, nil + return withOTP(c, o, ssh.PublicKeys(signer)), nil case domain.AuthAgent: conn, err := dialAgent() @@ -111,7 +128,7 @@ func authMethods(c domain.Connection, o Options) ([]ssh.AuthMethod, error) { return nil, fmt.Errorf(i18n.T("SSH-Agent nicht erreichbar: %w"), err) } // Der Agent hält die Private Keys; sshtermy sieht sie nie. - return []ssh.AuthMethod{ssh.PublicKeysCallback(agent.NewClient(conn).Signers)}, nil + return withOTP(c, o, ssh.PublicKeysCallback(agent.NewClient(conn).Signers)), nil case domain.AuthAuto: return autoMethods(c, o), nil @@ -132,6 +149,43 @@ func authMethods(c domain.Connection, o Options) ([]ssh.AuthMethod, error) { return nil, fmt.Errorf(i18n.T("unbekannte Auth-Methode %q"), c.Auth) } +// withOTP: Key plus Einmalcode (Server mit „AuthenticationMethods +// publickey,keyboard-interactive“): Den Code holt sshTermy aus der +// 2FA-Quelle, sonst wird gefragt. +func withOTP(c domain.Connection, o Options, m ssh.AuthMethod) []ssh.AuthMethod { + if c.OTPSource == "" { + return []ssh.AuthMethod{m} + } + return []ssh.AuthMethod{m, ssh.KeyboardInteractive(func(_, _ string, qs []string, _ []bool) ([]string, error) { + ans := make([]string, len(qs)) + for i, q := range qs { + a, err := otpAnswer(c, o, q) + if err != nil { + return nil, err + } + ans[i] = a + } + return ans, nil + })} +} + +// otpAnswer: Antwort auf eine Frage, die kein Passwort ist. +func otpAnswer(c domain.Connection, o Options, q string) (string, error) { + if c.OTPSource != "" && pwsource.IsOTPQuestion(q) { + v, err := pwsource.Get(context.Background(), c.OTPSource, pwsource.OTP, pwsource.Ask(o.AskSecret)) + if err == nil { + return v, nil + } + if o.Notice != nil { + o.Notice(pwsource.Label(c.OTPSource) + ": " + err.Error()) + } + } + if o.AskSecret == nil { + return "", nil + } + return o.AskSecret(strings.TrimSpace(q)) +} + // autoMethods: Agent + unverschlüsselte Standard-Keys, danach Passwort und // keyboard-interactive mit Rückfrage. Höchstens 5 Keys, sonst bricht OpenSSH // mit "Too many authentication failures" ab, bevor das Passwort drankommt. @@ -175,6 +229,13 @@ func autoMethods(c domain.Connection, o Options) []ssh.AuthMethod { label := strings.TrimSpace(q) if strings.Contains(strings.ToLower(q), "pass") { label = PasswordLabel(c) // gleiche Frage wie oben, nur einmal + } else if c.OTPSource != "" { + a, err := otpAnswer(c, o, q) + if err != nil { + return nil, err + } + ans[i] = a + continue } a, err := o.AskSecret(label) if err != nil { diff --git a/internal/ui/app.go b/internal/ui/app.go index 7bda80d..356acd2 100644 --- a/internal/ui/app.go +++ b/internal/ui/app.go @@ -64,6 +64,7 @@ const ( scrTeam // Team-Freigabe: Auswahl bzw. Vorschau (team.go) scrTeamForm // Team-Freigabe: Passwort, Datei, Optionen scrHighlightForm // Farbregeln (highlight.go) + scrScheduleForm // Zeitplan (schedule.go) ) // App ist das Wurzel-Modell. @@ -115,6 +116,10 @@ type App struct { hl hlState // Farbregeln (highlight.go) edits []*remoteEdit // Server-Dateien im eigenen Editor (editor.go) + formSched domain.Schedule // Zeitplan im Formular (schedule.go) + schedRBIDs map[string]string // Runbook-Name → ID im Formular + schedRun map[string]bool // laufende Zeitpläne + book *sessionlog.Book // Sitzungsprotokolle (Schlüssel nur bei entsperrtem Store) logs logsState @@ -426,6 +431,9 @@ func (a *App) update(msg tea.Msg) (tea.Model, tea.Cmd) { if cmd, ok := a.logsMsg(msg); ok { return a, cmd } + if cmd, ok := a.scheduleMsg(msg); ok { + return a, cmd + } if cmd, ok := a.editMsg(msg); ok { return a, cmd } @@ -456,7 +464,7 @@ func (a *App) update(msg tea.Msg) (tea.Model, tea.Cmd) { if a.pick != nil { return a, a.pickerKey(k) } - if a.keys.is(actHelp, k.String()) && (a.pal != nil || a.scr == scrConnForm || a.scr == scrSettings || a.scr == scrTunnelForm || a.scr == scrImport || a.scr == scrKeys || a.scr == scrBroadcast || a.scr == scrScan || a.scr == scrQuickForm || a.scr == scrMonitorForm || a.scr == scrHighlightForm || a.scr == scrKeyForm || a.scr == scrSSHKeyForm || a.scr == scrRelayForm) { + if a.keys.is(actHelp, k.String()) && (a.pal != nil || a.scr == scrConnForm || a.scr == scrSettings || a.scr == scrTunnelForm || a.scr == scrImport || a.scr == scrKeys || a.scr == scrBroadcast || a.scr == scrScan || a.scr == scrQuickForm || a.scr == scrMonitorForm || a.scr == scrHighlightForm || a.scr == scrScheduleForm || a.scr == scrKeyForm || a.scr == scrSSHKeyForm || a.scr == scrRelayForm) { a.modal = a.helpModal() return a, nil } @@ -497,7 +505,7 @@ func (a *App) update(msg tea.Msg) (tea.Model, tea.Cmd) { return a, a.updateUnlock(msg) case scrManager: return a, a.updateManager(msg) - case scrConnForm, scrSettings, scrTunnelForm, scrQuickForm, scrMonitorForm, scrHighlightForm, scrKeyForm, scrSSHKeyForm, scrRelayForm: + case scrConnForm, scrSettings, scrTunnelForm, scrQuickForm, scrMonitorForm, scrHighlightForm, scrScheduleForm, scrKeyForm, scrSSHKeyForm, scrRelayForm: return a, a.updateForm(msg) case scrTerminal: return a, a.updateTerminal(msg) @@ -553,6 +561,9 @@ func (a *App) onTick() tea.Cmd { } cmds = append(cmds, a.lockScreen()) } + if c := a.scheduleTick(); c != nil { + cmds = append(cmds, c) + } if c := a.editTick(); c != nil { cmds = append(cmds, c) } @@ -605,7 +616,7 @@ func (a *App) View() tea.View { k = append(k, [2]string{"Strg+D", i18n.T("löschen")}) } body = a.frame(a.viewForm(), append(k, [2]string{"Esc", i18n.T("abbrechen")})) - case scrConnForm, scrKeyForm, scrSSHKeyForm, scrRelayForm, scrMonitorForm, scrHighlightForm: + case scrConnForm, scrKeyForm, scrSSHKeyForm, scrRelayForm, scrMonitorForm, scrHighlightForm, scrScheduleForm: body = a.frame(a.viewForm(), [][2]string{{"Tab", i18n.T("weiter")}, {"←/→", i18n.T("wählen")}, {"Strg+S", i18n.T("speichern")}, {"Esc", i18n.T("abbrechen")}}) case scrQuickForm: body = a.frame(a.viewForm(), [][2]string{{"Tab", i18n.T("weiter")}, {"Strg+R", i18n.T("Vorbelegung")}, {"Strg+S", i18n.T("speichern")}, {"Esc", i18n.T("abbrechen")}}) diff --git a/internal/ui/help.go b/internal/ui/help.go index 9475c07..8c7320f 100644 --- a/internal/ui/help.go +++ b/internal/ui/help.go @@ -70,6 +70,7 @@ var helpSections = []helpSection{ {"q", "Schnellbefehle"}, {"m", "Broadcast an mehrere Hosts"}, {"f", "Netzwerk-Scan"}, + {"z", "Zeitpläne"}, {"s", "KI-Einstellungen"}, {"y", "Sync zwischen Rechnern"}, {"i", "Verbindungen importieren"}, diff --git a/internal/ui/keymap.go b/internal/ui/keymap.go index 3191706..ea3a511 100644 --- a/internal/ui/keymap.go +++ b/internal/ui/keymap.go @@ -68,6 +68,7 @@ const ( actGrowDown action = "pane_down" actWorkspace action = "workspaces" actFolderGrid action = "folder_grid" + actSchedule action = "schedules" ) // Schnellbefehle ⇧F1 … ⇧F8 (manche Terminals senden dafür F13 … F20). @@ -138,6 +139,7 @@ var actionDefs = []actionDef{ {actScan, "Netzwerk-Scan", "Manager", []string{"f"}}, {actWorkspace, "Arbeitsplätze", "Manager", []string{"w"}}, {actFolderGrid, "Ordner als Raster öffnen", "Manager", []string{"g"}}, + {actSchedule, "Zeitpläne (Broadcast/Runbook nach Uhrzeit)", "Manager", []string{"z"}}, } func defOf(id action) actionDef { diff --git a/internal/ui/manager.go b/internal/ui/manager.go index 3aefb98..11e8c27 100644 --- a/internal/ui/manager.go +++ b/internal/ui/manager.go @@ -15,6 +15,7 @@ import ( "github.com/db9979/sshtermy/internal/domain" "github.com/db9979/sshtermy/internal/i18n" + "github.com/db9979/sshtermy/internal/pwsource" "github.com/db9979/sshtermy/internal/keychain" "github.com/db9979/sshtermy/internal/sshx" "github.com/db9979/sshtermy/internal/store" @@ -139,7 +140,9 @@ func (a *App) updateManager(msg tea.Msg) tea.Cmd { cur = rows[m.sel] } switch a.keys.which(k.String(), actManager, actHelp, actAbout, actImport, actNextLook, actKeys, actBroadcast, actScan, actCheat, actQuickEdit, actSSHKey, - actFolderNew, actRename, actMoveTo, actMoveUp, actMoveDown, actTagFilter, actFoldAll, actUnfoldAll, actWorkspace, actFolderGrid) { + actFolderNew, actRename, actMoveTo, actMoveUp, actMoveDown, actTagFilter, actFoldAll, actUnfoldAll, actWorkspace, actFolderGrid, actSchedule) { + case actSchedule: + return a.openSchedules() case actWorkspace: return a.openWorkspaces() case actFolderGrid: @@ -694,6 +697,12 @@ func (a *App) openConnForm(c domain.Connection) tea.Cmd { } } + f.text("pwsrc", i18n.T("Passwort aus"), c.PassSource, + i18n.T("Passwortmanager statt gespeichertem Passwort: op://Tresor/Eintrag/password · bw:Eintrag · keepassxc:Datei.kdbx:Eintrag · pass:Name · cmd:Befehl")).hidden = func(f *form) bool { + return raw(f) || f.sel("auth") != "password" + } + f.get("pwsrc").in.Placeholder = i18n.T("leer = Passwort oben bzw. fragen") + f.section("s_org", i18n.T("Einordnung"), func(t Theme) color.Color { return t.OK }) f.pick("group", i18n.T("Ordner"), domain.NormPath(c.Group), func(v string) string { if v == "" { @@ -731,12 +740,15 @@ func (a *App) openConnForm(c domain.Connection) tea.Cmd { netDev := func(f *form) bool { return raw(f) || deviceFromLabel(f.sel("device")) == domain.DeviceNetwork } f.folded("s_adv", i18n.T("Erweitert"), false, connAdvSummary, - i18n.T("Agent-/X11-Weiterleitung und feste tmux-/screen-Sitzung · ⏎ klappt auf")) + i18n.T("Agent-/X11-Weiterleitung, feste tmux-/screen-Sitzung und 2FA-Code · ⏎ klappt auf")) f.toggle("fwdagent", i18n.T("Agent weiterreichen"), c.ForwardAgent, i18n.T("wie ssh -A: git, ssh, scp auf dem Server mit deinen lokalen Keys · nur bei vertrauten Servern")).hidden = netDev f.toggle("fwdx11", i18n.T("X11 weiterleiten"), c.ForwardX11, i18n.T("wie ssh -X: grafische Programme vom Server hier zeigen · braucht lokal einen X-Server (XQuartz, VcXsrv, WSLg)")).hidden = netDev addPersistFields(f, c, raw) + f.text("otpsrc", i18n.T("2FA-Code aus"), c.OTPSource, + i18n.T("für Server, die nach einem Einmalcode fragen · op://Tresor/Eintrag · bw:Eintrag · keepassxc:… · leer = nachfragen")).hidden = raw + f.get("otpsrc").in.Placeholder = i18n.T("leer = beim Verbinden fragen") f.get("tags").in.Placeholder = i18n.T("keine") f.get("p_os").in.Placeholder = i18n.T("noch nicht erkannt · wird beim Verbinden ermittelt") f.get("p_notes").in.Placeholder = i18n.T("keine · z. B. „VLAN 99 = Management, nie reload“") @@ -756,6 +768,9 @@ func connAdvSummary(f *form) string { if fl := f.get("fwdx11"); fl.on && (fl.hidden == nil || !fl.hidden(f)) { on = append(on, i18n.T("X11")) } + if fl := f.get("otpsrc"); fl != nil && strings.TrimSpace(fl.in.Value()) != "" && (fl.hidden == nil || !fl.hidden(f)) { + on = append(on, i18n.T("2FA aus ")+orDefault(pwsource.Label(strings.TrimSpace(fl.in.Value())), "?")) + } if fl := f.get("persist"); fl.options != nil && (fl.hidden == nil || !fl.hidden(f)) && persistFromLabel(f.sel("persist")) != "" { on = append(on, i18n.T("Feste Sitzung: ")+i18n.T(f.sel("persist"))) } @@ -868,6 +883,8 @@ func (a *App) updateForm(msg tea.Msg) tea.Cmd { err = a.saveMonitor() case scrHighlightForm: err = a.saveHighlight() + case scrScheduleForm: + err = a.saveScheduleForm() } if err != nil { a.form.err = err.Error() @@ -930,6 +947,18 @@ func (a *App) saveConn() error { c.CertPath = f.str("certpath") c.KeyPEM = a.formBase.KeyPEM } + c.PassSource, c.OTPSource = "", "" + if !c.Protocol.Raw() { + if c.Auth == domain.AuthPassword { + c.PassSource = f.str("pwsrc") + } + c.OTPSource = f.str("otpsrc") + for _, k := range []string{c.PassSource, c.OTPSource} { + if err := pwsource.Valid(k); err != nil { + return err + } + } + } c.Group = f.val("group") c.Tags = nil for _, t := range strings.Split(f.str("tags"), ",") { diff --git a/internal/ui/palette.go b/internal/ui/palette.go index a7b4393..d420cb2 100644 --- a/internal/ui/palette.go +++ b/internal/ui/palette.go @@ -253,6 +253,7 @@ func (a *App) paletteItems() []palItem { }}, {icon: ic("broadcast"), label: i18n.T("Broadcast: Befehl auf mehreren Hosts"), hint: a.keys.label(actBroadcast), run: func() tea.Cmd { return a.openBroadcast() }}, {icon: ic("scan"), label: i18n.T("Netzwerk-Scan: SSH-Geräte finden"), hint: a.keys.label(actScan), run: func() tea.Cmd { return a.openScan() }}, + {icon: ic("runbook"), label: i18n.T("Zeitpläne: Broadcast/Runbook nach Uhrzeit"), hint: a.keys.label(actSchedule), run: func() tea.Cmd { return a.openSchedules() }}, {icon: ic("team"), label: i18n.T("Mit dem Team teilen (verschlüsselt, ohne Passwörter)"), hint: "Team", run: func() tea.Cmd { a.scr = scrManager; return a.openTeamShare() }}, {icon: ic("team"), label: i18n.T("Team-Paket übernehmen"), hint: "Team", run: func() tea.Cmd { return a.openTeamTake() }}, {icon: ic("team"), label: i18n.T("Team-Ordner (veröffentlicht / abonniert)"), hint: "Team", run: func() tea.Cmd { return a.openTeamLinks() }}, diff --git a/internal/ui/schedule.go b/internal/ui/schedule.go new file mode 100644 index 0000000..4591817 --- /dev/null +++ b/internal/ui/schedule.go @@ -0,0 +1,544 @@ +package ui + +import ( + "context" + "errors" + "fmt" + "strings" + "time" + + tea "charm.land/bubbletea/v2" + + "github.com/db9979/sshtermy/internal/broadcast" + "github.com/db9979/sshtermy/internal/domain" + "github.com/db9979/sshtermy/internal/i18n" + "github.com/db9979/sshtermy/internal/runbook" + "github.com/db9979/sshtermy/internal/sshx" +) + +// Zeitpläne (Manager: z, Palette „Zeitpläne“) +// +// Ein Zeitplan lässt einen Broadcast oder ein Runbook zu einer Uhrzeit auf +// einem Ordner oder einzelnen Verbindungen laufen, täglich oder an +// bestimmten Wochentagen, z. B. „3:00 Mo–Fr: show running-config auf allen +// Switches“. Er läuft, solange sshTermy offen ist (auch gesperrt); einen +// verpassten Termin holt sshTermy innerhalb von 12 Stunden nach. +// +// Unbeaufsichtigt heißt: keine Rückfragen. Unbekannte Host-Keys und +// fehlende Passwörter lassen den Host scheitern, gefährliche Befehle und +// Runbooks mit Variablen oder Skripten lassen sich gar nicht einplanen. + +const schedStepSep = ";;" + +var dayChoices = []struct { + label string + days []int +}{ + {"täglich", nil}, + {"Mo–Fr", []int{1, 2, 3, 4, 5}}, + {"Sa + So", []int{6, 0}}, + {"Montag", []int{1}}, {"Dienstag", []int{2}}, {"Mittwoch", []int{3}}, {"Donnerstag", []int{4}}, + {"Freitag", []int{5}}, {"Samstag", []int{6}}, {"Sonntag", []int{0}}, +} + +func daysLabel(days []int) string { + for _, d := range dayChoices { + if fmt.Sprint(d.days) == fmt.Sprint(days) || (len(d.days) == 0 && len(days) == 0) { + return d.label + } + } + return "täglich" +} + +func daysFromLabel(l string) []int { + for _, d := range dayChoices { + if i18n.T(d.label) == l || d.label == l { + return append([]int(nil), d.days...) + } + } + return nil +} + +// ---------------------------------------------------------------- Liste + +func (a *App) schedules() []domain.Schedule { return a.st.Settings().Schedules } + +func (a *App) scheduleItems() []pickItem { + var out []pickItem + for _, sc := range a.schedules() { + hint := i18n.T("noch nie gelaufen") + if !sc.LastRun.IsZero() { + hint = sc.LastRun.Format("02.01. 15:04") + fmt.Sprintf(" ✓%d", sc.LastOK) + if sc.LastFail > 0 { + hint += fmt.Sprintf(" ×%d", sc.LastFail) + } + } + if a.schedRun[sc.ID] { + hint = i18n.T("läuft …") + } + if sc.Off { + hint = i18n.T("aus") + } + out = append(out, pickItem{value: sc.ID, label: sc.At + " " + i18n.T(daysLabel(sc.Days)) + " · " + sc.Name, + detail: a.schedTargetText(sc), hint: hint}) + } + return out +} + +func (a *App) schedTargetText(sc domain.Schedule) string { + if sc.Folder != "" { + return "▸ " + sc.Folder + } + var names []string + for _, id := range sc.Conns { + if c, ok := a.st.Connection(id); ok { + names = append(names, c.Alias) + } + } + return strings.Join(names, ", ") +} + +func (a *App) openSchedules() tea.Cmd { + p := newPicker(i18n.T("Zeitpläne"), i18n.T("Name, Zeit oder Ziel"), a.scheduleItems(), "\x00", func(it pickItem) tea.Cmd { + return a.showScheduleResult(it.value) + }) + p.help = i18n.T("Läuft, solange sshTermy offen ist; Verpasstes holt es innerhalb von 12 h nach. Nur Hosts mit gespeichertem Passwort oder Key.") + p.reload = a.scheduleItems + p.keys = [][2]string{{"⏎", i18n.T("letztes Ergebnis")}, {"Strg+N", i18n.T("neu")}, {"Strg+E", i18n.T("bearbeiten")}, + {"Strg+R", i18n.T("jetzt ausführen")}, {"Strg+O", i18n.T("an/aus")}, {"Strg+D", i18n.T("löschen")}, {"Esc", i18n.T("zurück")}} + p.onKey = func(key string, it *pickItem) (tea.Cmd, bool) { + if key == "ctrl+n" { + a.pick = nil + return a.openScheduleForm(domain.Schedule{At: "03:00"}), true + } + if it == nil { + return nil, false + } + sc, ok := a.scheduleByID(it.value) + if !ok { + return nil, false + } + switch key { + case "ctrl+e": + a.pick = nil + return a.openScheduleForm(sc), true + case "ctrl+r": + cmd := a.startSchedule(sc) + p.items = a.scheduleItems() + return cmd, true + case "ctrl+o": + a.updateSchedule(sc.ID, func(x *domain.Schedule) { x.Off = !x.Off }) + p.items = a.scheduleItems() + return nil, true + case "ctrl+d", "delete": + _ = a.st.UpdateSettings(func(s *domain.Settings) { + for i, x := range s.Schedules { + if x.ID == sc.ID { + s.Schedules = append(s.Schedules[:i], s.Schedules[i+1:]...) + break + } + } + }) + p.items = a.scheduleItems() + p.sel = clamp(p.sel, 0, max(0, len(p.items)-1)) + a.flash(i18n.T("Zeitplan gelöscht: ") + sc.Name) + return nil, true + } + return nil, false + } + if len(p.items) == 0 { + p.extra = func(string) *pickItem { + return &pickItem{value: "\x00new", label: i18n.T("+ Neuer Zeitplan (Strg+N)")} + } + inner := p.onPick + p.onPick = func(it pickItem) tea.Cmd { + if it.value == "\x00new" { + return a.openScheduleForm(domain.Schedule{At: "03:00"}) + } + return inner(it) + } + } + return a.openPicker(p) +} + +func (a *App) scheduleByID(id string) (domain.Schedule, bool) { + for _, sc := range a.schedules() { + if sc.ID == id { + return sc, true + } + } + return domain.Schedule{}, false +} + +func (a *App) updateSchedule(id string, fn func(*domain.Schedule)) { + _ = a.st.UpdateSettings(func(s *domain.Settings) { + for i := range s.Schedules { + if s.Schedules[i].ID == id { + fn(&s.Schedules[i]) + } + } + }) +} + +func (a *App) showScheduleResult(id string) tea.Cmd { + sc, ok := a.scheduleByID(id) + if !ok { + return nil + } + if sc.LastRun.IsZero() { + a.flash(i18n.T("Noch nie gelaufen · Strg+R führt ihn jetzt aus")) + return a.openSchedules() + } + title := fmt.Sprintf(i18n.T("%s · %s · %d ok, %d Fehler"), sc.Name, sc.LastRun.Format("02.01.2006 15:04"), sc.LastOK, sc.LastFail) + a.modal = textModal(title, strings.Split(sc.LastText, "\n")) + return nil +} + +// ---------------------------------------------------------------- Formular + +func (a *App) openScheduleForm(sc domain.Schedule) tea.Cmd { + title := i18n.T("Neuer Zeitplan") + if sc.ID != "" { + title = i18n.T("Zeitplan: ") + sc.Name + } + f := &form{title: title} + f.text("name", "Name", sc.Name, i18n.T("z. B. „Switch-Configs sichern“")) + f.text("at", i18n.T("Uhrzeit"), sc.At, i18n.T("HH:MM, Ortszeit dieses Rechners")) + var days []string + for _, d := range dayChoices { + days = append(days, i18n.T(d.label)) + } + f.choice("days", i18n.T("Tage"), days, i18n.T(daysLabel(sc.Days)), "") + folders := []string{i18n.T("— einzelne Verbindungen")} + var walk func(n *domain.TreeNode) + walk = func(n *domain.TreeNode) { + for _, fo := range n.Folders { + folders = append(folders, fo.Path) + walk(fo) + } + } + walk(a.st.Tree()) + cur := folders[0] + if sc.Folder != "" { + cur = sc.Folder + } + f.choice("folder", i18n.T("Ordner"), folders, cur, i18n.T("alle Verbindungen darin, auch in Unterordnern")) + var aliases []string + for _, id := range sc.Conns { + if c, ok := a.st.Connection(id); ok { + aliases = append(aliases, c.Alias) + } + } + f.text("conns", i18n.T("Verbindungen"), strings.Join(aliases, ", "), i18n.T("Aliasse durch Komma getrennt (nur ohne Ordner)")).hidden = func(f *form) bool { + return f.sel("folder") != folders[0] + } + rbs := []string{i18n.T("— eigene Befehle")} + rbIDs := map[string]string{} + rbCur := rbs[0] + for _, rb := range a.st.Runbooks("") { + label := rb.Name + rbs = append(rbs, label) + rbIDs[label] = rb.ID + if rb.ID == sc.RunbookID { + rbCur = label + } + } + a.schedRBIDs = rbIDs + f.choice("runbook", "Runbook", rbs, rbCur, i18n.T("Runbooks ohne Variablen und ohne Skripte")) + f.text("steps", i18n.T("Befehle"), strings.Join(sc.Steps, " "+schedStepSep+" "), i18n.T("mehrere Schritte mit ;; trennen · {{host}} {{alias}} werden je Host eingesetzt · Gefährliches geht nie")).hidden = func(f *form) bool { + return f.sel("runbook") != rbs[0] + } + f.get("conns").in.Placeholder = "sw-core, sw-etage1" + f.get("steps").in.Placeholder = "show running-config ;; show vlan" + a.formSched = sc + a.returnToTerminal = a.scr == scrTerminal + a.form, a.scr = f, scrScheduleForm + return f.setFocus(0) +} + +func (a *App) saveScheduleForm() error { + f := a.form + sc := a.formSched + sc.Name = f.str("name") + h, m, ok := domain.ParseClock(f.str("at")) + if !ok { + return errors.New(i18n.T("Uhrzeit als HH:MM, z. B. 03:00")) + } + sc.At = fmt.Sprintf("%02d:%02d", h, m) + sc.Days = daysFromLabel(f.sel("days")) + sc.Folder, sc.Conns = "", nil + if fo := f.sel("folder"); !strings.HasPrefix(fo, "—") { + sc.Folder = fo + } else { + for _, alias := range strings.Split(f.str("conns"), ",") { + alias = strings.TrimSpace(alias) + if alias == "" { + continue + } + c, ok := a.connByAlias(alias) + if !ok { + return fmt.Errorf(i18n.T("Verbindung „%s“ gibt es nicht"), alias) + } + sc.Conns = append(sc.Conns, c.ID) + } + } + sc.RunbookID, sc.Steps = a.schedRBIDs[f.sel("runbook")], nil + if sc.RunbookID == "" { + for _, st := range strings.Split(f.str("steps"), schedStepSep) { + if st = strings.TrimSpace(st); st != "" { + sc.Steps = append(sc.Steps, st) + } + } + } + if sc.Name == "" { + sc.Name = orDefault(firstOf(sc.Steps), i18n.T("Zeitplan")) + } + if len(a.schedConns(sc)) == 0 { + return errors.New(i18n.T("Kein Ziel: Ordner wählen oder Verbindungen eintragen")) + } + if _, err := a.schedSteps(sc); err != nil { + return err + } + if sc.ID == "" { + sc.ID = fmt.Sprintf("sch-%d", time.Now().UnixNano()) + // erst ab jetzt: nicht sofort einen „verpassten“ Termin von heute nachholen + sc.LastRun = time.Now() + } + return a.st.UpdateSettings(func(s *domain.Settings) { + for i := range s.Schedules { + if s.Schedules[i].ID == sc.ID { + s.Schedules[i] = sc + return + } + } + s.Schedules = append(s.Schedules, sc) + }) +} + +func firstOf(x []string) string { + if len(x) == 0 { + return "" + } + return trunc(x[0], 30) +} + +func (a *App) connByAlias(alias string) (domain.Connection, bool) { + for _, c := range a.st.Connections() { + if strings.EqualFold(c.Alias, alias) { + return c, true + } + } + return domain.Connection{}, false +} + +// schedConns: Ziel-Verbindungen (nur SSH; Telnet/Konsole/Lokal brauchen +// einen Tab). +func (a *App) schedConns(sc domain.Schedule) []domain.Connection { + var list []domain.Connection + if sc.Folder != "" { + for _, c := range a.st.Connections() { + if domain.InFolder(c.Group, sc.Folder) { + list = append(list, c) + } + } + } else { + for _, id := range sc.Conns { + if c, ok := a.st.Connection(id); ok { + list = append(list, c) + } + } + } + out := list[:0] + for _, c := range list { + if !c.Protocol.Raw() { + out = append(out, c) + } + } + return out +} + +// schedSteps: die Schritte, geprüft für einen Lauf ohne Aufsicht. +func (a *App) schedSteps(sc domain.Schedule) ([]string, error) { + steps := sc.Steps + if sc.RunbookID != "" { + var found bool + for _, rb := range a.st.Runbooks("") { + if rb.ID == sc.RunbookID { + if len(rb.Files) > 0 { + return nil, errors.New(i18n.T("Runbooks mit Skripten des Agenten lassen sich nicht einplanen")) + } + steps, found = rb.Steps, true + } + } + if !found { + return nil, errors.New(i18n.T("Das Runbook gibt es nicht mehr")) + } + } + if len(steps) == 0 { + return nil, errors.New(i18n.T("Keine Befehle")) + } + if v := runbook.Vars(steps); len(v) > 0 { + return nil, fmt.Errorf(i18n.T("Variable {{%s}} kann ohne Aufsicht niemand ausfüllen"), v[0].Name) + } + if d := broadcast.Dangers(steps); len(d) > 0 { + return nil, fmt.Errorf(i18n.T("Gefährlicher Befehl läuft nie nach Zeitplan: %s (%s)"), trunc(d[0].Command, 40), strings.Join(d[0].Reasons, ", ")) + } + return steps, nil +} + +// ---------------------------------------------------------------- Ausführen + +type schedDoneMsg struct { + id string + results []broadcast.Result + err error +} + +// scheduleTick: fällige Zeitpläne starten (jede Sekunde aus onTick). +func (a *App) scheduleTick() tea.Cmd { + if a.st == nil || a.scr == scrUnlock { + return nil + } + now := time.Now() + var cmds []tea.Cmd + for _, sc := range a.schedules() { + if sc.Due(now) && !a.schedRun[sc.ID] { + cmds = append(cmds, a.startSchedule(sc)) + } + } + return tea.Batch(cmds...) +} + +func (a *App) startSchedule(sc domain.Schedule) tea.Cmd { + if a.schedRun[sc.ID] { + a.flash(i18n.T("Läuft schon: ") + sc.Name) + return nil + } + a.updateSchedule(sc.ID, func(x *domain.Schedule) { x.LastRun = time.Now() }) + steps, err := a.schedSteps(sc) + conns := a.schedConns(sc) + if err == nil && len(conns) == 0 { + err = errors.New(i18n.T("keine SSH-Verbindung im Ziel")) + } + if err != nil { + return func() tea.Msg { return schedDoneMsg{id: sc.ID, err: err} } + } + if a.schedRun == nil { + a.schedRun = map[string]bool{} + } + a.schedRun[sc.ID] = true + job := broadcast.Job{Conns: conns, Steps: steps} + if runbook.HasBuiltins(steps) { + for _, c := range conns { + job.PerHost = append(job.PerHost, runbook.Fill(steps, nil, c)) + } + } + dial := schedDialer(a) + a.flash(i18n.T("Zeitplan startet: ") + sc.Name) + id := sc.ID + return func() tea.Msg { + ctx, cancel := context.WithTimeout(context.Background(), 30*time.Minute) + defer cancel() + res := broadcast.Run(ctx, job, dial, func(int, broadcast.Result) {}) + return schedDoneMsg{id: id, results: res} + } +} + +// schedDialer: in Tests austauschbar. +var schedDialer = func(a *App) broadcast.Dialer { return a.quietDialer() } + +// quietDialer: wie der Broadcast, aber ohne Rückfragen. Unbekannte Host-Keys +// und fehlende Passwörter lassen den Host scheitern. +func (a *App) quietDialer() broadcast.Dialer { + hk, st := a.hostKeys, a.st + relayDial := a.relayDialer() + return func(ctx context.Context, c domain.Connection) (broadcast.Executor, error) { + opts := sshx.Options{ + HostKeys: hk, + Resolve: st.Connection, + Relay: relayDial, + Prompt: func(string, string, string) bool { return false }, + AskSecret: func(label string) (string, error) { + return "", fmt.Errorf(i18n.T("braucht eine Eingabe (%s), Zeitpläne fragen nie"), label) + }, + } + cl, err := sshx.Dial(ctx, c, opts) + if err != nil { + return nil, err + } + return broadcast.SSH(cl, sshx.ShellTiming{}), nil + } +} + +func (a *App) scheduleMsg(msg tea.Msg) (tea.Cmd, bool) { + m, ok := msg.(schedDoneMsg) + if !ok { + return nil, false + } + delete(a.schedRun, m.id) + sc, ok := a.scheduleByID(m.id) + if !ok { + return nil, true + } + if m.err != nil { + a.updateSchedule(m.id, func(x *domain.Schedule) { + x.LastOK, x.LastFail, x.LastText = 0, 1, "× "+m.err.Error() + }) + a.flashErr(i18n.T("Zeitplan „") + sc.Name + "“: " + m.err.Error()) + a.schedDesktop(sc.Name, m.err.Error()) + return nil, true + } + okN, failN, _ := broadcast.Summary(m.results) + text := scheduleReport(m.results) + a.updateSchedule(m.id, func(x *domain.Schedule) { x.LastOK, x.LastFail, x.LastText = okN, failN, text }) + msgText := fmt.Sprintf(i18n.T("Zeitplan „%s“ fertig: %d ok, %d Fehler"), sc.Name, okN, failN) + if failN > 0 { + a.flashErr(msgText) + } else { + a.flashOK(msgText) + } + a.schedDesktop(sc.Name, fmt.Sprintf(i18n.T("%d ok, %d Fehler"), okN, failN)) + if a.pick != nil && a.pick.title == i18n.T("Zeitpläne") { + a.pick.items = a.scheduleItems() + } + return nil, true +} + +func (a *App) schedDesktop(name, body string) { + if (a.blurred || a.lock != nil) && a.desktopNotifyOn() && a.notifyOn() { + if a.lock != nil { + body = i18n.T("Zeitplan ist gelaufen") + } + a.sendDesktop("sshTermy · "+name, body) + } +} + +// scheduleReport: Ergebnis je Host, Ausgabe gekürzt (bleibt in den +// Einstellungen, also klein halten). +func scheduleReport(rs []broadcast.Result) string { + var b strings.Builder + per := max(400, 12000/max(1, len(rs))) + for _, r := range rs { + mark := "✓" + if !r.OK() { + mark = "×" + } + fmt.Fprintf(&b, "%s %s", mark, r.Alias) + if r.Exit > 0 { + fmt.Fprintf(&b, " (exit %d)", r.Exit) + } + if r.Err != "" { + b.WriteString(": " + r.Err) + } + b.WriteString("\n") + if out := strings.TrimSpace(r.Output); out != "" { + if len(out) > per { + out = "…" + out[len(out)-per:] + } + for _, l := range strings.Split(out, "\n") { + b.WriteString(" " + strings.TrimRight(l, "\r") + "\n") + } + } + } + return strings.TrimRight(b.String(), "\n") +} diff --git a/internal/ui/schedule_test.go b/internal/ui/schedule_test.go new file mode 100644 index 0000000..9a81990 --- /dev/null +++ b/internal/ui/schedule_test.go @@ -0,0 +1,82 @@ +package ui + +import ( + "context" + "errors" + "strings" + "testing" + "time" + + "github.com/db9979/sshtermy/internal/broadcast" + "github.com/db9979/sshtermy/internal/domain" + "github.com/db9979/sshtermy/internal/sshx" +) + +type schedExec struct{ alias string } + +func (e schedExec) NetDevice() bool { return false } +func (e schedExec) Learned() bool { return false } +func (e schedExec) Close() error { return nil } +func (e schedExec) Exec(_ context.Context, cmd string) (sshx.RunResult, error) { + return sshx.RunResult{Output: []byte(e.alias + ": " + cmd + "\n")}, nil +} +func (e schedExec) RunInShell(_ context.Context, cmds []string) (sshx.RunResult, error) { + return sshx.RunResult{Output: []byte(strings.Join(cmds, "\n"))}, nil +} + +func TestScheduleFormAndRun(t *testing.T) { + a := newPaletteTestApp(t) + a.pal = nil + for _, alias := range []string{"sw-1", "sw-2"} { + if _, err := a.st.UpsertConnection(domain.Connection{Alias: alias, Host: alias, Username: "admin", Auth: domain.AuthAgent, Group: "Netz"}); err != nil { + t.Fatal(err) + } + } + old := schedDialer + t.Cleanup(func() { schedDialer = old }) + schedDialer = func(*App) broadcast.Dialer { + return func(_ context.Context, c domain.Connection) (broadcast.Executor, error) { + if c.Alias == "sw-2" { + return nil, errors.New("host key unbekannt") + } + return schedExec{c.Alias}, nil + } + } + a.openScheduleForm(domain.Schedule{At: "03:00"}) + f := a.form + f.get("name").in.SetValue("Sicherung") + f.get("at").in.SetValue("3:5") + if err := a.saveScheduleForm(); err == nil { + t.Fatal("Uhrzeit 3:5 muss abgelehnt werden") + } + f.get("at").in.SetValue("0300") + setChoice(t, f, "folder", "Netz") + f.get("steps").in.SetValue("reboot") + if err := a.saveScheduleForm(); err == nil || !strings.Contains(err.Error(), "Gefährlich") { + t.Fatalf("Gefahr muss abgelehnt werden: %v", err) + } + f.get("steps").in.SetValue("uptime ;; hostname {{alias}}") + if err := a.saveScheduleForm(); err != nil { + t.Fatal(err) + } + scs := a.schedules() + if len(scs) != 1 || scs[0].At != "03:00" || scs[0].Folder != "Netz" || len(scs[0].Steps) != 2 { + t.Fatalf("%+v", scs) + } + // frisch angelegt: kein „verpasster“ Lauf von heute + if scs[0].Due(time.Now()) { + t.Fatal("darf nicht sofort laufen") + } + cmd := a.startSchedule(scs[0]) + if !a.schedRun[scs[0].ID] { + t.Fatal("läuft nicht") + } + a.scheduleMsg(cmd()) + sc, _ := a.scheduleByID(scs[0].ID) + if sc.LastOK != 1 || sc.LastFail != 1 || !strings.Contains(sc.LastText, "sw-1: hostname sw-1") || !strings.Contains(sc.LastText, "× sw-2") { + t.Fatalf("Ergebnis: %d/%d\n%s", sc.LastOK, sc.LastFail, sc.LastText) + } + if a.schedRun[sc.ID] { + t.Fatal("muss als fertig gelten") + } +} diff --git a/internal/ui/testdata/golden/palette.de.txt b/internal/ui/testdata/golden/palette.de.txt index 318057d..e95789b 100644 --- a/internal/ui/testdata/golden/palette.de.txt +++ b/internal/ui/testdata/golden/palette.de.txt @@ -1,6 +1,6 @@ >_ sshTermy vdev Idee: Dominik Bornhäußer ● KI Verbindungen 6 / suchen │ ▾ Netzwerk - ┌─ ◆ Befehlspalette 21 Einträge ────────────────────────────────────── × ─┐ + ┌─ ◆ Befehlspalette 22 Einträge ────────────────────────────────────── × ─┐ ▾ Netzwerk │ $ Ziel, Frage, Befehl, Tunnel, Verbindung oder user@host:port … │ ○ # switc│ ──────────────────────────────────────────────────────────────────────── │ ▾ Produktio│ // verbindungen │ @@ -17,12 +17,12 @@ │ [k] SSH-Schlüssel erzeugen / auf den Server übertragen c │ oder │ [*] Broadcast: Befehl auf mehreren Hosts m │ │ [/] Netzwerk-Scan: SSH-Geräte finden f │ + │ [>] Zeitpläne: Broadcast/Runbook nach Uhrzeit z │ │ [&] Mit dem Team teilen (verschlüsselt, ohne Passwörter) Team │ │ [&] Team-Paket übernehmen Team │ │ [&] Team-Ordner (veröffentlicht / abonniert) Team │ │ [#] Sitzungsprotokolle durchsuchen l │ │ [$] Lokale Shell öffnen Alt+L │ - │ [|] Arbeitsplätze … w │ │ │ │ ↑↓ wählen ⏎ ausführen Esc schließen │ └──────────────────────────────────────────────────────────────────────────┘ diff --git a/internal/ui/testdata/golden/palette.en.txt b/internal/ui/testdata/golden/palette.en.txt index f1e8a70..9a04e68 100644 --- a/internal/ui/testdata/golden/palette.en.txt +++ b/internal/ui/testdata/golden/palette.en.txt @@ -1,6 +1,6 @@ >_ sshTermy vdev Idea: Dominik Bornhäußer ● AI connections 6 / search │ ▾ Netzwerk - ┌─ ◆ Command palette 21 entries ────────────────────────────────────── × ─┐ + ┌─ ◆ Command palette 22 entries ────────────────────────────────────── × ─┐ ▾ Netzwerk │ $ Goal, question, command, tunnel, connection or user@host:port … │ ○ # switc│ ──────────────────────────────────────────────────────────────────────── │ ▾ Produktio│ // connections │ @@ -17,12 +17,12 @@ │ [k] Generate SSH key / copy it to the server c │r between │ [*] Broadcast: command on several hosts m │ │ [/] Network scan: find SSH devices f │ + │ [>] Schedules: broadcast/runbook at a set time z │ │ [&] Share with the team (encrypted, no passwords) Team │ │ [&] Import team package Team │ │ [&] Team folders (published / subscribed) Team │ │ [#] Search session logs l │ │ [$] Open local shell Alt+L │ - │ [|] Workspaces … w │ │ │ │ ↑↓ select ⏎ run Esc close │ └──────────────────────────────────────────────────────────────────────────┘ diff --git a/site/de/index.html b/site/de/index.html index ed5606a..050ba7e 100644 --- a/site/de/index.html +++ b/site/de/index.html @@ -124,6 +124,8 @@ sudo apt update && sudo apt install sshtermy

Host-Übersicht (F6)

CPU, Last, RAM, Platte und Updates bei Servern; Firmware, Ports und VLANs bei Aruba- und Cisco-Switches, mit Konfig-Sicherung und Diff.

Tunnel

-L, -R, -D (SOCKS5) und Webdienste mit einem Klick.

Broadcast

Ein Befehl oder Runbook parallel auf einer ganzen Gruppe, Ergebnisse nebeneinander.

+

Zeitpläne

Broadcast oder Runbook zu einer Uhrzeit auf einem Ordner, z. B. nachts show running-config auf allen Switches.

+

Passwortmanager

Passwörter und 2FA-Codes aus 1Password, Bitwarden, KeePassXC oder pass; gespeichert wird nur der Verweis.

Netzwerk-Scan

SSH-Geräte in einem Subnetz finden und als Verbindungen anlegen.

Gefahr-Regeln

Feste Regeln markieren riskante Befehle rot; sie brauchen zweimal Enter, auch beim Einfügen.

Sitzungsprotokoll

Verschlüsselt, durchsuchbar, mit KI-Zusammenfassung, Markdown-Export und KI-Änderungsbericht (b) für Ticket oder Doku.

@@ -182,6 +184,7 @@ sudo apt update && sudo apt install sshtermy Strg+FIm Verlauf suchen F5 → eServer-Datei im eigenen Editor (Speichern lädt hoch) l → bSitzungsprotokolle: KI-Änderungsbericht + z (Manager)Zeitpläne für Broadcast und Runbooks ⇧+F10Tab in ein eigenes Terminalfenster F10Zurück zum Manager (Sitzungen laufen weiter) F1 / F12 / Strg+QHilfe / Über und Update / Beenden diff --git a/site/handout/sshtermy-kurzreferenz-de.pdf b/site/handout/sshtermy-kurzreferenz-de.pdf index 8248760..e50d19d 100644 Binary files a/site/handout/sshtermy-kurzreferenz-de.pdf and b/site/handout/sshtermy-kurzreferenz-de.pdf differ diff --git a/site/handout/sshtermy-quickref-en.pdf b/site/handout/sshtermy-quickref-en.pdf index f916cd6..1a9f034 100644 Binary files a/site/handout/sshtermy-quickref-en.pdf and b/site/handout/sshtermy-quickref-en.pdf differ diff --git a/site/index.html b/site/index.html index beffcf5..680ebc9 100644 --- a/site/index.html +++ b/site/index.html @@ -124,6 +124,8 @@ sudo apt update && sudo apt install sshtermy

Host overview (F6)

CPU, load, RAM, disk and updates for servers; firmware, ports and VLANs for Aruba and Cisco switches, with config backup and diff.

Tunnels

-L, -R, -D (SOCKS5) and web services with one click.

Broadcast

One command or runbook on a whole group in parallel, results side by side.

+

Schedules

Broadcast or runbook at a set time on a folder, e.g. nightly show running-config on all switches.

+

Password manager

Passwords and 2FA codes from 1Password, Bitwarden, KeePassXC or pass; only the reference is stored.

Network scan

Find SSH devices in a subnet and create them as connections.

Danger rules

Fixed rules mark risky commands red; they need Enter twice, also when pasted.

Session log

Encrypted, searchable, with AI summary, Markdown export and an AI change report (b) for tickets or docs.

@@ -181,6 +183,7 @@ sudo apt update && sudo apt install sshtermy Ctrl+FSearch the scrollback F5 → eServer file in your own editor (saving uploads it) l → bSession logs: AI change report + z (manager)Schedules for broadcast and runbooks ⇧+F10Move the tab to its own terminal window F10Back to the manager (sessions keep running) F12About and update diff --git a/tools/handout/content.mjs b/tools/handout/content.mjs index 050b96c..394b5f0 100644 --- a/tools/handout/content.mjs +++ b/tools/handout/content.mjs @@ -37,7 +37,7 @@ export const de = { ['t', 'Tunnel anlegen'], ['c', 'SSH-Schlüssel erzeugen / übertragen'], ['q', 'Schnellbefehle bearbeiten'], - ['m / f', 'Broadcast / Netzwerk-Scan'], + ['m / f / z', 'Broadcast / Netzwerk-Scan / Zeitpläne'], ['w / g', 'Arbeitsplätze / Ordner als Raster öffnen'], ['s / y', 'KI-Einstellungen / Sync zwischen Rechnern'], ['i', 'importieren (ssh config, PuTTY, MobaXterm, Ansible, CSV)'], @@ -222,7 +222,7 @@ export const en = { ['t', 'add a tunnel'], ['c', 'create / copy an SSH key'], ['q', 'edit quick commands'], - ['m / f', 'broadcast / network scan'], + ['m / f / z', 'broadcast / network scan / schedules'], ['w / g', 'workspaces / open folder as a grid'], ['s / y', 'AI settings / sync between computers'], ['i', 'import (ssh config, PuTTY, MobaXterm, Ansible, CSV)'], diff --git a/tools/handout/keys.sha256 b/tools/handout/keys.sha256 index 1de3c1d..8d00f22 100644 --- a/tools/handout/keys.sha256 +++ b/tools/handout/keys.sha256 @@ -1 +1 @@ -1d59f3815385b6f6c84efefcfb3dd5b53b11118b953abdb15150409e50b02724 +1a86a2f0f3f968e5cd68e0cbed0a3cbd5d77e4b23612debf737ec8ee0ecedc50