@extends('layouts.app') @section('title', 'User Connection Logs - ISP ERP System') @section('page-title', 'User Connection Logs Management') @section('styles') @endsection @section('content')
Track user connections and disconnections from MikroTik servers
Total Logs
Connections
Disconnections
Unique Users
| SL | Username | Action | Status | Server | IP Address | Session ID | Connected At | Disconnected At | Uptime | Duration | Data (In/Out) | Created | Actions |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| {{ ($logs->currentPage() - 1) * $logs->perPage() + $loop->iteration }} |
{{ $log->username }}
@if($log->client)
{{ $log->client->name ?? '' }} @endif |
@if($log->action == 'connect') Connect @else Disconnect @endif | @php // Determine status for connect logs $status = 'N/A'; $statusBadge = 'secondary'; if ($log->action == 'connect') { // Check if this connect log has a disconnect log $hasDisconnect = false; if ($log->session_id) { $hasDisconnect = \App\Models\UserConnectionLog::where('username', $log->username) ->where('session_id', $log->session_id) ->where('action', 'disconnect') ->where('created_at', '>', $log->created_at) ->exists(); } // Check if user is currently active in ANY MikroTik server (has live uptime data) // Try exact match first, then case-insensitive match $isActive = false; if (isset($liveUptimeData) && is_array($liveUptimeData)) { // Try exact match first if (isset($liveUptimeData[$log->username])) { $isActive = true; } else { // Try case-insensitive match foreach ($liveUptimeData as $username => $uptime) { if (strtolower($username) === strtolower($log->username)) { $isActive = true; break; } } } } if ($isActive && !$hasDisconnect) { // User is currently active in at least one server $status = 'Active'; $statusBadge = 'success'; } elseif (!$hasDisconnect) { // User was connected but now disconnected (no disconnect log, no live uptime from any server) $status = 'Disconnected'; $statusBadge = 'danger'; } else { // Has disconnect log $status = 'Disconnected'; $statusBadge = 'warning'; } } else { // Disconnect action $status = 'Disconnected'; $statusBadge = 'warning'; } @endphp @if($status != 'N/A') @if($status == 'Active') @else @endif {{ $status }} @else {{ $status }} @endif | @if($log->mikrotikServer) {{ $log->mikrotikServer->name }} @else N/A @endif |
@if($log->ip_address)
{{ $log->ip_address }}
@else
N/A
@endif
|
@if($log->session_id)
{{ $log->session_id }}
@else
N/A
@endif
|
@if($log->connected_at) {{ $log->connected_at->format('M d, Y H:i:s') }} @else N/A @endif | @if($log->disconnected_at) {{ $log->disconnected_at->format('M d, Y H:i:s') }} @else N/A @endif | @php // Check if this connect log has a disconnect log $hasDisconnect = false; if ($log->action == 'connect' && $log->session_id) { $hasDisconnect = \App\Models\UserConnectionLog::where('username', $log->username) ->where('session_id', $log->session_id) ->where('action', 'disconnect') ->where('created_at', '>', $log->created_at) ->exists(); } // Check if we have live uptime data from MikroTik $mikrotikUptime = isset($liveUptimeData) && isset($liveUptimeData[$log->username]) ? $liveUptimeData[$log->username] : null; if ($log->action == 'connect' && !$hasDisconnect && $mikrotikUptime) { // Use MikroTik's actual uptime string format (e.g., "1d2h3m4s") // Keep the original format without converting days to hours $uptime = $mikrotikUptime; } elseif ($log->action == 'connect' && !$hasDisconnect && $log->connected_at) { // Fallback: calculate from connected_at timestamp $uptimeSeconds = now()->diffInSeconds($log->connected_at); $totalHours = floor($uptimeSeconds / 3600); $minutes = floor(($uptimeSeconds % 3600) / 60); $seconds = $uptimeSeconds % 60; if ($totalHours > 0) { $uptime = sprintf('%dh %dm %ds', $totalHours, $minutes, $seconds); } elseif ($minutes > 0) { $uptime = sprintf('%dm %ds', $minutes, $seconds); } else { $uptime = sprintf('%ds', $seconds); } } @endphp @if($log->action == 'connect' && !$hasDisconnect && isset($uptime)) @if($mikrotikUptime) {{ $uptime }} @else {{ $uptime }} @endif @elseif($log->duration_seconds) {{ $log->formatted_duration }} @else N/A @endif | @if($log->duration_seconds) {{ $log->formatted_duration }} @else N/A @endif |
@if($log->bytes_in || $log->bytes_out)
In: {{ number_format($log->bytes_in ?? 0) }} Out: {{ number_format($log->bytes_out ?? 0) }} @else N/A @endif |
{{ $log->created_at->format('M d, Y H:i') }} |
Start by creating your first connection log or run the monitoring command.
Create Connection Log