Visitor count fix

This commit is contained in:
Roman committed 2020-07-18 12:51:36 +02:00
1 parent 5254f3488b
commit 852d94e736
6 files changed
+32 -4

No files matched your search

+24
View File
@@ -2,6 +2,8 @@
namespace Api; namespace Api;
use DateTime;
use Driver\SQL\Condition\Compare;
use Driver\SQL\Condition\CondBool; use Driver\SQL\Condition\CondBool;
class Stats extends Request { class Stats extends Request {
@@ -47,6 +49,22 @@ class Stats extends Request {
return $this->success; return $this->success;
} }
private function getVisitorCount() {
$sql = $this->user->getSQL();
$date = new DateTime();
$monthStart = $date->format("Ym00");
$monthEnd = $date->modify("+1 month")->format("Ym00");
$res = $sql->select($sql->count($sql->distinct("cookie")))
->from("Visitor")
->where(new Compare("day", $monthStart, ">="))
->where(new Compare("day", $monthEnd, "<"))
->execute();
$this->success = ($res !== false);
$this->lastError = $sql->getLastError();
return ($this->success ? $res[0]["count"] : $this->success);
}
public function execute($values = array()) { public function execute($values = array()) {
if(!parent::execute($values)) { if(!parent::execute($values)) {
return false; return false;
@@ -62,6 +80,11 @@ class Stats extends Request {
} }
$visitorStatistics = $req->getResult()["visitors"]; $visitorStatistics = $req->getResult()["visitors"];
$visitorCount = $this->getVisitorCount();
if (!$this->success) {
return false;
}
$loadAvg = "Unknown"; $loadAvg = "Unknown";
if (function_exists("sys_getloadavg")) { if (function_exists("sys_getloadavg")) {
$loadAvg = sys_getloadavg(); $loadAvg = sys_getloadavg();
@@ -74,6 +97,7 @@ class Stats extends Request {
$this->result["userCount"] = $userCount; $this->result["userCount"] = $userCount;
$this->result["pageCount"] = $pageCount; $this->result["pageCount"] = $pageCount;
$this->result["visitors"] = $visitorStatistics; $this->result["visitors"] = $visitorStatistics;
$this->result["visitorsTotal"] = $visitorCount;
$this->result["server"] = array( $this->result["server"] = array(
"version" => WEBBASE_VERSION, "version" => WEBBASE_VERSION,
"server" => $_SERVER["SERVER_SOFTWARE"] ?? "Unknown", "server" => $_SERVER["SERVER_SOFTWARE"] ?? "Unknown",
+2
View File
@@ -303,6 +303,8 @@ abstract class SQL {
public function count($col = NULL) { public function count($col = NULL) {
if (is_null($col)) { if (is_null($col)) {
return new Keyword("COUNT(*) AS count"); return new Keyword("COUNT(*) AS count");
} else if($col instanceof Keyword) {
return new Keyword("COUNT(" . $col->getValue() . ") AS count");
} else { } else {
$countCol = strtolower(str_replace(".","_", $col)) . "_count"; $countCol = strtolower(str_replace(".","_", $col)) . "_count";
$col = $this->columnName($col); $col = $this->columnName($col);
+1 -1
View File
@@ -1,6 +1,6 @@
<?php <?php
define("WEBBASE_VERSION", "1.0.2"); define("WEBBASE_VERSION", "1.0.3");
function getProtocol() { function getProtocol() {
return (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) ? "https" : "http"; return (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) ? "https" : "http";
+1 -1
View File
@@ -351,4 +351,4 @@ e.defineLocale("zh-tw",{months:"一月_二月_三月_四月_五月_六月_七月
* *
* Copyright © 2012-2019 Faisal Salman <f@faisalman.com> * Copyright © 2012-2019 Faisal Salman <f@faisalman.com>
* Licensed under MIT License * Licensed under MIT License
*/!function(o,a){"use strict";var i="model",s="name",c="type",l="vendor",d="version",u="mobile",p="tablet",f="smarttv",m={extend:function(e,t){var r={};for(var n in e)t[n]&&t[n].length%2==0?r[n]=t[n].concat(e[n]):r[n]=e[n];return r},has:function(e,t){return"string"==typeof e&&-1!==t.toLowerCase().indexOf(e.toLowerCase())},lowerize:function(e){return e.toLowerCase()},major:function(e){return"string"==typeof e?e.replace(/[^\d\.]/g,"").split(".")[0]:void 0},trim:function(e){return e.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,"")}},h={rgx:function(e,t){for(var r,n,o,a,i,s,c=0;c<t.length&&!i;){var l=t[c],d=t[c+1];for(r=n=0;r<l.length&&!i;)if(i=l[r++].exec(e))for(o=0;o<d.length;o++)s=i[++n],"object"==typeof(a=d[o])&&a.length>0?2==a.length?"function"==typeof a[1]?this[a[0]]=a[1].call(this,s):this[a[0]]=a[1]:3==a.length?"function"!=typeof a[1]||a[1].exec&&a[1].test?this[a[0]]=s?s.replace(a[1],a[2]):void 0:this[a[0]]=s?a[1].call(this,s,a[2]):void 0:4==a.length&&(this[a[0]]=s?a[3].call(this,s.replace(a[1],a[2])):void 0):this[a]=s||void 0;c+=2}},str:function(e,t){for(var r in t)if("object"==typeof t[r]&&t[r].length>0){for(var n=0;n<t[r].length;n++)if(m.has(t[r][n],e))return"?"===r?void 0:r}else if(m.has(t[r],e))return"?"===r?void 0:r;return e}},g={browser:{oldsafari:{version:{"1.0":"/8",1.2:"/1",1.3:"/3","2.0":"/412","2.0.2":"/416","2.0.3":"/417","2.0.4":"/419","?":"/"}}},device:{amazon:{model:{"Fire Phone":["SD","KF"]}},sprint:{model:{"Evo Shift 4G":"7373KT"},vendor:{HTC:"APA",Sprint:"Sprint"}}},os:{windows:{version:{ME:"4.90","NT 3.11":"NT3.51","NT 4.0":"NT4.0",2e3:"NT 5.0",XP:["NT 5.1","NT 5.2"],Vista:"NT 6.0",7:"NT 6.1",8:"NT 6.2",8.1:"NT 6.3",10:["NT 6.4","NT 10.0"],RT:"ARM"}}}},b={browser:[[/(opera\smini)\/([\w\.-]+)/i,/(opera\s[mobiletab]+).+version\/([\w\.-]+)/i,/(opera).+version\/([\w\.]+)/i,/(opera)[\/\s]+([\w\.]+)/i],[s,d],[/(opios)[\/\s]+([\w\.]+)/i],[[s,"Opera Mini"],d],[/\s(opr)\/([\w\.]+)/i],[[s,"Opera"],d],[/(kindle)\/([\w\.]+)/i,/(lunascape|maxthon|netfront|jasmine|blazer)[\/\s]?([\w\.]*)/i,/(avant\s|iemobile|slim)(?:browser)?[\/\s]?([\w\.]*)/i,/(bidubrowser|baidubrowser)[\/\s]?([\w\.]+)/i,/(?:ms|\()(ie)\s([\w\.]+)/i,/(rekonq)\/([\w\.]*)/i,/(chromium|flock|rockmelt|midori|epiphany|silk|skyfire|ovibrowser|bolt|iron|vivaldi|iridium|phantomjs|bowser|quark|qupzilla|falkon)\/([\w\.-]+)/i],[s,d],[/(konqueror)\/([\w\.]+)/i],[[s,"Konqueror"],d],[/(trident).+rv[:\s]([\w\.]+).+like\sgecko/i],[[s,"IE"],d],[/(edge|edgios|edga|edg)\/((\d+)?[\w\.]+)/i],[[s,"Edge"],d],[/(yabrowser)\/([\w\.]+)/i],[[s,"Yandex"],d],[/(Avast)\/([\w\.]+)/i],[[s,"Avast Secure Browser"],d],[/(AVG)\/([\w\.]+)/i],[[s,"AVG Secure Browser"],d],[/(puffin)\/([\w\.]+)/i],[[s,"Puffin"],d],[/(focus)\/([\w\.]+)/i],[[s,"Firefox Focus"],d],[/(opt)\/([\w\.]+)/i],[[s,"Opera Touch"],d],[/((?:[\s\/])uc?\s?browser|(?:juc.+)ucweb)[\/\s]?([\w\.]+)/i],[[s,"UCBrowser"],d],[/(comodo_dragon)\/([\w\.]+)/i],[[s,/_/g," "],d],[/(windowswechat qbcore)\/([\w\.]+)/i],[[s,"WeChat(Win) Desktop"],d],[/(micromessenger)\/([\w\.]+)/i],[[s,"WeChat"],d],[/(brave)\/([\w\.]+)/i],[[s,"Brave"],d],[/(qqbrowserlite)\/([\w\.]+)/i],[s,d],[/(QQ)\/([\d\.]+)/i],[s,d],[/m?(qqbrowser)[\/\s]?([\w\.]+)/i],[s,d],[/(baiduboxapp)[\/\s]?([\w\.]+)/i],[s,d],[/(2345Explorer)[\/\s]?([\w\.]+)/i],[s,d],[/(MetaSr)[\/\s]?([\w\.]+)/i],[s],[/(LBBROWSER)/i],[s],[/xiaomi\/miuibrowser\/([\w\.]+)/i],[d,[s,"MIUI Browser"]],[/;fbav\/([\w\.]+);/i],[d,[s,"Facebook"]],[/safari\s(line)\/([\w\.]+)/i,/android.+(line)\/([\w\.]+)\/iab/i],[s,d],[/headlesschrome(?:\/([\w\.]+)|\s)/i],[d,[s,"Chrome Headless"]],[/\swv\).+(chrome)\/([\w\.]+)/i],[[s,/(.+)/,"$1 WebView"],d],[/((?:oculus|samsung)browser)\/([\w\.]+)/i],[[s,/(.+(?:g|us))(.+)/,"$1 $2"],d],[/android.+version\/([\w\.]+)\s+(?:mobile\s?safari|safari)*/i],[d,[s,"Android Browser"]],[/(sailfishbrowser)\/([\w\.]+)/i],[[s,"Sailfish Browser"],d],[/(chrome|omniweb|arora|[tizenoka]{5}\s?browser)\/v?([\w\.]+)/i],[s,d],[/(dolfin)\/([\w\.]+)/i],[[s,"Dolphin"],d],[/(qihu|qhbrowser|qihoobrowser|360browser)/i],[[s,"360 Browser"]],[/((?:android.+)crmo|crios)\/([\w\.]+)/i],[[s,"Chrome"],d],[/(coast)\/([\w\.]+)/i],[[s,"Opera Coast"],d],[/fxios\/([\w\.-]+)/i],[d,[s,"Firefox"]],[/version\/([\w\.]+).+?mobile\/\w+\s(safari)/i],[d,[s,"Mobile Safari"]],[/version\/([\w\.]+).+?(mobile\s?safari|safari)/i],[d,s],[/webkit.+?(gsa)\/([\w\.]+).+?(mobile\s?safari|safari)(\/[\w\.]+)/i],[[s,"GSA"],d],[/webkit.+?(mobile\s?safari|safari)(\/[\w\.]+)/i],[s,[d,h.str,g.browser.oldsafari.version]],[/(webkit|khtml)\/([\w\.]+)/i],[s,d],[/(navigator|netscape)\/([\w\.-]+)/i],[[s,"Netscape"],d],[/(swiftfox)/i,/(icedragon|iceweasel|camino|chimera|fennec|maemo\sbrowser|minimo|conkeror)[\/\s]?([\w\.\+]+)/i,/(firefox|seamonkey|k-meleon|icecat|iceape|firebird|phoenix|palemoon|basilisk|waterfox)\/([\w\.-]+)$/i,/(mozilla)\/([\w\.]+).+rv\:.+gecko\/\d+/i,/(polaris|lynx|dillo|icab|doris|amaya|w3m|netsurf|sleipnir)[\/\s]?([\w\.]+)/i,/(links)\s\(([\w\.]+)/i,/(gobrowser)\/?([\w\.]*)/i,/(ice\s?browser)\/v?([\w\._]+)/i,/(moLine truncated */!function(o,a){"use strict";var i="model",s="name",c="type",l="vendor",d="version",u="mobile",p="tablet",f="smarttv",m={extend:function(e,t){var r={};for(var n in e)t[n]&&t[n].length%2==0?r[n]=t[n].concat(e[n]):r[n]=e[n];return r},has:function(e,t){return"string"==typeof e&&-1!==t.toLowerCase().indexOf(e.toLowerCase())},lowerize:function(e){return e.toLowerCase()},major:function(e){return"string"==typeof e?e.replace(/[^\d\.]/g,"").split(".")[0]:void 0},trim:function(e){return e.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,"")}},h={rgx:function(e,t){for(var r,n,o,a,i,s,c=0;c<t.length&&!i;){var l=t[c],d=t[c+1];for(r=n=0;r<l.length&&!i;)if(i=l[r++].exec(e))for(o=0;o<d.length;o++)s=i[++n],"object"==typeof(a=d[o])&&a.length>0?2==a.length?"function"==typeof a[1]?this[a[0]]=a[1].call(this,s):this[a[0]]=a[1]:3==a.length?"function"!=typeof a[1]||a[1].exec&&a[1].test?this[a[0]]=s?s.replace(a[1],a[2]):void 0:this[a[0]]=s?a[1].call(this,s,a[2]):void 0:4==a.length&&(this[a[0]]=s?a[3].call(this,s.replace(a[1],a[2])):void 0):this[a]=s||void 0;c+=2}},str:function(e,t){for(var r in t)if("object"==typeof t[r]&&t[r].length>0){for(var n=0;n<t[r].length;n++)if(m.has(t[r][n],e))return"?"===r?void 0:r}else if(m.has(t[r],e))return"?"===r?void 0:r;return e}},g={browser:{oldsafari:{version:{"1.0":"/8",1.2:"/1",1.3:"/3","2.0":"/412","2.0.2":"/416","2.0.3":"/417","2.0.4":"/419","?":"/"}}},device:{amazon:{model:{"Fire Phone":["SD","KF"]}},sprint:{model:{"Evo Shift 4G":"7373KT"},vendor:{HTC:"APA",Sprint:"Sprint"}}},os:{windows:{version:{ME:"4.90","NT 3.11":"NT3.51","NT 4.0":"NT4.0",2e3:"NT 5.0",XP:["NT 5.1","NT 5.2"],Vista:"NT 6.0",7:"NT 6.1",8:"NT 6.2",8.1:"NT 6.3",10:["NT 6.4","NT 10.0"],RT:"ARM"}}}},b={browser:[[/(opera\smini)\/([\w\.-]+)/i,/(opera\s[mobiletab]+).+version\/([\w\.-]+)/i,/(opera).+version\/([\w\.]+)/i,/(opera)[\/\s]+([\w\.]+)/i],[s,d],[/(opios)[\/\s]+([\w\.]+)/i],[[s,"Opera Mini"],d],[/\s(opr)\/([\w\.]+)/i],[[s,"Opera"],d],[/(kindle)\/([\w\.]+)/i,/(lunascape|maxthon|netfront|jasmine|blazer)[\/\s]?([\w\.]*)/i,/(avant\s|iemobile|slim)(?:browser)?[\/\s]?([\w\.]*)/i,/(bidubrowser|baidubrowser)[\/\s]?([\w\.]+)/i,/(?:ms|\()(ie)\s([\w\.]+)/i,/(rekonq)\/([\w\.]*)/i,/(chromium|flock|rockmelt|midori|epiphany|silk|skyfire|ovibrowser|bolt|iron|vivaldi|iridium|phantomjs|bowser|quark|qupzilla|falkon)\/([\w\.-]+)/i],[s,d],[/(konqueror)\/([\w\.]+)/i],[[s,"Konqueror"],d],[/(trident).+rv[:\s]([\w\.]+).+like\sgecko/i],[[s,"IE"],d],[/(edge|edgios|edga|edg)\/((\d+)?[\w\.]+)/i],[[s,"Edge"],d],[/(yabrowser)\/([\w\.]+)/i],[[s,"Yandex"],d],[/(Avast)\/([\w\.]+)/i],[[s,"Avast Secure Browser"],d],[/(AVG)\/([\w\.]+)/i],[[s,"AVG Secure Browser"],d],[/(puffin)\/([\w\.]+)/i],[[s,"Puffin"],d],[/(focus)\/([\w\.]+)/i],[[s,"Firefox Focus"],d],[/(opt)\/([\w\.]+)/i],[[s,"Opera Touch"],d],[/((?:[\s\/])uc?\s?browser|(?:juc.+)ucweb)[\/\s]?([\w\.]+)/i],[[s,"UCBrowser"],d],[/(comodo_dragon)\/([\w\.]+)/i],[[s,/_/g," "],d],[/(windowswechat qbcore)\/([\w\.]+)/i],[[s,"WeChat(Win) Desktop"],d],[/(micromessenger)\/([\w\.]+)/i],[[s,"WeChat"],d],[/(brave)\/([\w\.]+)/i],[[s,"Brave"],d],[/(qqbrowserlite)\/([\w\.]+)/i],[s,d],[/(QQ)\/([\d\.]+)/i],[s,d],[/m?(qqbrowser)[\/\s]?([\w\.]+)/i],[s,d],[/(baiduboxapp)[\/\s]?([\w\.]+)/i],[s,d],[/(2345Explorer)[\/\s]?([\w\.]+)/i],[s,d],[/(MetaSr)[\/\s]?([\w\.]+)/i],[s],[/(LBBROWSER)/i],[s],[/xiaomi\/miuibrowser\/([\w\.]+)/i],[d,[s,"MIUI Browser"]],[/;fbav\/([\w\.]+);/i],[d,[s,"Facebook"]],[/safari\s(line)\/([\w\.]+)/i,/android.+(line)\/([\w\.]+)\/iab/i],[s,d],[/headlesschrome(?:\/([\w\.]+)|\s)/i],[d,[s,"Chrome Headless"]],[/\swv\).+(chrome)\/([\w\.]+)/i],[[s,/(.+)/,"$1 WebView"],d],[/((?:oculus|samsung)browser)\/([\w\.]+)/i],[[s,/(.+(?:g|us))(.+)/,"$1 $2"],d],[/android.+version\/([\w\.]+)\s+(?:mobile\s?safari|safari)*/i],[d,[s,"Android Browser"]],[/(sailfishbrowser)\/([\w\.]+)/i],[[s,"Sailfish Browser"],d],[/(chrome|omniweb|arora|[tizenoka]{5}\s?browser)\/v?([\w\.]+)/i],[s,d],[/(dolfin)\/([\w\.]+)/i],[[s,"Dolphin"],d],[/(qihu|qhbrowser|qihoobrowser|360browser)/i],[[s,"360 Browser"]],[/((?:android.+)crmo|crios)\/([\w\.]+)/i],[[s,"Chrome"],d],[/(coast)\/([\w\.]+)/i],[[s,"Opera Coast"],d],[/fxios\/([\w\.-]+)/i],[d,[s,"Firefox"]],[/version\/([\w\.]+).+?mobile\/\w+\s(safari)/i],[d,[s,"Mobile Safari"]],[/version\/([\w\.]+).+?(mobile\s?safari|safari)/i],[d,s],[/webkit.+?(gsa)\/([\w\.]+).+?(mobile\s?safari|safari)(\/[\w\.]+)/i],[[s,"GSA"],d],[/webkit.+?(mobile\s?safari|safari)(\/[\w\.]+)/i],[s,[d,h.str,g.browser.oldsafari.version]],[/(webkit|khtml)\/([\w\.]+)/i],[s,d],[/(navigator|netscape)\/([\w\.-]+)/i],[[s,"Netscape"],d],[/(swiftfox)/i,/(icedragon|iceweasel|camino|chimera|fennec|maemo\sbrowser|minimo|conkeror)[\/\s]?([\w\.\+]+)/i,/(firefox|seamonkey|k-meleon|icecat|iceape|firebird|phoenix|palemoon|basilisk|waterfox)\/([\w\.-]+)$/i,/(mozilla)\/([\w\.]+).+rv\:.+gecko\/\d+/i,/(polaris|lynx|dillo|icab|doris|amaya|w3m|netsurf|sleipnir)[\/\s]?([\w\.]+)/i,/(links)\s\(([\w\.]+)/i,/(gobrowser)\/?([\w\.]*)/i,/(ice\s?browser)\/v?([\w\._]+)/i,/(moLine truncated
+1 -1
View File
@@ -5,7 +5,7 @@ export default function Footer() {
return ( return (
<footer className={"main-footer"}> <footer className={"main-footer"}>
Theme: <strong>Copyright © 2014-2019 <a href={"http://adminlte.io"}>AdminLTE.io</a>. <b>Version</b> 3.0.3</strong>&nbsp; Theme: <strong>Copyright © 2014-2019 <a href={"http://adminlte.io"}>AdminLTE.io</a>. <b>Version</b> 3.0.3</strong>&nbsp;
CMS: <strong><a href={"https://git.romanh.de/Projekte/web-base"}>WebBase</a></strong>. <b>Version</b> 1.0.2 CMS: <strong><a href={"https://git.romanh.de/Projekte/web-base"}>WebBase</a></strong>. <b>Version</b> 1.0.3
</footer> </footer>
) )
} }
+3 -1
View File
@@ -22,6 +22,7 @@ export default class Overview extends React.Component {
statusVisible : true, statusVisible : true,
userCount: 0, userCount: 0,
notificationCount: 0, notificationCount: 0,
visitorsTotal: 0,
visitors: { }, visitors: { },
server: { load_avg: ["Unknown"] }, server: { load_avg: ["Unknown"] },
errors: [] errors: []
@@ -48,6 +49,7 @@ export default class Overview extends React.Component {
userCount: res.userCount, userCount: res.userCount,
pageCount: res.pageCount, pageCount: res.pageCount,
visitors: res.visitors, visitors: res.visitors,
visitorsTotal: res.visitorsTotal,
server: res.server server: res.server
}); });
} }
@@ -157,7 +159,7 @@ export default class Overview extends React.Component {
<div className={"col-lg-3 col-6"}> <div className={"col-lg-3 col-6"}>
<div className={"small-box bg-danger"}> <div className={"small-box bg-danger"}>
<div className={"inner"}> <div className={"inner"}>
<h3>{visitorCount}</h3> <h3>{this.state.visitorsTotal}</h3>
<p>Unique Visitors</p> <p>Unique Visitors</p>
</div> </div>
<div className="icon"> <div className="icon">