fscan/common/globals.go
ZacharyZcR 72b44429ba cleanup: 移除空的SyncToCore函数,消除死代码
清理内容:
- 删除空实现的SyncToCore函数及其调用
- 移除flag.go和parse.go中的无用同步调用
- 简化初始化流程,去除不必要的抽象层

代码健康改进:
- 减少3处死代码调用和1个空函数定义
- 符合Linus'删除代码比写代码更重要'原则
- 保持config包的合理架构:Constants→Config→Globals单向流

验证:编译通过,功能正常
2025-09-02 00:17:45 +00:00

175 lines
5.5 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 common
import (
"sync"
"time"
"github.com/shadow1ng/fscan/common/config"
)
/*
globals.go - 全局配置变量
直接定义全局变量消除base包的双重声明。
*/
var (
// =============================================================================
// 核心扫描配置
// =============================================================================
ScanMode string = DefaultScanMode // 扫描模式
ThreadNum int = DefaultThreadNum // 线程数
Timeout int64 = DefaultTimeout // 超时时间
DisablePing bool = false // 禁用ping
LocalMode bool = false // 本地模式
LocalPlugin string // 本地插件选择
AliveOnly bool // 仅存活检测
DisableBrute bool // 禁用暴力破解
MaxRetries int = 3 // 最大重试次数
// =============================================================================
// 认证相关配置
// =============================================================================
Username string // 用户名
Password string // 密码
Domain string // 域
Userdict map[string][]string // 用户字典
Passwords []string // 密码列表
// =============================================================================
// 网络配置
// =============================================================================
HttpProxy string // HTTP代理
Socks5Proxy string // SOCKS5代理
WebTimeout int64 = 5 // Web超时时间
// =============================================================================
// 文件路径
// =============================================================================
SshKeyPath string // SSH密钥路径
PersistenceTargetFile string // Linux持久化目标文件
WinPEFile string // Windows PE文件
// =============================================================================
// 功能开关
// =============================================================================
NoColor bool // 禁用颜色
Silent bool // 静默模式
DisableSave bool // 禁用保存
DisableProgress bool // 禁用进度条
Language string = DefaultLanguage // 语言
LogLevel string = DefaultLogLevel // 日志级别
// =============================================================================
// 高级功能
// =============================================================================
Shellcode string // Shellcode
LocalPluginsList []string // 本地插件列表
DnsLog bool // DNS日志
ForwardShellActive bool // 正向Shell状态
ReverseShellActive bool // 反向Shell状态
Socks5ProxyActive bool // SOCKS5代理状态
// =============================================================================
// 端口和服务映射
// =============================================================================
PortMap map[int][]string // 端口到服务映射
DefaultMap []string // 默认探测器映射
// =============================================================================
// 输出控制
// =============================================================================
Outputfile string = "result.txt" // 输出文件
OutputFormat string = "txt" // 输出格式
ShowProgress bool = true // 显示进度条
StartTime time.Time // 开始时间
ProgressBar interface{} // 进度条实例
OutputMutex sync.Mutex // 输出互斥锁
// =============================================================================
// 计数器
// =============================================================================
End int64 // 结束计数器
Num int64 // 数量计数器
// =============================================================================
// 初始化控制
// =============================================================================
initOnce sync.Once // 确保初始化只执行一次
)
// InitGlobalConfig 初始化全局配置
func InitGlobalConfig() {
initOnce.Do(func() {
// 初始化时间
if StartTime.IsZero() {
StartTime = time.Now()
}
// 初始化映射和切片
if Userdict == nil {
Userdict = make(map[string][]string)
}
if PortMap == nil {
PortMap = make(map[int][]string)
}
if DefaultMap == nil {
DefaultMap = make([]string, 0)
}
if Passwords == nil {
Passwords = make([]string, 0)
}
// 从config模块获取字典和映射
if serviceDict := config.GetGlobalServiceDict(); serviceDict != nil {
Userdict = serviceDict.GetAllUserDicts()
Passwords = serviceDict.GetPasswords()
}
if probeMapping := config.GetGlobalProbeMapping(); probeMapping != nil {
PortMap = probeMapping.GetAllPortMappings()
DefaultMap = probeMapping.GetDefaultProbes()
}
})
}
// init 自动初始化
func init() {
InitGlobalConfig()
}
// POCInfo POC相关信息
type PocInfo struct {
Target string
PocName string
}
var Pocinfo PocInfo
// 版本信息
const version = "2.2.1"
// 日志级别常量
const (
LogLevelAll = "all"
LogLevelError = "error"
LogLevelBase = "base"
LogLevelInfo = "info"
LogLevelSuccess = "success"
LogLevelDebug = "debug"
LogLevelInfoSuccess = "info,success"
LogLevelBaseInfoSuccess = "base,info,success"
)
// LogWithProgress 已在progressmanager.go中定义此处不重复