mirror of
https://github.com/vitodeploy/vito.git
synced 2025-07-02 14:36:17 +00:00
Force SSL and Multi SSL (#456)
This commit is contained in:
@ -75,6 +75,7 @@ class Site extends AbstractModel
|
||||
'port',
|
||||
'progress',
|
||||
'user',
|
||||
'force_ssl',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
@ -84,6 +85,7 @@ class Site extends AbstractModel
|
||||
'progress' => 'integer',
|
||||
'aliases' => 'array',
|
||||
'source_control_id' => 'integer',
|
||||
'force_ssl' => 'boolean',
|
||||
];
|
||||
|
||||
public static array $statusColors = [
|
||||
@ -227,6 +229,7 @@ public function activeSsl(): HasOne
|
||||
return $this->hasOne(Ssl::class)
|
||||
->where('expires_at', '>=', now())
|
||||
->where('status', SslStatus::CREATED)
|
||||
->where('is_active', true)
|
||||
->orderByDesc('id');
|
||||
}
|
||||
|
||||
|
@ -17,10 +17,13 @@
|
||||
* @property Carbon $expires_at
|
||||
* @property string $status
|
||||
* @property Site $site
|
||||
* @property string $ca_path
|
||||
* @property ?array $domains
|
||||
* @property int $log_id
|
||||
* @property string $email
|
||||
* @property bool $is_active
|
||||
* @property string $certificate_path
|
||||
* @property string $pk_path
|
||||
* @property string $ca_path
|
||||
* @property ?ServerLog $log
|
||||
*/
|
||||
class Ssl extends AbstractModel
|
||||
@ -38,6 +41,10 @@ class Ssl extends AbstractModel
|
||||
'domains',
|
||||
'log_id',
|
||||
'email',
|
||||
'is_active',
|
||||
'certificate_path',
|
||||
'pk_path',
|
||||
'ca_path',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
@ -48,6 +55,7 @@ class Ssl extends AbstractModel
|
||||
'expires_at' => 'datetime',
|
||||
'domains' => 'array',
|
||||
'log_id' => 'integer',
|
||||
'is_active' => 'boolean',
|
||||
];
|
||||
|
||||
public static array $statusColors = [
|
||||
@ -62,58 +70,6 @@ public function site(): BelongsTo
|
||||
return $this->belongsTo(Site::class);
|
||||
}
|
||||
|
||||
public function getCertsDirectoryPath(): ?string
|
||||
{
|
||||
if ($this->type == 'letsencrypt') {
|
||||
return '/etc/letsencrypt/live/'.$this->site->domain;
|
||||
}
|
||||
|
||||
if ($this->type == 'custom') {
|
||||
return '/etc/ssl/'.$this->site->domain;
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
public function getCertificatePath(): ?string
|
||||
{
|
||||
if ($this->type == 'letsencrypt') {
|
||||
return $this->certificate;
|
||||
}
|
||||
|
||||
if ($this->type == 'custom') {
|
||||
return $this->getCertsDirectoryPath().'/cert.pem';
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
public function getPkPath(): ?string
|
||||
{
|
||||
if ($this->type == 'letsencrypt') {
|
||||
return $this->pk;
|
||||
}
|
||||
|
||||
if ($this->type == 'custom') {
|
||||
return $this->getCertsDirectoryPath().'/privkey.pem';
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
public function getCaPath(): ?string
|
||||
{
|
||||
if ($this->type == 'letsencrypt') {
|
||||
return $this->ca;
|
||||
}
|
||||
|
||||
if ($this->type == 'custom') {
|
||||
return $this->getCertsDirectoryPath().'/fullchain.pem';
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
public function validateSetup(string $result): bool
|
||||
{
|
||||
if (! Str::contains($result, 'Successfully received certificate')) {
|
||||
@ -121,8 +77,8 @@ public function validateSetup(string $result): bool
|
||||
}
|
||||
|
||||
if ($this->type == 'letsencrypt') {
|
||||
$this->certificate = $this->getCertsDirectoryPath().'/fullchain.pem';
|
||||
$this->pk = $this->getCertsDirectoryPath().'/privkey.pem';
|
||||
$this->certificate_path = '/etc/letsencrypt/live/'.$this->id.'/fullchain.pem';
|
||||
$this->pk_path = '/etc/letsencrypt/live/'.$this->id.'/privkey.pem';
|
||||
$this->save();
|
||||
}
|
||||
|
||||
@ -145,13 +101,4 @@ 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;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user