Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArthur Schiwon <blizzz@arthur-schiwon.de>2018-04-25 18:42:14 +0300
committerMorris Jobke <hey@morrisjobke.de>2018-04-26 13:10:53 +0300
commitb841a477c6b96a13ea061df3fc622c3067514bf2 (patch)
treec0bb6e6aa539323f187aa03ed67b52b8dfb8b4ad /apps/admin_audit
parentab7a4b869397a5bc267a9f10b42654b35bbe1af6 (diff)
log to $datadir/audit.log by default and add rotation
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
Diffstat (limited to 'apps/admin_audit')
-rw-r--r--apps/admin_audit/appinfo/info.xml3
-rw-r--r--apps/admin_audit/composer/composer/autoload_classmap.php1
-rw-r--r--apps/admin_audit/composer/composer/autoload_static.php1
-rw-r--r--apps/admin_audit/lib/AppInfo/Application.php4
-rw-r--r--apps/admin_audit/lib/BackgroundJobs/Rotate.php52
5 files changed, 60 insertions, 1 deletions
diff --git a/apps/admin_audit/appinfo/info.xml b/apps/admin_audit/appinfo/info.xml
index 054ed9580f2..3006551b409 100644
--- a/apps/admin_audit/appinfo/info.xml
+++ b/apps/admin_audit/appinfo/info.xml
@@ -17,4 +17,7 @@
<dependencies>
<nextcloud min-version="14" max-version="14" />
</dependencies>
+ <background-jobs>
+ <job>OCA\AdminAudit\BackgroundJobs\Rotate</job>
+ </background-jobs>
</info>
diff --git a/apps/admin_audit/composer/composer/autoload_classmap.php b/apps/admin_audit/composer/composer/autoload_classmap.php
index c08200c7c20..95ddaac7452 100644
--- a/apps/admin_audit/composer/composer/autoload_classmap.php
+++ b/apps/admin_audit/composer/composer/autoload_classmap.php
@@ -18,4 +18,5 @@ return array(
'OCA\\AdminAudit\\Actions\\UserManagement' => $baseDir . '/../lib/Actions/UserManagement.php',
'OCA\\AdminAudit\\Actions\\Versions' => $baseDir . '/../lib/Actions/Versions.php',
'OCA\\AdminAudit\\AppInfo\\Application' => $baseDir . '/../lib/AppInfo/Application.php',
+ 'OCA\\AdminAudit\\BackgroundJobs\\Rotate' => $baseDir . '/../lib/BackgroundJobs/Rotate.php',
);
diff --git a/apps/admin_audit/composer/composer/autoload_static.php b/apps/admin_audit/composer/composer/autoload_static.php
index ef088bd22d9..1c01a35ceb2 100644
--- a/apps/admin_audit/composer/composer/autoload_static.php
+++ b/apps/admin_audit/composer/composer/autoload_static.php
@@ -33,6 +33,7 @@ class ComposerStaticInitAdminAudit
'OCA\\AdminAudit\\Actions\\UserManagement' => __DIR__ . '/..' . '/../lib/Actions/UserManagement.php',
'OCA\\AdminAudit\\Actions\\Versions' => __DIR__ . '/..' . '/../lib/Actions/Versions.php',
'OCA\\AdminAudit\\AppInfo\\Application' => __DIR__ . '/..' . '/../lib/AppInfo/Application.php',
+ 'OCA\\AdminAudit\\BackgroundJobs\\Rotate' => __DIR__ . '/..' . '/../lib/BackgroundJobs/Rotate.php',
);
public static function getInitializer(ClassLoader $loader)
diff --git a/apps/admin_audit/lib/AppInfo/Application.php b/apps/admin_audit/lib/AppInfo/Application.php
index f0387e86057..77b76885a20 100644
--- a/apps/admin_audit/lib/AppInfo/Application.php
+++ b/apps/admin_audit/lib/AppInfo/Application.php
@@ -63,8 +63,10 @@ class Application extends App {
public function initLogger() {
$c = $this->getContainer()->getServer();
+ $config = $c->getConfig();
- $logFile = $c->getConfig()->getAppValue('admin_audit', 'logfile', null);
+ $default = $config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/audit.log';
+ $logFile = $config->getAppValue('admin_audit', 'logfile', $default);
if($logFile === null) {
$this->logger = $c->getLogger();
return;
diff --git a/apps/admin_audit/lib/BackgroundJobs/Rotate.php b/apps/admin_audit/lib/BackgroundJobs/Rotate.php
new file mode 100644
index 00000000000..421ee65d643
--- /dev/null
+++ b/apps/admin_audit/lib/BackgroundJobs/Rotate.php
@@ -0,0 +1,52 @@
+<?php
+/**
+ * @copyright Copyright (c) 2018 Arthur Schiwon <blizzz@arthur-schiwon.de>
+ *
+ * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
+ *
+ * @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\AdminAudit\BackgroundJobs;
+
+use OC\BackgroundJob\TimedJob;
+use OCP\Log\RotationTrait;
+
+class Rotate extends TimedJob {
+ use RotationTrait;
+
+ public function __construct() {
+ $this->setInterval(60*60*3);
+ }
+
+ protected function run($argument) {
+ $config = \OC::$server->getConfig();
+ $default = $config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/audit.log';
+ $this->filePath = $config->getAppValue('admin_audit', 'logfile', $default);
+
+ if($this->filePath === '') {
+ // default log file, nothing to do
+ return;
+ }
+
+ $this->maxSize = $config->getSystemValue('log_rotate_size', 100 * 1024 * 1024);
+
+ if($this->shouldRotateBySize()) {
+ $this->rotate();
+ }
+ }
+}