Skip to content

Instantly share code, notes, and snippets.

@tascrafts
Created May 17, 2023 11:07
Show Gist options
  • Save tascrafts/82fb107f4e1883b948c33a10a000801a to your computer and use it in GitHub Desktop.
Save tascrafts/82fb107f4e1883b948c33a10a000801a to your computer and use it in GitHub Desktop.
A PHP script to check and display SSL certificate expiration in Google and .ical calendars
<?php
$urls[] = array(
"name" => "Domain 1 Name",
"url" => "https://domain.com"
);
$urls[] = array(
"name" => "Domain 2 Name",
"url" => "https://subdomain.domain.org"
);
$urls[] = array(
"name" => "Domain 3 Name",
"url" => "https://domain.io"
);
echo 'BEGIN:VCALENDAR' . "\n";
echo 'VERSION:2.0' . "\n";
echo 'PRODID:-//hacksw/handcal//NONSGML v1.0//EN' . "\n\n";
foreach($urls as $value) {
$orignal_parse = parse_url($value['url'], PHP_URL_HOST);
$get = stream_context_create(array("ssl" => array("capture_peer_cert" => TRUE)));
$read = stream_socket_client("ssl://".$orignal_parse.":443", $errno, $errstr, 30, STREAM_CLIENT_CONNECT, $get);
$cert = stream_context_get_params($read);
$certinfo = openssl_x509_parse($cert['options']['ssl']['peer_certificate']);
$valid_to_unix = $certinfo['validTo_time_t'];
echo "BEGIN:VEVENT\n";
echo "UID:" . uniqid() . "\n";
echo "DTSTAMP:".date("Ymd")."T".date("His")."Z\n";
echo "DTSTART:".date("Ymd", $valid_to_unix)."T080000Z\n";
echo "DTEND:".date("Ymd", $valid_to_unix)."T160000Z\n";
echo "SUMMARY:SSL Cert - {$value['name']}\n";
echo "END:VEVENT\n\n";
}
echo "END:VCALENDAR";
@tascrafts
Copy link
Author

You're very welcome! Thank you for leaving a comment! I've got about 10 domains on it and it's been so useful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment