- conntrack/event.go: TrafficEvent type - conntrack/filter.go: WG subnet filter, IsExternal, ProtoName - conntrack/subscriber.go: netlink conntrack DESTROY subscriber - writer/log.go: JSON line writer with mutex - resolver/peers.go: WG IP → peer name from conf files + endpoint index - resolver/services.go: IP:port → service name from services.json - config/config.go: reads wgctl.json, sensible defaults - cmd/root.go: CLI flags - main.go: wires everything together - DESTROY events only: full byte/packet counts per connection - filters to WireGuard subnet, marks external traffic
42 lines
No EOL
942 B
Go
42 lines
No EOL
942 B
Go
package config
|
|
|
|
import (
|
|
"encoding/json"
|
|
"os"
|
|
)
|
|
|
|
// Config holds wgctl-conntrack runtime configuration
|
|
type Config struct {
|
|
WGSubnet string
|
|
DataDir string
|
|
ClientsDir string
|
|
AcceptLogFile string
|
|
ServicesFile string
|
|
}
|
|
|
|
type wgctlJSON struct {
|
|
WireGuard struct {
|
|
Subnet string `json:"subnet"`
|
|
} `json:"wireguard"`
|
|
}
|
|
|
|
// Load reads config from wgctl.json and applies defaults
|
|
func Load(wgDir string) (*Config, error) {
|
|
cfg := &Config{
|
|
WGSubnet: "10.1.0.0/16",
|
|
DataDir: wgDir + "/.wgctl/data",
|
|
ClientsDir: wgDir + "/clients",
|
|
AcceptLogFile: wgDir + "/.wgctl/daemon/accept_events.log",
|
|
ServicesFile: wgDir + "/.wgctl/data/services.json",
|
|
}
|
|
|
|
jsonFile := wgDir + "/.wgctl/config/wgctl.json"
|
|
if data, err := os.ReadFile(jsonFile); err == nil {
|
|
var wj wgctlJSON
|
|
if json.Unmarshal(data, &wj) == nil && wj.WireGuard.Subnet != "" {
|
|
cfg.WGSubnet = wj.WireGuard.Subnet
|
|
}
|
|
}
|
|
|
|
return cfg, nil
|
|
} |