Ask for email when generating LetsEncrypt SSLs (#452)

This commit is contained in:
Saeed Vaziry
2025-01-29 21:00:43 +01:00
committed by GitHub
parent 270928af13
commit 53e20cbc2a
7 changed files with 59 additions and 5 deletions

View File

@ -30,6 +30,7 @@ public function create(Site $site, array $input): void
'pk' => $input['private'] ?? null,
'expires_at' => $input['type'] === SslType::LETSENCRYPT ? now()->addMonths(3) : $input['expires_at'],
'status' => SslStatus::CREATING,
'email' => $input['email'] ?? null,
]);
$ssl->domains = [$site->domain];
if (isset($input['aliases']) && $input['aliases']) {
@ -69,6 +70,12 @@ public static function rules(array $input): array
'after_or_equal:'.now(),
];
}
if (isset($input['type']) && $input['type'] == SslType::LETSENCRYPT) {
$rules['email'] = [
'required',
'email',
];
}
return $rules;
}

View File

@ -20,6 +20,7 @@
* @property string $ca_path
* @property ?array $domains
* @property int $log_id
* @property string $email
* @property ?ServerLog $log
*/
class Ssl extends AbstractModel
@ -36,6 +37,7 @@ class Ssl extends AbstractModel
'status',
'domains',
'log_id',
'email',
];
protected $casts = [
@ -143,4 +145,13 @@ public function log(): BelongsTo
{
return $this->belongsTo(ServerLog::class);
}
public function getEmailAttribute(?string $value): string
{
if ($value) {
return $value;
}
return $this->site->server->creator->email;
}
}

View File

@ -168,7 +168,7 @@ public function setupSSL(Ssl $ssl): void
$domains .= ' -d '.$domain;
}
$command = view('ssh.services.webserver.nginx.create-letsencrypt-ssl', [
'email' => $ssl->site->server->creator->email,
'email' => $ssl->email,
'domain' => $ssl->site->domain,
'domains' => $domains,
]);

View File

@ -3,7 +3,9 @@
namespace App\Web\Pages\Servers\Sites\Pages\SSL;
use App\Actions\SSL\CreateSSL;
use App\Enums\SslType;
use App\Models\Ssl;
use App\Web\Fields\AlertField;
use App\Web\Pages\Servers\Sites\Page;
use Filament\Actions\Action;
use Filament\Actions\CreateAction;
@ -11,6 +13,7 @@
use Filament\Forms\Components\DatePicker;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\Textarea;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Get;
use Filament\Support\Enums\MaxWidth;
@ -45,25 +48,32 @@ protected function getHeaderActions(): array
->label('New Certificate')
->icon('heroicon-o-lock-closed')
->form([
AlertField::make('letsencrypt-info')
->warning()
->message('Let\'s Encrypt has rate limits. Read more about them <a href="https://letsencrypt.org/docs/rate-limits/" target="_blank" class="underline">here</a>.'),
Select::make('type')
->options(
collect(config('core.ssl_types'))->mapWithKeys(fn ($type) => [$type => $type])
)
->rules(fn (Get $get) => CreateSSL::rules($get())['type'])
->reactive(),
TextInput::make('email')
->rules(fn (Get $get) => CreateSSL::rules($get())['email'] ?? [])
->visible(fn (Get $get) => $get('type') === SslType::LETSENCRYPT)
->helperText('Email address to provide to Certbot.'),
Textarea::make('certificate')
->rows(5)
->rules(fn (Get $get) => CreateSSL::rules($get())['certificate'])
->visible(fn (Get $get) => $get('type') === 'custom'),
->visible(fn (Get $get) => $get('type') === SslType::CUSTOM),
Textarea::make('private')
->label('Private Key')
->rows(5)
->rules(fn (Get $get) => CreateSSL::rules($get())['private'])
->visible(fn (Get $get) => $get('type') === 'custom'),
->visible(fn (Get $get) => $get('type') === SslType::CUSTOM),
DatePicker::make('expires_at')
->format('Y-m-d')
->rules(fn (Get $get) => CreateSSL::rules($get())['expires_at'])
->visible(fn (Get $get) => $get('type') === 'custom'),
->visible(fn (Get $get) => $get('type') === SslType::CUSTOM),
Checkbox::make('aliases')
->label("Set SSL for site's aliases as well"),
])