HellPot/internal/config/defaults.go

95 lines
1.8 KiB
Go
Raw Normal View History

2022-02-07 10:12:02 +00:00
package config
import (
2022-07-26 05:46:04 +00:00
"io"
2022-02-07 10:12:02 +00:00
"os"
2022-09-11 10:04:46 +00:00
"path"
2022-02-07 10:12:02 +00:00
"runtime"
2022-07-26 05:46:04 +00:00
"github.com/spf13/afero"
2022-02-07 10:12:02 +00:00
)
func init() {
2022-05-11 05:55:49 +00:00
var err error
if home, err = os.UserHomeDir(); err != nil {
panic(err)
}
2022-09-11 10:04:46 +00:00
defOpts["logger"]["directory"] = path.Join(home, ".local", "share", Title+"logs")
prefConfigLocation = path.Join(home, ".config", Title)
}
2022-02-07 10:12:02 +00:00
var (
configSections = []string{"logger", "http", "performance", "deception", "ssh"}
defNoColor = false
)
var defOpts = map[string]map[string]interface{}{
"logger": {
"debug": true,
2022-03-06 20:03:36 +00:00
"trace": false,
2022-02-07 10:12:02 +00:00
"nocolor": defNoColor,
"use_date_filename": true,
},
"http": {
"use_unix_socket": false,
"unix_socket_path": "/var/run/hellpot",
"unix_socket_permissions": "0666",
"bind_addr": "127.0.0.1",
"bind_port": "8080",
"router": map[string]interface{}{
"catchall": false,
"makerobots": true,
"paths": []string{
"wp-login.php",
"wp-login",
},
2022-02-07 10:12:02 +00:00
},
"uagent_string_blacklist": []string{
"Cloudflare-Traffic-Manager",
},
2022-02-07 10:12:02 +00:00
},
"performance": {
"restrict_concurrency": false,
"max_workers": 256,
},
"deception": {
"server_name": "nginx",
},
}
2022-07-26 05:46:04 +00:00
func gen(memfs afero.Fs) {
if err := snek.SafeWriteConfigAs("config.toml"); err != nil {
print(err.Error())
os.Exit(1)
}
var f afero.File
var err error
f, err = memfs.Open("config.toml")
if err != nil {
println(err.Error())
os.Exit(1)
}
newcfg, err := io.ReadAll(f)
if err != nil {
println(err.Error())
os.Exit(1)
}
println(string(newcfg))
}
2022-02-07 10:12:02 +00:00
func setDefaults() {
2022-07-26 05:46:04 +00:00
memfs := afero.NewMemMapFs()
//goland:noinspection GoBoolExpressions
2022-02-07 10:12:02 +00:00
if runtime.GOOS == "windows" {
defNoColor = true
}
for _, def := range configSections {
snek.SetDefault(def, defOpts[def])
}
if GenConfig {
2022-07-26 05:46:04 +00:00
snek.SetFs(memfs)
gen(memfs)
2022-02-07 10:12:02 +00:00
}
}