Skip to content

Commit

Permalink
chore: remove dns server
Browse files Browse the repository at this point in the history
Finding the DNS servers is more complex nowadays.

Signed-off-by: Daniel Kesselberg <mail@danielkesselberg.de>
  • Loading branch information
kesselb committed May 25, 2024
1 parent 6e2a0dc commit 565af19
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 18 deletions.
17 changes: 7 additions & 10 deletions lib/OperatingSystems/FreeBSD.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,24 +98,21 @@ public function getUptime(): int {
}

public function getNetworkInfo(): array {
$result = [];
$result['hostname'] = \gethostname();
$result = [
'gateway' => '',
'hostname' => \gethostname(),
];

try {
$dns = $this->executeCommand('cat /etc/resolv.conf 2>/dev/null');
preg_match_all("/(?<=^nameserver ).\S*/m", $dns, $matches);
$alldns = implode(' ', $matches[0]);
$result['dns'] = $alldns;
$netstat = $this->executeCommand('netstat -rn');
preg_match_all("/(?<=^default)\s*[0-9a-fA-f\.:]+/m", $netstat, $gw);
if (count($gw[0]) > 0) {
$result['gateway'] = implode(", ", array_map("trim", $gw[0]));
} else {
$result['gateway'] = '';
}
} catch (RuntimeException $e) {
return $result;
} catch (RuntimeException) {
// okay
}

return $result;
}

Expand Down
1 change: 0 additions & 1 deletion lib/OperatingSystems/IOperatingSystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ public function getMemory(): Memory;
* Get info about network connection.
*
* [
* 'dns' => string,
* 'gateway' => string,
* 'hostname' => string,
* ]
Expand Down
4 changes: 1 addition & 3 deletions lib/OperatingSystems/Linux.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,11 @@ public function getUptime(): int {

public function getNetworkInfo(): array {
$result = [
'hostname' => \gethostname(),
'dns' => '',
'gateway' => '',
'hostname' => \gethostname(),
];

if (function_exists('shell_exec')) {
$result['dns'] = shell_exec('cat /etc/resolv.conf |grep -i \'^nameserver\'|head -n1|cut -d \' \' -f2');
$result['gateway'] = shell_exec('ip route | awk \'/default/ { print $3 }\'');
}

Expand Down
4 changes: 0 additions & 4 deletions templates/settings-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,6 @@ function FormatMegabytes(int $byte): string {
<?php p($l->t('Hostname:')); ?>
<span class="info"><?php p($_['networkinfo']['hostname']); ?></span>
</div>
<div class="col col-12">
<?php p($l->t('DNS:')); ?>
<span class="info"><?php p($_['networkinfo']['dns']); ?></span>
</div>
<div class="col col-12">
<?php p($l->t('Gateway:')); ?>
<span class="info"><?php p($_['networkinfo']['gateway']); ?></span>
Expand Down

0 comments on commit 565af19

Please sign in to comment.