Compare commits
No commits in common. "bbc093b4973e9958dc30d87617481035dfd78718" and "6ae06b47650d2ae9eaed243810e0fc30720134e7" have entirely different histories.
bbc093b497
...
6ae06b4765
5 changed files with 4 additions and 54 deletions
|
@ -12,8 +12,7 @@
|
||||||
"search",
|
"search",
|
||||||
"templates",
|
"templates",
|
||||||
"css",
|
"css",
|
||||||
"database",
|
"database"
|
||||||
"analytics"
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -8,7 +8,7 @@ interface AnalyticsInterface {
|
||||||
public function log_path_access(
|
public function log_path_access(
|
||||||
$path,
|
$path,
|
||||||
$agent,
|
$agent,
|
||||||
$referrer, $runtime, $status = 200);
|
$referrer, $runtime);
|
||||||
|
|
||||||
public function log_path_errcode(
|
public function log_path_errcode(
|
||||||
$path,
|
$path,
|
||||||
|
|
|
@ -72,7 +72,7 @@ class MySQLAnalyticsHandler
|
||||||
$path,
|
$path,
|
||||||
$agent,
|
$agent,
|
||||||
$referrer,
|
$referrer,
|
||||||
$time, $status = 200) {
|
$time) {
|
||||||
|
|
||||||
if(strlen($path) == 0) {
|
if(strlen($path) == 0) {
|
||||||
$path = '/';
|
$path = '/';
|
||||||
|
@ -83,7 +83,6 @@ class MySQLAnalyticsHandler
|
||||||
'path' => $path,
|
'path' => $path,
|
||||||
'agent' => $agent,
|
'agent' => $agent,
|
||||||
'referrer' => $referrer,
|
'referrer' => $referrer,
|
||||||
'status' => $status
|
|
||||||
], 'access_sum');
|
], 'access_sum');
|
||||||
|
|
||||||
$this->increment_counter([
|
$this->increment_counter([
|
||||||
|
|
|
@ -107,8 +107,6 @@ if($REQUEST_PATH == '/search/') {
|
||||||
$post = $adapter->get_post($REQUEST_PATH);
|
$post = $adapter->get_post($REQUEST_PATH);
|
||||||
|
|
||||||
if(!isset($post)) {
|
if(!isset($post)) {
|
||||||
$analytics_return_status = 404;
|
|
||||||
|
|
||||||
$error_page = $SITE_CONFIG['site_defaults'];
|
$error_page = $SITE_CONFIG['site_defaults'];
|
||||||
$error_page['path'] = '/404';
|
$error_page['path'] = '/404';
|
||||||
$error_page['title'] = '404 oh no';
|
$error_page['title'] = '404 oh no';
|
||||||
|
|
|
@ -5,25 +5,6 @@ $data_time_start = microtime(true);
|
||||||
$analytics_enable_tail = false;
|
$analytics_enable_tail = false;
|
||||||
$analytics_post = null;
|
$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() {
|
function deduce_user_agent() {
|
||||||
$real_agent=$_SERVER['HTTP_USER_AGENT'];
|
$real_agent=$_SERVER['HTTP_USER_AGENT'];
|
||||||
|
|
||||||
|
@ -38,27 +19,6 @@ 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() {
|
function analytics_is_user() {
|
||||||
return preg_match('/^user/', deduce_user_agent());
|
return preg_match('/^user/', deduce_user_agent());
|
||||||
}
|
}
|
||||||
|
@ -74,8 +34,6 @@ register_shutdown_function(function() {
|
||||||
|
|
||||||
global $analytics_enable_tail;
|
global $analytics_enable_tail;
|
||||||
|
|
||||||
global $analytics_return_status;
|
|
||||||
|
|
||||||
$data_time_end = microtime(true);
|
$data_time_end = microtime(true);
|
||||||
|
|
||||||
$http_referer = 'magic';
|
$http_referer = 'magic';
|
||||||
|
@ -87,14 +45,10 @@ register_shutdown_function(function() {
|
||||||
|
|
||||||
$compute_time = $data_time_end - $data_time_start;
|
$compute_time = $data_time_end - $data_time_start;
|
||||||
|
|
||||||
if(analytics_is_bogus_request()) {
|
|
||||||
$analytics_return_status = 'bogus';
|
|
||||||
}
|
|
||||||
|
|
||||||
$analytics_adapter->log_path_access($REQUEST_PATH,
|
$analytics_adapter->log_path_access($REQUEST_PATH,
|
||||||
deduce_user_agent(),
|
deduce_user_agent(),
|
||||||
$referrer,
|
$referrer,
|
||||||
$compute_time, $analytics_return_status);
|
$compute_time);
|
||||||
|
|
||||||
if($analytics_enable_tail) {
|
if($analytics_enable_tail) {
|
||||||
echo "<!-- Total page time was: " . $compute_time . " -->";
|
echo "<!-- Total page time was: " . $compute_time . " -->";
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue