Exemple #1
0
    def isValidWithMsg(self):
        if not self.enabled and not self.server:
            # allow empty server if not enabled
            pass
        elif not check_ip_or_domain(self.server):
            return (False,
                    tr('Invalid server IP (IPv4 or IPv6 are allowed): ') \
                        + self.server)

        if not check_port(self.port):
            return False, tr('Invalid port (%s): must be greater than 0 and lower than 65536.') % self.port


        # allow empty client_network if not enabled
        if self.enabled or self.client_network:
            if not check_network(self.client_network):
                return False, tr('Invalid client network: ') + self.client_network

            if IP(self.client_network).len() > 65536L:
                return False, tr('The client network cannot be broader than a /16 network (netmask 255.255.0.0 at most).')
            elif IP(self.client_network).len() < 8:
                return False, tr('The client network cannot be narrower than a /29 network (netmask 255.255.255.248 at least).')

        if self.protocol not in ['tcp', 'udp']:
            return False, tr("Unknown protocol (choose 'tcp' or 'udp'): ") + self.protocol

        # should be done inside checkSerialVersion
        if self.enabled is None and self.hasCertWithMsg()[0]:
            self.enabled = False

        if self.enabled and not self.redirect and not self.manual_pushed_routes:
            return False, tr("You need to add routed networks for the VPN or\
                to redirect the default gateway through the VPN.")

        return True, ''