/*
+---------------------------------------------------------------------+
| File for useronline statistics |
+---------------------------------------------------------------------+
| Name: conf.inc |
| Author: CMJ |
| Build date: 19.10.2005 |
| Version: 1.0 |
| |
| info: www.semabit.com |
| copyright: (c) semabit 2006 |
+---------------------------------------------------------------------+
| Description: |
| Configuration file of Westlog |
| All entries are mandatory! |
+---------------------------------------------------------------------+
*/
$wlini = array();
$wlini['wlrootpath'] = "/"; // Path to westlog folder
$wlini['visitTime'] = 60; // Duration of 1 visit in minutes
$wlini['logShow'] = false; // true if you want to log the access on show.php too
$wlini['getParams'] = ""; // Configure all links with preset params (terminated by '&')
$wlini['logBots'] = false; // True if you want to count bots too
$wlini['dbConShow'] = true; // true if you don't open connection to db on your own in show file.
// false if you include show.php in your project and handle db connections
// somewhere else.
$wlini['dbName'] = "usr_web38_1"; // Name of the database
$wlini['dbHost'] = "localhost"; // Name of host where your DBMS runs
$wlini['dbUser'] = "web38"; // Name of database user
$wlini['dbPwd'] = "GhFEEYlp"; // Password of database user
$wlini['botKeywords'] = array("search","bot","crawl","spider","slurp","survey","engine","archive","library","spin","such","protocol");
// Add keywords in lower case
?>
/*
+---------------------------------------------------------------------+
| Class for useronline statistics |
+---------------------------------------------------------------------+
| Name: useronline.inc |
| Author: JEM |
| Build date: 11.10.2005 |
| Version: 1.0 |
+---------------------------------------------------------------------+
*/
global $wlini;
class useronline{
// class variables
var $m_dbName;
var $m_usoID;
var $m_usoIP;
var $m_usoHost = "";
var $m_usoUseragent = "";
var $m_onlineTime;
var $tableDoesNotExistError = "1146";
var $included;
var $botKeywords = array();
var $countBots = false;
var $jsfilesincluded = false;
// Constructor
function useronline($setAccessNow = true){
$this->m_dbName = $GLOBALS['wlini']['dbName'];
$this->m_onlineTime = $GLOBALS['wlini']['visitTime'];
$this->botKeywords = $GLOBALS['wlini']['botKeywords'];
$this->included = false;
$this->m_usoIP = $_SERVER['REMOTE_ADDR'];
if(isset($_SERVER['REMOTE_HOST'])){
$this->m_usoHost = stripslashes($_SERVER['REMOTE_HOST']);
}
if(isset($_SERVER['HTTP_USER_AGENT'])){
$this->m_usoUseragent = stripslashes($_SERVER['HTTP_USER_AGENT']);
}
if($setAccessNow){
$this->setAccess();
}
} // end constructor
// ----------------------------- Get methods ------------------------------------ //
/**
* Returns the own IP address
*
* @access public
* @return REMOTE_ADDR
*/
function getMyIP(){
return $this->m_usoIP;
} // end method
/**
* Returns the own Hostname
*
* @access public
* @return REMOTE_HOST
*/
function getMyHost(){
return $this->m_usoHost;
} // end method
/**
* Return the state of bot counts
*
* @access public
* @return true if bots are in statistics
*/
function getCountBots(){
return $this->countBots;
} // end method
/**
* Returns the oldest day found in the database, therefore begin of data collection
*
* @access public
* @return first day data collection, 0 if nothing found
*/
function getFirstDay(){
$ret = 0;
$sql = "SELECT DATE_FORMAT(min(usoDay),'%d-%m-%Y') AS firstday FROM tabuseronline";
$res = $this->_sendSql($sql);
if ($row = mysql_fetch_array($res,MYSQL_ASSOC)){
$ret = $row['firstday'];
}
return $ret;
} // end method
/**
* Returns the all time amount of different IP Adresses
*
* @access public
* @return count IPs total
*/
function getIPCountTotal($pUpdateCycle = 0, $pCss = 0){
$ret = "";
if($this->countBots){
$sql = "SELECT usoIP FROM tabuseronline GROUP BY usoIP";
}
else{
$sql = "SELECT usoIP FROM tabuseronline LEFT JOIN tabbotlist ON tabuseronline.usoUseragent = tabbotlist.botUseragent ";
$sql .= "WHERE (tabbotlist.botUseragent IS NULL OR tabbotlist.botState = 'inactive') GROUP BY usoIP";
}
$res = $this->_sendSql($sql);
$ret = mysql_num_rows($res);
if($pUpdateCycle){
$ret = $this->_getLiveDiv("getIPCountTotal", $pUpdateCycle, $ret, $pCss);
}
return $ret;
} // end method
/**
* Returns the amount of different IP Adresses of a specified day
*
* @access public
* @param mixed $day [YYYYMMDD]
* @return count IPs
*/
function getIPCountDay($day, $pUpdateCycle = 0, $pCss = 0){
$ret = "";
if($this->countBots){
$sql = "SELECT usoIP FROM tabuseronline WHERE ";
$sql .= "DATE_FORMAT(usoDay, '%Y%m%d') = '".$day."' GROUP BY usoIP";
}
else{
$sql = "SELECT usoIP FROM tabuseronline LEFT JOIN tabbotlist ON tabuseronline.usoUseragent = tabbotlist.botUseragent ";
$sql .= "WHERE (tabbotlist.botUseragent IS NULL OR tabbotlist.botState = 'inactive') AND ";
$sql .= "DATE_FORMAT(usoDay, '%Y%m%d') = '".$day."' GROUP BY usoIP";
}
$res = $this->_sendSql($sql);
$ret = mysql_num_rows($res);
if($pUpdateCycle){
$ret = $this->_getLiveDiv("getIPCountDay", $pUpdateCycle, $ret, $pCss, $day);
}
return $ret;
} // end method
/**
* Returns the amount of different IP Adresses of a specified month
*
* @access public
* @param mixed $month [YYYYMM]
* @return count IPs
*/
function getIPCountMonth($month, $pUpdateCycle = 0, $pCss = 0){
$ret = "";
if($this->countBots){
$sql = "SELECT usoIP FROM tabuseronline WHERE ";
$sql .= "DATE_FORMAT(usoDay, '%Y%m') = '".$month."' GROUP BY usoIP";
}
else{
$sql = "SELECT usoIP FROM tabuseronline LEFT JOIN tabbotlist ON tabuseronline.usoUseragent = tabbotlist.botUseragent ";
$sql .= "WHERE (tabbotlist.botUseragent IS NULL OR tabbotlist.botState = 'inactive') AND ";
$sql .= "DATE_FORMAT(usoDay, '%Y%m') = '".$month."' GROUP BY usoIP";
}
$res = $this->_sendSql($sql);
$ret = mysql_num_rows($res);
if($pUpdateCycle){
$ret = $this->_getLiveDiv("getIPCountMonth", $pUpdateCycle, $ret, $pCss, $month);
}
return $ret;
} // end method
/**
* Returns the amount of different IP Adresses of a specified year
*
* @access public
* @param mixed $year [YYYY]
* @return count IPs
*/
function getIPCountYear($year, $pUpdateCycle = 0, $pCss = 0){
$ret = "";
if($this->countBots){
$sql = "SELECT usoIP FROM tabuseronline WHERE ";
$sql .= "DATE_FORMAT(usoDay, '%Y') = '".$year."' GROUP BY usoIP";
}
else{
$sql = "SELECT usoIP FROM tabuseronline LEFT JOIN tabbotlist ON tabuseronline.usoUseragent = tabbotlist.botUseragent ";
$sql .= "WHERE (tabbotlist.botUseragent IS NULL OR tabbotlist.botState = 'inactive') AND ";
$sql .= "DATE_FORMAT(usoDay, '%Y') = '".$year."' GROUP BY usoIP";
}
$res = $this->_sendSql($sql);
$ret = mysql_num_rows($res);
if($pUpdateCycle){
$ret = $this->_getLiveDiv("getIPCountYear", $pUpdateCycle, $ret, $pCss, $year);
}
return $ret;
} // end method
/**
* Returns the highest amount of different IP Adresses on a single day
*
* @access public
* @return count IPs record
*/
function getIPCountRecord(){
$ret = array("","");
if($this->countBots){
$sql = "SELECT DATE_FORMAT(usoDay, '%d-%m-%Y') AS day, count(*) AS max ";
$sql .= "FROM tabuseronline GROUP BY usoDay ORDER BY max DESC, usoDay DESC limit 1";
}
else{
$sql = "SELECT DATE_FORMAT(usoDay, '%d-%m-%Y') AS day, count(*) AS max ";
$sql .= "FROM tabuseronline LEFT JOIN tabbotlist ON tabuseronline.usoUseragent = tabbotlist.botUseragent ";
$sql .= "WHERE (tabbotlist.botUseragent IS NULL OR tabbotlist.botState = 'inactive') ";
$sql .= "GROUP BY usoDay ORDER BY max DESC, usoDay DESC limit 1";
}
$res = $this->_sendSql($sql);
if($row = mysql_fetch_array($res,MYSQL_ASSOC)){
$ret['day'] = $row['day'];
$ret['max'] = $row['max'];
}
return $ret;
} // end method
/**
* Returns the amount of visitors during the last x minutes (specified online time)
*
* @access public
* @param $pUpdateCycle (seconds of reload cycle, 0 if static)
* @return count IPs online
*/
function getOnlineCount($pUpdateCycle = 0, $pCss = 0){
$ret = 0;
if($this->countBots){
$sql = "SELECT COUNT(usoIP) AS nowonline FROM tabuseronline WHERE ";
$sql .= "DATE_SUB(now(), INTERVAL ".$this->m_onlineTime." MINUTE) < usoLastAccess";
}
else{
$sql = "SELECT COUNT(usoIP) AS nowonline FROM tabuseronline LEFT JOIN tabbotlist ";
$sql .= "ON tabuseronline.usoUseragent = tabbotlist.botUseragent ";
$sql .= "WHERE (tabbotlist.botUseragent IS NULL OR tabbotlist.botState = 'inactive') AND ";
$sql .= "DATE_SUB(now(), INTERVAL ".$this->m_onlineTime." MINUTE) < usoLastAccess";
}
$res = $this->_sendSql($sql);
if ($row = mysql_fetch_array($res,MYSQL_ASSOC)){
$ret = $row['nowonline'];
}
if($pUpdateCycle){
$ret = $this->_getLiveDiv("getOnlineCount", $pUpdateCycle, $ret, $pCss);
}
return $ret;
} // end method
/**
* Returns the amount of active bots in the botlist
*
* @access public
* @return count bots
*/
function getActiveBotCount(){
$ret = 0;
$sql = "SELECT COUNT(botId) AS botscount FROM tabbotlist WHERE botState = 'active'";
$res = $this->_sendSql($sql);
if ($row = mysql_fetch_array($res,MYSQL_ASSOC)){
$ret = $row['botscount'];
}
return $ret;
} // end method
/**
* Returns an assoc. array of access values of the chosen day
*
* @access public
* @param mixed $date [YYYYMMDD]
* @return array (ip,host,useragent,visits,hits,botid,lastAccess[DD-MM-YYYY hh:mm:ss],lastAccessUnix)
*/
function getIPList($date){
$ret = array();
$onlineStart = time() - ($this->m_onlineTime * 60);
$sql = "SELECT *, DATE_FORMAT(usoLastAccess, '%d-%m-%Y %T') AS lastAccess, ";
$sql .= "UNIX_TIMESTAMP(usoLastAccess) AS lastAccessUnix ";
$sql .= "FROM tabuseronline LEFT JOIN tabbotlist ON tabuseronline.usoUseragent = tabbotlist.botUseragent ";
$sql .= "WHERE DATE_FORMAT(usoDay, '%Y%m%d') = ".$date;
$sql .= " ORDER BY usoId";
$res = $this->_sendSql($sql);
if(mysql_errno() == $this->tableDoesNotExistError){
if($this->_addAllTables()){
echo "-> added tables! please refresh!
";
}
}
else{
while ($row = mysql_fetch_array($res,MYSQL_ASSOC)){
$current = array();
$current['ip'] = $row['usoIP'];
$current['host'] = $row['usoHost'];
$current['useragent'] = $row['usoUseragent'];
$current['visits'] = $row['usoVisits'];
$current['hits'] = $row['usoHits'];
if(($row['botId']) && ($row['botState'] == "active")){
$current['botId'] = $row['botId'];
}
else{
$current['botId'] = 0;
}
$current['lastAccess'] = $row['lastAccess'];
if($row['lastAccessUnix'] > $onlineStart){
$current['online'] = true;
}
else{
$current['online'] = false;
}
array_push($ret,$current);
}
}
return $ret;
} // end method
/**
* Returns an assoc. array of bot values
*
* @access public
* @return array (botid,useragent,enterdate,moddate,state,lastAccess[DD-MM-YYYY hh:mm:ss])
*/
function getBotList(){
$ret = array();
$sql = "SELECT * FROM tabbotlist ORDER BY botState,botEnterdate DESC";
$res = $this->_sendSql($sql);
if(mysql_errno() == $this->tableDoesNotExistError){
if($this->_addAllTables()){
echo "-> added tables! please refresh!
";
}
}
else{
while ($row = mysql_fetch_array($res,MYSQL_ASSOC)){
$current = array();
$current['botid'] = $row['botId'];
$current['useragent'] = $row['botUseragent'];
$current['enterdate'] = $row['botEnterdate'];
$current['moddate'] = $row['botModdate'];
$current['state'] = $row['botState'];
array_push($ret,$current);
}
}
return $ret;
} // end method
/**
* Returns an assoc. array of values of useragents which might be a bot
*
* @access public
* @return array (useragent,visits,hist,lastAccess[DD-MM-YYYY hh:mm:ss])
*/
function getPossibleBotList(){
$ret = array();
$sql = "SELECT tabuseronline.usoUseragent, sum(usoVisits) AS visits, sum(usoHits) AS hits, ";
$sql .= "DATE_FORMAT(usoLastAccess, '%d-%m-%Y %T') AS lastAccess ";
$sql .= "FROM tabuseronline LEFT JOIN tabbotlist ON tabuseronline.usoUseragent = tabbotlist.botUseragent ";
$sql .= "WHERE tabbotlist.botUseragent IS NULL AND (";
foreach($this->botKeywords as $value){
$sql .= " lower(tabuseronline.usoUseragent) LIKE '%".$value."%' OR";
}
//$sql = ereg_replace("OR$", "", $sql);
$sql .= " length(tabuseronline.usoUseragent) < 25) ";
$sql .= "GROUP BY tabuseronline.usoUseragent";
$sql .= " ORDER BY usoLastAccess DESC";
$res = $this->_sendSql($sql);
if(mysql_errno() == $this->tableDoesNotExistError){
if($this->_addAllTables()){
echo "-> added tables! please refresh!
";
}
}
else{
while ($row = mysql_fetch_array($res,MYSQL_ASSOC)){
$current = array();
$current['useragent'] = $row['usoUseragent'];
$current['visits'] = $row['visits'];
$current['hits'] = $row['hits'];
$current['lastAccess'] = $row['lastAccess'];
array_push($ret,$current);
}
}
return $ret;
} // end method
/**
* Creates a image chart of the specified month.
* Call this method in src part of an img tag. e.g.
*
* @access public
* @param mixed $pFilepath Path an Filename of the image (directory must have rights to write)
* @param mixed $pTitle Title of chart
* @param mixed $pShow 'visits', 'hits' or 'ip'
* @param mixed $pBarColor default 'lightskyblue'
* @param mixed $pPicLength default 400px
* @param mixed $pPicHeight default 250px
* @param mixed $month [YYYYMM] default current month
* @return picsource
*/
function getChartMonth($pFilepath, $pTitle, $pShow, $month, $pBarColor = "lightskyblue", $pPicLength = 410, $pPicHeight = 250, $pShadow = true){
if(!$this->included){
include ("graphsrc/jpgraph.php");
include ("graphsrc/jpgraph_line.php");
include ("graphsrc/jpgraph_bar.php");
$this->included = true;
}
$curDayOfMonth = date("j");
$lastDayOfCurrentMonth = 1;
$unixTimestamp = 0;
$dataList = array();
$avgList = array();
if($pShow == "visits"){
$sql = "SELECT SUM(usoVisits) as total, ";
}
elseif($pShow == "hits"){
$sql = "SELECT SUM(usoHits) as total, ";
}
else{
$sql = "SELECT COUNT(usoIP) as total, ";
}
$sql .= "DATE_FORMAT(usoDay, '%d') AS day, UNIX_TIMESTAMP(usoDay) AS unixts FROM tabuseronline ";
if(!$this->countBots){
$sql .= "LEFT JOIN tabbotlist ON tabuseronline.usoUseragent = tabbotlist.botUseragent ";
$sql .= "WHERE (tabbotlist.botUseragent IS NULL OR tabbotlist.botState = 'inactive') AND ";
}
else{
$sql .= "WHERE ";
}
$datepattern = "%Y%m";
if(strlen($month) < 6){
$datepattern = "%Y%c";
}
$sql .= "DATE_FORMAT(usoDay, '".$datepattern."') = ".$month." GROUP BY usoDay ORDER BY usoDay";
$res = $this->_sendSql($sql);
while ($row = mysql_fetch_array($res,MYSQL_ASSOC)){
$lastDayOfCurrentMonth = $row['day'];
$dataList[$lastDayOfCurrentMonth - 1] = $row['total'];
if(!$unixTimestamp){
$unixTimestamp = $row['unixts'];
}
}
// fill up missing days
for($i = 0; $i < date("t", $unixTimestamp); $i++){
if(!isset($dataList[$i])){
$dataList[$i] = 0;
}
}
ksort($dataList);
reset($dataList);
// Calculate the average
$avg = (array_sum($dataList) / $lastDayOfCurrentMonth);
foreach($dataList as $elem){
array_push($avgList,$avg);
}
// Create the graph
$graph = new Graph($pPicLength, $pPicHeight, "auto");
$graph->SetScale("textlin");
$graph->img->SetMargin(40,20,20,30);
if($pShadow){
$graph->SetShadow();
}
// Create the linear error plot
$lPlot = new LinePlot($avgList);
$lPlot->SetColor("red");
$lPlot->SetWeight(2);
$lPlot->SetBarCenter();
// Create the bar plot
$bPlot = new BarPlot($dataList);
$bPlot->SetFillColor($pBarColor);
$bPlot->SetWidth(0.8);
if($pPicHeight >= 250){
$bPlot->value->Show();
$bPlot->value->SetFormat('%d');
$graph->yaxis->scale->SetGrace(5);
}
// Add the plots to the graph
$graph->Add($bPlot);
$graph->Add($lPlot);
$graph->title->Set($pTitle);
if($pPicLength < 410){
$graph->title->SetFont(FF_FONT1);
}
else{
$graph->title->SetFont(FF_FONT1 ,FS_BOLD);
}
$graph->xaxis->SetFont(FF_FONT0);
$graph->xaxis->SetLabelAngle(90);
if($pPicHeight < 250){
$graph->yaxis->SetFont(FF_FONT0);
}
//$graph->xaxis->title->Set($xTitle);
//$graph->yaxis->title->Set($yTitle);
$graph->SetMarginColor('#DDDDDD');
$graph->ygrid->SetFill(true,'#EFEFEF@0.5','#CCDDFF@0.5');
// Display the graph
$graph->Stroke($pFilepath);
} // end method
/**
* Returns the sourcecode for a livemonitor div
*
* @access private
* @param mixed $pFunctionName Name of the calling function
* @param mixed $pUpdateCycle Cycle of reload in seconds
* @param mixed $pValue Value of current standing
* @param mixed $pCss Styling of the div Element
* @param mixed $pMethodParams commaseperated all values to handover to the method in right order
* @return jscode and div
*/
function _getLiveDiv($pFunctionName, $pUpdateCycle, $pValue, $pCss, $pMethodParams = 0){
$ret = "\n";
if($pUpdateCycle < 10){
$pUpdateCycle = 10;
}
if(!$this->jsfilesincluded){
$ret .= $this->_includeJsFiles();
}
$url = $GLOBALS['wlini']['wlrootpath']."westlog/inc/livemonitor.php?method=";
$url .= $pFunctionName;
if($pMethodParams){
$url .= "¶ms=".$pMethodParams;
}
$ret .= "\n";
$ret .= "