diff --git a/app/Console/Commands/Server.php b/app/Console/Commands/Server.php new file mode 100644 index 0000000..e7d859e --- /dev/null +++ b/app/Console/Commands/Server.php @@ -0,0 +1,73 @@ +info("Can't get hostname"); + return self::FAILURE; + } + + //Used cache + $size = $this->getUsedCached(); + + $server = \App\Models\Server::query()->where("servername", "=", $hostname)->first(); + + if(is_null($server)) { + $server = new \App\Models\Server(); + $server->servername = $hostname; + $server->storage = disk_free_space(storage_path("cache")) - (1024*1000000) + $size; + } + $server->last_seen = date("Y-m-d H:i:s"); + $server->userd = $size; + $server->saveOrFail(); + + + return 0; + } + + private function getUsedCached() { + $r = \Illuminate\Support\Facades\Storage::disk("cache")->allFiles(); + $size = 0; + foreach ($r as $item) { + $size += \Illuminate\Support\Facades\Storage::disk("cache")->size($item); + } + return $size; + } +} diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index 49feb83..10a0953 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -6,6 +6,7 @@ use App\Console\Commands\CalculateSpace; use App\Console\Commands\CalculateTraffic; use App\Console\Commands\EXIFRead; use App\Console\Commands\ImageCacheAll; +use App\Console\Commands\Server; use App\Console\Commands\ThemesScann; use App\Console\Commands\ThemesScannTenant; use App\Console\Commands\UserAdmin; @@ -25,7 +26,8 @@ class Kernel extends ConsoleKernel ImageCacheAll::class, EXIFRead::class, UserAdmin::class, - ThemesScann::class + ThemesScann::class, + Server::class ]; /** @@ -41,6 +43,7 @@ class Kernel extends ConsoleKernel $schedule->command('calculate:traffic')->everyFiveMinutes()->withoutOverlapping(); $schedule->command('exit:read')->everyMinute()->withoutOverlapping(); $schedule->command('theme:scan')->everyMinute()->withoutOverlapping(); + $schedule->command("server:set")->everyMinute()->withoutOverlapping(); } /** diff --git a/app/Http/Controllers/AdminController.php b/app/Http/Controllers/AdminController.php index f18ac13..821acb5 100644 --- a/app/Http/Controllers/AdminController.php +++ b/app/Http/Controllers/AdminController.php @@ -2,12 +2,14 @@ namespace App\Http\Controllers; +use App\Models\Server; use App\Models\Theme; use Illuminate\Foundation\Auth\Access\AuthorizesRequests; use Illuminate\Foundation\Bus\DispatchesJobs; use Illuminate\Foundation\Validation\ValidatesRequests; use Illuminate\Http\Request; use Illuminate\Routing\Controller as BaseController; +use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Redirect; class AdminController extends BaseController @@ -27,6 +29,13 @@ class AdminController extends BaseController $theme->img_pixel = (bool)$request->input("img_pixel", false); $theme->saveOrFail(); return Redirect::back(); + } + public function serverView() { + if(Auth::user()->typ != "admin") { + abort(401); + } + $servers = Server::query()->get(); + return view("admin.servers", ["servers" => $servers]); } } diff --git a/app/Models/Server.php b/app/Models/Server.php new file mode 100644 index 0000000..4fcb18c --- /dev/null +++ b/app/Models/Server.php @@ -0,0 +1,42 @@ +id(); + $table->timestamps(); + $table->string("servername"); + $table->timestamp("last_seen")->nullable(); + $table->bigInteger("storage")->comment("In Byte, for cache"); + $table->bigInteger("userd")->comment("Userd Space in Byte")->nullable(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists("servers"); + } +} diff --git a/resources/views/admin/servers.blade.php b/resources/views/admin/servers.blade.php new file mode 100644 index 0000000..5170de0 --- /dev/null +++ b/resources/views/admin/servers.blade.php @@ -0,0 +1,33 @@ +@extends('layout/template') + +@section('content') + +
Servername | +Storage | +
---|---|
{{ $s->servername }} | +
+
+
+
+ |
+