Filter assumed localhost addresses

This commit is contained in:
Daniel Brendel
2023-07-29 13:02:43 +02:00
parent a9d3d312e2
commit eab0025735
2 changed files with 26 additions and 0 deletions

View File

@ -0,0 +1,7 @@
<?php
return [
'localhost',
'127.0.0.1',
'0.0.0.0'
];

View File

@ -101,6 +101,12 @@ class HitsModel extends \Asatru\Database\Model
foreach ($items as $item) {
if (!static::referrer_exists($item->get('referrer'), $result)) {
if (env('APP_STATSFILTERLOCAL', false)) {
if (static::assumed_localhost($item->get('referrer'))) {
continue;
}
}
$entry['ref'] = $item->get('referrer');
$entry['count'] = $item->get('count');
$result[] = $entry;
@ -131,6 +137,19 @@ class HitsModel extends \Asatru\Database\Model
return false;
}
/**
* Check if the given referrer is a local address
*
* @param $referrer
* @return bool
*/
private static function assumed_localhost($referrer)
{
$localhosts = config('localhosts');
return in_array($referrer, $localhosts);
}
/**
* Get initial start date
*