Last active
June 18, 2023 15:02
-
-
Save pstoute/f5d9227498b858da824d0f267d1ab8d8 to your computer and use it in GitHub Desktop.
Enable logging for Fortress by Snicco. This has not been tested on any hosting environment other than GridPane.
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 | |
/** | |
* Plugin Name: Fortress Logging - Only activate when actively troubleshooting | |
* Description: Enables a logging of the response event (other actions need to be made in order to have this work since fortress does not expose the response by default. | |
* Version: 0.0.1 | |
*/ | |
use Snicco\Bundle\HttpRouting\Event\ResponseSent; | |
add_action(ResponseSent::class, function (ResponseSent $event) { | |
// ONLY LOG TOTP CHALLENGE. | |
if (!str_contains($_SERVER['REQUEST_URI'], 'snicco-fortress/auth/totp/challenge')) { | |
return; | |
} | |
// CHANGE SITE_URL to match your domain. | |
$site_url = parse_url( get_site_url(), PHP_URL_HOST ) ); | |
$dir = "/var/www/$site_url/fortress/var/response_debug"; | |
if (!is_dir($dir)) { | |
mkdir($dir, 0777, true); | |
} | |
// Getting the current date and time in the format YYYY-MM-DD_HH-MM-SS | |
$timestamp = date('Y-m-d_H-i-s'); | |
// GET THE RESPONSE HTML AS STRING AND LOG IT. | |
$response = $event->response; | |
$body = $response->getBody(); | |
$body->rewind(); | |
$body_string = $body->__toString(); | |
file_put_contents("$dir/$timestamp.body.html", $body_string, LOCK_EX); | |
// LOG THE RESPONSE HEADERS | |
$headers = $response->getHeaders(); | |
file_put_contents("$dir/$timestamp.headers.json", json_encode($headers), LOCK_EX); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment