Ignore:
Timestamp:
Apr 1, 2013, 7:14:59 PM (12 years ago)
Author:
chronos
Message:
  • Opraveno: Generování nastavení sítě. Generování front Queue nyní pracuje s přiřazením služeb k zařízením a podsítím.
  • Opraveno: Zjišťování adresáře souborů na disku dle id adresáře.
File:
1 edited

Legend:

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

    r479 r507  
    99include('common.php');
    1010$PathQueue = array('queue', 'tree');
     11$Database = &$System->Database;
    1112
    1213$Routerboard = new Routerboard();
     
    2728$InDivider = 1;
    2829$OutDivider = 1;
    29 $TotalMaxSpeedIn = round($Finance->RealMaxSpeed / $InDivider) * 1024;
    30 $TotalMaxSpeedOut = round($Finance->RealMaxSpeed / $OutDivider) * 1024;
    31 $UsersMaxSpeedIn = round($Finance->MaxSpeed / $InDivider) * 1024;
    32 $UsersMaxSpeedOut = round($Finance->MaxSpeed / $OutDivider) * 1024;
     30$TotalMaxSpeedIn = round($Finance->RealMaxSpeed / $InDivider) * 1000;
     31$TotalMaxSpeedOut = round($Finance->RealMaxSpeed / $OutDivider) * 1000;
     32$UsersMaxSpeedIn = round($Finance->MaxSpeed / $InDivider) * 1000;
     33$UsersMaxSpeedOut = round($Finance->MaxSpeed / $OutDivider) * 1000;
    3334$VoipMaxSpeedIn = $TotalMaxSpeedIn - 136;
    3435$VoipMaxSpeedOut = $TotalMaxSpeedOut - 136;
     
    5556
    5657// Process users
    57 $DbResult = $Database->query('SELECT `Member`.*, `Subject`.`Name` FROM `Member` LEFT JOIN `Subject` ON `Subject`.`Id` = `Member`.`Subject`');
     58$DbResult = $Database->query('SELECT `Member`.*, `Subject`.`Name` FROM `Member` LEFT JOIN `Subject` ON `Subject`.`Id` = `Member`.`Subject` WHERE `Member`.`Blocked`=0');
    5859while($Member = $DbResult->fetch_assoc())
    5960{
    6061  $Member['Name'] = RouterOSIdent($Member['Name'].'-'.$Member['Id'] );
    6162
    62   echo('Uživatel '.$Member['Name'].': ');
    63   $Tariff = $Finance->Tariffs[$Member['InternetTariffCurrentMonth']];
    64   $SpeedIn = round($Tariff['InternetSpeedMin'] / $InDivider);
    65   $SpeedOut = round($Tariff['InternetSpeedMin'] / $OutDivider);
    66   $UserMaxSpeedIn = round($Tariff['InternetSpeedMax'] / $InDivider);
    67   $UserMaxSpeedOut = round($Tariff['InternetSpeedMax'] / $OutDivider);
    68   $ItemsQueue[] = array('name' => $Member['Name'].'-out', 'limit-at' => $SpeedIn, 'max-limit' => $UserMaxSpeedIn, 'parent' => 'main-out');
    69   $ItemsQueue[] = array('name' => $Member['Name'].'-in', 'limit-at' => $SpeedOut, 'max-limit' => $UserMaxSpeedOut, 'parent' => 'main-in');
     63  echo('Zákazník '.$Member['Name']."\n");
     64  $DbResult4 = $Database->query('SELECT `Service`.*, `ServiceCustomerRel`.`Id` AS `RelId` FROM `ServiceCustomerRel` JOIN `Service` ON `Service`.`Id` = `ServiceCustomerRel`.`Service` '.
     65    'WHERE (`ServiceCustomerRel`.`Customer` = '.$Member['Id'].') AND (`ServiceCustomerRel`.`Action` IS NULL)');
     66  while($Service = $DbResult4->fetch_assoc())
     67  {
     68    echo('Služba '.$Service['Name'].': ');
     69    $SpeedIn = round($Service['InternetSpeedMin'] / $InDivider) * 1000;
     70    $SpeedOut = round($Service['InternetSpeedMin'] / $OutDivider) * 1000;
     71    $UserMaxSpeedIn = round($Service['InternetSpeedMax'] / $InDivider) * 1000;
     72    $UserMaxSpeedOut = round($Service['InternetSpeedMax'] / $OutDivider) * 1000;
     73    $ItemsQueue[] = array('name' => $Member['Name'].'-out', 'limit-at' => $SpeedIn, 'max-limit' => $UserMaxSpeedIn, 'parent' => 'main-out');
     74    $ItemsQueue[] = array('name' => $Member['Name'].'-in', 'limit-at' => $SpeedOut, 'max-limit' => $UserMaxSpeedOut, 'parent' => 'main-in');
    7075
    71   $DbResult2 = $Database->select('NetworkDevice', 'COUNT(*)', '(`Used` = 1) AND (`Member`='.$Member['Id'].')');
    72   $Row = $DbResult2->fetch_row();
    73   $HostCount = $Row[0];
    74   if($HostCount > 0)
    75   {
    76     $HostSpeedIn = round($SpeedIn / $HostCount);
    77     $HostSpeedOut = round($SpeedOut / $HostCount);
    78   } else
    79   {
    80     $HostSpeedIn = $SpeedIn;
    81     $HostSpeedOut = $SpeedOut;
     76    $Filter = '(`Used` = 1) AND (`Service` = '.$Service['RelId'].')';
     77    $DbResult2 = $Database->select('NetworkDevice', 'COUNT(*)', $Filter);
     78    $Row = $DbResult2->fetch_row();
     79    $HostCount = $Row[0];
     80    if($HostCount > 0)
     81    {
     82      $HostSpeedIn = round($SpeedIn / $HostCount);
     83      $HostSpeedOut = round($SpeedOut / $HostCount);
     84    } else
     85    {
     86      $HostSpeedIn = $SpeedIn;
     87      $HostSpeedOut = $SpeedOut;
     88    }
     89
     90    $DbResult2 = $Database->select('NetworkDevice', '*', $Filter);
     91    while($Device = $DbResult2->fetch_assoc())
     92    {
     93      $DbResult3 = $Database->select('NetworkInterface', '*', '`Device` = '.$Device['Id'].' AND `LocalIP` != ""');
     94      while($Interface = $DbResult3->fetch_assoc())
     95      {
     96        $Name = $Device['Name'];
     97        if($Interface['Name'] != '') $Name .= '-'.$Interface['Name'];
     98        $Name = RouterOSIdent($Name);
     99        echo($Name.', ');
     100        $IPParts = explode('.', $Interface['LocalIP']);
     101        $Subnet = $IPParts[2];
     102        $PacketMark = GetMarkByComment($Name.'-out');
     103        $ItemsQueue[] = array('name' => $Name.'-out', 'limit-at' => $HostSpeedIn, 'max-limit' => $UserMaxSpeedIn, 'parent' => $Member['Name'].'-out', 'packet-mark' => $PacketMark);
     104        $PacketMark = GetMarkByComment($Name.'-in');
     105        $ItemsQueue[] = array('name' => $Name.'-in', 'limit-at' => $HostSpeedOut, 'max-limit' => $UserMaxSpeedOut, 'parent' => $Member['Name'].'-in', 'packet-mark' => $PacketMark);
     106      }
     107    }
     108 
     109    $DbResult2 = $Database->select('NetworkSubnet', '*', '`Service`='.$Service['RelId']);
     110    while($Subnet = $DbResult2->fetch_assoc())
     111    {
     112      $Subnet['Name'] = RouterOSIdent('subnet-'.$Subnet['Name']);
     113      echo($Subnet['Name'].', ');
     114      $IPParts = explode('.', $Subnet['AddressRange']);
     115      $SubnetNumber = $IPParts[2];
     116      $PacketMark = GetMarkByComment($Subnet['Name'].'-out');
     117      $ItemsQueue[] = array('name' => $Subnet['Name'].'-out', 'limit-at' => $HostSpeedIn, 'max-limit' => $UserMaxSpeedIn, 'parent' => $Member['Name'].'-out', 'packet-mark' => $PacketMark);
     118      $PacketMark = GetMarkByComment($Subnet['Name'].'-in');
     119      $ItemsQueue[] = array('name' => $Subnet['Name'].'-in', 'limit-at' => $HostSpeedOut, 'max-limit' => $UserMaxSpeedOut, 'parent' => $Member['Name'].'-in', 'packet-mark' => $PacketMark);
     120    }
     121    echo("\n");
    82122  }
    83 
    84   $DbResult2 = $Database->select('NetworkDevice', '*', '`Used` = 1 AND `Member` = '.$Member['Id']);
    85   while($Device = $DbResult2->fetch_assoc())
    86   {
    87     $DbResult3 = $Database->select('NetworkInterface', '*', '`Device` = '.$Device['Id'].' AND `LocalIP` != ""');
    88     while($Interface = $DbResult3->fetch_assoc())
    89     {
    90       $Name = $Device['Name'];
    91       if($Interface['Name'] != '') $Name .= '-'.$Interface['Name'];
    92       $Name = RouterOSIdent($Name);
    93       echo($Name.', ');
    94       $IPParts = explode('.', $Interface['LocalIP']);
    95       $Subnet = $IPParts[2];
    96       $PacketMark = GetMarkByComment($Name.'-out');
    97       $ItemsQueue[] = array('name' => $Name.'-out', 'limit-at' => $HostSpeedIn, 'max-limit' => $UserMaxSpeedIn, 'parent' => $Member['Name'].'-out', 'packet-mark' => $PacketMark);
    98       $PacketMark = GetMarkByComment($Name.'-in');
    99       $ItemsQueue[] = array('name' => $Name.'-in', 'limit-at' => $HostSpeedOut, 'max-limit' => $UserMaxSpeedOut, 'parent' => $Member['Name'].'-in', 'packet-mark' => $PacketMark);
    100     }
    101   }
    102  
    103   $DbResult2 = $Database->select('NetworkSubnet', '*', '`Member`='.$Member['Id']);
    104   while($Subnet = $DbResult2->fetch_assoc())
    105   {
    106     $Subnet['Name'] = RouterOSIdent('subnet-'.$Subnet['Name']);
    107     echo($Subnet['Name'].', ');
    108     $IPParts = explode('.', $Subnet['AddressRange']);
    109     $SubnetNumber = $IPParts[2];
    110     $PacketMark = GetMarkByComment($Subnet['Name'].'-out');
    111     $ItemsQueue[] = array('name' => $Subnet['Name'].'-out', 'limit-at' => $HostSpeedIn, 'max-limit' => $UserMaxSpeedIn, 'parent' => $Member['Name'].'-out', 'packet-mark' => $PacketMark);
    112     $PacketMark = GetMarkByComment($Subnet['Name'].'-in');
    113     $ItemsQueue[] = array('name' => $Subnet['Name'].'-in', 'limit-at' => $HostSpeedOut, 'max-limit' => $UserMaxSpeedOut, 'parent' => $Member['Name'].'-in', 'packet-mark' => $PacketMark);
    114   }
    115   echo("\n");
    116123}
    117124
Note: See TracChangeset for help on using the changeset viewer.