Changeset 239 for trunk/system/generators/dhcp_routerboard.php
- Timestamp:
- Aug 2, 2009, 10:28:58 AM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/system/generators/dhcp_routerboard.php
r213 r239 2 2 3 3 if(isset($_SERVER['REMOTE_ADDR'])) die(); 4 include_once('../../global.php'); 4 include('../../global.php'); 5 include('../routerboard.php'); 6 $Path = array('ip', 'dhcp-server', 'lease'); 7 8 $Routerboard = new Routerboard(); 9 $Routerboard->UserName = $Config['MainRouter']['UserName']; 10 $Routerboard->Timeout = $Config['MainRouter']['ConnectTimeout']; 5 11 6 12 $DbResult = $Database->query('SELECT * FROM `NetworkSubnet` WHERE `Member` = 0'); … … 8 14 { 9 15 echo($Subnet['DHCP']); 16 $Routerboard->HostName = $Subnet['DHCP']; 10 17 $I = explode('.', $Subnet['AddressRange']); 11 18 $I = $I[2]; 12 $Commands = array(); 13 $Commands[] = '/ip dhcp-server lease { remove [find server=dhcp'.$I.']}'; 19 $Items = array(); 14 20 $DbResult2 = $Database->query('SELECT NetworkInterface.*, NetworkDevice.Name AS DeviceName FROM `NetworkInterface` LEFT JOIN NetworkDevice ON NetworkDevice.Id = NetworkInterface.Device WHERE (`LocalIP` LIKE "192.168.'.$I.'.%") AND (`MAC` != "00:00:00:00:00:00") ORDER BY `LocalIP`'); 15 21 while($Interface = $DbResult2->fetch_assoc()) 16 22 { 17 $Commands[] = '/ip dhcp-server lease add mac-address='.$Interface['MAC'].' address='.$Interface['LocalIP'].' server=dhcp'.$I.' comment='.$Interface['DeviceName'].'-'.$Interface['Name']; 23 $Name = $Interface['DeviceName']; 24 if($Interface['Name'] != '') $Name .= '-'.$Interface['Name']; 25 $Items[] = array('mac-address' => $Interface['MAC'], 'address' => $Interface['LocalIP'], 'server' => 'dhcp'.$I, 'comment' => $Name); 18 26 } 19 $Commands = implode(';', $Commands); 20 $Command = '/usr/bin/ssh -o ConnectTimeout=5 -l '.$Config['MainRouter']['UserName'].' -i id_dsa '.$Subnet['DHCP'].' "'.$Commands.'"'; 21 //echo($Command."\n"); 22 $Output = ''; 23 exec($Command, $Output); 24 print_r($Output); 27 28 print_r($Routerboard->ListUpdate($Path, array('mac-address', 'address', 'server', 'comment'), $Items, array('server' => 'dhcp'.$I))); 25 29 echo("\n"); 26 30 }
Note:
See TracChangeset
for help on using the changeset viewer.