Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update DefaultOs.php #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 27 additions & 23 deletions lib/OperatingSystems/DefaultOs.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,33 +146,37 @@ public function getNetworkInterfaces() {
$interfaces = glob('/sys/class/net/*');
$result = [];

foreach ($interfaces as $interface) {
$iface = [];
$iface['interface'] = basename($interface);
$iface['mac'] = shell_exec('ip addr show dev ' . $iface['interface'] . ' | grep "link/ether " | cut -d \' \' -f 6 | cut -f 1 -d \'/\'');
$iface['ipv4'] = shell_exec('ip addr show dev ' . $iface['interface'] . ' | grep "inet " | cut -d \' \' -f 6 | cut -f 1 -d \'/\'');
$iface['ipv6'] = shell_exec('ip -o -6 addr show ' . $iface['interface'] . ' | sed -e \'s/^.*inet6 \([^ ]\+\).*/\1/\'');
if ($iface['interface'] !== 'lo') {
$iface['status'] = shell_exec('cat /sys/class/net/' . $iface['interface'] . '/operstate');
$iface['speed'] = shell_exec('cat /sys/class/net/' . $iface['interface'] . '/speed');
if ($iface['speed'] !== '') {
$iface['speed'] = $iface['speed'] . 'Mbps';
} else {
$iface['speed'] = 'unknown';
}

$duplex = shell_exec('cat /sys/class/net/' . $iface['interface'] . '/duplex');
if ($duplex !== '') {
$iface['duplex'] = 'Duplex: ' . $duplex;
if (is_array($interfaces) || is_object($interfaces)) {
foreach ($interfaces as $interface) {
$iface = [];
$iface['interface'] = basename($interface);
$iface['mac'] = shell_exec('ip addr show dev ' . $iface['interface'] . ' | grep "link/ether " | cut -d \' \' -f 6 | cut -f 1 -d \'/\'');
$iface['ipv4'] = shell_exec('ip addr show dev ' . $iface['interface'] . ' | grep "inet " | cut -d \' \' -f 6 | cut -f 1 -d \'/\'');
$iface['ipv6'] = shell_exec('ip -o -6 addr show ' . $iface['interface'] . ' | sed -e \'s/^.*inet6 \([^ ]\+\).*/\1/\'');
if ($iface['interface'] !== 'lo') {
$iface['status'] = shell_exec('cat /sys/class/net/' . $iface['interface'] . '/operstate');
$iface['speed'] = shell_exec('cat /sys/class/net/' . $iface['interface'] . '/speed');
if ($iface['speed'] !== '') {
$iface['speed'] = $iface['speed'] . 'Mbps';
} else {
$iface['speed'] = 'unknown';
}

$duplex = shell_exec('cat /sys/class/net/' . $iface['interface'] . '/duplex');
if ($duplex !== '') {
$iface['duplex'] = 'Duplex: ' . $duplex;
} else {
$iface['duplex'] = '';
}
} else {
$iface['status'] = 'up';
$iface['speed'] = 'unknown';
$iface['duplex'] = '';
}
} else {
$iface['status'] = 'up';
$iface['speed'] = 'unknown';
$iface['duplex'] = '';
$result[] = $iface;
}
$result[] = $iface;
} else {
// ToDo: Log a warning in the nextcloud log, that it was not possible to get the interfaces due to some unkown reasons?
}

return $result;
Expand Down