Skip to content

Commit

Permalink
Update mikrotik_monitor.php
Browse files Browse the repository at this point in the history
change interface listening logic, to prevent throwing error
  • Loading branch information
Focuslinkstech committed Dec 11, 2024
1 parent 3691b6e commit 1baa4eb
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions mikrotik_monitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -391,18 +391,24 @@ function mikrotik_monitor_get_interfaces_list()
$router = $routes['2'];
$mikrotik = ORM::for_table('tbl_routers')->where('enabled', '1')->find_one($router);
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
$interfaces = $client->sendSync(new RouterOS\Request('/interface/print'));

$interfaceList = [];
foreach ($interfaces as $interface) {
$name = $interface->getProperty('name');
if (!empty($name)) {
// Escape HTML characters
$safeName = htmlspecialchars($name, ENT_QUOTES, 'UTF-8');
$interfaceList[] = $safeName;

try {
$interfaces = $client->sendSync(new RouterOS\Request('/interface/print'));
$interfaceList = [];
foreach ($interfaces as $interface) {
$name = $interface->getProperty('name');
if (!empty($name)) {
// Escape HTML characters
$safeName = htmlspecialchars($name, ENT_QUOTES, 'UTF-8');
$interfaceList[] = $safeName;
}
}
return $interfaceList;
} catch (Exception $e) {
_log('Mikrotik Monitor Error fetching interface list: ' . $e->getMessage());
sendTelegram('Mikrotik Monitor Error fetching interface list: ' . $e->getMessage());
return [];
}
return $interfaceList;
}

function mikrotik_monitor_get_traffic()
Expand Down Expand Up @@ -665,7 +671,7 @@ function mikrotik_monitor_fetchLogs($routerId)
try {
$mikrotik = ORM::for_table('tbl_routers')->where('enabled', '1')->find_one($routerId);
if (!$mikrotik) {
return [];
return [];
}

$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
Expand Down

0 comments on commit 1baa4eb

Please sign in to comment.