moved lamdaemon function to lamdaemon.inc
This commit is contained in:
		
							parent
							
								
									d5dd1fbfcf
								
							
						
					
					
						commit
						7dd57d4ef7
					
				|  | @ -0,0 +1,91 @@ | ||||||
|  | <?php | ||||||
|  | /* | ||||||
|  | $Id$ | ||||||
|  | 
 | ||||||
|  |   This code is part of LDAP Account Manager (http://www.sourceforge.net/projects/lam) | ||||||
|  |   Copyright (C) 2004  Roland Gruber | ||||||
|  | 
 | ||||||
|  |   This program is free software; you can redistribute it and/or modify | ||||||
|  |   it under the terms of the GNU General Public License as published by | ||||||
|  |   the Free Software Foundation; either version 2 of the License, or | ||||||
|  |   (at your option) any later version. | ||||||
|  | 
 | ||||||
|  |   This program is distributed in the hope that it will be useful, | ||||||
|  |   but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||||
|  |   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||||
|  |   GNU General Public License for more details. | ||||||
|  | 
 | ||||||
|  |   You should have received a copy of the GNU General Public License | ||||||
|  |   along with this program; if not, write to the Free Software | ||||||
|  |   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA | ||||||
|  | 
 | ||||||
|  | */ | ||||||
|  | 
 | ||||||
|  | /** | ||||||
|  | * This file includes functions to control lamdaemon. | ||||||
|  | * | ||||||
|  | * @author Tilo Lutz | ||||||
|  | * @author Roland Gruber | ||||||
|  | * | ||||||
|  | * @package modules | ||||||
|  | */ | ||||||
|  | 
 | ||||||
|  | /** | ||||||
|  | * Sends commands to lamdaemon script. | ||||||
|  | * | ||||||
|  | * @param array $commands List of command lines | ||||||
|  | * @return array Output of lamdaemon | ||||||
|  | * | ||||||
|  | */ | ||||||
|  | function lamdaemon($commands) { | ||||||
|  | 	// get username and password of the current lam-admin
 | ||||||
|  | 	$ldap_q = $_SESSION['ldap']->decrypt_login(); | ||||||
|  | 	/* $towrite has the following syntax: | ||||||
|  | 	* admin-username, admin-password, owner of homedir, 'home', operation='add' | ||||||
|  | 	* use escapeshellarg to make exec() shell-safe | ||||||
|  | 	*/ | ||||||
|  | 	$towrite = escapeshellarg($_SESSION['config']->scriptServer)." ".escapeshellarg($_SESSION['config']->scriptPath)." ". | ||||||
|  | 		escapeshellarg($ldap_q[0]).' '.escapeshellarg($ldap_q[1]); | ||||||
|  | 
 | ||||||
|  | 	$userstring = implode ("\n", $commands); | ||||||
|  | 	if (function_exists(proc_open)) { | ||||||
|  | 		// New Code, requires PHP 4.3
 | ||||||
|  | 		$descriptorspec = array( | ||||||
|  | 			0 => array("pipe", "r"), // stdin
 | ||||||
|  | 			1 => array("pipe", "w"), // stout
 | ||||||
|  | 			2 => array("file", "/dev/null", "a") // sterr
 | ||||||
|  | 			); | ||||||
|  | 		$process = proc_open(escapeshellarg($_SESSION['lampath']."lib/lamdaemon.pl")." ".$towrite, | ||||||
|  | 			$descriptorspec, | ||||||
|  | 			$pipes); | ||||||
|  | 		if (is_resource($process)) { | ||||||
|  | 			/* perl-script is running | ||||||
|  | 			* $pipes[0] is writeable handle to child stdin | ||||||
|  | 			* $pipes[1] is readable handle to child stdout | ||||||
|  | 			* any error is send to /dev/null | ||||||
|  | 			*/ | ||||||
|  | 			// Write to stdin
 | ||||||
|  | 			fwrite($pipes[0], $userstring); | ||||||
|  | 			} | ||||||
|  | 		fclose($pipes[0]); | ||||||
|  | 		while (!feof($pipes[1])) { | ||||||
|  | 			$output = fgets($pipes[1], 1024); | ||||||
|  | 			if ($output!='') $output_array[] = $output; | ||||||
|  | 			} | ||||||
|  | 		fclose($pipes[1]); | ||||||
|  | 		proc_close($process); | ||||||
|  | 		} | ||||||
|  | 	else { // PHP 4.3>
 | ||||||
|  | 		$command = escapeshellarg($_SESSION['lampath']."lib/lamdaemon.pl")." ".$towrite; | ||||||
|  | 		$pipe = popen("echo \"$userstring\"|$command" , 'r');
 | ||||||
|  | 		while(!feof($pipe)) { | ||||||
|  | 			//$output .= fread($pipe, 1024);
 | ||||||
|  | 			$output = fgets($pipe, 1024); | ||||||
|  | 			if ($output!='') $output_array[] = $output; | ||||||
|  | 			} | ||||||
|  | 		pclose($pipe); | ||||||
|  | 		} | ||||||
|  | 	return $output_array; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | ?>
 | ||||||
|  | @ -39,6 +39,8 @@ include_once("account.inc"); | ||||||
| include_once("baseModule.inc"); | include_once("baseModule.inc"); | ||||||
| /** access to LDAP server */ | /** access to LDAP server */ | ||||||
| include_once("ldap.inc"); | include_once("ldap.inc"); | ||||||
|  | /** lamdaemon functions */ | ||||||
|  | include_once("lamdaemon.inc"); | ||||||
|   |   | ||||||
| /** | /** | ||||||
| * This includes all module files. | * This includes all module files. | ||||||
|  | @ -1424,7 +1426,7 @@ class accountContainer { | ||||||
| 
 | 
 | ||||||
| 		if (!$stopprocessing) { | 		if (!$stopprocessing) { | ||||||
| 			foreach ($attributes as $DN) { | 			foreach ($attributes as $DN) { | ||||||
| 				if (is_array($DN['lamdaemon']['command'])) $result = $this->lamdaemon($DN['lamdaemon']['command']); | 				if (is_array($DN['lamdaemon']['command'])) $result = lamdaemon($DN['lamdaemon']['command']); | ||||||
| 				// Error somewhere in lamdaemon
 | 				// Error somewhere in lamdaemon
 | ||||||
| 				if (is_array($result)) | 				if (is_array($result)) | ||||||
| 					foreach ($result as $singleresult) { | 					foreach ($result as $singleresult) { | ||||||
|  | @ -1442,57 +1444,6 @@ class accountContainer { | ||||||
| 		return 0; | 		return 0; | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 	function lamdaemon($commands) { |  | ||||||
| 		// get username and password of the current lam-admin
 |  | ||||||
| 		$ldap_q = $_SESSION['ldap']->decrypt_login(); |  | ||||||
| 		/* $towrite has the following syntax: |  | ||||||
| 		* admin-username, admin-password, owner of homedir, 'home', operation='add' |  | ||||||
| 		* use escapeshellarg to make exec() shell-safe |  | ||||||
| 		*/ |  | ||||||
| 		$towrite = escapeshellarg($_SESSION['config']->scriptServer)." ".escapeshellarg($_SESSION['config']->scriptPath)." ". |  | ||||||
| 			escapeshellarg($ldap_q[0]).' '.escapeshellarg($ldap_q[1]); |  | ||||||
| 
 |  | ||||||
| 		$userstring = implode ("\n", $commands); |  | ||||||
| 		if (function_exists(proc_open)) { |  | ||||||
| 			// New Code, requires PHP 4.3
 |  | ||||||
| 			$descriptorspec = array( |  | ||||||
| 				0 => array("pipe", "r"), // stdin
 |  | ||||||
| 				1 => array("pipe", "w"), // stout
 |  | ||||||
| 				2 => array("file", "/dev/null", "a") // sterr
 |  | ||||||
| 				); |  | ||||||
| 			$process = proc_open(escapeshellarg($_SESSION['lampath']."lib/lamdaemon.pl")." ".$towrite, |  | ||||||
| 				$descriptorspec, |  | ||||||
| 				$pipes); |  | ||||||
| 			if (is_resource($process)) { |  | ||||||
| 				/* perl-script is running |  | ||||||
| 				* $pipes[0] is writeable handle to child stdin |  | ||||||
| 				* $pipes[1] is readable handle to child stdout |  | ||||||
| 				* any error is send to /dev/null |  | ||||||
| 				*/ |  | ||||||
| 				// Write to stdin
 |  | ||||||
| 				fwrite($pipes[0], $userstring); |  | ||||||
| 				} |  | ||||||
| 			fclose($pipes[0]); |  | ||||||
| 			while (!feof($pipes[1])) { |  | ||||||
| 				$output = fgets($pipes[1], 1024); |  | ||||||
| 				if ($output!='') $output_array[] = $output; |  | ||||||
| 				} |  | ||||||
| 			fclose($pipes[1]); |  | ||||||
| 			proc_close($process); |  | ||||||
| 			} |  | ||||||
| 		else { // PHP 4.3>
 |  | ||||||
| 			$command = escapeshellarg($_SESSION['lampath']."lib/lamdaemon.pl")." ".$towrite; |  | ||||||
| 			$pipe = popen("echo \"$userstring\"|$command" , 'r');
 |  | ||||||
| 			while(!feof($pipe)) { |  | ||||||
| 				//$output .= fread($pipe, 1024);
 |  | ||||||
| 				$output = fgets($pipe, 1024); |  | ||||||
| 				if ($output!='') $output_array[] = $output; |  | ||||||
| 				} |  | ||||||
| 			pclose($pipe); |  | ||||||
| 			} |  | ||||||
| 		return $output_array; |  | ||||||
| 		} |  | ||||||
| 		 |  | ||||||
| 		/** | 		/** | ||||||
| 		 *  | 		 *  | ||||||
| 		 *  | 		 *  | ||||||
|  |  | ||||||
|  | @ -105,7 +105,7 @@ class quota extends baseModule { | ||||||
| 		// call parent init
 | 		// call parent init
 | ||||||
| 		parent::init($base); | 		parent::init($base); | ||||||
| 		// Get basic quotas for new account
 | 		// Get basic quotas for new account
 | ||||||
| 		$output_array = $_SESSION[$this->base]->lamdaemon(array("+ quota get " . $_SESSION[$this->base]->type)); | 		$output_array = lamdaemon(array("+ quota get " . $_SESSION[$this->base]->type)); | ||||||
| 		// process quotas
 | 		// process quotas
 | ||||||
| 		if (is_array($output_array)) { | 		if (is_array($output_array)) { | ||||||
| 			$all_quota = explode(':', $output_array[0]); | 			$all_quota = explode(':', $output_array[0]); | ||||||
|  | @ -174,7 +174,7 @@ class quota extends baseModule { | ||||||
| 		if ($_SESSION[$this->base]->type=='user') $id = $attr['uid'][0]; | 		if ($_SESSION[$this->base]->type=='user') $id = $attr['uid'][0]; | ||||||
| 		if ($_SESSION[$this->base]->type=='group') $id = $attr['cn'][0]; | 		if ($_SESSION[$this->base]->type=='group') $id = $attr['cn'][0]; | ||||||
| 		// Get quotas
 | 		// Get quotas
 | ||||||
| 		$output_array = $_SESSION[$this->base]->lamdaemon(array("$id quota get " . $_SESSION[$this->base]->type)); | 		$output_array = lamdaemon(array("$id quota get " . $_SESSION[$this->base]->type)); | ||||||
| 		// process quotas
 | 		// process quotas
 | ||||||
| 		if (is_array($output_array)) { | 		if (is_array($output_array)) { | ||||||
| 			$all_quota = explode(':', $output_array[0]); | 			$all_quota = explode(':', $output_array[0]); | ||||||
|  | @ -336,7 +336,7 @@ class quota extends baseModule { | ||||||
| 	*/ | 	*/ | ||||||
| 	function get_profileOptions() { | 	function get_profileOptions() { | ||||||
| 		// Get quotas
 | 		// Get quotas
 | ||||||
| 		$quotas = $_SESSION[$this->base]->lamdaemon(array("+ quota get " . $this->get_scope())); | 		$quotas = lamdaemon(array("+ quota get " . $this->get_scope())); | ||||||
| 		$dirs = split(":", $quotas[0]); | 		$dirs = split(":", $quotas[0]); | ||||||
| 		array_pop($dirs); // remove empty element at the end
 | 		array_pop($dirs); // remove empty element at the end
 | ||||||
| 		for ($i = 0; $i < sizeof($dirs); $i++) { | 		for ($i = 0; $i < sizeof($dirs); $i++) { | ||||||
|  |  | ||||||
|  | @ -31,6 +31,7 @@ include_once('../lib/profiles.inc'); // functions to load and save profiles | ||||||
| include_once('../lib/status.inc'); // Return error-message
 | include_once('../lib/status.inc'); // Return error-message
 | ||||||
| include_once('../lib/pdf.inc'); // Return a pdf-file
 | include_once('../lib/pdf.inc'); // Return a pdf-file
 | ||||||
| include_once('../lib/ldap.inc'); // LDAP-functions
 | include_once('../lib/ldap.inc'); // LDAP-functions
 | ||||||
|  | include_once('../lib/lamdaemon.inc'); // lamdaemon
 | ||||||
| 
 | 
 | ||||||
| /* We have to include all modules | /* We have to include all modules | ||||||
| * before start session | * before start session | ||||||
|  | @ -201,7 +202,7 @@ if ($_POST['delete']) { | ||||||
| 			} | 			} | ||||||
| 		if (!$stopprocessing) { | 		if (!$stopprocessing) { | ||||||
| 			foreach ($attributes as $DN) { | 			foreach ($attributes as $DN) { | ||||||
| 				if (is_array($DN['lamdaemon']['command'])) $result = $_SESSION['account']->lamdaemon($DN['lamdaemon']['command']); | 				if (is_array($DN['lamdaemon']['command'])) $result = lamdaemon($DN['lamdaemon']['command']); | ||||||
| 				// Error somewhere in lamdaemon
 | 				// Error somewhere in lamdaemon
 | ||||||
| 				foreach ($result as $singleresult) { | 				foreach ($result as $singleresult) { | ||||||
| 					if (is_array($singleresult)) { | 					if (is_array($singleresult)) { | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue