From 87d763969896a9e26e4b8035db4eba8c330e7799 Mon Sep 17 00:00:00 2001 From: Sascha Leib Date: Tue, 26 Aug 2025 21:37:19 +0300 Subject: [PATCH] Minor fixes --- README.md | 8 +++++++- action.php | 21 ++++++++++++++++++--- pview.php | 24 ++++++++++++------------ tick.php | 10 +++++----- 4 files changed, 42 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index 27d864f..3a659c0 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,10 @@ # DokuWiki Monitoring Plugin Plugin for live-monitoring your DokuWiki instance -#TODO: Work in progress \ No newline at end of file +#TODO: Work in progress + +IMPORTANT: This is an experimental plugin to investigate bot traffic. This is not a "install and forget" software, but rather requires that you actively look at and manage the log files. + +This plugin creates various log files in its own "logs" directory. These files can get quite large, and you should check them actively. + +Also, these files can get quite large and fill up your server. Make sure to manually delete older files from time to time! diff --git a/action.php b/action.php index 17a2e1a..95d3980 100644 --- a/action.php +++ b/action.php @@ -55,10 +55,25 @@ class action_plugin_monitor extends DokuWiki_Action_Plugin { /* Write out client info to a server log: */ + // what is the session identifier? + $sessionId = $_COOKIE['DokuWiki'] ?? null; + if (!$sessionId) { + if (session_id()) { + // if a session ID is set, use it + $sessionId = 'P:' . session_id(); + } else { + // if no session ID is set, use an empty string + $sessionId = ''; + } + } else { + // if no cookie is set, use the session ID + $sessionId = 'D:' . $sessionId; + } + $logArr = Array( - $_SERVER['REMOTE_ADDR'] ?? '–', /* remote IP */ - $INFO['id'] ?? '–', /* user agent */ - $_COOKIE['DokuWiki'] ?? '–', /* DokuWiki session ID */ + $_SERVER['REMOTE_ADDR'] ?? '', /* remote IP */ + $INFO['id'] ?? '', /* page ID */ + $sessionId, /* Session ID */ $username, $_SERVER['HTTP_USER_AGENT'] ?? '' /* User agent */ ); diff --git a/pview.php b/pview.php index 0c67131..6e04bee 100644 --- a/pview.php +++ b/pview.php @@ -9,18 +9,18 @@ if (!$json) { /* build the resulting log line (ensure fixed column positions!) */ $logArr = Array( - $_SERVER['REMOTE_ADDR'] ?? 'null', /* remote IP */ - $json['pg'] ?? 'null', /* DW page ID */ - $_COOKIE['DokuWiki'] ?? 'null', /* DokuWiki session ID */ - $json['u'] ?? 'null' /* DW User id (if logged in) */ - // $json['tz'] ?? 'null', /* timzone offset */ - // $json['lg'] ?? 'null', /* browser language */ - // $json['td'] ?? 'null', /* load time */ - // $json['scr'] ?? 'null', /* Screen dimensions */ - // $json['l'] ?? 'null', /* Accepted languages list */ - // $json['url'] ?? 'null', /* Full request URL */ - // $json['r'] ?? 'null', /* Referrer URL */ - // $_SERVER['HTTP_USER_AGENT'] ?? 'null', /* User agent */ + $_SERVER['REMOTE_ADDR'] ?? '', /* remote IP */ + $json['pg'] ?? '', /* DW page ID */ + $_COOKIE['DokuWiki'] ?? session_id() ?? '', /* DokuWiki session ID */ + $json['u'] ?? '' /* DW User id (if logged in) */ + // $json['tz'] ?? '', /* timzone offset */ + // $json['lg'] ?? '', /* browser language */ + // $json['td'] ?? '', /* load time */ + // $json['scr'] ?? '', /* Screen dimensions */ + // $json['l'] ?? '', /* Accepted languages list */ + // $json['url'] ?? '', /* Full request URL */ + // $json['r'] ?? '', /* Referrer URL */ + // $_SERVER['HTTP_USER_AGENT'] ?? '', /* User agent */ // $json['t'] ?? '' /* Page title */ ); diff --git a/tick.php b/tick.php index efa2de1..f0d60a6 100644 --- a/tick.php +++ b/tick.php @@ -2,20 +2,20 @@ /* build the resulting log line (ensure fixed column positions!) */ $logArr = Array( - $_SERVER['REMOTE_ADDR'] ?? 'null', /* remote IP */ - $_GET['p'] ?? null, /* page ID */ - $_COOKIE['DokuWiki'] ?? 'null' /* DokuWiki session ID */ + $_SERVER['REMOTE_ADDR'] ?? '', /* remote IP */ + $_GET['p'] ?? '', /* page ID */ + $_COOKIE['DokuWiki'] ?? session_id() ?? '' /* DokuWiki session ID */ ); /* create the log line */ -$filename = 'logs/' . gmdate('Y-m-d') . ".tck"; /* use GMT date for filename */ +$filename = 'logs/' . gmdate('Y-m-d') . '.tck'; /* use GMT date for filename */ $line = gmdate('Y-m-d H:i:s'); /* use GMT time for log entries */ foreach ($logArr as $val) { $line .= "\t" . $val; }; /* write the log line to the file */ -$tickfile = fopen($filename, "a"); +$tickfile = fopen($filename, 'a'); if (!$tickfile) { http_response_code(500); die("Error: Unable to open log file. Please check file permissions.");