package config import ( "log/slog" "github.com/spf13/viper" ) func ReadConfigFile(configFile string) { setDefaults() if configFile != "" { slog.Info("reading Config file", "file", configFile) viper.SetConfigFile(configFile) } else { viper.AddConfigPath(".") viper.AddConfigPath("/etc/scanfile/") viper.SetConfigName("config") viper.SetConfigType("toml") } viper.SetEnvPrefix("SF") viper.ReadInConfig() viper.AutomaticEnv() if viper.ConfigFileUsed() == "" { viper.WriteConfigAs("./config.toml") } slog.Info("done reading config", "file", viper.ConfigFileUsed()) } func setDefaults() { // Web viper.SetDefault("web.port", 8080) viper.SetDefault("web.host", "127.0.0.1") viper.SetDefault("web.tls", false) viper.SetDefault("web.cert", "/etc/ssl/certs/ssl-cert-snakeoil.pem") viper.SetDefault("web.key", "/etc/ssl/key/ssl-cert-snakeoil.key") viper.SetDefault("web.loghttp", true) viper.SetDefault("web.maxfilesizemb", 100) viper.SetDefault("web.download.usermax", 5) viper.SetDefault("web.download.anonmax", 1) viper.SetDefault("web.download.disable", false) // Database viper.SetDefault("db.host", "localhost") viper.SetDefault("db.port", 5432) viper.SetDefault("db.user", "scanfile") viper.SetDefault("db.database", "scanfile") viper.SetDefault("db.password", "CHANGEME") viper.SetDefault("db.debug", false) // Others viper.SetDefault("processing.oleurl", "http://localhost:5000") viper.SetDefault("processing.capaurl", "http://localhost:5001") viper.SetDefault("processing.maxmimesize", "100MB") viper.SetDefault("processing.yararules", "./storage/rules") viper.SetDefault("processing.yaracompiled", "./storage/output.yarc") viper.SetDefault("store.path", "./storage/files") viper.SetDefault("debug", false) // UI Interface info viper.SetDefault("ui.name", "Scanfile") viper.SetDefault("ui.byurl", "https://www.jmbit.de") viper.SetDefault("ui.byname", "Johannes Bülow") viper.SetDefault("ui.source", "https://git.jmbit.de/jmb/scanfile") } func SaveConfig() error { return viper.WriteConfig() }