mirror of
https://github.com/jwinterm/modoboa.git
synced 2026-10-18 05:51:26 +02:00
Merge branch '1.2.x'
Conflicts: modoboa/lib/form_utils.py
This commit is contained in:
@@ -344,17 +344,19 @@ class TabForms(object):
|
||||
#
|
||||
|
||||
|
||||
def is_valid_host(host):
|
||||
"""IDN compatible domain validator."""
|
||||
host = host.encode('idna').lower()
|
||||
if not hasattr(is_valid_host, '_re'):
|
||||
is_valid_host._re = re.compile(
|
||||
r'^([0-9a-z][-\w]*[0-9a-z]\.)+[a-z0-9\-]{2,15}$')
|
||||
return bool(is_valid_host._re.match(host))
|
||||
def is_valid_hostname(hostname):
|
||||
"""Domain name validaton."""
|
||||
if len(hostname) > 255:
|
||||
return False
|
||||
if hostname[-1] == ".":
|
||||
hostname = hostname[:-1] # strip exactly one dot from the
|
||||
# right, if present
|
||||
allowed = re.compile(r"(?!-)[A-Z\d-]{1,63}(?<!-)$", re.IGNORECASE)
|
||||
return all(allowed.match(x) for x in hostname.split("."))
|
||||
|
||||
|
||||
def validate_domain_name(value):
|
||||
if not is_valid_host(value):
|
||||
if not is_valid_hostname(value):
|
||||
raise ValidationError(_('Enter a valid domain name'), 'invalid')
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user