osb/app/Models/Service/SSL.php

78 lines
1.5 KiB
PHP
Raw Permalink Normal View History

2018-05-20 12:53:14 +00:00
<?php
namespace App\Models\Service;
2018-05-20 12:53:14 +00:00
2020-04-01 12:35:06 +00:00
use Illuminate\Support\Arr;
use Carbon\Carbon;
2020-02-20 11:54:28 +00:00
use App\Interfaces\ServiceItem;
use App\Models\Base\ServiceType;
use App\Traits\NextKey;
2020-02-20 11:54:28 +00:00
class SSL extends ServiceType implements ServiceItem
2018-05-20 12:53:14 +00:00
{
use NextKey;
const RECORD_ID = 'service__ssl';
2018-05-20 12:53:14 +00:00
protected $table = 'ab_service__ssl';
2020-04-01 12:35:06 +00:00
protected $crt_parse = NULL;
protected $public_key = NULL;
2018-05-20 12:53:14 +00:00
2020-04-01 12:35:06 +00:00
public static function boot()
2018-05-20 12:53:14 +00:00
{
2020-04-01 12:35:06 +00:00
parent::boot();
static::retrieved(function($model) {
if ($model->cert);
$model->crt_parse = collect(openssl_x509_parse($model->cert));
2018-07-16 05:06:43 +00:00
2020-04-01 12:35:06 +00:00
if ($model->csr) {
$model->public_key = collect(openssl_pkey_get_details(openssl_csr_get_public_key($model->csr)));
}
});
}
public function getValidToAttribute()
{
return $this->cert ? Carbon::createFromTimestamp($this->crt_parse->get('validTo_time_t')) : NULL;
2018-05-20 12:53:14 +00:00
}
2020-02-20 11:54:28 +00:00
public function getServiceDescriptionAttribute(): string
{
2020-04-01 12:35:06 +00:00
if ($this->cert)
return Arr::get($this->crt_parse,'name');
else {
$dn = '';
$dna = openssl_csr_get_subject($this->csr);
foreach ($dna as $k=>$v) {
if ($dn)
$dn .= ',';
$dn .= sprintf('%s=%s',$k,$v);
}
return $dn;
}
2020-02-20 11:54:28 +00:00
}
public function getServiceExpireAttribute(): Carbon
{
// TODO: Implement getServiceExpireAttribute() method.
}
2020-02-20 11:54:28 +00:00
public function getServiceNameAttribute(): string
2018-05-20 12:53:14 +00:00
{
2020-04-01 12:35:06 +00:00
return $this->cert
? Arr::get($this->crt_parse,'subject.CN')
: Arr::get(openssl_csr_get_subject($this->csr),'CN');
2018-05-20 12:53:14 +00:00
}
2020-02-20 11:54:28 +00:00
public function inContract(): bool
{
// N/A
return FALSE;
}
2018-05-20 12:53:14 +00:00
}