diff --git a/app/Http/Controllers/ConnectionController.php b/app/Http/Controllers/ConnectionController.php index 60a77ac..cd1cd74 100644 --- a/app/Http/Controllers/ConnectionController.php +++ b/app/Http/Controllers/ConnectionController.php @@ -4,6 +4,7 @@ use App\Http\Requests\ConnectRequest; use App\Http\Services\ConnectionService; +use App\Http\Services\LicenseService; use Illuminate\Http\JsonResponse; use Symfony\Component\HttpFoundation\Response; use Knuckles\Scribe\Attributes as SA; @@ -29,4 +30,12 @@ public function connect(ConnectRequest $request, ConnectionService $service): Js $service->connect($request->validated('connection')) ); } + + public function test(): JsonResponse + { + $jwt = request()->input('license'); + return response()->json( + LicenseService::checkAvailableNewThread($jwt, 5) + ); + } } diff --git a/app/Http/Requests/ConnectRequest.php b/app/Http/Requests/ConnectRequest.php index d2d6f72..5f98f2b 100644 --- a/app/Http/Requests/ConnectRequest.php +++ b/app/Http/Requests/ConnectRequest.php @@ -15,8 +15,22 @@ public function authorize(): bool public function rules(): array { - return [ + $rules = [ 'connection' => ['uuid', 'exists:connections,id'], ]; + if (config('slonik.check_license')) { + $rules['license'] = ['required', 'string']; + } + + return $rules; + } + + public function messages(): array + { + return [ + 'license.required' => 'Необходимо указать лицензию', + 'connection.exists' => 'Такого подключения не существует', + 'connection.uuid' => 'Неверный формат ID подключения', + ]; } } diff --git a/app/Http/Services/LicenseService.php b/app/Http/Services/LicenseService.php new file mode 100644 index 0000000..d180f2d --- /dev/null +++ b/app/Http/Services/LicenseService.php @@ -0,0 +1,22 @@ +connections; + return $threadsCount < $connections; + } + + private static function decodeJWT(string $jwt): \stdClass + { + return JWT::decode($jwt, new Key(config('slonik.jwt_key'), 'HS256')); + } + +} diff --git a/app/MoonShine/Resources/ConnectionResource.php b/app/MoonShine/Resources/ConnectionResource.php index 7478551..5f78b55 100644 --- a/app/MoonShine/Resources/ConnectionResource.php +++ b/app/MoonShine/Resources/ConnectionResource.php @@ -22,8 +22,11 @@ class ConnectionResource extends ModelResource { protected string $model = Connection::class; - protected string $title = 'Соединения'; + protected function onBoot(): void + { + $this->formPage()->setTitle(__('slonik.connections_title')); + } public function getActiveActions(): array { @@ -42,22 +45,22 @@ public function fields(): array } return [ ID::make()->sortable(), - Date::make('Настройки получены','last_connection')->sortable()->readonly()->hideOnUpdate(), - Block::make('Настройки',[ - Number::make('Количество потоков', 'threads_count')->max(64)->step(1)->hideOnIndex(), - Select::make('Разрешение', 'thread_resolution')->options([ + Date::make(__('slonik.last_connection'),'last_connection')->sortable()->readonly()->hideOnUpdate(), + Block::make(__('slonik.settings.title'),[ + Number::make(__('slonik.settings.threads_count'), 'threads_count')->max(64)->step(1)->hideOnIndex(), + Select::make(__('slonik.settings.resolution'), 'thread_resolution')->options([ '480p' => '480p', '720p' => '720p', '1080p' => '1080p', ])->hideOnIndex(), - Select::make('Частота кадров', 'thread_framerate')->options([ + Select::make(__('slonik.settings.thread_framerate'), 'thread_framerate')->options([ 10 => 10, 15 => 15, 25 => 25, 30 => 30 ])->hideOnIndex(), - Switcher::make('Подсветка активного монитора', 'highlight_active_tread')->hideOnIndex(), - Switcher::make('Подсветка зоны указателя мыши', 'highlight_mouse_pointer_area')->hideOnIndex(), + Switcher::make(__('slonik.settings.highlight_active_tread'), 'highlight_active_tread')->hideOnIndex(), + Switcher::make(__('slonik.settings.highlight_mouse_pointer_area'), 'highlight_mouse_pointer_area')->hideOnIndex(), ]), ]; } @@ -66,4 +69,10 @@ public function rules(Model $item): array { return []; } + + public function getTitle(): ConnectionResource + { + $this->title = __('auth.failed'); + return $this; + } } diff --git a/app/Providers/MoonShineServiceProvider.php b/app/Providers/MoonShineServiceProvider.php index 7646e80..067eca9 100644 --- a/app/Providers/MoonShineServiceProvider.php +++ b/app/Providers/MoonShineServiceProvider.php @@ -31,7 +31,8 @@ protected function pages(): array protected function menu(): array { return [ - MenuItem::make('Соединения', new ConnectionResource()), + MenuItem::make('slonik.connections_title', new ConnectionResource()) + ->translatable(), ]; } diff --git a/composer.json b/composer.json index a1f96ea..da326b6 100644 --- a/composer.json +++ b/composer.json @@ -7,6 +7,7 @@ "require": { "php": "^8.1", "bensampo/laravel-enum": "^6.11", + "firebase/php-jwt": "^6.10", "guzzlehttp/guzzle": "^7.2", "laravel/framework": "^10.10", "laravel/sanctum": "^3.3", diff --git a/composer.lock b/composer.lock index 00eaf78..1666d2c 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "7a4526a2edd45b46e4fbabc97bd4f9a1", + "content-hash": "1de365895cfbd646ac67f03fb9e81b04", "packages": [ { "name": "bensampo/laravel-enum", @@ -750,6 +750,69 @@ ], "time": "2023-10-06T06:47:41+00:00" }, + { + "name": "firebase/php-jwt", + "version": "v6.10.1", + "source": { + "type": "git", + "url": "https://github.com/firebase/php-jwt.git", + "reference": "500501c2ce893c824c801da135d02661199f60c5" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/firebase/php-jwt/zipball/500501c2ce893c824c801da135d02661199f60c5", + "reference": "500501c2ce893c824c801da135d02661199f60c5", + "shasum": "" + }, + "require": { + "php": "^8.0" + }, + "require-dev": { + "guzzlehttp/guzzle": "^7.4", + "phpspec/prophecy-phpunit": "^2.0", + "phpunit/phpunit": "^9.5", + "psr/cache": "^2.0||^3.0", + "psr/http-client": "^1.0", + "psr/http-factory": "^1.0" + }, + "suggest": { + "ext-sodium": "Support EdDSA (Ed25519) signatures", + "paragonie/sodium_compat": "Support EdDSA (Ed25519) signatures when libsodium is not present" + }, + "type": "library", + "autoload": { + "psr-4": { + "Firebase\\JWT\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Neuman Vong", + "email": "neuman+pear@twilio.com", + "role": "Developer" + }, + { + "name": "Anant Narayanan", + "email": "anant@php.net", + "role": "Developer" + } + ], + "description": "A simple library to encode and decode JSON Web Tokens (JWT) in PHP. Should conform to the current spec.", + "homepage": "https://github.com/firebase/php-jwt", + "keywords": [ + "jwt", + "php" + ], + "support": { + "issues": "https://github.com/firebase/php-jwt/issues", + "source": "https://github.com/firebase/php-jwt/tree/v6.10.1" + }, + "time": "2024-05-18T18:05:11+00:00" + }, { "name": "fruitcake/php-cors", "version": "v1.3.0", diff --git a/config/app.php b/config/app.php index b274c3f..09b1906 100644 --- a/config/app.php +++ b/config/app.php @@ -83,7 +83,7 @@ | */ - 'locale' => 'ru', + 'locale' => 'en', /* |-------------------------------------------------------------------------- diff --git a/config/moonshine.php b/config/moonshine.php index 4031ca0..280ab2f 100644 --- a/config/moonshine.php +++ b/config/moonshine.php @@ -91,7 +91,7 @@ 'pipelines' => [], ], 'locales' => [ - 'ru', + 'ru','en' ], 'global_search' => [ diff --git a/config/slonik.php b/config/slonik.php index 4215bd4..cbd52f9 100644 --- a/config/slonik.php +++ b/config/slonik.php @@ -9,4 +9,6 @@ 'highlightActiveTread' => true, 'highlightMousePointerArea' => true, ], + 'jwt_key' => 'X4Ma8mAwZDcTodT6', + 'check_license' => false, ]; diff --git a/lang/en/slonik.php b/lang/en/slonik.php new file mode 100644 index 0000000..ed7f728 --- /dev/null +++ b/lang/en/slonik.php @@ -0,0 +1,13 @@ + 'Connections', + 'last_connection' => 'Last connection', + 'settings' => [ + 'title' => 'Settings', + 'threads_count' => 'Threads count', + 'resolution' => 'Resolution', + 'thread_framerate' => 'Thread framerate', + 'highlight_active_tread' => 'Highlight active tread', + 'highlight_mouse_pointer_area' => 'Highlight mouse pointer area', + ] +]; diff --git a/lang/ru/slonik.php b/lang/ru/slonik.php new file mode 100644 index 0000000..9cc2200 --- /dev/null +++ b/lang/ru/slonik.php @@ -0,0 +1,13 @@ + 'Соединения', + 'last_connection' => 'Последнее подключение', + 'settings' => [ + 'title' => 'Настройки', + 'threads_count' => 'Количество потоков', + 'resolution' => 'Разрешение', + 'thread_framerate' => 'Частота кадров', + 'highlight_active_tread' => 'Подсветка активного монитора', + 'highlight_mouse_pointer_area' => 'Подсветка зоны указателя мыши', + ] +]; diff --git a/routes/api.php b/routes/api.php index 2493d6a..e456502 100644 --- a/routes/api.php +++ b/routes/api.php @@ -9,3 +9,4 @@ // Проверка лицензии и подключение Route::post('/connect', [ConnectionController::class, 'connect']); +Route::post('/test', [ConnectionController::class, 'test']);