[geeklog-cvs] geeklog-1.3/plugins/spamx EditHeader.Admin.class.php,NONE,1.1 Header.Examine.class.php,NONE,1.1

dhaun at iowaoutdoors.org dhaun at iowaoutdoors.org
Sat Apr 2 08:29:06 EST 2005


Update of /var/cvs/geeklog-1.3/plugins/spamx
In directory www:/tmp/cvs-serv13057

Added Files:
	EditHeader.Admin.class.php Header.Examine.class.php 
Log Message:
New SpamX module to filter by the HTTP request headers (to do: move text strings to the language files ...)


--- NEW FILE: Header.Examine.class.php ---
<?php

/**
* File: Header.Examine.class.php
* This is the HTTP Header Examine class for the Geeklog SpamX Plug-in!
*
* Copyright (C) 2005 by the following authors:
* Author    Dirk Haun <dirk AT haun-online DOT de>
*
* based on the works of Tom Willett <tomw AT pigstye DOT net>
*
* Licensed under the GNU General Public License
*
* $Id: Header.Examine.class.php,v 1.1 2005/04/02 13:29:03 dhaun Exp $
*/

/**
* Include Abstract Examine Class
*/
require_once($_CONF['path'] . 'plugins/spamx/' . 'BaseCommand.class.php');

/**
* Examines Post according to HTTP Headers
*
* @author Dirk Haun <dirk AT haun-online DOT de>
*/

class Header extends BaseCommand {
    /**
     * No Constructor Use BaseCommand constructor
     */
    /**
     * Here we do the work
     */
    function execute($comment)
    {
        global $_CONF, $_TABLES, $_USER, $LANG_SX00, $result;

        if (isset ($_USER['uid']) && ($_USER['uid'] > 1)) {
            $uid = $_USER['uid'];
        } else {
            $uid = 1;
        }

        // get HTTP headers of the current request
        if (function_exists ('getallheaders')) {
            $headers = getallheaders ();
        } else {
            // if getallheaders() is not available, we have to fake it using
            // the $_SERVER['HTTP_...'] values
            $headers = array ();
            foreach ($_SERVER as $key => $content) {
                if (substr ($key, 0, 4) == 'HTTP') {
                    $name = str_replace ('_', '-', substr ($key, 5));
                    $headers[$name] = $content;
                }
            }
        }

        $result = DB_query ("SELECT value FROM {$_TABLES['spamx']} WHERE name='HTTPHeader'", 1);
        $nrows = DB_numRows ($result);

        $ans = 0;
        for ($i = 0; $i < $nrows; $i++) {
            list ($entry) = DB_fetchArray ($result);

            $v = explode (':', $entry);
            $name = trim ($v[0]);
            $value = trim ($v[1]);

            foreach ($headers as $key => $content) {
                if (strcasecmp ($name, $key) == 0) {
                    if (preg_match ("#$value#i", $content)) {
                        $ans = 1; // quit on first positive match
                        SPAMX_log ($LANG_SX00['foundspam'] . $entry .
                                   $LANG_SX00['foundspam2'] . $uid . 
                                   $LANG_SX00['foundspam3'] .
                                   $_SERVER['REMOTE_ADDR']);
                    }
                }
            }
        }

        return $ans;
    }
}

?>

--- NEW FILE: EditHeader.Admin.class.php ---
<?php
/**
* File: EditHeader.Admin.class.php
* This is the Edit HTTP Header Module for the Geeklog SpamX Plug-in!
*
* Copyright (C) 2005 by the following authors:
* Author    Dirk Haun <dirk AT haun-online DOT de>
*
* based on the works of Tom Willett <tomw AT pigstye DOT net>
*
* Licensed under GNU General Public License
*
* $Id: EditHeader.Admin.class.php,v 1.1 2005/04/02 13:29:03 dhaun Exp $
*/

/**
* HTTP Header Editor
*/

require_once($_CONF['path'] . 'plugins/spamx/BaseAdmin.class.php');

class EditHeader extends BaseAdmin {
    /**
     * Constructor
     */
    function display()
    {
        global $_CONF, $_GET, $_POST, $_TABLES, $LANG_SX00;

        $action = COM_applyFilter ($_GET['action']);
        if (empty ($action)) {
            $action = COM_applyFilter ($_POST['paction']);
        }

        if ($action == 'delete') {
            $entry = $_GET['entry'];
            if (!empty ($entry)) {
                $dbentry = addslashes ($entry);
                $result = DB_query ("DELETE FROM {$_TABLES['spamx']} WHERE name='HTTPHeader' AND value='$dbentry'");
            }
        } elseif ($action == $LANG_SX00['addentry']) {
            $entry = '';
            $name = COM_applyFilter ($_REQUEST['header-name']);
            $n = explode (':', $name);
            $name = $n[0];
            $value = $_REQUEST['header-value'];

            if (!empty ($name) && !empty ($value)) {
                $entry = $name . ': ' . $value;
            }

            $dbentry = addslashes ($entry);
            if (!empty ($entry)) {
                $result = DB_query ("INSERT INTO {$_TABLES['spamx']} VALUES ('HTTPHeader','$dbentry')");
            }
        }

        $display = '<hr><p><b>';
        $display .= $LANG_SX00['pblack'];
        $display .= '</b></p><ul>';
        $result = DB_query ("SELECT value FROM {$_TABLES['spamx']} WHERE name='HTTPHeader' ORDER BY value");
        $nrows = DB_numRows ($result);
        for ($i = 0; $i < $nrows; $i++) {
            list($e) = DB_fetchArray ($result);

            $display .= '<li><a href="' . $_CONF['site_admin_url'] . '/plugins/spamx/index.php?command=EditHeader&action=delete&entry=' . urlencode ($e) . '">' . $e . '</a></li>';
        }
        $display .= '</ul><p>' . $LANG_SX00['e1'] . '</p>';
        $display .= '<p>' . $LANG_SX00['e2'] . '</p>';

        $display .= '<form method="POST" action="' . $_CONF['site_admin_url'] . '/plugins/spamx/index.php?command=EditHeader">';
        $display .= '<table border="0" width="100%">' . LB;
        $display .= '<tr><td align="right"><b>Header:</b></td>' . LB;
        $display .= '<td><input type="text" site="40" name="header-name"> e.g. <tt>User-Agent</tt></td></tr>' . LB;
        $display .= '<tr><td align="right"><b>Content:</b></td>' . LB;
        $display .= '<td><input type="text" site="40" name="header-value"> e.g. <tt>Mozilla</tt></td></tr>' . LB;
        $display .= '</table>' . LB;
        $display .= '<p><input type="Submit" name="paction" value="' . $LANG_SX00['addentry'] . '">';
        $display .= '</form>';
        return $display;
    }

    function link()
    {
        return "Edit HTTP Header Blacklist";
    }
}

?>




More information about the geeklog-cvs mailing list