Changeset 187 for trunk/system
- Timestamp:
- Apr 5, 2009, 3:54:46 PM (16 years ago)
- Location:
- trunk/system
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/system/generators/dhcp_routerboard.php
r171 r187 3 3 include_once('../../global.php'); 4 4 5 $UserName = 'admin-ssh'; 6 7 $DbResult = $Database->query('SELECT * FROM NetworkSubnet'); 5 $DbResult = $Database->query('SELECT * FROM `NetworkSubnet` WHERE `Member` = 0'); 8 6 while($Subnet = $DbResult->fetch_assoc()) 9 7 { … … 13 11 $Commands = array(); 14 12 $Commands[] = '/ip dhcp-server lease { remove [find server=dhcp'.$I.']}'; 15 $DbResult2 = $Database->query('SELECT * FROM hosts WHERE (IP LIKE "192.168.'.$I.'.%") AND (MAC != "00:00:00:00:00:00") ORDER BY IP');13 $DbResult2 = $Database->query('SELECT * FROM `hosts` WHERE (`IP` LIKE "192.168.'.$I.'.%") AND (`MAC` != "00:00:00:00:00:00") ORDER BY `IP`'); 16 14 while($Host = $DbResult2->fetch_assoc()) 17 15 { … … 19 17 } 20 18 $Commands = implode(';', $Commands); 21 $Command = '/usr/bin/ssh -l '.$ UserName.' -i id_dsa '.$Subnet['DHCP'].' "'.$Commands.'"';19 $Command = '/usr/bin/ssh -l '.$Config['MainRouter']['UserName'].' -i id_dsa '.$Subnet['DHCP'].' "'.$Commands.'"'; 22 20 //echo($Command."\n"); 23 21 $Output = ''; -
trunk/system/generators/nat_routerboard.php
r174 r187 3 3 include_once('../../global.php'); 4 4 5 $InetInterface = 'ether3'; 6 $Router = '192.168.0.11'; 5 $InetInterface = $Config['MainRouter']['InetInterface']; 7 6 8 7 $Commands = array(); … … 12 11 while($Member = $DbResult->fetch_assoc()) 13 12 { 14 echo($Member['Name']."\n"); 13 echo($Member['Name'].': '); 14 // Hosts 15 15 $DbResult2 = $Database->select('hosts', '*', '(external_ip <> "") AND (user='.$Member['Id'].') AND (IP != external_ip) ORDER BY id DESC'); 16 16 while($Host = $DbResult2->fetch_assoc()) 17 17 { 18 echo($Host['name']."\n"); 18 $Host['name'] = RouterOSIdent($Host['name']); 19 echo($Host['name'].'('.$Host['IP'].'), '); 19 20 $Commands[] = ' /ip firewall nat add chain=srcnat src-address='.$Host['IP'].' out-interface='.$InetInterface.' action=src-nat to-addresses='.$Host['external_ip'].' comment="'.$Host['name'].'"'; 20 21 $Commands[] = ' /ip firewall nat add chain=dstnat dst-address='.$Host['external_ip'].' in-interface='.$InetInterface.' action=dst-nat to-addresses='.$Host['IP'].' comment="'.$Host['name'].'"'; 21 22 } 23 24 // Subnets 25 $DbResult2 = $Database->select('NetworkSubnet', '*', 'Member='.$Member['Id']); 26 while($Subnet = $DbResult2->fetch_assoc()) 27 { 28 $Subnet['Name'] = RouterOSIdent('subnet-'.$Subnet['Name']); 29 echo($Subnet['Name'].'('.$Subnet['AddressRange'].'/'.$Subnet['Mask'].'), '); 30 $Range = CIDRToAddressRange($Subnet['ExtAddressRange'], $Subnet['ExtMask']); 31 $Range = $Range['From'].'-'.$Range['To']; 32 $Commands[] = ' /ip firewall nat add chain=srcnat src-address-list='.$Subnet['AddressRange'].'/'.$Subnet['Mask'].' out-interface='.$InetInterface.' action=src-nat to-addresses='.$Range.' comment="'.$Subnet['Name'].'"'; 33 $Range = CIDRToAddressRange($Subnet['AddressRange'], $Subnet['Mask']); 34 $Range = $Range['From'].'-'.$Range['To']; 35 $Commands[] = ' /ip firewall nat add chain=dstnat dst-address-list='.$Subnet['ExtAddressRange'].'/'.$Subnet['ExtMask'].' in-interface='.$InetInterface.' action=dst-nat to-addresses='.$Range.' comment="'.$Subnet['Name'].'"'; 36 } 37 echo("\n"); 22 38 } 23 39 … … 29 45 30 46 $Commands = addslashes(implode(';', $Commands)); 31 $Command = '/usr/bin/ssh -l admin-ssh -i id_dsa '.$Router.' "'.$Commands.'"'; 47 $Command = '/usr/bin/ssh -l '.$Config['MainRouter']['UserName'].' -i id_dsa '.$Config['MainRouter']['HostName'].' "'.$Commands.'"'; 48 $Output = array(); 32 49 echo($Command."\n"); 33 //exec($Command, $Output);50 exec($Command, $Output); 34 51 //array_pop($Output); 35 52 //print_r($Output); -
trunk/system/generators/netwatch.php
r171 r187 3 3 include_once('../../global.php'); 4 4 5 $UserName = 'admin-ssh'; 6 7 $DbResult3 = $Database->query('SELECT DISTINCT (`DHCP`) FROM `NetworkSubnet`'); 5 $DbResult3 = $Database->query('SELECT DISTINCT (`DHCP`) FROM `NetworkSubnet` WHERE `Member` = 0'); 8 6 while($Router = $DbResult3->fetch_assoc()) 9 7 { … … 23 21 } 24 22 $Commands = implode(';', $Commands); 25 $Command = '/usr/bin/ssh -l '.$ UserName.' -i id_dsa '.$Router['DHCP'].' "'.$Commands.'"';23 $Command = '/usr/bin/ssh -l '.$Config['MainRouter']['UserName'].' -i id_dsa '.$Router['DHCP'].' "'.$Commands.'"'; 26 24 //echo($Command."\n"); 27 25 $Output = ''; -
trunk/system/generators/traffic_shaping_routerboard.php
r171 r187 26 26 $OutInterface = 'eth1'; 27 27 $InInterface = 'ifb0'; 28 $InetInterface = $Config['MainRouter']['InetInterface']; 28 29 $FreeInetSpeed = 64 * 1024; 29 30 $InetInterface = 'ether3';31 $Router = '192.168.0.11';32 30 33 31 $Commands = array(); … … 43 41 44 42 // Divide rules by subnet number 45 foreach(array(0, 1, 2, 3, 4, 5, 7) as $Subnet) 43 $DbResult = $Database->query('SELECT Id, AddressRange, Mask FROM NetworkSubnet WHERE Member = 0'); 44 while($Subnet = $DbResult->fetch_assoc()) 46 45 { 47 $Commands[] = ' /ip firewall mangle add chain=inet-out src-address= 192.168.'.$Subnet.'.0/24 out-interface='.$InetInterface.' action=jump jump-target=inet-out-'.$Subnet;48 $Commands[] = ' /ip firewall mangle add chain=inet-in dst-address= 192.168.'.$Subnet.'.0/24 in-interface='.$InetInterface.' action=jump jump-target=inet-in-'.$Subnet;46 $Commands[] = ' /ip firewall mangle add chain=inet-out src-address='.$Subnet['AddressRange'].'/'.$Subnet['Mask'].' out-interface='.$InetInterface.' action=jump jump-target=inet-out-'.$Subnet['Id']; 47 $Commands[] = ' /ip firewall mangle add chain=inet-in dst-address='.$Subnet['AddressRange'].'/'.$Subnet['Mask'].' in-interface='.$InetInterface.' action=jump jump-target=inet-in-'.$Subnet['Id']; 49 48 } 50 49 … … 62 61 while($Member = $DbResult->fetch_array()) 63 62 { 64 $Member['Name'] = strtr(strtolower(trim($Member['Name'])), array(' ' => '-', '(' => '-', ')' => '-', 65 'č' => 'c', 'š' => 's', 'ě' => 'e', 'ř' => 'r', 'ž' => 'z', 'ý' => 'y', 'á' => 'a', 'í' => 'i', 'é' => 'e', 'ů' => 'u', 'ú' => 'u', 'ď' => 'd', 'ť' => 't', 'ň' => 'n', 'ó' => 'o', 66 'Č' => 'c', 'Š' => 's', 'Ě' => 'e', 'Ř' => 'r', 'Ž' => 'z', 'Ý' => 'y', 'Á' => 'a', 'Í' => 'i', 'É' => 'e', 'Ů' => 'u', 'Ú' => 'u', 'Ď' => 'd', 'Ť' => 't', 'Ň' => 'n', 'Ó' => 'o', 67 )); 63 $Member['Name'] = RouterOSIdent($Member['Name']); 68 64 69 65 echo('Uživatel '.$Member['Name'].": "); … … 77 73 $Commands[] = ' /queue tree add name='.$Member['Name'].'-in limit-at='.$SpeedOut.' max-limit='.$UserMaxSpeedOut.' parent=main-in queue=wireless-default'; 78 74 79 $DbResult2 = $Database->select('hosts', 'COUNT(*)', "block=0 AND MAC!='' AND user=".$Member['Id']);75 $DbResult2 = $Database->select('hosts', 'COUNT(*)', '(block = 0) AND (MAC != "") AND (user = '.$Member['Id'].')'); 80 76 $Row = $DbResult2->fetch_array(); 81 77 $HostCount = $Row[0]; 82 $HostSpeedIn = round($SpeedIn / $HostCount); 83 $HostSpeedOut = round($SpeedOut / $HostCount); 78 if($HostCount > 0) 79 { 80 $HostSpeedIn = round($SpeedIn / $HostCount); 81 $HostSpeedOut = round($SpeedOut / $HostCount); 82 } else 83 { 84 $HostSpeedIn = $SpeedIn; 85 $HostSpeedOut = $SpeedOut; 86 } 84 87 85 $DbResult2 = $Database->select('hosts', '*', "block=0 AND MAC!='' AND user=".$Member['Id']);88 $DbResult2 = $Database->select('hosts', '*', 'block=0 AND MAC!="" AND user='.$Member['Id']); 86 89 while($Host = $DbResult2->fetch_array()) 87 90 { 88 $Host['name'] = strtolower($Host['name']);91 $Host['name'] = RouterOSIdent($Host['name']); 89 92 echo($Host['name'].', '); 90 93 $IPParts = explode('.', $Host['IP']); … … 100 103 if($Index > 50) 101 104 { 105 //print_r($Commands); 102 106 $Commands = addslashes(implode(';', $Commands)); 103 $Command = '/usr/bin/ssh -l admin-ssh -i id_dsa '.$Router.' "'.$Commands.'"';104 //echo($Command."\n");107 $Command = '/usr/bin/ssh -l '.$Config['MainRouter']['UserName'].' -i id_dsa '.$Config['MainRouter']['HostName'].' "'.$Commands.'"'; 108 $Output = array(); 105 109 exec($Command, $Output); 106 110 print_r($Output); … … 110 114 $Index++; 111 115 } 116 117 $DbResult2 = $Database->select('NetworkSubnet', '*', 'Member='.$Member['Id']); 118 while($Subnet = $DbResult2->fetch_array()) 119 { 120 $Subnet['Name'] = RouterOSIdent('subnet-'.$Subnet['Name']); 121 echo($Subnet['Name'].', '); 122 $IPParts = explode('.', $Subnet['AddressRange']); 123 $SubnetNumber = $IPParts[2]; 124 $Commands[] = ' /ip firewall mangle add chain=inet-out-'.$SubnetNumber.' src-address='.$Subnet['AddressRange'].'/'.$Subnet['Mask'].' out-interface='.$InetInterface.' action=mark-packet new-packet-mark='.$PacketMark.' passthrough=no comment="'.$Subnet['Name'].'"'; 125 $Commands[] = ' /queue tree add name='.$Subnet['Name'].'-out limit-at='.$HostSpeedIn.' max-limit='.$UserMaxSpeedIn.' parent='.$Member['Name'].'-out packet-mark='.$PacketMark.' queue=wireless-default'; 126 $PacketMark++; 127 $Commands[] = ' /ip firewall mangle add chain=inet-in-'.$SubnetNumber.' dst-address='.$Subnet['AddressRange'].'/'.$Subnet['Mask'].' in-interface='.$InetInterface.' action=mark-packet new-packet-mark='.$PacketMark.' passthrough=no comment="'.$Subnet['Name'].'"'; 128 $Commands[] = ' /queue tree add name='.$Subnet['Name'].'-in limit-at='.$HostSpeedOut.' max-limit='.$UserMaxSpeedOut.' parent='.$Member['Name'].'-in packet-mark='.$PacketMark.' queue=wireless-default'; 129 $PacketMark++; 130 131 // Posílej po menších částech 132 if($Index > 50) 133 { 134 $Commands = addslashes(implode(';', $Commands)); 135 $Command = '/usr/bin/ssh -l '.$Config['MainRouter']['UserName'].' -i id_dsa '.$Config['MainRouter']['HostName'].' "'.$Commands.'"'; 136 //echo($Command."\n"); 137 $Output = array(); 138 exec($Command, $Output); 139 print_r($Output); 140 $Commands = array(); 141 $Index = 0; 142 } 143 $Index++; 144 } 145 112 146 echo("\n"); 113 147 } 114 148 //print_r($Commands); 115 149 $Commands = addslashes(implode(';', $Commands)); 116 $Command = '/usr/bin/ssh -l admin-ssh -i id_dsa '.$Router.' "'.$Commands.'"';150 $Command = '/usr/bin/ssh -l '.$Config['MainRouter']['UserName'].' -i id_dsa '.$Config['MainRouter']['HostName'].' "'.$Commands.'"'; 117 151 //echo($Command."\n"); 152 $Output = array(); 118 153 exec($Command, $Output); 119 154 //array_pop($Output); -
trunk/system/netwatch_import.php
r168 r187 1 1 <?php 2 2 3 include_once('../global.php'); 3 4 4 $UserName = 'admin-ssh';5 5 $Config['Web']['ShowErrors'] = 1; 6 6 7 $DbResult3 = $Database->query('SELECT DISTINCT (`DHCP`) FROM `NetworkSubnet` ');7 $DbResult3 = $Database->query('SELECT DISTINCT (`DHCP`) FROM `NetworkSubnet` WHERE `Member` = 0'); 8 8 while($Router = $DbResult3->fetch_assoc()) 9 9 { … … 11 11 $Commands[] = '/tool netwatch print terse'; 12 12 $Commands = implode(';', $Commands); 13 $Command = '/usr/bin/ssh -l '.$ UserName.' -i generators/id_dsa '.$Router['DHCP'].' "'.$Commands.'"';13 $Command = '/usr/bin/ssh -l '.$Config['MainRouter']['UserName'].' -i generators/id_dsa '.$Router['DHCP'].' "'.$Commands.'"'; 14 14 //echo($Command."\n"); 15 15 $Output = '';
Note:
See TracChangeset
for help on using the changeset viewer.