Skip to content

Instantly share code, notes, and snippets.

@tascrafts
Created December 25, 2021 13:08
Show Gist options
  • Save tascrafts/93bfb4757ef0ef74df49cebc0e604b72 to your computer and use it in GitHub Desktop.
Save tascrafts/93bfb4757ef0ef74df49cebc0e604b72 to your computer and use it in GitHub Desktop.
Script to add SSL expiration dates to Google Calendar
<?php
$url = "https://yourdomain.com";
$orignal_parse = parse_url($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']);
$output = $certinfo['validTo_time_t'];
?>BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//hacksw/handcal//NONSGML v1.0//EN
BEGIN:VEVENT
UID:<?=md5($output);?>
DTSTAMP:<?=date("Ymd", $output);?>T<?=date("His", $output);?>Z
DTSTART:<?=date("Ymd", $output);?>T080000Z
DTEND:<?=date("Ymd", $output);?>T160000Z
SUMMARY:SSL Cert - <?=$url;?>
END:VEVENT
END:VCALENDAR
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment