Bots often send commands via `ssh user@host <command>` (exec request) rather than requesting an interactive shell. These were previously rejected silently. Now exec commands are captured, stored on the session record, and displayed in the web UI session detail page. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
82 lines
1.6 KiB
Go
82 lines
1.6 KiB
Go
package web
|
|
|
|
import (
|
|
"embed"
|
|
"fmt"
|
|
"html/template"
|
|
"time"
|
|
)
|
|
|
|
//go:embed templates/*.html templates/fragments/*.html
|
|
var templateFS embed.FS
|
|
|
|
type templateSet struct {
|
|
dashboard *template.Template
|
|
sessionDetail *template.Template
|
|
}
|
|
|
|
func templateFuncMap() template.FuncMap {
|
|
return template.FuncMap{
|
|
"formatTime": func(t time.Time) string {
|
|
return t.Format("2006-01-02 15:04:05 UTC")
|
|
},
|
|
"truncateID": func(id string) string {
|
|
if len(id) > 8 {
|
|
return id[:8]
|
|
}
|
|
return id
|
|
},
|
|
"derefTime": func(t *time.Time) time.Time {
|
|
if t == nil {
|
|
return time.Time{}
|
|
}
|
|
return *t
|
|
},
|
|
"derefFloat": func(f *float64) float64 {
|
|
if f == nil {
|
|
return 0
|
|
}
|
|
return *f
|
|
},
|
|
"formatScore": func(f *float64) string {
|
|
if f == nil {
|
|
return "-"
|
|
}
|
|
return fmt.Sprintf("%.0f%%", *f*100)
|
|
},
|
|
"derefString": func(s *string) string {
|
|
if s == nil {
|
|
return ""
|
|
}
|
|
return *s
|
|
},
|
|
}
|
|
}
|
|
|
|
func loadTemplates() (*templateSet, error) {
|
|
funcMap := templateFuncMap()
|
|
|
|
dashboard, err := template.New("").Funcs(funcMap).ParseFS(templateFS,
|
|
"templates/layout.html",
|
|
"templates/dashboard.html",
|
|
"templates/fragments/stats.html",
|
|
"templates/fragments/active_sessions.html",
|
|
)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("parsing dashboard templates: %w", err)
|
|
}
|
|
|
|
sessionDetail, err := template.New("").Funcs(funcMap).ParseFS(templateFS,
|
|
"templates/layout.html",
|
|
"templates/session_detail.html",
|
|
)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("parsing session detail templates: %w", err)
|
|
}
|
|
|
|
return &templateSet{
|
|
dashboard: dashboard,
|
|
sessionDetail: sessionDetail,
|
|
}, nil
|
|
}
|