|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @copyright Copyright (c) 2016 Lukas Reschke <[email protected]> |
|
4
|
|
|
* |
|
5
|
|
|
* @author Lukas Reschke <[email protected]> |
|
6
|
|
|
* |
|
7
|
|
|
* @license GNU AGPL version 3 or any later version |
|
8
|
|
|
* |
|
9
|
|
|
* This program is free software: you can redistribute it and/or modify |
|
10
|
|
|
* it under the terms of the GNU Affero General Public License as |
|
11
|
|
|
* published by the Free Software Foundation, either version 3 of the |
|
12
|
|
|
* License, or (at your option) any later version. |
|
13
|
|
|
* |
|
14
|
|
|
* This program is distributed in the hope that it will be useful, |
|
15
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
16
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
17
|
|
|
* GNU Affero General Public License for more details. |
|
18
|
|
|
* |
|
19
|
|
|
* You should have received a copy of the GNU Affero General Public License |
|
20
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
21
|
|
|
* |
|
22
|
|
|
*/ |
|
23
|
|
|
|
|
24
|
|
|
namespace OCA\AdminAudit\Actions; |
|
25
|
|
|
|
|
26
|
|
|
use OCP\ILogger; |
|
27
|
|
|
|
|
28
|
|
|
class Action { |
|
29
|
|
|
/** @var ILogger */ |
|
30
|
|
|
private $logger; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @param ILogger $logger |
|
34
|
|
|
*/ |
|
35
|
|
|
public function __construct(ILogger $logger) { |
|
36
|
|
|
$this->logger = $logger; |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* Log a single action with a log level of info |
|
41
|
|
|
* |
|
42
|
|
|
* @param string $text |
|
43
|
|
|
* @param array $params |
|
44
|
|
|
* @param array $elements |
|
45
|
|
|
* @param bool $obfuscateParameters |
|
46
|
|
|
*/ |
|
47
|
|
|
public function log($text, |
|
48
|
|
|
array $params, |
|
49
|
|
|
array $elements, |
|
50
|
|
|
$obfuscateParameters = false) { |
|
51
|
|
|
foreach($elements as $element) { |
|
52
|
|
|
if(!isset($params[$element])) { |
|
53
|
|
|
if ($obfuscateParameters) { |
|
54
|
|
|
$this->logger->critical( |
|
55
|
|
|
'$params["'.$element.'"] was missing.', |
|
56
|
|
|
['app' => 'admin_audit'] |
|
57
|
|
|
); |
|
58
|
|
|
} else { |
|
59
|
|
|
$this->logger->critical( |
|
60
|
|
|
sprintf( |
|
61
|
|
|
'$params["'.$element.'"] was missing. Transferred value: %s', |
|
62
|
|
|
print_r($params, true) |
|
63
|
|
|
), |
|
64
|
|
|
['app' => 'admin_audit'] |
|
65
|
|
|
); |
|
66
|
|
|
} |
|
67
|
|
|
return; |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
$replaceArray = []; |
|
72
|
|
|
foreach($elements as $element) { |
|
73
|
|
|
if($params[$element] instanceof \DateTime) { |
|
74
|
|
|
$params[$element] = $params[$element]->format('Y-m-d H:i:s'); |
|
75
|
|
|
} |
|
76
|
|
|
$replaceArray[] = $params[$element]; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
$this->logger->info( |
|
80
|
|
|
vsprintf( |
|
81
|
|
|
$text, |
|
82
|
|
|
$replaceArray |
|
83
|
|
|
), |
|
84
|
|
|
[ |
|
85
|
|
|
'app' => 'admin_audit' |
|
86
|
|
|
] |
|
87
|
|
|
); |
|
88
|
|
|
} |
|
89
|
|
|
} |
|
90
|
|
|
|