Changeset 831
- Timestamp:
- May 1, 2016, 2:04:11 PM (9 years ago)
- Location:
- trunk
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Application/UpdateTrace.php
r829 r831 2021 2021 } 2022 2022 2023 /* 2024 function UpdateTo829($Manager) 2023 function UpdateTo831($Manager) 2025 2024 { 2026 2025 $Manager->Execute('ALTER TABLE `NetworkLinkType` '. … … 2029 2028 'ADD `FullDuplex` INT NOT NULL AFTER `MaxRealSpeed`, '. 2030 2029 'ADD `Color` VARCHAR(6) NOT NULL AFTER `FullDuplex`'); 2031 } 2032 */ 2030 2031 $Manager->Execute('UPDATE `Service` SET `InternetSpeedMin`=`InternetSpeedMin`*1000;'); 2032 $Manager->Execute('UPDATE `Service` SET `InternetSpeedMax`=`InternetSpeedMax`*1000;'); 2033 } 2033 2034 2034 2035 class Updates … … 2124 2125 817 => array('Revision' => 818, 'Function' => 'UpdateTo818'), 2125 2126 818 => array('Revision' => 824, 'Function' => 'UpdateTo824'), 2126 //824 => array('Revision' => 829, 'Function' => 'UpdateTo829'),2127 824 => array('Revision' => 831, 'Function' => 'UpdateTo831'), 2127 2128 )); 2128 2129 } -
trunk/Application/Version.php
r830 r831 1 1 <?php 2 2 3 $Revision = 83 0; // Subversion revision4 $DatabaseRevision = 8 24; // SQL structure revision5 $ReleaseTime = strtotime('2016-0 4-30');3 $Revision = 831; // Subversion revision 4 $DatabaseRevision = 831; // SQL structure revision 5 $ReleaseTime = strtotime('2016-05-01'); -
trunk/Modules/Customer/Customer.php
r817 r831 13 13 $this->Dependencies = array('User'); 14 14 } 15 15 16 16 function DoStart() 17 17 { … … 77 77 'SQL' => '(SELECT COUNT(*) FROM `ServiceCustomerRel` LEFT JOIN `Member` ON `Member`.`Id`=`ServiceCustomerRel`.`Customer` WHERE (`ServiceCustomerRel`.`Service`=#Id) AND (`Member`.`Blocked`=0))'), 78 78 'Public' => array('Type' => 'Boolean', 'Caption' => 'Veřejné', 'Default' => ''), 79 'InternetSpeedMin' => array('Type' => 'Integer', 'Caption' => 'Min. rychlost internetu', 'Default' => '0', 'Suffix' => ' kbit/s'),80 'InternetSpeedMax' => array('Type' => 'Integer', 'Caption' => 'Max. rychlost internetu', 'Default' => '0', 'Suffix' => ' kbit/s'),79 'InternetSpeedMin' => array('Type' => 'Integer', 'Caption' => 'Min. rychlost internetu', 'Default' => '0', 'Suffix' => 'bit/s'), 80 'InternetSpeedMax' => array('Type' => 'Integer', 'Caption' => 'Max. rychlost internetu', 'Default' => '0', 'Suffix' => 'bit/s'), 81 81 'UploadAsymmetry' => array('Type' => 'Integer', 'Caption' => 'Asymetrie odesílání', 'Default' => '1'), 82 82 'Memory' => array('Type' => 'Integer', 'Caption' => 'Paměť', 'Default' => '0', 'Suffix' => 'GB'), -
trunk/Modules/NetworkConfig/Generate.php
r817 r831 3 3 if(isset($_SERVER['REMOTE_ADDR'])) die(); 4 4 include_once(dirname(__FILE__).'/../../Application/System.php'); 5 $System = new System();5 $System = new Core(); 6 6 $System->ShowPage = false; 7 7 $System->Run(); -
trunk/Modules/NetworkConfigRouterOS/Generators/FirewallFilter.php
r781 r831 38 38 $Items[] = array('chain' => 'forward', 'out-interface' => $InetInterface, 'protocol' => 'tcp', 'dst-port' => 25, 'dst-address' => '82.119.226.113', 'action' => 'accept', 'comment' => 'smtp.svarko.cz'); 39 39 $Items[] = array('chain' => 'forward', 'out-interface' => $InetInterface, 'protocol' => 'tcp', 'dst-port' => 25, 'action' => 'drop', 'comment' => 'drop-rest-smtp'); 40 41 42 40 43 41 -
trunk/Modules/NetworkConfigRouterOS/Generators/Queue.php
r829 r831 4 4 { 5 5 var $UsedNames; 6 var $Devices; 7 var $QueueItems; 6 8 7 9 function CheckName($Name) … … 13 15 function Run() 14 16 { 15 //print_r($this->BuildTree($this->System->Config['MainRouter']['DeviceId'], 140 * 1000 * 1000));16 //die();17 18 17 $PathQueue = array('queue', 'tree'); 19 18 … … 53 52 { 54 53 $Service = $DbResult->fetch_array(); 55 $FreeInetSpeed = $Service['InternetSpeedMax'] * 1000;54 $FreeInetSpeed = $Service['InternetSpeedMax']; 56 55 } else $FreeInetSpeed = 0; 57 56 … … 62 61 $ItemsQueue[] = array('name' => 'main-in', 'limit-at' => $UsersMaxSpeedOut, 'max-limit' => $UsersMaxSpeedOut, 'parent' => 'global'); 63 62 64 // Divide rules by subnet number65 $DbResult = $this->Database->query('SELECT `Id`, `Name`, `AddressRange`, `Mask` FROM `NetworkSubnet`');66 63 // Slow free internet 67 64 $PacketMark = GetMarkByComment('free-out'); … … 71 68 72 69 // Process users 73 $DbResult = $this->Database->query('SELECT `Member`.*, `Subject`.`Name` FROM `Member` LEFT JOIN `Subject` ON `Subject`.`Id` = `Member`.`Subject` WHERE `Member`.`Blocked`=0'); 70 $DbResult = $this->Database->query('SELECT `Member`.*, `Subject`.`Name` FROM `Member` '. 71 'LEFT JOIN `Subject` ON `Subject`.`Id` = `Member`.`Subject` WHERE `Member`.`Blocked`=0'); 74 72 while($Member = $DbResult->fetch_assoc()) 75 73 { … … 84 82 echo('Služba '.$Service['Name'].': '); 85 83 $MemberName = RouterOSIdent($Member['Name'].'-'.$Member['Id'].'-'.$ServiceIndex); 86 $SpeedIn = round($Service['InternetSpeedMin'] / $InDivider) * 1000;87 $SpeedOut = round($Service['InternetSpeedMin'] / $OutDivider) * 1000;88 $UserMaxSpeedIn = round($Service['InternetSpeedMax'] / $InDivider) * 1000;89 $UserMaxSpeedOut = round($Service['InternetSpeedMax'] / $OutDivider) * 1000;84 $SpeedIn = round($Service['InternetSpeedMin'] / $InDivider); 85 $SpeedOut = round($Service['InternetSpeedMin'] / $OutDivider); 86 $UserMaxSpeedIn = round($Service['InternetSpeedMax'] / $InDivider); 87 $UserMaxSpeedOut = round($Service['InternetSpeedMax'] / $OutDivider); 90 88 $ItemsQueue[] = array('name' => $MemberName.'-out', 'limit-at' => $SpeedIn, 'max-limit' => $UserMaxSpeedIn, 'parent' => 'main-out'); 91 89 $ItemsQueue[] = array('name' => $MemberName.'-in', 'limit-at' => $SpeedOut, 'max-limit' => $UserMaxSpeedOut, 'parent' => 'main-in'); … … 117 115 $Name = RouterOSIdent($Name); 118 116 echo($Name.', '); 119 $IPParts = explode('.', $Interface['LocalIP']);120 $Subnet = $IPParts[2];121 117 $PacketMark = GetMarkByComment($Name.'-out'); 122 118 $ItemsQueue[] = array('name' => $Name.'-out', 'limit-at' => $HostSpeedIn, 'max-limit' => $UserMaxSpeedIn, 'parent' => $MemberName.'-out', 'packet-mark' => $PacketMark); … … 133 129 $Subnet['Name'] = RouterOSIdent('subnet-'.$Subnet['Name']); 134 130 echo($Subnet['Name'].', '); 135 $IPParts = explode('.', $Subnet['AddressRange']);136 $SubnetNumber = $IPParts[2];137 131 $PacketMark = GetMarkByComment($Subnet['Name'].'-out'); 138 132 $ItemsQueue[] = array('name' => $Subnet['Name'].'-out', 'limit-at' => $HostSpeedIn, 'max-limit' => $UserMaxSpeedIn, 'parent' => $MemberName.'-out', 'packet-mark' => $PacketMark); … … 151 145 } 152 146 147 function UpdateMinSpeed($DeviceId) 148 { 149 $MinSpeed = 0; 150 foreach($this->Devices[$DeviceId]['Childs'] as $DeviceChild) 151 { 152 $this->UpdateMinSpeed($DeviceChild); 153 $MinSpeed += $this->Devices[$DeviceChild]['MinSpeed']; 154 } 155 $this->Devices[$DeviceId]['MinSpeed'] = $MinSpeed; 156 if($this->Devices[$DeviceId]['DeviceCount'] > 0) 157 $this->Devices[$DeviceId]['MinSpeed'] += round($this->Devices[$DeviceId]['InternetSpeedMin'] / $this->Devices[$DeviceId]['DeviceCount']); 158 } 159 153 160 // Calculate maximum real speed available for each network device Start with main router and continue with adjecement nodes. 154 161 function BuildTree($RootDeviceId, $BaseSpeed) 155 162 { 156 163 // Load network devices 157 $Devices = array(); 158 $DbResult = $this->Database->query('SELECT `Name`,`Id` FROM `NetworkDevice`'); 164 $this->Devices = array(); 165 $DbResult = $this->Database->query('SELECT `NetworkDevice`.`Name`,`NetworkDevice`.`Id`, '. 166 '`Service`.`InternetSpeedMin`, `Service`.`InternetSpeedMax`, '. 167 '(SELECT COUNT(*) FROM `NetworkDevice` AS `T` WHERE `T`.`Service` = `NetworkDevice`.`Service`) AS `DeviceCount` FROM `NetworkDevice` '. 168 'LEFT JOIN `ServiceCustomerRel` ON `ServiceCustomerRel`.`Id`=`NetworkDevice`.`Service` '. 169 'LEFT JOIN `Service` ON `Service`.`Id` = `ServiceCustomerRel`.`Service`'); 159 170 while($Device = $DbResult->fetch_assoc()) 160 171 { … … 162 173 $Device['Calculated'] = false; 163 174 $Device['MaxSpeed'] = 0; 164 $Devices[$Device['Id']] = $Device; 175 $Device['MinSpeed'] = 0; 176 $Device['Childs'] = array(); 177 $Device['Parent'] = 0; 178 $Device['QueueName'] = ''; 179 $this->Devices[$Device['Id']] = $Device; 165 180 } 166 181 … … 172 187 $Interface['Links'] = array(); 173 188 $Interfaces[$Interface['Id']] = $Interface; 174 $ Devices[$Interface['Device']]['Interfaces'][] = $Interface['Id'];189 $this->Devices[$Interface['Device']]['Interfaces'][] = $Interface['Id']; 175 190 } 176 191 … … 187 202 } 188 203 204 // Calculate maximum speed for network devices 189 205 $DevicesToCheck = array($RootDeviceId); 190 $ Devices[$RootDeviceId]['MaxSpeed'] = $BaseSpeed;191 $ Devices[$RootDeviceId]['Calculated'] = true;206 $this->Devices[$RootDeviceId]['MaxSpeed'] = $BaseSpeed; 207 $this->Devices[$RootDeviceId]['Calculated'] = true; 192 208 193 209 while(count($DevicesToCheck) > 0) 194 210 { 195 echo('Pass'."\n");211 //echo('Pass'."\n"); 196 212 $NewDevicesToCheck = array(); 197 213 foreach($DevicesToCheck as $DeviceId) 198 214 { 199 echo($Devices[$DeviceId]['Name'].': ');200 foreach($ Devices[$DeviceId]['Interfaces'] as $InterfaceId)215 //echo($this->Devices[$DeviceId]['Name'].': '); 216 foreach($this->Devices[$DeviceId]['Interfaces'] as $InterfaceId) 201 217 { 202 218 foreach($Interfaces[$InterfaceId]['Links'] as $LinkId) … … 207 223 208 224 $Device2Id = $Interfaces[$Interface2Id]['Device']; 209 if($ Devices[$Device2Id]['Calculated'] == false)225 if($this->Devices[$Device2Id]['Calculated'] == false) 210 226 { 211 $ Devices[$Device2Id]['Calculated'] = true;212 $NewMaxSpeed = $ Devices[$DeviceId]['MaxSpeed'];227 $this->Devices[$Device2Id]['Calculated'] = true; 228 $NewMaxSpeed = $this->Devices[$DeviceId]['MaxSpeed']; 213 229 if($NewMaxSpeed > $Link['MaxRealSpeed']) 214 230 $NewMaxSpeed = $Link['MaxRealSpeed']; 215 echo($Devices[$Device2Id]['Name'].' '.$Device2Id.', '); 216 $Devices[$Device2Id]['MaxSpeed'] = $NewMaxSpeed; 217 echo($NewMaxSpeed.", ".count($NewDevicesToCheck).' '); 231 //echo($this->Devices[$Device2Id]['Name'].' '.$Device2Id.', '); 232 $this->Devices[$Device2Id]['MaxSpeed'] = $NewMaxSpeed; 233 // Set nodes tree relation 234 $this->Devices[$Device2Id]['Parent'] = $DeviceId; 235 $this->Devices[$DeviceId]['Childs'][] = $Device2Id; 236 //echo($NewMaxSpeed.", ".count($NewDevicesToCheck).' '); 218 237 $NewDevicesToCheck[] = $Device2Id; 219 238 } 220 239 } 221 240 } 222 echo("\n");241 //echo("\n"); 223 242 } 224 243 $DevicesToCheck = $NewDevicesToCheck; 225 244 } 226 //print_r($Devices); 245 246 // Calculate maximum speed for network devices 247 $this->UpdateMinSpeed($RootDeviceId); 248 249 //print_r($this->Devices); 227 250 228 251 echo('Not linked network devices: '); 229 foreach($ Devices as $Device)252 foreach($this->Devices as $Device) 230 253 { 231 254 if($Device['MaxSpeed'] == 0) echo($Device['Name'].', '); 232 255 } 233 256 echo("\n"); 234 235 $Tree = array(); 236 return($Tree); 257 } 258 259 function BuildQueueItems($DeviceId) 260 { 261 $Device = $this->Devices[$DeviceId]; 262 263 // 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'); 282 283 // Interfaces 284 $DbResult3 = $this->Database->select('NetworkInterface', '*', '`Device` = '.$DeviceId.' AND `LocalIP` != ""'); 285 $IntCount = $DbResult3->num_rows; 286 while($Interface = $DbResult3->fetch_assoc()) 287 { 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'); 303 } 304 305 // Process childs 306 foreach($Device['Childs'] as $DeviceChild) 307 { 308 $this->BuildQueueItems($DeviceChild); 309 } 310 } 311 312 function RunTopology() 313 { 314 $PathQueue = array('queue', 'tree'); 315 316 $Routerboard = new Routerboard(); 317 $Routerboard->UserName = $this->System->Config['MainRouter']['UserName']; 318 $Routerboard->Timeout = $this->System->Config['MainRouter']['ConnectTimeout']; 319 $Routerboard->HostName = $this->System->Config['MainRouter']['HostName']; 320 $Routerboard->Debug = true; 321 322 $this->UsedNames = array(); 323 324 $Finance = &$this->System->Modules['Finance']; 325 $Finance->LoadMonthParameters(0); 326 327 $InDivider = 1; 328 $OutDivider = 1; 329 $TotalMaxSpeedIn = round($Finance->RealMaxSpeed / $InDivider) * 1000; 330 $TotalMaxSpeedOut = round($Finance->RealMaxSpeed / $OutDivider) * 1000; 331 $UsersMaxSpeedIn = round($Finance->MaxSpeed / $InDivider) * 1000; 332 $UsersMaxSpeedOut = round($Finance->MaxSpeed / $OutDivider) * 1000; 333 $VoipMaxSpeedIn = $TotalMaxSpeedIn - 136; 334 $VoipMaxSpeedOut = $TotalMaxSpeedOut - 136; 335 $VoipSpeedIn = 100; //$SpeedReserve; 336 $VoipSpeedOut = 100; //$SpeedReserve; 337 $OutInterface = 'eth1'; 338 $InInterface = 'ifb0'; 339 $InetInterface = $this->System->Config['MainRouter']['InetInterface']; 340 341 $DbResult = $this->Database->select('Service', '*', '(`ChangeAction` IS NULL) AND (`Id`='.TARIFF_FREE.')'); 342 if($DbResult->num_rows == 1) 343 { 344 $Service = $DbResult->fetch_array(); 345 $FreeInetSpeed = $Service['InternetSpeedMax']; 346 } else $FreeInetSpeed = 0; 347 348 $this->ItemsQueue = array(); 349 350 // 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'); 353 354 // 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); 237 367 } 238 368 }
Note:
See TracChangeset
for help on using the changeset viewer.