mirror of
https://github.com/VueFileManager/vuefilemanager.git
synced 2026-04-30 19:45:59 +00:00
ability to download log from admin
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http;
|
||||
|
||||
use Fruitcake\Cors\HandleCors;
|
||||
use Support\Middleware\AdminCheck;
|
||||
use Support\Middleware\TrimStrings;
|
||||
use Support\Middleware\TrustProxies;
|
||||
use Support\Middleware\EncryptCookies;
|
||||
@@ -75,6 +77,7 @@ class Kernel extends HttpKernel
|
||||
'signed' => \Illuminate\Routing\Middleware\ValidateSignature::class,
|
||||
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
|
||||
'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class,
|
||||
'admin' => AdminCheck::class,
|
||||
'setup-wizard' => ProtectSetupWizardRoutes::class,
|
||||
'upload-request' => ProtectUploadRequestRoutes::class,
|
||||
];
|
||||
|
||||
@@ -48,7 +48,7 @@ class RouteServiceProvider extends ServiceProvider
|
||||
->group(base_path('routes/upload-request.php'));
|
||||
|
||||
Route::prefix('api/admin')
|
||||
->middleware(['api', 'auth:sanctum'])
|
||||
->middleware(['api', 'auth:sanctum', 'admin'])
|
||||
->group(base_path('routes/admin.php'));
|
||||
|
||||
Route::middleware(['setup-wizard'])
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace Domain\Settings\Controllers;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Contracts\Foundation\Application;
|
||||
use Illuminate\Contracts\Routing\ResponseFactory;
|
||||
use Illuminate\Http\Response;
|
||||
use Illuminate\Support\Facades\File;
|
||||
use Symfony\Component\HttpFoundation\BinaryFileResponse;
|
||||
|
||||
class DownloadLogController extends Controller
|
||||
{
|
||||
public function __invoke($log): Response|BinaryFileResponse|Application|ResponseFactory
|
||||
{
|
||||
if (is_demo()) {
|
||||
return response('Done.', 204);
|
||||
}
|
||||
|
||||
// Get log path
|
||||
$logPath = storage_path("logs/$log");
|
||||
|
||||
// Download log
|
||||
return response()->download(
|
||||
storage_path("logs/$log"), $log, [
|
||||
'Accept-Ranges' => 'bytes',
|
||||
'Content-Type' => 'text/plain',
|
||||
'Content-Length' => File::size($logPath),
|
||||
'Content-Range' => 'bytes 0-600/' . File::size($logPath),
|
||||
'Content-Disposition' => "attachment; filename=$log",
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -16,6 +16,9 @@ class GetServerStatusController
|
||||
// Get server data
|
||||
$status = ($this->getServerSetupStatus)();
|
||||
|
||||
// Get latest logs
|
||||
$status['logs'] = getListOfLatestLogs();
|
||||
|
||||
// Add latest database backups
|
||||
$status['backups'] = collect(Storage::allFiles('app-backup'))
|
||||
->map(fn ($path) => str_replace('app-backup/', '', $path))
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace Support\Middleware;
|
||||
|
||||
use Closure;
|
||||
|
||||
class AdminCheck
|
||||
{
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle($request, Closure $next)
|
||||
{
|
||||
// Check if user have access to administration settings
|
||||
if ( $request->user()->role !== 'admin') {
|
||||
abort(403, 'You don\'t have access for this operation!');
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,22 @@ use Domain\Localization\Models\Language;
|
||||
use Intervention\Image\ImageManagerStatic as Image;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
|
||||
if (! function_exists('getListOfLatestLogs')) {
|
||||
/**
|
||||
* Check if cron is running
|
||||
*/
|
||||
function getListOfLatestLogs(): array
|
||||
{
|
||||
return array_slice(
|
||||
array_reverse(
|
||||
array_filter(
|
||||
scandir(storage_path() . '/logs'), fn($fn) => !str_starts_with($fn, '.')
|
||||
)
|
||||
), 0, 5, true
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (! function_exists('isRunningCron')) {
|
||||
/**
|
||||
* Check if cron is running
|
||||
|
||||
Reference in New Issue
Block a user