From db58f06b299014d8f01dabd0f0205122ac60d84b Mon Sep 17 00:00:00 2001 From: Matt <125427297+ConstrictM@users.noreply.github.com> Date: Fri, 16 Oct 2026 17:24:25 -0400 Subject: [PATCH 1/2] feat(freebsd): support dns lookup FreeBSD uses /etc/resolv.conf for DNS. The same logic used in Linux is the same for FreeBSD. Signed-off-by: Matt <125427297+ConstrictM@users.noreply.github.com> --- lib/OperatingSystems/FreeBSD.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/lib/OperatingSystems/FreeBSD.php b/lib/OperatingSystems/FreeBSD.php index 08e88a49a..5ae3d6c8d 100644 --- a/lib/OperatingSystems/FreeBSD.php +++ b/lib/OperatingSystems/FreeBSD.php @@ -122,6 +122,10 @@ public function getNetworkInfo(): array { if (count($gw[0]) > 0) { $result['gateway'] = implode(', ', array_map('trim', $gw[0])); } + $resolvConf = $this->readContent('/etc/resolv.conf'); + if (preg_match_all('/^\s*nameserver\s+(\S+)/m', $resolvConf, $matches)) { + $result['dns'] = implode(', ', array_unique($matches[1])); + } } catch (RuntimeException) { // okay } @@ -239,6 +243,17 @@ public function getThermalZones(): array { return []; } + /** + * @throws RuntimeException + */ + protected function readContent(string $filename): string { + $data = @file_get_contents($filename); + if ($data === false || $data === '') { + throw new RuntimeException('Unable to read: "' . $filename . '"'); + } + return trim($data); + } + /** * Execute a command with shell_exec. * From 922217fd9696635c763e7a705b5ca277467481d0 Mon Sep 17 00:00:00 2001 From: Frank Karlitschek Date: Fri, 23 Oct 2026 11:28:12 +0200 Subject: [PATCH 2/2] test(freebsd): stub resolv.conf in the network info tests getNetworkInfo() now reads /etc/resolv.conf, but the FreeBSD test mock did not stub readContent(), so testGetNetworkInfo read the real file of whatever machine ran the tests and failed wherever that file lists a nameserver. The test now stubs it as unreadable, and a second test checks that nameservers are listed once each, in file order, with indented lines and comments handled. Assisted-by: ClaudeCode:claude-opus-5-5 Co-Authored-By: Claude Opus 5.5 Signed-off-by: Frank Karlitschek --- tests/lib/FreeBSDTest.php | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/tests/lib/FreeBSDTest.php b/tests/lib/FreeBSDTest.php index 3bc749b8e..fd28c151f 100644 --- a/tests/lib/FreeBSDTest.php +++ b/tests/lib/FreeBSDTest.php @@ -34,7 +34,7 @@ protected function setUp(): void { ->disableOriginalClone() ->disableArgumentCloning() ->disallowMockingUnknownTypes() - ->onlyMethods(['executeCommand', 'getNetInterfaces']) + ->onlyMethods(['readContent', 'executeCommand', 'getNetInterfaces']) ->getMock(); } @@ -194,6 +194,9 @@ public function testGetNetworkInfo(): void { $this->os->method('executeCommand') ->with('netstat -rn') ->willReturn("Routing tables\n\ndefault 192.0.2.1 UGS\n"); + $this->os->method('readContent') + ->with('/etc/resolv.conf') + ->willThrowException(new RuntimeException('Unable to read: "/etc/resolv.conf"')); $networkInfo = $this->os->getNetworkInfo(); @@ -202,6 +205,17 @@ public function testGetNetworkInfo(): void { $this->assertArrayHasKey('hostname', $networkInfo); } + public function testGetNetworkInfoListsTheNameservers(): void { + $this->os->method('executeCommand') + ->with('netstat -rn') + ->willReturn("Routing tables\n\ndefault 192.0.2.1 UGS\n"); + $this->os->method('readContent') + ->with('/etc/resolv.conf') + ->willReturn("# Generated by resolvconf\nsearch example.org\nnameserver 192.0.2.53\n nameserver 2001:db8::53\nnameserver 192.0.2.53\n"); + + $this->assertSame('192.0.2.53, 2001:db8::53', $this->os->getNetworkInfo()['dns']); + } + public function testGetNetworkInterfacesError(): void { $this->os->method('getNetInterfaces') ->willThrowException(new RuntimeException('Unable to get network interfaces'));