-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Expand file tree
/
Copy pathmain_cli.go
More file actions
67 lines (57 loc) · 1.64 KB
/
Copy pathmain_cli.go
File metadata and controls
67 lines (57 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
//go:build !web
package main
import (
"context"
"os"
"os/signal"
"syscall"
"github.com/shadow1ng/fscan/common"
"github.com/shadow1ng/fscan/common/debug"
"github.com/shadow1ng/fscan/common/i18n"
"github.com/shadow1ng/fscan/core"
// 导入统一插件系统
_ "github.com/shadow1ng/fscan/plugins/local"
_ "github.com/shadow1ng/fscan/plugins/services"
_ "github.com/shadow1ng/fscan/plugins/web"
)
func main() {
// 启动 pprof(仅调试版本)
debug.Start()
defer debug.Stop()
// 解析命令行参数
var info common.HostInfo
if err := common.Flag(&info); err != nil {
if err == common.ErrShowHelp {
os.Exit(0) // 显示帮助是正常退出
}
common.LogError(i18n.Tr("param_error", err))
os.Exit(1)
}
// 检查参数互斥性
if err := common.ValidateExclusiveParams(&info); err != nil {
common.LogError(i18n.Tr("error_generic", err))
os.Exit(1)
}
// 统一初始化:解析 → 配置 → 输出
result, err := common.Initialize(&info)
if err != nil {
common.LogError(i18n.Tr("init_failed", err))
os.Exit(1)
}
// 设置信号处理,确保 Ctrl+C 时能正确保存结果
sigChan := make(chan os.Signal, 1)
signal.Notify(sigChan, os.Interrupt, syscall.SIGTERM)
go func() {
<-sigChan
common.LogInfo(i18n.GetText("received_exit_signal"))
_ = common.Cleanup() // 确保结果写入磁盘
os.Exit(130) // 128 + SIGINT(2) = 130,标准的中断退出码
}()
defer func() { _ = common.Cleanup() }()
defer common.CloseLogger()
// 执行扫描
if _, err := core.RunScan(context.Background(), *result.Info, result.Session); err != nil {
common.LogError(i18n.Tr("error_generic", err))
os.Exit(1)
}
}