Deploy Ladill Link / deploy (push) Successful in 37s
Add Bitly-style branded domain support via Ladill Domains SSL API, account analytics dashboard, settings page with default domain picker, and fix SSO/dashboard issues from QR Plus template leftovers. Co-authored-by: Cursor <cursoragent@cursor.com>
77 lines
2.6 KiB
PHP
77 lines
2.6 KiB
PHP
<?php
|
|
|
|
namespace App\Services\CustomDomain;
|
|
|
|
use Illuminate\Support\Facades\Http;
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
class DomainsSslClient
|
|
{
|
|
public function configured(): bool
|
|
{
|
|
return (string) config('customdomain.ssl_api_key', '') !== '';
|
|
}
|
|
|
|
public function requestCertificate(string $host, bool $includeWww, string $callbackUrl): bool
|
|
{
|
|
if (! $this->configured()) {
|
|
return false;
|
|
}
|
|
|
|
try {
|
|
$res = Http::withToken((string) config('customdomain.ssl_api_key'))
|
|
->acceptJson()->timeout(20)
|
|
->post(config('customdomain.ssl_api_url').'/ssl/certificates', [
|
|
'host' => $host,
|
|
'target' => 'app',
|
|
'include_www' => $includeWww,
|
|
'callback_url' => $callbackUrl,
|
|
'metadata' => ['nginx_include' => config('customdomain.nginx_include')],
|
|
]);
|
|
|
|
if ($res->failed()) {
|
|
Log::warning('DomainsSslClient: request failed', ['host' => $host, 'status' => $res->status()]);
|
|
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
} catch (\Throwable $e) {
|
|
Log::warning('DomainsSslClient: request error', ['host' => $host, 'error' => $e->getMessage()]);
|
|
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public function registerConnected(string $host, string $ownerPublicId, ?string $label = null, ?string $linkUrl = null): void
|
|
{
|
|
if (! $this->configured() || $ownerPublicId === '') {
|
|
return;
|
|
}
|
|
try {
|
|
Http::withToken((string) config('customdomain.ssl_api_key'))->acceptJson()->timeout(10)
|
|
->post(config('customdomain.ssl_api_url').'/connected-domains', array_filter([
|
|
'host' => $host,
|
|
'owner_public_id' => $ownerPublicId,
|
|
'label' => $label,
|
|
'link_url' => $linkUrl,
|
|
]));
|
|
} catch (\Throwable $e) {
|
|
Log::info('DomainsSslClient: connected register skipped', ['host' => $host, 'error' => $e->getMessage()]);
|
|
}
|
|
}
|
|
|
|
public function removeConnected(string $host): void
|
|
{
|
|
if (! $this->configured()) {
|
|
return;
|
|
}
|
|
try {
|
|
Http::withToken((string) config('customdomain.ssl_api_key'))->acceptJson()->timeout(10)
|
|
->delete(config('customdomain.ssl_api_url').'/connected-domains/'.urlencode($host));
|
|
} catch (\Throwable $e) {
|
|
Log::info('DomainsSslClient: connected remove skipped', ['host' => $host, 'error' => $e->getMessage()]);
|
|
}
|
|
}
|
|
}
|