diff options
author | akshat0047 | 2020-05-31 00:32:03 +0530 |
---|---|---|
committer | akshat0047 | 2020-05-31 00:32:03 +0530 |
commit | 036c7d56368943a81b702e3cf5b2262fdd15982c (patch) | |
tree | e0b12f0ce96aafb6128e89492290bcc30a8e1149 | |
parent | 0b238d3e9342536efffcd65914f546b6639df3cb (diff) | |
download | AWDash-036c7d56368943a81b702e3cf5b2262fdd15982c.tar.gz AWDash-036c7d56368943a81b702e3cf5b2262fdd15982c.tar.bz2 AWDash-036c7d56368943a81b702e3cf5b2262fdd15982c.zip |
Added basic files without generalised used
-rw-r--r-- | awdash/.env | 2 | ||||
-rw-r--r-- | awdash/bootstrap.php | 11 | ||||
-rw-r--r-- | awdash/composer.json | 10 | ||||
-rw-r--r-- | awdash/composer.lock | 163 | ||||
-rw-r--r-- | awdash/public/index.css | 86 | ||||
-rw-r--r-- | awdash/public/index.html | 112 | ||||
-rw-r--r-- | awdash/public/index.js | 79 | ||||
-rw-r--r-- | awdash/public/index.php | 39 | ||||
-rw-r--r-- | awdash/public/sites.json | 11 | ||||
-rwxr-xr-x | awdash/src/Controller/WebsiteController.php | 122 | ||||
-rw-r--r-- | server/awstats.php | 171 | ||||
-rw-r--r-- | server/class.awfile.php | 221 |
12 files changed, 1027 insertions, 0 deletions
diff --git a/awdash/.env b/awdash/.env new file mode 100644 index 0000000..8cc6794 --- /dev/null +++ b/awdash/.env @@ -0,0 +1,2 @@ +OKTAAUDIENCE= +HOST= diff --git a/awdash/bootstrap.php b/awdash/bootstrap.php new file mode 100644 index 0000000..256564b --- /dev/null +++ b/awdash/bootstrap.php @@ -0,0 +1,11 @@ +<?php +require 'vendor/autoload.php'; +use Dotenv\Dotenv; + +$dotenv = new DotEnv(__DIR__); +$dotenv->load(); + +// test code, should output: +// api://default +// when you run $ php bootstrap.php +//echo getenv('OKTAAUDIENCE'); diff --git a/awdash/composer.json b/awdash/composer.json new file mode 100644 index 0000000..00cec7c --- /dev/null +++ b/awdash/composer.json @@ -0,0 +1,10 @@ +{ + "require": { + "vlucas/phpdotenv": "^2.4" + }, + "autoload": { + "psr-4": { + "Src\\": "src/" + } + } +} diff --git a/awdash/composer.lock b/awdash/composer.lock new file mode 100644 index 0000000..efe8b40 --- /dev/null +++ b/awdash/composer.lock @@ -0,0 +1,163 @@ +{ + "_readme": [ + "This file locks the dependencies of your project to a known state", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", + "This file is @generated automatically" + ], + "content-hash": "913950ad60dd11bbcdf3b8f3c8b0c052", + "packages": [ + { + "name": "symfony/polyfill-ctype", + "version": "v1.17.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-ctype.git", + "reference": "e94c8b1bbe2bc77507a1056cdb06451c75b427f9" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/e94c8b1bbe2bc77507a1056cdb06451c75b427f9", + "reference": "e94c8b1bbe2bc77507a1056cdb06451c75b427f9", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "suggest": { + "ext-ctype": "For best performance" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.17-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Polyfill\\Ctype\\": "" + }, + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Gert de Pagter", + "email": "BackEndTea@gmail.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill for ctype functions", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "ctype", + "polyfill", + "portable" + ], + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2020-05-12T16:14:59+00:00" + }, + { + "name": "vlucas/phpdotenv", + "version": "v2.6.4", + "source": { + "type": "git", + "url": "https://github.com/vlucas/phpdotenv.git", + "reference": "67d472b1794c986381a8950e4958e1adb779d561" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/vlucas/phpdotenv/zipball/67d472b1794c986381a8950e4958e1adb779d561", + "reference": "67d472b1794c986381a8950e4958e1adb779d561", + "shasum": "" + }, + "require": { + "php": "^5.3.9 || ^7.0 || ^8.0", + "symfony/polyfill-ctype": "^1.9" + }, + "require-dev": { + "ext-filter": "*", + "ext-pcre": "*", + "phpunit/phpunit": "^4.8.35 || ^5.0" + }, + "suggest": { + "ext-filter": "Required to use the boolean validator.", + "ext-pcre": "Required to use most of the library." + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.6-dev" + } + }, + "autoload": { + "psr-4": { + "Dotenv\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Graham Campbell", + "email": "graham@alt-three.com", + "homepage": "https://gjcampbell.co.uk/" + }, + { + "name": "Vance Lucas", + "email": "vance@vancelucas.com", + "homepage": "https://vancelucas.com/" + } + ], + "description": "Loads environment variables from `.env` to `getenv()`, `$_ENV` and `$_SERVER` automagically.", + "keywords": [ + "dotenv", + "env", + "environment" + ], + "funding": [ + { + "url": "https://github.com/GrahamCampbell", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/vlucas/phpdotenv", + "type": "tidelift" + } + ], + "time": "2020-05-02T13:38:00+00:00" + } + ], + "packages-dev": [], + "aliases": [], + "minimum-stability": "stable", + "stability-flags": [], + "prefer-stable": false, + "prefer-lowest": false, + "platform": [], + "platform-dev": [], + "plugin-api-version": "1.1.0" +} diff --git a/awdash/public/index.css b/awdash/public/index.css new file mode 100644 index 0000000..27aaabc --- /dev/null +++ b/awdash/public/index.css @@ -0,0 +1,86 @@ +body{ + position: relative; + width: 100%; + height: auto; + overflow-x:hidden; + overflow-y:auto; + background-color: rgb(255, 255, 255); + outline-box: none; +} + +header{ + box-shadow: 0 0 2px 2px rgba(0,0,0,0.2); +} + +form{ + margin: auto; +} + +#filterform{ + position: relative; + padding:1%; +} + +.loader{ + position: fixed; + margin: auto; + left: 0px; + right: 0px; + bottom: 0px; + top: 0px; + z-index: 5; +} + +.input-col{ + position: relative; + margin:5px !important; +} + +select, option { + position: relative; + width:200px; +} + +.cards-form{ + position: relative; + text-align: center; + margin:auto; + left: 0px; + right:0px; +} + +.input-col{ + position: relative; + text-align:center; + margin:auto; + left:0px; + right:0px; +} + +.table-box{ + position: relative; + width: 100%; + height:100%; + top: 50px; + padding-bottom:60px; +} + + +footer{ + position: fixed; + width: 100%; + height: 8%; + bottom: 0px; + box-shadow: 0 0 2px 2px rgba(0,0,0,0.2); + background: rgb(43, 42, 42); +} + +.ft-col{ + position: relative; + text-align: center; + color: white; +} + +.ft-col > span { + position: relative; +} diff --git a/awdash/public/index.html b/awdash/public/index.html new file mode 100644 index 0000000..6ab6e8e --- /dev/null +++ b/awdash/public/index.html @@ -0,0 +1,112 @@ +<!DOCTYPE html> +<html lang="en"> +<head> + <meta charset="UTF-8"> + <meta name="viewport" content="width=device-width, initial-scale=1.0"> + <title>Awdash Beta</title> + <!-- CSS only --> + <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous"> + <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css"> + <link rel="stylesheet" href="index.css"> + <!-- jQuery --> + <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> + <script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script> + <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js" integrity="sha384-OgVRvuATP1z7JjHLkuOU7Xw704+h835Lr+6QL9UvYjZE3Ipu6Tp75j7Bh/kR0JKI" crossorigin="anonymous"></script> +</head> +<body> + <header> + <nav class="navbar navbar-expand-lg navbar-light bg-d"> + <a class="navbar-brand" href="#">AWDASH</a> + <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation"> + <span class="navbar-toggler-icon"></span> + </button> + <div class="collapse navbar-collapse" id="navbarNav"> + <ul class="navbar-nav"> + <li class="nav-item active"> + <a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a> + </li> + <li class="nav-item"> + <a class="nav-link" href="#">API Docs</a> + </li> + </ul> + + <form id="filterform" class="form-inline my-2 my-lg-0"> + <div class="input-col input-group"> + <div class="input-group-prepend"> + <div class="input-group-text"><i class="fa fa-globe" aria-hidden="true"></i></div> + </div> + <select id="myselect" class="form-control"> + <option value=''>All Websites</option> + </select> + </div> + + <div class="input-col input-group"> + <div class="input-group-prepend"> + <div class="input-group-text"><i class="fa fa-calendar" aria-hidden="true"></i></div> + </div> + <input type="date" class="form-control" id="inlineFormInputGroup" placeholder="From"/> + </div> + + <div class="input-col input-group"> + <div class="input-group-prepend"> + <div class="input-group-text"><i class="fa fa-calendar" aria-hidden="true"></i></div> + </div> + <input type="date" class="form-control" id="inlineFormInputGroup" placeholder="To"/> + </div> + + <button id="filter" class="input-col btn btn-outline-primary my-2 my-sm-0">Submit</button> + <button id="reset" class="input-col btn btn-primary my-2 my-sm-0"><i class="fa fa-undo" aria-hidden="true"></i></button> + </form> + + </div> + </nav> + </header> + + <h6 id="no-data"></h6> + + <section class="table-box container"> + + <div id="loading" class="spinner-border text-primary loader" style="width: 2.5rem; height: 2.5rem;" role="status"> + <span class="sr-only"></span> + </div> + + <div class="table-responsive"> + <table class="table"> + <thead class="thead-dark"> + <tr> + <th scope="col">#</th> + <th scope="col">Website</th> + <th scope="col">Unique Visits(Monthly)</th> + <th scope="col">Total Visits</th> + <th scope="col">Total Page Loads</th> + <th scope="col">Hits</th> + <th scope="col">Bandwidth</th> + <th scope="col">Link</th> + </tr> + </thead> + <tbody id="table-body"> + + </tbody> + </table> + </div> + </section> + + <footer> + <div class="row"> + <div class="ft-col col-4"> + + </div> + <div class="ft-col col-4"> + <span style="font-size:0.7em">© Copyright 2020 || All Rights Reserved <br/> + Powered By FOSSEE, IIT Bombay</span> + </div> + <div class="ft-col col-4"> + + </div> + </div> + + </footer> + +<script src="index.js"></script> +</body> +</html> diff --git a/awdash/public/index.js b/awdash/public/index.js new file mode 100644 index 0000000..134b98b --- /dev/null +++ b/awdash/public/index.js @@ -0,0 +1,79 @@ +$(document).ready(function() { + +var today = new Date(); +var dd = today.getDate(); +var mm = today.getMonth()+1; +var yyyy = today.getFullYear(); +var defaultdate; + +if(dd<10) +{ + dd='0'+dd; +} +if(mm<10) +{ + mm='0'+mm; +} + +function getAll(time = "01012013" + dd + mm + yyyy, website = "") +{ +//console.log("time= " + time + "website = " + website); +$("#table-body").css("visibility","hidden"); +$("#loading").css("display","block"); + +var url = "https://Domain/websites/" + time + "/" + website; +$.get(url, function(data, status){ + var rows = ""; +// console.log(data); + for(var i=0; i<data.length; i++) + { + rows += "<tr>" + + "<th scope='row'>" + data[i].sno + "</th>" + + "<td><a href='http://" + data[i].website + "' target='_blank'>" + data[i].website + "</a></td>" + + "<td>" + data[i].unique_visit + "</td>" + + "<td>" + data[i].total_visit + "</td>" + + "<td>" + data[i].total_page_loads + "</td>" + + "<td>" + data[i].total_hits + "</td>" + + "<td>" + data[i].total_bandwidth + "</td>" + + "<td><a href='" + data[i].awstats + "' target='_blank'>Click Here</a></td>" + + "</tr>"; + } + + $("#table-body").html(rows); + $("#loading").css("display","none"); + $("#table-body").css("visibility","visible"); + + }); +} + +$("#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]; + + if(time.includes("undefined")) + time = null; + + if(time && website) + getAll(time, website); + else if(time) + getAll(time); + else + getAll(defaultdate+dd+mm+yyyy, website); + }); + +$("#reset").click(e => { + e.preventDefault(); + getAll(); + }); + +$.getJSON("sites.json", function(json) { + defaultdate = json['defaultdate']; + $.each(json['sites'], (index, value) => { + val = parseInt(index, 10) + 1; + $("#myselect").append("<option value='" + val + "'>" + value['domain'] + "</option>"); + }); + getAll(); +}); +}); diff --git a/awdash/public/index.php b/awdash/public/index.php new file mode 100644 index 0000000..937336e --- /dev/null +++ b/awdash/public/index.php @@ -0,0 +1,39 @@ +<?php +require "../bootstrap.php"; +use Src\Controller\WebsiteController; + +header("Access-Control-Allow-Origin: *"); +header("Content-Type: application/json; charset=UTF-8"); +header("Access-Control-Allow-Methods: OPTIONS,GET,POST,PUT,DELETE"); +header("Access-Control-Max-Age: 3600"); +header("Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With"); + +$uri = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH); +$uri = explode( '/', $uri ); + +if ($uri[1] !== 'websites') { + $file = 'index.html'; + if (file_exists($file)) { + header('Location: Domain'); + } else { + // throw new \Slim\Exception\NotFoundException($request, $response); + exit(); + } +} + +// the website and time arguements are checked else assigned a default value: +$website = null; +$time = null; +if (isset($uri[2]) && trim($uri[2])!=="") { + $time = htmlspecialchars_decode(trim($uri[2])); +} +else{ + $time = json_decode(file_get_contents('sites.json'), true)['defaultdate'].date("dmY"); +} +if (isset($uri[3])){ + $website = htmlspecialchars_decode(trim($uri[3])); +} + +$requestMethod = $_SERVER["REQUEST_METHOD"]; +$controller = new WebsiteController($requestMethod, $time, $website); +$controller->processRequest(); diff --git a/awdash/public/sites.json b/awdash/public/sites.json new file mode 100644 index 0000000..987c8a5 --- /dev/null +++ b/awdash/public/sites.json @@ -0,0 +1,11 @@ +{ + "defaultdate":"default start date of logs", + "sites":[{ + "domain":"domain to show in the list as name", + "awstats":"link of individual awstats url for the domain" + }, + { + "domain":"", + "awstats":"" + }] +} diff --git a/awdash/src/Controller/WebsiteController.php b/awdash/src/Controller/WebsiteController.php new file mode 100755 index 0000000..612391f --- /dev/null +++ b/awdash/src/Controller/WebsiteController.php @@ -0,0 +1,122 @@ +<?php +namespace Src\Controller; +use Src\Controller\awfile; + +class WebsiteController { + + private $requestMethod; + private $websiteId; + private $time; + private $sno=1; + private $sites; + private $result = array(); + + public function __construct($requestMethod, $time, $website) + { + $this->requestMethod = $requestMethod; + $this->website = (int)$website; + $this->time = $time; + } + + public function processRequest() + { + switch ($this->requestMethod) { + case 'GET': + $response = $this->getData($this -> time, $this -> website); + break; + case 'POST': + $response = $this->methodNotAllowed(); + break; + /*case 'PUT': + $response = $this->updateUserFromRequest($this->userId); + break; + case 'DELETE': + $response = $this->deleteUser($this->userId); + break; + default: + $response = $this->notFoundResponse(); + break;*/ + } + + header($response['status_code_header']); + if ($response['body']) { + echo $response['body']; + } + } + + private function unprocessableEntityResponse() + { + $response['status_code_header'] = 'HTTP/1.1 422 Unprocessable Entity'; + $response['body'] = json_encode([ + 'error' => 'Invalid input' + ]); + return $response; + } + + private function notFoundResponse() + { + $response['status_code_header'] = 'HTTP/1.1 404 Not Found'; + $response['body'] = null; + return $response; + } + + private function methodNotAllowed() + { + $response['status_code_header'] = 'HTTP/1.1 405 Method Not Allowed'; + $response['body'] = null; + return $response; + } + + private function getData($time, $website) + { + $sd = (int)substr($time, 0, 2); + $ed = (int)substr($time, 8, 2); + $sm = (int)substr($time, 2, 2); + $em = (int)substr($time, 10, 2); + $sy = (int)substr($time, 4, 4); + $ey = (int)substr($time, 12, 4); + + $this -> sites = json_decode(file_get_contents('./sites.json'),true); + + if($sd!==null && $ed!==null && $sm!==null && $em!==null && $sy!==null && $ey!==null) + { + if($website !== 0) + { + if(gettype($website) == 'integer') + { + if($website > 0 && $website <= sizeof($this->sites['sites'])) + $website = array($this->sites['sites'][$website - 1]); + else + return $this -> notFoundResponse(); + } + else{ + return $this -> notFoundResponse(); + } + } + else{ + $website = $this -> sites['sites']; + } + + 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']; + $contents = json_decode(file_get_contents($url)); + $contents -> sno = $this -> sno; + $this -> sno += 1; + $contents -> awstats = $web['awstats']; + array_push($this -> result, $contents); + } + + if (empty($this -> result)) { + return $this->notFoundResponse(); + } + +// echo "Date: ".$sd.$sm.$sy.$ed.$em.$ey; + $response['status_code_header'] = 'HTTP/1.1 200 OK'; + $response['body'] = json_encode($this -> result); + $response['dataType'] = 'json'; + return $response; + } + } + +} diff --git a/server/awstats.php b/server/awstats.php new file mode 100644 index 0000000..24adcb8 --- /dev/null +++ b/server/awstats.php @@ -0,0 +1,171 @@ +<?php +/** +* Copyright (c) 2005 - Javier Infante +* All rights reserved. This program and the accompanying materials +* are made available under the terms of the +* GNU General Public License (GPL) Version 2, June 1991, +* which accompanies this distribution, and is available at: +* http://www.opensource.org/licenses/gpl-license.php +* +* Description: Example of usage of class.awfile.php +* +* Author: Javier Infante (original author) +* Email: jabi (at) irontec (dot) com +**/ +require("class.awfile.php"); + +//echo "Inside File"; +//echo json_encode($_GET); + +$startd = $_GET['sd']; +$endd = $_GET['ed']; +$startm = $_GET['sm']; +$endm = $_GET['em']; +$starty = $_GET['sy']; +$endy = $_GET['ey']; +$website = $_GET['web']; + +//echo "vars= ".$startm.$endm.$starty.$endy.$website; + +function data($sd, $ed, $sm, $em, $sy, $ey, $web) +{ + + $result = array(); + $sno = 1; + +// Path to the AWSTATS DATA FILE + $unique_visit = 0; + $total_visit = 0; + $page_loads = 0; + $hits = 0; + $bandwidth =0; + +// 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'; + if($j < 10){ + $file = 'awstats/awstats0'.$j.$i.'.'.$web.'.txt'; + } + + if(file_exists($file)){ + $aw = new awfile($file); + if ($aw->Error()) die($aw->GetError()); + $total_visit += $aw->GetVisits(); + $unique_visit += $aw->GetUniqueVisits(); + + foreach ($aw->GetDays() as $day=>$stats) + { + $bandwidth += $stats[2]; + $hits += $stats[1]; + $page_loads += $stats[0]; + } + } + } + } + +//$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); + +// Calculation for start month + $file = 'awstats/awstats'.$sm.$sy.'.'.$web.'.txt'; + if($sm < 10){ + $file = 'awstats/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) + { + $total_visit += $stats[3]; + $bandwidth += $stats[2]; + $hits += $stats[1]; + $page_loads += $stats[0]; + } + } + } + +//$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); + + +// Calculation for end month + $file = 'awstats/awstats'.$em.$sy.'.'.$web.'.txt'; + if($em < 10){ + $file = 'awstats/awstats0'.$em.$sy.'.'.$web.'.txt'; + } + + if(file_exists($file)){ + $aw = new awfile($file); + if ($aw->Error()) die($aw->GetError()); + $unique_visit += $aw->GetUniqueVisits(); + foreach ($aw->GetDays() as $day=>$stats) + { + if($day <= $ed) + { + $total_visit += $stats[3]; + $bandwidth += $stats[2]; + $hits += $stats[1]; + $page_loads += $stats[0]; + } + } + } + + + + $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); + +/* + $aw = new awfile($file); + if ($aw->Error()) die($aw->GetError()); + + echo "<strong>Showing contents [".$file."]</strong><br />"; + + echo "The site first visit in the month: ".$aw->GetFirstVisit()."<br /><br />"; + echo "Total visits this month: ".$aw->GetVisits()."<br /><br />"; + echo "Total unique visits this month: ".$aw->GetUniqueVisits()."<br /><br />"; + /*echo "Pages viewed / hours:<br />"; + foreach ($aw->GetHours() as $hour=>$pages) + echo " <em>".str_pad($hour, 2, "0", STR_PAD_LEFT).": ".$pages." pages viewed.</em><br />"; + + echo "Pages viewed / days:<br />"; + foreach ($aw->GetDays() as $day=>$pages) + echo " <em>".$day.": ".$pages." pages viewed.</em><br />"; + echo "<br />"; + + $betterDay = $aw->GetBetterDay(); + echo "The day with more visitors(".$betterDay[1].") was the ".$betterDay[0].".<br /><br />"; + + echo "hits / os:<br />"; + foreach ($aw->GetOs() as $os=>$hits) + echo " <em>".$os.": ".$hits." hits.</em><br />"; + echo "<br />"; + + echo "hits / browser:<br />"; + foreach ($aw->GetBrowser() as $browser=>$hits) + echo " <em>".$browser.": ".$hits." hits.</em><br />"; + echo "<br />"; + + echo "Distinct Referers:<br />"; + foreach ($aw->GetReferers() as $referer=>$hits) + echo " <em>".$referer.": ".$hits." hits.</em><br />"; + echo "<br />"; + + echo "Visits / Session Ranges:<br />"; + foreach ($aw->GetRanges() as $range=>$visits) + echo " <em>".$range.": ".$visits." visits.</em><br />"; + echo "<br />";*/ + +?> diff --git a/server/class.awfile.php b/server/class.awfile.php new file mode 100644 index 0000000..fbbb8d9 --- /dev/null +++ b/server/class.awfile.php @@ -0,0 +1,221 @@ +<?php +/** +* Copyright (c) 2005 - Javier Infante +* All rights reserved. This program and the accompanying materials +* are made available under the terms of the +* GNU General Public License (GPL) Version 2, June 1991, +* which accompanies this distribution, and is available at: +* http://www.opensource.org/licenses/gpl-license.php +* +* Description: Simple class that parses into simple PPH arrays +* access information to a site, from a AWSTATS DATA FILE. +* This file is found as "awstatsMMYYYY.example.com.txt" commonly +* in shared servers or others. +* The information recieved is quite limited (as much as i needed so far). +* +* Name of the class: awfile +* Version: 0.1 +* Author: Javier Infante (original author) +* Email: jabi (at) irontec (dot) com +**/ + +class awfile { + var $fich; + var $first_visit; + var $visits; + var $uniquevisits; + var $dates = array(); + var $aHours = array(); + var $aDays = array(); + var $aOs = array(); + var $aBrowser = array(); + var $aReferers = array(); + var $aRange = array(); + var $aSections = array(); + var $error = false; + var $ErrorStr = array( + 1=>"file not found.", + 2=>"File not readable"); + var $_positions = array( + "POS_GENERAL"=>0, + "POS_TIME"=>0, + "POS_OS"=>0, + "POS_BROWSER"=>0, + "POS_PAGEREFS"=>0, + "POS_DAY"=>0, + "POS_SESSION"=>0, + "POS_SIDER"=>0); + + function awfile($fich) { + if (!file_exists($fich)) + $this->error = 1; + else { + $this->fich = $fich; + $this->__proc(); + } + } + + function __proc() { + if (!$fd = fopen($this->fich,"r")) + $this->error = 2; + else { + + do { + $str = trim(fgets($fd)); + if ($str{0} ==" ") continue; + + list($elem,$pos) = explode(" ",$str); + if (isset($this->_positions[$elem])) + $this->_positions[$elem] = $pos; + else continue; + } while ($str!="END_MAP"); + + + fseek($fd,$this->_positions["POS_GENERAL"]); + list(,$n) = explode(" ",trim(fgets($fd))); + $pendientes = 3; + while ($n>0) { + list($elem,$num) = explode(" ",trim(fgets($fd))); + switch($elem) { + case "FirstTime": + $this->first_visit = $num; + $pendientes--; + break; + case "TotalVisits": + $this->visits = $num; + $pendientes--; + break; + + case "TotalUnique": + $this->uniquevisits = $num; + $pendientes--; + break; + default: continue; + } + if ($pendientes==0) break; + $n--; + } + + fseek($fd,$this->_positions["POS_TIME"]); + list(,$n) = explode(" ",trim(fgets($fd))); + while ($n>0) { + list($elem,$num,,,,,) = explode(" ",trim(fgets($fd))); + $this->aHours[$elem] = $num; + $n--; + } + + fseek($fd,$this->_positions["POS_OS"]); + list(,$n) = explode(" ",trim(fgets($fd))); + while ($n>0) { + list($elem,$num) = explode(" ",trim(fgets($fd))); + $this->aOs[$elem] = $num; + $n--; + } + + fseek($fd,$this->_positions["POS_BROWSER"]); + list(,$n) = explode(" ",trim(fgets($fd))); + while ($n>0) { + list($elem,$num) = explode(" ",trim(fgets($fd))); + $this->aBrowser[$elem] = $num; + $n--; + } + + fseek($fd,$this->_positions["POS_PAGEREFS"]); + list(,$n) = explode(" ",trim(fgets($fd))); + while ($n>0) { + list($elem,$num,) = explode(" ",trim(fgets($fd))); + $this->aReferes[$elem] = $num; + $n--; + } + + fseek($fd,$this->_positions["POS_DAY"]); + list(,$n) = explode(" ",trim(fgets($fd))); + while ($n>0) { + list($elem,$numpages,$hits,$bandwidth,$numvisits) = explode(" ",trim(fgets($fd))); + $this->aDays[(int)substr($elem,6,2)] = array($numpages, $hits, $bandwidth, $numvisits); + $n--; + } + + fseek($fd,$this->_positions["POS_SESSION"]); + list(,$n) = explode(" ",trim(fgets($fd))); + while ($n>0) { + list($elem,$num) = explode(" ",trim(fgets($fd))); + $this->aRange[$elem] = $num; + $n--; + } + + fseek($fd,$this->_positions["POS_SIDER"]); + list(,$n) = explode(" ",trim(fgets($fd))); + while ($n>0) { + list($elem,$num,,,) = explode(" ",trim(fgets($fd))); + $this->aSections[$elem] = $num; + $n--; + } + + } + + } + + + function GetFirstVisit() { + return $this->first_visit; + } + + function GetVisits() { + return $this->visits; + } + + function GetUniqueVisits() { + return $this->uniquevisits; + } + + function GetHours() { + return $this->aHours; + } + + function GetDays() { + return $this->aDays; + } + + function GetOs() { + return $this->aOs; + } + + function GetBrowser() { + return $this->aBrowser; + } + + function GetReferers() { + return $this->aReferes; + } + + function GetRanges() { + return $this->aRange; + } + + function GetSections() { + return $this->aSections; + } + + function Error() { + return $this->error; + } + + function GetError() { + return $this->ErrorStr[$this->error]; + } + + function GetBetterDay() { + $max = 0; + foreach ($this->aDays as $day => $num) { + if ($num>$max) { + $max = $num; + $date = $day; + } + } + return array($date,$max); + } + +} + +?> |