- Timestamp:
- Mar 24, 2009, 7:52:02 PM (16 years ago)
- Location:
- system
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
system/generators/dhcp_routerboard.php
r111 r172 1 1 <?php 2 include_once('/a/www/centrala/global.php');3 2 4 // Generate DHCP server configuration 5 /* 6 $File = fopen('/etc/dhcpd.conf', 'w'); 7 fputs($File, "# DHCP Configuration file\n". 8 "authoritative;\n". 9 'option domain-name "zdechov.net";'."\n". 10 "server-name centrala;\n". 11 "ddns-update-style ad-hoc;\n". 12 "default-lease-time 86400;\n". 13 "max-lease-time 86400;\n". 14 "ddns-hostname centrala;\n". 15 "option domain-name-servers 192.168.0.1;\n". 16 "#option subnet-mask 255.255.0.0;\n\n". 17 "# nastaveni WINS serveru\n". 18 "option netbios-name-servers 192.168.0.1;\n". 19 "option netbios-dd-server 192.168.0.1;\n". 20 "option netbios-node-type 8;\n". 21 'option netbios-scope "";'."\n". 22 "server-identifier 192.168.0.1;\n\n"); 23 */ 24 $Commands = array(); 25 //$MaxSubnet = 1; 26 $Commands[] = '/ip dhcp-server lease { remove [find]}'; 27 for($i = 0; $i <= 5; $i++) 3 $SessionDisable = true; 4 chdir('/a/www/centrala'); 5 include('global.php'); 6 7 $UserName = 'admin-ssh'; 8 9 $DbResult = $Database->query('SELECT * FROM NetworkSubnet'); 10 while($Subnet = $DbResult->fetch_assoc()) 28 11 { 29 /* 30 fputs($File, "subnet 192.168.".$i.".0 netmask 255.255.255.0 {\n". 31 " range 192.168.".$i.".128 192.168.".$i.".254;\n". 32 " option broadcast-address 192.168.".$i.".255;\n". 33 " option routers 192.168.".$i.".1;\n"); 34 */ 35 $DbResult = $Database->select('hosts', '*', "IP LIKE '192.168.".$i."%' ORDER BY IP"); 36 while($Row = $DbResult->fetch_array()) 12 //print_r($Subnet); 13 $I = explode('.', $Subnet['AddressRange']); 14 $I = $I[2]; 15 $Commands = array(); 16 $Commands[] = '/ip dhcp-server lease { remove [find server=dhcp'.$I.']}'; 17 $DbResult2 = $Database->query('SELECT * FROM hosts WHERE (IP LIKE "192.168.'.$I.'.%") AND (MAC != "00:00:00:00:00:00") ORDER BY IP'); 18 while($Host = $DbResult2->fetch_assoc()) 37 19 { 38 // $Data = $Row['name']; 39 // if(strlen($Data) < 9) $Data .= "\t"; 40 // fputs($File, " host ".$Data."\t{ fixed-address ".$Row['IP'].";\thardware ethernet ".$Row['MAC']."; }\n"); 41 $Commands[] = '/ip dhcp-server lease add mac-address='.$Row['MAC'].' address='.$Row['IP'].' server=dhcp'.$i.' comment='.$Row['name']; 20 $Commands[] = '/ip dhcp-server lease add mac-address='.$Host['MAC'].' address='.$Host['IP'].' server=dhcp'.$I.' comment='.$Host['name']; 42 21 } 43 44 // fputs($File, "}\n\n"); 22 $Commands = implode(';', $Commands); 23 $Command = '/usr/bin/ssh -l '.$UserName.' -i /root/.ssh/id_dsa '.$Subnet['DHCP'].' "'.$Commands.'"'; 24 echo($Command."\n"); 25 $Output = ''; 26 exec($Command, $Output); 27 print_r($Output); 28 echo("\n"); 45 29 } 46 //fclose($File);47 $Commands = implode(';', $Commands);48 $Command = '/usr/bin/ssh -l admin-ssh -i /root/.ssh/id_dsa rt-hajda-0 "'.$Commands.'"';49 echo($Command);50 exec($Command, $Output);51 print_r($Output);52 30 53 31 ?> -
system/generators/netwatch.php
r111 r172 1 1 <?php 2 2 include_once('/a/www/centrala/global.php'); 3 $Router = '192.168.0.11'; 3 4 4 5 $Commands = array(); … … 14 15 //} 15 16 $Commands = implode(';', $Commands); 16 $Command = '/usr/bin/ssh -l admin-ssh -i /root/.ssh/id_dsa rt-hajda-0"'.$Commands.'"';17 $Command = '/usr/bin/ssh -l admin-ssh -i /root/.ssh/id_dsa '.$Router.' "'.$Commands.'"'; 17 18 echo($Command); 18 19 exec($Command, $Output); -
system/generators/traffic_shaping_routerboard.php
r141 r172 58 58 59 59 // Process users 60 $Index = 0; 60 61 $DbResult = $Database->select('users', '*, CONCAT(second_name, " ", first_name) as fullname', '(inet=1)'); 61 62 while($User = $DbResult->fetch_array()) … … 110 111 //echo($Row['id'].','); 111 112 */ 113 echo($Index.','); 114 if($Index > 50) 115 { 116 $Commands = addslashes(implode(';', $Commands)); 117 $Command = '/usr/bin/ssh -l admin-ssh -i /root/.ssh/id_dsa '.$Router.' "'.$Commands.'"'; 118 //echo($Command."\n\n\n"); 119 echo('.'); 120 exec($Command, $Output); 121 $Commands = array(); 122 $Index = 0; 123 } 124 $Index++; 112 125 } 113 126 echo("\n"); … … 116 129 $Commands = addslashes(implode(';', $Commands)); 117 130 $Command = '/usr/bin/ssh -l admin-ssh -i /root/.ssh/id_dsa '.$Router.' "'.$Commands.'"'; 118 echo($Command."\n");131 //echo($Command."\n"); 119 132 exec($Command, $Output); 120 133 //array_pop($Output); -
system/netwatch_import.php
r113 r172 1 1 <?php 2 include_once('/a/www/centrala/global.php'); 2 $SessionDisable = true; 3 chdir('/a/www/centrala'); 4 include_once('global.php'); 3 5 6 $UserName = 'admin-ssh'; 4 7 $Config['Web']['ShowErrors'] = 1; 5 8 6 $Commands = array(); 7 //$MaxSubnet = 1; 8 $Commands[] = '/tool netwatch print terse'; 9 $Commands = implode(';', $Commands); 10 $Command = '/usr/bin/ssh -l admin-ssh -i /root/.ssh/id_dsa rt-hajda-0 "'.$Commands.'"'; 11 //echo($Command."\n"); 12 exec($Command, $Output); 13 array_pop($Output); 14 //print_r($Output); 9 $DbResult3 = $Database->query('SELECT DISTINCT (`DHCP`) FROM `NetworkSubnet`'); 10 while($Router = $DbResult3->fetch_assoc()) 11 { 12 $Commands = array(); 13 $Commands[] = '/tool netwatch print terse'; 14 $Commands = implode(';', $Commands); 15 $Command = '/usr/bin/ssh -l '.$UserName.' -i /root/.ssh/id_dsa '.$Router['DHCP'].' "'.$Commands.'"'; 16 //echo($Command."\n"); 17 $Output = ''; 18 exec($Command, $Output); 19 array_pop($Output); 20 //print_r($Output); 21 foreach($Output as $Row) 22 { 23 $Row = substr($Row, 6); 24 $RowParts = explode(' ', $Row); 25 $Properties = array(); 26 foreach($RowParts as $Index => $Item) 27 { 28 if(strpos($Item, '=') !== false) 29 { 30 $ItemParts = explode('=', $Item); 31 $Properties[$ItemParts[0]] = $ItemParts[1]; 32 } 33 } 34 if($Properties['status'] == 'up') 35 { 36 $Online = 1; 37 $Values = array('online' => $Online, 'last_online' => 'NOW()'); 38 } else 39 { 40 $Online = 0; 41 $Values = array('online' => $Online); 42 } 15 43 16 foreach($Output as $Row) 17 { 18 $Row = substr($Row, 6); 19 $RowParts = explode(' ', $Row); 20 $Properties = array(); 21 foreach($RowParts as $Index => $Item) 22 { 23 if(strpos($Item, '=') !== false) 44 $DbResult = $Database->update('hosts', 'IP="'.$Properties['host'].'"', $Values); 45 if($Online == 1) 24 46 { 25 $ItemParts = explode('=', $Item); 26 $Properties[$ItemParts[0]] = $ItemParts[1]; 47 $DbResult = $Database->select('hosts', 'id', 'IP="'.$Properties['host'].'"'); 48 $DbRow = $DbResult->fetch_array(); 49 $HostId = $DbRow['id']; 50 $DbResult2 = $Database->select('stat_hosts', '*', '(host_id="'.$HostId.'") AND (time = DATE_FORMAT(NOW(), "%Y-%m-%d %H:00:00"))'); 51 if($DbResult2->num_rows == 0) $Database->query('REPLACE INTO stat_hosts (host_id, time) VALUES ("'.$HostId.'", DATE_FORMAT(NOW(), "%Y-%m-%d %H:00:00"))'); 52 $Database->query('UPDATE stat_hosts SET count = count + 1 WHERE (host_id="'.$HostId.'") AND (time = DATE_FORMAT(NOW(), "%Y-%m-%d %H:00:00"))'); 27 53 } 28 }29 if($Properties['status'] == 'up')30 {31 $Online = 1;32 $Values = array('online' => $Online, 'last_online' => 'NOW()');33 } else34 {35 $Online = 0;36 $Values = array('online' => $Online);37 }38 39 $DbResult = $Database->update('hosts', 'IP="'.$Properties['host'].'"', $Values);40 if($Online == 1)41 {42 $DbResult = $Database->select('hosts', 'id', 'IP="'.$Properties['host'].'"');43 $DbRow = $DbResult->fetch_array();44 $HostId = $DbRow['id'];45 $DbResult2 = $Database->select('stat_hosts', '*', '(host_id="'.$HostId.'") AND (time = DATE_FORMAT(NOW(), "%Y-%m-%d %H:00:00"))');46 if($DbResult2->num_rows == 0) $Database->query('REPLACE INTO stat_hosts (host_id, time) VALUES ("'.$HostId.'", DATE_FORMAT(NOW(), "%Y-%m-%d %H:00:00"))');47 $Database->query('UPDATE stat_hosts SET count = count + 1 WHERE (host_id="'.$HostId.'") AND (time = DATE_FORMAT(NOW(), "%Y-%m-%d %H:00:00"))');48 54 } 49 55 }
Note:
See TracChangeset
for help on using the changeset viewer.