|
@@ -8,20 +8,7 @@ from ldapdb.models.fields import CharField, ListField
|
|
|
from coin.models import CoinLdapSyncModel
|
|
|
from coin.offers.models import OfferSubscription
|
|
|
from coin import utils
|
|
|
-
|
|
|
-
|
|
|
-def validate_v4(address):
|
|
|
- if address.version != 4:
|
|
|
- raise ValidationError('{} is not an IPv4 address'.format(address))
|
|
|
-
|
|
|
-
|
|
|
-def validate_v6(address):
|
|
|
- if address.version != 6:
|
|
|
- raise ValidationError('{} is not an IPv6 address'.format(address))
|
|
|
-
|
|
|
-
|
|
|
-def str_or_none(obj):
|
|
|
- return str(obj) if obj else None
|
|
|
+from coin import validation
|
|
|
|
|
|
|
|
|
def validate_backend_type(subscription):
|
|
@@ -58,10 +45,10 @@ class VPNSubscription(CoinLdapSyncModel):
|
|
|
activated = models.BooleanField(default=False)
|
|
|
login = models.CharField(max_length=50, unique=True)
|
|
|
password = models.CharField(max_length=256)
|
|
|
- ipv4_endpoint = InetAddressField(validators=[validate_v4], blank=True,
|
|
|
- null=True)
|
|
|
- ipv6_endpoint = InetAddressField(validators=[validate_v6], blank=True,
|
|
|
- null=True)
|
|
|
+ ipv4_endpoint = InetAddressField(validators=[validation.validate_v4],
|
|
|
+ blank=True, null=True)
|
|
|
+ ipv6_endpoint = InetAddressField(validators=[validation.validate_v6],
|
|
|
+ blank=True, null=True)
|
|
|
comment = models.CharField(blank=True, max_length=512)
|
|
|
|
|
|
objects = NetManager()
|
|
@@ -78,8 +65,8 @@ class VPNSubscription(CoinLdapSyncModel):
|
|
|
config.login = config.sn = self.login
|
|
|
config.password = self.password
|
|
|
config.active = 'yes' if self.activated else 'no'
|
|
|
- config.ipv4_endpoint = str_or_none(self.ipv4_endpoint)
|
|
|
- config.ipv6_endpoint = str_or_none(self.ipv6_endpoint)
|
|
|
+ config.ipv4_endpoint = utils.str_or_none(self.ipv4_endpoint)
|
|
|
+ config.ipv6_endpoint = utils.str_or_none(self.ipv6_endpoint)
|
|
|
config.ranges_v4 = [str(s) for s in self.get_subnets(4)]
|
|
|
config.ranges_v6 = [str(s) for s in self.get_subnets(6)]
|
|
|
config.save()
|