return $ch;
}
- private function getAPIHeader() {
- return 'X-Baculum-API: ' . self::API_VERSION;
+ private function getAPIHeaders() {
+ $headers = array(
+ 'X-Baculum-API: ' . self::API_VERSION,
+ 'X-Baculum-User: ' . $this->Application->User->getName(),
+ 'X-Baculum-Pwd: ' . $this->Application->User->getPwd(),
+ 'Accept: application/json'
+ );
+ return $headers;
}
public function init($config) {
private function setParamsToUrl(&$url) {
$url .= (preg_match('/\?/', $url) === 1 ? '&' : '?' ) . 'director=' . ((array_key_exists('director', $_SESSION)) ? $_SESSION['director'] : '');
- /**
- * If user is not equal admin user then it is added to URL,
- * then will be used custom console for this user.
- */
- if($this->User->getIsAdmin() === false) {
- $url .= '&user=' . $this->User->getName();
- }
$this->Application->getModule('logging')->log(__FUNCTION__, PHP_EOL . PHP_EOL . 'EXECUTE URL ==> ' . $url . ' <==' . PHP_EOL . PHP_EOL, Logging::CATEGORY_APPLICATION, __FILE__, __LINE__);
}
$this->setParamsToUrl($url);
$ch = $this->getConnection();
curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_HTTPHEADER, array($this->getAPIHeader(), 'Accept: application/json'));
+ curl_setopt($ch, CURLOPT_HTTPHEADER, $this->getAPIHeaders());
$result = curl_exec($ch);
curl_close($ch);
$ret = $this->preParseOutput($result);
$ch = $this->getConnection();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
- curl_setopt($ch, CURLOPT_HTTPHEADER, array($this->getAPIHeader(), 'Accept: application/json', 'X-HTTP-Method-Override: PUT', 'Content-Length: ' . strlen($data), 'Expect:'));
+ curl_setopt($ch, CURLOPT_HTTPHEADER, array_merge($this->getAPIHeaders(), array('X-HTTP-Method-Override: PUT', 'Content-Length: ' . strlen($data), 'Expect:')));
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$result = curl_exec($ch);
$data = http_build_query(array('create' => $options));
$ch = $this->getConnection();
curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_HTTPHEADER, array($this->getAPIHeader(), 'Accept: application/json', 'Expect:'));
+ curl_setopt($ch, CURLOPT_HTTPHEADER, array_merge($this->getAPIHeaders(), array('Expect:')));
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$result = curl_exec($ch);
$ch = $this->getConnection();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE');
- curl_setopt($ch, CURLOPT_HTTPHEADER, array($this->getAPIHeader(), 'Accept: application/json', 'X-HTTP-Method-Override: DELETE'));
+ curl_setopt($ch, CURLOPT_HTTPHEADER, array_merge($this->getAPIHeaders(), array('X-HTTP-Method-Override: DELETE')));
$result = curl_exec($ch);
curl_close($ch);
return $this->preParseOutput($result);
$db = new ActiveRecord();
$db->getDbConnection();
$this->director = isset($this->Request['director']) ? $this->Request['director'] : null;
- $this->user = isset($this->Request['user']) ? $this->Request['user'] : null;
- if(is_null($this->user) && $this->Application->getModule('configuration')->isApplicationConfig() === true) {
- $appConfig = ConfigurationManager::getApplicationConfig();
- // @TOFIX: Baculum API layer should not use $_SERVER variables.
- if (isset($_SERVER['PHP_AUTH_USER'])) {
- // NOTE: With php-fpm $_SERVER['PHP_AUTH_USER'] value is empty string here
- $user = trim($_SERVER['PHP_AUTH_USER']);
- $this->user = (!empty($user) && $user != $appConfig['baculum']['login']) ? $user : null;
+
+ $user = isset($_SERVER['HTTP_X_BACULUM_USER']) ? $_SERVER['HTTP_X_BACULUM_USER']: null;
+ $pwd = isset($_SERVER['HTTP_X_BACULUM_PWD']) ? $_SERVER['HTTP_X_BACULUM_PWD']: null;
+ if(!is_null($user) && !is_null($pwd)) {
+ $logged = $this->Application->getModule('auth')->login($user, $pwd);
+ if ($logged === true) {
+ $this->user = ($this->User->getIsAdmin() === false) ? $user : null;
+ } else {
+ $this->output = AuthorizationError::MSG_ERROR_AUTHORIZATION_TO_WEBGUI_PROBLEM;
+ $this->error = AuthorizationError::ERROR_AUTHORIZATION_TO_WEBGUI_PROBLEM;
+ return;
}
+ } else {
+ $this->output = AuthorizationError::MSG_ERROR_AUTHORIZATION_TO_WEBGUI_PROBLEM;
+ $this->error = AuthorizationError::ERROR_AUTHORIZATION_TO_WEBGUI_PROBLEM;
+ return;
}
switch($_SERVER['REQUEST_METHOD']) {
class BaculumUser extends TUser {
private $_id;
+ private $_pwd;
public function getID() {
return $this->_id;
$this->_id = $id;
}
+ public function getPwd() {
+ return $this->_pwd;
+ }
+
+ public function setPwd($pwd) {
+ $this->_pwd = $pwd;
+ }
+
public function getIsAdmin() {
return $this->isInRole('admin');
}
}
-?>
\ No newline at end of file
+?>
class BaculumUsersManager extends TModule implements IUserManager {
private $config;
+ private $configMod;
+ private $users;
public function init($config) {
- $this->config = $this->Application->getModule('configuration')->isApplicationConfig() ? $this->Application->getModule('configuration')->getApplicationConfig() : null;
+ $this->configMod = $this->Application->getModule('configuration');
+ $this->config = $this->configMod->isApplicationConfig() ? $this->configMod->getApplicationConfig() : null;
+ $this->users = $this->configMod->getAllUsers();
}
public function getGuestName() {
}
public function validateUser($username, $password) {
- return !empty($username);
+ $valid = false;
+ if(!empty($username) && !empty($password)) {
+ $users = $this->configMod->getAllUsers();
+ $valid = (array_key_exists($username, $users) && $password === $users[$username]);
+ }
+ return $valid;
}
public function getUser($username = null) {
$user = new BaculumUser($this);
$id = sha1(time());
$user->setID($id);
- $user->setName($_SERVER['PHP_AUTH_USER']);
+ $user->setName($username);
$user->setIsGuest(false);
- if($this->config['baculum']['login'] == $_SERVER['PHP_AUTH_USER'] || is_null($this->config)) {
+ if ($username != null) {
+ $user->setPwd($this->users[$username]);
+ }
+ if(is_null($this->config) || $this->config['baculum']['login'] === $username) {
$user->setRoles('admin');
} else {
$user->setRoles('user');
public function saveUserToCookie($cookie) {
return;
}
+
+ public function loginUser() {
+ $enc_pwd = $this->Application->getModule('configuration')->getCryptedPassword($_SERVER['PHP_AUTH_PW']);
+ $logged = $this->Application->getModule('auth')->login($_SERVER['PHP_AUTH_USER'], $enc_pwd);
+ }
}
-?>
\ No newline at end of file
+?>
}
}
$output = count($output) > 1 ? array_values($output) : array_shift($output);
- return (object)array('output' => $output, 'exitcode' => $exitcode);
+ return (object)array('output' => $output, 'exitcode' => (integer)$exitcode);
}
public function bconsoleCommand($director, array $command, $user = null) {
return file_exists(Prado::getPathOfNamespace(self::CONFIG_FILE, '.conf'));
}
+ public function getCryptedPassword($password) {
+ $enc_pwd = crypt($password, base64_encode($password));
+ return $enc_pwd;
+ }
+
/**
* Saving user to users configuration file.
*
* @return boolean true if user saved successfully, otherwise false
*/
public function setUsersConfig($user, $password, $firstUsage = false, $oldUser = null) {
+ $allUsers = $this->getAllUsers();
$usersFile = Prado::getPathOfNamespace(self::USERS_FILE, '.users');
- $password = crypt($password, base64_encode($password));
+ $password = $this->getCryptedPassword($password);
+
if($firstUsage === true) {
$this->clearUsersConfig();
}
- $users = $this->isUsersConfig() === true ? file($usersFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES) : array();
- $userExists = false;
+ $userExists = array_key_exists($user, $allUsers);
- for($i = 0; $i < count($users); $i++) {
- // checking if user already exist in configuration file and if exist then update password
- if(preg_match("/^{$user}\:/", $users[$i]) === 1) {
- $users[$i] = "{$user}:{$password}";
- $userExists = true;
- break;
- }
+
+ if ($userExists === true) {
+ // update user password;
+ $allUsers[$user] = $password;
}
if(!is_null($oldUser) && $oldUser !== $user) {
// delete old username with password from configuration file
- for($j = 0; $j < count($users); $j++) {
- if(preg_match("/^{$oldUser}\:/", $users[$j]) === 1) {
- unset($users[$j]);
- break;
- }
+ if(array_key_exists($oldUser, $allUsers)) {
+ unset($allUsers[$oldUser]);
}
}
// add new user if does not exist
if($userExists === false) {
- array_push($users, "{$user}:{$password}");
+ $allUsers[$user] = $password;
+ }
+
+ $users = array();
+ foreach ($allUsers as $user => $pwd) {
+ $users[] = "$user:$pwd";
}
$usersToFile = implode("\n", $users);
return $result;
}
+ public function getAllUsers() {
+ $allUsers = array();
+ if ($this->isUsersConfig() === true) {
+ $usersFile = Prado::getPathOfNamespace(self::USERS_FILE, '.users');
+ $users = file($usersFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
+
+ for($i = 0; $i < count($users); $i++) {
+ if(preg_match("/^(?P<user>\S+)\:(?P<hash>\S+)$/", $users[$i], $match) === 1) {
+ $allUsers[$match['user']] = $match['hash'];
+ }
+ }
+ }
+ return $allUsers;
+ }
+
/**
* Checking if users configuration file exists.
*
class JobManager extends TModule {
- public function getJobs($limit) {
+ public function getJobs($limit, $allowedJobs = array()) {
$criteria = new TActiveRecordCriteria;
$order = 'JobId';
$cfg = $this->Application->getModule('configuration');
if(is_int($limit) && $limit > 0) {
$criteria->Limit = $limit;
}
+
+ if (count($allowedJobs) > 0) {
+ $where = array();
+ $names = array();
+ for ($i = 0; $i < count($allowedJobs); $i++) {
+ $where[] = "name = :name$i";
+ $names[":name$i"] = $allowedJobs[$i];
+ }
+ $criteria->Condition = implode(' OR ', $where);
+ foreach($names as $name => $jobname) {
+ $criteria->Parameters[$name] = $jobname;
+ }
+ }
return JobRecord::finder()->findAll($criteria);
}
return $jobids;
}
- public function getJobTotals() {
+ public function getJobTotals($allowedJobs = array()) {
$jobtotals = array('bytes' => 0, 'files' => 0);
$connection = JobRecord::finder()->getDbConnection();
$connection->setActive(true);
- $sql = "SELECT sum(JobFiles) AS files, sum(JobBytes) AS bytes FROM Job";
+
+ $where = '';
+ if (count($allowedJobs) > 0) {
+ $where = " WHERE name='" . implode("' OR name='", $allowedJobs) . "'";
+ }
+
+ $sql = "SELECT sum(JobFiles) AS files, sum(JobBytes) AS bytes FROM Job $where";
$pdo = $connection->getPdoInstance();
$result = $pdo->query($sql);
$ret = $result->fetch();
}
// Support for web servers which do not provide direct info about HTTP Basic auth to PHP superglobal $_SERVER array.
-if(!isset($_SERVER['PHP_AUTH_USER']) && !isset($_SERVER['PHP_AUTH_PW'])) {
+if(!isset($_SERVER['PHP_AUTH_USER']) && !isset($_SERVER['PHP_AUTH_PW']) && isset($_SERVER['HTTP_AUTHORIZATION'])) {
list($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']) = explode(':', base64_decode(substr($_SERVER['HTTP_AUTHORIZATION'], 6)));
}
public function get() {
$clientid = intval($this->Request['id']);
$client = $this->getModule('client')->getClientById($clientid);
- $allowedClients = $this->getModule('bconsole')->bconsoleCommand($this->director, array('.client'), $this->user)->output;
- if(!is_null($client) && in_array($client->name, $allowedClients)) {
- $this->output = $client;
- $this->error = ClientError::ERROR_NO_ERRORS;
+ $allowedClients = $this->getModule('bconsole')->bconsoleCommand($this->director, array('.client'), $this->user);
+ if ($allowedClients->exitcode === 0) {
+ if(!is_null($client) && in_array($client->name, $allowedClients->output)) {
+ $this->output = $client;
+ $this->error = ClientError::ERROR_NO_ERRORS;
+ } else {
+ $this->output = ClientError::MSG_ERROR_CLIENT_DOES_NOT_EXISTS;
+ $this->error =ClientError::ERROR_CLIENT_DOES_NOT_EXISTS;
+ }
} else {
- $this->output = ClientError::MSG_ERROR_CLIENT_DOES_NOT_EXISTS;
- $this->error =ClientError::ERROR_CLIENT_DOES_NOT_EXISTS;
+ $this->output = $allowedClients->output;
+ $this->error = $allowedClients->exitcode;
}
}
}
}
-?>
\ No newline at end of file
+?>
public function get() {
$limit = intval($this->Request['limit']);
$clients = $this->getModule('client')->getClients($limit);
- $allowedClients = $this->getModule('bconsole')->bconsoleCommand($this->director, array('.client'), $this->user)->output;
- $clientsOutput = array();
- foreach($clients as $client) {
- if(in_array($client->name, $allowedClients)) {
- $clientsOutput[] = $client;
+ $allowedClients = $this->getModule('bconsole')->bconsoleCommand($this->director, array('.client'), $this->user);
+ if ($allowedClients->exitcode === 0) {
+ $clientsOutput = array();
+ foreach($clients as $client) {
+ if(in_array($client->name, $allowedClients->output)) {
+ $clientsOutput[] = $client;
+ }
}
+ $this->output = $clientsOutput;
+ $this->error = ClientError::ERROR_NO_ERRORS;
+ } else {
+
+ $this->output = $allowedClients->output;
+ $this->error = $allowedClients->exitcode;
}
- $this->output = $clientsOutput;
- $this->error = ClientError::ERROR_NO_ERRORS;
}
}
-?>
\ No newline at end of file
+?>
$this->output = $directors->output;
$this->error = BconsoleError::ERROR_NO_ERRORS;
} else {
- $this->output = BconsoleError::MSG_ERROR_BCONSOLE_CONNECTION_PROBLEM;
- $this->error = BconsoleError::ERROR_BCONSOLE_CONNECTION_PROBLEM;
+ $this->output = $directors->output;
+ $this->error = $directors->exitcode;
}
}
}
-?>
\ No newline at end of file
+?>
public function get() {
$filesetid = intval($this->Request['id']);
$fileset = $this->getModule('fileset')->getFileSetById($filesetid);
- $allowedFileSets = $this->getModule('bconsole')->bconsoleCommand($this->director, array('.fileset'), $this->user)->output;
- if(!is_null($fileset) && in_array($fileset->fileset, $allowedFileSets)) {
- $this->output = $fileset;
- $this->error = FileSetError::ERROR_NO_ERRORS;
+ $allowedFileSets = $this->getModule('bconsole')->bconsoleCommand($this->director, array('.fileset'), $this->user);
+ if ($allowedFileSets->exitcode === 0) {
+ if(!is_null($fileset) && in_array($fileset->fileset, $allowedFileSets->output)) {
+ $this->output = $fileset;
+ $this->error = FileSetError::ERROR_NO_ERRORS;
+ } else {
+ $this->output = FileSetError::MSG_ERROR_FILESET_DOES_NOT_EXISTS;
+ $this->error = FileSetError::ERROR_FILESET_DOES_NOT_EXISTS;
+ }
} else {
- $this->output = FileSetError::MSG_ERROR_FILESET_DOES_NOT_EXISTS;
- $this->error = FileSetError::ERROR_FILESET_DOES_NOT_EXISTS;
+ $this->output = $allowedFileSets->output;
+ $this->error = $allowedFileSets->exitcode;
}
}
}
-?>
\ No newline at end of file
+?>
$directors = $this->getModule('bconsole')->getDirectors();
if($directors->exitcode === 0) {
$filesets = array();
+ $error = false;
+ $error_obj = null;
for($i = 0; $i < count($directors->output); $i++) {
- $filesetsshow = $this->getModule('bconsole')->bconsoleCommand($directors->output[$i], array('show', 'fileset'), $this->user)->output;
+ $filesetsshow = $this->getModule('bconsole')->bconsoleCommand($directors->output[$i], array('show', 'fileset'), $this->user);
+ if ($filesetsshow->exitcode != 0) {
+ $error_obj = $filesetsshow;
+ $error = true;
+ break;
+ }
$filesets[$directors->output[$i]] = array();
- for($j = 0; $j < count($filesetsshow); $j++) {
- if(preg_match('/^FileSet:\ name=(.*)$/', $filesetsshow[$j], $match) === 1) {
+ for($j = 0; $j < count($filesetsshow->output); $j++) {
+ if(preg_match('/^FileSet:\ name=(.*)$/', $filesetsshow->output[$j], $match) === 1) {
$filesets[$directors->output[$i]][] = $match[1];
}
}
}
- $this->output = $filesets;
- $this->error = BconsoleError::ERROR_NO_ERRORS;
+
+ if ($error === true) {
+ $this->output = $error_obj->output;
+ $this->error = $error_obj->exitcode;
+ } else {
+ $this->output = $filesets;
+ $this->error = BconsoleError::ERROR_NO_ERRORS;
+ }
} else {
- $this->output = BconsoleError::MSG_ERROR_BCONSOLE_CONNECTION_PROBLEM;
- $this->error = BconsoleError::ERROR_BCONSOLE_CONNECTION_PROBLEM;
+ $this->output = $directors->output;
+ $this->error = $directors->exitcode;
}
}
}
public function get() {
$jobid = intval($this->Request['id']);
$job = $this->getModule('job')->getJobById($jobid);
- $allowedJobs = $this->getModule('bconsole')->bconsoleCommand($this->director, array('.jobs'), $this->user)->output;
- if(!is_null($job) && in_array($job->name, $allowedJobs)) {
- $this->output = $job;
- $this->error = JobError::ERROR_NO_ERRORS;
+ $allowedJobs = $this->getModule('bconsole')->bconsoleCommand($this->director, array('.jobs'), $this->user);
+ if ($allowedJobs->exitcode === 0) {
+ if(!is_null($job) && in_array($job->name, $allowedJobs->output)) {
+ $this->output = $job;
+ $this->error = JobError::ERROR_NO_ERRORS;
+ } else {
+ $this->output = JobError::MSG_ERROR_JOB_DOES_NOT_EXISTS;
+ $this->error = JobError::ERROR_JOB_DOES_NOT_EXISTS;
+ }
} else {
- $this->output = JobError::MSG_ERROR_JOB_DOES_NOT_EXISTS;
- $this->error = JobError::ERROR_JOB_DOES_NOT_EXISTS;
+ $this->output = $allowedJobs->output;
+ $this->error = $allowedJobs->exitcode;
}
}
}
}
-?>
\ No newline at end of file
+?>
class JobShow extends BaculumAPI {
public function get() {
$jobname = null;
+ $error = false;
+ $error_obj = null;
if (isset($this->Request['id'])) {
$jobid = intval($this->Request['id']);
$job = $this->getModule('job')->getJobById($jobid);
$jobname = property_exists($job, 'name') ? $job->name : null;
} elseif (isset($this->Request['name'])) {
- $allowedJobs = $this->getModule('bconsole')->bconsoleCommand($this->director, array('.jobs'), $this->user)->output;
- $jobname = in_array($this->Request['name'], $allowedJobs) ? $this->Request['name'] : null;
+ $allowedJobs = $this->getModule('bconsole')->bconsoleCommand($this->director, array('.jobs'), $this->user);
+ if ($allowedJobs->exitcode === 0) {
+ $jobname = in_array($this->Request['name'], $allowedJobs->output) ? $this->Request['name'] : null;
+ } else {
+ $error_obj = $allowedJobs;
+ $error = true;
+ }
}
- if(!is_null($jobname)) {
- $jobShow = $this->getModule('bconsole')->bconsoleCommand($this->director, array('show', 'job="' . $jobname . '"'), $this->user);
- $this->output = $jobShow->output;
- $this->error = (integer)$jobShow->exitcode;
+ if ($error === false) {
+ if(!is_null($jobname)) {
+ $jobShow = $this->getModule('bconsole')->bconsoleCommand($this->director, array('show', 'job="' . $jobname . '"'), $this->user);
+ $this->output = $jobShow->output;
+ $this->error = (integer)$jobShow->exitcode;
+ } else {
+ $this->output = JobError::MSG_ERROR_JOB_DOES_NOT_EXISTS;
+ $this->error = JobError::ERROR_JOB_DOES_NOT_EXISTS;
+ }
} else {
- $this->output = JobError::MSG_ERROR_JOB_DOES_NOT_EXISTS;
- $this->error = JobError::ERROR_JOB_DOES_NOT_EXISTS;
+ $this->output = $error_obj->output;
+ $this->error = $error_obj->exitcode;
}
}
}
$directors = $this->getModule('bconsole')->getDirectors();
if($directors->exitcode === 0) {
$jobs = array();
+ $error = false;
+ $error_obj = null;
for($i = 0; $i < count($directors->output); $i++) {
- $jobsList = $this->getModule('bconsole')->bconsoleCommand($directors->output[$i], array('.jobs'), $this->user)->output;
- $jobsshow = $this->getModule('bconsole')->bconsoleCommand($directors->output[$i], array('show', 'jobs'), $this->user)->output;
+ $jobsList = $this->getModule('bconsole')->bconsoleCommand($directors->output[$i], array('.jobs'), $this->user);
+ if ($jobsList->exitcode != 0) {
+ $error_obj = $jobsList;
+ $error = true;
+ break;
+ }
+ $jobsshow = $this->getModule('bconsole')->bconsoleCommand($directors->output[$i], array('show', 'jobs'), $this->user);
+ if ($jobsshow->exitcode != 0) {
+ $error_obj = $jobsshow;
+ $error = true;
+ break;
+ }
$jobs[$directors->output[$i]] = array();
- for($j = 0; $j < count($jobsList); $j++) {
+ for($j = 0; $j < count($jobsList->output); $j++) {
/**
* Checking by "show job" command is ugly way to be sure that is reading jobname but not some
* random output (eg. "You have messages." or debugging).
* For now I did not find nothing better for be sure that output contains job.
*/
- for($k = 0; $k < count($jobsshow); $k++) {
- if(preg_match('/^Job: name=' . $jobsList[$j] . '.*/', $jobsshow[$k]) === 1) {
- $jobs[$directors->output[$i]][] = $jobsList[$j];
+ for($k = 0; $k < count($jobsshow->output); $k++) {
+ if(preg_match('/^Job: name=' . $jobsList->output[$j] . '.*/', $jobsshow->output[$k]) === 1) {
+ $jobs[$directors->output[$i]][] = $jobsList->output[$j];
break;
}
}
}
}
}
- $this->output = $jobs;
- $this->error = BconsoleError::ERROR_NO_ERRORS;
+ if ($error === true) {
+ $this->output = $error_obj->output;
+ $this->error = $error_obj->exitcode;
+ } else {
+ $this->output = $jobs;
+ $this->error = BconsoleError::ERROR_NO_ERRORS;
+ }
} else {
- $this->output = BconsoleError::MSG_ERROR_BCONSOLE_CONNECTION_PROBLEM;
- $this->error = BconsoleError::ERROR_BCONSOLE_CONNECTION_PROBLEM;
+ $this->output = $directors->output;
+ $this->error = $directors->exitcode;
}
}
}
-?>
\ No newline at end of file
+?>
class JobTotals extends BaculumAPI {
public function get() {
- $jobtotals = $this->getModule('job')->getJobTotals();
- $this->output = $jobtotals;
- $this->error = JobError::ERROR_NO_ERRORS;
+ $error = false;
+ $allowed = array();
+ if (!is_null($this->user)) {
+ $allowedJobs = $this->getModule('bconsole')->bconsoleCommand($this->director, array('.jobs'), $this->user);
+ if ($allowedJobs->exitcode === 0) {
+ array_shift($allowedJobs->output);
+ $allowed = $allowedJobs->output;
+ } else {
+ $error = true;
+ $this->output = $allowedJobs->output;
+ $this->error = $allowedJobs->error;
+ }
+ }
+
+ if ($error === false) {
+ $jobtotals = $this->getModule('job')->getJobTotals($allowed);
+ $this->output = $jobtotals;
+ $this->error = JobError::ERROR_NO_ERRORS;
+ }
}
}
?>
class Jobs extends BaculumAPI {
public function get() {
$limit = intval($this->Request['limit']);
- $jobs = $this->getModule('job')->getJobs($limit);
- $this->output = $jobs;
- $this->error = JobError::ERROR_NO_ERRORS;
+ $allowed = array();
+ $error = false;
+ if (!is_null($this->user)) {
+ $allowedJobs = $this->getModule('bconsole')->bconsoleCommand($this->director, array('.jobs'), $this->user);
+ if ($allowedJobs->exitcode === 0) {
+ array_shift($allowedJobs->output);
+ $allowed = $allowedJobs->output;
+ } else {
+ $error = true;
+ $this->output = $allowedJobs->output;
+ $this->error = $allowedJobs->error;
+ }
+ }
+
+ if ($error === false) {
+ $jobs = $this->getModule('job')->getJobs($limit, $allowed);
+ $this->output = $jobs;
+ $this->error = JobError::ERROR_NO_ERRORS;
+ }
}
}
?>
public function get() {
$poolid = intval($this->Request['id']);
$pool = $this->getModule('pool')->getPoolById($poolid);
- $allowedPools = $this->getModule('bconsole')->bconsoleCommand($this->director, array('.pool'), $this->user)->output;
- if(!is_null($pool) && in_array($pool->name, $allowedPools)) {
- $this->output = $pool;
- $this->error = PoolError::ERROR_NO_ERRORS;
+ $allowedPools = $this->getModule('bconsole')->bconsoleCommand($this->director, array('.pool'), $this->user);
+ if ($allowedPools->exitcode === 0) {
+ if(!is_null($pool) && in_array($pool->name, $allowedPools->output)) {
+ $this->output = $pool;
+ $this->error = PoolError::ERROR_NO_ERRORS;
+ } else {
+ $this->output = PoolError::MSG_ERROR_POOL_DOES_NOT_EXISTS;
+ $this->error = PoolError::ERROR_POOL_DOES_NOT_EXISTS;
+ }
} else {
- $this->output = PoolError::MSG_ERROR_POOL_DOES_NOT_EXISTS;
- $this->error = PoolError::ERROR_POOL_DOES_NOT_EXISTS;
+ $this->output = $allowedPools->output;
+ $this->error = $allowedPools->exitcode;
}
}
}
}
-?>
\ No newline at end of file
+?>
public function get() {
$limit = intval($this->Request['limit']);
$pools = $this->getModule('pool')->getPools($limit);
- $allowedPools = $this->getModule('bconsole')->bconsoleCommand($this->director, array('.pool'), $this->user)->output;
- $poolsOutput = array();
- foreach($pools as $pool) {
- if(in_array($pool->name, $allowedPools)) {
- $poolsOutput[] = $pool;
+ $allowedPools = $this->getModule('bconsole')->bconsoleCommand($this->director, array('.pool'), $this->user);
+ if ($allowedPools->exitcode === 0) {
+ $poolsOutput = array();
+ foreach($pools as $pool) {
+ if(in_array($pool->name, $allowedPools->output)) {
+ $poolsOutput[] = $pool;
+ }
}
+ $this->output = $poolsOutput;
+ $this->error = PoolError::ERROR_NO_ERRORS;
+ } else {
+ $this->output = $allowedPools->output;
+ $this->error = $allowedPools->exitcode;
}
- $this->output = $poolsOutput;
- $this->error = PoolError::ERROR_NO_ERRORS;
}
}
-?>
\ No newline at end of file
+?>
public function get() {
$storageid = intval($this->Request['id']);
$storage = $this->getModule('storage')->getStorageById($storageid);
- $allowedStorages = $this->getModule('bconsole')->bconsoleCommand($this->director, array('.storage'), $this->user)->output;
- if(!is_null($storage) && in_array($storage->name, $allowedStorages)) {
- $this->output = $storage;
- $this->error = StorageError::ERROR_NO_ERRORS;
+ $allowedStorages = $this->getModule('bconsole')->bconsoleCommand($this->director, array('.storage'), $this->user);
+ if ($allowedStorages->exitcode === 0) {
+ if(!is_null($storage) && in_array($storage->name, $allowedStorages->output)) {
+ $this->output = $storage;
+ $this->error = StorageError::ERROR_NO_ERRORS;
+ } else {
+ $this->output = StorageError::MSG_ERROR_STORAGE_DOES_NOT_EXISTS;
+ $this->error = StorageError::ERROR_STORAGE_DOES_NOT_EXISTS;
+ }
} else {
- $this->output = StorageError::MSG_ERROR_STORAGE_DOES_NOT_EXISTS;
- $this->error = StorageError::ERROR_STORAGE_DOES_NOT_EXISTS;
+ $this->output = $allowedStorages->output;
+ $this->error = $allowedStorages->exitcode;
}
}
}
-?>
\ No newline at end of file
+?>
public function get() {
$limit = intval($this->Request['limit']);
$storages = $this->getModule('storage')->getStorages($limit);
- $allowedStorages = $this->getModule('bconsole')->bconsoleCommand($this->director, array('.storage'), $this->user)->output;
- $storagesOutput = array();
- foreach($storages as $storage) {
- if(in_array($storage->name, $allowedStorages)) {
- $storagesOutput[] = $storage;
+ $allowedStorages = $this->getModule('bconsole')->bconsoleCommand($this->director, array('.storage'), $this->user);
+ if ($allowedStorages->exitcode === 0) {
+ $storagesOutput = array();
+ foreach($storages as $storage) {
+ if(in_array($storage->name, $allowedStorages->output)) {
+ $storagesOutput[] = $storage;
+ }
}
+ $this->output = $storagesOutput;
+ $this->error = StorageError::ERROR_NO_ERRORS;
+ } else {
+ $this->output = $allowedStorages->output;
+ $this->error = $allowedStorages->exitcode;
}
- $this->output = $storagesOutput;
- $this->error = StorageError::ERROR_NO_ERRORS;
}
}
?>
public function onInit($param) {
parent::onInit($param);
+ $this->Application->getModule('users')->loginUser();
if (!$this->IsPostBack && !$this->IsCallBack) {
$this->getModule('api')->initSessionCache(true);
$appConfig = $this->getModule('configuration')->getApplicationConfig();
$this->SettingsWizardBtn->Visible = $this->User->getIsAdmin();
+ $this->PoolBtn->Visible = $this->User->getIsAdmin();
$this->VolumeBtn->Visible = $this->User->getIsAdmin();
$this->ClearBvfsCache->Visible = $this->User->getIsAdmin();
$this->Logging->Visible = $this->User->getIsAdmin();
class Monitor extends BaculumPage {
public function onInit($param) {
parent::onInit($param);
+ $this->Application->getModule('users')->loginUser();
+
$_SESSION['monitor_data'] = array(
'jobs' => array(),
'running_jobs' => array(),
public function onInit($param) {
parent::onInit($param);
+ $this->Application->getModule('users')->loginUser();
if(!$this->IsPostBack && !$this->IsCallBack) {
$this->setBrowserFiles(array());
$this->setFileVersions(array());
$params['fileset'] = $this->getResourceName('fileset', $jobshow);
$params['clientid'] = $jobdata->clientid;
$storage = $this->getResourceName('storage', $jobshow);
- $params['storageid'] = $this->getStorageByName($storage)->storageid;
+ if (is_object($storage)) {
+ $params['storageid'] = $this->getStorageByName($storage)->storageid;
+ }
$pool = $this->getResourceName('pool', $jobshow);
- $params['poolid'] = $this->getPoolByName($pool)->poolid;
+ if (is_object($pool)) {
+ $params['poolid'] = $this->getPoolByName($pool)->poolid;
+ }
} else {
$params['id'] = $this->JobID->Text;
$params['level'] = $this->Level->SelectedValue;