improved quotas
fixed a possible problem: When chaning uidNumber quotas were lost.
This commit is contained in:
parent
ff02918d44
commit
2e46c96335
|
@ -192,8 +192,8 @@ function RndInt($Format){
|
|||
|
||||
|
||||
/* Whis function will return the quotas from the specified user If empty only filesystems with enabled quotas are returned
|
||||
* $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]
|
||||
* $users = array of account objects.
|
||||
* An array with all quota-enabled partitions will be returned in this case all returned values are 0 exept mointpoint[x][0]
|
||||
*/
|
||||
function getquotas($users) {
|
||||
// define new object
|
||||
|
@ -258,6 +258,7 @@ function getquotas($users) {
|
|||
* 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($output_array)) {
|
||||
for ($i=0; $i<count($return); $i++) {
|
||||
$all_quota = explode(':', $output_array[$i]);
|
||||
for ($j=0; $j<sizeof($all_quota)-1; $j++) {
|
||||
|
@ -278,18 +279,21 @@ function getquotas($users) {
|
|||
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);
|
||||
if (is_array($return[$i]->quota)) $return[$i]->quota = array_values($return[$i]->quota);
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
|
||||
else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/* Whis function will set the quotas from the specified user.
|
||||
* $values2 = array of object account with quotas which should be set
|
||||
* $values2_old = array of object account if set values and values_old will be compared. Quota will only be changed
|
||||
* if values differ
|
||||
*/
|
||||
function setquotas($values2,$values2_old=false) {
|
||||
function setquotas($values2) {
|
||||
// get username and password of the current lam-admin
|
||||
$ldap_q = $_SESSION['ldap']->decrypt();
|
||||
/* $towrite has the following syntax:
|
||||
|
@ -1745,6 +1749,13 @@ function modifyuser($values,$values_old,$uselamdaemon=true) { // Will modify the
|
|||
if (($values->personal_employeeType != $values_old->personal_employeeType) && ($values->personal_employeeType==''))
|
||||
$attr_rem['employeeType'] = utf8_encode($values_old->personal_employeeType);
|
||||
|
||||
if (($values->general_uidNumber != $values_old->general_uidNumber) && $_SESSION['config']->scriptServer) {
|
||||
// Remove old quotas
|
||||
remquotas(array($values_old->general_username), "user");
|
||||
// Remove quotas from $values_old because we have to rewrite them all
|
||||
unset ($values_old->quota);
|
||||
}
|
||||
|
||||
if ($values->general_dn != $values_old->general_dn) {
|
||||
// Account should be moved to a new location
|
||||
// Load old account
|
||||
|
@ -1829,8 +1840,8 @@ function modifyuser($values,$values_old,$uselamdaemon=true) { // Will modify the
|
|||
}
|
||||
|
||||
// Change quotas if quotas are set and lamdaemon.pl should be used
|
||||
if ($_SESSION['config']->scriptServer && is_array($values->quota) && $uselamdaemon)
|
||||
setquotas(array($values),array($values_old));
|
||||
if ($_SESSION['config']->scriptServer && is_array($values->quota) && $uselamdaemon && ($values->quota != $values_old->quota))
|
||||
setquotas(array($values));
|
||||
//make required changes in cache-array
|
||||
if ((isset($_SESSION['userDN']))) {
|
||||
if ($values->general_dn != $values_old->general_dn) {
|
||||
|
@ -2246,6 +2257,13 @@ function modifygroup($values,$values_old, $uselamdaemon=true) {
|
|||
if (count($values->unix_memberUid)==0) $attr_rem['memberUid'] = $values_old->unix_memberUid;
|
||||
else $attr['memberUid'] = $values->unix_memberUid;
|
||||
}
|
||||
// Rewrite quotas if uidnumbers has changed
|
||||
if ($values->general_uidNumber != $values_old->general_uidNumber && $_SESSION['config']->scriptServer) {
|
||||
// Remove old quotas
|
||||
remquotas(array($values_old->general_username), "user");
|
||||
// Remove quotas from $values_old because we have to rewrite them all
|
||||
unset ($values_old->quota);
|
||||
}
|
||||
|
||||
if ($values->general_dn != $values_old->general_dn) {
|
||||
// Account should be moved to a new location
|
||||
|
@ -2302,7 +2320,8 @@ function modifygroup($values,$values_old, $uselamdaemon=true) {
|
|||
}
|
||||
|
||||
// Change quotas if quotas are set and lamdaemon.pl should be used
|
||||
if ($_SESSION['config']->scriptServer && is_array($values->quota) && $uselamdaemon) setquotas(array($values),array($values_old));
|
||||
if ($_SESSION['config']->scriptServer && is_array($values->quota) && $uselamdaemon && ($values->quota != $values_old->quota))
|
||||
setquotas(array($values));
|
||||
//make required changes in cache-array
|
||||
if ((isset($_SESSION['groupDN']))) {
|
||||
if ($values->general_dn != $values_old->general_dn) {
|
||||
|
|
|
@ -110,7 +110,12 @@ else if (count($_POST)==0) {
|
|||
else $j++;
|
||||
}
|
||||
// Beautify array, repair index
|
||||
$account_new->quota = array_values($account_new->quota);
|
||||
if (is_array($account_new->quota)) $account_new->quota = array_values($account_new->quota);
|
||||
// Set used blocks
|
||||
for ($i=0; $i<count($account_new->quota); $i++) {
|
||||
$account_new->quota[$i][1] = 0;
|
||||
$account_new->quota[$i][5] = 0;
|
||||
}
|
||||
}
|
||||
// Display general-page
|
||||
$select_local = 'general';
|
||||
|
@ -272,7 +277,7 @@ switch ($_POST['select']) {
|
|||
// 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
|
||||
$quotas = getquotas(array($account_old));
|
||||
$account_new = $quotas[0];
|
||||
$account_new->quota = $quotas[0]->quota;
|
||||
}
|
||||
// Create / display PDf-file
|
||||
createGroupPDF(array($account_new));
|
||||
|
@ -398,7 +403,22 @@ do { // X-Or, only one if() can be true
|
|||
else $j++;
|
||||
}
|
||||
// Beautify array, repair index
|
||||
$account_new->quota = array_values($account_new->quota);
|
||||
if (is_array($account_new->quota)) $account_new->quota = array_values($account_new->quota);
|
||||
// Set used blocks
|
||||
if (isset($account_old)) {
|
||||
for ($i=0; $i<count($account_new->quota); $i++)
|
||||
for ($j=0; $j<count($quotas[0]->quota); $j++)
|
||||
if ($quotas[0]->quota[$j][0] == $account_new->quota[$i][0]) {
|
||||
$account_new->quota[$i][1] = $quotas[0]->quota[$i][1];
|
||||
$account_new->quota[$i][4] = $quotas[0]->quota[$i][4];
|
||||
$account_new->quota[$i][5] = $quotas[0]->quota[$i][5];
|
||||
$account_new->quota[$i][8] = $quotas[0]->quota[$i][8];
|
||||
}
|
||||
}
|
||||
else for ($i=0; $i<count($account_new->quota); $i++) {
|
||||
$account_new->quota[$i][1] = 0;
|
||||
$account_new->quota[$i][5] = 0;
|
||||
}
|
||||
}
|
||||
// select general page after group has been loaded
|
||||
$select_local='general';
|
||||
|
@ -707,7 +727,7 @@ switch ($select_local) {
|
|||
// Load quotas if not yet done
|
||||
if ($config_intern->scriptServer && !isset($account_new->quota[0]) ) { // load quotas
|
||||
$quotas = getquotas(array($account_new));
|
||||
$account_new = $quotas[0];
|
||||
$account_new->quota = $quotas[0]->quota;
|
||||
}
|
||||
echo "<input name=\"select\" type=\"hidden\" value=\"samba\">\n";
|
||||
echo "<table border=0 width=\"100%\">\n<tr><td valign=\"top\" width=\"15%\" >";
|
||||
|
|
|
@ -81,7 +81,6 @@ if (isset($_GET['DN']) && $_GET['DN']!='') {
|
|||
$DN = str_replace("\'", '',$_GET['DN']);
|
||||
// Load existing group
|
||||
$account_new = loaduser($DN);
|
||||
$account_new ->type = 'user';
|
||||
$account_old = $account_new;
|
||||
$account_new->unix_password='';
|
||||
$account_new->smb_password='';
|
||||
|
@ -131,7 +130,12 @@ if (isset($_GET['DN']) && $_GET['DN']!='') {
|
|||
else $j++;
|
||||
}
|
||||
// Beautify array, repair index
|
||||
$account_new->quota = array_values($account_new->quota);
|
||||
if (is_array($account_new->quota)) $account_new->quota = array_values($account_new->quota);
|
||||
// Set used blocks
|
||||
for ($i=0; $i<count($account_new->quota); $i++) {
|
||||
$account_new->quota[$i][1] = 0;
|
||||
$account_new->quota[$i][5] = 0;
|
||||
}
|
||||
}
|
||||
// Display general-page
|
||||
$select_local = 'general';
|
||||
|
@ -506,8 +510,7 @@ switch ($_POST['select']) {
|
|||
// 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
|
||||
$quotas = getquotas(array($account_old));
|
||||
$account_new = $quotas[0];
|
||||
$account_new->quota = $account_old->quota;
|
||||
$account_new->quota = $quotas[0]->quota;
|
||||
}
|
||||
// Create / display PDf-file
|
||||
createUserPDF(array($account_new));
|
||||
|
@ -670,7 +673,8 @@ 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
|
||||
$quotas = getquotas(array($account_new));
|
||||
if (isset($account_old)) $quotas = getquotas(array($account_old));
|
||||
else $quotas = getquotas(array($account_new));
|
||||
for ($i=0; $i<count($account_new->quota); $i++) $profile_quotas[] = $account_new->quota[$i][0];
|
||||
for ($i=0; $i<count($quotas[0]->quota); $i++) {
|
||||
$real_quotas[] = $quotas[0]->quota[$i][0];
|
||||
|
@ -687,7 +691,22 @@ do { // X-Or, only one if() can be true
|
|||
else $j++;
|
||||
}
|
||||
// Beautify array, repair index
|
||||
$account_new->quota = array_values($account_new->quota);
|
||||
if (is_array($account_new->quota)) $account_new->quota = array_values($account_new->quota);
|
||||
// Set used blocks
|
||||
if (isset($account_old)) {
|
||||
for ($i=0; $i<count($account_new->quota); $i++)
|
||||
for ($j=0; $j<count($quotas[0]->quota); $j++)
|
||||
if ($quotas[0]->quota[$j][0] == $account_new->quota[$i][0]) {
|
||||
$account_new->quota[$i][1] = $quotas[0]->quota[$i][1];
|
||||
$account_new->quota[$i][4] = $quotas[0]->quota[$i][4];
|
||||
$account_new->quota[$i][5] = $quotas[0]->quota[$i][5];
|
||||
$account_new->quota[$i][8] = $quotas[0]->quota[$i][8];
|
||||
}
|
||||
}
|
||||
else for ($i=0; $i<count($account_new->quota); $i++) {
|
||||
$account_new->quota[$i][1] = 0;
|
||||
$account_new->quota[$i][5] = 0;
|
||||
}
|
||||
}
|
||||
// select general page after group has been loaded
|
||||
$select_local='general';
|
||||
|
@ -738,7 +757,6 @@ if (is_array($errors))
|
|||
//print_r($account_new);
|
||||
//print_r($account_old);
|
||||
|
||||
|
||||
switch ($select_local) {
|
||||
/* Select which part of page should be loaded and check values
|
||||
* groups = page with all groups to which user is additional member
|
||||
|
@ -1379,7 +1397,7 @@ switch ($select_local) {
|
|||
// Load quotas if not yet done
|
||||
if ($config_intern->scriptServer && !isset($account_new->quota[0])) { // load quotas
|
||||
$quotas = getquotas(array($account_old));
|
||||
$account_new = $quotas[0];
|
||||
$account_new->quota = $quotas[0]->quota;
|
||||
}
|
||||
echo "<input name=\"select\" type=\"hidden\" value=\"quota\">\n";
|
||||
echo "<table border=0 width=\"100%\">\n<tr><td valign=\"top\" width=\"15%\" >";
|
||||
|
|
|
@ -69,7 +69,6 @@ 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
|
||||
|
|
Loading…
Reference in New Issue