From: Marcin Haba Date: Tue, 29 Dec 2015 23:10:51 +0000 (+0100) Subject: baculum: Implement users management from web interface X-Git-Tag: Release-7.4.0~72 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=e6d49d055d171a9b97a2db8effd327a90eb107cd;p=bacula%2Fbacula baculum: Implement users management from web interface --- diff --git a/gui/baculum/protected/Class/ConfigurationManager.php b/gui/baculum/protected/Class/ConfigurationManager.php index 7a711e98e0..caa1bdd6f6 100644 --- a/gui/baculum/protected/Class/ConfigurationManager.php +++ b/gui/baculum/protected/Class/ConfigurationManager.php @@ -167,7 +167,6 @@ class ConfigurationManager extends TModule */ public function setUsersConfig($user, $password, $firstUsage = false, $oldUser = null) { $allUsers = $this->getAllUsers(); - $usersFile = Prado::getPathOfNamespace(self::USERS_FILE, '.users'); $password = $this->getCryptedPassword($password); if($firstUsage === true) { @@ -194,16 +193,7 @@ class ConfigurationManager extends TModule $allUsers[$user] = $password; } - $users = array(); - foreach ($allUsers as $user => $pwd) { - $users[] = "$user:$pwd"; - } - - $usersToFile = implode("\n", $users); - $old_umask = umask(0); - umask(0077); - $result = file_put_contents($usersFile, $usersToFile) !== false; - umask($old_umask); + $result = $this->saveUserConfig($allUsers); return $result; } @@ -222,6 +212,30 @@ class ConfigurationManager extends TModule return $allUsers; } + public function saveUserConfig($allUsers) { + $users = array(); + foreach ($allUsers as $user => $pwd) { + $users[] = "$user:$pwd"; + } + $usersFile = Prado::getPathOfNamespace(self::USERS_FILE, '.users'); + $usersToFile = implode("\n", $users); + $old_umask = umask(0); + umask(0077); + $result = file_put_contents($usersFile, $usersToFile) !== false; + umask($old_umask); + return $result; + } + + public function removeUser($username) { + $result = false; + $allUsers = $this->getAllUsers(); + if (array_key_exists($username, $allUsers)) { + unset($allUsers[$username]); + $result = $this->saveUserConfig($allUsers); + } + return $result; + } + /** * Checking if users configuration file exists. * @@ -243,5 +257,17 @@ class ConfigurationManager extends TModule $result = file_put_contents($usersFile, '') !== false; return $result; } + + public function switchToUser($http_protocol, $host, $port, $user, $password) { + $urlPrefix = $this->Application->getModule('friendly-url')->getUrlPrefix(); + $location = sprintf("%s://%s:%s@%s:%d%s", $http_protocol, $user, $password, $host, $port, $urlPrefix); + header("Location: $location"); + } + + public function getRandomString() { + $characters = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; + $rand_string = str_shuffle($characters); + return $rand_string; + } } ?> diff --git a/gui/baculum/protected/JavaScript/misc.js b/gui/baculum/protected/JavaScript/misc.js index 9500c03026..b5d3706b1b 100644 --- a/gui/baculum/protected/JavaScript/misc.js +++ b/gui/baculum/protected/JavaScript/misc.js @@ -225,3 +225,100 @@ var Dashboard = { } } } + +var Users = { + ids: { + create_user: { + add_user: 'add_user', + add_user_btn: 'add_user_btn', + newuser: 'newuser', + newpwd: 'newpwd' + }, + change_pwd: { + rel_chpwd: 'chpwd', + rel_chpwd_btn: 'chpwd_btn' + } + }, + init: function() { + this.setEvents(); + }, + setEvents: function() { + document.getElementById(this.ids.create_user.add_user_btn).addEventListener('click', function(e) { + $(this.ids.create_user.add_user).show(); + $(this.ids.create_user.newuser).focus(); + }.bind(this)); + document.getElementById(this.ids.create_user.newuser).addEventListener('keypress', function(e) { + var target = e.target || e.srcElement; + if (e.keyCode == 13) { + target.parentNode.getElementsByTagName('A')[0].click(); + } + return false; + }.bind(this)); + document.getElementById(this.ids.create_user.newpwd).addEventListener('keypress', function(e) { + var target = e.target || e.srcElement; + if (e.keyCode == 13) { + $(target.nextElementSibling).click(); + } + return false; + }.bind(this)); + }, + userValidator: function(user) { + user = user.replace(/\s/g, ''); + var valid = user != ''; + return valid; + }, + pwdValidator: function(pwd) { + var valid = pwd.length > 4; + return valid; + }, + addUser: function() { + var valid = true; + var user = document.getElementById(this.ids.create_user.newuser).value; + var pwd = document.getElementById(this.ids.create_user.newpwd).value; + if (this.userValidator(user) === false) { + alert(this.txt.enter_login); + valid = false; + } + if (this.pwdValidator(pwd) === false) { + alert(this.txt.invalid_pwd); + valid = false; + } + if (valid === true) { + $(this.ids.create_user.add_user).hide(); + this.action_callback('newuser', user, pwd); + } + return valid; + }, + rmUser: function(user) { + this.action_callback('rmuser', user); + }, + showChangePwd: function(el) { + $$('a[rel=\'' + this.ids.change_pwd.rel_chpwd_btn + '\']').invoke('show'); + $(el).hide(); + $$('span[rel=\'' + this.ids.change_pwd.rel_chpwd + '\']').invoke('hide'); + $(el.nextElementSibling).show(); + $(el.nextElementSibling).select('input')[0].focus(); + }, + changePwd: function(el, user) { + var valid = true; + var pwd = el.previousElementSibling.value; + + if (this.pwdValidator(pwd) === false) { + alert(this.txt.invalid_pwd); + valid = false; + } + if (valid === true) { + $(el.parentNode).hide(); + $(el.parentNode.previousElementSibling).show(); + this.action_callback('chpwd', user, pwd); + } + }, + cancelAddUser: function(el) { + $(this.ids.create_user.add_user).hide(); + }, + cancelChangePwd: function(el) { + $(el.parentNode).hide(); + $(el.parentNode.previousElementSibling).show(); + } + +} diff --git a/gui/baculum/protected/JavaScript/panel-window.js b/gui/baculum/protected/JavaScript/panel-window.js index 82881cb1dc..64dcd4468f 100644 --- a/gui/baculum/protected/JavaScript/panel-window.js +++ b/gui/baculum/protected/JavaScript/panel-window.js @@ -1,7 +1,7 @@ var PanelWindowClass = Class.create({ currentWindowId: null, - windowIds: ['dashboard', 'container', 'graphs'], + windowIds: ['dashboard', 'container', 'graphs', 'users'], onShow: null, initialize: function() { @@ -20,7 +20,7 @@ var PanelWindowClass = Class.create({ }); } } - for (var i = 0, j = 1; i < this.windowIds.length; i++, j++) { + for (var i = 0; i < this.windowIds.length; i++) { hide_panel_by_id(this.windowIds[i]); } }, diff --git a/gui/baculum/protected/Lang/en/messages.mo b/gui/baculum/protected/Lang/en/messages.mo index bf230e4dea..4ffd86e024 100644 Binary files a/gui/baculum/protected/Lang/en/messages.mo and b/gui/baculum/protected/Lang/en/messages.mo differ diff --git a/gui/baculum/protected/Lang/en/messages.po b/gui/baculum/protected/Lang/en/messages.po index b4dcf0f6f4..1179348a93 100644 --- a/gui/baculum/protected/Lang/en/messages.po +++ b/gui/baculum/protected/Lang/en/messages.po @@ -1097,3 +1097,36 @@ msgstr "Baculum Settings" msgid "start time" msgstr "start time" +msgid "Users" +msgstr "Users" + +msgid "User name" +msgstr "User name" + +msgid "Role" +msgstr "Role" + +msgid "Remove user" +msgstr "Remove user" + +msgid "Logout" +msgstr "Logout" + +msgid "Change password" +msgstr "Change password" + +msgid "Administrator" +msgstr "Administrator" + +msgid "Normal user" +msgstr "Normal user" + +msgid "Add new user" +msgstr "Add new user" + +msgid "Username:" +msgstr "Username:" + +msgid "Please note that for each user (excluding administrator) there should exist separate Bconsole config file in form:" +msgstr "Please note that for each user (excluding administrator) there should exist separate Bconsole config file in form:" + diff --git a/gui/baculum/protected/Lang/pl/messages.mo b/gui/baculum/protected/Lang/pl/messages.mo index ba936762c4..5b082983cc 100644 Binary files a/gui/baculum/protected/Lang/pl/messages.mo and b/gui/baculum/protected/Lang/pl/messages.mo differ diff --git a/gui/baculum/protected/Lang/pl/messages.po b/gui/baculum/protected/Lang/pl/messages.po index eb0f93f57c..ae77299db4 100644 --- a/gui/baculum/protected/Lang/pl/messages.po +++ b/gui/baculum/protected/Lang/pl/messages.po @@ -1098,3 +1098,36 @@ msgstr "Ustawienia Baculum" msgid "start time" msgstr "czas rozpoczęcia" +msgid "Users" +msgstr "Użytkownicy" + +msgid "User name" +msgstr "Nazwa użytkownika" + +msgid "Role" +msgstr "Rola" + +msgid "Remove user" +msgstr "Usuń użytkownika" + +msgid "Logout" +msgstr "Wyloguj" + +msgid "Change password" +msgstr "Zmień hasło" + +msgid "Administrator" +msgstr "Administrator" + +msgid "Normal user" +msgstr "Użytkownik" + +msgid "Add new user" +msgstr "Dodaj nowego użytkownika" + +msgid "Username:" +msgstr "Nazwa użytkownika:" + +msgid "Please note that for each user (excluding administrator) there should exist separate Bconsole config file in form:" +msgstr "Uwaga! Dla każdego użytkownika (wyłączając administratora) powinien istnieć osobny plik konfiguracyjny Bconsole w postaci:" + diff --git a/gui/baculum/protected/Pages/ConfigurationWizard.php b/gui/baculum/protected/Pages/ConfigurationWizard.php index c84c22bf5c..8be23c600a 100644 --- a/gui/baculum/protected/Pages/ConfigurationWizard.php +++ b/gui/baculum/protected/Pages/ConfigurationWizard.php @@ -114,9 +114,7 @@ class ConfigurationWizard extends BaculumPage $this->getModule('configuration')->setUsersConfig($cfgData['baculum']['login'], $cfgData['baculum']['password'], $this->firstRun, $previousUser); // Automatic login after finish wizard. $http_protocol = isset($_SERVER['HTTPS']) && !empty($_SERVER['HTTPS']) ? 'https' : 'http'; - $urlPrefix = $this->Application->getModule('friendly-url')->getUrlPrefix(); - $location = sprintf("%s://%s:%s@%s:%d%s", $http_protocol, $cfgData['baculum']['login'], $cfgData['baculum']['password'], $_SERVER['SERVER_NAME'], $_SERVER['SERVER_PORT'], $urlPrefix); - header("Location: $location"); + $this->getModule('configuration')->switchToUser($http_protocol, $_SERVER['SERVER_NAME'], $_SERVER['SERVER_PORT'], $cfgData['baculum']['login'], $cfgData['baculum']['password']); exit(); } else { // standard version (user defined auth method) $this->goToDefaultPage(); diff --git a/gui/baculum/protected/Pages/Home.page b/gui/baculum/protected/Pages/Home.page index 05f6c124c1..7fa7da3e26 100644 --- a/gui/baculum/protected/Pages/Home.page +++ b/gui/baculum/protected/Pages/Home.page @@ -1,19 +1,24 @@ <%@ MasterClass="Application.Layouts.Main" Theme="Baculum-v1"%>
- -
- -
-
- - - - - - -
+
+
+ +
+
+ + + + + + + User->getIsAdmin() === false ? ' style="display: none;"' : ''%>/> + + + +
+
@@ -282,6 +287,73 @@

<%[ Tip: for getting zoom, please mark area on graph. ]%>

<%[ Tip 2: for back from zoom, please click somewhere on graph. ]%>

+
<%[ clear bvfs cache ]%> <%[ Enable debug ]%> diff --git a/gui/baculum/protected/Pages/Home.php b/gui/baculum/protected/Pages/Home.php index ff829d5c99..a3c6da4938 100644 --- a/gui/baculum/protected/Pages/Home.php +++ b/gui/baculum/protected/Pages/Home.php @@ -57,11 +57,13 @@ class Home extends BaculumPage $appConfig = $this->getModule('configuration')->getApplicationConfig(); + $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->BconsoleCustomPath->Text = $appConfig['bconsole']['cfg_custom_path']; if(!$this->IsPostBack && !$this->IsCallBack) { $this->Logging->Checked = $this->getModule('logging')->isDebugOn(); @@ -81,6 +83,7 @@ class Home extends BaculumPage $this->setJobsStates(); $this->setJobs(); $this->setClients(); + $this->setUsers(); $this->setWindowOpen(); } } @@ -157,6 +160,37 @@ class Home extends BaculumPage $this->Clients->dataBind(); } + public function setUsers() { + if($this->User->getIsAdmin() === true) { + $allUsers = $this->getModule('configuration')->getAllUsers(); + $users = array_keys($allUsers); + sort($users); + $this->UsersList->dataSource = $users; + $this->UsersList->dataBind(); + } + } + + public function userAction($sender, $param) { + if($this->User->getIsAdmin() === true) { + list($action, $param, $value) = explode(';', $param->CallbackParameter, 3); + switch($action) { + case 'newuser': + case 'chpwd': { + $this->getmodule('configuration')->setusersconfig($param, $value); + $this->setUsers(); + } + break; + case 'rmuser': { + if ($param != $this->User->getName()) { + $this->getModule('configuration')->removeUser($param); + $this->setUsers(); + } + break; + } + } + } + } + public function setWindowOpen() { if (isset($this->Request['open']) && in_array($this->Request['open'], $this->windowIds) && $this->Request['open'] != 'JobRun') { $btn = $this->Request['open'] . 'Btn'; @@ -167,5 +201,12 @@ class Home extends BaculumPage } } } + + public function logout($sender, $param) { + $cfg = $this->getModule('configuration'); + $http_protocol = isset($_SERVER['HTTPS']) && !empty($_SERVER['HTTPS']) ? 'https' : 'http'; + $fake_pwd = $cfg->getRandomString(); + $cfg->switchToUser($http_protocol, $_SERVER['SERVER_NAME'], $_SERVER['SERVER_PORT'], $this->User->getName(), $fake_pwd); + } } ?> diff --git a/gui/baculum/themes/Baculum-v1/key.png b/gui/baculum/themes/Baculum-v1/key.png new file mode 100644 index 0000000000..9a261bb6ba Binary files /dev/null and b/gui/baculum/themes/Baculum-v1/key.png differ diff --git a/gui/baculum/themes/Baculum-v1/logo.png b/gui/baculum/themes/Baculum-v1/logo.png index f50c1ac025..83c53ceac5 100644 Binary files a/gui/baculum/themes/Baculum-v1/logo.png and b/gui/baculum/themes/Baculum-v1/logo.png differ diff --git a/gui/baculum/themes/Baculum-v1/logout.png b/gui/baculum/themes/Baculum-v1/logout.png new file mode 100644 index 0000000000..f7afdbf23e Binary files /dev/null and b/gui/baculum/themes/Baculum-v1/logout.png differ diff --git a/gui/baculum/themes/Baculum-v1/style.css b/gui/baculum/themes/Baculum-v1/style.css index ebab362029..57a0789bb7 100644 --- a/gui/baculum/themes/Baculum-v1/style.css +++ b/gui/baculum/themes/Baculum-v1/style.css @@ -99,6 +99,12 @@ a.big { float: left; } +#topbar { + background: transparent url('logo.png') no-repeat 10px center; + width: 100%; + height: 51px; +} + #logo { margin-left: 20px; } @@ -916,7 +922,7 @@ span.tab_active { background-color: rgb(163, 180, 197); } -#graphs, #dashboard { +#graphs, #dashboard, #users { min-width: 954px; max-width: 100%; padding: 10px; @@ -926,6 +932,12 @@ span.tab_active { border-right: 1px solid black; } +#users input { + height: 9px; + margin: 0 4px; + font-size: 10px; +} + #graphs span { margin: 0 3px; } @@ -999,8 +1011,42 @@ span.tab_active { } #jobs_to_view { - width: 240px; - margin: 0 2px 0 5px; + width: 240px; + margin: 0 2px 0 5px; +} + +#users_list { + width: 720px; + font-size: 13px; +} + +#users_list td { + font-style: normal; + padding: 3px 5px; +} + +#users_list td:nth-of-type(1) { + font-weight: bold; +} + +#users_list tr { + cursor: initial; +} + +#users_list td:nth-of-type(1) { + width: 200px; +} + +i#users_list td:nth-of-type(1) { + width: 120px; +} + +#users_list td:nth-of-type(3) { + width: 400px; +} + +#users_list img { + float: none; } /* Overwrite date picker classes */ diff --git a/gui/baculum/themes/Baculum-v1/user-del.png b/gui/baculum/themes/Baculum-v1/user-del.png new file mode 100644 index 0000000000..9725fd7c95 Binary files /dev/null and b/gui/baculum/themes/Baculum-v1/user-del.png differ diff --git a/gui/baculum/themes/Baculum-v1/users.png b/gui/baculum/themes/Baculum-v1/users.png new file mode 100644 index 0000000000..084629b862 Binary files /dev/null and b/gui/baculum/themes/Baculum-v1/users.png differ