mirror of
https://github.com/h44z/wg-portal.git
synced 2026-09-03 21:36:44 +00:00
Add read-only support and UI indicators for MikroTik dynamic peers (#733)
* Add dynamic Mikrotik peer support & UI/i18n Introduce handling for dynamically created Mikrotik peers: add Dynamic/IsDynamic fields to domain, peer and interface models and API models; include "dynamic" in Mikrotik queries; skip updates/deletes for dynamic peers; sync dynamic flag when restoring state. Prevent modifying/deleting dynamic peers in manager. UI: disable selection/edit for dynamic peers and show badge. Implement Mikrotik interface hook execution. Add i18n keys/translations for dynamic-peer messages across languages. * Fix Mikrotik hooks implementation and UI visibility
This commit is contained in:
@@ -63,6 +63,7 @@ func (c *ControllerManager) registerLocalController() error {
|
||||
Config: config.BackendBase{
|
||||
Id: config.LocalBackendName,
|
||||
DisplayName: "Local WireGuard Controller",
|
||||
Type: "local",
|
||||
IgnoredInterfaces: c.cfg.Backend.IgnoredLocalInterfaces,
|
||||
},
|
||||
Implementation: localController,
|
||||
@@ -82,6 +83,7 @@ func (c *ControllerManager) registerMikrotikControllers() error {
|
||||
return fmt.Errorf("failed to create Mikrotik controller for backend %s: %w", backendConfig.Id, err)
|
||||
}
|
||||
|
||||
backendConfig.BackendBase.Type = "mikrotik"
|
||||
c.controllers[domain.InterfaceBackend(backendConfig.Id)] = backendInstance{
|
||||
Config: backendConfig.BackendBase,
|
||||
Implementation: controller,
|
||||
@@ -102,6 +104,7 @@ func (c *ControllerManager) registerPfsenseControllers() error {
|
||||
return fmt.Errorf("failed to create pfSense controller for backend %s: %w", backendConfig.Id, err)
|
||||
}
|
||||
|
||||
backendConfig.BackendBase.Type = "pfsense"
|
||||
c.controllers[domain.InterfaceBackend(backendConfig.Id)] = backendInstance{
|
||||
Config: backendConfig.BackendBase,
|
||||
Implementation: controller,
|
||||
|
||||
@@ -307,9 +307,19 @@ func (m Manager) RestoreInterfaceState(
|
||||
physicalPeers, _ := controller.GetPeers(ctx, iface.Identifier)
|
||||
for _, physicalPeer := range physicalPeers {
|
||||
isWgPortalPeer := false
|
||||
for _, peer := range peers {
|
||||
if peer.Identifier == domain.PeerIdentifier(physicalPeer.PublicKey) {
|
||||
for i := range peers {
|
||||
if peers[i].Identifier == domain.PeerIdentifier(physicalPeer.PublicKey) {
|
||||
isWgPortalPeer = true
|
||||
|
||||
// Sync IsDynamic flag if it was changed on the backend
|
||||
physConverted := domain.ConvertPhysicalPeer(&physicalPeer)
|
||||
if peers[i].IsDynamic != physConverted.IsDynamic {
|
||||
peers[i].IsDynamic = physConverted.IsDynamic
|
||||
_ = m.db.SavePeer(ctx, peers[i].Identifier, func(p *domain.Peer) (*domain.Peer, error) {
|
||||
p.IsDynamic = physConverted.IsDynamic
|
||||
return p, nil
|
||||
})
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
@@ -620,7 +620,11 @@ func (m Manager) getFreshPeerIpConfig(ctx context.Context, iface *domain.Interfa
|
||||
return
|
||||
}
|
||||
|
||||
func (m Manager) validatePeerModifications(ctx context.Context, _, _ *domain.Peer) error {
|
||||
func (m Manager) validatePeerModifications(ctx context.Context, old, _ *domain.Peer) error {
|
||||
if old != nil && old.IsDynamic {
|
||||
return fmt.Errorf("cannot modify dynamic peer: %w", domain.ErrInvalidData)
|
||||
}
|
||||
|
||||
currentUser := domain.GetUserInfo(ctx)
|
||||
|
||||
if !currentUser.IsAdmin && !m.cfg.Core.SelfProvisioningAllowed {
|
||||
@@ -649,7 +653,11 @@ func (m Manager) validatePeerCreation(ctx context.Context, _, new *domain.Peer)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m Manager) validatePeerDeletion(ctx context.Context, _ *domain.Peer) error {
|
||||
func (m Manager) validatePeerDeletion(ctx context.Context, peer *domain.Peer) error {
|
||||
if peer != nil && peer.IsDynamic {
|
||||
return fmt.Errorf("cannot delete dynamic peer: %w", domain.ErrInvalidData)
|
||||
}
|
||||
|
||||
currentUser := domain.GetUserInfo(ctx)
|
||||
|
||||
if !currentUser.IsAdmin && !m.cfg.Core.SelfProvisioningAllowed {
|
||||
|
||||
Reference in New Issue
Block a user