@@ -30,7 +30,7 @@ const demoConfig = `{
3030const demoPingList = `# 一行一个 ICMP 探测目标,# 是注释,改完重启生效
3131# 格式:host [名称] [pace=fast|slow] [sensitivity=strict|relaxed] [interval=秒] [alerts=false] [自定义k=v]
3232# 例:59.43.247.1 香港CN2 pace=fast sensitivity=strict 机房=GZ1 负责人=张三
33- www.baidu .com 演示·百度 pace=fast
33+ www.google .com Demo·Google pace=fast
3434`
3535
3636// portOf 从监听地址提取给人看的端口后缀。
@@ -44,8 +44,9 @@ func portOf(listen string) string {
4444}
4545
4646func main () {
47- cfgPath := flag .String ("c" , "pingping.jsonc" , "配置文件路径 (JSONC)" )
48- showVer := flag .Bool ("version" , false , "打印版本" )
47+ cfgPath := flag .String ("c" , "pingping.jsonc" , "config file path (JSONC)" )
48+ localOnly := flag .Bool ("localhost" , false , "bind 127.0.0.1 only — put Caddy/Nginx/Apache in front for auth/TLS" )
49+ showVer := flag .Bool ("version" , false , "print version" )
4950 flag .Parse ()
5051
5152 if * showVer {
@@ -55,15 +56,15 @@ func main() {
5556
5657 cfg , err := LoadConfig (* cfgPath )
5758 if err != nil {
58- // 零配置开箱:找不到配置文件时自动生成演示配置(探测 www.baidu .com),
59+ // 零配置开箱:找不到配置文件时自动生成演示配置(探测 www.google .com),
5960 // 下载解压、执行、开浏览器,三十秒看到第一缕烟。
6061 if os .IsNotExist (err ) {
6162 if werr := os .WriteFile (* cfgPath , []byte (demoConfig ), 0o644 ); werr == nil {
6263 os .MkdirAll ("targets" , 0o755 )
6364 if _ , serr := os .Stat ("targets/ping.list" ); os .IsNotExist (serr ) {
6465 os .WriteFile ("targets/ping.list" , []byte (demoPingList ), 0o644 )
6566 }
66- log .Printf ("未找到配置文件,已生成演示配置 %s + targets/ping.list(探测 www.baidu .com)" , * cfgPath )
67+ log .Printf ("未找到配置文件,已生成演示配置 %s + targets/ping.list(探测 www.google .com)" , * cfgPath )
6768 log .Printf ("加监控就一行:echo \" 1.2.3.4 广州电信\" >> targets/ping.list,重启生效" )
6869 cfg , err = LoadConfig (* cfgPath )
6970 }
@@ -73,6 +74,10 @@ func main() {
7374 }
7475 }
7576
77+ if * localOnly {
78+ cfg .Listen = "127.0.0.1" + portOf (cfg .Listen )
79+ }
80+
7681 store , err := NewStore (cfg .DataDir , cfg .Targets )
7782 if err != nil {
7883 log .Fatalf ("存储初始化失败: %v" , err )
0 commit comments