changed code to communicate with lamdaemon.pl

to support < PHP 4.3
This commit is contained in:
katagia 2003-11-08 12:29:23 +00:00
parent 78145c6288
commit 55e8c117ed
5 changed files with 225 additions and 132 deletions

View File

@ -210,33 +210,48 @@ function getquotas($type,$users=array('+')) {
/* scriptServer is the IP to remote-host to which lam should connect via ssh
* scriptPath is Path to lamdaemon.pl on remote system
*/
$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
*/
foreach ($users as $user) {
// put string to trasmit together
$userstring = "$user quota get $type\n";
// Write one output-line for every user
fwrite($pipes[0], $userstring);
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
*/
foreach ($users as $user) {
// put string to trasmit together
$userstring = "$user quota get $type\n";
// Write one output-line for every user
fwrite($pipes[0], $userstring);
}
fclose($pipes[0]);
while (!feof($pipes[1])) {
$output = fgets($pipes[1], 1024);
if ($output!='') $vals5[] = $output;
}
fclose($pipes[1]);
$return_value = proc_close($process);
}
fclose($pipes[0]);
while (!feof($pipes[1])) {
$output = fgets($pipes[1], 1024);
}
else { // PHP 4.3>
$input = "";
foreach ($users as $user) $input .= "$user quota get $type\n";
$command = escapeshellarg($_SESSION['lampath']."lib/lamdaemon.pl")." ".$towrite;
$pipe = popen("echo \"$input\"|$command" , 'r');
$output = '';
while(!feof($pipe)) {
$output .= fread($pipe, 1024);
if ($output!='') $vals5[] = $output;
}
fclose($pipes[1]);
$return_value = proc_close($process);
pclose($pipe);
}
/* $vals is a string which contains a two dimensional array.
* We have to recreate it with explode
@ -246,20 +261,21 @@ function getquotas($type,$users=array('+')) {
* mountpoint, used blocks, soft block limit, hard block limit, grace block period, used inodes,
* soft inode limit, hard inode limit, grace inode period
*/
foreach ($vals5 as $vals3) {
$vals = explode(':', $vals3);
for ($i=0; $i<sizeof($vals)-1; $i++) {
$vals2 = explode(',', $vals[$i]);
for ($j=0; $j<sizeof($vals2); $j++) {
$return->quota[$i][$j] = $vals2[$j];
if (is_array($vals5))
foreach ($vals5 as $vals3) {
$vals = explode(':', $vals3);
for ($i=0; $i<sizeof($vals)-1; $i++) {
$vals2 = explode(',', $vals[$i]);
for ($j=0; $j<sizeof($vals2); $j++) {
$return->quota[$i][$j] = $vals2[$j];
}
if ($return->quota[$i][4]<$time) $return->quota[$i][4] = '';
else $return->quota[$i][4] = strval(($return->quota[$i][4]-$time)/3600) .' '. _('hours');
if ($return->quota[$i][8]<$time) $return->quota[$i][8] = '';
else $return->quota[$i][8] = strval(($return->quota[$i][8]-$time)/3600) .' '. _('hours');
}
if ($return->quota[$i][4]<$time) $return->quota[$i][4] = '';
else $return->quota[$i][4] = strval(($return->quota[$i][4]-$time)/3600) .' '. _('hours');
if ($return->quota[$i][8]<$time) $return->quota[$i][8] = '';
else $return->quota[$i][8] = strval(($return->quota[$i][8]-$time)/3600) .' '. _('hours');
$return2[] = $return;
}
$return2[] = $return;
}
return $return2;
}
@ -278,20 +294,51 @@ function setquotas($values2,$values2_old=false) {
*/
$towrite = escapeshellarg($_SESSION['config']->scriptServer)." ".escapeshellarg($_SESSION['config']->scriptPath)." ".
escapeshellarg($ldap_q[0]).' '.escapeshellarg($ldap_q[1]);
$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
*/
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
*/
foreach ($values2 as $values) {
$i=0;
/* Check wich quotas have changed
* Because we can not send an array to lamdaemon.pl we have to put all
* values in a string. ':' sepraeates the first array, ',' the second
*
* $values->quota[][] First array is an index for every chare with active quotas
* second array Contains values for every share:
* mountpoint, used blocks, soft block limit, hard block limit, grace block period, used inodes,
* soft inode limit, hard inode limit, grace inode period
*/
while ($values->quota[$i][0]) {
if ($values->quota[$i] != $values_old->quota[$i]) {
$quotastring = $quotastring. $values->quota[$i][0] .','.$values->quota[$i][2] .','.$values->quota[$i][3]
.','.$values->quota[$i][6] .','. $values->quota[$i][7] .':';
}
$i++;
}
$userstring = $values->general_username." quota set ".$values->type." ".$quotastring."\n";
// Write to stdin
fwrite($pipes[0], $userstring);
}
}
fclose($pipes[0]);
fclose($pipes[1]);
$return_value = proc_close($process);
}
else { // PHP 4.3>
$input = "";
foreach ($values2 as $values) {
$i=0;
/* Check wich quotas have changed
@ -310,14 +357,15 @@ function setquotas($values2,$values2_old=false) {
}
$i++;
}
$userstring = $values->general_username." quota set ".$values->type." ".$quotastring."\n";
// Write to stdin
fwrite($pipes[0], $userstring);
$input .= $values->general_username." quota set ".$values->type." ".$quotastring."\n";
}
$command = escapeshellarg($_SESSION['lampath']."lib/lamdaemon.pl")." ".$towrite;
$pipe = popen("echo \"$input\"|$command" , 'r');
while(!feof($pipe)) {
$return[] = fread($pipe, 1024);
}
pclose($pipe);
}
fclose($pipes[0]);
fclose($pipes[1]);
$return_value = proc_close($process);
}
@ -335,29 +383,43 @@ function remquotas($users, $type) {
*/
$towrite = escapeshellarg($_SESSION['config']->scriptServer)." ".escapeshellarg($_SESSION['config']->scriptPath)." ".
escapeshellarg($ldap_q[0]).' '.escapeshellarg($ldap_q[1]);
$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
*/
foreach ($users as $user) {
$userstring = "$user quota rem $type\n";
// Write to stdin
fwrite($pipes[0], $userstring);
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
*/
foreach ($users as $user) {
$userstring = "$user quota rem $type\n";
// Write to stdin
fwrite($pipes[0], $userstring);
}
}
fclose($pipes[0]);
fclose($pipes[1]);
$return_value = proc_close($process);
}
else { // PHP 4.3>
$input = "";
foreach ($users as $user) $userstring .= "$user quota rem $type\n";
$command = escapeshellarg($_SESSION['lampath']."lib/lamdaemon.pl")." ".$towrite;
$pipe = popen("echo \"$input\"|$command" , 'r');
$output = '';
while(!feof($pipe)) {
$return[] = fread($pipe, 1024);
}
pclose($pipe);
}
fclose($pipes[0]);
fclose($pipes[1]);
$return_value = proc_close($process);
}
@ -375,32 +437,45 @@ function addhomedir($users) {
*/
$towrite = escapeshellarg($_SESSION['config']->scriptServer)." ".escapeshellarg($_SESSION['config']->scriptPath)." ".
escapeshellarg($ldap_q[0]).' '.escapeshellarg($ldap_q[1]);
$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
*/
foreach ($users as $user) {
$userstring = "$user home add\n";
// Write to stdin
fwrite($pipes[0], $userstring);
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
*/
foreach ($users as $user) {
$userstring = "$user home add\n";
// Write to stdin
fwrite($pipes[0], $userstring);
}
}
fclose($pipes[0]);
fclose($pipes[1]);
$return_value = proc_close($process);
}
else { // PHP 4.3>
$input = "";
foreach ($users as $user) $userstring .= "$user home add\n";
$command = escapeshellarg($_SESSION['lampath']."lib/lamdaemon.pl")." ".$towrite;
$pipe = popen("echo \"$input\"|$command" , 'r');
$output = '';
while(!feof($pipe)) {
$return[] = fread($pipe, 1024);
}
pclose($pipe);
}
fclose($pipes[0]);
fclose($pipes[1]);
$return_value = proc_close($process);
}
/* Remove Homedirectory
* lamdaemon.pl uses getpwnam on remote system to get homedir path.
* Therefore ldap have to be used on remote system for user accounts
@ -417,29 +492,43 @@ function remhomedir($users) {
*/
$towrite = escapeshellarg($_SESSION['config']->scriptServer)." ".escapeshellarg($_SESSION['config']->scriptPath)." ".
escapeshellarg($ldap_q[0]).' '.escapeshellarg($ldap_q[1]);
$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
*/
foreach ($users as $user) {
$userstring = "$user home rem\n";
// Write to stdin
fwrite($pipes[0], $userstring);
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
*/
foreach ($users as $user) {
$userstring = "$user home rem\n";
// Write to stdin
fwrite($pipes[0], $userstring);
}
}
fclose($pipes[0]);
fclose($pipes[1]);
$return_value = proc_close($process);
}
else { // PHP 4.3>
$input = "";
foreach ($users as $user) $userstring .= "$user home rem\n";
$command = escapeshellarg($_SESSION['lampath']."lib/lamdaemon.pl")." ".$towrite;
$pipe = popen("echo \"$input\"|$command" , 'r');
$output = '';
while(!feof($pipe)) {
$return[] = fread($pipe, 1024);
}
pclose($pipe);
}
fclose($pipes[0]);
fclose($pipes[1]);
$return_value = proc_close($process);
}
@ -471,10 +560,10 @@ function ldapreload($type) {
// insert timestamp in array
$_SESSION['userDN'][0] = time();
// Search 4 values which should be cached
$result = ldap_search($_SESSION['ldap']->server(), $_SESSION['config']->get_UserSuffix(),
$result = @ldap_search($_SESSION['ldap']->server(), $_SESSION['config']->get_UserSuffix(),
'(&(objectClass=posixAccount)(!(uid=*$)))', array('cn', 'uidNumber'), 0);
// Write search result in array
$entry = ldap_first_entry($_SESSION['ldap']->server(), $result);
$entry = @ldap_first_entry($_SESSION['ldap']->server(), $result);
while ($entry) {
$dn = (ldap_get_dn($_SESSION['ldap']->server(), $entry));
$attr = ldap_get_attributes($_SESSION['ldap']->server(), $entry);
@ -494,10 +583,10 @@ function ldapreload($type) {
// insert timestamp in array
$_SESSION['groupDN'][0] = time();
// Search 4 values which should be cached
$result = ldap_search($_SESSION['ldap']->server(), $_SESSION['config']->get_GroupSuffix(),
$result = @ldap_search($_SESSION['ldap']->server(), $_SESSION['config']->get_GroupSuffix(),
'objectClass=posixGroup', array('gidNumber', 'cn'), 0);
// Write search result in array
$entry = ldap_first_entry($_SESSION['ldap']->server(), $result);
$entry = @ldap_first_entry($_SESSION['ldap']->server(), $result);
while ($entry) {
$dn = (ldap_get_dn($_SESSION['ldap']->server(), $entry));
$attr = ldap_get_attributes($_SESSION['ldap']->server(), $entry);
@ -517,10 +606,10 @@ function ldapreload($type) {
// insert timestamp in array
$_SESSION['hostDN'][0] = time();
// Search 4 values which should be cached
$result = ldap_search($_SESSION['ldap']->server(), $_SESSION['config']->get_HostSuffix(),
$result = @ldap_search($_SESSION['ldap']->server(), $_SESSION['config']->get_HostSuffix(),
'(&(objectClass=posixAccount)(uid=*$))', array('cn', 'uidNumber'), 0);
// Write search result in array
$entry = ldap_first_entry($_SESSION['ldap']->server(), $result);
$entry = @ldap_first_entry($_SESSION['ldap']->server(), $result);
while ($entry) {
$dn = (ldap_get_dn($_SESSION['ldap']->server(), $entry));
$attr = ldap_get_attributes($_SESSION['ldap']->server(), $entry);

View File

@ -69,13 +69,15 @@ function createUserPDF($accounts) {
$info_string = str_replace('$'.$value, $sub_array, $info_string);
}
}
// Split string in array
$info_array = explode("\n", $info_string);
$pdfFile->setFont("arial","B",12);
$pdfFile->Write(5,"- " . _("User Information") . ":");
$pdfFile->Ln(6);
$pdfFile->setFont("times","",10);
$pdfFile->Cell(50,5,$info_string,0,1,"L",0);
$pdfFile->Ln(9);
foreach ($info_array as $info)
$pdfFile->Cell(50,5,$info,0,1,"L",0);
$pdfFile->Ln(6);
// Print Personal settings
$pdfFile->setFont("arial","B",12);
$pdfFile->Write(5,"- " . _("Personal User Infos") . ":");

View File

@ -94,9 +94,10 @@ else if (count($_POST)==0) {
"<link rel=\"stylesheet\" type=\"text/css\" href=\"../../style/layout.css\">\n".
"<meta http-equiv=\"pragma\" content=\"no-cache\">\n".
"<meta http-equiv=\"cache-control\" content=\"no-cache\">\n".
"</head><body>\n".
"</head><body>\n";
// Display errir-messages
StatusMessage("ERROR", _("Can not create any hosts."),_("Please create a group first."));
echo "<a href=../lists/listhosts.php>"._("Back to hostlist")."</a>\n";
echo "</body></html>";
die;
}

View File

@ -104,7 +104,7 @@ if (isset($_GET['DN']) && $_GET['DN']!='') {
"<link rel=\"stylesheet\" type=\"text/css\" href=\"../../style/layout.css\">\n".
"<meta http-equiv=\"pragma\" content=\"no-cache\">\n".
"<meta http-equiv=\"cache-control\" content=\"no-cache\">\n".
"</head><body>\n".
"</head><body>\n";
// Display errir-messages
StatusMessage("ERROR", _("Can not create any users."),_("Please create a group first."));
echo "<a href=../lists/listusers.php>"._("Back to userlist")."</a>\n";

View File

@ -44,7 +44,6 @@ $header_intern =& $_SESSION['header'];
$config_intern =& $_SESSION['config'];
$delete_dn =& $_SESSION['delete_dn'];
if ($_POST['backmain']) {
// back to list page
if (isset($_SESSION['delete_dn'])) unset ($_SESSION['delete_dn']);
@ -69,6 +68,8 @@ echo '</title>'."\n".
if ($_GET['type']) {
// $_GET['type'] is true if delete.php was called from *list.php
// Store $_GET['type'] as $_POST['type']
// Replace wrong chars from Session
for ($i=0; $i<count($delete_dn); $i++) $delete_dn[$i] = str_replace("_", " ", $delete_dn[$i]);
echo '<input name="type" type="hidden" value="'.$_GET['type'].'">';
switch ($_GET['type']) {
// Select which layout and text should be displayed