';
}
return array('quota_quotas' => $quotas);
}
else {
return array();
}
}
/**
* Returns an array containing all input columns for the file upload.
*
* Syntax:
* array(
* string: name, // fixed non-translated name which is used as column name (should be of format: _)
* string: description, // short descriptive name
* string: help, // help ID
* string: example, // example value
* boolean: required // true, if user must set a value for this column
* )
*
* @param array $selectedModules list of selected account modules
* @return array column list
*/
function get_uploadColumns($selectedModules) {
$this->initQuotas();
if (!isset($this->quota) || !is_array($this->quota)) return array();
$return = array();
if (sizeof($this->quota) > 0) {
// get list of lamdaemon servers
$lamdaemonServers = explode(";", $_SESSION['config']->get_scriptServers());
for ($s = 0; $s < sizeof($lamdaemonServers); $s++) {
$temp = explode(":", $lamdaemonServers[$s]);
$server = $temp[0];
// Get quotas
$quotas = lamdaemon(implode(quota::$SPLIT_DELIMITER, array("+", "quota", "get", $this->get_scope())), $server);
$dirs = explode(":", $quotas[0]);
array_pop($dirs); // remove empty element at the end
for ($i = 0; $i < sizeof($dirs); $i++) {
if (strpos($dirs[$i], quota::$QUOTA_PREFIX) !== 0) {
unset($dirs[$i]);
$i--;
continue;
}
$dirs[$i] = substr($dirs[$i], strlen(quota::$QUOTA_PREFIX));
$dirs[$i] = explode(",", $dirs[$i]);
$dirs[$i] = $dirs[$i][0];
}
$dirs = array_values($dirs);
for ($i = 0; $i < sizeof($dirs); $i++) {
$return[] = array(
'name' => 'quota_' . $server . ':' . $dirs[$i],
'description' => sprintf(_('Quota for %s on %s'), $dirs[$i], $server),
'help' => 'upload',
'example' => '2000,2500,3000,3500');
}
}
}
return $return;
}
/**
* This function executes one post upload action.
*
* @param array $data array containing one account in each element
* @param array $ids array( => )
* @param array $failed list of accounts which were not created successfully
* @param array $temp variable to store temporary data between two post actions
* @param array $accounts list of LDAP entries
* @return array current status
* array (
* 'status' => 'finished' | 'inProgress'
* 'progress' => 0..100
* 'errors' => array ()
* )
*/
function doUploadPostActions(&$data, $ids, $failed, &$temp, &$accounts) {
$errors = array();
// first call, get list of user names and quota values
if (!isset($temp['counter'])) {
$temp['counter'] = 0;
// create list of quota columns
$temp['quotas'] = array();
$columns = array_keys($ids);
for ($i = 0; $i < sizeof($columns); $i++) {
if (strpos($columns[$i], 'quota_') === 0) {
$temp['quotas'][] = substr($columns[$i], 6);
}
}
// select user/group name depending on current scope
$temp['accounts'] = array();
$col = 'invalid';
if ($this->get_scope() == 'user') $col = $ids['posixAccount_userName'];
elseif ($this->get_scope() == 'group') $col = $ids['posixGroup_cn'];
// create list of account names and their quota values
for ($i = 0; $i < sizeof($data); $i++) {
if (in_array($i, $failed)) continue; // ignore failed accounts
$name = $data[$i][$col];
for ($m = 0; $m < sizeof($temp['quotas']); $m++) {
if ($data[$i][$ids['quota_' . $temp['quotas'][$m]]] != '') {
$parts = explode(',', $data[$i][$ids['quota_' . $temp['quotas'][$m]]]);
// check syntax
if (sizeof($parts) != 4) {
$errMsg = $this->messages['upload'][0];
array_push($errMsg, array($i, 'quota_' . $temp['quotas'][$m]));
$errors[] = $errMsg;
continue;
}
if (!get_preg($parts[0], 'digit')) {
$errMsg = $this->messages['softblock'][1];
array_push($errMsg, array($i, 'quota_' . $temp['quotas'][$m]));
$errors[] = $errMsg;
continue;
}
if (!get_preg($parts[1], 'digit')) {
$errMsg = $this->messages['hardblock'][1];
array_push($errMsg, array($i, 'quota_' . $temp['quotas'][$m]));
$errors[] = $errMsg;
continue;
}
if (!get_preg($parts[2], 'digit')) {
$errMsg = $this->messages['softinode'][1];
array_push($errMsg, array($i, 'quota_' . $temp['quotas'][$m]));
$errors[] = $errMsg;
continue;
}
if (!get_preg($parts[3], 'digit')) {
$errMsg = $this->messages['hardinode'][1];
array_push($errMsg, array($i, 'quota_' . $temp['quotas'][$m]));
$errors[] = $errMsg;
continue;
}
if ($parts[0] > $parts[1]) {
$errMsg = $this->messages['block_cmp'][1];
array_push($errMsg, array($i, 'quota_' . $temp['quotas'][$m]));
$errors[] = $errMsg;
continue;
}
if ($parts[2] > $parts[3]) {
$errMsg = $this->messages['inode_cmp'][1];
array_push($errMsg, array($i, 'quota_' . $temp['quotas'][$m]));
$errors[] = $errMsg;
continue;
}
// save quota settings
$temp['accounts'][$name][$temp['quotas'][$m]] = $parts;
}
}
}
return array('status' => 'inProgress', 'progress' => 5, 'errors' => $errors);
}
// quotas are ready to set
elseif ($temp['counter'] < sizeof($temp['accounts'])) {
$names = array_keys($temp['accounts']);
$name = $names[$temp['counter']];
$mountPoints = array_keys($temp['accounts'][$name]);
// set quota
for ($m = 0; $m < sizeof($mountPoints); $m++) {
$mpParts = explode(":", $mountPoints[$m]);
$server = $mpParts[0];
$dir = $mpParts[1];
$quotaString = implode(quota::$SPLIT_DELIMITER, array($name, "quota", "set", $this->get_scope(), $dir . ',' .
implode(',', $temp['accounts'][$name][$mountPoints[$m]]) . "\n"));
$result = lamdaemon($quotaString, $server);
if (is_array($result)) {
for ($i = 0; $i < sizeof($result); $i++) {
$parts = explode(",", $result);
if ($parts[0] == 'ERROR') {
$errors[] = array('ERROR', $parts[1], $parts[2]);
}
}
}
}
// set counters to next account/mount point
$temp['counter']++;
return array(
'status' => 'inProgress',
'progress' => 5 + (95 * ($temp['counter'] / sizeof($temp['accounts']))),
'errors' => $errors);
}
return array('status' => 'finished');
}
/**
* Returns a list of modifications which have to be made to the LDAP account.
*
* Calling this method requires the existence of an enclosing {@link accountContainer}.
*
*
* This function returns an array with 3 entries:
* array( DN1 ('add' => array($attr), 'remove' => array($attr), 'modify' => array($attr)), DN2 .... )
* DN is the DN to change. It is possible to change several DNs (e.g. create a new user and add him
* to some groups via attribute memberUid)
* "add" are attributes which have to be added to the LDAP entry
* "remove" are attributes which have to be removed from the LDAP entry
* "modify" are attributes which have to be modified in the LDAP entry
* "notchanged" are attributes which stay unchanged
* "info" values with informational value (e.g. to be used later by pre/postModify actions)
*
* This builds the required comands from $this-attributes and $this->orig.
*
* @return array list of modifications
*/
public function save_attributes() {
// no LDAP changes
return $this->getAccountContainer()->save_module_attributes(array(), array());
}
}
?>