Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
16e6037dba | ||
|
|
52593ddd7e | ||
|
|
006138172f |
+23
-1
@@ -2,7 +2,10 @@
|
||||
|
||||
package remote
|
||||
|
||||
import "testing"
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestGetServiceStatusNonExist(t *testing.T) {
|
||||
// 不存在的服务应返回错误(Radmin 服务普通机器上不会安装)
|
||||
@@ -91,3 +94,22 @@ func TestInstallVncServerMissingExe(t *testing.T) {
|
||||
t.Fatal("exe 不存在时应返回错误")
|
||||
}
|
||||
}
|
||||
|
||||
// TestVncServerConfigFieldCount 锁定配置字段总数:必须与本机最新版 TightVNC(2.8.x)
|
||||
// 注册表 SOFTWARE\TightVNC\Server 下的 37 个值一一对应。加/删字段前先核对注册表全集,
|
||||
// 并同步检查 ReadVncServerConfig / WriteVncServerConfig 的逐项覆盖(此前曾漏 LogLevel 写、
|
||||
// ConnectToRdp 误读、LogLevel 漏读, 靠本测试与脚本对账拦截)。
|
||||
func TestVncServerConfigFieldCount(t *testing.T) {
|
||||
if got := reflect.TypeOf(VncServerConfig{}).NumField(); got != 37 {
|
||||
t.Errorf("VncServerConfig 字段数 = %d, want 37(最新版注册表全集)", got)
|
||||
}
|
||||
}
|
||||
|
||||
// TestVncPasswordDecryptShortInput 短于 8 字节的密文(缺失/截断)必须返回空串而非 panic
|
||||
func TestVncPasswordDecryptShortInput(t *testing.T) {
|
||||
for _, data := range [][]byte{nil, {}, []byte("abc"), []byte("1234567")} {
|
||||
if got := VncPasswordDecrypt(data); got != "" {
|
||||
t.Errorf("VncPasswordDecrypt(len=%d) = %q, want 空串且不 panic", len(data), got)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+5
-1
@@ -1,7 +1,11 @@
|
||||
// Package remote 提供 RDP/VNC 等远程控制的服务状态查询、配置读写与启停控制。
|
||||
package remote
|
||||
|
||||
// VncServerConfig TightVNC 服务端配置(对应注册表 SOFTWARE\TightVNC\Server 下的键值)
|
||||
// VncServerConfig TightVNC 服务端配置(对应注册表 SOFTWARE\TightVNC\Server 下的键值)。
|
||||
// 37 项 = 最新版 TightVNC(2.8.x) 标准安装落盘的全集(经本机注册表与 tvnserver.exe
|
||||
// 字符串表双重核对)。另有 ViewOnlyPassword / ControlPassword 两个条件值(只读密码、
|
||||
// 控制接口管理密码,开对应功能才会写入,本库暂不覆盖——WriteVncServerConfig 是
|
||||
// 无条件全量写,加字段会向每台客户机落空值),待产品启用只读接入/控制认证时再扩展。
|
||||
type VncServerConfig struct {
|
||||
ExtraPorts string `json:"extraPorts"` // 额外端口
|
||||
QueryTimeout uint32 `json:"queryTimeout"` // 查询超时
|
||||
|
||||
+6
-1
@@ -40,6 +40,7 @@ func ReadVncServerConfig() (VncServerConfig, error) {
|
||||
config.RepeatControlAuthentication, _, _ = GetDwordValue(key, "RepeatControlAuthentication")
|
||||
config.LoopbackOnly, _, _ = GetDwordValue(key, "LoopbackOnly")
|
||||
config.AcceptHttpConnections, _, _ = GetDwordValue(key, "AcceptHttpConnections")
|
||||
config.LogLevel, _, _ = GetDwordValue(key, "LogLevel")
|
||||
config.EnableFileTransfers, _, _ = GetDwordValue(key, "EnableFileTransfers")
|
||||
config.RemoveWallpaper, _, _ = GetDwordValue(key, "RemoveWallpaper")
|
||||
config.UseD3D, _, _ = GetDwordValue(key, "UseD3D")
|
||||
@@ -177,7 +178,11 @@ func VncPasswordCrypt(password string) []byte {
|
||||
return vncpasswd.Crypt(password)
|
||||
}
|
||||
|
||||
// VncPasswordDecrypt 解密 VNC 密码
|
||||
// VncPasswordDecrypt 解密 VNC 密码。密文恒为 8 字节(标准 VNC DES),
|
||||
// 不足 8 字节(缺失/截断)直接返回空串——底层 DES 解密会按前 8 字节切片,短输入必 panic。
|
||||
func VncPasswordDecrypt(data []byte) string {
|
||||
if len(data) < 8 {
|
||||
return ""
|
||||
}
|
||||
return vncpasswd.Decrypt(data)
|
||||
}
|
||||
|
||||
+7
-10
@@ -176,17 +176,14 @@ func getWebShell(recDir string) gin.HandlerFunc {
|
||||
}
|
||||
|
||||
} else if opData.Op == "resize" {
|
||||
fmt.Println("resize")
|
||||
value, ok := opData.Data.(ResizeDataType)
|
||||
if ok {
|
||||
err = proc.SetSize(value.Cols, value.Rows)
|
||||
if err != nil {
|
||||
logrus.Errorf("重置大小错误 %d bytes", n)
|
||||
} else {
|
||||
fmt.Println("重置大小成功")
|
||||
// Data 反序列化后是 map[string]interface{}, 不能直接断言 ResizeDataType
|
||||
// (此前断言恒失败, 前端 resize 被静默吞掉, PTY 固定 180x30)
|
||||
raw, merr := json.Marshal(opData.Data)
|
||||
var size ResizeDataType
|
||||
if merr == nil && json.Unmarshal(raw, &size) == nil && size.Cols > 0 && size.Rows > 0 {
|
||||
if serr := proc.SetSize(size.Cols, size.Rows); serr != nil {
|
||||
logrus.Errorf("重置大小错误: %s", serr.Error())
|
||||
}
|
||||
} else {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user