mirror of
https://github.com/shadow1ng/fscan.git
synced 2026-09-23 03:31:53 +08:00
- 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/ 下已无全局状态调用残留
89 lines
1.9 KiB
Go
89 lines
1.9 KiB
Go
package common
|
|
|
|
/*
|
|
output_api.go - 输出系统简化接口
|
|
|
|
提供扫描结果输出的统一API,底层使用output包实现。
|
|
*/
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/shadow1ng/fscan/common/output"
|
|
)
|
|
|
|
// ResultOutput 全局输出管理器
|
|
var ResultOutput *output.Manager
|
|
|
|
// InitOutput 初始化输出系统
|
|
func InitOutput() error {
|
|
fv := GetFlagVars()
|
|
|
|
// 用户通过-no flag禁用保存时,跳过文件初始化避免不必要的资源开销
|
|
if fv.DisableSave {
|
|
return nil
|
|
}
|
|
|
|
outputFile := fv.Outputfile
|
|
outputFormat := fv.OutputFormat
|
|
|
|
if outputFile == "" {
|
|
return fmt.Errorf("output file not specified")
|
|
}
|
|
|
|
var format output.Format
|
|
switch outputFormat {
|
|
case "txt":
|
|
format = output.FormatTXT
|
|
case "json":
|
|
format = output.FormatJSON
|
|
case "csv":
|
|
format = output.FormatCSV
|
|
default:
|
|
return fmt.Errorf("invalid output format: %s", outputFormat)
|
|
}
|
|
|
|
// 如果使用默认文件名但格式不是txt,自动修正扩展名
|
|
if outputFile == "result.txt" && outputFormat != "txt" {
|
|
outputFile = "result." + outputFormat
|
|
}
|
|
|
|
config := output.DefaultManagerConfig(outputFile, format)
|
|
manager, err := output.NewManager(config)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
ResultOutput = manager
|
|
return nil
|
|
}
|
|
|
|
// CloseOutput 关闭输出系统
|
|
func CloseOutput() error {
|
|
if ResultOutput == nil {
|
|
return nil
|
|
}
|
|
return ResultOutput.Close()
|
|
}
|
|
|
|
// SaveResult 保存扫描结果
|
|
func SaveResult(result *output.ScanResult) error {
|
|
if result == nil {
|
|
return nil
|
|
}
|
|
|
|
// 通知Web(无论是否保存文件)
|
|
NotifyResult(map[string]interface{}{
|
|
"type": string(result.Type),
|
|
"target": result.Target,
|
|
"status": result.Status,
|
|
"time": result.Time,
|
|
"details": result.Details,
|
|
})
|
|
|
|
// 用户禁用保存或输出未初始化时,跳过文件保存
|
|
if GetGlobalConfig().Output.DisableSave || ResultOutput == nil {
|
|
return nil
|
|
}
|
|
return ResultOutput.SaveResult(result)
|
|
}
|