Created
May 17, 2023 11:07
-
-
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
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
<?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"; |
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
Thank you for posting this code! It's much easier than calling openssl from the command line.