fscan/plugins/local/init.go
ZacharyZcR 4cd8ed5668 feat: 完成本地插件架构统一迁移
迁移所有本地插件到统一Plugin接口架构:
- socks5proxy/systemdservice: 网络代理和Linux服务持久化
- winregistry/winservice/winschtask/winstartup/winwmi: Windows持久化套件
- 所有插件消除BaseLocalPlugin继承,统一使用Plugin接口
- 保持原有功能完整性,支持跨平台编译标记
- 删除过度设计的继承体系,实现直接简洁实现
2025-08-26 14:39:53 +08:00

77 lines
1.8 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package local
import (
"context"
"os"
"strings"
"sync"
"github.com/shadow1ng/fscan/common"
)
// Plugin 本地扫描插件接口 - 统一架构,消除过度设计
//
// Linus哲学"好代码没有特殊情况"
// - 和services、web插件使用完全相同的接口
// - 删除复杂的继承体系和权限检查
// - 让代码直接、简单、清晰
type Plugin interface {
GetName() string
GetPorts() []int // local插件通常返回空数组
Scan(ctx context.Context, info *common.HostInfo) *ScanResult
}
// ScanResult 本地扫描结果 - 简化数据结构
type ScanResult struct {
Success bool
Output string
Error error
}
// 本地插件注册表
var (
localPluginRegistry = make(map[string]func() Plugin)
localPluginMutex sync.RWMutex
)
// RegisterLocalPlugin 注册本地插件
func RegisterLocalPlugin(name string, creator func() Plugin) {
localPluginMutex.Lock()
defer localPluginMutex.Unlock()
localPluginRegistry[name] = creator
}
// GetLocalPlugin 获取指定本地插件
func GetLocalPlugin(name string) Plugin {
localPluginMutex.RLock()
defer localPluginMutex.RUnlock()
if creator, exists := localPluginRegistry[name]; exists {
return creator()
}
return nil
}
// GetAllLocalPlugins 获取所有已注册本地插件的名称
func GetAllLocalPlugins() []string {
localPluginMutex.RLock()
defer localPluginMutex.RUnlock()
var plugins []string
for name := range localPluginRegistry {
plugins = append(plugins, name)
}
return plugins
}
// GetSystemInfo 获取基本系统信息 - 实用工具函数
func GetSystemInfo() string {
var info strings.Builder
// 直接使用os包避免复杂依赖
if hostname, err := os.Hostname(); err == nil {
info.WriteString("Hostname: " + hostname + " ")
}
return strings.TrimSpace(info.String())
}