1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Handles logging |
5
|
|
|
* |
6
|
|
|
* @author Sam Stenvall <[email protected]> |
7
|
|
|
* @copyright Copyright © Sam Stenvall 2013- |
8
|
|
|
* @license https://www.gnu.org/licenses/gpl.html The GNU General Public License v3.0 |
9
|
|
|
*/ |
10
|
|
|
class LogController extends AdminOnlyController |
11
|
|
|
{ |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Override parent implementation in order to force POST for the logEvent |
15
|
|
|
* action |
16
|
|
|
* @return array the filters for this controller |
17
|
|
|
*/ |
18
|
|
|
public function filters() |
19
|
|
|
{ |
20
|
|
|
return array_merge(parent::filters(), array( |
21
|
|
|
'postOnly + logEvent', |
22
|
|
|
)); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Override parent implementation so the user can check the logs even when |
27
|
|
|
* a backend is not yet configured |
28
|
|
|
* @param CFilterChain $filterChain |
29
|
|
|
*/ |
30
|
|
|
public function filterCheckConfiguration($filterChain) |
31
|
|
|
{ |
32
|
|
|
$filterChain->run(); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Override parent implementation to allow anyone to post log events |
37
|
|
|
* @return array the access rules for this controller |
38
|
|
|
*/ |
39
|
|
|
public function accessRules() |
40
|
|
|
{ |
41
|
|
|
return array_merge(array( |
42
|
|
|
array('allow', |
43
|
|
|
'actions'=>array('logEvent'), |
44
|
|
|
), |
45
|
|
|
), parent::accessRules()); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Flushes the system log and redirects to the admin page |
50
|
|
|
*/ |
51
|
|
|
public function actionFlush() |
52
|
|
|
{ |
53
|
|
|
Yii::app()->db->createCommand()->truncateTable('log'); |
54
|
|
|
Yii::app()->user->setFlash('success', Yii::t('Log', 'System log flushed successfully')); |
55
|
|
|
$this->redirect(array('admin')); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* AJAX-only action which logs the event described in the POST data. Used |
60
|
|
|
* to log link clicks using JavaScript. |
61
|
|
|
* @throws CHttpException if the request is invalid |
62
|
|
|
*/ |
63
|
|
|
public function actionLogEvent() |
64
|
|
|
{ |
65
|
|
|
foreach (array('logCategory', 'logMessage') as $attribute) |
66
|
|
|
if (!isset($_POST[$attribute])) |
67
|
|
|
throw new InvalidRequestException(); |
68
|
|
|
|
69
|
|
|
// The message may be HTML-encoded |
70
|
|
|
$message = html_entity_decode($_POST['logMessage']); |
71
|
|
|
Yii::log($message, CLogger::LEVEL_INFO, $_POST['logCategory']); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Displays the specified log item in its fullness |
76
|
|
|
* @param int $id the item primary key |
77
|
|
|
*/ |
78
|
|
|
public function actionView($id) |
79
|
|
|
{ |
80
|
|
|
$model = $this->loadModel($id); |
81
|
|
|
|
82
|
|
|
$this->render('view', array( |
83
|
|
|
'model'=>$model |
84
|
|
|
)); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
} |
88
|
|
|
|