-
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
18 changed files
with
410,963 additions
and
48 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,58 @@ | ||
<?php | ||
|
||
namespace App\Checkers; | ||
|
||
use Exception; | ||
use App\DnsScan; | ||
use App\Website; | ||
use App\CrawlObserver; | ||
use Spatie\Crawler\Crawler; | ||
use GuzzleHttp\RequestOptions; | ||
use Whoisdoma\DNSParser\DNSParser; | ||
use SebastianBergmann\Diff\Differ; | ||
use App\Notifications\DnsHasChanged; | ||
|
||
class Page | ||
{ | ||
private $website; | ||
|
||
public function __construct(Website $website) | ||
{ | ||
$this->website = $website; | ||
} | ||
|
||
public function run() | ||
{ | ||
$this->fetch(); | ||
$this->compare(); | ||
$this->notify(); | ||
} | ||
|
||
private function fetch() | ||
{ | ||
Crawler::create([ | ||
RequestOptions::COOKIES => true, | ||
RequestOptions::CONNECT_TIMEOUT => 10, | ||
RequestOptions::TIMEOUT => 10, | ||
RequestOptions::ALLOW_REDIRECTS => false, | ||
RequestOptions::HEADERS => [ | ||
'User-Agent' => '', | ||
], | ||
]) | ||
->ignoreRobots() | ||
->setConcurrency(2) | ||
->executeJavaScript() | ||
->setCrawlObserver(new CrawlObserver($this->website)) | ||
->startCrawling($this->website->url); | ||
} | ||
|
||
private function compare() | ||
{ | ||
|
||
} | ||
|
||
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
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\PageCheck; | ||
use Illuminate\Console\Command; | ||
|
||
class CrawlSiteCommand extends Command | ||
{ | ||
/** | ||
* The name and signature of the console command. | ||
* | ||
* @var string | ||
*/ | ||
protected $signature = 'check:pages {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'); | ||
|
||
PageCheck::dispatchNow( | ||
Website::findOrFail($websiteId) | ||
); | ||
} | ||
} |
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,49 @@ | ||
<?php | ||
|
||
namespace App; | ||
|
||
use Psr\Http\Message\UriInterface; | ||
use Psr\Http\Message\ResponseInterface; | ||
use GuzzleHttp\Exception\RequestException; | ||
use Spatie\Crawler\CrawlObserver as SpatieCrawlObserver; | ||
|
||
class CrawlObserver extends SpatieCrawlObserver | ||
{ | ||
/** | ||
* @var Website | ||
*/ | ||
private $website; | ||
|
||
public function __construct(Website $website) | ||
{ | ||
$this->website = $website; | ||
} | ||
|
||
/** | ||
* Called when the crawler has crawled the given url successfully. | ||
* | ||
* @param UriInterface $url | ||
* @param ResponseInterface $response | ||
* @param UriInterface|null $foundOnUrl | ||
*/ | ||
public function crawled(UriInterface $url, ResponseInterface $response, ?UriInterface $foundOnUrl = null) | ||
{ | ||
$page = $this->website->crawledPages()->firstOrCreate([ | ||
'url' => $url, | ||
]); | ||
|
||
$page->save(); | ||
} | ||
|
||
/** | ||
* Called when the crawler had a problem crawling the given url. | ||
* | ||
* @param UriInterface $url | ||
* @param RequestException $requestException | ||
* @param UriInterface|null $foundOnUrl | ||
*/ | ||
public function crawlFailed(UriInterface $url, RequestException $requestException, ?UriInterface $foundOnUrl = null) | ||
{ | ||
// TODO: Implement crawlFailed() method. | ||
} | ||
} |
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,10 @@ | ||
<?php | ||
|
||
namespace App; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
|
||
class CrawledPage extends Model | ||
{ | ||
protected $guarded = []; | ||
} |
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,11 @@ | ||
<?php | ||
|
||
namespace App; | ||
|
||
trait HasCrawledPages | ||
{ | ||
public function crawledPages() | ||
{ | ||
return $this->hasMany(CrawledPage::class); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,12 +1,9 @@ | ||
<?php | ||
|
||
|
||
namespace App; | ||
|
||
|
||
trait HasRobots | ||
{ | ||
|
||
public function robots() | ||
{ | ||
return $this->hasMany(RobotScan::class); | ||
|
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,43 @@ | ||
<?php | ||
|
||
namespace App\Jobs; | ||
|
||
use App\Website; | ||
use App\Checkers\Page; | ||
use App\Checkers\Certificate; | ||
use Illuminate\Bus\Queueable; | ||
use Illuminate\Queue\SerializesModels; | ||
use Illuminate\Queue\InteractsWithQueue; | ||
use Illuminate\Contracts\Queue\ShouldQueue; | ||
use Illuminate\Foundation\Bus\Dispatchable; | ||
|
||
class PageCheck 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 Page($this->website); | ||
$checker->run(); | ||
} | ||
} |
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
Oops, something went wrong.