From e28564dbde4f922a6a8263e3dea32d56b60b5b5b Mon Sep 17 00:00:00 2001
From: tbrehm <t.brehm@ispconfig.org>
Date: Wed, 16 Jun 2010 11:41:46 -0400
Subject: [PATCH] Implemented: FS#468 - Client name conversion in FTP user too restricted

---
 server/lib/classes/system.inc.php |  124 ++++++++++++++++++++++++++++++++++++++++
 1 files changed, 122 insertions(+), 2 deletions(-)

diff --git a/server/lib/classes/system.inc.php b/server/lib/classes/system.inc.php
index f6fce77..260c214 100644
--- a/server/lib/classes/system.inc.php
+++ b/server/lib/classes/system.inc.php
@@ -1,6 +1,7 @@
 <?php
+
 /*
-Copyright (c) 2007, projektfarm Gmbh, Till Brehm, Falko Timme
+Copyright (c) 2007, Till Brehm, projektfarm Gmbh
 All rights reserved.
 
 Redistribution and use in source and binary forms, with or without modification,
@@ -26,7 +27,6 @@
 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
 EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
-
 
 class system{
 
@@ -463,6 +463,28 @@
 	  	}
 	  	return false;
 	}
+	
+	/*
+	// Alternative implementation of the is_group function. Should be faster then the old one To be tested.
+	function is_group($group) {
+	$groupfile = '/etc/group';
+	if(is_file($groupfile)) {
+		$handle = fopen ($groupfile, "r");
+		while (!feof($handle)) {
+			$line = trim(fgets($handle, 4096));
+			if($line != ""){
+				$parts = explode(":", $line);
+	        	if($parts[0] == $group) {
+					fclose ($handle);
+					return true;
+				}
+			}
+		}
+		fclose ($handle);
+	}
+	return false;
+	}
+	*/
 	
 	function root_group(){
 		global $app;
@@ -1107,6 +1129,104 @@
 	    return false;
 	  }
 	}
+	
+	function replaceLine($filename,$search_pattern,$new_line,$strict = 0,$append = 1) {
+		$lines = @file($filename);
+		$out = '';
+		$found = 0;
+		if(is_array($lines)) {
+			foreach($lines as $line) {
+				if($strict == 0) {
+					if(stristr($line,$search_pattern)) {
+						$out .= $new_line."\n";
+						$found = 1;
+					} else {
+						$out .= $line;
+					}
+				} else {
+					if(trim($line) == $search_pattern) {
+						$out .= $new_line."\n";
+						$found = 1;
+					} else {
+						$out .= $line;
+					}
+				}
+			}
+		}
+		
+		if($found == 0) {
+			//* add \n if the last line does not end with \n or \r
+			if(substr($out,-1) != "\n" && substr($out,-1) != "\r") $out .= "\n";
+			//* add the new line at the end of the file
+			if($append == 1) $out .= $new_line."\n";
+		}
+		file_put_contents($filename,$out);
+	}
+	
+	function removeLine($filename,$search_pattern,$strict = 0) {
+	if($lines = @file($filename)) {
+		$out = '';
+		foreach($lines as $line) {
+			if($strict == 0) {
+				if(!stristr($line,$search_pattern)) {
+					$out .= $line;
+				}
+			} else {
+				if(!trim($line) == $search_pattern) {
+					$out .= $line;
+				}
+			}
+		}
+		file_put_contents($filename,$out);
+	}
+	}
+	
+	function maildirmake($maildir_path, $user = '', $subfolder = '') {
+		
+		global $app;
+		
+		if($subfolder != '') {
+			$dir = escapeshellarg($maildir_path.'/.'.$subfolder);
+			$dir_cur = escapeshellarg($maildir_path.'/.'.$subfolder.'/cur');
+			$dir_new = escapeshellarg($maildir_path.'/.'.$subfolder.'/new');
+			$dir_tmp = escapeshellarg($maildir_path.'/.'.$subfolder.'/tmp');
+		} else {
+			$dir = escapeshellarg($maildir_path);
+			$dir_cur = escapeshellarg($maildir_path.'/cur');
+			$dir_new = escapeshellarg($maildir_path.'/new');
+			$dir_tmp = escapeshellarg($maildir_path.'/tmp');
+		}
+		
+		exec("mkdir -p $dir_cur $dir_new $dir_tmp");
+		exec("chmod 0700 $dir $dir_cur $dir_new $dir_tmp");
+		
+		if($user != '' && $this->is_user($user) && $user != 'root') {
+			$user = escapeshellarg($user);
+			// I assume that the name of the (vmail group) is the same as the name of the mail user in ispconfig 3
+			$group = $user;
+			exec("chown $user:$group $dir $dir_cur $dir_new $dir_tmp");
+		}
+		
+		//* Add the subfolder to the subscriptions and courierimapsubscribed files
+		if($subfolder != '') {
+			// Courier
+			if(!is_file($maildir_path.'/courierimapsubscribed')) {
+				$tmp_file = escapeshellarg($maildir_path.'/courierimapsubscribed');
+				exec("touch $tmp_file && chown vmail:vmail $tmp_file");
+			}
+			$this->replaceLine($maildir_path.'/courierimapsubscribed','INBOX.'.$subfolder,'INBOX.'.$subfolder,1,1);
+			
+			// Dovecot
+			if(!is_file($maildir_path.'/subscriptions')) {
+				$tmp_file = escapeshellarg($maildir_path.'/subscriptions');
+				exec("touch $tmp_file && chown vmail:vmail $tmp_file");
+			}
+			$this->replaceLine($maildir_path.'/subscriptions',$subfolder,$subfolder,1,1);
+		}
+		
+		$app->log('Created Maildir '.$maildir_path.' with subfolder: '.$subfolder,LOGLEVEL_DEBUG);
+		
+	}
 
 }
 ?>
\ No newline at end of file

--
Gitblit v1.9.1