Skip to content
This repository has been archived by the owner on Nov 19, 2023. It is now read-only.

Commit

Permalink
Add new field for tracking domains that have been checked at least on…
Browse files Browse the repository at this point in the history
…ce, increase check to 30 minutes, code format
  • Loading branch information
Indy Griffiths committed Jun 28, 2018
1 parent 702865f commit d99b99f
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 19 deletions.
2 changes: 1 addition & 1 deletion mysite/_config.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@
'BrokenRedirectorPagesReport',
'BrokenVirtualPagesReport',
'RecentlyEditedReport',
'EmptyPagesReport'
'EmptyPagesReport',
]);
8 changes: 5 additions & 3 deletions mysite/code/Jobs/CheckSSLCertificates.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class CheckSSLCertificates implements CronTask
*/
public function getSchedule()
{
return '0 * * * *';
return '0/30 * * * *';
}

/**
Expand All @@ -26,6 +26,7 @@ public function process()
$this->log('Number of existing domains: '.$domains->count(), SS_Log::DEBUG);

foreach ($domains as $d) {
$hasBeenChecked = $d->HasBeenChecked;
$d->LastChecked = time();

$this->log('Checking '.$d->Domain, SS_Log::INFO);
Expand Down Expand Up @@ -90,6 +91,7 @@ public function process()
$d->ErrorCode = '';
$d->ErrorMessage = '';
$d->AlertedCommonNameMismatch = false;
$d->HasBeenChecked = true;

$this->log('Checking this certificate against the current one', SS_Log::DEBUG);
if ($lastCert->exists() && $lastCert->Fingerprint === $fingerprint) {
Expand Down Expand Up @@ -121,7 +123,7 @@ public function process()
$d->write();

// Post to Slack about the new certificate only if this isn't the first certificate
if ($lastCert->exists()) {
if ($hasBeenChecked) {
$this->notifyNewCertificate($d, $cert);
}
}
Expand Down Expand Up @@ -249,7 +251,7 @@ private function getStream($domain)
$streamOptions = stream_context_create([
'ssl' => [
'capture_peer_cert' => true,
'verify_peer' => false,
'verify_peer' => false,
],
]);

Expand Down
2 changes: 1 addition & 1 deletion mysite/code/Jobs/GetCloudFlareDomains.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function process()
$zones = $cf->Zones();

foreach ($zones as $z) {
if (in_array($z->name, $domains)) {
if (in_array($z->name, $domains, true)) {
continue;
}

Expand Down
2 changes: 1 addition & 1 deletion mysite/code/Jobs/GetIncapsulaDomains.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function process()
$zones = $cf->Sites();

foreach ($zones as $z) {
if (in_array($z->domain, $domains)) {
if (in_array($z->domain, $domains, true)) {
continue;
}

Expand Down
7 changes: 4 additions & 3 deletions mysite/code/Model/Domain.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class Domain extends DataObject
'OpsGenieID' => 'Text',
'AlertPriority' => 'Text',
'AlertedCommonNameMismatch' => 'Boolean(0)',
'HasBeenChecked' => 'Boolean(0)',
];

private static $has_many = [
Expand Down Expand Up @@ -144,9 +145,9 @@ public function HasValidCertificateNice()
public function LastCheckSuccessful()
{
return empty($this->ErrorCode) &&
empty($this->ErrorMessage) &&
!empty($this->LastChecked) &&
$this->HasValidCertificate();
empty($this->ErrorMessage) &&
!empty($this->LastChecked) &&
$this->HasValidCertificate();
}

/**
Expand Down
6 changes: 3 additions & 3 deletions mysite/code/Report/LetsEncryptReport.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

/**
* Report for listing domains who are using Let's Encrypt
* Report for listing domains who are using Let's Encrypt.
*/
class LetsEncryptReport extends SS_Report
{
Expand All @@ -18,8 +18,8 @@ public function description()
public function sourceRecords($params = null)
{
return Domain::get()
->filter(['Certificates.Issuer:PartialMatch' => 'Let\'s Encrypt'])
->sort('Domain');
->filter(['Certificates.Issuer:PartialMatch' => 'Let\'s Encrypt'])
->sort('Domain');
}

public function columns()
Expand Down
14 changes: 7 additions & 7 deletions mysite/code/Tasks/ClearData.php
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
<?php

/**
* Class for managing ClearData
* @package ${PACKAGE}
* Class for managing ClearData.
*/
class ClearData extends BuildTask {

class ClearData extends BuildTask
{
/**
* Implement this method in the task subclass to
* execute via the TaskRunner
* execute via the TaskRunner.
*
* @param SS_HTTPRequest $request
*/
public function run($request) {
public function run($request)
{
DB::query('TRUNCATE TABLE Domain');
DB::query('TRUNCATE TABLE Certificate');
}
}
}

0 comments on commit d99b99f

Please sign in to comment.