ff9c943614e9da6caefb5e5cfbb93dbe193f5920
[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  *                                                                      *
14  * -------------------------------------------------------------------- *
15  * Copyright (c) 2003 - 2008 by Roland Haeder                           *
16  * For more information visit: http://www.mxchange.org                  *
17  *                                                                      *
18  * This program is free software; you can redistribute it and/or modify *
19  * it under the terms of the GNU General Public License as published by *
20  * the Free Software Foundation; either version 2 of the License, or    *
21  * (at your option) any later version.                                  *
22  *                                                                      *
23  * This program is distributed in the hope that it will be useful,      *
24  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
25  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
26  * GNU General Public License for more details.                         *
27  *                                                                      *
28  * You should have received a copy of the GNU General Public License    *
29  * along with this program; if not, write to the Free Software          *
30  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
31  * MA  02110-1301  USA                                                  *
32  ************************************************************************/
33
34 // Some security stuff...
35 if ((!defined('__SECURITY')) || (!IS_ADMIN())) {
36         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
37         require($INC);
38 }
39
40 // Add description as navigation point
41 ADD_DESCR("admin", basename(__FILE__));
42
43 if (!empty($_GET['access'])) {
44         // Secure input and construct FQFN
45         $access = SQL_ESCAPE(strip_tags($_GET['access']));
46         $target = sprintf("%slogs/%s", PATH, $access);
47
48         // Is the file valid and readable?
49         if (FILE_READABLE($target)) {
50                 // Load it directly
51                 $content = implode("", file($target));
52
53                 // Set header
54                 if (substr($access, -3, 3) == "log") {
55                         header("Content-Type: text/plain");
56                 } elseif (substr($access, -3, 3) == ".gz") {
57                         header("Content-Type: text/plain");
58                 } else {
59                         LOAD_TEMPLATE("admin_settings_saved", false, UNKNOWN_LOGFILE_FORMAT_1.$access.UNKNOWN_LOGFILE_FORMAT_2);
60                         return;
61                 }
62
63                 // Clean content
64                 ob_end_clean();
65
66                 // Output the logfile's content and exit
67                 print($content);
68                 exit;
69         } else {
70                 // Not readable!
71                 LOAD_TEMPLATE("admin_settings_saved", false, LOGFILE_NOT_READABLE_1.$access.LOGFILE_NOT_READABLE_2);
72         }
73 } else {
74         // List access logfiles
75         $dir = PATH.LOGS_BASE."/";
76         if (is_dir($dir)) {
77                 // logs directory does exist
78                 OUTPUT_HTML("<OL>");
79                 $handle = @opendir($dir) or mxchange_die("Cannot open directory ".LOGS_BASE."!");
80                 while($file = @readdir($handle)) {
81                         // We currenly only like files with "access" as prefix, should be more flexible!
82                         if (substr($file, 0, 6) == "access") {
83                                 // Okay, let us print it out
84                                 OUTPUT_HTML("<LI><A href=\"".URL."/modules.php?module=admin&amp;what=".$GLOBALS['what']."&access=".urlencode($file)."\">".$file."</A></LI>");
85                         }
86                 }
87                 @closedir($handle);
88                 OUTPUT_HTML("</OL>");
89         }
90          else
91         {
92                 // logs directory does not exist
93                 LOAD_TEMPLATE("admin_settings_saved", false, ADMIN_LOGS_DIR_404_1.LOGS_BASE.ADMIN_LOGS_DIR_404_2);
94         }
95 }
96
97 //
98 ?>