Last active
September 17, 2017 09:34
-
-
Save sbrl/d92ed91f52227e587730e3eb521e607b to your computer and use it in GitHub Desktop.
A simple SSL certificate status panel for tracking the expiry of your (many) TLS certificates. #php #microservice
This file contains hidden or 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
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <meta charset="utf-8" /> | |
| <title>SSL Certificate Status Panel</title> | |
| </head> | |
| <body> | |
| <h1>SSL Certificate Status Panel</h1> | |
| <?php | |
| require("zengine.php"); | |
| // From http://snippets.pro/snippet/137-php-convert-the-timestamp-to-human-readable-format/ | |
| // Modified to calculate time to instead of time since | |
| function human_time_to($time) | |
| { | |
| $timediff = $time - time(); | |
| $tokens = array ( | |
| //31536000 => 'year', | |
| //2592000 => 'month', | |
| //604800 => 'week', | |
| 86400 => 'day', | |
| 3600 => 'hour', | |
| 60 => 'minute', | |
| 1 => 'second' | |
| ); | |
| foreach ($tokens as $unit => $text) { | |
| if ($timediff < $unit) continue; | |
| $numberOfUnits = floor($timediff / $unit); | |
| return $numberOfUnits.' '.$text.(($numberOfUnits>1)?'s':''); | |
| } | |
| } | |
| echo("<ul>"); | |
| foreach($results as $result) | |
| { | |
| $time_to_expiry = human_time_to($result["valid_to"]); | |
| echo("<li data-hash='" . $result["hash"] . "'> | |
| <span class='domain'>" . $result["domain"] . "</span> | |
| <span class='issuer'>" . $result["issuer_name"] . "</span> | |
| <span class='valid-to'>$time_to_expiry</span> | |
| </li>"); | |
| } | |
| echo("</ul>\n"); | |
| ?> | |
| <!---------------------> | |
| <link rel="stylesheet" href="theme.css" /> | |
| </body> | |
| </html> |
This file contains hidden or 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
| html, body { font-size: 100%; } | |
| body | |
| { | |
| font-family: sans-serif; | |
| background: rgba(106, 220, 76, 0.69); | |
| color: darkgreen; | |
| } | |
| h1 | |
| { | |
| margin: 0.5rem; | |
| padding: 0.5rem; | |
| color: darkgreen; | |
| text-align: center; | |
| } | |
| span | |
| { | |
| margin: 0.5rem; | |
| padding: 0.5rem; | |
| } | |
| ul | |
| { | |
| margin: 0.5rem; | |
| padding: 0.5rem; | |
| } | |
| li | |
| { | |
| display: flex; | |
| margin: 0.5rem; | |
| padding: 0.5rem; | |
| background: rgba(255, 255, 255, 0.4); | |
| border-radius: 0.3rem; | |
| list-style-type: none; | |
| } | |
| li:before | |
| { | |
| content: attr(data-hash); | |
| margin: 0.5rem; | |
| padding: 0.5rem; | |
| opacity: 0.6; | |
| } | |
| .domain { flex: 4; } | |
| .issuer { flex: 2; } | |
| .valid-to { flex: 2; } | |
| .valid-to:before | |
| { | |
| content: "Expires in:"; | |
| margin: 0.5rem; | |
| padding: 0.5rem; | |
| opacity: 0.6; | |
| } |
This file contains hidden or 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 | |
| $domains = [ | |
| "example.com", | |
| "git.cheese.org" | |
| ]; | |
| $raw_results = []; | |
| foreach($domains as $domain) | |
| { | |
| //echo("Probing $domain...\n"); | |
| $get = stream_context_create(["ssl" => [ "capture_peer_cert" => TRUE ] ]); | |
| $read = stream_socket_client("ssl://$domain:443", $error_num, $error_string, 10, STREAM_CLIENT_CONNECT, $get); | |
| $cert = stream_context_get_params($read); | |
| $certinfo = openssl_x509_parse($cert["options"]["ssl"]["peer_certificate"]); | |
| $raw_results[] = $certinfo; | |
| } | |
| //var_dump($raw_results); | |
| $results = []; | |
| foreach($raw_results as $raw_result) | |
| { | |
| $results[] = [ | |
| "domain" => $raw_result["subject"]["CN"], | |
| "valid_to" => $raw_result["validTo_time_t"], | |
| "issuer_name" => $raw_result["issuer"]["O"], | |
| "hash" => $raw_result["hash"] | |
| ]; | |
| } | |
| if(__FILE__ == $_SERVER["SCRIPT_FILENAME"]) | |
| { | |
| header("content-type: application/json"); | |
| echo(json_encode($results, JSON_PRETTY_PRINT)); | |
| } | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment