Skip to content
This repository has been archived by the owner on Apr 9, 2023. It is now read-only.

Commit

Permalink
Bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
beranek1 committed Jul 1, 2019
1 parent b51cc75 commit 708390d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 30 deletions.
2 changes: 1 addition & 1 deletion analyser.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ function analyse_countries($mysql, $table, $field, $start = null, $end = null, $
}
function analyse_time($mysql, $time = null) {
$timespan = null;
$times = array("24h" => array("start" => "-24 HOUR", "end" => null), "7days" => array("start" => "-7 DAY", "end" => null), "30days" => "30days" => array("start" => "-30 DAY", "end" => null), "365days" => array("start" => "365 DAY", "end" => null));
$times = array("24h" => array("start" => "-24 HOUR", "end" => null), "7days" => array("start" => "-7 DAY", "end" => null), "30days" => array("start" => "-30 DAY", "end" => null), "365days" => array("start" => "365 DAY", "end" => null));
$start = null;
$end = null;
if($time != null) {
Expand Down
54 changes: 25 additions & 29 deletions analytics.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
class b1_analytics {
public $a = array();
public $s = null;
public $h = null;
public $d = null;
public $bot_name = null;
public $agent_id = null;
Expand Down Expand Up @@ -298,8 +299,6 @@ function getmobile() {

// Gets user language and country from hostname and http header
function getlocation() {
$this->u_ip = $this->s['REMOTE_ADDR'];
$this->u_host = gethostbyaddr($this->u_ip);
if(filter_var($this->u_host, FILTER_VALIDATE_IP) == false) {
$domainparts = explode(".", $this->u_host);
$domainend = $domainparts[count($domainparts) - 1];
Expand All @@ -311,9 +310,7 @@ function getlocation() {
$this->u_country_code = $this->s["HTTP_CF_IPCOUNTRY"];
}
}
if(isset($this->s["HTTP_ACCEPT_LANGUAGE"])) {
$this->u_language = substr($this->s['HTTP_ACCEPT_LANGUAGE'], 0, 2);
}
$this->u_language = isset($this->s["HTTP_ACCEPT_LANGUAGE"]) ? substr($this->s['HTTP_ACCEPT_LANGUAGE'], 0, 2) : false;
}

// Anonymizes the ip adress
Expand All @@ -330,7 +327,7 @@ function anonymize_ip() {
function getisp($mysql) {
$mysql->query("CREATE TABLE IF NOT EXISTS `isps` (id VARCHAR(10) PRIMARY KEY, domain VARCHAR(127) NOT NULL, name TEXT, country VARCHAR(2), last TIMESTAMP NULL, created TIMESTAMP DEFAULT CURRENT_TIMESTAMP);");
$ispdomain = null;
if(filter_var($this->u_host, FILTER_VALIDATE_IP) == false) {
if(isset($this->u_host) && filter_var($this->u_host, FILTER_VALIDATE_IP) == false) {
$domainparts = explode(".", $this->u_host);
$ispdomain = $domainparts[count($domainparts) - 2] . "." . $domainparts[count($domainparts) - 1];
}
Expand Down Expand Up @@ -532,13 +529,9 @@ function getubid($mysql) {
// Gets information about the request and adds it to the database
function getrequest($mysql) {
$mysql->query("CREATE TABLE IF NOT EXISTS `requests` (id VARCHAR(15) PRIMARY KEY, accept TEXT, protocol TEXT, port INT(6), host VARCHAR(253), uri TEXT, referrer TEXT, visitor_ip VARCHAR(45) NOT NULL, visitor_country VARCHAR(2), cf_ray_id TEXT, browser_id VARCHAR(15), network_id VARCHAR(15), created TIMESTAMP DEFAULT CURRENT_TIMESTAMP);");
if(isset($this->s['REQUEST_SCHEME'])) {
$this->r_protocol = $this->s["REQUEST_SCHEME"];
}
$this->r_port = $this->s['SERVER_PORT'];
if(isset($this->s["HTTP_CF_RAY"])) {
$this->r_rayid = $this->s["HTTP_CF_RAY"];
}
$this->r_protocol = isset($this->s['REQUEST_SCHEME']) ? $this->s["REQUEST_SCHEME"] : null;
$this->r_port = isset($this->s["SERVER_PORT"]) ? $this->s['SERVER_PORT'] : null;
$this->r_rayid = isset($this->s["HTTP_CF_RAY"]) ? $this->s["HTTP_CF_RAY"] : null;
if(isset($this->s["REQUEST_URI"])) {
$uri = $this->s["REQUEST_URI"];
if($uri != null && $uri != "" && $uri != "/") {
Expand All @@ -551,11 +544,9 @@ function getrequest($mysql) {
$this->r_origin = $origin;
}
}
if(isset($this->d['HTTP_ACCEPT'])) {
$this->r_accept = "".explode(",", $this->s['HTTP_ACCEPT'])[0]."";
}
$this->r_accept = isset($this->d['HTTP_ACCEPT']) ? "".explode(",", $this->s['HTTP_ACCEPT'])[0]."" : null;
$this->rid = $this->generateid(15);
$this->r_domain = strtolower($this->s["HTTP_HOST"]);
$this->r_domain = strtolower($this->h);
$this->exgenquery($mysql, "requests", array("accept" => $this->r_accept, "protocol" => $this->r_protocol, "port" => $this->r_port, "host" => $this->r_domain, "uri" => $this->r_target, "referrer" => $this->r_origin, "visitor_ip" => $this->u_ip, "visitor_country" => $this->u_country_code, "cf_ray_id" => $this->r_rayid, "browser_id" => $this->ubid, "network_id" => $this->unid), $this->rid);
}

Expand All @@ -565,20 +556,25 @@ function getrequest($mysql) {
function __construct($mysql, $server, $clientcookies, $anonymousips = TRUE) {
if(!$mysql->connect_errno) {
$this->s = $server;
if(isset($server['HTTP_USER_AGENT'])) {
$this->ua = strtolower($server['HTTP_USER_AGENT']);
}
$this->ua = isset($this->s['HTTP_USER_AGENT']) ? strtolower($this->s['HTTP_USER_AGENT']) : null;
$this->c = $clientcookies;
$domain = strtolower($server["HTTP_HOST"]);
if(filter_var($domain, FILTER_VALIDATE_IP) == false) {
$domainparts = explode(".", $domain);
$this->d = $domainparts[count($domainparts) - 2] . "." . $domainparts[count($domainparts) - 1];
} else { $this->d = $domain; }
$this->getmobile();
$this->getlocation($reader);
if($anonymousips) {
$this->u_ip = isset($this->s['REMOTE_ADDR']) ? $this->s['REMOTE_ADDR'] : null;
if (filter_var($this->u_ip, FILTER_VALIDATE_IP)) {
$this->u_host = gethostbyaddr($this->u_ip);
}
if($anonymousips && isset($this->s['REMOTE_ADDR'])) {
$this->anonymize_ip();
}
if(isset($this->s["HTTP_HOST"])) {
$this->h = $this->s["HTTP_HOST"];
$domain = strtolower($this->h);
if(filter_var($domain, FILTER_VALIDATE_IP) == false) {
$domainparts = explode(".", $domain);
$this->d = $domainparts[count($domainparts) - 2] . "." . $domainparts[count($domainparts) - 1];
} else { $this->d = $domain; }
}
$this->getmobile();
$this->getlocation();
$this->getisp($mysql);
$this->getunid($mysql);
$this->getbot();
Expand All @@ -587,7 +583,7 @@ function __construct($mysql, $server, $clientcookies, $anonymousips = TRUE) {
$this->getubid($mysql);
$this->getrequest($mysql);
} else {
error_log("beranek1 analytics unable to connect to database\n");
error_log("b1 web analytics unable to connect to database\n");
}
}

Expand Down

0 comments on commit 708390d

Please sign in to comment.