From 8ec1d88214d82a625af71a50155895d3b202deaf Mon Sep 17 00:00:00 2001 From: mcramer Date: Thu, 13 Sep 2012 08:13:56 +0000 Subject: [PATCH] Fixed: FS#2426 - Auto subdomains are ignored when checking if domain is unique Implemented: FS#2427 - Allow wildcard subdomain creation on limit_wildcard = y --- interface/lib/classes/validate_domain.inc.php | 115 ++++++++++++++++++ .../web/sites/form/web_aliasdomain.tform.php | 13 +- interface/web/sites/form/web_domain.tform.php | 13 +- .../web/sites/form/web_subdomain.tform.php | 13 +- .../sites/form/web_vhost_subdomain.tform.php | 13 +- .../web/sites/lib/lang/de_web_subdomain.lng | 1 + .../sites/lib/lang/de_web_vhost_subdomain.lng | 1 + .../web/sites/lib/lang/en_web_subdomain.lng | 1 + .../sites/lib/lang/en_web_vhost_subdomain.lng | 1 + 9 files changed, 139 insertions(+), 32 deletions(-) create mode 100644 interface/lib/classes/validate_domain.inc.php diff --git a/interface/lib/classes/validate_domain.inc.php b/interface/lib/classes/validate_domain.inc.php new file mode 100644 index 000000000..25f16af68 --- /dev/null +++ b/interface/lib/classes/validate_domain.inc.php @@ -0,0 +1,115 @@ +tform->wordbook[$errmsg])) { + return $app->tform->wordbook[$errmsg]."
\r\n"; + } else { + return $errmsg."
\r\n"; + } + } + + /* Validator function for domain (website) */ + function web_domain($field_name, $field_value, $validator) { + if(empty($field_value)) return $this->get_error('domain_error_empty'); + + // do not allow wildcards on website domains + $result = $this->_regex_validate($field_value); + if(!$result) return $this->get_error('domain_error_regex'); + + $result = $this->_check_unique($field_value); + if(!$result) return $this->get_error('domain_error_unique'); + } + + /* Validator function for sub domain */ + function sub_domain($field_name, $field_value, $validator) { + if(empty($field_value)) return $this->get_error('domain_error_empty'); + + $allow_wildcard = $this->_wildcard_limit(); + if($allow_wildcard == false && substr($field_value, 0, 2) === '*.') return $this->get_error('domain_error_wildcard'); + + $result = $this->_regex_validate($field_value, $allow_wildcard); + if(!$result) return $this->get_error('domain_error_regex'); + + $result = $this->_check_unique($field_value); + if(!$result) return $this->get_error('domain_error_unique'); + } + + /* Validator function for alias domain */ + function alias_domain($field_name, $field_value, $validator) { + if(empty($field_value)) return $this->get_error('domain_error_empty'); + + // do not allow wildcards on alias domains + $result = $this->_regex_validate($field_value); + if(!$result) return $this->get_error('domain_error_regex'); + + $result = $this->_check_unique($field_value); + if(!$result) return $this->get_error('domain_error_unique'); + } + + /* internal validator function to match regexp */ + function _regex_validate($domain_name, $allow_wildcard = false) { + $pattern = '/^' . ($allow_wildcard == true ? '(\*\.)?' : '') . '[\w\.\-]{2,255}\.[a-zA-Z0-9\-]{2,30}$/'; + return preg_match($pattern, $domain_name); + } + + /* check if the domain hostname is unique (keep in mind the auto subdomains!) */ + function _check_unique($domain_name) { + global $app; + + $check = $app->db->queryOneRecord("SELECT COUNT(*) as `cnt` FROM `web_domain` WHERE `domain` = '" . $app->db->quote($domain_name) . "' AND `domain_id` != " . intval($app->tform->primary_id)); + if($check['cnt'] > 0) return false; + + $check = $app->db->queryOneRecord("SELECT COUNT(*) as `cnt` FROM `web_domain` WHERE CONCAT(`subdomain`, '.', `domain`) = '" . $app->db->quote($domain_name) . "' AND `domain_id` != " . intval($app->tform->primary_id)); + if($check['cnt'] > 0) return false; + + return true; + } + + /* check if the client may add wildcard domains */ + function _wildcard_limit() { + global $app; + + if($_SESSION["s"]["user"]["typ"] != 'admin') { + // Get the limits of the client + $client_group_id = $_SESSION["s"]["user"]["default_group"]; + $client = $app->db->queryOneRecord("SELECT limit_wildcard FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = $client_group_id"); + + if($client["limit_wildcard"] == 'y') return true; + else return false; + } + return true; // admin may always add wildcard domain + } +} \ No newline at end of file diff --git a/interface/web/sites/form/web_aliasdomain.tform.php b/interface/web/sites/form/web_aliasdomain.tform.php index 9507aa066..69cf83135 100644 --- a/interface/web/sites/form/web_aliasdomain.tform.php +++ b/interface/web/sites/form/web_aliasdomain.tform.php @@ -72,14 +72,11 @@ $form["tabs"]['domain'] = array ( 'domain' => array ( 'datatype' => 'VARCHAR', 'formtype' => 'TEXT', - 'validators' => array ( 0 => array ( 'type' => 'NOTEMPTY', - 'errmsg'=> 'domain_error_empty'), - 1 => array ( 'type' => 'UNIQUE', - 'errmsg'=> 'domain_error_unique'), - 2 => array ( 'type' => 'REGEX', - 'regex' => '/^[\w\.\-]{2,255}\.[a-zA-Z0-9\-]{2,30}$/', - 'errmsg'=> 'domain_error_regex'), - ), + 'validators' => array ( 0 => array ( 'type' => 'CUSTOM', + 'class' => 'validate_domain', + 'function' => 'alias_domain', + 'errmsg'=> 'domain_error_regex'), + ), 'default' => '', 'value' => '', 'width' => '30', diff --git a/interface/web/sites/form/web_domain.tform.php b/interface/web/sites/form/web_domain.tform.php index 467376cab..1deec48ad 100644 --- a/interface/web/sites/form/web_domain.tform.php +++ b/interface/web/sites/form/web_domain.tform.php @@ -119,14 +119,11 @@ $form["tabs"]['domain'] = array ( 'domain' => array ( 'datatype' => 'VARCHAR', 'formtype' => 'TEXT', - 'validators' => array ( 0 => array ( 'type' => 'NOTEMPTY', - 'errmsg'=> 'domain_error_empty'), - 1 => array ( 'type' => 'UNIQUE', - 'errmsg'=> 'domain_error_unique'), - 2 => array ( 'type' => 'REGEX', - 'regex' => '/^[\w\.\-]{2,255}\.[a-zA-Z0-9\-]{2,30}$/', - 'errmsg'=> 'domain_error_regex'), - ), + 'validators' => array ( 0 => array ( 'type' => 'CUSTOM', + 'class' => 'validate_domain', + 'function' => 'web_domain', + 'errmsg'=> 'domain_error_regex'), + ), 'filters' => array ( 0 => array ( 'event' => 'SAVE', 'type' => 'TOLOWER'), ), diff --git a/interface/web/sites/form/web_subdomain.tform.php b/interface/web/sites/form/web_subdomain.tform.php index 9b2744b68..d8d6c2c52 100644 --- a/interface/web/sites/form/web_subdomain.tform.php +++ b/interface/web/sites/form/web_subdomain.tform.php @@ -72,14 +72,11 @@ $form["tabs"]['domain'] = array ( 'domain' => array ( 'datatype' => 'VARCHAR', 'formtype' => 'TEXT', - 'validators' => array ( 0 => array ( 'type' => 'NOTEMPTY', - 'errmsg'=> 'domain_error_empty'), - 1 => array ( 'type' => 'UNIQUE', - 'errmsg'=> 'domain_error_unique'), - 2 => array ( 'type' => 'REGEX', - 'regex' => '/^[\w\.\-]{2,255}\.[a-zA-Z0-9\-]{2,30}$/', - 'errmsg'=> 'domain_error_regex'), - ), + 'validators' => array ( 0 => array ( 'type' => 'CUSTOM', + 'class' => 'validate_domain', + 'function' => 'sub_domain', + 'errmsg'=> 'domain_error_regex'), + ), 'default' => '', 'value' => '', 'width' => '30', diff --git a/interface/web/sites/form/web_vhost_subdomain.tform.php b/interface/web/sites/form/web_vhost_subdomain.tform.php index 1b2576712..3440eba59 100644 --- a/interface/web/sites/form/web_vhost_subdomain.tform.php +++ b/interface/web/sites/form/web_vhost_subdomain.tform.php @@ -111,14 +111,11 @@ $form["tabs"]['domain'] = array ( 'domain' => array ( 'datatype' => 'VARCHAR', 'formtype' => 'TEXT', - 'validators' => array ( 0 => array ( 'type' => 'NOTEMPTY', - 'errmsg'=> 'domain_error_empty'), - 1 => array ( 'type' => 'UNIQUE', - 'errmsg'=> 'domain_error_unique'), - 2 => array ( 'type' => 'REGEX', - 'regex' => '/^[\w\.\-]{2,255}\.[a-zA-Z0-9\-]{2,30}$/', - 'errmsg'=> 'domain_error_regex'), - ), + 'validators' => array ( 0 => array ( 'type' => 'CUSTOM', + 'class' => 'validate_domain', + 'function' => 'sub_domain', + 'errmsg'=> 'domain_error_regex'), + ), 'default' => '', 'value' => '', 'width' => '30', diff --git a/interface/web/sites/lib/lang/de_web_subdomain.lng b/interface/web/sites/lib/lang/de_web_subdomain.lng index 9621a1f2a..20565fd44 100644 --- a/interface/web/sites/lib/lang/de_web_subdomain.lng +++ b/interface/web/sites/lib/lang/de_web_subdomain.lng @@ -35,6 +35,7 @@ $wb['apache_directives_txt'] = 'Apache Direktiven'; $wb['domain_error_empty'] = 'Domain ist leer.'; $wb['domain_error_unique'] = 'Domain muss eindeutig sein.'; $wb['domain_error_regex'] = 'Domainname ist ungültig.'; +$wb['domain_error_wildcard'] = 'Wildcard Subdomains sind nicht erlaubt.'; $wb['host_txt'] = 'Host'; $wb['redirect_error_regex'] = 'Ungültiger redirect Pfad. Gültige Pfade sind beispielsweise: /test/ oder http://www.domain.tld/test/'; $wb['no_redirect_txt'] = 'Kein Redirect'; diff --git a/interface/web/sites/lib/lang/de_web_vhost_subdomain.lng b/interface/web/sites/lib/lang/de_web_vhost_subdomain.lng index d4d9660e8..0b3315a60 100644 --- a/interface/web/sites/lib/lang/de_web_vhost_subdomain.lng +++ b/interface/web/sites/lib/lang/de_web_vhost_subdomain.lng @@ -42,6 +42,7 @@ $wb['apache_directives_txt'] = 'Apache Direktiven'; $wb['domain_error_empty'] = 'Domain ist leer.'; $wb['domain_error_unique'] = 'Domain muss eindeutig sein'; $wb['domain_error_regex'] = 'Domainname ungültig.'; +$wb['domain_error_wildcard'] = 'Wildcard Subdomains sind nicht erlaubt.'; $wb['hd_quota_error_empty'] = 'Harddisk Quota ist leer.'; $wb['traffic_quota_error_empty'] = 'Traffic Quota ist leer.'; $wb['errordocs_txt'] = 'Eigene Fehlerseiten'; diff --git a/interface/web/sites/lib/lang/en_web_subdomain.lng b/interface/web/sites/lib/lang/en_web_subdomain.lng index a26e03e20..a6c3103e6 100644 --- a/interface/web/sites/lib/lang/en_web_subdomain.lng +++ b/interface/web/sites/lib/lang/en_web_subdomain.lng @@ -35,6 +35,7 @@ $wb["apache_directives_txt"] = 'Apache directives'; $wb["domain_error_empty"] = 'Domain is empty.'; $wb["domain_error_unique"] = 'There is already a website or sub / aliasdomain with this domain name.'; $wb["domain_error_regex"] = 'Domain name invalid.'; +$wb['domain_error_wildcard'] = 'Wildcard subdomains are not allowed.'; $wb["host_txt"] = 'Host'; $wb["redirect_error_regex"] = 'Invalid redirect path. Valid redirects are for example: /test/ or http://www.domain.tld/test/'; $wb['no_redirect_txt'] = 'No redirect'; diff --git a/interface/web/sites/lib/lang/en_web_vhost_subdomain.lng b/interface/web/sites/lib/lang/en_web_vhost_subdomain.lng index 42c6e4fe5..d993af80b 100644 --- a/interface/web/sites/lib/lang/en_web_vhost_subdomain.lng +++ b/interface/web/sites/lib/lang/en_web_vhost_subdomain.lng @@ -48,6 +48,7 @@ $wb["apache_directives_txt"] = 'Apache Directives'; $wb["domain_error_empty"] = 'Domain is empty.'; $wb["domain_error_unique"] = 'There is already a website or sub / aliasdomain with this domain name.'; $wb["domain_error_regex"] = 'Domain name invalid.'; +$wb['domain_error_wildcard'] = 'Wildcard subdomains are not allowed.'; $wb["hd_quota_error_empty"] = 'Harddisk quota is 0 or empty.'; $wb["traffic_quota_error_empty"] = 'Traffic quota is empty.'; $wb["error_ssl_state_empty"] = 'SSL State is empty.'; -- GitLab