Changeset 873 for trunk/Modules/NetworkConfigLinux/Generators
- Timestamp:
- Apr 6, 2020, 11:17:40 PM (5 years ago)
- Location:
- trunk/Modules/NetworkConfigLinux/Generators
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Modules/NetworkConfigLinux/Generators/CheckPorts.php
r819 r873 7 7 $Timeout = 1; 8 8 $State = 0; 9 if ($Protocol == 'tcp') $Prefix = '';10 else if ($Protocol == 'udp') $Prefix = 'udp://';9 if ($Protocol == 'tcp') $Prefix = ''; 10 else if ($Protocol == 'udp') $Prefix = 'udp://'; 11 11 else throw new Exception('Unsupported protocol "'.$Protocol.'"'); 12 if ($Socket = @fsockopen($Prefix.$IP, $Port, $ErrorNumber, $ErrorString, $Timeout))12 if ($Socket = @fsockopen($Prefix.$IP, $Port, $ErrorNumber, $ErrorString, $Timeout)) 13 13 { 14 14 fclose($Socket); 15 15 $State = 1; 16 16 } 17 return ($State);17 return ($State); 18 18 } 19 19 … … 29 29 'LEFT JOIN `NetworkInterface` ON `NetworkInterface`.`Id`=`NetworkPort`.`Interface` '. 30 30 'WHERE (`NetworkPort`.`Enabled`=1) AND (`NetworkInterface`.`LocalIP` !="")'); 31 while ($DbRow = $DbResult->fetch_assoc())31 while ($DbRow = $DbResult->fetch_assoc()) 32 32 $Ports[$DbRow['Id']] = $DbRow; 33 33 34 foreach ($Ports as $Index => $Port)34 foreach ($Ports as $Index => $Port) 35 35 { 36 if ($Port['Protocol'] == 0) $Port['Protocol'] = 'tcp';37 if ($Port['Protocol'] == 1) $Port['Protocol'] = 'udp';36 if ($Port['Protocol'] == 0) $Port['Protocol'] = 'tcp'; 37 if ($Port['Protocol'] == 1) $Port['Protocol'] = 'udp'; 38 38 $Port['NewOnline'] = $this->CheckPortStatus($Port['LocalIP'], $Port['Number'], $Port['Protocol']); 39 39 40 40 // Update last online time if still online 41 if ($Port['NewOnline'])41 if ($Port['NewOnline']) 42 42 { 43 43 $DbResult = $this->Database->update('NetworkPort', '`Id` = "'.$Port['Id'].'"', … … 46 46 47 47 // Update UpDown table 48 if ($Port['Online'] != $Port['NewOnline'])48 if ($Port['Online'] != $Port['NewOnline']) 49 49 { 50 50 // Online state changed … … 65 65 $DbResult = $this->Database->select('NetworkPort', '*', '(`Online` = 1) AND '. 66 66 '(`LastOnline` < "'.TimeToMysqlDateTime($StartTime).'")'); 67 while ($DbRow = $DbResult->fetch_assoc())67 while ($DbRow = $DbResult->fetch_assoc()) 68 68 { 69 69 echo('Port '.$DbRow['Number'].' online but time not updated.'."\n"); … … 71 71 $DbResult = $this->Database->select('NetworkPort', '*', '(`Online` = 0) AND '. 72 72 '(`LastOnline` >= "'.TimeToMysqlDateTime($StartTime).'")'); 73 while ($DbRow = $DbResult->fetch_assoc())73 while ($DbRow = $DbResult->fetch_assoc()) 74 74 { 75 75 echo('Port '.$DbRow['Number'].' not online but time updated.'."\n"); -
trunk/Modules/NetworkConfigLinux/Generators/DHCP.php
r790 r873 1 1 <?php 2 2 3 if (isset($_SERVER['REMOTE_ADDR'])) die();3 if (isset($_SERVER['REMOTE_ADDR'])) die(); 4 4 /* 5 5 include_once('../../global.php'); … … 23 23 'option netbios-scope "";'."\n". 24 24 "server-identifier 192.168.0.1;\n\n"); 25 for ($i = 0; $i <= $MaxSubnet; $i++)25 for ($i = 0; $i <= $MaxSubnet; $i++) 26 26 { 27 27 fputs($File, "subnet 192.168.".$i.".0 netmask 255.255.255.0 {\n". … … 30 30 " option routers 192.168.".$i.".1;\n"); 31 31 $DbResult = $Database->select('hosts', '*', "IP LIKE '192.168.".$i."%' ORDER BY IP"); 32 while ($Row = $DbResult->fetch_array())32 while ($Row = $DbResult->fetch_array()) 33 33 { 34 34 $Data = $Row['name']; 35 if (strlen($Data) < 9) $Data .= "\t";35 if (strlen($Data) < 9) $Data .= "\t"; 36 36 fputs($File, " host ".$Data."\t{ fixed-address ".$Row['IP'].";\thardware ethernet ".$Row['MAC']."; }\n"); 37 37 } -
trunk/Modules/NetworkConfigLinux/Generators/DNS.php
r854 r873 18 18 "\t\t\t".$DNS['Minimum']."\t; minimum\n". 19 19 "\t\t\t)\n"; 20 foreach ($DNS['NameServer'] as $NameServer)20 foreach ($DNS['NameServer'] as $NameServer) 21 21 { 22 22 $Output .= "\t\tIN\tNS\t".strtolower($NameServer).".\n"; … … 26 26 // Mail server records 27 27 $Priority = 10; 28 foreach ($DNS['MailServer'] as $MailServer)28 foreach ($DNS['MailServer'] as $MailServer) 29 29 { 30 30 $Output .="\t\t\tMX\t".$Priority." ".strtolower($MailServer).".\n"; … … 34 34 $DNS['Domain'].".\tIN\tTXT\t\"v=spf1 mx -all\"\n". 35 35 $DNS['Domain'].".\tIN\tSPF\t\"v=spf1 mx -all\"\n"; 36 foreach ($DNS['MailServer'] as $MailServer)36 foreach ($DNS['MailServer'] as $MailServer) 37 37 { 38 38 $Output .= $MailServer.".\tIN\tTXT\t\"v=spf1 a -all\"\n". … … 45 45 46 46 // IPv4 host list 47 foreach ($DNS['Host'] as $Host)48 { 49 if (strlen($Host['Name']) < 8) $Host['Name'] .= "\t";47 foreach ($DNS['Host'] as $Host) 48 { 49 if (strlen($Host['Name']) < 8) $Host['Name'] .= "\t"; 50 50 $Output .= strtolower($Host['Name'])."\tIN\tA\t".$Host['Address']."\n"; 51 51 } 52 52 53 53 // IPv6 host list 54 foreach ($DNS['Host'] as $Host)55 { 56 if (strlen($Host['Name']) < 8) $Host['Name'] .= "\t";57 if (array_key_exists('IPv6', $Host) and ($Host['IPv6'] != ''))54 foreach ($DNS['Host'] as $Host) 55 { 56 if (strlen($Host['Name']) < 8) $Host['Name'] .= "\t"; 57 if (array_key_exists('IPv6', $Host) and ($Host['IPv6'] != '')) 58 58 $Output .= strtolower($Host['Name'])."\tIN\tAAAA\t".$Host['IPv6']."\n"; 59 59 } 60 60 61 61 // Alias list 62 foreach ($DNS['Alias'] as $Alias)63 { 64 if (strlen($Alias['Name']) < 8) $Alias['Name'] .= "\t";62 foreach ($DNS['Alias'] as $Alias) 63 { 64 if (strlen($Alias['Name']) < 8) $Alias['Name'] .= "\t"; 65 65 $Output .= strtolower($Alias['Name'])."\tIN\tCNAME\t".strtolower($Alias['Target'])."\n"; 66 66 } … … 71 71 72 72 // Generate reverse DNS records 73 foreach ($DNS['Network'] as $Network)73 foreach ($DNS['Network'] as $Network) 74 74 { 75 75 $Parts = explode('.', $Network); … … 83 83 "\t\t\t\t".$DNS['Minimum']."\t; minimum\n". 84 84 "\t\t\t\t)\n"; 85 foreach ($DNS['ReverseNameServer'] as $NameServer)85 foreach ($DNS['ReverseNameServer'] as $NameServer) 86 86 { 87 if (substr($NameServer, -strlen($DNS['Domain'])) == $DNS['Domain'])87 if (substr($NameServer, -strlen($DNS['Domain'])) == $DNS['Domain']) 88 88 $Output .= "@\tIN\tNS\t".$NameServer.".\n"; 89 89 else $Output .= "\tIN\tNS\t".$NameServer.".\n"; 90 90 } 91 foreach ($DNS['Host'] as $Host)92 if (substr($Host['Address'], 0, strlen($Network)) == $Network)91 foreach ($DNS['Host'] as $Host) 92 if (substr($Host['Address'], 0, strlen($Network)) == $Network) 93 93 { 94 94 $AddressParts = explode('.', $Host['Address']); … … 103 103 104 104 // Generate reverse DNS IPv6 records 105 foreach ($DNS['IPv6Network'] as $Network)105 foreach ($DNS['IPv6Network'] as $Network) 106 106 { 107 107 $Parts = explode('/', $Network); … … 117 117 "\t\t\t\t".$DNS['Minimum']."\t; minimum\n". 118 118 "\t\t\t\t)\n"; 119 foreach ($DNS['ReverseNameServer'] as $NameServer)119 foreach ($DNS['ReverseNameServer'] as $NameServer) 120 120 { 121 if (substr($NameServer, -strlen($DNS['Domain'])) == $DNS['Domain'])121 if (substr($NameServer, -strlen($DNS['Domain'])) == $DNS['Domain']) 122 122 $Output .= "@\tIN\tNS\t".$NameServer.".\n"; 123 123 else $Output .= "\tIN\tNS\t".$NameServer.".\n"; 124 124 } 125 foreach ($DNS['Host'] as $Host)126 if (array_key_exists('IPv6', $Host) and ($Host['IPv6'] != ''))125 foreach ($DNS['Host'] as $Host) 126 if (array_key_exists('IPv6', $Host) and ($Host['IPv6'] != '')) 127 127 { 128 128 $Addr = new NetworkAddressIPv6(); … … 161 161 $BaseDir = '/var/cache/bind'; 162 162 //$BaseDir = '/home/chronos/Projekty/centrala/trunk/var/named'; 163 if (!file_exists($BaseDir)) die('Base directory "'.$BaseDir.'" not exists.');163 if (!file_exists($BaseDir)) die('Base directory "'.$BaseDir.'" not exists.'); 164 164 $MailServer = 'centrala'; 165 165 … … 193 193 'JOIN `NetworkDevice` ON `NetworkDevice`.`Id` = `NetworkInterface`.`Device` '. 194 194 'WHERE (`NetworkInterface`.`LocalIP` <> "") AND (`NetworkDevice`.`Used` = 1)'); 195 while ($Interface = $DbResult->fetch_assoc())196 { 197 $Name = $Interface['DeviceName']; 198 if ($Interface['Name'] != '') $Name .= '-'.$Interface['Name'];195 while ($Interface = $DbResult->fetch_assoc()) 196 { 197 $Name = $Interface['DeviceName']; 198 if ($Interface['Name'] != '') $Name .= '-'.$Interface['Name']; 199 199 $LocalDNS['Host'][] = array('Name' => $Name, 'Address' => $Interface['LocalIP'], 200 200 'IPv6' => $Interface['IPv6']); … … 205 205 'JOIN `NetworkDevice` ON `NetworkDevice`.`Id` = `NetworkInterface`.`Device` '. 206 206 'WHERE (`NetworkInterface`.`ExternalIP` <> "") AND (`NetworkDevice`.`Used` = 1)'); 207 while ($Interface = $DbResult->fetch_assoc())208 { 209 $Name = $Interface['DeviceName']; 210 if ($Interface['Name'] != '') $Name .= '-'.$Interface['Name'];207 while ($Interface = $DbResult->fetch_assoc()) 208 { 209 $Name = $Interface['DeviceName']; 210 if ($Interface['Name'] != '') $Name .= '-'.$Interface['Name']; 211 211 $LocalDNS['Host'][] = array('Name' => $Name.'-ext', 'Address' => $Interface['ExternalIP']); 212 212 } … … 216 216 $DbResult = $Database->query('SELECT NetworkInterface.*, NetworkDevice.Name AS DeviceName FROM NetworkInterface '. 217 217 'JOIN NetworkDevice ON NetworkDevice.Id = NetworkInterface.Device WHERE NetworkInterface.CZFreeIP <> ""'); 218 while ($Interface = $DbResult->fetch_assoc())218 while ($Interface = $DbResult->fetch_assoc()) 219 219 { 220 220 $Name = $Interface['DeviceName']; 221 if ($Interface['Name'] != '') $Name .= '-'.$Interface['Name'];221 if ($Interface['Name'] != '') $Name .= '-'.$Interface['Name']; 222 222 $LocalDNS['Host'][] = array('Name' => $Name.'-czfree', 'Address' => $Interface['CZFreeIP']); 223 223 } … … 226 226 // Domain aliases 227 227 $DbResult = $this->Database->select('NetworkDomainAlias', '*'); 228 while ($Alias = $DbResult->fetch_assoc())228 while ($Alias = $DbResult->fetch_assoc()) 229 229 { 230 230 $LocalDNS['Alias'][] = array('Name' => $Alias['Name'], 'Target' => $Alias['Target']); … … 257 257 'JOIN `NetworkDevice` ON `NetworkDevice`.`Id` = `NetworkInterface`.`Device` WHERE '. 258 258 '(`NetworkInterface`.`ExternalIP` != "") AND (`NetworkDevice`.`Used` = 1)'); 259 while ($Interface = $DbResult->fetch_assoc())260 { 261 $Name = $Interface['DeviceName']; 262 if ($Interface['Name'] != '') $Name .= '-'.$Interface['Name'];259 while ($Interface = $DbResult->fetch_assoc()) 260 { 261 $Name = $Interface['DeviceName']; 262 if ($Interface['Name'] != '') $Name .= '-'.$Interface['Name']; 263 263 $ExternalDNS['Host'][] = array('Name' => $Name, 'Address' => $Interface['ExternalIP'], 264 264 'IPv6' => $Interface['IPv6']); … … 268 268 $DbResult = $this->Database->query('SELECT `NetworkDomainAlias`.* FROM `NetworkDomainAlias`'); 269 269 // JOIN `NetworkDevice` ON NetworkDomainAlias.Target LIKE NetworkDevice.Name AND NetworkInterface.ExternalIP != ""'); 270 while ($Alias = $DbResult->fetch_assoc())270 while ($Alias = $DbResult->fetch_assoc()) 271 271 { 272 272 $ExternalDNS['Alias'][] = array('Name' => $Alias['Name'], 'Target' => $Alias['Target']); … … 302 302 'JOIN `NetworkDevice` ON `NetworkDevice`.`Id` = `NetworkInterface`.`Device` '. 303 303 'WHERE (`NetworkInterface`.`LocalIP` != "") AND (`NetworkDevice`.`Used` = 1)'); 304 while ($Interface = $DbResult->fetch_assoc())305 { 306 $Name = $Interface['DeviceName']; 307 if ($Interface['Name'] != '') $Name .= '-'.$Interface['Name'];304 while ($Interface = $DbResult->fetch_assoc()) 305 { 306 $Name = $Interface['DeviceName']; 307 if ($Interface['Name'] != '') $Name .= '-'.$Interface['Name']; 308 308 $CZFreeDNS['Host'][] = array('Name' => $Name, 'Address' => $Interface['LocalIP']); 309 309 } … … 312 312 $DbResult = $this->Database->query('SELECT `NetworkDomainAlias`.* FROM `NetworkDomainAlias`'); 313 313 // JOIN `hosts` ON NetworkDomainAlias.Target LIKE hosts.name AND hosts.czfree_ip != ""'); 314 while ($Alias = $DbResult->fetch_assoc())314 while ($Alias = $DbResult->fetch_assoc()) 315 315 { 316 316 $CZFreeDNS['Alias'][] = array('Name' => $Alias['Name'], 'Target' => $Alias['Target']); … … 344 344 $DbResult = $this->Database->query('SELECT `NetworkInterface`.*, `NetworkDevice`.`Name` AS `DeviceName` FROM `NetworkInterface` '. 345 345 'JOIN `NetworkDevice` ON `NetworkDevice`.`Id` = `NetworkInterface`.`Device` WHERE `NetworkInterface`.`LocalIP` != ""'); 346 while ($Interface = $DbResult->fetch_assoc())347 { 348 $Name = $Interface['DeviceName']; 349 if ($Interface['Name'] != '') $Name .= '-'.$Interface['Name'];346 while ($Interface = $DbResult->fetch_assoc()) 347 { 348 $Name = $Interface['DeviceName']; 349 if ($Interface['Name'] != '') $Name .= '-'.$Interface['Name']; 350 350 // $CZFreeLocalDNS['Host'][] = array('Name' => $Name.'-czfree', 'Address' => $Interface['LocalIP']); 351 351 $CZFreeLocalDNS['Host'][] = array('Name' => $Name, 'Address' => $Interface['LocalIP']); … … 355 355 $DbResult = $this->Database->query('SELECT `NetworkDomainAlias`.* FROM `NetworkDomainAlias`'); 356 356 // JOIN `hosts` ON NetworkDomainAlias.Target LIKE hosts.name AND hosts.czfree_ip != ""'); 357 while ($Alias = $DbResult->fetch_assoc())357 while ($Alias = $DbResult->fetch_assoc()) 358 358 { 359 359 $CZFreeLocalDNS['Alias'][] = array('Name' => $Alias['Name'], 'Target' => $Alias['Target']); -
trunk/Modules/NetworkConfigLinux/Generators/IPTables.php
r790 r873 1 1 <?php 2 if (isset($_SERVER['REMOTE_ADDR'])) die();2 if (isset($_SERVER['REMOTE_ADDR'])) die(); 3 3 include_once('../../../Common/Global.php'); 4 4 … … 14 14 // Blocking according IP address 15 15 $DbResult = $Database->select('users', '*', 'inet = 0'); 16 while ($User = $DbResult->fetch_array())16 while ($User = $DbResult->fetch_array()) 17 17 { 18 18 $DbResult2 = $Database->select('hosts', '*', "block<2 AND MAC!='' AND user=".$User['id']); 19 while ($Row = $DbResult2->fetch_array())19 while ($Row = $DbResult2->fetch_array()) 20 20 { 21 21 exec('/sbin/iptables -t nat -A Block -s '.$Row['IP'].' -j Local'); … … 23 23 } 24 24 $DbResult = $Database->select('users', '*', 'inet = 1'); 25 while ($User = $DbResult->fetch_array())25 while ($User = $DbResult->fetch_array()) 26 26 { 27 27 $DbResult2 = $Database->select('hosts','*',"block<2 AND MAC!='' AND vpn=1 AND user=".$User['id']); 28 while ($Row = $DbResult2->fetch_array())28 while ($Row = $DbResult2->fetch_array()) 29 29 { 30 30 exec('/sbin/iptables -t nat -A Block -s '.$Row['IP'].' -j Local'); … … 36 36 // Blocking according MAC address 37 37 $DbResult = $Database->select('users', '*'); 38 while ($User = $DbResult->fetch_array())38 while ($User = $DbResult->fetch_array()) 39 39 { 40 40 //echo($User['fullname']."\n"); 41 41 $DbResult2 = $Database->select('hosts', '*', '(block < 2) AND (MAC != "") AND (user='.$User['id'].') AND (IP != external_ip) ORDER BY id DESC'); 42 while ($Row = $DbResult2->fetch_array())42 while ($Row = $DbResult2->fetch_array()) 43 43 { 44 44 //echo(' '.$Row['name']." ".$Row['MAC']." "); 45 if ($User['inet'] == 0)45 if ($User['inet'] == 0) 46 46 { 47 //if (($Row['block'] == 0) and ($Row['type'] == 1)) exec('/sbin/iptables -t nat -A Block -m mac --mac-source '.$Row['MAC']." -j Proxy");47 //if (($Row['block'] == 0) and ($Row['type'] == 1)) exec('/sbin/iptables -t nat -A Block -m mac --mac-source '.$Row['MAC']." -j Proxy"); 48 48 // else exec('/sbin/iptables -t nat -A Block -m mac --mac-source '.$Row['MAC']." -j Local"); 49 49 } else { 50 if ($Row['vpn'] == 0)50 if ($Row['vpn'] == 0) 51 51 { 52 52 $CZFreeLocalIP = $Row['IP']; 53 53 //echo($Row['external_ip']."\n"); 54 //if ($Row['name'] == 'TBC')54 //if ($Row['name'] == 'TBC') 55 55 //{ 56 56 // exec('/sbin/iptables -t nat -A PreroutingDNAT -m tcp -p tcp --dport 3724 -d '.$Row['external_ip'].' -j DNAT --to-destination '.$Row['IP'].':3725'); 57 57 // exec('/sbin/iptables -t nat -A POSTROUTING -m tcp -p tcp -s '.$Row['IP'].' --sport 3725 -o '.$InetInterface.' -j SNAT --to-source '.$Row['external_ip'].':3724'); 58 58 //} 59 if (strtolower($Row['name']) != 'gate')59 if (strtolower($Row['name']) != 'gate') 60 60 { 61 if ($Row['external_ip'] != '')61 if ($Row['external_ip'] != '') 62 62 { 63 63 echo($Row['name'].'='.$Row['external_ip']."\n"); … … 75 75 //echo('vpn'); 76 76 //exec('/sbin/iptables -t nat -A PreroutingDNAT -s '.$Row['IP'].' -p udp -m udp --dport 55556 -j DROP'); 77 if ($Row['external_ip'] != '') exec('/sbin/iptables -t nat -A PreroutingDNAT -d '.$Row['external_ip'].' -j ACCEPT');77 if ($Row['external_ip'] != '') exec('/sbin/iptables -t nat -A PreroutingDNAT -d '.$Row['external_ip'].' -j ACCEPT'); 78 78 exec('/sbin/iptables -t nat -A Block -s '.ToVpnIp($Row)." -j Proxy"); 79 79 80 //if ($Row['vpn'] == 1)80 //if ($Row['vpn'] == 1) 81 81 //{ 82 82 //exec('/sbin/iptables -t nat -A Block -m mac --mac-source '.$Row['MAC']." -j Local"); 83 //} else if ($Row['vpn'] == 2) exec('/sbin/iptables -t nat -A Block -m mac --mac-source '.$Row['MAC']." -j Proxy");83 //} else if ($Row['vpn'] == 2) exec('/sbin/iptables -t nat -A Block -m mac --mac-source '.$Row['MAC']." -j Proxy"); 84 84 } 85 if ($Row['czfree_ip'] != '')85 if ($Row['czfree_ip'] != '') 86 86 { 87 87 // CZFree -
trunk/Modules/NetworkConfigLinux/Generators/Latency.php
r852 r873 14 14 'FROM `NetworkInterface` '. 15 15 'WHERE (`NetworkInterface`.`Enabled`=1) AND (`NetworkInterface`.`LocalIP` !="")'); 16 while ($DbRow = $DbResult->fetch_assoc())16 while ($DbRow = $DbResult->fetch_assoc()) 17 17 { 18 18 $Hosts[] = $DbRow['LocalIP']; … … 23 23 24 24 $Queries = array(); 25 foreach ($Output as $Index => $Line)25 foreach ($Output as $Index => $Line) 26 26 { 27 27 $IP = substr($Line, 0, strPos($Line, ' ')); -
trunk/Modules/NetworkConfigLinux/Generators/NAT.php
r790 r873 1 1 <?php 2 if (isset($_SERVER['REMOTE_ADDR'])) die();2 if (isset($_SERVER['REMOTE_ADDR'])) die(); 3 3 include_once('../../../Common/Global.php'); 4 4 … … 14 14 // Blocking according IP address 15 15 $DbResult = $Database->select('users', '*', 'inet = 0'); 16 while ($User = $DbResult->fetch_array())16 while ($User = $DbResult->fetch_array()) 17 17 { 18 18 $DbResult2 = $Database->select('hosts', '*', "block<2 AND MAC!='' AND user=".$User['id']); 19 while ($Row = $DbResult2->fetch_array())19 while ($Row = $DbResult2->fetch_array()) 20 20 { 21 21 exec('/sbin/iptables -t nat -A Block -s '.$Row['IP'].' -j Local'); … … 23 23 } 24 24 $DbResult = $Database->select('users', '*', 'inet = 1'); 25 while ($User = $DbResult->fetch_array())25 while ($User = $DbResult->fetch_array()) 26 26 { 27 27 $DbResult2 = $Database->select('hosts','*',"block<2 AND MAC!='' AND vpn=1 AND user=".$User['id']); 28 while ($Row = $DbResult2->fetch_array())28 while ($Row = $DbResult2->fetch_array()) 29 29 { 30 30 exec('/sbin/iptables -t nat -A Block -s '.$Row['IP'].' -j Local'); … … 36 36 // Blocking according MAC address 37 37 $DbResult = $Database->select('users', '*'); 38 while ($User = $DbResult->fetch_array())38 while ($User = $DbResult->fetch_array()) 39 39 { 40 40 //echo($User['fullname']."\n"); 41 41 $DbResult2 = $Database->select('hosts','*','block<2 AND MAC!="" AND user='.$User['id'].' ORDER BY id DESC'); 42 while ($Row = $DbResult2->fetch_array())42 while ($Row = $DbResult2->fetch_array()) 43 43 { 44 44 //echo(' '.$Row['name']." ".$Row['MAC']." "); 45 if ($User['inet'] == 0)45 if ($User['inet'] == 0) 46 46 { 47 //if (($Row['block'] == 0) and ($Row['type'] == 1)) exec('/sbin/iptables -t nat -A Block -m mac --mac-source '.$Row['MAC']." -j Proxy");47 //if (($Row['block'] == 0) and ($Row['type'] == 1)) exec('/sbin/iptables -t nat -A Block -m mac --mac-source '.$Row['MAC']." -j Proxy"); 48 48 // else exec('/sbin/iptables -t nat -A Block -m mac --mac-source '.$Row['MAC']." -j Local"); 49 49 } else { 50 if ($Row['vpn'] == 0)50 if ($Row['vpn'] == 0) 51 51 { 52 52 $CZFreeLocalIP = $Row['IP']; 53 53 //echo($Row['external_ip']."\n"); 54 //if ($Row['name'] == 'TBC')54 //if ($Row['name'] == 'TBC') 55 55 //{ 56 56 // exec('/sbin/iptables -t nat -A PreroutingDNAT -m tcp -p tcp --dport 3724 -d '.$Row['external_ip'].' -j DNAT --to-destination '.$Row['IP'].':3725'); 57 57 // exec('/sbin/iptables -t nat -A POSTROUTING -m tcp -p tcp -s '.$Row['IP'].' --sport 3725 -o eth1 -j SNAT --to-source '.$Row['external_ip'].':3724'); 58 58 //} 59 if (strtolower($Row['name']) != 'centrala')59 if (strtolower($Row['name']) != 'centrala') 60 60 { 61 if ($Row['external_ip'] != '')61 if ($Row['external_ip'] != '') 62 62 { 63 63 echo($Row['name'].'='.$Row['external_ip']."\n"); … … 75 75 //echo('vpn'); 76 76 //exec('/sbin/iptables -t nat -A PreroutingDNAT -s '.$Row['IP'].' -p udp -m udp --dport 55556 -j DROP'); 77 if ($Row['external_ip'] != '') exec('/sbin/iptables -t nat -A PreroutingDNAT -d '.$Row['external_ip'].' -j ACCEPT');77 if ($Row['external_ip'] != '') exec('/sbin/iptables -t nat -A PreroutingDNAT -d '.$Row['external_ip'].' -j ACCEPT'); 78 78 exec('/sbin/iptables -t nat -A Block -s '.ToVpnIp($Row)." -j Proxy"); 79 79 80 //if ($Row['vpn'] == 1)80 //if ($Row['vpn'] == 1) 81 81 //{ 82 82 //exec('/sbin/iptables -t nat -A Block -m mac --mac-source '.$Row['MAC']." -j Local"); 83 //} else if ($Row['vpn'] == 2) exec('/sbin/iptables -t nat -A Block -m mac --mac-source '.$Row['MAC']." -j Proxy");83 //} else if ($Row['vpn'] == 2) exec('/sbin/iptables -t nat -A Block -m mac --mac-source '.$Row['MAC']." -j Proxy"); 84 84 } 85 if ($Row['czfree_ip'] != '')85 if ($Row['czfree_ip'] != '') 86 86 { 87 87 // CZFree -
trunk/Modules/NetworkConfigLinux/Generators/TrafficShaping.php
r790 r873 1 1 <?php 2 2 3 if (isset($_SERVER['REMOTE_ADDR'])) die();3 if (isset($_SERVER['REMOTE_ADDR'])) die(); 4 4 5 5 $Enabled = 1; … … 37 37 exec('/sbin/iptables -t mangle -F PREROUTING'); 38 38 exec('/sbin/iptables -t mangle -F POSTROUTING'); 39 if ($Enabled)39 if ($Enabled) 40 40 { 41 41 //exec('/sbin/iptables -t mangle -A FORWARD -j MARK --set-mark 0'); … … 48 48 // In going traffic 49 49 fputs($File, "/sbin/tc qdisc del dev ".$InInterface." root\n"); 50 if ($Enabled)50 if ($Enabled) 51 51 { 52 52 fputs($File, "/sbin/tc qdisc add dev ".$InInterface." root handle 1:0 htb default 2\n"); … … 59 59 // Out going traffic 60 60 fputs($File, "/sbin/tc qdisc del dev ".$OutInterface." root\n"); 61 if ($Enabled)61 if ($Enabled) 62 62 { 63 63 fputs($File, "/sbin/tc qdisc add dev ".$OutInterface." root handle 1:0 htb default 2\n"); … … 69 69 } 70 70 71 if (!$Enabled) die("Traffic shaping disabled\n");72 73 if ($ClassesEnabled)71 if (!$Enabled) die("Traffic shaping disabled\n"); 72 73 if ($ClassesEnabled) 74 74 { 75 75 $ClassId = 3; … … 124 124 125 125 $DbResult = $Database->select('users', '*, CONCAT(second_name, " ", first_name) as fullname', '(inet=1)'); 126 while ($User = $DbResult->fetch_array())126 while ($User = $DbResult->fetch_array()) 127 127 { 128 128 $UserClassId = $ClassId; … … 152 152 153 153 $DbResult2 = $Database->select('hosts','*',"block=0 AND MAC!='' AND user=".$User['id']); 154 while ($Host = $DbResult2->fetch_array())155 //if ($Row['name'] != 'WOW')154 while ($Host = $DbResult2->fetch_array()) 155 //if ($Row['name'] != 'WOW') 156 156 { 157 157 $HostClassId = $ClassId; … … 160 160 fputs($FileClassInfo, '1:'.$HostClassId.' '.$Host['name']."\n"); 161 161 //echo(' Host class id: '.$HostClassId."\n"); 162 //if ($User['inet'] == 1)162 //if ($User['inet'] == 1) 163 163 { 164 164 $Prio = 1; 165 if ($Host['vpn'] == 1)165 if ($Host['vpn'] == 1) 166 166 { 167 if ($Host['external_ip'] != '') $Host['IP'] = $Host['external_ip'];167 if ($Host['external_ip'] != '') $Host['IP'] = $Host['external_ip']; 168 168 else $Host['IP'] = ToVpnIp($Host); 169 169 } 170 170 171 //if ($Host['name'] == 'TERMINAL') $SpeedDivider = 0.5;171 //if ($Host['name'] == 'TERMINAL') $SpeedDivider = 0.5; 172 172 //else 173 173 $SpeedDivider = 1; 174 174 175 if ($Host['name'] == 'centrala')175 if ($Host['name'] == 'centrala') 176 176 { 177 177 $Host['IP'] = $Host['external_ip']; … … 183 183 $TableIn = 'FORWARD'; 184 184 } 185 //if ($Row['name'] == 'TERMINAL2') $Prio = 0;186 // if ($Row['name'] = 'TERMINAL2') $Prio = 0;187 if ($Host['name'] == 'voip-hajda') $Protocol = ' -p tcp';185 //if ($Row['name'] == 'TERMINAL2') $Prio = 0; 186 // if ($Row['name'] = 'TERMINAL2') $Prio = 0; 187 if ($Host['name'] == 'voip-hajda') $Protocol = ' -p tcp'; 188 188 else $Protocol = ''; 189 // if ($Host['name'] == 'KARLOS') $UserMaxSpeedIn = 128000;189 // if ($Host['name'] == 'KARLOS') $UserMaxSpeedIn = 128000; 190 190 /* 191 if ($Host['name'] == 'GAME')191 if ($Host['name'] == 'GAME') 192 192 { 193 193 exec('/sbin/iptables -t mangle -F game-server'); … … 195 195 $TableIn = 'game-server'; 196 196 }*/ 197 //if ($Host['name'] == 'TBC') continue;197 //if ($Host['name'] == 'TBC') continue; 198 198 199 199 // In going traffic … … 213 213 } 214 214 // Free inet 215 if ($Tarify[$User['inet_tarif_now']]['group_id'] == 3)215 if ($Tarify[$User['inet_tarif_now']]['group_id'] == 3) 216 216 { 217 217 //exec('/sbin/iptables -t mangle -A '.$TableIn.' -i eth1 -d '.$Host['IP'].$Protocol." -j MARK --set-mark ".$FreeInetClass); … … 220 220 // VoIP devices 221 221 /* 222 if (($Host['name'] == 'HAJDA-VOIP') || ($Host['name'] == 'NAVRATIL-VOIP'))222 if (($Host['name'] == 'HAJDA-VOIP') || ($Host['name'] == 'NAVRATIL-VOIP')) 223 223 { 224 224 exec('/sbin/iptables -t mangle -A '.$TableIn." -i eth1 -d ".$Host['IP']." -p udp -j MARK --set-mark ".$VoipClassId); 225 225 exec('/sbin/iptables -t mangle -A '.$TableOut." -o eth1 -s ".$Host['IP']." -p udp -j MARK --set-mark ".$VoipClassId); 226 226 } else 227 if ($Host['name'] == 'GAME')227 if ($Host['name'] == 'GAME') 228 228 { 229 229 exec('/sbin/iptables -t mangle -A FORWARD -o eth1 -s '.$Host['IP']." -j game-server");
Note:
See TracChangeset
for help on using the changeset viewer.