829bc839bad52f457e7c92aa847fe296b65bd41a
[mailer.git] / inc / modules / admin / what-logs.php
1 <?php
2 /************************************************************************
3  * Mailer v0.2.1-FINAL                                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 - 2009 by Roland Haeder                           *
21  * Copyright (c) 2009, 2010 by Mailer Developer Team                    *
22  * For more information visit: http://www.mxchange.org                  *
23  *                                                                      *
24  * This program is free software; you can redistribute it and/or modify *
25  * it under the terms of the GNU General Public License as published by *
26  * the Free Software Foundation; either version 2 of the License, or    *
27  * (at your option) any later version.                                  *
28  *                                                                      *
29  * This program is distributed in the hope that it will be useful,      *
30  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
31  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
32  * GNU General Public License for more details.                         *
33  *                                                                      *
34  * You should have received a copy of the GNU General Public License    *
35  * along with this program; if not, write to the Free Software          *
36  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
37  * MA  02110-1301  USA                                                  *
38  ************************************************************************/
39
40 // Some security stuff...
41 if ((!defined('__SECURITY')) || (!isAdmin())) {
42         die();
43 }
44
45 // Add description as navigation point
46 addMenuDescription('admin', __FILE__);
47
48 if (isGetRequestParameterSet('access')) {
49         // Secure input and construct FQFN
50         $access = SQL_ESCAPE(secureString(getRequestParameter('access')));
51         $target = sprintf("%slogs/%s", getConfig('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                         outputHtml($OUTPUT);
77
78                         // Output message
79                         loadTemplate('admin_settings_saved', false, getMaskedMessage('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                 loadTemplate('admin_settings_saved', false, getMaskedMessage('LOGFILE_NOT_READABLE', $access));
89         }
90 } else {
91         // Is the directory there?
92         if (isDirectory(getConfig('PATH') . getConfig('logs_base'))) {
93                 // Logs directory does exist so begin the list
94                 outputHtml('<ol>');
95
96                 // Read all files
97                 $files = getArrayFromDirectory(getConfig('logs_base'), 'access');
98
99                 // And walk through them
100                 foreach ($files as $file) {
101                         // Cut dirname away
102                         $file = basename($file);
103
104                         // Okay, add it
105                         outputHtml('<li><a href="{%url=modules.php?module=admin&amp;what=' . getWhat() . '&amp;access=' . urlencode($file) . '%}">' . $file . '</a></li>');
106                 } // END - foreach
107
108                 // Finish list
109                 outputHtml('</ol>');
110         } else {
111                 // logs directory does not exist
112                 loadTemplate('admin_settings_saved', false, '{--ADMIN_LOGS_DIR_404--}');
113         }
114 }
115
116 // [EOF]
117 ?>