error handling

This commit is contained in:
Roland Gruber 2017-12-13 10:59:38 +01:00
parent 3eaeaa6c30
commit b541460231
2 changed files with 80 additions and 70 deletions

View File

@ -165,7 +165,6 @@ class quota extends baseModule {
/** /**
* Initializes the quota values. * Initializes the quota values.
*
*/ */
function initQuotas() { function initQuotas() {
if (isset($this->quota)) return; if (isset($this->quota)) return;
@ -519,73 +518,79 @@ class quota extends baseModule {
$optionsAvailable = false; $optionsAvailable = false;
// get list of lamdaemon servers // get list of lamdaemon servers
$lamdaemonServers = explode(";", $_SESSION['config']->get_scriptServers()); $lamdaemonServers = explode(";", $_SESSION['config']->get_scriptServers());
for ($s = 0; $s < sizeof($lamdaemonServers); $s++) { try {
$temp = explode(":", $lamdaemonServers[$s]); for ($s = 0; $s < sizeof($lamdaemonServers); $s++) {
$server = $temp[0]; $temp = explode(":", $lamdaemonServers[$s]);
$id = $this->replaceSpecialChars($server); $server = $temp[0];
$description = $temp[0]; $id = $this->replaceSpecialChars($server);
if (isset($temp[1])) { $description = $temp[0];
$description = $temp[1] . ' (' . $temp[0] . ')'; if (isset($temp[1])) {
} $description = $temp[1] . ' (' . $temp[0] . ')';
// Get quotas }
$remote = new \LAM\REMOTE\Remote(); // Get quotas
$remote->connect($server); $remote = new \LAM\REMOTE\Remote();
$quotas = $remote->execute(implode(quota::$SPLIT_DELIMITER, array("+", "quota", "get", $this->get_scope()))); $remote->connect($server);
$remote->disconnect(); $quotas = $remote->execute(implode(quota::$SPLIT_DELIMITER, array("+", "quota", "get", $this->get_scope())));
if (empty($quotas)) { $remote->disconnect();
continue; if (empty($quotas)) {
}
$dirs = explode(":", $quotas);
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]);
$dirs = array_values($dirs);
$i--;
continue; continue;
} }
$dirs[$i] = substr($dirs[$i], strlen(quota::$QUOTA_PREFIX)); $dirs = explode(":", $quotas);
$dirs[$i] = explode(",", $dirs[$i]); array_pop($dirs); // remove empty element at the end
$dirs[$i] = $dirs[$i][0]; for ($i = 0; $i < sizeof($dirs); $i++) {
} if (strpos($dirs[$i], quota::$QUOTA_PREFIX) !== 0) {
$dirs = array_values($dirs); unset($dirs[$i]);
if (sizeof($dirs) < 1) continue; // stop if no quota directories were found $dirs = array_values($dirs);
$optionsAvailable = true; $i--;
$return->addElement(new htmlSubTitle($description), true); continue;
$return->addElement(new htmlOutputText('&nbsp;' . _('Mountpoint') . '&nbsp;', false)); }
$return->addElement(new htmlOutputText('&nbsp;' . _('Soft block limit') . '&nbsp;', false)); $dirs[$i] = substr($dirs[$i], strlen(quota::$QUOTA_PREFIX));
$return->addElement(new htmlOutputText('&nbsp;' . _('Hard block limit') . '&nbsp;', false)); $dirs[$i] = explode(",", $dirs[$i]);
$return->addElement(new htmlOutputText('&nbsp;' . _('Soft inode limit') . '&nbsp;', false)); $dirs[$i] = $dirs[$i][0];
$return->addElement(new htmlOutputText('&nbsp;' . _('Hard inode limit') . '&nbsp;', false)); }
$return->addNewLine(); $dirs = array_values($dirs);
$return->addElement(new htmlHelpLink('Mountpoint')); if (sizeof($dirs) < 1) continue; // stop if no quota directories were found
$return->addElement(new htmlHelpLink('SoftBlockLimit')); $optionsAvailable = true;
$return->addElement(new htmlHelpLink('HardBlockLimit')); $return->addElement(new htmlSubTitle($description), true);
$return->addElement(new htmlHelpLink('SoftInodeLimit')); $return->addElement(new htmlOutputText('&nbsp;' . _('Mountpoint') . '&nbsp;', false));
$return->addElement(new htmlHelpLink('HardInodeLimit')); $return->addElement(new htmlOutputText('&nbsp;' . _('Soft block limit') . '&nbsp;', false));
$return->addNewLine(); $return->addElement(new htmlOutputText('&nbsp;' . _('Hard block limit') . '&nbsp;', false));
$return->addElement(new htmlOutputText('&nbsp;' . _('Soft inode limit') . '&nbsp;', false));
for ($i = 0; $i < sizeof($dirs); $i++) { $return->addElement(new htmlOutputText('&nbsp;' . _('Hard inode limit') . '&nbsp;', false));
$return->addElement(new htmlOutputText($dirs[$i]));
$sbLimit = new htmlInputField("quota_softblock_" . $id . "_" . $dirs[$i]);
$sbLimit->setFieldSize(12);
$sbLimit->setFieldMaxLength(20);
$return->addElement($sbLimit);
$hbLimit = new htmlInputField("quota_hardblock_" . $id . "_" . $dirs[$i]);
$hbLimit->setFieldSize(12);
$hbLimit->setFieldMaxLength(20);
$return->addElement($hbLimit);
$siLimit = new htmlInputField("quota_softinode_" . $id . "_" . $dirs[$i]);
$siLimit->setFieldSize(12);
$siLimit->setFieldMaxLength(20);
$return->addElement($siLimit);
$hiLimit = new htmlInputField("quota_hardinode_" . $id . "_" . $dirs[$i]);
$hiLimit->setFieldSize(12);
$hiLimit->setFieldMaxLength(20);
$return->addElement($hiLimit);
$return->addNewLine(); $return->addNewLine();
$return->addElement(new htmlHelpLink('Mountpoint'));
$return->addElement(new htmlHelpLink('SoftBlockLimit'));
$return->addElement(new htmlHelpLink('HardBlockLimit'));
$return->addElement(new htmlHelpLink('SoftInodeLimit'));
$return->addElement(new htmlHelpLink('HardInodeLimit'));
$return->addNewLine();
for ($i = 0; $i < sizeof($dirs); $i++) {
$return->addElement(new htmlOutputText($dirs[$i]));
$sbLimit = new htmlInputField("quota_softblock_" . $id . "_" . $dirs[$i]);
$sbLimit->setFieldSize(12);
$sbLimit->setFieldMaxLength(20);
$return->addElement($sbLimit);
$hbLimit = new htmlInputField("quota_hardblock_" . $id . "_" . $dirs[$i]);
$hbLimit->setFieldSize(12);
$hbLimit->setFieldMaxLength(20);
$return->addElement($hbLimit);
$siLimit = new htmlInputField("quota_softinode_" . $id . "_" . $dirs[$i]);
$siLimit->setFieldSize(12);
$siLimit->setFieldMaxLength(20);
$return->addElement($siLimit);
$hiLimit = new htmlInputField("quota_hardinode_" . $id . "_" . $dirs[$i]);
$hiLimit->setFieldSize(12);
$hiLimit->setFieldMaxLength(20);
$return->addElement($hiLimit);
$return->addNewLine();
}
} }
} }
catch (LAMException $e) {
$return->addElement(new htmlStatusMessage('WARN', $e->getTitle()));
return $return;
}
if (!$optionsAvailable) { if (!$optionsAvailable) {
return null; return null;
} }
@ -640,7 +645,12 @@ class quota extends baseModule {
* @param array $profile hash array with profile values (identifier => value) * @param array $profile hash array with profile values (identifier => value)
*/ */
function load_profile($profile) { function load_profile($profile) {
$this->initQuotas(); try {
$this->initQuotas();
}
catch (LAMException $e) {
logNewMessage(LOG_ERR, $e->getTitle(), $e->getMessage());
}
if (!isset($this->quota) || !is_array($this->quota)) return; if (!isset($this->quota) || !is_array($this->quota)) return;
$servers = array_keys($this->quota); $servers = array_keys($this->quota);
for ($s = 0; $s < sizeof($servers); $s++) { for ($s = 0; $s < sizeof($servers); $s++) {

View File

@ -1,6 +1,6 @@
<?php <?php
namespace LAM\REMOTE; namespace LAM\REMOTE;
use \Exception; use \LAMException;
use \phpseclib\Net\SSH2; use \phpseclib\Net\SSH2;
use \phpseclib\Crypt\RSA; use \phpseclib\Crypt\RSA;
/* /*
@ -78,7 +78,7 @@ class Remote {
$handle = @new SSH2($server); $handle = @new SSH2($server);
} }
if (!$handle) { if (!$handle) {
throw new Exception(_("Unable to connect to remote server!")); throw new LAMException(_("Unable to connect to remote server!"));
} }
$this->loginSSH($handle); $this->loginSSH($handle);
$this->server = $handle; $this->server = $handle;
@ -111,7 +111,7 @@ class Remote {
$username = $entry[0]['uid'][0]; $username = $entry[0]['uid'][0];
} }
if (empty($username)) { if (empty($username)) {
throw new Exception(sprintf(_("Your LAM admin user (%s) must be a valid Unix account to work with lamdaemon!"), getAbstractDN($credentials[0]))); throw new LAMException(sprintf(_("Your LAM admin user (%s) must be a valid Unix account to work with lamdaemon!"), getAbstractDN($credentials[0])));
} }
} }
$password = $credentials[1]; $password = $credentials[1];
@ -119,7 +119,7 @@ class Remote {
if (!empty($keyPath)) { if (!empty($keyPath)) {
// use key authentication // use key authentication
if (!file_exists($keyPath) || !is_readable($keyPath)) { if (!file_exists($keyPath) || !is_readable($keyPath)) {
throw new Exception(sprintf(_("Unable to read %s."), htmlspecialchars($keyPath))); throw new LAMException(sprintf(_("Unable to read %s."), htmlspecialchars($keyPath)));
} }
$key = file_get_contents($keyPath); $key = file_get_contents($keyPath);
$rsa = new RSA(); $rsa = new RSA();
@ -128,13 +128,13 @@ class Remote {
$rsa->setPassword($keyPassword); $rsa->setPassword($keyPassword);
} }
if (!$rsa->loadKey($key)) { if (!$rsa->loadKey($key)) {
throw new Exception(sprintf(_("Unable to load key %s."), htmlspecialchars($keyPath))); throw new LAMException(sprintf(_("Unable to load key %s."), htmlspecialchars($keyPath)));
} }
$password = $rsa; $password = $rsa;
} }
$login = @$handle->login($username, $password); $login = @$handle->login($username, $password);
if (!$login) { if (!$login) {
throw new Exception(_("Unable to login to remote server!")); throw new LAMException(_("Unable to login to remote server!"));
} }
} }