-
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.
π¨ WIP - beta version of crawl notifications
- Loading branch information
Owen Melbourne
committed
Nov 9, 2020
1 parent
03a5cf0
commit a8e47c6
Showing
12 changed files
with
213 additions
and
6 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
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,37 @@ | ||
<?php | ||
|
||
namespace App\Console\Commands; | ||
|
||
use App\Jobs\PageCheck; | ||
use App\Website; | ||
use Illuminate\Console\Command; | ||
|
||
class ScanCrawlerCommand extends Command | ||
{ | ||
/** | ||
* The name and signature of the console command. | ||
* | ||
* @var string | ||
*/ | ||
protected $signature = 'scan:crawler'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Schedules the crawler for all websites and collects all the linked URLs.'; | ||
|
||
/** | ||
* Execute the console command. | ||
* | ||
* @return mixed | ||
*/ | ||
public function handle() | ||
{ | ||
Website::canCrawl()->get()->each(function (Website $website) { | ||
dump('Crawler queued for ' . $website->url); | ||
PageCheck::dispatch($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
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
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,81 @@ | ||
<?php | ||
|
||
namespace App\Notifications; | ||
|
||
use App\Website; | ||
use App\CrawledPage; | ||
use App\CertificateScan; | ||
use Illuminate\Bus\Queueable; | ||
use Illuminate\Notifications\Notification; | ||
use Illuminate\Contracts\Queue\ShouldQueue; | ||
use Illuminate\Notifications\Messages\MailMessage; | ||
|
||
class BrowserMessageDetected extends Notification | ||
{ | ||
use Queueable; | ||
|
||
/** | ||
* @var Website | ||
*/ | ||
private $website; | ||
|
||
/** | ||
* @var CrawledPage | ||
*/ | ||
private $page; | ||
|
||
/** | ||
* Create a new notification instance. | ||
* | ||
* @param Website $website | ||
* @param CrawledPage $page | ||
*/ | ||
public function __construct(Website $website, CrawledPage $page) | ||
{ | ||
$this->website = $website; | ||
$this->page = $page; | ||
} | ||
|
||
/** | ||
* 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('π Browser Message Detected: ' . $this->website->url) | ||
->markdown('mail.browser-message', [ | ||
'website' => $this->website, | ||
'page' => $this->page, | ||
]); | ||
} | ||
|
||
/** | ||
* Get the array representation of the notification. | ||
* | ||
* @param mixed $notifiable | ||
* @return array | ||
*/ | ||
public function toArray($notifiable) | ||
{ | ||
return [ | ||
'website_id' => $this->website->id, | ||
'website' => $this->website->url, | ||
'url' => $this->page->url, | ||
'messages' => $this->page->messages, | ||
]; | ||
} | ||
} |
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,18 @@ | ||
@component('mail::message') | ||
# Browser message detected on: {{ $website->url }} | ||
|
||
The following URL flagged up a console warning, please investigate. | ||
|
||
Please see the output below: | ||
|
||
<div style="padding: 20px; background: #f1f2fb;"> | ||
<pre style="margin:0;padding:0;"><code style="margin:0;padding:0;">{{ $page->messages }}</code></pre> | ||
</div> | ||
|
||
@component('mail::button', ['url' => $website->show_link]) | ||
Open Monitor | ||
@endcomponent | ||
|
||
Thanks,<br> | ||
{{ config('app.name') }} | ||
@endcomponent |