1 | <?php
|
---|
2 |
|
---|
3 | class ConfigRouterOSDNS extends NetworkConfigItem
|
---|
4 | {
|
---|
5 | function Run(): void
|
---|
6 | {
|
---|
7 | $Path = array('ip', 'dns', 'static');
|
---|
8 |
|
---|
9 | $Routerboard = new Routerboard($this->System->Config['MainRouter']['HostName']);
|
---|
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 `NetworkDomain`');
|
---|
15 | while ($Domain = $DbResult->fetch_assoc())
|
---|
16 | {
|
---|
17 | $DomainName = $Domain['Name'];
|
---|
18 |
|
---|
19 | // Get full domain name from parent items
|
---|
20 | $CurrentDomain = $Domain;
|
---|
21 | while ($CurrentDomain['Parent'] > 0)
|
---|
22 | {
|
---|
23 | $DbResult2 = $this->Database->query('SELECT * FROM `NetworkDomain` WHERE `Id`='.$CurrentDomain['Parent']);
|
---|
24 | $CurrentDomain = $DbResult2->fetch_assoc();
|
---|
25 | $DomainName .= '.'.$CurrentDomain['Name'];
|
---|
26 | }
|
---|
27 |
|
---|
28 | $Items = array();
|
---|
29 |
|
---|
30 | // Devices, Interfaces
|
---|
31 | $DbResult2 = $this->Database->query('SELECT `NetworkInterface`.*, `NetworkDevice`.`Name` AS `DeviceName` FROM `NetworkInterface` '.
|
---|
32 | 'JOIN `NetworkDevice` ON `NetworkInterface`.`Device`=`NetworkDevice`.`Id` '.
|
---|
33 | 'WHERE (`NetworkDevice`.`Used`=1)');
|
---|
34 | while ($Interface = $DbResult2->fetch_assoc())
|
---|
35 | {
|
---|
36 | $Name = $Interface['DeviceName'];
|
---|
37 | if ($Interface['Name'] != '') $Name .= '-'.$Interface['Name'];
|
---|
38 | $NameFull = $Name.'.'.$DomainName;
|
---|
39 | $NameExtFull = $Name.'-ext.'.$DomainName;
|
---|
40 | if ($Interface['LocalIP'] != '')
|
---|
41 | $Items[] = array('name' => $NameFull, 'address' => $Interface['LocalIP']);
|
---|
42 | if ($Interface['IPv6'] != '')
|
---|
43 | $Items[] = array('name' => $NameFull, 'address' => $Interface['IPv6']);
|
---|
44 | if ($Interface['ExternalIP'] != '')
|
---|
45 | $Items[] = array('name' => $NameExtFull, 'address' => $Interface['ExternalIP']);
|
---|
46 | }
|
---|
47 |
|
---|
48 | // Domain aliases
|
---|
49 | $DbResult2 = $this->Database->query('SELECT `NetworkDomainAlias`.*, `NetworkInterface`.`LocalIP` AS `LocalIP`, '.
|
---|
50 | '`NetworkInterface`.`IPv6` AS `IPv6`, `NetworkInterface`.`ExternalIP` AS `ExternalIP` FROM `NetworkDomainAlias` '.
|
---|
51 | 'JOIN `NetworkDevice` ON SUBSTR(`NetworkDomainAlias`.`Target`, 1, LENGTH(`NetworkDevice`.`Name` ))=`NetworkDevice`.`Name` '.
|
---|
52 | 'JOIN `NetworkInterface` ON `NetworkInterface`.`Device`=`NetworkDevice`.`Id` '.
|
---|
53 | 'WHERE (`NetworkDevice`.`Used`=1) AND '.
|
---|
54 | '(CONCAT_WS("-", `NetworkDevice`.`Name`, NULLIF(`NetworkInterface`.`Name`, "")) = `NetworkDomainAlias`.`Target`)');
|
---|
55 | while ($Alias = $DbResult2->fetch_assoc())
|
---|
56 | {
|
---|
57 | $Name = $Alias['Name'];
|
---|
58 | $NameFull = $Name.'.'.$DomainName;
|
---|
59 | $NameExtFull = $Name.'-ext.'.$DomainName;
|
---|
60 | if ($Alias['LocalIP'] != '')
|
---|
61 | $Items[] = array('name' => $NameFull, 'address' => $Alias['LocalIP']);
|
---|
62 | if ($Alias['IPv6'] != '')
|
---|
63 | $Items[] = array('name' => $NameFull, 'address' => $Alias['IPv6']);
|
---|
64 | if ($Alias['ExternalIP'] != '')
|
---|
65 | $Items[] = array('name' => $NameExtFull, 'address' => $Alias['ExternalIP']);
|
---|
66 | }
|
---|
67 |
|
---|
68 | $DbResult2 = $this->Database->query('SELECT * FROM `NetworkDomainServer` WHERE `Domain`='.$Domain['Id']);
|
---|
69 | while ($Server = $DbResult2->fetch_assoc())
|
---|
70 | {
|
---|
71 | $Routerboard->HostName = $Server['Address'];
|
---|
72 | $Routerboard->ListUpdate($Path, array('name', 'address'), $Items);
|
---|
73 | }
|
---|
74 | }
|
---|
75 | }
|
---|
76 | }
|
---|