*/ if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../').'/'); require_once(DOKU_CONF.'dokuwiki.php'); /** * beautify a wiki page id for the log * * The wiki page id will be transformed to a filename like string * utf8 codes will be encoded. * * @param $id wiki page id * * @author Matthias Grimm */ function prepareID($path){ $path = cleanID($path); $path = str_replace(':','/',$path); $path = utf8_encodeFN($path); return $path; } /** * checks if a file exists and returns an appropriate web * server status * * @param $file complete filepath to check * * @author Matthias Grimm */ function getStatus($file){ if(@file_exists($file)){ $size = @filesize($file); return "200 $size"; }else return "404 0"; } /** * logs access to a wiki page * * @param $id page id of the wiki page including namespace * * @author Matthias Grimm */ function logPageAccess($id){ global $ACT; if ($ACT == 'show'){ $page = prepareID($id); $crumbs = breadcrumbs(); // get last visited pages $crumbs = array_keys($crumbs); // get raw page IDs array_pop($crumbs); // skip current page $referer = array_pop($crumbs); // get current page's predecessor $referer = ($referer) ? prepareID($referer) : ''; logAccess($page,getStatus(wikiFN($id)),$referer); } } /** * logs access to a media file (internally or externally) * * @param $media url or dokuwiki path of media * @param $file full path to the media file * * @author Matthias Grimm */ function logMediaAccess($media,$file){ if(!preg_match('#^(https?|ftp)://#i',$media)) $media = prepareID($media); logAccess($media,getStatus($file)); } /** * creates a log file entry and writes it to the log * * This function writes access information of the current page to a log * file. It uses the combined log file format that is also used by the * apache web server. A whole bunch of available log analysers could be * used to visualize the log. * * @param $page page name that was called * @param $status HTTP status code followed by the file size * @param $referer predecessor of $page (which page link to $page) * Is this field empty, the functions tries to get * the referer from the web server (HTTP_REFERER) * * @author Matthias Grimm * * combined log file format: * [] "" * "" ""\n * * IP of the client host (we don't do reverse host lookups) * remote user identification or '-' if not available * user id or '-' if not available * time in format [01/Dec/2005:22:19:12 +0200] * Requested protocol, for eg. GET or POST, requested page * and protocol * error code from server, for eg. 200 (OK) or 404 (file * not found) * size of the wiki page (only the bare text) * page that called this one. We don't have this information * and filled the dokuwiki script name in. * identifying information that the client browser reports * about itself */ function logAccess($page,$status,$referer=''){ global $conf; if (!empty($conf['accesslog'])){ $host = $_SERVER['REMOTE_ADDR']; $user = isset($_SERVER['REMOTE_USER']) ? $_SERVER['REMOTE_USER'] : "-"; $timestamp = date("[d/M/Y:H:i:s O]"); $method = isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : ""; $protocol = isset($_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : ""; $agent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : ""; if (empty($referer)){ if(isset($_SERVER['HTTP_REFERER'])){ $cnt = preg_match('/\?id=((\w+\:*)+)/i',$_SERVER['HTTP_REFERER'], $match); if($cnt == 1) $referer = prepareID($match[1]); } } $logline = "$host - $user $timestamp \"$method $page $protocol\" $status \"$referer\" \"$agent\"\n"; io_saveFile($conf['accesslog'], $logline, true); } } //Setup VIM: ex: et ts=2 enc=utf-8 :