An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.
PHP coolifydatabasesdeploymentdockerdocker-composeinertiajslaravelmariadbmysqlnextjsnodejsphppostgresredisself-hostedself-hostingserverstatic-sitesveltesvelte5
fix: licensing
Andras Bacsai97e2a5d30bc3
diff --git a/app/Actions/License/CheckResaleLicense.php b/app/Actions/License/CheckResaleLicense.phpindex cef4e62ee9..2ce3c574a7 100644--- a/app/Actions/License/CheckResaleLicense.php+++ b/app/Actions/License/CheckResaleLicense.php@@ -4,7 +4,6 @@ namespace App\Actions\License;use App\Models\InstanceSettings;use Illuminate\Support\Facades\Http;-use Visus\Cuid2\Cuid2;class CheckResaleLicense{@@ -12,41 +11,49 @@ class CheckResaleLicense{try {$settings = InstanceSettings::get();- $instance_id = config('app.id');+ $settings->update([+ 'is_resale_license_active' => false,+ ]);if (!$settings->resale_license) {return;}- ray('Checking license key');+ $base_url = config('coolify.license_url');+ if (isDev()) {+ $base_url = 'http://host.docker.internal:8787';+ }+ $instance_id = config('app.id');++ ray("Checking license key against $base_url/lemon/validate");$data = Http::withHeaders(['Accept' => 'application/json',- ])->post('https://api.lemonsqueezy.com/v1/licenses/validate', [+ ])->get("$base_url/lemon/validate", ['license_key' => $settings->resale_license,- 'instance_name' => $instance_id,- ])->throw()->json();- $product_id = (int)data_get($data, 'meta.product_id');- $valid_product_id = (int)config('coolify.lemon_squeezy_product_id');- if ($product_id !== $valid_product_id) {- throw new \Exception('Invalid product id');+ 'instance_id' => $instance_id,+ ])->json();+ if (data_get($data, 'valid') === true && data_get($data, 'license_key.status') === 'active') {+ ray('Valid & active license key');+ $settings->update([+ 'is_resale_license_active' => true,+ ]);+ return;}- ray('Valid Product Id');-- ['valid' => $valid, 'license_key' => $license_key] = $data;-- if ($valid) {- if (data_get($license_key, 'status') === 'inactive') {- Http::withHeaders([- 'Accept' => 'application/json',- ])->post('https://api.lemonsqueezy.com/v1/licenses/activate', [- 'license_key' => $settings->resale_license,- 'instance_name' => $instance_id,- ])->throw()->json();- }+ $data = Http::withHeaders([+ 'Accept' => 'application/json',+ ])->get("$base_url/lemon/activate", [+ 'license_key' => $settings->resale_license,+ 'instance_id' => $instance_id,+ ])->json();+ if (data_get($data, 'activated') === true) {+ ray('Activated license key');$settings->update(['is_resale_license_active' => true,]);return;}- throw new \Exception('Invalid license key');+ if (data_get($data, 'license_key.status') === 'active') {+ throw new \Exception('Invalid license key.');+ }+ throw new \Exception('Cannot activate license key.');} catch (\Throwable $th) {ray($th);$settings->update([diff --git a/app/Http/Livewire/License.php b/app/Http/Livewire/License.phpdeleted file mode 100644index 14c147a878..0000000000--- a/app/Http/Livewire/License.php+++ /dev/null@@ -1,26 +0,0 @@-<?php--namespace App\Http\Livewire;--use Illuminate\Support\Facades\Cache;-use Livewire\Component;--class License extends Component-{- public string $license;- public function submit()- {- ray('checking license');- $this->validate([- 'license' => 'required'- ]);- // Pretend we're checking the license- // if ($this->license === '123') {- // ray('license is valid');- // Cache::put('license_key', '123');- // return redirect()->to('/');- // } else {- // ray('license is invalid');- // }- }-}diff --git a/config/coolify.php b/config/coolify.phpindex 0a42208876..fba1087b9e 100644--- a/config/coolify.php+++ b/config/coolify.php@@ -2,8 +2,8 @@return ['self_hosted' => env('SELF_HOSTED', true),+ 'license_url' => 'https://license.coolify.io','lemon_squeezy_webhook_secret' => env('LEMON_SQUEEZY_WEBHOOK_SECRET'),- 'lemon_squeezy_product_id' => env('LEMON_SQUEEZY_PRODUCT_ID'),'lemon_squeezy_checkout_id' => env('LEMON_SQUEEZY_CHECKOUT_ID'),'mux_enabled' => env('MUX_ENABLED', true),'dev_webhook' => env('SERVEO_URL'),diff --git a/docker-compose.prod.yml b/docker-compose.prod.ymlindex ec28418ead..0a257eb9d2 100644--- a/docker-compose.prod.yml+++ b/docker-compose.prod.yml@@ -33,7 +33,6 @@ services:- SELF_HOSTED- LEMON_SQUEEZY_WEBHOOK_SECRET- LEMON_SQUEEZY_CHECKOUT_ID- - LEMON_SQUEEZY_PRODUCT_IDports:- "${APP_PORT:-8000}:80"expose:diff --git a/resources/views/livewire/check-license.blade.php b/resources/views/livewire/check-license.blade.phpindex 8f055da817..093e637fde 100644--- a/resources/views/livewire/check-license.blade.php+++ b/resources/views/livewire/check-license.blade.php@@ -18,7 +18,7 @@</div>@if (session()->has('error'))<div class="text-error">- {{ session('error') }}+ {!! session('error') !!}</div>@endif</form>diff --git a/resources/views/livewire/license.blade.php b/resources/views/livewire/license.blade.phpdeleted file mode 100644index a367c124e2..0000000000--- a/resources/views/livewire/license.blade.php+++ /dev/null@@ -1,6 +0,0 @@-<div>- <form wire:submit.prevent='submit'>- <x-forms.input id="license" label="License Key" />- <x-forms.button type='submit'>Check</x-forms.button>- </form>-</div>diff --git a/resources/views/subscription.blade.php b/resources/views/subscription.blade.phpindex d70c8e4957..b954c165e5 100644--- a/resources/views/subscription.blade.php+++ b/resources/views/subscription.blade.php@@ -29,6 +29,6 @@Subscription</a></x-forms.button>@else- <div>Resale license is not active. Please contact your instance admin.</div>+ <div class="px-10">Resale license is not active. Please contact your instance admin.</div>@endif</x-layout-subscription>