From a3576476db51350970a77bf8127ed89b1d626851 Mon Sep 17 00:00:00 2001
From: tbrehm <t.brehm@ispconfig.org>
Date: Tue, 3 Jul 2007 14:48:09 +0000
Subject: [PATCH] Several website related fixes.

---
 install/lib/installer_base.lib.php            |  4 +-
 .../web/admin/lib/lang/en_server_list.lng     |  1 +
 .../web/admin/lib/lang/en_users_list.lng      | 27 ++++-----
 interface/web/admin/lib/module.conf.php       |  8 +--
 .../web/sites/lib/lang/en_ftp_user_list.lng   |  1 +
 .../lib/lang/en_web_aliasdomain_list.lng      |  1 +
 .../sites/lib/lang/en_web_subdomain_list.lng  |  1 +
 interface/web/sites/web_domain_list.php       |  2 +-
 server/conf/vhost.conf.master                 | 34 +++++++++---
 server/plugins-enabled/apache2_plugin.inc.php | 55 +++++++++++++++++--
 10 files changed, 104 insertions(+), 30 deletions(-)

diff --git a/install/lib/installer_base.lib.php b/install/lib/installer_base.lib.php
index 8dfd88fe8..ed9153a34 100644
--- a/install/lib/installer_base.lib.php
+++ b/install/lib/installer_base.lib.php
@@ -544,7 +544,9 @@ maildrop  unix  -       n       n       -       -       pipe
 		// Copy the ISPConfig vhost for the controlpanel
 		copy('tpl/apache_ispconfig.vhost.master',$conf["dist_apache_vhost_conf_dir"].'/ispconfig.vhost');
 		// and create the symlink
-		exec('ln -s '.$conf["dist_apache_vhost_conf_dir"].'/ispconfig.vhost '.$conf["dist_apache_vhost_conf_enabled_dir"].'/ispconfig.vhost');
+		if(!is_link($conf["dist_apache_vhost_conf_enabled_dir"].'/ispconfig.vhost')) {
+			exec('ln -s '.$conf["dist_apache_vhost_conf_dir"].'/ispconfig.vhost '.$conf["dist_apache_vhost_conf_enabled_dir"].'/ispconfig.vhost');
+		}
 		
 	}
 	
diff --git a/interface/web/admin/lib/lang/en_server_list.lng b/interface/web/admin/lib/lang/en_server_list.lng
index 0160993d4..799a52e4c 100644
--- a/interface/web/admin/lib/lang/en_server_list.lng
+++ b/interface/web/admin/lib/lang/en_server_list.lng
@@ -13,4 +13,5 @@ $wb["page_next_txt"] = 'Next';
 $wb["page_back_txt"] = 'Back';
 $wb["delete_txt"] = 'Delete';
 $wb["filter_txt"] = 'Filter';
+$wb["add_new_record_txt"] = 'Add new Server';
 ?>
\ No newline at end of file
diff --git a/interface/web/admin/lib/lang/en_users_list.lng b/interface/web/admin/lib/lang/en_users_list.lng
index e02495858..d1397a078 100644
--- a/interface/web/admin/lib/lang/en_users_list.lng
+++ b/interface/web/admin/lib/lang/en_users_list.lng
@@ -1,14 +1,15 @@
-<?php
-$wb["list_head_txt"] = 'Users';
-$wb["username_txt"] = 'Username';
-$wb["name_txt"] = 'Name';
-$wb["vorname_txt"] = 'Forename';
-$wb["ort_txt"] = 'city';
-
-$wb["page_txt"] = 'Page';
-$wb["page_of_txt"] = 'of';
-$wb["page_next_txt"] = 'Next';
-$wb["page_back_txt"] = 'Back';
-$wb["delete_txt"] = 'Delete';
-$wb["filter_txt"] = 'Filter';
+<?php
+$wb["list_head_txt"] = 'Users';
+$wb["username_txt"] = 'Username';
+$wb["name_txt"] = 'Name';
+$wb["vorname_txt"] = 'Forename';
+$wb["ort_txt"] = 'city';
+
+$wb["page_txt"] = 'Page';
+$wb["page_of_txt"] = 'of';
+$wb["page_next_txt"] = 'Next';
+$wb["page_back_txt"] = 'Back';
+$wb["delete_txt"] = 'Delete';
+$wb["filter_txt"] = 'Filter';
+$wb["add_new_record_txt"] = 'Add new User';
 ?>
\ No newline at end of file
diff --git a/interface/web/admin/lib/module.conf.php b/interface/web/admin/lib/module.conf.php
index 0471b785e..8e60c7473 100644
--- a/interface/web/admin/lib/module.conf.php
+++ b/interface/web/admin/lib/module.conf.php
@@ -40,19 +40,19 @@ $module["nav"][] = array(	'title'	=> 'Groups',
 
 // aufräumen
 unset($items);
-
+/*
 $items[] = array( 'title' 	=> "Add server",
 				  'target' 	=> 'content',
 				  'link'	=> 'admin/server_edit.php');
-
+*/
 $items[] = array( 'title' 	=> "Edit server",
 				  'target' 	=> 'content',
 				  'link'	=> 'admin/server_list.php');
-
+/*
 $items[] = array( 'title' 	=> "Add Server IP",
 				  'target' 	=> 'content',
 				  'link'	=> 'admin/server_ip_edit.php');
-
+*/
 $items[] = array( 'title' 	=> "Edit Server IP",
 				  'target' 	=> 'content',
 				  'link'	=> 'admin/server_ip_list.php');				  
diff --git a/interface/web/sites/lib/lang/en_ftp_user_list.lng b/interface/web/sites/lib/lang/en_ftp_user_list.lng
index 582940c4b..e3403ef98 100644
--- a/interface/web/sites/lib/lang/en_ftp_user_list.lng
+++ b/interface/web/sites/lib/lang/en_ftp_user_list.lng
@@ -10,4 +10,5 @@ $wb["page_next_txt"] = 'Next';
 $wb["page_back_txt"] = 'Back';
 $wb["delete_txt"] = 'Delete';
 $wb["filter_txt"] = 'Filter';
+$wb["add_new_record_txt"] = 'Add new FTP-User';
 ?>
\ No newline at end of file
diff --git a/interface/web/sites/lib/lang/en_web_aliasdomain_list.lng b/interface/web/sites/lib/lang/en_web_aliasdomain_list.lng
index 90fe1ea16..957f2d552 100644
--- a/interface/web/sites/lib/lang/en_web_aliasdomain_list.lng
+++ b/interface/web/sites/lib/lang/en_web_aliasdomain_list.lng
@@ -10,4 +10,5 @@ $wb["page_next_txt"] = 'Next';
 $wb["page_back_txt"] = 'Back';
 $wb["delete_txt"] = 'Delete';
 $wb["filter_txt"] = 'Filter';
+$wb["add_new_record_txt"] = 'Add new aliasdomain';
 ?>
\ No newline at end of file
diff --git a/interface/web/sites/lib/lang/en_web_subdomain_list.lng b/interface/web/sites/lib/lang/en_web_subdomain_list.lng
index 720b42875..5efcbbb0d 100644
--- a/interface/web/sites/lib/lang/en_web_subdomain_list.lng
+++ b/interface/web/sites/lib/lang/en_web_subdomain_list.lng
@@ -10,4 +10,5 @@ $wb["page_next_txt"] = 'Next';
 $wb["page_back_txt"] = 'Back';
 $wb["delete_txt"] = 'Delete';
 $wb["filter_txt"] = 'Filter';
+$wb["add_new_record_txt"] = 'Add new subdomain';
 ?>
\ No newline at end of file
diff --git a/interface/web/sites/web_domain_list.php b/interface/web/sites/web_domain_list.php
index edc7e7feb..03a3cb276 100644
--- a/interface/web/sites/web_domain_list.php
+++ b/interface/web/sites/web_domain_list.php
@@ -50,7 +50,7 @@ if(!stristr($_SESSION["s"]["user"]["modules"],'sites')) {
 $app->uses('listform_actions');
 
 // Limit the results to alias domains
-// $app->listform_actions->SQLExtWhere = "type = 'local'";
+$app->listform_actions->SQLExtWhere = "type = 'vhost'";
 
 $app->listform_actions->onLoad();
 
diff --git a/server/conf/vhost.conf.master b/server/conf/vhost.conf.master
index 79ea7d724..4053d5ed4 100644
--- a/server/conf/vhost.conf.master
+++ b/server/conf/vhost.conf.master
@@ -1,26 +1,46 @@
 # NameVirtualHost *:80
 
 <VirtualHost <tmpl_var name='ip_address'>:80>
-    DocumentRoot <tmpl_var name='document_root'>
+    DocumentRoot <tmpl_var name='web_document_root'>
     ServerName <tmpl_var name='domain'>
-	ServerAlias <tmpl_var name='alias'>
+    ServerAlias <tmpl_var name='alias'>
+    RewriteEngine on
     
 <tmpl_if name='cgi'>
-	# cgi enabled
+    # cgi enabled
+    ScriptAlias  /cgi-bin/ <tmpl_var name='document_root'>/cgi-bin/
+    AddHandler cgi-script .cgi
+    AddHandler cgi-script .pl
 </tmpl_if>
 <tmpl_if name='ssi'>
-	# ssi enabled
+    # ssi enabled
+    AddType text/html .shtml
+    AddOutputFilter INCLUDES .shtml
 </tmpl_if>
 <tmpl_if name='suexec'>
 	# suexec enabled
+    SuexecUserGroup <tmpl_var name='system_user'> <tmpl_var name='system_group'>
 </tmpl_if>
 <tmpl_if name='php' op='==' value='mod'>
-	# mod_php enabled
+    # mod_php enabled
+    AddType application/x-httpd-php .php .php3 .php4 .php5
 </tmpl_if>
 <tmpl_if name='php' op='==' value='suphp'>
-	# suphp enabled
+    # suphp enabled
+    suPHP_Engine on
+    suPHP_UserGroup <tmpl_var name='system_user'> <tmpl_var name='system_group'>
+    AddHandler x-httpd-php .php .php3 .php4 .php5
+    suPHP_AddHandler x-httpd-php
 </tmpl_if>
 <tmpl_if name='php' op='==' value='cgi'>
-	# php as cgi enabled
+    # php as cgi enabled
+    AddType application/x-httpd-php .php .php3 .php4 .php5
 </tmpl_if>
+
+
+<tmpl_loop name="redirects">
+    RewriteCond %{HTTP_HOST}   ^<tmpl_var name='rewrite_domain'> [NC]
+    RewriteRule   ^/(.*)$ <tmpl_var name='rewrite_target'>$1  [<tmpl_var name='rewrite_type'>]
+</tmpl_loop>
+
 </VirtualHost>
\ No newline at end of file
diff --git a/server/plugins-enabled/apache2_plugin.inc.php b/server/plugins-enabled/apache2_plugin.inc.php
index 3d01fd621..c02bc3cd1 100644
--- a/server/plugins-enabled/apache2_plugin.inc.php
+++ b/server/plugins-enabled/apache2_plugin.inc.php
@@ -64,6 +64,16 @@ class apache2_plugin {
 	function update($event_name,$data) {
 		global $app, $conf;
 		
+		
+		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);
+			$data["new"] = $tmp;
+			$data["old"] = $tmp;
+		}
+		
+		
 		// load the server configuration options
 		$app->uses("getconf");
 		$web_config = $app->getconf->get_server_config($conf["server_id"], 'web');
@@ -72,6 +82,10 @@ class apache2_plugin {
 			$app->log("document_root not set",LOGLEVEL_WARN);
 			return 0;
 		}
+		if($data["new"]["system_user"] == 'root' or $data["new"]["system_group"] == 'root') {
+			$app->log("Websites can not be owned by the root user or group.",LOGLEVEL_WARN);
+			return 0;
+		}
 		
 		//print_r($data);
 		
@@ -99,6 +113,20 @@ class apache2_plugin {
 			$app->log("Adding the user: $username",LOGLEVEL_DEBUG);
 		}
 		
+		// Set the quota for the user
+		if($username != '' && $app->system->is_user($username)) {
+			if($data["new"]["hd_quota"] > 0){
+    			$blocks_soft = $data["new"]["hd_quota"] * 1024;
+    			$blocks_hard = $blocks_soft + 1024;
+  			} else {
+    			$blocks_soft = $blocks_hard = 0;
+  			}
+			exec("setquota -u $username $blocks_soft $blocks_hard 0 0 -a &> /dev/null");
+			exec("setquota -T -u $username 604800 604800 -a &> /dev/null");
+		}
+		
+		
+		
 		// Chown and chmod the directories
 		exec("chown -R $username:$groupname ".escapeshellcmd($data["new"]["document_root"]));
 		
@@ -109,16 +137,35 @@ class apache2_plugin {
 		$tpl->newTemplate("vhost.conf.master");
 		
 		$vhost_data = $data["new"];
-		$vhost_data["document_root"] = $data["new"]["document_root"]."/web";
+		$vhost_data["web_document_root"] = $data["new"]["document_root"]."/web";
+		//$vhost_data["document_root"] = $data["new"]["document_root"]."/web";
 		$tpl->setVar($vhost_data);
 		
-		// get alias domains
+		// Rewrite rules
+		$rewrite_rules = array();
+		if($data["new"]["redirect_type"] != '') {
+			$rewrite_rules[] = array(	'rewrite_domain' 	=> $data["new"]["domain"],
+										'rewrite_type' 		=> $data["new"]["redirect_type"],
+										'rewrite_target' 	=> $data["new"]["redirect_path"]);
+		}
+		
+		// get alias domains (co-domains and subdomains)
 		$aliases = $app->db->queryAllRecords("SELECT * FROM web_domain WHERE parent_domain_id = ".$data["new"]["domain_id"]);
 		$server_alias = '';
-		foreach($aliases as $alias) {
-			$server_alias .= $alias["domain"].' ';
+		if(is_array($aliases)) {
+			foreach($aliases as $alias) {
+				$server_alias .= $alias["domain"].' ';
+				$app->log("Add server alias: $alias[domain]",LOGLEVEL_DEBUG);
+				// Rewriting
+				if($alias["redirect_type"] != '') {
+					$rewrite_rules[] = array(	'rewrite_domain' 	=> $alias["domain"],
+												'rewrite_type' 		=> $alias["redirect_type"],
+												'rewrite_target' 	=> $alias["redirect_path"]);
+				}
+			}
 		}
 		$tpl->setVar('alias',trim($server_alias));
+		$tpl->setLoop('redirects',$rewrite_rules);
 		
 		$vhost_file = escapeshellcmd($web_config["vhost_conf_dir"].'/'.$data["new"]["domain"].'.vhost');
 		file_put_contents($vhost_file,$tpl->grab());
-- 
GitLab