Skip to content

Commit 8ec1d88

Browse files
author
mcramer
committed
Fixed: FS#2426 - Auto subdomains are ignored when checking if domain is unique
Implemented: FS#2427 - Allow wildcard subdomain creation on limit_wildcard = y
1 parent 3898c94 commit 8ec1d88

File tree

9 files changed

+139
-32
lines changed

9 files changed

+139
-32
lines changed
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
<?php
2+
3+
/*
4+
Copyright (c) 2007, Till Brehm, projektfarm Gmbh
5+
Copyright (c) 2012, Marius Cramer, pixcept KG
6+
All rights reserved.
7+
8+
Redistribution and use in source and binary forms, with or without modification,
9+
are permitted provided that the following conditions are met:
10+
11+
* Redistributions of source code must retain the above copyright notice,
12+
this list of conditions and the following disclaimer.
13+
* Redistributions in binary form must reproduce the above copyright notice,
14+
this list of conditions and the following disclaimer in the documentation
15+
and/or other materials provided with the distribution.
16+
* Neither the name of ISPConfig nor the names of its contributors
17+
may be used to endorse or promote products derived from this software without
18+
specific prior written permission.
19+
20+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
21+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23+
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
24+
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
25+
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
27+
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
29+
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30+
*/
31+
32+
class validate_domain {
33+
34+
function get_error($errmsg) {
35+
global $app;
36+
37+
if(isset($app->tform->wordbook[$errmsg])) {
38+
return $app->tform->wordbook[$errmsg]."<br>\r\n";
39+
} else {
40+
return $errmsg."<br>\r\n";
41+
}
42+
}
43+
44+
/* Validator function for domain (website) */
45+
function web_domain($field_name, $field_value, $validator) {
46+
if(empty($field_value)) return $this->get_error('domain_error_empty');
47+
48+
// do not allow wildcards on website domains
49+
$result = $this->_regex_validate($field_value);
50+
if(!$result) return $this->get_error('domain_error_regex');
51+
52+
$result = $this->_check_unique($field_value);
53+
if(!$result) return $this->get_error('domain_error_unique');
54+
}
55+
56+
/* Validator function for sub domain */
57+
function sub_domain($field_name, $field_value, $validator) {
58+
if(empty($field_value)) return $this->get_error('domain_error_empty');
59+
60+
$allow_wildcard = $this->_wildcard_limit();
61+
if($allow_wildcard == false && substr($field_value, 0, 2) === '*.') return $this->get_error('domain_error_wildcard');
62+
63+
$result = $this->_regex_validate($field_value, $allow_wildcard);
64+
if(!$result) return $this->get_error('domain_error_regex');
65+
66+
$result = $this->_check_unique($field_value);
67+
if(!$result) return $this->get_error('domain_error_unique');
68+
}
69+
70+
/* Validator function for alias domain */
71+
function alias_domain($field_name, $field_value, $validator) {
72+
if(empty($field_value)) return $this->get_error('domain_error_empty');
73+
74+
// do not allow wildcards on alias domains
75+
$result = $this->_regex_validate($field_value);
76+
if(!$result) return $this->get_error('domain_error_regex');
77+
78+
$result = $this->_check_unique($field_value);
79+
if(!$result) return $this->get_error('domain_error_unique');
80+
}
81+
82+
/* internal validator function to match regexp */
83+
function _regex_validate($domain_name, $allow_wildcard = false) {
84+
$pattern = '/^' . ($allow_wildcard == true ? '(\*\.)?' : '') . '[\w\.\-]{2,255}\.[a-zA-Z0-9\-]{2,30}$/';
85+
return preg_match($pattern, $domain_name);
86+
}
87+
88+
/* check if the domain hostname is unique (keep in mind the auto subdomains!) */
89+
function _check_unique($domain_name) {
90+
global $app;
91+
92+
$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));
93+
if($check['cnt'] > 0) return false;
94+
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;
97+
98+
return true;
99+
}
100+
101+
/* check if the client may add wildcard domains */
102+
function _wildcard_limit() {
103+
global $app;
104+
105+
if($_SESSION["s"]["user"]["typ"] != 'admin') {
106+
// Get the limits of the client
107+
$client_group_id = $_SESSION["s"]["user"]["default_group"];
108+
$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");
109+
110+
if($client["limit_wildcard"] == 'y') return true;
111+
else return false;
112+
}
113+
return true; // admin may always add wildcard domain
114+
}
115+
}

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

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,11 @@
7272
'domain' => array (
7373
'datatype' => 'VARCHAR',
7474
'formtype' => 'TEXT',
75-
'validators' => array ( 0 => array ( 'type' => 'NOTEMPTY',
76-
'errmsg'=> 'domain_error_empty'),
77-
1 => array ( 'type' => 'UNIQUE',
78-
'errmsg'=> 'domain_error_unique'),
79-
2 => array ( 'type' => 'REGEX',
80-
'regex' => '/^[\w\.\-]{2,255}\.[a-zA-Z0-9\-]{2,30}$/',
81-
'errmsg'=> 'domain_error_regex'),
82-
),
75+
'validators' => array ( 0 => array ( 'type' => 'CUSTOM',
76+
'class' => 'validate_domain',
77+
'function' => 'alias_domain',
78+
'errmsg'=> 'domain_error_regex'),
79+
),
8380
'default' => '',
8481
'value' => '',
8582
'width' => '30',

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

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -119,14 +119,11 @@
119119
'domain' => array (
120120
'datatype' => 'VARCHAR',
121121
'formtype' => 'TEXT',
122-
'validators' => array ( 0 => array ( 'type' => 'NOTEMPTY',
123-
'errmsg'=> 'domain_error_empty'),
124-
1 => array ( 'type' => 'UNIQUE',
125-
'errmsg'=> 'domain_error_unique'),
126-
2 => array ( 'type' => 'REGEX',
127-
'regex' => '/^[\w\.\-]{2,255}\.[a-zA-Z0-9\-]{2,30}$/',
128-
'errmsg'=> 'domain_error_regex'),
129-
),
122+
'validators' => array ( 0 => array ( 'type' => 'CUSTOM',
123+
'class' => 'validate_domain',
124+
'function' => 'web_domain',
125+
'errmsg'=> 'domain_error_regex'),
126+
),
130127
'filters' => array ( 0 => array ( 'event' => 'SAVE',
131128
'type' => 'TOLOWER'),
132129
),

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

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,11 @@
7272
'domain' => array (
7373
'datatype' => 'VARCHAR',
7474
'formtype' => 'TEXT',
75-
'validators' => array ( 0 => array ( 'type' => 'NOTEMPTY',
76-
'errmsg'=> 'domain_error_empty'),
77-
1 => array ( 'type' => 'UNIQUE',
78-
'errmsg'=> 'domain_error_unique'),
79-
2 => array ( 'type' => 'REGEX',
80-
'regex' => '/^[\w\.\-]{2,255}\.[a-zA-Z0-9\-]{2,30}$/',
81-
'errmsg'=> 'domain_error_regex'),
82-
),
75+
'validators' => array ( 0 => array ( 'type' => 'CUSTOM',
76+
'class' => 'validate_domain',
77+
'function' => 'sub_domain',
78+
'errmsg'=> 'domain_error_regex'),
79+
),
8380
'default' => '',
8481
'value' => '',
8582
'width' => '30',

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

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -111,14 +111,11 @@
111111
'domain' => array (
112112
'datatype' => 'VARCHAR',
113113
'formtype' => 'TEXT',
114-
'validators' => array ( 0 => array ( 'type' => 'NOTEMPTY',
115-
'errmsg'=> 'domain_error_empty'),
116-
1 => array ( 'type' => 'UNIQUE',
117-
'errmsg'=> 'domain_error_unique'),
118-
2 => array ( 'type' => 'REGEX',
119-
'regex' => '/^[\w\.\-]{2,255}\.[a-zA-Z0-9\-]{2,30}$/',
120-
'errmsg'=> 'domain_error_regex'),
121-
),
114+
'validators' => array ( 0 => array ( 'type' => 'CUSTOM',
115+
'class' => 'validate_domain',
116+
'function' => 'sub_domain',
117+
'errmsg'=> 'domain_error_regex'),
118+
),
122119
'default' => '',
123120
'value' => '',
124121
'width' => '30',

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ $wb['apache_directives_txt'] = 'Apache Direktiven';
3535
$wb['domain_error_empty'] = 'Domain ist leer.';
3636
$wb['domain_error_unique'] = 'Domain muss eindeutig sein.';
3737
$wb['domain_error_regex'] = 'Domainname ist ungültig.';
38+
$wb['domain_error_wildcard'] = 'Wildcard Subdomains sind nicht erlaubt.';
3839
$wb['host_txt'] = 'Host';
3940
$wb['redirect_error_regex'] = 'Ungültiger redirect Pfad. Gültige Pfade sind beispielsweise: /test/ oder http://www.domain.tld/test/';
4041
$wb['no_redirect_txt'] = 'Kein Redirect';

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ $wb['apache_directives_txt'] = 'Apache Direktiven';
4242
$wb['domain_error_empty'] = 'Domain ist leer.';
4343
$wb['domain_error_unique'] = 'Domain muss eindeutig sein';
4444
$wb['domain_error_regex'] = 'Domainname ungültig.';
45+
$wb['domain_error_wildcard'] = 'Wildcard Subdomains sind nicht erlaubt.';
4546
$wb['hd_quota_error_empty'] = 'Harddisk Quota ist leer.';
4647
$wb['traffic_quota_error_empty'] = 'Traffic Quota ist leer.';
4748
$wb['errordocs_txt'] = 'Eigene Fehlerseiten';

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ $wb["apache_directives_txt"] = 'Apache directives';
3535
$wb["domain_error_empty"] = 'Domain is empty.';
3636
$wb["domain_error_unique"] = 'There is already a website or sub / aliasdomain with this domain name.';
3737
$wb["domain_error_regex"] = 'Domain name invalid.';
38+
$wb['domain_error_wildcard'] = 'Wildcard subdomains are not allowed.';
3839
$wb["host_txt"] = 'Host';
3940
$wb["redirect_error_regex"] = 'Invalid redirect path. Valid redirects are for example: /test/ or http://www.domain.tld/test/';
4041
$wb['no_redirect_txt'] = 'No redirect';

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ $wb["apache_directives_txt"] = 'Apache Directives';
4848
$wb["domain_error_empty"] = 'Domain is empty.';
4949
$wb["domain_error_unique"] = 'There is already a website or sub / aliasdomain with this domain name.';
5050
$wb["domain_error_regex"] = 'Domain name invalid.';
51+
$wb['domain_error_wildcard'] = 'Wildcard subdomains are not allowed.';
5152
$wb["hd_quota_error_empty"] = 'Harddisk quota is 0 or empty.';
5253
$wb["traffic_quota_error_empty"] = 'Traffic quota is empty.';
5354
$wb["error_ssl_state_empty"] = 'SSL State is empty.';

0 commit comments

Comments
 (0)