From 4fae7e24eb4a3d3dd5cd3eeaa97d6fef97426547 Mon Sep 17 00:00:00 2001
From: tbrehm <t.brehm@ispconfig.org>
Date: Tue, 3 Jul 2007 20:23:03 +0000
Subject: [PATCH] Added limits for websites and FTP users.

---
 interface/web/client/form/client.tform.php    | 67 +++++++++++++++++++
 interface/web/client/lib/lang/en_client.lng   |  6 ++
 .../client/templates/client_edit_limits.htm   | 27 ++++++++
 interface/web/sites/ftp_user_edit.php         | 21 ++++++
 interface/web/sites/lib/lang/en_ftp_user.lng  |  1 +
 .../web/sites/lib/lang/en_web_domain.lng      | 47 +++++++------
 interface/web/sites/web_aliasdomain_edit.php  | 22 ++++++
 interface/web/sites/web_domain_edit.php       | 38 ++++++++---
 interface/web/sites/web_subdomain_edit.php    | 23 +++++++
 server/plugins-enabled/apache2_plugin.inc.php |  4 +-
 10 files changed, 224 insertions(+), 32 deletions(-)

diff --git a/interface/web/client/form/client.tform.php b/interface/web/client/form/client.tform.php
index 2d2920ecd1..6aba152b88 100644
--- a/interface/web/client/form/client.tform.php
+++ b/interface/web/client/form/client.tform.php
@@ -459,6 +459,73 @@ $form["tabs"]['limits'] = array (
 			'rows'		=> '',
 			'cols'		=> ''
 		),
+		'default_webserver' => array (
+			'datatype'	=> 'INTEGER',
+			'formtype'	=> 'SELECT',
+			'default'	=> '1',
+			'datasource'	=> array ( 	'type'	=> 'SQL',
+										'querystring' => 'SELECT server_id,server_name FROM server WHERE {AUTHSQL} ORDER BY server_name',
+										'keyfield'=> 'server_id',
+										'valuefield'=> 'server_name'
+									 ),
+			'value'		=> ''
+		),
+		'limit_web_domain' => array (
+			'datatype'	=> 'INTEGER',
+			'formtype'	=> 'TEXT',
+			'validators'	=> array ( 	0 => array (	'type'	=> 'ISINT',
+														'errmsg'=> 'limit_web_domain_error_notint'),
+									),
+			'default'	=> '-1',
+			'value'		=> '',
+			'separator'	=> '',
+			'width'		=> '10',
+			'maxlength'	=> '10',
+			'rows'		=> '',
+			'cols'		=> ''
+		),
+		'limit_web_aliasdomain' => array (
+			'datatype'	=> 'INTEGER',
+			'formtype'	=> 'TEXT',
+			'validators'	=> array ( 	0 => array (	'type'	=> 'ISINT',
+														'errmsg'=> 'limit_web_aliasdomain_error_notint'),
+									),
+			'default'	=> '-1',
+			'value'		=> '',
+			'separator'	=> '',
+			'width'		=> '10',
+			'maxlength'	=> '10',
+			'rows'		=> '',
+			'cols'		=> ''
+		),
+		'limit_web_subdomain' => array (
+			'datatype'	=> 'INTEGER',
+			'formtype'	=> 'TEXT',
+			'validators'	=> array ( 	0 => array (	'type'	=> 'ISINT',
+														'errmsg'=> 'limit_web_subdomain_error_notint'),
+									),
+			'default'	=> '-1',
+			'value'		=> '',
+			'separator'	=> '',
+			'width'		=> '10',
+			'maxlength'	=> '10',
+			'rows'		=> '',
+			'cols'		=> ''
+		),
+		'limit_ftp_user' => array (
+			'datatype'	=> 'INTEGER',
+			'formtype'	=> 'TEXT',
+			'validators'	=> array ( 	0 => array (	'type'	=> 'ISINT',
+														'errmsg'=> 'limit_ftp_user_error_notint'),
+									),
+			'default'	=> '-1',
+			'value'		=> '',
+			'separator'	=> '',
+			'width'		=> '10',
+			'maxlength'	=> '10',
+			'rows'		=> '',
+			'cols'		=> ''
+		),
 	##################################
 	# END Datatable fields
 	##################################
diff --git a/interface/web/client/lib/lang/en_client.lng b/interface/web/client/lib/lang/en_client.lng
index 39cd44b543..90472f60c6 100644
--- a/interface/web/client/lib/lang/en_client.lng
+++ b/interface/web/client/lib/lang/en_client.lng
@@ -45,4 +45,10 @@ $wb["ip_address_txt"] = 'ip_address';
 $wb["limit_client_error_notint"] = 'Client Limit is not a number.';
 $wb["firstname_error_empty"] = 'Firstname is empty.';
 $wb["contact_error_empty"] = 'Contact name is empty.';
+$wb["default_webserver_txt"] = 'Default Webserver';
+$wb["limit_web_domain_txt"] = 'Max. number of web domains';
+$wb["limit_web_aliasdomain_txt"] = 'Max. number of web aliasdomains';
+$wb["limit_web_subdomain_txt"] = 'Max. number of web subdomains';
+$wb["limit_ftp_user_txt"] = 'Max. number of FTP users';
+
 ?>
\ No newline at end of file
diff --git a/interface/web/client/templates/client_edit_limits.htm b/interface/web/client/templates/client_edit_limits.htm
index be92c42ec4..979e9d951c 100644
--- a/interface/web/client/templates/client_edit_limits.htm
+++ b/interface/web/client/templates/client_edit_limits.htm
@@ -63,6 +63,33 @@
     <td class="frmText11">{tmpl_var name='limit_spamfilter_policy_txt'}:</td>
     <td class="frmText11"><input name="limit_spamfilter_policy" type="text" class="text" value="{tmpl_var name='limit_spamfilter_policy'}" size="10" maxlength="10"></td>
   </tr>
+  <tr>
+    <td><h2>Websites</h2></td>
+  </tr>
+  <tr>
+    <td class="frmText11">{tmpl_var name='default_webserver_txt'}:</td>
+    <td class="frmText11">
+		<select name="default_webserver" class="text">
+			{tmpl_var name='default_webserver'}
+		</select>
+	</td>
+  </tr>
+  <tr>
+    <td class="frmText11" width="280">{tmpl_var name='limit_web_domain_txt'}:</td>
+    <td class="frmText11" width="220"><input name="limit_web_domain" type="text" class="text" value="{tmpl_var name='limit_web_domain'}" size="10" maxlength="10"></td>
+  </tr>
+  <tr>
+    <td class="frmText11" width="280">{tmpl_var name='limit_web_subdomain_txt'}:</td>
+    <td class="frmText11" width="220"><input name="limit_web_subdomain" type="text" class="text" value="{tmpl_var name='limit_web_subdomain'}" size="10" maxlength="10"></td>
+  </tr>
+  <tr>
+    <td class="frmText11" width="280">{tmpl_var name='limit_web_aliasdomain_txt'}:</td>
+    <td class="frmText11" width="220"><input name="limit_web_aliasdomain" type="text" class="text" value="{tmpl_var name='limit_web_aliasdomain'}" size="10" maxlength="10"></td>
+  </tr>
+  <tr>
+    <td class="frmText11" width="280">{tmpl_var name='limit_ftp_user_txt'}:</td>
+    <td class="frmText11" width="220"><input name="limit_ftp_user" type="text" class="text" value="{tmpl_var name='limit_ftp_user'}" size="10" maxlength="10"></td>
+  </tr>
   <tr>
     <td class="frmText11">&nbsp;</td>
     <td class="frmText11">&nbsp;</td>
diff --git a/interface/web/sites/ftp_user_edit.php b/interface/web/sites/ftp_user_edit.php
index 4c90855b4c..2c704b67c8 100644
--- a/interface/web/sites/ftp_user_edit.php
+++ b/interface/web/sites/ftp_user_edit.php
@@ -53,6 +53,27 @@ $app->load('tform_actions');
 
 class page_action extends tform_actions {
 	
+	function onShowNew() {
+		global $app, $conf;
+		
+		// we will check only users, not admins
+		if($_SESSION["s"]["user"]["typ"] == 'user') {
+			
+			// Get the limits of the client
+			$client_group_id = $_SESSION["s"]["user"]["default_group"];
+			$client = $app->db->queryOneRecord("SELECT limit_ftp_user FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = $client_group_id");
+			
+			// Check if the user may add another maildomain.
+			if($client["limit_ftp_user"] >= 0) {
+				$tmp = $app->db->queryOneRecord("SELECT count(ftp_user_id) as number FROM ftp_user WHERE sys_groupid = $client_group_id");
+				if($tmp["number"] >= $client["limit_ftp_user"]) {
+					$app->error($app->tform->wordbook["limit_ftp_user_txt"]);
+				}
+			}
+		}
+		
+		parent::onShowNew();
+	}
 	
 	function onAfterInsert() {
 		global $app, $conf;
diff --git a/interface/web/sites/lib/lang/en_ftp_user.lng b/interface/web/sites/lib/lang/en_ftp_user.lng
index 45fb750908..ba63a9ab89 100644
--- a/interface/web/sites/lib/lang/en_ftp_user.lng
+++ b/interface/web/sites/lib/lang/en_ftp_user.lng
@@ -15,4 +15,5 @@ $wb["username_txt"] = 'Username';
 $wb["password_txt"] = 'Password';
 $wb["quota_size_txt"] = 'Harddisk-Quota';
 $wb["active_txt"] = 'Active';
+$wb["limit_ftp_user_txt"] = 'The max. number of FTP users for your account is reached.';
 ?>
\ No newline at end of file
diff --git a/interface/web/sites/lib/lang/en_web_domain.lng b/interface/web/sites/lib/lang/en_web_domain.lng
index 38e0510f40..bdb41e26c8 100644
--- a/interface/web/sites/lib/lang/en_web_domain.lng
+++ b/interface/web/sites/lib/lang/en_web_domain.lng
@@ -1,23 +1,26 @@
-<?php
-$wb["server_id_txt"] = 'Server';
-$wb["domain_txt"] = 'Domain';
-$wb["type_txt"] = 'Type';
-$wb["parent_domain_id_txt"] = 'Parent Website';
-$wb["redirect_type_txt"] = 'Redirect Type';
-$wb["redirect_path_txt"] = 'Redirect Path';
-$wb["active_txt"] = 'Active';
-$wb["btn_save_txt"] = 'Save';
-$wb["btn_cancel_txt"] = 'Cancel';
-$wb["document_root_txt"] = 'Documentroot';
-$wb["system_user_txt"] = 'Linux User';
-$wb["system_group_txt"] = 'Linux Group';
-$wb["ip_address_txt"] = 'IP-Address';
-$wb["vhost_type_txt"] = 'VHost Type';
-$wb["hd_quota_txt"] = 'Harddisk Quota';
-$wb["traffic_quota_txt"] = 'Traffic Quaota';
-$wb["cgi_txt"] = 'CGI';
-$wb["ssi_txt"] = 'SSI';
-$wb["suexec_txt"] = 'SuEXEC';
-$wb["php_txt"] = 'PHP';
-$wb["client_txt"] = 'Client';
+<?php
+$wb["server_id_txt"] = 'Server';
+$wb["domain_txt"] = 'Domain';
+$wb["type_txt"] = 'Type';
+$wb["parent_domain_id_txt"] = 'Parent Website';
+$wb["redirect_type_txt"] = 'Redirect Type';
+$wb["redirect_path_txt"] = 'Redirect Path';
+$wb["active_txt"] = 'Active';
+$wb["btn_save_txt"] = 'Save';
+$wb["btn_cancel_txt"] = 'Cancel';
+$wb["document_root_txt"] = 'Documentroot';
+$wb["system_user_txt"] = 'Linux User';
+$wb["system_group_txt"] = 'Linux Group';
+$wb["ip_address_txt"] = 'IP-Address';
+$wb["vhost_type_txt"] = 'VHost Type';
+$wb["hd_quota_txt"] = 'Harddisk Quota';
+$wb["traffic_quota_txt"] = 'Traffic Quaota';
+$wb["cgi_txt"] = 'CGI';
+$wb["ssi_txt"] = 'SSI';
+$wb["suexec_txt"] = 'SuEXEC';
+$wb["php_txt"] = 'PHP';
+$wb["client_txt"] = 'Client';
+$wb["limit_web_domain_txt"] = 'The max. number of web domains for your account is reached.';
+$wb["limit_web_aliasdomain_txt"] = 'The max. number of aliasdomains for your account is reached.';
+$wb["limit_web_subdomain_txt"] = 'The max. number of web subdomains for your account is reached.';
 ?>
\ No newline at end of file
diff --git a/interface/web/sites/web_aliasdomain_edit.php b/interface/web/sites/web_aliasdomain_edit.php
index e7cef10532..67e7421f1d 100644
--- a/interface/web/sites/web_aliasdomain_edit.php
+++ b/interface/web/sites/web_aliasdomain_edit.php
@@ -53,6 +53,28 @@ $app->load('tform_actions');
 
 class page_action extends tform_actions {
 	
+	function onShowNew() {
+		global $app, $conf;
+		
+		// we will check only users, not admins
+		if($_SESSION["s"]["user"]["typ"] == 'user') {
+			
+			// Get the limits of the client
+			$client_group_id = $_SESSION["s"]["user"]["default_group"];
+			$client = $app->db->queryOneRecord("SELECT limit_web_aliasdomain FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = $client_group_id");
+			
+			// Check if the user may add another maildomain.
+			if($client["limit_web_aliasdomain"] >= 0) {
+				$tmp = $app->db->queryOneRecord("SELECT count(domain_id) as number FROM web_domain WHERE sys_groupid = $client_group_id and type = 'alias'");
+				if($tmp["number"] >= $client["limit_web_aliasdomain"]) {
+					$app->error($app->tform->wordbook["limit_web_aliasdomain_txt"]);
+				}
+			}
+		}
+		
+		parent::onShowNew();
+	}
+	
 	/*
 	function onShowEnd() {
 		global $app, $conf;
diff --git a/interface/web/sites/web_domain_edit.php b/interface/web/sites/web_domain_edit.php
index 5f208dbafc..f925bd2a26 100644
--- a/interface/web/sites/web_domain_edit.php
+++ b/interface/web/sites/web_domain_edit.php
@@ -53,6 +53,28 @@ $app->load('tform_actions');
 
 class page_action extends tform_actions {
 
+	function onShowNew() {
+		global $app, $conf;
+		
+		// we will check only users, not admins
+		if($_SESSION["s"]["user"]["typ"] == 'user') {
+			
+			// Get the limits of the client
+			$client_group_id = $_SESSION["s"]["user"]["default_group"];
+			$client = $app->db->queryOneRecord("SELECT limit_web_domain FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = $client_group_id");
+			
+			// Check if the user may add another maildomain.
+			if($client["limit_web_domain"] >= 0) {
+				$tmp = $app->db->queryOneRecord("SELECT count(domain_id) as number FROM web_domain WHERE sys_groupid = $client_group_id and type = 'vhost'");
+				if($tmp["number"] >= $client["limit_web_domain"]) {
+					$app->error($app->tform->wordbook["limit_web_domain_txt"]);
+				}
+			}
+		}
+		
+		parent::onShowNew();
+	}
+	
 	function onShowEnd() {
 		global $app, $conf;
 		
@@ -123,7 +145,7 @@ class page_action extends tform_actions {
 		if($_SESSION["s"]["user"]["typ"] != 'admin') {
 			// Get the limits of the client
 			$client_group_id = $_SESSION["s"]["user"]["default_group"];
-			$client = $app->db->queryOneRecord("SELECT limit_maildomain, default_mailserver FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = $client_group_id");
+			$client = $app->db->queryOneRecord("SELECT limit_web_domain, default_webserver FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = $client_group_id");
 			
 			// When the record is updated
 			if($this->id > 0) {
@@ -136,15 +158,15 @@ class page_action extends tform_actions {
 				// set the server ID to the default mailserver of the client
 				$this->dataRecord["server_id"] = $client["default_webserver"];
 				
-				/*
-				// Check if the user may add another mail_domain
-				if($client["limit_maildomain"] >= 0) {
-					$tmp = $app->db->queryOneRecord("SELECT count(domain_id) as number FROM mail_domain WHERE sys_groupid = $client_group_id");
-					if($tmp["number"] >= $client["limit_maildomain"]) {
-						$app->error($app->tform->wordbook["limit_webdomain_txt"]);
+				
+				// Check if the user may add another web_domain
+				if($client["limit_web_domain"] >= 0) {
+					$tmp = $app->db->queryOneRecord("SELECT count(domain_id) as number FROM web_domain WHERE sys_groupid = $client_group_id and type = 'vhost'");
+					if($tmp["number"] >= $client["limit_web_domain"]) {
+						$app->error($app->tform->wordbook["limit_web_domain_txt"]);
 					}
 				}
-				*/
+				
 			}
 			
 			// Clients may not set the client_group_id, so we unset them if user is not a admin
diff --git a/interface/web/sites/web_subdomain_edit.php b/interface/web/sites/web_subdomain_edit.php
index e2aaca9e21..0fb1cfe663 100644
--- a/interface/web/sites/web_subdomain_edit.php
+++ b/interface/web/sites/web_subdomain_edit.php
@@ -53,12 +53,35 @@ $app->load('tform_actions');
 
 class page_action extends tform_actions {
 	
+	function onShowNew() {
+		global $app, $conf;
+		
+		// we will check only users, not admins
+		if($_SESSION["s"]["user"]["typ"] == 'user') {
+			
+			// Get the limits of the client
+			$client_group_id = $_SESSION["s"]["user"]["default_group"];
+			$client = $app->db->queryOneRecord("SELECT limit_web_subdomain FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = $client_group_id");
+			
+			// Check if the user may add another maildomain.
+			if($client["limit_web_subdomain"] >= 0) {
+				$tmp = $app->db->queryOneRecord("SELECT count(domain_id) as number FROM web_domain WHERE sys_groupid = $client_group_id and type = 'subdomain'");
+				if($tmp["number"] >= $client["limit_web_subdomain"]) {
+					$app->error($app->tform->wordbook["limit_web_subdomain_txt"]);
+				}
+			}
+		}
+		
+		parent::onShowNew();
+	}
+	
 	function onShowEnd() {
 		global $app, $conf;
 		
 		// Get the record of the parent domain
 		$parent_domain = $app->db->queryOneRecord("select * FROM web_domain WHERE domain_id = ".intval($this->dataRecord["parent_domain_id"]));
 		
+		// remove the parent domain part of the domain name before we show it in the text field.
 		$this->dataRecord["domain"] = str_replace('.'.$parent_domain["domain"],'',$this->dataRecord["domain"]);
 		$app->tpl->setVar("domain",$this->dataRecord["domain"]);
 		
diff --git a/server/plugins-enabled/apache2_plugin.inc.php b/server/plugins-enabled/apache2_plugin.inc.php
index 178ba044c3..9b334678ba 100644
--- a/server/plugins-enabled/apache2_plugin.inc.php
+++ b/server/plugins-enabled/apache2_plugin.inc.php
@@ -68,7 +68,7 @@ class apache2_plugin {
 		if($data["new"]["type"] != "vhost" && $data["new"]["parent_domain_id"] > 0) {
 			// This is not a vhost, so we need to update the parent record instead.
 			$parent_domain_id = intval($data["new"]["parent_domain_id"]);
-			$tmp = $app->db->queryOneRecord("SELECT * FROM web_domain WHERE domain_id = ".$parent_domain_id);
+			$tmp = $app->db->queryOneRecord("SELECT * FROM web_domain WHERE domain_id = ".$parent_domain_id." AND active = 'y'");
 			$data["new"] = $tmp;
 			$data["old"] = $tmp;
 		}
@@ -150,7 +150,7 @@ class apache2_plugin {
 		}
 		
 		// get alias domains (co-domains and subdomains)
-		$aliases = $app->db->queryAllRecords("SELECT * FROM web_domain WHERE parent_domain_id = ".$data["new"]["domain_id"]);
+		$aliases = $app->db->queryAllRecords("SELECT * FROM web_domain WHERE parent_domain_id = ".$data["new"]["domain_id"]." AND active = 'y'");
 		$server_alias = '';
 		if(is_array($aliases)) {
 			foreach($aliases as $alias) {
-- 
GitLab