move plugin safety metadata to registry

This commit is contained in:
ZacharyZcR
2026-05-18 15:57:18 +08:00
parent d4ed0867c9
commit 3dde0c6a8e
5 changed files with 52 additions and 32 deletions
+33 -1
View File
@@ -43,7 +43,7 @@ const (
type Result struct {
Type ResultType
Success bool
Skipped bool // 扫描被跳过,不应输出结果
Skipped bool // 扫描被跳过,不应输出结果
Service string
Username string
Password string
@@ -84,6 +84,7 @@ type PluginInfo struct {
factory func() Plugin
ports []int
types []string // 插件类型标签
safe bool // 是否适合默认嵌入式扫描
}
// 插件类型常量
@@ -123,12 +124,23 @@ func RegisterWithPorts(name string, factory func() Plugin, ports []int) {
// RegisterWithTypes 注册带类型标签的插件
func RegisterWithTypes(name string, factory func() Plugin, ports []int, types []string) {
RegisterWithOptions(name, factory, ports, types, !hasPluginType(types, PluginTypeLocal))
}
// RegisterUnsafeWithTypes 注册不适合默认嵌入式扫描的插件。
func RegisterUnsafeWithTypes(name string, factory func() Plugin, ports []int, types []string) {
RegisterWithOptions(name, factory, ports, types, false)
}
// RegisterWithOptions 注册带完整元数据的插件。
func RegisterWithOptions(name string, factory func() Plugin, ports []int, types []string, safe bool) {
mutex.Lock()
defer mutex.Unlock()
plugins[name] = &PluginInfo{
factory: factory,
ports: ports,
types: types,
safe: safe,
}
}
@@ -147,6 +159,17 @@ func HasType(pluginName string, typeName string) bool {
return false
}
// IsSafe 检查插件是否适合默认嵌入式扫描。
func IsSafe(pluginName string) bool {
mutex.RLock()
defer mutex.RUnlock()
if info, exists := plugins[pluginName]; exists {
return info.safe
}
return false
}
// Get 获取插件实例
func Get(name string) Plugin {
mutex.RLock()
@@ -190,6 +213,15 @@ func GetPluginPorts(name string) []int {
return []int{} // 返回空列表表示适用于所有端口
}
func hasPluginType(types []string, typeName string) bool {
for _, t := range types {
if t == typeName {
return true
}
}
return false
}
// GenerateCredentials 生成测试凭据
func GenerateCredentials(service string, config *common.Config) []Credential {
var credentials []Credential