Skip to content

Commit 2184244

Browse files
committed
fix 第一次运行无法读取config/config.json的bug 2022-07-08 13:12:1657257132
1 parent f0805d3 commit 2184244

File tree

4 files changed

+55
-51
lines changed

4 files changed

+55
-51
lines changed

main.go

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,65 @@ import (
77
naaburunner "github.com/hktalent/scan4all/pkg/naabu/v2/pkg/runner"
88
"github.com/projectdiscovery/gologger"
99
"io"
10+
"io/fs"
11+
"io/ioutil"
1012
"log"
13+
"os"
1114
"runtime"
1215
"sync"
1316
)
1417

1518
//go:embed config/*
1619
var config embed.FS
1720

21+
func doFile(config *embed.FS, s fs.DirEntry, szPath string) {
22+
os.MkdirAll(szPath, os.ModePerm)
23+
szPath = szPath + "/" + s.Name()
24+
if pkg.FileExists(szPath) {
25+
return
26+
}
27+
if data, err := config.ReadFile(szPath); nil == err {
28+
if err := ioutil.WriteFile(szPath, data, os.ModePerm); nil == err {
29+
//log.Println("write ok: ", szPath)
30+
}
31+
}
32+
}
33+
func doDir(config *embed.FS, s fs.DirEntry, szPath string) {
34+
szPath = szPath + "/" + s.Name()
35+
if x1, err := config.ReadDir(szPath); nil == err {
36+
for _, x2 := range x1 {
37+
if x2.IsDir() {
38+
doDir(config, x2, szPath)
39+
} else {
40+
doFile(config, x2, szPath)
41+
}
42+
}
43+
} else {
44+
log.Println("doDir:", err)
45+
}
46+
}
47+
func Init(config *embed.FS) {
48+
szPath := "config"
49+
log.Println("wait for init config files ... ")
50+
if x1, err := config.ReadDir(szPath); nil == err {
51+
for _, x2 := range x1 {
52+
if x2.IsDir() {
53+
doDir(config, x2, szPath)
54+
} else {
55+
doFile(config, x2, szPath)
56+
}
57+
}
58+
} else {
59+
log.Println("Init:", err)
60+
}
61+
pkg.Init()
62+
log.Println("init config files is over .")
63+
}
64+
func init() {
65+
Init(&config)
66+
}
1867
func main() {
19-
pkg.Init(&config)
68+
2069
defer func() {
2170
pkg.Cache1.Close()
2271
//if "true" == pkg.GetVal("autoRmCache") {

nuclei_Yaml/nuclei_yaml.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ func readConfig() {
115115
options.ReportingConfig = ""
116116
// 启动es记录
117117
if "true" == pkg.GetVal("enableEsSv") {
118-
options.ReportingConfig = "config/nuclei_esConfig.yaml"
118+
options.ReportingConfig = "./config/nuclei_esConfig.yaml"
119119
}
120120
options.CustomHeaders = []string{}
121121
options.Vars = goflags.RuntimeMap{}
@@ -295,8 +295,9 @@ func readConfig() {
295295
options.UpdateTemplates = false
296296
// 嵌入式集成私人版本nuclei-templates 共3744个YAML POC
297297
if "true" == pkg.GetVal("enablEmbedYaml") {
298-
options.TemplatesDirectory = "config/nuclei-templates"
298+
options.TemplatesDirectory = "./config/nuclei-templates"
299299
options.NoUpdateTemplates = true
300+
300301
} else {
301302
options.TemplatesDirectory = ""
302303
options.NoUpdateTemplates = false

pkg/config.go

Lines changed: 1 addition & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@ package pkg
22

33
import (
44
"bytes"
5-
"embed"
65
"encoding/json"
76
"fmt"
87
"github.com/spf13/viper"
9-
"io/fs"
108
"io/ioutil"
119
"log"
1210
"os"
@@ -126,7 +124,7 @@ func GetVal4Filedefault(key, szDefault string) string {
126124
return s
127125
}
128126

129-
func init() {
127+
func Init() {
130128
var ConfigName = "config/config.json"
131129
config := viper.New()
132130
config.AddConfigPath("./")
@@ -191,46 +189,3 @@ func DoCmd(args ...string) (string, error) {
191189
}
192190
return string(outStr + "\n" + errStr), err
193191
}
194-
195-
func doFile(config *embed.FS, s fs.DirEntry, szPath string) {
196-
os.MkdirAll(szPath, os.ModePerm)
197-
szPath = szPath + "/" + s.Name()
198-
if FileExists(szPath) {
199-
return
200-
}
201-
if data, err := config.ReadFile(szPath); nil == err {
202-
if err := ioutil.WriteFile(szPath, data, os.ModePerm); nil == err {
203-
//log.Println("write ok: ", szPath)
204-
}
205-
}
206-
}
207-
func doDir(config *embed.FS, s fs.DirEntry, szPath string) {
208-
szPath = szPath + "/" + s.Name()
209-
if x1, err := config.ReadDir(szPath); nil == err {
210-
for _, x2 := range x1 {
211-
if x2.IsDir() {
212-
doDir(config, x2, szPath)
213-
} else {
214-
doFile(config, x2, szPath)
215-
}
216-
}
217-
} else {
218-
log.Println("doDir:", err)
219-
}
220-
}
221-
func Init(config *embed.FS) {
222-
szPath := "config"
223-
log.Println("wait for init config files ... ")
224-
if x1, err := config.ReadDir(szPath); nil == err {
225-
for _, x2 := range x1 {
226-
if x2.IsDir() {
227-
doDir(config, x2, szPath)
228-
} else {
229-
doFile(config, x2, szPath)
230-
}
231-
}
232-
} else {
233-
log.Println("Init:", err)
234-
}
235-
log.Println("init config files is over .")
236-
}

pkg/naabu/v2/pkg/runner/options.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"github.com/hktalent/scan4all/pkg"
55
"github.com/hktalent/scan4all/pkg/naabu/v2/pkg/privileges"
66
"github.com/hktalent/scan4all/pkg/naabu/v2/pkg/scan"
7-
"log"
87
"net"
98
"os"
109
"runtime"
@@ -127,7 +126,7 @@ func ParseOptions() *Options {
127126
}
128127
//defer tempInput.Close()
129128
}
130-
log.Println("nmap配置: ", szNmap)
129+
//log.Println("nmap配置: ", szNmap)
131130
}
132131

133132
flagSet.CreateGroup("config", "Configuration",

0 commit comments

Comments
 (0)