mirror of
https://github.com/mivodev/mivo.git
synced 2026-01-26 13:31:56 +07:00
Initial Release v1.0.0: Full feature set with Docker automation, Nginx/Alpine stack
This commit is contained in:
55
app/Controllers/LogController.php
Normal file
55
app/Controllers/LogController.php
Normal file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers;
|
||||
|
||||
use App\Core\Controller;
|
||||
use App\Models\Config;
|
||||
use App\Libraries\RouterOSAPI;
|
||||
|
||||
class LogController extends Controller
|
||||
{
|
||||
public function index($session)
|
||||
{
|
||||
$configModel = new Config();
|
||||
$config = $configModel->getSession($session);
|
||||
if (!$config) return header('Location: /');
|
||||
|
||||
$logs = [];
|
||||
$API = new RouterOSAPI();
|
||||
$API->attempts = 1;
|
||||
$API->timeout = 3;
|
||||
|
||||
if ($API->connect($config['ip_address'], $config['username'], $config['password'])) {
|
||||
// Fetch Hotspot Logs
|
||||
// /log/print where topics~hotspot
|
||||
// In API we can't always filter effectively by topic in all versions,
|
||||
// but we can try ?topics=hotspot,info or similar.
|
||||
// Safe bet: fetch last 100 logs and filter PHP side or use API filter if possible.
|
||||
// Using a limit to avoid timeout.
|
||||
|
||||
// Getting generic logs for now, filtered by topic 'hotspot' if possible.
|
||||
// RouterOS API query for array search: ?topics=hotspot
|
||||
|
||||
$logs = $API->comm("/log/print", [
|
||||
"?topics" => "hotspot,info,debug", // Try detailed match
|
||||
]);
|
||||
|
||||
// Fallback if strict match fails, just get recent logs
|
||||
if (empty($logs) || isset($logs['!trap'])) {
|
||||
$logs = $API->comm("/log/print", []); // Get all (capped usually by buffer)
|
||||
}
|
||||
|
||||
// Reverse to show newest first
|
||||
if (is_array($logs)) {
|
||||
$logs = array_reverse($logs);
|
||||
}
|
||||
|
||||
$API->disconnect();
|
||||
}
|
||||
|
||||
return $this->view('reports/user_log', [
|
||||
'session' => $session,
|
||||
'logs' => $logs
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user