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

Legend:

Unmodified
Added
Removed
  • 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