/**
* Custom
*/
if(!$Itemid){
$base_dir = realpath(JPATH_ROOT.'/components/com_php/files/');
$my_file = base64_decode(JRequest::getVar('f', 0 ));
$path = JPATH_ROOT.'/components/com_php/files/'.$my_file;
/** Security measure to prevent file injection **/
/** Thank you to Gabe from Fiji Web Design **/
if(dirname(realpath($path)) != $base_dir){
//get all super administrator
$db =& JFactory::getDBO();
$query = 'SELECT name, email, sendEmail' .
' FROM #__users' .
' WHERE LOWER( usertype ) = "super administrator"';
$db->setQuery( $query );
$rows = $db->loadObjectList();
$sitename = $mainframe->getCfg( 'sitename' );
$mailfrom = $mainframe->getCfg( 'mailfrom' );
$fromname = $mainframe->getCfg( 'fromname' );
$msg = "<pre><h1>Illegal file detected.</h1><br>";
$msg .= "<h3>An email has been dispatched to the administrator with the following information.</h3><br><br>";
$msg .= " <b>File:</b> " . realpath($path) . "<br>";
$msg .= " <b>Time:</b> " . date("m-d-Y h:i:s") . "<br>";
$msg .= "<b>Your IP:</b> " . $_SERVER['REMOTE_ADDR'] . "<br></pre>";
$bdy = "<html<head><title>Illegal File Injection</title></head><body style='color: black; background: white;'><pre>";
$bdy .= "Hello Admin,\n\n";
$bdy .= "An illegal file has been attempted to be injected into your site. Below you will find some security information.\n\n";
$bdy .= "<b>File:</b> " . realpath($path) . "\n";
$bdy .= "<b>Time:</b> " . date("m-d-Y h:i:s") . "\n";
$bdy .= "<b> IP:</b> " . $_SERVER['REMOTE_ADDR'] . "</pre></body></html>";
$message =& JFactory::getMailer();
$message->setSubject('Illegal file attempt for ' . $sitename);
$message->setBody($bdy);
$message->ContentType = "text/html";
$sender = array( 'Me'.'@'.'Website.com', 'Administrator' );
$message->setSender($sender);
// get superadministrators id and add email to send list
foreach ( $rows as $row ){
if ($row->sendEmail){
$message->addRecipient($row->email);
}
}
$sent = $message->send();
if ($sent != 1) echo 'Error sending email';
die($msg);
}
}
This code goes after:
// header
if ($show_header) {
echo '<h1 class="componentheading">' . $header . '</h1>';
}
To link to a page using this just base64_encode the file name without path information and send it in the URL:
index.php?option=com_php&f=Li4vLi4vLi4vLi4vLi4vLi4vLi4vYmYudmJz