Functions imported, some dev-scripts added
[mailer.git] / inc / modules / admin / what-usage.php
1 <?php
2 /************************************************************************
3  * MXChange v0.2.1                                    Start: 11/15/2003 *
4  * ===============                              Last change: 04/02/2004 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : what-usage.php                                   *
8  * -------------------------------------------------------------------- *
9  * Short description : Auto-detection of usage statistics               *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Automatische Erkennung der Aufrufstatistiken     *
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 // Base directory (should be moved to database)
44 $usage = getConfig('usage_base')."/";
45
46 if (!empty($_GET['image'])) {
47         if ($_GET['type'] == "usage") {
48                 $FQFN = sprintf("%s%s/usage.png",
49                         constant('PATH'),
50                         getConfig('usage_base')
51                 );
52         } else {
53                 if (strpos($_GET['image'], "\\") > 0) $_GET['image'] = substr($_GET['image'], 0, strpos($_GET['image'], "\\"));
54                 $FQFN = sprintf("%s%s/%s_usage_%s.png",
55                         constant('PATH'),
56                         getConfig('usage_base'),
57                         SQL_ESCAPE($_GET['type']),
58                         SQL_ESCAPE($_GET['image'])
59                 );
60         }
61
62         if (FILE_READABLE($FQFN)) {
63                 $image = imagecreatefrompng($FQFN);
64                 header("Content-type: image/png");
65                 imagepng($image);
66                 imagedestroy($image);
67         }
68         exit();
69 } elseif (empty($_GET['usage'])) {
70         $FQFN = sprintf("%s%s/index.html",
71                 constant('PATH'),
72                 getConfig('usage_base')
73         );
74 } else {
75         $FQFN = sprintf("%s%s/usage_%s.html",
76                 constant('PATH'),
77                 getConfig('usage_base'),
78                 SQL_ESCAPE($_GET['usage'])
79         );
80 }
81
82 if ((!empty($FQFN)) && (FILE_READABLE($FQFN))) {
83         // @TODO This code is double, see LOAD_TEMPLATE and LOAD_EMAIL_TEMPLATE in functions.php
84         $tmpl_file = READ_FILE($FQFN);
85         $tmpl_file = SQL_ESCAPE($tmpl_file);
86         $tmpl_file = "\$content=\"".$tmpl_file."\";";
87         eval($tmpl_file);
88         // Until here...
89
90         // Replace URLs
91         $content = str_replace("usage.png", "{!URL!}/modules.php?module=admin&amp;what=".$GLOBALS['what']."&type=usage&image=usage", $content);
92         $content = str_replace("daily_usage_", "{!URL!}/modules.php?module=admin&amp;what=".$GLOBALS['what']."&type=daily&image=", $content);
93         $content = str_replace("hourly_usage_", "{!URL!}/modules.php?module=admin&amp;what=".$GLOBALS['what']."&type=hourly&image=", $content);
94         $content = str_replace("ctry_usage_", "{!URL!}/modules.php?module=admin&amp;what=".$GLOBALS['what']."&type=ctry&image=", $content);
95         $content = str_replace("usage_", "{!URL!}/modules.php?module=admin&amp;what=".$GLOBALS['what']."&usage=", str_replace(".html", "", $content));
96
97         // Disabled due to too much trouble
98         //$content = str_replace("HREF=\"http://", "href=\"{!URL!}/modules.php?module=loader&amp;url=http://", $content);
99         $test = strtolower($content);
100
101         // Do we need to strip out above and including <body> plus trailing </html> tag?
102         if ((strpos($test, "<body") > 0) && (strpos($test, "</body>") > 0)) {
103                 // Okay, then do so.
104                 $content = substr(substr($content, 0, $body_end), $body_start);
105                 $content = substr($content, strpos($content, ">") + 1);
106         } // END - if
107
108         // Output code
109         OUTPUT_HTML("<div align=\"left\">
110   ".$content."
111 </div>");
112 } else {
113         // Nothing to load, then we have no directory "usage"
114         LOAD_TEMPLATE("admin_settings_saved", false, sprintf(ADMIN_USAGE_DIRECTORY_404, getConfig('usage_base')));
115 }
116
117 //
118 ?>