mirror of
https://github.com/shadow1ng/fscan.git
synced 2026-09-22 03:10:42 +08:00
refactor: 清除 core/plugins 全局状态依赖,ProgressManager 缓存引用 (Phase 5)
- core/alive_scanner.go: GetFlagVars() → session.Params - core/service_scanner.go: GetFlagVars() → session.Params 和 config.Target.Ports - common/progress_manager.go: 缓存 State 和 NoColor 到字段,不再运行时读全局 - common/output_api.go: SaveResult 改用 GetGlobalConfig().Output.DisableSave - common/network.go: WrapperTcpWithTimeout 标记 Deprecated - core/ 和 plugins/ 下已无全局状态调用残留
This commit is contained in:
+2
-4
@@ -102,11 +102,9 @@ func createProxyConfig(timeout time.Duration) *proxy.ProxyConfig {
|
||||
// TCP 连接
|
||||
// =============================================================================
|
||||
|
||||
// WrapperTcpWithTimeout TCP连接包装器,带超时
|
||||
// 支持通过代理管理器进行SOCKS5和HTTP代理连接,并集成发包控制
|
||||
// 使用全局拨号器复用连接,避免重复创建代理握手开销
|
||||
// Deprecated: WrapperTcpWithTimeout 仅供 mylib/grdp 兼容使用,新代码请用 ScanSession.DialTCP
|
||||
//
|
||||
//nolint:revive // 保持向后兼容性,避免破坏大量现有代码
|
||||
//nolint:revive
|
||||
func WrapperTcpWithTimeout(network, address string, timeout time.Duration) (net.Conn, error) {
|
||||
// 检查发包限制 - 在代理连接前进行控制
|
||||
if canSend, reason := CanSendPacket(); !canSend {
|
||||
|
||||
@@ -81,7 +81,7 @@ func SaveResult(result *output.ScanResult) error {
|
||||
})
|
||||
|
||||
// 用户禁用保存或输出未初始化时,跳过文件保存
|
||||
if GetFlagVars().DisableSave || ResultOutput == nil {
|
||||
if GetGlobalConfig().Output.DisableSave || ResultOutput == nil {
|
||||
return nil
|
||||
}
|
||||
return ResultOutput.SaveResult(result)
|
||||
|
||||
@@ -48,6 +48,10 @@ type ProgressManager struct {
|
||||
|
||||
// 进度条更新控制(减少 Windows 终端的重复输出)
|
||||
lastRenderedPercent int
|
||||
|
||||
// 引用,避免读全局
|
||||
state *State
|
||||
noColor bool
|
||||
}
|
||||
|
||||
// =============================================================================
|
||||
@@ -102,11 +106,13 @@ func GetProgressManager() *ProgressManager {
|
||||
|
||||
// InitProgress 初始化进度条
|
||||
func (pm *ProgressManager) InitProgress(total int64, description string) {
|
||||
fv := GetFlagVars()
|
||||
if fv.DisableProgress || fv.Silent {
|
||||
cfg := GetGlobalConfig()
|
||||
if cfg.Output.DisableProgress || cfg.Output.Silent {
|
||||
pm.enabled = false
|
||||
return
|
||||
}
|
||||
pm.state = GetGlobalState()
|
||||
pm.noColor = cfg.Output.NoColor
|
||||
|
||||
pm.mu.Lock()
|
||||
defer pm.mu.Unlock()
|
||||
@@ -277,13 +283,16 @@ func (pm *ProgressManager) generateProgressBar() string {
|
||||
|
||||
// getPacketInfo 获取发包统计信息(简化版)
|
||||
func (pm *ProgressManager) getPacketInfo() string {
|
||||
packetCount := GetGlobalState().GetPacketCount()
|
||||
if pm.state == nil {
|
||||
return ""
|
||||
}
|
||||
packetCount := pm.state.GetPacketCount()
|
||||
if packetCount == 0 {
|
||||
return ""
|
||||
}
|
||||
|
||||
tcpSuccess := GetGlobalState().GetTCPSuccessPacketCount()
|
||||
tcpFailed := GetGlobalState().GetTCPFailedPacketCount()
|
||||
tcpSuccess := pm.state.GetTCPSuccessPacketCount()
|
||||
tcpFailed := pm.state.GetTCPFailedPacketCount()
|
||||
|
||||
// 简化格式:TCP:成功/失败
|
||||
if tcpSuccess > 0 || tcpFailed > 0 {
|
||||
@@ -301,7 +310,7 @@ func (pm *ProgressManager) showCompletionInfo() {
|
||||
fmt.Print("\n")
|
||||
|
||||
completionMsg := i18n.GetText("progress_scan_completed")
|
||||
if GetFlagVars().NoColor {
|
||||
if pm.noColor {
|
||||
fmt.Printf("[完成] %s %d/%d (耗时: %s)\n",
|
||||
completionMsg, pm.total, pm.total, formatDuration(elapsed))
|
||||
} else {
|
||||
@@ -532,7 +541,7 @@ func (pm *ProgressManager) renderProgressUnsafe() {
|
||||
fmt.Print(clearStr)
|
||||
|
||||
// 输出进度条(带颜色,如果启用)
|
||||
if GetFlagVars().NoColor {
|
||||
if pm.noColor {
|
||||
fmt.Print(progressBar)
|
||||
} else {
|
||||
fmt.Printf("%s%s%s", AnsiCyan, progressBar, AnsiReset)
|
||||
|
||||
@@ -71,8 +71,7 @@ func (s *AliveScanStrategy) Execute(_ context.Context, session *common.ScanSessi
|
||||
// performAliveScan 执行存活探测
|
||||
func (s *AliveScanStrategy) performAliveScan(info common.HostInfo, session *common.ScanSession) {
|
||||
// 解析目标主机
|
||||
fv := common.GetFlagVars()
|
||||
hosts, err := parsers.ParseIP(info.Host, fv.HostsFile, fv.ExcludeHosts)
|
||||
hosts, err := parsers.ParseIP(info.Host, session.Params.HostsFile, session.Params.ExcludeHosts)
|
||||
if err != nil {
|
||||
common.LogError(i18n.Tr("parse_target_failed", err))
|
||||
return
|
||||
|
||||
@@ -28,7 +28,7 @@ func NewServiceScanStrategy() *ServiceScanStrategy {
|
||||
func (s *ServiceScanStrategy) LogPluginInfo(config *common.Config) {
|
||||
// 需要从命令行参数获取端口信息来进行过滤
|
||||
// 如果没有指定端口,使用默认端口进行过滤显示
|
||||
ports := common.GetFlagVars().Ports
|
||||
ports := config.Target.Ports
|
||||
if ports == "" || ports == "all" {
|
||||
// 默认端口扫描:显示所有插件
|
||||
s.BaseScanStrategy.LogPluginInfo(config)
|
||||
@@ -43,7 +43,7 @@ func (s *ServiceScanStrategy) showPluginsForSpecifiedPorts(config *common.Config
|
||||
allPlugins, isCustomMode := s.GetPlugins(config)
|
||||
|
||||
// 解析端口
|
||||
ports := s.parsePortList(common.GetFlagVars().Ports)
|
||||
ports := s.parsePortList(config.Target.Ports)
|
||||
if len(ports) == 0 {
|
||||
s.BaseScanStrategy.LogPluginInfo(config)
|
||||
return
|
||||
@@ -219,8 +219,7 @@ func (s *ServiceScanStrategy) discoverTargets(hostInput string, baseInfo common.
|
||||
config := session.Config
|
||||
state := session.State
|
||||
// 标准流程:解析目标主机
|
||||
fv := common.GetFlagVars()
|
||||
hosts, err := parsers.ParseIP(hostInput, fv.HostsFile, fv.ExcludeHosts)
|
||||
hosts, err := parsers.ParseIP(hostInput, session.Params.HostsFile, session.Params.ExcludeHosts)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("%s: %w", i18n.GetText("parse_target_failed"), err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user