| 1 | <?php
|
|---|
| 2 |
|
|---|
| 3 | class ConfigRouterOSDHCP extends NetworkConfigItem
|
|---|
| 4 | {
|
|---|
| 5 | function Run(): void
|
|---|
| 6 | {
|
|---|
| 7 | $Path = array('ip', 'dhcp-server', 'lease');
|
|---|
| 8 |
|
|---|
| 9 | $Routerboard = new Routerboard();
|
|---|
| 10 | $Routerboard->UserName = $this->System->Config['MainRouter']['UserName'];
|
|---|
| 11 | $Routerboard->Timeout = $this->System->Config['MainRouter']['ConnectTimeout'];
|
|---|
| 12 | $Routerboard->Debug = true;
|
|---|
| 13 |
|
|---|
| 14 | $DbResult = $this->Database->query('SELECT * FROM `NetworkSubnet` WHERE `Configure`=1');
|
|---|
| 15 | while ($Subnet = $DbResult->fetch_assoc())
|
|---|
| 16 | {
|
|---|
| 17 | echo($Subnet['DHCP']);
|
|---|
| 18 | $Routerboard->HostName = $Subnet['DHCP'];
|
|---|
| 19 | $Items = array();
|
|---|
| 20 | $Server = 'dhcp'.$Subnet['Id'];
|
|---|
| 21 | $DbResult2 = $this->Database->query('SELECT `NetworkInterface`.*, `NetworkDevice`.`Name` AS `DeviceName` FROM `NetworkInterface` '.
|
|---|
| 22 | 'LEFT JOIN `NetworkDevice` ON `NetworkDevice`.`Id` = `NetworkInterface`.`Device` '.
|
|---|
| 23 | 'WHERE CompareNetworkPrefix(INET_ATON(`LocalIP`), INET_ATON("'.$Subnet['AddressRange'].'"), '.$Subnet['Mask'].') '.
|
|---|
| 24 | 'AND (`MAC` != "00:00:00:00:00:00") ORDER BY `LocalIP`');
|
|---|
| 25 | while ($Interface = $DbResult2->fetch_assoc())
|
|---|
| 26 | {
|
|---|
| 27 | $Name = $Interface['DeviceName'];
|
|---|
| 28 | if ($Interface['Name'] != '') $Name .= '-'.$Interface['Name'];
|
|---|
| 29 | $Items[] = array('mac-address' => $Interface['MAC'], 'address' => $Interface['LocalIP'], 'server' => $Server, 'comment' => $Name, 'lease-time' => '1d00:00:00');
|
|---|
| 30 | }
|
|---|
| 31 |
|
|---|
| 32 | print_r($Routerboard->ListUpdate($Path, array('mac-address', 'address', 'server', 'comment', 'lease-time'), $Items, array('server' => $Server, 'dynamic' => 'no')));
|
|---|
| 33 | echo("\n");
|
|---|
| 34 | }
|
|---|
| 35 | }
|
|---|
| 36 | }
|
|---|