Changeset 171 for www/system/generators/traffic_shaping_routerboard.php
- Timestamp:
- Mar 24, 2009, 7:28:33 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
www/system/generators/traffic_shaping_routerboard.php
r167 r171 6 6 include_once('../../global.php'); 7 7 $Finance = &$System->Modules['Finance']; 8 $Finance-> NactiMesicniParametry(0);8 $Finance->LoadMonthParameters(0); 9 9 10 10 // Generate traffic shaping rules … … 29 29 30 30 $InetInterface = 'ether3'; 31 $Router = '192.168.0. 99';31 $Router = '192.168.0.11'; 32 32 33 33 $Commands = array(); … … 59 59 // Process users 60 60 $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'); 62 while($Member = $DbResult->fetch_array()) 63 63 { 64 $ User['fullname'] = strtr(strtolower(trim($User['fullname'])), array(' ' => '-', '(' => '-', ')' => '-',64 $Member['Name'] = strtr(strtolower(trim($Member['Name'])), array(' ' => '-', '(' => '-', ')' => '-', 65 65 'č' => 'c', 'š' => 's', 'ě' => 'e', 'ř' => 'r', 'ž' => 'z', 'ý' => 'y', 'á' => 'a', 'í' => 'i', 'é' => 'e', 'ů' => 'u', 'ú' => 'u', 'ď' => 'd', 'ť' => 't', 'ň' => 'n', 'ó' => 'o', 66 66 'Č' => 'c', 'Š' => 's', 'Ě' => 'e', 'Ř' => 'r', 'Ž' => 'z', 'Ý' => 'y', 'Á' => 'a', 'Í' => 'i', 'É' => 'e', 'Ů' => 'u', 'Ú' => 'u', 'Ď' => 'd', 'Ť' => 't', 'Ň' => 'n', 'Ó' => 'o', 67 67 )); 68 68 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'; 77 78 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']); 79 80 $Row = $DbResult2->fetch_array(); 80 81 $HostCount = $Row[0]; … … 82 83 $HostSpeedOut = round($SpeedOut / $HostCount); 83 84 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']); 85 86 while($Host = $DbResult2->fetch_array()) 86 87 { … … 90 91 $Subnet = $IPParts[2]; 91 92 $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'; 93 94 $PacketMark++; 94 95 $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'; 96 97 $PacketMark++; 97 98 98 99 // Posílej po menších částech 99 100 if($Index > 50) 100 {101 { 101 102 $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"); 103 105 exec($Command, $Output); 104 106 print_r($Output); 105 $Commands = array();106 $Index = 0;107 }107 $Commands = array(); 108 $Index = 0; 109 } 108 110 $Index++; 109 111 } … … 112 114 //print_r($Commands); 113 115 $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.'"'; 115 117 //echo($Command."\n"); 116 118 exec($Command, $Output);
Note:
See TracChangeset
for help on using the changeset viewer.