@@ -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 }
0 commit comments