1 | <?php
|
---|
2 | if(isset($_SERVER['REMOTE_ADDR'])) die();
|
---|
3 |
|
---|
4 | $Enabled = 1;
|
---|
5 | $ClassesEnabled = 1;
|
---|
6 | $SessionDisable = true;
|
---|
7 | include('../../Common/Global.php');
|
---|
8 | include('../routerboard.php');
|
---|
9 | include('common.php');
|
---|
10 | $PathQueue = array('queue', 'tree');
|
---|
11 |
|
---|
12 | $Routerboard = new Routerboard();
|
---|
13 | $Routerboard->UserName = $Config['MainRouter']['UserName'];
|
---|
14 | $Routerboard->Timeout = $Config['MainRouter']['ConnectTimeout'];
|
---|
15 | $Routerboard->HostName = $Config['MainRouter']['HostName'];
|
---|
16 | $Routerboard->Debug = true;
|
---|
17 |
|
---|
18 | $Finance = &$System->Modules['Finance'];
|
---|
19 | $Finance->LoadMonthParameters(0);
|
---|
20 |
|
---|
21 | // Generate traffic shaping rules
|
---|
22 | //$TotalMaxSpeedIn = 4048; //$RealMaxSpeed; //1536;
|
---|
23 | //TotalMaxSpeedOut = 3048; //$RealMaxSpeed; //1536;
|
---|
24 | //$UsersMaxSpeedIn = 1900; //$MaxSpeed;
|
---|
25 | //$UsersMaxSpeedOut = 1900; //$MaxSpeed;
|
---|
26 |
|
---|
27 | $InDivider = 1;
|
---|
28 | $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;
|
---|
33 | $VoipMaxSpeedIn = $TotalMaxSpeedIn - 136;
|
---|
34 | $VoipMaxSpeedOut = $TotalMaxSpeedOut - 136;
|
---|
35 | $VoipSpeedIn = 100; //$SpeedReserve;
|
---|
36 | $VoipSpeedOut = 100; //$SpeedReserve;
|
---|
37 | $OutInterface = 'eth1';
|
---|
38 | $InInterface = 'ifb0';
|
---|
39 | $InetInterface = $Config['MainRouter']['InetInterface'];
|
---|
40 | $FreeInetSpeed = $Finance->Tariffs[TARIFF_FREE]['InternetSpeedMax'];
|
---|
41 |
|
---|
42 | $ItemsQueue = array();
|
---|
43 |
|
---|
44 | // Root of tree and main limit
|
---|
45 | $ItemsQueue[] = array('name' => 'main-out', 'limit-at' => $UsersMaxSpeedIn, 'max-limit' => $UsersMaxSpeedIn, 'parent' => 'global-out');
|
---|
46 | $ItemsQueue[] = array('name' => 'main-in', 'limit-at' => $UsersMaxSpeedOut, 'max-limit' => $UsersMaxSpeedOut, 'parent' => 'global-out');
|
---|
47 |
|
---|
48 | // Divide rules by subnet number
|
---|
49 | $DbResult = $Database->query('SELECT `Id`, `Name`, `AddressRange`, `Mask` FROM `NetworkSubnet`');
|
---|
50 | // Slow free internet
|
---|
51 | $PacketMark = GetMarkByComment('free-out');
|
---|
52 | $ItemsQueue[] = array('name' => 'free-out', 'limit-at' => $FreeInetSpeed, 'max-limit' => $FreeInetSpeed, 'parent' => 'main-out', 'packet-mark' => $PacketMark);
|
---|
53 | $PacketMark = GetMarkByComment('free-in');
|
---|
54 | $ItemsQueue[] = array('name' => 'free-in', 'limit-at' => $FreeInetSpeed, 'max-limit' => $FreeInetSpeed, 'parent' => 'main-in', 'packet-mark' => $PacketMark);
|
---|
55 |
|
---|
56 | // Process users
|
---|
57 | $DbResult = $Database->query('SELECT `Member`.*, `Subject`.`Name` FROM `Member` LEFT JOIN `Subject` ON `Subject`.`Id` = `Member`.`Subject`');
|
---|
58 | while($Member = $DbResult->fetch_assoc())
|
---|
59 | {
|
---|
60 | $Member['Name'] = RouterOSIdent($Member['Name'].'-'.$Member['Id'] );
|
---|
61 |
|
---|
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');
|
---|
70 |
|
---|
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;
|
---|
82 | }
|
---|
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");
|
---|
116 | }
|
---|
117 |
|
---|
118 | //print_r($ItemsQueue);
|
---|
119 | $Routerboard->ListUpdate($PathQueue, array('name', 'limit-at', 'max-limit', 'parent', 'packet-mark'), $ItemsQueue, array(), true);
|
---|
120 |
|
---|
121 | ?>
|
---|