From 8f6d8e481f8728239a23a542134ea82dc065cdb5 Mon Sep 17 00:00:00 2001 From: RCDaddy Date: Fri, 7 Dec 2018 16:44:18 +0000 Subject: [PATCH 1/5] Add slack integration --- README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README.md b/README.md index c470173..488f8e3 100644 --- a/README.md +++ b/README.md @@ -48,6 +48,14 @@ Also change the `$current_domain` variable, it is used in all the email addresse And `$current_link`, which may or may not be the same. It is used in the confirm and unsubscribe links, and depends on your webserver configuration. `example.com/subdir` here means your unsubscribe links will start `https://example.com/subdir/unsubscribe.php`. $current_link = "certificatemonitor.org"; + +If you use Slack/Rocketchat, you can set up automatic posts whenever a subscription is added or removed, or checked and found to be expiring soon, expired or failed. To do this, create an [incoming webhook](https://api.slack.com/incoming-webhooks) and add its URL to the configuration (if you don't want this function, leave the string empty): + + $slack_webhook = "https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX"; + + or + + $slack_webhook = "https://my.rocketchat.com/XXXXXXXXXXXXXXXXXXXXXXXX"; Set up the cronjob to run once a day: From 1a2c95b57ce5690d3980208d2b492b7ed5e4381b Mon Sep 17 00:00:00 2001 From: RCDaddy Date: Fri, 7 Dec 2018 16:46:39 +0000 Subject: [PATCH 2/5] Update add_check.php --- functions/add_check.php | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/functions/add_check.php b/functions/add_check.php index 8776a0f..281484d 100644 --- a/functions/add_check.php +++ b/functions/add_check.php @@ -121,7 +121,20 @@ function add_domain_check($id,$visitor_ip) { 'List-Unsubscribe: " . "\r\n" . 'X-Mailer: PHP/4.1.1'; - + slack_send_array(array('attachments' => array(array( + 'fallback' => $subject, + 'color' => '#00ff00', + 'pretext' => $subject, + 'title' => $json_a[$id]['domain'], + 'title_link' => 'https://' . $json_a[$id]['domain'], + 'text' => 'Subscription confirmed for this domain:', + 'fields' => array( + array('title' => 'Domain', 'value' => $json_a[$id]['domain']), + array('title' => 'Email', 'value' => $json_a[$id]['email']), + array('title' => 'Confirmed from', 'value' => $visitor_ip, 'short' => TRUE), + array('title' => 'Confirmed date', 'value' => date("Y-m-d H:i:s T"), 'short' => TRUE), + ) + )))); if (mail($to, $subject, $message, $headers) === true) { $result['success'][] = true; @@ -131,4 +144,4 @@ function add_domain_check($id,$visitor_ip) { } return $result; -} \ No newline at end of file +} From 01958477a25db6ec0a9c4bdb1d0231339f0d5243 Mon Sep 17 00:00:00 2001 From: RCDaddy Date: Fri, 7 Dec 2018 16:48:16 +0000 Subject: [PATCH 3/5] Update email.php --- functions/email.php | 68 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/functions/email.php b/functions/email.php index 7ab6e0c..148f4f8 100644 --- a/functions/email.php +++ b/functions/email.php @@ -57,6 +57,19 @@ function send_error_mail($domain, $email, $errors) { 'List-Unsubscribe: " . "\r\n" . 'X-Mailer: PHP/4.1.1'; + slack_send_array(array('attachments' => array(array( + 'fallback' => $subject, + 'color' => '#ff0000', + 'pretext' => $subject, + 'title' => $domain, + 'title_link' => 'https://' . $domain, + 'text' => 'Failed to check certificates for this domain:', + 'fields' => array( + array('title' => 'Errors', 'value' => $errors), + array('title' => 'Failures', 'value' => $failures) + ) + )))); + if (mail($to, $subject, $message, $headers) === true) { echo "\t\tEmail sent to $to.\n"; return true; @@ -117,6 +130,22 @@ function send_cert_expired_email($days, $domain, $email, $raw_cert) { 'List-Unsubscribe: " . "\r\n" . 'X-Mailer: PHP/4.1.1'; + slack_send_array(array('attachments' => array(array( + 'fallback' => $subject, + 'color' => '#ff0000', + 'pretext' => $subject, + 'title' => $domain, + 'title_link' => 'https://' . $domain, + 'text' => 'The following certificate in the chain for this domain has expired:', + 'fields' => array( + array('title' => 'Common Name', 'value' => $cert_cn), + array('title' => 'Subject', 'value' => $cert_subject), + array('title' => 'Serial', 'value' => $cert_serial), + array('title' => 'Valid From', 'value' => date("Y-m-d H:i:s T", $cert_validfrom_date), 'short' => TRUE), + array('title' => 'Valid Until', 'value' => date("Y-m-d H:i:s T", $cert_expiry_date), 'short' => TRUE) + ) + )))); + if (mail($to, $subject, $message, $headers) === true) { echo "\t\tEmail sent to $to.\n"; return true; @@ -178,6 +207,22 @@ function send_expires_in_email($days, $domain, $email, $raw_cert) { 'List-Unsubscribe: " . "\r\n" . 'X-Mailer: PHP/4.1.1'; + slack_send_array(array('attachments' => array(array( + 'fallback' => $subject, + 'color' => '#ffff00', + 'pretext' => $subject, + 'title' => $domain, + 'title_link' => 'https://' . $domain, + 'text' => 'The following certificate in the chain for this domain is about to expire:', + 'fields' => array( + array('title' => 'Common Name', 'value' => $cert_cn), + array('title' => 'Subject', 'value' => $cert_subject), + array('title' => 'Serial', 'value' => $cert_serial), + array('title' => 'Valid From', 'value' => date("Y-m-d H:i:s T", $cert_validfrom_date), 'short' => TRUE), + array('title' => 'Valid Until', 'value' => date("Y-m-d H:i:s T", $cert_expiry_date), 'short' => TRUE) + ) + )))); + if (mail($to, $subject, $message, $headers) === true) { echo "\t\tEmail sent to $to.\n"; return true; @@ -189,5 +234,28 @@ function send_expires_in_email($days, $domain, $email, $raw_cert) { } } +function slack_send_array($payload) { + global $slack_webhook; + if (!$payload) { + echo "\t\tNot sending empty Slack payload.\n"; + return FALSE; + } + if (!$slack_webhook) { + echo "\t\tNo Slack webhook URL set.\n"; + return FALSE; + } + $ch = curl_init($slack_webhook); + $postdata = array('payload' => json_encode($payload)); + curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata); + $result = curl_exec($ch); + $http = curl_getinfo($ch, CURLINFO_HTTP_CODE); + curl_close($ch); + if ($result && $http == 200) { + echo "\n\t\tSlack message sent.\n"; + } else { + echo "\n\t\tError sending Slack message.\n"; + } + return $result; +} ?> From dae595ca8aaaf8729313118bb8296171384346fa Mon Sep 17 00:00:00 2001 From: RCDaddy Date: Fri, 7 Dec 2018 16:49:10 +0000 Subject: [PATCH 4/5] Update remove_check.php --- functions/remove_check.php | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/functions/remove_check.php b/functions/remove_check.php index 0425f24..953687c 100644 --- a/functions/remove_check.php +++ b/functions/remove_check.php @@ -91,7 +91,22 @@ function remove_domain_check($id,$visitor_ip) { 'List-Unsubscribe: " . "\r\n" . 'X-Mailer: PHP/4.1.1'; - if (mail($to, $subject, $message, $headers) === true) { + slack_send_array(array('attachments' => array(array( + 'fallback' => $subject, + 'color' => '#ffff00', + 'pretext' => $subject, + 'title' => $deleted_json_a[$id]['domain'], + 'title_link' => 'https://' . $deleted_json_a[$id]['domain'], + 'text' => 'Subscription removed for this domain:', + 'fields' => array( + array('title' => 'Domain', 'value' => $deleted_json_a[$id]['domain']), + array('title' => 'Email', 'value' => $deleted_json_a[$id]['email']), + array('title' => 'Removed from', 'value' => $visitor_ip, 'short' => TRUE), + array('title' => 'Removed date', 'value' => date("Y-m-d H:i:s T"), 'short' => TRUE), + ) + )))); + + if (mail($to, $subject, $message, $headers) === true) { $result['success'][] = true; } else { $result['errors'][] = "Can't send email."; @@ -100,4 +115,4 @@ function remove_domain_check($id,$visitor_ip) { return $result; } } -} \ No newline at end of file +} From fd3242dc3ffb4dfd18f6985d7f6ff16bec60cbe1 Mon Sep 17 00:00:00 2001 From: RCDaddy Date: Fri, 7 Dec 2018 16:50:11 +0000 Subject: [PATCH 5/5] Update variables.php --- functions/variables.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/functions/variables.php b/functions/variables.php index b5551af..0547054 100644 --- a/functions/variables.php +++ b/functions/variables.php @@ -31,6 +31,8 @@ $current_domain = "certificatemonitor.org"; $current_link = "certificatemonitor.org"; +$slack_webhook = ""; + $showListOfDomains = false; $showEmailsOnListOfDomains = false; $showClickToUnsubscribeOnListOfDomains = false;