-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add report to display logs of admin audit app
Signed-off-by: Vitor Mattos <[email protected]>
- Loading branch information
1 parent
288314f
commit a6159f3
Showing
3 changed files
with
159 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* @copyright Copyright (c) 2023, Vitor Mattos <[email protected]> | ||
* | ||
* @author Vitor Mattos <[email protected]> | ||
* | ||
* @license GNU AGPL version 3 or any later version | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
namespace OCA\MyCompany\Datasource; | ||
|
||
use OCA\Analytics\Datasource\IDatasource; | ||
use OCP\IConfig; | ||
use OCP\IL10N; | ||
|
||
class AdminAudit implements IDatasource | ||
Check failure on line 33 in lib/Datasource/AdminAudit.php GitHub Actions / NextcloudUndefinedClass
|
||
{ | ||
public function __construct( | ||
private IL10N $l10n, | ||
private IConfig $config, | ||
) { | ||
} | ||
|
||
/** | ||
* @return string Display Name of the datasource | ||
*/ | ||
public function getName(): string { | ||
return $this->l10n->t('App: Admin Audit'); | ||
} | ||
|
||
/** | ||
* @return int digit unique datasource id | ||
*/ | ||
public function getId(): int { | ||
return 6; | ||
} | ||
|
||
/** | ||
* @return array available options of the datasoure | ||
*/ | ||
public function getTemplate(): array { | ||
return []; | ||
} | ||
|
||
/** | ||
* Read the Data | ||
* @param $option | ||
* @return array available options of the datasoure | ||
*/ | ||
public function readData($option): array | ||
{ | ||
$default = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/audit.log'; | ||
$logFile = $this->config->getAppValue('admin_audit', 'logfile', $default); | ||
|
||
$fp = fopen($logFile, 'r'); | ||
$i = 1; | ||
while (($buffer = fgets($fp, 4096)) !== false) { | ||
$json = json_decode($buffer, true); | ||
if (!str_contains($json['message'], 'File accessed')) { | ||
continue; | ||
} | ||
preg_match('/File accessed: "(?<file>.*)"/', $json['message'], $matches); | ||
$data[] = [ | ||
$json['time'], | ||
$matches['file'], | ||
$json['user'], | ||
$json['remoteAddr'], | ||
$json['userAgent'], | ||
$i, | ||
]; | ||
$i++; | ||
} | ||
fclose($fp); | ||
|
||
$header = [ | ||
// TRANSLATORS Column name of report that list log entries of app Audit Report. This column will display the date of log. | ||
$this->l10n->t('Date'), | ||
// TRANSLATORS Column name of report that list log entries of app Audit Report. This column will display the acessed file. | ||
$this->l10n->t('File'), | ||
// TRANSLATORS Column name of report that list log entries of app Audit Report. This column will display the user that trigged the log. | ||
$this->l10n->t('User'), | ||
// TRANSLATORS Column name of report that list log entries of app Audit Report. This column will display the IP of user that trigged the log. | ||
$this->l10n->t('IP'), | ||
// TRANSLATORS Column name of report that list log entries of app Audit Report. This column will display the user agent of user that trigged the log. | ||
$this->l10n->t('userAgent'), | ||
// TRANSLATORS Column name of report that list log entries of app Audit Report. This column will display a sequencial number of rows to be displayed in report. | ||
$this->l10n->t('row'), | ||
]; | ||
|
||
return [ | ||
'header' => $header, | ||
'dimensions' => array_slice($header, 0, count($header) - 1), | ||
'data' => $data, | ||
'error' => 0, | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* @copyright Copyright (c) 2023, Vitor Mattos <[email protected]> | ||
* | ||
* @author Vitor Mattos <[email protected]> | ||
* | ||
* @license GNU AGPL version 3 or any later version | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
namespace OCA\MyCompany\Listener; | ||
|
||
use OCA\MyCompany\Datasource\AdminAudit; | ||
use OCA\Analytics\Datasource\DatasourceEvent; | ||
use OCP\EventDispatcher\Event; | ||
use OCP\EventDispatcher\IEventListener; | ||
|
||
class AnalyticsDatasourceListener implements IEventListener { | ||
Check failure on line 34 in lib/Listener/AnalyticsDatasourceListener.php GitHub Actions / NextcloudMissingTemplateParam
|
||
public function handle(Event $event): void { | ||
if (!($event instanceof DatasourceEvent)) { | ||
Check failure on line 36 in lib/Listener/AnalyticsDatasourceListener.php GitHub Actions / NextcloudUndefinedClass
|
||
// Unrelated | ||
return; | ||
} | ||
$event->registerDatasource(AdminAudit::class); | ||
} | ||
} |