From c719dc0b1dd696e0cd6b51f09ee13c8263375f7c Mon Sep 17 00:00:00 2001
From: tbrehm <t.brehm@ispconfig.org>
Date: Wed, 07 Sep 2011 05:57:38 -0400
Subject: [PATCH] Fixed a warning in maildrop plugin.

---
 install/lib/installer_base.lib.php |  262 ++++++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 224 insertions(+), 38 deletions(-)

diff --git a/install/lib/installer_base.lib.php b/install/lib/installer_base.lib.php
index 4626c22..86db75f 100644
--- a/install/lib/installer_base.lib.php
+++ b/install/lib/installer_base.lib.php
@@ -52,6 +52,10 @@
 		die('ERROR: '.$msg."\n");
 	}
 
+	public function warning($msg) {
+		echo('WARNING: '.$msg."\n");
+	}
+	
 	public function simple_query($query, $answers, $default) {
 		$finished = false;
 		do {
@@ -113,11 +117,12 @@
 
 		if(is_installed('mysql') || is_installed('mysqld')) $conf['mysql']['installed'] = true;
 		if(is_installed('postfix')) $conf['postfix']['installed'] = true;
+		if(is_installed('mailman')) $conf['mailman']['installed'] = true;
 		if(is_installed('apache') || is_installed('apache2') || is_installed('httpd')) $conf['apache']['installed'] = true;
 		if(is_installed('getmail')) $conf['getmail']['installed'] = true;
 		if(is_installed('courierlogger')) $conf['courier']['installed'] = true;
 		if(is_installed('dovecot')) $conf['dovecot']['installed'] = true;
-		if(is_installed('saslsauthd')) $conf['saslauthd']['installed'] = true;
+		if(is_installed('saslauthd')) $conf['saslauthd']['installed'] = true;
 		if(is_installed('amavisd-new')) $conf['amavis']['installed'] = true;
 		if(is_installed('clamdscan')) $conf['clamav']['installed'] = true;
 		if(is_installed('pure-ftpd') || is_installed('pure-ftpd-wrapper')) $conf['pureftpd']['installed'] = true;
@@ -125,7 +130,13 @@
 		if(is_installed('jk_chrootsh')) $conf['jailkit']['installed'] = true;
 		if(is_installed('pdns_server') || is_installed('pdns_control')) $conf['powerdns']['installed'] = true;
 		if(is_installed('named') || is_installed('bind') || is_installed('bind9')) $conf['bind']['installed'] = true;
-
+		if(is_installed('squid')) $conf['squid']['installed'] = true;
+		if(is_installed('nginx')) $conf['nginx']['installed'] = true;
+		if(is_installed('iptables') && is_installed('ufw')) $conf['ufw']['installed'] = true;
+		if(is_installed('fail2ban-server')) $conf['fail2ban']['installed'] = true;
+		if(is_dir("/etc/Bastille")) $conf['bastille']['installed'] = true;
+		
+		if ($conf['services']['web'] && $conf['apache']['installed'] && is_file($conf['apache']["vhost_conf_enabled_dir"]."/000-ispconfig.vhost")) $this->ispconfig_interface_installed = true;
 	}
 
 	/** Create the database for ISPConfig */
@@ -222,6 +233,11 @@
 		$tpl_ini_array['dns']['named_conf_path'] = $conf['bind']['named_conf_path'];
 		$tpl_ini_array['dns']['named_conf_local_path'] = $conf['bind']['named_conf_local_path'];
 		
+		if ($conf['nginx']['installed'] == true) {
+			$tpl_ini_array['nginx']['vhost_conf_dir'] = $conf['nginx']['vhost_conf_dir'];
+			$tpl_ini_array['nginx']['vhost_conf_enabled_dir'] = $conf['nginx']['vhost_conf_enabled_dir'];
+		}
+		
 		if (array_key_exists('awstats', $conf)) {
 			foreach ($conf['awstats'] as $aw_sett => $aw_value) {
 				$tpl_ini_array['web']['awstats_'.$aw_sett] = $aw_value;
@@ -237,6 +253,8 @@
 		$file_server_enabled = ($conf['services']['file'])?1:0;
 		$db_server_enabled = ($conf['services']['db'])?1:0;
 		$vserver_server_enabled = ($conf['services']['vserver'])?1:0;
+		$proxy_server_enabled = ($conf['services']['proxy'])?1:0;
+		$firewall_server_enabled = ($conf['services']['firewall'])?1:0;
 		
 		//** Get the database version number based on the patchfiles
 		$found = true;
@@ -256,13 +274,13 @@
 		if($conf['mysql']['master_slave_setup'] == 'y') {
 
 			//* Insert the server record in master DB
-			$sql = "INSERT INTO `server` (`sys_userid`, `sys_groupid`, `sys_perm_user`, `sys_perm_group`, `sys_perm_other`, `server_name`, `mail_server`, `web_server`, `dns_server`, `file_server`, `db_server`, `vserver_server`, `config`, `updated`, `active`, `dbversion`) VALUES (1, 1, 'riud', 'riud', 'r', '".$conf['hostname']."', '$mail_server_enabled', '$web_server_enabled', '$dns_server_enabled', '$file_server_enabled', '$db_server_enabled', '$vserver_server_enabled', '$server_ini_content', 0, 1, $current_db_version);";
+			$sql = "INSERT INTO `server` (`sys_userid`, `sys_groupid`, `sys_perm_user`, `sys_perm_group`, `sys_perm_other`, `server_name`, `mail_server`, `web_server`, `dns_server`, `file_server`, `db_server`, `vserver_server`, `config`, `updated`, `active`, `dbversion`,`firewall_server`,`proxy_server`) VALUES (1, 1, 'riud', 'riud', 'r', '".$conf['hostname']."', '$mail_server_enabled', '$web_server_enabled', '$dns_server_enabled', '$file_server_enabled', '$db_server_enabled', '$vserver_server_enabled', '$server_ini_content', 0, 1, $current_db_version, $proxy_server_enabled, $firewall_server_enabled);";
 			$this->dbmaster->query($sql);
 			$conf['server_id'] = $this->dbmaster->insertID();
 			$conf['server_id'] = $conf['server_id'];
 
 			//* Insert the same record in the local DB
-			$sql = "INSERT INTO `server` (`server_id`, `sys_userid`, `sys_groupid`, `sys_perm_user`, `sys_perm_group`, `sys_perm_other`, `server_name`, `mail_server`, `web_server`, `dns_server`, `file_server`, `db_server`, `vserver_server`, `config`, `updated`, `active`, `dbversion`) VALUES ('".$conf['server_id']."',1, 1, 'riud', 'riud', 'r', '".$conf['hostname']."', '$mail_server_enabled', '$web_server_enabled', '$dns_server_enabled', '$file_server_enabled', '$db_server_enabled', '$vserver_server_enabled', '$server_ini_content', 0, 1, $current_db_version);";
+			$sql = "INSERT INTO `server` (`server_id`, `sys_userid`, `sys_groupid`, `sys_perm_user`, `sys_perm_group`, `sys_perm_other`, `server_name`, `mail_server`, `web_server`, `dns_server`, `file_server`, `db_server`, `vserver_server`, `config`, `updated`, `active`, `dbversion`,`firewall_server`,`proxy_server`) VALUES ('".$conf['server_id']."',1, 1, 'riud', 'riud', 'r', '".$conf['hostname']."', '$mail_server_enabled', '$web_server_enabled', '$dns_server_enabled', '$file_server_enabled', '$db_server_enabled', '$vserver_server_enabled', '$server_ini_content', 0, 1, $current_db_version, $proxy_server_enabled, $firewall_server_enabled);";
 			$this->db->query($sql);
 
 			//* username for the ispconfig user
@@ -272,7 +290,7 @@
 
 		} else {
 			//* Insert the server, if its not a mster / slave setup
-			$sql = "INSERT INTO `server` (`sys_userid`, `sys_groupid`, `sys_perm_user`, `sys_perm_group`, `sys_perm_other`, `server_name`, `mail_server`, `web_server`, `dns_server`, `file_server`, `db_server`, `vserver_server`, `config`, `updated`, `active`, `dbversion`) VALUES (1, 1, 'riud', 'riud', 'r', '".$conf['hostname']."', '$mail_server_enabled', '$web_server_enabled', '$dns_server_enabled', '$file_server_enabled', '$db_server_enabled', '$vserver_server_enabled', '$server_ini_content', 0, 1, $current_db_version);";
+			$sql = "INSERT INTO `server` (`sys_userid`, `sys_groupid`, `sys_perm_user`, `sys_perm_group`, `sys_perm_other`, `server_name`, `mail_server`, `web_server`, `dns_server`, `file_server`, `db_server`, `vserver_server`, `config`, `updated`, `active`, `dbversion`,`firewall_server`,`proxy_server`) VALUES (1, 1, 'riud', 'riud', 'r', '".$conf['hostname']."', '$mail_server_enabled', '$web_server_enabled', '$dns_server_enabled', '$file_server_enabled', '$db_server_enabled', '$vserver_server_enabled', '$server_ini_content', 0, 1, $current_db_version, $proxy_server_enabled, $firewall_server_enabled);";
 			$this->db->query($sql);
 			$conf['server_id'] = $this->db->insertID();
 			$conf['server_id'] = $conf['server_id'];
@@ -281,7 +299,7 @@
 
 	}
 
-	public function grant_master_database_rights() {
+	public function grant_master_database_rights($verbose = false) {
 		global $conf;
 
 		/*
@@ -292,6 +310,8 @@
 		 *   1) it is a single server
 		 *   2) it is the MASTER of n clients
 		*/
+		$hosts = array();
+		
 		if($conf['mysql']['master_slave_setup'] == 'y') {
 			/*
 			 * it is a master-slave - Setup so the slave has to grant its rights in the master
@@ -326,7 +346,7 @@
 			}
 		}
 		
-		if(is_array($hosts)) {
+		if(count($hosts) > 0) {
 		foreach($hosts as $host => $value) {
 			/*
 			 * If a pwd exists, this means, we have to add the new user (and his pwd).
@@ -334,6 +354,9 @@
 			 */
 			if ($value['pwd'] != ''){
 				$query = "CREATE USER '".$value['user']."'@'".$host."' IDENTIFIED BY '" . $value['pwd'] . "'";
+				if ($verbose){
+					echo "\n\n" . $query ."\n";
+				}
 				$this->dbmaster->query($query); // ignore the error
 			}
 
@@ -342,62 +365,98 @@
 			 *  In Case that it will not exist, do nothing (ignore the error!)
 			 */
 			$query = "REVOKE ALL PRIVILEGES, GRANT OPTION FROM '".$value['user']."'@'".$host."' ";
+			if ($verbose){
+					echo "\n\n" . $query ."\n";
+			}
 			$this->dbmaster->query($query); // ignore the error
 
 			//* Create the ISPConfig database user in the remote database
 			$query = "GRANT SELECT ON ".$value['db'].".`server` TO '".$value['user']."'@'".$host."' ";
+			if ($verbose){
+				echo $query ."\n";
+			}
 			if(!$this->dbmaster->query($query)) {
-				$this->error('Unable to set rights of user in master database: '.$value['db'].' Error: '.$this->dbmaster->errorMessage);
+				$this->warning('Unable to set rights of user in master database: '.$value['db']."\n Query: ".$query."\n Error: ".$this->dbmaster->errorMessage);
 			}
 
 			$query = "GRANT SELECT, INSERT ON ".$value['db'].".`sys_log` TO '".$value['user']."'@'".$host."' ";
+			if ($verbose){
+				echo $query ."\n";
+			}
 			if(!$this->dbmaster->query($query)) {
-				$this->error('Unable to set rights of user in master database: '.$value['db'].' Error: '.$this->dbmaster->errorMessage);
+				$this->warning('Unable to set rights of user in master database: '.$value['db']."\n Query: ".$query."\n Error: ".$this->dbmaster->errorMessage);
 			}
 
 			$query = "GRANT SELECT, UPDATE(`status`) ON ".$value['db'].".`sys_datalog` TO '".$value['user']."'@'".$host."' ";
+			if ($verbose){
+				echo $query ."\n";
+			}
 			if(!$this->dbmaster->query($query)) {
-				$this->error('Unable to set rights of user in master database: '.$value['db'].' Error: '.$this->dbmaster->errorMessage);
+				$this->warning('Unable to set rights of user in master database: '.$value['db']."\n Query: ".$query."\n Error: ".$this->dbmaster->errorMessage);
 			}
 
 			$query = "GRANT SELECT, UPDATE(`status`) ON ".$value['db'].".`software_update_inst` TO '".$value['user']."'@'".$host."' ";
+			if ($verbose){
+				echo $query ."\n";
+			}
 			if(!$this->dbmaster->query($query)) {
-				$this->error('Unable to set rights of user in master database: '.$value['db'].' Error: '.$this->dbmaster->errorMessage);
+				$this->warning('Unable to set rights of user in master database: '.$value['db']."\n Query: ".$query."\n Error: ".$this->dbmaster->errorMessage);
 			}
 
 			$query = "GRANT SELECT, UPDATE(`updated`) ON ".$value['db'].".`server` TO '".$value['user']."'@'".$host."' ";
+			if ($verbose){
+				echo $query ."\n";
+			}
 			if(!$this->dbmaster->query($query)) {
-				$this->error('Unable to set rights of user in master database: '.$value['db'].' Error: '.$this->dbmaster->errorMessage);
+				$this->warning('Unable to set rights of user in master database: '.$value['db']."\n Query: ".$query."\n Error: ".$this->dbmaster->errorMessage);
 			}
 
 			$query = "GRANT SELECT, UPDATE (`ssl_request`, `ssl_cert`, `ssl_action`) ON ".$value['db'].".`web_domain` TO '".$value['user']."'@'".$host."' ";
+			if ($verbose){
+				echo $query ."\n";
+			}
 			if(!$this->dbmaster->query($query)) {
-				$this->error('Unable to set rights of user in master database: '.$value['db'].' Error: '.$this->dbmaster->errorMessage);
+				$this->warning('Unable to set rights of user in master database: '.$value['db']."\n Query: ".$query."\n Error: ".$this->dbmaster->errorMessage);
 			}
 
 			$query = "GRANT SELECT ON ".$value['db'].".`sys_group` TO '".$value['user']."'@'".$host."' ";
+			if ($verbose){
+				echo $query ."\n";
+			}
 			if(!$this->dbmaster->query($query)) {
-				$this->error('Unable to set rights of user in master database: '.$value['db'].' Error: '.$this->dbmaster->errorMessage);
+				$this->warning('Unable to set rights of user in master database: '.$value['db']."\n Query: ".$query."\n Error: ".$this->dbmaster->errorMessage);
 			}
 
 			$query = "GRANT SELECT, UPDATE (`action_state`, `response`) ON ".$value['db'].".`sys_remoteaction` TO '".$value['user']."'@'".$host."' ";
+			if ($verbose){
+				echo $query ."\n";
+			}
 			if(!$this->dbmaster->query($query)) {
-				$this->error('Unable to set rights of user in master database: '.$value['db'].' Error: '.$this->dbmaster->errorMessage);
+				$this->warning('Unable to set rights of user in master database: '.$value['db']."\n Query: ".$query."\n Error: ".$this->dbmaster->errorMessage);
 			}
 
 			$query = "GRANT SELECT, INSERT , DELETE ON ".$value['db'].".`monitor_data` TO '".$value['user']."'@'".$host."' ";
+			if ($verbose){
+				echo $query ."\n";
+			}
 			if(!$this->dbmaster->query($query)) {
-				$this->error('Unable to set rights of user in master database: '.$value['db'].' Error: '.$this->dbmaster->errorMessage);
+				$this->warning('Unable to set rights of user in master database: '.$value['db']."\n Query: ".$query."\n Error: ".$this->dbmaster->errorMessage);
 			}
 
 			$query = "GRANT SELECT, INSERT, UPDATE ON ".$value['db'].".`mail_traffic` TO '".$value['user']."'@'".$host."' ";
+			if ($verbose){
+				echo $query ."\n";
+			}
 			if(!$this->dbmaster->query($query)) {
-				$this->error('Unable to set rights of user in master database: '.$value['db'].' Error: '.$this->dbmaster->errorMessage);
+				$this->warning('Unable to set rights of user in master database: '.$value['db']."\n Query: ".$query."\n Error: ".$this->dbmaster->errorMessage);
 			}
 
 			$query = "GRANT SELECT, INSERT, UPDATE ON ".$value['db'].".`web_traffic` TO '".$value['user']."'@'".$host."' ";
+			if ($verbose){
+				echo $query ."\n";
+			}
 			if(!$this->dbmaster->query($query)) {
-				$this->error('Unable to set rights of user in master database: '.$value['db'].' Error: '.$this->dbmaster->errorMessage);
+				$this->warning('Unable to set rights of user in master database: '.$value['db']."\n Query: ".$query."\n Error: ".$this->dbmaster->errorMessage);
 			}
 		}
 
@@ -444,6 +503,62 @@
 			copy('tpl/'.$jk_chrootsh.'.master', $config_dir.'/'.$jk_chrootsh);
 		}
 
+	}
+	
+	public function configure_mailman($status = 'insert') {
+		global $conf;
+
+		$config_dir = $conf['mailman']['config_dir'].'/';
+		$full_file_name = $config_dir.'mm_cfg.py';
+		//* Backup exiting file
+		if(is_file($full_file_name)) {
+			copy($full_file_name, $config_dir.'mm_cfg.py~');
+		}
+		
+		// load files
+		$content = rf('tpl/mm_cfg.py.master');
+		$old_file = rf($full_file_name);
+		
+		$old_options = array();
+		$lines = explode("\n", $old_file); 
+		foreach ($lines as $line)
+		{
+			if (trim($line) != '' && substr($line, 0, 1) != '#')
+			{
+				@list($key, $value) = @explode("=", $line);
+				if (!empty($value))
+				{
+					$key = rtrim($key);
+					$old_options[$key] = trim($value);
+				}
+			}
+		}
+		
+		$virtual_domains = '';
+		if($status == 'update')
+		{
+			// create virtual_domains list
+			$domainAll = $this->db->queryAllRecords("SELECT domain FROM mail_mailinglist GROUP BY domain");
+			
+			if(is_array($domainAll)) {
+			foreach($domainAll as $domain)
+			{
+				if ($domainAll[0]['domain'] == $domain['domain'])
+					$virtual_domains .= "'".$domain['domain']."'";
+				else
+					$virtual_domains .= ", '".$domain['domain']."'";
+			}
+			}
+		}
+		else
+			$virtual_domains = "' '";
+			
+		$content = str_replace('{hostname}', $conf['hostname'], $content);
+		if(!isset($old_options['DEFAULT_SERVER_LANGUAGE'])) $old_options['DEFAULT_SERVER_LANGUAGE'] = '';
+		$content = str_replace('{default_language}', $old_options['DEFAULT_SERVER_LANGUAGE'], $content);
+		$content = str_replace('{virtual_domains}', $virtual_domains, $content);
+
+		wf($full_file_name, $content);
 	}
 
 	public function configure_postfix($options = '') {
@@ -502,8 +617,10 @@
 				'myhostname = '.$conf['hostname'],
 				'mydestination = '.$conf['hostname'].', localhost, localhost.localdomain',
 				'mynetworks = 127.0.0.0/8 [::1]/128',
+				'alias_maps = hash:/etc/aliases, hash:/var/lib/mailman/data/aliases',
+				'alias_database = hash:/etc/aliases, hash:/var/lib/mailman/data/aliases',
 				'virtual_alias_domains =',
-				'virtual_alias_maps = proxy:mysql:'.$config_dir.'/mysql-virtual_forwardings.cf, mysql:'.$config_dir.'/mysql-virtual_email2email.cf',
+				'virtual_alias_maps = proxy:mysql:'.$config_dir.'/mysql-virtual_forwardings.cf, proxy:mysql:'.$config_dir.'/mysql-virtual_email2email.cf, hash:/var/lib/mailman/data/virtual-mailman',
 				'virtual_mailbox_domains = proxy:mysql:'.$config_dir.'/mysql-virtual_domains.cf',
 				'virtual_mailbox_maps = proxy:mysql:'.$config_dir.'/mysql-virtual_mailboxes.cf',
 				'virtual_mailbox_base = '.$cf['vmail_mailbox_base'],
@@ -520,22 +637,18 @@
 				'transport_maps = proxy:mysql:'.$config_dir.'/mysql-virtual_transports.cf',
 				'relay_domains = mysql:'.$config_dir.'/mysql-virtual_relaydomains.cf',
 				'relay_recipient_maps = mysql:'.$config_dir.'/mysql-virtual_relayrecipientmaps.cf',
-				'virtual_create_maildirsize = yes',
-				'virtual_maildir_extended = yes',
-				'virtual_mailbox_limit_maps = proxy:mysql:'.$config_dir.'/mysql-virtual_mailbox_limit_maps.cf',
-				'virtual_mailbox_limit_override = yes',
-				'virtual_maildir_limit_message = "The user you are trying to reach is over quota."',
-				'virtual_overquota_bounce = yes',
 				'proxy_read_maps = $local_recipient_maps $mydestination $virtual_alias_maps $virtual_alias_domains $virtual_mailbox_maps $virtual_mailbox_domains $relay_recipient_maps $relay_domains $canonical_maps $sender_canonical_maps $recipient_canonical_maps $relocated_maps $transport_maps $mynetworks $virtual_mailbox_limit_maps',
 				'smtpd_sender_restrictions = check_sender_access mysql:'.$config_dir.'/mysql-virtual_sender.cf',
 				'smtpd_client_restrictions = check_client_access mysql:'.$config_dir.'/mysql-virtual_client.cf',
+				'smtpd_client_message_rate_limit = 100',
 				'maildrop_destination_concurrency_limit = 1',
 				'maildrop_destination_recipient_limit   = 1',
 				'virtual_transport = maildrop',
 				'header_checks = regexp:'.$config_dir.'/header_checks',
 				'mime_header_checks = regexp:'.$config_dir.'/mime_header_checks',
 				'nested_header_checks = regexp:'.$config_dir.'/nested_header_checks',
-				'body_checks = regexp:'.$config_dir.'/body_checks'
+				'body_checks = regexp:'.$config_dir.'/body_checks',
+				'owner_request_special = no'
 		);
 
 		//* Create the header and body check files
@@ -543,7 +656,13 @@
 		touch($config_dir.'/mime_header_checks');
 		touch($config_dir.'/nested_header_checks');
 		touch($config_dir.'/body_checks');
-
+		
+		//* Create the mailman files
+		exec('mkdir -p /var/lib/mailman/data');
+		touch('/var/lib/mailman/data/aliases');
+		exec('postmap /var/lib/mailman/data/aliases');
+		touch('/var/lib/mailman/data/virtual-mailman');
+		exec('postmap /var/lib/mailman/data/virtual-mailman');
 
 		//* Make a backup copy of the main.cf file
 		copy($config_dir.'/main.cf', $config_dir.'/main.cf~');
@@ -557,7 +676,7 @@
 		if(!stristr($options,'dont-create-certs')) {
 			//* Create the SSL certificate
 			$command = 'cd '.$config_dir.'; '
-					.'openssl req -new -outform PEM -out smtpd.cert -newkey rsa:2048 -nodes -keyout smtpd.key -keyform PEM -days 365 -x509';
+					.'openssl req -new -outform PEM -out smtpd.cert -newkey rsa:2048 -nodes -keyout smtpd.key -keyform PEM -days 3650 -x509';
 			exec($command);
 
 			$command = 'chmod o= '.$config_dir.'/smtpd.key';
@@ -711,11 +830,11 @@
 		$config_dir = $conf['dovecot']['config_dir'];
 
 		//* Configure master.cf and add a line for deliver
-		if(is_file($config_dir.'/master.cf')) {
-			copy($config_dir.'/master.cf', $config_dir.'/master.cf~2');
+		if(is_file($conf['postfix']['config_dir'].'/master.cf')) {
+			copy($conf['postfix']['config_dir'].'/master.cf', $conf['postfix']['config_dir'].'/master.cf~2');
 		}
-		if(is_file($config_dir.'/master.cf~')) {
-			chmod($config_dir.'/master.cf~2', 0400);
+		if(is_file($conf['postfix']['config_dir'].'/master.cf~')) {
+			chmod($conf['postfix']['config_dir'].'/master.cf~2', 0400);
 		}
 		$content = rf($conf['postfix']['config_dir'].'/master.cf');
 		// Only add the content if we had not addded it before
@@ -1008,7 +1127,7 @@
 		// copy('tpl/apache_ispconfig.conf.master',$vhost_conf_dir.'/ispconfig.conf');
 
 		$content = rf('tpl/apache_ispconfig.conf.master');
-		$records = $this->db->queryAllRecords("SELECT * FROM server_ip WHERE server_id = ".$conf["server_id"]." AND virtualhost = 'y'");
+		$records = $this->db->queryAllRecords('SELECT * FROM '.$conf['mysql']['master_database'].'.server_ip WHERE server_id = '.$conf['server_id']." AND virtualhost = 'y'");
 		if(is_array($records) && count($records) > 0) {
 			foreach($records as $rec) {
 				$content .= 'NameVirtualHost '.$rec['ip_address'].":80\n";
@@ -1034,11 +1153,77 @@
 			replaceLine('/etc/webalizer/webalizer.conf','#Incremental','Incremental     yes',0,0);
 			replaceLine('/etc/webalizer/webalizer.conf','#HistoryName','HistoryName     webalizer.hist',0,0);
 		}
-
+		
+		// Check the awsatst script
+		if(!is_dir('/usr/share/awstats/tools')) exec('mkdir -p /usr/share/awstats/tools');
+		if(!file_exists('/usr/share/awstats/tools/awstats_buildstaticpages.pl') && file_exists('/usr/share/doc/awstats/examples/awstats_buildstaticpages.pl')) symlink('/usr/share/doc/awstats/examples/awstats_buildstaticpages.pl','/usr/share/awstats/tools/awstats_buildstaticpages.pl');
+		if(file_exists('/etc/awstats/awstats.conf.local')) replaceLine('/etc/awstats/awstats.conf.local','LogFormat=4','LogFormat=1',0,1);
+		
 		//* add a sshusers group
 		$command = 'groupadd sshusers';
 		if(!is_group('sshusers')) caselog($command.' &> /dev/null 2> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
 
+	}
+	
+	public function configure_nginx()
+	{
+		global $conf;
+		$row = $this->db->queryOneRecord("SELECT server_name FROM server WHERE server_id = ".$conf["server_id"]."");
+		$ip_address = gethostbyname($row["server_name"]);
+		$server_name = $row["server_name"];
+
+        //setup proxy.conf
+		$configfile = 'proxy.conf';
+		if(is_file($conf["nginx"]["config_dir"].'/'.$configfile)) copy($conf["nginx"]["config_dir"].'/'.$configfile,$conf["nginx"]["config_dir"].'/'.$configfile.'~');
+		if(is_file($conf["nginx"]["config_dir"].'/'.$configfile.'~')) exec('chmod 400 '.$conf["nginx"]["config_dir"].'/'.$configfile.'~');
+		$content = rf("tpl/nginx_".$configfile.".master");
+		wf($conf["nginx"]["config_dir"].'/'.$configfile,$content);
+		exec('chmod 600 '.$conf["nginx"]["config_dir"].'/'.$configfile);
+		exec('chown root:root '.$conf["nginx"]["config_dir"].'/'.$configfile);
+
+        //setup conf.d/cache.conf
+        $configfile = 'cache.conf';
+		if(is_file($conf["nginx"]["config_dir"].'/conf.d/'.$configfile)) copy($conf["nginx"]["config_dir"].'/conf.d/'.$configfile,$conf["nginx"]["config_dir"].'/conf.d/'.$configfile.'~');
+		if(is_file($conf["nginx"]["config_dir"].'/conf.d/'.$configfile.'~')) exec('chmod 400 '.$conf["nginx"]["config_dir"].'/conf.d/'.$configfile.'~');
+		$content = rf("tpl/nginx_".$configfile.".master");
+		wf($conf["nginx"]["config_dir"].'/conf.d/'.$configfile,$content);
+		exec('chmod 600 '.$conf["nginx"]["config_dir"].'/conf.d/'.$configfile);
+		exec('chown root:root '.$conf["nginx"]["config_dir"].'/conf.d/'.$configfile);
+
+        //setup cache directories
+        mkdir('/var/cache/nginx/cache');
+        exec('chown www-data:www-data /var/cache/nginx/cache');
+        mkdir('/var/cache/nginx/temp');
+        exec('chown www-data:www-data /var/cache/nginx/temp');
+	}
+	
+	public function configure_squid()
+	{
+		global $conf;
+		$row = $this->db->queryOneRecord("SELECT server_name FROM server WHERE server_id = ".$conf["server_id"]."");
+		$ip_address = gethostbyname($row["server_name"]);
+		$server_name = $row["server_name"];
+		
+		$configfile = 'squid.conf';
+		if(is_file($conf["squid"]["config_dir"].'/'.$configfile)) copy($conf["squid"]["config_dir"].'/'.$configfile,$conf["squid"]["config_dir"].'/'.$configfile.'~');
+		if(is_file($conf["squid"]["config_dir"].'/'.$configfile.'~')) exec('chmod 400 '.$conf["squid"]["config_dir"].'/'.$configfile.'~');
+		$content = rf("tpl/".$configfile.".master");
+		$content = str_replace('{server_name}',$server_name,$content);
+		$content = str_replace('{ip_address}',$ip_address, $content);
+		$content = str_replace('{config_dir}',$conf['squid']['config_dir'], $content);
+		wf($conf["squid"]["config_dir"].'/'.$configfile,$content);
+		exec('chmod 600 '.$conf["squid"]["config_dir"].'/'.$configfile);
+		exec('chown root:root '.$conf["squid"]["config_dir"].'/'.$configfile);
+	}
+	
+	public function configure_ufw_firewall()
+	{
+		$configfile = 'ufw.conf';
+		if(is_file('/etc/ufw/ufw.conf')) copy('/etc/ufw/ufw.conf','/etc/ufw/ufw.conf~');
+		$content = rf("tpl/".$configfile.".master");
+		wf('/etc/ufw/ufw.conf',$content);
+		exec('chmod 600 /etc/ufw/ufw.conf');
+		exec('chown root:root /etc/ufw/ufw.conf');	
 	}
 
 	public function configure_firewall() {
@@ -1058,7 +1243,7 @@
 		$tcp_public_services = '';
 		$udp_public_services = '';
 
-		$row = $this->db->queryOneRecord('SELECT * FROM firewall WHERE server_id = '.intval($conf['server_id']));
+		$row = $this->db->queryOneRecord('SELECT * FROM '.$conf["mysql"]["database"].'.firewall WHERE server_id = '.intval($conf['server_id']));
 
 		if(trim($row['tcp_port']) != '' || trim($row['udp_port']) != '') {
 			$tcp_public_services = trim(str_replace(',',' ',$row['tcp_port']));
@@ -1358,13 +1543,14 @@
 		$file_server_enabled = ($conf['services']['file'])?1:0;
 		$db_server_enabled = ($conf['services']['db'])?1:0;
 		$vserver_server_enabled = ($conf['services']['vserver'])?1:0;
+		$proxy_server_enabled = ($conf['services']['proxy'])?1:0;
+		$firewall_server_enabled = ($conf['services']['firewall'])?1:0;
 
 
 
 
 
-
-		$sql = "UPDATE `server` SET mail_server = '$mail_server_enabled', web_server = '$web_server_enabled', dns_server = '$dns_server_enabled', file_server = '$file_server_enabled', db_server = '$db_server_enabled', vserver_server = '$vserver_server_enabled' WHERE server_id = ".intval($conf['server_id']);
+		$sql = "UPDATE `server` SET mail_server = '$mail_server_enabled', web_server = '$web_server_enabled', dns_server = '$dns_server_enabled', file_server = '$file_server_enabled', db_server = '$db_server_enabled', vserver_server = '$vserver_server_enabled', proxy_server = '$proxy_server_enabled', firewall_server = '$firewall_server_enabled' WHERE server_id = ".intval($conf['server_id']);
 
 		if($conf['mysql']['master_slave_setup'] == 'y') {
 			$this->dbmaster->query($sql);
@@ -1717,4 +1903,4 @@
 	}
 }
 
-?>
+?>
\ No newline at end of file

--
Gitblit v1.9.1