]> git.mxchange.org Git - mailer.git/blobdiff - inc/modules/admin/what-logs.php
Huge rewrite:
[mailer.git] / inc / modules / admin / what-logs.php
index c88090e1714b1293fe69eca592893467f15b989b..49b9553395e5463bd783678d69ff69f6f34ad743 100644 (file)
 
 // Some security stuff...
 if ((!defined('__SECURITY')) || (!IS_ADMIN())) {
-       $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
+       $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), '/inc') + 4) . '/security.php';
        require($INC);
 }
 
 // Add description as navigation point
-ADD_DESCR("admin", __FILE__);
+ADD_DESCR('admin', __FILE__);
 
-if (REQUEST_ISSET_GET(('access'))) {
+if (REQUEST_ISSET_GET('access')) {
        // Secure input and construct FQFN
        $access = SQL_ESCAPE(strip_tags(REQUEST_GET('access')));
        $target = sprintf("%slogs/%s", constant('PATH'), $access);
 
        // Is the file valid and readable?
-       if (FILE_READABLE($target)) {
+       if (isFileReadable($target)) {
                // Load it directly
-               $content = READ_FILE($target);
+               $content = readFromFile($target);
 
                // Save old content
                $OUTPUT = ob_get_contents();
@@ -62,21 +62,21 @@ if (REQUEST_ISSET_GET(('access'))) {
                clearOutputBuffer();
 
                // Set header
-               if (substr($access, -3, 3) == "log") {
+               if (substr($access, -3, 3) == 'log') {
                        // Output header
-                       header("Content-Type: text/plain");
-               } elseif (substr($access, -3, 3) == ".gz") {
+                       sendHeader('Content-Type: text/plain');
+               } elseif (substr($access, -3, 3) == '.gz') {
                        // @TODO Fix content-type here
-                       header("Content-Type: text/plain");
-               } elseif (substr($access, -3, 3) == ".bz2") {
+                       sendHeader('Content-Type: text/plain');
+               } elseif (substr($access, -3, 3) == '.bz2') {
                        // @TODO Fix content-type here
-                       header("Content-Type: text/plain");
+                       sendHeader('Content-Type: text/plain');
                } else {
                        // Restore old content
                        OUTPUT_HTML($OUTPUT);
 
                        // Output message
-                       LOAD_TEMPLATE("admin_settings_saved", false, sprintf(getMessage('ADMIN_UNKNOWN_LOGFILE_FORMAT'), $access));
+                       LOAD_TEMPLATE('admin_settings_saved', false, sprintf(getMessage('ADMIN_UNKNOWN_LOGFILE_FORMAT'), $access));
                        return;
                }
 
@@ -85,29 +85,33 @@ if (REQUEST_ISSET_GET(('access'))) {
                shutdown();
        } else {
                // Not readable!
-               LOAD_TEMPLATE("admin_settings_saved", false, sprintf(getMessage('LOGFILE_NOT_READABLE'), $access));
+               LOAD_TEMPLATE('admin_settings_saved', false, sprintf(getMessage('LOGFILE_NOT_READABLE'), $access));
        }
 } else {
-       // List access logfiles
-       $dir = constant('PATH') . getConfig('logs_base') . "/";
-       if (isDirectory($dir)) {
-               // logs directory does exist
-               OUTPUT_HTML("<ol>");
-               $handle = opendir($dir) or app_die(__FILE__, __LINE__, "Cannot open directory ".getConfig('logs_base')."!");
-               while ($file = readdir($handle)) {
-                       // We currenly only like files with "access" as prefix, should be more flexible!
-                       if (substr($file, 0, 6) == "access") {
-                               // Okay, let us print it out
-                               OUTPUT_HTML("<li><a href=\"{!URL!}/modules.php?module=admin&amp;what=".$GLOBALS['what']."&amp;access=".urlencode($file)."\">".$file."</a></li>");
-                       }
-               }
-               closedir($handle);
-               OUTPUT_HTML("</ol>");
+       // Is the directory there?
+       if (isDirectory(constant('PATH') . getConfig('logs_base'))) {
+               // Logs directory does exist so begin the list
+               OUTPUT_HTML('<ol>');
+
+               // Read all files
+               $files = getArrayFromDirectory(getConfig('logs_base'), 'access');
+
+               // And walk through them
+               foreach ($files as $file) {
+                       // Cut dirname away
+                       $file = basename($file);
+
+                       // Okay, let us print it out
+                       OUTPUT_HTML("<li><a href=\"{!URL!}/modules.php?module=admin&amp;what=".getWhat()."&amp;access=".urlencode($file)."\">".$file."</a></li>");
+               } // END - foreach
+
+               // Finish list
+               OUTPUT_HTML('</ol>');
        } else {
                // logs directory does not exist
-               LOAD_TEMPLATE("admin_settings_saved", false, sprintf(getMessage('ADMIN_LOGS_DIR_404'), getConfig('logs_base')));
+               LOAD_TEMPLATE('admin_settings_saved', false, sprintf(getMessage('ADMIN_LOGS_DIR_404'), getConfig('logs_base')));
        }
 }
 
-//
+// [EOF]
 ?>