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.
*
*/
function initQuotas() {
if (isset($this->quota)) return;
@ -519,6 +518,7 @@ class quota extends baseModule {
$optionsAvailable = false;
// get list of lamdaemon servers
$lamdaemonServers = explode(";", $_SESSION['config']->get_scriptServers());
try {
for ($s = 0; $s < sizeof($lamdaemonServers); $s++) {
$temp = explode(":", $lamdaemonServers[$s]);
$server = $temp[0];
@ -586,6 +586,11 @@ class quota extends baseModule {
$return->addNewLine();
}
}
}
catch (LAMException $e) {
$return->addElement(new htmlStatusMessage('WARN', $e->getTitle()));
return $return;
}
if (!$optionsAvailable) {
return null;
}
@ -640,7 +645,12 @@ class quota extends baseModule {
* @param array $profile hash array with profile values (identifier => value)
*/
function load_profile($profile) {
try {
$this->initQuotas();
}
catch (LAMException $e) {
logNewMessage(LOG_ERR, $e->getTitle(), $e->getMessage());
}
if (!isset($this->quota) || !is_array($this->quota)) return;
$servers = array_keys($this->quota);
for ($s = 0; $s < sizeof($servers); $s++) {

View File

@ -1,6 +1,6 @@
<?php
namespace LAM\REMOTE;
use \Exception;
use \LAMException;
use \phpseclib\Net\SSH2;
use \phpseclib\Crypt\RSA;
/*
@ -78,7 +78,7 @@ class Remote {
$handle = @new SSH2($server);
}
if (!$handle) {
throw new Exception(_("Unable to connect to remote server!"));
throw new LAMException(_("Unable to connect to remote server!"));
}
$this->loginSSH($handle);
$this->server = $handle;
@ -111,7 +111,7 @@ class Remote {
$username = $entry[0]['uid'][0];
}
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];
@ -119,7 +119,7 @@ class Remote {
if (!empty($keyPath)) {
// use key authentication
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);
$rsa = new RSA();
@ -128,13 +128,13 @@ class Remote {
$rsa->setPassword($keyPassword);
}
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;
}
$login = @$handle->login($username, $password);
if (!$login) {
throw new Exception(_("Unable to login to remote server!"));
throw new LAMException(_("Unable to login to remote server!"));
}
}