Changeset 1413

Show
Ignore:
Timestamp:
08/06/09 09:55:30 (4 years ago)
Author:
benoitg
Message:
  • Experimental fix for #596
Location:
trunk/wifidog-auth/wifidog
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • trunk/wifidog-auth/wifidog/auth/index.php

    r1412 r1413  
    159159                    else 
    160160                    { 
    161                         /* TODO:  This is a bit hackish, is't a shortcut untill the Token architecture uniform connection limit calculations are in place. */ 
     161                        /* TODO:  This is a bit hackish, it's a shortcut untill the Token architecture uniform connection limit calculations are in place. */ 
    162162                        $abuseControlFault = User::isAbuseControlViolated(User::getObject($info['user_id']), $info['user_mac'], Node::getObject($info['node_id'])); 
    163163                        if($abuseControlFault) { 
  • trunk/wifidog-auth/wifidog/classes/User.php

    r1409 r1413  
    564564            $sql .= " SUM (CASE WHEN node_id = '".$node->getId()."' THEN (incoming+outgoing) END) AS node_total_bytes, \n"; 
    565565            $sql .= " SUM (timestamp_out - timestamp_in) AS network_duration, \n"; 
    566             $sql .= " SUM (CASE WHEN node_id = '".$node->getId()."' THEN (timestamp_out - timestamp_in) END) AS node_duration \n";//For real 
     566            $sql .= " SUM (CASE WHEN node_id = '".$node->getId()."' THEN (COALESCE(timestamp_out,last_updated) - timestamp_in) END) AS node_duration \n";//For real //The coalesce is to make sure the substraction returns a value for active conections, since active connections do not yet have a timestamp_out.  Do NOT coalesce with CURRENT_TIMESTAMP, it could cause real problems for users in case of gateway crash. 
    567567            $sql .= " FROM connections \n";//For real 
    568568            $sql .= " JOIN nodes USING (node_id) \n"; 
  • trunk/wifidog-auth/wifidog/include/common.php

    r1350 r1413  
    150150define('ONLINE_STATUS_ONLINE', 1); 
    151151define('ONLINE_STATUS_OFFLINE', 2); 
     152 
    152153/* End Constant shared with the gateway*/ 
     154 
     155/* Other constants */ 
     156define('LOGOUT_REASON_GARBAGE_COLLECTED', 3); 
     157define('LOGOUT_REASON_UNKNOWN', 0); 
     158/* End of Other constants */ 
    153159 
    154160/** Convert a password hash form a NoCat passwd file into the same format as get_password_hash(). 
     
    172178    // 10 minutes 
    173179    $expiration = '10 minutes'; 
    174     $db->execSqlUpdate("UPDATE tokens SET token_status='" . TOKEN_USED . "' FROM connections WHERE connections.token_id=tokens.token_id AND last_updated < (CURRENT_TIMESTAMP - interval '$expiration') AND token_status = '" . TOKEN_INUSE . "';", false); 
     180    $sql = null; 
     181    $sql .= "BEGIN;\n";  
     182    $sql .= "UPDATE connections SET logout_reason=" . LOGOUT_REASON_GARBAGE_COLLECTED . ", timestamp_out=(CURRENT_TIMESTAMP - interval '$expiration') FROM tokens WHERE connections.token_id=tokens.token_id AND last_updated < (CURRENT_TIMESTAMP - interval '$expiration') AND token_status = '" . TOKEN_INUSE . "';"; 
     183    $sql .= "UPDATE tokens SET token_status='" . TOKEN_USED . "' FROM connections WHERE connections.token_id=tokens.token_id AND last_updated < (CURRENT_TIMESTAMP - interval '$expiration') AND token_status = '" . TOKEN_INUSE . "';"; 
     184    $sql .= "COMMIT;\n"; 
     185    $db->execSqlUpdate($sql, false); 
    175186} 
    176187 
  • trunk/wifidog-auth/wifidog/include/schema_validate.php

    r1395 r1413  
    4848 * Define current database schema version 
    4949 */ 
    50 define('REQUIRED_SCHEMA_VERSION', 65); 
     50define('REQUIRED_SCHEMA_VERSION', 66); 
    5151/** Used to test a new shecma version before modyfying the database */ 
    5252define('SCHEMA_UPDATE_TEST_MODE', false); 
     
    14421442    } 
    14431443     
     1444    $new_schema_version = 66; 
     1445    if ($schema_version < $new_schema_version && $new_schema_version <= $targetSchema) { 
     1446        printUpdateVersion($new_schema_version); 
     1447        $sql .= "\n\nUPDATE schema_info SET value='$new_schema_version' WHERE tag='schema_version';\n"; 
     1448        $sql .= "UPDATE connections SET logout_reason=0, timestamp_out=timestamp_in FROM tokens WHERE connections.token_id=tokens.token_id AND timestamp_out IS NULL AND (token_status = 'USED' OR token_status = 'UNUSED');\n"; 
     1449    } 
     1450     
    14441451    /* 
    14451452     $new_schema_version = ;