Skip to content
This repository
tree: 87d48e48c5
Fetching contributors…

Cannot retrieve contributors at this time

file 137 lines (101 sloc) 4.9 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
<?php

/*======================================================================
Copyright Project BeehiveForum 2002

This file is part of BeehiveForum.

BeehiveForum is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

BeehiveForum is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with Beehive; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
USA
======================================================================*/

// Constant to define where the Beehive Forum include files are
define("BH_INCLUDE_PATH", "../forum/include/");

// Beehive Forum configuration.
include_once(BH_INCLUDE_PATH. "config.inc.php");

// Development configuration
if (@file_exists(BH_INCLUDE_PATH. "config-dev.inc.php")) {
    include_once(BH_INCLUDE_PATH. "config-dev.inc.php");
}

// Put Ewiki in protected mode and default to view / browse only
define("EWIKI_PROTECTED_MODE", 1);
define("EWIKI_AUTH_DEFAULT_RING", 3);

// We need this script from EWiki as well
include("plugins/auth/auth_perm_ring.php");

// Set ourselves up with EWiki.
$ewiki_plugins["auth_query"][] = "ewiki_auth_query_beehive";
$ewiki_plugins["auth_userdb"][] = "ewiki_auth_userdb_beehive";

function ewiki_auth_query_beehive($data, $force_query = false)
{
    global $ewiki_errmsg;

    $t_success = false;

    if (isset($_COOKIE['bh_ewiki_logon']) && strlen(trim($_COOKIE['bh_ewiki_logon'])) > 0) {

        list($t_logon, $t_passwd) = explode(':', base64_decode($_COOKIE["bh_ewiki_logon"]));

    }else {

        if (isset($_POST['logon']) && strlen(trim($_POST['logon'])) > 0) {
            $t_logon = $_POST['logon'];
        }

        if (isset($_POST['passwd']) && strlen(trim($_POST['passwd'])) > 0) {
            $t_passwd = $_POST['passwd'];
        }
    }

    if (isset($t_logon) && isset($t_passwd)) {

        if (($t_success = ewiki_auth_user($t_logon, $t_passwd))) {

            setcookie("bh_ewiki_logon", base64_encode("$t_logon:$t_passwd"), 0);
        }
    }

    if ($force_query && !$t_success || ($force_query >= 2)) {

        $ewiki_errmsg.= "<form accept-charset=\"utf-8\" action=\"{$_SERVER['REQUEST_URI']}\" method=\"post\">\n";
        $ewiki_errmsg.= "<p>Please enter your forum logon and password below to continue.</p>\n";
        $ewiki_errmsg.= "<table>\n";
        $ewiki_errmsg.= " <tr>\n";
        $ewiki_errmsg.= " <td>". ewiki_t("_{Logon}"). ":</td>\n";
        $ewiki_errmsg.= " <td>". ewiki_t("<input type=\"text\" size=\"20\" name=\"logon\">"). "</td>\n";
        $ewiki_errmsg.= " </tr>\n";
        $ewiki_errmsg.= " <tr>\n";
        $ewiki_errmsg.= " <td>". ewiki_t("_{Password}"). ":</td>\n";
        $ewiki_errmsg.= " <td>". ewiki_t("<input type=\"password\" size=\"20\" name=\"passwd\">"). "</td>\n";
        $ewiki_errmsg.= " </tr>\n";
        $ewiki_errmsg.= " <tr>\n";
        $ewiki_errmsg.= " <td>&nbsp;</td>\n";
        $ewiki_errmsg.= " <td>". ewiki_t("<input type=\"submit\" value=\"_{Logon}\">"). "</td>\n";
        $ewiki_errmsg.= " </tr>\n";
        $ewiki_errmsg.= "</table>\n";

        if (defined("EWIKI_AUTH_QUERY_SAFE")) {

            foreach ($_POST as $key => $value) {

                if ($key == "logon" || $key == "passwd") continue;
                $ewiki_errmsg.= "<input type=\"hidden\" name=\"{$key}\" value=\"". preg_replace('/([^\w\d\260-\377])/eu', '"&#".ord("$1").";"', $value). "\">\n";
            }
        }

        $ewiki_errmsg.= "</form>\n";
    }

    return $t_success;
}

function ewiki_auth_userdb_beehive($username, $password)
{
    // Beehive include files that we need.
    include_once(BH_INCLUDE_PATH. "db.inc.php");
    include_once(BH_INCLUDE_PATH. "logon.inc.php");
    include_once(BH_INCLUDE_PATH. "session.inc.php");

    // Reset the PHP error reporting level and disable
    // Beehive's error handler - Ewiki isn't as well
    // written as Beehive ;)
    restore_error_handler();
    error_reporting(E_ALL ^ E_NOTICE);

    // Attempt user logon
    if (($uid = user_logon($username, $password))) {

        if (session_init($uid)) {

            if (session_user_banned()) return false;
            if (session_check_perm(USER_PERM_ADMIN_TOOLS | USER_PERM_FORUM_TOOLS, 0)) return array($password, 0);

            return array($password, 2);
        }
    }

    return array($password, 3);
}

?>
Something went wrong with that request. Please try again.