mirror of
https://github.com/db9979/sshtermy.git
synced 2026-12-05 12:24:08 +01:00
Befehlssätze je Hersteller als Dateien, eigene und Team-Sätze (1–16) (#123)
- internal/cmdset: ein YAML-Satz pro Hersteller (48 eingebaut) mit Varianten, Erkennung, Befehlen, Lesemustern, Logs, Syslog, Gefahrenregeln, Beispielen - Neue Hersteller: Switches, Firewalls, WLAN-Controller, Appliances; Comware und Huawei vervollständigt - Eigene Sätze (basiert auf), Formular, Test am Gerät, KI-Entwurf, Korrekturen übernehmen, Export/Import, Team-Sätze mit Freigabe - Sicherheit: nur Lesebefehle, Gefahrenregeln nur ergänzbar, eingebaute Kennungen und Erkennung haben Vorrang, Syslog-Schritte geprüft, Grenzen, Selbsttest - Doku: README, Webseite, Kurzreferenz Claude-Session: https://claude.ai/code/session_018i4GUhVDoXMfSDNsb58H5M Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
1 parent
dd6a9a759b
commit
a86c5b756d
98 files changed
+5053
-297
No files matched your search
+13
-1
@@ -47,7 +47,7 @@ sshTermy ist eine schlanke Terminal-Anwendung (TUI, eine einzige Datei, ~9 MB, k
|
||||
- **Host-Übersicht (F6)**: Server zeigen beim Verbinden CPU, Last, RAM, alle Platten (jedes echte Dateisystem; tmpfs, overlay, snap und Ähnliches bleiben weg), Laufzeit und offene Updates. Der Grenzwert für Platten (`g`) gilt für jede Platte einzeln.
|
||||
Bei Linux-Servern laufen, solange F6 offen ist, Live-Graphen aus Braille-Punkten für CPU, RAM, Netz und Platte
|
||||
(alle 2 s, `t` wechselt 5 min / 1 h, `z` zeigt sie groß über dem Terminal mit den Top-Prozessen; ein kleines,
|
||||
nur lesendes Skript in einer eigenen Exec-Sitzung, Panel zu = Skript beendet). Switches, Router und Firewalls (ArubaOS-Switch/ProCurve, ArubaOS-CX, Cisco IOS, Juniper Junos, MikroTik RouterOS, Fortinet FortiGate, Ubiquiti-UniFi-Switches) zeigen auf Abruf Firmware, Ports und VLANs; die show-Befehle laufen sichtbar am Prompt, nie als versteckte Exec-Sitzung
|
||||
nur lesendes Skript in einer eigenen Exec-Sitzung, Panel zu = Skript beendet). Switches, Router und Firewalls (ArubaOS-Switch/ProCurve, ArubaOS-CX, Cisco IOS/NX-OS/ASA/Small Business, Arista, Juniper, HPE Comware, Huawei, Dell, Extreme, Ruckus, Allied Telesis, Netgear, Zyxel, TP-Link, Lancom, MikroTik, FortiGate, Palo Alto, Sophos, Check Point, SonicWall, WatchGuard, pfSense/OPNsense, VyOS/EdgeOS, UniFi u. a.; siehe *Befehlssätze*) zeigen auf Abruf Firmware, Ports und VLANs; die show-Befehle laufen sichtbar am Prompt, nie als versteckte Exec-Sitzung
|
||||
- **Container** (`c` in F6 oder Palette „docker“): Docker- und Podman-Container und Kubernetes-Pods des Servers in einer Liste. ⏎ öffnet eine Shell im Container, Strg+L verfolgt die Logs, Strg+K lässt die KI die letzten 400 Log-Zeilen auswerten. Neustart und Start/Stopp werden nur am Prompt eingefügt, ⏎ führt sie aus. Braucht docker root und geht sudo ohne Passwort, nimmt sshTermy `sudo -n`
|
||||
- **Log-Blick (Alt+E oder `l` in F6)**: liest die Logs des Systems, auf dem du gerade bist, nur lesend, und zeigt Auffälligkeiten statt Zeilen. Linux/BSD: journalctl (oder Syslog-Dateien), fehlgeschlagene Units und Paket-Updates; Windows (PowerShell/WinRM): Ereignisprotokolle System/Application, Fehlanmeldungen 4625/4740 und gestoppte automatische Dienste; Switches und Firewalls: die Log-Befehle sichtbar am Prompt getippt (ProCurve/CX, Cisco, Junos, RouterOS, FortiOS, UniFi) und eine Port-Leiste. Gleiche Zeilen werden lokal ohne KI zu Mustern zusammengefasst (Zahlen, IPs, MACs ersetzt), bekannte Muster bekommen einen Klartext-Titel, einen Hinweis und lesende Prüfbefehle (`1`…`4` fügen sie ein). `n` *Was ist neu?* vergleicht mit deinem letzten Blick (neu, deutlich häufiger, verschwunden; die Grundlinie liegt verschlüsselt nur auf diesem Rechner), `x`/`X` blendet Rauschen für den Host oder den ganzen Ordner aus (wird gesynct). `t` Zeitleiste: Fehler und Warnungen pro Zeitabschnitt mit Marken für Neustarts, Paket-Updates, Konfigurationsänderungen und deine eigenen Befehle; ←→ wählt einen Abschnitt, `k` fragt die KI, was dort passierte. `k` lässt die KI ein Muster erklären, `b` schreibt einen KI-Lagebericht nur aus den verdichteten Mustern (Ursache, Zusammenhang, was prüfen). `z` Zeitraum 1 h … 7 Tage, `w` Meldungen der Logwache, `c` kopiert als Markdown. Bei Switches und Firewalls richtet `s` Syslog an sshTermy ein: Es zeigt die Befehle des Herstellers mit deiner eigenen IP und tippt sie nach Bestätigung sichtbar ein (am Gerät wird nichts gespeichert, `write memory` bleibt bei dir). Von sshTermy empfangenes Syslog fließt in den Log-Blick des Switches ein und reicht so weiter zurück als der Puffer im Gerät.
|
||||
- **Logwache** (Einstellungen › *Logwache*: Fehler oder Fehler + Warnungen): Solange ein Tab offen ist, folgt sshTermy im Hintergrund seinen Logs (Linux `journalctl -f`, Windows über WinRM jede Minute) und meldet nur, was gegenüber dem letzten Log-Blick neu oder kritisch ist, jedes Muster höchstens einmal pro Stunde: Toast, ▲ am Tab, Desktop-Benachrichtigung, wenn sshTermy im Hintergrund ist. Ausgeblendetes Rauschen bleibt still. *Syslog-Empfang* (UDP 5514, 1514 oder 514) nimmt Syslog von Switches und Firewalls an und ordnet es über IP oder Hostnamen der passenden Verbindung zu. Die Liste: Palette *Logwache: Meldungen* oder `w` im Log-Blick; ⏎ springt zum Muster im Log-Blick des Hosts, `x` blendet es als Rauschen aus. Fehlanmeldungen (SSH, Windows 4625) zählen ab 20 in 10 Minuten als Fehler; Link-down-Meldungen behalten die Schwere des Geräts (Cisco `LINK-3` = Fehler).
|
||||
@@ -133,6 +133,18 @@ sshTermy ist eine schlanke Terminal-Anwendung (TUI, eine einzige Datei, ~9 MB, k
|
||||
Das Profil geht in jeden KI-Prompt; Befehle, die das Gerät mit „% Invalid input“ ablehnt, merkt es sich und die
|
||||
KI schlägt sie nicht mehr vor. Im Manager editierbar (System, Befehlssatz, KI-Notizen). In der Palette schreibt
|
||||
„Für dieses System umschreiben“ einen Befehl in den passenden Dialekt um.
|
||||
- **Befehlssätze je Hersteller**: Was sshTermy an einem Gerät tippt (Blättern aus, Version, CPU/RAM, Ports, VLANs,
|
||||
Konfiguration, Logs, Syslog einrichten), wie es die Ausgabe liest und was es der KI sagt, steht je Hersteller in
|
||||
einer YAML-Datei, mit Varianten für ältere oder neuere Firmware. 48 eingebaut: Switches (Cisco, Arista, Aruba, HPE
|
||||
Comware, Huawei, Dell, Extreme, Ruckus, Allied Telesis, Netgear, Zyxel, TP-Link, Lancom …), Firewalls (FortiGate,
|
||||
Palo Alto, Sophos, Check Point, SonicWall, WatchGuard, Cisco ASA, pfSense, OPNsense, VyOS, EdgeOS), WLAN-Controller
|
||||
(Aruba, Cisco WLC) und Appliances (Proxmox, ESXi, Synology, QNAP, TrueNAS, iLO, iDRAC). Palette › Einstellungen ›
|
||||
*Befehlssätze*: `n` neuer Satz auf Basis eines eingebauten, `e`/`o` im Formular oder in der Datei bearbeiten, `t` am
|
||||
offenen Gerät testen, `k` KI-Entwurf aus dem Terminal, `l` die am Gerät korrigierten Befehle übernehmen, `x`/`i`
|
||||
Export/Import; Sätze geteilter Verbindungen gehen mit der Team-Freigabe mit. Sicherheit: eigene Sätze tippen nur
|
||||
Lesebefehle, können Gefahrenregeln nur ergänzen (eingebaute nie abschwächen), erkennen ein Gerät erst, wenn kein
|
||||
eingebauter Satz passt, Syslog-Schritte werden jedes Mal gezeigt und geprüft, und Team-Sätze bleiben aus, bis du sie
|
||||
freigibst (nach jeder Änderung erneut, mit Diff).
|
||||
- **Fehler erklären**: schlägt ein Befehl fehl, bietet die Vorschlagszeile „Warum? & Fix“ an (Alt+0). Die KI bekommt
|
||||
Befehl, Exit-Code und Ausgabe und antwortet mit Ursache und einfügbaren Befehlen
|
||||
- **Log-Diagnose**: Palette „KI: Log/Ausgabe auswerten“ (oder Text markieren, dann Palette): Die KI liest die Markierung
|
||||
|
||||
@@ -47,7 +47,7 @@ sshTermy is a lean terminal application (TUI, a single file, ~9 MB, no installer
|
||||
- **Host overview (F6)**: servers show CPU, load, RAM, every disk (all real file systems; tmpfs, overlay, snap and the like are left out), uptime and pending updates when you connect. The disk warning limit (`g`) applies to each disk separately.
|
||||
On Linux servers, while F6 is open, live Braille graphs show CPU, RAM, network and disk (every 2 s, `t` switches
|
||||
5 min / 1 h, `z` shows them large over the terminal with the top processes; a small read-only script in its own
|
||||
exec session, closing the panel ends it). Switches, routers and firewalls (ArubaOS-Switch/ProCurve, ArubaOS-CX, Cisco IOS, Juniper Junos, MikroTik RouterOS, Fortinet FortiGate, Ubiquiti UniFi switches) show firmware, ports and VLANs on request; the show commands run visibly at the prompt, never as a hidden exec session
|
||||
exec session, closing the panel ends it). Switches, routers and firewalls (ArubaOS-Switch/ProCurve, ArubaOS-CX, Cisco IOS/NX-OS/ASA/Small Business, Arista, Juniper, HPE Comware, Huawei, Dell, Extreme, Ruckus, Allied Telesis, Netgear, Zyxel, TP-Link, Lancom, MikroTik, FortiGate, Palo Alto, Sophos, Check Point, SonicWall, WatchGuard, pfSense/OPNsense, VyOS/EdgeOS, UniFi and more; see *Command sets*) show firmware, ports and VLANs on request; the show commands run visibly at the prompt, never as a hidden exec session
|
||||
- **Containers** (`c` in F6 or palette “docker”): Docker and Podman containers and Kubernetes pods of the server in one list. ⏎ opens a shell in the container, Ctrl+L follows the logs, Ctrl+K lets the AI analyze the last 400 log lines. Restart and start/stop are only inserted at the prompt, ⏎ runs them. Uses `sudo -n` when docker needs root and sudo works without a password
|
||||
- **Log view (Alt+E, or `l` in F6)**: reads the logs of the system you are on, read-only, and shows anomalies instead of lines. Linux/BSD: journalctl (or syslog files), failed units and package updates; Windows (PowerShell/WinRM): event logs System/Application, failed sign-ins 4625/4740 and stopped automatic services; switches and firewalls: the log commands typed visibly at the prompt (ProCurve/CX, Cisco, Junos, RouterOS, FortiOS, UniFi) plus a port bar. Same lines are grouped into patterns locally, without AI (numbers, IPs, MACs replaced), known patterns get a plain title, hint and read-only check commands (`1`…`4` insert them). `n` *What's new?* compares with your last look (new, much more frequent, gone; the baseline stays encrypted on this computer), `x`/`X` hides noise for the host or the whole folder (synced). `t` timeline: errors and warnings per time slot with marks for reboots, package updates, config changes and your own commands; ←→ picks a slot, `k` asks the AI what happened there. `k` lets the AI explain a pattern, `b` writes an AI status report from the condensed patterns only (cause, connections, what to check). `z` period 1 h … 7 days, `w` log watch alerts, `c` copies as Markdown. On switches and firewalls `s` sets up syslog to sshTermy: it shows the vendor's commands with your own IP and types them visibly after you confirm (nothing is saved on the device; `write memory` stays with you). Syslog received by sshTermy is merged into the switch's log view, so it reaches further back than the device's own buffer.
|
||||
- **Log watch** (Settings › *Log watch*: errors or errors + warnings): while a tab is open, sshTermy follows its logs in the background (Linux `journalctl -f`, Windows over WinRM every minute) and reports only what is new compared with the last log view or critical, each pattern at most once an hour: toast, ▲ on the tab, desktop notification when sshTermy is in the background. Hidden noise stays quiet. *Syslog receiver* (UDP 5514, 1514 or 514) takes syslog from switches and firewalls and assigns it to the matching connection by IP or host name. The list: palette *Log watch: alerts* or `w` in the log view; ⏎ jumps to the pattern in the host's log view, `x` hides it as noise. Failed sign-ins (SSH, Windows 4625) count as an error from 20 in 10 minutes; link-down messages keep the device's severity (Cisco `LINK-3` = error).
|
||||
@@ -131,6 +131,17 @@ sshTermy is a lean terminal application (TUI, a single file, ~9 MB, no installer
|
||||
The profile goes into every AI prompt; commands the device rejects with “% Invalid input” are remembered and the
|
||||
AI stops suggesting them. Editable in the manager (system, command set, AI notes). In the palette,
|
||||
“Rewrite for this system” rewrites a command into the matching dialect.
|
||||
- **Command sets per vendor**: what sshTermy types on a device (paging off, version, CPU/RAM, ports, VLANs, config, logs,
|
||||
syslog setup), how it reads the output and what it tells the AI lives in one YAML file per vendor, with variants for
|
||||
older or newer firmware. 48 built in: switches (Cisco, Arista, Aruba, HPE Comware, Huawei, Dell, Extreme, Ruckus,
|
||||
Allied Telesis, Netgear, Zyxel, TP-Link, Lancom …), firewalls (FortiGate, Palo Alto, Sophos, Check Point, SonicWall,
|
||||
WatchGuard, Cisco ASA, pfSense, OPNsense, VyOS, EdgeOS), WLAN controllers (Aruba, Cisco WLC) and appliances
|
||||
(Proxmox, ESXi, Synology, QNAP, TrueNAS, iLO, iDRAC). Palette › Settings › *Command sets*: `n` new set based on a
|
||||
built-in one, `e`/`o` edit in the form or the file, `t` test on the open device, `k` AI draft from the terminal,
|
||||
`l` take over the commands you corrected on a device, `x`/`i` export/import; sets used by shared connections travel
|
||||
with the team share. Safety: own sets only type read commands, can only add danger rules (never weaken the built-in
|
||||
ones), only detect a device when no built-in set matches, syslog steps are shown and danger-checked every time,
|
||||
and team sets stay inactive until you approve them (and again after every change, with a diff).
|
||||
- **Explain errors**: when a command fails, the suggestion line offers “Why? & Fix” (Alt+0). The AI gets the
|
||||
command, exit code and output and answers with the cause and commands you can insert
|
||||
- **Log diagnosis**: palette “AI: analyze log/output” (or select text first): the AI reads the selection or the last
|
||||
|
||||
@@ -25,6 +25,7 @@ require (
|
||||
go.bug.st/serial v1.8.0
|
||||
golang.org/x/crypto v0.58.0
|
||||
golang.org/x/sys v0.49.0
|
||||
gopkg.in/yaml.v3 v3.0.1
|
||||
)
|
||||
|
||||
require (
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
package agent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/db9979/sshtermy/internal/llm"
|
||||
)
|
||||
|
||||
// Entwurf eines Befehlssatzes (internal/cmdset) aus dem, was im Terminal
|
||||
// steht. Die KI schreibt nur einen Entwurf; geprüft (nur Lesebefehle,
|
||||
// gültige Muster) und gespeichert wird er erst in sshTermy, nach Bestätigung.
|
||||
|
||||
const sysCmdSet = "Du schreibst für das Admin-Werkzeug sshTermy eine Befehlssatz-Datei (YAML) für das Netzwerkgerät oder System, dessen Terminal-Ausgabe du bekommst. " +
|
||||
"Antworte NUR mit YAML, ohne Erklärung und ohne ```-Zaun. Felder (alle optional außer id und name):\n" +
|
||||
"id: kleinbuchstaben-mit-bindestrich (z. B. hersteller-modell)\nname: Anzeigename\nfamily: network (Switch/Router/Firewall) oder linux/bsd\n" +
|
||||
"hint: ein Absatz für die KI: welche CLI, typische Lesebefehle, wie man konfiguriert und speichert\n" +
|
||||
"detect:\n screen: ['Go-Regex auf Login-Banner oder Prompt']\n version: ['Go-Regex auf die Ausgabe des Versionsbefehls']\n" +
|
||||
"commands:\n paging_off: nur einer von: terminal length 0 | no page | screen-length disable | screen-length 0 temporary | terminal pager 0 | set cli pager off | no paging (sonst weglassen)\n" +
|
||||
" version: Befehl für Modell/Firmware\n system: Befehl für CPU/Speicher\n ports: Befehl für Port-Übersicht\n vlans: Befehl für VLAN-Liste\n config: Befehl, der die laufende Konfiguration ausgibt\n" +
|
||||
"parse:\n firmware: 'Go-Regex mit einer Klammer'\n model: 'Go-Regex mit einer Klammer'\n name: '…'\n uptime: '…'\n" +
|
||||
"logs:\n commands: [Befehl für das Gerätelog]\n reader: generic\n" +
|
||||
"syslog:\n steps: ['Befehle, die Syslog an {{ip}} Port {{port}} schicken (Konfigurationsmodus betreten und verlassen)']\n save: Befehl zum dauerhaften Speichern\n" +
|
||||
"Regeln: Unter commands und logs NUR Befehle, die nichts ändern (show/display/get …). Regex in einfachen Anführungszeichen. " +
|
||||
"Nimm nur Befehle, die es auf diesem Gerät sicher gibt; was du nicht weißt, lässt du weg. Erfinde keine Gefahrenregeln und keine read-Liste." + guard
|
||||
|
||||
var reYAMLFence = regexp.MustCompile("(?s)^```(?:ya?ml)?\\s*\\n(.*?)\\n```\\s*$")
|
||||
|
||||
// DraftCmdSet bittet die KI um einen Befehlssatz-Entwurf.
|
||||
func (a *Agent) DraftCmdSet(ctx context.Context, screen string, c Context) (string, error) {
|
||||
body := strings.NewReplacer("<<<", "‹‹‹", ">>>", "›››").Replace(Redact(tail(screen, 6000)))
|
||||
res, err := a.C.CompleteResult(ctx, []llm.Message{
|
||||
{Role: "system", Content: a.sys(sysCmdSet)},
|
||||
{Role: "user", Content: material(c) + "\nTerminal:\n<<<\n" + body + "\n>>>"},
|
||||
}, llm.Opts{MaxTokens: goalTokens, Temperature: 0.2, NoThink: true, Task: TaskAdapt})
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
out := strings.TrimSpace(stripThink(res.Content))
|
||||
if m := reYAMLFence.FindStringSubmatch(out); m != nil {
|
||||
out = m[1]
|
||||
}
|
||||
if out == "" {
|
||||
return "", unreadable(res)
|
||||
}
|
||||
return out + "\n", nil
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
id: allied-awplus
|
||||
name: Allied Telesis AlliedWare Plus
|
||||
order: 250
|
||||
hint: "Allied Telesis AlliedWare Plus (IOS-ähnlich): show running-config, show interface brief, show vlan brief, show mac address-table, show lldp neighbors, show system, show version, show log; Blättern aus mit terminal length 0; Konfiguration mit configure terminal … end, speichern mit copy running-config startup-config (oder write). Ports heißen port1.0.1."
|
||||
detect:
|
||||
screen: ['(?i)alliedware plus|allied telesis']
|
||||
version: ['(?i)alliedware plus|allied telesis']
|
||||
commands:
|
||||
paging_off: terminal length 0
|
||||
version: show version
|
||||
system: show cpu
|
||||
memory: show memory
|
||||
ports: show interface brief
|
||||
vlans: show vlan brief
|
||||
config: show running-config
|
||||
parse:
|
||||
firmware: '(?i)AlliedWare Plus \(TM\)\s+(\S+)'
|
||||
cpu: '(?i)1 second:\s*(\d{1,3})(?:\.\d+)?%'
|
||||
mem: '(?i)RAM total:\s*(?P<total>\d+)\s*kB;\s*free:\s*(?P<free>\d+)'
|
||||
port_up: '^port\S+\s+admin up\s+running'
|
||||
port_down: '^port\S+\s+admin (?:down|up\s+down)'
|
||||
logs:
|
||||
commands: [show log tail 600]
|
||||
ports: show interface brief
|
||||
reader: generic
|
||||
syslog:
|
||||
steps: [configure terminal, 'log host {{ip}} level warnings', end]
|
||||
save: copy running-config startup-config
|
||||
@@ -0,0 +1,39 @@
|
||||
id: arista-eos
|
||||
name: Arista EOS
|
||||
order: 230
|
||||
hint: "Arista EOS (IOS-ähnlich, aber eigene Befehle): show running-config, show interfaces status, show vlan, show mac address-table, show lldp neighbors, show version; Blättern aus mit terminal length 0; Konfiguration mit configure … end (oder configure session), speichern mit write memory. bash öffnet eine Linux-Shell."
|
||||
detect:
|
||||
screen: ['(?i)arista networks|\barista\s+dcs-|\bEOS-\d']
|
||||
version: ['(?im)^arista\s|software image version:']
|
||||
commands:
|
||||
paging_off: terminal length 0
|
||||
version: show version
|
||||
system: show processes top once
|
||||
ports: show interfaces status
|
||||
vlans: show vlan
|
||||
config: show running-config
|
||||
parse:
|
||||
firmware: '(?im)^Software image version:\s*(\S+)'
|
||||
model: '(?im)^Arista\s+(\S+)'
|
||||
cpu: '(?i)%cpu\(s\):.*?(?P<idle>\d{1,3})(?:\.\d+)?\s+id'
|
||||
mem: '(?is)total memory:\s+(?P<total>\d+)\s*kB.*?free memory:\s+(?P<free>\d+)'
|
||||
logs:
|
||||
commands: [show logging]
|
||||
ports: show interfaces status
|
||||
reader: generic
|
||||
syslog:
|
||||
steps: [configure, 'logging host {{ip}} {{port}}', logging trap warnings, end]
|
||||
save: write memory
|
||||
samples:
|
||||
- name: DCS-7050
|
||||
version: |
|
||||
Arista DCS-7050SX-64-F
|
||||
Hardware version: 01.11
|
||||
Software image version: 4.28.3M
|
||||
Uptime: 3 weeks, 2 days, 4 hours and 1 minute
|
||||
Total memory: 8099828 kB
|
||||
Free memory: 5998672 kB
|
||||
expect:
|
||||
firmware: 4.28.3M
|
||||
model: DCS-7050SX-64-F
|
||||
mem: 25
|
||||
@@ -0,0 +1,29 @@
|
||||
id: aruba-instant
|
||||
name: Aruba Instant (IAP)
|
||||
order: 207
|
||||
hint: "Aruba Instant Access Points (IAP-Cluster, kein Controller): show aps, show clients, show version, show running-config, show log system, show ap-env; Konfiguration am virtuellen Controller mit configure terminal … end und commit apply. Mit Aruba Central verwaltete APs nehmen Änderungen dort zurück."
|
||||
detect:
|
||||
screen: ['(?i)ArubaOS \(MODEL:\s*\d{3}[\w-]*\)|aruba instant']
|
||||
version: ['(?i)ArubaOS \(MODEL:\s*\d{3}[\w-]*\)']
|
||||
commands:
|
||||
version: show version
|
||||
system: show cpu
|
||||
memory: show memory
|
||||
config: show running-config
|
||||
extra:
|
||||
- label: APs
|
||||
cmd: show aps
|
||||
count: '(?m)^\S+\s+\d{1,3}(?:\.\d{1,3}){3}\s'
|
||||
- label: Clients
|
||||
cmd: show clients
|
||||
pick: '(?i)Number of Clients\s*:\s*(\d+)'
|
||||
parse:
|
||||
firmware: '(?i)ArubaOS \(MODEL:[^)]*\),\s*Version\s+(\S+)'
|
||||
model: '(?i)ArubaOS \(MODEL:\s*([^)]+)\)'
|
||||
cpu: '(?i)idle\s+(?P<idle>\d{1,3})(?:\.\d+)?%'
|
||||
mem: '(?is)MemTotal:\s*(?P<total>\d+).*?MemFree:\s*(?P<free>\d+)'
|
||||
logs:
|
||||
commands: [show log system]
|
||||
reader: generic
|
||||
syslog:
|
||||
note: "Aruba Instant: Konfiguration › System › Monitoring › Syslog-Server (IP); oder in Aruba Central."
|
||||
@@ -0,0 +1,50 @@
|
||||
id: aruba-mobility
|
||||
name: Aruba Mobility Controller (AOS 8)
|
||||
order: 206
|
||||
hint: "Aruba Mobility Conductor/Controller (ArubaOS 8/10, WLAN-Controller), kein ArubaOS-Switch: show ap database, show ap active, show user-table, show ap radio-summary, show running-config, show version, show log system; Blättern aus mit no paging; Konfiguration am Conductor mit configure terminal … end und write memory; Konfigurationsknoten mit cd /md/…"
|
||||
detect:
|
||||
screen: ['(?i)ArubaOS \(MODEL:\s*(?:Aruba)?(?:7\d{3}|9\d{3}|MM-|MC-|A7\d{3})']
|
||||
version: ['(?i)ArubaOS \(MODEL:\s*(?:Aruba)?(?:7\d{3}|9\d{3}|MM-|MC-|A7\d{3})']
|
||||
commands:
|
||||
paging_off: no paging
|
||||
version: show version
|
||||
system: show cpuload
|
||||
memory: show memory
|
||||
config: show running-config
|
||||
extra:
|
||||
- label: APs aktiv
|
||||
label_en: APs up
|
||||
cmd: show ap database
|
||||
count: '(?m)\s\d{1,3}(?:\.\d{1,3}){3}\s+Up\b'
|
||||
- label: Clients
|
||||
cmd: show user-table
|
||||
pick: '(?i)User Entries:\s*(\d+)'
|
||||
parse:
|
||||
firmware: '(?i)ArubaOS \(MODEL:[^)]*\),\s*Version\s+(\S+)'
|
||||
model: '(?i)ArubaOS \(MODEL:\s*([^)]+)\)'
|
||||
cpu: '(?i)idle\s+(?P<idle>\d{1,3})(?:\.\d+)?%'
|
||||
mem: '(?i)total:\s*(?P<total>\d+),\s*used:\s*(?P<used>\d+)'
|
||||
logs:
|
||||
commands: [show log system 300]
|
||||
reader: generic
|
||||
syslog:
|
||||
steps: [configure terminal, 'logging {{ip}} severity warnings', end]
|
||||
save: write memory
|
||||
danger:
|
||||
- rx: '^\s*(apboot|ap\s+wipe|clear\s+gap-db|ap-regroup)\b'
|
||||
reason: startet Access Points neu oder setzt sie zurück
|
||||
reason_en: reboots or resets access points
|
||||
samples:
|
||||
- name: Aruba 7010
|
||||
version: |
|
||||
Aruba Operating System Software.
|
||||
ArubaOS (MODEL: Aruba7010-US), Version 8.10.0.7
|
||||
Switch uptime is 30 days 2 hours 3 minutes 4 seconds
|
||||
system: |
|
||||
user 4.5%, system 3.2%, idle 92.3%
|
||||
Memory (Kb): total: 4026572, used: 2013286, free: 2013286
|
||||
expect:
|
||||
firmware: 8.10.0.7
|
||||
model: Aruba7010-US
|
||||
cpu: 8
|
||||
mem: 50
|
||||
@@ -0,0 +1,21 @@
|
||||
id: arubaos-cx
|
||||
name: ArubaOS-CX
|
||||
order: 210
|
||||
hint: "ArubaOS-CX-CLI, kein Linux: show running-config, show interface brief, show vlan, show mac-address-table, show lldp neighbor-info, show version, show system; Blättern aus mit no page; Konfiguration mit configure terminal … end, speichern mit write memory."
|
||||
detect:
|
||||
screen: ['(?i)arubaos-cx|\baos-cx\b']
|
||||
version: ['(?i)arubaos-cx|aos-cx']
|
||||
commands:
|
||||
paging_off: no page
|
||||
version: show version
|
||||
system: show system
|
||||
ports: show interface brief
|
||||
vlans: show vlan
|
||||
config: show running-config
|
||||
logs:
|
||||
commands: [show logging -r]
|
||||
ports: show interface brief
|
||||
reader: arubaos-cx
|
||||
syslog:
|
||||
steps: [configure terminal, 'logging {{ip}} udp {{port}}', end]
|
||||
save: write memory
|
||||
@@ -0,0 +1,5 @@
|
||||
id: bsd
|
||||
name: BSD
|
||||
family: bsd
|
||||
order: 3
|
||||
hint: "BSD: sh/csh, BSD-Werkzeuge, service/rc.d statt systemctl, pkg."
|
||||
@@ -0,0 +1,18 @@
|
||||
id: checkpoint-gaia
|
||||
name: Check Point Gaia
|
||||
order: 290
|
||||
hint: "Check Point Gaia: clish (Prompt host>) mit show version all, show interfaces all, show route, show configuration, set …/add …/delete … (wirkt sofort), save config (dauerhaft). expert öffnet die Linux-Shell (cpstat, fw stat, cphaprob state, fw ctl pstat). Regelwerk über SmartConsole, nicht per CLI."
|
||||
detect:
|
||||
screen: ['(?i)\bgaia\b|check point']
|
||||
version: ['(?i)check point gaia']
|
||||
commands:
|
||||
version: show version all
|
||||
config: show configuration
|
||||
parse:
|
||||
firmware: '(?i)Check Point Gaia\s+(R[\d.]+)'
|
||||
syslog:
|
||||
steps: ['add syslog log-remote-address {{ip}} level warning']
|
||||
save: save config
|
||||
danger:
|
||||
- rx: '^\s*(fw\s+unloadlocal|cpstop|set\s+expert-password|delete\s+user)\b'
|
||||
reason: leert oder deaktiviert die Firewall
|
||||
@@ -0,0 +1,60 @@
|
||||
id: cisco-asa
|
||||
name: Cisco ASA
|
||||
order: 213
|
||||
hint: "Cisco ASA (Firewall), kein IOS: show running-config, show interface ip brief, show nameif, show route, show conn count, show xlate, show access-list, show vpn-sessiondb summary, show failover; Blättern aus mit terminal pager 0; Konfiguration mit configure terminal … end, speichern mit write memory. Schnittstellen haben Namen (nameif, z. B. inside/outside)."
|
||||
detect:
|
||||
screen: ['(?i)cisco adaptive security appliance']
|
||||
version: ['(?i)cisco adaptive security appliance']
|
||||
commands:
|
||||
paging_off: terminal pager 0
|
||||
version: show version
|
||||
system: show cpu usage
|
||||
memory: show memory
|
||||
ports: show interface ip brief
|
||||
config: show running-config
|
||||
extra:
|
||||
- label: Verbindungen
|
||||
label_en: Connections
|
||||
cmd: show conn count
|
||||
pick: '(?i)(\d+)\s+in use'
|
||||
- label: VPN
|
||||
cmd: show vpn-sessiondb summary
|
||||
pick: '(?im)^\s*Total Active and Inactive\s*:\s*(\d+)'
|
||||
parse:
|
||||
firmware: '(?i)adaptive security appliance software version\s+(\S+)'
|
||||
model: '(?im)^Hardware:\s+([^,]+)'
|
||||
name: '(?im)^(\S+)\s+up\s+\d'
|
||||
uptime: '(?im)^\S+\s+up\s+(\d.*?)\s*$'
|
||||
cpu: '(?i)cpu utilization for 5 seconds\s*=\s*(\d{1,3})%'
|
||||
mem: '(?im)^Used memory:\s+\d+ bytes\s*\(\s*(\d{1,3})%\)'
|
||||
logs:
|
||||
commands: [show logging]
|
||||
ports: show interface ip brief
|
||||
reader: generic
|
||||
syslog:
|
||||
note: "ASA: configure terminal · logging enable · logging trap warnings · logging host <Schnittstelle, z. B. inside> <IP> 17/<Port> · end. Die Schnittstelle kennt sshTermy nicht, deshalb von Hand."
|
||||
save: write memory
|
||||
danger:
|
||||
- rx: '^\s*clear\s+configure\b'
|
||||
reason: löscht Konfiguration oder Speicher des Geräts
|
||||
- rx: '^\s*no\s+(access-list|access-group|nat|crypto|route|object|nameif|ssh|http\s+server)\b'
|
||||
reason: entfernt Konfiguration (VLAN, Routing, Zugang)
|
||||
- rx: '^\s*(failover\s+active|no\s+failover)\b'
|
||||
reason: schaltet die Hochverfügbarkeit um
|
||||
reason_en: switches high availability over
|
||||
samples:
|
||||
- name: ASA 5516
|
||||
version: |
|
||||
Cisco Adaptive Security Appliance Software Version 9.16(4)
|
||||
fw1 up 12 days 3 hours
|
||||
Hardware: ASA5516, 8192 MB RAM, CPU Atom C2000 series 2416 MHz, 1 CPU (8 cores)
|
||||
system: |
|
||||
CPU utilization for 5 seconds = 4%; 1 minute: 3%; 5 minutes: 3%
|
||||
Free memory: 5312345678 bytes (62%)
|
||||
Used memory: 3214567890 bytes (38%)
|
||||
expect:
|
||||
firmware: 9.16(4)
|
||||
model: ASA5516
|
||||
name: fw1
|
||||
cpu: 4
|
||||
mem: 38
|
||||
@@ -0,0 +1,38 @@
|
||||
id: cisco-ios
|
||||
name: Cisco IOS / IOS-XE
|
||||
order: 220
|
||||
hint: "Cisco-IOS-CLI, kein Linux: show running-config, show ip interface brief, show interfaces status, show vlan brief, show mac address-table, show cdp neighbors, show version; Blättern aus mit terminal length 0; Konfiguration mit configure terminal … end, speichern mit write memory."
|
||||
detect:
|
||||
banner: ['(?i)cisco']
|
||||
screen: ['(?i)cisco ios|cisco internetwork operating system|IOS-XE']
|
||||
version: ['(?i)cisco ios|cisco internetwork']
|
||||
commands:
|
||||
paging_off: terminal length 0
|
||||
version: show version
|
||||
system: show processes cpu | include CPU utilization
|
||||
ports: show interfaces status
|
||||
vlans: show vlan brief
|
||||
config: show running-config
|
||||
logs:
|
||||
commands: [show logging]
|
||||
ports: show interfaces status
|
||||
reader: generic
|
||||
syslog:
|
||||
steps: [configure terminal, 'logging host {{ip}} transport udp port {{port}}', logging trap warnings, end]
|
||||
save: write memory
|
||||
variants:
|
||||
- name: IOS 12.x
|
||||
firmware: '^1[0-2]\.'
|
||||
hint: "Alte IOS-Version 12.x: logging host kennt keinen Port (immer UDP 514)."
|
||||
syslog:
|
||||
steps: [configure terminal, 'logging {{ip}}', logging trap warnings, end]
|
||||
samples:
|
||||
- name: Catalyst 2960
|
||||
version: |
|
||||
Cisco IOS Software, C2960X Software (C2960X-UNIVERSALK9-M), Version 15.2(7)E4, RELEASE SOFTWARE (fc2)
|
||||
sw1 uptime is 1 year, 2 weeks, 3 days, 4 hours, 5 minutes
|
||||
cisco WS-C2960X-48FPD-L (APM86XXX) processor (revision M0) with 524288K bytes of memory.
|
||||
expect:
|
||||
firmware: 15.2(7)E4
|
||||
model: WS-C2960X-48FPD-L
|
||||
name: sw1
|
||||
@@ -0,0 +1,48 @@
|
||||
id: cisco-nxos
|
||||
name: Cisco NX-OS (Nexus)
|
||||
order: 214
|
||||
hint: "Cisco NX-OS (Nexus), kein IOS: show running-config, show interface brief, show vlan brief, show mac address-table, show cdp neighbors, show version, show system resources; Blättern aus mit terminal length 0; Konfiguration mit configure terminal … end, speichern mit copy running-config startup-config. Viele Funktionen müssen erst mit feature … eingeschaltet werden."
|
||||
detect:
|
||||
screen: ['(?i)cisco nexus|\bNX-OS\b']
|
||||
version: ['(?i)cisco nexus|\bNX-OS\b|nxos']
|
||||
commands:
|
||||
paging_off: terminal length 0
|
||||
version: show version
|
||||
system: show system resources
|
||||
ports: show interface brief
|
||||
vlans: show vlan brief
|
||||
config: show running-config
|
||||
parse:
|
||||
firmware: '(?im)^\s*(?:NXOS|system):\s+version\s+(\S+)'
|
||||
model: '(?im)^\s*cisco\s+(Nexus\s*\S+.*?)\s+(?:chassis|Chassis)'
|
||||
name: '(?im)^\s*Device name:\s*(\S+)'
|
||||
uptime: '(?im)^Kernel uptime is\s+(.+)$'
|
||||
cpu: '(?im)^CPU states\s*:.*?(?P<idle>\d{1,3})(?:\.\d+)?%\s+idle'
|
||||
mem: '(?im)^Memory usage:\s*(?P<total>\d+)K total,\s*(?P<used>\d+)K used'
|
||||
logs:
|
||||
commands: [show logging last 600]
|
||||
ports: show interface brief
|
||||
reader: generic
|
||||
syslog:
|
||||
steps: [configure terminal, 'logging server {{ip}} 4 port {{port}}', end]
|
||||
save: copy running-config startup-config
|
||||
danger:
|
||||
- rx: '^\s*no\s+feature\s+\S+'
|
||||
reason: entfernt Konfiguration (VLAN, Routing, Zugang)
|
||||
samples:
|
||||
- name: Nexus 9000
|
||||
version: |
|
||||
Cisco Nexus Operating System (NX-OS) Software
|
||||
NXOS: version 9.3(10)
|
||||
cisco Nexus9000 C93180YC-EX chassis
|
||||
Device name: leaf1
|
||||
Kernel uptime is 120 day(s), 3 hour(s), 4 minute(s), 5 second(s)
|
||||
system: |
|
||||
CPU states : 3.55% user, 1.27% kernel, 95.18% idle
|
||||
Memory usage: 24633028K total, 8613540K used, 16019488K free
|
||||
expect:
|
||||
firmware: 9.3(10)
|
||||
model: Nexus9000 C93180YC-EX
|
||||
name: leaf1
|
||||
cpu: 5
|
||||
mem: 34
|
||||
@@ -0,0 +1,24 @@
|
||||
id: cisco-sb
|
||||
name: Cisco Small Business (SG/CBS)
|
||||
order: 225
|
||||
hint: "Cisco Small Business / Catalyst 1200/1300 (SG300, SG350, CBS250, CBS350), kein IOS: show running-config, show interfaces status, show vlan, show mac address-table, show lldp neighbors, show system, show version; Blättern aus mit terminal datadump; Konfiguration mit configure … end, speichern mit write memory (fragt Y/N)."
|
||||
detect:
|
||||
screen: ['(?i)cisco (?:sg|sf|cbs)\d{3}|cisco small business|\bCBS\d{3}-']
|
||||
version: ['(?im)^\s*SW version\s+\d|^\s*Active-image:\s+flash://system/images/']
|
||||
commands:
|
||||
paging_off: terminal datadump
|
||||
version: show version
|
||||
system: show cpu utilization
|
||||
ports: show interfaces status
|
||||
vlans: show vlan
|
||||
config: show running-config
|
||||
parse:
|
||||
firmware: '(?im)^\s*(?:SW version|Version:)\s+([\d.]+)'
|
||||
cpu: '(?i)five seconds\s*(\d{1,3})\s*%'
|
||||
logs:
|
||||
commands: [show logging]
|
||||
ports: show interfaces status
|
||||
reader: generic
|
||||
syslog:
|
||||
steps: [configure, 'logging host {{ip}} port {{port}} severity warnings', end]
|
||||
save: write memory
|
||||
@@ -0,0 +1,33 @@
|
||||
id: cisco-wlc
|
||||
name: Cisco WLC (AireOS)
|
||||
order: 212
|
||||
hint: "Cisco Wireless LAN Controller mit AireOS (Prompt (Cisco Controller) >), kein IOS: show sysinfo, show ap summary, show client summary, show wlan summary, show run-config commands, show msglog; Blättern aus mit config paging disable; Änderungen mit config … (wirken sofort), speichern mit save config. Catalyst 9800 ist IOS-XE (Befehlssatz Cisco IOS)."
|
||||
detect:
|
||||
screen: ['(?i)\(Cisco Controller\)\s*>|cisco controller']
|
||||
version: ['(?im)^Product Name\.*\s*Cisco Controller']
|
||||
commands:
|
||||
paging_off: config paging disable
|
||||
version: show sysinfo
|
||||
system: show cpu
|
||||
config: show run-config commands
|
||||
extra:
|
||||
- label: APs
|
||||
cmd: show ap summary
|
||||
pick: '(?i)Number of APs\.*\s*(\d+)'
|
||||
- label: Clients
|
||||
cmd: show client summary
|
||||
pick: '(?i)Number of Clients\.*\s*(\d+)'
|
||||
parse:
|
||||
firmware: '(?im)^Product Version\.*\s*(\S+)'
|
||||
name: '(?im)^System Name\.*\s*(\S+)'
|
||||
uptime: '(?im)^System Up Time\.*\s*(.+?)\s*$'
|
||||
cpu: '(?i)current cpu\(s\) load:\s*(\d{1,3})%'
|
||||
logs:
|
||||
commands: [show msglog]
|
||||
reader: generic
|
||||
syslog:
|
||||
steps: ['config logging syslog host {{ip}}', config logging syslog level warnings]
|
||||
save: save config
|
||||
danger:
|
||||
- rx: '^\s*(reset\s+system|clear\s+config|config\s+ap\s+reset|transfer\s+download\s+start)\b'
|
||||
reason: startet das Gerät neu
|
||||
@@ -0,0 +1,5 @@
|
||||
id: cmd
|
||||
name: Windows cmd.exe
|
||||
family: windows
|
||||
order: 5
|
||||
hint: "Windows-Eingabeaufforderung (cmd.exe): dir, type, ipconfig, sc query, findstr; keine Unix-Befehle."
|
||||
@@ -0,0 +1,90 @@
|
||||
id: comware
|
||||
name: HPE Comware / H3C
|
||||
order: 270
|
||||
hint: "Comware-CLI: display current-configuration, display interface brief, display vlan, display version, display logbuffer; Blättern aus mit screen-length disable; Konfiguration mit system-view … quit, entfernen mit undo …, speichern mit save force."
|
||||
detect:
|
||||
banner: ['(?i)comware|h3c']
|
||||
screen: ['(?i)comware']
|
||||
version: ['(?i)comware software']
|
||||
commands:
|
||||
paging_off: screen-length disable
|
||||
version: display version
|
||||
system: display cpu-usage
|
||||
memory: display memory
|
||||
ports: display interface brief
|
||||
vlans: display vlan brief
|
||||
config: display current-configuration
|
||||
parse:
|
||||
firmware: '(?i)comware software,\s*version\s+([\d.]+,\s*release\s+\w+)'
|
||||
model: '(?im)^(?:H3C|HPE|HP)\s+(.+?)\s+uptime is'
|
||||
cpu: '(?im)^\s*(\d{1,3})%\s+in last 5 seconds'
|
||||
mem: '(?im)^\s*Mem:\s+(?P<total>\d+)\s+(?P<used>\d+)\s'
|
||||
port_up: '^(?:GE|XGE|FGE|HGE|WGE|MGE|BAGG|Ten-GigabitEthernet|GigabitEthernet)\d\S*\s+UP\b'
|
||||
port_down: '^(?:GE|XGE|FGE|HGE|WGE|MGE|BAGG|Ten-GigabitEthernet|GigabitEthernet)\d\S*\s+(?:DOWN|ADM)\b'
|
||||
vlan: '^\s*(\d{1,4})\s+(\S+(?: \S+)?)'
|
||||
logs:
|
||||
commands: [display logbuffer]
|
||||
ports: display interface brief
|
||||
reader: vrp
|
||||
syslog:
|
||||
steps: [system-view, info-center enable, 'info-center loghost {{ip}} port {{port}}', quit]
|
||||
save: save force
|
||||
variants:
|
||||
- name: Comware 5
|
||||
firmware: '^5\.'
|
||||
hint: "Comware 5: info-center loghost kennt keinen Port (immer UDP 514), Speicherangabe mit display memory in Byte."
|
||||
syslog:
|
||||
steps: [system-view, info-center enable, 'info-center loghost {{ip}}', quit]
|
||||
danger:
|
||||
- rx: '^\s*undo\s+(vlan|interface|ip\s+route|stp|local-user|ssh|ip\s+address|info-center\s+enable)\b'
|
||||
reason: entfernt Konfiguration (VLAN, Routing, Zugang)
|
||||
- rx: '^\s*(startup\s+saved-configuration|boot-loader\s+file)\b'
|
||||
reason: ändert die Startkonfiguration oder das Startabbild
|
||||
reason_en: changes the startup configuration or boot image
|
||||
samples:
|
||||
- name: H3C S5130
|
||||
version: |
|
||||
H3C Comware Software, Version 7.1.070, Release 3208P13
|
||||
Copyright (c) 2004-2021 New H3C Technologies Co., Ltd. All rights reserved.
|
||||
H3C S5130S-28S-EI uptime is 0 weeks, 3 days, 4 hours, 25 minutes
|
||||
Last reboot reason: User reboot
|
||||
Boot image: flash:/s5130s_ei-cmw710-boot-r3208p13.bin
|
||||
system: |
|
||||
Slot 1 CPU 0 CPU usage:
|
||||
3% in last 5 seconds
|
||||
2% in last 1 minute
|
||||
2% in last 5 minutes
|
||||
Memory statistics are measured in KB:
|
||||
Slot 1:
|
||||
Total Used Free Shared Buffers Cached FreeRatio
|
||||
Mem: 999656 490336 509320 0 2496 139256 51.0%
|
||||
ports: |
|
||||
Brief information on interfaces in bridge mode:
|
||||
Link: ADM - administratively down; Stby - standby
|
||||
Speed: (a) - auto
|
||||
Duplex: (a)/A - auto; H - half; F - full
|
||||
Type: A - access; T - trunk; H - hybrid
|
||||
Interface Link Speed Duplex Type PVID Description
|
||||
GE1/0/1 UP 1G(a) F(a) A 1
|
||||
GE1/0/2 DOWN auto A A 1
|
||||
XGE1/0/25 ADM auto A A 1
|
||||
vlans: |
|
||||
Brief information about all VLANs:
|
||||
Supported Minimum VLAN ID: 1
|
||||
Supported Maximum VLAN ID: 4094
|
||||
Default VLAN ID: 1
|
||||
VLAN ID Name Port
|
||||
1 VLAN 0001 GE1/0/1 GE1/0/2
|
||||
10 Server GE1/0/1
|
||||
logs: |
|
||||
%Nov 10 10:21:33:518 2026 H3C SHELL/5/SHELL_LOGIN: admin logged in from 10.0.0.5.
|
||||
%Nov 10 10:25:01:002 2026 H3C IFNET/3/PHY_UPDOWN: Physical state on the interface GigabitEthernet1/0/2 changed to down.
|
||||
expect:
|
||||
firmware: 7.1.070, Release 3208P13
|
||||
model: S5130S-28S-EI
|
||||
cpu: 3
|
||||
mem: 49
|
||||
ports_up: 1
|
||||
ports_down: 2
|
||||
vlans: 2
|
||||
log_lines: 2
|
||||
@@ -0,0 +1,24 @@
|
||||
id: dell-nseries
|
||||
name: Dell N-Serie / PowerConnect
|
||||
name_en: Dell N-Series / PowerConnect
|
||||
order: 236
|
||||
hint: "Dell Networking N1500/N2000/N3000 und ältere PowerConnect (DNOS 6, IOS-ähnlich): show running-config, show interfaces status, show vlan, show mac address-table, show lldp remote-device all, show version, show switch; Blättern aus mit terminal length 0; Konfiguration mit configure … exit, speichern mit copy running-config startup-config."
|
||||
detect:
|
||||
screen: ['(?i)dell networking n\d{4}|powerconnect']
|
||||
version: ['(?im)^(?:Machine Description|System Description)\.*\s*Dell Networking N\d|powerconnect']
|
||||
commands:
|
||||
paging_off: terminal length 0
|
||||
version: show version
|
||||
ports: show interfaces status
|
||||
vlans: show vlan
|
||||
config: show running-config
|
||||
parse:
|
||||
firmware: '(?im)^System Description\.*\s*[^,]+,\s*([\d.]+)'
|
||||
model: '(?im)^Machine Model\.*\s*(\S+)'
|
||||
logs:
|
||||
commands: [show logging]
|
||||
ports: show interfaces status
|
||||
reader: generic
|
||||
syslog:
|
||||
steps: [configure, 'logging {{ip}}', 'port {{port}}', level warning, exit, exit]
|
||||
save: copy running-config startup-config
|
||||
@@ -0,0 +1,25 @@
|
||||
id: dell-os10
|
||||
name: Dell OS10
|
||||
order: 235
|
||||
hint: "Dell EMC SmartFabric OS10 (Linux-basiert, CLI ähnlich IOS): show running-configuration, show interface status, show vlan, show mac address-table, show lldp neighbors, show version; Blättern aus mit terminal length 0; Konfiguration mit configure terminal … end, speichern mit write memory. Schnittstellen heißen ethernet 1/1/1."
|
||||
detect:
|
||||
screen: ['(?i)dell (?:emc )?(?:smartfabric |networking )?os10']
|
||||
version: ['(?i)dell (?:emc )?(?:smartfabric |networking )?os10|^OS Version:\s*10\.']
|
||||
commands:
|
||||
paging_off: terminal length 0
|
||||
version: show version
|
||||
ports: show interface status
|
||||
vlans: show vlan
|
||||
config: show running-configuration
|
||||
parse:
|
||||
firmware: '(?im)^OS Version:\s*(\S+)'
|
||||
model: '(?im)^System Type:\s*(\S+)'
|
||||
port_up: '(?i)^Eth\s+\d\S*\s+(?:.*?\s)?up\s'
|
||||
port_down: '(?i)^Eth\s+\d\S*\s+(?:.*?\s)?down\s'
|
||||
vlan: '^\s*\*?\s*(\d{1,4})\s+(?:up|down|active|inactive)\b'
|
||||
logs:
|
||||
commands: [show logging log-file]
|
||||
reader: generic
|
||||
syslog:
|
||||
steps: [configure terminal, 'logging server {{ip}} udp {{port}}', end]
|
||||
save: write memory
|
||||
@@ -0,0 +1,11 @@
|
||||
id: edgeos
|
||||
name: Ubiquiti EdgeOS (EdgeRouter)
|
||||
order: 129
|
||||
family: linux
|
||||
hint: "Ubiquiti EdgeRouter (EdgeOS, Vyatta-Basis): Betriebsmodus show interfaces, show ip route, show version, show log; Konfiguration mit configure · set …/delete … · commit · save · exit. Hardware-Infos mit /usr/sbin/ubnt-hal show-version."
|
||||
detect:
|
||||
screen: ['(?i)welcome to edgeos']
|
||||
probe: [/usr/sbin/ubnt-hal]
|
||||
danger:
|
||||
- rx: '^\s*(load\s+\S|rollback\s+\d)'
|
||||
reason: überschreibt die Gerätekonfiguration
|
||||
@@ -0,0 +1,22 @@
|
||||
id: esxi
|
||||
name: VMware ESXi
|
||||
family: linux
|
||||
order: 102
|
||||
hint: "VMware ESXi (BusyBox-Shell, kein Linux-Paketmanager, kein systemctl): esxcli (system version get, network nic list, storage filesystem list, vm process list), vim-cmd vmsvc/getallvms, vim-cmd vmsvc/power.getstate <id>, vim-cmd hostsvc/maintenance_mode_enter, /etc/init.d/<dienst> restart. Dateien der VMs unter /vmfs/volumes/."
|
||||
detect:
|
||||
probe: [/bin/vim-cmd]
|
||||
commands:
|
||||
extra:
|
||||
- label: VMs
|
||||
cmd: vim-cmd vmsvc/getallvms
|
||||
count: '(?m)^\d+\s+\S'
|
||||
- label: Version
|
||||
cmd: vmware -v
|
||||
pick: 'VMware ESXi\s+(\S+(?:\s+build-\d+)?)'
|
||||
read: ['^vim-cmd vmsvc/getallvms$', '^vmware -v$', '^esxcli (system version get|storage filesystem list|network nic list|vm process list)$']
|
||||
danger:
|
||||
- rx: '\bvim-cmd\s+vmsvc/(destroy|unregister|power\.off|power\.reset|power\.shutdown)\b|\besxcli\s+vm\s+process\s+kill\b'
|
||||
reason: schaltet VMs ab oder löscht sie
|
||||
reason_en: stops or deletes VMs
|
||||
- rx: '\besxcli\s+system\s+(shutdown|maintenanceMode\s+set)\b'
|
||||
reason: fährt den Server herunter oder neu
|
||||
@@ -0,0 +1,29 @@
|
||||
id: extreme-exos
|
||||
name: Extreme EXOS (Switch-Engine)
|
||||
name_en: Extreme EXOS (Switch Engine)
|
||||
order: 240
|
||||
hint: "ExtremeXOS / Switch Engine, kein IOS: show configuration, show ports information, show vlan, show fdb, show lldp neighbors, show switch, show version, show log; Blättern aus mit disable clipaging; Änderungen mit configure …/enable …/disable …, speichern mit save configuration. VLANs haben Namen (configure vlan <name> add ports …)."
|
||||
detect:
|
||||
screen: ['(?i)extremexos|\bswitch engine\b.*extreme|extreme networks']
|
||||
version: ['(?i)extremexos version|\bExtremeXOS\b']
|
||||
commands:
|
||||
paging_off: disable clipaging
|
||||
version: show version
|
||||
system: show switch
|
||||
vlans: show vlan
|
||||
config: show configuration
|
||||
parse:
|
||||
firmware: '(?i)ExtremeXOS version\s+(\S+)'
|
||||
model: '(?im)^System Type:\s*(\S+)'
|
||||
name: '(?im)^SysName:\s*(\S+)'
|
||||
uptime: '(?im)^System UpTime:\s*(.+?)\s*$'
|
||||
vlan: '^(?P<name>[A-Za-z][\w.-]*)\s+(?P<id>\d{1,4})\s'
|
||||
logs:
|
||||
commands: [show log]
|
||||
reader: generic
|
||||
syslog:
|
||||
note: "EXOS: configure syslog add <IP>:<Port> vr VR-Default local0 · enable log target syslog <IP>:<Port> vr VR-Default local0 · configure log target syslog <IP>:<Port> vr VR-Default local0 severity warning. Das virtuelle Netz (VR-Default oder VR-Mgmt) hängt vom Anschluss ab, deshalb von Hand."
|
||||
save: save configuration
|
||||
danger:
|
||||
- rx: '^\s*(unconfigure\s+switch|delete\s+vlan|unconfigure\s+vlan|use\s+image)\b'
|
||||
reason: löscht Konfiguration oder Speicher des Geräts
|
||||
@@ -0,0 +1,23 @@
|
||||
id: extreme-voss
|
||||
name: Extreme VOSS / Fabric Engine
|
||||
order: 241
|
||||
hint: "Extreme VOSS / Fabric Engine (VSP): show running-config, show interfaces gigabitEthernet, show vlan basic, show sys-info, show isis adjacencies, show logging file; Blättern aus mit terminal more disable; Konfiguration mit enable · configure terminal … end, speichern mit save config."
|
||||
detect:
|
||||
screen: ['(?i)\bVOSS\b|\bVSP-\d{4}|virtual services platform|fabric engine']
|
||||
version: ['(?i)\bVOSS\b|virtual services platform|\bVSP-\d{4}']
|
||||
commands:
|
||||
paging_off: terminal more disable
|
||||
version: show sys-info
|
||||
vlans: show vlan basic
|
||||
config: show running-config
|
||||
parse:
|
||||
firmware: '(?im)^\s*SysDescr\s*:\s*\S+\s+\(([\d.]+)\)'
|
||||
model: '(?im)^\s*SysDescr\s*:\s*(\S+)'
|
||||
name: '(?im)^\s*SysName\s*:\s*(\S+)'
|
||||
uptime: '(?im)^\s*SysUpTime\s*:\s*(.+?)\s*$'
|
||||
logs:
|
||||
commands: [show logging file tail]
|
||||
reader: generic
|
||||
syslog:
|
||||
note: "VOSS: syslog host 1 address <IP> · syslog host 1 udp-port <Port> · syslog host 1 enable (Port nur 514–530)."
|
||||
save: save config
|
||||
@@ -0,0 +1,27 @@
|
||||
id: fortios
|
||||
name: FortiOS
|
||||
order: 260
|
||||
hint: "FortiOS-CLI: get system status, show full-configuration, get system interface, diagnose …; Konfiguration mit config … edit … set … next … end."
|
||||
detect:
|
||||
banner: ['(?i)fortissh']
|
||||
screen: ['(?i)fortigate|fortios']
|
||||
version: ['(?i)fortigate|fortios|fortiswitch']
|
||||
commands:
|
||||
version: get system status
|
||||
system: get system performance status
|
||||
ports: get system interface physical
|
||||
config: show full-configuration
|
||||
parse:
|
||||
reader: fortios
|
||||
# „execute log filter“ setzt nur den Anzeigefilter dieser CLI-Sitzung.
|
||||
read:
|
||||
- '^execute log filter (reset|category \d{1,2}|view-lines \d{1,4})$'
|
||||
- '^execute log display$'
|
||||
logs:
|
||||
commands: [execute log filter reset, execute log filter category 1, execute log filter view-lines 1000, execute log display]
|
||||
reader: fortios
|
||||
syslog:
|
||||
steps: [config log syslogd setting, set status enable, 'set server {{ip}}', 'set port {{port}}', end]
|
||||
danger:
|
||||
- rx: '^\s*(execute\s+(restore|batch|disk\s+format|factoryreset2|erase-disk))\b'
|
||||
reason: überschreibt die Gerätekonfiguration
|
||||
@@ -0,0 +1,73 @@
|
||||
id: huawei-vrp
|
||||
name: Huawei VRP
|
||||
order: 275
|
||||
hint: "Huawei-VRP-CLI: display current-configuration, display interface brief, display vlan, display version, display logbuffer; Blättern aus mit screen-length 0 temporary; Konfiguration mit system-view … quit (neuere Geräte: danach commit), entfernen mit undo …, speichern mit save."
|
||||
detect:
|
||||
banner: ['(?i)huawei']
|
||||
screen: ['(?i)huawei versatile routing platform']
|
||||
version: ['(?i)huawei versatile routing platform|VRP \(R\) software']
|
||||
commands:
|
||||
paging_off: screen-length 0 temporary
|
||||
version: display version
|
||||
system: display cpu-usage
|
||||
memory: display memory-usage
|
||||
ports: display interface brief
|
||||
vlans: display vlan
|
||||
config: display current-configuration
|
||||
parse:
|
||||
firmware: '(?i)VRP \(R\) software,\s*Version\s+([\d.]+\s*\([^)]*\))'
|
||||
model: '(?im)^HUAWEI\s+(\S+).*?uptime is'
|
||||
cpu: '(?im)^\s*CPU Usage\s*:\s*(\d{1,3})%'
|
||||
mem: '(?i)memory (?:using|utilization) percentage is\s*:\s*(\d{1,3})%'
|
||||
port_up: '^\s*(?:X|25|40|100|Multi)?(?:GE|GigabitEthernet|Ethernet|MultiGE)\d\S*\s+up\b'
|
||||
port_down: '^\s*(?:X|25|40|100|Multi)?(?:GE|GigabitEthernet|Ethernet|MultiGE)\d\S*\s+\*?down\b'
|
||||
vlan: '^(\d{1,4})\s+(?:enable|disable)\s+\S+\s+\S+\s+\S+\s+(.*?)\s*$'
|
||||
logs:
|
||||
commands: [display logbuffer]
|
||||
ports: display interface brief
|
||||
reader: vrp
|
||||
syslog:
|
||||
steps: [system-view, info-center enable, 'info-center loghost {{ip}} port {{port}}', quit]
|
||||
save: save
|
||||
danger:
|
||||
- rx: '^\s*undo\s+(vlan|interface|ip\s+route-static|stp|local-user|stelnet|ip\s+address|info-center\s+enable)\b'
|
||||
reason: entfernt Konfiguration (VLAN, Routing, Zugang)
|
||||
- rx: '^\s*(startup\s+(saved-configuration|system-software)|clear\s+configuration)\b'
|
||||
reason: ändert die Startkonfiguration oder das Startabbild
|
||||
reason_en: changes the startup configuration or boot image
|
||||
samples:
|
||||
- name: Huawei S5735
|
||||
version: |
|
||||
Huawei Versatile Routing Platform Software
|
||||
VRP (R) software, Version 5.170 (S5735 V200R019C10SPC500)
|
||||
Copyright (C) 2000-2020 HUAWEI TECH Co., Ltd.
|
||||
HUAWEI S5735-L24T4S-A1 Routing Switch uptime is 0 week, 2 days, 3 hours, 15 minutes
|
||||
system: |
|
||||
CPU Usage Stat. Cycle: 60 (Second)
|
||||
CPU Usage : 6% Max: 30%
|
||||
Memory utilization statistics at 2026-11-10 10:00:00+01:00
|
||||
System Total Memory Is: 536870912 bytes
|
||||
Total Memory Used Is: 283678464 bytes
|
||||
Memory Using Percentage Is: 52%
|
||||
ports: |
|
||||
Interface PHY Protocol InUti OutUti inErrors outErrors
|
||||
GigabitEthernet0/0/1 up up 0% 0% 0 0
|
||||
GigabitEthernet0/0/2 down down 0% 0% 0 0
|
||||
XGigabitEthernet0/0/1 *down down 0% 0% 0 0
|
||||
vlans: |
|
||||
VID Status Property MAC-LRN Statistics Description
|
||||
--------------------------------------------------------------------------------
|
||||
1 enable default enable disable VLAN 0001
|
||||
10 enable default enable disable Server
|
||||
logs: |
|
||||
Nov 10 2026 10:21:33 HUAWEI %%01SHELL/5/CMDRECORD(s)[3]:Recorded command information. (Task=VT0, User=admin)
|
||||
Nov 10 2026 10:22:00+01:00 HUAWEI %%01IFNET/4/IF_STATE(l)[4]:Interface GigabitEthernet0/0/2 has turned into DOWN state.
|
||||
expect:
|
||||
firmware: 5.170 (S5735 V200R019C10SPC500)
|
||||
model: S5735-L24T4S-A1
|
||||
cpu: 6
|
||||
mem: 52
|
||||
ports_up: 1
|
||||
ports_down: 2
|
||||
vlans: 2
|
||||
log_lines: 2
|
||||
@@ -0,0 +1,40 @@
|
||||
id: idrac
|
||||
name: Dell iDRAC
|
||||
order: 311
|
||||
hint: "Dell iDRAC (Fernwartung, Prompt /admin1-> oder racadm>>): racadm getsysinfo, racadm getversion, racadm getsel (Ereignisse), racadm lclog view -n 50, racadm get iDRAC.Info; racadm serveraction powerup/powerdown/powercycle/graceshutdown wirkt sofort; console com2 öffnet die serielle Konsole."
|
||||
detect:
|
||||
screen: ['(?i)/admin1->|racadm>>|integrated dell remote access controller|\bidrac\d*\b']
|
||||
version: ['(?i)idrac|racadm|integrated dell remote access|(?m)^RAC Information:']
|
||||
commands:
|
||||
version: racadm getsysinfo
|
||||
extra:
|
||||
- label: Strom
|
||||
label_en: Power
|
||||
cmd: racadm getsysinfo
|
||||
pick: '(?im)^Power Status\s*=\s*(\S+)'
|
||||
read: ['^racadm (getsysinfo|getversion|getsel|lclog view(\s+-n\s+\d{1,4})?|get iDRAC\.Info)$']
|
||||
parse:
|
||||
firmware: '(?im)^Firmware Version\s*=\s*(\S+)'
|
||||
model: '(?im)^System Model\s*=\s*(.+?)\s*$'
|
||||
name: '(?im)^Host Name\s*=\s*(\S+)'
|
||||
danger:
|
||||
- rx: '\bracadm\s+serveraction\s+(powerdown|powercycle|hardreset|graceshutdown)\b'
|
||||
reason: schaltet den Server aus oder startet ihn neu
|
||||
reason_en: powers the server off or restarts it
|
||||
- rx: '\bracadm\s+(racresetcfg|systemerase|resetcfg)\b'
|
||||
reason: löscht Konfiguration oder Speicher des Geräts
|
||||
- rx: '\bracadm\s+racreset\b'
|
||||
reason: startet das Gerät neu
|
||||
samples:
|
||||
- name: R740
|
||||
version: |
|
||||
RAC Information:
|
||||
Firmware Version = 6.10.30.00
|
||||
System Information:
|
||||
System Model = PowerEdge R740
|
||||
Host Name = esx01
|
||||
Power Status = ON
|
||||
expect:
|
||||
firmware: 6.10.30.00
|
||||
model: PowerEdge R740
|
||||
name: esx01
|
||||
@@ -0,0 +1,25 @@
|
||||
id: ilo
|
||||
name: HPE iLO
|
||||
order: 310
|
||||
hint: "HPE iLO (Fernwartung, SMASH-CLP, Prompt </>hpiLO->): show /system1, show /map1/firmware1, show /system1/log1 (IML), show /map1/log1, power (Zustand), vsp (serielle Konsole, zurück mit Esc+( ). power on/off/reset und reset /map1 wirken sofort."
|
||||
detect:
|
||||
banner: ['(?i)mpSSH']
|
||||
screen: ['(?i)hpiLO->|integrated lights-out']
|
||||
version: ['(?i)hpiLO|integrated lights-out|/map1/firmware1']
|
||||
commands:
|
||||
version: show /map1/firmware1
|
||||
system: show /system1
|
||||
extra:
|
||||
- label: Strom
|
||||
label_en: Power
|
||||
cmd: show /system1
|
||||
pick: '(?im)^\s*(?:power|enabled_state)=(\S+)'
|
||||
parse:
|
||||
firmware: '(?im)^\s*version=(\S+)'
|
||||
model: '(?im)^\s*name=(.+?)\s*$'
|
||||
danger:
|
||||
- rx: '^\s*(power\s+(off|reset|warm)|reset\s+/system1|stop\s+/system1|reset\s+/map1)\b'
|
||||
reason: schaltet den Server aus oder startet ihn neu
|
||||
reason_en: powers the server off or restarts it
|
||||
- rx: '^\s*(delete\s+/map1/accounts1|set\s+/map1/config1\s+oemhp_)'
|
||||
reason: ändert Benutzer oder Passwörter
|
||||
@@ -0,0 +1,23 @@
|
||||
id: junos
|
||||
name: Juniper Junos
|
||||
order: 240
|
||||
hint: "Junos-CLI: show configuration | display set, show interfaces terse, show version, show chassis hardware; Konfiguration mit configure, set …, commit."
|
||||
detect:
|
||||
screen: ['(?i)\bjunos\b']
|
||||
version: ['(?i)junos']
|
||||
commands:
|
||||
paging_off: set cli screen-length 0
|
||||
version: show version
|
||||
system: show chassis routing-engine
|
||||
ports: show interfaces terse
|
||||
vlans: show vlans brief
|
||||
config: show configuration | display set
|
||||
parse:
|
||||
reader: junos
|
||||
logs:
|
||||
commands: [show log messages | last 600 | no-more]
|
||||
ports: show interfaces terse | no-more
|
||||
reader: junos
|
||||
syslog:
|
||||
steps: [configure, 'set system syslog host {{ip}} any warning', 'set system syslog host {{ip}} port {{port}}', commit and-quit]
|
||||
abort: [rollback, exit configuration-mode]
|
||||
@@ -0,0 +1,21 @@
|
||||
id: lancom
|
||||
name: LANCOM LCOS
|
||||
order: 270
|
||||
hint: "LANCOM LCOS (Router, Access Points, Switches mit LCOS): sysinfo, ls /Status, ls /Setup, show bootlog, readconfig (ganze Konfiguration als Skript), cd /Setup/… und set …; gespeichert wird sofort. LCOS SX-Switches haben eine eigene IOS-ähnliche CLI (show running-config, copy running-config startup-config). Meist besser mit LANconfig."
|
||||
detect:
|
||||
banner: ['(?i)lancom']
|
||||
screen: ['(?i)\blancom\b']
|
||||
version: ['(?i)\blancom\b|\bLCOS\b']
|
||||
commands:
|
||||
version: sysinfo
|
||||
config: readconfig
|
||||
read: ['^sysinfo$', '^readconfig$']
|
||||
parse:
|
||||
firmware: '(?im)^VERSION:\s*(\S+)'
|
||||
model: '(?im)^DEVICE:\s*(.+?)\s*$'
|
||||
name: '(?im)^NAME:\s*(\S+)'
|
||||
syslog:
|
||||
note: "LANCOM: in LANconfig unter Meldungen/Protokolle › SYSLOG einen Server mit IP und Port eintragen."
|
||||
danger:
|
||||
- rx: '^\s*do\s+/Other/(Reboot|Cold-Boot|Factory)'
|
||||
reason: startet das Gerät neu
|
||||
@@ -0,0 +1,5 @@
|
||||
id: macos
|
||||
name: macOS
|
||||
family: macos
|
||||
order: 2
|
||||
hint: "macOS: zsh, BSD-Werkzeuge (z. B. sed -i '', kein systemctl; launchctl, brew)."
|
||||
@@ -0,0 +1,24 @@
|
||||
id: netgear
|
||||
name: NETGEAR (M4250/M4300/M4500)
|
||||
order: 255
|
||||
hint: "NETGEAR managed Switches (FASTPATH-ähnlich): show running-config, show port all, show vlan brief, show mac-addr-table, show lldp remote-device all, show version, show logging buffered; Blättern aus mit terminal length 0; Konfiguration mit configure … exit, speichern mit write memory. Ports heißen 1/0/1."
|
||||
detect:
|
||||
screen: ['(?i)netgear|prosafe|\((?:M4[235]\d\d|GSM\d{4})[\w-]*\)\s*[>#]']
|
||||
version: ['(?i)netgear|prosafe']
|
||||
commands:
|
||||
paging_off: terminal length 0
|
||||
version: show version
|
||||
ports: show port all
|
||||
vlans: show vlan brief
|
||||
config: show running-config
|
||||
parse:
|
||||
firmware: '(?im)^Software Version\.*\s*(\S+)'
|
||||
model: '(?im)^Machine Model\.*\s*(\S+)|^Machine Type\.*\s*(\S+)'
|
||||
logs:
|
||||
commands: [show logging buffered]
|
||||
ports: show port all
|
||||
reader: generic
|
||||
syslog:
|
||||
steps: [configure, 'logging host {{ip}} ipv4 {{port}} warning', logging syslog, exit]
|
||||
abort: [exit]
|
||||
save: write memory
|
||||
@@ -0,0 +1,12 @@
|
||||
# Unbekanntes Netzwerkgerät: was die meisten CLIs verstehen.
|
||||
id: network
|
||||
name: Netzwerkgerät (unbekannt)
|
||||
name_en: Network device (unknown)
|
||||
order: 9999
|
||||
hint: "Netzwerkgerät mit eigener CLI, kein Linux. Erst mit Befehlen wie show version oder ? herausfinden, was es kann."
|
||||
commands:
|
||||
version: show version
|
||||
config: show running-config
|
||||
logs:
|
||||
commands: [show logging]
|
||||
reader: generic
|
||||
@@ -0,0 +1,17 @@
|
||||
id: opnsense
|
||||
name: OPNsense
|
||||
family: bsd
|
||||
order: 121
|
||||
hint: "OPNsense (FreeBSD): nach der Anmeldung als root ein Menü, 8 = Shell. Shell: opnsense-version, configctl … (z. B. configctl filter reload), pfctl -s rules/-s state/-s info, cat /conf/config.xml, pkg, opnsense-update. Dauerhafte Änderungen über die Weboberfläche."
|
||||
detect:
|
||||
screen: ['(?i)\bOPNsense\b']
|
||||
probe: [/usr/local/sbin/opnsense-version]
|
||||
commands:
|
||||
extra:
|
||||
- label: Version
|
||||
cmd: opnsense-version
|
||||
pick: '(OPNsense\s+\S+)'
|
||||
- label: Firewall
|
||||
cmd: pfctl -si
|
||||
pick: '(?im)^Status:\s*(\w+)'
|
||||
read: ['^opnsense-version$']
|
||||
@@ -0,0 +1,57 @@
|
||||
id: panos
|
||||
name: Palo Alto PAN-OS
|
||||
order: 280
|
||||
hint: "Palo Alto PAN-OS, kein IOS: Betriebsmodus mit show system info, show interface all, show routing route, show session info, show running security-policy, show log system, show config running; Blättern aus mit set cli pager off; Konfiguration mit configure · set …/delete … · commit (erst commit macht Änderungen wirksam), Ausgabe als Befehle mit set cli config-output-format set."
|
||||
detect:
|
||||
screen: ['(?i)palo alto networks|\bPAN-OS\b|^\S+@PA-[\w-]+(?:\(\w+\))?[>#]\s*$']
|
||||
version: ['(?im)^sw-version:\s|^family:\s+\S+']
|
||||
commands:
|
||||
paging_off: set cli pager off
|
||||
version: show system info
|
||||
system: show system resources
|
||||
ports: show interface all
|
||||
config: show config running
|
||||
extra:
|
||||
- label: Sitzungen
|
||||
label_en: Sessions
|
||||
cmd: show session info
|
||||
pick: '(?im)^\s*Number of active sessions:\s*(\d+)'
|
||||
parse:
|
||||
firmware: '(?im)^sw-version:\s*(\S+)'
|
||||
model: '(?im)^model:\s*(\S+)'
|
||||
name: '(?im)^hostname:\s*(\S+)'
|
||||
uptime: '(?im)^uptime:\s*(.+?)\s*$'
|
||||
cpu: '(?i)%cpu\(s\):.*?(?P<idle>\d{1,3})(?:\.\d+)?\s+id'
|
||||
mem: '(?i)MiB Mem\s*:\s*(?P<total>[\d.]+)\s+total,\s*(?P<free>[\d.]+)\s+free'
|
||||
port_up: '(?i)^ethernet\S+\s+\d+\s+\S*/up\b'
|
||||
port_down: '(?i)^ethernet\S+\s+\d+\s+\S*/down\b'
|
||||
logs:
|
||||
commands: [show log system direction equal backward]
|
||||
reader: generic
|
||||
syslog:
|
||||
note: "PAN-OS: Device › Server Profiles › Syslog anlegen (IP, UDP, Port), unter Device › Log Settings zuweisen, dann Commit."
|
||||
danger:
|
||||
- rx: '^\s*request\s+(restart\s+(system|dataplane)|shutdown\s+system)\b'
|
||||
reason: startet das Gerät neu
|
||||
- rx: '^\s*(request\s+system\s+private-data-reset|load\s+config\b)'
|
||||
reason: überschreibt die Gerätekonfiguration
|
||||
- rx: '^\s*commit\s+force\b'
|
||||
reason: übernimmt Änderungen ohne Prüfung
|
||||
reason_en: commits changes without checks
|
||||
samples:
|
||||
- name: PA-220
|
||||
version: |
|
||||
hostname: PA-220
|
||||
model: PA-220
|
||||
sw-version: 10.2.4
|
||||
uptime: 12 days, 3:04:05
|
||||
family: 220
|
||||
system: |
|
||||
%Cpu(s): 2.3 us, 1.1 sy, 0.0 ni, 96.0 id, 0.4 wa, 0.0 hi, 0.2 si, 0.0 st
|
||||
MiB Mem : 3911.6 total, 977.9 free, 2047.5 used, 886.2 buff/cache
|
||||
expect:
|
||||
firmware: 10.2.4
|
||||
model: PA-220
|
||||
name: PA-220
|
||||
cpu: 4
|
||||
mem: 75
|
||||
@@ -0,0 +1,22 @@
|
||||
id: pfsense
|
||||
name: pfSense
|
||||
family: bsd
|
||||
order: 120
|
||||
hint: "pfSense (FreeBSD): nach der Anmeldung als admin ein Menü, 8 = Shell. Shell: pfctl -s rules/-s state/-s info, pfSsh.php playback …, cat /conf/config.xml (Konfiguration), clog/ tail /var/log/filter.log, service … , pkg. Dauerhafte Änderungen über die Weboberfläche, sonst überschreibt pfSense sie aus config.xml."
|
||||
detect:
|
||||
screen: ['(?i)welcome to pfsense|pfsense - netgate|\*\*\* welcome to pfsense']
|
||||
probe: [/usr/local/sbin/pfSsh.php]
|
||||
commands:
|
||||
extra:
|
||||
- label: Version
|
||||
cmd: cat /etc/version
|
||||
pick: '^\s*(\S+)'
|
||||
- label: Firewall
|
||||
cmd: pfctl -si
|
||||
pick: '(?im)^Status:\s*(\w+)'
|
||||
read: ['^pfctl -si$']
|
||||
danger:
|
||||
- rx: '\bpfctl\s+(-d\b|-F\s*all\b|-Fa\b)'
|
||||
reason: leert oder deaktiviert die Firewall
|
||||
- rx: '\b(/etc/rc\.initial\.defaults|rc\.initial\.defaults)\b'
|
||||
reason: löscht Konfiguration oder Speicher des Geräts
|
||||
@@ -0,0 +1,6 @@
|
||||
id: posix
|
||||
name: Linux/Unix-Shell
|
||||
name_en: Linux/Unix shell
|
||||
family: linux
|
||||
order: 1
|
||||
hint: POSIX-Shell (bash/sh) mit GNU-Werkzeugen.
|
||||
@@ -0,0 +1,5 @@
|
||||
id: powershell
|
||||
name: Windows PowerShell
|
||||
family: windows
|
||||
order: 4
|
||||
hint: "Windows mit PowerShell: Get-Service, Get-Process, Get-ChildItem, Get-NetIPAddress; keine Unix-Befehle."
|
||||
@@ -0,0 +1,40 @@
|
||||
id: procurve
|
||||
name: ArubaOS-Switch (ProCurve)
|
||||
# Spät in der Erkennung: „Boot Image“ und Versionsnummern wie YA.16.10.0009
|
||||
# sind weniger eindeutig als die Merkmale anderer Hersteller.
|
||||
order: 800
|
||||
hint: "HPE/Aruba ProCurve-CLI, kein Linux: show running-config, show interfaces brief, show vlans, show mac-address, show lldp info remote-device, show system, show version; Blättern aus mit no page; Konfiguration mit configure … exit, speichern mit write memory."
|
||||
detect:
|
||||
banner: ['(?i)mocana|procurve']
|
||||
screen: ['(?i)arubaos-switch|procurve|image stamp:|\bsoftware revision\s+:?\s*[A-Z]{1,2}\.\d{2}\.']
|
||||
version: ['(?i)image stamp', '(?im)^\s*boot image:\s+(primary|secondary)', '\b[A-Z]{1,3}\.\d{2}\.\d{2}\.\d{4}\b']
|
||||
commands:
|
||||
paging_off: no page
|
||||
version: show version
|
||||
system: show system
|
||||
ports: show interfaces brief
|
||||
vlans: show vlans
|
||||
config: show running-config
|
||||
logs:
|
||||
commands: [show logging -r]
|
||||
ports: show interfaces brief
|
||||
reader: procurve
|
||||
syslog:
|
||||
steps: [configure terminal, 'logging {{ip}} udp {{port}}', end]
|
||||
save: write memory
|
||||
variants:
|
||||
- name: ältere Firmware (vor 15.x)
|
||||
firmware: '^[A-Z]{1,2}\.(0\d|1[0-4])\.'
|
||||
hint: "Ältere Firmware: logging <IP> kennt keinen Port (immer UDP 514), manche show-Befehle fehlen."
|
||||
syslog:
|
||||
steps: [configure terminal, 'logging {{ip}}', end]
|
||||
samples:
|
||||
- name: Aruba 2930F
|
||||
version: |
|
||||
Image stamp: /ws/swbuildm/rel_onfire_qaoff/code/build/lpr(swbuildm_rel_onfire_qaoff_rel_onfire)
|
||||
Jan 13 2022 06:21:45
|
||||
WC.16.10.0009
|
||||
1018
|
||||
Boot Image: Primary
|
||||
expect:
|
||||
firmware: WC.16.10.0009
|
||||
@@ -0,0 +1,32 @@
|
||||
id: proxmox
|
||||
name: Proxmox VE
|
||||
family: linux
|
||||
order: 101
|
||||
hint: "Proxmox VE (Debian): qm list/status/start/shutdown (VMs), pct list/enter (Container), pvesm status (Speicher), pvecm status (Cluster), pveversion -v, vzdump (Sicherung), zfs/zpool, ha-manager status. Updates nur mit apt dist-upgrade und passenden Proxmox-Repos, nie apt upgrade allein. Netzwerk in /etc/network/interfaces (ifreload -a)."
|
||||
detect:
|
||||
probe: [/usr/bin/pveversion]
|
||||
commands:
|
||||
extra:
|
||||
- label: VMs aktiv
|
||||
label_en: VMs running
|
||||
cmd: qm list
|
||||
count: '(?m)^\s*\d+\s+\S+\s+running\b'
|
||||
- label: Container
|
||||
label_en: Containers
|
||||
cmd: pct list
|
||||
count: '(?m)^\d+\s+running\b'
|
||||
- label: Speicher
|
||||
label_en: Storage
|
||||
cmd: pvesm status
|
||||
count: '(?m)^\S+\s+\S+\s+active\b'
|
||||
- label: Version
|
||||
cmd: pveversion
|
||||
pick: 'pve-manager/(\S+)'
|
||||
read: ['^qm list$', '^pct list$', '^pvesm status$', '^pveversion$', '^pvecm status$']
|
||||
danger:
|
||||
- rx: '\b(qm|pct)\s+(destroy|stop|reset|rollback|unlock)\b'
|
||||
reason: schaltet VMs ab oder löscht sie
|
||||
reason_en: stops or deletes VMs
|
||||
- rx: '\bpvecm\s+(delnode|expected)\b'
|
||||
reason: ändert den Cluster
|
||||
reason_en: changes the cluster
|
||||
@@ -0,0 +1,16 @@
|
||||
id: qnap
|
||||
name: QNAP QTS / QuTS
|
||||
family: linux
|
||||
order: 104
|
||||
hint: "QNAP QTS/QuTS hero (Linux ohne apt): qpkg_cli, getcfg/setcfg (Einstellungen in /etc/config/uLinux.conf), /etc/init.d/<dienst>.sh restart, cat /proc/mdstat; Freigaben unter /share/…. Viele Einstellungen nur in der Weboberfläche."
|
||||
detect:
|
||||
probe: [/etc/config/uLinux.conf]
|
||||
commands:
|
||||
extra:
|
||||
- label: Version
|
||||
cmd: cat /etc/config/uLinux.conf
|
||||
pick: '(?im)^\s*Version\s*=\s*(\S+)'
|
||||
- label: Modell
|
||||
label_en: Model
|
||||
cmd: cat /etc/config/uLinux.conf
|
||||
pick: '(?im)^\s*Model\s*=\s*(\S+)'
|
||||
@@ -0,0 +1,28 @@
|
||||
id: routeros
|
||||
name: MikroTik RouterOS
|
||||
order: 250
|
||||
hint: "RouterOS-CLI: /system resource print, /interface print, /ip address print, /ip route print, /export; keine Linux-Befehle."
|
||||
detect:
|
||||
banner: ['(?i)rosssh|mikrotik']
|
||||
screen: ['(?i)mikrotik routeros|\[[\w.-]+@[\w.-]+\] >']
|
||||
version: ['(?i)routeros|mikrotik|board-name:']
|
||||
commands:
|
||||
version: /system resource print
|
||||
system: /system identity print
|
||||
ports: /interface ethernet print terse
|
||||
vlans: /interface vlan print terse
|
||||
config: /export
|
||||
parse:
|
||||
reader: routeros
|
||||
logs:
|
||||
commands: [/log print without-paging]
|
||||
reader: routeros
|
||||
syslog:
|
||||
steps:
|
||||
- '/system logging action add name=sshtermy target=remote remote={{ip}} remote-port={{port}}'
|
||||
- /system logging add topics=warning action=sshtermy
|
||||
- /system logging add topics=error action=sshtermy
|
||||
- /system logging add topics=critical action=sshtermy
|
||||
danger:
|
||||
- rx: '^\s*/?(ip\s+firewall\s+\S+\s+remove|interface\s+\S*\s*remove|user\s+remove|ip\s+address\s+remove)\b'
|
||||
reason: entfernt Konfiguration (VLAN, Routing, Zugang)
|
||||
@@ -0,0 +1,29 @@
|
||||
id: ruckus-icx
|
||||
name: Ruckus ICX / Brocade FastIron
|
||||
order: 245
|
||||
hint: "Ruckus ICX bzw. Brocade FastIron: show running-config, show interfaces brief, show vlan brief, show mac-address, show lldp neighbors, show version, show logging; Blättern aus mit skip-page-display; Konfiguration mit configure terminal … end, speichern mit write memory. Ports heißen ethernet 1/1/1."
|
||||
detect:
|
||||
screen: ['(?i)ruckus networks|brocade communications|\bfastiron\b|\bICX\d{4}']
|
||||
version: ['(?i)ruckus|brocade|fastiron|\bICX\d{4}']
|
||||
commands:
|
||||
paging_off: skip-page-display
|
||||
version: show version
|
||||
system: show cpu-utilization
|
||||
memory: show memory
|
||||
ports: show interfaces brief
|
||||
vlans: show vlan brief
|
||||
config: show running-config
|
||||
parse:
|
||||
firmware: '(?i)SW:\s*Version\s+(\S+)'
|
||||
model: '(?im)HW:\s*Stackable\s+(\S+)|HW:\s*(\S+)'
|
||||
uptime: '(?i)system uptime is\s+(.+?)\s*$'
|
||||
cpu: '(?i)(\d{1,3}) percent busy'
|
||||
mem: '(?i)(\d{1,3})% used'
|
||||
vlan: '^\s*(\d{1,4})\s+(\S+)'
|
||||
logs:
|
||||
commands: [show logging]
|
||||
ports: show interfaces brief
|
||||
reader: generic
|
||||
syslog:
|
||||
steps: [configure terminal, 'logging host {{ip}} udp-port {{port}}', end]
|
||||
save: write memory
|
||||
@@ -0,0 +1,18 @@
|
||||
id: sonicos
|
||||
name: SonicWall SonicOS
|
||||
order: 295
|
||||
hint: "SonicWall SonicOS (ab 7 eigene CLI): show status, show interfaces, show route, show current-config; Konfiguration mit configure · … · commit. Ältere Versionen (6.x) haben eine eingeschränkte CLI; dann über die Weboberfläche."
|
||||
detect:
|
||||
screen: ['(?i)sonicwall|sonicos']
|
||||
version: ['(?i)sonicwall|sonicos']
|
||||
commands:
|
||||
version: show status
|
||||
config: show current-config
|
||||
parse:
|
||||
firmware: '(?im)^Firmware Version:\s*(?:SonicOS\s+)?(\S+)'
|
||||
model: '(?im)^Model:\s*(.+?)\s*$'
|
||||
syslog:
|
||||
note: "SonicOS: Device › Log › Syslog › Hinzufügen (IP, Port)."
|
||||
danger:
|
||||
- rx: '^\s*(restart\s*$|import\s+config\b|restore\s+settings\b)'
|
||||
reason: überschreibt die Gerätekonfiguration
|
||||
@@ -0,0 +1,14 @@
|
||||
id: sophos-sfos
|
||||
name: Sophos Firewall (SFOS)
|
||||
order: 285
|
||||
hint: "Sophos Firewall (SFOS): nach der Anmeldung ein Menü; 4 = Device Console (console>), 5 = Device Management › Advanced Shell (Linux, nur zur Fehlersuche). In der Console: system diagnostics show version-info, show advanced-firewall, system diagnostics utilities ping/traceroute, show … . Konfiguration fast nur über die Weboberfläche oder Sophos Central."
|
||||
detect:
|
||||
screen: ['(?i)sophos firewall|\bSFOS\b|sophos xg|sophos firmware version']
|
||||
version: ['(?i)\bSFOS\b|sophos']
|
||||
commands:
|
||||
version: system diagnostics show version-info
|
||||
read: ['^system diagnostics show version-info$']
|
||||
parse:
|
||||
firmware: '(?i)(SFOS\s+[\d.]+(?:\s+MR-\d+)?)'
|
||||
syslog:
|
||||
note: "Sophos Firewall: System services › Log settings › Syslog servers › Hinzufügen (IP, UDP, Port)."
|
||||
@@ -0,0 +1,19 @@
|
||||
id: synology
|
||||
name: Synology DSM
|
||||
family: linux
|
||||
order: 103
|
||||
hint: "Synology DSM (Linux ohne apt/dnf): synopkg list/start/stop, synosystemctl bzw. synoservice, cat /etc.defaults/VERSION, cat /proc/mdstat (RAID), btrfs/mdadm; Daten unter /volume1/…; root mit sudo -i. Viele Einstellungen nur in der Weboberfläche, Änderungen an Systemdateien überleben Updates oft nicht."
|
||||
detect:
|
||||
probe: [/etc.defaults/synoinfo.conf]
|
||||
commands:
|
||||
extra:
|
||||
- label: DSM
|
||||
cmd: cat /etc.defaults/VERSION
|
||||
pick: 'productversion="([^"]+)"'
|
||||
- label: RAID aktiv
|
||||
label_en: RAID active
|
||||
cmd: cat /proc/mdstat
|
||||
count: '(?m)^md\d+\s*:\s*active'
|
||||
danger:
|
||||
- rx: '\bsynopkg\s+uninstall\b'
|
||||
reason: entfernt Pakete
|
||||
@@ -0,0 +1,26 @@
|
||||
id: tplink
|
||||
name: TP-Link JetStream / Omada
|
||||
order: 265
|
||||
hint: "TP-Link JetStream-/Omada-Switches: show system-info, show running-config, show interface status, show vlan brief, show mac address-table all, show lldp neighbor-information interface; Konfiguration mit configure … end, speichern mit copy running-config startup-config. Von Omada verwaltete Switches nimmt der Controller zurück: dauerhaft dort ändern."
|
||||
detect:
|
||||
screen: ['(?i)tp-?link|jetstream']
|
||||
version: ['(?i)tp-?link|jetstream']
|
||||
commands:
|
||||
version: show system-info
|
||||
ports: show interface status
|
||||
vlans: show vlan brief
|
||||
config: show running-config
|
||||
parse:
|
||||
firmware: '(?im)^\s*Firmware Version\s*-\s*(.+?)\s*$'
|
||||
model: '(?im)^\s*Hardware Version\s*-\s*(\S+)'
|
||||
name: '(?im)^\s*System Name\s*-\s*(.+?)\s*$'
|
||||
uptime: '(?im)^\s*Running Time\s*-\s*(.+?)\s*$'
|
||||
port_up: '(?i)^\s*(?:Gi|Te|Tw)\S+\s+LinkUp'
|
||||
port_down: '(?i)^\s*(?:Gi|Te|Tw)\S+\s+LinkDown'
|
||||
logs:
|
||||
commands: [show logging buffer]
|
||||
ports: show interface status
|
||||
reader: generic
|
||||
syslog:
|
||||
steps: [configure, 'logging host index 1 {{ip}} 4', end]
|
||||
save: copy running-config startup-config
|
||||
@@ -0,0 +1,20 @@
|
||||
id: truenas
|
||||
name: TrueNAS
|
||||
family: linux
|
||||
order: 105
|
||||
hint: "TrueNAS (SCALE: Debian, CORE: FreeBSD): zpool status/list, zfs list, midclt call … (API), cli (TrueNAS-CLI ab 23.10); Einstellungen über die Weboberfläche oder midclt, nicht über Systemdateien und nie per apt/pkg."
|
||||
detect:
|
||||
probe: [/usr/bin/midclt, /usr/local/bin/midclt]
|
||||
commands:
|
||||
extra:
|
||||
- label: Pools
|
||||
cmd: zpool list -H -o name,health
|
||||
count: '(?m)\tONLINE\s*$'
|
||||
- label: Version
|
||||
cmd: cat /etc/version
|
||||
pick: '^\s*(\S+)'
|
||||
read: ['^zpool list -H -o name,health$', '^zpool status$', '^zfs list$']
|
||||
danger:
|
||||
- rx: '\bzpool\s+(destroy|labelclear|offline|detach)\b|\bzfs\s+(destroy|rollback)\b'
|
||||
reason: löscht Daten auf dem Speicher
|
||||
reason_en: deletes data on the storage
|
||||
@@ -0,0 +1,29 @@
|
||||
id: unifi
|
||||
name: UniFi-Switch (Ubiquiti)
|
||||
name_en: UniFi switch (Ubiquiti)
|
||||
order: 205
|
||||
# BusyBox-Shell: Lesebefehle wie auf einem Server prüfen.
|
||||
read_check: unix
|
||||
hint: "Ubiquiti-UniFi-Switch: Anmeldung landet in einer BusyBox-Linux-Shell (ash), keine Cisco-Syntax. Die Konfiguration kommt vom UniFi-Controller (Network-App) und wird beim nächsten Provisionieren überschrieben; dauerhaft also dort ändern. Shell: info (Modell, Firmware, Controller-Status), swctrl port show, swctrl poe show, swctrl mac show, cat /tmp/system.cfg (laufende Konfiguration), logread, set-inform http://<controller>:8080/inform. Ältere Modelle (US-…) haben zusätzlich eine EdgeSwitch-/FASTPATH-CLI über cli bzw. telnet localhost (Prompt (UBNT) >): enable, show running-config, show interfaces status all, show vlan brief, show mac-addr-table, show lldp remote-device all, zurück mit exit. syswrapper.sh restore-default setzt das Gerät zurück."
|
||||
detect:
|
||||
screen: ['(?im)welcome to unifi\s+us[^g\s!]|^\(UBNT\)\s*[>#]|^\s*model:\s+us[^g\s!][\w-]*\s*$']
|
||||
version: ['(?im)^\s*model:\s+US[^Gg\s][\w-]*\s*$|^\s*status:\s+.*?/inform\b']
|
||||
commands:
|
||||
version: info
|
||||
system: free; top -bn1 | head -n 3
|
||||
ports: swctrl port show
|
||||
config: cat /tmp/system.cfg
|
||||
parse:
|
||||
reader: unifi
|
||||
read:
|
||||
- '^info$'
|
||||
- '^swctrl [\w-]+ show$'
|
||||
- '^free; top -bn1 \| head -n 3$'
|
||||
logs:
|
||||
commands: [tail -n 600 /var/log/messages]
|
||||
reader: busybox
|
||||
syslog:
|
||||
note: "UniFi-Switches stellt man im UniFi-Controller ein: Einstellungen › System › Remote Logging (Syslog)."
|
||||
danger:
|
||||
- rx: '(\bsyswrapper\.sh\s+restore-default\b|^\s*set-default\s*$)'
|
||||
reason: löscht Konfiguration oder Speicher des Geräts
|
||||
@@ -0,0 +1,11 @@
|
||||
id: vyos
|
||||
name: VyOS
|
||||
family: linux
|
||||
order: 130
|
||||
hint: "VyOS (Router auf Debian-Basis): Betriebsmodus show interfaces, show ip route, show version, show log; Konfiguration mit configure · set …/delete … · commit · save · exit; compare zeigt offene Änderungen, rollback geht zurück. Normale Linux-Befehle gibt es auch, die Konfiguration aber nur über configure."
|
||||
detect:
|
||||
screen: ['(?i)welcome to vyos']
|
||||
probe: [/usr/libexec/vyos]
|
||||
danger:
|
||||
- rx: '^\s*(load\s+\S|rollback\s+\d|reboot\s+now\b|poweroff\s+now\b)'
|
||||
reason: überschreibt die Gerätekonfiguration
|
||||
@@ -0,0 +1,15 @@
|
||||
id: watchguard
|
||||
name: WatchGuard Fireware
|
||||
order: 300
|
||||
hint: "WatchGuard Fireware: CLI mit show sysinfo, show interface, show route, show log, configure … exit; Regelwerk meist über Policy Manager oder Weboberfläche."
|
||||
detect:
|
||||
screen: ['(?i)watchguard|fireware']
|
||||
version: ['(?i)watchguard|fireware']
|
||||
commands:
|
||||
version: show sysinfo
|
||||
parse:
|
||||
firmware: '(?im)^\s*version\s*:\s*(\S+)'
|
||||
model: '(?im)^\s*model\s*:\s*(\S+)'
|
||||
name: '(?im)^\s*system name\s*:\s*(\S+)'
|
||||
syslog:
|
||||
note: "WatchGuard: Policy Manager › Setup › Logging › Syslog-Server (IP, Port)."
|
||||
@@ -0,0 +1,27 @@
|
||||
id: zyxel
|
||||
name: Zyxel (Switch / Firewall)
|
||||
order: 260
|
||||
hint: "Zyxel: Switches (GS/XGS, ZyNOS) mit show system-information, show running-config, show interfaces status, show vlan, show mac address-table, write memory; Firewalls (USG FLEX/ATP, ZLD) mit show version, show interface all, show running-config, configure terminal … exit, write. Nicht alle Befehle gibt es auf allen Modellen; im Zweifel mit ? nachsehen."
|
||||
detect:
|
||||
screen: ['(?i)\bzyxel\b|\bzynos\b']
|
||||
version: ['(?i)\bzyxel\b|\bzynos\b']
|
||||
commands:
|
||||
version: show system-information
|
||||
config: show running-config
|
||||
parse:
|
||||
firmware: '(?im)^\s*(?:ZyNOS )?F/W Version\s*:\s*(\S+)'
|
||||
model: '(?im)^\s*Product Model\s*:\s*(\S+)'
|
||||
name: '(?im)^\s*System Name\s*:\s*(\S+)'
|
||||
uptime: '(?im)^\s*System up Time\s*:\s*(.+?)\s*$'
|
||||
variants:
|
||||
- name: Firewall (ZLD)
|
||||
model: '(?i)^(USG|ATP|VPN|ZyWALL)'
|
||||
commands:
|
||||
version: show version
|
||||
system: show cpu status
|
||||
config: show running-config
|
||||
logs:
|
||||
commands: [show logging]
|
||||
reader: generic
|
||||
syslog:
|
||||
note: "Zyxel: in der Weboberfläche unter Management › Syslog Setup (Switch) bzw. Log & Report › Log Settings (Firewall)."
|
||||
@@ -0,0 +1,559 @@
|
||||
// Package cmdset beschreibt Befehlssätze: alles, was sshTermy über ein
|
||||
// System oder einen Gerätehersteller weiß, in einer Datei pro Satz.
|
||||
//
|
||||
// Ein Befehlssatz sagt, woran man das System erkennt (SSH-Kennung,
|
||||
// Terminaltext, Ausgabe des Versionsbefehls, Dateien auf Servern), welche
|
||||
// Befehle die Host-Übersicht (F6), die Config-Sicherung und der Log-Blick
|
||||
// tippen, wie deren Ausgabe gelesen wird, wie Syslog eingerichtet wird und
|
||||
// welchen Hinweis die KI bekommt. Varianten decken alte und neue Modelle ab.
|
||||
//
|
||||
// # Herkunft
|
||||
//
|
||||
// Eingebaute Sätze liegen als YAML-Dateien im Programm (builtin/). Eigene
|
||||
// Sätze liegen im Konfigordner unter befehlssaetze/, Sätze aus dem Team
|
||||
// unter befehlssaetze/team/. Team-Sätze sind erst aktiv, wenn der Nutzer
|
||||
// genau diesen Inhalt freigegeben hat (Prüfsumme).
|
||||
//
|
||||
// # Sicherheit
|
||||
//
|
||||
// - Eigene Sätze können Gefahrenregeln nur hinzufügen, nie entfernen.
|
||||
// - Jeder Befehl, den sshTermy selbst tippt (F6, Sicherung, Log-Blick),
|
||||
// muss die „Nur lesen“-Prüfung bestehen; das Blättern-aus-Kommando muss
|
||||
// auf einer festen Liste stehen. Lesebefehle freigeben („read“) dürfen
|
||||
// nur eingebaute Sätze.
|
||||
// - Syslog-Schritte ändern das Gerät: Sie werden jedes Mal gezeigt und
|
||||
// Zeile für Zeile gegen die Gefahrenregeln geprüft. Platzhalter gibt es
|
||||
// nur für IP und Port, und beide werden vorher geprüft.
|
||||
// - Eigene Sätze haben eigene Kennungen; ihre Erkennung greift erst, wenn
|
||||
// kein eingebauter Satz passt.
|
||||
// - Größe, Anzahl und Länge der Einträge sind begrenzt; Go-Suchmuster
|
||||
// (RE2) laufen in linearer Zeit.
|
||||
package cmdset
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/sha256"
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"gopkg.in/yaml.v3"
|
||||
|
||||
"github.com/db9979/sshtermy/internal/i18n"
|
||||
)
|
||||
|
||||
// Familien (wie domain.Family*).
|
||||
const (
|
||||
FamilyLinux = "linux"
|
||||
FamilyMacOS = "macos"
|
||||
FamilyBSD = "bsd"
|
||||
FamilyWindows = "windows"
|
||||
FamilyNetwork = "network"
|
||||
)
|
||||
|
||||
// Source: woher ein Satz kommt.
|
||||
type Source int
|
||||
|
||||
const (
|
||||
Builtin Source = iota // im Programm
|
||||
Own // eigene Datei im Konfigordner
|
||||
Team // aus dem Team-Ordner (nur nach Freigabe aktiv)
|
||||
)
|
||||
|
||||
// Set ist ein Befehlssatz, wie er in der Datei steht.
|
||||
type Set struct {
|
||||
ID string `yaml:"id"`
|
||||
Name string `yaml:"name"`
|
||||
NameEN string `yaml:"name_en,omitempty"`
|
||||
Family string `yaml:"family,omitempty"` // linux, bsd, windows, macos, network (Standard)
|
||||
Base string `yaml:"base,omitempty"` // baut auf diesem Satz auf
|
||||
Order int `yaml:"order,omitempty"` // Reihenfolge bei der Erkennung (kleiner zuerst)
|
||||
ReadKind string `yaml:"read_check,omitempty"` // Regelgruppe für die Nur-lesen-Prüfung: network, unix, windows
|
||||
Hint string `yaml:"hint,omitempty"` // Hinweis für die KI
|
||||
Detect Detect `yaml:"detect,omitempty"`
|
||||
Commands Commands `yaml:"commands,omitempty"`
|
||||
Parse Parse `yaml:"parse,omitempty"`
|
||||
Logs Logs `yaml:"logs,omitempty"`
|
||||
Syslog Syslog `yaml:"syslog,omitempty"`
|
||||
Read []string `yaml:"read,omitempty"` // nur eingebaut: weitere Lesebefehle (ganze Zeile)
|
||||
Danger []Danger `yaml:"danger,omitempty"` // zusätzliche Gefahrenregeln
|
||||
Variants []Variant `yaml:"variants,omitempty"`
|
||||
Samples []Sample `yaml:"samples,omitempty"`
|
||||
|
||||
Source Source `yaml:"-"`
|
||||
File string `yaml:"-"` // Pfad der Datei (eigene und Team-Sätze)
|
||||
Sum string `yaml:"-"` // Prüfsumme des Dateiinhalts
|
||||
Raw []byte `yaml:"-"`
|
||||
From string `yaml:"-"` // Team: wer ihn geteilt hat (aus dem Paket)
|
||||
famEff string // geerbte Familie (Install)
|
||||
}
|
||||
|
||||
// Detect: Merkmale, an denen man das System erkennt (Suchmuster).
|
||||
type Detect struct {
|
||||
Banner []string `yaml:"banner,omitempty"` // SSH-Kennung
|
||||
Screen []string `yaml:"screen,omitempty"` // Terminaltext (Login, Prompt, show version)
|
||||
Version []string `yaml:"version,omitempty"` // Ausgabe des Versionsbefehls
|
||||
Probe []string `yaml:"probe,omitempty"` // Server: diese Datei gibt es
|
||||
}
|
||||
|
||||
// Commands: Befehle, die sshTermy am Gerät tippt (alle nur lesend).
|
||||
type Commands struct {
|
||||
PagingOff string `yaml:"paging_off,omitempty"`
|
||||
Version string `yaml:"version,omitempty"`
|
||||
System string `yaml:"system,omitempty"`
|
||||
Memory string `yaml:"memory,omitempty"` // Ausgabe wird mit system zusammen gelesen
|
||||
Ports string `yaml:"ports,omitempty"`
|
||||
VLANs string `yaml:"vlans,omitempty"`
|
||||
Config string `yaml:"config,omitempty"`
|
||||
Extra []Extra `yaml:"extra,omitempty"`
|
||||
}
|
||||
|
||||
// Extra: Zusatzzeile in der Host-Übersicht, z. B. „VMs: 12“.
|
||||
type Extra struct {
|
||||
Label string `yaml:"label"`
|
||||
LabelEN string `yaml:"label_en,omitempty"`
|
||||
Cmd string `yaml:"cmd"`
|
||||
Count string `yaml:"count,omitempty"` // Wert = Anzahl der passenden Zeilen
|
||||
Pick string `yaml:"pick,omitempty"` // Wert = erste Klammer des ersten Treffers
|
||||
}
|
||||
|
||||
// Parse: wie die Ausgaben gelesen werden. Ohne Angabe gilt der allgemeine
|
||||
// Leser; die Muster überschreiben einzelne Werte. Wert = erste nicht leere
|
||||
// Klammer. cpu: Klammer = belegt in %, benannt (?P<idle>…) = frei in %.
|
||||
// mem: Klammer = belegt in %, oder benannt (?P<used>…)/(?P<free>…) mit
|
||||
// (?P<total>…).
|
||||
type Parse struct {
|
||||
Reader string `yaml:"reader,omitempty"` // eingebauter Leser: junos, routeros, fortios, unifi
|
||||
Model string `yaml:"model,omitempty"`
|
||||
Firmware string `yaml:"firmware,omitempty"`
|
||||
Name string `yaml:"name,omitempty"`
|
||||
Uptime string `yaml:"uptime,omitempty"`
|
||||
CPU string `yaml:"cpu,omitempty"`
|
||||
Mem string `yaml:"mem,omitempty"`
|
||||
PortUp string `yaml:"port_up,omitempty"` // Zeile = aktiver Port
|
||||
PortDown string `yaml:"port_down,omitempty"`
|
||||
VLAN string `yaml:"vlan,omitempty"` // Zeile mit ID und Name: Klammern 1/2 oder (?P<id>…)/(?P<name>…)
|
||||
}
|
||||
|
||||
// Logs: Log-Blick (Alt+E) und Logwache.
|
||||
type Logs struct {
|
||||
Commands []string `yaml:"commands,omitempty"`
|
||||
Ports string `yaml:"ports,omitempty"`
|
||||
Reader string `yaml:"reader,omitempty"` // procurve, arubaos-cx, routeros, fortios, busybox, junos, vrp, generic
|
||||
}
|
||||
|
||||
// Syslog: Schritte, mit denen das Gerät Meldungen an sshTermy schickt.
|
||||
type Syslog struct {
|
||||
Steps []string `yaml:"steps,omitempty"` // Platzhalter {{ip}} und {{port}}
|
||||
Note string `yaml:"note,omitempty"` // statt Schritten: so geht es von Hand
|
||||
Save string `yaml:"save,omitempty"` // Hinweis, wie man dauerhaft speichert
|
||||
// Abort: verwirft eine abgebrochene Einrichtung und verlässt den
|
||||
// Konfigurationsmodus. Nur bekannte Befehle (end, quit, return, abort …).
|
||||
Abort []string `yaml:"abort,omitempty"`
|
||||
}
|
||||
|
||||
// Danger: zusätzliche Gefahrenregel (Suchmuster pro Zeile, Grund).
|
||||
type Danger struct {
|
||||
Rx string `yaml:"rx"`
|
||||
Reason string `yaml:"reason"`
|
||||
ReasonEN string `yaml:"reason_en,omitempty"`
|
||||
}
|
||||
|
||||
// Variant: Abweichungen für bestimmte Modelle oder Firmware-Stände.
|
||||
type Variant struct {
|
||||
Name string `yaml:"name"`
|
||||
Model string `yaml:"model,omitempty"` // Suchmuster auf das Modell
|
||||
Firmware string `yaml:"firmware,omitempty"` // Suchmuster auf die Firmware
|
||||
Hint string `yaml:"hint,omitempty"` // kommt zum Hinweis dazu
|
||||
Commands Commands `yaml:"commands,omitempty"`
|
||||
Parse Parse `yaml:"parse,omitempty"`
|
||||
Logs Logs `yaml:"logs,omitempty"`
|
||||
Syslog Syslog `yaml:"syslog,omitempty"`
|
||||
}
|
||||
|
||||
// Sample: Beispielausgaben für den Selbsttest.
|
||||
type Sample struct {
|
||||
Name string `yaml:"name,omitempty"`
|
||||
Banner string `yaml:"banner,omitempty"`
|
||||
Screen string `yaml:"screen,omitempty"`
|
||||
Version string `yaml:"version,omitempty"`
|
||||
System string `yaml:"system,omitempty"`
|
||||
Ports string `yaml:"ports,omitempty"`
|
||||
VLANs string `yaml:"vlans,omitempty"`
|
||||
Logs string `yaml:"logs,omitempty"`
|
||||
Expect Expect `yaml:"expect,omitempty"`
|
||||
}
|
||||
|
||||
// Expect: was der Selbsttest erwartet (leer = egal).
|
||||
type Expect struct {
|
||||
Model string `yaml:"model,omitempty"`
|
||||
Firmware string `yaml:"firmware,omitempty"`
|
||||
Name string `yaml:"name,omitempty"`
|
||||
Uptime string `yaml:"uptime,omitempty"`
|
||||
CPU *int `yaml:"cpu,omitempty"`
|
||||
Mem *int `yaml:"mem,omitempty"`
|
||||
PortsUp *int `yaml:"ports_up,omitempty"`
|
||||
PortsDown *int `yaml:"ports_down,omitempty"`
|
||||
VLANs *int `yaml:"vlans,omitempty"`
|
||||
LogLines *int `yaml:"log_lines,omitempty"` // erkannte Log-Einträge
|
||||
Variant string `yaml:"variant,omitempty"`
|
||||
}
|
||||
|
||||
// Grenzen für Dateien (eigene und Team-Sätze, eingebaute ebenso).
|
||||
const (
|
||||
MaxFileSize = 64 << 10
|
||||
maxPatterns = 32
|
||||
maxPattern = 512
|
||||
maxCommand = 300
|
||||
maxHint = 2000
|
||||
maxVariants = 16
|
||||
maxSamples = 16
|
||||
maxExtras = 8
|
||||
maxSteps = 12
|
||||
maxDanger = 32
|
||||
maxBaseDepth = 4
|
||||
)
|
||||
|
||||
var (
|
||||
reID = regexp.MustCompile(`^[a-z0-9][a-z0-9-]{1,31}$`)
|
||||
reProbePath = regexp.MustCompile(`^/[A-Za-z0-9._/+-]{1,120}$`)
|
||||
rePlace = regexp.MustCompile(`\{\{\s*([^}]*?)\s*\}\}`)
|
||||
|
||||
// pagingOK: Befehle, die nur das Blättern dieser Sitzung abschalten.
|
||||
pagingOK = regexp.MustCompile(`(?i)^(no page|terminal length 0|terminal pager 0|terminal datadump|screen-length disable|screen-length 0 temporary|` +
|
||||
`set cli screen-length 0|set cli pager off|skip-page-display|disable clipaging|terminal more disable|terminal no more|` +
|
||||
`set terminal length 0|terminal length 0 temporary|config paging disable|no paging)$`)
|
||||
|
||||
readers = map[string]bool{"": true, "junos": true, "routeros": true, "fortios": true, "unifi": true}
|
||||
logReaders = map[string]bool{"": true, "generic": true, "procurve": true, "arubaos-cx": true, "routeros": true, "fortios": true, "busybox": true, "junos": true, "vrp": true}
|
||||
families = map[string]bool{FamilyLinux: true, FamilyMacOS: true, FamilyBSD: true, FamilyWindows: true, FamilyNetwork: true}
|
||||
readKinds = map[string]bool{"": true, "network": true, "unix": true, "windows": true}
|
||||
)
|
||||
|
||||
// CheckRead prüft, ob ein Befehl nur liest (kind: network, unix, windows).
|
||||
// Das Paket safety trägt sich hier ein; ohne Prüfung lehnt Validate eigene
|
||||
// Sätze ab.
|
||||
var CheckRead func(cmd, kind string) bool
|
||||
|
||||
// Parse liest eine Datei.
|
||||
func ParseFile(raw []byte) (*Set, error) {
|
||||
if len(raw) > MaxFileSize {
|
||||
return nil, fmt.Errorf(i18n.T("Datei zu groß (höchstens %d KB)"), MaxFileSize>>10)
|
||||
}
|
||||
dec := yaml.NewDecoder(bytes.NewReader(raw))
|
||||
dec.KnownFields(true)
|
||||
var s Set
|
||||
if err := dec.Decode(&s); err != nil {
|
||||
return nil, fmt.Errorf(i18n.T("Datei nicht lesbar: %v"), err)
|
||||
}
|
||||
s.Raw = raw
|
||||
s.Sum = Sum(raw)
|
||||
return &s, nil
|
||||
}
|
||||
|
||||
// Sum: Prüfsumme eines Dateiinhalts (für Freigaben).
|
||||
func Sum(raw []byte) string {
|
||||
h := sha256.Sum256(raw)
|
||||
return hex.EncodeToString(h[:])
|
||||
}
|
||||
|
||||
// EffFamily: Familie mit Standard.
|
||||
func (s *Set) EffFamily() string {
|
||||
switch {
|
||||
case s.Family != "":
|
||||
return s.Family
|
||||
case s.famEff != "":
|
||||
return s.famEff
|
||||
}
|
||||
return FamilyNetwork
|
||||
}
|
||||
|
||||
// DisplayName: Name in der aktiven Sprache.
|
||||
func (s *Set) DisplayName() string {
|
||||
if i18n.English() && s.NameEN != "" {
|
||||
return s.NameEN
|
||||
}
|
||||
return s.Name
|
||||
}
|
||||
|
||||
// readKind: Regelgruppe der Nur-lesen-Prüfung.
|
||||
func (s *Set) readKind() string {
|
||||
if s.ReadKind != "" {
|
||||
return s.ReadKind
|
||||
}
|
||||
if s.Family == "" && s.famEff == "" && s.Base != "" && s.Base != s.ID {
|
||||
// Familie nicht angegeben: wie die Grundlage (vor Install noch unbekannt)
|
||||
if b := Resolve(s.Base, "", ""); b != nil {
|
||||
return b.readKind()
|
||||
}
|
||||
}
|
||||
switch s.EffFamily() {
|
||||
case FamilyNetwork:
|
||||
return "network"
|
||||
case FamilyWindows:
|
||||
return "windows"
|
||||
}
|
||||
return "unix"
|
||||
}
|
||||
|
||||
// Validate prüft einen Satz. Eingebaute Sätze unterliegen denselben Regeln,
|
||||
// dürfen aber zusätzlich Lesebefehle freigeben.
|
||||
func (s *Set) Validate() error {
|
||||
var errs []string
|
||||
bad := func(format string, a ...any) { errs = append(errs, fmt.Sprintf(i18n.T(format), a...)) }
|
||||
if !reID.MatchString(s.ID) {
|
||||
bad("Kennung „%s“: nur a–z, 0–9 und -, 2 bis 32 Zeichen", s.ID)
|
||||
}
|
||||
if strings.TrimSpace(s.Name) == "" || len([]rune(s.Name)) > 60 {
|
||||
bad("Name fehlt oder ist länger als 60 Zeichen")
|
||||
}
|
||||
if s.Family != "" && !families[s.Family] {
|
||||
bad("Familie „%s“ unbekannt (linux, bsd, macos, windows, network)", s.Family)
|
||||
}
|
||||
if !readKinds[s.ReadKind] {
|
||||
bad("read_check „%s“ unbekannt (network, unix, windows)", s.ReadKind)
|
||||
}
|
||||
if s.Base == s.ID && s.ID != "" {
|
||||
bad("Ein Satz kann nicht auf sich selbst aufbauen")
|
||||
}
|
||||
if len([]rune(s.Hint)) > maxHint {
|
||||
bad("KI-Hinweis länger als %d Zeichen", maxHint)
|
||||
}
|
||||
pats := func(what string, list []string, anchored bool) {
|
||||
if len(list) > maxPatterns {
|
||||
bad("%s: höchstens %d Muster", what, maxPatterns)
|
||||
}
|
||||
for _, p := range list {
|
||||
pat(what, p, anchored, bad)
|
||||
}
|
||||
}
|
||||
pats("detect.banner", s.Detect.Banner, false)
|
||||
pats("detect.screen", s.Detect.Screen, false)
|
||||
pats("detect.version", s.Detect.Version, false)
|
||||
if len(s.Detect.Probe) > maxPatterns {
|
||||
bad("detect.probe: höchstens %d Pfade", maxPatterns)
|
||||
}
|
||||
for _, p := range s.Detect.Probe {
|
||||
if !reProbePath.MatchString(p) {
|
||||
bad("detect.probe „%s“: nur ein absoluter Pfad ohne Leer- und Sonderzeichen", p)
|
||||
}
|
||||
}
|
||||
if len(s.Read) > 0 && s.Source != Builtin {
|
||||
bad("Lesebefehle freigeben (read) dürfen nur eingebaute Befehlssätze")
|
||||
}
|
||||
pats("read", s.Read, true)
|
||||
if len(s.Danger) > maxDanger {
|
||||
bad("danger: höchstens %d Regeln", maxDanger)
|
||||
}
|
||||
for _, d := range s.Danger {
|
||||
pat("danger", d.Rx, false, bad)
|
||||
if strings.TrimSpace(d.Reason) == "" || len([]rune(d.Reason)) > 120 {
|
||||
bad("danger: Grund fehlt oder ist länger als 120 Zeichen")
|
||||
}
|
||||
}
|
||||
s.checkCommands("commands", s.Commands, bad)
|
||||
s.checkParse("parse", s.Parse, bad)
|
||||
s.checkLogs("logs", s.Logs, bad)
|
||||
checkSyslog("syslog", s.Syslog, bad)
|
||||
if len(s.Variants) > maxVariants {
|
||||
bad("höchstens %d Varianten", maxVariants)
|
||||
}
|
||||
for i, v := range s.Variants {
|
||||
w := fmt.Sprintf("variants[%d]", i+1)
|
||||
if strings.TrimSpace(v.Name) == "" {
|
||||
bad("%s: Name fehlt", w)
|
||||
}
|
||||
if v.Model == "" && v.Firmware == "" {
|
||||
bad("%s: braucht model oder firmware", w)
|
||||
}
|
||||
pat(w+".model", v.Model, false, bad)
|
||||
pat(w+".firmware", v.Firmware, false, bad)
|
||||
if len([]rune(v.Hint)) > maxHint {
|
||||
bad("%s: KI-Hinweis zu lang", w)
|
||||
}
|
||||
s.checkCommands(w+".commands", v.Commands, bad)
|
||||
s.checkParse(w+".parse", v.Parse, bad)
|
||||
s.checkLogs(w+".logs", v.Logs, bad)
|
||||
checkSyslog(w+".syslog", v.Syslog, bad)
|
||||
}
|
||||
if len(s.Samples) > maxSamples {
|
||||
bad("höchstens %d Beispiele", maxSamples)
|
||||
}
|
||||
if len(errs) > 0 {
|
||||
return errors.New(strings.Join(errs, "\n"))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func pat(what, p string, anchored bool, bad func(string, ...any)) {
|
||||
if p == "" {
|
||||
return
|
||||
}
|
||||
if len(p) > maxPattern {
|
||||
bad("%s: Muster länger als %d Zeichen", what, maxPattern)
|
||||
return
|
||||
}
|
||||
if _, err := regexp.Compile(p); err != nil {
|
||||
bad("%s: Muster „%s“ ungültig: %v", what, p, err)
|
||||
return
|
||||
}
|
||||
if anchored && (!strings.HasPrefix(p, "^") || !strings.HasSuffix(p, "$")) {
|
||||
bad("%s: Muster „%s“ muss mit ^ beginnen und mit $ enden", what, p)
|
||||
}
|
||||
}
|
||||
|
||||
// checkCommands: alles, was sshTermy tippt, muss lesen; Blättern aus nur
|
||||
// aus der festen Liste.
|
||||
func (s *Set) checkCommands(w string, c Commands, bad func(string, ...any)) {
|
||||
if c.PagingOff != "" && !pagingOK.MatchString(strings.TrimSpace(c.PagingOff)) {
|
||||
bad("%s.paging_off „%s“: nur bekannte Befehle, die das Blättern dieser Sitzung abschalten", w, c.PagingOff)
|
||||
}
|
||||
for _, x := range []struct{ k, v string }{{"version", c.Version}, {"system", c.System}, {"memory", c.Memory}, {"ports", c.Ports}, {"vlans", c.VLANs}, {"config", c.Config}} {
|
||||
s.readCmd(w+"."+x.k, x.v, bad)
|
||||
}
|
||||
if len(c.Extra) > maxExtras {
|
||||
bad("%s.extra: höchstens %d Zeilen", w, maxExtras)
|
||||
}
|
||||
for _, e := range c.Extra {
|
||||
if strings.TrimSpace(e.Label) == "" || len([]rune(e.Label)) > 12 {
|
||||
bad("%s.extra: Beschriftung fehlt oder ist länger als 12 Zeichen", w)
|
||||
}
|
||||
if strings.TrimSpace(e.Cmd) == "" {
|
||||
bad("%s.extra „%s“: Befehl fehlt", w, e.Label)
|
||||
}
|
||||
s.readCmd(w+".extra", e.Cmd, bad)
|
||||
pat(w+".extra.count", e.Count, false, bad)
|
||||
pat(w+".extra.pick", e.Pick, false, bad)
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Set) readCmd(w, cmd string, bad func(string, ...any)) {
|
||||
cmd = strings.TrimSpace(cmd)
|
||||
if cmd == "" {
|
||||
return
|
||||
}
|
||||
if len(cmd) > maxCommand || strings.ContainsAny(cmd, "\r\n") {
|
||||
bad("%s: Befehl zu lang oder mehrzeilig", w)
|
||||
return
|
||||
}
|
||||
if s.Source == Builtin && s.readBuiltin(cmd) {
|
||||
return
|
||||
}
|
||||
if CheckRead == nil {
|
||||
bad("%s: Nur-lesen-Prüfung nicht verfügbar", w)
|
||||
return
|
||||
}
|
||||
if !CheckRead(cmd, s.readKind()) {
|
||||
bad("%s: „%s“ ist kein reiner Lesebefehl; sshTermy tippt nur Befehle, die nichts ändern", w, cmd)
|
||||
}
|
||||
}
|
||||
|
||||
// readBuiltin: steht der Befehl auf der Leseliste dieses (eingebauten) Satzes?
|
||||
func (s *Set) readBuiltin(cmd string) bool {
|
||||
for _, p := range s.Read {
|
||||
if rx, err := regexp.Compile(p); err == nil && rx.MatchString(cmd) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (s *Set) checkParse(w string, p Parse, bad func(string, ...any)) {
|
||||
if !readers[p.Reader] {
|
||||
bad("%s.reader „%s“ unbekannt (junos, routeros, fortios, unifi)", w, p.Reader)
|
||||
}
|
||||
for _, x := range []string{p.Model, p.Firmware, p.Name, p.Uptime, p.CPU, p.Mem, p.PortUp, p.PortDown, p.VLAN} {
|
||||
pat(w, x, false, bad)
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Set) checkLogs(w string, l Logs, bad func(string, ...any)) {
|
||||
if !logReaders[l.Reader] {
|
||||
bad("%s.reader „%s“ unbekannt (generic, procurve, arubaos-cx, routeros, fortios, busybox, junos, vrp)", w, l.Reader)
|
||||
}
|
||||
if len(l.Commands) > 6 {
|
||||
bad("%s.commands: höchstens 6 Befehle", w)
|
||||
}
|
||||
for _, c := range l.Commands {
|
||||
s.readCmd(w+".commands", c, bad)
|
||||
}
|
||||
s.readCmd(w+".ports", l.Ports, bad)
|
||||
}
|
||||
|
||||
func checkSyslog(w string, sl Syslog, bad func(string, ...any)) {
|
||||
if len(sl.Steps) > maxSteps {
|
||||
bad("%s.steps: höchstens %d Schritte", w, maxSteps)
|
||||
}
|
||||
for _, st := range sl.Steps {
|
||||
if len(st) > maxCommand || strings.ContainsAny(st, "\r\n") || strings.TrimSpace(st) == "" {
|
||||
bad("%s.steps: Schritt leer, zu lang oder mehrzeilig", w)
|
||||
}
|
||||
for _, m := range rePlace.FindAllStringSubmatch(st, -1) {
|
||||
if m[1] != "ip" && m[1] != "port" {
|
||||
bad("%s.steps: Platzhalter {{%s}} unbekannt (nur {{ip}} und {{port}})", w, m[1])
|
||||
}
|
||||
}
|
||||
}
|
||||
if len(sl.Abort) > 4 {
|
||||
bad("%s.abort: höchstens 4 Befehle", w)
|
||||
}
|
||||
for _, c := range sl.Abort {
|
||||
if !abortOK.MatchString(c) {
|
||||
bad("%s.abort: „%s“ ist kein bekannter Befehl zum Verlassen (end, exit, quit, return, abort, rollback, exit configuration-mode)", w, c)
|
||||
}
|
||||
}
|
||||
if len([]rune(sl.Note)) > 400 || len([]rune(sl.Save)) > 120 {
|
||||
bad("%s: note oder save zu lang", w)
|
||||
}
|
||||
}
|
||||
|
||||
var abortOK = regexp.MustCompile(`(?i)^\s*(end|exit|quit|return|abort|rollback|exit configuration-mode|top)\s*$`)
|
||||
|
||||
// SyslogAbort: Befehle, die eine abgebrochene Einrichtung verwerfen. Ohne
|
||||
// Angabe im Satz aus dem ersten Schritt abgeleitet.
|
||||
func (s *Set) SyslogAbort() []string {
|
||||
if len(s.Syslog.Abort) > 0 {
|
||||
return s.Syslog.Abort
|
||||
}
|
||||
if len(s.Syslog.Steps) == 0 {
|
||||
return nil
|
||||
}
|
||||
first := strings.ToLower(strings.TrimSpace(s.Syslog.Steps[0]))
|
||||
switch {
|
||||
case first == "system-view":
|
||||
return []string{"return"}
|
||||
case strings.HasPrefix(first, "config log ") || strings.HasPrefix(first, "config system "):
|
||||
return []string{"abort"}
|
||||
case first == "configure" || first == "configure terminal" || first == "config":
|
||||
return []string{"end"}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// SyslogSteps setzt IP und Port ein. Beide werden geprüft, damit nichts
|
||||
// anderes in die Gerätekonfiguration gelangt.
|
||||
func SyslogSteps(steps []string, ip string, port int) ([]string, error) {
|
||||
if net.ParseIP(ip) == nil {
|
||||
return nil, fmt.Errorf(i18n.T("„%s“ ist keine IP-Adresse"), ip)
|
||||
}
|
||||
if port < 1 || port > 65535 {
|
||||
return nil, fmt.Errorf(i18n.T("Port %d ungültig"), port)
|
||||
}
|
||||
out := make([]string, 0, len(steps))
|
||||
for _, st := range steps {
|
||||
out = append(out, rePlace.ReplaceAllStringFunc(st, func(m string) string {
|
||||
switch strings.TrimSpace(strings.Trim(m, "{}")) {
|
||||
case "ip":
|
||||
return ip
|
||||
case "port":
|
||||
return strconv.Itoa(port)
|
||||
}
|
||||
return m
|
||||
}))
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
@@ -0,0 +1,772 @@
|
||||
package cmdset
|
||||
|
||||
import (
|
||||
"embed"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"sort"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"gopkg.in/yaml.v3"
|
||||
|
||||
"github.com/db9979/sshtermy/internal/i18n"
|
||||
)
|
||||
|
||||
//go:embed builtin/*.yaml
|
||||
var builtinFS embed.FS
|
||||
|
||||
// LoadError: eine Datei, die nicht geladen wurde.
|
||||
type LoadError struct {
|
||||
File string
|
||||
ID string
|
||||
Err string
|
||||
}
|
||||
|
||||
// Status eines Satzes im Register.
|
||||
type Status struct {
|
||||
Set *Set
|
||||
Active bool // wird benutzt
|
||||
Pending bool // Team: wartet auf Freigabe
|
||||
Changed bool // Team: früher freigegeben, Inhalt seitdem geändert
|
||||
Problem string // warum nicht aktiv / Selbsttest
|
||||
Shadowed bool // Kennung schon vergeben
|
||||
}
|
||||
|
||||
type registry struct {
|
||||
builtin []*Set
|
||||
user []*Set // eigene + freigegebene Team-Sätze (aktiv)
|
||||
all []Status
|
||||
errs []LoadError
|
||||
rx map[string]*regexp.Regexp
|
||||
danger []compiledDanger
|
||||
}
|
||||
|
||||
type compiledDanger struct {
|
||||
rx *regexp.Regexp
|
||||
reason, reasonEN string
|
||||
from string
|
||||
}
|
||||
|
||||
var (
|
||||
mu sync.RWMutex
|
||||
reg = ®istry{rx: map[string]*regexp.Regexp{}}
|
||||
)
|
||||
|
||||
func init() {
|
||||
sets, err := loadBuiltin()
|
||||
if err != nil {
|
||||
panic(err) // eingebaute Sätze sind Teil des Programms; Tests fangen das ab
|
||||
}
|
||||
r := ®istry{builtin: sets, rx: map[string]*regexp.Regexp{}}
|
||||
for _, s := range sets {
|
||||
r.all = append(r.all, Status{Set: s, Active: true})
|
||||
}
|
||||
r.compile()
|
||||
reg = r
|
||||
}
|
||||
|
||||
func loadBuiltin() ([]*Set, error) {
|
||||
ents, err := builtinFS.ReadDir("builtin")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var out []*Set
|
||||
seen := map[string]bool{}
|
||||
for _, e := range ents {
|
||||
raw, err := builtinFS.ReadFile("builtin/" + e.Name())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
s, err := ParseFile(raw)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("%s: %w", e.Name(), err)
|
||||
}
|
||||
s.Source = Builtin
|
||||
if seen[s.ID] {
|
||||
return nil, fmt.Errorf("%s: Kennung %s doppelt", e.Name(), s.ID)
|
||||
}
|
||||
seen[s.ID] = true
|
||||
out = append(out, s)
|
||||
}
|
||||
sort.SliceStable(out, func(i, j int) bool {
|
||||
if out[i].Order != out[j].Order {
|
||||
return out[i].Order < out[j].Order
|
||||
}
|
||||
return out[i].ID < out[j].ID
|
||||
})
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// ValidateBuiltin prüft alle eingebauten Sätze (für Tests; braucht CheckRead).
|
||||
func ValidateBuiltin() error {
|
||||
var errs []string
|
||||
for _, s := range Builtins() {
|
||||
if err := s.Validate(); err != nil {
|
||||
errs = append(errs, s.ID+": "+err.Error())
|
||||
}
|
||||
if s.Base != "" {
|
||||
errs = append(errs, s.ID+": eingebaute Sätze bauen auf keinem anderen auf")
|
||||
}
|
||||
}
|
||||
if len(errs) > 0 {
|
||||
return errors.New(strings.Join(errs, "\n"))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *registry) compile() {
|
||||
add := func(p string) {
|
||||
if p == "" {
|
||||
return
|
||||
}
|
||||
if _, ok := r.rx[p]; ok {
|
||||
return
|
||||
}
|
||||
if rx, err := regexp.Compile(p); err == nil {
|
||||
r.rx[p] = rx
|
||||
}
|
||||
}
|
||||
r.danger = nil
|
||||
for _, s := range r.active() {
|
||||
for _, l := range [][]string{s.Detect.Banner, s.Detect.Screen, s.Detect.Version, s.Read} {
|
||||
for _, p := range l {
|
||||
add(p)
|
||||
}
|
||||
}
|
||||
for _, d := range s.Danger {
|
||||
if rx, err := regexp.Compile(`(?im)` + d.Rx); err == nil {
|
||||
r.danger = append(r.danger, compiledDanger{rx: rx, reason: d.Reason, reasonEN: d.ReasonEN, from: s.ID})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (r *registry) active() []*Set { return append(append([]*Set(nil), r.builtin...), r.user...) }
|
||||
|
||||
func (r *registry) match(p, text string) bool {
|
||||
if rx := r.rx[p]; rx != nil {
|
||||
return rx.MatchString(text)
|
||||
}
|
||||
rx, err := regexp.Compile(p)
|
||||
return err == nil && rx.MatchString(text)
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- Abfragen
|
||||
|
||||
// Builtins: alle eingebauten Sätze in Erkennungsreihenfolge.
|
||||
func Builtins() []*Set {
|
||||
mu.RLock()
|
||||
defer mu.RUnlock()
|
||||
return append([]*Set(nil), reg.builtin...)
|
||||
}
|
||||
|
||||
// All: alle aktiven Sätze (eingebaute zuerst).
|
||||
func All() []*Set {
|
||||
mu.RLock()
|
||||
defer mu.RUnlock()
|
||||
return reg.active()
|
||||
}
|
||||
|
||||
// Statuses: alle bekannten Sätze mit Zustand (für die Liste im Editor).
|
||||
func Statuses() []Status {
|
||||
mu.RLock()
|
||||
defer mu.RUnlock()
|
||||
return append([]Status(nil), reg.all...)
|
||||
}
|
||||
|
||||
// Errors: Dateien, die beim Laden scheiterten.
|
||||
func Errors() []LoadError {
|
||||
mu.RLock()
|
||||
defer mu.RUnlock()
|
||||
return append([]LoadError(nil), reg.errs...)
|
||||
}
|
||||
|
||||
// Lookup sucht einen aktiven Satz.
|
||||
func Lookup(id string) (*Set, bool) {
|
||||
if id == "" {
|
||||
return nil, false
|
||||
}
|
||||
mu.RLock()
|
||||
defer mu.RUnlock()
|
||||
return reg.lookup(id)
|
||||
}
|
||||
|
||||
func (r *registry) lookup(id string) (*Set, bool) {
|
||||
for _, s := range r.builtin {
|
||||
if s.ID == id {
|
||||
return s, true
|
||||
}
|
||||
}
|
||||
for _, s := range r.user {
|
||||
if s.ID == id {
|
||||
return s, true
|
||||
}
|
||||
}
|
||||
return nil, false
|
||||
}
|
||||
|
||||
// IsBuiltin: Kennung eines eingebauten Satzes?
|
||||
func IsBuiltin(id string) bool {
|
||||
for _, s := range Builtins() {
|
||||
if s.ID == id {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// Resolve liefert den wirksamen Satz für ein Gerät: Grundlage(n), dann der
|
||||
// Satz selbst, dann die erste passende Variante. nil = unbekannt.
|
||||
func Resolve(id, model, firmware string) *Set {
|
||||
mu.RLock()
|
||||
defer mu.RUnlock()
|
||||
return reg.resolve(id, model, firmware)
|
||||
}
|
||||
|
||||
func (r *registry) resolve(id, model, firmware string) *Set {
|
||||
s, ok := r.lookup(id)
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
chain := []*Set{s}
|
||||
for cur := s; cur.Base != "" && len(chain) <= maxBaseDepth; {
|
||||
b, ok := r.lookup(cur.Base)
|
||||
if !ok || b == s {
|
||||
break
|
||||
}
|
||||
chain = append(chain, b)
|
||||
cur = b
|
||||
}
|
||||
eff := &Set{}
|
||||
for i := len(chain) - 1; i >= 0; i-- {
|
||||
overlay(eff, chain[i], i == 0)
|
||||
}
|
||||
eff.Variants = nil
|
||||
for _, v := range s.Variants {
|
||||
if v.matches(model, firmware) {
|
||||
applyVariant(eff, v)
|
||||
break
|
||||
}
|
||||
}
|
||||
return eff
|
||||
}
|
||||
|
||||
func (v Variant) matches(model, firmware string) bool {
|
||||
ok := func(p, val string) bool {
|
||||
if p == "" {
|
||||
return true
|
||||
}
|
||||
rx, err := regexp.Compile(p)
|
||||
return err == nil && val != "" && rx.MatchString(val)
|
||||
}
|
||||
return ok(v.Model, model) && ok(v.Firmware, firmware)
|
||||
}
|
||||
|
||||
// VariantName: welche Variante für Modell/Firmware gilt ("" = keine).
|
||||
func VariantName(id, model, firmware string) string {
|
||||
s, ok := Lookup(id)
|
||||
if !ok {
|
||||
return ""
|
||||
}
|
||||
for _, v := range s.Variants {
|
||||
if v.matches(model, firmware) {
|
||||
return v.Name
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// overlay legt src über dst: gesetzte Felder gewinnen. Kennung, Name und
|
||||
// Herkunft kommen vom obersten Satz (top). Erkennung wird nicht vererbt.
|
||||
func overlay(dst, src *Set, top bool) {
|
||||
str := func(d *string, v string) {
|
||||
if v != "" {
|
||||
*d = v
|
||||
}
|
||||
}
|
||||
if top {
|
||||
dst.ID, dst.Name, dst.NameEN, dst.Base = src.ID, src.Name, src.NameEN, src.Base
|
||||
dst.Source, dst.File, dst.Sum, dst.From, dst.Order = src.Source, src.File, src.Sum, src.From, src.Order
|
||||
dst.Detect = src.Detect
|
||||
dst.Samples = src.Samples
|
||||
dst.Read = src.Read
|
||||
}
|
||||
str(&dst.Family, src.Family)
|
||||
str(&dst.ReadKind, src.ReadKind)
|
||||
if src.Hint != "" {
|
||||
dst.Hint = strings.TrimSpace(dst.Hint + " " + src.Hint)
|
||||
}
|
||||
overCommands(&dst.Commands, src.Commands)
|
||||
overParse(&dst.Parse, src.Parse)
|
||||
overLogs(&dst.Logs, src.Logs)
|
||||
overSyslog(&dst.Syslog, src.Syslog)
|
||||
dst.Danger = append(dst.Danger, src.Danger...)
|
||||
dst.Variants = src.Variants
|
||||
}
|
||||
|
||||
func applyVariant(dst *Set, v Variant) {
|
||||
if v.Hint != "" {
|
||||
dst.Hint = strings.TrimSpace(dst.Hint + " " + v.Hint)
|
||||
}
|
||||
overCommands(&dst.Commands, v.Commands)
|
||||
overParse(&dst.Parse, v.Parse)
|
||||
overLogs(&dst.Logs, v.Logs)
|
||||
overSyslog(&dst.Syslog, v.Syslog)
|
||||
}
|
||||
|
||||
func overCommands(d *Commands, s Commands) {
|
||||
for _, x := range []struct {
|
||||
d *string
|
||||
v string
|
||||
}{{&d.PagingOff, s.PagingOff}, {&d.Version, s.Version}, {&d.System, s.System}, {&d.Memory, s.Memory},
|
||||
{&d.Ports, s.Ports}, {&d.VLANs, s.VLANs}, {&d.Config, s.Config}} {
|
||||
if x.v != "" {
|
||||
*x.d = x.v
|
||||
}
|
||||
}
|
||||
if len(s.Extra) > 0 {
|
||||
d.Extra = s.Extra
|
||||
}
|
||||
}
|
||||
|
||||
func overParse(d *Parse, s Parse) {
|
||||
for _, x := range []struct {
|
||||
d *string
|
||||
v string
|
||||
}{{&d.Reader, s.Reader}, {&d.Model, s.Model}, {&d.Firmware, s.Firmware},
|
||||
{&d.Name, s.Name}, {&d.Uptime, s.Uptime}, {&d.CPU, s.CPU}, {&d.Mem, s.Mem},
|
||||
{&d.PortUp, s.PortUp}, {&d.PortDown, s.PortDown}, {&d.VLAN, s.VLAN}} {
|
||||
if x.v != "" {
|
||||
*x.d = x.v
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func overLogs(d *Logs, s Logs) {
|
||||
if len(s.Commands) > 0 {
|
||||
d.Commands = s.Commands
|
||||
}
|
||||
if s.Ports != "" {
|
||||
d.Ports = s.Ports
|
||||
}
|
||||
if s.Reader != "" {
|
||||
d.Reader = s.Reader
|
||||
}
|
||||
}
|
||||
|
||||
func overSyslog(d *Syslog, s Syslog) {
|
||||
if len(s.Steps) > 0 {
|
||||
d.Steps, d.Abort, d.Note = s.Steps, s.Abort, "" // Abbruch gehört zu den Schritten
|
||||
}
|
||||
if s.Note != "" {
|
||||
d.Note = s.Note
|
||||
if len(s.Steps) == 0 {
|
||||
d.Steps, d.Abort = nil, nil
|
||||
}
|
||||
}
|
||||
if s.Save != "" {
|
||||
d.Save = s.Save
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- Erkennung
|
||||
|
||||
// detect: erster Satz, dessen Muster passt. Eingebaute Sätze zuerst, eigene
|
||||
// und Team-Sätze nur, wenn kein eingebauter passt.
|
||||
func detect(text string, pick func(*Set) []string) *Set {
|
||||
if text == "" {
|
||||
return nil
|
||||
}
|
||||
mu.RLock()
|
||||
defer mu.RUnlock()
|
||||
for _, group := range [][]*Set{reg.builtin, reg.user} {
|
||||
for _, s := range group {
|
||||
for _, p := range pick(s) {
|
||||
if reg.match(p, text) {
|
||||
return s
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// DetectBanner: Satz zur SSH-Kennung.
|
||||
func DetectBanner(banner string) *Set {
|
||||
return detect(banner, func(s *Set) []string { return s.Detect.Banner })
|
||||
}
|
||||
|
||||
// DetectScreen: Satz zum Terminaltext.
|
||||
func DetectScreen(text string) *Set {
|
||||
return detect(text, func(s *Set) []string { return s.Detect.Screen })
|
||||
}
|
||||
|
||||
// DetectVersion: Satz zur Ausgabe des Versionsbefehls (auch Bildschirmmuster).
|
||||
func DetectVersion(out string) *Set {
|
||||
if s := detect(out, func(s *Set) []string { return s.Detect.Version }); s != nil {
|
||||
return s
|
||||
}
|
||||
return detect(out, func(s *Set) []string {
|
||||
if s.EffFamily() != FamilyNetwork {
|
||||
return nil
|
||||
}
|
||||
return s.Detect.Screen
|
||||
})
|
||||
}
|
||||
|
||||
// ProbePaths: Dateien, an denen man Server-Sätze erkennt (Pfad → Kennung),
|
||||
// in Erkennungsreihenfolge.
|
||||
func ProbePaths() [][2]string {
|
||||
var out [][2]string
|
||||
seen := map[string]bool{}
|
||||
for _, s := range All() {
|
||||
for _, p := range s.Detect.Probe {
|
||||
if reProbePath.MatchString(p) && !seen[p] {
|
||||
seen[p] = true
|
||||
out = append(out, [2]string{p, s.ID})
|
||||
}
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- Sicherheit
|
||||
|
||||
// BuiltinRead: steht der ganze Befehl auf der Leseliste eines eingebauten
|
||||
// Satzes? Eigene Sätze können keine Lesebefehle freigeben.
|
||||
func BuiltinRead(cmd string) bool {
|
||||
cmd = strings.TrimSpace(cmd)
|
||||
if cmd == "" || strings.ContainsAny(cmd, "\r\n") {
|
||||
return false
|
||||
}
|
||||
mu.RLock()
|
||||
defer mu.RUnlock()
|
||||
for _, s := range reg.builtin {
|
||||
for _, p := range s.Read {
|
||||
if reg.match(p, cmd) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// DangerFinding: Treffer einer zusätzlichen Gefahrenregel.
|
||||
type DangerFinding struct {
|
||||
Reason string
|
||||
From string // Kennung des Satzes
|
||||
}
|
||||
|
||||
// CheckDanger prüft einen Befehl gegen die zusätzlichen Gefahrenregeln
|
||||
// aller aktiven Sätze (egal, welcher Satz zum Gerät gehört: nur ergänzen).
|
||||
func CheckDanger(cmd string) []DangerFinding {
|
||||
mu.RLock()
|
||||
defer mu.RUnlock()
|
||||
var out []DangerFinding
|
||||
for _, d := range reg.danger {
|
||||
if d.rx.MatchString(cmd) {
|
||||
r := d.reason
|
||||
if i18n.English() {
|
||||
r = i18n.T(r)
|
||||
if d.reasonEN != "" {
|
||||
r = d.reasonEN
|
||||
}
|
||||
}
|
||||
out = append(out, DangerFinding{Reason: r, From: d.from})
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- eigene Sätze
|
||||
|
||||
// DirName: Unterordner im Konfigordner.
|
||||
const DirName = "befehlssaetze"
|
||||
|
||||
// TeamDir: Unterordner für Sätze aus dem Team.
|
||||
const TeamDir = "team"
|
||||
|
||||
// Ext: Dateiendung.
|
||||
const Ext = ".yaml"
|
||||
|
||||
// Loaded: Ergebnis von LoadUser (eigene und Team-Dateien).
|
||||
type Loaded struct {
|
||||
Own, Team []*Set
|
||||
Errs []LoadError
|
||||
}
|
||||
|
||||
// ReadDir liest eigene (dir) und Team-Sätze (dir/team).
|
||||
func ReadDir(dir string) Loaded {
|
||||
var l Loaded
|
||||
read := func(d string, src Source) []*Set {
|
||||
ents, err := os.ReadDir(d)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
var out []*Set
|
||||
for _, e := range ents {
|
||||
if e.IsDir() || !strings.HasSuffix(strings.ToLower(e.Name()), Ext) {
|
||||
continue
|
||||
}
|
||||
p := filepath.Join(d, e.Name())
|
||||
info, err := e.Info()
|
||||
if err != nil || info.Size() > MaxFileSize {
|
||||
l.Errs = append(l.Errs, LoadError{File: p, Err: fmt.Sprintf(i18n.T("Datei zu groß (höchstens %d KB)"), MaxFileSize>>10)})
|
||||
continue
|
||||
}
|
||||
raw, err := os.ReadFile(p)
|
||||
if err != nil {
|
||||
l.Errs = append(l.Errs, LoadError{File: p, Err: err.Error()})
|
||||
continue
|
||||
}
|
||||
s, err := ParseFile(raw)
|
||||
if err != nil {
|
||||
l.Errs = append(l.Errs, LoadError{File: p, Err: err.Error()})
|
||||
continue
|
||||
}
|
||||
s.Source, s.File = src, p
|
||||
if src == Team {
|
||||
s.From = readFrom(raw)
|
||||
}
|
||||
out = append(out, s)
|
||||
}
|
||||
return out
|
||||
}
|
||||
l.Own = read(dir, Own)
|
||||
l.Team = read(filepath.Join(dir, TeamDir), Team)
|
||||
return l
|
||||
}
|
||||
|
||||
// readFrom: Absender aus der Kommentarzeile „# von: …“ am Dateianfang.
|
||||
func readFrom(raw []byte) string {
|
||||
first, _, _ := strings.Cut(string(raw), "\n")
|
||||
if v, ok := strings.CutPrefix(strings.TrimSpace(first), "# von:"); ok {
|
||||
return strings.TrimSpace(v)
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// Install übernimmt eigene und Team-Sätze. approved: Kennung → Prüfsumme
|
||||
// des freigegebenen Inhalts. Team-Sätze ohne passende Freigabe bleiben
|
||||
// inaktiv. selfTest (optional) prüft die Beispiele eines Satzes.
|
||||
func Install(l Loaded, approved map[string]string, selfTest func(*Set) []string) {
|
||||
r := ®istry{rx: map[string]*regexp.Regexp{}}
|
||||
mu.RLock()
|
||||
r.builtin = reg.builtin
|
||||
mu.RUnlock()
|
||||
for _, s := range r.builtin {
|
||||
r.all = append(r.all, Status{Set: s, Active: true})
|
||||
}
|
||||
r.errs = append(r.errs, l.Errs...)
|
||||
taken := map[string]bool{}
|
||||
for _, s := range r.builtin {
|
||||
taken[s.ID] = true
|
||||
}
|
||||
// Zuerst prüfen, dann Grundlagen auflösen (eigene Sätze können auf
|
||||
// anderen eigenen aufbauen).
|
||||
try := func(s *Set) (st Status) {
|
||||
st.Set = s
|
||||
switch {
|
||||
case taken[s.ID]:
|
||||
st.Shadowed = true
|
||||
if IsBuiltinID(r.builtin, s.ID) {
|
||||
st.Problem = i18n.T("Kennung gehört zu einem eingebauten Satz; bitte umbenennen")
|
||||
} else {
|
||||
st.Problem = i18n.T("Kennung schon vergeben")
|
||||
}
|
||||
return st
|
||||
}
|
||||
if err := s.Validate(); err != nil {
|
||||
st.Problem = err.Error()
|
||||
return st
|
||||
}
|
||||
return st
|
||||
}
|
||||
var cands []Status
|
||||
for _, s := range l.Own {
|
||||
st := try(s)
|
||||
if st.Problem == "" {
|
||||
taken[s.ID] = true
|
||||
}
|
||||
cands = append(cands, st)
|
||||
}
|
||||
for _, s := range l.Team {
|
||||
st := try(s)
|
||||
if st.Problem == "" {
|
||||
sum, ok := approved[s.ID]
|
||||
switch {
|
||||
case !ok:
|
||||
st.Pending = true
|
||||
st.Problem = i18n.T("wartet auf Freigabe")
|
||||
case sum != s.Sum:
|
||||
st.Pending, st.Changed = true, true
|
||||
st.Problem = i18n.T("vom Team geändert, wartet auf Freigabe")
|
||||
default:
|
||||
taken[s.ID] = true
|
||||
}
|
||||
}
|
||||
cands = append(cands, st)
|
||||
}
|
||||
for i := range cands {
|
||||
if cands[i].Problem == "" {
|
||||
r.user = append(r.user, cands[i].Set)
|
||||
}
|
||||
}
|
||||
// Grundlage muss existieren und darf keinen Kreis bilden.
|
||||
for changed := true; changed; {
|
||||
changed = false
|
||||
for i := range cands {
|
||||
st := &cands[i]
|
||||
if st.Problem != "" || st.Set.Base == "" {
|
||||
continue
|
||||
}
|
||||
if msg := r.baseProblem(st.Set); msg != "" {
|
||||
st.Problem = msg
|
||||
r.user = without(r.user, st.Set)
|
||||
changed = true
|
||||
}
|
||||
}
|
||||
}
|
||||
// Familie erbt von der Grundlage (für Erkennung, Anzeige, Nur-lesen-Regeln).
|
||||
for _, u := range r.user {
|
||||
if u.Family == "" && u.Base != "" {
|
||||
if res := r.resolve(u.ID, "", ""); res != nil {
|
||||
u.famEff = res.Family
|
||||
}
|
||||
}
|
||||
}
|
||||
if selfTest != nil {
|
||||
for i := range cands {
|
||||
st := &cands[i]
|
||||
if st.Problem != "" || len(st.Set.Samples) == 0 {
|
||||
continue
|
||||
}
|
||||
if fails := selfTest(st.Set); len(fails) > 0 {
|
||||
// aktiv bleiben (Erkennung kann trotzdem stimmen), aber zeigen
|
||||
st.Problem = i18n.T("Selbsttest: ") + strings.Join(fails, "; ")
|
||||
}
|
||||
}
|
||||
}
|
||||
for _, st := range cands {
|
||||
st.Active = !st.Pending && !st.Shadowed && containsSet(r.user, st.Set)
|
||||
r.all = append(r.all, st)
|
||||
}
|
||||
r.compile()
|
||||
mu.Lock()
|
||||
reg = r
|
||||
mu.Unlock()
|
||||
}
|
||||
|
||||
// IsBuiltinID: gehört id zu einem der Sätze?
|
||||
func IsBuiltinID(list []*Set, id string) bool {
|
||||
for _, s := range list {
|
||||
if s.ID == id {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (r *registry) baseProblem(s *Set) string {
|
||||
seen := map[string]bool{s.ID: true}
|
||||
cur := s
|
||||
for depth := 0; cur.Base != ""; depth++ {
|
||||
if depth >= maxBaseDepth {
|
||||
return i18n.T("Grundlage zu tief verschachtelt")
|
||||
}
|
||||
if seen[cur.Base] {
|
||||
return i18n.T("Grundlagen bilden einen Kreis")
|
||||
}
|
||||
b, ok := r.lookup(cur.Base)
|
||||
if !ok {
|
||||
return fmt.Sprintf(i18n.T("Grundlage „%s“ fehlt"), cur.Base)
|
||||
}
|
||||
seen[b.ID] = true
|
||||
cur = b
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func without(list []*Set, s *Set) []*Set {
|
||||
out := list[:0:0]
|
||||
for _, x := range list {
|
||||
if x != s {
|
||||
out = append(out, x)
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func containsSet(list []*Set, s *Set) bool {
|
||||
for _, x := range list {
|
||||
if x == s {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// RunSelfTests prüft die Beispiele aller aktiven eigenen und Team-Sätze und
|
||||
// merkt Abweichungen in der Liste. Die Sätze bleiben aktiv: die Erkennung
|
||||
// kann trotzdem stimmen, der Nutzer sieht aber, was nicht passt.
|
||||
func RunSelfTests(test func(*Set) []string) {
|
||||
mu.RLock()
|
||||
var todo []*Set
|
||||
for _, st := range reg.all {
|
||||
if st.Active && st.Set.Source != Builtin && len(st.Set.Samples) > 0 {
|
||||
todo = append(todo, st.Set)
|
||||
}
|
||||
}
|
||||
mu.RUnlock()
|
||||
res := map[*Set]string{}
|
||||
for _, s := range todo {
|
||||
if fails := test(s); len(fails) > 0 {
|
||||
res[s] = i18n.T("Selbsttest: ") + strings.Join(fails, "; ")
|
||||
}
|
||||
}
|
||||
mu.Lock()
|
||||
for i := range reg.all {
|
||||
if msg, ok := res[reg.all[i].Set]; ok {
|
||||
reg.all[i].Problem = msg
|
||||
}
|
||||
}
|
||||
mu.Unlock()
|
||||
}
|
||||
|
||||
// Marshal schreibt einen Satz als YAML (für den Editor und den Export).
|
||||
func Marshal(s *Set) ([]byte, error) {
|
||||
var b strings.Builder
|
||||
enc := yaml.NewEncoder(&b)
|
||||
enc.SetIndent(2)
|
||||
if err := enc.Encode(s); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
_ = enc.Close()
|
||||
return []byte(b.String()), nil
|
||||
}
|
||||
|
||||
// ParseOwn liest eine Datei als eigenen Satz und prüft sie (Import, Editor,
|
||||
// KI-Entwurf). Eine Kennung, die schon ein eingebauter Satz hat, gilt nicht.
|
||||
func ParseOwn(raw []byte) (*Set, error) {
|
||||
s, err := ParseFile(raw)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
s.Source = Own
|
||||
if IsBuiltin(s.ID) {
|
||||
return s, fmt.Errorf(i18n.T("Kennung „%s“ gehört zu einem eingebauten Satz; bitte eine eigene wählen (z. B. %s-eigen)"), s.ID, s.ID)
|
||||
}
|
||||
if err := s.Validate(); err != nil {
|
||||
return s, err
|
||||
}
|
||||
if s.Base != "" {
|
||||
if _, ok := Lookup(s.Base); !ok {
|
||||
return s, fmt.Errorf(i18n.T("Grundlage „%s“ fehlt"), s.Base)
|
||||
}
|
||||
}
|
||||
return s, nil
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
// Package cmdsetcheck prüft Befehlssätze gegen ihre Beispielausgaben
|
||||
// (Selbsttest). Eigenes Paket, weil dafür Erkennung (cmdset), Leser
|
||||
// (hostinfo) und Log-Leser (logscan) zusammenkommen.
|
||||
package cmdsetcheck
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"regexp"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/db9979/sshtermy/internal/cmdset"
|
||||
"github.com/db9979/sshtermy/internal/hostinfo"
|
||||
"github.com/db9979/sshtermy/internal/i18n"
|
||||
"github.com/db9979/sshtermy/internal/logscan"
|
||||
_ "github.com/db9979/sshtermy/internal/safety" // Nur-lesen-Prüfung für cmdset
|
||||
)
|
||||
|
||||
// SelfTest prüft alle Beispiele eines (aktiven) Satzes. Rückgabe: was nicht
|
||||
// stimmt, leer = alles gut.
|
||||
func SelfTest(s *cmdset.Set) []string {
|
||||
var fails []string
|
||||
for i, smp := range s.Samples {
|
||||
name := smp.Name
|
||||
if name == "" {
|
||||
name = fmt.Sprintf(i18n.T("Beispiel %d"), i+1)
|
||||
}
|
||||
bad := func(format string, a ...any) { fails = append(fails, name+": "+fmt.Sprintf(i18n.T(format), a...)) }
|
||||
if smp.Banner != "" && len(s.Detect.Banner) > 0 && !anyMatch(s.Detect.Banner, smp.Banner) {
|
||||
bad("SSH-Kennung wird nicht erkannt")
|
||||
}
|
||||
if smp.Screen != "" && len(s.Detect.Screen) > 0 && !anyMatch(s.Detect.Screen, smp.Screen) {
|
||||
bad("Bildschirmtext wird nicht erkannt")
|
||||
}
|
||||
if smp.Version != "" && len(s.Detect.Version)+len(s.Detect.Screen) > 0 && !anyMatch(append(append([]string(nil), s.Detect.Version...), s.Detect.Screen...), smp.Version) {
|
||||
bad("Versionsausgabe wird nicht erkannt")
|
||||
}
|
||||
eff := cmdset.Resolve(s.ID, "", "")
|
||||
if eff == nil {
|
||||
eff = s
|
||||
}
|
||||
e := smp.Expect
|
||||
if smp.Version != "" || smp.System != "" || smp.Ports != "" || smp.VLANs != "" {
|
||||
sw := hostinfo.ParseWith(eff, smp.Version, smp.System, smp.Ports, smp.VLANs)
|
||||
if v := cmdset.Resolve(s.ID, sw.Model, sw.Firmware); v != nil {
|
||||
sw = hostinfo.ParseWith(v, smp.Version, smp.System, smp.Ports, smp.VLANs)
|
||||
}
|
||||
str := func(what, want, got string) {
|
||||
if want != "" && strings.TrimSpace(want) != got {
|
||||
bad("%s: erwartet „%s“, gelesen „%s“", what, want, got)
|
||||
}
|
||||
}
|
||||
str("Modell", e.Model, sw.Model)
|
||||
str("Firmware", e.Firmware, sw.Firmware)
|
||||
str("Name", e.Name, sw.Name)
|
||||
str("Laufzeit", e.Uptime, sw.Uptime)
|
||||
n := func(what string, want *int, got int) {
|
||||
if want != nil && *want != got {
|
||||
bad("%s: erwartet %d, gelesen %d", what, *want, got)
|
||||
}
|
||||
}
|
||||
n("CPU", e.CPU, sw.CPUPct)
|
||||
n("RAM", e.Mem, sw.MemPct)
|
||||
n("Ports aktiv", e.PortsUp, sw.PortsUp)
|
||||
n("Ports inaktiv", e.PortsDown, sw.PortsDown)
|
||||
n("VLANs", e.VLANs, len(sw.VLANs))
|
||||
if e.Variant != "" {
|
||||
if got := cmdset.VariantName(s.ID, sw.Model, sw.Firmware); got != e.Variant {
|
||||
bad("Variante: erwartet „%s“, gewählt „%s“", e.Variant, got)
|
||||
}
|
||||
}
|
||||
}
|
||||
if smp.Logs != "" && e.LogLines != nil {
|
||||
if got := logscan.CountLines(eff.Logs.Reader, smp.Logs, time.Now()); got != *e.LogLines {
|
||||
bad("Log-Zeilen: erwartet %d, erkannt %d", *e.LogLines, got)
|
||||
}
|
||||
}
|
||||
}
|
||||
return fails
|
||||
}
|
||||
|
||||
func anyMatch(pats []string, text string) bool {
|
||||
for _, p := range pats {
|
||||
if rx, err := regexp.Compile(p); err == nil && rx.MatchString(text) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
package cmdsetcheck
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/db9979/sshtermy/internal/cmdset"
|
||||
"github.com/db9979/sshtermy/internal/hostinfo"
|
||||
"github.com/db9979/sshtermy/internal/safety"
|
||||
)
|
||||
|
||||
// Alle eingebauten Sätze: gültig, Befehle nur lesend, Beispiele stimmen.
|
||||
func TestBuiltinSetsValid(t *testing.T) {
|
||||
if err := cmdset.ValidateBuiltin(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if n := len(cmdset.Builtins()); n < 45 {
|
||||
t.Fatalf("nur %d eingebaute Sätze", n)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuiltinSamples(t *testing.T) {
|
||||
for _, s := range cmdset.Builtins() {
|
||||
if fails := SelfTest(s); len(fails) > 0 {
|
||||
t.Errorf("%s:\n %s", s.ID, strings.Join(fails, "\n "))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Die Versionsausgabe eines Beispiels erkennt genau diesen Satz (nicht
|
||||
// einen früher stehenden anderen Hersteller).
|
||||
func TestBuiltinDetectionUnique(t *testing.T) {
|
||||
for _, s := range cmdset.Builtins() {
|
||||
for _, smp := range s.Samples {
|
||||
if smp.Version == "" || s.EffFamily() != cmdset.FamilyNetwork {
|
||||
continue
|
||||
}
|
||||
if got := hostinfo.DetectVendor(smp.Version); string(got) != s.ID {
|
||||
t.Errorf("%s/%s: erkannt als %q", s.ID, smp.Name, got)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Jeder Befehl, den sshTermy selbst tippt, ist für die Agent-/MCP-Prüfung
|
||||
// „nur lesen“ (auch über die Varianten).
|
||||
func TestBuiltinCommandsReadOnly(t *testing.T) {
|
||||
for _, s := range cmdset.Builtins() {
|
||||
kind := "network"
|
||||
if s.EffFamily() != cmdset.FamilyNetwork || s.ReadKind == "unix" {
|
||||
kind = "unix"
|
||||
}
|
||||
cs := []cmdset.Commands{s.Commands}
|
||||
ls := []cmdset.Logs{s.Logs}
|
||||
for _, v := range s.Variants {
|
||||
cs, ls = append(cs, v.Commands), append(ls, v.Logs)
|
||||
}
|
||||
var cmds []string
|
||||
for _, c := range cs {
|
||||
cmds = append(cmds, c.Version, c.System, c.Memory, c.Ports, c.VLANs, c.Config)
|
||||
for _, e := range c.Extra {
|
||||
cmds = append(cmds, e.Cmd)
|
||||
}
|
||||
}
|
||||
for _, l := range ls {
|
||||
cmds = append(cmds, l.Commands...)
|
||||
cmds = append(cmds, l.Ports)
|
||||
}
|
||||
for _, c := range cmds {
|
||||
if c != "" && !safety.ReadOnly(c, kind) {
|
||||
t.Errorf("%s: %q gilt nicht als nur lesend", s.ID, c)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Syslog-Schritte der eingebauten Sätze treffen keine Gefahrenregel.
|
||||
func TestBuiltinSyslogStepsNotDangerous(t *testing.T) {
|
||||
for _, s := range cmdset.Builtins() {
|
||||
steps, err := cmdset.SyslogSteps(s.Syslog.Steps, "192.0.2.10", 5514)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, st := range steps {
|
||||
for _, k := range safety.Kinds {
|
||||
if f := safety.Check(st, k); len(f) > 0 {
|
||||
t.Errorf("%s: %q → %v", s.ID, st, f)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Wer Syslog-Schritte in den Konfigurationsmodus hat, muss ihn bei einem
|
||||
// Fehler auch wieder verlassen können.
|
||||
func TestBuiltinSyslogAbort(t *testing.T) {
|
||||
for _, s := range cmdset.Builtins() {
|
||||
r := cmdset.Resolve(s.ID, "", "")
|
||||
if len(r.Syslog.Steps) < 2 || s.ID == "routeros" || s.ID == "cisco-wlc" {
|
||||
continue // einzelne Befehle ohne Konfigurationsmodus
|
||||
}
|
||||
if len(r.SyslogAbort()) == 0 {
|
||||
t.Errorf("%s: Syslog-Schritte ohne Abbruch-Befehle", s.ID)
|
||||
}
|
||||
}
|
||||
if _, err := cmdset.ParseOwn([]byte("id: x-abort\nname: X\nsyslog:\n steps: [configure, 'logging {{ip}}', end]\n abort: ['reload']\n")); err == nil {
|
||||
t.Error("unbekannter Abbruch-Befehl angenommen")
|
||||
}
|
||||
}
|
||||
@@ -580,6 +580,10 @@ type Settings struct {
|
||||
// Geht mit dem Sync.
|
||||
ConfigRules []string `json:"config_rules,omitempty"`
|
||||
|
||||
// CmdSetApproved: freigegebene Team-Befehlssätze (Kennung → Prüfsumme des
|
||||
// Inhalts). Ändert das Team die Datei, ist der Satz bis zur neuen Freigabe aus.
|
||||
CmdSetApproved map[string]string `json:"cmdset_approved,omitempty"`
|
||||
|
||||
// Highlight: Farbregeln für die Ausgabe im Terminal (highlight-Paket).
|
||||
Highlight HighlightConfig `json:"highlight,omitempty"`
|
||||
|
||||
@@ -650,6 +654,7 @@ func (s Settings) SyncedPart() Settings {
|
||||
s.LastLayout, s.Editor, s.Schedules = nil, "", nil
|
||||
s.Debug, s.Audit, s.MCP = false, false, ""
|
||||
s.SyslogPort = 0
|
||||
s.CmdSetApproved = nil // Freigaben gelten für die Team-Dateien dieses Rechners
|
||||
return s
|
||||
}
|
||||
|
||||
|
||||
+33
-39
@@ -3,6 +3,8 @@ package domain
|
||||
import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/db9979/sshtermy/internal/cmdset"
|
||||
)
|
||||
|
||||
// Familien eines Systemprofils.
|
||||
@@ -61,63 +63,50 @@ const MaxLearned = 12
|
||||
const MaxFailed = 12
|
||||
|
||||
// Dialect beschreibt einen Befehlssatz: Anzeigename und Hinweis für die KI.
|
||||
// Die Sätze selbst stehen in internal/cmdset (eine Datei pro Satz).
|
||||
type Dialect struct {
|
||||
ID, Name, Hint string
|
||||
Own bool // eigener oder Team-Satz (nicht eingebaut)
|
||||
}
|
||||
|
||||
// Dialects: bekannte Befehlssätze. Die Hinweise sind bewusst knapp und nennen
|
||||
// typische Befehle, damit ein Modell nicht in Linux- oder Cisco-Syntax
|
||||
// zurückfällt.
|
||||
var Dialects = []Dialect{
|
||||
{"posix", "Linux/Unix-Shell", "POSIX-Shell (bash/sh) mit GNU-Werkzeugen."},
|
||||
{"macos", "macOS", "macOS: zsh, BSD-Werkzeuge (z. B. sed -i '', kein systemctl; launchctl, brew)."},
|
||||
{"bsd", "BSD", "BSD: sh/csh, BSD-Werkzeuge, service/rc.d statt systemctl, pkg."},
|
||||
{"powershell", "Windows PowerShell", "Windows mit PowerShell: Get-Service, Get-Process, Get-ChildItem, Get-NetIPAddress; keine Unix-Befehle."},
|
||||
{"cmd", "Windows cmd.exe", "Windows-Eingabeaufforderung (cmd.exe): dir, type, ipconfig, sc query, findstr; keine Unix-Befehle."},
|
||||
{"procurve", "ArubaOS-Switch (ProCurve)", "HPE/Aruba ProCurve-CLI, kein Linux: show running-config, show interfaces brief, show vlans, show mac-address, show lldp info remote-device, show system, show version; Blättern aus mit no page; Konfiguration mit configure … exit, speichern mit write memory."},
|
||||
{"arubaos-cx", "ArubaOS-CX", "ArubaOS-CX-CLI, kein Linux: show running-config, show interface brief, show vlan, show mac-address-table, show lldp neighbor-info, show version, show system; Blättern aus mit no page; Konfiguration mit configure terminal … end, speichern mit write memory."},
|
||||
{"cisco-ios", "Cisco IOS / IOS-XE", "Cisco-IOS-CLI, kein Linux: show running-config, show ip interface brief, show interfaces status, show vlan brief, show mac address-table, show cdp neighbors, show version; Blättern aus mit terminal length 0; Konfiguration mit configure terminal … end, speichern mit write memory."},
|
||||
{"junos", "Juniper Junos", "Junos-CLI: show configuration | display set, show interfaces terse, show version, show chassis hardware; Konfiguration mit configure, set …, commit."},
|
||||
{"comware", "HPE Comware / H3C", "Comware-CLI: display current-configuration, display interface brief, display vlan, display version; Konfiguration mit system-view … quit, speichern mit save."},
|
||||
{"huawei-vrp", "Huawei VRP", "Huawei-VRP-CLI: display current-configuration, display interface brief, display version; Konfiguration mit system-view … quit, speichern mit save."},
|
||||
{"routeros", "MikroTik RouterOS", "RouterOS-CLI: /system resource print, /interface print, /ip address print, /ip route print, /export; keine Linux-Befehle."},
|
||||
{"fortios", "FortiOS", "FortiOS-CLI: get system status, show full-configuration, get system interface, diagnose …; Konfiguration mit config … edit … set … next … end."},
|
||||
{"unifi", "UniFi-Switch (Ubiquiti)", "Ubiquiti-UniFi-Switch: Anmeldung landet in einer BusyBox-Linux-Shell (ash), keine Cisco-Syntax. Die Konfiguration kommt vom UniFi-Controller (Network-App) und wird beim nächsten Provisionieren überschrieben; dauerhaft also dort ändern. Shell: info (Modell, Firmware, Controller-Status), swctrl port show, swctrl poe show, swctrl mac show, cat /tmp/system.cfg (laufende Konfiguration), logread, set-inform http://<controller>:8080/inform. Ältere Modelle (US-…) haben zusätzlich eine EdgeSwitch-/FASTPATH-CLI über cli bzw. telnet localhost (Prompt (UBNT) >): enable, show running-config, show interfaces status all, show vlan brief, show mac-addr-table, show lldp remote-device all, zurück mit exit. syswrapper.sh restore-default setzt das Gerät zurück."},
|
||||
{"network", "Netzwerkgerät (unbekannt)", "Netzwerkgerät mit eigener CLI, kein Linux. Erst mit Befehlen wie show version oder ? herausfinden, was es kann."},
|
||||
func dialectOf(s *cmdset.Set) Dialect {
|
||||
return Dialect{ID: s.ID, Name: s.Name, Hint: s.Hint, Own: s.Source != cmdset.Builtin}
|
||||
}
|
||||
|
||||
// Dialects: alle aktiven Befehlssätze (eingebaute zuerst). Der allgemeine
|
||||
// Satz „Netzwerkgerät (unbekannt)“ steht am Ende der eingebauten.
|
||||
func Dialects() []Dialect {
|
||||
var out []Dialect
|
||||
for _, s := range cmdset.All() {
|
||||
out = append(out, dialectOf(s))
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// DialectByID sucht einen Befehlssatz (leer ⇒ ok=false).
|
||||
func DialectByID(id string) (Dialect, bool) {
|
||||
for _, d := range Dialects {
|
||||
if d.ID == id {
|
||||
return d, true
|
||||
}
|
||||
if s, ok := cmdset.Lookup(id); ok {
|
||||
return dialectOf(s), true
|
||||
}
|
||||
return Dialect{}, false
|
||||
}
|
||||
|
||||
// FamilyOf: zu welcher Familie ein Befehlssatz gehört.
|
||||
func FamilyOf(dialect string) string {
|
||||
switch dialect {
|
||||
case "posix":
|
||||
return FamilyLinux
|
||||
case "macos":
|
||||
return FamilyMacOS
|
||||
case "bsd":
|
||||
return FamilyBSD
|
||||
case "powershell", "cmd":
|
||||
return FamilyWindows
|
||||
case "":
|
||||
if dialect == "" {
|
||||
return ""
|
||||
}
|
||||
if s := cmdset.Resolve(dialect, "", ""); s != nil {
|
||||
return s.EffFamily()
|
||||
}
|
||||
return FamilyNetwork
|
||||
}
|
||||
|
||||
// DialectByName sucht einen Befehlssatz über den Anzeigenamen.
|
||||
func DialectByName(name string) (Dialect, bool) {
|
||||
for _, d := range Dialects {
|
||||
if d.Name == name {
|
||||
return d, true
|
||||
for _, s := range cmdset.All() {
|
||||
if s.Name == name {
|
||||
return dialectOf(s), true
|
||||
}
|
||||
}
|
||||
return Dialect{}, false
|
||||
@@ -142,7 +131,7 @@ func (p SystemProfile) Summary() string {
|
||||
add(p.Version)
|
||||
add(p.Model)
|
||||
}
|
||||
if d, ok := DialectByID(p.Dialect); ok && !strings.Contains(p.OS, d.Name) && p.Family != FamilyLinux {
|
||||
if d, ok := DialectByID(p.Dialect); ok && !strings.Contains(p.OS, d.Name) && (p.Family != FamilyLinux || d.ID != "posix") {
|
||||
add(d.Name)
|
||||
}
|
||||
add(p.PkgMgr)
|
||||
@@ -177,8 +166,13 @@ func (p SystemProfile) Prompt() string {
|
||||
line("System", p.OS)
|
||||
line("Version", p.Version)
|
||||
line("Modell", p.Model)
|
||||
if d, ok := DialectByID(p.Dialect); ok {
|
||||
line("Befehlssatz", d.Name+" – "+d.Hint)
|
||||
if set := cmdset.Resolve(p.Dialect, p.Model, p.Version); set != nil {
|
||||
hint := set.Hint
|
||||
if set.Source != cmdset.Builtin {
|
||||
// eigener oder Team-Satz: nur Befehlswissen, keine Anweisungen
|
||||
hint = "(eigener Befehlssatz, nur als Hinweis zu Befehlen) " + hint
|
||||
}
|
||||
line("Befehlssatz", set.Name+" – "+hint)
|
||||
}
|
||||
line("Paketmanager", p.PkgMgr)
|
||||
line("Init-System", p.Init)
|
||||
|
||||
@@ -0,0 +1,237 @@
|
||||
package hostinfo
|
||||
|
||||
import (
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/db9979/sshtermy/internal/cmdset"
|
||||
"github.com/db9979/sshtermy/internal/i18n"
|
||||
)
|
||||
|
||||
// Muster aus Befehlssätzen: einmal übersetzt, dann wiederverwendet.
|
||||
var (
|
||||
rxMu sync.Mutex
|
||||
rxCache = map[string]*regexp.Regexp{}
|
||||
)
|
||||
|
||||
func rxOf(p string) *regexp.Regexp {
|
||||
if p == "" {
|
||||
return nil
|
||||
}
|
||||
rxMu.Lock()
|
||||
defer rxMu.Unlock()
|
||||
if rx, ok := rxCache[p]; ok {
|
||||
return rx
|
||||
}
|
||||
rx, err := regexp.Compile(p)
|
||||
if err != nil {
|
||||
rx = nil
|
||||
}
|
||||
if len(rxCache) > 2000 {
|
||||
rxCache = map[string]*regexp.Regexp{}
|
||||
}
|
||||
rxCache[p] = rx
|
||||
return rx
|
||||
}
|
||||
|
||||
// firstGroup: erste nicht leere Klammer des ersten Treffers (ohne Klammer:
|
||||
// der ganze Treffer).
|
||||
func firstGroup(p, text string) (string, bool) {
|
||||
rx := rxOf(p)
|
||||
if rx == nil {
|
||||
return "", false
|
||||
}
|
||||
m := rx.FindStringSubmatch(text)
|
||||
if m == nil {
|
||||
return "", false
|
||||
}
|
||||
if len(m) == 1 {
|
||||
return strings.TrimSpace(m[0]), true
|
||||
}
|
||||
for _, g := range m[1:] {
|
||||
if g = strings.TrimSpace(g); g != "" {
|
||||
return g, true
|
||||
}
|
||||
}
|
||||
return "", false
|
||||
}
|
||||
|
||||
// named: benannte Klammern eines Treffers.
|
||||
func named(rx *regexp.Regexp, text string) map[string]string {
|
||||
m := rx.FindStringSubmatch(text)
|
||||
if m == nil {
|
||||
return nil
|
||||
}
|
||||
out := map[string]string{}
|
||||
for i, n := range rx.SubexpNames() {
|
||||
if i == 0 {
|
||||
continue
|
||||
}
|
||||
if n == "" {
|
||||
n = "#" + strconv.Itoa(i)
|
||||
}
|
||||
if _, ok := out[n]; !ok || out[n] == "" {
|
||||
out[n] = strings.TrimSpace(m[i])
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func fnum(s string) (float64, bool) {
|
||||
f, err := strconv.ParseFloat(strings.ReplaceAll(strings.TrimSpace(s), ",", ""), 64)
|
||||
return f, err == nil
|
||||
}
|
||||
|
||||
func pctOf(f float64) int {
|
||||
if f < 0 || f > 100 {
|
||||
return -1
|
||||
}
|
||||
return int(f)
|
||||
}
|
||||
|
||||
// cpuFrom: cpu-Muster; (?P<idle>…) = frei, sonst erste Klammer = belegt.
|
||||
func cpuFrom(p, text string) int {
|
||||
rx := rxOf(p)
|
||||
if rx == nil {
|
||||
return -1
|
||||
}
|
||||
g := named(rx, text)
|
||||
if g == nil {
|
||||
return -1
|
||||
}
|
||||
if v, ok := fnum(g["idle"]); ok && g["idle"] != "" {
|
||||
return pctOf(100 - v)
|
||||
}
|
||||
if v, ok := fnum(firstNonEmpty(g)); ok {
|
||||
return pctOf(v)
|
||||
}
|
||||
return -1
|
||||
}
|
||||
|
||||
// memFrom: mem-Muster; used/free mit total, sonst erste Klammer = belegt %.
|
||||
func memFrom(p, text string) int {
|
||||
rx := rxOf(p)
|
||||
if rx == nil {
|
||||
return -1
|
||||
}
|
||||
g := named(rx, text)
|
||||
if g == nil {
|
||||
return -1
|
||||
}
|
||||
tot, okT := fnum(g["total"])
|
||||
if okT && tot > 0 {
|
||||
if u, ok := fnum(g["used"]); ok && g["used"] != "" && u <= tot {
|
||||
return pctOf(u * 100 / tot)
|
||||
}
|
||||
if f, ok := fnum(g["free"]); ok && g["free"] != "" && f <= tot {
|
||||
return pctOf((tot - f) * 100 / tot)
|
||||
}
|
||||
}
|
||||
if v, ok := fnum(firstNonEmpty(g)); ok {
|
||||
return pctOf(v)
|
||||
}
|
||||
return -1
|
||||
}
|
||||
|
||||
func firstNonEmpty(g map[string]string) string {
|
||||
for i := 1; i < 20; i++ {
|
||||
if v := g["#"+strconv.Itoa(i)]; v != "" {
|
||||
return v
|
||||
}
|
||||
}
|
||||
for k, v := range g {
|
||||
if k != "idle" && k != "total" && k != "used" && k != "free" && v != "" {
|
||||
return v
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// applyParse legt die Muster des Befehlssatzes über die gelesenen Werte.
|
||||
func applyParse(s *Switch, p cmdset.Parse, all, ports, vlans string) {
|
||||
for _, f := range []struct {
|
||||
rx string
|
||||
dst *string
|
||||
}{{p.Model, &s.Model}, {p.Firmware, &s.Firmware}, {p.Name, &s.Name}, {p.Uptime, &s.Uptime}} {
|
||||
if v, ok := firstGroup(f.rx, all); ok {
|
||||
*f.dst = cleanField(v)
|
||||
}
|
||||
}
|
||||
if p.CPU != "" {
|
||||
if v := cpuFrom(p.CPU, all); v >= 0 {
|
||||
s.CPUPct = v
|
||||
}
|
||||
}
|
||||
if p.Mem != "" {
|
||||
if v := memFrom(p.Mem, all); v >= 0 {
|
||||
s.MemPct = v
|
||||
}
|
||||
}
|
||||
if up, down := rxOf(p.PortUp), rxOf(p.PortDown); up != nil || down != nil {
|
||||
s.PortsUp, s.PortsDown = 0, 0
|
||||
for _, l := range strings.Split(strings.ReplaceAll(ports, "\r", ""), "\n") {
|
||||
switch {
|
||||
case up != nil && up.MatchString(l):
|
||||
s.PortsUp++
|
||||
case down != nil && down.MatchString(l):
|
||||
s.PortsDown++
|
||||
}
|
||||
}
|
||||
}
|
||||
if rx := rxOf(p.VLAN); rx != nil {
|
||||
s.VLANs = nil
|
||||
seen := map[int]bool{}
|
||||
for _, l := range strings.Split(strings.ReplaceAll(vlans, "\r", ""), "\n") {
|
||||
g := named(rx, l)
|
||||
if g == nil {
|
||||
continue
|
||||
}
|
||||
idS, name := g["id"], g["name"]
|
||||
if idS == "" {
|
||||
idS, name = g["#1"], g["#2"]
|
||||
}
|
||||
id, err := strconv.Atoi(idS)
|
||||
if err != nil || id < 1 || id > 4094 || seen[id] {
|
||||
continue
|
||||
}
|
||||
seen[id] = true
|
||||
s.VLANs = append(s.VLANs, VLAN{ID: id, Name: name})
|
||||
}
|
||||
sortVLANs(s.VLANs)
|
||||
}
|
||||
}
|
||||
|
||||
// ExtraValue: Wert einer Zusatzzeile aus der Ausgabe ihres Befehls.
|
||||
func ExtraValue(e cmdset.Extra, out string) string {
|
||||
out = strings.ReplaceAll(out, "\r", "")
|
||||
switch {
|
||||
case e.Count != "":
|
||||
rx := rxOf(e.Count)
|
||||
if rx == nil {
|
||||
return ""
|
||||
}
|
||||
return strconv.Itoa(len(rx.FindAllStringIndex(out, -1)))
|
||||
case e.Pick != "":
|
||||
v, _ := firstGroup(e.Pick, out)
|
||||
return v
|
||||
}
|
||||
for _, l := range strings.Split(out, "\n") {
|
||||
if l = strings.TrimSpace(l); l != "" {
|
||||
if len([]rune(l)) > 60 {
|
||||
l = string([]rune(l)[:60]) + "…"
|
||||
}
|
||||
return l
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// ExtraLabel: Beschriftung in der aktiven Sprache.
|
||||
func ExtraLabel(e cmdset.Extra) string {
|
||||
if i18n.English() && e.LabelEN != "" {
|
||||
return e.LabelEN
|
||||
}
|
||||
return e.Label
|
||||
}
|
||||
@@ -73,6 +73,7 @@ type Server struct {
|
||||
Security int // -1 = unbekannt
|
||||
UpdateTool string // apt, dnf, …
|
||||
RebootNeeded bool
|
||||
Extras []Extra // Zusatzzeilen aus dem Befehlssatz (Proxmox, ESXi, …)
|
||||
At time.Time
|
||||
}
|
||||
|
||||
|
||||
+64
-106
@@ -8,132 +8,76 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/db9979/sshtermy/internal/cmdset"
|
||||
"github.com/db9979/sshtermy/internal/i18n"
|
||||
)
|
||||
|
||||
// Vendor: Familie des Netzwerkgeräts, erkannt an "show version".
|
||||
// Vendor: Befehlssatz des Netzwerkgeräts (Kennung aus internal/cmdset),
|
||||
// erkannt an "show version" oder aus dem Systemprofil.
|
||||
type Vendor string
|
||||
|
||||
// Die Hersteller, die der Code selbst kennt (eigene Leser). Alle anderen
|
||||
// kommen nur aus den Befehlssatz-Dateien.
|
||||
const (
|
||||
VendorUnknown Vendor = ""
|
||||
VendorProCurve Vendor = "procurve" // ArubaOS-Switch / HP ProCurve
|
||||
VendorArubaCX Vendor = "aruba-cx" // ArubaOS-CX
|
||||
VendorCisco Vendor = "cisco" // IOS / IOS-XE
|
||||
VendorJunos Vendor = "junos" // Juniper EX/SRX/MX
|
||||
VendorMikroTik Vendor = "routeros" // MikroTik RouterOS
|
||||
VendorFortiOS Vendor = "fortios" // Fortinet FortiGate
|
||||
VendorUniFi Vendor = "unifi" // Ubiquiti UniFi-Switch (BusyBox-Shell)
|
||||
VendorProCurve Vendor = "procurve" // ArubaOS-Switch / HP ProCurve
|
||||
VendorArubaCX Vendor = "arubaos-cx" // ArubaOS-CX
|
||||
VendorCisco Vendor = "cisco-ios" // IOS / IOS-XE
|
||||
VendorJunos Vendor = "junos" // Juniper EX/SRX/MX
|
||||
VendorMikroTik Vendor = "routeros" // MikroTik RouterOS
|
||||
VendorFortiOS Vendor = "fortios" // Fortinet FortiGate
|
||||
VendorUniFi Vendor = "unifi" // Ubiquiti UniFi-Switch (BusyBox-Shell)
|
||||
)
|
||||
|
||||
// SetOf: wirksamer Befehlssatz für ein Gerät (mit Variante für Modell und
|
||||
// Firmware). Unbekannt ⇒ der allgemeine Satz „network“.
|
||||
func SetOf(v Vendor, model, firmware string) *cmdset.Set {
|
||||
if s := cmdset.Resolve(string(v), model, firmware); s != nil {
|
||||
return s
|
||||
}
|
||||
if s := cmdset.Resolve("network", "", ""); s != nil {
|
||||
return s
|
||||
}
|
||||
return &cmdset.Set{ID: "network", Commands: cmdset.Commands{Version: "show version", Config: "show running-config"}}
|
||||
}
|
||||
|
||||
// Name für die Anzeige.
|
||||
func (v Vendor) Name() string {
|
||||
switch v {
|
||||
case VendorProCurve:
|
||||
return "ArubaOS-Switch (ProCurve)"
|
||||
case VendorArubaCX:
|
||||
return "ArubaOS-CX"
|
||||
case VendorCisco:
|
||||
return "Cisco IOS"
|
||||
case VendorJunos:
|
||||
return "Juniper Junos"
|
||||
case VendorMikroTik:
|
||||
return "MikroTik RouterOS"
|
||||
case VendorFortiOS:
|
||||
return "FortiOS"
|
||||
case VendorUniFi:
|
||||
return "UniFi-Switch (Ubiquiti)"
|
||||
if s, ok := cmdset.Lookup(string(v)); ok && v != "" && s.ID != "network" {
|
||||
return s.DisplayName()
|
||||
}
|
||||
return "unbekannt"
|
||||
return i18n.T("unbekannt")
|
||||
}
|
||||
|
||||
// DetectVendor erkennt die Familie an der Ausgabe von "show version".
|
||||
// DetectVendor erkennt den Befehlssatz an der Ausgabe von "show version".
|
||||
func DetectVendor(showVersion string) Vendor {
|
||||
l := strings.ToLower(showVersion)
|
||||
switch {
|
||||
case unifiInfo.MatchString(showVersion):
|
||||
return VendorUniFi
|
||||
case strings.Contains(l, "arubaos-cx") || strings.Contains(l, "aos-cx"):
|
||||
return VendorArubaCX
|
||||
case strings.Contains(l, "cisco ios") || strings.Contains(l, "cisco internetwork"):
|
||||
return VendorCisco
|
||||
case strings.Contains(l, "junos"):
|
||||
return VendorJunos
|
||||
case strings.Contains(l, "routeros") || strings.Contains(l, "mikrotik") || strings.Contains(l, "board-name:"):
|
||||
return VendorMikroTik
|
||||
case strings.Contains(l, "fortigate") || strings.Contains(l, "fortios") || strings.Contains(l, "fortiswitch"):
|
||||
return VendorFortiOS
|
||||
case strings.Contains(l, "image stamp") || strings.Contains(l, "boot image") || procurveRev.MatchString(showVersion):
|
||||
return VendorProCurve
|
||||
if s := cmdset.DetectVersion(showVersion); s != nil && s.EffFamily() == cmdset.FamilyNetwork && s.ID != "network" {
|
||||
return Vendor(s.ID)
|
||||
}
|
||||
return VendorUnknown
|
||||
}
|
||||
|
||||
// PagingOff: Befehl, der das Blättern (-- MORE --) für diese Sitzung
|
||||
// abschaltet. Wirkt nur bis zum Abmelden, ändert keine Konfiguration.
|
||||
func (v Vendor) PagingOff() string {
|
||||
switch v {
|
||||
case VendorProCurve, VendorArubaCX:
|
||||
return "no page"
|
||||
case VendorCisco:
|
||||
return "terminal length 0"
|
||||
case VendorJunos:
|
||||
return "set cli screen-length 0"
|
||||
}
|
||||
// RouterOS blättert bei „print terse“ nicht; FortiOS ginge nur über
|
||||
// eine Konfigurationsänderung (config system console) – dort beantwortet
|
||||
// shellRun „--More--“ selbst.
|
||||
return ""
|
||||
}
|
||||
// Ohne Befehl beantwortet shellRun „--More--“ selbst.
|
||||
func (v Vendor) PagingOff() string { return SetOf(v, "", "").Commands.PagingOff }
|
||||
|
||||
// VersionCommand: Befehl, der Modell und Firmware nennt.
|
||||
func (v Vendor) VersionCommand() string {
|
||||
switch v {
|
||||
case VendorMikroTik:
|
||||
return "/system resource print"
|
||||
case VendorFortiOS:
|
||||
return "get system status"
|
||||
case VendorUniFi:
|
||||
return "info"
|
||||
if c := SetOf(v, "", "").Commands.Version; c != "" {
|
||||
return c
|
||||
}
|
||||
return "show version"
|
||||
}
|
||||
|
||||
// ConfigCommand: Befehl, der die laufende Konfiguration ausgibt (für die
|
||||
// Konfigurationssicherung). Ändert nichts am Gerät.
|
||||
func (v Vendor) ConfigCommand() string {
|
||||
switch v {
|
||||
case VendorJunos:
|
||||
return "show configuration | display set"
|
||||
case VendorMikroTik:
|
||||
return "/export"
|
||||
case VendorFortiOS:
|
||||
return "show full-configuration"
|
||||
case VendorUniFi:
|
||||
// vom Controller verteilte, gerade gültige Konfiguration
|
||||
return "cat /tmp/system.cfg"
|
||||
}
|
||||
return "show running-config"
|
||||
}
|
||||
// Konfigurationssicherung). Ändert nichts am Gerät. "" = unbekannt.
|
||||
func (v Vendor) ConfigCommand() string { return SetOf(v, "", "").Commands.Config }
|
||||
|
||||
// InfoCommands: show-Befehle für die Übersicht (nach "show version").
|
||||
// InfoCommands: Befehle für die Übersicht (nach "show version").
|
||||
func (v Vendor) InfoCommands() (system, ports, vlans string) {
|
||||
switch v {
|
||||
case VendorProCurve:
|
||||
return "show system", "show interfaces brief", "show vlans"
|
||||
case VendorArubaCX:
|
||||
return "show system", "show interface brief", "show vlan"
|
||||
case VendorCisco:
|
||||
return "show processes cpu | include CPU utilization", "show interfaces status", "show vlan brief"
|
||||
case VendorJunos:
|
||||
return "show chassis routing-engine", "show interfaces terse", "show vlans brief"
|
||||
case VendorMikroTik:
|
||||
return "/system identity print", "/interface ethernet print terse", "/interface vlan print terse"
|
||||
case VendorFortiOS:
|
||||
return "get system performance status", "get system interface physical", ""
|
||||
case VendorUniFi:
|
||||
return "free; top -bn1 | head -n 3", "swctrl port show", ""
|
||||
}
|
||||
return "", "", ""
|
||||
c := SetOf(v, "", "").Commands
|
||||
return c.System, c.Ports, c.VLANs
|
||||
}
|
||||
|
||||
// VLAN: ID und Name.
|
||||
@@ -154,9 +98,15 @@ type Switch struct {
|
||||
VLANs []VLAN
|
||||
CPUPct int // -1 = unbekannt
|
||||
MemPct int // belegter Speicher in %, -1 = unbekannt
|
||||
Extras []Extra
|
||||
At time.Time
|
||||
}
|
||||
|
||||
// Extra: Zusatzzeile aus dem Befehlssatz (z. B. „APs: 12“).
|
||||
type Extra struct {
|
||||
Label, Value string
|
||||
}
|
||||
|
||||
// Summary: eine Zeile für die Sitzungsleiste.
|
||||
func (s Switch) Summary() string {
|
||||
parts := []string{}
|
||||
@@ -202,6 +152,16 @@ var (
|
||||
|
||||
// ParseSwitch wertet die Ausgaben aus (fehlende Befehle sind leer).
|
||||
func ParseSwitch(v Vendor, version, system, ports, vlans string) Switch {
|
||||
return ParseWith(SetOf(v, "", ""), version, system, ports, vlans)
|
||||
}
|
||||
|
||||
// ParseWith liest die Ausgaben mit einem Befehlssatz: erst der allgemeine
|
||||
// Leser, dann ein eingebauter Herstellerleser, dann die Muster des Satzes.
|
||||
func ParseWith(set *cmdset.Set, version, system, ports, vlans string) Switch {
|
||||
v := Vendor(set.ID)
|
||||
if set.ID == "network" {
|
||||
v = VendorUnknown
|
||||
}
|
||||
s := Switch{Vendor: v, At: time.Now(), CPUPct: -1, MemPct: -1}
|
||||
all := version + "\n" + system
|
||||
if m := cpuUtil.FindStringSubmatch(system); m != nil {
|
||||
@@ -237,22 +197,20 @@ func ParseSwitch(v Vendor, version, system, ports, vlans string) Switch {
|
||||
} else if m := ciscoName.FindStringSubmatch(version); m != nil {
|
||||
s.Name = m[1]
|
||||
}
|
||||
switch v {
|
||||
case VendorJunos:
|
||||
switch set.Parse.Reader {
|
||||
case "junos":
|
||||
parseJunos(&s, version, system, ports, vlans)
|
||||
return s
|
||||
case VendorMikroTik:
|
||||
case "routeros":
|
||||
parseRouterOS(&s, version, system, ports, vlans)
|
||||
return s
|
||||
case VendorFortiOS:
|
||||
case "fortios":
|
||||
parseFortiOS(&s, version, system, ports)
|
||||
return s
|
||||
case VendorUniFi:
|
||||
case "unifi":
|
||||
parseUniFi(&s, version, system, ports)
|
||||
return s
|
||||
default:
|
||||
s.PortsUp, s.PortsDown = countPorts(ports)
|
||||
s.VLANs = parseVLANs(vlans)
|
||||
}
|
||||
s.PortsUp, s.PortsDown = countPorts(ports)
|
||||
s.VLANs = parseVLANs(vlans)
|
||||
applyParse(&s, set.Parse, all, ports, vlans)
|
||||
return s
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,131 @@
|
||||
package i18n
|
||||
|
||||
// Befehlssätze je Hersteller (cmdset, ui/cmdsets.go). Eigene Datei, damit
|
||||
// parallele Änderungen an en.go nicht kollidieren.
|
||||
func init() {
|
||||
for k, v := range enCmdSet {
|
||||
en[k] = v
|
||||
}
|
||||
}
|
||||
|
||||
var enCmdSet = map[string]string{
|
||||
" (Kopie)": " (copy)",
|
||||
" (danach mit i importieren)": " (then import with i)",
|
||||
" (eigen)": " (own)",
|
||||
" · %d eigene": " · %d own",
|
||||
" · %d warten": " · %d waiting",
|
||||
" · was sshTermy je Hersteller tippt, liest und der KI sagt": " · what sshTermy types, reads and tells the AI for each vendor",
|
||||
" ▤ Befehlssätze": " ▤ Command sets",
|
||||
"! Die Versionsausgabe erkennt der Satz „%s“ (Vorrang vor eigenen Sätzen).": "! The version output is detected by the set “%s” (takes precedence over own sets).",
|
||||
"%d Befehlssätze vom Team warten auf Freigabe (Einstellungen › Befehlssätze, f)": "%d command sets from the team are waiting for approval (Settings › Command sets, f)",
|
||||
"%d Beispiele für den Selbsttest": "%d samples for the self-test",
|
||||
"%d eingebaut": "%d built in",
|
||||
". Sie können eingebaute Gefahrenregeln nur ergänzen, tippen nur Lesebefehle und erkennen ein Gerät erst, wenn kein eingebauter Satz passt.": ". They can only add to built-in danger rules, only type read commands and only detect a device when no built-in set matches.",
|
||||
"Achtung: Dieses Gerät sendet immer an UDP 514, der Empfang läuft auf %d. Port in den Einstellungen auf 514 stellen oder weiterleiten.": "Warning: this device always sends to UDP 514, the receiver listens on %d. Set the port to 514 in the settings or forward it.",
|
||||
"Als eigenen Befehlssatz speichern? Danach am Gerät testen (t) und bei Bedarf bearbeiten (e).": "Save as an own command set? Then test it on the device (t) and edit it if needed (e).",
|
||||
"Basiert auf": "Based on",
|
||||
"Befehle (nur lesend)": "Commands (read-only)",
|
||||
"Befehle, die sshTermy tippt (nur lesend)": "Commands sshTermy types (read-only)",
|
||||
"Befehle:": "Commands:",
|
||||
"Befehlssatz importieren": "Import command set",
|
||||
"Befehlssatz löschen": "Delete command set",
|
||||
"Befehlssatz testen …": "Test command set …",
|
||||
"Befehlssatz „%s“ (%s) bekommt diesen Hinweis für die KI:\n\n%s\n\nDie Verbindung %s nutzt danach diesen Satz.": "Command set “%s” (%s) gets this hint for the AI:\n\n%s\n\nThe connection %s then uses this set.",
|
||||
"Befehlssatz „%s“ gespeichert": "Command set “%s” saved",
|
||||
"Befehlssatz „%s“ importiert": "Command set “%s” imported",
|
||||
"Befehlssätze (Hersteller) …": "Command sets (vendors) …",
|
||||
"Befehlssätze neu geladen": "Command sets reloaded",
|
||||
"Beispiel %d": "Sample %d",
|
||||
"Bildschirm": "Screen",
|
||||
"Blättern aus": "Paging off",
|
||||
"Datei da": "File present",
|
||||
"Datei nicht lesbar: %v": "File not readable: %v",
|
||||
"Datei zu groß (höchstens %d KB)": "File too large (at most %d KB)",
|
||||
"Der Entwurf besteht die Prüfung nicht:": "The draft does not pass the check:",
|
||||
"Der KI-Entwurf braucht den Terminal-Inhalt; in den KI-Einstellungen ist „Bildschirm mitschicken“ aus.": "The AI draft needs the terminal content; “Send screen” is off in the AI settings.",
|
||||
"Der KI-Hinweis wäre zu lang; bitte den Satz zuerst bearbeiten (e).": "The AI hint would be too long; please edit the set first (e).",
|
||||
"Der Satz ist nicht aktiv (Freigabe oder Fehler?).": "The set is not active (approval or error?).",
|
||||
"Details": "Details",
|
||||
"Die Schritte stammen aus dem eigenen Befehlssatz „%s“ (%s), nicht aus sshTermy.": "The steps come from the own command set “%s” (%s), not from sshTermy.",
|
||||
"Eigene Sätze liegen in ": "Own sets live in ",
|
||||
"Erkannt: %s (%s)": "Detected: %s (%s)",
|
||||
"Erkennung": "Detection",
|
||||
"Erkennung (reguläre Ausdrücke, mehrere mit ||)": "Detection (regular expressions, several with ||)",
|
||||
"Familie": "Family",
|
||||
"Freigeben? Danach gelten Erkennung, Befehle, KI-Hinweis und zusätzliche Gefahrenregeln dieses Satzes. Lesebefehle prüft sshTermy trotzdem, Syslog-Schritte zeigt es jedes Mal.": "Approve? Then detection, commands, AI hint and extra danger rules of this set apply. sshTermy still checks read commands and shows syslog steps every time.",
|
||||
"Für dieses Gerät ist noch kein Befehlssatz erkannt.": "No command set detected for this device yet.",
|
||||
"Für dieses Gerät kennt der Befehlssatz keinen Befehl für die Konfiguration (Einstellungen › Befehlssätze).": "The command set knows no command for the configuration of this device (Settings › Command sets).",
|
||||
"Für einen KI-Entwurf erst am Gerät anmelden und z. B. show version eingeben; die KI liest den aktuellen Tab.": "For an AI draft, first log in to the device and enter e.g. show version; the AI reads the current tab.",
|
||||
"Gespeichert wird am Gerät nichts: dauerhaft mit %s.": "Nothing is saved on the device: make it permanent with %s.",
|
||||
"Gespeichert zum Nacharbeiten: ": "Saved for rework: ",
|
||||
"Grund": "Reason",
|
||||
"Grundlage": "Base",
|
||||
"Grundlage zu tief verschachtelt": "Base nested too deeply",
|
||||
"Grundlage „%s“ fehlt": "Base “%s” missing",
|
||||
"Grundlagen bilden einen Kreis": "Bases form a loop",
|
||||
"Herkunft": "Origin",
|
||||
"Hinweis für die KI": "Hint for the AI",
|
||||
"Im aktuellen Tab gibt es keine gemerkten Korrekturen (entstehen, wenn du einen KI-Vorschlag vor dem Ausführen änderst).": "The current tab has no remembered corrections (they appear when you change an AI suggestion before running it).",
|
||||
"KI schreibt einen Entwurf …": "AI is writing a draft …",
|
||||
"KI-Entwurf": "AI draft",
|
||||
"KI-Entwurf: ": "AI draft: ",
|
||||
"Kennung": "ID",
|
||||
"Kennung gehört zu einem eingebauten Satz; bitte umbenennen": "ID belongs to a built-in set; please rename",
|
||||
"Kennung schon vergeben": "ID already taken",
|
||||
"Kennung „%s“ gehört zu einem eingebauten Satz; bitte eine eigene wählen (z. B. %s-eigen)": "ID “%s” belongs to a built-in set; please choose your own (e.g. %s-own)",
|
||||
"Kennung „%s“ ist schon vergeben": "ID “%s” is already taken",
|
||||
"Klammer = belegt in %, (?P<idle>…) = frei": "group = used in %, (?P<idle>…) = free",
|
||||
"Klammer = belegt in %, oder (?P<used>…)/(?P<free>…) mit (?P<total>…)": "group = used in %, or (?P<used>…)/(?P<free>…) with (?P<total>…)",
|
||||
"Konfiguration": "Configuration",
|
||||
"Korrekturen in „%s“ übernommen": "Corrections taken over into “%s”",
|
||||
"Korrekturen übernehmen": "Take over corrections",
|
||||
"Lesen (reguläre Ausdrücke, eine Klammer = Wert)": "Reading (regular expressions, one group = value)",
|
||||
"Login-Banner oder Prompt, z. B. (?i)acme switch": "Login banner or prompt, e.g. (?i)acme switch",
|
||||
"Neuer Befehlssatz aus dem Team:": "New command set from the team:",
|
||||
"Pfad zur .yaml-Datei:": "Path to the .yaml file:",
|
||||
"Port %d ungültig": "Port %d invalid",
|
||||
"SSH-Kennung": "SSH ID",
|
||||
"Selbsttest: ": "Self-test: ",
|
||||
"Server-Sätze testet sshTermy über eine eigene SSH-Sitzung; der aktuelle Tab ist keine.": "Server sets are tested by sshTermy over its own SSH session; the current tab is not one.",
|
||||
"Speicher": "Memory",
|
||||
"Speichern mit": "Save with",
|
||||
"Syslog eingerichtet (UDP %d). Dauerhaft erst nach dem Speichern am Gerät.": "Syslog set up (UDP %d). Permanent only after saving on the device.",
|
||||
"Syslog einrichten (ändert das Gerät)": "Set up syslog (changes the device)",
|
||||
"Syslog einrichten (ändert das Gerät, wird jedes Mal gezeigt)": "Set up syslog (changes the device, shown every time)",
|
||||
"Syslog-Schritt „%s“ gesperrt: %s": "Syslog step “%s” blocked: %s",
|
||||
"System": "System",
|
||||
"System (CPU)": "System (CPU)",
|
||||
"Team": "Team",
|
||||
"Team-Befehlssatz „%s“ freigeben": "Approve team command set “%s”",
|
||||
"Team: ": "Team: ",
|
||||
"Test „%s“ an %s": "Test “%s” on %s",
|
||||
"Text in der Ausgabe des Versionsbefehls": "Text in the output of the version command",
|
||||
"Variante": "Variant",
|
||||
"Varianten": "Variants",
|
||||
"Version": "Version",
|
||||
"Versionsausgabe": "Version output",
|
||||
"Zum Testen erst eine Verbindung zu dem Gerät öffnen (der aktuelle Tab wird benutzt).": "To test, first open a connection to the device (the current tab is used).",
|
||||
"Zusätzliche Gefahrenregel (nur ergänzen)": "Extra danger rule (add only)",
|
||||
"Zusätzliche Gefahrenregeln (gelten für alle Geräte)": "Extra danger rules (apply to all devices)",
|
||||
"am Gerät testen": "test on device",
|
||||
"a–z, 0–9 und -, eindeutig; eingebaute Kennungen sind vergeben": "a–z, 0–9 and -, unique; built-in IDs are taken",
|
||||
"eigen": "own",
|
||||
"eingebaut": "built in",
|
||||
"export": "export",
|
||||
"für den Log-Blick (Alt+E), mehrere mit ||": "for the log view (Alt+E), several with ||",
|
||||
"für die Sicherung (F6 b)": "for the backup (F6 b)",
|
||||
"import": "import",
|
||||
"leer gelassene Felder kommen von dort (Befehle, Leser, Hinweis); Erkennung nicht": "fields left empty come from there (commands, reader, hint); detection does not",
|
||||
"mit || getrennt, Platzhalter {{ip}} und {{port}}; jede Zeile wird gegen die Gefahrenregeln geprüft": "separated by ||, placeholders {{ip}} and {{port}}; every line is checked against the danger rules",
|
||||
"network = Switch/Router/Firewall (Befehle sichtbar am Prompt), sonst Server": "network = switch/router/firewall (commands visible at the prompt), otherwise server",
|
||||
"nur bekannte: terminal length 0, no page, screen-length disable, terminal pager 0, …": "only known ones: terminal length 0, no page, screen-length disable, terminal pager 0, …",
|
||||
"so erscheint er in der Auswahl „Befehlssatz“ der Verbindung": "this is how it appears in the connection's “Command set” choice",
|
||||
"vom Team geändert, wartet auf Freigabe": "changed by the team, waiting for approval",
|
||||
"wartet auf Freigabe": "waiting for approval",
|
||||
"welche CLI, typische Befehle, wie man speichert; kommt zum Hinweis der Grundlage dazu": "which CLI, typical commands, how to save; added to the base's hint",
|
||||
"wird bei einem Treffer angezeigt": "shown on a match",
|
||||
"z. B. (?i)acmessh": "e.g. (?i)acmessh",
|
||||
"z. B. ^\\s*factory-reset\\b · weitere Regeln, Varianten und Beispiele in der Datei (o)": "e.g. ^\\s*factory-reset\\b · more rules, variants and samples in the file (o)",
|
||||
"Änderungen seit der letzten Freigabe: +%d −%d": "Changes since the last approval: +%d −%d",
|
||||
"„%s“ (%s) löschen?\n\n%s\n\nVerbindungen, die ihn nutzen, fallen auf die Erkennung zurück.": "Delete “%s” (%s)?\n\n%s\n\nConnections using it fall back to detection.",
|
||||
}
|
||||
+58
-62
@@ -6,32 +6,21 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/db9979/sshtermy/internal/cmdset"
|
||||
"github.com/db9979/sshtermy/internal/hostinfo"
|
||||
"github.com/db9979/sshtermy/internal/i18n"
|
||||
)
|
||||
|
||||
// NetCommands: lesende Befehle für Switches und Firewalls. logs liefern die
|
||||
// Meldungen, ports (falls vorhanden) den Zustand der Ports für die Leiste.
|
||||
// FortiOS: „execute log filter“ setzt nur den Anzeigefilter dieser
|
||||
// CLI-Sitzung, nichts an der Konfiguration.
|
||||
// NetCommands: lesende Befehle für Switches und Firewalls aus dem
|
||||
// Befehlssatz. logs liefern die Meldungen, ports (falls vorhanden) den
|
||||
// Zustand der Ports für die Leiste. FortiOS: „execute log filter“ setzt nur
|
||||
// den Anzeigefilter dieser CLI-Sitzung, nichts an der Konfiguration.
|
||||
func NetCommands(v hostinfo.Vendor) (logs []string, ports string) {
|
||||
switch v {
|
||||
case hostinfo.VendorProCurve:
|
||||
return []string{"show logging -r"}, "show interfaces brief"
|
||||
case hostinfo.VendorArubaCX:
|
||||
return []string{"show logging -r"}, "show interface brief"
|
||||
case hostinfo.VendorCisco:
|
||||
return []string{"show logging"}, "show interfaces status"
|
||||
case hostinfo.VendorJunos:
|
||||
return []string{"show log messages | last 600 | no-more"}, "show interfaces terse | no-more"
|
||||
case hostinfo.VendorMikroTik:
|
||||
return []string{"/log print without-paging"}, ""
|
||||
case hostinfo.VendorFortiOS:
|
||||
return []string{"execute log filter reset", "execute log filter category 1", "execute log filter view-lines 1000", "execute log display"}, ""
|
||||
case hostinfo.VendorUniFi:
|
||||
return []string{"tail -n 600 /var/log/messages"}, ""
|
||||
l := hostinfo.SetOf(v, "", "").Logs
|
||||
if len(l.Commands) == 0 {
|
||||
return []string{"show logging"}, l.Ports
|
||||
}
|
||||
return []string{"show logging"}, ""
|
||||
return l.Commands, l.Ports
|
||||
}
|
||||
|
||||
// ParseNetwork liest die Ausgaben der Log-Befehle (in der Reihenfolge von
|
||||
@@ -39,6 +28,7 @@ func NetCommands(v hostinfo.Vendor) (logs []string, ports string) {
|
||||
func ParseNetwork(v hostinfo.Vendor, outs []string, ports string, hours int, now time.Time) *Report {
|
||||
r := &Report{Kind: KindNetwork, Hours: hours, At: now}
|
||||
logs, pc := NetCommands(v)
|
||||
reader := hostinfo.SetOf(v, "", "").Logs.Reader
|
||||
for _, c := range logs {
|
||||
if !strings.HasPrefix(c, "execute log filter") {
|
||||
r.Read = append(r.Read, c)
|
||||
@@ -54,7 +44,7 @@ func ParseNetwork(v hostinfo.Vendor, outs []string, ports string, hours int, now
|
||||
if strings.TrimSpace(line) == "" {
|
||||
continue
|
||||
}
|
||||
e, ok := netLine(v, line, now)
|
||||
e, ok := netLine(reader, line, now)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
@@ -74,6 +64,21 @@ func ParseNetwork(v hostinfo.Vendor, outs []string, ports string, hours int, now
|
||||
return r
|
||||
}
|
||||
|
||||
// CountLines: so viele Zeilen erkennt der Leser (für den Selbsttest).
|
||||
func CountLines(reader, out string, now time.Time) int {
|
||||
n := 0
|
||||
for _, line := range strings.Split(out, "\n") {
|
||||
line = strings.TrimRight(line, "\r ")
|
||||
if strings.TrimSpace(line) == "" {
|
||||
continue
|
||||
}
|
||||
if _, ok := netLine(reader, line, now); ok {
|
||||
n++
|
||||
}
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
var (
|
||||
reProCurve = regexp.MustCompile(`^\s*([IWMEDP])\s+(\d\d/\d\d/\d\d)\s+(\d\d:\d\d:\d\d)\s+\d+\s+([\w-]+):\s+(.*)$`)
|
||||
reCXLog = regexp.MustCompile(`^(\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d(?:\.\d+)?(?:Z|[+-]\d\d:?\d\d)?)\s+\S+\s+([^\s:\[]+)(?:\[\d+\])?:\s*(.*)$`)
|
||||
@@ -85,9 +90,9 @@ var (
|
||||
reBusybox = regexp.MustCompile(`^([A-Z][a-z]{2}\s+\d{1,2}\s+\d\d:\d\d:\d\d)\s+(?:\S+\s+)?(\w+)\.(\w+)\s+([^\s:\[]+)(?:\[\d+\])?:\s*(.*)$`)
|
||||
)
|
||||
|
||||
func netLine(v hostinfo.Vendor, line string, now time.Time) (Entry, bool) {
|
||||
switch v {
|
||||
case hostinfo.VendorProCurve:
|
||||
func netLine(reader, line string, now time.Time) (Entry, bool) {
|
||||
switch reader {
|
||||
case "procurve":
|
||||
if m := reProCurve.FindStringSubmatch(line); m != nil {
|
||||
e := Entry{Source: m[4], Msg: m[5]}
|
||||
switch m[1] {
|
||||
@@ -104,7 +109,7 @@ func netLine(v hostinfo.Vendor, line string, now time.Time) (Entry, bool) {
|
||||
return e, true
|
||||
}
|
||||
return Entry{}, false
|
||||
case hostinfo.VendorArubaCX:
|
||||
case "arubaos-cx":
|
||||
if m := reCXLog.FindStringSubmatch(line); m != nil {
|
||||
e := Entry{Time: parseISO(m[1]), Source: m[2], Msg: m[3]}
|
||||
e.Sev = sevOfWords(e.Msg)
|
||||
@@ -117,7 +122,7 @@ func netLine(v hostinfo.Vendor, line string, now time.Time) (Entry, bool) {
|
||||
return e, true
|
||||
}
|
||||
return Entry{}, false
|
||||
case hostinfo.VendorMikroTik:
|
||||
case "routeros":
|
||||
if m := reROS.FindStringSubmatch(line); m != nil && strings.Contains(m[4], ",") || m != nil && rosTopic(m[4]) {
|
||||
e := Entry{Source: m[4], Msg: m[5], Sev: SevInfo}
|
||||
switch {
|
||||
@@ -132,7 +137,7 @@ func netLine(v hostinfo.Vendor, line string, now time.Time) (Entry, bool) {
|
||||
return e, true
|
||||
}
|
||||
return Entry{}, false
|
||||
case hostinfo.VendorFortiOS:
|
||||
case "fortios":
|
||||
if !strings.Contains(line, "logid=") && !strings.Contains(line, "date=") {
|
||||
return Entry{}, false
|
||||
}
|
||||
@@ -163,7 +168,12 @@ func netLine(v hostinfo.Vendor, line string, now time.Time) (Entry, bool) {
|
||||
}
|
||||
e.Msg = strings.TrimSpace(msg)
|
||||
return e, e.Msg != ""
|
||||
case hostinfo.VendorUniFi:
|
||||
case "vrp":
|
||||
if e, ok := vrpLine(line, now); ok {
|
||||
return e, true
|
||||
}
|
||||
return Entry{}, false
|
||||
case "busybox":
|
||||
if m := reBusybox.FindStringSubmatch(line); m != nil {
|
||||
e := Entry{Time: parseBSD(m[1], now), Source: m[4], Msg: m[5]}
|
||||
e.Sev = map[string]Sev{"emerg": SevCrit, "alert": SevCrit, "crit": SevCrit, "err": SevErr, "warn": SevWarn, "warning": SevWarn}[m[3]]
|
||||
@@ -184,8 +194,11 @@ func netLine(v hostinfo.Vendor, line string, now time.Time) (Entry, bool) {
|
||||
lv, _ := strconv.Atoi(m[2])
|
||||
return Entry{Sev: sevOfSyslog(lv), Source: m[1], ID: m[1] + "-" + m[3], Msg: m[4]}, true
|
||||
}
|
||||
if e, ok := otherLine(line, now); ok {
|
||||
return e, true
|
||||
}
|
||||
if e, ok := syslogLine(line, now); ok {
|
||||
if v == hostinfo.VendorJunos {
|
||||
if reader == "junos" {
|
||||
e.Sev = max(e.Sev, junosSev(e.Msg))
|
||||
}
|
||||
return e, true
|
||||
@@ -280,42 +293,25 @@ var rePortName = regexp.MustCompile(`^(?:[A-Za-z]{1,3}\d|\d)[\d/:.]*$|^(?:Gi|Te|
|
||||
|
||||
func portLike(s string) bool { return rePortName.MatchString(s) && len(s) <= 16 }
|
||||
|
||||
// SyslogSetup: Befehle, mit denen das Gerät Syslog (ab Warnung) an ip:port
|
||||
// schickt. Leer = per CLI nicht einstellbar (UniFi: im Controller).
|
||||
// Gespeichert wird nichts außer bei Junos (commit); write memory macht der
|
||||
// Benutzer selbst.
|
||||
// SyslogAbort: Befehle, die eine abgebrochene Einrichtung verwerfen und den
|
||||
// Konfigurationsmodus verlassen (nil = nichts zu tun).
|
||||
// Konfigurationsmodus verlassen (aus dem Befehlssatz).
|
||||
func SyslogAbort(v hostinfo.Vendor) []string {
|
||||
switch v {
|
||||
case hostinfo.VendorProCurve, hostinfo.VendorArubaCX, hostinfo.VendorCisco:
|
||||
return []string{"end"}
|
||||
case hostinfo.VendorJunos:
|
||||
return []string{"rollback", "exit configuration-mode"}
|
||||
case hostinfo.VendorFortiOS:
|
||||
return []string{"abort"}
|
||||
}
|
||||
return nil
|
||||
return hostinfo.SetOf(v, "", "").SyslogAbort()
|
||||
}
|
||||
|
||||
// SyslogSetup: Befehle aus dem Befehlssatz, mit denen das Gerät Syslog an
|
||||
// ip:port schickt. Leer = per CLI nicht einstellbar (dann SyslogNote).
|
||||
// Gespeichert wird nichts außer bei Junos (commit); write memory macht der
|
||||
// Benutzer selbst.
|
||||
func SyslogSetup(v hostinfo.Vendor, ip string, port int) []string {
|
||||
p := strconv.Itoa(port)
|
||||
switch v {
|
||||
case hostinfo.VendorProCurve, hostinfo.VendorArubaCX:
|
||||
return []string{"configure terminal", "logging " + ip + " udp " + p, "end"}
|
||||
case hostinfo.VendorCisco:
|
||||
return []string{"configure terminal", "logging host " + ip + " transport udp port " + p, "logging trap warnings", "end"}
|
||||
case hostinfo.VendorJunos:
|
||||
return []string{"configure", "set system syslog host " + ip + " any warning", "set system syslog host " + ip + " port " + p, "commit and-quit"}
|
||||
case hostinfo.VendorMikroTik:
|
||||
return []string{
|
||||
"/system logging action add name=sshtermy target=remote remote=" + ip + " remote-port=" + p,
|
||||
"/system logging add topics=warning action=sshtermy",
|
||||
"/system logging add topics=error action=sshtermy",
|
||||
"/system logging add topics=critical action=sshtermy",
|
||||
}
|
||||
case hostinfo.VendorFortiOS:
|
||||
return []string{"config log syslogd setting", "set status enable", "set server " + ip, "set port " + p, "end"}
|
||||
}
|
||||
return nil
|
||||
return SyslogSetupWith(hostinfo.SetOf(v, "", ""), ip, port)
|
||||
}
|
||||
|
||||
// SyslogSetupWith wie SyslogSetup mit einem (aufgelösten) Befehlssatz.
|
||||
func SyslogSetupWith(set *cmdset.Set, ip string, port int) []string {
|
||||
out, err := cmdset.SyslogSteps(set.Syslog.Steps, ip, port)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
return out
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package logscan
|
||||
|
||||
import (
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Weitere Log-Formate für Befehlssätze ohne eigenen Leser.
|
||||
|
||||
var (
|
||||
// Comware „%Nov 10 10:21:33:518 2026 H3C SHELL/5/SHELL_LOGIN: …“ und
|
||||
// Huawei „Nov 10 2026 10:21:33 HUAWEI %%01SHELL/5/CMDRECORD(s)[3]:…“.
|
||||
reVRP = regexp.MustCompile(`^%?([A-Z][a-z]{2})\s+(\d{1,2})\s+(?:\d{4}\s+)?(\d\d:\d\d:\d\d)(?::\d+)?(?:\s+\d{4})?(?:[+-]\d\d:\d\d)?\s+\S+\s+%*(?:\d\d)?([\w-]+)/(\d)/([\w-]+)(?:\([a-z]+\))?(?:\[\d+\])?:\s*(.*)$`)
|
||||
// Cisco Small Business: „%LINK-W-Down: gi1/0/2“ (Buchstabe statt Zahl).
|
||||
reSBLog = regexp.MustCompile(`%([\w-]+?)-([EWNIACF])-([\w]+):\s*(.*)$`)
|
||||
// AireOS: „*emWeb: Nov 10 10:00:00.123: #CLI-3-LOGIN_FAILED: …“
|
||||
reAireOS = regexp.MustCompile(`#([\w-]+?)-(\d)-([\w]+):\s*(.*)$`)
|
||||
// ExtremeXOS: „11/10/2026 10:00:00.12 <Warn:AAA.authFail> Login failed …“
|
||||
reEXOS = regexp.MustCompile(`^(\d\d/\d\d/\d{4}\s+\d\d:\d\d:\d\d)(?:\.\d+)?\s+<(Crit|Erro|Warn|Noti|Info|Debu|Summ|Verb)[^:>]*:([\w.]+)>\s*(.*)$`)
|
||||
// PAN-OS: „2026/11/10 10:00:00 high general general 0 …“
|
||||
rePANLog = regexp.MustCompile(`^(\d{4}/\d\d/\d\d\s+\d\d:\d\d:\d\d)\s+(critical|high|medium|low|informational|info)\s+(\S+)\s+(\S+)\s+(.*)$`)
|
||||
)
|
||||
|
||||
func vrpLine(line string, now time.Time) (Entry, bool) {
|
||||
m := reVRP.FindStringSubmatch(strings.TrimSpace(line))
|
||||
if m == nil {
|
||||
return Entry{}, false
|
||||
}
|
||||
lv, _ := strconv.Atoi(m[5])
|
||||
e := Entry{Time: parseBSD(m[1]+" "+m[2]+" "+m[3], now), Sev: sevOfSyslog(lv), Source: m[4], ID: m[4] + "/" + m[6], Msg: m[7]}
|
||||
return e, true
|
||||
}
|
||||
|
||||
// otherLine: Formate weiterer Hersteller im allgemeinen Leser.
|
||||
func otherLine(line string, now time.Time) (Entry, bool) {
|
||||
if m := reSBLog.FindStringSubmatch(line); m != nil {
|
||||
sev := map[string]Sev{"E": SevErr, "W": SevWarn, "A": SevCrit, "C": SevCrit, "F": SevCrit}[m[2]]
|
||||
return Entry{Sev: sev, Source: m[1], ID: m[1] + "-" + m[3], Msg: m[4]}, true
|
||||
}
|
||||
if m := reAireOS.FindStringSubmatch(line); m != nil {
|
||||
lv, _ := strconv.Atoi(m[2])
|
||||
return Entry{Sev: sevOfSyslog(lv), Source: m[1], ID: m[1] + "-" + m[3], Msg: m[4]}, true
|
||||
}
|
||||
if m := reEXOS.FindStringSubmatch(line); m != nil {
|
||||
e := Entry{Source: m[3], Msg: m[4]}
|
||||
e.Sev = map[string]Sev{"Crit": SevCrit, "Erro": SevErr, "Warn": SevWarn}[m[2]]
|
||||
if t, err := time.ParseInLocation("01/02/2006 15:04:05", m[1], time.Local); err == nil {
|
||||
e.Time = t
|
||||
}
|
||||
return e, true
|
||||
}
|
||||
if m := rePANLog.FindStringSubmatch(line); m != nil {
|
||||
e := Entry{Source: m[3], Msg: m[5]}
|
||||
e.Sev = map[string]Sev{"critical": SevCrit, "high": SevErr, "medium": SevWarn}[m[2]]
|
||||
if t, err := time.ParseInLocation("2006/01/02 15:04:05", m[1], time.Local); err == nil {
|
||||
e.Time = t
|
||||
}
|
||||
return e, true
|
||||
}
|
||||
return Entry{}, false
|
||||
}
|
||||
@@ -6,8 +6,6 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/db9979/sshtermy/internal/hostinfo"
|
||||
)
|
||||
|
||||
// Logwache: einzelne Zeilen aus einem laufenden Strom (journalctl -f,
|
||||
@@ -127,11 +125,11 @@ func SyslogPacket(pkt string, now time.Time) (Entry, bool) {
|
||||
}
|
||||
// FortiOS: date=… time=… logid=… level=… msg="…"
|
||||
// Cisco: "123: *Mar 1 00:01:02: %LINK-3-UPDOWN: …"
|
||||
for _, v := range []hostinfo.Vendor{hostinfo.VendorFortiOS, hostinfo.VendorCisco} {
|
||||
if (v == hostinfo.VendorFortiOS) != strings.Contains(rest, "logid=") || (v == hostinfo.VendorCisco && !strings.Contains(rest, "%")) {
|
||||
for _, rd := range []string{"fortios", "generic"} {
|
||||
if (rd == "fortios") != strings.Contains(rest, "logid=") || (rd == "generic" && !strings.Contains(rest, "%")) {
|
||||
continue
|
||||
}
|
||||
if x, ok := netLine(v, rest, now); ok {
|
||||
if x, ok := netLine(rd, rest, now); ok {
|
||||
x.Time = now
|
||||
return x, true
|
||||
}
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
package safety
|
||||
|
||||
import "github.com/db9979/sshtermy/internal/cmdset"
|
||||
|
||||
// Befehlssätze (internal/cmdset) prüfen ihre Befehle mit ReadOnly und
|
||||
// bringen zusätzliche Gefahrenregeln mit. Die Regeln aller aktiven Sätze
|
||||
// gelten immer, egal welcher Satz zum Gerät gehört: Sie können die festen
|
||||
// Regeln hier nur ergänzen, nie abschwächen.
|
||||
|
||||
func init() { cmdset.CheckRead = ReadOnly }
|
||||
|
||||
// withSetRules hängt Treffer der Befehlssatz-Regeln an (ohne doppelte Gründe).
|
||||
func withSetRules(out []Finding, cmd string) []Finding {
|
||||
for _, f := range cmdset.CheckDanger(cmd) {
|
||||
dup := false
|
||||
for _, o := range out {
|
||||
if o.Reason == f.Reason {
|
||||
dup = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !dup {
|
||||
out = append(out, Finding{f.Reason})
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
@@ -135,7 +135,7 @@ func Check(cmd, kind string) []Finding {
|
||||
}
|
||||
}
|
||||
}
|
||||
return out
|
||||
return withSetRules(out, cmd)
|
||||
}
|
||||
|
||||
// Network ist die Regelgruppe für Switches und Router.
|
||||
|
||||
@@ -3,6 +3,8 @@ package safety
|
||||
import (
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/db9979/sshtermy/internal/cmdset"
|
||||
)
|
||||
|
||||
// ReadOnly: ändert der Befehl sicher nichts am System? Der Agent-Modus führt
|
||||
@@ -13,6 +15,9 @@ func ReadOnly(cmd, kind string) bool {
|
||||
if cmd == "" {
|
||||
return false
|
||||
}
|
||||
if cmdset.BuiltinRead(cmd) {
|
||||
return true // ganze Zeile steht auf der Leseliste eines eingebauten Befehlssatzes
|
||||
}
|
||||
switch kind {
|
||||
case Network:
|
||||
return netReadOnly(cmd)
|
||||
|
||||
@@ -636,7 +636,7 @@ func (c *Client) probe() (prof domain.SystemProfile, locale, refused string) {
|
||||
}
|
||||
defer s.Close()
|
||||
done := make(chan []byte, 1)
|
||||
go func() { out, _ := s.Output(sysprof.ProbeCommand); done <- out }()
|
||||
go func() { out, _ := s.Output(sysprof.Probe()); done <- out }()
|
||||
select {
|
||||
case out := <-done:
|
||||
if msg := sysprof.ProbeRejected(string(out)); msg != "" {
|
||||
|
||||
@@ -83,6 +83,7 @@ func TestSettingsSyncNerdNeedsProbe(t *testing.T) {
|
||||
var localSettings = map[string]bool{
|
||||
"UseDPAPI": true, "NoMouse": true, "LastVersion": true, "NerdFont": true,
|
||||
"LastLayout": true, "Editor": true, "Schedules": true, "Debug": true, "Audit": true, "MCP": true, "SyslogPort": true,
|
||||
"CmdSetApproved": true,
|
||||
}
|
||||
|
||||
func TestSettingsFieldsClassified(t *testing.T) {
|
||||
|
||||
+71
-29
@@ -18,6 +18,7 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/db9979/sshtermy/internal/cmdset"
|
||||
"github.com/db9979/sshtermy/internal/domain"
|
||||
)
|
||||
|
||||
@@ -27,22 +28,16 @@ func FromBanner(banner string) domain.SystemProfile {
|
||||
p := domain.SystemProfile{Banner: strings.TrimSpace(banner)}
|
||||
l := strings.ToLower(banner)
|
||||
set := func(fam, os, dia string) { p.Family, p.OS, p.Dialect = fam, os, dia }
|
||||
switch {
|
||||
case strings.Contains(l, "openssh_for_windows"):
|
||||
if strings.Contains(l, "openssh_for_windows") {
|
||||
set(domain.FamilyWindows, "Windows (OpenSSH)", "")
|
||||
case strings.Contains(l, "rosssh") || strings.Contains(l, "mikrotik"):
|
||||
set(domain.FamilyNetwork, "MikroTik RouterOS", "routeros")
|
||||
case strings.Contains(l, "mocana") || strings.Contains(l, "procurve"):
|
||||
// HPE/Aruba ProCurve (ArubaOS-Switch) meldet sich mit Mocana SSH.
|
||||
set(domain.FamilyNetwork, "ArubaOS-Switch (ProCurve)", "procurve")
|
||||
case strings.Contains(l, "cisco"):
|
||||
set(domain.FamilyNetwork, "Cisco IOS", "cisco-ios")
|
||||
case strings.Contains(l, "huawei"):
|
||||
set(domain.FamilyNetwork, "Huawei VRP", "huawei-vrp")
|
||||
case strings.Contains(l, "comware") || strings.Contains(l, "h3c"):
|
||||
set(domain.FamilyNetwork, "HPE Comware", "comware")
|
||||
case strings.Contains(l, "fortissh"):
|
||||
set(domain.FamilyNetwork, "FortiOS", "fortios")
|
||||
return p
|
||||
}
|
||||
// Netzwerkgeräte: Merkmale aus den Befehlssätzen
|
||||
if s := cmdset.DetectBanner(banner); s != nil {
|
||||
set(s.EffFamily(), s.Name, s.ID)
|
||||
return p
|
||||
}
|
||||
switch {
|
||||
case strings.Contains(l, "ubuntu"):
|
||||
set(domain.FamilyLinux, "Ubuntu", "posix")
|
||||
case strings.Contains(l, "debian"):
|
||||
@@ -93,9 +88,41 @@ func FromProbe(out string) domain.SystemProfile {
|
||||
p.OS = firstWord(p.Version)
|
||||
}
|
||||
p.Init = initName(p.Init)
|
||||
// Zeile 8: Merkmal-Datei eines Server-Befehlssatzes (Proxmox, ESXi, …)
|
||||
if id := probeSet(get(7)); id != "" {
|
||||
p.Dialect = id
|
||||
}
|
||||
return p
|
||||
}
|
||||
|
||||
// probeSet: Kennung des Befehlssatzes zur gefundenen Merkmal-Datei.
|
||||
func probeSet(path string) string {
|
||||
if path == "" {
|
||||
return ""
|
||||
}
|
||||
for _, pp := range cmdset.ProbePaths() {
|
||||
if pp[0] == path {
|
||||
return pp[1]
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// Probe: ProbeCommand plus Zeile 8, die erste vorhandene Merkmal-Datei der
|
||||
// Server-Befehlssätze (nur Pfade, die cmdset geprüft hat: keine Leer- oder
|
||||
// Sonderzeichen, die das Skript verändern könnten).
|
||||
func Probe() string {
|
||||
var paths []string
|
||||
for _, pp := range cmdset.ProbePaths() {
|
||||
paths = append(paths, pp[0])
|
||||
}
|
||||
if len(paths) == 0 {
|
||||
return ProbeCommand
|
||||
}
|
||||
loop := `; m=; for f in ` + strings.Join(paths, " ") + `; do if [ -e "$f" ]; then m=$f; break; fi; done; echo "$m"'`
|
||||
return strings.TrimSuffix(ProbeCommand, "'") + loop
|
||||
}
|
||||
|
||||
// probeLines: so viele Zeilen hat die Ausgabe von ProbeCommand mindestens
|
||||
// (fünf Angaben, jede mit Zeilenende).
|
||||
const probeLines = 5
|
||||
@@ -182,16 +209,6 @@ type screenRule struct {
|
||||
// sicher erkennt (Login-Banner, „show version“, typische Prompts). Reihenfolge
|
||||
// zählt: Spezifisches zuerst.
|
||||
var screenRules = []screenRule{
|
||||
{regexp.MustCompile(`(?i)arubaos-cx|\baos-cx\b`), domain.FamilyNetwork, "ArubaOS-CX", "arubaos-cx"},
|
||||
{regexp.MustCompile(`(?i)arubaos-switch|procurve|image stamp:|\bsoftware revision\s+:?\s*[A-Z]{1,2}\.\d{2}\.`), domain.FamilyNetwork, "ArubaOS-Switch (ProCurve)", "procurve"},
|
||||
{regexp.MustCompile(`(?i)cisco nexus|\bNX-OS\b`), domain.FamilyNetwork, "Cisco NX-OS", "cisco-ios"},
|
||||
{regexp.MustCompile(`(?i)cisco ios|cisco internetwork operating system|IOS-XE`), domain.FamilyNetwork, "Cisco IOS", "cisco-ios"},
|
||||
{regexp.MustCompile(`(?i)\bjunos\b`), domain.FamilyNetwork, "Juniper Junos", "junos"},
|
||||
{regexp.MustCompile(`(?i)mikrotik routeros|\[[\w.-]+@[\w.-]+\] >`), domain.FamilyNetwork, "MikroTik RouterOS", "routeros"},
|
||||
{regexp.MustCompile(`(?i)huawei versatile routing platform`), domain.FamilyNetwork, "Huawei VRP", "huawei-vrp"},
|
||||
{regexp.MustCompile(`(?i)comware`), domain.FamilyNetwork, "HPE Comware", "comware"},
|
||||
{regexp.MustCompile(`(?i)fortigate|fortios`), domain.FamilyNetwork, "FortiOS", "fortios"},
|
||||
{regexp.MustCompile(`(?im)welcome to unifi\s+us[^g\s!]|^\(UBNT\)\s*[>#]|^\s*model:\s+us[^g\s!][\w-]*\s*$`), domain.FamilyNetwork, unifiName, "unifi"},
|
||||
{regexp.MustCompile(`(?m)^PS [A-Z]:\\[^>]*> ?$`), domain.FamilyWindows, "", "powershell"},
|
||||
{regexp.MustCompile(`(?m)^[A-Z]:\\[^>]*> ?$`), domain.FamilyWindows, "", "cmd"},
|
||||
}
|
||||
@@ -212,10 +229,14 @@ var (
|
||||
// wird nur, was eindeutig ist; sonst bleibt das Ergebnis leer.
|
||||
func FromScreen(text string) domain.SystemProfile {
|
||||
var p domain.SystemProfile
|
||||
for _, r := range screenRules {
|
||||
if r.rx.MatchString(text) {
|
||||
p.Family, p.OS, p.Dialect = r.family, r.os, r.dialect
|
||||
break
|
||||
if set := cmdset.DetectScreen(text); set != nil {
|
||||
p.Family, p.OS, p.Dialect = set.EffFamily(), set.Name, set.ID
|
||||
} else {
|
||||
for _, r := range screenRules {
|
||||
if r.rx.MatchString(text) {
|
||||
p.Family, p.OS, p.Dialect = r.family, r.os, r.dialect
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
sub := func(rx *regexp.Regexp) string {
|
||||
@@ -239,10 +260,31 @@ func FromScreen(text string) domain.SystemProfile {
|
||||
p.Version, p.Model = sub(rxUniFiVersion), sub(rxUniFiModel)
|
||||
case "powershell", "cmd":
|
||||
p.OS = "Windows"
|
||||
default:
|
||||
// andere Befehlssätze: Muster für Firmware und Modell aus der Datei
|
||||
if set := cmdset.Resolve(p.Dialect, "", ""); set != nil {
|
||||
if rx := compileOr(set.Parse.Firmware); rx != nil {
|
||||
p.Version = sub(rx)
|
||||
}
|
||||
if rx := compileOr(set.Parse.Model); rx != nil {
|
||||
p.Model = sub(rx)
|
||||
}
|
||||
}
|
||||
}
|
||||
return p
|
||||
}
|
||||
|
||||
func compileOr(p string) *regexp.Regexp {
|
||||
if p == "" {
|
||||
return nil
|
||||
}
|
||||
rx, err := regexp.Compile(p)
|
||||
if err != nil || rx.NumSubexp() == 0 {
|
||||
return nil
|
||||
}
|
||||
return rx
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- Ablehnung
|
||||
|
||||
// rejections: Fehlermeldungen, mit denen ein System einen Befehl ablehnt, den
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
package team
|
||||
|
||||
import (
|
||||
"sort"
|
||||
|
||||
"github.com/db9979/sshtermy/internal/cmdset"
|
||||
"github.com/db9979/sshtermy/internal/domain"
|
||||
)
|
||||
|
||||
// CmdSet: eigener Befehlssatz im Paket (YAML wie in der Datei). Beim
|
||||
// Empfänger landet er unter befehlssaetze/team und wirkt erst nach Freigabe.
|
||||
type CmdSet struct {
|
||||
ID string `json:"id"`
|
||||
YAML string `json:"yaml"`
|
||||
}
|
||||
|
||||
// cmdSetsFor: eigene Sätze, die die geteilten Verbindungen benutzen (samt
|
||||
// ihrer eigenen Grundlagen). Eingebaute hat der Empfänger selbst.
|
||||
func cmdSetsFor(conns []domain.Connection) []CmdSet {
|
||||
need := map[string]bool{}
|
||||
for _, c := range conns {
|
||||
if c.Profile != nil && c.Profile.Dialect != "" {
|
||||
need[c.Profile.Dialect] = true
|
||||
}
|
||||
}
|
||||
ids := make([]string, 0, len(need))
|
||||
for id := range need {
|
||||
ids = append(ids, id)
|
||||
}
|
||||
sort.Strings(ids)
|
||||
var out []CmdSet
|
||||
seen := map[string]bool{}
|
||||
var add func(id string, depth int)
|
||||
add = func(id string, depth int) {
|
||||
s, ok := cmdset.Lookup(id)
|
||||
if !ok || seen[id] || depth > 4 || s.Source != cmdset.Own || len(s.Raw) == 0 {
|
||||
return
|
||||
}
|
||||
seen[id] = true
|
||||
out = append(out, CmdSet{ID: s.ID, YAML: string(s.Raw)})
|
||||
if s.Base != "" {
|
||||
add(s.Base, depth+1)
|
||||
}
|
||||
}
|
||||
for _, id := range ids {
|
||||
add(id, 0)
|
||||
}
|
||||
return out
|
||||
}
|
||||
@@ -54,6 +54,7 @@ type Package struct {
|
||||
Connections []domain.Connection `json:"connections"`
|
||||
Tunnels []domain.Tunnel `json:"tunnels,omitempty"`
|
||||
Runbooks []domain.Runbook `json:"runbooks,omitempty"`
|
||||
CmdSets []CmdSet `json:"cmdsets,omitempty"` // eigene Befehlssätze der Verbindungen
|
||||
}
|
||||
|
||||
type header struct {
|
||||
@@ -190,6 +191,7 @@ func Build(d *domain.Data, ids []string, from string, o Options, now time.Time)
|
||||
}
|
||||
}
|
||||
}
|
||||
p.CmdSets = cmdSetsFor(p.Connections)
|
||||
sort.Strings(jumps)
|
||||
return p, jumps
|
||||
}
|
||||
|
||||
+13
-3
@@ -75,6 +75,8 @@ const (
|
||||
scrScheduleForm // Zeitplan (schedule.go)
|
||||
scrRulesForm // Regeln für Switch-Configs (configrules.go)
|
||||
scrLogScan // Log-Blick (logscan.go)
|
||||
scrCmdSets // Befehlssätze (cmdsets.go)
|
||||
scrCmdSetForm // eigener Befehlssatz bearbeiten
|
||||
)
|
||||
|
||||
// App ist das Wurzel-Modell.
|
||||
@@ -84,6 +86,7 @@ type App struct {
|
||||
asyncModals []*modal
|
||||
|
||||
lscan logScanState // Log-Blick (logscan.go)
|
||||
cmds cmdsetState // Befehlssätze (cmdsets.go)
|
||||
lwatch logWatchState // Logwache + Syslog-Empfang (logwatch.go)
|
||||
lfold folderScanState // Ordner-Scan (logfolder.go)
|
||||
compUse companionUsage // Begleiter: Anfragen, Tokens (companion.go)
|
||||
@@ -530,6 +533,9 @@ func (a *App) update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
if cmd, ok := a.reportMsg(msg); ok {
|
||||
return a, cmd
|
||||
}
|
||||
if cmd, ok := a.cmdsetMsg(msg); ok {
|
||||
return a, cmd
|
||||
}
|
||||
if cmd, ok := a.logsMsg(msg); ok {
|
||||
return a, cmd
|
||||
}
|
||||
@@ -593,7 +599,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 == scrFolderForm || a.scr == scrHighlightForm || a.scr == scrScheduleForm || a.scr == scrRulesForm || a.scr == scrKeyForm || a.scr == scrSSHKeyForm || a.scr == scrRelayForm || a.scr == scrMasterForm || a.scr == scrBackupForm) {
|
||||
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 == scrFolderForm || a.scr == scrHighlightForm || a.scr == scrScheduleForm || a.scr == scrRulesForm || a.scr == scrCmdSetForm || a.scr == scrKeyForm || a.scr == scrSSHKeyForm || a.scr == scrRelayForm || a.scr == scrMasterForm || a.scr == scrBackupForm) {
|
||||
a.modal = a.helpModal()
|
||||
return a, nil
|
||||
}
|
||||
@@ -634,7 +640,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, scrFolderForm, scrHighlightForm, scrScheduleForm, scrRulesForm, scrKeyForm, scrSSHKeyForm, scrRelayForm, scrMasterForm, scrBackupForm:
|
||||
case scrConnForm, scrSettings, scrTunnelForm, scrQuickForm, scrMonitorForm, scrFolderForm, scrHighlightForm, scrScheduleForm, scrRulesForm, scrCmdSetForm, scrKeyForm, scrSSHKeyForm, scrRelayForm, scrMasterForm, scrBackupForm:
|
||||
return a, a.updateForm(msg)
|
||||
case scrTerminal:
|
||||
return a, a.updateTerminal(msg)
|
||||
@@ -644,6 +650,8 @@ func (a *App) update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
return a, a.updateLogs(msg)
|
||||
case scrLogScan:
|
||||
return a, a.updateLogScan(msg)
|
||||
case scrCmdSets:
|
||||
return a, a.updateCmdSets(msg)
|
||||
case scrImport:
|
||||
return a, a.updateImport(msg)
|
||||
case scrTeam:
|
||||
@@ -771,7 +779,7 @@ func (a *App) viewFrame() tea.View {
|
||||
body = a.frame(a.viewForm(), append(k, [2]string{"Esc", i18n.T("abbrechen")}))
|
||||
case scrConnForm:
|
||||
body = a.frame(a.viewForm(), [][2]string{{"Tab", i18n.T("weiter")}, {"←/→", i18n.T("wählen")}, {"Strg+T", i18n.T("testen")}, {"Strg+S", i18n.T("speichern")}, {"Esc", i18n.T("abbrechen")}})
|
||||
case scrKeyForm, scrSSHKeyForm, scrRelayForm, scrMasterForm, scrBackupForm, scrMonitorForm, scrFolderForm, scrHighlightForm, scrScheduleForm, scrRulesForm:
|
||||
case scrKeyForm, scrSSHKeyForm, scrRelayForm, scrMasterForm, scrBackupForm, scrMonitorForm, scrFolderForm, scrHighlightForm, scrScheduleForm, scrRulesForm, scrCmdSetForm:
|
||||
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")}})
|
||||
@@ -785,6 +793,8 @@ func (a *App) viewFrame() tea.View {
|
||||
body = a.frame(a.viewLogs(), a.logsKeys())
|
||||
case scrLogScan:
|
||||
body = a.frame(a.viewLogScan(), a.logScanKeys())
|
||||
case scrCmdSets:
|
||||
body = a.frame(a.viewCmdSets(), a.cmdSetsKeys())
|
||||
case scrImport:
|
||||
body = a.frame(a.viewImport(), a.importKeys())
|
||||
case scrTeam:
|
||||
|
||||
@@ -0,0 +1,991 @@
|
||||
package ui
|
||||
|
||||
// Befehlssätze (Einstellungen › Befehlssätze)
|
||||
//
|
||||
// Liste aller Befehlssätze: eingebaute, eigene (Konfigordner/befehlssaetze)
|
||||
// und Team-Sätze (…/befehlssaetze/team, erst nach Freigabe aktiv). Eigene
|
||||
// Sätze legt man über das Formular an (n, meist „basiert auf“ einem
|
||||
// eingebauten), bearbeitet sie dort oder in der Datei (o), testet sie am
|
||||
// offenen Gerät (t), lässt die KI einen Entwurf schreiben (k) oder übernimmt
|
||||
// die Korrekturen eines Geräts (l). Export/Import als .yaml (x/i).
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"image/color"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
tea "charm.land/bubbletea/v2"
|
||||
"charm.land/lipgloss/v2"
|
||||
|
||||
"github.com/db9979/sshtermy/internal/cmdset"
|
||||
"github.com/db9979/sshtermy/internal/cmdsetcheck"
|
||||
"github.com/db9979/sshtermy/internal/domain"
|
||||
"github.com/db9979/sshtermy/internal/hostinfo"
|
||||
"github.com/db9979/sshtermy/internal/i18n"
|
||||
"github.com/db9979/sshtermy/internal/sysprof"
|
||||
"github.com/db9979/sshtermy/internal/team"
|
||||
)
|
||||
|
||||
type cmdsetState struct {
|
||||
sel int
|
||||
err string
|
||||
back screen
|
||||
edit *cmdset.Set // im Formular: Ausgangssatz (eigener Satz oder Grundlage)
|
||||
own bool // edit ist ein eigener Satz (überschreiben statt neu)
|
||||
}
|
||||
|
||||
type cmdsetTestMsg struct {
|
||||
sid int
|
||||
title string
|
||||
lines []string
|
||||
}
|
||||
|
||||
type cmdsetDraftMsg struct {
|
||||
sid int
|
||||
yaml string
|
||||
err error
|
||||
}
|
||||
|
||||
func (a *App) cmdsetDir() string { return filepath.Join(a.st.Dir, cmdset.DirName) }
|
||||
|
||||
// loadCmdSets liest eigene und Team-Sätze und nimmt sie in Betrieb.
|
||||
func (a *App) loadCmdSets() {
|
||||
cmdset.Install(cmdset.ReadDir(a.cmdsetDir()), a.st.Settings().CmdSetApproved, nil)
|
||||
cmdset.RunSelfTests(cmdsetcheck.SelfTest)
|
||||
}
|
||||
|
||||
// cmdsetSource: Herkunft für die Anzeige.
|
||||
func cmdsetSource(s *cmdset.Set) string {
|
||||
switch s.Source {
|
||||
case cmdset.Own:
|
||||
return i18n.T("eigen")
|
||||
case cmdset.Team:
|
||||
if s.From != "" {
|
||||
return i18n.T("Team: ") + s.From
|
||||
}
|
||||
return i18n.T("Team")
|
||||
}
|
||||
return i18n.T("eingebaut")
|
||||
}
|
||||
|
||||
func (a *App) cmdsetHint() string {
|
||||
own, pend := 0, 0
|
||||
for _, st := range cmdset.Statuses() {
|
||||
if st.Set.Source != cmdset.Builtin {
|
||||
own++
|
||||
}
|
||||
if st.Pending {
|
||||
pend++
|
||||
}
|
||||
}
|
||||
h := fmt.Sprintf(i18n.T("%d eingebaut"), len(cmdset.Builtins()))
|
||||
if own > 0 {
|
||||
h += fmt.Sprintf(i18n.T(" · %d eigene"), own)
|
||||
}
|
||||
if pend > 0 {
|
||||
h += fmt.Sprintf(i18n.T(" · %d warten"), pend)
|
||||
}
|
||||
return h
|
||||
}
|
||||
|
||||
func (a *App) openCmdSets() tea.Cmd {
|
||||
a.loadCmdSets()
|
||||
c := &a.cmds
|
||||
c.err = ""
|
||||
if a.scr != scrCmdSets {
|
||||
c.back = a.scr
|
||||
}
|
||||
a.scr = scrCmdSets
|
||||
return nil
|
||||
}
|
||||
|
||||
// cmdsetRows: eigene und Team-Sätze zuerst, dann die eingebauten.
|
||||
func cmdsetRows() []cmdset.Status {
|
||||
all := cmdset.Statuses()
|
||||
sort.SliceStable(all, func(i, j int) bool {
|
||||
bi, bj := all[i].Set.Source == cmdset.Builtin, all[j].Set.Source == cmdset.Builtin
|
||||
if bi != bj {
|
||||
return !bi
|
||||
}
|
||||
if bi {
|
||||
return false
|
||||
}
|
||||
return all[i].Set.ID < all[j].Set.ID
|
||||
})
|
||||
return all
|
||||
}
|
||||
|
||||
func (a *App) cmdsetSelected() (cmdset.Status, bool) {
|
||||
rows := cmdsetRows()
|
||||
if a.cmds.sel < 0 || a.cmds.sel >= len(rows) {
|
||||
return cmdset.Status{}, false
|
||||
}
|
||||
return rows[a.cmds.sel], true
|
||||
}
|
||||
|
||||
func (a *App) cmdSetsKeys() [][2]string {
|
||||
k := [][2]string{{"⏎", i18n.T("Details")}, {"n", i18n.T("neu")}}
|
||||
if st, ok := a.cmdsetSelected(); ok && st.Set.Source != cmdset.Builtin {
|
||||
k = append(k, [2]string{"e", i18n.T("bearbeiten")}, [2]string{"o", i18n.T("Datei")}, [2]string{"Entf", i18n.T("löschen")})
|
||||
if st.Pending {
|
||||
k = append(k, [2]string{"f", i18n.T("freigeben")})
|
||||
}
|
||||
}
|
||||
return append(k, [2]string{"t", i18n.T("am Gerät testen")}, [2]string{"k", i18n.T("KI-Entwurf")}, [2]string{"l", i18n.T("Korrekturen")},
|
||||
[2]string{"x", i18n.T("export")}, [2]string{"i", i18n.T("import")}, [2]string{"Esc", i18n.T("zurück")})
|
||||
}
|
||||
|
||||
func (a *App) cmdsetBack() {
|
||||
a.scr = a.cmds.back
|
||||
if a.scr == scrCmdSets || a.scr == scrCmdSetForm {
|
||||
a.scr = scrManager
|
||||
}
|
||||
}
|
||||
|
||||
func (a *App) updateCmdSets(msg tea.Msg) tea.Cmd {
|
||||
c := &a.cmds
|
||||
k, ok := msg.(tea.KeyPressMsg)
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
rows := cmdsetRows()
|
||||
c.err = ""
|
||||
st, have := a.cmdsetSelected()
|
||||
switch k.String() {
|
||||
case "esc", "q":
|
||||
a.cmdsetBack()
|
||||
case "up", "k":
|
||||
if k.String() == "k" {
|
||||
return a.cmdsetDraft()
|
||||
}
|
||||
c.sel = max(0, c.sel-1)
|
||||
case "down", "j":
|
||||
c.sel = min(len(rows)-1, c.sel+1)
|
||||
case "pgup":
|
||||
c.sel = max(0, c.sel-10)
|
||||
case "pgdown":
|
||||
c.sel = min(len(rows)-1, c.sel+10)
|
||||
case "home":
|
||||
c.sel = 0
|
||||
case "end":
|
||||
c.sel = len(rows) - 1
|
||||
case "enter":
|
||||
if have {
|
||||
a.modal = textModal(st.Set.Name, a.cmdsetDetails(st))
|
||||
}
|
||||
case "n":
|
||||
if have {
|
||||
return a.openCmdSetForm(st.Set, false)
|
||||
}
|
||||
case "e":
|
||||
if have && st.Set.Source != cmdset.Builtin {
|
||||
return a.openCmdSetForm(st.Set, true)
|
||||
}
|
||||
if have {
|
||||
return a.openCmdSetForm(st.Set, false) // eingebaut: Kopie mit Grundlage
|
||||
}
|
||||
case "o":
|
||||
if have && st.Set.File != "" {
|
||||
return a.launchEditor(st.Set.File)
|
||||
}
|
||||
case "f":
|
||||
if have && st.Pending {
|
||||
a.askApproveCmdSet(st.Set)
|
||||
}
|
||||
case "delete", "backspace", "ctrl+d":
|
||||
if have && st.Set.File != "" {
|
||||
a.askDeleteCmdSet(st.Set)
|
||||
}
|
||||
case "t":
|
||||
if have {
|
||||
return a.cmdsetTest(st.Set)
|
||||
}
|
||||
case "l":
|
||||
return a.cmdsetFromLearned()
|
||||
case "x":
|
||||
if have {
|
||||
a.exportCmdSet(st.Set)
|
||||
}
|
||||
case "i":
|
||||
a.modal = inputModal(i18n.T("Befehlssatz importieren"), i18n.T("Pfad zur .yaml-Datei:"), filepath.Join(exportDir(), ""), func(p string) tea.Cmd {
|
||||
if err := a.importCmdSet(expandHome(strings.TrimSpace(p))); err != nil {
|
||||
a.cmds.err = err.Error()
|
||||
}
|
||||
return nil
|
||||
})
|
||||
case "r":
|
||||
a.loadCmdSets()
|
||||
a.flash(i18n.T("Befehlssätze neu geladen"))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *App) viewCmdSets() string {
|
||||
s := a.s
|
||||
c := &a.cmds
|
||||
w := min(120, a.w-2)
|
||||
var b strings.Builder
|
||||
b.WriteString(s.Accent.Render(i18n.T(" ▤ Befehlssätze")) + s.Muted.Render(i18n.T(" · was sshTermy je Hersteller tippt, liest und der KI sagt")) + "\n\n")
|
||||
b.WriteString(s.Muted.Render(" "+trunc(i18n.T("Eigene Sätze liegen in ")+a.cmdsetDir()+".", w-1)) + "\n")
|
||||
b.WriteString(s.Muted.Render(wrap(" "+strings.TrimPrefix(i18n.T(". Sie können eingebaute Gefahrenregeln nur ergänzen, tippen nur Lesebefehle und erkennen ein Gerät erst, wenn kein eingebauter Satz passt."), ". "), w)) + "\n\n")
|
||||
if c.err != "" {
|
||||
b.WriteString(" " + s.Danger.Render(wrap(c.err, w-2)) + "\n\n")
|
||||
}
|
||||
rows := cmdsetRows()
|
||||
errs := cmdset.Errors()
|
||||
head := lipgloss.Height(b.String())
|
||||
avail := max(3, a.h-2-head-3-min(len(errs), 4))
|
||||
start := 0
|
||||
if c.sel >= avail {
|
||||
start = c.sel - avail + 1
|
||||
}
|
||||
for i := start; i < len(rows) && i < start+avail; i++ {
|
||||
st := rows[i]
|
||||
mark := " "
|
||||
name := fmt.Sprintf("%-34s", trunc(st.Set.DisplayName(), 34))
|
||||
id := fmt.Sprintf("%-16s", trunc(st.Set.ID, 16))
|
||||
src := fmt.Sprintf("%-16s", trunc(cmdsetSource(st.Set), 16))
|
||||
state := s.OK.Render(i18n.T("aktiv"))
|
||||
switch {
|
||||
case st.Pending:
|
||||
state = s.Warn.Render(st.Problem)
|
||||
case !st.Active:
|
||||
state = s.Danger.Render(trunc(firstLine(st.Problem), max(10, w-74)))
|
||||
case st.Problem != "":
|
||||
state = s.Warn.Render(trunc(firstLine(st.Problem), max(10, w-74)))
|
||||
}
|
||||
line := name + " " + s.Muted.Render(id) + " " + s.Muted.Render(src) + " "
|
||||
if i == c.sel {
|
||||
mark = s.Accent.Render("▸ ")
|
||||
line = s.Selected.Render(name) + " " + s.Muted.Render(id) + " " + s.Muted.Render(src) + " "
|
||||
} else {
|
||||
line = s.Text.Render(name) + " " + s.Muted.Render(id) + " " + s.Muted.Render(src) + " "
|
||||
}
|
||||
i := i
|
||||
b.WriteString(a.z.click(" "+mark+line+state, func(_ tea.Mouse, double bool) tea.Cmd {
|
||||
c.sel = i
|
||||
if double {
|
||||
a.modal = textModal(rows[i].Set.Name, a.cmdsetDetails(rows[i]))
|
||||
}
|
||||
return nil
|
||||
}) + "\n")
|
||||
}
|
||||
for i, e := range errs {
|
||||
if i >= 4 {
|
||||
break
|
||||
}
|
||||
b.WriteString(" " + s.Danger.Render(trunc("× "+filepath.Base(e.File)+": "+firstLine(e.Err), w-2)) + "\n")
|
||||
}
|
||||
return b.String()
|
||||
}
|
||||
|
||||
func firstLine(s string) string {
|
||||
l, _, _ := strings.Cut(s, "\n")
|
||||
return l
|
||||
}
|
||||
|
||||
// cmdsetDetails: alles Wichtige eines Satzes zum Lesen.
|
||||
func (a *App) cmdsetDetails(st cmdset.Status) []string {
|
||||
s := st.Set
|
||||
eff := cmdset.Resolve(s.ID, "", "")
|
||||
if eff == nil {
|
||||
eff = s
|
||||
}
|
||||
var out []string
|
||||
add := func(k, v string) {
|
||||
if strings.TrimSpace(v) != "" {
|
||||
out = append(out, fmt.Sprintf("%-14s %s", k, v))
|
||||
}
|
||||
}
|
||||
add(i18n.T("Kennung"), s.ID)
|
||||
add(i18n.T("Herkunft"), cmdsetSource(s))
|
||||
add(i18n.T("Familie"), eff.EffFamily())
|
||||
add(i18n.T("Grundlage"), s.Base)
|
||||
if s.File != "" {
|
||||
add(i18n.T("Datei"), s.File)
|
||||
}
|
||||
if st.Problem != "" {
|
||||
out = append(out, "", a.s.Warn.Render("! "+st.Problem))
|
||||
}
|
||||
out = append(out, "", a.s.Accent.Render(i18n.T("Erkennung")))
|
||||
add(i18n.T("SSH-Kennung"), strings.Join(s.Detect.Banner, " || "))
|
||||
add(i18n.T("Bildschirm"), strings.Join(s.Detect.Screen, " || "))
|
||||
add(i18n.T("Version"), strings.Join(s.Detect.Version, " || "))
|
||||
add(i18n.T("Datei da"), strings.Join(s.Detect.Probe, " || "))
|
||||
out = append(out, "", a.s.Accent.Render(i18n.T("Befehle (nur lesend)")))
|
||||
cm := eff.Commands
|
||||
add(i18n.T("Blättern aus"), cm.PagingOff)
|
||||
add(i18n.T("Version"), cm.Version)
|
||||
add(i18n.T("System"), cm.System)
|
||||
add(i18n.T("Speicher"), cm.Memory)
|
||||
add("Ports", cm.Ports)
|
||||
add("VLANs", cm.VLANs)
|
||||
add(i18n.T("Konfiguration"), cm.Config)
|
||||
for _, e := range cm.Extra {
|
||||
add(hostinfo.ExtraLabel(e), e.Cmd)
|
||||
}
|
||||
add(i18n.T("Logs"), strings.Join(eff.Logs.Commands, " || "))
|
||||
out = append(out, "", a.s.Accent.Render(i18n.T("Syslog einrichten (ändert das Gerät)")))
|
||||
for _, x := range eff.Syslog.Steps {
|
||||
out = append(out, " "+x)
|
||||
}
|
||||
if eff.Syslog.Note != "" {
|
||||
out = append(out, " "+eff.Syslog.Note)
|
||||
}
|
||||
add(i18n.T("Speichern"), eff.Syslog.Save)
|
||||
if len(s.Variants) > 0 {
|
||||
out = append(out, "", a.s.Accent.Render(i18n.T("Varianten")))
|
||||
for _, v := range s.Variants {
|
||||
cond := strings.TrimSpace(strings.Join([]string{v.Model, v.Firmware}, " "))
|
||||
out = append(out, " "+v.Name+a.s.Muted.Render(" ("+cond+")"))
|
||||
}
|
||||
}
|
||||
if len(eff.Danger) > 0 {
|
||||
out = append(out, "", a.s.Accent.Render(i18n.T("Zusätzliche Gefahrenregeln (gelten für alle Geräte)")))
|
||||
for _, d := range eff.Danger {
|
||||
out = append(out, " "+d.Reason+a.s.Muted.Render(" "+d.Rx))
|
||||
}
|
||||
}
|
||||
if eff.Hint != "" {
|
||||
out = append(out, "", a.s.Accent.Render(i18n.T("Hinweis für die KI")), wrap(eff.Hint, min(100, a.w-8)))
|
||||
}
|
||||
if len(s.Samples) > 0 {
|
||||
out = append(out, "", a.s.Muted.Render(fmt.Sprintf(i18n.T("%d Beispiele für den Selbsttest"), len(s.Samples))))
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- Formular
|
||||
|
||||
const cmdsetSep = "||"
|
||||
|
||||
func joinList(l []string) string { return strings.Join(l, " "+cmdsetSep+" ") }
|
||||
|
||||
func splitList(s string) []string {
|
||||
var out []string
|
||||
for _, p := range strings.Split(s, cmdsetSep) {
|
||||
if p = strings.TrimSpace(p); p != "" {
|
||||
out = append(out, p)
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// openCmdSetForm: own = vorhandenen eigenen Satz bearbeiten, sonst neuer
|
||||
// Satz, der auf from aufbaut (eingebaut) bzw. eine Kopie davon ist.
|
||||
func (a *App) openCmdSetForm(from *cmdset.Set, own bool) tea.Cmd {
|
||||
c := &a.cmds
|
||||
c.edit, c.own = from, own
|
||||
f := &form{title: i18n.T("Befehlssatz")}
|
||||
var s cmdset.Set
|
||||
if own {
|
||||
s = *from
|
||||
} else {
|
||||
s = cmdset.Set{ID: from.ID + "-eigen", Name: from.Name + i18n.T(" (eigen)"), Base: from.ID}
|
||||
if from.Source != cmdset.Builtin {
|
||||
s = *from
|
||||
s.ID, s.Name, s.File = from.ID+"-kopie", from.Name+i18n.T(" (Kopie)"), ""
|
||||
}
|
||||
}
|
||||
accent := func(t Theme) color.Color { return t.Accent }
|
||||
f.section("s_main", i18n.T("Befehlssatz"), accent)
|
||||
f.text("id", i18n.T("Kennung"), s.ID, i18n.T("a–z, 0–9 und -, eindeutig; eingebaute Kennungen sind vergeben"))
|
||||
f.text("name", i18n.T("Name"), s.Name, i18n.T("so erscheint er in der Auswahl „Befehlssatz“ der Verbindung"))
|
||||
bases := []string{"—"}
|
||||
for _, x := range cmdset.All() {
|
||||
if x.ID != s.ID {
|
||||
bases = append(bases, x.ID)
|
||||
}
|
||||
}
|
||||
cur := s.Base
|
||||
if cur == "" {
|
||||
cur = "—"
|
||||
}
|
||||
f.choice("base", i18n.T("Basiert auf"), bases, cur, i18n.T("leer gelassene Felder kommen von dort (Befehle, Leser, Hinweis); Erkennung nicht"))
|
||||
fam := s.Family
|
||||
if fam == "" && s.Base != "" {
|
||||
if b := cmdset.Resolve(s.Base, "", ""); b != nil {
|
||||
fam = b.EffFamily() // erbt die Familie der Grundlage
|
||||
}
|
||||
}
|
||||
if fam == "" {
|
||||
fam = cmdset.FamilyNetwork
|
||||
}
|
||||
f.choice("family", i18n.T("Familie"), []string{cmdset.FamilyNetwork, cmdset.FamilyLinux, cmdset.FamilyBSD, cmdset.FamilyWindows, cmdset.FamilyMacOS}, fam,
|
||||
i18n.T("network = Switch/Router/Firewall (Befehle sichtbar am Prompt), sonst Server"))
|
||||
f.text("hint", i18n.T("Hinweis für die KI"), s.Hint, i18n.T("welche CLI, typische Befehle, wie man speichert; kommt zum Hinweis der Grundlage dazu"))
|
||||
f.section("s_detect", i18n.T("Erkennung (reguläre Ausdrücke, mehrere mit ||)"), func(t Theme) color.Color { return t.OK })
|
||||
f.text("d_screen", i18n.T("Bildschirm"), joinList(s.Detect.Screen), i18n.T("Login-Banner oder Prompt, z. B. (?i)acme switch"))
|
||||
f.text("d_version", i18n.T("Versionsausgabe"), joinList(s.Detect.Version), i18n.T("Text in der Ausgabe des Versionsbefehls"))
|
||||
f.text("d_banner", i18n.T("SSH-Kennung"), joinList(s.Detect.Banner), i18n.T("z. B. (?i)acmessh"))
|
||||
f.section("s_cmds", i18n.T("Befehle, die sshTermy tippt (nur lesend)"), func(t Theme) color.Color { return t.Warn })
|
||||
f.text("c_paging", i18n.T("Blättern aus"), s.Commands.PagingOff, i18n.T("nur bekannte: terminal length 0, no page, screen-length disable, terminal pager 0, …"))
|
||||
f.text("c_version", i18n.T("Version"), s.Commands.Version, "show version")
|
||||
f.text("c_system", i18n.T("System (CPU)"), s.Commands.System, "")
|
||||
f.text("c_memory", i18n.T("Speicher"), s.Commands.Memory, "")
|
||||
f.text("c_ports", "Ports", s.Commands.Ports, "")
|
||||
f.text("c_vlans", "VLANs", s.Commands.VLANs, "")
|
||||
f.text("c_config", i18n.T("Konfiguration"), s.Commands.Config, i18n.T("für die Sicherung (F6 b)"))
|
||||
f.text("l_cmds", i18n.T("Logs"), joinList(s.Logs.Commands), i18n.T("für den Log-Blick (Alt+E), mehrere mit ||"))
|
||||
f.section("s_read", i18n.T("Lesen (reguläre Ausdrücke, eine Klammer = Wert)"), accent)
|
||||
f.text("p_firmware", "Firmware", s.Parse.Firmware, "")
|
||||
f.text("p_model", i18n.T("Modell"), s.Parse.Model, "")
|
||||
f.text("p_name", "Name", s.Parse.Name, "")
|
||||
f.text("p_cpu", "CPU", s.Parse.CPU, i18n.T("Klammer = belegt in %, (?P<idle>…) = frei"))
|
||||
f.text("p_mem", "RAM", s.Parse.Mem, i18n.T("Klammer = belegt in %, oder (?P<used>…)/(?P<free>…) mit (?P<total>…)"))
|
||||
f.section("s_syslog", i18n.T("Syslog einrichten (ändert das Gerät, wird jedes Mal gezeigt)"), func(t Theme) color.Color { return t.Danger })
|
||||
f.text("s_steps", i18n.T("Schritte"), joinList(s.Syslog.Steps), i18n.T("mit || getrennt, Platzhalter {{ip}} und {{port}}; jede Zeile wird gegen die Gefahrenregeln geprüft"))
|
||||
f.text("s_save", i18n.T("Speichern mit"), s.Syslog.Save, "write memory")
|
||||
f.section("s_danger", i18n.T("Zusätzliche Gefahrenregel (nur ergänzen)"), func(t Theme) color.Color { return t.Danger })
|
||||
dRx, dReason := "", ""
|
||||
if len(s.Danger) > 0 {
|
||||
dRx, dReason = s.Danger[0].Rx, s.Danger[0].Reason
|
||||
}
|
||||
f.text("g_rx", i18n.T("Muster"), dRx, i18n.T("z. B. ^\\s*factory-reset\\b · weitere Regeln, Varianten und Beispiele in der Datei (o)"))
|
||||
f.text("g_reason", i18n.T("Grund"), dReason, i18n.T("wird bei einem Treffer angezeigt"))
|
||||
a.form, a.scr = f, scrCmdSetForm
|
||||
return f.setFocus(1)
|
||||
}
|
||||
|
||||
// saveCmdSetForm schreibt den Satz als Datei und lädt neu.
|
||||
func (a *App) saveCmdSetForm() error {
|
||||
f := a.form
|
||||
c := &a.cmds
|
||||
var s cmdset.Set
|
||||
if c.own && c.edit != nil {
|
||||
s = *c.edit // Felder, die das Formular nicht zeigt, bleiben
|
||||
if len(s.Danger) > 1 {
|
||||
s.Danger = s.Danger[1:]
|
||||
} else {
|
||||
s.Danger = nil
|
||||
}
|
||||
} else if c.edit != nil && c.edit.Source != cmdset.Builtin {
|
||||
s = *c.edit
|
||||
s.Danger = nil
|
||||
}
|
||||
s.Source = cmdset.Own
|
||||
s.ID, s.Name, s.Hint = f.str("id"), f.str("name"), f.str("hint")
|
||||
s.Base = f.sel("base")
|
||||
if s.Base == "—" {
|
||||
s.Base = ""
|
||||
}
|
||||
s.Family = f.sel("family")
|
||||
inherit := cmdset.FamilyNetwork
|
||||
if s.Base != "" {
|
||||
if b := cmdset.Resolve(s.Base, "", ""); b != nil {
|
||||
inherit = b.EffFamily()
|
||||
}
|
||||
}
|
||||
if s.Family == cmdset.FamilyNetwork && inherit == cmdset.FamilyNetwork {
|
||||
s.Family = "" // Standard
|
||||
}
|
||||
s.Detect.Screen, s.Detect.Version, s.Detect.Banner = splitList(f.str("d_screen")), splitList(f.str("d_version")), splitList(f.str("d_banner"))
|
||||
s.Commands.PagingOff, s.Commands.Version, s.Commands.System = f.str("c_paging"), f.str("c_version"), f.str("c_system")
|
||||
s.Commands.Memory, s.Commands.Ports, s.Commands.VLANs, s.Commands.Config = f.str("c_memory"), f.str("c_ports"), f.str("c_vlans"), f.str("c_config")
|
||||
s.Logs.Commands = splitList(f.str("l_cmds"))
|
||||
s.Parse.Firmware, s.Parse.Model, s.Parse.Name, s.Parse.CPU, s.Parse.Mem = f.str("p_firmware"), f.str("p_model"), f.str("p_name"), f.str("p_cpu"), f.str("p_mem")
|
||||
s.Syslog.Steps, s.Syslog.Save = splitList(f.str("s_steps")), f.str("s_save")
|
||||
if rx := f.str("g_rx"); rx != "" {
|
||||
s.Danger = append([]cmdset.Danger{{Rx: rx, Reason: f.str("g_reason")}}, s.Danger...)
|
||||
}
|
||||
if cmdset.IsBuiltin(s.ID) {
|
||||
return fmt.Errorf(i18n.T("Kennung „%s“ gehört zu einem eingebauten Satz; bitte eine eigene wählen (z. B. %s-eigen)"), s.ID, s.ID)
|
||||
}
|
||||
if !(c.own && c.edit != nil && c.edit.ID == s.ID) {
|
||||
if _, taken := cmdset.Lookup(s.ID); taken {
|
||||
return fmt.Errorf(i18n.T("Kennung „%s“ ist schon vergeben"), s.ID)
|
||||
}
|
||||
}
|
||||
if err := s.Validate(); err != nil {
|
||||
return err
|
||||
}
|
||||
raw, err := cmdset.Marshal(&s)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
path := filepath.Join(a.cmdsetDir(), s.ID+cmdset.Ext)
|
||||
if err := writeCmdSet(path, raw); err != nil {
|
||||
return err
|
||||
}
|
||||
if c.own && c.edit != nil && c.edit.File != "" && c.edit.File != path {
|
||||
_ = os.Remove(c.edit.File) // umbenannt
|
||||
}
|
||||
a.loadCmdSets()
|
||||
a.selectCmdSet(s.ID)
|
||||
a.flashOK(fmt.Sprintf(i18n.T("Befehlssatz „%s“ gespeichert"), s.Name))
|
||||
return nil
|
||||
}
|
||||
|
||||
func writeCmdSet(path string, raw []byte) error {
|
||||
if err := os.MkdirAll(filepath.Dir(path), 0o700); err != nil {
|
||||
return err
|
||||
}
|
||||
return os.WriteFile(path, raw, 0o600)
|
||||
}
|
||||
|
||||
func (a *App) selectCmdSet(id string) {
|
||||
for i, st := range cmdsetRows() {
|
||||
if st.Set.ID == id {
|
||||
a.cmds.sel = i
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- Löschen, Freigabe
|
||||
|
||||
func (a *App) askDeleteCmdSet(s *cmdset.Set) {
|
||||
path := s.File
|
||||
a.modal = confirmModal(i18n.T("Befehlssatz löschen"), fmt.Sprintf(i18n.T("„%s“ (%s) löschen?\n\n%s\n\nVerbindungen, die ihn nutzen, fallen auf die Erkennung zurück."), s.Name, s.ID, path), func() tea.Cmd {
|
||||
if err := os.Remove(path); err != nil {
|
||||
a.cmds.err = err.Error()
|
||||
return nil
|
||||
}
|
||||
a.loadCmdSets()
|
||||
a.cmds.sel = max(0, a.cmds.sel-1)
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
func approvedCopy(dir, id string) string {
|
||||
return filepath.Join(dir, cmdset.TeamDir, ".freigegeben", id+cmdset.Ext)
|
||||
}
|
||||
|
||||
// askApproveCmdSet zeigt Inhalt bzw. Änderungen eines Team-Satzes und gibt
|
||||
// ihn nach Bestätigung frei (Prüfsumme in den verschlüsselten Einstellungen).
|
||||
func (a *App) askApproveCmdSet(s *cmdset.Set) {
|
||||
if err := s.Validate(); err != nil {
|
||||
a.cmds.err = err.Error()
|
||||
return
|
||||
}
|
||||
var lines []string
|
||||
old, _ := os.ReadFile(approvedCopy(a.cmdsetDir(), s.ID))
|
||||
if len(old) > 0 {
|
||||
diff, add, del := hostinfo.Diff(strings.Split(string(old), "\n"), strings.Split(string(s.Raw), "\n"), 2)
|
||||
lines = append(lines, fmt.Sprintf(i18n.T("Änderungen seit der letzten Freigabe: +%d −%d"), add, del), "")
|
||||
for _, l := range diff {
|
||||
switch l.Op {
|
||||
case hostinfo.DiffAdd:
|
||||
lines = append(lines, a.s.OK.Render("+ "+l.Text))
|
||||
case hostinfo.DiffDel:
|
||||
lines = append(lines, a.s.Danger.Render("- "+l.Text))
|
||||
case hostinfo.DiffHunk:
|
||||
lines = append(lines, a.s.AI.Render(l.Text))
|
||||
default:
|
||||
lines = append(lines, a.s.Muted.Render(" "+l.Text))
|
||||
}
|
||||
}
|
||||
} else {
|
||||
lines = append(lines, i18n.T("Neuer Befehlssatz aus dem Team:"), "")
|
||||
lines = append(lines, strings.Split(strings.TrimRight(string(s.Raw), "\n"), "\n")...)
|
||||
}
|
||||
body := strings.Join(lines, "\n") + "\n\n" +
|
||||
i18n.T("Freigeben? Danach gelten Erkennung, Befehle, KI-Hinweis und zusätzliche Gefahrenregeln dieses Satzes. Lesebefehle prüft sshTermy trotzdem, Syslog-Schritte zeigt es jedes Mal.")
|
||||
id, sum, raw := s.ID, s.Sum, s.Raw
|
||||
a.modal = confirmModal(fmt.Sprintf(i18n.T("Team-Befehlssatz „%s“ freigeben"), s.Name), body, func() tea.Cmd {
|
||||
err := a.st.UpdateSettings(func(x *domain.Settings) {
|
||||
m := map[string]string{}
|
||||
for k, v := range x.CmdSetApproved {
|
||||
m[k] = v
|
||||
}
|
||||
m[id] = sum
|
||||
x.CmdSetApproved = m
|
||||
})
|
||||
if err == nil {
|
||||
_ = writeCmdSet(approvedCopy(a.cmdsetDir(), id), raw)
|
||||
} else {
|
||||
a.cmds.err = err.Error()
|
||||
}
|
||||
a.loadCmdSets()
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- Export / Import
|
||||
|
||||
func (a *App) exportCmdSet(s *cmdset.Set) {
|
||||
raw := s.Raw
|
||||
if len(raw) == 0 {
|
||||
var err error
|
||||
if raw, err = cmdset.Marshal(s); err != nil {
|
||||
a.cmds.err = err.Error()
|
||||
return
|
||||
}
|
||||
}
|
||||
path := filepath.Join(exportDir(), "sshtermy-befehlssatz-"+unsafeName.ReplaceAllString(s.ID, "_")+cmdset.Ext)
|
||||
if err := os.WriteFile(path, raw, 0o600); err != nil {
|
||||
a.cmds.err = err.Error()
|
||||
return
|
||||
}
|
||||
a.flashOK(i18n.T("Exportiert: ") + path)
|
||||
}
|
||||
|
||||
// importCmdSet übernimmt eine Datei als eigenen Satz (nach Prüfung).
|
||||
func (a *App) importCmdSet(path string) error {
|
||||
if path == "" {
|
||||
return errors.New(i18n.T("Datei fehlt"))
|
||||
}
|
||||
info, err := os.Stat(path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if info.Size() > cmdset.MaxFileSize {
|
||||
return fmt.Errorf(i18n.T("Datei zu groß (höchstens %d KB)"), cmdset.MaxFileSize>>10)
|
||||
}
|
||||
raw, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
s, err := cmdset.ParseOwn(raw)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if _, taken := cmdset.Lookup(s.ID); taken {
|
||||
return fmt.Errorf(i18n.T("Kennung „%s“ ist schon vergeben"), s.ID)
|
||||
}
|
||||
if err := writeCmdSet(filepath.Join(a.cmdsetDir(), s.ID+cmdset.Ext), raw); err != nil {
|
||||
return err
|
||||
}
|
||||
a.loadCmdSets()
|
||||
a.selectCmdSet(s.ID)
|
||||
a.flashOK(fmt.Sprintf(i18n.T("Befehlssatz „%s“ importiert"), s.Name))
|
||||
return nil
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- Team
|
||||
|
||||
// storeTeamCmdSets legt Sätze aus einem Team-Paket als Team-Dateien ab.
|
||||
// Aktiv werden sie erst nach Freigabe in der Liste (f).
|
||||
func (a *App) storeTeamCmdSets(from string, files []cmdsetFile) int {
|
||||
n := 0
|
||||
for _, f := range files {
|
||||
if len(f.YAML) > cmdset.MaxFileSize {
|
||||
continue
|
||||
}
|
||||
s, err := cmdset.ParseFile([]byte(f.YAML))
|
||||
if err != nil || cmdset.IsBuiltin(s.ID) || s.ID != f.ID {
|
||||
continue
|
||||
}
|
||||
path := filepath.Join(a.cmdsetDir(), cmdset.TeamDir, s.ID+cmdset.Ext)
|
||||
head := ""
|
||||
if from = strings.TrimSpace(strings.ReplaceAll(from, "\n", " ")); from != "" {
|
||||
head = "# von: " + from + "\n"
|
||||
}
|
||||
raw := []byte(head + strings.TrimPrefix(f.YAML, firstLineIf(f.YAML, "# von:")))
|
||||
if old, err := os.ReadFile(path); err == nil && string(old) == string(raw) {
|
||||
continue
|
||||
}
|
||||
if writeCmdSet(path, raw) == nil {
|
||||
n++
|
||||
}
|
||||
}
|
||||
if n > 0 {
|
||||
a.loadCmdSets()
|
||||
a.pushToast(toastWarn, fmt.Sprintf(i18n.T("%d Befehlssätze vom Team warten auf Freigabe (Einstellungen › Befehlssätze, f)"), n))
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
type cmdsetFile = team.CmdSet
|
||||
|
||||
func firstLineIf(s, prefix string) string {
|
||||
l, _, _ := strings.Cut(s, "\n")
|
||||
if strings.HasPrefix(strings.TrimSpace(l), prefix) {
|
||||
return l + "\n"
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- am Gerät testen
|
||||
|
||||
// cmdsetTest führt die Lesebefehle eines Satzes im aktuellen Tab aus und
|
||||
// zeigt, was dabei herauskommt.
|
||||
func (a *App) cmdsetTest(set *cmdset.Set) tea.Cmd {
|
||||
s := a.current()
|
||||
if s == nil || s.state != stConnected {
|
||||
a.cmds.err = i18n.T("Zum Testen erst eine Verbindung zu dem Gerät öffnen (der aktuelle Tab wird benutzt).")
|
||||
return nil
|
||||
}
|
||||
eff := cmdset.Resolve(set.ID, s.prof.Model, s.prof.Version)
|
||||
if eff == nil {
|
||||
a.cmds.err = i18n.T("Der Satz ist nicht aktiv (Freigabe oder Fehler?).")
|
||||
return nil
|
||||
}
|
||||
sid := s.id
|
||||
title := fmt.Sprintf(i18n.T("Test „%s“ an %s"), set.Name, s.conn.Alias)
|
||||
if eff.EffFamily() != cmdset.FamilyNetwork {
|
||||
if s.client == nil || s.netDevice() {
|
||||
a.cmds.err = i18n.T("Server-Sätze testet sshTermy über eine eigene SSH-Sitzung; der aktuelle Tab ist keine.")
|
||||
return nil
|
||||
}
|
||||
cl := s.client
|
||||
return func() tea.Msg {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
|
||||
defer cancel()
|
||||
var lines []string
|
||||
out, _ := cl.RunScript(ctx, sysprof.Probe())
|
||||
p := sysprof.FromProbe(out)
|
||||
lines = append(lines, fmt.Sprintf(i18n.T("Erkannt: %s (%s)"), orDefault(p.Dialect, "?"), orDefault(p.OS, "?")))
|
||||
for _, e := range eff.Commands.Extra {
|
||||
eo, err := cl.RunScript(ctx, e.Cmd+" 2>/dev/null\n")
|
||||
v := hostinfo.ExtraValue(e, eo)
|
||||
if err != nil {
|
||||
v = err.Error()
|
||||
}
|
||||
lines = append(lines, fmt.Sprintf("%-12s %s %s", hostinfo.ExtraLabel(e), orDefault(v, "—"), e.Cmd))
|
||||
}
|
||||
return cmdsetTestMsg{sid: sid, title: title, lines: lines}
|
||||
}
|
||||
}
|
||||
if s.shell == nil || s.term == nil {
|
||||
return nil
|
||||
}
|
||||
prompt := strings.TrimSpace(s.term.CursorLine())
|
||||
if s.term.AltScreen() || !hostinfo.IsPrompt(prompt) || s.host.busy {
|
||||
a.cmds.err = i18n.T("Abfrage nur an einem leeren Prompt (z. B. switch#). Bitte erst Eingabe beenden oder ⏎ drücken.")
|
||||
return nil
|
||||
}
|
||||
if configPrompt(prompt) {
|
||||
a.cmds.err = i18n.T("Der Switch ist im Konfigurationsmodus. Erst mit end bzw. exit zurück an den normalen Prompt.")
|
||||
return nil
|
||||
}
|
||||
s.host.busy, s.host.step = true, i18n.T("Befehlssatz testen …")
|
||||
a.scr = scrTerminal
|
||||
s.cap.hold() // bis alles getippt ist keine Tasten an diese Shell (shelllock.go)
|
||||
return func() tea.Msg {
|
||||
defer s.cap.release()
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Minute)
|
||||
defer cancel()
|
||||
var lines []string
|
||||
run := func(cmd string) (string, bool) {
|
||||
if cmd == "" {
|
||||
return "", false
|
||||
}
|
||||
out, err := shellRun(ctx, s, prompt, cmd, 30*time.Second)
|
||||
txt := strings.Join(out, "\n")
|
||||
state := "✓"
|
||||
switch {
|
||||
case err != nil:
|
||||
state = "× " + err.Error()
|
||||
case sysprof.Rejection(txt) != "":
|
||||
state = "× " + sysprof.Rejection(txt)
|
||||
}
|
||||
lines = append(lines, fmt.Sprintf("%-40s %s", trunc(cmd, 40), state))
|
||||
return txt, err == nil
|
||||
}
|
||||
c := eff.Commands
|
||||
ver, _ := run(orDefault(c.Version, "show version"))
|
||||
if d := hostinfo.DetectVendor(ver); d != hostinfo.VendorUnknown && string(d) != set.ID {
|
||||
lines = append(lines, fmt.Sprintf(i18n.T("! Die Versionsausgabe erkennt der Satz „%s“ (Vorrang vor eigenen Sätzen)."), d))
|
||||
}
|
||||
run(c.PagingOff)
|
||||
sys, _ := run(c.System)
|
||||
mem, _ := run(c.Memory)
|
||||
ports, _ := run(c.Ports)
|
||||
vlans, _ := run(c.VLANs)
|
||||
sw := hostinfo.ParseWith(eff, ver, sys+"\n"+mem, ports, vlans)
|
||||
if v := cmdset.Resolve(set.ID, sw.Model, sw.Firmware); v != nil {
|
||||
eff = v
|
||||
sw = hostinfo.ParseWith(v, ver, sys+"\n"+mem, ports, vlans)
|
||||
}
|
||||
for _, e := range eff.Commands.Extra {
|
||||
if out, ok := run(e.Cmd); ok {
|
||||
sw.Extras = append(sw.Extras, hostinfo.Extra{Label: hostinfo.ExtraLabel(e), Value: hostinfo.ExtraValue(e, out)})
|
||||
}
|
||||
}
|
||||
for _, lc := range eff.Logs.Commands {
|
||||
run(lc)
|
||||
}
|
||||
res := []string{
|
||||
fmt.Sprintf("%-12s %s", i18n.T("Modell"), orDefault(sw.Model, "—")),
|
||||
fmt.Sprintf("%-12s %s", "Firmware", orDefault(sw.Firmware, "—")),
|
||||
fmt.Sprintf("%-12s %s", "Name", orDefault(sw.Name, "—")),
|
||||
fmt.Sprintf("%-12s %s", i18n.T("Laufzeit"), orDefault(sw.Uptime, "—")),
|
||||
fmt.Sprintf("%-12s %s", "CPU", pctText(sw.CPUPct)),
|
||||
fmt.Sprintf("%-12s %s", "RAM", pctText(sw.MemPct)),
|
||||
fmt.Sprintf("%-12s %d / %d", "Ports", sw.PortsUp, sw.PortsUp+sw.PortsDown),
|
||||
fmt.Sprintf("%-12s %d", "VLANs", len(sw.VLANs)),
|
||||
}
|
||||
if vn := cmdset.VariantName(set.ID, sw.Model, sw.Firmware); vn != "" {
|
||||
res = append(res, fmt.Sprintf("%-12s %s", i18n.T("Variante"), vn))
|
||||
}
|
||||
for _, e := range sw.Extras {
|
||||
res = append(res, fmt.Sprintf("%-12s %s", e.Label, orDefault(e.Value, "—")))
|
||||
}
|
||||
res = append(res, "", i18n.T("Befehle:"))
|
||||
return cmdsetTestMsg{sid: sid, title: title, lines: append(res, lines...)}
|
||||
}
|
||||
}
|
||||
|
||||
func pctText(p int) string {
|
||||
if p < 0 {
|
||||
return "—"
|
||||
}
|
||||
return fmt.Sprintf("%d %%", p)
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- KI-Entwurf
|
||||
|
||||
// cmdsetDraft: die KI schreibt aus dem aktuellen Bildschirm einen Entwurf.
|
||||
func (a *App) cmdsetDraft() tea.Cmd {
|
||||
s := a.current()
|
||||
if s == nil || s.term == nil {
|
||||
a.cmds.err = i18n.T("Für einen KI-Entwurf erst am Gerät anmelden und z. B. show version eingeben; die KI liest den aktuellen Tab.")
|
||||
return nil
|
||||
}
|
||||
ag, err := a.agentClientFor(s.conn)
|
||||
if err != nil {
|
||||
a.cmds.err = "KI: " + err.Error()
|
||||
return nil
|
||||
}
|
||||
if !a.st.LLM().SendScreen {
|
||||
a.cmds.err = i18n.T("Der KI-Entwurf braucht den Terminal-Inhalt; in den KI-Einstellungen ist „Bildschirm mitschicken“ aus.")
|
||||
return nil
|
||||
}
|
||||
c := a.agentContext(s, false)
|
||||
screen := s.term.PlainLines(200)
|
||||
sid := s.id
|
||||
a.flash(i18n.T("KI schreibt einen Entwurf …"))
|
||||
return func() tea.Msg {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
|
||||
defer cancel()
|
||||
y, err := ag.DraftCmdSet(ctx, screen, c)
|
||||
return cmdsetDraftMsg{sid: sid, yaml: y, err: err}
|
||||
}
|
||||
}
|
||||
|
||||
func (a *App) onCmdSetDraft(m cmdsetDraftMsg) {
|
||||
if m.err != nil {
|
||||
a.cmds.err = i18n.T("KI-Entwurf: ") + m.err.Error()
|
||||
return
|
||||
}
|
||||
s, err := cmdset.ParseOwn([]byte(m.yaml))
|
||||
lines := strings.Split(strings.TrimRight(m.yaml, "\n"), "\n")
|
||||
if err != nil {
|
||||
lines = append([]string{a.s.Danger.Render(i18n.T("Der Entwurf besteht die Prüfung nicht:")), a.s.Danger.Render(err.Error()), ""}, lines...)
|
||||
path := filepath.Join(exportDir(), "sshtermy-befehlssatz-entwurf"+cmdset.Ext)
|
||||
if os.WriteFile(path, []byte(m.yaml), 0o600) == nil {
|
||||
lines = append(lines, "", i18n.T("Gespeichert zum Nacharbeiten: ")+path+i18n.T(" (danach mit i importieren)"))
|
||||
}
|
||||
a.modal = textModal(i18n.T("KI-Entwurf"), lines)
|
||||
return
|
||||
}
|
||||
if _, taken := cmdset.Lookup(s.ID); taken {
|
||||
s.ID += "-ki"
|
||||
raw, _ := cmdset.Marshal(s)
|
||||
m.yaml = string(raw)
|
||||
}
|
||||
body := strings.Join(lines, "\n") + "\n\n" + i18n.T("Als eigenen Befehlssatz speichern? Danach am Gerät testen (t) und bei Bedarf bearbeiten (e).")
|
||||
id, raw := s.ID, []byte(m.yaml)
|
||||
a.modal = confirmModal(i18n.T("KI-Entwurf"), body, func() tea.Cmd {
|
||||
if err := writeCmdSet(filepath.Join(a.cmdsetDir(), id+cmdset.Ext), raw); err != nil {
|
||||
a.cmds.err = err.Error()
|
||||
return nil
|
||||
}
|
||||
a.loadCmdSets()
|
||||
a.selectCmdSet(id)
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- Korrekturen übernehmen
|
||||
|
||||
// cmdsetFromLearned: Was der Admin an KI-Vorschlägen auf diesem Gerät
|
||||
// korrigiert hat, kommt in den Hinweis eines eigenen Satzes. Ist der Satz
|
||||
// eingebaut, entsteht ein eigener, der darauf aufbaut, und die Verbindung
|
||||
// nutzt ihn.
|
||||
func (a *App) cmdsetFromLearned() tea.Cmd {
|
||||
s := a.current()
|
||||
if s == nil || len(s.prof.Learned) == 0 {
|
||||
a.cmds.err = i18n.T("Im aktuellen Tab gibt es keine gemerkten Korrekturen (entstehen, wenn du einen KI-Vorschlag vor dem Ausführen änderst).")
|
||||
return nil
|
||||
}
|
||||
base := s.prof.Dialect
|
||||
if base == "" {
|
||||
a.cmds.err = i18n.T("Für dieses Gerät ist noch kein Befehlssatz erkannt.")
|
||||
return nil
|
||||
}
|
||||
var add []string
|
||||
for _, c := range s.prof.Learned {
|
||||
add = append(add, fmt.Sprintf("statt „%s“: „%s“", c.AI, c.Fixed))
|
||||
}
|
||||
note := "Auf diesen Geräten so: " + strings.Join(add, "; ") + "."
|
||||
cur, _ := cmdset.Lookup(base)
|
||||
var target cmdset.Set
|
||||
if cur != nil && cur.Source == cmdset.Own {
|
||||
target = *cur
|
||||
if !strings.Contains(target.Hint, note) {
|
||||
target.Hint = strings.TrimSpace(target.Hint + " " + note)
|
||||
}
|
||||
} else {
|
||||
id := base + "-eigen"
|
||||
if _, taken := cmdset.Lookup(id); taken {
|
||||
if o, _ := cmdset.Lookup(id); o.Source == cmdset.Own {
|
||||
target = *o
|
||||
target.Hint = strings.TrimSpace(target.Hint + " " + note)
|
||||
} else {
|
||||
a.cmds.err = fmt.Sprintf(i18n.T("Kennung „%s“ ist schon vergeben"), id)
|
||||
return nil
|
||||
}
|
||||
} else {
|
||||
name := base
|
||||
if cur != nil {
|
||||
name = cur.Name
|
||||
}
|
||||
target = cmdset.Set{ID: id, Name: trunc(name+i18n.T(" (eigen)"), 60), Base: base, Hint: note}
|
||||
}
|
||||
}
|
||||
target.Source = cmdset.Own
|
||||
if len([]rune(target.Hint)) > 2000 {
|
||||
a.cmds.err = i18n.T("Der KI-Hinweis wäre zu lang; bitte den Satz zuerst bearbeiten (e).")
|
||||
return nil
|
||||
}
|
||||
if err := target.Validate(); err != nil {
|
||||
a.cmds.err = err.Error()
|
||||
return nil
|
||||
}
|
||||
raw, err := cmdset.Marshal(&target)
|
||||
if err != nil {
|
||||
a.cmds.err = err.Error()
|
||||
return nil
|
||||
}
|
||||
body := fmt.Sprintf(i18n.T("Befehlssatz „%s“ (%s) bekommt diesen Hinweis für die KI:\n\n%s\n\nDie Verbindung %s nutzt danach diesen Satz."), target.Name, target.ID, note, s.conn.Alias)
|
||||
sid, id := s.id, target.ID
|
||||
a.modal = confirmModal(i18n.T("Korrekturen übernehmen"), body, func() tea.Cmd {
|
||||
if err := writeCmdSet(filepath.Join(a.cmdsetDir(), id+cmdset.Ext), raw); err != nil {
|
||||
a.cmds.err = err.Error()
|
||||
return nil
|
||||
}
|
||||
a.loadCmdSets()
|
||||
if x := a.byID(sid); x != nil {
|
||||
x.prof.Dialect, x.prof.Manual = id, true
|
||||
a.saveProfile(x)
|
||||
}
|
||||
a.selectCmdSet(id)
|
||||
a.flashOK(fmt.Sprintf(i18n.T("Korrekturen in „%s“ übernommen"), id))
|
||||
return nil
|
||||
})
|
||||
return nil
|
||||
}
|
||||
|
||||
// cmdsetMsg verarbeitet Ergebnisse (Test, KI-Entwurf).
|
||||
func (a *App) cmdsetMsg(msg tea.Msg) (tea.Cmd, bool) {
|
||||
switch m := msg.(type) {
|
||||
case cmdsetTestMsg:
|
||||
if s := a.byID(m.sid); s != nil {
|
||||
s.host.busy, s.host.step = false, ""
|
||||
}
|
||||
a.modal = textModal(m.title, m.lines)
|
||||
return nil, true
|
||||
case cmdsetDraftMsg:
|
||||
a.onCmdSetDraft(m)
|
||||
return nil, true
|
||||
}
|
||||
return nil, false
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
package ui
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/db9979/sshtermy/internal/cmdset"
|
||||
"github.com/db9979/sshtermy/internal/i18n"
|
||||
"github.com/db9979/sshtermy/internal/safety"
|
||||
"github.com/db9979/sshtermy/internal/team"
|
||||
)
|
||||
|
||||
// Eigenen Satz anlegen, Team-Satz erst nach Freigabe aktiv, Gefahrenregel
|
||||
// eines Team-Satzes wirkt erst danach, eingebaute Kennungen bleiben gesperrt.
|
||||
func TestCmdSetsFlow(t *testing.T) {
|
||||
g := newGold(t, i18n.DE, 110, 34, true)
|
||||
t.Cleanup(func() { cmdset.Install(cmdset.Loaded{}, nil, nil) })
|
||||
a := g.a
|
||||
a.openCmdSets()
|
||||
a.selectCmdSet("cisco-ios")
|
||||
g.keys("n")
|
||||
if a.scr != scrCmdSetForm {
|
||||
t.Fatalf("Formular nicht offen: %v", a.scr)
|
||||
}
|
||||
g.keys("ctrl+s")
|
||||
if a.scr != scrCmdSets {
|
||||
t.Fatalf("nach dem Speichern nicht zurück in der Liste (Fehler: %q)", a.form.err)
|
||||
}
|
||||
s := cmdset.Resolve("cisco-ios-eigen", "", "")
|
||||
if s == nil || s.Source != cmdset.Own || s.Commands.Version == "" || s.EffFamily() != cmdset.FamilyNetwork {
|
||||
t.Fatalf("eigener Satz fehlt oder erbt nicht: %+v", s)
|
||||
}
|
||||
if _, err := os.Stat(filepath.Join(a.cmdsetDir(), "cisco-ios-eigen.yaml")); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// Team-Satz mit eingebauter Kennung wird verworfen, eigener wartet.
|
||||
evil := "id: cisco-ios\nname: Fake\n"
|
||||
good := "id: acme-sw\nname: ACME\ndanger:\n - rx: '^\\s*acme-wipe\\b'\n reason: löscht alles\n"
|
||||
if n := a.storeTeamCmdSets("Kollege", []team.CmdSet{{ID: "cisco-ios", YAML: evil}, {ID: "acme-sw", YAML: good}}); n != 1 {
|
||||
t.Fatalf("gespeichert: %d, erwartet 1", n)
|
||||
}
|
||||
if b, _ := cmdset.Lookup("cisco-ios"); b.Source != cmdset.Builtin {
|
||||
t.Fatal("eingebauter Satz überschrieben")
|
||||
}
|
||||
if _, ok := cmdset.Lookup("acme-sw"); ok {
|
||||
t.Fatal("Team-Satz ohne Freigabe aktiv")
|
||||
}
|
||||
if len(safety.Check("acme-wipe", "")) != 0 {
|
||||
t.Fatal("Gefahrenregel eines nicht freigegebenen Team-Satzes wirkt")
|
||||
}
|
||||
a.selectCmdSet("acme-sw")
|
||||
g.keys("f")
|
||||
if a.modal == nil || !strings.Contains(a.modal.body, "acme-wipe") {
|
||||
t.Fatal("Freigabe zeigt den Inhalt nicht")
|
||||
}
|
||||
a.modal.onYes()
|
||||
a.modal = nil
|
||||
if s, ok := cmdset.Lookup("acme-sw"); !ok || s.From != "Kollege" {
|
||||
t.Fatalf("Team-Satz nach Freigabe nicht aktiv: %+v", s)
|
||||
}
|
||||
if len(safety.Check("acme-wipe", "")) == 0 {
|
||||
t.Fatal("Gefahrenregel nach Freigabe wirkt nicht")
|
||||
}
|
||||
|
||||
// Geändert vom Team: wieder gesperrt bis zur nächsten Freigabe.
|
||||
a.storeTeamCmdSets("Kollege", []team.CmdSet{{ID: "acme-sw", YAML: good + "hint: neu\n"}})
|
||||
if _, ok := cmdset.Lookup("acme-sw"); ok {
|
||||
t.Fatal("geänderter Team-Satz ohne neue Freigabe aktiv")
|
||||
}
|
||||
}
|
||||
|
||||
// Ohne family gilt die Familie der Grundlage, auch für die Nur-lesen-Prüfung.
|
||||
func TestCmdSetInheritsFamily(t *testing.T) {
|
||||
s, err := cmdset.ParseOwn([]byte("id: mein-linux\nname: Mein Linux\nbase: posix\ncommands:\n system: uptime\n"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := cmdset.ParseOwn([]byte("id: mein-linux\nname: Mein Linux\nbase: posix\ncommands:\n system: rm -rf /tmp/x\n")); err == nil {
|
||||
t.Fatal("schreibender Befehl angenommen")
|
||||
}
|
||||
t.Cleanup(func() { cmdset.Install(cmdset.Loaded{}, nil, nil) })
|
||||
cmdset.Install(cmdset.Loaded{Own: []*cmdset.Set{s}}, nil, nil)
|
||||
if f := cmdset.Resolve("mein-linux", "", "").EffFamily(); f != cmdset.FamilyLinux {
|
||||
t.Fatalf("Familie %q, erwartet linux", f)
|
||||
}
|
||||
if l, _ := cmdset.Lookup("mein-linux"); l.EffFamily() != cmdset.FamilyLinux {
|
||||
t.Fatalf("Familie ohne Auflösung %q", l.EffFamily())
|
||||
}
|
||||
}
|
||||
@@ -46,8 +46,9 @@ var updateGolden = flag.Bool("update", os.Getenv("UPDATE_GOLDEN") != "", "Golden
|
||||
// gold ist eine App im Testaufbau: eigener Store-Ordner, feste Daten, keine
|
||||
// Netzwerkzugriffe (Kommandos aus Update werden verworfen, nicht ausgeführt).
|
||||
type gold struct {
|
||||
t *testing.T
|
||||
a *App
|
||||
t *testing.T
|
||||
a *App
|
||||
dir string // Konfigordner (temporär), im Bild als ~/.config/sshtermy
|
||||
}
|
||||
|
||||
// goldenConns: feste Beispielverbindungen (Ordner, Tags, Netzwerkgerät,
|
||||
@@ -119,7 +120,7 @@ func newGold(t *testing.T, lang string, w, h int, seed bool) *gold {
|
||||
t.Fatal(err)
|
||||
}
|
||||
a.intro = nil
|
||||
g := &gold{t: t, a: a}
|
||||
g := &gold{t: t, a: a, dir: dir}
|
||||
g.send(tea.WindowSizeMsg{Width: w, Height: h})
|
||||
if seed {
|
||||
g.send(unlockedMsg{})
|
||||
@@ -224,6 +225,9 @@ func (g *gold) screen() string {
|
||||
v := g.a.View()
|
||||
out := ansi.Strip(v.Content)
|
||||
out = strings.ReplaceAll(out, runtime.GOOS+"/"+runtime.GOARCH, "linux/amd64") // Über-Dialog
|
||||
if g.dir != "" {
|
||||
out = strings.ReplaceAll(out, g.dir, "~/.config/sshtermy")
|
||||
}
|
||||
lines := strings.Split(out, "\n")
|
||||
for i, l := range lines {
|
||||
lines[i] = strings.TrimRight(l, " ")
|
||||
@@ -342,6 +346,8 @@ var goldenCases = []goldenCase{
|
||||
{name: "about", w: 100, h: 30, setup: func(g *gold) { g.keys("f12") }},
|
||||
{name: "palette", w: 100, h: 30, setup: func(g *gold) { g.keys("ctrl+space") }},
|
||||
{name: "palette-filter", w: 100, h: 30, setup: func(g *gold) { g.keys("ctrl+space").typ("tunnel") }},
|
||||
{name: "cmdsets", w: 110, h: 34, setup: func(g *gold) { g.a.openCmdSets() }},
|
||||
{name: "cmdset-form", w: 110, h: 40, setup: func(g *gold) { g.a.openCmdSets(); g.keys("n") }},
|
||||
{name: "llm-status", w: 100, h: 30, setup: func(g *gold) { llm.ResetTaskStats(); g.a.openLLMStatus() }},
|
||||
{name: "tour", w: 100, h: 30, setup: func(g *gold) { g.a.modal = g.a.tourModal() }},
|
||||
{name: "hostkey", w: 100, h: 30, setup: func(g *gold) {
|
||||
|
||||
@@ -28,6 +28,7 @@ import (
|
||||
"charm.land/lipgloss/v2"
|
||||
|
||||
"github.com/db9979/sshtermy/internal/audit"
|
||||
"github.com/db9979/sshtermy/internal/cmdset"
|
||||
"github.com/db9979/sshtermy/internal/domain"
|
||||
"github.com/db9979/sshtermy/internal/hostinfo"
|
||||
"github.com/db9979/sshtermy/internal/i18n"
|
||||
@@ -225,6 +226,10 @@ func (a *App) hostServerCmd(s *session, mode hostMode) tea.Cmd {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 40*time.Second)
|
||||
h.cancelFn = cancel
|
||||
sid, seq, cl := s.id, h.seq, s.client
|
||||
var extras []cmdset.Extra
|
||||
if set := cmdset.Resolve(s.prof.Dialect, s.prof.Model, s.prof.Version); set != nil && set.EffFamily() != cmdset.FamilyNetwork {
|
||||
extras = set.Commands.Extra // geprüft: nur Lesebefehle
|
||||
}
|
||||
return func() tea.Msg {
|
||||
defer cancel()
|
||||
out, err := cl.RunScript(ctx, hostinfo.ServerScript)
|
||||
@@ -232,6 +237,15 @@ func (a *App) hostServerCmd(s *session, mode hostMode) tea.Cmd {
|
||||
return hostSrvMsg{sid: sid, seq: seq, err: err, mode: mode}
|
||||
}
|
||||
srv, err := hostinfo.ParseServer(out)
|
||||
for _, e := range extras {
|
||||
eo, err := cl.RunScript(ctx, e.Cmd+" 2>/dev/null\n")
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
if v := hostinfo.ExtraValue(e, eo); v != "" {
|
||||
srv.Extras = append(srv.Extras, hostinfo.Extra{Label: hostinfo.ExtraLabel(e), Value: v})
|
||||
}
|
||||
}
|
||||
return hostSrvMsg{sid: sid, seq: seq, srv: srv, err: err, mode: mode}
|
||||
}
|
||||
}
|
||||
@@ -272,6 +286,7 @@ func (a *App) hostNetCmd(s *session, info, backup bool) tea.Cmd {
|
||||
if vendor == hostinfo.VendorUnknown {
|
||||
vendor = hostVendor(s.prof) // aus dem Systemprofil
|
||||
}
|
||||
model, firmware := s.prof.Model, s.prof.Version
|
||||
st := a.st
|
||||
connID := s.conn.ID
|
||||
rules := a.configRules()
|
||||
@@ -288,7 +303,11 @@ func (a *App) hostNetCmd(s *session, info, backup bool) tea.Cmd {
|
||||
|
||||
var ver string
|
||||
if info || r.vendor == hostinfo.VendorUnknown {
|
||||
out, err := run(r.vendor.VersionCommand(), 20*time.Second)
|
||||
vcmd := hostinfo.SetOf(r.vendor, model, firmware).Commands.Version
|
||||
if vcmd == "" {
|
||||
vcmd = r.vendor.VersionCommand()
|
||||
}
|
||||
out, err := run(vcmd, 20*time.Second)
|
||||
if err != nil {
|
||||
return fail(err)
|
||||
}
|
||||
@@ -296,31 +315,52 @@ func (a *App) hostNetCmd(s *session, info, backup bool) tea.Cmd {
|
||||
if v := hostinfo.DetectVendor(out); v != hostinfo.VendorUnknown {
|
||||
r.vendor = v
|
||||
}
|
||||
// Modell und Firmware entscheiden über die Variante des Satzes.
|
||||
if sw := hostinfo.ParseWith(hostinfo.SetOf(r.vendor, "", ""), ver, "", "", ""); sw.Model != "" || sw.Firmware != "" {
|
||||
model, firmware = orDefault(sw.Model, model), orDefault(sw.Firmware, firmware)
|
||||
}
|
||||
}
|
||||
if p := r.vendor.PagingOff(); p != "" && !r.pagingOff {
|
||||
set := hostinfo.SetOf(r.vendor, model, firmware)
|
||||
if p := set.Commands.PagingOff; p != "" && !r.pagingOff {
|
||||
if _, err := run(p, 10*time.Second); err != nil {
|
||||
return fail(err)
|
||||
}
|
||||
r.pagingOff = true
|
||||
}
|
||||
if info {
|
||||
sysCmd, portCmd, vlanCmd := r.vendor.InfoCommands()
|
||||
outs := make([]string, 3)
|
||||
for i, c := range []string{sysCmd, portCmd, vlanCmd} {
|
||||
if c == "" {
|
||||
c := set.Commands
|
||||
outs := make([]string, 4)
|
||||
for i, cmd := range []string{c.System, c.Ports, c.VLANs, c.Memory} {
|
||||
if cmd == "" {
|
||||
continue
|
||||
}
|
||||
out, err := run(c, 30*time.Second)
|
||||
out, err := run(cmd, 30*time.Second)
|
||||
if err != nil {
|
||||
return fail(err)
|
||||
}
|
||||
outs[i] = out
|
||||
}
|
||||
sw := hostinfo.ParseSwitch(r.vendor, ver, outs[0], outs[1], outs[2])
|
||||
system := outs[0]
|
||||
if outs[3] != "" {
|
||||
system += "\n" + outs[3]
|
||||
}
|
||||
sw := hostinfo.ParseWith(set, ver, system, outs[1], outs[2])
|
||||
for _, e := range c.Extra {
|
||||
out, err := run(e.Cmd, 30*time.Second)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
if v := hostinfo.ExtraValue(e, out); v != "" {
|
||||
sw.Extras = append(sw.Extras, hostinfo.Extra{Label: hostinfo.ExtraLabel(e), Value: v})
|
||||
}
|
||||
}
|
||||
r.sw = &sw
|
||||
}
|
||||
if backup {
|
||||
cfgCmd := r.vendor.ConfigCommand()
|
||||
cfgCmd := set.Commands.Config
|
||||
if cfgCmd == "" {
|
||||
return fail(errors.New(i18n.T("Für dieses Gerät kennt der Befehlssatz keinen Befehl für die Konfiguration (Einstellungen › Befehlssätze).")))
|
||||
}
|
||||
cfg, err := run(cfgCmd, 2*time.Minute)
|
||||
if err != nil {
|
||||
return fail(err)
|
||||
@@ -795,6 +835,9 @@ func (a *App) viewHost(b *strings.Builder, s *session, w int) {
|
||||
if srv.RebootNeeded {
|
||||
b.WriteString(st.Warn.Render(i18n.T("◌ Neustart erforderlich")) + "\n")
|
||||
}
|
||||
for _, e := range srv.Extras {
|
||||
row(trunc(e.Label, 9), e.Value)
|
||||
}
|
||||
a.viewAlerts(b, s, w)
|
||||
b.WriteString("\n" + st.Muted.Render(i18n.T("Stand ")+srv.At.Format("15:04:05")+i18n.T(" · r aktualisieren")) + "\n")
|
||||
b.WriteString(st.Muted.Render(wrap(a.monitorLine(false), w)) + "\n")
|
||||
@@ -835,6 +878,9 @@ func (a *App) viewHost(b *strings.Builder, s *session, w int) {
|
||||
}
|
||||
b.WriteString(st.Muted.Render(fmt.Sprintf("%-9s ", "VLANs")) + st.Text.Render(lipgloss.NewStyle().Width(w-10).Render(trunc(strings.Join(vs, ", "), 3*(w-10)))) + "\n")
|
||||
}
|
||||
for _, e := range sw.Extras {
|
||||
row(trunc(e.Label, 9), e.Value)
|
||||
}
|
||||
a.viewAlerts(b, s, w)
|
||||
b.WriteString(st.Muted.Render(i18n.T("Stand ")+sw.At.Format("15:04:05")) + "\n")
|
||||
b.WriteString(st.Muted.Render(wrap(a.monitorLine(true), w)) + "\n")
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package ui
|
||||
|
||||
import (
|
||||
"github.com/db9979/sshtermy/internal/cmdset"
|
||||
"regexp"
|
||||
"testing"
|
||||
|
||||
@@ -60,8 +61,14 @@ func TestTablesTranslated(t *testing.T) {
|
||||
texts = append(texts, deviceLabels...)
|
||||
texts = append(texts, accentLabels()...)
|
||||
texts = append(texts, dialectAuto, modeFolder, modeOff, version.Idea, version.Slogan)
|
||||
for _, d := range domain.Dialects {
|
||||
texts = append(texts, d.Name)
|
||||
// Befehlssätze heißen meist wie das Produkt; deutsche Namen brauchen name_en.
|
||||
german := regexp.MustCompile(`[äöüÄÖÜß]|\b(und|oder|eigener|Gerät|Geräte)\b`)
|
||||
for _, d := range domain.Dialects() {
|
||||
if german.MatchString(d.Name) {
|
||||
if s, ok := cmdset.Lookup(d.ID); !ok || s.NameEN == "" {
|
||||
texts = append(texts, d.Name)
|
||||
}
|
||||
}
|
||||
}
|
||||
word := regexp.MustCompile(`[A-Za-zÄÖÜäöüß]{2,}`)
|
||||
for _, s := range texts {
|
||||
|
||||
@@ -9,12 +9,24 @@ import (
|
||||
|
||||
tea "charm.land/bubbletea/v2"
|
||||
|
||||
"github.com/db9979/sshtermy/internal/cmdset"
|
||||
"github.com/db9979/sshtermy/internal/domain"
|
||||
"github.com/db9979/sshtermy/internal/hostinfo"
|
||||
"github.com/db9979/sshtermy/internal/i18n"
|
||||
"github.com/db9979/sshtermy/internal/logscan"
|
||||
"github.com/db9979/sshtermy/internal/safety"
|
||||
)
|
||||
|
||||
// syslogHasPort: kann das Gerät einen Zielport? Ohne {{port}} sendet es an 514.
|
||||
func syslogHasPort(steps []string) bool {
|
||||
for _, s := range steps {
|
||||
if strings.Contains(strings.ReplaceAll(s, " ", ""), "{{port}}") {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// Syslog-Ziel am Gerät einrichten: sshTermy zeigt die Befehle für den
|
||||
// Hersteller mit der eigenen IP und tippt sie nach Bestätigung sichtbar ein.
|
||||
// Gespeichert wird am Gerät nichts (außer Junos commit), write memory bleibt
|
||||
@@ -61,21 +73,42 @@ func (a *App) askSyslogSetup(s *session) tea.Cmd {
|
||||
a.flashErr(i18n.T("Der Switch ist im Konfigurationsmodus. Erst mit end bzw. exit zurück an den normalen Prompt."))
|
||||
return nil
|
||||
}
|
||||
cmds := logscan.SyslogSetup(v, ip, port)
|
||||
set := hostinfo.SetOf(v, s.prof.Model, s.prof.Version)
|
||||
cmds := logscan.SyslogSetupWith(set, ip, port)
|
||||
if len(cmds) == 0 {
|
||||
hint := i18n.T("Für dieses Gerät kennt sshTermy die Befehle nicht.")
|
||||
if v == hostinfo.VendorUniFi {
|
||||
hint = i18n.T("UniFi-Switches stellt man im UniFi-Controller ein: Einstellungen › System › Remote Logging (Syslog).")
|
||||
if set.Syslog.Note != "" {
|
||||
hint = i18n.T(set.Syslog.Note)
|
||||
}
|
||||
a.modal = textModal(i18n.T("Syslog an sshTermy senden"), []string{hint, "", fmt.Sprintf(i18n.T("Ziel: %s, UDP-Port %d"), ip, port)})
|
||||
return nil
|
||||
}
|
||||
// Jede Zeile gegen alle Gefahrenregeln: ein Befehlssatz darf über die
|
||||
// Syslog-Schritte nichts Gefährliches eintippen lassen.
|
||||
for _, c := range cmds {
|
||||
for _, k := range safety.Kinds {
|
||||
if f := safety.Check(c, k); len(f) > 0 {
|
||||
a.flashErr(fmt.Sprintf(i18n.T("Syslog-Schritt „%s“ gesperrt: %s"), c, f[0].Reason))
|
||||
return nil
|
||||
}
|
||||
}
|
||||
}
|
||||
body := fmt.Sprintf(i18n.T("Das Gerät schickt danach Meldungen (ab Warnung) an %s:%d. sshTermy tippt diese Zeilen sichtbar ein:"), ip, port) +
|
||||
"\n\n " + strings.Join(cmds, "\n ") + "\n\n"
|
||||
if set.Source != cmdset.Builtin {
|
||||
body += fmt.Sprintf(i18n.T("Die Schritte stammen aus dem eigenen Befehlssatz „%s“ (%s), nicht aus sshTermy."), set.Name, cmdsetSource(set)) + "\n"
|
||||
}
|
||||
if !syslogHasPort(set.Syslog.Steps) && port != 514 {
|
||||
body += fmt.Sprintf(i18n.T("Achtung: Dieses Gerät sendet immer an UDP 514, der Empfang läuft auf %d. Port in den Einstellungen auf 514 stellen oder weiterleiten."), port) + "\n"
|
||||
}
|
||||
if a.st.Settings().SyslogPort == 0 {
|
||||
body += fmt.Sprintf(i18n.T("Der Syslog-Empfang wird dabei auf UDP %d eingeschaltet."), port) + "\n"
|
||||
}
|
||||
body += i18n.T("Gespeichert wird am Gerät nichts: dauerhaft mit write memory (bzw. copy run start).") + "\n" +
|
||||
save := "write memory"
|
||||
if set.Syslog.Save != "" {
|
||||
save = set.Syslog.Save
|
||||
}
|
||||
body += fmt.Sprintf(i18n.T("Gespeichert wird am Gerät nichts: dauerhaft mit %s."), save) + "\n" +
|
||||
i18n.T("Läuft eine Firewall auf diesem Rechner, muss sie den UDP-Port durchlassen.")
|
||||
sid := s.id
|
||||
a.modal = confirmModal(i18n.T("Syslog an sshTermy senden"), body, func() tea.Cmd {
|
||||
@@ -83,7 +116,7 @@ func (a *App) askSyslogSetup(s *session) tea.Cmd {
|
||||
_ = a.st.UpdateSettings(func(x *domain.Settings) { x.SyslogPort = port })
|
||||
a.watchTick()
|
||||
}
|
||||
return a.runSyslogSetup(sid, cmds, logscan.SyslogAbort(v))
|
||||
return a.runSyslogSetup(sid, cmds, set.SyslogAbort())
|
||||
})
|
||||
return nil
|
||||
}
|
||||
@@ -157,6 +190,6 @@ func (a *App) syslogSetupMsg(msg tea.Msg) (tea.Cmd, bool) {
|
||||
a.flashErr(i18n.T("Syslog einrichten: ") + m.err.Error())
|
||||
return nil, true
|
||||
}
|
||||
a.flashOK(fmt.Sprintf(i18n.T("Syslog eingerichtet (UDP %d). Mit write memory dauerhaft speichern."), a.st.Settings().SyslogPort))
|
||||
a.flashOK(fmt.Sprintf(i18n.T("Syslog eingerichtet (UDP %d). Dauerhaft erst nach dem Speichern am Gerät."), a.st.Settings().SyslogPort))
|
||||
return nil, true
|
||||
}
|
||||
+11
-1
@@ -961,6 +961,10 @@ func (a *App) updateForm(msg tea.Msg) tea.Cmd {
|
||||
a.confirmDeleteTunnel(a.formTunnel)
|
||||
return nil
|
||||
}
|
||||
if k, ok := msg.(tea.KeyPressMsg); ok && k.String() == "esc" && a.scr == scrCmdSetForm {
|
||||
a.form, a.scr = nil, scrCmdSets
|
||||
return nil
|
||||
}
|
||||
if k, ok := msg.(tea.KeyPressMsg); ok && k.String() == "esc" {
|
||||
a.form = nil
|
||||
a.scr = scrManager
|
||||
@@ -1006,11 +1010,17 @@ func (a *App) updateForm(msg tea.Msg) tea.Cmd {
|
||||
err = a.saveScheduleForm()
|
||||
case scrRulesForm:
|
||||
err = a.saveConfigRules()
|
||||
case scrCmdSetForm:
|
||||
err = a.saveCmdSetForm()
|
||||
}
|
||||
if err != nil {
|
||||
a.form.err = err.Error()
|
||||
return nil
|
||||
}
|
||||
if a.scr == scrCmdSetForm {
|
||||
a.form, a.scr = nil, scrCmdSets
|
||||
return next
|
||||
}
|
||||
a.form = nil
|
||||
a.scr = scrManager
|
||||
if a.returnToTerminal {
|
||||
@@ -1271,7 +1281,7 @@ const dialectAuto = "automatisch"
|
||||
|
||||
func dialectLabels() []string {
|
||||
l := []string{dialectAuto}
|
||||
for _, d := range domain.Dialects {
|
||||
for _, d := range domain.Dialects() {
|
||||
l = append(l, d.Name)
|
||||
}
|
||||
return l
|
||||
|
||||
@@ -748,6 +748,8 @@ func (a *App) palMenuItems() []palItem {
|
||||
look(hide(palToggle(ic("colors"), i18n.T("Farbregeln: Ausgabe einfärben"), a.highlightOn(), "highlight farbregeln einfärben", func() tea.Cmd { return a.toggleHighlight() }))),
|
||||
palItem{group: pgSetLook, menu: "settings", icon: ic("backup"), label: i18n.T("Regeln für Switch-Configs …"), hint: a.configRulesHint(),
|
||||
keys: "config regeln rules compliance prüfen check ntp telnet snmp switch", run: func() tea.Cmd { return a.openConfigRulesForm() }},
|
||||
palItem{group: pgSetLook, menu: "settings", icon: ic("backup"), label: i18n.T("Befehlssätze (Hersteller) …"), hint: a.cmdsetHint(),
|
||||
keys: "befehlssatz befehlssätze hersteller vendor dialekt switch firewall router wlan yaml modell", run: func() tea.Cmd { return a.openCmdSets() }},
|
||||
)
|
||||
iconIdx := -1
|
||||
for i, st := range iconStyles {
|
||||
|
||||
+9
-20
@@ -8,6 +8,7 @@ import (
|
||||
tea "charm.land/bubbletea/v2"
|
||||
|
||||
"github.com/db9979/sshtermy/internal/agent"
|
||||
"github.com/db9979/sshtermy/internal/cmdset"
|
||||
"github.com/db9979/sshtermy/internal/domain"
|
||||
"github.com/db9979/sshtermy/internal/hostinfo"
|
||||
"github.com/db9979/sshtermy/internal/i18n"
|
||||
@@ -115,12 +116,13 @@ func (a *App) profileTick(s *session) {
|
||||
// profileFromSwitch: Die Host-Übersicht hat „show version“ gelesen; was sie
|
||||
// dabei über Hersteller, Modell und Firmware erfahren hat, kommt ins Profil.
|
||||
func (a *App) profileFromSwitch(s *session, v hostinfo.Vendor, sw *hostinfo.Switch) {
|
||||
dia := map[hostinfo.Vendor]string{hostinfo.VendorProCurve: "procurve", hostinfo.VendorArubaCX: "arubaos-cx", hostinfo.VendorCisco: "cisco-ios",
|
||||
hostinfo.VendorJunos: "junos", hostinfo.VendorMikroTik: "routeros", hostinfo.VendorFortiOS: "fortios", hostinfo.VendorUniFi: "unifi"}[v]
|
||||
if dia == "" {
|
||||
if v == hostinfo.VendorUnknown {
|
||||
return
|
||||
}
|
||||
fresh := domain.SystemProfile{Family: domain.FamilyNetwork, OS: v.Name(), Dialect: dia}
|
||||
if _, ok := cmdset.Lookup(string(v)); !ok {
|
||||
return
|
||||
}
|
||||
fresh := domain.SystemProfile{Family: domain.FamilyNetwork, OS: v.Name(), Dialect: string(v)}
|
||||
if sw != nil {
|
||||
fresh.Model, fresh.Version = sw.Model, sw.Firmware
|
||||
}
|
||||
@@ -130,24 +132,11 @@ func (a *App) profileFromSwitch(s *session, v hostinfo.Vendor, sw *hostinfo.Swit
|
||||
}
|
||||
}
|
||||
|
||||
// hostVendor: Familie für die Host-Übersicht aus dem Profil (spart dort
|
||||
// hostVendor: Befehlssatz für die Host-Übersicht aus dem Profil (spart dort
|
||||
// „show version“ beim ersten Aufruf nicht, aber wählt passende Befehle).
|
||||
func hostVendor(p domain.SystemProfile) hostinfo.Vendor {
|
||||
switch p.Dialect {
|
||||
case "procurve":
|
||||
return hostinfo.VendorProCurve
|
||||
case "arubaos-cx":
|
||||
return hostinfo.VendorArubaCX
|
||||
case "cisco-ios":
|
||||
return hostinfo.VendorCisco
|
||||
case "junos":
|
||||
return hostinfo.VendorJunos
|
||||
case "routeros":
|
||||
return hostinfo.VendorMikroTik
|
||||
case "fortios":
|
||||
return hostinfo.VendorFortiOS
|
||||
case "unifi":
|
||||
return hostinfo.VendorUniFi
|
||||
if set, ok := cmdset.Lookup(p.Dialect); ok && p.Dialect != "network" && domain.FamilyOf(p.Dialect) == domain.FamilyNetwork && set.ID != "" {
|
||||
return hostinfo.Vendor(p.Dialect)
|
||||
}
|
||||
return hostinfo.VendorUnknown
|
||||
}
|
||||
|
||||
@@ -32,8 +32,12 @@ func (a *App) shellBusyKey(s *session, k tea.KeyPressMsg) bool {
|
||||
// Abfragen und Einrichtung starten dort nicht: Befehle hätten eine andere
|
||||
// Bedeutung oder änderten etwas.
|
||||
func configPrompt(p string) bool {
|
||||
l := strings.ToLower(p)
|
||||
return strings.Contains(l, "(config") || strings.Contains(l, "[edit")
|
||||
l := strings.ToLower(strings.TrimSpace(p))
|
||||
if strings.Contains(l, "(config") || strings.Contains(l, "[edit") {
|
||||
return true
|
||||
}
|
||||
// Comware/Huawei: <Name> normal, [Name] bzw. [~Name] in der system-view
|
||||
return strings.HasPrefix(l, "[") && strings.HasSuffix(l, "]") && !strings.ContainsAny(l, "@ ")
|
||||
}
|
||||
|
||||
// cliError: meldet das Gerät einen Fehler in der Ausgabe?
|
||||
|
||||
@@ -294,6 +294,7 @@ func (a *App) commitTeamTake() {
|
||||
return
|
||||
}
|
||||
msg := fmt.Sprintf(i18n.T("Team-Paket übernommen: %d neu, %d aktualisiert"), st.Added, st.Updated)
|
||||
a.storeTeamCmdSets(t.pkg.From, t.pkg.CmdSets) // wirken erst nach Freigabe
|
||||
if t.abo {
|
||||
var have, skip []string
|
||||
for _, it := range t.items {
|
||||
|
||||
@@ -163,6 +163,7 @@ func (a *App) pullLink(l domain.TeamLink, force bool) tea.Cmd {
|
||||
if len(st.AddrChanges) > 0 && a.modal != nil {
|
||||
sum = l.LastSum // gerade ein anderer Dialog offen: beim nächsten Abgleich fragen
|
||||
}
|
||||
a.storeTeamCmdSets(p.From, p.CmdSets) // wirken erst nach Freigabe
|
||||
l.Have, l.LastSum, l.LastErr, l.LastRun = have, sum, "", time.Now().UTC()
|
||||
a.saveLink(l)
|
||||
note := fmt.Sprintf(i18n.T("Team-Ordner „%s“: %d neu, %d aktualisiert, %d entfernt"), l.Name, st.Added, st.Updated, st.Removed) + teamGuardNote(st)
|
||||
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
>_ sshTermy vdev Idee: Dominik Bornhäußer ● KI
|
||||
┌──────────────────────────────────────────────────────────────────────────────────────────────────┐
|
||||
│ Befehlssatz │
|
||||
│ │
|
||||
│ ━━ Befehlssatz ───────────────────────────────────────────────────────────────────────────────── │
|
||||
│ ▌ Kennung posix-eigen │
|
||||
│ │ Name Linux/Unix-Shell (eigen) │
|
||||
│ │ Basiert auf posix │
|
||||
│ │ Familie linux │
|
||||
│ │ Hinweis für die KI │
|
||||
│ │
|
||||
│ ━━ Erkennung (reguläre Ausdrücke, mehrere mit ||) ────────────────────────────────────────────── │
|
||||
│ │ Bildschirm │
|
||||
│ │ Versionsausgabe │
|
||||
│ │ SSH-Kennung │
|
||||
│ │
|
||||
│ ━━ Befehle, die sshTermy tippt (nur lesend) ──────────────────────────────────────────────────── │
|
||||
│ │ Blättern aus │
|
||||
│ │ Version │
|
||||
│ │ System (CPU) │
|
||||
│ │ Speicher │
|
||||
│ │ Ports │
|
||||
│ │ VLANs │
|
||||
│ │ Konfiguration │
|
||||
│ │ Logs │
|
||||
│ │
|
||||
│ ━━ Lesen (reguläre Ausdrücke, eine Klammer = Wert) ───────────────────────────────────────────── │
|
||||
│ │ Firmware │
|
||||
│ │ Modell │
|
||||
│ │ Name │
|
||||
│ │ CPU │
|
||||
│ │ RAM │
|
||||
│ │
|
||||
│ ━━ Syslog einrichten (ändert das Gerät, wird jedes Mal gezeigt) ──────────────────────────────── │
|
||||
│ │ Schritte │
|
||||
│ │ Speichern mit │
|
||||
│ │
|
||||
│ ━━ Zusätzliche Gefahrenregel (nur ergänzen) ──────────────────────────────────────────────────── │
|
||||
│ │ Muster │
|
||||
Tab weiter ←/→ wählen Strg+S speichern Esc abbrechen
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
>_ sshTermy vdev Idea: Dominik Bornhäußer ● AI
|
||||
┌──────────────────────────────────────────────────────────────────────────────────────────────────┐
|
||||
│ Command set │
|
||||
│ │
|
||||
│ ━━ Command set ───────────────────────────────────────────────────────────────────────────────── │
|
||||
│ ▌ ID posix-eigen │
|
||||
│ │ Name Linux/Unix-Shell (own) │
|
||||
│ │ Based on posix │
|
||||
│ │ Family linux │
|
||||
│ │ Hint for the AI │
|
||||
│ │
|
||||
│ ━━ Detection (regular expressions, several with ||) ──────────────────────────────────────────── │
|
||||
│ │ Screen │
|
||||
│ │ Version output │
|
||||
│ │ SSH ID │
|
||||
│ │
|
||||
│ ━━ Commands sshTermy types (read-only) ───────────────────────────────────────────────────────── │
|
||||
│ │ Paging off │
|
||||
│ │ Version │
|
||||
│ │ System (CPU) │
|
||||
│ │ Memory │
|
||||
│ │ Ports │
|
||||
│ │ VLANs │
|
||||
│ │ Configuration │
|
||||
│ │ Logs │
|
||||
│ │
|
||||
│ ━━ Reading (regular expressions, one group = value) ──────────────────────────────────────────── │
|
||||
│ │ Firmware │
|
||||
│ │ Model │
|
||||
│ │ Name │
|
||||
│ │ CPU │
|
||||
│ │ RAM │
|
||||
│ │
|
||||
│ ━━ Set up syslog (changes the device, shown every time) ──────────────────────────────────────── │
|
||||
│ │ steps │
|
||||
│ │ Save with │
|
||||
│ │
|
||||
│ ━━ Extra danger rule (add only) ──────────────────────────────────────────────────────────────── │
|
||||
│ │ Pattern │
|
||||
Tab next ←/→ select Ctrl+S save Esc cancel
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
>_ sshTermy vdev Idee: Dominik Bornhäußer ● KI
|
||||
▤ Befehlssätze · was sshTermy je Hersteller tippt, liest und der KI sagt
|
||||
|
||||
Eigene Sätze liegen in ~/.config/sshtermy/befehlssaetze.
|
||||
Sie können eingebaute Gefahrenregeln nur ergänzen, tippen nur Lesebefehle und erkennen ein Gerät erst, wenn
|
||||
kein eingebauter Satz passt.
|
||||
|
||||
▸ Linux/Unix-Shell posix eingebaut aktiv
|
||||
macOS macos eingebaut aktiv
|
||||
BSD bsd eingebaut aktiv
|
||||
Windows PowerShell powershell eingebaut aktiv
|
||||
Windows cmd.exe cmd eingebaut aktiv
|
||||
Proxmox VE proxmox eingebaut aktiv
|
||||
VMware ESXi esxi eingebaut aktiv
|
||||
Synology DSM synology eingebaut aktiv
|
||||
QNAP QTS / QuTS qnap eingebaut aktiv
|
||||
TrueNAS truenas eingebaut aktiv
|
||||
pfSense pfsense eingebaut aktiv
|
||||
OPNsense opnsense eingebaut aktiv
|
||||
Ubiquiti EdgeOS (EdgeRouter) edgeos eingebaut aktiv
|
||||
VyOS vyos eingebaut aktiv
|
||||
UniFi-Switch (Ubiquiti) unifi eingebaut aktiv
|
||||
Aruba Mobility Controller (AOS 8) aruba-mobility eingebaut aktiv
|
||||
Aruba Instant (IAP) aruba-instant eingebaut aktiv
|
||||
ArubaOS-CX arubaos-cx eingebaut aktiv
|
||||
Cisco WLC (AireOS) cisco-wlc eingebaut aktiv
|
||||
Cisco ASA cisco-asa eingebaut aktiv
|
||||
Cisco NX-OS (Nexus) cisco-nxos eingebaut aktiv
|
||||
Cisco IOS / IOS-XE cisco-ios eingebaut aktiv
|
||||
|
||||
|
||||
|
||||
|
||||
⏎ Details n neu t am Gerät testen k KI-Entwurf l Korrekturen x export i import Esc zurück
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
>_ sshTermy vdev Idea: Dominik Bornhäußer ● AI
|
||||
▤ Command sets · what sshTermy types, reads and tells the AI for each vendor
|
||||
|
||||
Own sets live in ~/.config/sshtermy/befehlssaetze.
|
||||
They can only add to built-in danger rules, only type read commands and only detect a device when no built-
|
||||
in set matches.
|
||||
|
||||
▸ Linux/Unix shell posix built in active
|
||||
macOS macos built in active
|
||||
BSD bsd built in active
|
||||
Windows PowerShell powershell built in active
|
||||
Windows cmd.exe cmd built in active
|
||||
Proxmox VE proxmox built in active
|
||||
VMware ESXi esxi built in active
|
||||
Synology DSM synology built in active
|
||||
QNAP QTS / QuTS qnap built in active
|
||||
TrueNAS truenas built in active
|
||||
pfSense pfsense built in active
|
||||
OPNsense opnsense built in active
|
||||
Ubiquiti EdgeOS (EdgeRouter) edgeos built in active
|
||||
VyOS vyos built in active
|
||||
UniFi switch (Ubiquiti) unifi built in active
|
||||
Aruba Mobility Controller (AOS 8) aruba-mobility built in active
|
||||
Aruba Instant (IAP) aruba-instant built in active
|
||||
ArubaOS-CX arubaos-cx built in active
|
||||
Cisco WLC (AireOS) cisco-wlc built in active
|
||||
Cisco ASA cisco-asa built in active
|
||||
Cisco NX-OS (Nexus) cisco-nxos built in active
|
||||
Cisco IOS / IOS-XE cisco-ios built in active
|
||||
|
||||
|
||||
|
||||
|
||||
⏎ Details n new t test on device k AI draft l corrections x export i import Esc back
|
||||
+1
-1
@@ -22,7 +22,7 @@
|
||||
│ [/] Netzwerk & Switches › Gerät finden, Topologie 2 │
|
||||
│ [&] Team & Teilen › live teilen, Team-Ordner 4 │
|
||||
│ [=] Verbindungen & Schlüssel › Manager, neu, SSH-Key, Protokolle 5 │
|
||||
│ [:] Einstellungen › Maus, Aussehen, Sprache, KI … 37 │
|
||||
│ [:] Einstellungen › Maus, Aussehen, Sprache, KI … 38 │
|
||||
│ │
|
||||
│ ↑↓ wählen ⏎ ausführen Esc schließen │
|
||||
└──────────────────────────────────────────────────────────────────────────┘
|
||||
|
||||
+1
-1
@@ -22,7 +22,7 @@
|
||||
│ [/] Network & switches › find device, topology 2 │
|
||||
│ [&] Team & sharing › live sharing, team folders 4 │
|
||||
│ [=] Connections & keys › manager, new, SSH key, logs 5 │
|
||||
│ [:] Settings › mouse, look, language, AI … 37 │
|
||||
│ [:] Settings › mouse, look, language, AI … 38 │
|
||||
│ │
|
||||
│ ↑↓ select ⏎ run Esc close │
|
||||
└──────────────────────────────────────────────────────────────────────────┘
|
||||
|
||||
@@ -72,6 +72,7 @@ func (a *App) updateUnlock(msg tea.Msg) tea.Cmd {
|
||||
a.startDebugLog()
|
||||
a.startAudit()
|
||||
a.startMCP()
|
||||
a.loadCmdSets()
|
||||
a.mgr = newManager()
|
||||
a.showWhatsNew(u.setup)
|
||||
a.maybeTour(u.setup)
|
||||
|
||||
+2
-1
@@ -134,7 +134,7 @@ sudo apt update && sudo apt install sshtermy</pre></div>
|
||||
<div class="card"><h3>Farbregeln</h3><p>Fehler rot, Warnungen gelb, IP blau, MAC lila, Switch-Syslog nach Schwere; eigene Regeln, mit <code>!</code> meldet sich ein verdeckter Tab.</p></div>
|
||||
<div class="card"><h3>Bilder im Terminal</h3><p>Sixel, kitty-Grafik und iTerm2-Bilder (img2sixel, icat, viu, imgcat) als farbige Halbblöcke, in jedem Terminal; in kitty, Ghostty und im eigenen Fenster pixelgenau.</p></div>
|
||||
<div class="card"><h3>Container</h3><p>Docker, Podman und Kubernetes-Pods in einer Liste: Shell im Container, Logs live, KI-Auswertung der Logs.</p></div>
|
||||
<div class="card"><h3>Host-Übersicht (F6)</h3><p>CPU, Last, RAM, alle Platten und Updates bei Servern, Live-Graphen aus Braille-Punkten über 5 min oder 1 h mit Top-Prozessen; Firmware, Ports und VLANs bei Aruba, Cisco, Juniper, MikroTik, FortiGate und UniFi-Switches, mit Konfig-Sicherung und Diff.</p></div>
|
||||
<div class="card"><h3>Host-Übersicht (F6)</h3><p>CPU, Last, RAM, alle Platten und Updates bei Servern, Live-Graphen aus Braille-Punkten über 5 min oder 1 h mit Top-Prozessen; Firmware, Ports und VLANs bei über 35 Switch-, Router- und Firewall-Systemen, mit Konfig-Sicherung und Diff.</p></div>
|
||||
<div class="card"><h3>Tunnel</h3><p><code>-L</code>, <code>-R</code>, <code>-D</code> (SOCKS5) und Webdienste mit einem Klick.</p></div>
|
||||
<div class="card"><h3>Broadcast</h3><p>Ein Befehl oder Runbook parallel auf einer ganzen Gruppe, je Host eine Kachel: grün wenn fertig, rot bei Fehler, pulsierend solange er läuft. Änderungen laufen erst auf einem Host als Probelauf und stoppen nach 3 Fehlern.</p></div>
|
||||
<div class="card"><h3>Live teilen</h3><p>Kollegen sehen einen Tab live über den eigenen Vermittler mit, Ende-zu-Ende verschlüsselt, der Schlüssel steht nur im Link.</p></div>
|
||||
@@ -150,6 +150,7 @@ sudo apt update && sudo apt install sshtermy</pre></div>
|
||||
<div class="card"><h3>Logwache & Ordner-Scan</h3><p>Folgt im Hintergrund den Logs offener Tabs und meldet nur neue oder kritische Muster; empfängt Syslog von Switches und Firewalls. Der Ordner-Scan prüft alle Hosts eines Ordners auf einmal (auch nachts als Zeitplan) und zeigt, was mehrere gemeinsam haben. <kbd>s</kbd> im Log-Blick eines Switches richtet Syslog an sshTermy ein.</p></div>
|
||||
<div class="card"><h3>Sync</h3><p>Ende-zu-Ende-verschlüsselt über OneDrive, Dropbox, iCloud, Syncthing oder WebDAV (Synology, Nextcloud).</p></div>
|
||||
<div class="card"><h3>Systemprofil</h3><p>Kennt Linux-Distributionen, macOS, Windows und Netzwerk-Dialekte (Aruba, Cisco, Juniper, MikroTik, FortiGate, UniFi …), damit die KI passende Befehle vorschlägt.</p></div>
|
||||
<div class="card"><h3>Befehlssätze</h3><p>48 Befehlssätze eingebaut (Cisco, Arista, Aruba, Comware, Huawei, Dell, Extreme, Ruckus, Palo Alto, Sophos, FortiGate, pfSense, Proxmox …). Eigene als YAML ergänzen, am Gerät testen oder von der KI entwerfen lassen; eigene und Team-Sätze können die eingebauten Sicherheitsregeln nie abschwächen.</p></div>
|
||||
<div class="card"><h3>KI-Begleiter</h3><p>Liest mit und kommentiert von selbst: leise (Fehler, riskante Zeilen vor Enter, Wiederholungen), gesprächig (jeder Befehl) oder Coach (erkennt dein Ziel, Rückblick mit Runbook). Eigene KI-Server, auch extern, lassen sich eintragen.</p></div>
|
||||
<div class="card"><h3>Agent- & Plan-Modus</h3><p>Die KI arbeitet selbstständig aufs Ziel hin, legt Skripte an und führt sie aus; drei Stufen, gefährliche Schritte warten immer auf dich. Erst planen: den ganzen Plan prüfen und freigeben.</p></div>
|
||||
<div class="card"><h3>Geteilte Ansicht & Tabs</h3><p>Sieben Aufteilungen mit bis zu sechs Sitzungen, Zoom, Tauschen, Eingabe an alle; Tab-Leiste mit <code>+</code>, <code>×</code>, Rechtsklick-Menü und Tab-Liste (<kbd>Alt</kbd>+<kbd>T</kbd>).</p></div>
|
||||
|
||||
Binary file not shown.
Binary file not shown.
+2
-1
@@ -134,7 +134,7 @@ sudo apt update && sudo apt install sshtermy</pre></div>
|
||||
<div class="card"><h3>Color rules</h3><p>Errors red, warnings yellow, IP blue, MAC purple, switch syslog by severity; your own rules, with <code>!</code> a hidden tab notifies you.</p></div>
|
||||
<div class="card"><h3>Images in the terminal</h3><p>Sixel, kitty graphics and iTerm2 images (img2sixel, icat, viu, imgcat) as colored half blocks, in any terminal; pixel-perfect in kitty, Ghostty and sshTermy's own window.</p></div>
|
||||
<div class="card"><h3>Containers</h3><p>Docker, Podman and Kubernetes pods in one list: shell in the container, live logs, AI log analysis.</p></div>
|
||||
<div class="card"><h3>Host overview (F6)</h3><p>CPU, load, RAM, every disk and updates for servers, live Braille graphs over 5 min or 1 h with top processes; firmware, ports and VLANs for Aruba, Cisco, Juniper, MikroTik, FortiGate and UniFi switches, with config backup and diff.</p></div>
|
||||
<div class="card"><h3>Host overview (F6)</h3><p>CPU, load, RAM, every disk and updates for servers, live Braille graphs over 5 min or 1 h with top processes; firmware, ports and VLANs for more than 35 switch, router and firewall systems, with config backup and diff.</p></div>
|
||||
<div class="card"><h3>Tunnels</h3><p><code>-L</code>, <code>-R</code>, <code>-D</code> (SOCKS5) and web services with one click.</p></div>
|
||||
<div class="card"><h3>Broadcast</h3><p>One command or runbook on a whole group in parallel, one tile per host: green when done, red on failure, pulsing while running. Changes run on one host first as a trial run and stop after 3 failures.</p></div>
|
||||
<div class="card"><h3>Share live</h3><p>Colleagues watch a tab live through your own relay, end-to-end encrypted, the key is only in the link.</p></div>
|
||||
@@ -150,6 +150,7 @@ sudo apt update && sudo apt install sshtermy</pre></div>
|
||||
<div class="card"><h3>Log watch & folder scan</h3><p>Follows the logs of open tabs in the background and reports only new or critical patterns; receives syslog from switches and firewalls. The folder scan checks every host of a folder at once (also nightly as a schedule) and shows what several hosts share. <kbd>s</kbd> in a switch's log view sets up syslog to sshTermy.</p></div>
|
||||
<div class="card"><h3>Sync</h3><p>End-to-end encrypted via OneDrive, Dropbox, iCloud, Syncthing or WebDAV (Synology, Nextcloud).</p></div>
|
||||
<div class="card"><h3>System profile</h3><p>Knows Linux distributions, macOS, Windows and network OS dialects (Aruba, Cisco, Juniper, MikroTik, FortiGate, UniFi …), so the AI suggests matching commands.</p></div>
|
||||
<div class="card"><h3>Command sets</h3><p>48 command sets built in (Cisco, Arista, Aruba, Comware, Huawei, Dell, Extreme, Ruckus, Palo Alto, Sophos, FortiGate, pfSense, Proxmox …). Add your own as YAML, test it on the device or let the AI draft it; own and team sets can never weaken the built-in safety rules.</p></div>
|
||||
<div class="card"><h3>AI companion</h3><p>Reads along and comments on its own: quiet (errors, risky lines before Enter, repeats), chatty (every command) or coach (spots your goal, recap with runbook). Your own AI servers, also external, can be registered.</p></div>
|
||||
<div class="card"><h3>Agent & plan mode</h3><p>The AI works towards a goal on its own, writes and runs scripts; three levels, dangerous steps always wait for you. Plan first: review and approve the whole plan.</p></div>
|
||||
<div class="card"><h3>Split view & tabs</h3><p>Seven layouts with up to six sessions, zoom, swap, type into all; tab bar with <code>+</code>, <code>×</code>, right-click menu and tab list (<kbd>Alt</kbd>+<kbd>T</kbd>).</p></div>
|
||||
|
||||
@@ -137,7 +137,7 @@ export const de = {
|
||||
['_tippen_ ⏎ / Tab', 'filtern · als Ziel starten / KI fragen'],
|
||||
['user@host', 'schnell verbinden (auch telnet, COM3, winrm)'],
|
||||
['→ / ←', 'Ordner › öffnen · ‹ Wert › weiter / zurück'],
|
||||
['„log“ / „farb“', 'KI wertet Ausgabe aus / Farbregeln'],
|
||||
['„log“ / „befehl“', 'Ausgabe auswerten / Befehlssätze'],
|
||||
['MAC, IP / „topo“', 'Switch-Port finden / Topologie'],
|
||||
['Esc', 'Ordner zurück / schließen'],
|
||||
]},
|
||||
@@ -332,7 +332,7 @@ export const en = {
|
||||
['_type_ ⏎ / Tab', 'filter · start as goal / ask AI'],
|
||||
['user@host', 'quick connect (also telnet, COM3, winrm)'],
|
||||
['→ / ←', 'open folder › · ‹ value › next / back'],
|
||||
['“log” / “color”', 'AI analyzes output / color rules'],
|
||||
['“log” / “vendor”', 'AI analyzes output / command sets'],
|
||||
['MAC, IP / “topo”', 'find switch port / topology'],
|
||||
['Esc', 'back from folder / close'],
|
||||
]},
|
||||
|
||||
Reference in new issue
Block a user