From c7f0b83c0da6f807f5859d5d666c1dfd009019b9 Mon Sep 17 00:00:00 2001
From: tbrehm <t.brehm@ispconfig.org>
Date: Tue, 06 Nov 2012 10:11:11 -0500
Subject: [PATCH] Implemented: FS#2437 - iterate_query in dovecot-sql.conf is missing The query is added for reference and is commented out by default as it is not compatible with dovecot 1.2 and not required by ispconfig.

---
 interface/lib/classes/validate_domain.inc.php |   35 +++++++++++++++++++++++++++++++----
 1 files changed, 31 insertions(+), 4 deletions(-)

diff --git a/interface/lib/classes/validate_domain.inc.php b/interface/lib/classes/validate_domain.inc.php
index 25f16af..e70f161 100644
--- a/interface/lib/classes/validate_domain.inc.php
+++ b/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 = " . $app->functions->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,22 @@
     }
     
     /* 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(isset($app->remoting_lib->primary_id)) {
+            $primary_id = $app->remoting_lib->primary_id;
+        } else {
+            $primary_id = $app->tform->primary_id;
+        }
+        
+        $check = $app->db->queryOneRecord("SELECT COUNT(*) as `cnt` FROM `web_domain` WHERE `domain` = '" . $app->db->quote($domain_name) . "' AND `domain_id` != " . $app->functions->intval($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` != " . $app->functions->intval($primary_id));
+            if($check['cnt'] > 0) return false;
+        }
         
         return true;
     }

--
Gitblit v1.9.1