| verzia 1.27, 2002/03/31 20:52:42 |
verzia 1.28, 2002/04/03 20:33:26 |
|
|
| * - support for resolving hostnames from IP address fields |
* - support for resolving hostnames from IP address fields |
| * containing commas |
* containing commas |
| * - truncating hostnames and IP addresses implementation |
* - truncating hostnames and IP addresses implementation |
| |
* 03/04/2002 - standartized SQL queries |
| |
* - striping slashes from HTTP headers |
| |
* - using appropriate PEAR DB function for slashes adding |
| */ |
*/ |
| |
|
| define('WEB_LOG_VALUE_SUBSTR_LENGTH', 255); |
define('WEB_LOG_VALUE_SUBSTR_LENGTH', 255); |
| Riadok 513 class Web_Log { |
|
| Riadok 516 class Web_Log { |
|
| if (! isset($this->_db)) { |
if (! isset($this->_db)) { |
| $this->_db = DB::connect($this->_dsn); |
$this->_db = DB::connect($this->_dsn); |
| |
|
| if (DB::isError($this->_db)) { |
if (DB::isError($this->_db)) |
| return $this->_db; |
return false; |
| //$this->_error($this->_db->getMessage()); |
|
| } |
|
| |
|
| $this->_db->setFetchMode(DB_FETCHMODE_ASSOC); |
$this->_db->setFetchMode(DB_FETCHMODE_ASSOC); |
| } |
} |
| |
|
| |
return true; |
| } |
} |
| |
|
| /* |
/* |
| Riadok 538 class Web_Log { |
|
| Riadok 541 class Web_Log { |
|
| $addr_idx--; |
$addr_idx--; |
| $addr_ar[$addr_idx] = trim($addr_ar[$addr_idx]); |
$addr_ar[$addr_idx] = trim($addr_ar[$addr_idx]); |
| |
|
| if (preg_match("/^(\d{1,3}\.){3}\d{1,3}$/", $addr_ar[$addr_idx])) { |
if (preg_match('/^(\d{1,3}\.){3}\d{1,3}$/', $addr_ar[$addr_idx])) { |
| $host = @gethostbyaddr($addr_ar[$addr_idx]); |
$host = @gethostbyaddr($addr_ar[$addr_idx]); |
| if (! strcmp($host, $addr_ar[$addr_idx])) |
if (! strcmp($host, $addr_ar[$addr_idx])) |
| $host = ''; |
$host = ''; |
| Riadok 581 class Web_Log { |
|
| Riadok 584 class Web_Log { |
|
| |
|
| function registerAccess($value = 0) |
function registerAccess($value = 0) |
| { |
{ |
| $this->_checkDB(); |
if ($this->_checkDB() == false) |
| |
return $this->_db; |
| |
|
| global $HTTP_SERVER_VARS; |
global $HTTP_SERVER_VARS; |
| global $HTTP_ENV_VARS; |
global $HTTP_ENV_VARS; |
| Riadok 596 class Web_Log { |
|
| Riadok 600 class Web_Log { |
|
| continue; |
continue; |
| |
|
| if (! empty($this->_props[$prop_name]['var'])) { |
if (! empty($this->_props[$prop_name]['var'])) { |
| $this->_props[$prop_name]['value'] = |
$this->_props[$prop_name]['value'] = stripslashes( |
| $this->_props[$prop_name]['var'][0] == '$' |
$this->_props[$prop_name]['var'][0] == '$' |
| ? eval('return' |
? eval('return' |
| . ' (isset('.$this->_props[$prop_name]['var'].')' |
. ' (isset('.$this->_props[$prop_name]['var'].')' |
| . ' ? '.$this->_props[$prop_name]['var'].' : false);') |
. ' ? '.$this->_props[$prop_name]['var'].' : false);') |
| : getenv($this->_props[$prop_name]['var']); |
: getenv($this->_props[$prop_name]['var'])); |
| } |
} |
| } |
} |
| |
|
| Riadok 615 class Web_Log { |
|
| Riadok 619 class Web_Log { |
|
| $proxy_host = ''; |
$proxy_host = ''; |
| |
|
| if (! empty($HTTP_SERVER_VARS["HTTP_X_FORWARDED_FOR"])) { |
if (! empty($HTTP_SERVER_VARS["HTTP_X_FORWARDED_FOR"])) { |
| $remote_addr = $HTTP_SERVER_VARS["HTTP_X_FORWARDED_FOR"]; |
$remote_addr = stripslashes($HTTP_SERVER_VARS["HTTP_X_FORWARDED_FOR"]); |
| $proxy_addr = $HTTP_SERVER_VARS["REMOTE_ADDR"]; |
$proxy_addr = stripslashes($HTTP_SERVER_VARS["REMOTE_ADDR"]); |
| } |
} |
| else { |
else { |
| $remote_addr = $HTTP_SERVER_VARS["REMOTE_ADDR"]; |
$remote_addr = stripslashes($HTTP_SERVER_VARS["REMOTE_ADDR"]); |
| } |
} |
| |
|
| /* REMOVE ME */ |
/* REMOVE ME */ |
| Riadok 640 class Web_Log { |
|
| Riadok 644 class Web_Log { |
|
| */ |
*/ |
| |
|
| if (! $this->_props['remote_host']['disabled']) { |
if (! $this->_props['remote_host']['disabled']) { |
| if (empty($HTTP_SERVER_VARS["REMOTE_HOST"])) { |
$remote_host = empty($HTTP_SERVER_VARS["REMOTE_HOST"]) |
| $remote_host = $this->_resolveIP($remote_addr); |
? $this->_resolveIP($remote_addr) |
| $remote_host = 'neptun.kofola.xxx.sk'; |
: stripslashes($HTTP_SERVER_VARS["REMOTE_HOST"]); |
| $this->_props['remote_host']['value'] = $this->_truncate_names |
|
| ? $this->_truncateName($remote_host) |
$this->_props['remote_host']['value'] = $this->_truncate_names |
| : $remote_host; |
? $this->_truncateName($remote_host) |
| } |
: $remote_host; |
| else { |
|
| $this->_props['remote_host']['value'] = $this->_truncate_names |
|
| ? $this->_truncateName($HTTP_SERVER_VARS["REMOTE_HOST"]) |
|
| : $HTTP_SERVER_VARS["REMOTE_HOST"]; |
|
| } |
|
| } |
} |
| |
|
| if ($proxy_addr) { |
if ($proxy_addr) { |
| Riadok 671 class Web_Log { |
|
| Riadok 670 class Web_Log { |
|
| || ! $this->_props['ident_username']['disabled']) { |
|| ! $this->_props['ident_username']['disabled']) { |
| |
|
| $ident = new Net_Ident($remote_addr, |
$ident = new Net_Ident($remote_addr, |
| $HTTP_SERVER_VARS["REMOTE_PORT"], |
stripslashes($HTTP_SERVER_VARS["REMOTE_PORT"]), |
| $HTTP_SERVER_VARS["SERVER_PORT"]); |
stripslashes($HTTP_SERVER_VARS["SERVER_PORT"])); |
| |
|
| if ($ident->status() == 1) { |
if ($ident->status() == 1) { |
| // print "Ident query failed: " . $ident->error() . ".<br>\n"; |
// print "Ident query failed: " . $ident->error() . ".<br>\n"; |
| Riadok 746 class Web_Log { |
|
| Riadok 745 class Web_Log { |
|
| if (! $this->_props['datetime']['disabled']) |
if (! $this->_props['datetime']['disabled']) |
| $this->_props['datetime']['id'] = |
$this->_props['datetime']['id'] = |
| $this->_props['datetime']['value'] = |
$this->_props['datetime']['value'] = |
| 'sysdate()'; |
'SYSDATE()'; |
| |
|
| $keys = ''; |
$keys = ''; |
| $vals = ''; |
$vals = ''; |
| Riadok 759 class Web_Log { |
|
| Riadok 758 class Web_Log { |
|
| if ($this->_raw_log) { |
if ($this->_raw_log) { |
| if (isset($this->_props[$prop_name]['value']) |
if (isset($this->_props[$prop_name]['value']) |
| && ! empty($this->_props[$prop_name]['value'])) { |
&& ! empty($this->_props[$prop_name]['value'])) { |
| $val = addslashes($this->_props[$prop_name]['value']); |
if (! empty($this->_props[$prop_name]['table'])) { |
| if (! empty($this->_props[$prop_name]['table'])) |
$val = $this->_props[$prop_name]['value']; |
| $val = "'" . addslashes(substr($val, 0, |
$val = substr($val, 0, WEB_LOG_VALUE_SUBSTR_LENGTH); |
| WEB_LOG_VALUE_SUBSTR_LENGTH)) . "'"; |
$val = $this->_db->quoteString($val); |
| |
$val = "'$val'"; |
| |
} |
| |
else { |
| |
$val = $this->_props[$prop_name]['value']; |
| |
} |
| } |
} |
| else { |
else { |
| $val = 0; |
$val = 0; |
| Riadok 785 class Web_Log { |
|
| Riadok 789 class Web_Log { |
|
| } |
} |
| |
|
| $accesses_table = $this->_raw_log |
$accesses_table = $this->_raw_log |
| ? "weblog_accesses_raw" |
? 'weblog_accesses_raw' |
| : "weblog_accesses"; |
: 'weblog_accesses'; |
| |
|
| $query = "insert into $accesses_table ($keys) values ($vals)"; |
$query = "INSERT INTO $accesses_table ($keys) VALUES ($vals)"; |
| |
|
| //print "<hr>$query<br>\n"; |
//print "<hr>$query<br>\n"; |
| |
|
| $result = $this->_db->query($query); |
if (DB::isError($result = $this->_db->query($query))) { |
| |
|
| if (DB::isError($result)) { |
|
| return $result; |
return $result; |
| //$this->_error($result->getMessage()); |
//$this->_error($result->getMessage()); |
| } |
} |
| Riadok 814 class Web_Log { |
|
| Riadok 816 class Web_Log { |
|
| |
|
| function _getID($table, $value) |
function _getID($table, $value) |
| { |
{ |
| $this->_checkDB(); |
if ($this->_checkDB() == false) |
| |
return $this->_db; |
| |
|
| for ($i = 0; $i < 2; $i++) { |
for ($i = 0; $i < 2; $i++) { |
| $query = "select id from $table" |
|
| ." where value = '" |
|
| . addslashes(substr($value, 0, WEB_LOG_VALUE_SUBSTR_LENGTH)) |
|
| ."' limit 1"; // TODO: 'limit' is MySQL dependent, or no? |
|
| $id = $this->_db->getOne($query); |
|
| |
|
| if (DB::isError($id)) { |
// TODO: LIMIT is MySQL dependent? Yes it is! |
| |
// use appropriate PEAR DB method |
| |
$query = sprintf('SELECT id FROM %s' |
| |
.' WHERE value = "%s"' |
| |
.' LIMIT 1', |
| |
$table, $this->_db->quoteString( |
| |
substr($value, 0, WEB_LOG_VALUE_SUBSTR_LENGTH))); |
| |
|
| |
if (DB::isError($id = $this->_db->getOne($query))) |
| return $id; |
return $id; |
| //$this->_error($id->getMessage()); |
|
| } |
|
| |
|
| if ($id) |
if ($id) |
| return $id; |
return $id; |
| Riadok 839 class Web_Log { |
|
| Riadok 843 class Web_Log { |
|
| appropriate record into table. And our insert will fail. |
appropriate record into table. And our insert will fail. |
| */ |
*/ |
| |
|
| $query = "insert into $table (id, value)" |
$query = sprintf('INSERT INTO %s (id, value) VALUES (0, "%s")', |
| ." values (0, '" . addslashes($value) . "')"; |
$table, $this->_db->quoteString($value)); |
| |
|
| if ($i == 0) { |
if ($i == 0) { |
| $this->_db->expectError(DB_ERROR_ALREADY_EXISTS); |
$this->_db->expectError(DB_ERROR_ALREADY_EXISTS); |
| Riadok 865 class Web_Log { |
|
| Riadok 869 class Web_Log { |
|
| } |
} |
| else { |
else { |
| return $result; |
return $result; |
| //$this->_error($result->getMessage()); |
|
| } |
} |
| } |
} |
| else { |
else { |
| Riadok 874 class Web_Log { |
|
| Riadok 877 class Web_Log { |
|
| } |
} |
| } |
} |
| |
|
| // TODO: last_insert_id() is MySQL dependent? |
// TODO: LAST_INSERT_ID() is MySQL dependent? Yes it is! |
| $query = "select last_insert_id()"; |
// use appropriate PEAR DB method |
| $id = $this->_db->getOne($query); |
$query = 'SELECT LAST_INSERT_ID()'; |
| |
if (DB::isError($id = $this->_db->getOne($query))) |
| if (DB::isError($id)) { |
|
| return $id; |
return $id; |
| //$this->_error($id->getMessage()); |
|
| } |
|
| |
|
| if ($id) |
if ($id) |
| return $id; |
return $id; |
| Riadok 897 class Web_Log { |
|
| Riadok 897 class Web_Log { |
|
| */ |
*/ |
| function _getSessionID() |
function _getSessionID() |
| { |
{ |
| $this->_checkDB(); |
if ($this->_checkDB() == false) |
| |
return $this->_db; |
| |
|
| $where = ''; |
$where = ''; |
| foreach ($this->_session_keys as $session_key) { |
foreach ($this->_session_keys as $session_key) { |
| if (isset($this->_props[$session_key])) { |
if (isset($this->_props[$session_key])) { |
| $where .= ($where == '' ? "where " : " and "); |
$where .= ($where == '' ? "WHERE " : " AND "); |
| |
|
| $where .= $this->_props[$session_key]['column']; |
$where .= $this->_props[$session_key]['column']; |
| $where .= $this->_raw_log |
$where .= $this->_raw_log |
| ? (isset($this->_props[$session_key]['value']) |
? (isset($this->_props[$session_key]['value']) |
| ? " = '" . addslashes(substr( |
? " = '" . $this->_db->quoteString(substr( |
| $this->_props[$session_key]['value'], |
$this->_props[$session_key]['value'], |
| 0, WEB_LOG_VALUE_SUBSTR_LENGTH)) . "'" |
0, WEB_LOG_VALUE_SUBSTR_LENGTH)) . "'" |
| : ' is NULL') |
: ' is NULL') |
| Riadok 918 class Web_Log { |
|
| Riadok 919 class Web_Log { |
|
| } |
} |
| |
|
| $accesses_table = $this->_raw_log |
$accesses_table = $this->_raw_log |
| ? "weblog_accesses_raw" |
? 'weblog_accesses_raw' |
| : "weblog_accesses"; |
: 'weblog_accesses'; |
| |
|
| $query = "select" |
$query = 'SELECT id, session_id,' |
| ." id, session_id," |
.' UNIX_TIMESTAMP(SYSDATE()) - UNIX_TIMESTAMP(datetime) AS diff_sec' |
| ." unix_timestamp(sysdate()) - unix_timestamp(datetime) as diff_sec" |
.' FROM ' . "$accesses_table $where" |
| ." from $accesses_table" |
.' ORDER BY datetime DESC' |
| ." $where" |
.' LIMIT 1'; |
| ." order by datetime desc" |
|
| ." limit 1"; |
|
| $row = $this->_db->getRow($query); |
|
| |
|
| if (DB::isError($row)) { |
if (DB::isError($row = $this->_db->getRow($query))) |
| return $row; |
return $row; |
| //$this->_error($row->getMessage()); |
|
| } |
|
| |
|
| if (is_array($row) |
if (is_array($row) |
| && ($row['diff_sec'] < $this->_session_timeout) |
&& ($row['diff_sec'] < $this->_session_timeout) |
| Riadok 952 class Web_Log { |
|
| Riadok 948 class Web_Log { |
|
| foreach (($this->_raw_log |
foreach (($this->_raw_log |
| ? array('weblog_accesses_raw', 'weblog_accesses') |
? array('weblog_accesses_raw', 'weblog_accesses') |
| : array('weblog_accesses')) as $table) { |
: array('weblog_accesses')) as $table) { |
| $query = "select max(session_id) + 1 as new_session_id" |
|
| ." from $table"; |
|
| $id = $this->_db->getOne($query); |
|
| |
|
| if (DB::isError($id)) { |
$query = 'SELECT MAX(session_id) + 1 AS new_session_id' |
| |
.' FROM ' . $table; |
| |
|
| |
if (DB::isError($id = $this->_db->getOne($query))) |
| return $id; |
return $id; |
| //$this->_error($id->getMessage()); |
|
| } |
|
| |
|
| if ($id) |
if ($id) |
| return $id; |
return $id; |
| Riadok 977 class Web_Log { |
|
| Riadok 971 class Web_Log { |
|
| |
|
| function getSessionsCount($array = '') |
function getSessionsCount($array = '') |
| { |
{ |
| $this->_checkDB(); |
if ($this->_checkDB() == false) |
| |
return $this->_db; |
| |
|
| $accesses_table = $this->_raw_log |
$accesses_table = $this->_raw_log |
| ? "weblog_accesses_raw" |
? 'weblog_accesses_raw' |
| : "weblog_accesses"; |
: 'weblog_accesses'; |
| |
|
| $list_tables = ''; |
$list_tables = ''; |
| $list_where = ''; |
$list_where = ''; |
| Riadok 1007 class Web_Log { |
|
| Riadok 1002 class Web_Log { |
|
| } |
} |
| } |
} |
| |
|
| $query = "select" |
$query = 'SELECT COUNT(DISTINCT session_id) AS sessions_count' |
| ." count(distinct session_id) as sessions_count" |
.' FROM ' . $accesses_table; |
| ." from $accesses_table"; |
|
| |
|
| if (strlen($list_tables) > 0) |
if (strlen($list_tables) > 0) |
| $query .= ", $list_tables"; |
$query .= ", $list_tables"; |
| |
|
| if (strlen($list_where) > 0) |
if (strlen($list_where) > 0) |
| $query .= " where $list_where"; |
$query .= " WHERE $list_where"; |
| |
|
| $count = $this->_db->getOne($query); |
if (DB::isError($count = $this->_db->getOne($query))) |
| |
|
| if (DB::isError($count)) { |
|
| return $count; |
return $count; |
| //$this->_error($count->getMessage()); |
|
| } |
|
| |
|
| if (isset($count)) |
if (isset($count)) |
| return $count; |
return $count; |
| Riadok 1047 class Web_Log { |
|
| Riadok 1037 class Web_Log { |
|
| return $this->_cache_active_sessions; |
return $this->_cache_active_sessions; |
| } |
} |
| |
|
| $this->_checkDB(); |
if ($this->_checkDB() == false) |
| |
return $this->_db; |
| |
|
| $accesses_table = $this->_raw_log |
$accesses_table = $this->_raw_log |
| ? "weblog_accesses_raw" |
? 'weblog_accesses_raw' |
| : "weblog_accesses"; |
: 'weblog_accesses'; |
| |
|
| $query = "select" |
$query = 'SELECT session_id' |
| ." session_id" |
.' FROM ' . $accesses_table |
| ." from $accesses_table" |
.' GROUP BY session_id' |
| ." group by session_id" |
.' HAVING UNIX_TIMESTAMP(SYSDATE())' |
| ." having unix_timestamp(sysdate())" |
.' - UNIX_TIMESTAMP(MAX(datetime)) < ' . $this->_session_timeout; |
| ." - unix_timestamp(max(datetime)) < " . $this->_session_timeout; |
|
| |
|
| $active_sessions = $this->_db->getCol($query); |
$active_sessions = $this->_db->getCol($query); |
| |
|