Ignore:
Timestamp:
Apr 14, 2015, 10:20:16 PM (10 years ago)
Author:
chronos
Message:
  • Removed: Spaces on end of line.
  • Modified: Tabs converted to spaces.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Modules/NetworkConfigLinux/Generators/TrafficShaping.php

    r548 r738  
    1010// Generate traffic shaping rules
    1111//$TotalMaxSpeedIn = 4048; //$RealMaxSpeed; //1536;
    12 //TotalMaxSpeedOut = 3048; //$RealMaxSpeed; //1536; 
     12//TotalMaxSpeedOut = 3048; //$RealMaxSpeed; //1536;
    1313//$UsersMaxSpeedIn = 1900; //$MaxSpeed;
    1414//$UsersMaxSpeedOut = 1900; //$MaxSpeed;
     
    4545
    4646  $FreeInetClass = 2;
    47  
     47
    4848  // In going traffic
    4949  fputs($File, "/sbin/tc qdisc del dev ".$InInterface." root\n");
    5050  if($Enabled)
    51   { 
     51  {
    5252    fputs($File, "/sbin/tc qdisc add dev ".$InInterface." root handle 1:0 htb default 2\n");
    5353    fputs($FileClassInfo, "1:1 Základní\n");
     
    6868    fputs($File, "/sbin/tc qdisc add dev ".$OutInterface." parent 1:".$FreeInetClass." handle ".$FreeInetClass.": sfq perturb 10\n");
    6969  }
    70  
     70
    7171  if(!$Enabled) die("Traffic shaping disabled\n");
    7272
    73   if($ClassesEnabled) 
     73  if($ClassesEnabled)
    7474  {
    7575  $ClassId = 3;
     
    9898  //$SpeedOut = round($UsersMaxSpeedOut / $InetUserCount);
    9999  $Prio = 1;
    100  
    101  
     100
     101
    102102  $AllUsersClassId = $ClassId;
    103103  $ClassId = $ClassId + 1;
     
    123123  fputs($FileClassInfo, '1:'.$TorrentClassId." Torrent\n");
    124124
    125   $DbResult = $Database->select('users', '*, CONCAT(second_name, " ", first_name) as fullname', '(inet=1)'); 
     125  $DbResult = $Database->select('users', '*, CONCAT(second_name, " ", first_name) as fullname', '(inet=1)');
    126126  while($User = $DbResult->fetch_array())
    127127  {
     
    144144
    145145    //echo('User class id: '.$UserClassId."\n");
    146  
     146
    147147    $DbResult2 = $Database->select('hosts', 'COUNT(*)', "block=0 AND MAC!='' AND user=".$User['id']);
    148148    $Row = $DbResult2->fetch_array();
     
    150150    $HostSpeedIn = round($SpeedIn / $HostCount);
    151151    $HostSpeedOut = round($SpeedOut / $HostCount);
    152  
     152
    153153    $DbResult2 = $Database->select('hosts','*',"block=0 AND MAC!='' AND user=".$User['id']);
    154154    while($Host = $DbResult2->fetch_array())
     
    164164        $Prio = 1;
    165165        if($Host['vpn'] == 1)
    166               {
    167                 if($Host['external_ip'] != '') $Host['IP'] = $Host['external_ip'];
    168                 else $Host['IP'] = ToVpnIp($Host);
    169               }
    170        
    171               //if($Host['name'] == 'TERMINAL') $SpeedDivider = 0.5;
    172                 //else
     166        {
     167          if($Host['external_ip'] != '') $Host['IP'] = $Host['external_ip'];
     168          else $Host['IP'] = ToVpnIp($Host);
     169        }
     170
     171        //if($Host['name'] == 'TERMINAL') $SpeedDivider = 0.5;
     172          //else
    173173        $SpeedDivider = 1;
    174174
    175               if($Host['name'] == 'centrala')
    176               {
    177                 $Host['IP'] = $Host['external_ip'];
    178                 $TableOut = 'OUTPUT';
    179                 $TableIn = 'INPUT';
    180                } else
     175        if($Host['name'] == 'centrala')
     176        {
     177          $Host['IP'] = $Host['external_ip'];
     178          $TableOut = 'OUTPUT';
     179          $TableIn = 'INPUT';
     180         } else
    181181         {
    182                  $TableOut = 'FORWARD';
    183                  $TableIn = 'FORWARD';
    184                }
    185               //if($Row['name'] == 'TERMINAL2') $Prio = 0;
    186         //      if($Row['name'] = 'TERMINAL2') $Prio = 0;
    187         if($Host['name'] == 'voip-hajda') $Protocol = ' -p tcp'; 
    188           else $Protocol = '';
    189         //      if($Host['name'] == 'KARLOS') $UserMaxSpeedIn = 128000;
     182           $TableOut = 'FORWARD';
     183           $TableIn = 'FORWARD';
     184         }
     185        //if($Row['name'] == 'TERMINAL2') $Prio = 0;
     186        //  if($Row['name'] = 'TERMINAL2') $Prio = 0;
     187        if($Host['name'] == 'voip-hajda') $Protocol = ' -p tcp';
     188        else $Protocol = '';
     189        //  if($Host['name'] == 'KARLOS') $UserMaxSpeedIn = 128000;
    190190        /*
    191 if($Host['name'] == 'GAME') 
    192         {
    193           exec('/sbin/iptables -t mangle -F game-server');       
    194                 $TableOut = 'game-server';
    195                 $TableIn = 'game-server';
    196         }*/
     191if($Host['name'] == 'GAME')
     192        {
     193          exec('/sbin/iptables -t mangle -F game-server');
     194          $TableOut = 'game-server';
     195          $TableIn = 'game-server';
     196        }*/
    197197        //if($Host['name'] == 'TBC') continue;
    198198
    199199        // In going traffic
    200         //exec('/sbin/iptables -t mangle -A '.$TableIn.' -i eth1 -d '.$Host['IP'].$Protocol." -j MARK --set-mark ".$HostClassId); 
    201               fputs($File, "/sbin/tc class add dev ".$InInterface." parent 1:".$UserClassId." classid 1:".$HostClassId." htb rate ".$HostSpeedIn."bit ceil ".$UserMaxSpeedIn."bit prio ".$Prio." quantum ".$Quantum."\n");
    202               fputs($File, "/sbin/tc qdisc add dev ".$InInterface." parent 1:".$HostClassId." handle ".$HostClassId.":0 sfq perturb 10\n");
    203             //fputs($File, "/sbin/tc filter add dev ".$InInterface." parent 1:0 protocol ip handle ".$HostClassId." fw flowid 1:".$UserClassId."\n");
    204             fputs($File, "/sbin/tc filter add dev ".$InInterface." parent 1:0 protocol ip prio 1 u32 match ip dst ".$Host['external_ip']."/32 flowid 1:".$HostClassId."\n");
    205        
     200        //exec('/sbin/iptables -t mangle -A '.$TableIn.' -i eth1 -d '.$Host['IP'].$Protocol." -j MARK --set-mark ".$HostClassId);
     201        fputs($File, "/sbin/tc class add dev ".$InInterface." parent 1:".$UserClassId." classid 1:".$HostClassId." htb rate ".$HostSpeedIn."bit ceil ".$UserMaxSpeedIn."bit prio ".$Prio." quantum ".$Quantum."\n");
     202        fputs($File, "/sbin/tc qdisc add dev ".$InInterface." parent 1:".$HostClassId." handle ".$HostClassId.":0 sfq perturb 10\n");
     203        //fputs($File, "/sbin/tc filter add dev ".$InInterface." parent 1:0 protocol ip handle ".$HostClassId." fw flowid 1:".$UserClassId."\n");
     204        fputs($File, "/sbin/tc filter add dev ".$InInterface." parent 1:0 protocol ip prio 1 u32 match ip dst ".$Host['external_ip']."/32 flowid 1:".$HostClassId."\n");
     205
    206206        // Out going traffic
    207207        //exec('/sbin/iptables -t mangle -A '.$TableOut.' -o eth1 -s '.$Host['IP'].$Protocol." -j MARK --set-mark ".$HostClassId);
    208         fputs($File, "/sbin/tc class add dev ".$OutInterface." parent 1:".$UserClassId." classid 1:".$HostClassId." htb rate ".$HostSpeedOut."bit ceil ".$UserMaxSpeedOut."bit prio ".$Prio." quantum ".$Quantum."\n");
    209               fputs($File, "/sbin/tc qdisc add dev ".$OutInterface." parent 1:".$HostClassId." handle ".$HostClassId.":0 sfq perturb 10\n");
    210               //fputs($File, "/sbin/tc filter add dev ".$OutInterface." parent 1:0 protocol ip handle ".$HostClassId." fw flowid 1:".$UserClassId."\n");
    211               fputs($File, "/sbin/tc filter add dev ".$OutInterface." parent 1:0 protocol ip prio 1 u32 match ip src ".$Host['external_ip']."/32 flowid 1:".$HostClassId."\n");
    212                //echo($Row['id'].',');
     208        fputs($File, "/sbin/tc class add dev ".$OutInterface." parent 1:".$UserClassId." classid 1:".$HostClassId." htb rate ".$HostSpeedOut."bit ceil ".$UserMaxSpeedOut."bit prio ".$Prio." quantum ".$Quantum."\n");
     209        fputs($File, "/sbin/tc qdisc add dev ".$OutInterface." parent 1:".$HostClassId." handle ".$HostClassId.":0 sfq perturb 10\n");
     210        //fputs($File, "/sbin/tc filter add dev ".$OutInterface." parent 1:0 protocol ip handle ".$HostClassId." fw flowid 1:".$UserClassId."\n");
     211        fputs($File, "/sbin/tc filter add dev ".$OutInterface." parent 1:0 protocol ip prio 1 u32 match ip src ".$Host['external_ip']."/32 flowid 1:".$HostClassId."\n");
     212         //echo($Row['id'].',');
    213213      }
    214214      // Free inet
    215215      if($Tarify[$User['inet_tarif_now']]['group_id'] == 3)
    216216      {
    217         //exec('/sbin/iptables -t mangle -A '.$TableIn.' -i eth1 -d '.$Host['IP'].$Protocol." -j MARK --set-mark ".$FreeInetClass); 
     217        //exec('/sbin/iptables -t mangle -A '.$TableIn.' -i eth1 -d '.$Host['IP'].$Protocol." -j MARK --set-mark ".$FreeInetClass);
    218218        //exec('/sbin/iptables -t mangle -A '.$TableOut.' -o eth1 -s '.$Host['IP'].$Protocol." -j MARK --set-mark ".$FreeInetClass);
    219219      }
    220220      // VoIP devices
    221221/*
    222       if(($Host['name'] == 'HAJDA-VOIP') || ($Host['name'] == 'NAVRATIL-VOIP')) 
     222      if(($Host['name'] == 'HAJDA-VOIP') || ($Host['name'] == 'NAVRATIL-VOIP'))
    223223      {
    224224        exec('/sbin/iptables -t mangle -A '.$TableIn." -i eth1 -d ".$Host['IP']." -p udp -j MARK --set-mark ".$VoipClassId);
    225225        exec('/sbin/iptables -t mangle -A '.$TableOut." -o eth1 -s ".$Host['IP']." -p udp -j MARK --set-mark ".$VoipClassId);
    226       } else 
     226      } else
    227227      if($Host['name'] == 'GAME')
    228228      {
    229         exec('/sbin/iptables -t mangle -A FORWARD -o eth1 -s '.$Host['IP']." -j game-server"); 
    230         exec('/sbin/iptables -t mangle -A FORWARD -i eth1 -d '.$Host['IP']." -j game-server"); 
    231    
     229        exec('/sbin/iptables -t mangle -A FORWARD -o eth1 -s '.$Host['IP']." -j game-server");
     230        exec('/sbin/iptables -t mangle -A FORWARD -i eth1 -d '.$Host['IP']." -j game-server");
     231
    232232        exec('/sbin/iptables -t mangle -A game-server -o eth1 -s '.$Host['IP']." -j MARK --set-mark ".$TorrentClassId);
    233233        exec('/sbin/iptables -t mangle -A game-server -i eth1 -d '.$Host['IP']." -j MARK --set-mark ".$TorrentClassId);
     
    237237
    238238        // Local services
    239               exec('/sbin/iptables -t mangle -A game-server -o eth1 -s '.$Host['IP']." -p icmp -j MARK --set-mark ".$HostClassId); // ICMP
     239        exec('/sbin/iptables -t mangle -A game-server -o eth1 -s '.$Host['IP']." -p icmp -j MARK --set-mark ".$HostClassId); // ICMP
    240240        exec('/sbin/iptables -t mangle -A game-server -i eth1 -d '.$Host['IP']." -p icmp -j MARK --set-mark ".$HostClassId);
    241241        exec('/sbin/iptables -t mangle -A game-server -o eth1 -s '.$Host['IP']." -p tcp --sport 6969 -j MARK --set-mark ".$HostClassId); // web torrent
    242242        exec('/sbin/iptables -t mangle -A game-server -i eth1 -d '.$Host['IP']." -p tcp --dport 6969 -j MARK --set-mark ".$HostClassId);
    243243        exec('/sbin/iptables -t mangle -A game-server -o eth1 -s '.$Host['IP']." -p tcp --sport 80 -j MARK --set-mark ".$HostClassId);   // web
    244         exec('/sbin/iptables -t mangle -A game-server -i eth1 -d '.$Host['IP']." -p tcp --dport 80 -j MARK --set-mark ".$HostClassId); 
     244        exec('/sbin/iptables -t mangle -A game-server -i eth1 -d '.$Host['IP']." -p tcp --dport 80 -j MARK --set-mark ".$HostClassId);
    245245        exec('/sbin/iptables -t mangle -A game-server -o eth1 -s '.$Host['IP']." -p tcp --sport 21 -j MARK --set-mark ".$HostClassId);    // FTP
    246246        exec('/sbin/iptables -t mangle -A game-server -i eth1 -d '.$Host['IP']." -p tcp --dport 21 -j MARK --set-mark ".$HostClassId);
     
    252252        exec('/sbin/iptables -t mangle -A game-server -i eth1 -d '.$Host['IP']." -p tcp --dport 22 -j MARK --set-mark ".$HostClassId);
    253253        exec('/sbin/iptables -t mangle -A game-server -o eth1 -s '.$Host['IP']." -p tcp --sport 443 -j MARK --set-mark ".$HostClassId);   // https
    254               exec('/sbin/iptables -t mangle -A game-server -i eth1 -d '.$Host['IP']." -p tcp --dport 443 -j MARK --set-mark ".$HostClassId);
     254        exec('/sbin/iptables -t mangle -A game-server -i eth1 -d '.$Host['IP']." -p tcp --dport 443 -j MARK --set-mark ".$HostClassId);
    255255        exec('/sbin/iptables -t mangle -A game-server -o eth1 -s '.$Host['IP']." -p tcp --sport 27015 -j MARK --set-mark ".$HostClassId); // Counter Strike
    256256        exec('/sbin/iptables -t mangle -A game-server -i eth1 -d '.$Host['IP']." -p tcp --dport 27015 -j MARK --set-mark ".$HostClassId);
     
    259259        exec('/sbin/iptables -t mangle -A game-server -o eth1 -s '.$Host['IP']." -p tcp --sport 5906 -j MARK --set-mark ".$HostClassId);  // VNC
    260260        exec('/sbin/iptables -t mangle -A game-server -i eth1 -d '.$Host['IP']." -p tcp --dport 5906 -j MARK --set-mark ".$HostClassId);
    261        
    262         // Remote services
     261
     262  // Remote services
    263263        exec('/sbin/iptables -t mangle -A game-server -o eth1 -s '.$Host['IP']." -p tcp --dport 443 -j MARK --set-mark ".$HostClassId);   // https
    264         exec('/sbin/iptables -t mangle -A game-server -i eth1 -d '.$Host['IP']." -p tcp --sport 443 -j MARK --set-mark ".$HostClassId);
     264  exec('/sbin/iptables -t mangle -A game-server -i eth1 -d '.$Host['IP']." -p tcp --sport 443 -j MARK --set-mark ".$HostClassId);
    265265        exec('/sbin/iptables -t mangle -A game-server -o eth1 -s '.$Host['IP']." -p tcp --dport 80 -j MARK --set-mark ".$HostClassId);   // http
    266         exec('/sbin/iptables -t mangle -A game-server -i eth1 -d '.$Host['IP']." -p tcp --sport 80 -j MARK --set-mark ".$HostClassId);
    267        
     266  exec('/sbin/iptables -t mangle -A game-server -i eth1 -d '.$Host['IP']." -p tcp --sport 80 -j MARK --set-mark ".$HostClassId);
     267
    268268      }
    269269*/
Note: See TracChangeset for help on using the changeset viewer.