config.php partly solved, see #117
[mailer.git] / inc / modules / admin / what-logs.php
1 <?php
2 /************************************************************************
3  * MXChange v0.2.1                                    Start: 11/15/2003 *
4  * ===============                              Last change: 04/02/2004 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : what-logs.php                                    *
8  * -------------------------------------------------------------------- *
9  * Short description : Management for access log files                  *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Management fuer Zugriffslogbuecher               *
12  * -------------------------------------------------------------------- *
13  * $Revision::                                                        $ *
14  * $Date::                                                            $ *
15  * $Tag:: 0.2.1-FINAL                                                 $ *
16  * $Author::                                                          $ *
17  * Needs to be in all Files and every File needs "svn propset           *
18  * svn:keywords Date Revision" (autoprobset!) at least!!!!!!            *
19  * -------------------------------------------------------------------- *
20  * Copyright (c) 2003 - 2008 by Roland Haeder                           *
21  * For more information visit: http://www.mxchange.org                  *
22  *                                                                      *
23  * This program is free software; you can redistribute it and/or modify *
24  * it under the terms of the GNU General Public License as published by *
25  * the Free Software Foundation; either version 2 of the License, or    *
26  * (at your option) any later version.                                  *
27  *                                                                      *
28  * This program is distributed in the hope that it will be useful,      *
29  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
30  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
31  * GNU General Public License for more details.                         *
32  *                                                                      *
33  * You should have received a copy of the GNU General Public License    *
34  * along with this program; if not, write to the Free Software          *
35  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
36  * MA  02110-1301  USA                                                  *
37  ************************************************************************/
38
39 // Some security stuff...
40 if ((!defined('__SECURITY')) || (!IS_ADMIN())) {
41         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), '/inc') + 4) . '/security.php';
42         require($INC);
43 }
44
45 // Add description as navigation point
46 ADD_DESCR('admin', __FILE__);
47
48 if (REQUEST_ISSET_GET('access')) {
49         // Secure input and construct FQFN
50         $access = SQL_ESCAPE(strip_tags(REQUEST_GET('access')));
51         $target = sprintf("%slogs/%s", constant('PATH'), $access);
52
53         // Is the file valid and readable?
54         if (isFileReadable($target)) {
55                 // Load it directly
56                 $content = readFromFile($target);
57
58                 // Save old content
59                 $OUTPUT = ob_get_contents();
60
61                 // Clean content
62                 clearOutputBuffer();
63
64                 // Set header
65                 if (substr($access, -3, 3) == 'log') {
66                         // Output header
67                         sendHeader('Content-Type: text/plain');
68                 } elseif (substr($access, -3, 3) == '.gz') {
69                         // @TODO Fix content-type here
70                         sendHeader('Content-Type: text/plain');
71                 } elseif (substr($access, -3, 3) == '.bz2') {
72                         // @TODO Fix content-type here
73                         sendHeader('Content-Type: text/plain');
74                 } else {
75                         // Restore old content
76                         OUTPUT_HTML($OUTPUT);
77
78                         // Output message
79                         LOAD_TEMPLATE('admin_settings_saved', false, sprintf(getMessage('ADMIN_UNKNOWN_LOGFILE_FORMAT'), $access));
80                         return;
81                 }
82
83                 // Output the logfile's content and exit
84                 print($content);
85                 shutdown();
86         } else {
87                 // Not readable!
88                 LOAD_TEMPLATE('admin_settings_saved', false, sprintf(getMessage('LOGFILE_NOT_READABLE'), $access));
89         }
90 } else {
91         // List access logfiles
92         $dir = constant('PATH') . getConfig('logs_base') . '/';
93
94         // Is the directory there?
95         if (isDirectory($dir)) {
96                 // logs directory does exist
97                 OUTPUT_HTML("<ol>");
98                 $handle = opendir($dir) or app_die(__FILE__, __LINE__, 'Cannot open directory '.getConfig('logs_base') . '!');
99                 while ($file = readdir($handle)) {
100                         // We currenly only like files with "access" as prefix, should be more flexible!
101                         if (substr($file, 0, 6) == 'access') {
102                                 // Okay, let us print it out
103                                 OUTPUT_HTML("<li><a href=\"{!URL!}/modules.php?module=admin&amp;what=".$GLOBALS['what']."&amp;access=".urlencode($file)."\">".$file."</a></li>");
104                         }
105                 }
106                 closedir($handle);
107                 OUTPUT_HTML("</ol>");
108         } else {
109                 // logs directory does not exist
110                 LOAD_TEMPLATE('admin_settings_saved', false, sprintf(getMessage('ADMIN_LOGS_DIR_404'), getConfig('logs_base')));
111         }
112 }
113
114 //
115 ?>