Files
opsx f3733f0bfc feat: 品牌统一 LokiStack + 全站中英 i18n + 用户批量删除 + 主题定时切换与浅色侧栏
- 品牌: Go 模块/数据文件/二进制/构建部署资产全部 opsx→lokistack;前端 localStorage 命名空间迁移(读旧写新,含按用户 id 前缀迁移);修复 nginx upstream 与 Makefile 引用已改名服务的断裂
- i18n: react-i18next 落地,common + 11 个页面域命名空间全站中英(菜单/顶栏/登录/列表页/表单/确认弹窗/状态徽章);设置页语言即时切换;修复词典自注册导致的循环导入白屏
- 用户管理: 批量删除(POST /users/batch-delete,不删自己/最后管理员,部分失败不阻断)+ 行复选/全选/批量工具条
- 主题: 浅色侧栏(中性灰激活态)、四态模式(浅色/深色/跟随系统/定时切换,按时区判定)、顶栏太阳月亮二态、设置页紧凑分段选择器
- UI: 登录记住用户名、CardActionButton 统一五页卡片操作钮、shadcn Badge 替换手写徽章、语义色修正
- 清理: 移除主机 Web 终端(前后端)、k8s-helm/Helm 遗留代码与字段、README 重写精简
- 修复: 侧栏与日志告警 order 重复、路由标题 i18n key 未翻译、词典双逗号等
2026-10-27 17:11:38 +08:00

124 lines
3.3 KiB
Go

package models
import (
"time"
"lokistack/pkg/crypto"
)
// SSHAuthConfig SSH认证配置(定义在models包避免循环导入)
type SSHAuthConfig struct {
Host string
Port int
User string
Password string
PrivateKey string
KeyPhrase string
}
// Host 主机模型,敏感字段(Password/PrivateKey/KeyPhrase)加密存储
// 加密格式: ENC:<base64(AES-GCM(ciphertext))>
type Host struct {
ID uint `json:"id"`
Name string `json:"name"`
HostIP string `json:"hostIP"`
Port int `json:"port"`
User string `json:"user"`
AuthType string `json:"authType"`
Password string `json:"password"` // 加密存储(ENC:前缀)
PrivateKey string `json:"privateKey"` // 加密存储(ENC:前缀)
KeyPhrase string `json:"keyPhrase"` // 加密存储(ENC:前缀)
OS string `json:"os"`
Arch string `json:"arch"`
Status string `json:"status"`
StatusMessage string `json:"statusMessage,omitempty"`
Labels string `json:"labels"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
}
func (h *Host) Sanitized() map[string]interface{} {
return map[string]interface{}{
"id": h.ID,
"name": h.Name,
"hostIP": h.HostIP,
"port": h.Port,
"user": h.User,
"authType": h.AuthType,
"os": h.OS,
"arch": h.Arch,
"status": h.Status,
"statusMessage": h.StatusMessage,
"labels": h.Labels,
"createdAt": h.CreatedAt,
"updatedAt": h.UpdatedAt,
}
}
// DecryptPassword 解密主机密码
func (h *Host) DecryptPassword() string {
return crypto.DecryptField(h.Password)
}
// DecryptPrivateKey 解密SSH私钥
func (h *Host) DecryptPrivateKey() string {
return crypto.DecryptField(h.PrivateKey)
}
// DecryptKeyPhrase 解密私钥密码
func (h *Host) DecryptKeyPhrase() string {
return crypto.DecryptField(h.KeyPhrase)
}
// IsPasswordEncrypted 检查密码是否已加密
func (h *Host) IsPasswordEncrypted() bool {
return crypto.IsEncryptedField(h.Password)
}
// IsPrivateKeyEncrypted 检查私钥是否已加密
func (h *Host) IsPrivateKeyEncrypted() bool {
return crypto.IsEncryptedField(h.PrivateKey)
}
// EncryptAndSetPassword 加密并设置密码
func (h *Host) EncryptAndSetPassword(password string) error {
enc, err := crypto.EncryptField(password)
if err != nil {
return err
}
h.Password = enc
return nil
}
// EncryptAndSetPrivateKey 加密并设置私钥
func (h *Host) EncryptAndSetPrivateKey(privateKey string) error {
enc, err := crypto.EncryptField(privateKey)
if err != nil {
return err
}
h.PrivateKey = enc
return nil
}
// EncryptAndSetKeyPhrase 加密并设置私钥密码
func (h *Host) EncryptAndSetKeyPhrase(keyPhrase string) error {
enc, err := crypto.EncryptField(keyPhrase)
if err != nil {
return err
}
h.KeyPhrase = enc
return nil
}
// GetSSHAuthConfig 获取SSH认证配置(自动解密敏感字段)
func (h *Host) GetSSHAuthConfig() *SSHAuthConfig {
return &SSHAuthConfig{
Host: h.HostIP,
Port: h.Port,
User: h.User,
Password: h.DecryptPassword(),
PrivateKey: h.DecryptPrivateKey(),
KeyPhrase: h.DecryptKeyPhrase(),
}
}