From: Marcin Haba Date: Sun, 6 Aug 2017 07:19:32 +0000 (+0200) Subject: baculum: Add ability to assign host to specific user X-Git-Tag: Release-9.0.3~5 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=defcf9a3eb3c2655fef28380b34b1d2bded8a947;p=bacula%2Fbacula baculum: Add ability to assign host to specific user - Define api host for user - Fix users working in BWeb - Drop using user manager - Separate users code to new portlet --- diff --git a/gui/baculum/protected/API/Pages/API/Jobs.php b/gui/baculum/protected/API/Pages/API/Jobs.php index 942e70e53d..e7a7bb6b82 100644 --- a/gui/baculum/protected/API/Pages/API/Jobs.php +++ b/gui/baculum/protected/API/Pages/API/Jobs.php @@ -24,23 +24,16 @@ class Jobs extends BaculumAPIServer { public function get() { $limit = intval($this->Request['limit']); $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->exitcode; - } - } - - if ($error === false) { + $allowedJobs = $this->getModule('bconsole')->bconsoleCommand($this->director, array('.jobs'), $this->user); + if ($allowedJobs->exitcode === 0) { + array_shift($allowedJobs->output); + $allowed = $allowedJobs->output; $jobs = $this->getModule('job')->getJobs($limit, $allowed); $this->output = $jobs; $this->error = JobError::ERROR_NO_ERRORS; + } else { + $this->output = $allowedJobs->output; + $this->error = $allowedJobs->exitcode; } } } diff --git a/gui/baculum/protected/API/Pages/Panel/APIInstallWizard.php b/gui/baculum/protected/API/Pages/Panel/APIInstallWizard.php index c676fb68f4..5429682e6d 100644 --- a/gui/baculum/protected/API/Pages/Panel/APIInstallWizard.php +++ b/gui/baculum/protected/API/Pages/Panel/APIInstallWizard.php @@ -59,7 +59,7 @@ class APIInstallWizard extends BaculumAPIPage { $config = $this->getModule('api_config'); $this->config = $config->getConfig(); $this->first_run = (count($this->config) === 0); - if ($this->first_run === false && $this->User->getIsAdmin() === false) { + if ($this->first_run === false) { die('Access denied.'); } } diff --git a/gui/baculum/protected/API/Pages/config.xml b/gui/baculum/protected/API/Pages/config.xml index 3013ffcca8..60e712cc00 100644 --- a/gui/baculum/protected/API/Pages/config.xml +++ b/gui/baculum/protected/API/Pages/config.xml @@ -4,9 +4,6 @@ - - - diff --git a/gui/baculum/protected/Common/Class/BaculumUser.php b/gui/baculum/protected/Common/Class/BaculumUser.php deleted file mode 100644 index 320cbaf9e2..0000000000 --- a/gui/baculum/protected/Common/Class/BaculumUser.php +++ /dev/null @@ -1,45 +0,0 @@ -_id; - } - - public function setID($id) { - $this->_id = $id; - } - - public function getIsAdmin() { - return $this->isInRole('admin'); - } - - public function getIsUser() { - return $this->isInRole('user'); - } -} -?> diff --git a/gui/baculum/protected/Common/Class/BaculumUsersManager.php b/gui/baculum/protected/Common/Class/BaculumUsersManager.php deleted file mode 100644 index 7e5f655a99..0000000000 --- a/gui/baculum/protected/Common/Class/BaculumUsersManager.php +++ /dev/null @@ -1,106 +0,0 @@ - 'web_auth', - 'api_users' => 'api_auth' - ); - - public function getGuestName() { - return 'guest'; - } - - public function validateUser($username, $password) { - /* - * In Basic auth web server cares about access. - * For OAuth2 there will be separate module. - */ - $valid = true; - // @TOREMOVE - /*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); - $user->setIsGuest(false); - $id = sha1(time()); - $user->setID($id); - $user->setName($username); - // @TOFIX: Don't use web config values here - /*if(is_null($this->config) || $this->config['baculum']['login'] === $username) { - $user->setRoles('admin'); - } else { - $user->setRoles('user'); - }*/ - // @TODO: Set roles in Web part only for webGUI users. API will have own new auth method. - // Temporary set user to admin. - $user->setRoles('admin'); - return $user; - } - - public function getUserFromCookie($cookie) { - $data = $cookie->Value; - if (!empty($data)) { - $data = $this->Application->SecurityManager->validateData($data); - if ($data != false) { - $data = unserialize($data); - if (is_array($data) && count($data) === 3) { - list($username, $address, $token) = $data; - return $this->getUser($username); - } - } - } - } - - public function saveUserToCookie($cookie) { - $address = $this->Application->Request->UserHostAddress; - $username = $this->User->getName(); - $token = $this->User->getID(); - $data = array($username, $address, $token); - $data = serialize($data); - $data = $this->Application->SecurityManager->hashData($data); - $cookie->setValue($data); - } - - public function loginUser($user = null, $pwd = null) { - if (is_null($user) && is_null($pwd) && isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW'])) { - $user = $_SERVER['PHP_AUTH_USER']; - $pwd = $_SERVER['PHP_AUTH_PW']; - } - $auth = $this->auth_managers[$this->getID()]; - $logged = $this->Application->getModule($auth)->login($user, $pwd, 86400); - return $logged; - } -} -?> diff --git a/gui/baculum/protected/Web/Class/BaculumAPIClient.php b/gui/baculum/protected/Web/Class/BaculumAPIClient.php index d918aa1af1..6e7ce35bb3 100644 --- a/gui/baculum/protected/Web/Class/BaculumAPIClient.php +++ b/gui/baculum/protected/Web/Class/BaculumAPIClient.php @@ -259,7 +259,11 @@ class BaculumAPIClient extends WebModule { $cached = null; $ret = null; if (is_null($host)) { - $host = HostConfig::MAIN_CATALOG_HOST; + if (isset($_SESSION['api_host'])) { + $host = $_SESSION['api_host']; + } else { + $host = HostConfig::MAIN_CATALOG_HOST; + } } if ($use_cache === true) { $cached = $this->getSessionCache($host, $params); @@ -296,7 +300,11 @@ class BaculumAPIClient extends WebModule { */ public function set(array $params, array $options, $host = null, $show_error = true) { if (is_null($host)) { - $host = HostConfig::MAIN_CATALOG_HOST; + if (isset($_SESSION['api_host'])) { + $host = $_SESSION['api_host']; + } else { + $host = HostConfig::MAIN_CATALOG_HOST; + } } $host_cfg = $this->getHostParams($host); $uri = $this->getURIResource($host, $params); @@ -329,7 +337,11 @@ class BaculumAPIClient extends WebModule { */ public function create(array $params, array $options, $host = null, $show_error = true) { if (is_null($host)) { - $host = HostConfig::MAIN_CATALOG_HOST; + if (isset($_SESSION['api_host'])) { + $host = $_SESSION['api_host']; + } else { + $host = HostConfig::MAIN_CATALOG_HOST; + } } $host_cfg = $this->getHostParams($host); $uri = $this->getURIResource($host, $params); @@ -357,7 +369,11 @@ class BaculumAPIClient extends WebModule { */ public function remove(array $params, $host = null, $show_error = true) { if (is_null($host)) { - $host = HostConfig::MAIN_CATALOG_HOST; + if (isset($_SESSION['api_host'])) { + $host = $_SESSION['api_host']; + } else { + $host = HostConfig::MAIN_CATALOG_HOST; + } } $host_cfg = $this->getHostParams($host); $uri = $this->getURIResource($host, $params); diff --git a/gui/baculum/protected/Web/Class/BaculumWebPage.php b/gui/baculum/protected/Web/Class/BaculumWebPage.php index e98a7bf34f..ae2fdba191 100644 --- a/gui/baculum/protected/Web/Class/BaculumWebPage.php +++ b/gui/baculum/protected/Web/Class/BaculumWebPage.php @@ -20,6 +20,8 @@ * Bacula(R) is a registered trademark of Kern Sibbald. */ +session_start(); + Prado::using('Application.Common.Class.BaculumPage'); Prado::using('Application.Web.Class.WebConfig'); diff --git a/gui/baculum/protected/Web/JavaScript/misc.js b/gui/baculum/protected/Web/JavaScript/misc.js index b9b0db81f8..1327080579 100644 --- a/gui/baculum/protected/Web/JavaScript/misc.js +++ b/gui/baculum/protected/Web/JavaScript/misc.js @@ -233,8 +233,10 @@ var Dashboard = { document.getElementById(this.ids.jobtotals.total_files).textContent = this.stats.jobtotals.files || 0; }, update_database: function() { - document.getElementById(this.ids.database.type).textContent = this.dbtype[this.stats.dbsize.dbtype]; - document.getElementById(this.ids.database.size).textContent = Units.get_decimal_size(this.stats.dbsize.dbsize); + if (this.stats.dbsize.dbsize) { + document.getElementById(this.ids.database.type).textContent = this.dbtype[this.stats.dbsize.dbtype]; + document.getElementById(this.ids.database.size).textContent = Units.get_decimal_size(this.stats.dbsize.dbsize); + } }, update_pools: function() { var pools = this.stats.pools_occupancy; @@ -277,11 +279,15 @@ var Users = { change_pwd: { rel_chpwd: 'chpwd', rel_chpwd_btn: 'chpwd_btn' + }, + set_host: { + rel_user_host: 'user_host_img' } }, validators: { user_pattern: null }, + current_action: null, init: function() { this.setEvents(); }, @@ -365,6 +371,16 @@ var Users = { this.action_callback('chpwd', user, pwd); return true; }, + set_host: function(user, select) { + select.nextElementSibling.style.visibility = 'visible'; + this.action_callback('set_host', user, select.value); + }, + hide_loader: function() { + if (this.current_action === 'set_host') { + $('img[rel=\'' + this.ids.set_host.rel_user_host + '\']').css({visibility: 'hidden'}); + } + + }, cancelAddUser: function() { $('#' + this.ids.create_user.add_user).hide(); }, diff --git a/gui/baculum/protected/Web/JavaScript/slide-window.js b/gui/baculum/protected/Web/JavaScript/slide-window.js index c8dd15f208..ce24cf7fd0 100644 --- a/gui/baculum/protected/Web/JavaScript/slide-window.js +++ b/gui/baculum/protected/Web/JavaScript/slide-window.js @@ -292,7 +292,7 @@ var SlideWindowClass = jQuery.klass({ return; } set_callback_parameter(tr); - }.bind(tr)); + }); }.bind(this)); Formatters.set_formatters(); this.revertSortingFromCookie(); diff --git a/gui/baculum/protected/Web/Lang/en/messages.mo b/gui/baculum/protected/Web/Lang/en/messages.mo index 07248f9c71..639fe1df70 100644 Binary files a/gui/baculum/protected/Web/Lang/en/messages.mo and b/gui/baculum/protected/Web/Lang/en/messages.mo differ diff --git a/gui/baculum/protected/Web/Lang/en/messages.po b/gui/baculum/protected/Web/Lang/en/messages.po index 3e88541eb0..6eaba610f5 100644 --- a/gui/baculum/protected/Web/Lang/en/messages.po +++ b/gui/baculum/protected/Web/Lang/en/messages.po @@ -1408,3 +1408,12 @@ msgstr "OAuth2 Scope:" msgid "Restore job:" msgstr "Restore job:" + +msgid "API host" +msgstr "API host" + +msgid "API host:" +msgstr "API host:" + +msgid "Select host" +msgstr "Select host" diff --git a/gui/baculum/protected/Web/Lang/ja/messages.mo b/gui/baculum/protected/Web/Lang/ja/messages.mo index d1bf720ba3..db593bd790 100644 Binary files a/gui/baculum/protected/Web/Lang/ja/messages.mo and b/gui/baculum/protected/Web/Lang/ja/messages.mo differ diff --git a/gui/baculum/protected/Web/Lang/ja/messages.po b/gui/baculum/protected/Web/Lang/ja/messages.po index ed84f3abd9..b10f5213b5 100644 --- a/gui/baculum/protected/Web/Lang/ja/messages.po +++ b/gui/baculum/protected/Web/Lang/ja/messages.po @@ -1153,3 +1153,12 @@ msgstr "No jobs for the client." msgid "Restore job:" msgstr "Restore job:" + +msgid "API host" +msgstr "API host" + +msgid "API host:" +msgstr "API host:" + +msgid "Select host" +msgstr "Select host" diff --git a/gui/baculum/protected/Web/Lang/pl/messages.mo b/gui/baculum/protected/Web/Lang/pl/messages.mo index 2224193e68..1d429a4693 100644 Binary files a/gui/baculum/protected/Web/Lang/pl/messages.mo and b/gui/baculum/protected/Web/Lang/pl/messages.mo differ diff --git a/gui/baculum/protected/Web/Lang/pl/messages.po b/gui/baculum/protected/Web/Lang/pl/messages.po index 602a85d865..14934474c6 100644 --- a/gui/baculum/protected/Web/Lang/pl/messages.po +++ b/gui/baculum/protected/Web/Lang/pl/messages.po @@ -1409,3 +1409,12 @@ msgstr "Zakresy OAuth2:" msgid "Restore job:" msgstr "Zadanie przywracania:" + +msgid "API host" +msgstr "API host" + +msgid "API host:" +msgstr "API host:" + +msgid "Select host" +msgstr "Wybierz host" diff --git a/gui/baculum/protected/Web/Lang/pt/messages.mo b/gui/baculum/protected/Web/Lang/pt/messages.mo index 52783a3f0f..682a3dca96 100644 Binary files a/gui/baculum/protected/Web/Lang/pt/messages.mo and b/gui/baculum/protected/Web/Lang/pt/messages.mo differ diff --git a/gui/baculum/protected/Web/Lang/pt/messages.po b/gui/baculum/protected/Web/Lang/pt/messages.po index a20c093b02..32450403ac 100644 --- a/gui/baculum/protected/Web/Lang/pt/messages.po +++ b/gui/baculum/protected/Web/Lang/pt/messages.po @@ -1408,3 +1408,12 @@ msgstr "OAuth2 Scope:" msgid "Restore job:" msgstr "Restore job:" + +msgid "API host" +msgstr "API host" + +msgid "API host:" +msgstr "API host:" + +msgid "Select host" +msgstr "Select host" diff --git a/gui/baculum/protected/Web/Pages/Monitor.php b/gui/baculum/protected/Web/Pages/Monitor.php index 6f1b7ba6f6..15852b55f0 100644 --- a/gui/baculum/protected/Web/Pages/Monitor.php +++ b/gui/baculum/protected/Web/Pages/Monitor.php @@ -25,7 +25,6 @@ Prado::using('Application.Web.Class.BaculumWebPage'); class Monitor extends BaculumWebPage { public function onInit($param) { parent::onInit($param); - $this->Application->getModule('web_users')->loginUser(); $_SESSION['monitor_data'] = array( 'jobs' => array(), @@ -40,7 +39,7 @@ class Monitor extends BaculumWebPage { $_SESSION['monitor_data']['clients'] = $this->getModule('api')->get(array('clients'))->output; $_SESSION['monitor_data']['pools'] = $this->getModule('api')->get(array('pools'))->output; $_SESSION['monitor_data']['jobtotals'] = $this->getModule('api')->get(array('jobs', 'totals'))->output; - if ($this->User->getIsAdmin() === true) { + if ($_SESSION['admin']) { $_SESSION['monitor_data']['dbsize'] = $this->getModule('api')->get(array('dbsize'))->output; } diff --git a/gui/baculum/protected/Web/Pages/RestoreWizard.php b/gui/baculum/protected/Web/Pages/RestoreWizard.php index b9c8637b7f..f395a7812b 100644 --- a/gui/baculum/protected/Web/Pages/RestoreWizard.php +++ b/gui/baculum/protected/Web/Pages/RestoreWizard.php @@ -47,11 +47,6 @@ class RestoreWizard extends BaculumWebPage const BVFS_PATH_PREFIX = 'b2'; - public function onPreInit($param) { - parent::onPreInit($param); - $this->Application->getModule('web_users')->loginUser(); - } - public function onInit($param) { parent::onInit($param); if(!$this->IsPostBack && !$this->IsCallBack) { diff --git a/gui/baculum/protected/Web/Pages/WebConfigWizard.php b/gui/baculum/protected/Web/Pages/WebConfigWizard.php index e1c042ee0b..2450e99670 100644 --- a/gui/baculum/protected/Web/Pages/WebConfigWizard.php +++ b/gui/baculum/protected/Web/Pages/WebConfigWizard.php @@ -40,7 +40,7 @@ class WebConfigWizard extends BaculumWebPage $this->web_config = $config->getConfig(); $this->host_config = $this->getModule('host_config')->getConfig(); $this->first_run = (count($this->host_config) == 0); - if($this->first_run === false && $this->User->getIsAdmin() === false) { + if($this->first_run === false && !$_SESSION['admin']) { die('Access denied.'); } } @@ -119,11 +119,19 @@ class WebConfigWizard extends BaculumWebPage $host_config[$host] = $cfg_host; $ret = $this->getModule('host_config')->setConfig($host_config); if($ret === true) { - $cfg_web = array('baculum' => array()); + $web_config = $this->getModule('web_config')->getConfig(); + $cfg_web = array('baculum' => array(), 'users' => array()); + if (count($web_config) > 0) { + $cfg_web = $web_config; + } $cfg_web['baculum']['login'] = $this->WebLogin->Text; $cfg_web['baculum']['password'] = $this->WebPassword->Text; $cfg_web['baculum']['debug'] = 0; $cfg_web['baculum']['lang'] = 'en'; + if (array_key_exists('users', $cfg_web) && array_key_exists($this->WebLogin->Text, $cfg_web)) { + // Admin shoudn't be added to users section, only regular users + unset($cfg_web['users'][$this->WebLogin->Text]); + } $ret = $this->getModule('web_config')->setConfig($cfg_web); if($ret && $this->getModule('basic_webuser')->isUsersConfig() === true) { $previous_user = !$this->first_run ? $this->web_config['baculum']['login'] : null; diff --git a/gui/baculum/protected/Web/Pages/WebHome.page b/gui/baculum/protected/Web/Pages/WebHome.page index d2b8c60fb3..59200bd757 100644 --- a/gui/baculum/protected/Web/Pages/WebHome.page +++ b/gui/baculum/protected/Web/Pages/WebHome.page @@ -12,9 +12,9 @@ - User->getIsAdmin() === false ? ' style="display: none;"' : ''%>/> + /> - + /> @@ -52,7 +52,7 @@

<%[ Most often used: ]%>

<%[ Execution count most used: ]%> <%[ times ]%>

-
User->getIsAdmin() === false ? ' style="display: none;"' : ''%>> + -
User->getIsAdmin() === false ? ' style="display: none;"' : ''%>> + @@ -293,78 +293,12 @@
<%[ clear bvfs cache ]%> <%[ Enable debug ]%> - User->getIsAdmin() === false ? ' style="display: none;"' : ''%>><%[ volumes tools ]%><%[ volumes tools ]%> + <%[ Bacula console ]%><%[ show console ]%> @@ -373,12 +307,12 @@ diff --git a/gui/baculum/themes/Baculum-v1/style.css b/gui/baculum/themes/Baculum-v1/style.css index d31c15b6cd..49badceabc 100644 --- a/gui/baculum/themes/Baculum-v1/style.css +++ b/gui/baculum/themes/Baculum-v1/style.css @@ -968,6 +968,7 @@ span.tab_active { height: 9px; margin: 0 4px; font-size: 10px; + vertical-align: super; } #graphs span { @@ -1104,7 +1105,7 @@ span.config_test_loader, span.config_test_result { } #users_list { - width: 720px; + width: 890px; font-size: 13px; } @@ -1123,14 +1124,15 @@ span.config_test_loader, span.config_test_result { #users_list td:nth-of-type(1) { width: 200px; + text-align: center; } -i#users_list td:nth-of-type(1) { - width: 120px; +#users_list td:nth-of-type(3) { + text-align: center; } -#users_list td:nth-of-type(3) { - width: 400px; +#users_list td:nth-of-type(4) { + width: 340px; } #users_list img {