You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
64 lines
2.0 KiB
64 lines
2.0 KiB
package configure
|
|
|
|
// Copyright (c) 2025 Robert Strutts <bobs@NewToFaith.com>
|
|
// License: MIT
|
|
// GIT: https://git.mysnippetsofcode.com/bobs/execguard
|
|
|
|
import (
|
|
"os"
|
|
"gopkg.in/yaml.v3"
|
|
"fmt"
|
|
)
|
|
|
|
const (
|
|
MaxSizeMB = 10
|
|
Backups = 5
|
|
tsFmt = "2006-01-02 15:04:05"
|
|
)
|
|
|
|
type LoggingConfig struct {
|
|
FilePath string `yaml:"filePath"`
|
|
MaxSizeMB int `yaml:"maxSizeMB"`
|
|
Backups int `yaml:"backups"`
|
|
CompressBackups bool `yaml:"compressBackups"`
|
|
TimestampFormat string `yaml:"timestampFormat"`
|
|
}
|
|
|
|
type Config struct {
|
|
Logging LoggingConfig `yaml:"logging"`
|
|
DbFile string `yaml:"db_file"` // optional DB File
|
|
MailProg string `yaml:"mail_prog"` // optional Mail Program
|
|
ScannerProg string `yaml:"scanner_prog"` // optional Virus Scanner Program
|
|
ProtectedDirs []string `yaml:"protected_dirs"`
|
|
Downloads []string `yaml:"downloads"`
|
|
AlertEmail string `yaml:"alert_email"` // optional root@localhost
|
|
SkipDirs []string `yaml:"skip_dirs"`
|
|
ScanInterval int `yaml:"scan_interval"` // in minutes, 0 disables scan
|
|
Passphrase string `yaml:"passphrase"` // optional hash encryption key
|
|
HashEncryption string `yaml:"hash_encryption"` // "none", "xor", or "xxtea"
|
|
HashType string `yaml:"hash_type"` // "sha256" or "sha512"
|
|
}
|
|
|
|
func LoadConfig(configFile string, logFile string) (*Config, error) {
|
|
data, err := os.ReadFile(configFile)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
var cfg Config
|
|
if err := yaml.Unmarshal(data, &cfg); err != nil {
|
|
return nil, fmt.Errorf("failed to parse config: %v", err)
|
|
}
|
|
if cfg.Logging.FilePath == "" {
|
|
cfg.Logging.FilePath = logFile
|
|
}
|
|
if cfg.Logging.MaxSizeMB == 0 {
|
|
cfg.Logging.MaxSizeMB = MaxSizeMB
|
|
}
|
|
if cfg.Logging.Backups == 0 {
|
|
cfg.Logging.Backups = Backups
|
|
}
|
|
if cfg.Logging.TimestampFormat == "" {
|
|
cfg.Logging.TimestampFormat = tsFmt
|
|
}
|
|
return &cfg, nil
|
|
}
|
|
|