Skip to content

Commit

Permalink
πŸ”¨ WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
Owen Melbourne committed Aug 19, 2019
1 parent b4a6661 commit fcbbd01
Show file tree
Hide file tree
Showing 11 changed files with 201 additions and 365 deletions.
8 changes: 5 additions & 3 deletions app/Checkers/Certificate.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
namespace App\Checkers;

use App\Website;
use Andyftw\SSLLabs\Api;
use App\CertificateScan;
use VisualAppeal\SslLabs;
use Spatie\SslCertificate\SslCertificate;

class Certificate
Expand Down Expand Up @@ -36,7 +36,7 @@ private function fetch()
'did_expire' => $certificate->isExpired(),
]);

$labs = new \VisualAppeal\SslLabs();
$labs = new SslLabs();

$result = $labs->analyze(
$this->website->certificate_hostname,
Expand All @@ -56,7 +56,9 @@ private function fetch()
}
}

dump($scan->exists ? 'Cert Updated' : 'Pending...');
if (app()->runningInConsole()) {
dump($scan->exists ? 'Cert Updated' : 'Pending...');
}
}

private function notify()
Expand Down
21 changes: 21 additions & 0 deletions app/Checkers/Robots.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@
use GuzzleHttp\Client;
use App\Website;
use SebastianBergmann\Diff\Differ;
use App\Notifications\RobotsHasChanged;


class Robots
{
private $website;

private $scan;

public function __construct(Website $website)
{
$this->website = $website;
Expand All @@ -21,6 +24,7 @@ public function run()
{
$this->fetch();
$this->compare();
$this->notify();
}

private function fetch()
Expand Down Expand Up @@ -56,5 +60,22 @@ private function compare()

$scans->first()->diff = $diff;
$scans->first()->save();

$this->scan = $scans->first();
}

private function notify()
{
if (!$this->scan) {
return null;
}

if (empty($this->scan->diff)) {
return null;
}

$this->website->user->notify(
new RobotsHasChanged($this->website, $this->scan)
);
}
}
80 changes: 80 additions & 0 deletions app/Notifications/RobotsHasChanged.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?php

namespace App\Notifications;

use App\Website;
use App\RobotScan;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;

class RobotsHasChanged extends Notification
{
use Queueable;
/**
* @var Website
*/
private $website;

/**
* @var RobotScan
*/
private $scan;

/**
* Create a new notification instance.
*
* @param Website $website
* @param RobotScan $scan
*/
public function __construct(Website $website, RobotScan $scan)
{
$this->website = $website;
$this->scan = $scan;
}

/**
* Get the notification's delivery channels.
*
* @param mixed $notifiable
* @return array
*/
public function via($notifiable)
{
return ['database', 'mail'];
}

/**
* Get the mail representation of the notification.
*
* @param mixed $notifiable
* @return \Illuminate\Notifications\Messages\MailMessage
*/
public function toMail($notifiable)
{
return (new MailMessage)
->subject('πŸ€– Change detected on: ' . $this->website->url)
->markdown('mail.robots-changed', [
'website' => $this->website,
'scan' => $this->scan,
]);
}

/**
* Get the array representation of the notification.
*
* @param mixed $notifiable
* @return array
*/
public function toArray($notifiable)
{
return [
'website_id' => $this->website->id,
'url' => $this->website->robots_url,
'changed_on' => $this->scan->created_at,
'txt' => $this->scan->txt,
'diff' => $this->scan->diff,
];
}
}
3 changes: 0 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,13 @@
"license": "MIT",
"require": {
"php": "^7.1.3",
"amhr/laravel-dnsparser": "^1.3@dev",
"andyftw/ssllabs-php": "^1.2",
"doctrine/annotations": "^1.7",
"fideloper/proxy": "^4.0",
"guzzlehttp/guzzle": "^6.3",
"laravel/framework": "5.8.*",
"laravel/tinker": "^1.0",
"maelstrom-cms/toolkit": "^1.0",
"sebastian/diff": "^3.0",
"spatie/dns": "^1.4",
"spatie/ssl-certificate": "^1.15",
"visualappeal/php-ssllabs-api": "^1.0",
"whoisdoma/dnsparser": "dev-master",
Expand Down
Loading

0 comments on commit fcbbd01

Please sign in to comment.