From 9b9ba428a25ff39cca0f92c97ffa24659392a2f9 Mon Sep 17 00:00:00 2001
From: daniel <daniel@ispconfig3>
Date: Wed, 04 Jun 2008 15:44:07 -0400
Subject: [PATCH] 

---
 server/conf/vhost.conf.master                   |    6 +++
 install/install.php                             |   17 ++++++++
 install/lib/installer_base.lib.php              |   12 +++++
 server/plugins-available/apache2_plugin.inc.php |   37 ++++++++++++++++++
 install/tpl/apache_ispconfig.vhost.master       |    7 ++-
 install/update.php                              |   18 +++++++++
 interface/web/sites/web_domain_edit.php         |    1 
 install/tpl/server.ini.master                   |    9 ++++
 8 files changed, 101 insertions(+), 6 deletions(-)

diff --git a/install/install.php b/install/install.php
index a8b772a..65a7f22 100644
--- a/install/install.php
+++ b/install/install.php
@@ -174,6 +174,23 @@
 
 	//* Configure ISPConfig
 	swriteln('Installing ISPConfig');
+	
+	//** We want to check if the server is a module or cgi based php enabled server
+	//** TODO: Don't always ask for this somehow ? 
+	$fast_cgi = $inst->simple_query('CGI PHP Enabled Server?', array('yes','no'),'no');
+
+	if($fast_cgi == 'yes') {
+	 	$alias = $inst->free_query('Script Alias', '/php/');
+	 	$path = $inst->free_query('Script Alias Path', '/path/to/cgi/bin');
+	 	$inst->conf['apache']['vhost_cgi_alias'] = sprintf('ScriptAlias %s %s', $alias, $path);
+	} else {
+	 	$inst->conf['apache']['vhost_cgi_alias'] = "";
+	}
+
+
+	//** Customise the port ISPConfig runs on
+	$inst->conf['apache']['vhost_port'] = $inst->free_query('ISPConfig Port', '8080');
+
 	$inst->install_ispconfig();
 
 	//* Configure ISPConfig
diff --git a/install/lib/installer_base.lib.php b/install/lib/installer_base.lib.php
index daef564..cad13a5 100644
--- a/install/lib/installer_base.lib.php
+++ b/install/lib/installer_base.lib.php
@@ -691,7 +691,17 @@
         // TODO: These are missing! should they be "vhost_dist_*_dir" ?
         $vhost_conf_dir = $this->conf['apache']['vhost_conf_dir'];
         $vhost_conf_enabled_dir = $this->conf['apache']['vhost_conf_enabled_dir'];
-		copy('tpl/apache_ispconfig.vhost.master', "$vhost_conf_dir/ispconfig.vhost");
+        
+        
+        // Dont just copy over the virtualhost template but add some custom settings
+         
+        $content = rf("tpl/apache_ispconfig.vhost.master");
+		$content = str_replace('{vhost_port}', $this->conf['apache']['vhost_port'], $content);
+		$content = str_replace('{vhost_cgi_alias}', $this->conf['apache']['vhost_cgi_alias'], $content);
+		
+		wf("$vhost_conf_dir/ispconfig.vhost", $content);
+		
+		//copy('tpl/apache_ispconfig.vhost.master', "$vhost_conf_dir/ispconfig.vhost");
 		//* and create the symlink
 		if(!is_link("$vhost_conf_enabled_dir/ispconfig.vhost")) {
 			exec("ln -s $vhost_conf_dir/ispconfig.vhost $vhost_conf_enabled_dir/ispconfig.vhost");
diff --git a/install/tpl/apache_ispconfig.vhost.master b/install/tpl/apache_ispconfig.vhost.master
index 040d5ee..f72676a 100644
--- a/install/tpl/apache_ispconfig.vhost.master
+++ b/install/tpl/apache_ispconfig.vhost.master
@@ -4,13 +4,14 @@
 # for the ISPConfig controlpanel
 ######################################################
 
-Listen 8080
-NameVirtualHost *:8080
+Listen {vhost_port}
+NameVirtualHost *:{vhost_port}
 
-<VirtualHost _default_:8080>
+<VirtualHost _default_:{vhost_port}>
 	ServerAdmin webmaster@localhost
     DocumentRoot /usr/local/ispconfig/interface/web/
 	
+	{vhost_cgi_alias}
 	<IfModule mod_php5.c>
   		AddType application/x-httpd-php .php
 	</IfModule>
diff --git a/install/tpl/server.ini.master b/install/tpl/server.ini.master
index 3ec583e..5e66de1 100644
--- a/install/tpl/server.ini.master
+++ b/install/tpl/server.ini.master
@@ -31,4 +31,11 @@
 website_path=/var/clients/client[client_id]/web[website_id]
 website_symlinks=/var/www/[website_domain]/:/var/clients/client[client_id]/[website_domain]/
 vhost_conf_dir=/etc/apache2/sites-available
-vhost_conf_enabled_dir=/etc/apache2/sites-enabled
\ No newline at end of file
+vhost_conf_enabled_dir=/etc/apache2/sites-enabled
+fastcgi_starter_path=/var/www/php-fcgi-scripts/[system_user]/
+fastcgi_starter_script=.php-fcgi-starter
+fastcgi_alias=/php/
+fastcgi_phpini_path=/etc/php5/cgi/
+fastcgi_children=8
+fastcgi_max_requests=5000
+fastcgi_bin=/usr/bin/php-cgi
\ No newline at end of file
diff --git a/install/update.php b/install/update.php
index c05c00b..3c8c936 100644
--- a/install/update.php
+++ b/install/update.php
@@ -174,6 +174,24 @@
 
 //** Configure ISPConfig
 swriteln('Updating ISPConfig');
+
+
+//** We want to check if the server is a module or cgi based php enabled server
+//** TODO: Don't always ask for this somehow ? 
+$fast_cgi = $inst->simple_query('CGI PHP Enabled Server?', array('yes','no'),'no');
+
+if($fast_cgi == 'yes') {
+	 $alias = $inst->free_query('Script Alias', '/php/');
+	 $path = $inst->free_query('Script Alias Path', '/path/to/cgi/bin');
+	 $inst->conf['apache']['vhost_cgi_alias'] = sprintf('ScriptAlias %s %s', $alias, $path);
+} else {
+	 $inst->conf['apache']['vhost_cgi_alias'] = "";
+}
+
+
+//** Customise the port ISPConfig runs on
+$inst->conf['apache']['vhost_port'] = $inst->free_query('ISPConfig Port', '8080');
+
 $inst->install_ispconfig();
 
 //** Configure Crontab
diff --git a/interface/web/sites/web_domain_edit.php b/interface/web/sites/web_domain_edit.php
index 2670de7..8bf89c4 100644
--- a/interface/web/sites/web_domain_edit.php
+++ b/interface/web/sites/web_domain_edit.php
@@ -154,7 +154,6 @@
 			}
 			$app->tpl->setVar("client_group_id",$client_select);
 			
-			
 		}
 		
 		parent::onShowEnd();
diff --git a/server/conf/vhost.conf.master b/server/conf/vhost.conf.master
index 0d6f14e..220570e 100644
--- a/server/conf/vhost.conf.master
+++ b/server/conf/vhost.conf.master
@@ -46,6 +46,12 @@
     # php as cgi enabled
     AddType application/x-httpd-php .php .php3 .php4 .php5
 </tmpl_if>
+<tmpl_if name='php' op='==' value='fast-cgi'>
+    # php as fast-cgi enabled
+    AddType application/x-httpd-php .php .php3 .php4 .php5
+
+    ScriptAlias <tmpl_var name='fastcgi_alias'> <tmpl_var name='fastcgi_starter_path'>
+</tmpl_if>
 
 <tmpl_if name="rewrite_enabled">
     RewriteEngine on
diff --git a/server/plugins-available/apache2_plugin.inc.php b/server/plugins-available/apache2_plugin.inc.php
index d084d7b..445f30e 100644
--- a/server/plugins-available/apache2_plugin.inc.php
+++ b/server/plugins-available/apache2_plugin.inc.php
@@ -374,6 +374,43 @@
 		}
 		$tpl->setLoop('redirects',$rewrite_rules);
 		
+		/** 
+		 * install fast-cgi starter script and add script aliasd config 
+		 * first we create the script directory if not already created, then copy over the starter script
+		 * settings are copied over from the server ini config for now
+		 * TODO: Create form for fastcgi configs per site.
+		 */
+		
+		if ($data["new"]["php"] == "fast-cgi")
+		{
+			$fastcgi_starter_path = str_replace("[system_user]",$data["new"]["system_user"],$web_config["fastcgi_starter_path"]);
+			if (!is_dir($fastcgi_starter_path))
+			{
+				exec("mkdir $fastcgi_starter_path");
+				exec("chown ".$data["new"]["system_user"].":".$data["new"]["system_group"]." $fastcgi_starter_path");
+			}
+			
+			$fcgi_tpl = new tpl();
+			$fcgi_tpl->newTemplate("php-fcgi-starter.master");
+				
+			$fcgi_tpl->setVar('php_ini_path',$web_config["fastcgi_phpini_path"]);
+			$fcgi_tpl->setVar('document_root',$data["new"]["document_root"]);
+			$fcgi_tpl->setVar('php_fcgi_children',$web_config["fastcgi_children"]);
+			$fcgi_tpl->setVar('php_fcgi_max_requests',$web_config["fastcgi_max_requests"]);
+			$fcgi_tpl->setVar('php_fcgi_bin',$web_config["fastcgi_bin"]);
+				
+			$fcgi_starter_script = escapeshellcmd($fastcgi_starter_path."/".$web_config["fastcgi_starter_script"]);
+			file_put_contents($fcgi_starter_script,$fcgi_tpl->grab());
+			unset($fcgi_tpl);
+			
+			exec("chmod 755 $fcgi_starter_script");
+			exec("chown ".$data["new"]["system_user"].":".$data["new"]["system_group"]." $fcgi_starter_script");
+
+			$tpl->setVar('fastcgi_alias',$web_config["fastcgi_alias"]);
+			$tpl->setVar('fastcgi_starter_path',$fastcgi_starter_path);
+			
+		}
+		
 		$vhost_file = escapeshellcmd($web_config["vhost_conf_dir"].'/'.$data["new"]["domain"].'.vhost');
 		file_put_contents($vhost_file,$tpl->grab());
 		$app->log("Writing the vhost file: $vhost_file",LOGLEVEL_DEBUG);

--
Gitblit v1.9.1