More language strings rewritten
[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", __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", constant('PATH'), $access);
47
48         // Is the file valid and readable?
49         if (FILE_READABLE($target)) {
50                 // Load it directly
51                 $content = READ_FILE($target);
52
53                 // Save old content
54                 $OUTPUT = ob_get_contents();
55
56                 // Clean content
57                 clearOutputBuffer();
58
59                 // Set header
60                 if (substr($access, -3, 3) == "log") {
61                         // Output header
62                         header("Content-Type: text/plain");
63                 } elseif (substr($access, -3, 3) == ".gz") {
64                         // @TODO Fix content-type here
65                         header("Content-Type: text/plain");
66                 } elseif (substr($access, -3, 3) == ".bz2") {
67                         // @TODO Fix content-type here
68                         header("Content-Type: text/plain");
69                 } else {
70                         // Restore old content
71                         OUTPUT_HTML($OUTPUT);
72
73                         // Output message
74                         LOAD_TEMPLATE("admin_settings_saved", false, sprintf(getMessage('ADMIN_UNKNOWN_LOGFILE_FORMAT'), $access));
75                         return;
76                 }
77
78                 // Output the logfile's content and exit
79                 print($content);
80                 exit;
81         } else {
82                 // Not readable!
83                 LOAD_TEMPLATE("admin_settings_saved", false, sprintf(getMessage('LOGFILE_NOT_READABLE'), $access));
84         }
85 } else {
86         // List access logfiles
87         $dir = PATH.getConfig('logs_base')."/";
88         if (is_dir($dir)) {
89                 // logs directory does exist
90                 OUTPUT_HTML("<ol>");
91                 $handle = opendir($dir) or mxchange_die("Cannot open directory ".getConfig('logs_base')."!");
92                 while ($file = readdir($handle)) {
93                         // We currenly only like files with "access" as prefix, should be more flexible!
94                         if (substr($file, 0, 6) == "access") {
95                                 // Okay, let us print it out
96                                 OUTPUT_HTML("<li><a href=\"{!URL!}/modules.php?module=admin&amp;what=".$GLOBALS['what']."&amp;access=".urlencode($file)."\">".$file."</a></li>");
97                         }
98                 }
99                 closedir($handle);
100                 OUTPUT_HTML("</ol>");
101         } else {
102                 // logs directory does not exist
103                 LOAD_TEMPLATE("admin_settings_saved", false, sprintf(getMessage('ADMIN_LOGS_DIR_404'), getConfig('logs_base')));
104         }
105 }
106
107 //
108 ?>