Ignore:
Timestamp:
Apr 5, 2009, 3:54:46 PM (16 years ago)
Author:
george
Message:
  • Přidáno: Možnost registrace podsítí pro klienty.
  • Upraveno: Skripty pro generování nastavení routerů byly upraveny pro podporu tabulky NetworkSubnet.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/system/generators/traffic_shaping_routerboard.php

    r171 r187  
    2626$OutInterface = 'eth1';
    2727$InInterface = 'ifb0';
     28$InetInterface = $Config['MainRouter']['InetInterface'];
    2829$FreeInetSpeed = 64 * 1024;
    29 
    30 $InetInterface = 'ether3';
    31 $Router = '192.168.0.11';
    3230
    3331$Commands = array();
     
    4341
    4442// Divide rules by subnet number
    45 foreach(array(0, 1, 2, 3, 4, 5, 7) as $Subnet)
     43$DbResult = $Database->query('SELECT Id, AddressRange, Mask FROM NetworkSubnet WHERE Member = 0');
     44while($Subnet = $DbResult->fetch_assoc())
    4645{
    47   $Commands[] = ' /ip firewall mangle add chain=inet-out src-address=192.168.'.$Subnet.'.0/24 out-interface='.$InetInterface.' action=jump jump-target=inet-out-'.$Subnet;
    48   $Commands[] = ' /ip firewall mangle add chain=inet-in dst-address=192.168.'.$Subnet.'.0/24 in-interface='.$InetInterface.' action=jump jump-target=inet-in-'.$Subnet;
     46  $Commands[] = ' /ip firewall mangle add chain=inet-out src-address='.$Subnet['AddressRange'].'/'.$Subnet['Mask'].' out-interface='.$InetInterface.' action=jump jump-target=inet-out-'.$Subnet['Id'];
     47  $Commands[] = ' /ip firewall mangle add chain=inet-in dst-address='.$Subnet['AddressRange'].'/'.$Subnet['Mask'].' in-interface='.$InetInterface.' action=jump jump-target=inet-in-'.$Subnet['Id'];
    4948}
    5049
     
    6261while($Member = $DbResult->fetch_array())
    6362{
    64   $Member['Name'] = strtr(strtolower(trim($Member['Name'])), array(' ' => '-', '(' => '-', ')' => '-',
    65   'č' => 'c', 'š' => 's', 'ě' => 'e', 'ř' => 'r', 'ž' => 'z', 'ý' => 'y', 'á' => 'a', 'í' => 'i', 'é' => 'e', 'ů' => 'u', 'ú' => 'u', 'ď' => 'd', 'ť' => 't', 'ň' => 'n', 'ó' => 'o',
    66   'Č' => 'c', 'Š' => 's', 'Ě' => 'e', 'Ř' => 'r', 'Ž' => 'z', 'Ý' => 'y', 'Á' => 'a', 'Í' => 'i', 'É' => 'e', 'Ů' => 'u', 'Ú' => 'u', 'Ď' => 'd', 'Ť' => 't', 'Ň' => 'n', 'Ó' => 'o',
    67 ));
     63  $Member['Name'] = RouterOSIdent($Member['Name']);
    6864
    6965  echo('Uživatel '.$Member['Name'].": ");
     
    7773  $Commands[] = ' /queue tree add name='.$Member['Name'].'-in limit-at='.$SpeedOut.' max-limit='.$UserMaxSpeedOut.' parent=main-in queue=wireless-default';
    7874
    79   $DbResult2 = $Database->select('hosts', 'COUNT(*)', "block=0 AND MAC!='' AND user=".$Member['Id']);
     75  $DbResult2 = $Database->select('hosts', 'COUNT(*)', '(block = 0) AND (MAC != "") AND (user = '.$Member['Id'].')');
    8076  $Row = $DbResult2->fetch_array();
    8177  $HostCount = $Row[0];
    82   $HostSpeedIn = round($SpeedIn / $HostCount);
    83   $HostSpeedOut = round($SpeedOut / $HostCount);
     78  if($HostCount > 0)
     79  {
     80    $HostSpeedIn = round($SpeedIn / $HostCount);
     81    $HostSpeedOut = round($SpeedOut / $HostCount);
     82  } else
     83  {
     84    $HostSpeedIn = $SpeedIn;
     85    $HostSpeedOut = $SpeedOut;
     86  }
    8487
    85   $DbResult2 = $Database->select('hosts', '*', "block=0 AND MAC!='' AND user=".$Member['Id']);
     88  $DbResult2 = $Database->select('hosts', '*', 'block=0 AND MAC!="" AND user='.$Member['Id']);
    8689  while($Host = $DbResult2->fetch_array())
    8790  {
    88     $Host['name'] = strtolower($Host['name']);
     91    $Host['name'] = RouterOSIdent($Host['name']);
    8992    echo($Host['name'].', ');
    9093    $IPParts = explode('.', $Host['IP']);
     
    100103    if($Index > 50)
    101104          {
     105      //print_r($Commands);
    102106      $Commands = addslashes(implode(';', $Commands));
    103       $Command = '/usr/bin/ssh -l admin-ssh -i id_dsa '.$Router.' "'.$Commands.'"';
    104       //echo($Command."\n");
     107      $Command = '/usr/bin/ssh -l '.$Config['MainRouter']['UserName'].' -i id_dsa '.$Config['MainRouter']['HostName'].' "'.$Commands.'"';
     108      $Output = array();
    105109      exec($Command, $Output);
    106110      print_r($Output);
     
    110114    $Index++;
    111115  }
     116 
     117  $DbResult2 = $Database->select('NetworkSubnet', '*', 'Member='.$Member['Id']);
     118  while($Subnet = $DbResult2->fetch_array())
     119  {
     120    $Subnet['Name'] = RouterOSIdent('subnet-'.$Subnet['Name']);
     121    echo($Subnet['Name'].', ');
     122    $IPParts = explode('.', $Subnet['AddressRange']);
     123    $SubnetNumber = $IPParts[2];
     124    $Commands[] = ' /ip firewall mangle add chain=inet-out-'.$SubnetNumber.' src-address='.$Subnet['AddressRange'].'/'.$Subnet['Mask'].' out-interface='.$InetInterface.' action=mark-packet new-packet-mark='.$PacketMark.' passthrough=no comment="'.$Subnet['Name'].'"';
     125    $Commands[] = ' /queue tree add name='.$Subnet['Name'].'-out limit-at='.$HostSpeedIn.' max-limit='.$UserMaxSpeedIn.' parent='.$Member['Name'].'-out packet-mark='.$PacketMark.' queue=wireless-default';
     126    $PacketMark++;
     127    $Commands[] = ' /ip firewall mangle add chain=inet-in-'.$SubnetNumber.' dst-address='.$Subnet['AddressRange'].'/'.$Subnet['Mask'].' in-interface='.$InetInterface.' action=mark-packet new-packet-mark='.$PacketMark.' passthrough=no comment="'.$Subnet['Name'].'"';
     128    $Commands[] = ' /queue tree add name='.$Subnet['Name'].'-in limit-at='.$HostSpeedOut.' max-limit='.$UserMaxSpeedOut.' parent='.$Member['Name'].'-in packet-mark='.$PacketMark.' queue=wireless-default';
     129    $PacketMark++;
     130
     131    // Posílej po menších částech
     132    if($Index > 50)
     133          {
     134      $Commands = addslashes(implode(';', $Commands));
     135      $Command = '/usr/bin/ssh -l '.$Config['MainRouter']['UserName'].' -i id_dsa '.$Config['MainRouter']['HostName'].' "'.$Commands.'"';
     136      //echo($Command."\n");
     137      $Output = array();
     138      exec($Command, $Output);
     139      print_r($Output);
     140          $Commands = array();
     141            $Index = 0;
     142          }
     143    $Index++;
     144  }
     145 
    112146  echo("\n");
    113147}
    114148//print_r($Commands);
    115149$Commands = addslashes(implode(';', $Commands));
    116 $Command = '/usr/bin/ssh -l admin-ssh -i id_dsa '.$Router.' "'.$Commands.'"';
     150$Command = '/usr/bin/ssh -l '.$Config['MainRouter']['UserName'].' -i id_dsa '.$Config['MainRouter']['HostName'].' "'.$Commands.'"';
    117151//echo($Command."\n");
     152$Output = array();
    118153exec($Command, $Output);
    119154//array_pop($Output);
Note: See TracChangeset for help on using the changeset viewer.