diff --git a/lam/HISTORY b/lam/HISTORY index 5b172506..5f3f5e36 100644 --- a/lam/HISTORY +++ b/lam/HISTORY @@ -1,6 +1,7 @@ December 2017 - PHP 5.6 and Internet Explorer 11 or later required - Account status also shows expired accounts + - Quota: support k/m/g/t/K/M/G/T to specify values in e.g. kB 19.09.2017 6.1 diff --git a/lam/lib/account.inc b/lam/lib/account.inc index 4487030f..72c72252 100644 --- a/lam/lib/account.inc +++ b/lam/lib/account.inc @@ -583,6 +583,9 @@ function get_preg($argument, $regexp) { case 'objectClass': $pregexpr = '/^[[:alnum:]_-]+$/'; break; + case 'quotaNumber': + $pregexpr = '/^[[:digit:]]+[KMGTkmgt]?$/'; + break; } if ($pregexpr!='') if (preg_match($pregexpr, $argument)) { diff --git a/lam/lib/modules/quota.inc b/lam/lib/modules/quota.inc index f8d5d405..8b9cdc17 100644 --- a/lam/lib/modules/quota.inc +++ b/lam/lib/modules/quota.inc @@ -280,8 +280,11 @@ class quota extends baseModule { $i=0; $quotastring = ""; for ($i = 0; $i < sizeof($this->quota[$server]); $i++) { - $quotastring = $quotastring . $this->quota[$server][$i][0] . ',' . $this->quota[$server][$i][2] . ',' . $this->quota[$server][$i][3] - . ',' . $this->quota[$server][$i][6] . ',' . $this->quota[$server][$i][7] . ':'; + $quotastring .= $this->quota[$server][$i][0]; + $quotastring .= ',' . $this->getQuotaNumber($this->quota[$server][$i][2]); + $quotastring .= ',' . $this->getQuotaNumber($this->quota[$server][$i][3]); + $quotastring .= ',' . $this->getQuotaNumber($this->quota[$server][$i][6]); + $quotastring .= ',' . $this->getQuotaNumber($this->quota[$server][$i][7]) . ':'; } $remote = new \LAM\REMOTE\Remote(); $remote->connect($server); @@ -291,6 +294,43 @@ class quota extends baseModule { return $messages; } + /** + * Returns the quota value as plain number. + * + * @param string $quotaInput quota value (might contain e.g. "K" for KB) + * @return int quota number + */ + private function getQuotaNumber($quotaInput) { + if (empty($quotaInput) || (strlen($quotaInput) < 2)) { + return $quotaInput; + } + if (substr($quotaInput, -1, 1) === 'K') { + return 1024 * substr($quotaInput, 0, -1); + } + if (substr($quotaInput, -1, 1) === 'M') { + return 1024 * 1024 * substr($quotaInput, 0, -1); + } + if (substr($quotaInput, -1, 1) === 'G') { + return 1024 * 1024 * 1024 * substr($quotaInput, 0, -1); + } + if (substr($quotaInput, -1, 1) === 'T') { + return 1024 * 1024 * 1024 * 1024 * substr($quotaInput, 0, -1); + } + if (substr($quotaInput, -1, 1) === 'k') { + return 1000 * substr($quotaInput, 0, -1); + } + if (substr($quotaInput, -1, 1) === 'm') { + return 1000 * 1000 * substr($quotaInput, 0, -1); + } + if (substr($quotaInput, -1, 1) === 'g') { + return 1000 * 1000 * 1000 * substr($quotaInput, 0, -1); + } + if (substr($quotaInput, -1, 1) === 't') { + return 1000 * 1000 * 1000 * 1000 * substr($quotaInput, 0, -1); + } + return $quotaInput; + } + /** * Allows the module to run commands before the LDAP entry is deleted. * @@ -363,13 +403,13 @@ class quota extends baseModule { $this->quota[$server][$i][6] = $_POST[$i . '_6_' . $id]; $this->quota[$server][$i][7] = $_POST[$i . '_7_' . $id]; // Check if values are OK and set automatic values. if not error-variable will be set - if (!get_preg($this->quota[$server][$i][2], 'digit')) + if (!get_preg($this->quota[$server][$i][2], 'quotaNumber')) $errors[] = $this->messages['softblock'][0]; - if (!get_preg($this->quota[$server][$i][3], 'digit')) + if (!get_preg($this->quota[$server][$i][3], 'quotaNumber')) $errors[] = $this->messages['hardblock'][0]; - if (!get_preg($this->quota[$server][$i][6], 'digit')) + if (!get_preg($this->quota[$server][$i][6], 'quotaNumber')) $errors[] = $this->messages['softinode'][0]; - if (!get_preg($this->quota[$server][$i][7], 'digit')) + if (!get_preg($this->quota[$server][$i][7], 'quotaNumber')) $errors[] = $this->messages['hardinode'][0]; if (intval($this->quota[$server][$i][2]) > intval($this->quota[$server][$i][3])) $errors[] = $this->messages['block_cmp'][0]; @@ -437,24 +477,20 @@ class quota extends baseModule { $sbLimitInput = new htmlInputField($i . '_2_' . $id, $this->quota[$server][$i][2]); $sbLimitInput->setFieldSize(12); $sbLimitInput->setFieldMaxLength(20); - $sbLimitInput->setValidationRule(htmlElement::VALIDATE_NUMERIC); $return->addElement($sbLimitInput); $hbLimit = new htmlInputField($i . '_3_' . $id, $this->quota[$server][$i][3]); $hbLimit->setFieldSize(12); $hbLimit->setFieldMaxLength(20); - $hbLimit->setValidationRule(htmlElement::VALIDATE_NUMERIC); $return->addElement($hbLimit); $return->addElement(new htmlOutputText($this->quota[$server][$i][4])); $return->addElement(new htmlOutputText($this->quota[$server][$i][5])); $siLimit = new htmlInputField($i . '_6_' . $id, $this->quota[$server][$i][6]); $siLimit->setFieldMaxLength(20); $siLimit->setFieldSize(12); - $siLimit->setValidationRule(htmlElement::VALIDATE_NUMERIC); $return->addElement($siLimit); $hiLimit = new htmlInputField($i . '_7_' . $id, $this->quota[$server][$i][7]); $hiLimit->setFieldMaxLength(20); $hiLimit->setFieldSize(12); - $hiLimit->setValidationRule(htmlElement::VALIDATE_NUMERIC); $return->addElement($hiLimit); $return->addElement(new htmlOutputText($this->quota[$server][$i][8])); $return->addNewLine(); @@ -749,25 +785,25 @@ class quota extends baseModule { $errors[] = $errMsg; continue; } - if (!get_preg($parts[0], 'digit')) { + if (!get_preg($parts[0], 'quotaNumber')) { $errMsg = $this->messages['softblock'][1]; array_push($errMsg, array($i, 'quota_' . $temp['quotas'][$m])); $errors[] = $errMsg; continue; } - if (!get_preg($parts[1], 'digit')) { + if (!get_preg($parts[1], 'quotaNumber')) { $errMsg = $this->messages['hardblock'][1]; array_push($errMsg, array($i, 'quota_' . $temp['quotas'][$m])); $errors[] = $errMsg; continue; } - if (!get_preg($parts[2], 'digit')) { + if (!get_preg($parts[2], 'quotaNumber')) { $errMsg = $this->messages['softinode'][1]; array_push($errMsg, array($i, 'quota_' . $temp['quotas'][$m])); $errors[] = $errMsg; continue; } - if (!get_preg($parts[3], 'digit')) { + if (!get_preg($parts[3], 'quotaNumber')) { $errMsg = $this->messages['hardinode'][1]; array_push($errMsg, array($i, 'quota_' . $temp['quotas'][$m])); $errors[] = $errMsg; @@ -785,6 +821,10 @@ class quota extends baseModule { $errors[] = $errMsg; continue; } + $parts[0] = $this->getQuotaNumber($parts[0]); + $parts[1] = $this->getQuotaNumber($parts[1]); + $parts[2] = $this->getQuotaNumber($parts[2]); + $parts[3] = $this->getQuotaNumber($parts[3]); // save quota settings $temp['accounts'][$name][$temp['quotas'][$m]] = $parts; } diff --git a/lam/lib/modules/systemQuotas.inc b/lam/lib/modules/systemQuotas.inc index d62e21db..5bb2b68e 100644 --- a/lam/lib/modules/systemQuotas.inc +++ b/lam/lib/modules/systemQuotas.inc @@ -140,19 +140,15 @@ class systemQuotas extends baseModule { $container->addElement(new htmlInputField('path_' . $i, $parts[0], 20)); $container->addElement($spacer); $softBlockInput = new htmlInputField('softBlock_' . $i, $parts[1], 10); - $softBlockInput->setValidationRule(htmlElement::VALIDATE_NUMERIC); $container->addElement($softBlockInput); $container->addElement($spacer); $hardBlockInput = new htmlInputField('hardBlock_' . $i, $parts[2], 10); - $hardBlockInput->setValidationRule(htmlElement::VALIDATE_NUMERIC); $container->addElement($hardBlockInput); $container->addElement($spacer); $softInodeInput = new htmlInputField('softInode_' . $i, $parts[3], 10); - $softInodeInput->setValidationRule(htmlElement::VALIDATE_NUMERIC); $container->addElement($softInodeInput); $container->addElement($spacer); $hardInodeInput = new htmlInputField('hardInode_' . $i, $parts[4], 10); - $hardInodeInput->setValidationRule(htmlElement::VALIDATE_NUMERIC); $container->addElement($hardInodeInput); $container->addElement(new htmlButton('del_' . $i, 'del.png', true), true); } @@ -161,19 +157,15 @@ class systemQuotas extends baseModule { $container->addElement(new htmlInputField('path', null, 20)); $container->addElement($spacer); $newSoftBlockInput = new htmlInputField('softBlock', 0, 10); - $newSoftBlockInput->setValidationRule(htmlElement::VALIDATE_NUMERIC); $container->addElement($newSoftBlockInput); $container->addElement($spacer); $newHardBlockInput = new htmlInputField('hardBlock', 0, 10); - $newHardBlockInput->setValidationRule(htmlElement::VALIDATE_NUMERIC); $container->addElement($newHardBlockInput); $container->addElement($spacer); $newSoftInodeInput = new htmlInputField('softInode', 0, 10); - $newSoftInodeInput->setValidationRule(htmlElement::VALIDATE_NUMERIC); $container->addElement($newSoftInodeInput); $container->addElement($spacer); $newHardInodeInput = new htmlInputField('hardInode', 0, 10); - $newHardInodeInput->setValidationRule(htmlElement::VALIDATE_NUMERIC); $container->addElement($newHardInodeInput); $container->addElement(new htmlButton('add', 'add.png', true)); return $container; @@ -253,7 +245,7 @@ class systemQuotas extends baseModule { $return[] = $error; } } - if (!get_preg($softBlock, 'digit')) { + if (!get_preg($softBlock, 'quotaNumber')) { if ($uploadIndex == null) { $return[] = $this->messages['softblock'][0]; } @@ -263,7 +255,7 @@ class systemQuotas extends baseModule { $return[] = $error; } } - if (!get_preg($hardBlock, 'digit')) { + if (!get_preg($hardBlock, 'quotaNumber')) { if ($uploadIndex == null) { $return[] = $this->messages['hardblock'][0]; } @@ -273,7 +265,7 @@ class systemQuotas extends baseModule { $return[] = $error; } } - if (!get_preg($softInode, 'digit')) { + if (!get_preg($softInode, 'quotaNumber')) { if ($uploadIndex == null) { $return[] = $this->messages['softinode'][0]; } @@ -283,7 +275,7 @@ class systemQuotas extends baseModule { $return[] = $error; } } - if (!get_preg($hardInode, 'digit')) { + if (!get_preg($hardInode, 'quotaNumber')) { if ($uploadIndex == null) { $return[] = $this->messages['hardinode'][0]; }