return $is_valid;
}
+ /**
+ * Get users.
+ * NOTE: User list bases on basic password file.
+ * @see BasicAPIUserConfig
+ *
+ * @return array basic user list
+ */
+ public function getUsers() {
+ $basic_users = [];
+ $basic_apiuser = $this->getModule('basic_apiuser')->getUsers();
+ $basic_config = $this->getConfig();
+ foreach($basic_apiuser as $user => $pwd) {
+ $bconsole_cfg_path = '';
+ if (key_exists($user, $basic_config) && key_exists('bconsole_cfg_path', $basic_config[$user])) {
+ $bconsole_cfg_path = $basic_config[$user]['bconsole_cfg_path'];
+ }
+ $basic_users[] = [
+ 'username' => $user,
+ 'bconsole_cfg_path' => $bconsole_cfg_path
+ ];
+ }
+ return $basic_users;
+
+ }
+
/**
* Add single basic user to config.
* NOTE: Basic password hashes are stored in separate file.
* @return boolean true on success, otherwise false
*/
public function removeUser($username) {
- $success = false;
$config = $this->getConfig();
if (key_exists($username, $config)) {
unset($config[$username]);
- $success = $this->setConfig($config);
- }
- if ($success) {
- $success = $this->getModule('basic_apiuser')->removeUser($username);
+ $this->setConfig($config);
}
+ /**
+ * There is returned only state of removing user from password file because
+ * because user can be defined in password file but it does not have
+ * to be defined in basic.conf file. It is for backward compatibility
+ * with config files.
+ */
+ $success = $this->getModule('basic_apiuser')->removeUser($username);
return $success;
}
}
msgid "Configs:"
msgstr "Configs:"
+
+msgid "Dedicated Bconsole config"
+msgstr "Dedicated Bconsole config"
msgid "Configs:"
msgstr "Pliki konfig.:"
+
+msgid "Dedicated Bconsole config"
+msgstr "Dedykowana konfiguracja Bconsole"
msgid "Configs:"
msgstr "Configurações:"
+
+msgid "Dedicated Bconsole config"
+msgstr "Dedicated Bconsole config"
msgid "Configs:"
msgstr "Настройка:"
+
+msgid "Dedicated Bconsole config"
+msgstr "Dedicated Bconsole config"
--- /dev/null
+<?php
+/*
+ * Bacula(R) - The Network Backup Solution
+ * Baculum - Bacula web interface
+ *
+ * Copyright (C) 2013-2021 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.
+ */
+
+/**
+ * Basic user endpoint.
+ *
+ * @author Marcin Haba <marcin.haba@bacula.pl>
+ * @category API
+ * @package Baculum API
+ */
+class BasicUser extends BaculumAPIServer {
+
+ public function get() {
+ $user = $this->Request->contains('id') ? $this->Request['id'] : 0;
+ $username = $this->getModule('basic_apiuser')->validateUsername($user) ? $user : null;
+ if (is_string($username)) {
+ $basic_config = $this->getModule('basic_config')->getConfig($username);
+ if (count($basic_config) > 0) {
+ $this->output = array_merge($basic_config, ['username' => $username]);
+ $this->error = BasicUserError::ERROR_NO_ERRORS;
+ } else {
+ $this->output = BasicUserError::MSG_ERROR_BASIC_USER_DOES_NOT_EXIST;
+ $this->error = BasicUserError::ERROR_BASIC_USER_DOES_NOT_EXIST;
+ }
+ } else {
+ $this->output = BasicUserError::MSG_ERROR_BASIC_USER_INVALID_USERNAME;
+ $this->error = BasicUserError::ERROR_BASIC_USER_INVALID_USERNAME;
+ }
+ }
+
+ public function create($params) {
+ $basic_apiuser = $this->getModule('basic_apiuser');
+ $basic_config = $this->getModule('basic_config');
+ $misc = $this->getModule('misc');
+ $basic_cfg = $basic_apiuser->getUsers();
+ $username = '';
+ $password = '';
+ $props = [];
+
+ if (property_exists($params, 'username') && key_exists($params->username, $basic_cfg)) {
+ $this->output = BasicUserError::MSG_ERROR_BASIC_USER_ALREADY_EXISTS;
+ $this->error = BasicUserError::ERROR_BASIC_USER_ALREADY_EXISTS;
+ return;
+ }
+
+ if (property_exists($params, 'username') && $basic_apiuser->validateUsername($params->username)) {
+ $username = $params->username;
+ } else {
+ $this->output = BasicUserError::MSG_ERROR_BASIC_USER_INVALID_USERNAME;
+ $this->error = BasicUserError::ERROR_BASIC_USER_INVALID_USERNAME;
+ return;
+ }
+
+ if (property_exists($params, 'password')) {
+ $password = $params->password;
+ } else {
+ $this->output = BasicUserError::MSG_ERROR_BASIC_USER_INVALID_PASSWORD;
+ $this->error = BasicUserError::ERROR_BASIC_USER_INVALID_PASSWORD;
+ return;
+ }
+
+ if (property_exists($params, 'bconsole_cfg_path')) {
+ if ($misc->isValidPath($params->bconsole_cfg_path)) {
+ $props['bconsole_cfg_path'] = $params->bconsole_cfg_path;
+ } else {
+ $this->output = BasicUserError::MSG_ERROR_BASIC_USER_INVALID_BCONSOLE_CFG_PATH;
+ $this->error = BasicUserError::ERROR_BASIC_USER_INVALID_BCONSOLE_CFG_PATH;
+ return;
+ }
+ } else {
+ $props['bconsole_cfg_path'] = '';
+ }
+
+ if (property_exists($params, 'console') && property_exists($params, 'director')) {
+ if (!$misc->isValidName($params->console)) {
+ $this->output = BasicUserError::MSG_ERROR_BASIC_USER_INVALID_CONSOLE;
+ $this->error = BasicUserError::ERROR_BASIC_USER_INVALID_CONSOLE;
+ return;
+ }
+ if (!$misc->isValidName($params->director)) {
+ $this->output = BasicUserError::MSG_ERROR_BASIC_USER_INVALID_DIRECTOR;
+ $this->error = BasicUserError::ERROR_BASIC_USER_INVALID_DIRECTOR;
+ return;
+ }
+ $bs = $this->getModule('bacula_setting');
+
+ $dir_cfg = $bs->getConfig('bcons', 'Director', $params->director);
+ if ($dir_cfg['exitcode'] != 0) {
+ $this->output = $dir_cfg['output'];
+ $this->error = BasicUserError::ERROR_INTERNAL_ERROR;
+ return;
+ }
+
+ $console_cfg = $bs->getConfig('dir', 'Console', $params->console);
+ if ($console_cfg['exitcode'] != 0) {
+ $this->output = $console_cfg['output'];
+ $this->error = BasicUserError::ERROR_INTERNAL_ERROR;
+ return;
+ }
+
+ $cfg = [
+ [
+ 'Director' => [
+ 'Name' => '"' . $dir_cfg['output']['Name'] . '"',
+ 'DirPort' => $dir_cfg['output']['DirPort'],
+ 'Address' => $dir_cfg['output']['Address'],
+ 'Password' => 'XXXX'
+ ],
+ 'Console' => [
+ 'Name' => '"' . $console_cfg['output']['Name'] . '"',
+ 'Password' => '"' . $console_cfg['output']['Password'] . '"'
+ ]
+ ]
+ ];
+ $json_tools = $this->getModule('api_config')->getConfig('jsontools');
+ $dir = $json_tools['bconfig_dir'];
+ $file = sprintf('%s/bconsole-%s.cfg', $dir, $console_cfg['output']['Name']);
+ $this->getModule('bacula_config')->setConfig('bcons', $cfg, $file);
+ $props['bconsole_cfg_path'] = $file;
+ }
+
+ // save config
+ $result = $basic_config->addUser($username, $password, $props);
+
+ if ($result) {
+ $this->output = $props;
+ $this->error = BasicUserError::ERROR_NO_ERRORS;
+ } else {
+ $this->output = BasicUserError::MSG_ERROR_INTERNAL_ERROR;
+ $this->error = BasicUserError::ERROR_INTERNAL_ERROR;
+ }
+ }
+
+ public function set($id, $params) {
+ $basic_apiuser = $this->getModule('basic_apiuser');
+ $basic_config = $this->getModule('basic_config');
+ $misc = $this->getModule('misc');
+ $basic_cfg = $basic_apiuser->getUsers();
+ $username = '';
+ $password = '';
+ $props = [];
+
+ if (property_exists($params, 'username') && !key_exists($params->username, $basic_cfg)) {
+ $this->output = BasicUserError::MSG_ERROR_BASIC_USER_DOES_NOT_EXIST;
+ $this->error = BasicUserError::ERROR_BASIC_USER_DOES_NOT_EXIST;
+ return;
+ }
+
+ if (property_exists($params, 'username') && $basic_apiuser->validateUsername($params->username)) {
+ $username = $params->username;
+ } else {
+ $this->output = BasicUserError::MSG_ERROR_BASIC_USER_INVALID_USERNAME;
+ $this->error = BasicUserError::ERROR_BASIC_USER_INVALID_USERNAME;
+ return;
+ }
+
+ if (property_exists($params, 'password')) {
+ $password = $params->password;
+ } else {
+ $this->output = BasicUserError::MSG_ERROR_BASIC_USER_INVALID_PASSWORD;
+ $this->error = BasicUserError::ERROR_BASIC_USER_INVALID_PASSWORD;
+ return;
+ }
+
+ if (property_exists($params, 'bconsole_cfg_path')) {
+ if ($misc->isValidPath($params->bconsole_cfg_path)) {
+ $props['bconsole_cfg_path'] = $params->bconsole_cfg_path;
+ } else {
+ $this->output = BasicUserError::MSG_ERROR_BASIC_USER_INVALID_BCONSOLE_CFG_PATH;
+ $this->error = BasicUserError::ERROR_BASIC_USER_INVALID_BCONSOLE_CFG_PATH;
+ return;
+ }
+ } else {
+ $props['bconsole_cfg_path'] = '';
+ }
+
+ if (property_exists($params, 'console') && property_exists($params, 'director')) {
+ if (!$misc->isValidName($params->console)) {
+ $this->output = BasicUserError::MSG_ERROR_BASIC_USER_INVALID_CONSOLE;
+ $this->error = BasicUserError::ERROR_BASIC_USER_INVALID_CONSOLE;
+ return;
+ }
+ if (!$misc->isValidName($params->director)) {
+ $this->output = BasicUserError::MSG_ERROR_BASIC_USER_INVALID_DIRECTOR;
+ $this->error = BasicUserError::ERROR_BASIC_USER_INVALID_DIRECTOR;
+ return;
+ }
+ $bs = $this->getModule('bacula_setting');
+
+ $dir_cfg = $bs->getConfig('bcons', 'Director', $params->director);
+ if ($dir_cfg['exitcode'] != 0) {
+ $this->output = $dir_cfg['output'];
+ $this->error = BasicUserError::ERROR_INTERNAL_ERROR;
+ return;
+ }
+
+ $console_cfg = $bs->getConfig('dir', 'Console', $params->console);
+ if ($console_cfg['exitcode'] != 0) {
+ $this->output = $console_cfg['output'];
+ $this->error = BasicUserError::ERROR_INTERNAL_ERROR;
+ return;
+ }
+
+ $cfg = [
+ [
+ 'Director' => [
+ 'Name' => '"' . $dir_cfg['output']['Name'] . '"',
+ 'DirPort' => $dir_cfg['output']['DirPort'],
+ 'Address' => $dir_cfg['output']['Address'],
+ 'Password' => 'XXXX'
+ ],
+ 'Console' => [
+ 'Name' => '"' . $console_cfg['output']['Name'] . '"',
+ 'Password' => '"' . $console_cfg['output']['Password'] . '"'
+ ]
+ ]
+ ];
+ $json_tools = $this->getModule('api_config')->getConfig('jsontools');
+ $dir = $json_tools['bconfig_dir'];
+ $file = sprintf('%s/bconsole-%s.cfg', $dir, $console_cfg['output']['Name']);
+ $this->getModule('bacula_config')->setConfig('bcons', $cfg, $file);
+ $props['bconsole_cfg_path'] = $file;
+ }
+
+ // save config
+ $result = $basic_config->editUser($username, $password, $props);
+
+ if ($result) {
+ $this->output = $props;
+ $this->error = BasicUserError::ERROR_NO_ERRORS;
+ } else {
+ $this->output = BasicUserError::MSG_ERROR_INTERNAL_ERROR;
+ $this->error = BasicUserError::ERROR_INTERNAL_ERROR;
+ }
+ }
+
+ public function remove($id) {
+ $user_cfg = $this->getModule('basic_apiuser')->getUserCfg($id);
+ if (count($user_cfg) > 0) {
+ $result = $this->getModule('basic_config')->removeUser($id);
+ if ($result) {
+ $this->output = [];
+ $this->error = BasicUserError::ERROR_NO_ERRORS;
+ } else {
+ $this->output = BasicUserError::MSG_ERROR_INTERNAL_ERROR;
+ $this->error = BasicUserError::ERROR_INTERNAL_ERROR;
+ }
+ } else {
+ $this->output = BasicUserError::MSG_ERROR_BASIC_USER_DOES_NOT_EXIST;
+ $this->error = BasicUserError::ERROR_BASIC_USER_DOES_NOT_EXIST;
+ }
+ }
+}
+?>
--- /dev/null
+<?php
+/*
+ * Bacula(R) - The Network Backup Solution
+ * Baculum - Bacula web interface
+ *
+ * Copyright (C) 2013-2021 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.
+ */
+
+/**
+ * Basic users endpoint.
+ *
+ * @author Marcin Haba <marcin.haba@bacula.pl>
+ * @category API
+ * @package Baculum API
+ */
+class BasicUsers extends BaculumAPIServer {
+
+ public function get() {
+ $this->output = $this->getModule('basic_config')->getUsers();;
+ $this->error = ClientError::ERROR_NO_ERRORS;
+ }
+}
+?>
* Bacula(R) - The Network Backup Solution
* Baculum - Bacula web interface
*
- * Copyright (C) 2013-2020 Kern Sibbald
+ * Copyright (C) 2013-2021 Kern Sibbald
*
* The main author of Baculum is Marcin Haba.
* The original author of Bacula is Kern Sibbald, with contributions
$dir_cfg = $bs->getConfig('bcons', 'Director', $params->director);
if ($dir_cfg['exitcode'] != 0) {
- $this->output = $dir_cfg->output;
+ $this->output = $dir_cfg['output'];
$this->error = OAuth2Error::ERROR_INTERNAL_ERROR;
return;
}
$console_cfg = $bs->getConfig('dir', 'Console', $params->console);
if ($console_cfg['exitcode'] != 0) {
- $this->output = $console_cfg->output;
+ $this->output = $console_cfg['output'];
$this->error = OAuth2Error::ERROR_INTERNAL_ERROR;
return;
}
$dir_cfg = $bs->getConfig('bcons', 'Director', $params->director);
if ($dir_cfg['exitcode'] != 0) {
- $this->output = $dir_cfg->output;
+ $this->output = $dir_cfg['output'];
$this->error = OAuth2Error::ERROR_INTERNAL_ERROR;
return;
}
$console_cfg = $bs->getConfig('dir', 'Console', $params->console);
if ($console_cfg['exitcode'] != 0) {
- $this->output = $console_cfg->output;
+ $this->output = $console_cfg['output'];
$this->error = OAuth2Error::ERROR_INTERNAL_ERROR;
return;
}
<module id="oauth2_token" class="Application.API.Class.OAuth2.TokenManager" />
<!-- Basic user config -->
+ <module id="basic_apiuser" class="Application.API.Class.BasicAPIUserConfig" />
<module id="basic_config" class="Application.API.Class.BasicConfig" />
<!-- API Server modules -->
<!-- OAuth2 client endpoints -->
<url ServiceParameter="OAuth2Clients" pattern="api/v2/oauth2/clients/" />
<url ServiceParameter="OAuth2Client" pattern="api/v2/oauth2/clients/{id}/" parameters.id="[a-zA-Z0-9\-_]{32}" />
+ <!-- Basic user endpoints -->
+ <url ServiceParameter="BasicUsers" pattern="api/v2/basic/users/" />
+ <url ServiceParameter="BasicUser" pattern="api/v2/basic/users/{id}/" parameters.id="[a-zA-Z0-9]+" />
<!-- API v1 -->
<!-- general endpoint -->
}
public function loadBasicUsers($sender, $param) {
- $users = $this->getBasicUsers();
+ $users = $this->getModule('basic_config')->getUsers();
$this->getCallbackClient()->callClientFunction(
'oAPIBasicUsers.load_basic_users_cb',
[$users]
}
}
- private function getBasicUsers() {
- $basic_users = array();
- $basic_apiuser = $this->getModule('basic_apiuser')->getUsers();
- $basic_config = $this->getModule('basic_config')->getConfig();
- foreach($basic_apiuser as $user => $pwd) {
- $bconsole_cfg_path = '';
- if (key_exists($user, $basic_config) && key_exists('bconsole_cfg_path', $basic_config[$user])) {
- $bconsole_cfg_path = $basic_config[$user]['bconsole_cfg_path'];
- }
- $basic_users[] = [
- 'username' => $user,
- 'bconsole_cfg_path' => $bconsole_cfg_path
- ];
- }
- return $basic_users;
- }
-
public function deleteBasicUser($sender, $param) {
$username = $param->getCallbackParameter();
$this->getModule('basic_config')->removeUser($username);
"OAuth2Client": {
"$ref": "#/definitions/OAuth2Client"
},
+ "BasicUsers": {
+ "type": "array",
+ "items": {
+ "$ref": "#/definitions/BasicUser"
+ }
+ },
+ "BasicUser": {
+ "$ref": "#/definitions/BasicUser"
+ },
"AutochangerDriveVolume": {
"$ref": "#/definitions/AutochangerDriveVolume"
},
"type": "string"
}
},
+ {
+ "name": "console",
+ "in": "body",
+ "required": false,
+ "description": "Director Console name to create dedicated bconsole.conf that is assigned to account. Parameter must be used together with 'director' parameter.",
+ "schema": {
+ "type": "string"
+ }
+ },
+ {
+ "name": "director",
+ "in": "body",
+ "required": false,
+ "description": "Director Name to create dedicated bconsole.conf that is assigned to account. Parameter must be used together with 'console' parameter.",
+ "schema": {
+ "type": "string"
+ }
+ },
{
"name": "name",
"in": "body",
"type": "string"
}
},
+ {
+ "name": "console",
+ "in": "body",
+ "required": false,
+ "description": "Director Console name to create dedicated bconsole.conf that is assigned to account. Parameter must be used together with 'director' parameter.",
+ "schema": {
+ "type": "string"
+ }
+ },
+ {
+ "name": "director",
+ "in": "body",
+ "required": false,
+ "description": "Director Name to create dedicated bconsole.conf that is assigned to account. Parameter must be used together with 'console' parameter.",
+ "schema": {
+ "type": "string"
+ }
+ },
{
"name": "name",
"in": "body",
}
]
}
+ },
+ "/api/v2/basic/users": {
+ "get": {
+ "tags": ["basic"],
+ "summary": "Basic user list",
+ "description": "Get Basic user list.",
+ "responses": {
+ "200": {
+ "description": "List of Basic users properties",
+ "content": {
+ "application/json": {
+ "schema": {
+ "type": "object",
+ "properties": {
+ "output": {
+ "$ref": "#/components/schemas/BasicUsers"
+ },
+ "error": {
+ "type": "integer",
+ "description": "Error code",
+ "enum": [0, 1000]
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ },
+ "/api/v2/basic/users/{username}": {
+ "get": {
+ "tags": ["basic"],
+ "summary": "Specific Basic user config",
+ "description": "Get specific Basic user config",
+ "responses": {
+ "200": {
+ "description": "Specific Basic user config",
+ "content": {
+ "application/json": {
+ "schema": {
+ "type": "object",
+ "properties": {
+ "output": {
+ "$ref": "#/components/schemas/BasicUser"
+ },
+ "error": {
+ "type": "integer",
+ "description": "Error code",
+ "enum": [0, 140, 142, 1000]
+ }
+ }
+ }
+ }
+ }
+ }
+ },
+ "parameters": [
+ {
+ "name": "username",
+ "in": "path",
+ "required": true,
+ "description": "Basic user name",
+ "schema": {
+ "type": "string"
+ }
+ }
+ ]
+ },
+ "put": {
+ "tags": ["basic"],
+ "summary": "Set Basic user settings",
+ "description": "Set specific Basic user settings",
+ "consumes": [ "application/json" ],
+ "responses": {
+ "200": {
+ "description": "Set Basic user settings",
+ "content": {
+ "application/json": {
+ "schema": {
+ "type": "object",
+ "properties": {
+ "output": {
+ "type": "object",
+ "description": "Updated Basic user settings"
+ },
+ "error": {
+ "type": "integer",
+ "description": "Error code",
+ "enum": [0, 140, 142, 143, 144, 145, 146, 1000]
+ }
+ }
+ }
+ }
+ }
+ }
+ },
+ "parameters": [
+ {
+ "name": "username",
+ "in": "path",
+ "required": true,
+ "description": "Basic user name",
+ "schema": {
+ "type": "string"
+ }
+ },
+ {
+ "name": "password",
+ "in": "body",
+ "required": false,
+ "description": "Basic user password",
+ "schema": {
+ "type": "string"
+ }
+ },
+ {
+ "name": "bconsole_cfg_path",
+ "in": "body",
+ "required": false,
+ "description": "Dedicated Bconsole configuration file path",
+ "schema": {
+ "type": "string"
+ }
+ },
+ {
+ "name": "console",
+ "in": "body",
+ "required": false,
+ "description": "Director Console name to create dedicated bconsole.conf that is assigned to account. Parameter must be used together with 'director' parameter.",
+ "schema": {
+ "type": "string"
+ }
+ },
+ {
+ "name": "director",
+ "in": "body",
+ "required": false,
+ "description": "Director Name to create dedicated bconsole.conf that is assigned to account. Parameter must be used together with 'console' parameter.",
+ "schema": {
+ "type": "string"
+ }
+ }
+ ]
+ },
+ "post": {
+ "tags": ["basic"],
+ "summary": "Create Basic user account",
+ "description": "Create specific Basic user account",
+ "consumes": [ "application/json" ],
+ "responses": {
+ "200": {
+ "description": "Create Basic user account",
+ "content": {
+ "application/json": {
+ "schema": {
+ "type": "object",
+ "properties": {
+ "output": {
+ "type": "object",
+ "description": "New Basic user settings"
+ },
+ "error": {
+ "type": "integer",
+ "description": "Error code",
+ "enum": [0, 141, 142, 143, 144, 145, 146, 1000]
+ }
+ }
+ }
+ }
+ }
+ }
+ },
+ "parameters": [
+ {
+ "name": "username",
+ "in": "path",
+ "required": true,
+ "description": "Basic user name",
+ "schema": {
+ "type": "string"
+ }
+ },
+ {
+ "name": "password",
+ "in": "body",
+ "required": true,
+ "description": "Basic user password",
+ "schema": {
+ "type": "string"
+ }
+ },
+ {
+ "name": "bconsole_cfg_path",
+ "in": "body",
+ "required": false,
+ "description": "Dedicated Bconsole configuration file path",
+ "schema": {
+ "type": "string"
+ }
+ },
+ {
+ "name": "console",
+ "in": "body",
+ "required": false,
+ "description": "Director Console name to create dedicated bconsole.conf that is assigned to account. Parameter must be used together with 'director' parameter.",
+ "schema": {
+ "type": "string"
+ }
+ },
+ {
+ "name": "director",
+ "in": "body",
+ "required": false,
+ "description": "Director Name to create dedicated bconsole.conf that is assigned to account. Parameter must be used together with 'console' parameter.",
+ "schema": {
+ "type": "string"
+ }
+ }
+ ]
+ },
+ "delete": {
+ "tags": ["basic"],
+ "summary": "Delete Basic user account",
+ "description": "Delete Basic user account.",
+ "responses": {
+ "200": {
+ "description": "Delete Basic user account",
+ "content": {
+ "application/json": {
+ "schema": {
+ "type": "object",
+ "properties": {
+ "output": {
+ "type": "array",
+ "items": {
+ }
+ },
+ "error": {
+ "type": "integer",
+ "description": "Error code",
+ "enum": [0, 140, 1000]
+ }
+ }
+ }
+ }
+ }
+ }
+ },
+ "parameters": [
+ {
+ "name": "username",
+ "in": "path",
+ "required": true,
+ "description": "Basic user name",
+ "schema": {
+ "type": "string"
+ }
+ }
+ ]
+ }
}
},
"definitions": {
}
}
},
+ "BasicUser": {
+ "type": "object",
+ "properties": {
+ "bconsole_cfg_path": {
+ "description": "Dedicated Bconsole configuration file",
+ "type": "string"
+ },
+ "username": {
+ "description": "User login name",
+ "type": "string"
+ }
+ }
+ },
"AutochangerDriveVolume": {
"type": "object",
"properties": {
* Bacula(R) - The Network Backup Solution
* Baculum - Bacula web interface
*
- * Copyright (C) 2013-2020 Kern Sibbald
+ * Copyright (C) 2013-2021 Kern Sibbald
*
* The main author of Baculum is Marcin Haba.
* The original author of Bacula is Kern Sibbald, with contributions
*/
const USER_PATTERN = '[a-zA-Z0-9]+';
+ /**
+ * Password allowed characters pattern.
+ */
+ const PASSWORD_PATTERN = '[\S\s]{5,60}';
+
/**
* Get config file path to store users' parameters.
* @return string config path
* @return boolean true if users removed successfully, otherwise false
*/
public function removeUsers(array $usernames) {
- $result = false;
$all_users = $this->getUsers();
for ($i = 0; $i < count($usernames); $i++) {
if (key_exists($usernames[$i], $all_users)) {
$result = file_put_contents($this->getConfigPath(), '', LOCK_EX) !== false;
return $result;
}
+
+ public function validateUsername($username) {
+ return (preg_match('/^' . self::USER_PATTERN . '$/', $username) === 1);
+ }
}
* Bacula(R) - The Network Backup Solution
* Baculum - Bacula web interface
*
- * Copyright (C) 2013-2020 Kern Sibbald
+ * Copyright (C) 2013-2021 Kern Sibbald
*
* The main author of Baculum is Marcin Haba.
* The original author of Bacula is Kern Sibbald, with contributions
const MSG_ERROR_DEVICE_DRIVE_DOES_NOT_BELONG_TO_AUTOCHANGER = 'Drive does not belong to selected autochanger.';
}
+class BasicUserError extends GenericError {
+
+ const ERROR_BASIC_USER_DOES_NOT_EXIST = 140;
+ const ERROR_BASIC_USER_ALREADY_EXISTS = 141;
+ const ERROR_BASIC_USER_INVALID_USERNAME = 142;
+ const ERROR_BASIC_USER_INVALID_BCONSOLE_CFG_PATH = 143;
+ const ERROR_BASIC_USER_INVALID_CONSOLE = 144;
+ const ERROR_BASIC_USER_INVALID_DIRECTOR = 145;
+ const ERROR_BASIC_USER_INVALID_PASSWORD= 146;
+
+ const MSG_ERROR_BASIC_USER_DOES_NOT_EXIST = 'Basic user does not exist.';
+ const MSG_ERROR_BASIC_USER_ALREADY_EXISTS = 'Basic user already exists.';
+ const MSG_ERROR_BASIC_USER_INVALID_USERNAME = 'Invalid basic user username';
+ const MSG_ERROR_BASIC_USER_INVALID_BCONSOLE_CFG_PATH = 'Invalid bconsole config path.';
+ const MSG_ERROR_BASIC_USER_INVALID_CONSOLE = 'Invalid Console name.';
+ const MSG_ERROR_BASIC_USER_INVALID_DIRECTOR = 'Invalid Director name.';
+ const MSG_ERROR_BASIC_USER_INVALID_PASSWORD = 'Invalid password.';
+}
?>
Display="Dynamic"
ControlCssClass="invalidate"
ControlToValidate="APIBasicPassword"
- RegularExpression="[\S\s]{5,60}"
+ RegularExpression="<%=BasicUserConfig::PASSWORD_PATTERN%>"
ValidationGroup="<%=$this->ClientID%>Basic"
Text="<%[ Password must be longer than 4 chars. ]%>"
/>
Display="Dynamic"
ControlCssClass="invalidate"
ControlToValidate="RetypeAPIBasicPassword"
- RegularExpression="[\S\s]{5,60}"
+ RegularExpression="<%=BasicUserConfig::PASSWORD_PATTERN%>"
ValidationGroup="<%=$this->ClientID%>Basic"
Text="<%[ Password must be longer than 4 chars. ]%>"
/>