diff --git a/lam/lib/account.inc b/lam/lib/account.inc index 541b6061..26aa7640 100644 --- a/lam/lib/account.inc +++ b/lam/lib/account.inc @@ -192,13 +192,12 @@ function RndInt($Format){ /* Whis function will return the quotas from the specified user If empty only filesystems with enabled quotas are returned -* $type = 'user' or 'group' -* $users = array of users or groupnames. If no user or groupname is defined, +* $users = array of account objects. If $user is a string (user or group) * an array with all quota-enabled partitions will be returned in this case all returned values are 0 exept mointpoint[x][0] */ -function getquotas($type,$users=array('+')) { +function getquotas($users) { // define new object - $return = new account(); + $return = $users; // get username and password of the current lam-admin $ldap_q = $_SESSION['ldap']->decrypt(); /* $towrite has the following syntax: @@ -210,6 +209,10 @@ 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 */ + for($i=0; $igeneral_username!='') $userstring .= $return[$i]->general_username." quota get ".$return[$i]->type."\n"; + else $userstring .= "+ quota get ".$return[$i]->type."\n"; if (function_exists(proc_open)) { // New Code, requires PHP 4.3 $descriptorspec = array( @@ -226,30 +229,24 @@ function getquotas($type,$users=array('+')) { * $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); - } + // 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; + if ($output!='') $output_array[] = $output; } fclose($pipes[1]); $return_value = proc_close($process); } } 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'); + $pipe = popen("echo \"$userstring\"|$command" , 'r'); $output = ''; while(!feof($pipe)) { $output .= fread($pipe, 1024); - if ($output!='') $vals5[] = $output; + if ($output!='') $output_array[] = $output; } pclose($pipe); } @@ -261,22 +258,29 @@ 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 */ - if (is_array($vals5)) - foreach ($vals5 as $vals3) { - $vals = explode(':', $vals3); - for ($i=0; $iquota[$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'); - } - $return2[] = $return; + for ($i=0; $iquota[$j][$k] = $single_quota[$k]; + if ($return[$i]->quota[$j][4]quota[$j][4] = ''; + else $return[$i]->quota[$j][4] = strval(($return[$i]->quota[$j][4]-time())/3600) .' '. _('hours'); + if ($return[$i]->quota[$j][8]quota[$j][8] = ''; + else $return[$i]->quota[$j][8] = strval(($return[$i]->quota[$j][8]-time())/3600) .' '. _('hours'); } - return $return2; + $j=0; + while (isset($return[$i]->quota[$j][0])) + // remove invalid quotas + if (!in_array($return[$i]->quota[$j][0], $real_quotas)) unset($return[$i]->quota[$j]); + else $j++; + // Beautify array, repair index + $return[$i]->quota = array_values($return[$i]->quota); + } + return $return; } diff --git a/lam/templates/account/groupedit.php b/lam/templates/account/groupedit.php index 665bf0c6..4b7a4a12 100644 --- a/lam/templates/account/groupedit.php +++ b/lam/templates/account/groupedit.php @@ -93,37 +93,24 @@ else if (count($_POST)==0) { $account_new ->type = 'group'; if ($config_intern->scriptServer) { // load quotas and check if quotas from profile are valid - $values = getquotas('group'); - if (isset($account_new->quota[0])) { - // check quotas from profile - $i=0; - // check quota settings, loop for every partition with quotas - while (isset($account_new->quota[$i])) { - // search if quotas from profile fit to a real quota - $found = (-1); - for ($j=0; $jquota); $j++) - if ($values->quota[$j][0]==$account_new->quota[$i][0]) $found = $j; - // unset quota from profile if quotas (mointpoint) doesn't exists anymore - if ($found==-1) unset($account_new->quota[$i]); - else { - // Set missing part in quota-array - $account_new->quota[$i][1] = $values[0]->quota[$found][1]; - $account_new->quota[$i][5] = $values[0]->quota[$found][5]; - $account_new->quota[$i][4] = $values[0]->quota[$found][4]; - $account_new->quota[$i][8] = $values[0]->quota[$found][8]; - $i++; - } + $quotas = getquotas(array($account_new)); + for ($i=0; $iquota); $i++) $profile_quotas[] = $account_new->quota[$i][0]; + for ($i=0; $iquota); $i++) { + $real_quotas[] = $quotas[0]->quota[$i][0]; + if (is_array($profile_quotas)) { + if (!in_array($quotas[0]->quota[$i][0], $profile_quotas)) $account_new->quota[]=$quotas[0]->quota[$i]; } - // Beautify array, repair index - $account_new->quota = array_values($account_new->quota); + else $account_new->quota[]=$quotas[0]->quota[$i]; } - else { // No quotas saved in profile - // Display quotas for new users (Quota set to 0) - if (is_object($values[0])) { - while (list($key, $val) = each($values[0])) // Set only defined values - if (isset($val)) $account_new->$key = $val; - } + $j=0; + // delete not existing quotas + while (isset($account_new->quota[$j][0])) { + // remove invalid quotas + if (!in_array($account_new->quota[$j][0], $real_quotas)) unset($account_new->quota[$j]); + else $j++; } + // Beautify array, repair index + $account_new->quota = array_values($account_new->quota); } // Display general-page $select_local = 'general'; @@ -284,15 +271,8 @@ switch ($_POST['select']) { if ($_POST['outputpdf']) { // Load quotas if not yet done because they are needed for the pdf-file if ($config_intern->scriptServer && !isset($account_new->quota[0])) { // load quotas - $values = getquotas('group', array($account_old->general_username)); - if (is_object($values[0])) { - while (list($key, $val) = each($values[0])) // Set only defined values - if (isset($val)) $account_new->$key = $val; - } - if (is_object($values[0]) && isset($account_old)) { - while (list($key, $val) = each($values[0])) // Set only defined values - if (isset($val)) $account_old->$key = $val; - } + $quotas = getquotas(array($account_old)); + $account_new = $quotas[0]; } // Create / display PDf-file createGroupPDF(array($account_new)); @@ -401,37 +381,24 @@ do { // X-Or, only one if() can be true } if ($config_intern->scriptServer) { // load quotas and check if quotas from profile are valid - $values = getquotas('group'); - if (isset($account_new->quota[0])) { - // check quotas from profile - $i=0; - // check quota settings, loop for every partition with quotas - while (isset($account_new->quota[$i])) { - // search if quotas from profile fit to a real quota - $found = (-1); - for ($j=0; $jquota); $j++) - if ($values[0]->quota[$j][0]==$account_new->quota[$i][0]) $found = $j; - // unset quota from profile if quotas (mointpoint) doesn't exists anymore - if ($found==-1) unset($account_new->quota[$i]); - else { - // Set missing part in quota-array - $account_new->quota[$i][1] = $values[0]->quota[$found][1]; - $account_new->quota[$i][5] = $values[0]->quota[$found][5]; - $account_new->quota[$i][4] = $values[0]->quota[$found][4]; - $account_new->quota[$i][8] = $values[0]->quota[$found][8]; - $i++; - } + $quotas = getquotas(array($account_new)); + for ($i=0; $iquota); $i++) $profile_quotas[] = $account_new->quota[$i][0]; + for ($i=0; $iquota); $i++) { + $real_quotas[] = $quotas[0]->quota[$i][0]; + if (is_array($profile_quotas)) { + if (!in_array($quotas[0]->quota[$i][0], $profile_quotas)) $account_new->quota[]=$quotas[0]->quota[$i]; } - // Beautify array, repair index - $account_new->quota = array_values($account_new->quota); + else $account_new->quota[]=$quotas[0]->quota[$i]; } - else { // No quotas saved in profile - // Display quotas for new users (Quota set to 0) - if (is_object($values[0])) { - while (list($key, $val) = each($values[0])) // Set only defined values - if (isset($val)) $account_new->$key = $val; - } + $j=0; + // delete not existing quotas + while (isset($account_new->quota[$j][0])) { + // remove invalid quotas + if (!in_array($account_new->quota[$j][0], $real_quotas)) unset($account_new->quota[$j]); + else $j++; } + // Beautify array, repair index + $account_new->quota = array_values($account_new->quota); } // select general page after group has been loaded $select_local='general'; @@ -739,15 +706,8 @@ switch ($select_local) { // Quota Settings // Load quotas if not yet done if ($config_intern->scriptServer && !isset($account_new->quota[0]) ) { // load quotas - $values = getquotas('group', array($account_new->general_username)); - if (is_object($values[0])) { - while (list($key, $val) = each($values[0])) // Set only defined values - if (isset($val)) $account_new->$key = $val; - } - if (is_object($values[0]) && isset($account_old)) { - while (list($key, $val) = each($values[0])) // Set only defined values - if (isset($val)) $account_old->$key = $val; - } + $quotas = getquotas(array($account_new)); + $account_new = $quotas[0]; } echo "\n"; echo "\n
"; diff --git a/lam/templates/account/useredit.php b/lam/templates/account/useredit.php index ad46317c..3883b451 100644 --- a/lam/templates/account/useredit.php +++ b/lam/templates/account/useredit.php @@ -89,7 +89,7 @@ if (isset($_GET['DN']) && $_GET['DN']!='') { // Display general-page $select_local = 'general'; } -// Startcondition. useredit.php was called from outside to create a new group +// Startcondition. useredit.php was called from outside to create a new user else if (count($_POST)==0) { // Create new account object with settings from default profile // Check if there are valid groups. Can not create user with no primary group @@ -114,37 +114,24 @@ if (isset($_GET['DN']) && $_GET['DN']!='') { $account_new ->type = 'user'; if ($config_intern->scriptServer) { // load quotas and check if quotas from profile are valid - $values = getquotas('user'); - if (isset($account_new->quota[0])) { - // check quotas from profile - $i=0; - // check quota settings, loop for every partition with quotas - while (isset($account_new->quota[$i])) { - // search if quotas from profile fit to a real quota - $found = (-1); - for ($j=0; $jquota); $j++) - if ($values[0]->quota[$j][0]==$account_new->quota[$i][0]) $found = $j; - // unset quota from profile if quotas (mointpoint) doesn't exists anymore - if ($found==-1) unset($account_new->quota[$i]); - else { - // Set missing part in quota-array - $account_new->quota[$i][1] = $values[0]->quota[$found][1]; - $account_new->quota[$i][5] = $values[0]->quota[$found][5]; - $account_new->quota[$i][4] = $values[0]->quota[$found][4]; - $account_new->quota[$i][8] = $values[0]->quota[$found][8]; - $i++; - } + $quotas = getquotas(array($account_new)); + for ($i=0; $iquota); $i++) $profile_quotas[] = $account_new->quota[$i][0]; + for ($i=0; $iquota); $i++) { + $real_quotas[] = $quotas[0]->quota[$i][0]; + if (is_array($profile_quotas)) { + if (!in_array($quotas[0]->quota[$i][0], $profile_quotas)) $account_new->quota[]=$quotas[0]->quota[$i]; } - // Beautify array, repair index - $account_new->quota = array_values($account_new->quota); + else $account_new->quota[]=$quotas[0]->quota[$i]; } - else { // No quotas saved in profile - // Display quotas for new users (Quota set to 0) - if (is_object($values[0])) { - while (list($key, $val) = each($values[0])) // Set only defined values - if (isset($val)) $account_new->$key = $val; - } + $j=0; + // delete not existing quotas + while (isset($account_new->quota[$j][0])) { + // remove invalid quotas + if (!in_array($account_new->quota[$j][0], $real_quotas)) unset($account_new->quota[$j]); + else $j++; } + // Beautify array, repair index + $account_new->quota = array_values($account_new->quota); } // Display general-page $select_local = 'general'; @@ -518,15 +505,9 @@ switch ($_POST['select']) { if ($_POST['outputpdf']) { // Load quotas if not yet done because they are needed for the pdf-file if ($config_intern->scriptServer && !isset($account_new->quota[0])) { // load quotas - $values = getquotas('user', array($account_old->general_username)); - if (is_object($values[0])) { - while (list($key, $val) = each($values[0])) // Set only defined values - if (isset($val)) $account_new->$key = $val; - } - if (is_object($values[0]) && isset($account_old)) { - while (list($key, $val) = each($values[0])) // Set only defined values - if (isset($val)) $account_old->$key = $val; - } + $quotas = getquotas(array($account_old)); + $account_new = $quotas[0]; + $account_new->quota = $account_old->quota; } // Create / display PDf-file createUserPDF(array($account_new)); @@ -689,37 +670,24 @@ do { // X-Or, only one if() can be true $account_new->smb_smbhome = str_replace('$user', $account_new->general_username, $account_new->smb_smbhome); if ($config_intern->scriptServer) { // load quotas and check if quotas from profile are valid - $values = getquotas('user'); - if (isset($account_new->quota[0])) { - // check quotas from profile - $i=0; - // check quota settings, loop for every partition with quotas - while (isset($account_new->quota[$i])) { - // search if quotas from profile fit to a real quota - $found = (-1); - for ($j=0; $jquota); $j++) - if ($values[0]->quota[$j][0]==$account_new->quota[$i][0]) $found = $j; - // unset quota from profile if quotas (mointpoint) doesn't exists anymore - if ($found==-1) unset($account_new->quota[$i]); - else { - // Set missing part in quota-array - $account_new->quota[$i][1] = $values[0]->quota[$found][1]; - $account_new->quota[$i][5] = $values[0]->quota[$found][5]; - $account_new->quota[$i][4] = $values[0]->quota[$found][4]; - $account_new->quota[$i][8] = $values[0]->quota[$found][8]; - $i++; - } + $quotas = getquotas(array($account_new)); + for ($i=0; $iquota); $i++) $profile_quotas[] = $account_new->quota[$i][0]; + for ($i=0; $iquota); $i++) { + $real_quotas[] = $quotas[0]->quota[$i][0]; + if (is_array($profile_quotas)) { + if (!in_array($quotas[0]->quota[$i][0], $profile_quotas)) $account_new->quota[]=$quotas[0]->quota[$i]; } - // Beautify array, repair index - $account_new->quota = array_values($account_new->quota); + else $account_new->quota[]=$quotas[0]->quota[$i]; } - else { // No quotas saved in profile - // Display quotas for new users (Quota set to 0) - if (is_object($values[0])) { - while (list($key, $val) = each($values[0])) // Set only defined values - if (isset($val)) $account_new->$key = $val; - } + $j=0; + // delete not existing quotas + while (isset($account_new->quota[$j][0])) { + // remove invalid quotas + if (!in_array($account_new->quota[$j][0], $real_quotas)) unset($account_new->quota[$j]); + else $j++; } + // Beautify array, repair index + $account_new->quota = array_values($account_new->quota); } // select general page after group has been loaded $select_local='general'; @@ -1410,15 +1378,8 @@ switch ($select_local) { // Quota Settings // Load quotas if not yet done if ($config_intern->scriptServer && !isset($account_new->quota[0])) { // load quotas - $values = getquotas('user', array($account_old->general_username)); - if (is_object($values[0])) { - while (list($key, $val) = each($values[0])) // Set only defined values - if (isset($val)) $account_new->$key = $val; - } - if (is_object($values[0]) && isset($account_old)) { - while (list($key, $val) = each($values[0])) // Set only defined values - if (isset($val)) $account_old->$key = $val; - } + $quotas = getquotas(array($account_old)); + $account_new = $quotas[0]; } echo "\n"; echo "\n
"; diff --git a/lam/templates/masscreate.php b/lam/templates/masscreate.php index 085b1aa0..8af568c7 100644 --- a/lam/templates/masscreate.php +++ b/lam/templates/masscreate.php @@ -173,37 +173,24 @@ switch ($select) { // load quotas from profile and check if they are valid if ($config_intern->scriptServer) { // load quotas and check if quotas from profile are valid - $values = getquotas('group'); - if (isset($group->quota[0])) { - // check quotas from profile - $i=0; - // check quota settings, loop for every partition with quotas - while (isset($group->quota[$i])) { - // search if quotas from profile fit to a real quota - $found = (-1); - for ($j=0; $jquota); $j++) - if ($values[0]->quota[$j][0]==$group->quota[$i][0]) $found = $j; - // unset quota from profile if quotas (mointpoint) doesn't exists anymore - if ($found==-1) unset($group->quota[$i]); - else { - // Set missing part in quota-array - $group->quota[$i][1] = $values[0]->quota[$found][1]; - $group->quota[$i][5] = $values[0]->quota[$found][5]; - $group->quota[$i][4] = $values[0]->quota[$found][4]; - $group->quota[$i][8] = $values[0]->quota[$found][8]; - $i++; - } + $quotas = getquotas(array($group)); + for ($i=0; $iquota); $i++) $profile_quotas[] = $group->quota[$i][0]; + for ($i=0; $iquota); $i++) { + $real_quotas[] = $quotas[0]->quota[$i][0]; + if (is_array($profile_quotas)) { + if (!in_array($quotas[0]->quota[$i][0], $profile_quotas)) $group->quota[]=$quotas[0]->quota[$i]; } - // Beautify array, repair index - $group->quota = array_values($group->quota); + else $group->quota[]=$quotas[0]->quota[$i]; } - else { // No quotas saved in profile - // Display quotas for new users (Quota set to 0) - if (is_object($values[0])) { - while (list($key, $val) = each($values[0])) // Set only defined values - if (isset($val)) $group->$key = $val; - } + $j=0; + // delete not existing quotas + while (isset($group->quota[$j][0])) { + // remove invalid quotas + if (!in_array($group->quota[$j][0], $real_quotas)) unset($group->quota[$j]); + else $j++; } + // Beautify array, repair index + $group->quota = array_values($group->quota); } // Get groupname from current user $group->general_username=$_SESSION['accounts'][$_SESSION['pointer']]->general_group; @@ -467,37 +454,24 @@ function loadfile() { $profile->type = 'user'; if ($config_intern->scriptServer) { // load quotas and check if quotas from profile are valid - $values = getquotas('user'); - if (isset($profile->quota[0])) { - // check quotas from profile - $i=0; - // check quota settings, loop for every partition with quotas - while (isset($profile->quota[$i])) { - // search if quotas from profile fit to a real quota - $found = (-1); - for ($j=0; $jquota); $j++) - if ($values[0]->quota[$j][0]==$profile->quota[$i][0]) $found = $j; - // unset quota from profile if quotas (mointpoint) doesn't exists anymore - if ($found==-1) unset($profile->quota[$i]); - else { - // Set missing part in quota-array - $profile->quota[$i][1] = $values[0]->quota[$found][1]; - $profile->quota[$i][5] = $values[0]->quota[$found][5]; - $profile->quota[$i][4] = $values[0]->quota[$found][4]; - $profile->quota[$i][8] = $values[0]->quota[$found][8]; - $i++; - } + $quotas = getquotas(array($profile)); + for ($i=0; $iquota); $i++) $profile_quotas[] = $profile->quota[$i][0]; + for ($i=0; $iquota); $i++) { + $real_quotas[] = $quotas[0]->quota[$i][0]; + if (is_array($profile_quotas)) { + if (!in_array($quotas[0]->quota[$i][0], $profile_quotas)) $profile->quota[]=$quotas[0]->quota[$i]; } - // Beautify array, repair index - $profile->quota = array_values($profile->quota); + else $profile->quota[]=$quotas[0]->quota[$i]; } - else { // No quotas saved in profile - // Display quotas for new users (Quota set to 0) - if (is_object($values[0])) { - while (list($key, $val) = each($values[0])) // Set only defined values - if (isset($val)) $profile->$key = $val; - } + $j=0; + // delete not existing quotas + while (isset($profile->quota[$j][0])) { + // remove invalid quotas + if (!in_array($profile->quota[$j][0], $real_quotas)) unset($profile->quota[$j]); + else $j++; } + // Beautify array, repair index + $profile->quota = array_values($profile->quota); } // Get keys to en/decrypt passwords $iv = base64_decode($_COOKIE["IV"]);