feat: xxbb
This commit is contained in:
@@ -8,37 +8,31 @@ use Illuminate\Support\Facades\File;
|
||||
|
||||
class RawLogController extends Controller
|
||||
{
|
||||
/** @var list<string> */
|
||||
private const KINDS = ['c2', 'xxbb'];
|
||||
|
||||
public function index(Request $request)
|
||||
{
|
||||
$dir = public_path('log/c2');
|
||||
$files = [];
|
||||
if (is_dir($dir)) {
|
||||
foreach (File::files($dir) as $file) {
|
||||
if ($file->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']));
|
||||
}
|
||||
|
||||
$kind = $this->kind($request);
|
||||
$path = trim((string) $request->query('path', ''));
|
||||
$device = trim((string) $request->query('device', ''));
|
||||
|
||||
return view('admin.logs.index', compact('files', 'path', 'device'));
|
||||
$groups = [];
|
||||
foreach (self::KINDS as $k) {
|
||||
$groups[$k] = $this->listFiles($k);
|
||||
}
|
||||
|
||||
return view('admin.logs.index', compact('groups', 'kind', 'path', 'device'));
|
||||
}
|
||||
|
||||
public function show(Request $request, string $file)
|
||||
{
|
||||
$kind = $this->kind($request);
|
||||
$safe = basename($file);
|
||||
if (! preg_match('/^\d{8}\.log$/', $safe)) {
|
||||
abort(404);
|
||||
}
|
||||
$full = public_path('log/c2/'.$safe);
|
||||
$full = public_path('log/'.$kind.'/'.$safe);
|
||||
abort_unless(is_file($full), 404);
|
||||
|
||||
$path = trim((string) $request->query('path', ''));
|
||||
@@ -62,10 +56,43 @@ class RawLogController extends Controller
|
||||
$entries = array_reverse($entries);
|
||||
|
||||
return view('admin.logs.show', [
|
||||
'kind' => $kind,
|
||||
'file' => $safe,
|
||||
'entries' => $entries,
|
||||
'path' => $path,
|
||||
'device' => $device,
|
||||
]);
|
||||
}
|
||||
|
||||
private function kind(Request $request): string
|
||||
{
|
||||
$kind = (string) $request->query('kind', 'c2');
|
||||
|
||||
return in_array($kind, self::KINDS, true) ? $kind : 'c2';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list<array{name: string, size: int, mtime: string}>
|
||||
*/
|
||||
private function listFiles(string $kind): array
|
||||
{
|
||||
$dir = public_path('log/'.$kind);
|
||||
$files = [];
|
||||
if (! is_dir($dir)) {
|
||||
return $files;
|
||||
}
|
||||
foreach (File::files($dir) as $file) {
|
||||
if ($file->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']));
|
||||
|
||||
return $files;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user