]> git.sur5r.net Git - bacula/bacula/commitdiff
baculum: Rework access by restricted consoles
authorMarcin Haba <marcin.haba@bacula.pl>
Sun, 27 Dec 2015 12:09:14 +0000 (13:09 +0100)
committerMarcin Haba <marcin.haba@bacula.pl>
Sun, 27 Dec 2015 12:11:15 +0000 (13:11 +0100)
26 files changed:
gui/baculum/protected/Class/API.php
gui/baculum/protected/Class/BaculumAPI.php
gui/baculum/protected/Class/BaculumUser.php
gui/baculum/protected/Class/BaculumUsersManager.php
gui/baculum/protected/Class/Bconsole.php
gui/baculum/protected/Class/ConfigurationManager.php
gui/baculum/protected/Class/JobManager.php
gui/baculum/protected/Init.php
gui/baculum/protected/Pages/API/Client.php
gui/baculum/protected/Pages/API/Clients.php
gui/baculum/protected/Pages/API/Directors.php
gui/baculum/protected/Pages/API/FileSet.php
gui/baculum/protected/Pages/API/FileSets.php
gui/baculum/protected/Pages/API/Job.php
gui/baculum/protected/Pages/API/JobShow.php
gui/baculum/protected/Pages/API/JobTasks.php
gui/baculum/protected/Pages/API/JobTotals.php
gui/baculum/protected/Pages/API/Jobs.php
gui/baculum/protected/Pages/API/Pool.php
gui/baculum/protected/Pages/API/Pools.php
gui/baculum/protected/Pages/API/Storage.php
gui/baculum/protected/Pages/API/Storages.php
gui/baculum/protected/Pages/Home.php
gui/baculum/protected/Pages/Monitor.php
gui/baculum/protected/Pages/RestoreWizard.php
gui/baculum/protected/Portlets/JobConfiguration.php

index d4071a07d2b59a59f43271fe00eef6d86636fcf3..9d109fbb4d575dc43506410b74ca43294fbbba93 100644 (file)
@@ -44,8 +44,14 @@ class API extends TModule {
                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) {
@@ -64,13 +70,6 @@ class API extends TModule {
 
        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__);
        }
 
@@ -91,7 +90,7 @@ class API extends TModule {
                        $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);
@@ -109,7 +108,7 @@ class API extends TModule {
                $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);
@@ -123,7 +122,7 @@ class API extends TModule {
                $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);
@@ -137,7 +136,7 @@ class API extends TModule {
                $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);
index 94236f66899ed0a3807fbc6288ec23ddc7c6713c..50d4526cfd904d158605580e38c4b12aca56d5e2 100644 (file)
@@ -49,15 +49,22 @@ abstract class BaculumAPI extends TPage
                $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']) {
index 9fe2ce578055b83636c93295eb25d849ad0923d1..4cf3a8eaa9425e5fc47bd44f2a0eb7c54af96767 100644 (file)
@@ -25,6 +25,7 @@ Prado::using('System.Security.TUser');
 class BaculumUser extends TUser {
 
        private $_id;
+       private $_pwd;
 
        public function getID() {
                return $this->_id;
@@ -34,8 +35,16 @@ class BaculumUser extends TUser {
                $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
+?>
index 154aaaeaef633060bbae912862a634edbd47f10a..f47e0b57e5c5715df378a71146a2b0d709097816 100644 (file)
@@ -26,9 +26,13 @@ Prado::using('Application.Class.BaculumUser');
 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() {
@@ -36,16 +40,24 @@ class BaculumUsersManager extends TModule implements IUserManager {
        }
 
        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');
@@ -60,5 +72,10 @@ class BaculumUsersManager extends TModule implements IUserManager {
        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
+?>
index 9dc27690df6c34fe47bc4016c90a85dff3dd0512..d16191e577563be1ae5a13ddea7a76729927555f 100644 (file)
@@ -77,7 +77,7 @@ class Bconsole extends TModule {
                        }
                }
                $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) {
index 8580daa875fee5578d549020885ea00628c00c56..7a711e98e0aea0425ea97c0329b252094e98a821 100644 (file)
@@ -143,6 +143,11 @@ class ConfigurationManager extends TModule
                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.
         *
@@ -161,37 +166,37 @@ class ConfigurationManager extends TModule
         * @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);
@@ -202,6 +207,21 @@ class ConfigurationManager extends TModule
                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.
         *
index cf53733d6b33eca9743999e6c8bfd67ce5761050..c2670edcfd98311c9bdc69325d1ed25598310210 100644 (file)
@@ -22,7 +22,7 @@
  
 class JobManager extends TModule {
 
-       public function getJobs($limit) {
+       public function getJobs($limit, $allowedJobs = array()) {
                $criteria = new TActiveRecordCriteria;
                $order = 'JobId';
                $cfg = $this->Application->getModule('configuration');
@@ -34,6 +34,19 @@ class JobManager extends TModule {
                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);
        }
 
@@ -72,11 +85,17 @@ class JobManager extends TModule {
                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();
index 01744022ea561cf8f3a288de1559f5ca050d275b..d3627030a2d937f071e731a3475a66ba56275f0b 100644 (file)
@@ -32,7 +32,7 @@ if (!ini_get('date.timezone')) {
 }
 
 // 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)));
 }
 
index cb689f1c03fc65a2e1d83ebb2fab31284fc15b6e..a2b17398e90c42dd0243855c06cc7171a6e703ce 100644 (file)
@@ -25,13 +25,18 @@ class Client extends BaculumAPI {
        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;
                }
        }
 
@@ -47,4 +52,4 @@ class Client extends BaculumAPI {
        }
 }
 
-?>
\ No newline at end of file
+?>
index 459a3d36b6532265912c732758d907c18a2867e2..ee8ff0aea82890a48f54c5eacb4a31a8700adf5c 100644 (file)
@@ -53,16 +53,22 @@ class Clients extends BaculumAPI {
        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
+?>
index 472c5abd275436ab87b4aa5fc6884f870b8ed9fe..c3ff0580e769787cc410faf69f1509d92dcc6719 100644 (file)
@@ -27,9 +27,9 @@ class Directors extends BaculumAPI {
                        $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
+?>
index bccfc81fced2743a5b5796e1d363213f156a3452..5e45738159e7b581af60af83550fc3d750812f6c 100644 (file)
@@ -24,15 +24,20 @@ class FileSet extends BaculumAPI {
        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
+?>
index b5275c140de0f57ad3b1bd532c8572fd66941c74..70271817946f5d0c6dd66e2a97ed7502a4a4df79 100644 (file)
@@ -25,21 +25,34 @@ class FileSets extends BaculumAPI {
                $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;
                }
        }
 }
index 0913200d42970a9c54b933b3e07d46b037c6de77..40d4f08ad0a924f7f71a9afa9b96f93ddf7c7d04 100644 (file)
@@ -24,13 +24,18 @@ class Job extends BaculumAPI {
        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;
                }
        }
 
@@ -48,4 +53,4 @@ class Job extends BaculumAPI {
        }
 }
 
-?>
\ No newline at end of file
+?>
index b378386f8b5d045e74fdf92ff29ab937993acff7..0e73f9922294200746adb69be4f9b9bd3490a59e 100644 (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;
                }
        }
 }
index 689a1d508a656a843e7f4e94f0022f4a80840ff5..75bbe02ee13edc15ba447bc8a872b2220910b07b 100644 (file)
@@ -26,19 +26,31 @@ class JobTasks extends BaculumAPI {
                $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;
                                                }
                                        }
@@ -48,13 +60,18 @@ class JobTasks extends BaculumAPI {
                                        }
                                }
                        }
-                       $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
+?>
index 18e04cac9eb598941a5a8c5ed914c9fbc56eb0cd..c7481fc33766be0e50bebe95f913a4010f58497f 100644 (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;
+               }
        }
 }
 ?>
index bc8b45ea0955423cc6fa3f23c6dccae370f34201..d9a45f58987687cb0ee48658f17a8f887b49c1ed 100644 (file)
 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;
+               }
        }
 }
 ?>
index 9e796e035e4b1606ae8db800a42a4c7f7d105ceb..4d9ba0adea35ad99cb1666629924feeca6e5c888 100644 (file)
@@ -24,13 +24,18 @@ class Pool extends BaculumAPI {
        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;
                }
        }
        
@@ -46,4 +51,4 @@ class Pool extends BaculumAPI {
        }
 }
 
-?>
\ No newline at end of file
+?>
index 7fecf7c494e234cb18f27a6b64632573b6ef3de9..21414f240d2cc6a66eb29cbe2707e588fdc34ccd 100644 (file)
@@ -24,15 +24,20 @@ class Pools extends BaculumAPI {
        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
+?>
index f9b81bf7db8ef00c568cb41bc4073d5ba570f5d5..bdd6c6e5f2eb375717ae540bb8aedcbf55b7d186 100644 (file)
@@ -24,15 +24,20 @@ class Storage extends BaculumAPI {
        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
+?>
index 12b4a682bfd8878150f1393dec4cd6cd5323aad7..4d1b3c263920446adf29e427c2cc9c071cf44815 100644 (file)
@@ -25,15 +25,20 @@ class Storages extends BaculumAPI {
        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;
        }
 }
 ?>
index c78c00b0eb736299e18e7548a71fa4f1e5c80a46..8de3dbc4ff44803480c34ce031138b2c76e99f7b 100644 (file)
@@ -44,6 +44,7 @@ class Home extends BaculumPage
 
        public function onInit($param) {
                parent::onInit($param);
+               $this->Application->getModule('users')->loginUser();
 
                if (!$this->IsPostBack && !$this->IsCallBack) {
                        $this->getModule('api')->initSessionCache(true);
@@ -57,6 +58,7 @@ class Home extends BaculumPage
                $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();
index e96009f1157c8ee4da7a85d3c8a570c6d7ca5bef..0fd4cf1b276c5ab9dfea9af8e2c9302e6280c553 100644 (file)
@@ -23,6 +23,8 @@
 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(),
index cae5afce5ff312836e8f9c4ccd6d948a6ba6571b..df595889fe8c3fafcb95733ed17075fc1b57ff1b 100644 (file)
@@ -47,6 +47,7 @@ class RestoreWizard extends BaculumPage
 
        public function onInit($param) {
                parent::onInit($param);
+               $this->Application->getModule('users')->loginUser();
                if(!$this->IsPostBack && !$this->IsCallBack) {
                        $this->setBrowserFiles(array());
                        $this->setFileVersions(array());
index 1c5ffcb08712f469d45e6d3ae8298f196a814615..2a852a61d3ded2682d4b97c0ba2f6229e02d9bb8 100644 (file)
@@ -183,9 +183,13 @@ class JobConfiguration extends Portlets {
                        $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;