]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/Configurator/LogView.php
Release 6.5.0
[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 $logFile = $sugar_config['log_dir'].'/'.$sugar_config['log_file'];
78
79 if (!file_exists($logFile)) {
80         die('No Log File');
81 }
82 $lastMatch = false;
83 $doaction =(!empty($_REQUEST['doaction']))?$_REQUEST['doaction']:'';
84
85 switch($doaction){
86         case 'mark':
87                 echo "<h3>{$mod_strings['LBL_MARKING_WHERE_START_LOGGING']}</h3><br>";
88                 $_SESSION['log_file_size'] = filesize($logFile);
89                 break;
90         case 'next':
91                 if(!empty($_SESSION['last_log_file_size'])){
92                         $_SESSION['log_file_size'] = $_SESSION['last_log_file_size'];
93                 }else{
94                         $_SESSION['log_file_size'] = 0;
95                 }
96                 $_REQUEST['display'] = true;
97                 break;
98         case 'all':
99                 $_SESSION['log_file_size'] = 0;
100                 $_REQUEST['display'] = true;
101                 break;
102 }
103
104
105 if (!empty ($_REQUEST['display'])) {
106         echo "<h3>{$mod_strings['LBL_DISPLAYING_LOG']}</h3>";
107         $process_id =  getmypid();
108
109         echo $mod_strings['LBL_YOUR_PROCESS_ID'].' [' . $process_id. ']';
110         echo '<br>'.$mod_strings['LBL_YOUR_IP_ADDRESS'].' ' . $_SERVER['REMOTE_ADDR'];
111         if($ignore_self){
112                 echo $mod_strings['LBL_IT_WILL_BE_IGNORED'];
113         }
114         if (empty ($_SESSION['log_file_size'])) {
115                 $_SESSION['log_file_size'] = 0;
116         }
117         $cur_size = filesize($logFile);
118         $_SESSION['last_log_file_size'] = $cur_size;
119         $pos = 0;
120         if ($cur_size >= $_SESSION['log_file_size']) {
121                 $pos = $_SESSION['log_file_size'] - $cur_size;
122         }
123         if($_SESSION['log_file_size'] == $cur_size){
124                 echo $mod_strings['LBL_LOG_NOT_CHANGED'].'<br>';
125         }else{
126                 $fp = sugar_fopen($logFile, 'r');
127                 fseek($fp, $pos , SEEK_END);
128                 echo '<pre>';
129                 while($line = fgets($fp)){
130
131             $line = filter_var($line, FILTER_SANITIZE_SPECIAL_CHARS);
132                         //preg_match('/[^\]]*\[([0-9]*)\] ([a-zA-Z]+) ([a-zA-Z0-9\.]+) - (.*)/', $line, $result);
133                         preg_match('/[^\]]*\[([0-9]*)\]/', $line, $result);
134                         ob_flush();
135                         flush();
136                         if(empty($result) && $lastMatch){
137                                 echo $line;
138                         }else{
139                                 $lastMatch = false;
140                                 if(empty($result) || ($ignore_self &&$result[LOG_NAME] == $_SERVER['REMOTE_ADDR'] )){
141
142                                 }else{
143                                         if(empty($filter) || (!$reg_ex && substr_count($line, $filter) > 0) || ($reg_ex && preg_match($filter, $line))){
144                                                 $lastMatch = true;
145                                                 echo $line;
146                                         }
147                                 }
148                         }
149                 }
150                 echo '</pre>';
151                 fclose($fp);
152
153         }
154 }
155 ?>