Beispiel #1
0
function spamhurdle_block_replay_after_post($data)
{
    global $PHORUM;
    // Register the used key in the database.
    if (!spamhurdles_db_init()) {
        return $data;
    }
    spamhurdles_db_put($data['key'], TRUE, $PHORUM['mod_spamhurdles']['key_max_ttl']);
    return $data;
}
Beispiel #2
0
function phorum_mod_spamhurdles_common()
{
    global $PHORUM;
    // Initialize the database layer. This will handle automatic installation
    // and upgrading of the database structure. Do not continue running the
    // Spam Hurldes module in case the initialization fails.
    if (!spamhurdles_db_init()) {
        return;
    }
    // Garbage collection for cleaning up expired items from the database.
    if (rand(1, 100) <= SPAMHURDLES_GARBAGE_COLLECTION_RATE) {
        spamhurdles_db_remove_expired();
    }
    // See if the old post.php script is called. This one is sometimes
    // left behind on systems after upgrading, but it should no longer
    // be used for posting. Since this script is not protected against
    // spamming, we fully deny access to it here.
    if (strstr($_SERVER["PHP_SELF"], "post.php")) {
        die("Illegal access to post.php. That script is the message posting " . "script for Phorum 5.0. Phorum 5.1 and higher use posting.php " . "instead. The post.php script might be a left-behind from a " . "Phorum 5.0 upgrade. It should be removed from the server.");
    }
    $conf = $PHORUM["mod_spamhurdles"];
    // See if there's a spamhurdles key available in the request.
    $key = NULL;
    if (isset($PHORUM["args"]["spokencaptcha"])) {
        $key = $PHORUM["args"]["spokencaptcha"];
    } elseif (isset($PHORUM["args"]["imagecaptcha"])) {
        $key = $PHORUM["args"]["imagecaptcha"];
    } elseif (isset($_POST["spamhurdles_key"])) {
        $key = $_POST["spamhurdles_key"];
    }
    // Our main data storage for this module.
    $PHORUM["SPAMHURDLES"] = NULL;
    // If there was a key, then retrieve the spamhurdles information for
    // that key from the database. If there was no key or an expired
    // key, keep track of that (used in case we want to post
    // messages with an expired key as unapproved).
    $PHORUM["SPAMHURDLES_KEY_STATUS"] = KEY_NOTAVAIL;
    if ($key !== NULL) {
        $spamhurdles = spamhurdles_db_get($key);
        if (!empty($spamhurdles)) {
            $PHORUM["SPAMHURDLES"] = $spamhurdles;
            $PHORUM["SPAMHURDLES_KEY_STATUS"] = KEY_AVAIL;
        } else {
            // Early bail out option for expired or already used keys,
            if (phorum_page == "post" && do_spamhurdle("blockmultipost") && $conf["blockaction"] == "blockerror") {
                spamhurdles_blockerror();
            }
            $PHORUM["SPAMHURDLES_KEY_STATUS"] = KEY_EXPIRED;
        }
    }
    // If a spoken captcha is requested, then generate a wav file for it
    // and stream it to the user.
    if (isset($PHORUM["args"]["spokencaptcha"])) {
        include "./mods/spamhurdles/captcha/spoken_captcha.php";
        exit(0);
    }
    // If a CAPTCHA image is requested, then let the CAPTCHA class that we
    // used for generating the CAPTCHA generate the image (this class must
    // have a generate_image() method for doing this).
    if (isset($PHORUM["args"]["imagecaptcha"])) {
        if (isset($PHORUM["SPAMHURDLES"]["captcha"]["question"]) && isset($PHORUM["SPAMHURDLES"]["captcha_class"])) {
            $question = $PHORUM["SPAMHURDLES"]["captcha"]["question"];
            $class = $PHORUM["SPAMHURDLES"]["captcha_class"];
            require_once "./mods/spamhurdles/captcha/class.{$class}.php";
            $captcha = new $class();
            $captcha->generate_image($question);
            exit(0);
        } else {
            die("<h1>Internal Spam Hurdles module error</h1>" . "Image captcha requested, but not all spamhurdles " . "info is available.");
        }
    }
    // See if we switched to another key. If this is the case, we
    // can delete the previously cashed key's data.
    if (isset($_COOKIE["mod_spamhurdles_key"])) {
        $oldkey = $_COOKIE["mod_spamhurdles_key"];
        if (isset($key) && $oldkey !== $key) {
            phorum_mod_spamhurdles_cleanup_key($oldkey);
            setcookie("mod_spamhurdles_key", "", time() - 86400);
        }
    }
    // We use (a modified version of) iScramble on several occasions.
    // Load a little javascript function that we need for it.
    $PHORUM['DATA']['HEAD_TAGS'] .= iScramble_javascript();
}