mirror of
https://github.com/db9979/sshtermy.git
synced 2026-12-05 12:24:08 +01:00
* Absturzschutz: Fehler in Hintergrundarbeit beenden sshTermy nicht mehr; Zeitgrenzen für Update-Download und Team-Abo; Gast-Tasten über Warteschlange Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018i4GUkBzZ657Au6Rz4BPXj * CI: Zeitgrenzen je Job, alte Läufe abbrechen, Tests in zufälliger Reihenfolge; make check; Bibliotheken aktualisiert Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018i4GUkBzZ657Au6Rz4BPXj * update: Stillstand auch ohne Lesefehler erkennen Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018i4GUkBzZ657Au6Rz4BPXj * Zufallstests für Teilen, Vermittler, MCP, Syslog, KI-Antworten, Sync und Fenster-Rahmen; Syslog-Empfang übersteht kaputte Pakete; MCP antwortet auch nach Fehler Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018i4GUkBzZ657Au6Rz4BPXj * Tests: Tresor (Passwortwechsel, Sperre, Blobs, KDF-Grenzen), SFTP-Rundreise, serielle Konsole mit Ersatzkabel Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018i4GUkBzZ657Au6Rz4BPXj * Dauerlauf-Test (make soak) und nächtlicher Lauf mit langen Zufallstests Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018i4GUkBzZ657Au6Rz4BPXj * Fuzz: Zeitlimit je Eingabe auch für die neuen Tests Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018i4GUkBzZ657Au6Rz4BPXj * Selbstprüfung: sshtermy doctor und Palette › Hilfe › Fehlersuche; versehentlich eingecheckte Programmdatei entfernt Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018i4GUkBzZ657Au6Rz4BPXj * Oberfläche aufteilen, erster Schritt: Mausbereiche (ui/clickzone) und abgelegte Dateien (ui/dropped) als eigene Pakete Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018i4GUkBzZ657Au6Rz4BPXj * Doku: Absturzschutz und Selbstprüfung in README, Webseite und Handbuch; Plan zur Aufteilung von internal/ui; Zusehen-WASM neu gebaut Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018i4GUkBzZ657Au6Rz4BPXj --------- Co-authored-by: Claude <noreply@anthropic.com>
83 lines
1.9 KiB
Go
83 lines
1.9 KiB
Go
package sshx
|
|
|
|
import (
|
|
"bufio"
|
|
"context"
|
|
"strings"
|
|
|
|
"github.com/db9979/sshtermy/internal/i18n"
|
|
"github.com/db9979/sshtermy/internal/safe"
|
|
)
|
|
|
|
// ErrNetDevice: Exec-Abfragen sind bei Netzwerkgeräten tabu, weil z. B.
|
|
// Aruba/ProCurve dann die ganze Verbindung beenden.
|
|
var ErrNetDevice = i18n.NewError("bei Netzwerkgeräten keine Exec-Abfrage")
|
|
|
|
// RunScript führt ein sh-Skript in einer eigenen Exec-Sitzung aus ("sh -s",
|
|
// Skript über stdin), unsichtbar für das Terminal. Nur für Server.
|
|
func (c *Client) RunScript(ctx context.Context, script string) (string, error) {
|
|
if c.NetDevice {
|
|
return "", ErrNetDevice
|
|
}
|
|
s, err := c.NewSession()
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
defer s.Close()
|
|
s.Stdin = strings.NewReader(script)
|
|
type res struct {
|
|
out []byte
|
|
err error
|
|
}
|
|
done := make(chan res, 1)
|
|
go func() { out, err := s.Output("sh -s"); done <- res{out, err} }()
|
|
select {
|
|
case r := <-done:
|
|
if len(r.out) > 0 {
|
|
return string(r.out), nil // Exit-Code egal, solange etwas kam
|
|
}
|
|
return "", r.err
|
|
case <-ctx.Done():
|
|
return "", ctx.Err()
|
|
}
|
|
}
|
|
|
|
// StreamScript startet ein lang laufendes sh-Skript in einer eigenen
|
|
// Exec-Sitzung und reicht jede Ausgabezeile an line weiter, bis ctx endet
|
|
// oder das Skript aufhört. Nur für Server (wie RunScript).
|
|
func (c *Client) StreamScript(ctx context.Context, script string, line func(string)) error {
|
|
if c.NetDevice {
|
|
return ErrNetDevice
|
|
}
|
|
s, err := c.NewSession()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer s.Close()
|
|
s.Stdin = strings.NewReader(script)
|
|
out, err := s.StdoutPipe()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if err := s.Start("sh -s"); err != nil {
|
|
return err
|
|
}
|
|
go func() {
|
|
defer safe.Recover("sshx/run.go")
|
|
<-ctx.Done()
|
|
_ = s.Close() // beendet auch das Lesen unten
|
|
}()
|
|
sc := bufio.NewScanner(out)
|
|
sc.Buffer(make([]byte, 64<<10), 1<<20)
|
|
for sc.Scan() {
|
|
if ctx.Err() != nil {
|
|
break
|
|
}
|
|
line(sc.Text())
|
|
}
|
|
if ctx.Err() != nil {
|
|
return ctx.Err()
|
|
}
|
|
return sc.Err()
|
|
}
|