New function isDirectory() introduced, fixed GET_DIR_AS_ARRAY() (replaces scandir())
[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:: 856                                                    $ *
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 (FILE_READABLE($target)) {
55                 // Load it directly
56                 $content = READ_FILE($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                         header("Content-Type: text/plain");
68                 } elseif (substr($access, -3, 3) == ".gz") {
69                         // @TODO Fix content-type here
70                         header("Content-Type: text/plain");
71                 } elseif (substr($access, -3, 3) == ".bz2") {
72                         // @TODO Fix content-type here
73                         header("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         if (isDirectory($dir)) {
94                 // logs directory does exist
95                 OUTPUT_HTML("<ol>");
96                 $handle = opendir($dir) or mxchange_die("Cannot open directory ".getConfig('logs_base')."!");
97                 while ($file = readdir($handle)) {
98                         // We currenly only like files with "access" as prefix, should be more flexible!
99                         if (substr($file, 0, 6) == "access") {
100                                 // Okay, let us print it out
101                                 OUTPUT_HTML("<li><a href=\"{!URL!}/modules.php?module=admin&amp;what=".$GLOBALS['what']."&amp;access=".urlencode($file)."\">".$file."</a></li>");
102                         }
103                 }
104                 closedir($handle);
105                 OUTPUT_HTML("</ol>");
106         } else {
107                 // logs directory does not exist
108                 LOAD_TEMPLATE("admin_settings_saved", false, sprintf(getMessage('ADMIN_LOGS_DIR_404'), getConfig('logs_base')));
109         }
110 }
111
112 //
113 ?>