Skip to content

Commit

Permalink
Refactor code to use new function to get wireless clients info
Browse files Browse the repository at this point in the history
- See issue #128.
  • Loading branch information
martignoni committed Dec 2, 2023
1 parent b793707 commit 84d8120
Showing 1 changed file with 6 additions and 19 deletions.
25 changes: 6 additions & 19 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,22 +135,10 @@
// Get CPU load.
$cpuload = sys_getloadavg();

// Get DHCP leases.
if ($networkmanager) {
$moodleboxleasesfile = '/tmp/dnsmasq.leases';
} else {
$moodleboxleasesfile = '/var/lib/misc/dnsmasq.leases';
}
if ( file_exists($moodleboxleasesfile) ) {
if ( filesize($moodleboxleasesfile) > 0 ) {
$leases = explode(PHP_EOL, trim(file_get_contents($moodleboxleasesfile)));
} else {
$leases = [];
}
$dhcpclientnumber = count($leases);
} else {
$dhcpclientnumber = 0;
}
// Get IP addresses of connected clients.
$interface = 'uap0';
$leases = \tool_moodlebox\local\utils::get_connected_ip_adresses($interface);
$dhcpclientnumber = count($leases);

// Get local static IP address.
$staticipaddress = gethostbyname(gethostname());
Expand Down Expand Up @@ -269,10 +257,9 @@
if ($dhcpclientnumber > 0) {
$table->add_data([get_string('dhcpclients', 'tool_moodlebox') .
' (' . get_string('dhcpclientnumber', 'tool_moodlebox') . ': ' . $dhcpclientnumber . ')', '', ]);
foreach ($leases as $row) {
$item = explode(' ', $row);
foreach ($leases as $mac => $ip) {
$table->add_data([get_string('dhcpclientinfo', 'tool_moodlebox'),
$item[2] . ' (' . $item[3] . ')', ], 'subinfo');
$ip . ' (' . $mac . ')', ], 'subinfo');
}
}
// Ethernet info.
Expand Down

0 comments on commit 84d8120

Please sign in to comment.