2 /************************************************************************
3 * MXChange v0.2.1 Start: 11/15/2003 *
4 * =============== Last change: 04/02/2004 *
6 * -------------------------------------------------------------------- *
7 * File : what-logs.php *
8 * -------------------------------------------------------------------- *
9 * Short description : Management for access log files *
10 * -------------------------------------------------------------------- *
11 * Kurzbeschreibung : Management fuer Zugriffslogbuecher *
12 * -------------------------------------------------------------------- *
15 * $Tag:: 0.2.1-FINAL $ *
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 *
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. *
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. *
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, *
37 ************************************************************************/
39 // Some security stuff...
40 if ((!defined('__SECURITY')) || (!IS_ADMIN())) {
41 $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), '/inc') + 4) . '/security.php';
45 // Add description as navigation point
46 ADD_DESCR('admin', __FILE__);
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);
53 // Is the file valid and readable?
54 if (isFileReadable($target)) {
56 $content = readFromFile($target);
59 $OUTPUT = ob_get_contents();
65 if (substr($access, -3, 3) == 'log') {
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');
75 // Restore old content
79 LOAD_TEMPLATE('admin_settings_saved', false, sprintf(getMessage('ADMIN_UNKNOWN_LOGFILE_FORMAT'), $access));
83 // Output the logfile's content and exit
88 LOAD_TEMPLATE('admin_settings_saved', false, sprintf(getMessage('LOGFILE_NOT_READABLE'), $access));
91 // List access logfiles
92 $dir = constant('PATH') . getConfig('logs_base') . '/';
94 // Is the directory there?
95 if (isDirectory($dir)) {
96 // logs directory does exist
98 $handle = opendir($dir) or app_die(__FILE__, __LINE__, 'Cannot open directory '.getConfig('logs_base') . '!');
99 while ($file = readdir($handle)) {
100 // We currenly only like files with "access" as prefix, should be more flexible!
101 if (substr($file, 0, 6) == 'access') {
102 // Okay, let us print it out
103 OUTPUT_HTML("<li><a href=\"{!URL!}/modules.php?module=admin&what=".$GLOBALS['what']."&access=".urlencode($file)."\">".$file."</a></li>");
107 OUTPUT_HTML("</ol>");
109 // logs directory does not exist
110 LOAD_TEMPLATE('admin_settings_saved', false, sprintf(getMessage('ADMIN_LOGS_DIR_404'), getConfig('logs_base')));