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;
}
}
}
$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.');
}
}
<using namespace="Application.API.Class.BaculumAPIServer" />
</paths>
<modules>
- <!-- API auth modules (@TODO: change auth method for API to more secure) -->
- <module id="api_users" class="Application.Common.Class.BaculumUsersManager" />
- <module id="api_auth" class="System.Security.TAuthManager" UserManager="api_users" AllowAutoLogin="true" AuthExpire="864000" />
<!-- database modules -->
<module id="db" class="Application.API.Class.Database" />
<module id="client" class="Application.API.Class.ClientManager" />
+++ /dev/null
-<?php
-/*
- * Bacula(R) - The Network Backup Solution
- * Baculum - Bacula web interface
- *
- * Copyright (C) 2013-2016 Kern Sibbald
- *
- * The main author of Baculum is Marcin Haba.
- * The original author of Bacula is Kern Sibbald, with contributions
- * from many others, a complete list can be found in the file AUTHORS.
- *
- * You may use this file and others of this release according to the
- * license defined in the LICENSE file, which includes the Affero General
- * Public License, v3.0 ("AGPLv3") and some additional permissions and
- * terms pursuant to its AGPLv3 Section 7.
- *
- * This notice must be preserved when any source code is
- * conveyed and/or propagated.
- *
- * Bacula(R) is a registered trademark of Kern Sibbald.
- */
-
-Prado::using('System.Security.TUser');
-
-class BaculumUser extends TUser implements IUser {
-
- private $_id;
-
- public function getID() {
- return $this->_id;
- }
-
- public function setID($id) {
- $this->_id = $id;
- }
-
- public function getIsAdmin() {
- return $this->isInRole('admin');
- }
-
- public function getIsUser() {
- return $this->isInRole('user');
- }
-}
-?>
+++ /dev/null
-<?php
-/*
- * Bacula(R) - The Network Backup Solution
- * Baculum - Bacula web interface
- *
- * Copyright (C) 2013-2016 Kern Sibbald
- *
- * The main author of Baculum is Marcin Haba.
- * The original author of Bacula is Kern Sibbald, with contributions
- * from many others, a complete list can be found in the file AUTHORS.
- *
- * You may use this file and others of this release according to the
- * license defined in the LICENSE file, which includes the Affero General
- * Public License, v3.0 ("AGPLv3") and some additional permissions and
- * terms pursuant to its AGPLv3 Section 7.
- *
- * This notice must be preserved when any source code is
- * conveyed and/or propagated.
- *
- * Bacula(R) is a registered trademark of Kern Sibbald.
- */
-
-Prado::using('System.Security.IUserManager');
-Prado::using('Application.Common.Class.CommonModule');
-Prado::using('Application.Common.Class.BaculumUser');
-
-class BaculumUsersManager extends CommonModule implements IUserManager {
-
-
- // @TODO: Do auth managers transparent for application without using 'web' and 'api' modules.
- private $auth_managers = array(
- 'web_users' => '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;
- }
-}
-?>
$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);
*/
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);
*/
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);
*/
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);
* Bacula(R) is a registered trademark of Kern Sibbald.
*/
+session_start();
+
Prado::using('Application.Common.Class.BaculumPage');
Prado::using('Application.Web.Class.WebConfig');
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;
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();
},
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();
},
return;
}
set_callback_parameter(tr);
- }.bind(tr));
+ });
}.bind(this));
Formatters.set_formatters();
this.revertSortingFromCookie();
msgid "Restore job:"
msgstr "Restore job:"
+
+msgid "API host"
+msgstr "API host"
+
+msgid "API host:"
+msgstr "API host:"
+
+msgid "Select host"
+msgstr "Select host"
msgid "Restore job:"
msgstr "Restore job:"
+
+msgid "API host"
+msgstr "API host"
+
+msgid "API host:"
+msgstr "API host:"
+
+msgid "Select host"
+msgstr "Select host"
msgid "Restore job:"
msgstr "Zadanie przywracania:"
+
+msgid "API host"
+msgstr "API host"
+
+msgid "API host:"
+msgstr "API host:"
+
+msgid "Select host"
+msgstr "Wybierz host"
msgid "Restore job:"
msgstr "Restore job:"
+
+msgid "API host"
+msgstr "API host"
+
+msgid "API host:"
+msgstr "API host:"
+
+msgid "Select host"
+msgstr "Select host"
class Monitor extends BaculumWebPage {
public function onInit($param) {
parent::onInit($param);
- $this->Application->getModule('web_users')->loginUser();
$_SESSION['monitor_data'] = array(
'jobs' => array(),
$_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;
}
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) {
$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.');
}
}
$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;
<com:TActiveLinkButton ID="Workspace" Text="<%[ Workspace ]%>" Attributes.onclick="PanelWindow.show('container'); return false;" />
<img src="<%=$this->getPage()->getTheme()->getBaseUrl()%>/graphs.png" alt="" onclick="$('#<%=$this->Graphs->ClientID%>').click()" />
<com:TActiveLinkButton ID="Graphs" Text="<%[ Graphs ]%>" Attributes.onclick="PanelWindow.show('graphs'); return false;" />
- <img src="<%=$this->getPage()->getTheme()->getBaseUrl()%>/users.png" alt="" onclick="$('#<%=$this->Users->ClientID%>').click()" <%=$this->User->getIsAdmin() === false ? ' style="display: none;"' : ''%>/>
+ <img src="<%=$this->getPage()->getTheme()->getBaseUrl()%>/users.png" alt="" onclick="$('#<%=$this->Users->ClientID%>').click()" <%=!$_SESSION['admin'] ? ' style="display: none;"' : ''%>/>
<com:TActiveLinkButton ID="Users" Text="<%[ Users ]%>" Attributes.onclick="PanelWindow.show('users'); return false;" />
- <img src="<%=$this->getPage()->getTheme()->getBaseUrl()%>/config.png" alt="" onclick="$('#<%=$this->Config->ClientID%>').click()" />
+ <img src="<%=$this->getPage()->getTheme()->getBaseUrl()%>/config.png" alt="" onclick="$('#<%=$this->Config->ClientID%>').click()" <%=!$_SESSION['admin'] ? ' style="display: none;"' : ''%> />
<com:TActiveLinkButton ID="Config" Text="<%[ Configuration ]%>" Attributes.onclick="PanelWindow.show('config'); return false;" />
<img src="<%=$this->getPage()->getTheme()->getBaseUrl()%>/logout.png" alt="" onclick="$('#<%=$this->Logout->ClientID%>').click()" />
<com:TActiveLinkButton ID="Logout" Text="<%[ Logout ]%>" OnCommand="Page.logout" />
<p><span><%[ Most often used: ]%></span><span id="jobs_most"></span></p>
<p><span><%[ Execution count most used: ]%></span><span id="jobs_most_count"></span> <%[ times ]%></p>
</fieldset>
- <fieldset class="dashboard_field"<%=$this->User->getIsAdmin() === false ? ' style="display: none;"' : ''%>>
+ <fieldset class="dashboard_field"<%=!$_SESSION['admin'] ? ' style="display: none;"' : ''%>>
<legend><%[ Database ]%></legend>
<img src="<%=$this->getPage()->getTheme()->getBaseUrl()%>/database.png" alt="" />
<p><span><%[ Database type: ]%></span><span id="database_type"></span></p>
<legend><%[ Restore Wizard ]%></legend>
<a class="big" href="<%=$this->Service->constructUrl('RestoreWizard')%>" style="line-height: 73px; display: block; text-align: center;"><img src="<%=$this->getPage()->getTheme()->getBaseUrl()%>/restore.png" alt="" /><%[ Perform Restore ]%></a>
</fieldset>
- <fieldset class="dashboard_field"<%=$this->User->getIsAdmin() === false ? ' style="display: none;"' : ''%>>
+ <fieldset class="dashboard_field"<%=!$_SESSION['admin'] ? ' style="display: none;"' : ''%>>
<legend><%[ Configuration Wizard ]%></legend>
<a class="big" href="<%=$this->Service->constructUrl('WebConfigWizard')%>" style="line-height: 73px; display: block; text-align: center;"><img src="<%=$this->getPage()->getTheme()->getBaseUrl()%>/setting.png" alt="" /><%[ Baculum Settings ]%></a>
</fieldset>
<div><com:Application.Web.Portlets.BaculaHosts ID="BaculaConfig" /></div>
</div>
<div id="users" style="display: none">
- <div>
- <a href="javascript:void(0)" id="add_user_btn"><strong><%[ Add new user ]%></strong></a>
- <div id="add_user" style="display: none">
- <p><%[ Username: ]%><input id="newuser" type="text" /><%[ Password: ]%><input id="newpwd" type="password" />
- <a href="javascript:void(0)" onclick="Users.addUser()">
- <img src="<%=$this->getPage()->getTheme()->getBaseUrl()%>/icon_ok.png" alt="<%[ Save ]%>" title="<%[ Save ]%>"/>
- </a>
- <a href="javascript:void(0)" onclick="Users.cancelAddUser()">
- <img src="<%=$this->getPage()->getTheme()->getBaseUrl()%>/icon_err.png" alt="<%[ Close ]%>" title="<%[ Close ]%>" />
- </a></p>
- </div>
- <com:TActiveRepeater ID="UsersList">
- <prop:HeaderTemplate>
- <table id="users_list" class="window-section-detail-smallrow">
- <tr>
- <th><%[ User name ]%></th>
- <th><%[ Role ]%></th>
- <th><%[ Actions ]%></th>
- </tr>
- </prop:HeaderTemplate>
- <prop:ItemTemplate>
- <tr class="slide-window-element">
- <td><%=$this->DataItem%></td>
- <td><%=$this->User->getName() == $this->DataItem ? Prado::localize('Administrator') : Prado::localize('Normal user')%></td>
- <td>
- <a href="javascript:void(0)" <%=$this->User->getName() == $this->DataItem ? 'style="visibility: hidden"' : ''%> onclick="Users.rmUser('<%=$this->DataItem%>')"><img src="<%=$this->getPage()->getTheme()->getBaseUrl()%>/user-del.png"> <%[ Remove user ]%></a>
- <a href="javascript:void(0)" onclick="Users.showChangePwd(this)" rel="chpwd_btn">
- <img src="<%=$this->getPage()->getTheme()->getBaseUrl()%>/key.png" alt="" />
- <%[ Change password ]%>
- </a>
- <span style="display: none;" rel="chpwd">
- <input type="password" onkeydown="event.keyCode == 13 ? Users.changePwd(this, '<%=$this->DataItem%>') : (event.keyCode == 27 ? Users.cancelChangePwd(this.nextElementSibling.nextElementSibling) : '');" />
- <a href="javascript:void(0)" onclick="Users.changePwd(this.prevousElementSibling, '<%=$this->DataItem%>')">
- <img src="<%=$this->getPage()->getTheme()->getBaseUrl()%>/icon_ok.png" alt="<%[ Save ]%>" title="<%[ Save ]%>"/>
- </a>
- <a href="javascript:void(0)" onclick="Users.cancelChangePwd(this)">
- <img src="<%=$this->getPage()->getTheme()->getBaseUrl()%>/icon_err.png" alt="<%[ Close ]%>" title="<%[ Close ]%>" />
- </a>
- </span>
- </td>
- </tr>
- </prop:ItemTemplate>
- <prop:FooterTemplate>
- </table>
- </prop:FooterTemplate>
- </com:TActiveRepeater>
- <p><em><%[ Please note that for each user (excluding administrator) there should exist separate Bconsole config file in form: ]%> <strong><com:TLabel ID="BconsoleCustomPath" /></strong></em></p>
- <com:TCallback ID="UserAction" OnCallback="userAction" />
- <script type="text/javascript">
- var send_user_action = function(action, param, value) {
- if (!value) {
- value = '';
- }
- var user_action_callback = <%=$this->UserAction->ActiveControl->Javascript%>;
- user_action_callback.setCallbackParameter([action, param, value].join(';'));
- user_action_callback.dispatch();
- };
- Users.txt = {
- enter_login: '<%[ Please enter login. ]%>',
- invalid_login: '<%[ Invalid login value. Login may contain a-z A-Z 0-9 characters. ]%>',
- invalid_pwd: '<%[ Password must be longer than 4 chars. ]%>'
- };
- Users.action_callback = send_user_action;
- Users.validators = { user_pattern: new RegExp('^<%=BasicUserConfig::USER_PATTERN%>$') };
- Users.init();
- </script>
- </div>
+ <div><com:Application.Web.Portlets.Users ID="WebUsers" /></div>
</div>
<div id="console">
<a id="clear_bvfs_cache" href="javascript: void(0)"><com:TActiveImageButton ID="ClearBvfsCache" OnCallback="clearBvfsCache" Attributes.onclick="return (confirm('<%=Prado::localize('This action will clear bvfs cache that was created during preparing restore files. There is not recommended use this action during restore job working. Are you sure?')%>'));" ImageUrl="<%=$this->getPage()->getTheme()->getBaseUrl()%>/trash_icon.png" AlternateText="<%[ clear bvfs cache ]%>" /><com:TLabel ForControl="ClearBvfsCache"><%[ clear bvfs cache ]%></com:TLabel></a>
<a id="logging" href="javascript:void(0)"><com:TActiveCheckBox ID="Logging" OnCallback="setDebug" Attributes.onclick="return (this.checked === false || confirm('<%=Prado::localize('Debug files enable possibility to save most of actions executed on Baculum WebGUI. Debug functionality should be enabled if is happening shomething wrong with Baculum or something that looks like a bug. Logs can be useful for detecting a problems in Baculum working. After confirmation this message Baculum debug files will be continuously saving in /protected/Web/Logs/ directory. Are you sure?')%>'));" /><com:TLabel ForControl="Logging"><%[ Enable debug ]%></com:TLabel></a>
- <a id="volumes_tools_launcher" href="javascript:void(0)" <%=$this->User->getIsAdmin() === false ? ' style="display: none;"' : ''%>><img src="<%=$this->getPage()->getTheme()->getBaseUrl()%>/tape_tools_icon.png" alt="<%[ volumes tools ]%>" /><span><%[ volumes tools ]%></span></a>
+ <a id="volumes_tools_launcher" href="javascript:void(0)" <%=!$_SESSION['admin'] ? ' style="display: none;"' : ''%>><img src="<%=$this->getPage()->getTheme()->getBaseUrl()%>/tape_tools_icon.png" alt="<%[ volumes tools ]%>" /><span><%[ volumes tools ]%></span></a>
<a id="console_launcher" href="javascript:void(0)"><img src="<%=$this->getPage()->getTheme()->getBaseUrl()%>/console_icon.png" alt="<%[ Bacula console ]%>" /><span><%[ show console ]%></span></a>
<com:Application.Web.Portlets.VolumesTools ID="VolumesTools" />
<com:Application.Web.Portlets.Console ID="Console" />
<script type="text/javascript">
var oMonitor;
$(function() {
- <%=(!is_null($this->initWindowId) && !is_null($this->initElementId) ?
- 'SlideWindow.getObj("' . $this->initWindowId . 'Window").setInitElementId("' . $this->initElementId . '");'
+ <%=(!is_null($this->init_window_id) && !is_null($this->init_element_id) ?
+ 'SlideWindow.getObj("' . $this->init_window_id . 'Window").setInitElementId("' . $this->init_element_id . '");'
: '')%>
- <%=(!is_null($this->openWindow) ?
+ <%=(!is_null($this->open_window) ?
'PanelWindow.show("container");
- $("#' . $this->openWindow . '").trigger(\'click\');
+ $("#' . $this->open_window . '").trigger(\'click\');
window.history.pushState("", "", "/");'
: '')%>
});
class WebHome extends BaculumWebPage
{
- protected $app_config;
-
public $jobs;
- public $openWindow = null;
+ public $open_window = null;
- public $initWindowId = null;
+ public $init_window_id = null;
- public $initElementId = null;
+ public $init_element_id = null;
public $jobs_states = null;
- public $dbtype = '';
-
- public $windowIds = array('Storage', 'Client', 'Volume', 'Pool', 'Job', 'JobRun');
+ public $window_ids = array('Storage', 'Client', 'Volume', 'Pool', 'Job', 'JobRun');
+ private $web_config = array();
- public function onInit($param) {
- parent::onInit($param);
- $this->Application->getModule('web_users')->loginUser();
+ private $api_hosts = array();
+ public function onPreInit($param) {
+ parent::onPreInit($param);
+ $this->web_config = $this->getModule('web_config')->getConfig();
if (!$this->IsPostBack && !$this->IsCallBack) {
- $this->getModule('api')->initSessionCache(true);
+ $this->setSessionUserVars($this->web_config);
}
+ }
- $config = $this->getModule('web_config')->getConfig();
- if(count($config) === 0) {
+ public function onInit($param) {
+ parent::onInit($param);
+ if(count($this->web_config) === 0) {
// Config doesn't exist
$this->goToPage('WebConfigWizard');
}
+ if (!$this->IsPostBack && !$this->IsCallBack) {
+ $this->getModule('api')->initSessionCache(true);
+ }
- $this->Users->Visible = $this->User->getIsAdmin();
- $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();
+ $this->Users->Visible = $_SESSION['admin'];
+ $this->Config->Visible = $_SESSION['admin'];
+ $this->SettingsWizardBtn->Visible = $_SESSION['admin'];
+ $this->PoolBtn->Visible = $_SESSION['admin'];
+ $this->VolumeBtn->Visible = $_SESSION['admin'];
+ $this->ClearBvfsCache->Visible = $_SESSION['admin'];
+ $this->Logging->Visible = $_SESSION['admin'];
if(!$this->IsPostBack && !$this->IsCallBack) {
$this->Logging->Checked = Logging::$debug_enabled;
$this->Director->dataSource = array_combine($directors, $directors);
$this->Director->SelectedValue = $_SESSION['director'];
$this->Director->dataBind();
- // Web doesn't store any info about db and it is OK
- /*if ($this->User->getIsAdmin() === true) {
- $this->dbtype = $this->app_config['db']['type'];
- }*/
$this->setJobsStates();
$this->setJobs();
$this->setClients();
- $this->setUsers();
$this->setWindowOpen();
$this->BaculaConfig->loadConfig(null, null);
}
}
+ private function setSessionUserVars($cfg) {
+ // Set administrator role
+ $_SESSION['admin'] = ($_SERVER['PHP_AUTH_USER'] === $cfg['baculum']['login']);
+ // Set api host for normal user
+ if (!$_SESSION['admin'] && array_key_exists('users', $cfg) && array_key_exists($_SERVER['PHP_AUTH_USER'], $cfg['users'])) {
+ $_SESSION['api_host'] = $cfg['users'][$_SERVER['PHP_AUTH_USER']];
+ } elseif (isset($_SESSION['api_host'])) {
+ unset($_SESSION['api_hosts']);
+ }
+ }
+
public function director($sender, $param) {
$_SESSION['director'] = $this->Director->SelectedValue;
}
public function setDebug($sender, $param) {
- if($this->User->getIsAdmin() === true) {
+ if($_SESSION['admin']) {
$this->enableDebug($this->Logging->Checked);
$this->goToDefaultPage();
}
public function enableDebug($enable) {
$result = false;
- $config = $this->getModule('web_config')->getConfig();
- if(count($config) > 0) {
- $config['baculum']['debug'] = ($enable === true) ? "1" : "0";
- $result = $this->getModule('web_config')->setConfig($config);
+ if(count($this->web_config) > 0) {
+ $this->web_config['baculum']['debug'] = ($enable === true) ? "1" : "0";
+ $result = $this->getModule('web_config')->setConfig($this->web_config);
}
return $result;
}
public function clearBvfsCache($sender, $param) {
- if($this->User->getIsAdmin() === true) {
+ if($_SESSION['admin']) {
$this->getModule('api')->set(array('bvfs', 'clear'), array());
}
}
'running' => array()
);
$job_types = $jobs_summary;
- $job_states = array();
+ $jobs_states = array();
$misc = $this->getModule('misc');
foreach($job_types as $type => $arr) {
$this->Clients->dataBind();
}
- public function setUsers() {
- if($this->User->getIsAdmin() === true) {
- $allUsers = $this->getModule('basic_webuser')->getAllUsers();
- $users = array_keys($allUsers);
- sort($users);
- $this->UsersList->dataSource = $users;
- $this->UsersList->dataBind();
- }
- }
-
- public function userAction($sender, $param) {
- $config = $this->getModule('web_config');
- $cfg = $config->getConfig();
-
- if($this->User->getIsAdmin() === true) {
- list($action, $user, $value) = explode(';', $param->CallbackParameter, 3);
- switch($action) {
- case 'newuser':
- case 'chpwd': {
- $admin = false;
- $valid = true;
- if ($user === $cfg['baculum']['login']) {
- $cfg['baculum']['password'] = $value;
- $valid = $config->setConfig($cfg);
- $admin = true;
- }
- if ($valid === true) {
- $this->getModule('basic_webuser')->setUsersConfig($user, $value);
- }
- if ($admin === true) {
- // if admin password changed then try to auto-login by async request
- $http_protocol = isset($_SERVER['HTTPS']) && !empty($_SERVER['HTTPS']) ? 'https' : 'http';
- $this->switchToUser($user, $value);
- exit();
- } else {
- // if normal user's password changed then update users grid
- $this->setUsers();
- }
- }
- break;
- case 'rmuser': {
- if ($user != $this->User->getName()) {
- $this->getModule('basic_webuser')->removeUser($user);
- $this->setUsers();
- }
- break;
- }
- }
- }
- }
-
public function setWindowOpen() {
- if (isset($this->Request['open']) && in_array($this->Request['open'], $this->windowIds) && $this->Request['open'] != 'JobRun') {
+ if (isset($this->Request['open']) && in_array($this->Request['open'], $this->window_ids) && $this->Request['open'] != 'JobRun') {
$btn = $this->Request['open'] . 'Btn';
- $this->openWindow = $this->{$btn}->ClientID;
+ $this->open_window = $this->{$btn}->ClientID;
if (isset($this->Request['id']) && (is_numeric($this->Request['id']))) {
- $this->initWindowId = $this->Request['open'];
- $this->initElementId = $this->Request['id'];
+ $this->init_window_id = $this->Request['open'];
+ $this->init_element_id = $this->Request['id'];
}
}
}
public function logout($sender, $param) {
$fake_pwd = $this->getModule('misc')->getRandomString();
- $this->switchToUser($this->User->getName(), $fake_pwd);
+ $this->switchToUser($_SERVER['PHP_AUTH_USER'], $fake_pwd);
exit();
}
}
<using namespace="System.I18N.*" />
</paths>
<modules>
- <!-- web auth modules -->
- <module id="web_users" class="Application.Common.Class.BaculumUsersManager" />
- <module id="web_auth" class="System.Security.TAuthManager" UserManager="web_users" AllowAutoLogin="true" AuthExpire="864000" />
<!-- config modules -->
<module id="web_config" class="Application.Web.Class.WebConfig" />
<module id="host_config" class="Application.Web.Class.HostConfig" />
public $config;
public function loadConfig($sender, $param) {
+ if(!$_SESSION['admin']) {
+ return;
+ }
$this->config = $this->getModule('host_config')->getConfig();
$hosts = array_keys($this->config);
$this->RepeaterHosts->DataSource = $hosts;
}
public function removeHost($sender, $param) {
+ if(!$_SESSION['admin']) {
+ return;
+ }
$host = $param->getCommandParameter();
if (!empty($host)) {
$host_config = $this->getModule('host_config');
--- /dev/null
+<?php
+/*
+ * Bacula(R) - The Network Backup Solution
+ * Baculum - Bacula web interface
+ *
+ * Copyright (C) 2013-2017 Kern Sibbald
+ *
+ * The main author of Baculum is Marcin Haba.
+ * The original author of Bacula is Kern Sibbald, with contributions
+ * from many others, a complete list can be found in the file AUTHORS.
+ *
+ * You may use this file and others of this release according to the
+ * license defined in the LICENSE file, which includes the Affero General
+ * Public License, v3.0 ("AGPLv3") and some additional permissions and
+ * terms pursuant to its AGPLv3 Section 7.
+ *
+ * This notice must be preserved when any source code is
+ * conveyed and/or propagated.
+ *
+ * Bacula(R) is a registered trademark of Kern Sibbald.
+ */
+
+
+Prado::using('System.Web.UI.WebControls.TConditional');
+Prado::using('Application.Web.Portlets.Portlets');
+
+class Users extends Portlets {
+
+ public $web_config;
+
+ public function onInit($param) {
+ parent::onInit($param);
+ $this->web_config = $this->getModule('web_config')->getConfig();
+ $this->setUsers();
+ }
+
+ public function setUsers() {
+ if(!$_SESSION['admin']) {
+ return;
+ }
+ $all_users = $this->getModule('basic_webuser')->getAllUsers();
+ $users = array_keys($all_users);
+ sort($users);
+ $users_list = array();
+ $users_feature = (array_key_exists('users', $this->web_config) && is_array($this->web_config['users']));
+ for ($i = 0; $i < count($users); $i++) {
+ $host = null;
+ if ($users_feature && array_key_exists($users[$i], $this->web_config['users'])) {
+ $host = $this->web_config['users'][$users[$i]];
+ }
+ $users_list[] = array(
+ 'user' => $users[$i],
+ 'host' => $host,
+ 'admin' => ($users[$i] === $this->web_config['baculum']['login'])
+ );
+ }
+ $this->UsersList->dataSource = $users_list;
+ $this->UsersList->dataBind();
+ }
+
+ public function initHosts($sender, $param) {
+ $api_hosts = array_keys($this->getModule('host_config')->getConfig());
+ $sender->DataSource = array_combine($api_hosts, $api_hosts);
+ $sender->dataBind();
+ }
+
+ public function userAction($sender, $param) {
+ if(!$_SESSION['admin']) {
+ return;
+ }
+ list($action, $user, $value) = explode(';', $param->CallbackParameter, 3);
+ switch($action) {
+ case 'newuser':
+ case 'chpwd': {
+ $admin = false;
+ $valid = true;
+ if ($user === $this->web_config['baculum']['login']) {
+ $this->web_config['baculum']['password'] = $value;
+ $valid = $this->getModule('web_config')->setConfig($this->web_config);
+ $admin = true;
+ }
+ if ($valid === true) {
+ $this->getModule('basic_webuser')->setUsersConfig($user, $value);
+ }
+ if ($admin === true) {
+ // if admin password changed then try to auto-login by async request
+ $http_protocol = isset($_SERVER['HTTPS']) && !empty($_SERVER['HTTPS']) ? 'https' : 'http';
+ $this->switchToUser($user, $value);
+ exit();
+ } else {
+ // if normal user's password changed then update users grid
+ $this->setUsers();
+ }
+ }
+ break;
+ case 'rmuser': {
+ if ($user != $_SERVER['PHP_AUTH_USER']) {
+ $this->getModule('basic_webuser')->removeUser($user);
+ $this->setUsers();
+ }
+ break;
+ }
+ case 'set_host': {
+ if (empty($value) && array_key_exists($user, $this->web_config['users'])) {
+ unset($this->web_config['users'][$user]);
+ } else {
+ $this->web_config['users'][$user] = $value;
+ }
+ $this->getModule('web_config')->setConfig($this->web_config);
+ break;
+ }
+ }
+ }
+}
--- /dev/null
+<a class="big" href="javascript:void(0)" id="add_user_btn"><img src="/themes/Baculum-v1/add.png" alt="Add"><%[ Add new user ]%></a>
+<div id="add_user" style="display: none">
+ <p><%[ Username: ]%><input id="newuser" type="text" /><%[ Password: ]%><input id="newpwd" type="password" /><%[ API host: ]%><com:TDropDownList ID="HostsList" OnInit="SourceTemplateControl.initHosts" />
+ <a href="javascript:void(0)" onclick="Users.addUser()">
+ <img src="<%=$this->getPage()->getTheme()->getBaseUrl()%>/icon_ok.png" alt="<%[ Save ]%>" title="<%[ Save ]%>"/>
+ </a>
+ <a href="javascript:void(0)" onclick="Users.cancelAddUser()">
+ <img src="<%=$this->getPage()->getTheme()->getBaseUrl()%>/icon_err.png" alt="<%[ Close ]%>" title="<%[ Close ]%>" />
+ </a></p>
+</div>
+<com:TRepeater ID="UsersList">
+ <prop:HeaderTemplate>
+ <table id="users_list" class="window-section-detail-smallrow">
+ <tr>
+ <th><%[ User name ]%></th>
+ <th><%[ Role ]%></th>
+ <th><%[ API host ]%></th>
+ <th><%[ Actions ]%></th>
+ </tr>
+ </prop:HeaderTemplate>
+ <prop:ItemTemplate>
+ <tr class="slide-window-element">
+ <td><%=$this->DataItem['user']%></td>
+ <td><%=$this->DataItem['admin'] ? Prado::localize('Administrator') : Prado::localize('Normal user')%></td>
+ <td>
+ <com:TPanel Visible="<%=$this->DataItem['admin']%>" Style="line-height: 29px">
+ Main
+ </com:TPanel>
+ <com:TPanel Visible="<%=!$this->DataItem['admin']%>">
+ <select rel="user_host" onchange="Users.set_host('<%=$this->DataItem['user']%>', this);">
+ <com:TRepeater OnInit="SourceTemplateControl.initHosts">
+ <prop:HeaderTemplate>
+ <option value=""><%[ Select host ]%></option>
+ </prop:HeaderTemplate>
+ <prop:ItemTemplate>
+ <option value="<%=$this->DataItem%>" <%=(array_key_exists('users', $this->SourceTemplateControl->web_config) && array_key_exists($this->Parent->Parent->Parent->DataItem['user'], $this->SourceTemplateControl->web_config['users']) && $this->SourceTemplateControl->web_config['users'][$this->Parent->Parent->Parent->DataItem['user']] === $this->DataItem) ? 'selected' : ''%>><%=$this->DataItem%></option>
+ </prop:ItemTemplate>
+ </com:TRepeater>
+ </select>
+ <img src="<%=$this->getPage()->getTheme()->getBaseUrl()%>/ajax-loader-arrows.gif" rel="user_host_img" alt="" style="visibility: hidden" />
+ </com:TPanel>
+ </td>
+ <td>
+ <a href="javascript:void(0)" <%=$this->DataItem['admin'] ? 'style="visibility: hidden"' : ''%> onclick="Users.rmUser('<%=$this->DataItem['user']%>')"><img src="<%=$this->getPage()->getTheme()->getBaseUrl()%>/user-del.png"> <%[ Remove user ]%></a>
+ <a href="javascript:void(0)" onclick="Users.showChangePwd(this)" rel="chpwd_btn">
+ <img src="<%=$this->getPage()->getTheme()->getBaseUrl()%>/key.png" alt="" />
+ <%[ Change password ]%>
+ </a>
+ <span style="display: none;" rel="chpwd">
+ <input type="password" onkeydown="event.keyCode == 13 ? Users.changePwd(this, '<%=$this->DataItem['user']%>') : (event.keyCode == 27 ? Users.cancelChangePwd(this.nextElementSibling.nextElementSibling) : '');" />
+ <a href="javascript:void(0)" onclick="Users.changePwd(this.prevousElementSibling, '<%=$this->DataItem['user']%>')">
+ <img src="<%=$this->getPage()->getTheme()->getBaseUrl()%>/icon_ok.png" alt="<%[ Save ]%>" title="<%[ Save ]%>"/>
+ </a>
+ <a href="javascript:void(0)" onclick="Users.cancelChangePwd(this)">
+ <img src="<%=$this->getPage()->getTheme()->getBaseUrl()%>/icon_err.png" alt="<%[ Close ]%>" title="<%[ Close ]%>" />
+ </a>
+ </span>
+ </td>
+ </tr>
+ </prop:ItemTemplate>
+ <prop:FooterTemplate>
+ </table>
+ </prop:FooterTemplate>
+</com:TRepeater>
+<p><em><%[ Please note that for each user (excluding administrator) there should exist separate Bconsole config file in form: ]%> <strong><com:TLabel ID="BconsoleCustomPath" /></strong></em></p>
+<com:TCallback ID="UserAction" OnCallback="TemplateControl.userAction" ClientSide.OnComplete="Users.hide_loader();" />
+<script type="text/javascript">
+ var send_user_action = function(action, param, value) {
+ Users.current_action = action;
+ if (!value) {
+ value = '';
+ }
+ var user_action_callback = <%=$this->UserAction->ActiveControl->Javascript%>;
+ user_action_callback.setCallbackParameter([action, param, value].join(';'));
+ user_action_callback.dispatch();
+ };
+ Users.txt = {
+ enter_login: '<%[ Please enter login. ]%>',
+ invalid_login: '<%[ Invalid login value. Login may contain a-z A-Z 0-9 characters. ]%>',
+ invalid_pwd: '<%[ Password must be longer than 4 chars. ]%>'
+ };
+ Users.action_callback = send_user_action;
+ Users.validators = { user_pattern: new RegExp('^<%=BasicUserConfig::USER_PATTERN%>$') };
+ Users.init();
+</script>
height: 9px;
margin: 0 4px;
font-size: 10px;
+ vertical-align: super;
}
#graphs span {
}
#users_list {
- width: 720px;
+ width: 890px;
font-size: 13px;
}
#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 {