mcramer
2012-09-13 f6528883010fef654e2bdd870dd5ce020a76dfe8
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.

5 files modified
39 ■■■■■ changed files
interface/lib/classes/validate_domain.inc.php 27 ●●●● patch | view | raw | blame | history
interface/web/sites/form/web_aliasdomain.tform.php 5 ●●●●● patch | view | raw | blame | history
interface/web/sites/form/web_domain.tform.php 5 ●●●●● patch | view | raw | blame | history
interface/web/sites/lib/lang/de_web_domain.lng 1 ●●●● patch | view | raw | blame | history
interface/web/sites/lib/lang/en_web_domain.lng 1 ●●●● patch | view | raw | blame | history
interface/lib/classes/validate_domain.inc.php
@@ -79,6 +79,25 @@
        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 @@
    }
    
    /* 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;
    }
interface/web/sites/form/web_aliasdomain.tform.php
@@ -121,6 +121,11 @@
            '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 (
interface/web/sites/form/web_domain.tform.php
@@ -212,6 +212,11 @@
            '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 (
interface/web/sites/lib/lang/de_web_domain.lng
@@ -37,6 +37,7 @@
$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';
interface/web/sites/lib/lang/en_web_domain.lng
@@ -43,6 +43,7 @@
$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.';