Generate an e-mail on page-not-found (404) errors [support thread]
I got tired of scouring my Apache logs for 404 errors, so wrote this little update that will send an e-mail to the address of your choice as part of the page_not_found processing.
Installation is short and simple (see the readme). You'll need to edit /includes/languages/english/YOURTEMPLATE/page_not_found.php to contain your desired e-mail address.
See download here: http://www.zen-cart.com/downloads.php?do=file&id=1090
Re: Generate an e-mail on page-not-found (404) errors
If you have a Google WebmasterTools account, there's a neat little report in there listing all the URLs that Google finds as 'not found' and all the pages that have those links on.
Most of the time, the list will contain URLs for removed products, but it's worth a scan every now and again.
Re: Generate an e-mail on page-not-found (404) errors
Thanks for the info, g1smd. My focus for developing this little add-on was more to get a notification for accesses that are likely someone groping around my site, of the like
www.example.com/admin
... when I've followed the security guidelines and renamed that folder.
Re: Generate an e-mail on page-not-found (404) errors
OK. That works too. :smile:
Additionally, I like to add this in the .htaccess file in the /admin/ folder:
Code:
Order Deny,Allow
Deny from all
Allow from 11.22.33
which allows access from a small range of IP addresses.
Re: Generate an e-mail on page-not-found (404) errors
Oops! There was an error in the first release (the observer class was not being instantiated).
I've just uploaded v1.1 to correct the error in class.emailFor404.php from
Code:
function emailFor404() {
if (SEND_404_ERRORS_EMAIL_TO_STATUS == '1' and SEND_404_ERRORS_EMAILS_TO != '') {
$this->attach($this, array('NOTIFY_HEADER_END_PAGE_NOT_FOUND'));
}
}
to
Code:
function emailFor404() {
global $zco_notifier;
if (SEND_404_ERRORS_EMAIL_TO_STATUS == '1' and SEND_404_ERRORS_EMAILS_TO != '') {
$zco_notifier->attach($this, array('NOTIFY_HEADER_END_PAGE_NOT_FOUND'));
}
}
Re: Generate an e-mail on page-not-found (404) errors
The $this-> approach will work fine in 1.3.9 and newer.
For 1.3.8 and older you may have to use the old $zco_notifier-> approach instead.
Email on 404 (page-not-found) errors [support thread]
I've updated this add-on to v1.2 (http://www.zen-cart.com/downloads.php?do=file&id=1090), including a switch to enable/disable the archiving of these emails.
email body text not included in email
Hi,
Just tried out this latest version on ZC 1.5.
I receive the email but the text is not passed, its always:
Quote:
A 404 Error Was Generated
$EMAIL_MESSAGE_HTML
Strangely the email is in html format irrespective of the format chosen in the admin.
I get the same results with an (almost) vanilla 1.5 installation.
It tried it local/Xampp and remote hosting, same result.
regards
Steve
Re: email body text not included in email
I'm having a devil of a time replicating this. I've tried changing my CHARSET to utf-8 (which I'm assuming you're using), tried running as a logged-in or guest customer, changing my admin email format from HTML to Text and back. Regardless of these settings, I'm always receiving a Text-format message:
Code:
A user at host address [xxxx] with IP address [yyyy] generated a 404 using the query string [/index.php?main_page=elsewhere].
The settings in my Configuration->Email Settings are
Code:
E-Mail Transport Method PHP
E-Mail Linefeeds LF
Use MIME HTML When Sending Emails true
What are your email settings?
Re: email body text not included in email
torvista, would you try this updated version of /includes/classes/class.emailFor404.php and let me know if it works?
Code:
<?php
class emailFor404 extends base {
/** constructor method !
*
* Attach observer class to the global $zco_notifier and watch for a single notifier event.
*/
function emailFor404() {
global $zco_notifier;
if (SEND_404_ERRORS_EMAIL_TO_STATUS == '1' and SEND_404_ERRORS_EMAILS_TO != '' and SEND_404_ERRORS_EMAILS_TO != '[email protected]') {
$zco_notifier->attach($this, array('NOTIFY_HEADER_END_PAGE_NOT_FOUND'));
}
}
/** Actual Method that does the desired activity
*
* Called by observed class when any of the notifiable events occur
*
* @param object $class
* @param string $eventID
*/
function update(&$class, $eventID, $paramsArray = array()) {
// BOF Send email to admin for 404 errors
$email_text = sprintf(EMAIL_PAGE_NOT_FOUND_CONTENT, $_SESSION['customers_host_address'], $_SESSION['customers_ip_address'], $_ENV['REQUEST_URI'])."\n\n";
$email_subject = EMAIL_PAGE_NOT_FOUND_SUBJECT;
$module = (SEND_404_ERRORS_EMAILS_ARCHIVE != '0') ? 'default' : 'no_archive';
$html_msg['EMAIL_SUBJECT'] = EMAIL_PAGE_NOT_FOUND_SUBJECT;
$html_msg['EMAIL_MESSAGE_HTML'] = str_replace('\n','',$email_text);
zen_mail('', SEND_404_ERRORS_EMAILS_TO, $email_subject, $email_text, STORE_NAME, EMAIL_FROM, $html_msg, $module);
// EOF Send email to admin for 404 errors
}
}
?>
Re: email body text not included in email
Got it! If the email address to which the 404 emails are to be sent was used as a test-customer account email and that customer account uses HTML email settings, the email described by torvista will be sent. I've submitted v1.2.1 to the plugins area to correct the problem and describe how the HTML/TEXT emails will be sent.
Re: email body text not included in email
Well done! Excellent service!
Re: email body text not included in email
Thank you for your kind words! Here's the entire updated "update" function in the class module:
Code:
function update(&$class, $eventID, $paramsArray = array()) {
// BOF Send email to admin for 404 errors
$email_text = sprintf(EMAIL_PAGE_NOT_FOUND_CONTENT, $_SESSION['customers_host_address'], $_SESSION['customers_ip_address'], $_ENV['REQUEST_URI'])."\n\n";
$email_subject = EMAIL_PAGE_NOT_FOUND_SUBJECT;
$module = (SEND_404_ERRORS_EMAIL_ARCHIVE != '0') ? 'default' : 'no_archive';
$html_msg['EMAIL_SUBJECT'] = EMAIL_PAGE_NOT_FOUND_SUBJECT;
$html_msg['EMAIL_MESSAGE_HTML'] .= str_replace('\n','',$email_text);
zen_mail('', SEND_404_ERRORS_EMAILS_TO, $email_subject, $email_text, STORE_NAME, EMAIL_FROM, $html_msg, $module);
// EOF Send email to admin for 404 errors
}
Re: Generate an e-mail on page-not-found (404) errors [support thread]
While the current version in the plugins will "play nice" with Zen Cart v1.5.5, it needed a change for PHP 7.0 compliance (class constructor named __construct). v1.2.3 has been submitted to the plugins to correct this incompatibility.
Re: Generate an e-mail on page-not-found (404) errors [support thread]
I've just submitted v1.2.4 for the Zen Cart moderators' review and will post back here when it's available for download.
This version contains changes captured for GitHub issue #2. Language constants (and pseudo-configuration definitions) have been moved from the auto_loader to a language-based extra_definitions file.
The email report now includes the contents of the entire $_SERVER and $_SESSION values.
Re: Generate an e-mail on page-not-found (404) errors [support thread]
Quote:
Originally Posted by
lat9
I've just submitted v1.2.4 for the Zen Cart moderators' review and will post back here when it's available for download.
This version contains changes captured for GitHub issue
#2. Language constants (and pseudo-configuration definitions) have been moved from the auto_loader to a language-based extra_definitions file.
The email report now includes the contents of the entire $_SERVER and $_SESSION values.
Now available for download: https://www.zen-cart.com/downloads.php?do=file&id=1090
Re: Generate an e-mail on page-not-found (404) errors [support thread]
Quote:
Originally Posted by
lat9
I don't know how I got this far without knowing this mod exists. Perfect. YOU ROCK!
Re: Generate an e-mail on page-not-found (404) errors [support thread]
Any ideas if this would work with zen cart 2.1.0?
Re: Generate an e-mail on page-not-found (404) errors [support thread]
Quote:
Originally Posted by
TamyA
Any ideas if this would work with zen cart 2.1.0?
I see no reason why it wouldn't.
Re: Generate an e-mail on page-not-found (404) errors [support thread]
Quote:
Originally Posted by
lat9
I see no reason why it wouldn't.
Well, i copied the file and did the set up and it works, Now,
I am not sure to get happy or cry that it works.
I start getting emails like if you open a flood gate, 95+% of the emails about
loading images from the bmz_cache directory and it has a wired format like
'/Main-Category/Sub-Category/bmz_cache/m/mso421_2jpg.image.480x480.gif',
this is the structure of the bmz_cache folder /public_html/bmz_cache/
why the bot accessing it with '/Main-Category/Sub-Category/'
This is part of the email
'USER' => 'user74',
'HOME' => '/home/user74',
'SCRIPT_NAME' => '/index.php',
'REQUEST_URI' => '/Main-Catagory/Sub-Catagory/bmz_cache/m/mso421_2jpg.image.480x480.gif',
'QUERY_STRING' => 'main_page=page_not_found',
'REQUEST_METHOD' => 'GET',
'SERVER_PROTOCOL' => 'HTTP/2.0',
'GATEWAY_INTERFACE' => 'CGI/1.1',
'REDIRECT_URL' => '/Main-Category/Sub-Category/bmz_cache/m/mso421_2jpg.image.480x480.gif',
'REMOTE_PORT' => '419xx',
'SCRIPT_FILENAME' => '/home/user74/public_html/index.php',
'SERVER_ADMIN' => '[email protected]',
'CONTEXT_DOCUMENT_ROOT' => '/home/user74/public_html',