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