mirror of
				https://github.com/h44z/wg-portal.git
				synced 2025-11-03 23:56:18 +00:00 
			
		
		
		
	execute interface hooks if interface settings have changed (#224)
This commit is contained in:
		@@ -28,6 +28,7 @@ func (r *WgQuickRepo) ExecuteInterfaceHook(id domain.InterfaceIdentifier, hookCm
 | 
			
		||||
		return nil
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	logrus.Tracef("interface %s: executing hook %s", id, hookCmd)
 | 
			
		||||
	err := r.exec(hookCmd, id)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return fmt.Errorf("failed to exec hook: %w", err)
 | 
			
		||||
 
 | 
			
		||||
@@ -202,9 +202,6 @@ func (m Manager) RestoreInterfaceState(ctx context.Context, updateDbOnError bool
 | 
			
		||||
 | 
			
		||||
			// try to move interface to stored state
 | 
			
		||||
			_, err = m.saveInterface(ctx, &iface, peers)
 | 
			
		||||
			if err != nil {
 | 
			
		||||
				return err
 | 
			
		||||
			}
 | 
			
		||||
			if err != nil {
 | 
			
		||||
				if updateDbOnError {
 | 
			
		||||
					// disable interface in database as no physical interface is available
 | 
			
		||||
@@ -469,7 +466,26 @@ func (m Manager) hasInterfaceStateChanged(ctx context.Context, iface *domain.Int
 | 
			
		||||
		return false
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return oldInterface.IsDisabled() != iface.IsDisabled()
 | 
			
		||||
	if oldInterface.IsDisabled() != iface.IsDisabled() {
 | 
			
		||||
		return true // interface in db has changed
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	wgInterface, err := m.wg.GetInterface(ctx, iface.Identifier)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return true // interface might not exist - so we assume that there must be a change
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// compare physical interface settings
 | 
			
		||||
	if len(wgInterface.Addresses) != len(iface.Addresses) ||
 | 
			
		||||
		wgInterface.Mtu != iface.Mtu ||
 | 
			
		||||
		wgInterface.FirewallMark != iface.FirewallMark ||
 | 
			
		||||
		wgInterface.ListenPort != iface.ListenPort ||
 | 
			
		||||
		wgInterface.PrivateKey != iface.PrivateKey ||
 | 
			
		||||
		wgInterface.PublicKey != iface.PublicKey {
 | 
			
		||||
		return true
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return false
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (m Manager) handleInterfacePreSaveActions(iface *domain.Interface) error {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user