Commit f6528883 authored by mcramer's avatar mcramer
Browse files

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.
parent 8ec1d882
......@@ -79,6 +79,25 @@ class validate_domain {
if(!$result) return $this->get_error('domain_error_unique');
}
/* Validator function for checking the auto subdomain of a web/aliasdomain */
function web_domain_autosub($field_name, $field_value, $validator) {
global $app;
if(empty($field_value) || $field_name != 'subdomain') return; // none set
$check_domain = $_POST['domain'];
$app->uses('ini_parser,getconf');
$settings = $app->getconf->get_global_config('domains');
if ($settings['use_domain_module'] == 'y') {
$sql = "SELECT domain_id, domain FROM domain WHERE domain_id = " . intval($check_domain);
$domain_check = $app->db->queryOneRecord($sql);
if(!$domain_check) return;
$check_domain = $domain_check['domain'];
}
$result = $this->_check_unique($field_value . '.' . $check_domain, true);
if(!$result) return $this->get_error('domain_error_autosub');
}
/* 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}$/';
......@@ -86,14 +105,16 @@ class validate_domain {
}
/* check if the domain hostname is unique (keep in mind the auto subdomains!) */
function _check_unique($domain_name) {
function _check_unique($domain_name, $only_domain = false) {
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;
if($only_domain == 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;
}
......
......@@ -121,6 +121,11 @@ $form["tabs"]['domain'] = array (
'datatype' => 'VARCHAR',
'formtype' => 'SELECT',
'default' => 'www',
'validators' => array ( 0 => array ( 'type' => 'CUSTOM',
'class' => 'validate_domain',
'function' => 'web_domain_autosub',
'errmsg'=> 'domain_error_autosub'),
),
'value' => array('none' => 'none_txt', 'www' => 'www.', '*' => '*.')
),
'active' => array (
......
......@@ -212,6 +212,11 @@ $form["tabs"]['domain'] = array (
'datatype' => 'VARCHAR',
'formtype' => 'SELECT',
'default' => 'www',
'validators' => array ( 0 => array ( 'type' => 'CUSTOM',
'class' => 'validate_domain',
'function' => 'web_domain_autosub',
'errmsg'=> 'domain_error_autosub'),
),
'value' => ($wildcard_available ? array('none' => 'none_txt', 'www' => 'www.', '*' => '*.') : array('none' => 'none_txt', 'www' => 'www.'))
),
'ssl' => array (
......
......@@ -37,6 +37,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_autosub'] = 'Es existiert bereits eine Subdomain mit diesen Einstellungen.';
$wb['hd_quota_error_empty'] = 'Harddisk Quota ist leer.';
$wb['traffic_quota_error_empty'] = 'Traffic Quota ist leer.';
$wb['errordocs_txt'] = 'Eigene Fehlerseiten';
......
......@@ -43,6 +43,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_autosub"] = 'There is already a subdomain with these settings.';
$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.';
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment