]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/Configurator/LogView.php
Release 6.5.1
[Github/sugarcrm.git] / modules / Configurator / LogView.php
1 <?php
2 if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
3 /*********************************************************************************
4  * SugarCRM Community Edition is a customer relationship management program developed by
5  * SugarCRM, Inc. Copyright (C) 2004-2012 SugarCRM Inc.
6  * 
7  * This program is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU Affero General Public License version 3 as published by the
9  * Free Software Foundation with the addition of the following permission added
10  * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
11  * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
12  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
13  * 
14  * This program is distributed in the hope that it will be useful, but WITHOUT
15  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16  * FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more
17  * details.
18  * 
19  * You should have received a copy of the GNU Affero General Public License along with
20  * this program; if not, see http://www.gnu.org/licenses or write to the Free
21  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22  * 02110-1301 USA.
23  * 
24  * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
25  * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
26  * 
27  * The interactive user interfaces in modified source and object code versions
28  * of this program must display Appropriate Legal Notices, as required under
29  * Section 5 of the GNU Affero General Public License version 3.
30  * 
31  * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
32  * these Appropriate Legal Notices must retain the display of the "Powered by
33  * SugarCRM" logo. If the display of the logo is not reasonably feasible for
34  * technical reasons, the Appropriate Legal Notices must display the words
35  * "Powered by SugarCRM".
36  ********************************************************************************/
37
38
39
40 global $mod_strings;
41 if(!is_admin($current_user)){
42         sugar_die($GLOBALS['app_strings']['ERR_NOT_ADMIN']);
43 }
44 $filter = '';
45 if(!empty($_REQUEST['filter'])){
46         $filter =       $_REQUEST['filter'];
47 }
48 $ignore_self = false;
49 if(!empty($_REQUEST['ignore_self'])){
50         $ignore_self = 'checked';
51 }
52 $reg_ex = false;
53 if(!empty($_REQUEST['reg_ex'])){
54         $reg_ex = 'checked';
55 }
56 set_time_limit(180);
57 echo <<<EOQ
58 <form action='index.php' name='logview'>
59 <input type='hidden' name='action' value='LogView'>
60 <input type='hidden' name='module' value='Configurator'>
61 <input type='hidden' name='doaction' value=''>
62 <input type='button' onclick='document.logview.doaction.value="all";document.logview.submit()' name='all' value='{$mod_strings['LBL_ALL']}'>
63 <input type='button' onclick='document.logview.doaction.value="mark";document.logview.submit()' name='mark' value='{$mod_strings['LBL_MARK_POINT']}'>
64 <input type='submit' name='display' value='{$mod_strings['LBL_REFRESH_FROM_MARK']}'>
65 <input type='button' onclick='document.logview.doaction.value="next";document.logview.submit()' name='next' value='{$mod_strings['LBL_NEXT_']}'>
66 <br>
67 {$mod_strings['LBL_SEARCH']} <input type='text' name='filter' value='$filter'>&nbsp;{$mod_strings['LBL_REG_EXP']} <input type='checkbox' name='reg_ex' $reg_ex>
68 <br>
69 {$mod_strings['LBL_IGNORE_SELF']} <input type='checkbox' name='ignore_self' $ignore_self>
70 </form>
71 EOQ;
72
73 define('PROCESS_ID', 1);
74 define('LOG_LEVEL', 2);
75 define('LOG_NAME', 3);
76 define('LOG_DATA', 4);
77
78 // bug 53041 - now that we are respecting file name suffixes for log files, we need to get the log file name properly
79 $config = SugarConfig::getInstance();
80 $ext = $config->get('logger.file.ext');
81 $logfile = $config->get('logger.file.name');
82 $log_dir = $config->get('log_dir');
83 $log_dir = $log_dir . (empty($log_dir)?'':'/');
84 $file_suffix = $config->get('logger.file.suffix');
85 $date_suffix = "";
86 if( !empty($file_suffix) )
87 {
88     $date_suffix = "_" . date(str_replace("%", "", $file_suffix));
89 }
90
91 $logFile = $log_dir . $logfile . $date_suffix . $ext;
92
93 if (!file_exists($logFile)) {
94         die('No Log File');
95 }
96 $lastMatch = false;
97 $doaction =(!empty($_REQUEST['doaction']))?$_REQUEST['doaction']:'';
98
99 switch($doaction){
100         case 'mark':
101                 echo "<h3>{$mod_strings['LBL_MARKING_WHERE_START_LOGGING']}</h3><br>";
102                 $_SESSION['log_file_size'] = filesize($logFile);
103                 break;
104         case 'next':
105                 if(!empty($_SESSION['last_log_file_size'])){
106                         $_SESSION['log_file_size'] = $_SESSION['last_log_file_size'];
107                 }else{
108                         $_SESSION['log_file_size'] = 0;
109                 }
110                 $_REQUEST['display'] = true;
111                 break;
112         case 'all':
113                 $_SESSION['log_file_size'] = 0;
114                 $_REQUEST['display'] = true;
115                 break;
116 }
117
118
119 if (!empty ($_REQUEST['display'])) {
120         echo "<h3>{$mod_strings['LBL_DISPLAYING_LOG']}</h3>";
121         $process_id =  getmypid();
122
123         echo $mod_strings['LBL_YOUR_PROCESS_ID'].' [' . $process_id. ']';
124         echo '<br>'.$mod_strings['LBL_YOUR_IP_ADDRESS'].' ' . $_SERVER['REMOTE_ADDR'];
125         if($ignore_self){
126                 echo $mod_strings['LBL_IT_WILL_BE_IGNORED'];
127         }
128         if (empty ($_SESSION['log_file_size'])) {
129                 $_SESSION['log_file_size'] = 0;
130         }
131         $cur_size = filesize($logFile);
132         $_SESSION['last_log_file_size'] = $cur_size;
133         $pos = 0;
134         if ($cur_size >= $_SESSION['log_file_size']) {
135                 $pos = $_SESSION['log_file_size'] - $cur_size;
136         }
137         if($_SESSION['log_file_size'] == $cur_size){
138                 echo $mod_strings['LBL_LOG_NOT_CHANGED'].'<br>';
139         }else{
140                 $fp = sugar_fopen($logFile, 'r');
141                 fseek($fp, $pos , SEEK_END);
142                 echo '<pre>';
143                 while($line = fgets($fp)){
144
145             $line = filter_var($line, FILTER_SANITIZE_SPECIAL_CHARS);
146                         //preg_match('/[^\]]*\[([0-9]*)\] ([a-zA-Z]+) ([a-zA-Z0-9\.]+) - (.*)/', $line, $result);
147                         preg_match('/[^\]]*\[([0-9]*)\]/', $line, $result);
148                         ob_flush();
149                         flush();
150                         if(empty($result) && $lastMatch){
151                                 echo $line;
152                         }else{
153                                 $lastMatch = false;
154                                 if(empty($result) || ($ignore_self &&$result[LOG_NAME] == $_SERVER['REMOTE_ADDR'] )){
155
156                                 }else{
157                                         if(empty($filter) || (!$reg_ex && substr_count($line, $filter) > 0) || ($reg_ex && preg_match($filter, $line))){
158                                                 $lastMatch = true;
159                                                 echo $line;
160                                         }
161                                 }
162                         }
163                 }
164                 echo '</pre>';
165                 fclose($fp);
166
167         }
168 }
169 ?>