plugins/spamx/LogView.Admin.class.php
author Dirk Haun <dirk@haun-online.de>
Thu, 29 Oct 2009 13:00:11 +0100
branchHEAD
changeset 7397 c27e9026f22a
parent 6838 cb1ba8d99085
permissions -rw-r--r--
Fixed inclusion protection
     1 <?php
     2 
     3 /**
     4  * File: Logview.Admin.class.php
     5  * This is the LogViewer for the Geeklog Spam-X plugin
     6  *
     7  * Copyright (C) 2004-2006 by the following authors:
     8  * Author       Tom Willett     tomw AT pigstye DOT net
     9  *
    10  * Licensed under GNU General Public License
    11  *
    12  * @package Spam-X
    13  * @subpackage Modules
    14  */
    15 
    16 if (strpos(strtolower($_SERVER['PHP_SELF']), 'logview.admin.class.php') !== false) {
    17     die('This file can not be used on its own!');
    18 }
    19 
    20 /**
    21 * Include Abstract Base Class
    22 */
    23 require_once $_CONF['path'] . 'plugins/spamx/BaseAdmin.class.php';
    24 
    25 /**
    26 * LogView class
    27 *
    28 * @package Spam-X
    29 *
    30 */
    31 class LogView extends BaseAdmin {
    32     /**
    33      * Constructor
    34      */
    35     function display()
    36     {
    37         global $_CONF, $LANG_SX00;
    38 
    39         $display = '';
    40 
    41         $max_Log_Size = 100000;
    42         $action = '';
    43         if (isset ($_POST['action'])) {
    44             $action = COM_applyFilter ($_POST['action']);
    45         }
    46         $path = $_CONF['site_admin_url']
    47               . '/plugins/spamx/index.php?command=LogView';
    48         $log = 'spamx.log';
    49         $display .= "<form method=\"post\" action=\"{$path}\"><div>";
    50         $display .= "<input type=\"submit\" name=\"action\" value=\"{$LANG_SX00['clearlog']}\"" . XHTML . ">";
    51         $display .= "</div></form>";
    52         if ($action == $LANG_SX00['clearlog']) {
    53             $timestamp = strftime("%c");
    54             $fd = fopen($_CONF['path_log'] . $log, "w");
    55             fputs($fd, "$timestamp {$LANG_SX00['logcleared']} \n");
    56             fclose($fd);
    57         }
    58         $fsize = filesize($_CONF['path_log'] . $log);
    59         if ($fsize > $max_Log_Size) {
    60           $fd=fopen($_CONF['path_log'] . $log, "r");
    61           fseek($fd,-$max_Log_Size,SEEK_END);
    62           $data = fgets($fd);
    63           $data = fread($fd,$max_Log_Size);
    64           fclose($fd);
    65           $fd = fopen($_CONF['path_log'] . $log, "w");
    66           fputs($fd, "$timestamp {$LANG_SX00['logcleared']} \n");
    67           fwrite($fd,$data);
    68           fclose($fd);
    69         }
    70         $display .= "<hr" . XHTML . "><pre>";
    71         $display .= implode('', file($_CONF['path_log'] . $log));
    72         $display .= "</pre>";
    73         return $display;
    74     }
    75 
    76     function link()
    77     {
    78         global $LANG_SX00;
    79 
    80         return $LANG_SX00['viewlog'];
    81     }
    82 }
    83 
    84 ?>