| verzia 1.12, 2001/12/18 16:15:45 |
verzia 1.13, 2002/01/13 01:36:39 |
|
|
| * __________________________________________________________ |
* __________________________________________________________ |
| * |
* |
| * Developed by Ondrej Jombik <nepto@pobox.sk> |
* Developed by Ondrej Jombik <nepto@pobox.sk> |
| * Copyright (c) 2001 Platon software development group |
* Copyright (c) 2001-2002 Platon software development group |
| * All rights reserved. |
* All rights reserved. |
| * |
* |
| * See README file for more informations about this software. |
* See README file for more informations about this software. |
|
|
| * 19/11/2001 - session_id column added |
* 19/11/2001 - session_id column added |
| * - sessions implemented |
* - sessions implemented |
| * - various bugfixes and SQL improvements |
* - various bugfixes and SQL improvements |
| |
* 13/01/2002 - PEAR compliancy |
| */ |
*/ |
| |
|
| /* |
/* |
| * Before doing anything else read config file. |
* Before doing anything else read config file. |
| */ |
*/ |
| include("config.inc.php"); |
//include("config.inc.php"); |
| |
|
| /* |
/* |
| * Ident library |
* Ident library |
| */ |
*/ |
| include_once("libident/libident.php"); |
include_once("libident/libident.php"); |
| |
|
| class Web_Log { |
/* |
| |
* Pear DB library |
| var $_session_timeout; |
*/ |
| |
include_once("DB.php"); |
| var $_db_handle; |
|
| var $_db; |
|
| |
|
| function Web_Log() |
|
| { |
|
| $this->_session_timeout = 30 * 60; |
|
| |
|
| unset($this->_db_handle); |
|
| unset($this->_db); |
|
| } |
|
| |
|
| function set_session_timeout($timeout) |
class Web_Log { |
| { |
|
| $this->_session_timeout = $timeout; |
|
| } |
|
| |
|
| function set_db($host = "", $port = "", |
/* Session variables |
| $username = "", $password = "", $name = "") |
|
| { |
|
| if ($host != "") |
|
| $this->_db['host'] = $host; |
|
| |
|
| if ($port != 0) |
$_session_timeout - maximum delay between two click from the same site |
| $this->_db['host'] = $host; |
with the same user agent to count it as one session |
| |
$_session_keys - keys of properties (keys to $_props array) defined |
| |
session; for each session all values of particular key |
| |
are the same |
| |
*/ |
| |
var $_session_timeout; |
| |
var $_session_keys = array('remote_addr', 'http_user_agent'); |
| |
|
| if ($username != "") |
/* Database variables |
| $this->_db['username'] = $username; |
|
| |
|
| if ($password != "") |
$_db - PEAR DB object |
| $this->_db['password'] = $password; |
$_dsn - database connection URI (db_type://user:pass@host/db_name) |
| |
*/ |
| |
var $_db; |
| |
var $_dsn; |
| |
|
| if ($name != "") |
/* $_props - properties array |
| $this->_db['name'] = $name; |
|
| } |
|
| |
|
| function set_db_handle($db_handle) |
keys: identifiers (when user is specifing some property for some |
| { |
special action (ingnore property or add property to list |
| $this->_db_handle = $db_handle; |
of session definers), it is provided via this identifiers) |
| } |
|
| |
values: arrays; keys of each array are described below |
| |
|
| |
key description |
| |
------ ----------- |
| |
column column name in main accesses table |
| |
table table name for values storing (in accesses table will be only |
| |
ID to this table stored) |
| |
var how to get property value; if starts with '$' character, than |
| |
it is eval()-ed, if not, than is string passed to getenv() |
| |
function to obtain value |
| |
value value of property |
| |
id id of property; defined only if value is stored in its own |
| |
separate table |
| |
*/ |
| |
var $_props = array( |
| |
'id' => array( |
| |
'column' => 'id', |
| |
'table' => '', |
| |
'var' => '' ), |
| |
'datetime' => array( |
| |
'column' => 'datetime', |
| |
'table' => '', |
| |
'var' => '' ), |
| |
'value' => array( |
| |
'column' => 'value_id', |
| |
'table' => 'weblog_values', |
| |
'var' => '' ), |
| |
'request_method' => array( |
| |
'column' => 'request_method_id', |
| |
'table' => 'weblog_request_methods', |
| |
'var' => '$HTTP_SERVER_VARS["REQUEST_METHOD"]' ), |
| |
'query_string' => array( |
| |
'column' => 'query_string_id', |
| |
'table' => 'weblog_query_strings', |
| |
'var' => '$HTTP_SERVER_VARS["QUERY_STRING"]' ), |
| |
'path_info' => array( |
| |
'column' => 'path_info_id', |
| |
'table' => 'weblog_path_infos', |
| |
'var' => 'PATH_INFO' ), |
| |
'path_translated' => array( |
| |
'column' => 'path_translated_id', |
| |
'table' => 'weblog_paths_translated', |
| |
'var' => '$HTTP_SERVER_VARS["PATH_TRANSLATED"]' ), |
| |
'content_type' => array( |
| |
'column' => 'content_type_id', |
| |
'table' => 'weblog_content_types', |
| |
'var' => '$HTTP_SERVER_VARS["CONTENT_TYPE"]' ), |
| |
'content_length' => array( |
| |
'column' => 'content_length', |
| |
'table' => '', |
| |
'var' => '$HTTP_SERVER_VARS["CONTENT_LENGTH"]' ), |
| |
'script_name' => array( |
| |
'column' => 'script_name_id', |
| |
'table' => 'weblog_script_names', |
| |
'var' => '$HTTP_SERVER_VARS["SCRIPT_NAME"]' ), |
| |
'server_name' => array( |
| |
'column' => 'server_name_id', |
| |
'table' => 'weblog_server_names', |
| |
'var' => '$HTTP_SERVER_VARS["SERVER_NAME"]' ), |
| |
'server_port' => array( |
| |
'column' => 'server_port', |
| |
'table' => '', |
| |
'var' => '$HTTP_SERVER_VARS["SERVER_PORT"]' ), |
| |
'server_software' => array( |
| |
'column' => 'server_software_id', |
| |
'table' => 'weblog_server_softwares', |
| |
'var' => '$HTTP_SERVER_VARS["SERVER_SOFTWARE"]' ), |
| |
'server_protocol' => array( |
| |
'column' => 'server_protocol_id', |
| |
'table' => 'weblog_server_protocols', |
| |
'var' => '$HTTP_SERVER_VARS["SERVER_PROTOCOL"]' ), |
| |
'gateway_interface' => array( |
| |
'column' => 'gateway_interface_id', |
| |
'table' => 'weblog_gateway_interfaces', |
| |
'var' => '$HTTP_SERVER_VARS["GATEWAY_INTERFACE"]' ), |
| |
'proxy_addr' => array( |
| |
'column' => 'proxy_addr_id', |
| |
'table' => 'weblog_remote_addrs', |
| |
'var' => '' ), |
| |
'proxy_host' => array( |
| |
'column' => 'proxy_host_id', |
| |
'table' => 'weblog_remote_hosts', |
| |
'var' => '' ), |
| |
'remote_addr' => array( |
| |
'column' => 'remote_addr_id', |
| |
'table' => 'weblog_remote_addrs', |
| |
'var' => '' ), |
| |
'remote_host' => array( |
| |
'column' => 'remote_host_id', |
| |
'table' => 'weblog_remote_hosts', |
| |
'var' => '' ), |
| |
'remote_port' => array( |
| |
'column' => 'remote_port', |
| |
'table' => '', |
| |
'var' => '$HTTP_SERVER_VARS["REMOTE_PORT"]' ), |
| |
'auth_type' => array( |
| |
'column' => 'auth_type_id', |
| |
'table' => 'weblog_auth_types', |
| |
'var' => 'AUTH_TYPE' ), |
| |
'remote_user' => array( |
| |
'column' => 'remote_user_id', |
| |
'table' => 'weblog_remote_users', |
| |
'var' => '$HTTP_SERVER_VARS["REMOTE_USER"]' ), |
| |
'remote_ident' => array( |
| |
'column' => 'remote_ident_id', |
| |
'table' => 'weblog_remote_idents', |
| |
'var' => '' ), |
| |
'document_root' => array( |
| |
'column' => 'document_root_id', |
| |
'table' => 'weblog_document_roots', |
| |
'var' => '$HTTP_SERVER_VARS["DOCUMENT_ROOT"]' ), |
| |
'http_accept' => array( |
| |
'column' => 'http_accept_id', |
| |
'table' => 'weblog_http_accepts', |
| |
'var' => '$HTTP_SERVER_VARS["HTTP_ACCEPT"]' ), |
| |
'http_accept_charset' => array( |
| |
'column' => 'http_accept_charset_id', |
| |
'table' => 'weblog_http_accept_charsets', |
| |
'var' => '$HTTP_SERVER_VARS["HTTP_ACCEPT_CHARSET"]' ), |
| |
'http_accept_encoding' => array( |
| |
'column' => 'http_accept_encoding_id', |
| |
'table' => 'weblog_http_accept_encodings', |
| |
'var' => '$HTTP_SERVER_VARS["HTTP_ACCEPT_ENCODING"]' ), |
| |
'http_accept_language' => array( |
| |
'column' => 'http_accept_language_id', |
| |
'table' => 'weblog_http_accept_languages', |
| |
'var' => '$HTTP_SERVER_VARS["HTTP_ACCEPT_LANGUAGE"]' ), |
| |
'http_connection' => array( |
| |
'column' => 'http_connection_id', |
| |
'table' => 'weblog_http_connections', |
| |
'var' => '$HTTP_SERVER_VARS["HTTP_CONNECTION"]' ), |
| |
'http_host' => array( |
| |
'column' => 'http_host_id', |
| |
'table' => 'weblog_http_hosts', |
| |
'var' => '$HTTP_SERVER_VARS["HTTP_HOST"]' ), |
| |
'http_referer' => array( |
| |
'column' => 'http_referer_id', |
| |
'table' => 'weblog_http_referers', |
| |
'var' => '$HTTP_SERVER_VARS["HTTP_REFERER"]' ), |
| |
'http_user_agent' => array( |
| |
'column' => 'http_user_agent_id', |
| |
'table' => 'weblog_http_user_agents', |
| |
'var' => '$HTTP_SERVER_VARS["HTTP_USER_AGENT"]' ), |
| |
'script_filename' => array( |
| |
'column' => 'script_filename_id', |
| |
'table' => 'weblog_script_filenames', |
| |
'var' => '$HTTP_SERVER_VARS["SCRIPT_FILENAME"]' ), |
| |
'server_admin' => array( |
| |
'column' => 'server_admin_id', |
| |
'table' => 'weblog_server_admins', |
| |
'var' => '$HTTP_SERVER_VARS["SERVER_ADMIN"]' ), |
| |
'server_signature' => array( |
| |
'column' => 'server_signature_id', |
| |
'table' => 'weblog_server_signatures', |
| |
'var' => '$HTTP_SERVER_VARS["SERVER_SIGNATURE"]' ), |
| |
'request_uri' => array( |
| |
'column' => 'request_uri_id', |
| |
'table' => 'weblog_request_uris', |
| |
'var' => '$HTTP_SERVER_VARS["REQUEST_URI"]' ), |
| |
'ident_username' => array( |
| |
'column' => 'ident_username_id', |
| |
'table' => 'weblog_ident_usernames', |
| |
'var' => '' ), |
| |
'ident_ostype' => array( |
| |
'column' => 'ident_ostype_id', |
| |
'table' => 'weblog_ident_ostypes', |
| |
'var' => '' ), |
| |
'session' => array( |
| |
'column' => 'session_id', |
| |
'table' => '', |
| |
'var' => '' ) |
| |
); |
| |
|
| /* |
/* |
| * open_db_connection() |
* Web_Log() |
| * |
* |
| * Opens database connection. |
* Object constructor. |
| */ |
*/ |
| function open_db_connections($host = "", $port = 0, |
function Web_Log($dsn = '') |
| $username = "", $password = "", $name = "") |
|
| { |
{ |
| $this->set_db($host, $port, $username, $password, $name); |
|
| |
|
| $this->_db_handle = @mysql_connect( |
$this->_session_timeout = 30 * 60; |
| $this->_db['host'] |
|
| . ($this->_db['port'] != 0 ? ":" . $this->_db['port'] : ""), |
|
| $this->_db['username'], |
|
| $this->_db['password']); |
|
| |
|
| if ($this->_db_handle == false) |
|
| return false; |
|
| |
|
| if (@mysql_select_db($this->_db['name'], $this->_db_handle) == false) |
unset($this->_db); |
| return false; |
unset($this->_dsn); |
| |
|
| return $this->_db_handle; |
if (! empty($dsn)) { |
| |
$this->set_dsn($dsn); |
| |
} |
| } |
} |
| |
|
| /* |
/* |
| * close_db_connection() |
* set_session_timeout() |
| * |
* |
| * Closes database connection. |
* Sets session timeout. Session timeout is a maximum delay between |
| |
* two click from the same site with the same user agent to count it |
| |
* as one session. |
| */ |
*/ |
| |
function set_session_timeout($timeout) |
| function close_db_connection() |
|
| { |
{ |
| $this->_db_handle = @mysql_close($this->_db_handle); |
$this->_session_timeout = $timeout; |
| return $this->_db_handle; // true if OK, false if failed |
|
| } |
} |
| |
|
| /* |
/* |
| * _check_db_handle() |
* set_dsn() |
| * |
* |
| * Check if database handle is still opened. |
* Sets DSN (db_type://user:pass@host/db_name) for database connection. |
| */ |
*/ |
| |
function set_dsn($dsn) |
| function _check_db_handle() { |
{ |
| if (! isset($this->_db_handle)) { |
$this->_dsn = $dsn; |
| $this->open_db_connection() |
|
| or _error("database server connection error"); |
|
| } |
|
| } |
} |
| |
|
| /* |
/* |
| * _db_error() |
* _error() |
| * |
* |
| * Database error handling function. |
* Error handling function. |
| */ |
*/ |
| |
function _error($message = "Unknown error") { |
| |
die ("<b>phpWebLogAnalyzer fatal failure</b>: " . $message |
| |
. "<br>Please contact webmaster or system administrator" |
| |
. " of this page with this problem.<br>"); |
| |
|
| function _db_error() { |
return false; |
| return _error("error during work with database server"); |
|
| } |
} |
| |
|
| /* |
/* |
| * _error() |
* _check_db() |
| * |
* |
| * Error handling function. |
* Checks if $this->_db is a valid PEAR DB object. If not it creates a new |
| |
* one using $this->_dsn variable. |
| */ |
*/ |
| |
function _check_db() |
| |
{ |
| |
if (! isset($this->_db)) { |
| |
$this->_db = DB::connect($this->_dsn); |
| |
} |
| |
|
| function _error($message = "Unknown error") { |
if (DB::isError($this->_db)) { |
| die ("<b> fatal failure</b>: " . $message |
$this->_error($this->_db->getMessage()); |
| . "<br>Please contact webmaster or system administrator" |
} |
| . " of this page with this problem.<br>"); |
|
| |
|
| return false; |
$this->_db->setFetchMode(DB_FETCHMODE_ASSOC); |
| } |
} |
| |
|
| /* |
/* |
| Riadok 167 class Web_Log { |
|
| Riadok 327 class Web_Log { |
|
| */ |
*/ |
| function register_access($value = 0) { |
function register_access($value = 0) { |
| |
|
| $this->_check_db_handle(); |
$this->_check_db(); |
| |
|
| global $REQUEST_METHOD; |
global $HTTP_SERVER_VARS; |
| global $QUERY_STRING; |
global $HTTP_ENV_VARS; |
| global $PATH_INFO; |
|
| global $PATH_TRANSLATED; |
/* |
| global $CONTENT_TYPE; |
* Process props[] values. |
| global $CONTENT_LENGTH; |
*/ |
| global $SCRIPT_NAME; |
|
| global $SERVER_NAME; |
echo "Path info: " .$HTTP_SERVER_VARS["PATH_TRANSLATED"]."<br>"; |
| global $SERVER_PORT; |
|
| global $SERVER_SOFTWARE; |
|
| global $SERVER_PROTOCOL; |
foreach (array_keys($this->_props) as $prop_name) { |
| global $SERVER_ADMIN; |
if (! empty($this->_props[$prop_name]['var'])) { |
| global $SERVER_SIGNATURE; |
$this->_props[$prop_name]['value'] = |
| global $GATEWAY_INTERFACE; |
$this->_props[$prop_name]['var'][0] == '$' |
| global $REMOTE_HOST; |
? eval('return '.$this->_props[$prop_name]['var'].';') |
| global $REMOTE_ADDR; |
: getenv($this->_props[$prop_name]['var']); |
| global $REMOTE_PORT; |
} |
| global $AUTH_TYPE; |
} |
| global $REMOTE_USER; |
|
| global $REMOTE_IDENT; |
|
| global $DOCUMENT_ROOT; |
|
| global $HTTP_ACCEPT; |
|
| global $HTTP_ACCEPT_CHARSET; |
|
| global $HTTP_ACCEPT_ENCODING; |
|
| global $HTTP_ACCEPT_LANGUAGE; |
|
| global $HTTP_CONNECTION; |
|
| global $HTTP_HOST; |
|
| global $HTTP_REFERER; |
|
| global $HTTP_USER_AGENT; |
|
| global $SCRIPT_FILENAME; |
|
| global $REQUEST_URI; |
|
| |
|
| $ip_addr = ''; |
|
| $hostname = ''; |
|
| $proxy_ip_addr = ''; |
|
| $proxy_hostname = ''; |
|
| $ident_user = ''; |
|
| $ident_ostype = ''; |
|
| |
|
| /* |
/* |
| * IP address & proxy server getting. |
* IP address & proxy server getting. |
| */ |
*/ |
| |
|
| if (getenv('HTTP_X_FORWARDED_FOR') != '') { |
$remote_addr = ''; |
| $ip_addr = getenv('HTTP_X_FORWARDED_FOR'); |
$remote_host = ''; |
| $proxy_ip_addr = getenv('REMOTE_ADDR'); |
$proxy_addr = ''; |
| |
$proxy_host = ''; |
| |
$ident_user = ''; |
| |
$ident_ostype = ''; |
| |
|
| |
|
| |
if (! empty($HTTP_SERVER_VARS["HTTP_X_FORWARDED_FOR"])) { |
| |
$remote_addr = $HTTP_SERVER_VARS["HTTP_X_FORWARDED_FOR"]; |
| |
$proxy_addr = $HTTP_SERVER_VARS["REMOTE_ADDR"]; |
| } |
} |
| else { |
else { |
| $ip_addr = getenv('REMOTE_ADDR'); |
$remote_addr = $HTTP_SERVER_VARS["REMOTE_ADDR"]; |
| } |
} |
| |
|
| /* |
/* |
| * Host name resolving. |
* Host names resolving. |
| */ |
*/ |
| |
|
| $hostname = @gethostbyaddr($ip_addr); |
$remote_host = @gethostbyaddr($remote_addr); |
| if (! strcmp($hostname, $ip_addr)) |
if (! strcmp($remote_host, $remote_addr)) |
| $hostname = ''; |
$remote_host = ''; |
| |
|
| if ($proxy_ip_addr) { |
if ($proxy_addr) { |
| $proxy_hostname = @gethostbyaddr($proxy_ip_addr); |
$proxy_host = @gethostbyaddr($proxy_addr); |
| if (! strcmp($proxy_hostname, $proxy_ip_addr)) |
if (! strcmp($proxy_host, $proxy_addr)) |
| $proxy_hostname = ''; |
$proxy_host = ''; |
| } |
} |
| |
|
| /* |
/* |
| * Ident protocol stuff |
* Ident protocol stuff |
| */ |
*/ |
| $ident = new Net_Ident($ip_addr, $REMOTE_PORT, $SERVER_PORT); |
|
| |
$ident = new Net_Ident( $remote_addr, |
| |
$HTTP_SERVER_VARS["REMOTE_PORT"], |
| |
$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 247 class Web_Log { |
|
| Riadok 398 class Web_Log { |
|
| $ident_ostype = $ident->osType(); |
$ident_ostype = $ident->osType(); |
| } |
} |
| |
|
| $record = array ( // * - not in PHP manual |
$this->_props['remote_addr']['value'] = $remote_addr; |
| |
$this->_props['remote_host']['value'] = $remote_host; |
| |
$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! |
| |
$this->_props['value']['value'] = $value; |
| |
|
| |
$keys = ''; |
| |
$vals = ''; |
| |
$count = 0; |
| |
|
| |
foreach (array_keys($this->_props) as $prop_name) { |
| |
if (! empty($this->_props[$prop_name]['table'])) { |
| |
|
| |
$sep = ($keys == '' ? '' : ', '); |
| |
|
| |
$this->_props[$prop_name]['id'] = $this->_get_id( |
| |
$this->_props[$prop_name]['table'], |
| |
$this->_props[$prop_name]['value']); |
| |
|
| |
echo "Returned: " . $this->_props[$prop_name]['id'] . "<br>"; |
| |
|
| |
$keys .= $sep . $this->_props[$prop_name]['column']; |
| |
$vals .= $sep . ($this->_props[$prop_name]['id'] |
| |
? "'".$this->_props[$prop_name]['id']."'" |
| |
: "NULL"); |
| |
} |
| |
} |
| |
|
| 'id' => 0, // 0 - auto_increment |
$this->_props['session']['value'] = $this->_get_session_id(); |
| 'value_id' => _get_id( |
$keys .= ($keys == '' ? '' : ', ') . $this->_props['session']['column']; |
| 'weblog_values', $value), |
$vals .= ($vals == '' ? '' : ', ') . $this->_props['session']['value']; |
| 'request_method_id' => _get_id( |
|
| 'weblog_request_methods', $REQUEST_METHOD), |
|
| 'query_string_id' => _get_id( |
|
| 'weblog_query_strings', $QUERY_STRING), |
|
| 'path_info_id' => _get_id( |
|
| 'weblog_path_infos', $PATH_INFO), // * |
|
| 'path_translated_id' => _get_id( |
|
| 'weblog_paths_translated', $PATH_TRANSLATED), |
|
| 'content_type_id' => _get_id( |
|
| 'weblog_content_types', $CONTENT_TYPE), // * |
|
| 'content_length' => $CONTENT_LENGTH, // * |
|
| 'script_name_id' => _get_id( |
|
| 'weblog_script_names', $SCRIPT_NAME), |
|
| 'server_name_id' => _get_id( |
|
| 'weblog_server_names', $SERVER_NAME), |
|
| 'server_port' => $SERVER_PORT, // * |
|
| 'server_software_id' => _get_id( |
|
| 'weblog_server_softwares', $SERVER_SOFTWARE), |
|
| 'server_protocol_id' => _get_id( |
|
| 'weblog_server_protocols', $SERVER_PROTOCOL), |
|
| 'server_admin_id' => _get_id( |
|
| 'weblog_server_admins', $SERVER_ADMIN), |
|
| 'server_signature_id' => _get_id( |
|
| 'weblog_server_signatures', $SERVER_SIGNATURE), |
|
| 'gateway_interface_id' => _get_id( |
|
| 'weblog_gateway_interfaces', $GATEWAY_INTERFACE), |
|
| 'remote_host_id' => _get_id( |
|
| 'weblog_remote_hosts', $hostname), // * |
|
| 'proxy_addr_id' => _get_id( |
|
| 'weblog_remote_addrs', $proxy_ip_addr), |
|
| 'proxy_host_id' => _get_id( |
|
| 'weblog_remote_hosts', $proxy_hostname), // * |
|
| 'remote_addr_id' => ($remote_addr_id = |
|
| _get_id( |
|
| 'weblog_remote_addrs', $ip_addr)), |
|
| 'remote_host_id' => _get_id( |
|
| 'weblog_remote_hosts', $hostname), // * |
|
| 'remote_port' => $REMOTE_PORT, |
|
| 'auth_type_id' => _get_id( |
|
| 'weblog_auth_types', $AUTH_TYPE), // * |
|
| 'remote_user_id' => _get_id( |
|
| 'weblog_remote_users', $REMOTE_USER), // * |
|
| 'remote_ident_id' => _get_id( |
|
| 'weblog_remote_idents', $REMOTE_IDENT), // * |
|
| 'document_root_id' => _get_id( |
|
| 'weblog_document_roots', $DOCUMENT_ROOT), |
|
| 'http_accept_id' => _get_id( |
|
| 'weblog_http_accepts', $HTTP_ACCEPT), |
|
| 'http_accept_charset_id' => _get_id( |
|
| 'weblog_http_accept_charsets', $HTTP_ACCEPT_CHARSET), |
|
| 'http_accept_encoding_id' => _get_id( |
|
| 'weblog_http_accept_encodings', $HTTP_ACCEPT_ENCODING), |
|
| 'http_accept_language_id' => _get_id( |
|
| 'weblog_http_accept_languages', $HTTP_ACCEPT_LANGUAGE), |
|
| 'http_connection_id' => _get_id( |
|
| 'weblog_http_connections', $HTTP_CONNECTION), |
|
| 'http_host_id' => _get_id( |
|
| 'weblog_http_hosts', $HTTP_HOST), |
|
| 'http_referer_id' => _get_id( |
|
| 'weblog_http_referers', $HTTP_REFERER), |
|
| 'http_user_agent_id' => ($http_user_agent_id = |
|
| _get_id( |
|
| 'weblog_http_user_agents', $HTTP_USER_AGENT)), |
|
| 'script_filename_id' => _get_id( |
|
| 'weblog_script_filenames', $SCRIPT_FILENAME), |
|
| 'request_uri_id' => _get_id( |
|
| 'weblog_request_uris', $REQUEST_URI), |
|
| 'ident_username_id' => _get_id( |
|
| 'weblog_ident_usernames', $ident_user), |
|
| 'ident_ostype_id' => _get_id( |
|
| 'weblog_ident_ostypes', $ident_ostype), |
|
| 'session_id' => _get_session_id( |
|
| $remote_addr_id, $http_user_agent_id) |
|
| ); |
|
| |
|
| |
|
| $keys = ''; |
|
| $vals = ''; |
|
| $count = 0; |
|
| |
|
| foreach ($record as $key => $val) { |
|
| $count++; |
|
| $sep = ($count < count($record) ? ", " : ""); |
|
| |
|
| $keys .= $key . $sep; |
$query = "insert into weblog_accesses" |
| $vals .= ($val ? "'$val'" : "NULL") . $sep; |
. " ( datetime, $keys ) values ( sysdate(), $vals )"; |
| } |
|
| |
|
| $query = "insert into weblog_accesses" |
print "<hr>$query<br>\n"; |
| ." ( datetime, $keys ) values ( sysdate(), $vals )"; |
|
| |
|
| //print "$query<br>\n"; |
$result = $this->_db->query($query); |
| |
|
| $result = @mysql_query($query, $this->_db_handle) |
if (DB::isError($result)) { |
| or _db_error(); |
$this->_error($result->getMessage()); |
| |
} |
| |
|
| return; |
$this->_db->disconnect(); |
| |
unset($this->_db); |
| |
|
| |
return; |
| } |
} |
| |
|
| /* |
/* |
| * _get_id() |
* _get_id() |
| * |
* |
| * Return ID of $value in $table. |
* Return ID of $value in $table. |
| * If $value is not in table, record will be inserted. |
* If $value is not in table, record will be inserted and ID returned. |
| */ |
*/ |
| |
|
| function _get_id($table, $value) { |
function _get_id($table, $value) { |
| |
|
| |
echo "<hr>_get_id() entered: $table, $value<br>"; |
| |
|
| /* |
/* |
| * 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 |
| Riadok 367 class Web_Log { |
|
| Riadok 469 class Web_Log { |
|
| */ |
*/ |
| |
|
| // if (!isset($value) || !isset($table)) return 0; |
// if (!isset($value) || !isset($table)) return 0; |
| if (!$value || !$table) |
if (! $value || ! $table) |
| return 0; |
return 0; |
| |
|
| $this->_check_db_handle(); |
$this->_check_db(); |
| |
|
| $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"; |
." limit 1"; // TODO: MySQL dependent |
| $result = @mysql_query($query, $this->_db_handle) |
echo "$query<br>"; |
| or _db_error(); |
|
| |
$id = $this->_db->getOne($query); |
| |
|
| |
if (DB::isError($id)) |
| |
$this->_error($id->getMessage()); |
| |
|
| |
if ($id) |
| |
return $id; |
| |
|
| if ($row = @mysql_fetch_array($result)) |
/* Important note: |
| return $row[0]; |
|
| |
We cannot count id before insert (for example with: select |
| |
max(id) from $table) because there can be also another connection |
| |
to the same database. It queries the same maximal id and insert |
| |
appropriate record into table. And our insert will fail. |
| |
*/ |
| |
|
| $query = "insert into $table (id, value)" |
$query = "insert into $table (id, value)" |
| ." values (0, '" . addslashes($value) . "')"; |
." values (0, '" . addslashes($value) . "')"; |
| $result = @mysql_query($query, $this->_db_handle) |
echo "$query<br>"; |
| or _db_error(); |
$result = $this->_db->query($query); |
| |
|
| |
if (DB::isError($result)) |
| |
$this->_error($result->getMessage()); |
| |
|
| |
$query = "select last_insert_id()"; // TODO: MySQL dependent |
| |
echo "$query<br>"; |
| |
|
| |
$id = $this->_db->getOne($query); |
| |
|
| $query = "select last_insert_id()"; |
if (DB::isError($id)) |
| $result = @mysql_query($query, $this->_db_handle) |
$this->_error($id->getMessage()); |
| or _db_error(); |
|
| |
|
| if ($row = @mysql_fetch_array($result)) |
if ($id) |
| return $row[0]; |
return $id; |
| |
|
| return 0; |
return 0; |
| } |
} |
| Riadok 399 class Web_Log { |
|
| Riadok 520 class Web_Log { |
|
| /* |
/* |
| * _get_session_id() |
* _get_session_id() |
| * |
* |
| * Returns session_id according to $remote_addr_id and $http_user_agent_id |
* Returns session_id according to session variables of object. Session |
| * and session timeout defined in config.inc.php file. |
* variables are $_session_timeout and $_session_keys. |
| */ |
*/ |
| function _get_session_id( |
function _get_session_id() { |
| $remote_addr_id, $http_user_agent_id) { |
|
| |
|
| $this->_check_db_handle(); |
$this->_check_db(); |
| |
|
| |
$where = ''; |
| |
foreach ($this->_session_keys as $session_key) { |
| |
if (isset($this->_props[$session_key])) { |
| |
$where .= ($where == '' ? "where " : " and "); |
| |
|
| |
$where .= $this->_props[$session_key]['column']; |
| |
$where .= " = "; |
| |
$where .= "'" . $this->_props[$session_key]['id'] . "'"; |
| |
} |
| |
} |
| |
|
| $query = "select" |
$query = "select" |
| ." id, session_id," |
." id, session_id," |
| ." unix_timestamp(now()) - unix_timestamp(datetime) as diff_sec" |
." unix_timestamp(now()) - unix_timestamp(datetime) as diff_sec" |
| ." from weblog_accesses" |
." from weblog_accesses" |
| ." where remote_addr_id = '$remote_addr_id'" |
." $where" |
| ." and http_user_agent_id = '$http_user_agent_id'" |
|
| ." order by datetime desc" |
." order by datetime desc" |
| ." limit 1"; |
." limit 1"; |
| |
|
| $result = @mysql_query($query, $this->_db_handle) |
echo "<hr>Session query: $query<br>"; |
| or _db_error(); |
|
| |
$row = $this->_db->getRow($query); |
| |
|
| if (($row = @mysql_fetch_array($result, MYSQL_ASSOC)) |
if (DB::isError($row)) |
| && ($row[diff_sec] < $_SESSION_TIMEOUT) |
$this->_error($row->getMessage()); |
| |
|
| |
if (is_array($row) |
| |
&& ($row[diff_sec] < $this->_session_timeout) |
| && ($row[session_id])) { |
&& ($row[session_id])) { |
| |
|
| return $row[session_id]; |
return $row[session_id]; |
| } |
} |
| |
|
| //echo "if: ". $row[diff_sec] . " < " |
|
| // . $_SESSION_TIMEOUT . "<br>"; |
|
| |
|
| $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"; |
| |
|
| $result = @mysql_query($query, $this->_db_handle) |
$id = $this->_db->getOne($query); |
| or _db_error(); |
|
| |
|
| if (($row = @mysql_fetch_array($result, MYSQL_ASSOC)) |
if (DB::isError($id)) |
| && ($row[new_session_id])) { |
$this->_error($id->getMessage()); |
| |
|
| return $row[new_session_id]; |
if ($id) |
| } |
return $id; |
| |
|
| return 1; |
return 1; |
| } |
} |
| |
|
| /* |
/* |
| * _get_sessions_count() |
* get_sessions_count() |
| * |
* |
| */ |
*/ |
| function _get_sessions_count($ar = '') { |
function get_sessions_count($array = '') { |
| |
|
| $this->_check_db_handle(); |
$this->_check_db(); |
| |
|
| $list_tables = ''; |
$list_tables = ''; |
| $list_where = ''; |
$list_where = ''; |
| |
|
| if (is_array($ar)) { |
if (is_array($array)) { |
| $names = array( |
|
| 'id' => array( |
$count = 0; |
| 'column' => 'id_id'), |
foreach ($array as $key => $val) { |
| 'datetime' => array( |
$count++; |
| 'column' => 'datetime_id'), |
|
| 'value' => array( |
if (isset($this->_props[$key]['table'])) { |
| 'column' => 'value_id', |
$list_where .= ($list_where == '' ? '' : ' and '); |
| 'table' => 'weblog_values'), |
$list_where .= "weblog_accesses." |
| 'request_method' => array( |
. $this->_props[$key]['column'] . " = " |
| 'column' => 'request_method_id', |
. $this->_props[$key]['table'] . ".id and " |
| 'table' => 'weblog_request_methods'), |
. $this->_props[$key]['table'] . ".value like '$val'"; |
| 'query_string' => array( |
|
| 'column' => 'query_string_id', |
$list_tables .= ($list_tables == '' ? '' : ', '); |
| 'table' => 'weblog_query_strings'), |
$list_tables .= $this->_props[$key]['table']; |
| 'path_info' => array( |
} |
| 'column' => 'path_info_id', |
elseif (isset($this->_props[$key])) { |
| 'table' => 'weblog_path_infos'), |
$list_where .= ($list_where == '' ? '' : ' and '); |
| 'path_translated' => array( |
$list_where .= $this->_props[$key]['column'] . " = '$val'"; |
| 'column' => 'path_translated_id', |
} |
| 'table' => 'weblog_paths_translated'), |
} |
| 'content_type' => array( |
|
| 'column' => 'content_type_id', |
|
| 'table' => 'weblog_content_types'), |
|
| 'content_length' => array( |
|
| 'column' => 'content_length'), |
|
| 'script_name' => array( |
|
| 'column' => 'script_name_id', |
|
| 'table' => 'weblog_script_names'), |
|
| 'server_name' => array( |
|
| 'column' => 'server_name_id', |
|
| 'table' => 'weblog_server_names'), |
|
| 'server_port' => array( |
|
| 'column' => 'server_port'), |
|
| 'server_software' => array( |
|
| 'column' => 'server_software_id', |
|
| 'table' => 'weblog_server_softwares'), |
|
| 'server_protocol' => array( |
|
| 'column' => 'server_protocol_id', |
|
| 'table' => 'weblog_server_protocols'), |
|
| 'gateway_interface' => array( |
|
| 'column' => 'gateway_interface_id', |
|
| 'table' => 'weblog_gateway_interfaces'), |
|
| 'proxy_addr' => array( |
|
| 'column' => 'proxy_addr_id', |
|
| 'table' => 'weblog_remote_addrs'), |
|
| 'proxy_host' => array( |
|
| 'column' => 'proxy_host_id', |
|
| 'table' => 'weblog_remote_hosts'), |
|
| 'remote_addr' => array( |
|
| 'column' => 'remote_addr_id', |
|
| 'table' => 'weblog_remote_addrs'), |
|
| 'remote_host' => array( |
|
| 'column' => 'remote_host_id', |
|
| 'table' => 'weblog_remote_hosts'), |
|
| 'remote_port' => array( |
|
| 'column' => 'remote_port_id'), |
|
| 'auth_type' => array( |
|
| 'column' => 'auth_type_id', |
|
| 'table' => 'weblog_auth_types'), |
|
| 'remote_user' => array( |
|
| 'column' => 'remote_user_id', |
|
| 'table' => 'weblog_remote_users'), |
|
| 'remote_ident' => array( |
|
| 'column' => 'remote_ident_id', |
|
| 'table' => 'weblog_remote_idents'), |
|
| 'document_root' => array( |
|
| 'column' => 'document_root_id', |
|
| 'table' => 'weblog_document_roots'), |
|
| 'http_accept' => array( |
|
| 'column' => 'http_accept_id', |
|
| 'table' => 'weblog_http_accepts'), |
|
| 'http_accept_charset' => array( |
|
| 'column' => 'http_accept_charset_id', |
|
| 'table' => 'weblog_http_accept_charsets'), |
|
| 'http_accept_encoding' => array( |
|
| 'column' => 'http_accept_encoding_id', |
|
| 'table' => 'weblog_http_accept_encodings'), |
|
| 'http_accept_language' => array( |
|
| 'column' => 'http_accept_language_id', |
|
| 'table' => 'weblog_http_accept_languages'), |
|
| 'http_connection' => array( |
|
| 'column' => 'http_connection_id', |
|
| 'table' => 'weblog_http_connections'), |
|
| 'http_host' => array( |
|
| 'column' => 'http_host_id', |
|
| 'table' => 'weblog_http_hosts'), |
|
| 'http_referer' => array( |
|
| 'column' => 'http_referer_id', |
|
| 'table' => 'weblog_http_referers'), |
|
| 'http_user_agent' => array( |
|
| 'column' => 'http_user_agent_id', |
|
| 'table' => 'weblog_http_user_agents'), |
|
| 'script_filename' => array( |
|
| 'column' => 'script_filename_id', |
|
| 'table' => 'weblog_script_filenames'), |
|
| 'server_admin' => array( |
|
| 'column' => 'server_admin_id', |
|
| 'table' => 'weblog_server_admins'), |
|
| 'server_signature' => array( |
|
| 'column' => 'server_signature_id', |
|
| 'table' => 'weblog_server_signatures'), |
|
| 'request_uri' => array( |
|
| 'column' => 'request_uri_id', |
|
| 'table' => 'weblog_request_uris'), |
|
| 'ident_username' => array( |
|
| 'column' => 'ident_username_id', |
|
| 'table' => 'weblog_ident_usernames'), |
|
| 'ident_ostype' => array( |
|
| 'column' => 'ident_ostype_id', |
|
| 'table' => 'weblog_ident_ostypes'), |
|
| 'session' => array( |
|
| 'column' => 'session_id', |
|
| 'table' => 'weblog_sessions'), |
|
| ); |
|
| |
|
| $count = 0; |
|
| |
|
| foreach ($ar as $key => $val) { |
|
| $count++; |
|
| |
|
| if (isset($names[$key][table])) { |
|
| $list_where .= "weblog_accesses." |
|
| . $names[$key][column] . " = " |
|
| . $names[$key][table] . ".id and " |
|
| . $names[$key][table] . ".value like '$val'"; |
|
| |
|
| $list_tables .= $names[$key][table]; |
|
| |
|
| if ($count < count($ar)) |
|
| $list_tables .= ', '; |
|
| } |
|
| else { |
|
| $list_where .= $names[$key] . " = '$val'"; |
|
| } |
|
| |
|
| if ($count < count($ar)) |
|
| $list_where .= ' and '; |
|
| } |
|
| } |
} |
| |
|
| $query = "select" |
$query = "select" |
| Riadok 601 class Web_Log { |
|
| Riadok 613 class Web_Log { |
|
| ." from weblog_accesses"; |
." from weblog_accesses"; |
| |
|
| 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"; |
| |
|
| |
echo "<p>$query<hr>"; |
| |
//$result = @mysql_query($query, $this->_db) or _db_error(); |
| |
|
| //echo "<p>$query<hr>"; |
$count = $this->_db->getOne($query); |
| |
|
| $result = @mysql_query($query, $this->_db_handle) |
if (DB::isError($count)) |
| or _db_error(); |
$this->_error($count->getMessage()); |
| |
|
| if ($row = @mysql_fetch_array($result, MYSQL_ASSOC)) |
if (isset($count)) |
| return $row[sessions_count]; |
return $count; |
| |
|
| return false; |
return false; |
| } |
} |