-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
32 changed files
with
2,054 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
namespace App; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
|
||
class CertificateScan extends Model | ||
{ | ||
protected $guarded = []; | ||
|
||
protected $casts = [ | ||
'additional_domains' => 'array', | ||
'valid_from' => 'datetime', | ||
'valid_to' => 'datetime', | ||
'was_valid' => 'boolean', | ||
'did_expire' => 'boolean', | ||
]; | ||
|
||
protected $appends = [ | ||
'expires_in', | ||
]; | ||
|
||
public function getExpiresInAttribute() | ||
{ | ||
return now()->diffAsCarbonInterval($this->valid_to)->forHumans(['join' => true]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php | ||
|
||
namespace App\Checkers; | ||
|
||
use App\Website; | ||
use Andyftw\SSLLabs\Api; | ||
use App\CertificateScan; | ||
use Spatie\SslCertificate\SslCertificate; | ||
|
||
class Certificate | ||
{ | ||
private $website; | ||
|
||
public function __construct(Website $website) | ||
{ | ||
$this->website = $website; | ||
} | ||
|
||
public function run() | ||
{ | ||
$this->fetch(); | ||
$this->notify(); | ||
} | ||
|
||
private function fetch() | ||
{ | ||
$certificate = SslCertificate::createForHostName($this->website->certificate_hostname); | ||
|
||
$scan = new CertificateScan([ | ||
'issuer' => $certificate->getIssuer(), | ||
'domain' => $certificate->getDomain(), | ||
'additional_domains' => $certificate->getAdditionalDomains(), | ||
'valid_from' => $certificate->validFromDate(), | ||
'valid_to' => $certificate->expirationDate(), | ||
'was_valid' => $certificate->isValid(), | ||
'did_expire' => $certificate->isExpired(), | ||
]); | ||
|
||
$labs = new \VisualAppeal\SslLabs(); | ||
|
||
$result = $labs->analyze( | ||
$this->website->certificate_hostname, | ||
$publish = false, | ||
$startNew = false, | ||
$fromCache = true, | ||
$maxAge = 12, | ||
$all = null, | ||
$ignoreMismatch = false | ||
); | ||
|
||
foreach ($result->endpoints ?? [] as $endpoint) { | ||
if ($endpoint->statusMessage === 'Ready') { | ||
$scan->grade = $endpoint->grade; | ||
$this->website->certificates()->save($scan); | ||
break; | ||
} | ||
} | ||
|
||
dump($scan->exists ? 'Cert Updated' : 'Pending...'); | ||
} | ||
|
||
private function notify() | ||
{ | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<?php | ||
|
||
namespace App\Checkers; | ||
|
||
use App\DnsScan; | ||
use App\Website; | ||
use Whoisdoma\DNSParser\DNSParser; | ||
use SebastianBergmann\Diff\Differ; | ||
use Spatie\Dns\Dns as DnsLookup; | ||
|
||
class Dns | ||
{ | ||
private $website; | ||
|
||
public function __construct(Website $website) | ||
{ | ||
$this->website = $website; | ||
} | ||
|
||
public function run() | ||
{ | ||
$this->fetch(); | ||
$this->compare(); | ||
$this->notify(); | ||
} | ||
|
||
private function fetch() | ||
{ | ||
$response = (new DNSParser('array'))->lookup($this->website->dns_hostname); | ||
|
||
$flat = collect($response['records'])->transform(function ($item) { | ||
return sprintf( | ||
'%s %s %s ttl:%d', | ||
$item['host'], | ||
$item['type'], | ||
$item['ip'] ?? $item['target'] ?? $item['mname'] ?? $item['txt'] ?? $item['ipv6'] ?? '', | ||
$item['ttl'] | ||
); | ||
})->sort()->values()->implode("\n"); | ||
|
||
$scan = new DnsScan([ | ||
'records' => $response['records'], | ||
'flat' => $flat, | ||
]); | ||
|
||
$this->website->dns()->save($scan); | ||
} | ||
|
||
private function compare() | ||
{ | ||
$scans = $this->website->last_dns_scans; | ||
|
||
if ($scans->isEmpty() || $scans->count() === 1) { | ||
return; | ||
} | ||
|
||
$diff = (new Differ)->diff( | ||
$scans->last()->flat, | ||
$scans->first()->flat | ||
); | ||
|
||
$placeholder = '--- Original | ||
+++ New | ||
'; | ||
|
||
if ($diff === $placeholder) { | ||
$diff = null; | ||
} | ||
|
||
$scans->first()->diff = $diff; | ||
$scans->first()->save(); | ||
} | ||
|
||
private function notify() | ||
{ | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
|
||
namespace App\Console\Commands; | ||
|
||
use App\Jobs\CertificateCheck; | ||
use App\Jobs\DnsCheck; | ||
use App\Jobs\RobotsCheck; | ||
use App\Jobs\UptimeCheck; | ||
use App\Website; | ||
use Illuminate\Console\Command; | ||
|
||
class AllCheckersCommand extends Command | ||
{ | ||
/** | ||
* The name and signature of the console command. | ||
* | ||
* @var string | ||
*/ | ||
protected $signature = 'check:all {website}'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Command description'; | ||
|
||
/** | ||
* Create a new command instance. | ||
* | ||
* @return void | ||
*/ | ||
public function __construct() | ||
{ | ||
parent::__construct(); | ||
} | ||
|
||
/** | ||
* Execute the console command. | ||
* | ||
* @return mixed | ||
*/ | ||
public function handle() | ||
{ | ||
$websiteId = $this->argument('website'); | ||
$website = Website::findOrFail($websiteId); | ||
|
||
DnsCheck::dispatchNow($website); | ||
RobotsCheck::dispatchNow($website); | ||
UptimeCheck::dispatchNow($website); | ||
CertificateCheck::dispatchNow($website); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
namespace App\Console\Commands; | ||
|
||
use App\Website; | ||
use App\Jobs\CertificateCheck; | ||
use Illuminate\Console\Command; | ||
|
||
class CertificateCheckCommand extends Command | ||
{ | ||
/** | ||
* The name and signature of the console command. | ||
* | ||
* @var string | ||
*/ | ||
protected $signature = 'check:ssl {website}'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Command description'; | ||
|
||
/** | ||
* Create a new command instance. | ||
* | ||
* @return void | ||
*/ | ||
public function __construct() | ||
{ | ||
parent::__construct(); | ||
} | ||
|
||
/** | ||
* Execute the console command. | ||
* | ||
* @return mixed | ||
*/ | ||
public function handle() | ||
{ | ||
$websiteId = $this->argument('website'); | ||
|
||
CertificateCheck::dispatchNow( | ||
Website::findOrFail($websiteId) | ||
); | ||
} | ||
} |
Oops, something went wrong.