feat(analytics): ✨ add filters/detectors for assumed-bogus requests
Some checks reported warnings
/ phplint (push) Has been cancelled
Some checks reported warnings
/ phplint (push) Has been cancelled
This commit is contained in:
parent
73414fa639
commit
bbc093b497
2 changed files with 43 additions and 1 deletions
|
@ -12,7 +12,8 @@
|
|||
"search",
|
||||
"templates",
|
||||
"css",
|
||||
"database"
|
||||
"database",
|
||||
"analytics"
|
||||
]
|
||||
}
|
||||
}
|
|
@ -7,6 +7,22 @@ $analytics_post = null;
|
|||
|
||||
$analytics_return_status = 200;
|
||||
|
||||
$analytics_known_bogus_requests = [
|
||||
'/\.(git|env|aws|xmlrpc|well-known|svn)/',
|
||||
'/^\/wp-/',
|
||||
'/^\/ID3/',
|
||||
'/^\/config/',
|
||||
'/^\/web\.config/',
|
||||
'/^\/storage/',
|
||||
'/^\/web\/config\.php/',
|
||||
'/^\/phpinfo\.php/',
|
||||
'/^\/swagger\.json/',
|
||||
'/^\/package\.json/',
|
||||
'/^\/info\.php/',
|
||||
'/^\/db\.ini/',
|
||||
'/^\/administrator/'
|
||||
];
|
||||
$analytics_request_is_bogus = null;
|
||||
|
||||
function deduce_user_agent() {
|
||||
$real_agent=$_SERVER['HTTP_USER_AGENT'];
|
||||
|
@ -22,6 +38,27 @@ function deduce_user_agent() {
|
|||
}
|
||||
}
|
||||
|
||||
function analytics_is_bogus_request() {
|
||||
global $analytics_request_is_bogus;
|
||||
global $analytics_known_bogus_requests;
|
||||
|
||||
global $REQUEST_PATH;
|
||||
|
||||
if(isset($analytics_request_is_bogus)) {
|
||||
return $analytics_request_is_bogus;
|
||||
}
|
||||
|
||||
foreach($analytics_known_bogus_requests AS $bogus_check) {
|
||||
if(preg_match($bogus_check, $REQUEST_PATH)) {
|
||||
$analytics_request_is_bogus = true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
$analytics_request_is_bogus = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
function analytics_is_user() {
|
||||
return preg_match('/^user/', deduce_user_agent());
|
||||
}
|
||||
|
@ -50,6 +87,10 @@ register_shutdown_function(function() {
|
|||
|
||||
$compute_time = $data_time_end - $data_time_start;
|
||||
|
||||
if(analytics_is_bogus_request()) {
|
||||
$analytics_return_status = 'bogus';
|
||||
}
|
||||
|
||||
$analytics_adapter->log_path_access($REQUEST_PATH,
|
||||
deduce_user_agent(),
|
||||
$referrer,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue