You've already forked Atomcms-edit
Initial commit
This commit is contained in:
Executable
+98
@@ -0,0 +1,98 @@
|
||||
<?php
|
||||
|
||||
namespace App\Livewire;
|
||||
|
||||
use Illuminate\Support\Facades\Process;
|
||||
use Livewire\Attributes\On;
|
||||
use Livewire\Component;
|
||||
|
||||
class EmulatorLogViewer extends Component
|
||||
{
|
||||
public string $logPath = '';
|
||||
|
||||
public string $selectedFile = '';
|
||||
|
||||
public array $logFiles = [];
|
||||
|
||||
public string $logContent = '';
|
||||
|
||||
public int $lines = 100;
|
||||
|
||||
public bool $autoRefresh = true;
|
||||
|
||||
public int $refreshInterval = 5;
|
||||
|
||||
public function mount(): void
|
||||
{
|
||||
// Get log path from settings (default to logging subdirectory)
|
||||
$emulatorPath = setting('emulator_jar_path', '/var/www/Emulator');
|
||||
$this->logPath = $emulatorPath . '/logging';
|
||||
|
||||
$this->loadLogFiles();
|
||||
|
||||
if ($this->logFiles !== []) {
|
||||
$this->selectedFile = $this->logFiles[0];
|
||||
$this->loadLogContent();
|
||||
}
|
||||
}
|
||||
|
||||
#[On('refresh')]
|
||||
public function refresh(): void
|
||||
{
|
||||
$this->loadLogContent();
|
||||
}
|
||||
|
||||
public function loadLogFiles(): void
|
||||
{
|
||||
// Find log files (txt, log, and gz files)
|
||||
$result = Process::timeout(5)->run("find {$this->logPath} -name '*.txt' -o -name '*.log' -o -name '*.log.*' 2>/dev/null | sort -r | head -20");
|
||||
|
||||
if ($result->successful()) {
|
||||
$files = explode("\n", trim($result->output()));
|
||||
$this->logFiles = array_filter($files, fn ($f) => ! empty($f) && ! str_contains((string) $f, '.gz'));
|
||||
}
|
||||
}
|
||||
|
||||
public function loadLogContent(): void
|
||||
{
|
||||
if ($this->selectedFile === '' || $this->selectedFile === '0') {
|
||||
$this->logContent = 'Geen log bestand geselecteerd';
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$result = Process::timeout(10)->run("tail -n {$this->lines} {$this->selectedFile} 2>/dev/null");
|
||||
|
||||
if ($result->successful()) {
|
||||
$this->logContent = $result->output() ?: 'Log bestand is leeg';
|
||||
} else {
|
||||
$this->logContent = 'Fout bij lezen van log bestand';
|
||||
}
|
||||
}
|
||||
|
||||
public function selectFile(string $file): void
|
||||
{
|
||||
$this->selectedFile = $file;
|
||||
$this->loadLogContent();
|
||||
}
|
||||
|
||||
public function clearLog(): void
|
||||
{
|
||||
if ($this->selectedFile !== '' && $this->selectedFile !== '0') {
|
||||
Process::timeout(5)->run("sudo truncate -s 0 {$this->selectedFile} 2>/dev/null");
|
||||
$this->loadLogContent();
|
||||
}
|
||||
}
|
||||
|
||||
public function downloadLog()
|
||||
{
|
||||
if ($this->selectedFile !== '' && $this->selectedFile !== '0') {
|
||||
return response()->download($this->selectedFile);
|
||||
}
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
return view('livewire.emulator-log-viewer');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user