Ejemplo n.º 1
0
function wifidog_auth()
{
    $token = $_GET["token"];
    $ARP = $_GET["mac"];
    $mac = $_GET["mac"];
    $ip = $_GET["ip"];
    $stage = $_GET["stage"];
    $token = $_GET["token"];
    $incoming = $_GET["incoming"];
    $outgoing = $_GET["outgoing"];
    $q = new mysql_squid_builder();
    ///hotspot.php?wifidog-auth=yes&stage=counters&ip=192.168.1.19&mac=00:15:5d:01:09:06&token=token&incoming=7161&outgoing=10255&gw_id=000C29D5571C
    if ($GLOBALS["HOTSPOT_DEBUG"]) {
        ToSyslog("wifidog_auth:: Receiving stage {$stage}");
    }
    if ($stage == "logout") {
        $q = new mysql_squid_builder();
        $ligne = mysql_fetch_array($q->QUERY_SQL("SELECT * FROM hotspot_sessions WHERE `md5`='{$token}'"));
        $username = $ligne["username"];
        events(1, "LOGOFF {$username}/{$mac}", null);
        $q->QUERY_SQL("DELETE FROM hotspot_sessions WHERE `md5`='{$token}'");
        $q->QUERY_SQL("DELETE FROM hotspot_sessions WHERE `MAC`='{$mac}'");
    }
    if ($stage == "counters") {
        $incoming = $incoming / 1024;
        $outgoing = $outgoing / 1024;
        if ($GLOBALS["HOTSPOT_DEBUG"]) {
            ToSyslog("wifidog_auth:: -> wifidog_auth_auto_created()");
        }
        if (wifidog_auth_auto_created($token)) {
            $q->QUERY_SQL("UPDATE hotspot_sessions SET `incoming`='{$incoming}',`outgoing`='{$outgoing}',`ipaddr`='{$ip}' WHERE `md5`='{$token}'");
            return;
        }
        if ($GLOBALS["HOTSPOT_DEBUG"]) {
            ToSyslog("wifidog_auth:: -> wifidog_is_end_of_life()");
        }
        if (wifidog_is_end_of_life($token)) {
            if ($GLOBALS["HOTSPOT_DEBUG"]) {
                ToSyslog("wifidog_auth:: * * * COUNTER: MAC: {$mac}, Token {$token} [End-Of-Life] * * *");
            }
            events(1, "COUNTER: MAC: {$mac}, Token {$token} [End-Of-Life]", null);
            echo "Auth: -1\n";
            echo "Messages: No session saved\n";
            return;
        }
        $q->QUERY_SQL("UPDATE hotspot_sessions SET `incoming`='{$incoming}',`outgoing`='{$outgoing}',`ipaddr`='{$ip}' WHERE `md5`='{$token}'");
    }
    $ligne = mysql_fetch_array($q->QUERY_SQL("SELECT * FROM hotspot_sessions WHERE `md5`='{$token}'"));
    if (wifidog_auth_auto_created($token)) {
        return;
    }
    if ($ligne["logintime"] == 0) {
        if ($GLOBALS["HOTSPOT_DEBUG"]) {
            ToSyslog("wifidog_auth:: * * * logintime = 0  No session saved * * *");
        }
        echo "Auth: -1\n";
        echo "Messages: No session saved\n";
        return;
    }
    /*	0 - AUTH_DENIED - User firewall users are deleted and the user removed.
    	6 - AUTH_VALIDATION_FAILED - User email validation timeout has occured and user/firewall is deleted
    	1 - AUTH_ALLOWED - User was valid, add firewall rules if not present
    	5 - AUTH_VALIDATION - Permit user access to email to get validation email under default rules
    	-1 - AUTH_ERROR - An error occurred during the validation process
    */
    events(2, "LOGON MAC: {$mac}, Token {$token}", null);
    echo "Auth: 1\n";
    echo "Messages: OK\n";
}
Ejemplo n.º 2
0
function wifidog_auth()
{
    $token = $_GET["token"];
    $ARP = $_GET["mac"];
    $mac = $_GET["mac"];
    $ip = $_GET["ip"];
    $GLOBALS["CONNECTED_IP"] = $ip;
    $GLOBALS["CONNECTED_MAC"] = $mac;
    $stage = $_GET["stage"];
    $token = $_GET["token"];
    $incoming = $_GET["incoming"];
    $outgoing = $_GET["outgoing"];
    $q = new mysql_hotspot();
    ///hotspot.php?wifidog-auth=yes&stage=counters&ip=192.168.1.19&mac=00:15:5d:01:09:06&token=token&incoming=7161&outgoing=10255&gw_id=000C29D5571C
    if ($GLOBALS["HOTSPOT_DEBUG"]) {
        wifidog_logs("wifidog_auth:: Receiving stage \"{$stage}\"", __FUNCTION__, __LINE__);
    }
    if ($stage == "logout") {
        $q = new mysql_hotspot();
        $ligne = mysql_fetch_array($q->QUERY_SQL("SELECT * FROM hotspot_sessions WHERE `md5`='{$token}'"));
        $username = $ligne["username"];
        events(1, "{$username} [LOGOFF] for {$mac}", null);
        $q->QUERY_SQL("DELETE FROM hotspot_sessions WHERE `md5`='{$token}'");
        $q->QUERY_SQL("DELETE FROM hotspot_sessions WHERE `MAC`='{$mac}'");
    }
    if ($stage == "counters") {
        $incoming = $incoming / 1024;
        //KB
        $outgoing = $outgoing / 1024;
        // KB
        $incomingMB = round($incoming / 1024);
        //MB
        //mac=00:0c:29:9b:e0:bf
        if (wifidog_auth_auto_created($token)) {
            wifidog_logs("[TRUE] {$token}/{$ip} -> Session is Failed");
            return;
        }
        if (wifidog_is_end_of_session($token)) {
            wifidog_logs("[FALSE] {$token}/{$ip} END OF SESSION  Send [0] ERROR CODE");
            events(1, "COUNTER: MAC: {$mac}, Token {$token} Session: [End-Of-Life] (L:" . __LINE__ . ")", null);
            echo "Auth: 0\n";
            echo "Messages: No session saved\n";
            return;
        }
        if (wifidog_is_end_of_life($token, $mac)) {
            wifidog_logs("[FALSE] {$token}/{$ip} END OF LIFE  Send [0] ERROR CODE");
            events(1, "COUNTER: MAC: {$mac}, Token {$token} Account: [End-Of-Life] (L:" . __LINE__ . ")", null);
            echo "Auth: 0\n";
            echo "Messages: No session saved\n";
            return;
        }
        if ($incomingMB > 0) {
            if (wifidog_is_session_exceed_size($token, $incoming)) {
                events(1, "Session exceed size:{$incoming} [End-Of-Life] (L:" . __LINE__ . ")", null);
                wifidog_logs("[FALSE] {$token}/{$ip} exceed session size");
                echo "Auth: 0\n";
                echo "Messages: No session saved\n";
                return;
            }
        }
        wifidog_logs("[TRUE] {$token}/{$ip} Update session values");
        $q->QUERY_SQL("UPDATE hotspot_sessions SET `incoming`='{$incoming}',`outgoing`='{$outgoing}',`ipaddr`='{$ip}' WHERE `md5`='{$token}'");
    }
    $ligne = mysql_fetch_array($q->QUERY_SQL("SELECT * FROM hotspot_sessions WHERE `md5`='{$token}'"));
    if ($ligne["logintime"] == 0) {
        events(1, "An error occurred during the validation process logintime = 0  No session saved [AUTH_ERROR] (L:" . __LINE__ . ")", null);
        if ($GLOBALS["HOTSPOT_DEBUG"]) {
            wifidog_logs("wifidog_auth:: * * * logintime = 0  No session saved * * *");
        }
        echo "Auth: -1\n";
        echo "Messages: No session saved\n";
        return;
    }
    /*	0 - AUTH_DENIED - User firewall users are deleted and the user removed.
    	6 - AUTH_VALIDATION_FAILED - User email validation timeout has occured and user/firewall is deleted
    	1 - AUTH_ALLOWED - User was valid, add firewall rules if not present
    	5 - AUTH_VALIDATION - Permit user access to email to get validation email under default rules
    	-1 - AUTH_ERROR - An error occurred during the validation process
    */
    echo "Auth: 1\n";
    echo "Messages: OK\n";
}