'.jlist',
'.search',
'@putfile',
- 'cloud'
+ 'cloud',
+ 'time'
);
private $config;
--- /dev/null
+<?php
+/*
+ * Bacula(R) - The Network Backup Solution
+ * Baculum - Bacula web interface
+ *
+ * Copyright (C) 2013-2023 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.
+ */
+
+namespace Baculum\API\Modules;
+
+/**
+ * Time manager module.
+ *
+ * @author Marcin Haba <marcin.haba@bacula.pl>
+ * @category Module
+ * @package Baculum API
+ */
+class TimeManager extends APIModule {
+
+ /**
+ * Director time format.
+ * Example: '29-May-2023 09:01:34'.
+ */
+ const DIRECTOR_TIME_FORMAT = 'j-M-Y h:i:s';
+
+ /**
+ * Parse time returned by Director time command.
+ * It is in form: '29-May-2023 09:01:34'
+ * @TODO: Make sure that 'May' is always returned in English
+ *
+ * @param string date/time string from the Director
+ * @return array split date and time single values or empty array if error or warning happens
+ */
+ public function parseDirectorTime($time) {
+ list($dow, $date_time) = explode(' ', $time, 2);
+ $tres = date_parse_from_format(self::DIRECTOR_TIME_FORMAT, $date_time);
+ $ret = [];
+ if ($tres['warning_count'] === 0 && $tres['error_count'] === 0) {
+ $ret = [
+ 'year' => $tres['year'],
+ 'month' => $tres['month'],
+ 'day' => $tres['day'],
+ 'hour' => $tres['hour'],
+ 'minute' => $tres['minute'],
+ 'second' => $tres['second']
+ ];
+ }
+ return $ret;
+ }
+}
--- /dev/null
+<?php
+/*
+ * Bacula(R) - The Network Backup Solution
+ * Baculum - Bacula web interface
+ *
+ * Copyright (C) 2013-2023 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.
+ */
+
+use Baculum\Common\Modules\Errors\BconsoleError;
+use Baculum\Common\Modules\Errors\TimeError;
+
+/**
+ * Director time.
+ *
+ * @author Marcin Haba <marcin.haba@bacula.pl>
+ * @category API
+ * @package Baculum API
+ */
+class DirectorTime extends BaculumAPIServer {
+
+ public function get() {
+ $misc = $this->getModule('misc');
+ $director = $this->Request->contains('name') && $misc->isValidName($this->Request['name']) ? $this->Request['name'] : null;
+
+ $dirs = [];
+ $result = $this->getModule('bconsole')->getDirectors();
+ if ($result->exitcode === 0) {
+ $dirs = $result->output;
+ }
+
+ if (is_null($director) || !in_array($director, $dirs)) {
+ // Invalid director
+ $this->output = BconsoleError::MSG_ERROR_INVALID_DIRECTOR;
+ $this->error = BconsoleError::ERROR_INVALID_DIRECTOR;
+ return;
+ }
+
+ $result = $this->getModule('bconsole')->bconsoleCommand(
+ $director,
+ ['time'],
+ null,
+ true
+ );
+ if ($result->exitcode === 0) {
+ $result->output = array_filter($result->output);
+ if (count($result->output) == 1) {
+ $this->output = $this->getModule('time')->parseDirectorTime($result->output[0]);
+ if (count($this->output) > 0) {
+ $this->error = TimeError::ERROR_NO_ERRORS;
+ } else {
+ $this->output = TimeError::MSG_ERROR_INVALID_DATE_TIME . ' Output=>' . $result->output[0];
+ $this->error = TimeError::ERROR_INVALID_DATE_TIME;
+ }
+ } else {
+ $this->output = TimeError::MSG_ERROR_INVALID_DATE_TIME . ' Output=>' . implode('', $result->output);
+ $this->error = TimeError::ERROR_INVALID_DATE_TIME;
+ }
+ } else {
+ $this->output = TimeError::MSG_ERROR_WRONG_EXITCODE . ' Exitcode=' . $result->exitcode;
+ $this->error = TimeError::ERROR_WRONG_EXITCODE;
+ }
+ }
+}
<!-- bconsole command modules -->
<module id="ls" class="Baculum\API\Modules\Ls" />
<module id="list" class="Baculum\API\Modules\BList" />
+ <module id="time" class="Baculum\API\Modules\TimeManager" />
<!-- changer command modules -->
<module id="changer_command" class="Baculum\API\Modules\ChangerCommand" />
<!-- plugin modules -->
<!-- director endpoints -->
<url ServiceParameter="DirectorShow" pattern="api/v2/directors/{name}/show/" parameters.name="[a-zA-Z0-9:.\-_ ]+" />
<url ServiceParameter="DirectorStatus" pattern="api/v2/directors/{name}/status/" parameters.name="[a-zA-Z0-9:.\-_ ]+" />
+ <url ServiceParameter="DirectorTime" pattern="api/v2/directors/{name}/time/" parameters.name="[a-zA-Z0-9:.\-_ ]+" />
<!-- actions endpoints -->
<url ServiceParameter="Actions" pattern="api/v2/actions/{component}/{action}/" parameters.component="(director|storage|client)" parameters.action="(start|stop|restart)" />
<!-- OAuth2 client endpoints -->
]
}
},
+ "/api/v2/directors/{director_name}/time": {
+ "get": {
+ "tags": ["directors"],
+ "summary": "Get director system time",
+ "description": "Get director system time",
+ "responses": {
+ "200": {
+ "description": "Director system time",
+ "content": {
+ "application/json": {
+ "schema": {
+ "type": "object",
+ "properties": {
+ "output": {
+ "type": "object",
+ "properties": {
+ "year": {
+ "description": "Four digit year",
+ "type": "integer"
+ },
+ "month": {
+ "description": "Month (1-12)",
+ "type": "integer"
+ },
+ "day": {
+ "description": "Day (1-31)",
+ "type": "integer"
+ },
+ "hour": {
+ "description": "Hour (0-23)",
+ "type": "integer"
+ },
+ "minute": {
+ "description": "Minute (0-59)",
+ "type": "integer"
+ },
+ "second": {
+ "description": "Second (0-59)",
+ "type": "integer"
+ }
+ }
+ },
+ "error": {
+ "type": "integer",
+ "description": "Error code",
+ "enum": [0, 1, 2, 3, 4, 5, 6, 7, 9, 11, 530, 1000]
+ }
+ }
+ }
+ }
+ }
+ }
+ },
+ "parameters": [
+ {
+ "name": "director_name",
+ "in": "path",
+ "description": "Director name",
+ "required": true,
+ "schema": {
+ "type": "string"
+ }
+ }
+ ]
+ }
+ },
"/api/v2/oauth2/clients": {
"get": {
"tags": ["oauth2"],
--- /dev/null
+<?php
+/*
+ * Bacula(R) - The Network Backup Solution
+ * Baculum - Bacula web interface
+ *
+ * Copyright (C) 2013-2023 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.
+ */
+
+namespace Baculum\Common\Modules\Errors;
+
+/**
+ * Time error class.
+ *
+ * @author Marcin Haba <marcin.haba@bacula.pl>
+ * @category Errors
+ * @package Baculum Common
+ */
+class TimeError extends GenericError {
+ const ERROR_INVALID_DATE_TIME = 530;
+
+ const MSG_ERROR_INVALID_DATE_TIME = 'Invalid date/time value.';
+}