| verzia 1.13, 2002/01/13 01:36:39 |
verzia 1.14, 2002/01/13 19:58:42 |
|
|
| */ |
*/ |
| |
|
| /* |
/* |
| * Before doing anything else read config file. |
|
| */ |
|
| //include("config.inc.php"); |
|
| |
|
| /* |
|
| * Ident library |
* Ident library |
| */ |
*/ |
| |
|
| include_once("libident/libident.php"); |
include_once("libident/libident.php"); |
| |
|
| /* |
/* |
| * Pear DB library |
* Pear DB library |
| */ |
*/ |
| |
|
| include_once("DB.php"); |
include_once("DB.php"); |
| |
|
| class Web_Log { |
class Web_Log { |
| Riadok 53 class Web_Log { |
|
| Riadok 50 class Web_Log { |
|
| |
|
| $_session_timeout - maximum delay between two click from the same site |
$_session_timeout - maximum delay between two click from the same site |
| with the same user agent to count it as one session |
with the same user agent to count it as one session |
| $_session_keys - keys of properties (keys to $_props array) defined |
$_session_keys - keys of properties (keys to $_props array) which define |
| session; for each session all values of particular key |
session; for each session all values of particular key |
| are the same |
are the same |
| */ |
*/ |
| |
|
| var $_session_timeout; |
var $_session_timeout; |
| var $_session_keys = array('remote_addr', 'http_user_agent'); |
var $_session_keys = array('remote_addr', 'http_user_agent'); |
| |
|
| Riadok 65 class Web_Log { |
|
| Riadok 63 class Web_Log { |
|
| $_db - PEAR DB object |
$_db - PEAR DB object |
| $_dsn - database connection URI (db_type://user:pass@host/db_name) |
$_dsn - database connection URI (db_type://user:pass@host/db_name) |
| */ |
*/ |
| |
|
| var $_db; |
var $_db; |
| var $_dsn; |
var $_dsn; |
| |
|
| Riadok 87 class Web_Log { |
|
| Riadok 86 class Web_Log { |
|
| value value of property |
value value of property |
| id id of property; defined only if value is stored in its own |
id id of property; defined only if value is stored in its own |
| separate table |
separate table |
| |
disable if non zero, property is disabled; no action with that property |
| |
is done; by default, all properties are enabled (not disabled) |
| */ |
*/ |
| |
|
| var $_props = array( |
var $_props = array( |
| 'id' => array( |
'id' => array( |
| 'column' => 'id', |
'column' => 'id', |
| Riadok 252 class Web_Log { |
|
| Riadok 254 class Web_Log { |
|
| * |
* |
| * Object constructor. |
* Object constructor. |
| */ |
*/ |
| |
|
| function Web_Log($dsn = '') |
function Web_Log($dsn = '') |
| { |
{ |
| |
|
| Riadok 261 class Web_Log { |
|
| Riadok 264 class Web_Log { |
|
| unset($this->_dsn); |
unset($this->_dsn); |
| |
|
| if (! empty($dsn)) { |
if (! empty($dsn)) { |
| $this->set_dsn($dsn); |
$this->setDSN($dsn); |
| } |
} |
| } |
} |
| |
|
| /* |
/* |
| * set_session_timeout() |
* setSessionTimeout(), getSessionTimeout() |
| * |
* |
| * Sets session timeout. Session timeout is a maximum delay between |
* Sets/gets session timeout. Session timeout is a maximum delay between |
| * two click from the same site with the same user agent to count it |
* two click from the same site with the same user agent to count it as |
| * as one session. |
* one session. |
| */ |
*/ |
| function set_session_timeout($timeout) |
|
| |
function setSessionTimeout($timeout) |
| { |
{ |
| $this->_session_timeout = $timeout; |
$this->_session_timeout = $timeout; |
| } |
} |
| |
|
| |
function getSessionTimeout() |
| |
{ |
| |
return $this->_session_timeout; |
| |
} |
| |
|
| |
/* |
| |
* setSessionKeys(), getSessionKeys() |
| |
* |
| |
* Sets/gets session keys. |
| |
*/ |
| |
|
| |
function setSessionKeys($keys) |
| |
{ |
| |
if (is_array($keys)) { |
| |
$this->_session_keys = $keys; |
| |
} |
| |
elseif (is_string($keys)) { |
| |
$this->_session_keys = array($keys); |
| |
} |
| |
} |
| |
|
| |
function getSessionKeys() |
| |
{ |
| |
return $this->_session_keys; |
| |
} |
| |
|
| /* |
/* |
| * set_dsn() |
* enableProperty(), disableProperty() |
| |
* |
| |
* Enable/disable loging of specific property. |
| |
*/ |
| |
|
| |
function enableProperty($property) |
| |
{ |
| |
if (isset($this->_props[$property])) |
| |
$this->_props[$property]['disabled'] = false; |
| |
} |
| |
|
| |
function disableProperty($property) |
| |
{ |
| |
if (isset($this->_props[$property])) |
| |
$this->_props[$property]['disabled'] = true; |
| |
} |
| |
|
| |
/* |
| |
* enableAllProperties(), disableAllProperties() |
| |
* |
| |
* Enable/disable loging of all properties. |
| |
*/ |
| |
|
| |
function enableAllProperties() |
| |
{ |
| |
foreach (array_keys($this->_props) as $property) { |
| |
$this->_props[$property]['disabled'] = false; |
| |
} |
| |
} |
| |
|
| |
function disableAllProperties() |
| |
{ |
| |
foreach (array_keys($this->_props) as $property) { |
| |
$this->_props[$property]['disabled'] = true; |
| |
} |
| |
} |
| |
|
| |
/* |
| |
* setDSN() |
| * |
* |
| * Sets DSN (db_type://user:pass@host/db_name) for database connection. |
* Sets DSN (db_type://user:pass@host/db_name) for database connection. |
| */ |
*/ |
| function set_dsn($dsn) |
|
| |
function setDSN($dsn) |
| { |
{ |
| $this->_dsn = $dsn; |
$this->_dsn = $dsn; |
| } |
} |
| Riadok 292 class Web_Log { |
|
| Riadok 361 class Web_Log { |
|
| * |
* |
| * Error handling function. |
* Error handling function. |
| */ |
*/ |
| |
|
| function _error($message = "Unknown error") { |
function _error($message = "Unknown error") { |
| die ("<b>phpWebLogAnalyzer fatal failure</b>: " . $message |
die ("<b>phpWebLogAnalyzer fatal failure</b>: " . $message |
| . "<br>Please contact webmaster or system administrator" |
. "<br>Please contact webmaster or system administrator" |
| Riadok 301 class Web_Log { |
|
| Riadok 371 class Web_Log { |
|
| } |
} |
| |
|
| /* |
/* |
| * _check_db() |
* _checkDB() |
| * |
* |
| * Checks if $this->_db is a valid PEAR DB object. If not it creates a new |
* Checks if $this->_db is a valid PEAR DB object. If not it creates a new |
| * one using $this->_dsn variable. |
* one using $this->_dsn variable. |
| */ |
*/ |
| function _check_db() |
|
| |
function _checkDB() |
| { |
{ |
| if (! isset($this->_db)) { |
if (! isset($this->_db)) { |
| $this->_db = DB::connect($this->_dsn); |
$this->_db = DB::connect($this->_dsn); |
| Riadok 320 class Web_Log { |
|
| Riadok 391 class Web_Log { |
|
| } |
} |
| |
|
| /* |
/* |
| * register_access() |
* registerAccess() |
| * |
* |
| * Register access. Insert one record to accesses table. |
* Register access. Insert one record to accesses table. |
| * Also insert records into another tables if it is neccessary. |
* Also insert records into another tables if it is neccessary. |
| */ |
*/ |
| function register_access($value = 0) { |
|
| |
|
| $this->_check_db(); |
function registerAccess($value = 0) |
| |
{ |
| |
|
| |
$this->_checkDB(); |
| |
|
| global $HTTP_SERVER_VARS; |
global $HTTP_SERVER_VARS; |
| global $HTTP_ENV_VARS; |
global $HTTP_ENV_VARS; |
| |
|
| /* |
/* |
| * Process props[] values. |
* Sets $_props values according appropriate 'var' if defined. |
| */ |
*/ |
| |
|
| echo "Path info: " .$HTTP_SERVER_VARS["PATH_TRANSLATED"]."<br>"; |
foreach (array_keys($this->_props) as $prop_name) { |
| |
|
| |
if ($this->_props[$prop_name]['disabled']) |
| |
continue; |
| |
|
| foreach (array_keys($this->_props) as $prop_name) { |
|
| if (! empty($this->_props[$prop_name]['var'])) { |
if (! empty($this->_props[$prop_name]['var'])) { |
| $this->_props[$prop_name]['value'] = |
$this->_props[$prop_name]['value'] = |
| $this->_props[$prop_name]['var'][0] == '$' |
$this->_props[$prop_name]['var'][0] == '$' |
| Riadok 356 class Web_Log { |
|
| Riadok 430 class Web_Log { |
|
| $remote_host = ''; |
$remote_host = ''; |
| $proxy_addr = ''; |
$proxy_addr = ''; |
| $proxy_host = ''; |
$proxy_host = ''; |
| $ident_user = ''; |
|
| $ident_ostype = ''; |
|
| |
|
| |
|
| if (! empty($HTTP_SERVER_VARS["HTTP_X_FORWARDED_FOR"])) { |
if (! empty($HTTP_SERVER_VARS["HTTP_X_FORWARDED_FOR"])) { |
| Riadok 368 class Web_Log { |
|
| Riadok 440 class Web_Log { |
|
| $remote_addr = $HTTP_SERVER_VARS["REMOTE_ADDR"]; |
$remote_addr = $HTTP_SERVER_VARS["REMOTE_ADDR"]; |
| } |
} |
| |
|
| |
if (! $this->_props['remote_addr']['disabled']) |
| |
$this->_props['remote_addr']['value'] = $remote_addr; |
| |
|
| |
if (! $this->_props['proxy_addr']['disabled']) |
| |
$this->_props['proxy_addr']['value'] = $proxy_addr; |
| |
|
| /* |
/* |
| * Host names resolving. |
* Host names resolving. |
| */ |
*/ |
| |
|
| $remote_host = @gethostbyaddr($remote_addr); |
if (! $this->_props['remote_host']['disabled']) { |
| if (! strcmp($remote_host, $remote_addr)) |
$remote_host = @gethostbyaddr($remote_addr); |
| $remote_host = ''; |
if (! strcmp($remote_host, $remote_addr)) |
| |
$remote_host = ''; |
| |
|
| |
$this->_props['remote_host']['value'] = $remote_host; |
| |
} |
| |
|
| if ($proxy_addr) { |
if ($proxy_addr) { |
| $proxy_host = @gethostbyaddr($proxy_addr); |
if ($this->_props['proxy_host']['disabled']) { |
| if (! strcmp($proxy_host, $proxy_addr)) |
$proxy_host = @gethostbyaddr($proxy_addr); |
| $proxy_host = ''; |
if (! strcmp($proxy_host, $proxy_addr)) |
| |
$proxy_host = ''; |
| |
|
| |
$this->_props['proxy_host']['value'] = $proxy_host; |
| |
} |
| } |
} |
| |
|
| /* |
/* |
| * Ident protocol stuff |
* Ident protocol stuff. |
| */ |
*/ |
| |
|
| $ident = new Net_Ident( $remote_addr, |
if (! $this->_props['ident_username']['disabled'] |
| $HTTP_SERVER_VARS["REMOTE_PORT"], |
|| ! $this->_props['ident_username']['disabled']) { |
| $HTTP_SERVER_VARS["SERVER_PORT"]); |
|
| |
$ident = new Net_Ident( $remote_addr, |
| if ($ident->status() == 1) { |
$HTTP_SERVER_VARS["REMOTE_PORT"], |
| // print "Ident query failed: " . $ident->error() . ".<br>\n"; |
$HTTP_SERVER_VARS["SERVER_PORT"]); |
| } |
|
| else { |
if ($ident->status() == 1) { |
| $ident_user = $ident->user(); |
// print "Ident query failed: " . $ident->error() . ".<br>\n"; |
| $ident_ostype = $ident->osType(); |
} |
| |
else { |
| |
if (! $this->_props['ident_username']['disabled']) |
| |
$this->_props['ident_username']['value'] = $ident->user(); |
| |
if (! $this->_props['ident_ostype']['disabled']) |
| |
$this->_props['ident_ostype']['value'] = $ident->osType(); |
| |
} |
| } |
} |
| |
|
| $this->_props['remote_addr']['value'] = $remote_addr; |
/* |
| $this->_props['remote_host']['value'] = $remote_host; |
* Value property processing. |
| $this->_props['proxy_addr']['value'] = $proxy_addr; |
*/ |
| $this->_props['proxy_host']['value'] = $proxy_host; |
|
| $this->_props['ident_username']['value'] = $ident_user; |
|
| $this->_props['ident_ostype']['value'] = $ident_ostype; |
|
| |
|
| // No, it's not a typo. Funny, but important! |
if (! $this->_props['value']['disabled']) |
| $this->_props['value']['value'] = $value; |
$this->_props['value']['value'] = $value; |
| |
|
| $keys = ''; |
/* |
| $vals = ''; |
* Counting IDs according to values. |
| $count = 0; |
*/ |
| |
|
| foreach (array_keys($this->_props) as $prop_name) { |
foreach (array_keys($this->_props) as $prop_name) { |
| if (! empty($this->_props[$prop_name]['table'])) { |
if (isset($this->_props[$prop_name]['value'])) { |
| |
|
| $sep = ($keys == '' ? '' : ', '); |
if (! empty($this->_props[$prop_name]['table'])) { |
| |
$id = $this->_getID( |
| |
$this->_props[$prop_name]['table'], |
| |
$this->_props[$prop_name]['value']); |
| |
|
| $this->_props[$prop_name]['id'] = $this->_get_id( |
if (intval($id)) |
| $this->_props[$prop_name]['table'], |
$this->_props[$prop_name]['id'] = $id; |
| $this->_props[$prop_name]['value']); |
} |
| |
else { |
| echo "Returned: " . $this->_props[$prop_name]['id'] . "<br>"; |
$this->_props[$prop_name]['id'] = |
| |
$this->_props[$prop_name]['value']; |
| |
} |
| |
} |
| |
} |
| |
|
| |
/* |
| |
* Session property. It is counted according to other IDs, |
| |
* so it must be after loop above. |
| |
*/ |
| |
|
| |
if (! $this->_props['session']['disabled']) { |
| |
$session_id = $this->_getSessionID(); |
| |
|
| |
if (intval($session_id)) |
| |
$this->_props['session']['id'] = |
| |
$this->_props['session']['value'] = |
| |
$session_id; |
| |
} |
| |
|
| |
/* |
| |
* Datetime property. It doesn't contain real value, |
| |
* but SQL clausule for getting datetime. |
| |
* |
| |
* TODO: make it database independent |
| |
*/ |
| |
|
| |
if (! $this->_props['datetime']['disabled']) |
| |
$this->_props['datetime']['id'] = |
| |
$this->_props['datetime']['value'] = |
| |
'sysdate()'; |
| |
|
| |
$keys = ''; |
| |
$vals = ''; |
| |
|
| |
foreach (array_keys($this->_props) as $prop_name) { |
| |
$sep = ($keys == '' ? '' : ', '); |
| |
|
| |
if ($this->_props[$prop_name]['id']) { |
| $keys .= $sep . $this->_props[$prop_name]['column']; |
$keys .= $sep . $this->_props[$prop_name]['column']; |
| $vals .= $sep . ($this->_props[$prop_name]['id'] |
$vals .= $sep . $this->_props[$prop_name]['id']; |
| ? "'".$this->_props[$prop_name]['id']."'" |
|
| : "NULL"); |
|
| } |
} |
| } |
} |
| |
|
| $this->_props['session']['value'] = $this->_get_session_id(); |
$query = "insert into weblog_accesses ($keys) values ($vals)"; |
| $keys .= ($keys == '' ? '' : ', ') . $this->_props['session']['column']; |
|
| $vals .= ($vals == '' ? '' : ', ') . $this->_props['session']['value']; |
|
| |
|
| $query = "insert into weblog_accesses" |
|
| . " ( datetime, $keys ) values ( sysdate(), $vals )"; |
|
| |
|
| print "<hr>$query<br>\n"; |
print "<hr>$query<br>\n"; |
| |
|
| Riadok 452 class Web_Log { |
|
| Riadok 574 class Web_Log { |
|
| } |
} |
| |
|
| /* |
/* |
| * _get_id() |
* _getID() |
| * |
* |
| * Return ID of $value in $table. |
* Return ID of $value in $table. |
| * If $value is not in table, record will be inserted and ID returned. |
* If $value is not in table, record will be inserted and ID returned. |
| */ |
*/ |
| |
|
| function _get_id($table, $value) { |
function _getID($table, $value) |
| |
{ |
| echo "<hr>_get_id() entered: $table, $value<br>"; |
|
| |
|
| /* |
/* |
| |
* OBSOLETE: $table and $value are now always set on _getID() call |
| |
* |
| * If you want to have 0 or "" in you database as valid values, |
* If you want to have 0 or "" in you database as valid values, |
| * uncomment this and comment the next line. Otherwise 0 and "" values |
* uncomment this and comment the next line. Otherwise 0 and "" values |
| * will be counted as NULL. |
* will be counted as NULL. |
| Riadok 472 class Web_Log { |
|
| Riadok 595 class Web_Log { |
|
| if (! $value || ! $table) |
if (! $value || ! $table) |
| return 0; |
return 0; |
| |
|
| $this->_check_db(); |
$this->_checkDB(); |
| |
|
| $query = "select id from $table" |
$query = "select id from $table" |
| ." where value = substring('" . addslashes($value) . "', 1, 255)" |
." where value = substring('" . addslashes($value) . "', 1, 255)" |
| ." limit 1"; // TODO: MySQL dependent |
." limit 1"; // TODO: 'limit' seems to be MySQL dependent, or no? |
| echo "$query<br>"; |
|
| |
|
| $id = $this->_db->getOne($query); |
$id = $this->_db->getOne($query); |
| |
|
| if (DB::isError($id)) |
if (DB::isError($id)) |
| Riadok 497 class Web_Log { |
|
| Riadok 618 class Web_Log { |
|
| |
|
| $query = "insert into $table (id, value)" |
$query = "insert into $table (id, value)" |
| ." values (0, '" . addslashes($value) . "')"; |
." values (0, '" . addslashes($value) . "')"; |
| echo "$query<br>"; |
|
| $result = $this->_db->query($query); |
$result = $this->_db->query($query); |
| |
|
| if (DB::isError($result)) |
if (DB::isError($result)) |
| $this->_error($result->getMessage()); |
$this->_error($result->getMessage()); |
| |
|
| $query = "select last_insert_id()"; // TODO: MySQL dependent |
$query = "select last_insert_id()"; // TODO: lst_insert_id() is MySQL dependent? |
| echo "$query<br>"; |
|
| |
|
| $id = $this->_db->getOne($query); |
$id = $this->_db->getOne($query); |
| |
|
| if (DB::isError($id)) |
if (DB::isError($id)) |
| Riadok 518 class Web_Log { |
|
| Riadok 636 class Web_Log { |
|
| } |
} |
| |
|
| /* |
/* |
| * _get_session_id() |
* _getSessionID() |
| * |
* |
| * Returns session_id according to session variables of object. Session |
* Returns session_id according to session variables of object. Session |
| * variables are $_session_timeout and $_session_keys. |
* variables are $_session_timeout and $_session_keys. |
| */ |
*/ |
| function _get_session_id() { |
function _getSessionID() |
| |
{ |
| |
|
| $this->_check_db(); |
$this->_checkDB(); |
| |
|
| $where = ''; |
$where = ''; |
| foreach ($this->_session_keys as $session_key) { |
foreach ($this->_session_keys as $session_key) { |
| Riadok 545 class Web_Log { |
|
| Riadok 664 class Web_Log { |
|
| ." $where" |
." $where" |
| ." order by datetime desc" |
." order by datetime desc" |
| ." limit 1"; |
." limit 1"; |
| |
|
| echo "<hr>Session query: $query<br>"; |
|
| |
|
| $row = $this->_db->getRow($query); |
$row = $this->_db->getRow($query); |
| |
|
| if (DB::isError($row)) |
if (DB::isError($row)) |
| Riadok 562 class Web_Log { |
|
| Riadok 678 class Web_Log { |
|
| |
|
| $query = "select max(session_id) + 1 as new_session_id" |
$query = "select max(session_id) + 1 as new_session_id" |
| ." from weblog_accesses"; |
." from weblog_accesses"; |
| |
|
| $id = $this->_db->getOne($query); |
$id = $this->_db->getOne($query); |
| |
|
| if (DB::isError($id)) |
if (DB::isError($id)) |
| Riadok 575 class Web_Log { |
|
| Riadok 690 class Web_Log { |
|
| } |
} |
| |
|
| /* |
/* |
| * get_sessions_count() |
* getSessionsCount() |
| * |
* |
| */ |
*/ |
| function get_sessions_count($array = '') { |
function getSessionsCount($array = '') |
| |
{ |
| |
|
| $this->_check_db(); |
$this->_checkDB(); |
| |
|
| $list_tables = ''; |
$list_tables = ''; |
| $list_where = ''; |
$list_where = ''; |
| |
|
| if (is_array($array)) { |
if (is_array($array)) { |
| |
|
| $count = 0; |
|
| foreach ($array as $key => $val) { |
foreach ($array as $key => $val) { |
| $count++; |
|
| |
|
| if (isset($this->_props[$key]['table'])) { |
if (isset($this->_props[$key]['table'])) { |
| $list_where .= ($list_where == '' ? '' : ' and '); |
$list_where .= ($list_where == '' ? '' : ' and '); |
| Riadok 618 class Web_Log { |
|
| Riadok 732 class Web_Log { |
|
| if (strlen($list_where) > 0) |
if (strlen($list_where) > 0) |
| $query .= " where $list_where"; |
$query .= " where $list_where"; |
| |
|
| echo "<p>$query<hr>"; |
|
| //$result = @mysql_query($query, $this->_db) or _db_error(); |
|
| |
|
| $count = $this->_db->getOne($query); |
$count = $this->_db->getOne($query); |
| |
|
| if (DB::isError($count)) |
if (DB::isError($count)) |