-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathadmin.php
More file actions
174 lines (148 loc) · 5.48 KB
/
admin.php
File metadata and controls
174 lines (148 loc) · 5.48 KB
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
<?php
class admin_plugin_loglog extends DokuWiki_Admin_Plugin
{
/**
* @var \helper_plugin_loglog_logging
*/
protected $logHelper;
/**
* @var \helper_plugin_loglog_main
*/
protected $mainHelper;
/**
* @var string
*/
protected $filter = '';
/** @inheritDoc */
public function forAdminOnly()
{
return false;
}
/** @inheritDoc */
public function getMenuSort()
{
return 141;
}
public function __construct()
{
$this->logHelper = $this->loadHelper('loglog_logging');
$this->mainHelper = $this->loadHelper('loglog_main');
global $INPUT;
$this->filter = $INPUT->str('filter');
}
/** @inheritDoc */
public function html()
{
global $ID, $INPUT, $conf, $lang;
$now = time();
$go = isset($_REQUEST['time']) ? intval($_REQUEST['time']) : $now;
$min = $go - (7 * 24 * 60 * 60);
$max = $go;
$past = $now - $go > 60 * 60 * 5;
if ($past) {
$next = $max + (7 * 24 * 60 * 60);
if ($now - $next < 60 * 60 * 5) {
$next = $now;
}
}
$time = $INPUT->str('time') ?: $now;
// alternative date format?
$dateFormat = $this->getConf('admin_date_format') ?: $conf['dformat'];
echo $this->locale_xhtml('intro');
$form = new dokuwiki\Form\Form(['method'=>'GET']);
$form->setHiddenField('do', 'admin');
$form->setHiddenField('page', 'loglog');
$form->setHiddenField('time', $time);
$form->addDropdown(
'filter',
[
'' => '',
'auth_ok' => $this->getLang('filter_auth_ok'),
'auth_error' => $this->getLang('filter_auth_error'),
'admin' => $this->getLang('filter_admin'),
'other' => $this->getLang('filter_other')
]
);
$form->addButton('submit', $this->getLang('submit'))->attr('type','submit');
echo $form->toHTML();
echo '<p>' . $this->getLang('range') . ' ' . strftime($dateFormat, $min) .
' - ' . strftime($dateFormat, $max) . '</p>';
echo '<table class="inline loglog">';
echo '<tr>';
echo '<th>' . $this->getLang('date') . '</th>';
echo '<th>' . $this->getLang('ip') . '</th>';
echo '<th>' . $lang['user'] . '</th>';
echo '<th>' . $this->getLang('action') . '</th>';
echo '<th>'. $this->getLang('data') . '</th>';
echo '</tr>';
$lines = $this->logHelper->readLines($min, $max);
$lines = array_reverse($lines);
foreach ($lines as $line) {
if (!$line['user']) continue;
$logType = $this->mainHelper->getLogTypeFromMsg($line['msg']);
if ($this->filter && $this->filter !== '' && $this->filter!== $logType) {
continue;
}
if ($line['msg'] == 'logged off') {
$line['msg'] = $this->getLang('off');
$class = 'off';
} elseif ($line['msg'] == 'logged in permanently') {
$line['msg'] = $this->getLang('in');
$class = 'perm';
} elseif ($line['msg'] == 'logged in temporarily') {
$line['msg'] = $this->getLang('tin');
$class = 'temp';
} elseif ($line['msg'] == 'failed login attempt') {
$line['msg'] = $this->getLang('fail');
$class = 'fail';
} elseif ($line['msg'] == 'has been automatically logged off') {
$line['msg'] = $this->getLang('autologoff');
$class = 'off';
} else {
$line['msg'] = hsc($line['msg']);
if (strpos($line['msg'], 'logged off') !== false) {
$class = 'off';
} elseif (strpos($line['msg'], 'logged in permanently') !== false) {
$class = 'perm';
} elseif (strpos($line['msg'], 'logged in') !== false) {
$class = 'temp';
} elseif (strpos($line['msg'], 'failed') !== false) {
$class = 'fail';
} else {
$class = 'unknown';
}
}
echo '<tr>';
echo '<td>' . strftime($dateFormat, $line['dt']) . '</td>';
echo '<td>' . hsc($line['ip']) . '</td>';
echo '<td>' . hsc($line['user']) . '</td>';
echo '<td><span class="loglog_' . $class . '">' . $line['msg'] . '</span></td>';
echo '<td>';
if ($line['data']) {
// logs contain single-line JSON data, so we have to decode and encode it again for pretty print
echo '<pre>' . json_encode(json_decode($line['data']), JSON_PRETTY_PRINT) . '</pre>';
}
echo '</td>';
echo '</tr>';
}
echo '</table>';
echo '<div class="pagenav">';
if ($past) {
echo '<div class="pagenav-prev">';
echo html_btn('newer',
$ID,
"p",
['do' => 'admin', 'page' => 'loglog', 'time' => $next, 'filter' => $this->filter]
);
echo '</div>';
}
echo '<div class="pagenav-next">';
echo html_btn('older',
$ID,
"n",
['do' => 'admin', 'page' => 'loglog', 'time' => $min, 'filter' => $this->filter]
);
echo '</div>';
echo '</div>';
}
}