* Bacula(R) - The Network Backup Solution
* Baculum - Bacula web interface
*
- * Copyright (C) 2013-2018 Kern Sibbald
+ * Copyright (C) 2013-2019 Kern Sibbald
*
* The main author of Baculum is Marcin Haba.
* The original author of Bacula is Kern Sibbald, with contributions
'.pool',
'.schedule',
'.api',
- '.status'
+ '.status',
+ '.ls'
);
private $config;
--- /dev/null
+<?php
+/*
+ * Bacula(R) - The Network Backup Solution
+ * Baculum - Bacula web interface
+ *
+ * Copyright (C) 2013-2019 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('Application.API.Class.APIModule');
+
+class Ls extends APIModule {
+ const LS_OUTPUT_PATTERN = '/^(?P<perm>[a-z\-\.]+)\s+(?P<nb_hardlink>\d+)\s+(?P<owner>\w+)\s+(?P<group>\w+)\s+(?P<size>\d+)\s+(?P<mtime>[\d\-]+\s+[\d:]+)\s+(?P<item>(?U:[\S\s]+))(?P<dest>(?(?=\s+\-\>\s+)[\S\s]*))$/i';
+
+ public function parseOutput(array $output) {
+ $result = array();
+ for ($i = 0; $i < count($output); $i++) {
+ if (preg_match(self::LS_OUTPUT_PATTERN, $output[$i], $match) === 1) {
+ $type = substr($match['perm'], 0, 1);
+ $result[] = array(
+ 'perm' => $match['perm'],
+ 'nb_hardlink' => intval($match['nb_hardlink']),
+ 'owner' => $match['owner'],
+ 'group' => $match['group'],
+ 'size' => intval($match['size']),
+ 'mtime' => $match['mtime'],
+ 'item' => $match['item'],
+ 'type' => $type,
+ 'dest' => key_exists('dest', $match) ? $match['dest'] : null
+ );
+ }
+ }
+ return $result;
+ }
+}
+?>
--- /dev/null
+<?php
+/*
+ * Bacula(R) - The Network Backup Solution
+ * Baculum - Bacula web interface
+ *
+ * Copyright (C) 2013-2019 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.
+ */
+
+class ClientLs extends BaculumAPIServer {
+
+ public function get() {
+ $clientid = $this->Request->contains('id') ? intval($this->Request['id']) : 0;
+ $client = null;
+ $cli = null;
+ if ($clientid > 0) {
+ $cli = $this->getModule('client')->getClientById($clientid);
+ }
+
+ $result = $this->getModule('bconsole')->bconsoleCommand($this->director, array('.client'));
+ if ($result->exitcode === 0) {
+ array_shift($result->output);
+ if(is_object($cli) && in_array($cli->name, $result->output)) {
+ $client = $cli->name;
+ }
+ }
+ if (is_null($client)) {
+ $this->output = ClientError::MSG_ERROR_CLIENT_DOES_NOT_EXISTS;
+ $this->error = ClientError::ERROR_CLIENT_DOES_NOT_EXISTS;
+ return;
+ }
+
+ $path = $this->Request->contains('path') && $this->getModule('misc')->isValidPath($this->Request['path']) ? $this->Request['path'] : null;
+
+ if (is_null($path)) {
+ $this->output = GenericError::MSG_ERROR_INVALID_PATH;
+ $this->error = GenericError::ERROR_INVALID_PATH;
+ return;
+ }
+
+ $cmd = array('.ls', 'client="' . $client . '"', 'path="' . $path . '"');
+ $result = $this->getModule('bconsole')->bconsoleCommand($this->director, $cmd);
+ if ($result->exitcode === 0) {
+ $ls = $this->getModule('ls')->parseOutput($result->output);
+ $this->output = $ls;
+ $this->error = GenericError::ERROR_NO_ERRORS;
+ }
+ }
+}
+?>
<!-- component status modules -->
<module id="status_dir" class="Application.API.Class.StatusDirector" />
<module id="status_sd" class="Application.API.Class.StatusStorage" />
+ <!-- misc modules -->
+ <module id="ls" class="Application.API.Class.Ls" />
</modules>
</configuration>
<url ServiceParameter="API.ClientShow" pattern="api/v1/clients/{id}/show/" parameters.id="\d+" />
<url ServiceParameter="API.ClientStatus" pattern="api/v1/clients/{id}/status/" parameters.id="\d+" />
<url ServiceParameter="API.JobsForClient" pattern="api/v1/clients/{id}/jobs/" parameters.id="\d+" />
+ <url ServiceParameter="API.ClientLs" pattern="api/v1/clients/{id}/ls/" parameters.id="\d+" />
<!-- storages (storage daemons) endpoints -->
<url ServiceParameter="API.Storages" pattern="api/v1/storages/" />
<url ServiceParameter="API.Storage" pattern="api/v1/storages/{id}/" parameters.id="\d+" />
* Bacula(R) - The Network Backup Solution
* Baculum - Bacula web interface
*
- * Copyright (C) 2013-2018 Kern Sibbald
+ * Copyright (C) 2013-2019 Kern Sibbald
*
* The main author of Baculum is Marcin Haba.
* The original author of Bacula is Kern Sibbald, with contributions
const ERROR_NO_ERRORS = 0;
const ERROR_INVALID_COMMAND = 1;
const ERROR_INTERNAL_ERROR = 1000;
+ const ERROR_INVALID_PATH = 8;
const MSG_ERROR_NO_ERRORS = '';
const MSG_ERROR_INVALID_COMMAND = 'Invalid command.';
const MSG_ERROR_INTERNAL_ERROR = 'Internal error.';
+ const MSG_ERROR_INVALID_PATH = 'Invalid path.';
}
class DatabaseError extends GenericError {