From: Marcin Haba Date: Sun, 4 Jul 2021 19:05:00 +0000 (+0200) Subject: baculum: Add director show command API endpoint X-Git-Tag: Release-11.3.2~205 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6845ff74bc376c017d7da6bb1bed0312be22ff9c;p=thirdparty%2Fbacula.git baculum: Add director show command API endpoint --- diff --git a/gui/baculum/protected/API/Pages/API/DirectorShow.php b/gui/baculum/protected/API/Pages/API/DirectorShow.php new file mode 100644 index 000000000..70cd305c7 --- /dev/null +++ b/gui/baculum/protected/API/Pages/API/DirectorShow.php @@ -0,0 +1,95 @@ + + * @category API + * @package Baculum API + */ +class DirectorShow extends ConsoleOutputShowPage { + + public function get() { + $director = $this->Request->contains('name') && $this->getModule('misc')->isValidName($this->Request['name']) ? $this->Request['name'] : null; + $out_format = $this->Request->contains('output') && $this->isOutputFormatValid($this->Request['output']) ? $this->Request['output'] : ConsoleOutputPage::OUTPUT_FORMAT_RAW; + $dirs = []; + $result = $this->getModule('bconsole')->getDirectors(); + if ($result->exitcode === 0) { + $dirs = $result->output; + } + + if (is_string($director) && in_array($director, $dirs)) { + $out = (object)[ + 'output' => [], + 'exitcode' => 0 + ]; + if ($out_format === ConsoleOutputPage::OUTPUT_FORMAT_RAW) { + $out = $this->getRawOutput(['director' => $director]); + } elseif($out_format === ConsoleOutputPage::OUTPUT_FORMAT_JSON) { + $out = $this->getJSONOutput(['director' => $director]); + } + $this->output = $out->output; + $this->error = $out->exitcode; + } else { + $this->output = BconsoleError::MSG_ERROR_INVALID_DIRECTOR; + $this->error = BconsoleError::ERROR_INVALID_DIRECTOR; + } + } + + /** + * Get show director output from console in raw format. + * + * @param array $params command parameters + * @return StdClass object with output and exitcode + */ + protected function getRawOutput($params = []) { + return $this->getModule('bconsole')->bconsoleCommand( + $params['director'], + ['show', 'director'] + ); + } + + /** + * Get show director output in JSON format. + * + * @param array $params command parameters + * @return StdClass object with output and exitcode + */ + protected function getJSONOutput($params = []) { + $result = (object)[ + 'output' => [], + 'exitcode' => 0 + ]; + $output = $this->getRawOutput($params); + if ($output->exitcode === 0) { + array_shift($output->output); + $result->output = $this->parseOutput($output->output); + } + $result->exitcode = $output->exitcode; + return $result; + } +} +?> diff --git a/gui/baculum/protected/API/Pages/API/endpoints.xml b/gui/baculum/protected/API/Pages/API/endpoints.xml index 5f3bbc433..6e54bf056 100644 --- a/gui/baculum/protected/API/Pages/API/endpoints.xml +++ b/gui/baculum/protected/API/Pages/API/endpoints.xml @@ -102,6 +102,7 @@ +