Changeset 869
- Timestamp:
- Apr 1, 2020, 12:43:07 AM (5 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Application/UpdateTrace.php
r867 r869 2075 2075 KEY `Time` (`Time`) 2076 2076 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;'); 2077 2077 } 2078 2079 function UpdateTo869($Manager) 2080 { 2081 $Manager->Execute('CREATE TABLE IF NOT EXISTS `NetworkSpeedLimit` ( 2082 `Id` int(11) NOT NULL AUTO_INCREMENT, 2083 `Name` varchar(255) CHARACTER SET utf8 NOT NULL, 2084 `SpeedMaxOut` bigint(20) NOT NULL DEFAULT 0, 2085 `SpeedMaxIn` bigint(20) NOT NULL DEFAULT 0, 2086 `Parent` int(11) DEFAULT 0, 2087 PRIMARY KEY (`Id`), 2088 KEY `Parent` (`Parent`) 2089 ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;'); 2090 $Manager->Execute('ALTER TABLE `ServiceCustomerRel` ADD COLUMN `SpeedLimit` INT NULL AFTER `ChangeReplaceId`, ADD INDEX `SpeedLimit` (`SpeedLimit`);'); 2091 2092 // IS menu item 2093 $Manager->Execute('INSERT INTO `Action` (`Id` ,`Name` ,`Title` ,`Type` ,`URL` , 2094 `Group` ,`Icon` ,`PermissionOperation` ,`Enable`) VALUES ( 2095 NULL , "", "Omezení rychlosti", "1", "/is/?t=NetworkSpeedLimit&a=list", NULL , NULL , NULL , "1");'); 2096 $ActionId = $Manager->Database->insert_id; 2097 $DbResult = $Manager->Execute('SELECT `Id` FROM `MenuItem` WHERE `Name`="Síť"'); 2098 if($DbResult->num_rows > 0) 2099 { 2100 $DbRow = $DbResult->fetch_assoc(); 2101 $Manager->Execute("INSERT INTO `MenuItem` (`Id` ,`Name` ,`Parent` ,`Action` ,`Menu`) ". 2102 "VALUES (NULL , 'Omezení rychlosti', ".$DbRow['Id'].", '".$ActionId."', '1');"); 2103 } 2078 2104 } 2079 2105 … … 2176 2202 855 => array('Revision' => 862, 'Function' => 'UpdateTo862'), 2177 2203 862 => array('Revision' => 867, 'Function' => 'UpdateTo867'), 2204 867 => array('Revision' => 869, 'Function' => 'UpdateTo869'), 2178 2205 )); 2179 2206 } -
trunk/Application/Version.php
r868 r869 1 1 <?php 2 2 3 $Revision = 86 8; // Subversion revision4 $DatabaseRevision = 86 7; // SQL structure revision5 $ReleaseTime = strtotime('2020-0 1-13');3 $Revision = 869; // Subversion revision 4 $DatabaseRevision = 869; // SQL structure revision 5 $ReleaseTime = strtotime('2020-03-31'); -
trunk/Common/Global.php
r825 r869 212 212 global $OrderDirSQL, $OrderArrowImage, $Config, $System; 213 213 214 if(array_key_exists('ObjectName', $_GET) and ($_GET['ObjectName'] == $ObjectName)) 214 if(array_key_exists('ObjectName', $_GET) and ($_GET['ObjectName'] == $ObjectName)) 215 215 { 216 216 if(array_key_exists('OrderCol', $_GET)) $_SESSION[$ObjectName.'OrderCol'] = $_GET['OrderCol']; … … 219 219 if(!array_key_exists($ObjectName.'OrderCol', $_SESSION)) $_SESSION[$ObjectName.'OrderCol'] = $DefaultColumn; 220 220 if(!array_key_exists($ObjectName.'OrderDir', $_SESSION) ) $_SESSION[$ObjectName.'OrderDir'] = $DefaultOrder; 221 221 222 222 // Check OrderCol 223 223 $Found = false; … … 236 236 } 237 237 // Check OrderDir 238 if(($_SESSION[$ObjectName.'OrderDir'] != 0) and ($_SESSION[$ObjectName.'OrderDir'] != 1)) 238 if(($_SESSION[$ObjectName.'OrderDir'] != 0) and ($_SESSION[$ObjectName.'OrderDir'] != 1)) 239 239 $_SESSION[$ObjectName.'OrderDir'] = 0; 240 240 … … 246 246 $QueryItems['OrderCol'] = $Column['Name']; 247 247 $QueryItems['OrderDir'] = 1 - $_SESSION[$ObjectName.'OrderDir']; 248 if($Column['Name'] == $_SESSION[$ObjectName.'OrderCol']) 248 if($Column['Name'] == $_SESSION[$ObjectName.'OrderCol']) 249 249 $ArrowImage = '<img style="vertical-align: middle; border: 0px;" src="'. 250 250 $System->Link('/images/'.$OrderArrowImage[$_SESSION[$ObjectName.'OrderDir']]).'" alt="order arrow">'; … … 317 317 function RouterOSIdent($Name) 318 318 { 319 return(strtr(strtolower(trim($Name)), array(' ' => '-', '.' => '', '(' => '-', ')' => '-', 319 return(strtr(strtolower(trim($Name)), array(' ' => '-', '.' => '', '(' => '-', ')' => '-', ',' => '-', 320 320 'č' => 'c', 'š' => 's', 'ě' => 'e', 'ř' => 'r', 'ž' => 'z', 'ý' => 'y', 321 321 'á' => 'a', 'í' => 'i', 'é' => 'e', 'ů' => 'u', 'ú' => 'u', 'ď' => 'd', -
trunk/Modules/Customer/Customer.php
r831 r869 99 99 )); 100 100 $this->System->FormManager->RegisterClass('ServiceCustomerRel', array( 101 'Title' => ' Vztahy služba - zákazník',101 'Title' => 'Služby zákazníka', 102 102 'Table' => 'ServiceCustomerRel', 103 103 'Items' => array( 104 104 'Service' => array('Type' => 'TService', 'Caption' => 'Služba', 'Default' => ''), 105 105 'Customer' => array('Type' => 'TMember', 'Caption' => 'Zákazník', 'Default' => ''), 106 'SpeedLimit' => array('Type' => 'TNetworkSpeedLimit', 'Caption' => 'Omezení rychlosti', 'Default' => null, 'Null' => true), 107 'Devices' => array('Type' => 'TNetworkDeviceListService', 'Caption' => 'Zařízení', 'Default' => ''), 106 108 'ChangeAction' => array('Type' => 'TActionEnum', 'Caption' => 'Změna - akce', 'Default' => '', 'Null' => true), 107 109 'ChangeTime' => array('Type' => 'DateTime', 'Caption' => 'Změna - čas', 'Default' => '', 'Null' => true, 'NotInList' => true), … … 135 137 'Id' => 'Id', 136 138 'Ref' => 'Customer', 139 'Filter' => '1', 140 )); 141 $this->System->FormManager->RegisterFormType('TNetworkDeviceListService', array( 142 'Type' => 'ManyToOne', 143 'Table' => 'NetworkDevice', 144 'Id' => 'Id', 145 'Ref' => 'Service', 137 146 'Filter' => '1', 138 147 )); -
trunk/Modules/Network/Network.php
r868 r869 293 293 'UpDown' => array('Type' => 'TNetworkPortUpDown', 'Caption' => 'Změny stavu', 'Default' => ''), 294 294 ), 295 )); 296 $this->System->FormManager->RegisterClass('NetworkSpeedLimit', array( 297 'Title' => 'Omezení přenosové rychlosti', 298 'Table' => 'NetworkSpeedLimit', 299 'Items' => array( 300 'Name' => array('Type' => 'String', 'Caption' => 'Jméno', 'Default' => ''), 301 'SpeedMaxOut' => array('Type' => 'Integer', 'Caption' => 'Max. rychlost odesílání', 'Default' => '0', 'Suffix' => 'bits/s'), 302 'SpeedMaxIn' => array('Type' => 'Integer', 'Caption' => 'Max. rychlost přijímání', 'Default' => 0, 'Suffix' => 'bits/s'), 303 'Parent' => array('Type' => 'TNetworkSpeedLimit', 'Caption' => 'Rodič', 'Default' => '', 'Null' => true), 304 'Items' => array('Type' => 'TNetworkSpeedLimitListParent', 'Caption' => 'Položky'), 305 'CustomerServices' => array('Type' => 'TServiceCustomerRelListSpeedLimit', 'Caption' => 'Služby zákazníka'), 306 ), 307 )); 308 $this->System->FormManager->RegisterFormType('TNetworkSpeedLimit', array( 309 'Type' => 'Reference', 310 'Table' => 'NetworkSpeedLimit', 311 'Id' => 'Id', 312 'Name' => 'Name', 313 'Filter' => '1', 314 )); 315 $this->System->FormManager->RegisterFormType('TNetworkSpeedLimitListParent', array( 316 'Type' => 'ManyToOne', 317 'Table' => 'NetworkSpeedLimit', 318 'Id' => 'Id', 319 'Ref' => 'Parent', 320 'Filter' => '1', 321 )); 322 $this->System->FormManager->RegisterFormType('TServiceCustomerRelListSpeedLimit', array( 323 'Type' => 'ManyToOne', 324 'Table' => 'ServiceCustomerRel', 325 'Id' => 'Id', 326 'Ref' => 'SpeedLimit', 327 'Filter' => '1', 295 328 )); 296 329 $this->System->FormManager->RegisterClass('NetworkInterfaceLatency', array( -
trunk/Modules/NetworkConfigRouterOS/Generators/Queue.php
r831 r869 1 1 <?php 2 3 class SpeedLimit 4 { 5 var $Min; 6 var $Max; 7 var $PacketMark; 8 9 function __construct(int $Min, int $Max, int $PacketMark = null) 10 { 11 $this->Min = $Min; 12 $this->Max = $Max; 13 $this->PacketMark = $PacketMark; 14 } 15 16 function Print() 17 { 18 $Output = '(Min: '.$this->Min.' Max: '.$this->Max; 19 if ($this->PacketMark != null) $Output .= ' PacketMark: '.$this->PacketMark; 20 $Output .= ')'; 21 return $Output; 22 } 23 } 24 25 class SpeedLimitItem 26 { 27 var $Name; 28 var $Parent; 29 var $LimitIn; 30 var $LimitOut; 31 var $SubItems; 32 33 function __construct(string $Name, SpeedLimitItem $Parent = null) 34 { 35 $this->Name = $Name; 36 $this->Parent = $Parent; 37 if ($Parent != null) $Parent->SubItems->Add($this); 38 $this->SubItems = new SpeedLimitItems(); 39 } 40 41 function Print(int $Indent = 0): string 42 { 43 $Output = str_repeat(' ', $Indent * 2).$this->Name.' In:'.$this->LimitIn->Print().' Out:'.$this->LimitOut->Print()."\n"; 44 $Output .= $this->SubItems->Print($Indent + 1); 45 return $Output; 46 } 47 48 function CheckName($Name, &$UsedNames) 49 { 50 if(in_array($Name, $UsedNames)) die("\n".'Duplicate name: '.$Name); 51 else $UsedNames[] = $Name; 52 } 53 54 function GetCommands(&$UsedNames = null) 55 { 56 if ($UsedNames == null) $UsedNames = array(); 57 58 $this->CheckName($this->Name.'-out', $UsedNames); 59 $Item = array('name' => $this->Name.'-out', 'limit-at' => $this->LimitOut->Min, 'max-limit' => $this->LimitOut->Max, 60 'parent' => $this->GetParentName('-out'), 'packet-mark' => $this->LimitOut->PacketMark); 61 if ($this->LimitOut->PacketMark != null) $Item['packet-mark'] = $this->LimitOut->PacketMark; 62 $Output[] = $Item; 63 64 $this->CheckName($this->Name.'-in', $UsedNames); 65 $Item = array('name' => $this->Name.'-in', 'limit-at' => $this->LimitIn->Min, 'max-limit' => $this->LimitIn->Max, 66 'parent' => $this->GetParentName('-in')); 67 if ($this->LimitIn->PacketMark != null) $Item['packet-mark'] = $this->LimitIn->PacketMark; 68 $Output[] = $Item; 69 70 $Output = array_merge($Output, $this->SubItems->GetCommands($UsedNames)); 71 return $Output; 72 } 73 74 function GetParentName(string $Suffix) 75 { 76 if ($this->Parent != null) return $this->Parent->Name.$Suffix; 77 return 'global'; 78 } 79 80 function UpdateMinSpeeds() 81 { 82 if (($this->LimitIn->Min == 0) or ($this->LimitOut->Min == 0)) 83 { 84 $SpeedMinOut = 0; 85 $SpeedMinIn = 0; 86 foreach ($this->SubItems->Items as $Index => $Item) 87 { 88 $this->SubItems->Items[$Index]->UpdateMinSpeeds(); 89 $SpeedMinOut += $this->SubItems->Items[$Index]->LimitOut->Min; 90 $SpeedMinIn += $this->SubItems->Items[$Index]->LimitIn->Min; 91 } 92 if ($SpeedMinOut > $this->LimitOut->Max) $SpeedMinOut = $this->LimitOut->Max; 93 if ($SpeedMinIn > $this->LimitIn->Max) $SpeedMinIn = $this->LimitIn->Max; 94 $this->LimitOut->Min = $SpeedMinOut; 95 $this->LimitIn->Min = $SpeedMinIn; 96 } 97 } 98 } 99 100 class SpeedLimitItems extends GenericList 101 { 102 function AddNew(string $Name, SpeedLimitItem $Parent = null) 103 { 104 $Item = new SpeedLimitItem($Name, $Parent); 105 $Item->LimitIn = new SpeedLimit(); 106 $Item->LimitOut = new SpeedLimit(); 107 $this->Items[] = $Item; 108 return $Item; 109 } 110 111 function Print(int $Indent = 0): string 112 { 113 $Output = ''; 114 foreach ($this->Items as $SubItem) 115 { 116 $Output .= $SubItem->Print($Indent); 117 } 118 return $Output; 119 } 120 121 function GetCommands(&$UsedNames) 122 { 123 $Output = array(); 124 foreach ($this->Items as $SubItem) 125 { 126 $Output = array_merge($Output, $SubItem->GetCommands($UsedNames)); 127 } 128 return $Output; 129 } 130 } 2 131 3 132 class ConfigRouterOSQueue extends NetworkConfigItem … … 6 135 var $Devices; 7 136 var $QueueItems; 8 9 function CheckName($Name) 10 { 11 if(in_array($Name, $this->UsedNames)) die("\n".'Duplicate name: '.$Name); 12 else $this->UsedNames[] = $Name; 13 } 137 var $SpeedLimits; 14 138 15 139 function Run() … … 29 153 30 154 // Generate traffic shaping rules 31 //$TotalMaxSpeedIn = 4048; //$RealMaxSpeed; //1536;32 //TotalMaxSpeedOut = 3048; //$RealMaxSpeed; //1536;33 //$UsersMaxSpeedIn = 1900; //$MaxSpeed;34 //$UsersMaxSpeedOut = 1900; //$MaxSpeed;35 36 155 $InDivider = 1; 37 156 $OutDivider = 1; … … 49 168 50 169 $DbResult = $this->Database->select('Service', '*', '(`ChangeAction` IS NULL) AND (`Id`='.TARIFF_FREE.')'); 51 if ($DbResult->num_rows == 1)170 if ($DbResult->num_rows == 1) 52 171 { 53 172 $Service = $DbResult->fetch_array(); … … 55 174 } else $FreeInetSpeed = 0; 56 175 57 $ItemsQueue = array();58 59 176 // Root of tree and main limit 60 $ItemsQueue[] = array('name' => 'main-out', 'limit-at' => $UsersMaxSpeedIn, 'max-limit' => $UsersMaxSpeedIn, 'parent' => 'global'); 61 $ItemsQueue[] = array('name' => 'main-in', 'limit-at' => $UsersMaxSpeedOut, 'max-limit' => $UsersMaxSpeedOut, 'parent' => 'global'); 177 $Main = new SpeedLimitItem('main'); 178 $Main->LimitIn = new SpeedLimit(0, $UsersMaxSpeedIn); 179 $Main->LimitOut = new SpeedLimit(0, $UsersMaxSpeedOut); 180 181 $this->LoadSpeedLimits($Main); 62 182 63 183 // Slow free internet 64 $PacketMark = GetMarkByComment('free-out'); 65 $ItemsQueue[] = array('name' => 'free-out', 'limit-at' => $FreeInetSpeed, 'max-limit' => $FreeInetSpeed, 'parent' => 'main-out', 'packet-mark' => $PacketMark); 66 $PacketMark = GetMarkByComment('free-in'); 67 $ItemsQueue[] = array('name' => 'free-in', 'limit-at' => $FreeInetSpeed, 'max-limit' => $FreeInetSpeed, 'parent' => 'main-in', 'packet-mark' => $PacketMark); 184 $Free = new SpeedLimitItem('free', $Main); 185 $Free->LimitIn = new SpeedLimit($FreeInetSpeed, $FreeInetSpeed, GetMarkByComment('free-in')); 186 $Free->LimitOut = new SpeedLimit($FreeInetSpeed, $FreeInetSpeed, GetMarkByComment('free-out')); 68 187 69 188 // Process users … … 74 193 $ServiceIndex = 1; 75 194 echo('Zákazník '.$Member['Name']."\n"); 76 $DbResult4 = $this->Database->query('SELECT `Service`.*, `ServiceCustomerRel`.`Id` AS `RelId` FROM `ServiceCustomerRel` '. 195 $DbResult4 = $this->Database->query('SELECT `Service`.*, `ServiceCustomerRel`.`Id` AS `RelId`, '. 196 '`ServiceCustomerRel`.`SpeedLimit` AS `SpeedLimit` FROM `ServiceCustomerRel` '. 77 197 'JOIN `Service` ON `Service`.`Id` = `ServiceCustomerRel`.`Service` '. 78 198 'WHERE (`ServiceCustomerRel`.`Customer` = '.$Member['Id'].') AND (`ServiceCustomerRel`.`ChangeAction` IS NULL) '. … … 86 206 $UserMaxSpeedIn = round($Service['InternetSpeedMax'] / $InDivider); 87 207 $UserMaxSpeedOut = round($Service['InternetSpeedMax'] / $OutDivider); 88 $ItemsQueue[] = array('name' => $MemberName.'-out', 'limit-at' => $SpeedIn, 'max-limit' => $UserMaxSpeedIn, 'parent' => 'main-out'); 89 $ItemsQueue[] = array('name' => $MemberName.'-in', 'limit-at' => $SpeedOut, 'max-limit' => $UserMaxSpeedOut, 'parent' => 'main-in'); 90 $this->CheckName($MemberName.'-out'); 91 $this->CheckName($MemberName.'-in'); 208 209 // Reduce max speed by speed limits 210 $SpeedLimitItem = $Main; 211 if ($Service['SpeedLimit'] != null) 212 { 213 $SpeedLimit = $this->SpeedLimits[$Service['SpeedLimit']]; 214 $SpeedLimitItem = $SpeedLimit['SpeedLimitItem']; 215 if ($UserMaxSpeedIn > $SpeedLimit['SpeedMaxIn']) $UserMaxSpeedIn = $SpeedLimit['SpeedMaxIn']; 216 if ($UserMaxSpeedOut > $SpeedLimit['SpeedMaxOut']) $UserMaxSpeedOut = $SpeedLimit['SpeedMaxOut']; 217 while ($SpeedLimit['Parent'] != null) 218 { 219 $SpeedLimit = $this->SpeedLimits[$SpeedLimit['Parent']]; 220 if ($UserMaxSpeedIn > $SpeedLimit['SpeedMaxIn']) $UserMaxSpeedIn = $SpeedLimit['SpeedMaxIn']; 221 if ($UserMaxSpeedOut > $SpeedLimit['SpeedMaxOut']) $UserMaxSpeedOut = $SpeedLimit['SpeedMaxOut']; 222 } 223 } 224 225 $LimitMember = new SpeedLimitItem($MemberName, $SpeedLimitItem); 226 $LimitMember->LimitIn = new SpeedLimit($SpeedIn, $UserMaxSpeedIn); 227 $LimitMember->LimitOut = new SpeedLimit($SpeedOut, $UserMaxSpeedOut); 92 228 93 229 $Filter = '(`Used` = 1) AND (`Service` = '.$Service['RelId'].')'; … … 111 247 while($Interface = $DbResult3->fetch_assoc()) 112 248 { 113 $Name = $Device['Name']; 114 if($Interface['Name'] != '') $Name .= '-'.$Interface['Name']; 115 $Name = RouterOSIdent($Name); 116 echo($Name.', '); 117 $PacketMark = GetMarkByComment($Name.'-out'); 118 $ItemsQueue[] = array('name' => $Name.'-out', 'limit-at' => $HostSpeedIn, 'max-limit' => $UserMaxSpeedIn, 'parent' => $MemberName.'-out', 'packet-mark' => $PacketMark); 119 $PacketMark = GetMarkByComment($Name.'-in'); 120 $ItemsQueue[] = array('name' => $Name.'-in', 'limit-at' => $HostSpeedOut, 'max-limit' => $UserMaxSpeedOut, 'parent' => $MemberName.'-in', 'packet-mark' => $PacketMark); 121 $this->CheckName($Name.'-out'); 122 $this->CheckName($Name.'-in'); 249 $DeviceName = $Device['Name']; 250 if($Interface['Name'] != '') $DeviceName .= '-'.$Interface['Name']; 251 $DeviceName = RouterOSIdent($DeviceName); 252 echo($DeviceName.', '); 253 $LimitDevice = new SpeedLimitItem($DeviceName, $LimitMember); 254 $LimitDevice->LimitIn = new SpeedLimit($HostSpeedIn, $UserMaxSpeedIn, GetMarkByComment($DeviceName.'-in')); 255 $LimitDevice->LimitOut = new SpeedLimit($HostSpeedOut, $UserMaxSpeedOut, GetMarkByComment($DeviceName.'-out')); 123 256 } 124 257 } … … 127 260 while($Subnet = $DbResult2->fetch_assoc()) 128 261 { 129 $Subnet['Name'] = RouterOSIdent('subnet-'.$Subnet['Name']); 130 echo($Subnet['Name'].', '); 131 $PacketMark = GetMarkByComment($Subnet['Name'].'-out'); 132 $ItemsQueue[] = array('name' => $Subnet['Name'].'-out', 'limit-at' => $HostSpeedIn, 'max-limit' => $UserMaxSpeedIn, 'parent' => $MemberName.'-out', 'packet-mark' => $PacketMark); 133 $PacketMark = GetMarkByComment($Subnet['Name'].'-in'); 134 $ItemsQueue[] = array('name' => $Subnet['Name'].'-in', 'limit-at' => $HostSpeedOut, 'max-limit' => $UserMaxSpeedOut, 'parent' => $MemberName.'-in', 'packet-mark' => $PacketMark); 135 $this->CheckName($Subnet['Name'].'-out'); 136 $this->CheckName($Subnet['Name'].'-in'); 262 $SubnetName = RouterOSIdent('subnet-'.$Subnet['Name']); 263 echo($SubnetName.', '); 264 $LimitSubnet = new SpeedLimitItem($SubnetName, $LimitMember); 265 $LimitSubnet->LimitIn = new SpeedLimit($HostSpeedIn, $UserMaxSpeedIn, GetMarkByComment($SubnetName.'-in')); 266 $LimitSubnet->LimitOut = new SpeedLimit($HostSpeedOut, $UserMaxSpeedOut, GetMarkByComment($SubnetName.'-out')); 137 267 } 138 268 echo("\n"); … … 140 270 } 141 271 } 272 $Main->UpdateMinSpeeds(); 273 echo($Main->Print()); 274 $ItemsQueue = $Main->GetCommands(); 275 //print_r($ItemsQueue); 276 //die(); 142 277 143 278 //print_r($ItemsQueue); 144 279 $Routerboard->ListUpdate($PathQueue, array('name', 'limit-at', 'max-limit', 'parent', 'packet-mark'), $ItemsQueue, array(), true); 280 } 281 282 function BuildSpeedLimit(&$SpeedLimit, $TopSpeedLimitItem) 283 { 284 $SpeedLimitName = $SpeedLimit['Name'].'-grp'; 285 $SpeedLimitName = RouterOSIdent($SpeedLimitName); 286 echo($SpeedLimitName.', '); 287 288 $SpeedLimitItem = new SpeedLimitItem($SpeedLimitName, $TopSpeedLimitItem); 289 $SpeedLimitItem->LimitIn = new SpeedLimit(0, $SpeedLimit['SpeedMaxIn']); 290 $SpeedLimitItem->LimitOut = new SpeedLimit(0, $SpeedLimit['SpeedMaxOut']); 291 $SpeedLimit['SpeedLimitItem'] = $SpeedLimitItem; 292 293 foreach ($SpeedLimit['Childs'] as $ChildId) 294 { 295 $this->BuildSpeedLimit($this->SpeedLimits[$ChildId], $SpeedLimitItem); 296 } 297 } 298 299 function LoadSpeedLimits($SpeedLimitItem) 300 { 301 echo('Limit groups: '); 302 // Load all speed limits 303 $this->SpeedLimits = array(); 304 $DbResult = $this->Database->query('SELECT * FROM `NetworkSpeedLimit`'); 305 while ($SpeedLimit = $DbResult->fetch_array()) 306 { 307 $SpeedLimit['Childs'] = array(); 308 $this->SpeedLimits[$SpeedLimit['Id']] = $SpeedLimit; 309 } 310 311 // Calculate childs from parent 312 foreach ($this->SpeedLimits as $Index => $SpeedLimit) 313 { 314 if ($SpeedLimit['Parent'] != null) $this->SpeedLimits[$SpeedLimit['Parent']]['Childs'][] = $Index; 315 } 316 317 // Build speed limits from top 318 foreach ($this->SpeedLimits as $Index => $SpeedLimit) 319 { 320 if ($SpeedLimit['Parent'] == null) 321 { 322 $this->BuildSpeedLimit($this->SpeedLimits[$Index], $SpeedLimitItem); 323 } 324 } 325 echo("\n"); 145 326 } 146 327 … … 257 438 } 258 439 259 function BuildQueueItems($DeviceId )440 function BuildQueueItems($DeviceId, $SpeedLimitParent) 260 441 { 261 442 $Device = $this->Devices[$DeviceId]; 262 443 263 444 // Device 264 if($Device['Parent'] != 0) 265 $ParentQueueName = $this->Devices[$Device['Parent']]['QueueName']; 266 else $ParentQueueName = 'main'; 267 $Name = $Device['Name']; 268 $Name = RouterOSIdent($Name); 269 $DeviceName = $Name; 270 $this->Devices[$DeviceId]['QueueName'] = $Name; 271 echo($Name.', '); 272 $PacketMark = GetMarkByComment($Name.'-out'); 273 $this->ItemsQueue[] = array('name' => $Name.'-out', 'limit-at' => $Device['MinSpeed'], 274 'max-limit' => $Device['MaxSpeed'], 'parent' => $ParentQueueName.'-out', 275 'packet-mark' => $PacketMark); 276 $PacketMark = GetMarkByComment($Name.'-in'); 277 $this->ItemsQueue[] = array('name' => $Name.'-in', 'limit-at' => $Device['MinSpeed'], 278 'max-limit' => $Device['MaxSpeed'], 'parent' => $ParentQueueName.'-in', 279 'packet-mark' => $PacketMark); 280 $this->CheckName($Name.'-out'); 281 $this->CheckName($Name.'-in'); 445 $DeviceName = $Device['Name']; 446 $DeviceName = RouterOSIdent($DeviceName); 447 $this->Devices[$DeviceId]['QueueName'] = $DeviceName; 448 echo($DeviceName.', '); 449 450 $LimitDevice = new SpeedLimitItem($DeviceName, $SpeedLimitParent); 451 $LimitDevice->LimitIn = new SpeedLimit($Device['MinSpeed'], $Device['MaxSpeed'], GetMarkByComment($DeviceName.'-in')); 452 $LimitDevice->LimitOut = new SpeedLimit($Device['MinSpeed'], $Device['MaxSpeed'], GetMarkByComment($DeviceName.'-out')); 282 453 283 454 // Interfaces … … 286 457 while($Interface = $DbResult3->fetch_assoc()) 287 458 { 288 $Name = $Device['Name']; 289 if($Interface['Name'] != '') $Name .= '-'.$Interface['Name']; 290 else $Name .= '-'; 291 $Name = RouterOSIdent($Name); 292 echo($Name.', '); 293 $PacketMark = GetMarkByComment($Name.'-out'); 294 $this->ItemsQueue[] = array('name' => $Name.'-out', 'limit-at' => round($Device['MinSpeed'] / $IntCount), 295 'max-limit' => $Device['MaxSpeed'], 'parent' => $DeviceName.'-out', 296 'packet-mark' => $PacketMark); 297 $PacketMark = GetMarkByComment($Name.'-in'); 298 $this->ItemsQueue[] = array('name' => $Name.'-in', 'limit-at' => round($Device['MinSpeed'] / $IntCount), 299 'max-limit' => $Device['MaxSpeed'], 'parent' => $DeviceName.'-in', 300 'packet-mark' => $PacketMark); 301 $this->CheckName($Name.'-out'); 302 $this->CheckName($Name.'-in'); 459 $InterfaceName = $Device['Name']; 460 if($Interface['Name'] != '') $InterfaceName .= '-'.$Interface['Name']; 461 else $InterfaceName .= '-'; 462 $InterfaceName = RouterOSIdent($InterfaceName); 463 echo($InterfaceName.', '); 464 465 $LimitInterface = new SpeedLimitItem($InterfaceName, $LimitDevice); 466 $LimitInterface->LimitIn = new SpeedLimit(round($Device['MinSpeed'] / $IntCount), $Device['MaxSpeed'], GetMarkByComment($InterfaceName.'-in')); 467 $LimitInterface->LimitOut = new SpeedLimit(round($Device['MinSpeed'] / $IntCount), $Device['MaxSpeed'], GetMarkByComment($InterfaceName.'-out')); 303 468 } 304 469 … … 306 471 foreach($Device['Childs'] as $DeviceChild) 307 472 { 308 $this->BuildQueueItems($DeviceChild );473 $this->BuildQueueItems($DeviceChild, $LimitDevice); 309 474 } 310 475 } … … 349 514 350 515 // Root of tree and main limit 351 $this->ItemsQueue[] = array('name' => 'main-out', 'limit-at' => $UsersMaxSpeedIn, 'max-limit' => $UsersMaxSpeedIn, 'parent' => 'global'); 352 $this->ItemsQueue[] = array('name' => 'main-in', 'limit-at' => $UsersMaxSpeedOut, 'max-limit' => $UsersMaxSpeedOut, 'parent' => 'global'); 516 $Main = new SpeedLimitItem('main'); 517 $Main->LimitIn = new SpeedLimit($UsersMaxSpeedIn, $UsersMaxSpeedIn); 518 $Main->LimitOut = new SpeedLimit($UsersMaxSpeedOut, $UsersMaxSpeedOut); 353 519 354 520 // Slow free internet 355 $PacketMark = GetMarkByComment('free-out'); 356 $this->ItemsQueue[] = array('name' => 'free-out', 'limit-at' => $FreeInetSpeed, 'max-limit' => $FreeInetSpeed, 'parent' => 'main-out', 'packet-mark' => $PacketMark); 357 $PacketMark = GetMarkByComment('free-in'); 358 $this->ItemsQueue[] = array('name' => 'free-in', 'limit-at' => $FreeInetSpeed, 'max-limit' => $FreeInetSpeed, 'parent' => 'main-in', 'packet-mark' => $PacketMark); 359 360 $this->BuildTree($this->System->Config['MainRouter']['DeviceId'], 140 * 1000 * 1000); 361 362 $this->BuildQueueItems($this->System->Config['MainRouter']['DeviceId']); 363 364 //print_r($this->ItemsQueue); 365 $Routerboard->ListUpdate($PathQueue, array('name', 'limit-at', 'max-limit', 366 'parent', 'packet-mark'), $this->ItemsQueue, array(), true); 521 $Free = new SpeedLimitItem('free', $Main); 522 $Free->LimitIn = new SpeedLimit($FreeInetSpeed, $FreeInetSpeed, GetMarkByComment('free-in')); 523 $Free->LimitOut = new SpeedLimit($FreeInetSpeed, $FreeInetSpeed, GetMarkByComment('free-out')); 524 525 $this->BuildTree($this->System->Config['MainRouter']['DeviceId'], $UsersMaxSpeedIn); 526 $this->BuildQueueItems($this->System->Config['MainRouter']['DeviceId'], $Main); 527 528 echo($Main->Print()); 529 //print_r($Main->GetCommands()); 530 die(); 531 532 print_r($this->ItemsQueue); 533 //$Routerboard->ListUpdate($PathQueue, array('name', 'limit-at', 'max-limit', 534 // 'parent', 'packet-mark'), $this->ItemsQueue, array(), true); 367 535 } 368 536 } -
trunk/Packages/Common/Common.php
r816 r869 20 20 include_once(dirname(__FILE__).'/Table.php'); 21 21 include_once(dirname(__FILE__).'/Process.php'); 22 include_once(dirname(__FILE__).'/Generics.php'); 22 23 23 24 class PackageCommon … … 34 35 $this->Name = 'Common'; 35 36 $this->Version = '1.2'; 36 $this->ReleaseDate = strtotime('20 16-03-10');37 $this->ReleaseDate = strtotime('2020-03-29'); 37 38 $this->Creator = 'Chronos'; 38 39 $this->License = 'GNU/GPL'; 39 $this->Homepage = 'http ://svn.zdechov.net/svn/PHPlib/Common/';40 $this->Homepage = 'https://svn.zdechov.net/PHPlib/Common/'; 40 41 } 41 42 }
Note:
See TracChangeset
for help on using the changeset viewer.