Compare commits

..

17 Commits

Author SHA1 Message Date
Christoph Haas
97896b7a9e Merge branch 'master' into mikrotik_integration
# Conflicts:
#	internal/app/wireguard/wireguard_interfaces.go
2025-08-10 14:33:13 +02:00
Christoph Haas
593bb983fb improve configuration defaults handling 2025-08-10 14:12:24 +02:00
Christoph Haas
0037938f9e update docs 2025-08-10 14:12:12 +02:00
Christoph Haas
f5e29e2cd3 ensure that deleted peers are restored once the interface is re-enabled 2025-08-09 16:37:09 +02:00
Christoph Haas
5dee6d051d do not delete disabled mikrotik peers on app restart 2025-08-09 16:25:38 +02:00
Christoph Haas
a9f5190ab4 Merge branch 'refs/heads/master' into mikrotik_integration
# Conflicts:
#	internal/app/wireguard/wireguard_peers.go
2025-08-09 16:09:39 +02:00
Christoph Haas
e10b4abec4 speed up mikrotik interactions 2025-08-09 15:21:17 +02:00
Christoph Haas
08373fa675 fix peer creation/update on mikrotik, add loading spinner to frontend for long running actions 2025-08-08 22:23:35 +02:00
Christoph Haas
ed7761a918 Merge branch 'master' into mikrotik_integration
# Conflicts:
#	internal/app/api/v0/handlers/endpoint_config.go
#	internal/app/api/v0/model/models.go
#	internal/app/wireguard/statistics.go
#	internal/app/wireguard/wireguard_interfaces.go
2025-07-29 22:16:00 +02:00
Christoph Haas
f086ba2605 wip: basic CRUD for peer (#426) 2025-06-06 22:21:47 +02:00
Christoph Haas
0724505ea1 wip: basic CRUD for interfaces (#426) 2025-06-01 11:40:05 +02:00
Christoph Haas
c612b5bbb1 wip: ping handler per backend (#426) 2025-06-01 09:50:46 +02:00
Christoph Haas
ea6da4114f wip: create different backend handlers (#426) 2025-05-31 22:15:09 +02:00
Christoph Haas
e934232e0b wip: implement mikrotik rest api client (#426) 2025-05-31 17:17:08 +02:00
Christoph Haas
d5ce889e4f visualize invalid backend selections (#426) 2025-05-31 10:01:47 +02:00
Christoph Haas
15d035ec10 wip: create different backend handlers (#426) 2025-05-30 23:19:48 +02:00
Christoph Haas
33dcc80078 prepare frontend for different WireGuard backends (#426) 2025-05-18 19:49:59 +02:00
16 changed files with 23 additions and 128 deletions

View File

@@ -20,7 +20,7 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
if: ${{ github.event_name == 'pull_request' }} if: ${{ github.event_name == 'pull_request' }}
steps: steps:
- uses: actions/checkout@v5 - uses: actions/checkout@v4
with: with:
fetch-depth: 0 fetch-depth: 0
@@ -60,7 +60,7 @@ jobs:
permissions: permissions:
packages: write packages: write
steps: steps:
- uses: actions/checkout@v5 - uses: actions/checkout@v4
- uses: docker/login-action@v3 - uses: docker/login-action@v3
with: with:

View File

@@ -18,7 +18,7 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Check out the repo - name: Check out the repo
uses: actions/checkout@v5 uses: actions/checkout@v4
- name: Set up QEMU - name: Set up QEMU
uses: docker/setup-qemu-action@v3 uses: docker/setup-qemu-action@v3
@@ -66,6 +66,10 @@ jobs:
type=semver,pattern={{major}} type=semver,pattern={{major}}
type=semver,pattern=v{{major}}.{{minor}} type=semver,pattern=v{{major}}.{{minor}}
type=semver,pattern=v{{major}} type=semver,pattern=v{{major}}
# add v{{major}} tag, even for beta or release-canidate releases
type=match,pattern=(v\d),group=1,enable=${{ contains(github.ref, 'beta') || contains(github.ref, 'rc') }}
# add {{major}} tag, even for beta releases or release-canidate releases
type=match,pattern=v(\d),group=1,enable=${{ contains(github.ref, 'beta') || contains(github.ref, 'rc') }}
- name: Build and push Docker image - name: Build and push Docker image
uses: docker/build-push-action@v6 uses: docker/build-push-action@v6
@@ -110,7 +114,7 @@ jobs:
contents: write contents: write
steps: steps:
- name: Download binaries - name: Download binaries
uses: actions/download-artifact@v5 uses: actions/download-artifact@v4
with: with:
name: binaries name: binaries

View File

@@ -15,7 +15,7 @@ jobs:
deploy: deploy:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v5 - uses: actions/checkout@v4
with: with:
fetch-depth: 0 fetch-depth: 0

View File

@@ -20,7 +20,7 @@ RUN npm run build
###### ######
# Build backend # Build backend
###### ######
FROM --platform=${BUILDPLATFORM} golang:1.25-alpine AS builder FROM --platform=${BUILDPLATFORM} golang:1.24-alpine AS builder
# Set the working directory # Set the working directory
WORKDIR /build WORKDIR /build
# Download dependencies # Download dependencies

View File

@@ -403,12 +403,6 @@ definitions:
type: object type: object
models.ProvisioningRequest: models.ProvisioningRequest:
properties: properties:
DisplayName:
description: |-
DisplayName is an optional name for the new peer.
If unset, a default template value (e.g., "API Peer ...") will be assigned.
example: API Peer xyz
type: string
InterfaceIdentifier: InterfaceIdentifier:
description: InterfaceIdentifier is the identifier of the WireGuard interface the peer should be linked to. description: InterfaceIdentifier is the identifier of the WireGuard interface the peer should be linked to.
example: wg0 example: wg0

4
go.mod
View File

@@ -8,7 +8,7 @@ require (
github.com/coreos/go-oidc/v3 v3.15.0 github.com/coreos/go-oidc/v3 v3.15.0
github.com/glebarez/sqlite v1.11.0 github.com/glebarez/sqlite v1.11.0
github.com/go-ldap/ldap/v3 v3.4.11 github.com/go-ldap/ldap/v3 v3.4.11
github.com/go-pkgz/routegroup v1.5.3 github.com/go-pkgz/routegroup v1.5.1
github.com/go-playground/validator/v10 v10.27.0 github.com/go-playground/validator/v10 v10.27.0
github.com/go-webauthn/webauthn v0.13.4 github.com/go-webauthn/webauthn v0.13.4
github.com/google/uuid v1.6.0 github.com/google/uuid v1.6.0
@@ -29,7 +29,7 @@ require (
gorm.io/driver/mysql v1.6.0 gorm.io/driver/mysql v1.6.0
gorm.io/driver/postgres v1.6.0 gorm.io/driver/postgres v1.6.0
gorm.io/driver/sqlserver v1.6.1 gorm.io/driver/sqlserver v1.6.1
gorm.io/gorm v1.30.2 gorm.io/gorm v1.30.1
) )
require ( require (

8
go.sum
View File

@@ -70,8 +70,8 @@ github.com/go-openapi/spec v0.21.0 h1:LTVzPc3p/RzRnkQqLRndbAzjY0d0BCL72A6j3CdL9Z
github.com/go-openapi/spec v0.21.0/go.mod h1:78u6VdPw81XU44qEWGhtr982gJ5BWg2c0I5XwVMotYk= github.com/go-openapi/spec v0.21.0/go.mod h1:78u6VdPw81XU44qEWGhtr982gJ5BWg2c0I5XwVMotYk=
github.com/go-openapi/swag v0.23.1 h1:lpsStH0n2ittzTnbaSloVZLuB5+fvSY/+hnagBjSNZU= github.com/go-openapi/swag v0.23.1 h1:lpsStH0n2ittzTnbaSloVZLuB5+fvSY/+hnagBjSNZU=
github.com/go-openapi/swag v0.23.1/go.mod h1:STZs8TbRvEQQKUA+JZNAm3EWlgaOBGpyFDqQnDHMef0= github.com/go-openapi/swag v0.23.1/go.mod h1:STZs8TbRvEQQKUA+JZNAm3EWlgaOBGpyFDqQnDHMef0=
github.com/go-pkgz/routegroup v1.5.3 h1:IvH1KLcQkMap9jucQGBlef3IBloxSAe8USUFvxShFqs= github.com/go-pkgz/routegroup v1.5.1 h1:hwVU4w2ltMQXIGEM4WIM0aWyRn7FsZbfbZIlPH7f1Rk=
github.com/go-pkgz/routegroup v1.5.3/go.mod h1:Pmu04fhgWhRtBMIJ8HXppnnzOPjnL/IEPBIdO2zmeqg= github.com/go-pkgz/routegroup v1.5.1/go.mod h1:kDDPDRLRiRY1vnENrZJw1jQAzQX7fvsbsHGRQFNQfKc=
github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s= github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s=
github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4= github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA= github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA=
@@ -374,8 +374,8 @@ gorm.io/driver/postgres v1.6.0/go.mod h1:vUw0mrGgrTK+uPHEhAdV4sfFELrByKVGnaVRkXD
gorm.io/driver/sqlserver v1.6.1 h1:XWISFsu2I2pqd1KJhhTZNJMx1jNQ+zVL/Q8ovDcUjtY= gorm.io/driver/sqlserver v1.6.1 h1:XWISFsu2I2pqd1KJhhTZNJMx1jNQ+zVL/Q8ovDcUjtY=
gorm.io/driver/sqlserver v1.6.1/go.mod h1:VZeNn7hqX1aXoN5TPAFGWvxWG90xtA8erGn2gQmpc6U= gorm.io/driver/sqlserver v1.6.1/go.mod h1:VZeNn7hqX1aXoN5TPAFGWvxWG90xtA8erGn2gQmpc6U=
gorm.io/gorm v1.30.0/go.mod h1:8Z33v652h4//uMA76KjeDH8mJXPm1QNCYrMeatR0DOE= gorm.io/gorm v1.30.0/go.mod h1:8Z33v652h4//uMA76KjeDH8mJXPm1QNCYrMeatR0DOE=
gorm.io/gorm v1.30.2 h1:f7bevlVoVe4Byu3pmbWPVHnPsLoWaMjEb7/clyr9Ivs= gorm.io/gorm v1.30.1 h1:lSHg33jJTBxs2mgJRfRZeLDG+WZaHYCk3Wtfl6Ngzo4=
gorm.io/gorm v1.30.2/go.mod h1:8Z33v652h4//uMA76KjeDH8mJXPm1QNCYrMeatR0DOE= gorm.io/gorm v1.30.1/go.mod h1:8Z33v652h4//uMA76KjeDH8mJXPm1QNCYrMeatR0DOE=
modernc.org/cc/v4 v4.26.3 h1:yEN8dzrkRFnn4PUUKXLYIqVf2PJYAEjMTFjO3BDGc3I= modernc.org/cc/v4 v4.26.3 h1:yEN8dzrkRFnn4PUUKXLYIqVf2PJYAEjMTFjO3BDGc3I=
modernc.org/cc/v4 v4.26.3/go.mod h1:uVtb5OGqUKpoLWhqwNQo/8LwvoiEBLvZXIQ/SmO6mL0= modernc.org/cc/v4 v4.26.3/go.mod h1:uVtb5OGqUKpoLWhqwNQo/8LwvoiEBLvZXIQ/SmO6mL0=
modernc.org/ccgo/v4 v4.28.0 h1:rjznn6WWehKq7dG4JtLRKxb52Ecv8OUGah8+Z/SfpNU= modernc.org/ccgo/v4 v4.28.0 h1:rjznn6WWehKq7dG4JtLRKxb52Ecv8OUGah8+Z/SfpNU=

View File

@@ -1781,11 +1781,6 @@
"type": "string" "type": "string"
} }
}, },
"Backend": {
"description": "the backend used for this interface e.g., local, mikrotik, ...",
"type": "string",
"example": "local"
},
"Disabled": { "Disabled": {
"description": "flag that specifies if the interface is enabled (up) or not (down)", "description": "flag that specifies if the interface is enabled (up) or not (down)",
"type": "boolean" "type": "boolean"
@@ -2254,12 +2249,6 @@
"ApiAdminOnly": { "ApiAdminOnly": {
"type": "boolean" "type": "boolean"
}, },
"AvailableBackends": {
"type": "array",
"items": {
"$ref": "#/definitions/model.SettingsBackendNames"
}
},
"LoginFormVisible": { "LoginFormVisible": {
"type": "boolean" "type": "boolean"
}, },
@@ -2280,17 +2269,6 @@
} }
} }
}, },
"model.SettingsBackendNames": {
"type": "object",
"properties": {
"Id": {
"type": "string"
},
"Name": {
"type": "string"
}
}
},
"model.User": { "model.User": {
"type": "object", "type": "object",
"properties": { "properties": {

View File

@@ -65,10 +65,6 @@ definitions:
items: items:
type: string type: string
type: array type: array
Backend:
description: the backend used for this interface e.g., local, mikrotik, ...
example: local
type: string
Disabled: Disabled:
description: flag that specifies if the interface is enabled (up) or not (down) description: flag that specifies if the interface is enabled (up) or not (down)
type: boolean type: boolean
@@ -385,10 +381,6 @@ definitions:
properties: properties:
ApiAdminOnly: ApiAdminOnly:
type: boolean type: boolean
AvailableBackends:
items:
$ref: '#/definitions/model.SettingsBackendNames'
type: array
LoginFormVisible: LoginFormVisible:
type: boolean type: boolean
MailLinkOnly: MailLinkOnly:
@@ -402,13 +394,6 @@ definitions:
WebAuthnEnabled: WebAuthnEnabled:
type: boolean type: boolean
type: object type: object
model.SettingsBackendNames:
properties:
Id:
type: string
Name:
type: string
type: object
model.User: model.User:
properties: properties:
ApiEnabled: ApiEnabled:

View File

@@ -2086,11 +2086,6 @@
"InterfaceIdentifier" "InterfaceIdentifier"
], ],
"properties": { "properties": {
"DisplayName": {
"description": "DisplayName is an optional name for the new peer.\nIf unset, a default template value (e.g., \"API Peer ...\") will be assigned.",
"type": "string",
"example": "API Peer xyz"
},
"InterfaceIdentifier": { "InterfaceIdentifier": {
"description": "InterfaceIdentifier is the identifier of the WireGuard interface the peer should be linked to.", "description": "InterfaceIdentifier is the identifier of the WireGuard interface the peer should be linked to.",
"type": "string", "type": "string",

View File

@@ -445,12 +445,6 @@ definitions:
type: object type: object
models.ProvisioningRequest: models.ProvisioningRequest:
properties: properties:
DisplayName:
description: |-
DisplayName is an optional name for the new peer.
If unset, a default template value (e.g., "API Peer ...") will be assigned.
example: API Peer xyz
type: string
InterfaceIdentifier: InterfaceIdentifier:
description: InterfaceIdentifier is the identifier of the WireGuard interface description: InterfaceIdentifier is the identifier of the WireGuard interface
the peer should be linked to. the peer should be linked to.

View File

@@ -162,11 +162,7 @@ func (p ProvisioningService) NewPeer(ctx context.Context, req models.Provisionin
if req.PresharedKey != "" { if req.PresharedKey != "" {
peer.PresharedKey = domain.PreSharedKey(req.PresharedKey) peer.PresharedKey = domain.PreSharedKey(req.PresharedKey)
} }
if req.DisplayName == "" {
peer.GenerateDisplayName("API") peer.GenerateDisplayName("API")
} else {
peer.DisplayName = req.DisplayName
}
// save new peer // save new peer
peer, err = p.peers.CreatePeer(ctx, peer) peer, err = p.peers.CreatePeer(ctx, peer)

View File

@@ -68,10 +68,6 @@ type ProvisioningRequest struct {
// If no user identifier is set, the authenticated user is used. // If no user identifier is set, the authenticated user is used.
UserIdentifier string `json:"UserIdentifier" example:"uid-1234567"` UserIdentifier string `json:"UserIdentifier" example:"uid-1234567"`
// DisplayName is an optional name for the new peer.
// If unset, a default template value (e.g., "API Peer ...") will be assigned.
DisplayName string `json:"DisplayName" example:"API Peer xyz" binding:"omitempty"`
// PublicKey is the optional public key of the peer. If no public key is set, a new key pair is generated. // PublicKey is the optional public key of the peer. If no public key is set, a new key pair is generated.
PublicKey string `json:"PublicKey" example:"xTIBA5rboUvnH4htodjb6e697QjLERt1NAB4mZqp8Dg=" binding:"omitempty,len=44"` PublicKey string `json:"PublicKey" example:"xTIBA5rboUvnH4htodjb6e697QjLERt1NAB4mZqp8Dg=" binding:"omitempty,len=44"`
// PresharedKey is the optional pre-shared key of the peer. If no pre-shared key is set, a new key is generated. // PresharedKey is the optional pre-shared key of the peer. If no pre-shared key is set, a new key is generated.

View File

@@ -54,7 +54,7 @@ func (l LdapAuthenticator) PlaintextAuthentication(userId domain.UserIdentifier,
attrs := []string{"dn"} attrs := []string{"dn"}
loginFilter := strings.Replace(l.cfg.LoginFilter, "{{login_identifier}}", ldap.EscapeFilter(string(userId)), -1) loginFilter := strings.Replace(l.cfg.LoginFilter, "{{login_identifier}}", string(userId), -1)
searchRequest := ldap.NewSearchRequest( searchRequest := ldap.NewSearchRequest(
l.cfg.BaseDN, l.cfg.BaseDN,
ldap.ScopeWholeSubtree, ldap.NeverDerefAliases, 0, 20, false, // 20 second time limit ldap.ScopeWholeSubtree, ldap.NeverDerefAliases, 0, 20, false, // 20 second time limit
@@ -100,7 +100,7 @@ func (l LdapAuthenticator) GetUserInfo(_ context.Context, userId domain.UserIden
attrs := internal.LdapSearchAttributes(&l.cfg.FieldMap) attrs := internal.LdapSearchAttributes(&l.cfg.FieldMap)
loginFilter := strings.Replace(l.cfg.LoginFilter, "{{login_identifier}}", ldap.EscapeFilter(string(userId)), -1) loginFilter := strings.Replace(l.cfg.LoginFilter, "{{login_identifier}}", string(userId), -1)
searchRequest := ldap.NewSearchRequest( searchRequest := ldap.NewSearchRequest(
l.cfg.BaseDN, l.cfg.BaseDN,
ldap.ScopeWholeSubtree, ldap.NeverDerefAliases, 0, 20, false, // 20 second time limit ldap.ScopeWholeSubtree, ldap.NeverDerefAliases, 0, 20, false, // 20 second time limit

View File

@@ -47,18 +47,11 @@ func migrateFromV1(db *gorm.DB, source, typ string) error {
} }
latestVersion := "1.0.9" latestVersion := "1.0.9"
if lastVersion.Version != latestVersion { if lastVersion.Version != latestVersion {
return fmt.Errorf("unsupported old version, update to database version %s first", latestVersion) return fmt.Errorf("unsupported old version, update to database version %s first: %w", latestVersion, err)
} }
slog.Info("found valid V1 database", "version", lastVersion.Version) slog.Info("found valid V1 database", "version", lastVersion.Version)
// validate target database
if err := validateTargetDatabase(db); err != nil {
return fmt.Errorf("target database validation failed: %w", err)
}
slog.Info("found valid target database, starting migration...")
if err := migrateV1Users(oldDb, db); err != nil { if err := migrateV1Users(oldDb, db); err != nil {
return fmt.Errorf("user migration failed: %w", err) return fmt.Errorf("user migration failed: %w", err)
} }
@@ -77,36 +70,6 @@ func migrateFromV1(db *gorm.DB, source, typ string) error {
return nil return nil
} }
// validateTargetDatabase checks if the target database is empty and ready for migration.
func validateTargetDatabase(db *gorm.DB) error {
var count int64
err := db.Model(&domain.User{}).Count(&count).Error
if err != nil {
return fmt.Errorf("failed to check user table: %w", err)
}
if count > 0 {
return fmt.Errorf("target database contains %d users, please use an empty database for migration", count)
}
err = db.Model(&domain.Interface{}).Count(&count).Error
if err != nil {
return fmt.Errorf("failed to check interface table: %w", err)
}
if count > 0 {
return fmt.Errorf("target database contains %d interfaces, please use an empty database for migration", count)
}
err = db.Model(&domain.Peer{}).Count(&count).Error
if err != nil {
return fmt.Errorf("failed to check peer table: %w", err)
}
if count > 0 {
return fmt.Errorf("target database contains %d peers, please use an empty database for migration", count)
}
return nil
}
func migrateV1Users(oldDb, newDb *gorm.DB) error { func migrateV1Users(oldDb, newDb *gorm.DB) error {
type User struct { type User struct {
Email string `gorm:"primaryKey"` Email string `gorm:"primaryKey"`
@@ -160,7 +123,7 @@ func migrateV1Users(oldDb, newDb *gorm.DB) error {
LinkedPeerCount: 0, LinkedPeerCount: 0,
} }
if err := newDb.Create(&newUser).Error; err != nil { if err := newDb.Save(&newUser).Error; err != nil {
return fmt.Errorf("failed to migrate user %s: %w", oldUser.Email, err) return fmt.Errorf("failed to migrate user %s: %w", oldUser.Email, err)
} }
@@ -254,8 +217,7 @@ func migrateV1Interfaces(oldDb, newDb *gorm.DB) error {
PeerDefPostDown: "", PeerDefPostDown: "",
} }
// Create new interface with associations if err := newDb.Save(&newInterface).Error; err != nil {
if err := newDb.Create(&newInterface).Error; err != nil {
return fmt.Errorf("failed to migrate device %s: %w", oldDevice.DeviceName, err) return fmt.Errorf("failed to migrate device %s: %w", oldDevice.DeviceName, err)
} }
@@ -400,7 +362,7 @@ func migrateV1Peers(oldDb, newDb *gorm.DB) error {
}, },
} }
if err := newDb.Create(&newPeer).Error; err != nil { if err := newDb.Save(&newPeer).Error; err != nil {
return fmt.Errorf("failed to migrate peer %s (%s): %w", oldPeer.Identifier, oldPeer.PublicKey, err) return fmt.Errorf("failed to migrate peer %s (%s): %w", oldPeer.Identifier, oldPeer.PublicKey, err)
} }

View File

@@ -225,15 +225,6 @@ func (m Manager) RestoreInterfaceState(
if err != nil && !iface.IsDisabled() { if err != nil && !iface.IsDisabled() {
slog.Debug("creating missing interface", "interface", iface.Identifier) slog.Debug("creating missing interface", "interface", iface.Identifier)
// temporarily disable interface in database so that the current state is reflected correctly
_ = m.db.SaveInterface(ctx, iface.Identifier,
func(in *domain.Interface) (*domain.Interface, error) {
now := time.Now()
in.Disabled = &now // set
in.DisabledReason = domain.DisabledReasonInterfaceMissing
return in, nil
})
// try to create a new interface // try to create a new interface
_, err = m.saveInterface(ctx, &iface) _, err = m.saveInterface(ctx, &iface)
if err != nil { if err != nil {