Changeset 1352

Show
Ignore:
Timestamp:
06/12/08 09:56:08 (2 months ago)
Author:
benoitg
Message:
  • Use bigint for dynamic abuse control byte values
  • UIAllowedBandwidth: Format values in a human-readable way
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/wifidog-auth/CHANGELOG

    r1351 r1352  
    11# $Id$ 
     22008-06-12 Benoit GrĂ©goire  <bock@step.polymtl.ca> 
     3        * Use bigint for dynamic abuse control byte values 
     4        * UIAllowedBandwidth:  Format values in a human-readable way 
     5 
    262008-06-10 Benoit GrĂ©goire  <bock@step.polymtl.ca> 
    37        * Authenticator.php:  Fix SQL error closing connections. 
  • trunk/wifidog-auth/wifidog/classes/AbstractDb.php

    r1287 r1352  
    545545     * @return a string suitable for storage in the database's interval datatype 
    546546     */ 
    547     function GetIntervalStrFromDuration($duration) 
     547    function GetIntervalStrFromDurationArray($duration) 
    548548    { 
    549549        $str = ''; 
    550         if ($duration->GetYears() != 0) 
    551         $str .= $duration->GetYears().' years '; 
    552         if ($duration->GetMonths() != 0) 
    553         $str .= $duration->GetMonths().' months '; 
    554         if ($duration->GetDays() != 0) 
    555         $str .= $duration->GetDays().' days '; 
    556  
    557         if ($duration->GetHours() != 0 || $duration->GetMinutes() != 0 || $duration->GetSeconds() != 0) 
    558         { 
    559             $str .= $duration->GetHours().':'.$duration->GetMinutes().':'.$duration->GetSeconds()
     550        if ($duration['years'] != 0) 
     551        $str .= $duration['years'].' years '; 
     552        if ($duration['months'] != 0) 
     553        $str .= $duration['months'].' months '; 
     554        if ($duration['days'] != 0) 
     555        $str .= $duration['days'].' days '; 
     556 
     557        if ($duration['hours'] != 0 || $duration['minutes'] != 0 || $duration['seconds'] != 0) 
     558        { 
     559            $str .= $duration['hours'].':'.$duration['minutes'].':'.$duration['seconds']
    560560        } 
    561561        return $str; 
  • trunk/wifidog-auth/wifidog/classes/Content/UIAllowedBandwidth/UIAllowedBandwidth.php

    r1351 r1352  
    5757class UIAllowedBandwidth extends Content 
    5858{ 
     59 
    5960    /** 
    6061     * Constructor 
     
    8889        return Content :: getAdminUI($html, $title); 
    8990    } 
    90  
     91    /* Format human readable filesize */ 
     92    static function formatSize($size, $round = 0) { 
     93        //Size must be bytes! 
     94        $sizes = array(_('B'), _('kB'), _('MB'), _('GB'), _('TB'), _('PB'), _('EB'), _('ZB'), _('YB')); 
     95        for ($i=0; $size > 1024 && $i < count($sizes) - 1; $i++) $size /= 1024; 
     96        return round($size,$round).$sizes[$i]; 
     97    } 
    9198    /** 
    9299     * Retreives the user interface of this object. 
     
    103110 
    104111        $user = User::getCurrentUser(); 
    105           
    106         if($current_node){ 
    107             $abuseControlReport = User::getAbuseControlConnectionHistory($user, null, $current_node); 
    108             if($abuseControlReport) { 
    109                 //pretty_print_r($abuseControlReport); 
     112        if ($user) { 
     113            if($current_node){ 
     114                $abuseControlReport = User::getAbuseControlConnectionHistory($user, null, $current_node); 
     115                if($abuseControlReport) { 
     116                    //pretty_print_r($abuseControlReport); 
     117                    $db = AbstractDb::getObject(); 
     118                    $html .= sprintf(_("During the last %s period, you transfered %s / %s and were connected %s / %s at this node.  Throughout the network, you transfered %s / %s and were connected %s / %s"), 
     119                    $abuseControlReport['connection_limit_window']?$db->GetIntervalStrFromDurationArray($db->GetDurationArrayFromIntervalStr($abuseControlReport['connection_limit_window'])):_("Unknown"), 
     120                    self::formatSize($abuseControlReport['node_total_bytes']), 
     121                    $abuseControlReport['connection_limit_node_max_total_bytes']?self::formatSize($abuseControlReport['connection_limit_node_max_total_bytes']):_("Unlimited"), 
     122                    $abuseControlReport['node_duration']?$abuseControlReport['node_duration']:_("None"), 
     123                    $abuseControlReport['connection_limit_node_max_usage_duration']?$abuseControlReport['connection_limit_node_max_usage_duration']:_("Unlimited"), 
     124                    self::formatSize($abuseControlReport['network_total_bytes']), 
     125                    $abuseControlReport['connection_limit_network_max_total_bytes']?self::formatSize($abuseControlReport['connection_limit_network_max_total_bytes']):_("Unlimited"), 
     126                    $abuseControlReport['network_duration']?$abuseControlReport['network_duration']:_("None"), 
     127                    $abuseControlReport['connection_limit_network_max_usage_duration']?$abuseControlReport['connection_limit_network_max_usage_duration']:_("Unlimited") 
     128                    ); 
    110129 
    111                 $html .= sprintf(_("During the last %s period, you transfered %s / %s bytes and were connected %s / %s at this node.  Throughout the network, you transfered %s / %s bytes and were connected %s / %s"), 
    112                 $abuseControlReport['connection_limit_window']?$abuseControlReport['connection_limit_window']:_("Unknown"), 
    113                 $abuseControlReport['node_total_bytes']?$abuseControlReport['node_total_bytes']:_("Unknown"), 
    114                 $abuseControlReport['connection_limit_node_max_total_bytes']?$abuseControlReport['connection_limit_node_max_total_bytes']:_("Unlimited"), 
    115                 $abuseControlReport['node_duration']?$abuseControlReport['node_duration']:_("Unknown"), 
    116                 $abuseControlReport['connection_limit_node_max_usage_duration']?$abuseControlReport['connection_limit_node_max_usage_duration']:_("Unlimited"), 
    117                 $abuseControlReport['network_total_bytes']?$abuseControlReport['network_total_bytes']:_("Unknown"), 
    118                 $abuseControlReport['connection_limit_network_max_total_bytes']?$abuseControlReport['connection_limit_network_max_total_bytes']:_("Unlimited"), 
    119                 $abuseControlReport['network_duration']?$abuseControlReport['network_duration']:_("Unknown"), 
    120                 $abuseControlReport['connection_limit_network_max_usage_duration']?$abuseControlReport['connection_limit_network_max_usage_duration']:_("Unlimited") 
    121                 ); 
    122  
     130                } 
     131                else { 
     132                    $html .= _("Abuse control is currently disabled"); 
     133                } 
    123134            } 
    124135            else { 
    125                 $html .= _("Abuse control is currently disabled"); 
     136                $html .= _("Unable to retrieve node specific restrictions (you are not at a node)"); 
    126137            } 
     138            $this->setUserUIMainDisplayContent($html); 
     139 
     140            return Content :: getUserUI(); 
    127141        } 
    128         else { 
    129             $html .= _("Unable to retrieve node specific restrictions (you are not at a node)"); 
    130         } 
    131         $this->setUserUIMainDisplayContent($html); 
    132         return Content :: getUserUI(); 
    133142    } 
    134143 
  • trunk/wifidog-auth/wifidog/include/schema_validate.php

    r1351 r1352  
    4848 * Define current database schema version 
    4949 */ 
    50 define('REQUIRED_SCHEMA_VERSION', 61); 
     50define('REQUIRED_SCHEMA_VERSION', 62); 
    5151/** Used to test a new shecma version before modyfying the database */ 
    5252define('SCHEMA_UPDATE_TEST_MODE', false); 
     
    14051405         
    14061406    } 
    1407      
     1407    $new_schema_version = 62; 
     1408    if ($schema_version < $new_schema_version && $new_schema_version <= $targetSchema) { 
     1409        printUpdateVersion($new_schema_version); 
     1410        $sql .= "\n\nUPDATE schema_info SET value='$new_schema_version' WHERE tag='schema_version';\n"; 
     1411 
     1412        $sql .= "ALTER TABLE networks ALTER COLUMN connection_limit_network_max_total_bytes TYPE bigint;\n"; 
     1413        $sql .= "ALTER TABLE networks ALTER COLUMN connection_limit_node_max_total_bytes TYPE bigint;\n"; 
     1414 
     1415        $sql .= "ALTER TABLE nodes ALTER COLUMN connection_limit_node_max_total_bytes_override TYPE bigint;\n"; 
     1416         
     1417    } 
    14081418    /* 
    14091419     $new_schema_version = ;