A plugin version (Evo 1.0.4 and prior, I’d guess) :
$md5hash = 'your_checksum_from_above'; //could get this from the DB if stored there
$chkmd5return = md5_file('index.php');
if ($chkmd5return != $md5hash)
{
$pathtoroot = substr(MODX_BASE_PATH, 0, -strlen(MODX_BASE_URL)) . '/';
if (strpos($pathtoroot,'public_html')>0 ) $pathtoroot = substr(MODX_BASE_PATH, 0, strpos(MODX_BASE_PATH, 'public_html'));
//if backup copy is buried above the root in a subfolder, append that here
$backuprestored = copy($pathtoroot.'indexbackup.php', 'index.php'); //assumes you named backup copy indexbackup.php
$emailaddy = '[email protected]';
if ($backuprestored)
{
$message = 'Backup restored for '.MODX_SITE_URL;
header("Location: .");
}
else
{
$message = 'Tried to restore backup copy but failed for '.MODX_SITE_URL;
//try a backup plan?
//how log message to system?
//should log the problem to an error file
}
mail($emailaddy,'Checksum analysis',$message);
}
I think this accomodates testing on a local install like XAMPP as well as a live version.
What I did was save this as a plugin and select
OnWebPagePrerender under System Events as the trigger. So no systems files were messed with.
EDIT : It looks like OnWebPageInit is the first event unconditionally invoked.
Does anyone know if this would be getting called early enough in the code execution to prevent any hacked code from getting executed? Or, rather, what does go on prior to this event?
MattC
PS FWIW, I tried storing the backup copy in the database and writing it to disk, but ran into a permissions problem. Probably a good thing ...
Edit : fix of typo in question, revised event name used