From c9b9f2fba8f90f8aa19807a1a5212acb999d1520 Mon Sep 17 00:00:00 2001
From: tbrehm <t.brehm@ispconfig.org>
Date: Wed, 28 Oct 2009 11:24:54 +0000
Subject: [PATCH] Added: FS#871 - Add a "apps" vhost for applications like
 phpmyadmin and webmail

---
 install/dist/conf/centos52.conf.php           |   7 ++
 install/dist/conf/centos53.conf.php           |   7 ++
 install/dist/conf/debian40.conf.php           |   7 ++
 install/dist/conf/fedora9.conf.php            |   7 ++
 install/dist/conf/opensuse110.conf.php        |   7 ++
 install/install.php                           |   8 ++
 install/lib/installer_base.lib.php            |  61 ++++++++++
 install/tpl/apache_apps.vhost.master          |  42 +++++++
 install/tpl/apache_apps_fcgi_starter.master   |   6 +
 .../tpl/apache_ispconfig_fcgi_starter.master  |   2 +-
 install/tpl/server.ini.master                 |   3 +
 install/update.php                            |   4 +
 .../web/admin/form/server_config.tform.php    |  33 +++++
 .../templates/server_config_web_edit.htm      |  14 ++-
 server/conf/apache_apps.vhost.master          |  42 +++++++
 .../apps_vhost_plugin.inc.php                 | 113 ++++++++++++++++++
 16 files changed, 361 insertions(+), 2 deletions(-)
 create mode 100644 install/tpl/apache_apps.vhost.master
 create mode 100644 install/tpl/apache_apps_fcgi_starter.master
 create mode 100644 server/conf/apache_apps.vhost.master
 create mode 100644 server/plugins-available/apps_vhost_plugin.inc.php

diff --git a/install/dist/conf/centos52.conf.php b/install/dist/conf/centos52.conf.php
index 165de932f7..5d1216be2e 100644
--- a/install/dist/conf/centos52.conf.php
+++ b/install/dist/conf/centos52.conf.php
@@ -87,6 +87,13 @@ $conf['web']['website_basedir'] = '/var/www';
 $conf['web']['website_path'] = '/var/www/clients/client[client_id]/web[website_id]';
 $conf['web']['website_symlinks'] = '/var/www/[website_domain]/:/var/www/clients/client[client_id]/[website_domain]/';
 
+//* Apps base settings
+$conf['web']['apps_vhost_ip'] = '_default_';
+$conf['web']['apps_vhost_port'] = '8081';
+$conf['web']['apps_vhost_servername'] = '';
+$conf['web']['apps_vhost_user'] = 'ispapps';
+$conf['web']['apps_vhost_group'] = 'ispapps';
+
 //* Fastcgi
 $conf['fastcgi']['fastcgi_phpini_path'] = '/etc/';
 $conf['fastcgi']['fastcgi_starter_path'] = '/var/www/php-fcgi-scripts/[system_user]/';
diff --git a/install/dist/conf/centos53.conf.php b/install/dist/conf/centos53.conf.php
index 165de932f7..5d1216be2e 100644
--- a/install/dist/conf/centos53.conf.php
+++ b/install/dist/conf/centos53.conf.php
@@ -87,6 +87,13 @@ $conf['web']['website_basedir'] = '/var/www';
 $conf['web']['website_path'] = '/var/www/clients/client[client_id]/web[website_id]';
 $conf['web']['website_symlinks'] = '/var/www/[website_domain]/:/var/www/clients/client[client_id]/[website_domain]/';
 
+//* Apps base settings
+$conf['web']['apps_vhost_ip'] = '_default_';
+$conf['web']['apps_vhost_port'] = '8081';
+$conf['web']['apps_vhost_servername'] = '';
+$conf['web']['apps_vhost_user'] = 'ispapps';
+$conf['web']['apps_vhost_group'] = 'ispapps';
+
 //* Fastcgi
 $conf['fastcgi']['fastcgi_phpini_path'] = '/etc/';
 $conf['fastcgi']['fastcgi_starter_path'] = '/var/www/php-fcgi-scripts/[system_user]/';
diff --git a/install/dist/conf/debian40.conf.php b/install/dist/conf/debian40.conf.php
index d75729a923..cdfdb26f27 100644
--- a/install/dist/conf/debian40.conf.php
+++ b/install/dist/conf/debian40.conf.php
@@ -87,6 +87,13 @@ $conf['web']['website_basedir'] = '/var/www';
 $conf['web']['website_path'] = '/var/www/clients/client[client_id]/web[website_id]';
 $conf['web']['website_symlinks'] = '/var/www/[website_domain]/:/var/www/clients/client[client_id]/[website_domain]/';
 
+//* Apps base settings
+$conf['web']['apps_vhost_ip'] = '_default_';
+$conf['web']['apps_vhost_port'] = '8081';
+$conf['web']['apps_vhost_servername'] = '';
+$conf['web']['apps_vhost_user'] = 'ispapps';
+$conf['web']['apps_vhost_group'] = 'ispapps';
+
 //* Fastcgi
 $conf['fastcgi']['fastcgi_phpini_path'] = '/etc/php5/cgi/';
 $conf['fastcgi']['fastcgi_starter_path'] = '/var/www/php-fcgi-scripts/[system_user]/';
diff --git a/install/dist/conf/fedora9.conf.php b/install/dist/conf/fedora9.conf.php
index 4211732386..0ab5a0ba79 100644
--- a/install/dist/conf/fedora9.conf.php
+++ b/install/dist/conf/fedora9.conf.php
@@ -87,6 +87,13 @@ $conf['web']['website_basedir'] = '/var/www';
 $conf['web']['website_path'] = '/var/www/clients/client[client_id]/web[website_id]';
 $conf['web']['website_symlinks'] = '/var/www/[website_domain]/:/var/www/clients/client[client_id]/[website_domain]/';
 
+//* Apps base settings
+$conf['web']['apps_vhost_ip'] = '_default_';
+$conf['web']['apps_vhost_port'] = '8081';
+$conf['web']['apps_vhost_servername'] = '';
+$conf['web']['apps_vhost_user'] = 'ispapps';
+$conf['web']['apps_vhost_group'] = 'ispapps';
+
 //* Fastcgi
 $conf['fastcgi']['fastcgi_phpini_path'] = '/etc/';
 $conf['fastcgi']['fastcgi_starter_path'] = '/var/www/php-fcgi-scripts/[system_user]/';
diff --git a/install/dist/conf/opensuse110.conf.php b/install/dist/conf/opensuse110.conf.php
index af704a32ed..8c40a8813a 100644
--- a/install/dist/conf/opensuse110.conf.php
+++ b/install/dist/conf/opensuse110.conf.php
@@ -87,6 +87,13 @@ $conf['web']['website_basedir'] = '/srv/www';
 $conf['web']['website_path'] = '/srv/www/clients/client[client_id]/web[website_id]';
 $conf['web']['website_symlinks'] = '/srv/www/[website_domain]/:/srv/www/clients/client[client_id]/[website_domain]/';
 
+//* Apps base settings
+$conf['web']['apps_vhost_ip'] = '_default_';
+$conf['web']['apps_vhost_port'] = '8081';
+$conf['web']['apps_vhost_servername'] = '';
+$conf['web']['apps_vhost_user'] = 'ispapps';
+$conf['web']['apps_vhost_group'] = 'ispapps';
+
 //* Fastcgi
 $conf['fastcgi']['fastcgi_phpini_path'] = '/etc/php5/cgi/';
 $conf['fastcgi']['fastcgi_starter_path'] = '/srv/www/php-fcgi-scripts/[system_user]/';
diff --git a/install/install.php b/install/install.php
index b870f5309a..544902898d 100644
--- a/install/install.php
+++ b/install/install.php
@@ -206,6 +206,10 @@ if($install_mode == 'standard') {
     //** Configure vlogger
     swriteln('Configuring vlogger');
     $inst->configure_vlogger();
+	
+	//** Configure apps vhost
+	swriteln('Configuring Apps vhost');
+	$inst->configure_apps_vhost();
     
 	//* Configure Firewall
 	swriteln('Configuring Firewall');
@@ -384,6 +388,10 @@ if($install_mode == 'standard') {
         //** Configure vlogger
         swriteln('Configuring vlogger');
         $inst->configure_vlogger();
+		
+		//** Configure apps vhost
+		swriteln('Configuring Apps vhost');
+		$inst->configure_apps_vhost();
 	}
 	
 	//** Configure Firewall
diff --git a/install/lib/installer_base.lib.php b/install/lib/installer_base.lib.php
index f489e087af..93b28abef6 100644
--- a/install/lib/installer_base.lib.php
+++ b/install/lib/installer_base.lib.php
@@ -970,6 +970,67 @@ class installer_base {
         exec('chown root:root '.$conf["vlogger"]["config_dir"].'/'.$configfile);
     
     }
+	
+	public function install_apps_vhost()
+	{
+		global $conf;
+		
+		//* Create the ispconfig apps vhost user and group
+		
+		$apps_vhost_user = $conf['web']['apps_vhost_user'];
+		$apps_vhost_group = $conf['web']['apps_vhost_group'];
+		
+		$command = 'groupadd '.$apps_vhost_user;
+		if(!is_group($apps_vhost_group)) caselog($command.' &> /dev/null 2> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
+		
+		$command = "useradd -g '$apps_vhost_group' -d $install_dir $apps_vhost_group";
+		if(!is_user($apps_vhost_user)) caselog($command.' &> /dev/null 2> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
+
+		
+		$command = 'adduser '.$conf['apache']['user'].' '.$apps_vhost_group;
+		caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
+				
+		//* Copy the apps vhost file
+        $vhost_conf_dir = $conf['apache']['vhost_conf_dir'];
+        $vhost_conf_enabled_dir = $conf['apache']['vhost_conf_enabled_dir'];
+        $apps_vhost_servername = ($conf['apache']['apps_vhost_servername'] == '')?'':'ServerName '.$conf['apache']['apps_vhost_servername'];
+        
+        // Dont just copy over the virtualhost template but add some custom settings
+        $content = rf("tpl/apache_apps.vhost.master");
+		
+		$content = str_replace('{apps_vhost_ip}', $conf['apache']['apps_vhost_ip'], $content);
+		$content = str_replace('{apps_vhost_port}', $conf['apache']['apps_vhost_port'], $content);
+		$content = str_replace('{apps_vhost_dir}', $conf['web']['website_basedir'].'/apps', $content);
+		$content = str_replace('{apps_vhost_servername}', $apps_vhost_servername, $content);
+		
+		
+		// comment out the listen directive if port is 80 or 443
+		if($conf['apache']['apps_vhost_ip'] == 80 or $conf['apache']['apps_vhost_ip'] == 443) {
+			$content = str_replace('{vhost_port_listen}', '#', $content);
+		} else {
+			$content = str_replace('{vhost_port_listen}', '', $content);
+		}
+		
+		wf("$vhost_conf_dir/apps.vhost", $content);
+		
+		//copy('tpl/apache_ispconfig.vhost.master', "$vhost_conf_dir/ispconfig.vhost");
+		//* and create the symlink
+		if($this->install_ispconfig_interface == true && $this->is_update == false) {
+			if(@is_link("$vhost_conf_enabled_dir/apps.vhost")) unlink("$vhost_conf_enabled_dir/apps.vhost");
+			if(!@is_link("$vhost_conf_enabled_dir/000-apps.vhost")) {
+				exec("ln -s $vhost_conf_dir/apps.vhost $vhost_conf_enabled_dir/000-apps.vhost");
+			}
+		}
+		if(!is_file($conf['web']['website_basedir'].'/php-fcgi-scripts/apps/.php-fcgi-starter')) {
+			exec('mkdir -p '.$conf['web']['website_basedir'].'/php-fcgi-scripts/apps');
+			exec('cp tpl/apache_apps_fcgi_starter.master '.$conf['web']['website_basedir'].'/php-fcgi-scripts/apps/.php-fcgi-starter');
+			exec('chmod +x '.$conf['web']['website_basedir'].'/php-fcgi-scripts/apps/.php-fcgi-starter');
+			exec('ln -s /usr/local/apps/interface/web '.$conf['web']['website_basedir'].'/apps');
+			exec('chown -R ispapps:ispapps '.$conf['web']['website_basedir'].'/php-fcgi-scripts/apps');
+			
+		}
+	
+	}
     
 	public function install_ispconfig()
     {
diff --git a/install/tpl/apache_apps.vhost.master b/install/tpl/apache_apps.vhost.master
new file mode 100644
index 0000000000..ceb9c3a3e4
--- /dev/null
+++ b/install/tpl/apache_apps.vhost.master
@@ -0,0 +1,42 @@
+
+######################################################
+# This virtual host contains the configuration
+# for the ISPConfig apps vhost
+######################################################
+
+{vhost_port_listen} Listen {apps_vhost_port}
+NameVirtualHost *:{apps_vhost_port}
+
+<VirtualHost {apps_vhost_ip}:{apps_vhost_port}>
+  ServerAdmin webmaster@localhost
+  {apps_vhost_servername}
+  
+  <IfModule mod_fcgid.c>
+    DocumentRoot {apps_vhost_dir}
+    SuexecUserGroup ispapps ispapps
+    <Directory {apps_vhost_dir}>
+      Options Indexes FollowSymLinks MultiViews +ExecCGI
+      AllowOverride AuthConfig Indexes Limit Options FileInfo
+      AddHandler fcgid-script .php
+      FCGIWrapper /var/www/php-fcgi-scripts/apps/.php-fcgi-starter .php
+      Order allow,deny
+      Allow from all
+    </Directory>
+  </IfModule>
+  
+  <IfModule mod_php5.c>
+    DocumentRoot {apps_vhost_dir}
+    AddType application/x-httpd-php .php
+    <Directory {apps_vhost_dir}>
+      Options FollowSymLinks
+      AllowOverride None
+      Order allow,deny
+      Allow from all
+    </Directory>
+  </IfModule>
+  
+  ServerSignature Off
+
+</VirtualHost>
+
+
diff --git a/install/tpl/apache_apps_fcgi_starter.master b/install/tpl/apache_apps_fcgi_starter.master
new file mode 100644
index 0000000000..a638732da9
--- /dev/null
+++ b/install/tpl/apache_apps_fcgi_starter.master
@@ -0,0 +1,6 @@
+#!/bin/sh
+PHPRC=/etc/php5/cgi/
+export PHPRC
+export PHP_FCGI_MAX_REQUESTS=5000
+export PHP_FCGI_CHILDREN=1
+exec /usr/lib/cgi-bin/php -d magic_quotes_gpc=off
\ No newline at end of file
diff --git a/install/tpl/apache_ispconfig_fcgi_starter.master b/install/tpl/apache_ispconfig_fcgi_starter.master
index 1d7262a573..a638732da9 100644
--- a/install/tpl/apache_ispconfig_fcgi_starter.master
+++ b/install/tpl/apache_ispconfig_fcgi_starter.master
@@ -2,5 +2,5 @@
 PHPRC=/etc/php5/cgi/
 export PHPRC
 export PHP_FCGI_MAX_REQUESTS=5000
-export PHP_FCGI_CHILDREN=8
+export PHP_FCGI_CHILDREN=1
 exec /usr/lib/cgi-bin/php -d magic_quotes_gpc=off
\ No newline at end of file
diff --git a/install/tpl/server.ini.master b/install/tpl/server.ini.master
index 551e2b3f61..9cc4e6f144 100644
--- a/install/tpl/server.ini.master
+++ b/install/tpl/server.ini.master
@@ -39,6 +39,9 @@ vhost_conf_enabled_dir=/etc/apache2/sites-enabled
 security_level=10
 user=www-data
 group=www-data
+apps_vhost_port=8081
+apps_vhost_ip=_default_
+apps_vhost_servername=
 
 [fastcgi]
 fastcgi_starter_path=/var/www/php-fcgi-scripts/[system_user]/
diff --git a/install/update.php b/install/update.php
index 08a2fb257c..01158e6e7a 100644
--- a/install/update.php
+++ b/install/update.php
@@ -356,6 +356,10 @@ if($reconfigure_services_answer == 'yes') {
         //** Configure vlogger
         swriteln('Configuring vlogger');
         $inst->configure_vlogger();
+		
+		//** Configure apps vhost
+		swriteln('Configuring Apps vhost');
+		$inst->configure_apps_vhost();
 	}
 	
 
diff --git a/interface/web/admin/form/server_config.tform.php b/interface/web/admin/form/server_config.tform.php
index a522c4cf9c..feeeb6fda6 100644
--- a/interface/web/admin/form/server_config.tform.php
+++ b/interface/web/admin/form/server_config.tform.php
@@ -375,6 +375,39 @@ $form["tabs"]['web'] = array (
 			'width'		=> '40',
 			'maxlength'	=> '255'
 		),
+		'apps_vhost_port' => array (
+			'datatype'	=> 'VARCHAR',
+			'formtype'	=> 'TEXT',
+			'default'	=> '8081',
+			'validators'	=> array ( 	0 => array (	'type'	=> 'NOTEMPTY',
+														'errmsg'=> 'apps_vhost_port_error_empty'),
+									),
+			'value'		=> '',
+			'width'		=> '40',
+			'maxlength'	=> '255'
+		),
+		'apps_vhost_ip' => array (
+			'datatype'	=> 'VARCHAR',
+			'formtype'	=> 'TEXT',
+			'default'	=> '_default_',
+			'validators'	=> array ( 	0 => array (	'type'	=> 'NOTEMPTY',
+														'errmsg'=> 'apps_vhost_ip_error_empty'),
+									),
+			'value'		=> '',
+			'width'		=> '40',
+			'maxlength'	=> '255'
+		),
+		'apps_vhost_servername' => array (
+			'datatype'	=> 'VARCHAR',
+			'formtype'	=> 'TEXT',
+			'default'	=> '',
+			'validators'	=> array ( 	0 => array (	'type'	=> 'NOTEMPTY',
+														'errmsg'=> 'apps_vhost_servername_error_empty'),
+									),
+			'value'		=> '',
+			'width'		=> '40',
+			'maxlength'	=> '255'
+		),
 	##################################
 	# ENDE Datatable fields
 	##################################
diff --git a/interface/web/admin/templates/server_config_web_edit.htm b/interface/web/admin/templates/server_config_web_edit.htm
index 646c0765e0..ca1c3aed90 100644
--- a/interface/web/admin/templates/server_config_web_edit.htm
+++ b/interface/web/admin/templates/server_config_web_edit.htm
@@ -40,7 +40,19 @@
 	  <div class="ctrlHolder">
       	<label for="group">{tmpl_var name='web_group_txt'}</label>
         <input name="group" id="group" value="{tmpl_var name='group'}" size="40" maxlength="255" type="text" class="textInput" />
-			</div>
+	  </div>
+	  <div class="ctrlHolder">
+      	<label for="apps_vhost_port">{tmpl_var name='apps_vhost_port_txt'}</label>
+        <input name="apps_vhost_port" id="apps_vhost_port" value="{tmpl_var name='apps_vhost_port'}" size="40" maxlength="255" type="text" class="textInput" />
+	  </div>
+	  <div class="ctrlHolder">
+      	<label for="apps_vhost_ip">{tmpl_var name='apps_vhost_ip_txt'}</label>
+        <input name="apps_vhost_ip" id="apps_vhost_ip" value="{tmpl_var name='apps_vhost_ip'}" size="40" maxlength="255" type="text" class="textInput" />
+	  </div>
+	  <div class="ctrlHolder">
+      	<label for="apps_vhost_servername">{tmpl_var name='apps_vhost_servername_txt'}</label>
+        <input name="apps_vhost_servername" id="apps_vhost_servername" value="{tmpl_var name='apps_vhost_servername'}" size="40" maxlength="255" type="text" class="textInput" />
+	  </div>
     </fieldset>
 
     <input type="hidden" name="id" value="{tmpl_var name='id'}">
diff --git a/server/conf/apache_apps.vhost.master b/server/conf/apache_apps.vhost.master
new file mode 100644
index 0000000000..ceb9c3a3e4
--- /dev/null
+++ b/server/conf/apache_apps.vhost.master
@@ -0,0 +1,42 @@
+
+######################################################
+# This virtual host contains the configuration
+# for the ISPConfig apps vhost
+######################################################
+
+{vhost_port_listen} Listen {apps_vhost_port}
+NameVirtualHost *:{apps_vhost_port}
+
+<VirtualHost {apps_vhost_ip}:{apps_vhost_port}>
+  ServerAdmin webmaster@localhost
+  {apps_vhost_servername}
+  
+  <IfModule mod_fcgid.c>
+    DocumentRoot {apps_vhost_dir}
+    SuexecUserGroup ispapps ispapps
+    <Directory {apps_vhost_dir}>
+      Options Indexes FollowSymLinks MultiViews +ExecCGI
+      AllowOverride AuthConfig Indexes Limit Options FileInfo
+      AddHandler fcgid-script .php
+      FCGIWrapper /var/www/php-fcgi-scripts/apps/.php-fcgi-starter .php
+      Order allow,deny
+      Allow from all
+    </Directory>
+  </IfModule>
+  
+  <IfModule mod_php5.c>
+    DocumentRoot {apps_vhost_dir}
+    AddType application/x-httpd-php .php
+    <Directory {apps_vhost_dir}>
+      Options FollowSymLinks
+      AllowOverride None
+      Order allow,deny
+      Allow from all
+    </Directory>
+  </IfModule>
+  
+  ServerSignature Off
+
+</VirtualHost>
+
+
diff --git a/server/plugins-available/apps_vhost_plugin.inc.php b/server/plugins-available/apps_vhost_plugin.inc.php
new file mode 100644
index 0000000000..b16778bef2
--- /dev/null
+++ b/server/plugins-available/apps_vhost_plugin.inc.php
@@ -0,0 +1,113 @@
+<?php
+
+/*
+Copyright (c) 2009, Till Brehm, projektfarm Gmbh
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without modification,
+are permitted provided that the following conditions are met:
+
+    * Redistributions of source code must retain the above copyright notice,
+      this list of conditions and the following disclaimer.
+    * Redistributions in binary form must reproduce the above copyright notice,
+      this list of conditions and the following disclaimer in the documentation
+      and/or other materials provided with the distribution.
+    * Neither the name of ISPConfig nor the names of its contributors
+      may be used to endorse or promote products derived from this software without
+      specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+class apps_vhost_plugin {
+	
+	var $plugin_name = 'apps_vhost_plugin';
+	var $class_name = 'apps_vhost_plugin';
+	
+	
+	//* This function is called during ispconfig installation to determine
+	//  if a symlink shall be created for this plugin.
+	function onInstall() {
+		global $conf;
+		
+		return true;
+		
+	}
+	
+	/*
+	 	This function is called when the plugin is loaded
+	*/
+	
+	function onLoad() {
+		global $app;
+		
+		/*
+		Register for the events
+		*/
+		
+		$app->plugins->registerEvent('server_insert','apps_vhost_plugin','insert');
+		$app->plugins->registerEvent('server_update','apps_vhost_plugin','update');		
+		
+		
+	}
+	
+	function insert($event_name,$data) {
+		global $app, $conf;
+		
+		$this->update($event_name,$data);
+		
+	}
+	
+	// The purpose of this plugin is to rewrite the main.cf file
+	function update($event_name,$data) {
+		global $app, $conf;
+		
+		if(	$data['old']['apps_vhost_ip'] != $data['new']['apps_vhost_ip'] or
+			$data['old']['apps_vhost_port'] != $data['new']['apps_vhost_port'] or
+			$data['old']['apps_vhost_servername'] != $data['new']['apps_vhost_servername'] ) {
+		
+		// get the config
+		$app->uses("getconf");
+		$web_config = $app->getconf->get_server_config($conf["server_id"], 'web');
+				
+		// Dont just copy over the virtualhost template but add some custom settings
+        $content = rf("conf/apache_apps.vhost.master");
+		
+		$vhost_conf_dir = $web_config['vhost_conf_dir'];
+        $vhost_conf_enabled_dir = $web_config['vhost_conf_enabled_dir'];
+		$apps_vhost_servername = ($web_config['apps_vhost_servername'] == '')?'':'ServerName '.$web_config['apps_vhost_servername'];
+		
+		$content = str_replace('{apps_vhost_ip}', $web_config['apps_vhost_ip'], $content);
+		$content = str_replace('{apps_vhost_port}', $web_config['apps_vhost_port'], $content);
+		$content = str_replace('{apps_vhost_dir}', $web_config['website_basedir'].'/apps', $content);
+		$content = str_replace('{apps_vhost_servername}', $apps_vhost_servername, $content);
+		
+		
+		// comment out the listen directive if port is 80 or 443
+		if($web_config['apps_vhost_ip'] == 80 or $web_config['apps_vhost_ip'] == 443) {
+			$content = str_replace('{vhost_port_listen}', '#', $content);
+		} else {
+			$content = str_replace('{vhost_port_listen}', '', $content);
+		}
+		
+		wf("$vhost_conf_dir/apps.vhost", $content);
+		}
+		
+		
+	}
+	
+
+} // end class
+
+
+
+?>
\ No newline at end of file
-- 
GitLab