Skip to content

Commit f652888

Browse files
author
mcramer
committed
Fixed/Implemented: Added unique check on auto-subdomains, too.
If you change an auto subdomain of an alias/web-domain there has to be checked if a subdomain with www. or *. has been created already.
1 parent 8ec1d88 commit f652888

File tree

5 files changed

+36
-3
lines changed

5 files changed

+36
-3
lines changed

interface/lib/classes/validate_domain.inc.php

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,21 +79,42 @@ function alias_domain($field_name, $field_value, $validator) {
7979
if(!$result) return $this->get_error('domain_error_unique');
8080
}
8181

82+
/* Validator function for checking the auto subdomain of a web/aliasdomain */
83+
function web_domain_autosub($field_name, $field_value, $validator) {
84+
global $app;
85+
if(empty($field_value) || $field_name != 'subdomain') return; // none set
86+
87+
$check_domain = $_POST['domain'];
88+
$app->uses('ini_parser,getconf');
89+
$settings = $app->getconf->get_global_config('domains');
90+
if ($settings['use_domain_module'] == 'y') {
91+
$sql = "SELECT domain_id, domain FROM domain WHERE domain_id = " . intval($check_domain);
92+
$domain_check = $app->db->queryOneRecord($sql);
93+
if(!$domain_check) return;
94+
$check_domain = $domain_check['domain'];
95+
}
96+
97+
$result = $this->_check_unique($field_value . '.' . $check_domain, true);
98+
if(!$result) return $this->get_error('domain_error_autosub');
99+
}
100+
82101
/* internal validator function to match regexp */
83102
function _regex_validate($domain_name, $allow_wildcard = false) {
84103
$pattern = '/^' . ($allow_wildcard == true ? '(\*\.)?' : '') . '[\w\.\-]{2,255}\.[a-zA-Z0-9\-]{2,30}$/';
85104
return preg_match($pattern, $domain_name);
86105
}
87106

88107
/* check if the domain hostname is unique (keep in mind the auto subdomains!) */
89-
function _check_unique($domain_name) {
108+
function _check_unique($domain_name, $only_domain = false) {
90109
global $app;
91110

92111
$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));
93112
if($check['cnt'] > 0) return false;
94113

95-
$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));
96-
if($check['cnt'] > 0) return false;
114+
if($only_domain == false) {
115+
$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));
116+
if($check['cnt'] > 0) return false;
117+
}
97118

98119
return true;
99120
}

interface/web/sites/form/web_aliasdomain.tform.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,11 @@
121121
'datatype' => 'VARCHAR',
122122
'formtype' => 'SELECT',
123123
'default' => 'www',
124+
'validators' => array ( 0 => array ( 'type' => 'CUSTOM',
125+
'class' => 'validate_domain',
126+
'function' => 'web_domain_autosub',
127+
'errmsg'=> 'domain_error_autosub'),
128+
),
124129
'value' => array('none' => 'none_txt', 'www' => 'www.', '*' => '*.')
125130
),
126131
'active' => array (

interface/web/sites/form/web_domain.tform.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,11 @@
212212
'datatype' => 'VARCHAR',
213213
'formtype' => 'SELECT',
214214
'default' => 'www',
215+
'validators' => array ( 0 => array ( 'type' => 'CUSTOM',
216+
'class' => 'validate_domain',
217+
'function' => 'web_domain_autosub',
218+
'errmsg'=> 'domain_error_autosub'),
219+
),
215220
'value' => ($wildcard_available ? array('none' => 'none_txt', 'www' => 'www.', '*' => '*.') : array('none' => 'none_txt', 'www' => 'www.'))
216221
),
217222
'ssl' => array (

interface/web/sites/lib/lang/de_web_domain.lng

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ $wb['apache_directives_txt'] = 'Apache Direktiven';
3737
$wb['domain_error_empty'] = 'Domain ist leer.';
3838
$wb['domain_error_unique'] = 'Domain muss eindeutig sein';
3939
$wb['domain_error_regex'] = 'Domainname ungültig.';
40+
$wb['domain_error_autosub'] = 'Es existiert bereits eine Subdomain mit diesen Einstellungen.';
4041
$wb['hd_quota_error_empty'] = 'Harddisk Quota ist leer.';
4142
$wb['traffic_quota_error_empty'] = 'Traffic Quota ist leer.';
4243
$wb['errordocs_txt'] = 'Eigene Fehlerseiten';

interface/web/sites/lib/lang/en_web_domain.lng

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ $wb["apache_directives_txt"] = 'Apache Directives';
4343
$wb["domain_error_empty"] = 'Domain is empty.';
4444
$wb["domain_error_unique"] = 'There is already a website or sub / aliasdomain with this domain name.';
4545
$wb["domain_error_regex"] = 'Domain name invalid.';
46+
$wb["domain_error_autosub"] = 'There is already a subdomain with these settings.';
4647
$wb["hd_quota_error_empty"] = 'Harddisk quota is 0 or empty.';
4748
$wb["traffic_quota_error_empty"] = 'Traffic quota is empty.';
4849
$wb["error_ssl_state_empty"] = 'SSL State is empty.';

0 commit comments

Comments
 (0)