From 4faaa29568c4f481640a436726f952d0c4f58529 Mon Sep 17 00:00:00 2001 From: akshat0047 Date: Wed, 3 Jun 2020 18:26:59 +0530 Subject: fixed calculation bugs, edited JSON --- awdash/public/add.php | 19 +++++++++ awdash/public/index.js | 28 +++++++------ awdash/public/index.php | 2 +- awdash/public/sites.json | 7 +++- awdash/src/Controller/WebsiteController.php | 4 +- server/awstats.php | 61 +++++++++++++++++++++++------ server/class.awfile.php | 3 +- 7 files changed, 93 insertions(+), 31 deletions(-) create mode 100644 awdash/public/add.php diff --git a/awdash/public/add.php b/awdash/public/add.php new file mode 100644 index 0000000..f782fc9 --- /dev/null +++ b/awdash/public/add.php @@ -0,0 +1,19 @@ +//Script to add parameters to JSON + +sites as $i){ + +//Adding parameter +$i -> filename = $i -> domain; +} + +//Encoding +$js = json_encode($js, JSON_PRETTY_PRINT); + +//Writing to file +file_put_contents("sites.json", $js); +?> diff --git a/awdash/public/index.js b/awdash/public/index.js index 134b98b..0057d12 100644 --- a/awdash/public/index.js +++ b/awdash/public/index.js @@ -15,13 +15,21 @@ if(mm<10) mm='0'+mm; } -function getAll(time = "01012013" + dd + mm + yyyy, website = "") +$.getJSON("sites.json", function(json) { + defaultdate = json['defaultdate']; + $.each(json['sites'], (index, value) => { + val = parseInt(index, 10) + 1; + $("#myselect").append(""); + }); + + +function getAll(time = defaultdate + dd + mm + yyyy, website = "") { -//console.log("time= " + time + "website = " + website); +console.log("time= " + time + "website = " + website); $("#table-body").css("visibility","hidden"); $("#loading").css("display","block"); - -var url = "https://Domain/websites/" + time + "/" + website; +console.log(time); +var url = "https://awdash.fossee.in/websites/" + time + "/" + website; $.get(url, function(data, status){ var rows = ""; // console.log(data); @@ -34,7 +42,7 @@ $.get(url, function(data, status){ "" + data[i].total_visit + "" + "" + data[i].total_page_loads + "" + "" + data[i].total_hits + "" + - "" + data[i].total_bandwidth + "" + + "" + data[i].total_bandwidth + " MB" + "Click Here" + ""; } @@ -50,11 +58,11 @@ $("#filter").click(e => { e.preventDefault(); let website = $("#myselect").val(); let time = ($("input")[0].value).split("-")[2] + ($("input")[0].value).split("-")[1] + ($("input")[0].value).split("-")[0] + - ($("input")[1].value).split("-")[1] + ($("input")[1].value).split("-")[1] + ($("input")[1].value).split("-")[0]; + ($("input")[1].value).split("-")[2] + ($("input")[1].value).split("-")[1] + ($("input")[1].value).split("-")[0]; if(time.includes("undefined")) time = null; - +// console.log(time); if(time && website) getAll(time, website); else if(time) @@ -68,12 +76,6 @@ $("#reset").click(e => { getAll(); }); -$.getJSON("sites.json", function(json) { - defaultdate = json['defaultdate']; - $.each(json['sites'], (index, value) => { - val = parseInt(index, 10) + 1; - $("#myselect").append(""); - }); getAll(); }); }); diff --git a/awdash/public/index.php b/awdash/public/index.php index 937336e..af2a4d3 100644 --- a/awdash/public/index.php +++ b/awdash/public/index.php @@ -14,7 +14,7 @@ $uri = explode( '/', $uri ); if ($uri[1] !== 'websites') { $file = 'index.html'; if (file_exists($file)) { - header('Location: Domain'); + header('Location: https://awdash.fossee.in/index.html'); } else { // throw new \Slim\Exception\NotFoundException($request, $response); exit(); diff --git a/awdash/public/sites.json b/awdash/public/sites.json index 987c8a5..bd4df74 100644 --- a/awdash/public/sites.json +++ b/awdash/public/sites.json @@ -1,11 +1,14 @@ { "defaultdate":"default start date of logs", + "defaultpath":"default path of awstats log files", "sites":[{ "domain":"domain to show in the list as name", - "awstats":"link of individual awstats url for the domain" + "awstats":"link of individual awstats url for the domain", + "filename":"domain used as filename" }, { "domain":"", - "awstats":"" + "awstats":"", + "filename":"" }] } diff --git a/awdash/src/Controller/WebsiteController.php b/awdash/src/Controller/WebsiteController.php index 612391f..9bef690 100755 --- a/awdash/src/Controller/WebsiteController.php +++ b/awdash/src/Controller/WebsiteController.php @@ -99,7 +99,9 @@ class WebsiteController { foreach ($website as $web) { - $url = 'https://'.$web['domain'].'/data/awstats/awstats.php?sd='.$sd.'&ed='.$ed.'&sm='.$sm.'&em='.$em.'&sy='.$sy.'&ey='.$ey.'&web='.$web['domain']; + $url = 'https://'.$web['domain'].'/data/awstats/awstats.php?sd='.$sd.'&ed='.$ed.'&sm='.$sm.'&em='.$em.'&sy='.$sy.'&ey='.$ey.'&path='.$this->sites['defaultpath'].'&web='.$web['filename']; +// $url = "https://awdash.fossee.in?sd=".$sd.'&ed='.$ed.'&sm='.$sm.'&em='.$em.'&sy='.$sy.'&ey='.$ey.'&web='.$web['domain']; +// echo $url; $contents = json_decode(file_get_contents($url)); $contents -> sno = $this -> sno; $this -> sno += 1; diff --git a/server/awstats.php b/server/awstats.php index 24adcb8..0b9145b 100644 --- a/server/awstats.php +++ b/server/awstats.php @@ -24,10 +24,10 @@ $endm = $_GET['em']; $starty = $_GET['sy']; $endy = $_GET['ey']; $website = $_GET['web']; - +$pathaw = $_GET['path']; //echo "vars= ".$startm.$endm.$starty.$endy.$website; -function data($sd, $ed, $sm, $em, $sy, $ey, $web) +function data($sd, $ed, $sm, $em, $sy, $ey, $web, $path) { $result = array(); @@ -43,10 +43,10 @@ function data($sd, $ed, $sm, $em, $sy, $ey, $web) // Total Calculation leaving start month and end month for($i=$sy;$i<=$ey;$i++){ for($j=(($i==$sy)?($sm+1):1);$j<=(($i==$ey)?($em-1):12);$j++){ - - $file = 'awstats/awstats'.$j.$i.'.'.$web.'.txt'; +// echo $sy.$sm."---"; + $file = $path.'awstats'.$j.$i.'.'.$web.'.txt'; if($j < 10){ - $file = 'awstats/awstats0'.$j.$i.'.'.$web.'.txt'; + $file = $path.'awstats0'.$j.$i.'.'.$web.'.txt'; } if(file_exists($file)){ @@ -54,7 +54,7 @@ function data($sd, $ed, $sm, $em, $sy, $ey, $web) if ($aw->Error()) die($aw->GetError()); $total_visit += $aw->GetVisits(); $unique_visit += $aw->GetUniqueVisits(); - + foreach ($aw->GetDays() as $day=>$stats) { $bandwidth += $stats[2]; @@ -68,16 +68,17 @@ function data($sd, $ed, $sm, $em, $sy, $ey, $web) //$output = array('website' => $web, 'unique_visit' => $unique_visit, 'total_visit' => $total_visit, 'total_page_loads' => $page_loads, 'total_hits' => $hits, 'total_bandwidth' => $bandwidth); //echo json_encode($output); +if(!($sm == $em && $sy == $ey)) +{ // Calculation for start month - $file = 'awstats/awstats'.$sm.$sy.'.'.$web.'.txt'; + $file = $path.'awstats'.$sm.$sy.'.'.$web.'.txt'; if($sm < 10){ - $file = 'awstats/awstats0'.$sm.$sy.'.'.$web.'.txt'; + $file = $path.'awstats0'.$sm.$sy.'.'.$web.'.txt'; } - if(file_exists($file)){ $aw = new awfile($file); if ($aw->Error()) die($aw->GetError()); -// echo json_encode($aw->GetDays()); + //echo json_encode($aw->GetDays()); $unique_visit += $aw->GetUniqueVisits(); foreach ($aw->GetDays() as $day=>$stats) { @@ -95,16 +96,22 @@ function data($sd, $ed, $sm, $em, $sy, $ey, $web) //echo json_encode($output); + // Calculation for end month - $file = 'awstats/awstats'.$em.$sy.'.'.$web.'.txt'; + $file = $path.'awstats'.$em.$sy.'.'.$web.'.txt'; if($em < 10){ - $file = 'awstats/awstats0'.$em.$sy.'.'.$web.'.txt'; + $file = $path.'awstats0'.$em.$sy.'.'.$web.'.txt'; } if(file_exists($file)){ $aw = new awfile($file); if ($aw->Error()) die($aw->GetError()); + //echo json_encode($aw->GetDays()); + if($sy == $ey && $sm == $em){ + } + else{ $unique_visit += $aw->GetUniqueVisits(); + } foreach ($aw->GetDays() as $day=>$stats) { if($day <= $ed) @@ -117,15 +124,43 @@ function data($sd, $ed, $sm, $em, $sy, $ey, $web) } } +//$output = array('website' => $web, 'unique_visit' => $unique_visit, 'total_visit' => $total_visit, 'total_page_loads' => $page_loads, 'total_hits' => $hits, 'total_bandwidth' => $bandwidth); +//echo json_encode($output); +} +else{ +// Calculation for common month + $file = $path.'awstats'.$sm.$sy.'.'.$web.'.txt'; + if($sm < 10){ + $file = $path.'awstats0'.$sm.$sy.'.'.$web.'.txt'; + } + if(file_exists($file)){ + $aw = new awfile($file); + if ($aw->Error()) die($aw->GetError()); + //echo json_encode($aw->GetDays()); + $unique_visit += $aw->GetUniqueVisits(); + foreach ($aw->GetDays() as $day=>$stats) + { + if($day >= $sd && $day <= $ed) + { + $total_visit += $stats[3]; + $bandwidth += $stats[2]; + $hits += $stats[1]; + $page_loads += $stats[0]; + } + } + } + +} + $bandwidth = round($bandwidth/1048576); $output = array('website' => $web, 'unique_visit' => $unique_visit, 'total_visit' => $total_visit, 'total_page_loads' => $page_loads, 'total_hits' => $hits, 'total_bandwidth' => $bandwidth); // var_dump($output); echo json_encode($output); return $output; } -data($startd, $endd, $startm, $endm, $starty, $endy, $website); +data($startd, $endd, $startm, $endm, $starty, $endy, $website, $pathaw); /* $aw = new awfile($file); diff --git a/server/class.awfile.php b/server/class.awfile.php index fbbb8d9..bd50ec3 100644 --- a/server/class.awfile.php +++ b/server/class.awfile.php @@ -62,7 +62,7 @@ class awfile { do { $str = trim(fgets($fd)); - if ($str{0} ==" ") continue; + if ($str[0] ==" ") continue; list($elem,$pos) = explode(" ",$str); if (isset($this->_positions[$elem])) @@ -134,6 +134,7 @@ class awfile { list($elem,$numpages,$hits,$bandwidth,$numvisits) = explode(" ",trim(fgets($fd))); $this->aDays[(int)substr($elem,6,2)] = array($numpages, $hits, $bandwidth, $numvisits); $n--; + //echo $this->aDays[(int)substr($elem,6,2)]; } fseek($fd,$this->_positions["POS_SESSION"]); -- cgit