--- /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.Web.Class.WebModule');
+
+class LogParser extends WebModule {
+
+ const CLIENT_PATTERN = '/^\s+Client\:\s+"?(?P<client>[a-zA-Z0-9:.\-_ ]+)"?/i';
+ const POOL_PATTERN = '/^\s+Pool\:\s+"?(?P<pool>[a-zA-Z0-9:.\-_ ]+)"?/i';
+ const READ_POOL_PATTERN = '/^\s+Read Pool\:\s+"?(?P<read_pool>[a-zA-Z0-9:.\-_ ]+)"?/i';
+ const WRITE_POOL_PATTERN = '/^\s+Write Pool\:\s+"?(?P<write_pool>[a-zA-Z0-9:.\-_ ]+)"?/i';
+ const STORAGE_PATTERN = '/^\s+Storage\:\s+"?(?P<storage>[a-zA-Z0-9:.\-_ ]+)"?/i';
+ const READ_STORAGE_PATTERN = '/^\s+Read Storage\:\s+"?(?P<read_storage>[a-zA-Z0-9:.\-_ ]+)"?/i';
+ const WRITE_STORAGE_PATTERN = '/^\s+Write Storage\:\s+"?(?P<write_storage>[a-zA-Z0-9:.\-_ ]+)"?/i';
+ const FILESET_PATTERN = '/^\s+FileSet\:\s+"?(?P<fileset>[a-zA-Z0-9:.\-_ ]+)"?/i';
+ const VERIFY_JOB_PATTERN = '/^\s+Verify Job\:\s+"?(?P<verify_job>[a-zA-Z0-9:.\-_ ]+)"?/i';
+
+ public function parse(array $logs) {
+ $out = array();
+ for ($i = 0; $i < count($logs); $i++) {
+ $lines = explode("\n", $logs[$i]);
+ for ($j = 0; $j < count($lines); $j++) {
+ $out[] = $this->parseLine($lines[$j]);
+ }
+ }
+ return $out;
+ }
+
+ private function parseLine($log_line) {
+ if (preg_match(self::CLIENT_PATTERN, $log_line, $match) === 1) {
+ $link = $this->getLink('client', $match['client']);
+ $log_line = str_replace($match['client'], $link, $log_line);
+ } elseif (preg_match(self::POOL_PATTERN, $log_line, $match) === 1) {
+ $link = $this->getLink('pool', $match['pool']);
+ $log_line = str_replace($match['pool'], $link, $log_line);
+ } elseif (preg_match(self::READ_POOL_PATTERN, $log_line, $match) === 1) {
+ $link = $this->getLink('pool', $match['read_pool']);
+ $log_line = str_replace($match['read_pool'], $link, $log_line);
+ } elseif (preg_match(self::WRITE_POOL_PATTERN, $log_line, $match) === 1) {
+ $link = $this->getLink('pool', $match['write_pool']);
+ $log_line = str_replace($match['write_pool'], $link, $log_line);
+ } elseif (preg_match(self::STORAGE_PATTERN, $log_line, $match) === 1) {
+ $link = $this->getLink('storage', $match['storage']);
+ $log_line = str_replace($match['storage'], $link, $log_line);
+ } elseif (preg_match(self::READ_STORAGE_PATTERN, $log_line, $match) === 1) {
+ $link = $this->getLink('storage', $match['read_storage']);
+ $log_line = str_replace($match['read_storage'], $link, $log_line);
+ } elseif (preg_match(self::WRITE_STORAGE_PATTERN, $log_line, $match) === 1) {
+ $link = $this->getLink('storage', $match['write_storage']);
+ $log_line = str_replace($match['write_storage'], $link, $log_line);
+ } elseif (preg_match(self::FILESET_PATTERN, $log_line, $match) === 1) {
+ $link = $this->getLink('fileset', $match['fileset']);
+ $log_line = str_replace($match['fileset'], $link, $log_line);
+ } elseif (preg_match(self::VERIFY_JOB_PATTERN, $log_line, $match) === 1) {
+ $link = $this->getLink('job', $match['verify_job']);
+ $log_line = str_replace($match['verify_job'], $link, $log_line);
+ }
+ return $log_line;
+ }
+
+ private function getLink($type, $name) {
+ return sprintf(
+ '<a href="/web/%s/%s">%s</a>',
+ $type,
+ rawurlencode($name),
+ $name
+ );
+ }
+}
+?>
<url ServiceParameter="JobView" pattern="web/job/{job}/" parameters.job="[a-zA-Z0-9:.\-_ ]+" />
<url ServiceParameter="StorageList" pattern="web/storage/" />
<url ServiceParameter="StorageView" pattern="web/storage/{storageid}/" parameters.storageid="\d+" />
+ <url ServiceParameter="StorageView" pattern="web/storage/{storage}/" parameters.storage="[a-zA-Z0-9:.\-_ ]+" />
<url ServiceParameter="DeviceView" pattern="web/device/{storageid}/{device}/" parameters.storageid="\d+" parameters.device="[a-zA-Z0-9:.\-_ ]+" />
<url ServiceParameter="PoolList" pattern="web/pool/" />
<url ServiceParameter="PoolView" pattern="web/pool/{poolid}/" parameters.poolid="\d+" />
+ <url ServiceParameter="PoolView" pattern="web/pool/{pool}/" parameters.pool="[a-zA-Z0-9:.\-_ ]+" />
<url ServiceParameter="VolumeList" pattern="web/volume/" />
<url ServiceParameter="VolumeView" pattern="web/volume/{mediaid}/" parameters.mediaid="\d+" />
<url ServiceParameter="ClientList" pattern="web/client/" />
<url ServiceParameter="ClientView" pattern="web/client/{clientid}/" parameters.clientid="\d+" />
+ <url ServiceParameter="ClientView" pattern="web/client/{client}/" parameters.client="[a-zA-Z0-9:.\-_ ]+" />
<url ServiceParameter="FileSetList" pattern="web/fileset/" />
<url ServiceParameter="FileSetView" pattern="web/fileset/{fileset}/" parameters.fileset="[a-zA-Z0-9:.\-_ ]+" />
<url ServiceParameter="ScheduleList" pattern="web/schedule/" />