plugins/spamx/Header.Examine.class.php
author Dirk Haun <dirk@haun-online.de>
Thu, 29 Oct 2009 13:00:11 +0100
branchHEAD
changeset 7397 c27e9026f22a
parent 6842 e08747bfab7c
permissions -rw-r--r--
Fixed inclusion protection
     1 <?php
     2 
     3 /**
     4 * File: Header.Examine.class.php
     5 * This is the HTTP Header Examine class for the Geeklog Spam-X plugin
     6 *
     7 * Copyright (C) 2005-2009 by the following authors:
     8 * Author    Dirk Haun <dirk AT haun-online DOT de>
     9 *
    10 * based on the works of Tom Willett <tomw AT pigstye DOT net>
    11 *
    12 * Licensed under the GNU General Public License
    13 *
    14 * @package Spam-X
    15 * @subpackage Modules
    16 */
    17 
    18 if (strpos(strtolower($_SERVER['PHP_SELF']), 'header.examine.class.php') !== false) {
    19     die('This file can not be used on its own!');
    20 }
    21 
    22 /**
    23 * Include Abstract Examine Class
    24 */
    25 require_once $_CONF['path'] . 'plugins/spamx/' . 'BaseCommand.class.php';
    26 
    27 /**
    28 * Examines Post according to HTTP Headers
    29 *
    30 * @author Dirk Haun, dirk AT haun-online DOT de
    31 *
    32 * @package Spam-X
    33 *
    34 */
    35 class Header extends BaseCommand {
    36     /**
    37      * No Constructor Use BaseCommand constructor
    38      */
    39     /**
    40      * Here we do the work
    41      */
    42     function execute($comment)
    43     {
    44         global $_CONF, $_TABLES, $_USER, $LANG_SX00, $result;
    45 
    46         if (isset ($_USER['uid']) && ($_USER['uid'] > 1)) {
    47             $uid = $_USER['uid'];
    48         } else {
    49             $uid = 1;
    50         }
    51 
    52         // get HTTP headers of the current request
    53         if (function_exists ('getallheaders')) {
    54             $headers = getallheaders ();
    55         } else {
    56             // if getallheaders() is not available, we have to fake it using
    57             // the $_SERVER['HTTP_...'] values
    58             $headers = array ();
    59             foreach ($_SERVER as $key => $content) {
    60                 if (substr ($key, 0, 4) == 'HTTP') {
    61                     $name = str_replace ('_', '-', substr ($key, 5));
    62                     $headers[$name] = $content;
    63                 }
    64             }
    65         }
    66 
    67         $result = DB_query ("SELECT value FROM {$_TABLES['spamx']} WHERE name='HTTPHeader'", 1);
    68         $nrows = DB_numRows ($result);
    69 
    70         $ans = 0;
    71         for ($i = 0; $i < $nrows; $i++) {
    72             list ($entry) = DB_fetchArray ($result);
    73 
    74             $v = explode (':', $entry);
    75             $name = trim ($v[0]);
    76             $value = trim ($v[1]);
    77             $value = str_replace ('#', '\\#', $value);
    78 
    79             foreach ($headers as $key => $content) {
    80                 if (strcasecmp ($name, $key) == 0) {
    81                     if (preg_match ("#$value#i", $content)) {
    82                         $ans = 1; // quit on first positive match
    83                         SPAMX_log ($LANG_SX00['foundspam'] . $entry .
    84                                    $LANG_SX00['foundspam2'] . $uid . 
    85                                    $LANG_SX00['foundspam3'] .
    86                                    $_SERVER['REMOTE_ADDR']);
    87                         break;
    88                     }
    89                 }
    90             }
    91         }
    92 
    93         return $ans;
    94     }
    95 }
    96 
    97 ?>