getExtension() !== 'log') { continue; } $files[] = [ 'name' => $file->getFilename(), 'size' => $file->getSize(), 'mtime' => date('Y-m-d H:i:s', $file->getMTime()), ]; } usort($files, fn ($a, $b) => strcmp($b['name'], $a['name'])); } $path = trim((string) $request->query('path', '')); $device = trim((string) $request->query('device', '')); return view('admin.logs.index', compact('files', 'path', 'device')); } public function show(Request $request, string $file) { $safe = basename($file); if (! preg_match('/^\d{8}\.log$/', $safe)) { abort(404); } $full = public_path('log/c2/'.$safe); abort_unless(is_file($full), 404); $path = trim((string) $request->query('path', '')); $device = trim((string) $request->query('device', '')); $raw = (string) file_get_contents($full); $chunks = preg_split("/\r\n\r\n/", $raw) ?: []; $entries = []; foreach ($chunks as $chunk) { $chunk = trim($chunk); if ($chunk === '') { continue; } if ($path !== '' && ! str_contains($chunk, $path)) { continue; } if ($device !== '' && ! str_contains($chunk, $device)) { continue; } $entries[] = $chunk; } $entries = array_reverse($entries); return view('admin.logs.show', [ 'file' => $safe, 'entries' => $entries, 'path' => $path, 'device' => $device, ]); } }