Skip to content

Instantly share code, notes, and snippets.

@iamrobert
Created January 3, 2025 02:04
Show Gist options
  • Save iamrobert/9e4027706bb577a618a48d1b47941d99 to your computer and use it in GitHub Desktop.
Save iamrobert/9e4027706bb577a618a48d1b47941d99 to your computer and use it in GitHub Desktop.
JOOOMLA J4 DEBUGGER - overwrite administrator/index.php
<?php
/* + JOOOMLA DEBUGGER- will write to /administrator/logs/admin-500.log.
+ Overwrite your /administrator/index.php root file
+ Revert back after debugging!
======================================================================*/
// At the very start of /administrator/index.php
if (!function_exists('debugLog')) {
function debugLog($message, $data = null) {
$logFile = __DIR__ . '/logs/admin-500.log';
$timestamp = date('Y-m-d H:i:s');
$logMessage = "[{$timestamp}] {$message}";
if ($data !== null) {
$logMessage .= ": " . print_r($data, true);
}
file_put_contents($logFile, $logMessage . PHP_EOL, FILE_APPEND);
}
}
// Enable error reporting
ini_set('display_errors', 0);
error_reporting(E_ALL);
ini_set('log_errors', 1);
ini_set('error_log', __DIR__ . '/logs/php-errors.log');
try {
debugLog('Admin request starting', [
'method' => $_SERVER['REQUEST_METHOD'],
'uri' => $_SERVER['REQUEST_URI'],
'post' => $_POST,
'task' => $_REQUEST['task'] ?? 'none'
]);
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
debugLog('POST Headers', getallheaders());
debugLog('POST Session', $_SESSION ?? 'No Session');
debugLog('POST Cookies', $_COOKIE);
}
/**
* @package Joomla.Administrator
*
* @copyright (C) 2005 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
// NOTE: This file should remain compatible with PHP 5.2 to allow us to run our PHP minimum check and show a friendly error message
// Define the application's minimum supported PHP version as a constant so it can be referenced within the application.
define('JOOMLA_MINIMUM_PHP', '7.2.5');
if (version_compare(PHP_VERSION, JOOMLA_MINIMUM_PHP, '<')) {
die(
str_replace(
'{{phpversion}}',
JOOMLA_MINIMUM_PHP,
file_get_contents(dirname(__FILE__) . '/../templates/system/incompatible.html')
)
);
}
/**
* Constant that is checked in included files to prevent direct access.
* define() is used rather than "const" to not error for PHP 5.2 and lower
*/
define('_JEXEC', 1);
// Run the application - All executable code should be triggered through this file
require_once dirname(__FILE__) . '/includes/app.php';
} catch (Exception $e) {
debugLog('Admin error', [
'message' => $e->getMessage(),
'file' => $e->getFile(),
'line' => $e->getLine(),
'trace' => $e->getTraceAsString()
]);
throw $e;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment