1 | <?php
|
---|
2 |
|
---|
3 | class ConfigRouterOSNetwatch extends NetworkConfigItem
|
---|
4 | {
|
---|
5 | function Run(): void
|
---|
6 | {
|
---|
7 | $Path = array('tool', 'netwatch');
|
---|
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 | $DbResult3 = $this->Database->query('SELECT DISTINCT (`DHCP`) FROM `NetworkSubnet` WHERE `Configure` = 1'); // WHERE `Member` = 0');
|
---|
15 | while ($Router = $DbResult3->fetch_assoc())
|
---|
16 | {
|
---|
17 | echo($Router['DHCP']."\n");
|
---|
18 | $Routerboard->HostName = $Router['DHCP'];
|
---|
19 | $Items = array();
|
---|
20 | $DbResult = $this->Database->query('SELECT * FROM `NetworkSubnet` WHERE (`Configure` = 1) AND (`DHCP`="'.$Router['DHCP'].'")');
|
---|
21 | while ($Subnet = $DbResult->fetch_assoc())
|
---|
22 | {
|
---|
23 | $I = explode('.', $Subnet['AddressRange']);
|
---|
24 | $I = $I[2];
|
---|
25 | $DbResult2 = $this->Database->query('SELECT `NetworkInterface`.*, `NetworkDevice`.`Name` AS `DeviceName` FROM `NetworkInterface`'.
|
---|
26 | ' LEFT JOIN `NetworkDevice` ON `NetworkDevice`.`Id` = `NetworkInterface`.`Device` WHERE CompareNetworkPrefix(INET_ATON(`LocalIP`), INET_ATON("'.$Subnet['AddressRange'].'"), '.$Subnet['Mask'].')'.
|
---|
27 | ' AND (`NetworkDevice`.`Used` = 1) ORDER BY `NetworkInterface`.`LocalIP`');
|
---|
28 | while ($Interface = $DbResult2->fetch_assoc())
|
---|
29 | {
|
---|
30 | $Name = $Interface['DeviceName'];
|
---|
31 | if ($Interface['Name'] != '') $Name .= '-'.$Interface['Name'];
|
---|
32 | echo($Name.', ');
|
---|
33 | $Items[] = array('host' => $Interface['LocalIP'], 'interval' => '00:00:10', 'comment' => $Name);
|
---|
34 | }
|
---|
35 | }
|
---|
36 | $Routerboard->ListUpdate($Path, array('host', 'interval', 'comment'), $Items);
|
---|
37 | echo("\n");
|
---|
38 | }
|
---|
39 | }
|
---|
40 | }
|
---|