主要变更: - RDP 远程桌面:新增 backend/pkg/rdp(RDP 引擎 + credssp/display/rle/trace)、 backend/controller/rdp*(连接/凭证/文件/会话/实时)、frontend RDP 组件与 API - Windows SMB 文件传输:backend/pkg/winsmb - 云账单同步:backend/pkg/billingsync + billing_sync/aliyun_billing,前端账单详情 - Agent CLI Kubernetes 工具:kubernetes_action/get、pod_execute/logs - 服务器导入助手:server_import_helpers、ImportCredentialSettings - 国际化与组件重构(cloud/deploy/monitor/server/system 等多模块) - 清理编译产物二进制:移除 backend/server、backend/agent/bin/aiops-agent-* - .gitignore:新增 backend/agent/ 与 .cache/(避免 334MB go-build 缓存误入库) Co-Authored-By: Claude <noreply@anthropic.com>
86 lines
2.3 KiB
Go
86 lines
2.3 KiB
Go
package controller
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
|
|
"ezops/model"
|
|
"ezops/pkg/crypto"
|
|
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
func (h *ServerHandler) loadImportCredential(id *uint, wantType string) (model.Credential, string, bool, error) {
|
|
return loadImportCredentialByDB(h.db, h.crypt, id, wantType)
|
|
}
|
|
|
|
func (h *CloudSyncHandler) loadImportCredential(id *uint, wantType string) (model.Credential, string, bool, error) {
|
|
return loadImportCredentialByDB(h.db, h.crypt, id, wantType)
|
|
}
|
|
|
|
func loadImportCredentialByDB(db *gorm.DB, crypt *crypto.SecretBox, id *uint, wantType string) (model.Credential, string, bool, error) {
|
|
var cred model.Credential
|
|
if id == nil || *id == 0 {
|
|
return cred, "", false, nil
|
|
}
|
|
if err := db.First(&cred, *id).Error; err != nil {
|
|
return cred, "", false, fmt.Errorf("凭据不存在")
|
|
}
|
|
if cred.SecretType != wantType {
|
|
return cred, "", false, fmt.Errorf("请选择 %s 类型凭据", strings.ToUpper(wantType))
|
|
}
|
|
plain, err := crypt.Decrypt(cred.Content)
|
|
if err != nil {
|
|
return cred, "", false, fmt.Errorf("凭据解密失败")
|
|
}
|
|
return cred, plain, true, nil
|
|
}
|
|
|
|
func normalizeImportOSType(osType, osName string) string {
|
|
raw := strings.ToLower(strings.TrimSpace(osType + " " + osName))
|
|
if strings.Contains(raw, "windows") || strings.Contains(raw, "win") {
|
|
return "windows"
|
|
}
|
|
return "linux"
|
|
}
|
|
|
|
// normalizeServerRemoteAccess 补齐历史导入数据中缺失的 os_type/protocol 字段 // Logan.Li
|
|
func normalizeServerRemoteAccess(server *model.Server) {
|
|
if server == nil {
|
|
return
|
|
}
|
|
if server.OSType != "" && server.Protocol != "" {
|
|
if server.OSType == "windows" && server.Protocol != "rdp" {
|
|
server.Protocol = "rdp"
|
|
}
|
|
if server.Protocol == "rdp" && server.OSType == "" {
|
|
server.OSType = "windows"
|
|
}
|
|
if server.RDPPort == 0 {
|
|
server.RDPPort = 3389
|
|
}
|
|
return
|
|
}
|
|
osType := normalizeImportOSType(server.OSType, server.OS)
|
|
if osType == "windows" {
|
|
server.OSType = "windows"
|
|
server.Protocol = "rdp"
|
|
if server.RDPPort == 0 {
|
|
server.RDPPort = 3389
|
|
}
|
|
return
|
|
}
|
|
if server.OSType == "" {
|
|
server.OSType = "linux"
|
|
}
|
|
if server.Protocol == "" {
|
|
server.Protocol = "ssh"
|
|
}
|
|
}
|
|
|
|
// isRDPServer 判断资产是否应走 RDP 图形会话 // Logan.Li
|
|
func isRDPServer(server model.Server) bool {
|
|
normalizeServerRemoteAccess(&server)
|
|
return server.Protocol == "rdp" || server.OSType == "windows"
|
|
}
|