Ignore:
Timestamp:
Mar 24, 2009, 7:28:33 PM (16 years ago)
Author:
george
Message:
  • Opraveno: Konfigurační skripty síťových zařízení opraveny pro nové tabulky Member a Subject.
File:
1 edited

Legend:

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

    r167 r171  
    66include_once('../../global.php');
    77$Finance = &$System->Modules['Finance'];
    8 $Finance->NactiMesicniParametry(0);
     8$Finance->LoadMonthParameters(0);
    99
    1010// Generate traffic shaping rules
     
    2929
    3030$InetInterface = 'ether3';
    31 $Router = '192.168.0.99';
     31$Router = '192.168.0.11';
    3232
    3333$Commands = array();
     
    5959// Process users
    6060$Index = 0;
    61 $DbResult = $Database->select('users', '*, CONCAT(second_name, " ", first_name) as fullname', '(inet=1)');
    62 while($User = $DbResult->fetch_array())
     61$DbResult = $Database->query('SELECT Member.*, Subject.Name FROM Member LEFT JOIN Subject ON Subject.Id = Member.Subject');
     62while($Member = $DbResult->fetch_array())
    6363{
    64   $User['fullname'] = strtr(strtolower(trim($User['fullname'])), array(' ' => '-', '(' => '-', ')' => '-',
     64  $Member['Name'] = strtr(strtolower(trim($Member['Name'])), array(' ' => '-', '(' => '-', ')' => '-',
    6565  'č' => 'c', 'š' => 's', 'ě' => 'e', 'ř' => 'r', 'ž' => 'z', 'ý' => 'y', 'á' => 'a', 'í' => 'i', 'é' => 'e', 'ů' => 'u', 'ú' => 'u', 'ď' => 'd', 'ť' => 't', 'ň' => 'n', 'ó' => 'o',
    6666  'Č' => 'c', 'Š' => 's', 'Ě' => 'e', 'Ř' => 'r', 'Ž' => 'z', 'Ý' => 'y', 'Á' => 'a', 'Í' => 'i', 'É' => 'e', 'Ů' => 'u', 'Ú' => 'u', 'Ď' => 'd', 'Ť' => 't', 'Ň' => 'n', 'Ó' => 'o',
    6767));
    6868
    69   echo('Uživatel '.$User['fullname'].": ");
    70   $SpeedIn = round($Tarify[$User['inet_tarif_now']]['min_speed'] / $InDivider);
    71   $SpeedOut = round($Tarify[$User['inet_tarif_now']]['min_speed'] / $OutDivider);
    72   $UserMaxSpeedIn = round($Tarify[$User['inet_tarif_now']]['max_speed'] / $InDivider);
    73   $UserMaxSpeedOut = round($Tarify[$User['inet_tarif_now']]['max_speed'] / $OutDivider);
    74   $Quantum = $Tarify[$User['inet_tarif_now']]['speed_factor'] * 1500;
    75   $Commands[] = ' /queue tree add name='.$User['fullname'].'-out limit-at='.$SpeedIn.' max-limit='.$UserMaxSpeedIn.' parent=main-out queue=wireless-default';
    76   $Commands[] = ' /queue tree add name='.$User['fullname'].'-in limit-at='.$SpeedOut.' max-limit='.$UserMaxSpeedOut.' parent=main-in queue=wireless-default';
     69  echo('Uživatel '.$Member['Name'].": ");
     70  $Tariff = $Finance->Tarify[$Member['InternetTariffCurrentMonth']];
     71  $SpeedIn = round($Tariff['min_speed'] / $InDivider);
     72  $SpeedOut = round($Tariff['min_speed'] / $OutDivider);
     73  $UserMaxSpeedIn = round($Tariff['max_speed'] / $InDivider);
     74  $UserMaxSpeedOut = round($Tariff['max_speed'] / $OutDivider);
     75  $Quantum = $Tariff['speed_factor'] * 1500;
     76  $Commands[] = ' /queue tree add name='.$Member['Name'].'-out limit-at='.$SpeedIn.' max-limit='.$UserMaxSpeedIn.' parent=main-out queue=wireless-default';
     77  $Commands[] = ' /queue tree add name='.$Member['Name'].'-in limit-at='.$SpeedOut.' max-limit='.$UserMaxSpeedOut.' parent=main-in queue=wireless-default';
    7778
    78   $DbResult2 = $Database->select('hosts', 'COUNT(*)', "block=0 AND MAC!='' AND user=".$User['id']);
     79  $DbResult2 = $Database->select('hosts', 'COUNT(*)', "block=0 AND MAC!='' AND user=".$Member['Id']);
    7980  $Row = $DbResult2->fetch_array();
    8081  $HostCount = $Row[0];
     
    8283  $HostSpeedOut = round($SpeedOut / $HostCount);
    8384
    84   $DbResult2 = $Database->select('hosts', '*', "block=0 AND MAC!='' AND user=".$User['id']);
     85  $DbResult2 = $Database->select('hosts', '*', "block=0 AND MAC!='' AND user=".$Member['Id']);
    8586  while($Host = $DbResult2->fetch_array())
    8687  {
     
    9091    $Subnet = $IPParts[2];
    9192    $Commands[] = ' /ip firewall mangle add chain=inet-out-'.$Subnet.' src-address='.$Host['IP'].' out-interface='.$InetInterface.' action=mark-packet new-packet-mark='.$PacketMark.' passthrough=no comment="'.$Host['name'].'"';
    92     $Commands[] = ' /queue tree add name='.$Host['name'].'-out limit-at='.$HostSpeedIn.' max-limit='.$UserMaxSpeedIn.' parent='.$User['fullname'].'-out packet-mark='.$PacketMark.' queue=wireless-default';
     93    $Commands[] = ' /queue tree add name='.$Host['name'].'-out limit-at='.$HostSpeedIn.' max-limit='.$UserMaxSpeedIn.' parent='.$Member['Name'].'-out packet-mark='.$PacketMark.' queue=wireless-default';
    9394    $PacketMark++;
    9495    $Commands[] = ' /ip firewall mangle add chain=inet-in-'.$Subnet.' dst-address='.$Host['IP'].' in-interface='.$InetInterface.' action=mark-packet new-packet-mark='.$PacketMark.' passthrough=no comment="'.$Host['name'].'"';
    95     $Commands[] = ' /queue tree add name='.$Host['name'].'-in limit-at='.$HostSpeedOut.' max-limit='.$UserMaxSpeedOut.' parent='.$User['fullname'].'-in packet-mark='.$PacketMark.' queue=wireless-default';
     96    $Commands[] = ' /queue tree add name='.$Host['name'].'-in limit-at='.$HostSpeedOut.' max-limit='.$UserMaxSpeedOut.' parent='.$Member['Name'].'-in packet-mark='.$PacketMark.' queue=wireless-default';
    9697    $PacketMark++;
    9798
    9899    // Posílej po menších částech
    99100    if($Index > 50)
    100         {
     101          {
    101102      $Commands = addslashes(implode(';', $Commands));
    102       $Command = '/usr/bin/ssh -l admin-ssh -i /root/.ssh/id_dsa '.$Router.' "'.$Commands.'"';
     103      $Command = '/usr/bin/ssh -l admin-ssh -i id_dsa '.$Router.' "'.$Commands.'"';
     104      //echo($Command."\n");
    103105      exec($Command, $Output);
    104106      print_r($Output);
    105           $Commands = array();
    106           $Index = 0;
    107         }
     107          $Commands = array();
     108            $Index = 0;
     109          }
    108110    $Index++;
    109111  }
     
    112114//print_r($Commands);
    113115$Commands = addslashes(implode(';', $Commands));
    114 $Command = '/usr/bin/ssh -l admin-ssh -i /root/.ssh/id_dsa '.$Router.' "'.$Commands.'"';
     116$Command = '/usr/bin/ssh -l admin-ssh -i id_dsa '.$Router.' "'.$Commands.'"';
    115117//echo($Command."\n");
    116118exec($Command, $Output);
Note: See TracChangeset for help on using the changeset viewer.