xref: /plugin/botmon/tick.php (revision 87d763969896a9e26e4b8035db4eba8c330e7799)
1<?php /* MONITOR PLUGIN HEARTBEAT TICKER SCRIPT */
2
3/* build the resulting log line (ensure fixed column positions!) */
4$logArr = Array(
5	$_SERVER['REMOTE_ADDR'] ?? '', /* remote IP */
6	$_GET['p'] ?? '', /* page ID */
7	$_COOKIE['DokuWiki'] ?? session_id() ?? '' /* DokuWiki session ID */
8);
9
10/* create the log line */
11$filename = 'logs/' . gmdate('Y-m-d') . '.tck'; /* use GMT date for filename */
12$line = gmdate('Y-m-d H:i:s'); /* use GMT time for log entries */
13foreach ($logArr as $val) {
14	$line .= "\t" . $val;
15};
16
17/* write the log line to the file */
18$tickfile = fopen($filename, 'a');
19if (!$tickfile) {
20	http_response_code(500);
21	die("Error: Unable to open log file. Please check file permissions.");
22}
23if (fwrite($tickfile, $line . "\n") === false) {
24	http_response_code(500);
25	fclose($tickfile);
26	die("Error: Could not write to log file.");
27}
28fclose($tickfile);
29
30/* Send "Accepted" header */
31http_response_code(202);
32echo "OK";