From 5a0007002857caef276796383c05b5cbdcdcdd75 Mon Sep 17 00:00:00 2001 From: Terence Eden Date: Tue, 5 Mar 2024 21:51:00 +0000 Subject: [PATCH] Rationalise the signature logs --- index.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/index.php b/index.php index 4f79fcc..991599a 100644 --- a/index.php +++ b/index.php @@ -600,7 +600,7 @@ HTML; // Buttons to interact with a message. // By default, just shows a "Follow User" button. if ( "read" == $style ) { - $interactHTML = " "; + $interactHTML = "👤 "; } else { $interactHTML = ""; } @@ -1415,6 +1415,11 @@ HTML; function verifyHTTPSignature() { global $input, $body, $server, $directories; + // What type of message is this? What's the time now? + // Used in the log filename. + $type = urlencode( $body["type"] ); + $timestamp = ( new DateTime() )->format( DATE_RFC3339_EXTENDED ); + // Get the headers send with the request $headers = getallheaders(); // Ensure the header keys match the format expected by the signature @@ -1430,9 +1435,8 @@ HTML; $timeDifference = abs( $currentDatetime->getTimestamp() - $headerDatetime->getTimestamp() ); if ( $timeDifference > 30 ) { // Write a log detailing the error - $timestamp = ( new DateTime() )->format( DATE_RFC3339_EXTENDED ); // Filename for the log - $filename = "{$timestamp}.Signature.Time_Failure.txt"; + $filename = "{$timestamp}.{$type}.Signature.Time_Failure.txt"; // Save headers and request data to the timestamped file in the logs directory file_put_contents( $directories["logs"] . "/{$filename}", @@ -1467,9 +1471,7 @@ HTML; // Does our calculation match what was sent? if ( !( $digestCalculated == $digestHash ) ) { // Write a log detailing the error - $timestamp = ( new DateTime() )->format( DATE_RFC3339_EXTENDED ); - // Filename for the log - $filename = "{$timestamp}.Signature.Digest_Failure.txt"; + $filename = "{$timestamp}.{$type}.Signature.Digest_Failure.txt"; // Save headers and request data to the timestamped file in the logs directory file_put_contents( $directories["logs"] . "/{$filename}", @@ -1551,10 +1553,8 @@ HTML; $verified = null; } - // Write a log detailing the signature verification process - $timestamp = ( new DateTime() )->format( DATE_RFC3339_EXTENDED ); // Filename for the log - $filename = "{$timestamp}.Signature.". json_encode( $verified ) . ".txt"; + $filename = "{$timestamp}.{$type}.Signature.". json_encode( $verified ) . ".txt"; // Save headers and request data to the timestamped file in the logs directory file_put_contents( $directories["logs"] . "/{$filename}",