Skip to content

Commit

Permalink
πŸ”¨ WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
OwenMelbz committed Aug 19, 2019
1 parent 752e2b3 commit 2290a14
Show file tree
Hide file tree
Showing 26 changed files with 866 additions and 21 deletions.
37 changes: 37 additions & 0 deletions app/Checkers/OpenGraph.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace App\Checkers;

use Embed\Embed;
use App\Website;
use App\OpenGraphScan;

class OpenGraph
{
private $website;

public function __construct(Website $website)
{
$this->website = $website;
}

public function run()
{
$this->fetch();
}

private function fetch()
{
$info = Embed::create($this->website->url);

$scan = new OpenGraphScan([
'title' => $info->title,
'description' => $info->description,
'image' => $info->image,
'url' => $info->url,
'icon' => $info->providerIcon,
]);

$this->website->openGraph()->save($scan);
}
}
1 change: 0 additions & 1 deletion app/Checkers/Robots.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use SebastianBergmann\Diff\Differ;
use App\Notifications\RobotsHasChanged;


class Robots
{
private $website;
Expand Down
1 change: 0 additions & 1 deletion app/Checkers/Uptime.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use App\Notifications\WebsiteIsDown;
use App\Notifications\WebsiteIsBackUp;


class Uptime
{
private $website;
Expand Down
49 changes: 49 additions & 0 deletions app/Console/Commands/OpenGraphCheckCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

namespace App\Console\Commands;

use App\Jobs\OpenGraphCheck;
use App\Jobs\RobotsCheck;
use App\Website;
use Illuminate\Console\Command;

class OpenGraphCheckCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'check:opengraph {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');

OpenGraphCheck::dispatchNow(
Website::findOrFail($websiteId)
);
}
}
12 changes: 10 additions & 2 deletions app/Console/Commands/ScanCertificateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

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 ScanCertificateCommand extends Command
Expand All @@ -11,7 +16,7 @@ class ScanCertificateCommand extends Command
*
* @var string
*/
protected $signature = 'command:name';
protected $signature = 'scan:certificate';

/**
* The console command description.
Expand All @@ -37,6 +42,9 @@ public function __construct()
*/
public function handle()
{
//
Website::all()->each(function (Website $website) {
CertificateCheck::dispatch($website);
dump('Certificate check queued for ' . $website->url);
});
}
}
10 changes: 8 additions & 2 deletions app/Console/Commands/ScanDnsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

namespace App\Console\Commands;

use App\Jobs\CertificateCheck;
use App\Jobs\DnsCheck;
use App\Website;
use Illuminate\Console\Command;

class ScanDnsCommand extends Command
Expand All @@ -11,7 +14,7 @@ class ScanDnsCommand extends Command
*
* @var string
*/
protected $signature = 'command:name';
protected $signature = 'scan:dns';

/**
* The console command description.
Expand All @@ -37,6 +40,9 @@ public function __construct()
*/
public function handle()
{
//
Website::all()->each(function (Website $website) {
DnsCheck::dispatch($website);
dump('DNS check queued for ' . $website->url);
});
}
}
48 changes: 48 additions & 0 deletions app/Console/Commands/ScanOpenGraphCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

namespace App\Console\Commands;

use App\Jobs\CertificateCheck;
use App\Jobs\OpenGraphCheck;
use App\Website;
use Illuminate\Console\Command;

class ScanOpenGraphCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'scan:opengraph';

/**
* 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()
{
Website::all()->each(function (Website $website) {
OpenGraphCheck::dispatch($website);
dump('Open Graph check queued for ' . $website->url);
});
}
}
10 changes: 8 additions & 2 deletions app/Console/Commands/ScanRobotsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

namespace App\Console\Commands;

use App\Jobs\CertificateCheck;
use App\Jobs\RobotsCheck;
use App\Website;
use Illuminate\Console\Command;

class ScanRobotsCommand extends Command
Expand All @@ -11,7 +14,7 @@ class ScanRobotsCommand extends Command
*
* @var string
*/
protected $signature = 'command:name';
protected $signature = 'scan:robots';

/**
* The console command description.
Expand All @@ -37,6 +40,9 @@ public function __construct()
*/
public function handle()
{
//
Website::all()->each(function (Website $website) {
RobotsCheck::dispatch($website);
dump('Robots check queued for ' . $website->url);
});
}
}
10 changes: 8 additions & 2 deletions app/Console/Commands/ScanUptimeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

namespace App\Console\Commands;

use App\Jobs\CertificateCheck;
use App\Jobs\UptimeCheck;
use App\Website;
use Illuminate\Console\Command;

class ScanUptimeCommand extends Command
Expand All @@ -11,7 +14,7 @@ class ScanUptimeCommand extends Command
*
* @var string
*/
protected $signature = 'command:name';
protected $signature = 'scan:uptime';

/**
* The console command description.
Expand All @@ -37,6 +40,9 @@ public function __construct()
*/
public function handle()
{
//
Website::all()->each(function (Website $website) {
UptimeCheck::dispatch($website);
dump('Uptime check queued for ' . $website->url);
});
}
}
1 change: 1 addition & 0 deletions app/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ protected function schedule(Schedule $schedule)
$schedule->command('scan:robots')->hourly()->withoutOverlapping()->runInBackground();
$schedule->command('scan:dns')->hourly()->withoutOverlapping()->runInBackground();
$schedule->command('scan:certificate')->dailyAt('08:00:00')->withoutOverlapping()->runInBackground();
$schedule->command('scan:opengraph')->dailyAt('08:00:00')->withoutOverlapping()->runInBackground();
}

/**
Expand Down
11 changes: 11 additions & 0 deletions app/HasOpenGraph.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace App;

trait HasOpenGraph
{
public function openGraph()
{
return $this->hasMany(OpenGraphScan::class);
}
}
25 changes: 25 additions & 0 deletions app/Http/Controllers/OpenGraphController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace App\Http\Controllers;

use App\Jobs\OpenGraphCheck;
use App\Website;
use Illuminate\Http\Request;

class OpenGraphController extends Controller
{
/**
* Handle the incoming request.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function __invoke(Request $request, Website $website)
{
if ($request->has('refresh')) {
OpenGraphCheck::dispatchNow($website);
}

return $website->openGraph()->latest()->first();
}
}
42 changes: 42 additions & 0 deletions app/Jobs/OpenGraphCheck.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

namespace App\Jobs;

use App\Website;
use App\Checkers\OpenGraph;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;

class OpenGraphCheck implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

/**
* @var Website
*/
private $website;

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

/**
* Execute the job.
*
* @return void
*/
public function handle()
{
$checker = new OpenGraph($this->website);
$checker->run();
}
}
15 changes: 15 additions & 0 deletions app/OpenGraphScan.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class OpenGraphScan extends Model
{
protected $guarded = [];

protected $hidden = [
'created_at', 'id',
'updated_at', 'website_id',
];
}
1 change: 1 addition & 0 deletions app/Website.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class Website extends Model
use HasRobots;
use HasCertificates;
use HasDns;
use HasOpenGraph;

protected $fillable = [
'url',
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"require": {
"php": "^7.1.3",
"doctrine/annotations": "^1.7",
"embed/embed": "^3.4",
"fideloper/proxy": "^4.0",
"guzzlehttp/guzzle": "^6.3",
"laravel/framework": "5.8.*",
Expand Down
Loading

0 comments on commit 2290a14

Please sign in to comment.