security.class.php
11.9 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
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
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
<?php
/**
* [Discuz! X] (C)2001-2099 Comsenz Inc.
* This is NOT a freeware, use is subject to license terms
*
* $Id: security.class.php 33945 2013-09-05 01:48:02Z nemohou $
*/
if(!defined('IN_DISCUZ')) {
exit('Access Denied');
}
class plugin_security {
const DEBUG = 0;
protected static $postReportAction = array('post_newthread_succeed', 'post_edit_succeed', 'post_reply_succeed',
'post_newthread_mod_succeed', 'post_newthread_mod_succeed', 'post_reply_mod_succeed',
'edit_reply_mod_succeed', 'edit_newthread_mod_succeed');
protected static $userReportAction = array('login_succeed', 'register_succeed', 'location_login_succeed_mobile',
'location_login_succeed', 'register_succeed_location', 'register_email_verify',
'register_manual_verify', 'login_succeed_inactive_member');
protected static $hookMoudle = array('post', 'logging', 'register');
protected static $isAdminGroup = 0;
protected static $cloudAppService;
protected static $securityService;
protected static $securityStatus;
public function __construct() {
self::$cloudAppService = Cloud::loadClass('Service_App');
self::$securityStatus = self::$cloudAppService->getCloudAppStatus('security');
self::$securityService = Cloud::loadClass('Service_Security');
}
public function common() {
global $_G;
if (self::$securityStatus != TRUE) {
return false;
}
if ($_G['uid']) {
$lastCookieReportTime = $this->_decodeReportTime($_G['cookie']['security_cookiereport']);
if ($lastCookieReportTime < strtotime('today')) {
$this->_reportLoginUser(array('uid' => $_G['uid']));
}
}
if ($_G['adminid'] > 0) {
self::$isAdminGroup = 1;
}
return true;
}
public function global_footer() {
global $_G, $_GET;
if (self::$securityStatus != TRUE) {
return false;
}
$ajaxReportScript = '';
$formhash = formhash();
if($_G['member']['allowadmincp'] == 1) {
$processName = 'securityOperate';
if (self::$isAdminGroup && !discuz_process::islocked($processName, 30)) {
$ajaxReportScript .= <<<EOF
<script type='text/javascript'>
var url = SITEURL + '/plugin.php?id=security:sitemaster';
var x = new Ajax();
x.post(url, 'formhash=$formhash', function(s){});
</script>
EOF;
}
$processName = 'securityNotice';
if (self::$isAdminGroup && !discuz_process::islocked($processName, 30)) {
$ajaxReportScript .= <<<EOF
<div class="focus plugin" id="evil_notice"></div>
<script type='text/javascript'>
var url = SITEURL + '/plugin.php?id=security:evilnotice&formhash=$formhash';
ajaxget(url, 'evil_notice', '');
</script>
EOF;
}
}
$processName = 'securityRetry';
$time = 10;
if (!discuz_process::islocked($processName, $time)) {
if (C::t('#security#security_failedlog')->count()) {
$ajaxRetryScript = <<<EOF
<script type='text/javascript'>
var urlRetry = SITEURL + '/plugin.php?id=security:job';
var ajaxRetry = new Ajax();
ajaxRetry.post(urlRetry, 'formhash=$formhash', function(s){});
</script>
EOF;
}
}
return $ajaxReportScript . $ajaxRetryScript;
}
function global_footerlink() {
return ' <a href="http://discuz.qq.com/service/security" target="_blank" title="'.lang('plugin/security', 'title').'"><img src="static/image/common/security.png"></a>';
}
public function deletepost($param) {
global $_G, $_POST;
if (self::$securityStatus != TRUE) {
return false;
}
$step = $param['step'];
$param = $param['param'];
$ids = $param[0];
$idType = $param[1];
$recycle = $param[4];
if ($step == 'check' && $idType == 'pid') {
self::$securityService->updatePostOperate($ids, 'delete');
if ($_POST['module'] == 'security' && $_POST['method'] == 'setEvilPost') {
return true;
}
self::$securityService->logDeletePost($ids, $_POST['reason']);
}
return true;
}
public function deletethread($param) {
global $_G, $_POST;
if (self::$securityStatus != TRUE) {
return false;
}
$step = $param['step'];
$param = $param['param'];
$ids = $param[0];
if ($step == 'check') {
self::$securityService->updateThreadOperate($ids, 'delete');
if ($_POST['module'] == 'security' && $_POST['method'] == 'setEvilPost') {
return true;
}
self::$securityService->logDeleteThread($ids, $_POST['reason']);
}
return true;
}
public function savebanlog($param) {
global $_G, $_POST;
if (self::$securityStatus != TRUE) {
return false;
}
$param = $param['param'];
$username = $param[0];
$oldGid = $param[1];
$newGid = $param[2];
$reason = $param[4];
if ($_POST['formhash'] && $newGid >= 4 && $newGid < 10) {
self::$securityService->logBannedMember($username, $reason);
} else {
self::$securityService->updateMemberRecover($username);
}
}
public function undeletethreads($param) {
$tids = $param['param'][0];
if ($tids && is_array($tids)) {
self::$securityService->updateThreadOperate($tids, 'recover');
}
}
public function recyclebinpostundelete ($param) {
$pids = $param['param'][0];
if ($pids && is_array($pids)) {
self::$securityService->updatePostOperate($pids, 'recover');
}
}
public function deletemember($param) {
$uids = $param['param'][0];
$step = $param['step'];
if ($step == 'check' && $uids && is_array($uids)) {
self::$securityService->updateMemberOperate($uids, 'delete');
}
}
protected function _decodeReportTime($time) {
if (!$time) {
return 0;
}
return authcode($time);
}
protected function _encodeReportTime($time) {
if (!$time) {
return 0;
}
return authcode($time, 'ENCODE');
}
protected function _reportRegisterUser($param) {
global $_G;
if (!$param['uid'] && !$_G['uid']) {
return false;
} else {
$param['uid'] = $_G['uid'];
}
$this->secLog('USERREG-UID', $param['uid']);
self::$securityService->reportRegister($param['uid']);
$this->_retryReport();
}
protected function _reportLoginUser($param) {
global $_G;
if (!$param['uid'] && !$_G['uid']) {
return false;
} else {
$param['uid'] = $_G['uid'];
}
$this->secLog('USERLOG-UID', $param['uid']);
self::$securityService->reportLogin($param['uid']);
$this->_retryReport();
$cookieTime = 43200;
dsetcookie('security_cookiereport', $this->_encodeReportTime($_G['timestamp']), $cookieTime, 1);
return true;
}
protected function _reportMobileLoginUser($param) {
if (!$param['username']) {
return false;
}
$username = $param['username'];
$result = C::t('common_member')->fetch_by_username($username);
return $this->_reportLoginUser($result);
}
protected function _reportNewThread($param) {
global $_G;
if (!$param['pid'] || !$param['tid']) {
return false;
}
$this->secLog('NEWTHREAD-TID', $param['tid']);
$tid = $param['tid'];
$pid = $param['pid'];
self::$securityService->reportPost('new', $tid, $pid, $extra, $param['isFollow']);
$this->_retryReport();
return true;
}
protected function _reportNewPost($param) {
global $_G;
if (!$param['pid'] || !$param['tid']) {
return false;
}
$this->secLog('NEWPOST-PID', $param['pid']);
$tid = $param['tid'];
$pid = $param['pid'];
self::$securityService->reportPost('new', $tid, $pid, $extra, $param['isFollow']);
$this->_retryReport();
return true;
}
protected function _reportEditPost($param) {
global $_G;
if (!$param['pid'] || !$param['tid']) {
return false;
}
$this->secLog('EDITPOST-PID', $param['pid']);
$tid = $param['tid'];
$pid = $param['pid'];
self::$securityService->reportPost('edit', $tid, $pid, $extra, $param['isFollow']);
$this->_retryReport();
return true;
}
protected function _retryReport() {
return self::$securityService->retryReportData();
}
public function secLog($type, $data) {
global $_G;
if (self::$securityStatus != TRUE) {
return false;
}
if (!self::DEBUG) {
return false;
}
}
public function getMergeAction() {
return array_merge(self::$postReportAction, self::$userReportAction);
}
}
class plugin_security_forum extends plugin_security {
public function post_security(){
return true;
}
public function post_report_message($param) {
global $_G, $extra, $redirecturl;
if (self::$securityStatus != TRUE) {
return false;
}
$param['message'] = $param['param'][0];
$param['values'] = $param['param'][2];
if (in_array($param['message'], self::$postReportAction)) {
switch ($param['message']) {
case 'post_newthread_succeed':
case 'post_newthread_mod_succeed':
$this->_reportNewThread($param['values']);
break;
case 'post_edit_succeed':
case 'edit_reply_mod_succeed':
case 'edit_newthread_mod_succeed':
$this->_reportEditPost($param['values']);
break;
case 'post_reply_succeed':
case 'post_reply_mod_succeed':
$this->_reportNewPost($param['values']);
default:break;
}
}
}
}
class plugin_security_group extends plugin_security_forum {}
class plugin_security_home extends plugin_security_forum {
public function spacecp_follow_report_message($param) {
global $_G, $extra, $redirecturl;
if (self::$securityStatus != TRUE) {
return false;
}
$param['message'] = $param['param'][0];
$param['values'] = $param['param'][2];
$param['values']['isFollow'] = 1;
if (in_array($param['message'], self::$postReportAction)) {
switch ($param['message']) {
case 'post_newthread_succeed':
case 'post_newthread_mod_succeed':
$this->_reportNewThread($param['values']);
break;
case 'post_edit_succeed':
case 'edit_reply_mod_succeed':
case 'edit_newthread_mod_succeed':
$this->_reportEditPost($param['values']);
break;
case 'post_reply_succeed':
case 'post_reply_mod_succeed':
$this->_reportNewPost($param['values']);
default:break;
}
}
}
}
class plugin_security_member extends plugin_security {
public function logging_report_message($param) {
global $_G;
if (self::$securityStatus != TRUE) {
return false;
}
$param['message'] = $param['param'][0];
$param['values'] = $param['param'][2];
if (in_array($param['message'], self::$userReportAction)) {
if (!$param['values']['uid']) {
$this->_reportLoginUser($param['values']);
} else {
$this->_reportMobileLoginUser($param['values']);
}
}
}
public function register_report_message($param) {
if (self::$securityStatus != TRUE) {
return false;
}
$param['message'] = $param['param'][0];
$param['values'] = $param['param'][2];
if (in_array($param['message'], self::$userReportAction)) {
$this->_reportRegisterUser($param['values']);
}
}
public function connect_report_message($param) {
global $_G;
if (self::$securityStatus != TRUE) {
return false;
}
$param['message'] = $param['param'][0];
$param['values'] = $param['param'][2];
if (($_POST['regsubmit'] || $_POST['loginsubmit']) && $_POST['formhash']) {
if ($_POST['loginsubmit']) {
$this->_reportLoginUser($_G['member']);
} else {
$this->_reportRegisterUser($param['values']);
}
}
}
}
class mobileplugin_security extends plugin_security {}
class mobileplugin_security_forum extends plugin_security_forum {}
class mobileplugin_security_member extends plugin_security_member {}
class plugin_security_connect extends plugin_security_member {
public function login_report_message($param) {
if (self::$securityStatus != TRUE) {
return false;
}
$param['message'] = $param['param'][0];
$param['values'] = $param['param'][2];
if (in_array($param['message'], self::$userReportAction)) {
switch ($param['message']) {
case login_succeed:
case location_login_succeed:
case location_login_succeed_mobile:
$this->_reportMobileLoginUser($param['values']);
default:break;
}
}
}
}