<?php
 namespace App\Http\Controllers\Admin; use App\Http\Controllers\Controller; use App\Models\Setting; use App\Services\License\LicenseService; use Illuminate\Http\Request; class SystemLicenseController extends Controller { public function index(LicenseService $license) { return view('admin.system.license.index', [ 'state' => $license->state(), 'mode' => Setting::getValue('license_mode') ?: config('license.mode', 'self'), 'serverUrl' => Setting::getValue('license_server_url') ?: config('license.server_url', ''), 'keyMasked' => $this->maskKey((string) config('license.key', '')), 'downstream' => $license->downstreamEndpoint(), ]); } public function update(Request $request) { $data = $request->validate([ 'mode' => ['required', 'in:self,client'], 'server_url' => ['nullable', 'url', 'max:255'], ]); if ($data['mode'] === 'client' && empty($data['server_url'])) { return back()->with('error', __('admin/license.err_server_required')); } Setting::set('license_mode', $data['mode']); Setting::set('license_server_url', rtrim((string) ($data['server_url'] ?? ''), '/')); return back()->with('success', __('admin/license.saved')); } public function test(LicenseService $license) { $fresh = $license->refresh(); if ($fresh === null) { return back()->with('error', __('admin/license.test_unreachable')); } $payload = (array) ($fresh['payload'] ?? []); if (! empty($payload['valid'])) { return back()->with('success', __('admin/license.test_valid', ['status' => $payload['status'] ?? 'active'])); } return back()->with('error', __('admin/license.test_invalid', ['status' => $payload['status'] ?? 'invalid'])); } private function maskKey(string $key): string { return $key === '' ? '—' : \Illuminate\Support\Str::mask($key, '*', 6); } } 