* Parse 'show' type command output for all resources given type.
*
* @param array $output 'show' command output
+ * @param array $filters filters in [key => value, ...] form
* @return array parsed output
*/
- protected function parseOutputAll(array $output) {
+ protected function parseOutputAll(array $output, array $filters = []) {
$ret = $part = [];
- $section = '';
+ $skip = false;
for ($i = 0; $i < count($output); $i++) {
$scount = preg_match('/^[A-Za-z]+: name=.+/i', $output[$i]);
$mcount = preg_match_all('/(?<=\s)\w+=.*?(?=\s+\w+=.*?|$)/i', $output[$i], $matches);
for ($j = 0; $j < count($matches[0]); $j++) {
list($key, $value) = explode('=', $matches[0][$j], 2);
$key = strtolower($key);
+ if (key_exists($key, $filters) && $filters[$key] != $value) {
+ // filter values that do not match
+ $skip = true;
+ }
if ($i > 0 && $scount == 1 && count($part) > 0) {
- $ret[] = $part;
+ if (!$skip) {
+ $ret[] = $part;
+ }
$part = [];
$scount = 0;
+ $skip = false;
}
if (key_exists($key, $part)) {
/*
}
}
if (count($part) > 0) {
- $ret[] = $part;
+ if (!$skip) {
+ $ret[] = $part;
+ }
$part = [];
+ $skip = false;
}
return $ret;
}
class ClientsShow extends ConsoleOutputShowPage {
public function get() {
+ $misc = $this->getModule('misc');
$out_format = $this->Request->contains('output') && $this->isOutputFormatValid($this->Request['output']) ? $this->Request['output'] : ConsoleOutputPage::OUTPUT_FORMAT_RAW;
+ $enabled = $this->Request->contains('enabled') && $misc->isValidBoolean($this->Request['enabled']) ? (int) $this->Request['enabled'] : null;
$result = $this->getModule('bconsole')->bconsoleCommand(
$this->director,
['.client'],
}
$params = [];
if (is_string($client)) {
- $params = ['client' => $client];
+ $params['client'] = $client;
}
+ $filters = [];
+ if (is_int($enabled)) {
+ $filters['enabled'] = $enabled;
+ }
+
$out = (object)[
'output' => [],
'exitcode' => 0
if ($out_format === ConsoleOutputPage::OUTPUT_FORMAT_RAW) {
$out = $this->getRawOutput($params);
} elseif($out_format === ConsoleOutputPage::OUTPUT_FORMAT_JSON) {
- $out = $this->getJSONOutput($params);
+ $out = $this->getJSONOutput($params, $filters);
}
$this->output = $out->output;
$this->error = $out->exitcode;
* Get show client output in JSON format.
*
* @param array $params command parameters
+ * @param array $filter filters in [key => value, ...] form
* @return StdClass object with output and exitcode
*/
- protected function getJSONOutput($params = []) {
+ protected function getJSONOutput($params = [], $filters = []) {
$result = (object)[
'output' => [],
'exitcode' => 0
if (key_exists('client', $params)) {
$result->output = $this->parseOutput($output->output);
} else {
- $result->output = $this->parseOutputAll($output->output);
+ $result->output = $this->parseOutputAll($output->output, $filters);
}
}
$result->exitcode = $output->exitcode;