Commit a2531ba9 authored by Erick Hitter's avatar Erick Hitter

Alert for anything expiring within 30 days

parent 92061175
......@@ -26,7 +26,6 @@ function report( $exit = true ): void {
'CN',
'Expires',
'Days Left',
'SAN',
],
];
......@@ -48,24 +47,13 @@ function report( $exit = true ): void {
1 => $x509['subject']['CN'],
2 => date( 'Y-m-d H:i:s T', $x509['validTo_time_t'] ),
3 => (int) round( ( $x509['validTo_time_t'] - time() ) / 86400 ),
4 => '',
];
if ( ! $dir_includes_expired && $cert_data[3] <= 0 ) {
// Alert if any expire within the next 30 days.
if ( ! $dir_includes_expired && $cert_data[3] - 30 <= 0 ) {
$dir_includes_expired = true;
}
if ( isset( $x509['extensions']['subjectAltName'] ) ) {
$sans = explode( ',', $x509['extensions']['subjectAltName'] );
foreach ( $sans as $i => $san ) {
$san = explode( ':', $san );
$sans[ $i ] = array_pop( $san );
}
$cert_data[4] = implode( ' ', $sans );
}
$data[] = $cert_data;
}
......@@ -74,6 +62,10 @@ function report( $exit = true ): void {
$table->sort( 2 );
$table->display();
if ( $dir_includes_expired ) {
echo "EXPIRING CERTIFICATES FOUND!\n";
}
if ( $exit ) {
exit( $dir_includes_expired ? 1 : 0 );
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment