mirror of
https://github.com/h44z/wg-portal.git
synced 2026-12-05 19:56:06 +01:00
feat: add support for AmneziaWG (#649)
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
)
|
||||
|
||||
const LocalBackendName = "local"
|
||||
const AmneziaWGBackendName = "amneziawg"
|
||||
|
||||
type Backend struct {
|
||||
Default string `yaml:"default"` // The default backend to use (defaults to the internal backend)
|
||||
@@ -19,9 +20,10 @@ type Backend struct {
|
||||
|
||||
// External Backend-specific configuration
|
||||
|
||||
Mikrotik []BackendMikrotik `yaml:"mikrotik"`
|
||||
Pfsense []BackendPfsense `yaml:"pfsense"`
|
||||
Opnsense []BackendOpnsense `yaml:"opnsense"`
|
||||
Mikrotik []BackendMikrotik `yaml:"mikrotik"`
|
||||
Pfsense []BackendPfsense `yaml:"pfsense"`
|
||||
Opnsense []BackendOpnsense `yaml:"opnsense"`
|
||||
AmneziaWG BackendAmneziaWG `yaml:"amneziawg"`
|
||||
}
|
||||
|
||||
// Validate checks the backend configuration for errors.
|
||||
@@ -31,9 +33,12 @@ func (b *Backend) Validate() error {
|
||||
}
|
||||
|
||||
uniqueMap := make(map[string]struct{})
|
||||
if b.AmneziaWG.Enabled {
|
||||
uniqueMap[AmneziaWGBackendName] = struct{}{}
|
||||
}
|
||||
checkBackendId := func(id string) error {
|
||||
if id == LocalBackendName {
|
||||
return fmt.Errorf("backend ID %q is a reserved keyword", LocalBackendName)
|
||||
if id == LocalBackendName || id == AmneziaWGBackendName {
|
||||
return fmt.Errorf("backend ID %q is a reserved keyword", id)
|
||||
}
|
||||
if _, exists := uniqueMap[id]; exists {
|
||||
return fmt.Errorf("backend ID %q is not unique", id)
|
||||
@@ -197,3 +202,8 @@ func (b *BackendOpnsense) GetApiTimeout() time.Duration {
|
||||
}
|
||||
return b.ApiTimeout
|
||||
}
|
||||
|
||||
type BackendAmneziaWG struct {
|
||||
Enabled bool `yaml:"enabled"` // Requires a loaded AmneziaWG host kernel module.
|
||||
IgnoredInterfaces []string `yaml:"ignored_interfaces"`
|
||||
}
|
||||
|
||||
@@ -165,6 +165,10 @@ func defaultConfig() *Config {
|
||||
// Most resolconf implementations use "tun." as a prefix for interface names.
|
||||
// But systemd's implementation uses no prefix, for example.
|
||||
LocalResolvconfPrefix: getEnvStr("WG_PORTAL_BACKEND_LOCAL_RESOLVCONF_PREFIX", "tun."),
|
||||
AmneziaWG: BackendAmneziaWG{
|
||||
Enabled: getEnvBool("WG_PORTAL_BACKEND_AMNEZIAWG_ENABLED", false),
|
||||
IgnoredInterfaces: getEnvStrSlice("WG_PORTAL_BACKEND_IGNORED_AMNEZIAWG_INTERFACES", nil),
|
||||
},
|
||||
}
|
||||
|
||||
cfg.Web = WebConfig{
|
||||
|
||||
Reference in New Issue
Block a user