Added license management module
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class GenerateLicenseKeysCommand extends Command
|
||||
{
|
||||
protected $signature = 'license:generate-keys {--force : Overwrite existing key pair}';
|
||||
|
||||
protected $description = 'Generate a new application-wide license signing key pair.';
|
||||
|
||||
public function handle(): int
|
||||
{
|
||||
$directory = 'license-keys';
|
||||
$privateKeyPath = $directory . '/private.pem';
|
||||
$publicKeyPath = $directory . '/public.pem';
|
||||
$disk = Storage::disk('local');
|
||||
|
||||
$privateExists = $disk->exists($privateKeyPath);
|
||||
$publicExists = $disk->exists($publicKeyPath);
|
||||
|
||||
if (($privateExists || $publicExists) && !$this->option('force')) {
|
||||
$this->error('Key pair already exists. Use --force to overwrite.');
|
||||
return 1;
|
||||
}
|
||||
|
||||
$keyPair = $this->generateKeyPair();
|
||||
$disk->put($privateKeyPath, $keyPair['privateKey']);
|
||||
$disk->put($publicKeyPath, $keyPair['publicKey']);
|
||||
|
||||
$this->info('Generated application license key pair.');
|
||||
$this->line('Private key: ' . $privateKeyPath);
|
||||
$this->line('Public key: ' . $publicKeyPath);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
protected function generateKeyPair(): array
|
||||
{
|
||||
$privateKey = openssl_pkey_new([
|
||||
'private_key_bits' => 2048,
|
||||
'private_key_type' => OPENSSL_KEYTYPE_RSA,
|
||||
]);
|
||||
|
||||
openssl_pkey_export($privateKey, $privateKeyPem);
|
||||
$publicKeyDetails = openssl_pkey_get_details($privateKey);
|
||||
|
||||
return [
|
||||
'privateKey' => $privateKeyPem,
|
||||
'publicKey' => $publicKeyDetails['key'],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -15,6 +15,7 @@ class Kernel extends ConsoleKernel
|
||||
protected $commands = [
|
||||
\App\Console\Commands\CaldavSyncCommand::class,
|
||||
\App\Console\Commands\CheckInvoiceDueDatesCommand::class,
|
||||
\App\Console\Commands\GenerateLicenseKeysCommand::class,
|
||||
];
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user