1818from ...base import ShareableOrgMixinUniqueName
1919from .. import crypto
2020from .. import settings as app_settings
21- from ..signals import vpn_peers_changed
21+ from ..signals import vpn_peers_changed , vpn_server_modified
2222from ..tasks import create_vpn_dh , trigger_vpn_server_endpoint
2323from .base import BaseConfig
2424
@@ -127,6 +127,11 @@ class Meta:
127127 unique_together = ('organization' , 'name' )
128128 abstract = True
129129
130+ def __init__ (self , * args , ** kwargs ):
131+ super ().__init__ (* args , ** kwargs )
132+ # for internal usage
133+ self ._send_vpn_modified_after_save = False
134+
130135 def clean (self , * args , ** kwargs ):
131136 super ().clean (* args , ** kwargs )
132137 self ._validate_backend ()
@@ -190,6 +195,9 @@ def save(self, *args, **kwargs):
190195 """
191196 Calls _auto_create_cert() if cert is not set
192197 """
198+ created = self ._state .adding
199+ if not created :
200+ self ._check_changes ()
193201 create_dh = False
194202 if not self .cert and self .ca :
195203 self .cert = self ._auto_create_cert ()
@@ -203,8 +211,35 @@ def save(self, *args, **kwargs):
203211 super ().save (* args , ** kwargs )
204212 if create_dh :
205213 transaction .on_commit (lambda : create_vpn_dh .delay (self .id ))
214+ if not created and self ._send_vpn_modified_after_save :
215+ self ._send_vpn_modified_signal ()
216+ self ._send_vpn_modified_after_save = False
206217 self .update_vpn_server_configuration ()
207218
219+ def _check_changes (self ):
220+ attrs = [
221+ 'config' ,
222+ 'host' ,
223+ 'ca' ,
224+ 'cert' ,
225+ 'key' ,
226+ 'backend' ,
227+ 'subnet' ,
228+ 'ip' ,
229+ 'dh' ,
230+ 'public_key' ,
231+ 'private_key' ,
232+ ]
233+ current = self ._meta .model .objects .only (* attrs ).get (pk = self .pk )
234+ for attr in attrs :
235+ if getattr (self , attr ) == getattr (current , attr ):
236+ continue
237+ self ._send_vpn_modified_after_save = True
238+ break
239+
240+ def _send_vpn_modified_signal (self ):
241+ vpn_server_modified .send (sender = self .__class__ , instance = self )
242+
208243 @classmethod
209244 def dhparam (cls , length ):
210245 """
@@ -734,3 +769,14 @@ def _auto_ip(self):
734769 if func (self ):
735770 return
736771 self .ip = self .vpn .subnet .request_ip ()
772+
773+ @classmethod
774+ def invalidate_clients_cache (cls , vpn ):
775+ """
776+ Invalidate checksum cache for clients that uses this VPN server
777+ """
778+ for client in vpn .vpnclient_set .iterator ():
779+ # invalidate cache for device
780+ client .config ._send_config_modified_signal (
781+ action = 'related_template_changed'
782+ )
0 commit comments