fd7361aa14
- go.mod replace directive for git.tukangketik.id/swanadiva/hostkeeper → ../../v1 - store/ package: JSON file persistence for hosts, snippets, keys, settings (~/Library/Application Support/hostkeeper/v2/) - model SSH fields: Hostname, Port, Username, AuthType, Password, KeyID - sshconn/ package: real SSH client via golang.org/x/crypto/ssh - Terminal WS: real SSH connection with fallback to mock shell - Dynamic host list in terminal (server-rendered JSON script tag) - All mock data defaults removed from model packages - Settings persist via store/settings.go
46 lines
1.3 KiB
Go
46 lines
1.3 KiB
Go
package handler
|
|
|
|
import (
|
|
"github.com/gofiber/fiber/v2"
|
|
"git.tukangketik.id/swanadiva/hostkeeper/v2/internal/model"
|
|
"git.tukangketik.id/swanadiva/hostkeeper/v2/internal/store"
|
|
)
|
|
|
|
var deviceStore = model.NewDeviceStore()
|
|
var settingsStore = store.NewSettingsStore()
|
|
|
|
func Settings(c *fiber.Ctx) error {
|
|
return c.Render("settings", fiber.Map{
|
|
"View": "settings",
|
|
"Title": "Settings",
|
|
"Config": settingsStore.Get(),
|
|
"Devices": deviceStore.All(),
|
|
"NavItems": navItems,
|
|
})
|
|
}
|
|
|
|
func UpdateConfig(c *fiber.Ctx) error {
|
|
cfg := settingsStore.Get()
|
|
if v := c.FormValue("theme"); v != "" { cfg.Theme = v }
|
|
if v := c.FormValue("fontSize"); v != "" { cfg.FontSize = parseInt(v, 14) }
|
|
if v := c.FormValue("scrollback"); v != "" { cfg.Scrollback = parseInt(v, 5000) }
|
|
if v := c.FormValue("autoLock"); v != "" { cfg.AutoLock = parseInt(v, 5) }
|
|
cfg.Keepalive = c.FormValue("keepalive") == "on"
|
|
cfg.CopyOnSelect = c.FormValue("copyOnSelect") == "on"
|
|
cfg.BellEnabled = c.FormValue("bellEnabled") == "on"
|
|
cfg.AutoReconnect = c.FormValue("autoReconnect") == "on"
|
|
cfg.BlinkCursor = c.FormValue("blinkCursor") == "on"
|
|
settingsStore.Update(cfg)
|
|
return c.Redirect("/settings", 303)
|
|
}
|
|
|
|
func parseInt(s string, def int) int {
|
|
i := 0
|
|
for _, c := range s {
|
|
if c < '0' || c > '9' { return def }
|
|
i = i*10 + int(c-'0')
|
|
}
|
|
if i == 0 { return def }
|
|
return i
|
|
}
|