Files
dokuwiki-plugin-botmon/pview.php

50 lines
1.5 KiB
PHP
Raw Normal View History

2025-09-01 16:25:25 +02:00
<?php /* BOT MONITOR PLUGIN PAGE VIEW SCRIPT */
2025-08-20 22:58:42 +03:00
/* parse the JSON payload */
$json = json_decode($_POST['pageview'], true);
if (!$json) {
http_response_code(400);
die("Error: Invalid JSON data sent to server.");
}
/* build the resulting log line (ensure fixed column positions!) */
$logArr = Array(
2025-08-26 21:37:19 +03:00
$_SERVER['REMOTE_ADDR'] ?? '', /* remote IP */
$json['pg'] ?? '', /* DW page ID */
2025-09-01 18:55:56 +02:00
$_COOKIE['DokuWiki'] ?? session_id() ?? '', /* DW session ID */
2025-08-30 13:01:50 +03:00
$json['u'] ?? '', /* DW User id (if logged in) */
2025-09-01 18:55:56 +02:00
$json['lt'] ?? '', /* load time */
2025-08-30 18:40:16 +03:00
$json['r'] ?? '', /* Referrer URL */
$_SERVER['HTTP_USER_AGENT'] ?? '' /* User agent */
2025-08-26 21:37:19 +03:00
// $json['lg'] ?? '', /* browser language */
// $json['scr'] ?? '', /* Screen dimensions */
2025-08-30 13:01:50 +03:00
// $json['tz'] ?? '', /* timzone offset */
2025-08-26 21:37:19 +03:00
// $json['l'] ?? '', /* Accepted languages list */
// $json['url'] ?? '', /* Full request URL */
2025-08-20 22:58:42 +03:00
// $json['t'] ?? '' /* Page title */
);
/* create the log line */
2025-09-01 10:15:36 +02:00
$filename = 'logs/' . gmdate('Y-m-d') . '.log.txt'; /* use server datetime */
2025-08-20 22:58:42 +03:00
$logline = gmdate('Y-m-d H:i:s');
foreach ($logArr as $val) {
$logline .= "\t" . $val;
};
/* write the log line to the file */
$logfile = fopen($filename, 'a');
if (!$logfile) {
http_response_code(500);
die("Error: Unable to open log file. Please check file permissions.");
}
if (fwrite($logfile, $logline . "\n") === false) {
http_response_code(500);
fclose($logfile);
die("Error: Could not write to log file.");
}
fclose($logfile);
/* send a 202 response */
http_response_code(202);
echo "OK";