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