1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Alpha\Controller; |
4
|
|
|
|
5
|
|
|
use Alpha\Util\Logging\Logger; |
6
|
|
|
use Alpha\Util\Logging\LogProviderFile; |
7
|
|
|
use Alpha\Util\Http\Request; |
8
|
|
|
use Alpha\Util\Http\Response; |
9
|
|
|
use Alpha\Exception\IllegalArguementException; |
10
|
|
|
use Alpha\View\View; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Controller used to display a log file, the path for which must be supplied in GET vars. |
14
|
|
|
* |
15
|
|
|
* @since 1.0 |
16
|
|
|
* |
17
|
|
|
* @author John Collins <[email protected]> |
18
|
|
|
* @license http://www.opensource.org/licenses/bsd-license.php The BSD License |
19
|
|
|
* @copyright Copyright (c) 2018, John Collins (founder of Alpha Framework). |
20
|
|
|
* All rights reserved. |
21
|
|
|
* |
22
|
|
|
* <pre> |
23
|
|
|
* Redistribution and use in source and binary forms, with or |
24
|
|
|
* without modification, are permitted provided that the |
25
|
|
|
* following conditions are met: |
26
|
|
|
* |
27
|
|
|
* * Redistributions of source code must retain the above |
28
|
|
|
* copyright notice, this list of conditions and the |
29
|
|
|
* following disclaimer. |
30
|
|
|
* * Redistributions in binary form must reproduce the above |
31
|
|
|
* copyright notice, this list of conditions and the |
32
|
|
|
* following disclaimer in the documentation and/or other |
33
|
|
|
* materials provided with the distribution. |
34
|
|
|
* * Neither the name of the Alpha Framework nor the names |
35
|
|
|
* of its contributors may be used to endorse or promote |
36
|
|
|
* products derived from this software without specific |
37
|
|
|
* prior written permission. |
38
|
|
|
* |
39
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND |
40
|
|
|
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, |
41
|
|
|
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
42
|
|
|
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
43
|
|
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR |
44
|
|
|
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
45
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
46
|
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
47
|
|
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
48
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
49
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE |
50
|
|
|
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
51
|
|
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
52
|
|
|
* </pre> |
53
|
|
|
*/ |
54
|
|
|
class LogController extends Controller implements ControllerInterface |
55
|
|
|
{ |
56
|
|
|
/** |
57
|
|
|
* The path to the log that we are displaying. |
58
|
|
|
* |
59
|
|
|
* @var string |
60
|
|
|
* |
61
|
|
|
* @since 1.0 |
62
|
|
|
*/ |
63
|
|
|
private $logPath; |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Trace logger. |
67
|
|
|
* |
68
|
|
|
* @var \Alpha\Util\Logging\Logger |
69
|
|
|
* |
70
|
|
|
* @since 1.0 |
71
|
|
|
*/ |
72
|
|
|
private static $logger = null; |
|
|
|
|
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* The constructor. |
76
|
|
|
* |
77
|
|
|
* @since 1.0 |
78
|
|
|
*/ |
79
|
|
|
public function __construct() |
80
|
|
|
{ |
81
|
|
|
self::$logger = new Logger('LogController'); |
82
|
|
|
self::$logger->debug('>>__construct()'); |
83
|
|
|
|
84
|
|
|
// ensure that the super class constructor is called, indicating the rights group |
85
|
|
|
parent::__construct('Admin'); |
86
|
|
|
|
87
|
|
|
$this->setTitle('Displaying the requested log'); |
88
|
|
|
|
89
|
|
|
self::$logger->debug('<<__construct'); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* Handle GET requests. |
94
|
|
|
* |
95
|
|
|
* @param \Alpha\Util\Http\Request $request |
96
|
|
|
* |
97
|
|
|
* @return \Alpha\Util\Http\Response |
98
|
|
|
* |
99
|
|
|
* @throws \Alpha\Exception\IllegalArguementException |
100
|
|
|
* |
101
|
|
|
* @since 1.0 |
102
|
|
|
*/ |
103
|
|
|
public function doGET($request) |
104
|
|
|
{ |
105
|
|
|
self::$logger->debug('>>doGET($request=['.var_export($request, true).'])'); |
106
|
|
|
|
107
|
|
|
$params = $request->getParams(); |
108
|
|
|
|
109
|
|
|
$body = ''; |
110
|
|
|
|
111
|
|
|
try { |
112
|
|
|
if (isset($params['logPath']) && file_exists(urldecode($params['logPath']))) { |
113
|
|
|
$logPath = urldecode($params['logPath']); |
114
|
|
|
} else { |
115
|
|
|
throw new IllegalArguementException('No log file available to view!'); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
$this->logPath = $logPath; |
119
|
|
|
|
120
|
|
|
$body .= View::displayPageHead($this); |
121
|
|
|
|
122
|
|
|
$log = new LogProviderFile(); |
123
|
|
|
$log->setPath($this->logPath); |
124
|
|
|
|
125
|
|
|
if (preg_match('/alpha.*/', basename($this->logPath))) { |
126
|
|
|
$body .= $log->renderLog(array('Date/time', 'Level', 'Class', 'Message', 'Client', 'IP', 'Server hostname', 'URI')); |
127
|
|
|
} |
128
|
|
|
if (preg_match('/search.*/', basename($this->logPath))) { |
129
|
|
|
$body .= $log->renderLog(array('Search query', 'Search date', 'Client Application', 'Client IP')); |
130
|
|
|
} |
131
|
|
|
if (preg_match('/feeds.*/', basename($this->logPath))) { |
132
|
|
|
$body .= $log->renderLog(array('Business object', 'Feed type', 'Request date', 'Client Application', 'Client IP')); |
133
|
|
|
} |
134
|
|
|
if (preg_match('/tasks.*/', basename($this->logPath))) { |
135
|
|
|
$body .= $log->renderLog(array('Date/time', 'Level', 'Class', 'Message')); |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
$body .= View::displayPageFoot($this); |
139
|
|
|
} catch (IllegalArguementException $e) { |
140
|
|
|
self::$logger->warn($e->getMessage()); |
141
|
|
|
|
142
|
|
|
$body .= View::displayPageHead($this); |
143
|
|
|
|
144
|
|
|
$body .= View::displayErrorMessage($e->getMessage()); |
145
|
|
|
|
146
|
|
|
$body .= View::displayPageFoot($this); |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
self::$logger->debug('<<doGET'); |
150
|
|
|
|
151
|
|
|
return new Response(200, $body, array('Content-Type' => 'text/html')); |
152
|
|
|
} |
153
|
|
|
} |
154
|
|
|
|