Skip to content

Commit

Permalink
Improved handling of ignore_user_agents (OpenMage#3238)
Browse files Browse the repository at this point in the history
Co-authored-by: Fabrizio Balliano <fabrizio.balliano@gmail.com>
  • Loading branch information
empiricompany and fballiano committed May 13, 2023
1 parent 0e8319c commit c0d136a
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 9 deletions.
17 changes: 11 additions & 6 deletions app/code/core/Mage/Log/Model/Visitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,17 +101,22 @@ public function __construct(array $data = [])
protected function _construct()
{
$this->_init('log/visitor');
$userAgent = $this->_httpHelper->getHttpUserAgent();
if ($this->_logCondition->isLogDisabled()) {
$this->_skipRequestLogging = true;
return;
}

$ignoreAgents = $this->_config->getNode('global/ignore_user_agents');
if ($ignoreAgents) {
$ignoreAgents = $ignoreAgents->asArray();
if (in_array($userAgent, $ignoreAgents)) {
$this->_skipRequestLogging = true;
$userAgent = $this->_httpHelper->getHttpUserAgent();
foreach ($ignoreAgents as $ignoreAgent) {
if (stripos($userAgent, $ignoreAgent) !== false) {
$this->_skipRequestLogging = true;
break;
}
}
}
if ($this->_logCondition->isLogDisabled()) {
$this->_skipRequestLogging = true;
}
}

/**
Expand Down
25 changes: 22 additions & 3 deletions app/code/core/Mage/Log/etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,28 @@
</entities>
</ignoredModules>
<ignore_user_agents>
<google1>Googlebot/1.0 (googlebot@googlebot.com http://googlebot.com/)</google1>
<google2>Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)</google2>
<google3>Googlebot/2.1 (+http://www.googlebot.com/bot.html)</google3>
<adsbot>AdsBot</adsbot>
<alphabot>AlphaBot</alphabot>
<amazonbot>Amazonbot</amazonbot>
<bingbot>bingbot</bingbot>
<blexbot>BLEXBot</blexbot>
<dotbot>DotBot</dotbot>
<facebookexternalhit>facebookexternalhit</facebookexternalhit>
<google>Googlebot</google>
<google-site-verification>Google-Site-Verification</google-site-verification>
<hrefsbot>AhrefsBot</hrefsbot>
<istellabot>istellabot</istellabot>
<mauibot>MauiBot</mauibot>
<mj12bot>MJ12bot</mj12bot>
<mod_pagespeed>mod_pagespeed</mod_pagespeed>
<opensiteexplorer>spbot</opensiteexplorer>
<pinterestbot>Pinterestbot</pinterestbot>
<semrushbot>SemrushBot</semrushbot>
<seotester>SEOTesterBot</seotester>
<yandexbot>YandexBot</yandexbot>
<yandeximage>YandexImages</yandeximage>
<yandexmobilebot>YandexMobileBot</yandexmobilebot>
<zoominfobot>ZoominfoBot</zoominfobot>
</ignore_user_agents>
<helpers>
<log>
Expand Down

0 comments on commit c0d136a

Please sign in to comment.