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