-
Notifications
You must be signed in to change notification settings - Fork 5
/
action.php
300 lines (269 loc) · 7.91 KB
/
action.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
<?php
/**
* Login/Logout logging plugin
*
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author Andreas Gohr <gohr@cosmocode.de>
*/
class action_plugin_loglog extends DokuWiki_Action_Plugin
{
/**
* @var \helper_plugin_loglog_logging
*/
protected $logHelper;
/**
* @var \helper_plugin_loglog_main
*/
protected $mainHelper;
/**
* @var \helper_plugin_loglog_alert
*/
protected $alertHelper;
public function __construct()
{
$this->mainHelper = $this->loadHelper('loglog_main');
$this->logHelper = $this->loadHelper('loglog_logging');
$this->alertHelper = $this->loadHelper('loglog_alert');
}
/** @inheritDoc */
function register(Doku_Event_Handler $controller)
{
// tasks to perform on login/logoff
$controller->register_hook(
'ACTION_ACT_PREPROCESS',
'BEFORE',
$this,
'handleAuth'
);
// allow other plugins to emit logging events
$controller->register_hook(
'PLUGIN_LOGLOG_LOG',
'BEFORE',
$this,
'handleCustom'
);
// autologout plugin
$controller->register_hook(
'ACTION_AUTH_AUTOLOGOUT',
'BEFORE',
$this,
'handleAutologout'
);
// log admin access
$controller->register_hook(
'ACTION_ACT_PREPROCESS',
'BEFORE',
$this,
'handleAdminAccess'
);
// log user modifications
$controller->register_hook(
'AUTH_USER_CHANGE',
'BEFORE',
$this,
'handleUsermod'
);
// log admin actions triggered via Ajax
$controller->register_hook(
'AJAX_CALL_UNKNOWN',
'AFTER',
$this,
'handleAjax'
);
// log other admin actions
$controller->register_hook(
'DOKUWIKI_STARTED',
'AFTER',
$this,
'handleOther'
);
// log other admin actions
$controller->register_hook(
'INDEXER_TASKS_RUN',
'AFTER',
$this,
'handleReport'
);
}
/**
* Log login/logoff actions and optionally trigger alerts
* if configured thresholds have just been exceeded
*
* @param $msg
* @param null|string $user
*/
protected function logAuth($msg, $user = null)
{
$this->logHelper->writeLine($msg, $user);
// trigger alert notifications if necessary
$this->alertHelper->checkAlertThresholds();
}
/**
* Log usage of admin tools
*
* @param array $data
* @param string $more
*/
protected function logAdmin(array $data = [], $more = '')
{
global $INPUT;
$msg = 'admin';
$page = $INPUT->str('page');
if ($page) $msg .= " - $page";
if ($more && $more !== $page) $msg .= " - $more";
$this->logHelper->writeLine($msg,null, $data);
}
/**
* Handle custom logging events
*
* @param Doku_Event $event
* @param mixed $param data passed to the event handler
*/
public function handleCustom(Doku_Event $event, $param)
{
if (isset($event->data['message'])) {
$log = $event->data['message'];
} else {
return;
}
if (isset($event->data['user'])) {
$user = $event->data['user'];
} else {
$user = null;
}
$this->logHelper->writeLine($log, $user);
}
/**
* Handle autologoffs by the autologout plugin
*
* @param Doku_Event $event
* @param mixed $param data passed to the event handler
*/
public function handleAutologout(Doku_Event $event, $param)
{
$this->logAuth('has been automatically logged off');
}
/**
* catch standard logins/logouts, check if any alert notifications should be sent
*
* @param Doku_Event $event
* @param mixed $param data passed to the event handler
*/
public function handleAuth(Doku_Event $event, $param)
{
// log authentication events
$act = act_clean($event->data);
if ($act == 'logout') {
$this->logAuth('logged off');
} elseif (!empty($_SERVER['REMOTE_USER']) && $act == 'login') {
if (isset($_REQUEST['r'])) {
$this->logAuth('logged in permanently');
} else {
$this->logAuth('logged in temporarily');
}
} elseif ($_REQUEST['u'] && empty($_REQUEST['http_credentials']) && empty($_SERVER['REMOTE_USER'])) {
$this->logAuth('failed login attempt');
}
}
/**
* Log access to admin pages
*
* @param Doku_Event $event
*/
public function handleAdminAccess(Doku_Event $event)
{
global $ACT;
if ($ACT === 'admin') {
$this->logAdmin();
}
}
/**
* Log user modifications
*
* @param Doku_Event $event
*/
public function handleUsermod(Doku_Event $event)
{
$modType = $event->data['type'];
$modUser = $event->data['params'][0];
if (is_array($modUser)) $modUser = implode(', ', $modUser);
// check if admin or user are modifying the data
global $ACT;
if ($ACT === 'profile') {
$this->logHelper->writeLine('user profile',null, [$modType . ' user', $modUser]);
} else {
$this->logAdmin([$modType . ' user', $modUser]);
}
}
/**
* Catch admin actions performed via Ajax
*
* @param Doku_Event $event
*/
public function handleAjax(Doku_Event $event)
{
global $INPUT;
// extension manager
if ($event->data === 'plugin_extension') {
$this->logAdmin([$INPUT->str('act') . ' ' . $INPUT->str('ext')], 'extension');
}
}
/**
* Log activity in select core admin modules
*
* @param \Doku_Event $event
*/
public function handleOther(\Doku_Event $event)
{
global $INPUT;
// configuration manager
if ($INPUT->str('page') === 'config'
&& $INPUT->bool('save') === true
&& !empty($INPUT->arr('config'))
) {
$this->logAdmin(['save config']);
}
// extension manager
if ($INPUT->str('page') === 'extension') {
if ($INPUT->post->has('fn')) {
$actions = $INPUT->post->arr('fn');
foreach ($actions as $action => $extensions) {
foreach ($extensions as $extname => $label) {
$this->logAdmin([$action, $extname]);
}
}
} elseif ($INPUT->post->str('installurl')) {
$this->logAdmin(['installurl', $INPUT->post->str('installurl')]);
} elseif (isset($_FILES['installfile'])) {
$this->logAdmin(['installfile', $_FILES['installfile']['name']]);
}
}
// ACL manager
if ($INPUT->str('page') === 'acl' && $INPUT->has('cmd')) {
$cmd = $INPUT->extract('cmd')->str('cmd');
$del = $INPUT->arr('del');
if ($cmd === 'update' && !empty($del)) {
$cmd = 'delete';
$rule = $del;
} else {
$rule = [
'ns' => $INPUT->str('ns'),
'acl_t' => $INPUT->str('acl_t'),
'acl_w' => $INPUT->str('acl_w'),
'acl' => $INPUT->str('acl')
];
}
$this->logAdmin([$cmd, $rule]);
}
}
/**
* Handle monthly usage reports
*
* @param Doku_Event $event
*/
public function handleReport(Doku_Event $event)
{
$reportHelper = new helper_plugin_loglog_report();
$reportHelper->handleReport();
}
}