-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdebug_log.php
More file actions
102 lines (84 loc) · 2.94 KB
/
debug_log.php
File metadata and controls
102 lines (84 loc) · 2.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<?php
// Enable error logging
error_reporting(E_ALL);
ini_set('display_errors', 0);
ini_set('log_errors', 1);
ini_set('error_log', 'debug_errors.log');
header('Content-Type: application/json');
class DebugLogger {
private const FILTERED_PHRASES = [
"Location data sent",
"getLocation called",
"Geolocation error",
"Location permission denied",
"Requesting location",
"Getting your location"
];
private const ESSENTIAL_PHRASES = [
'Lat:',
'Latitude:',
'Lon:',
'Longitude:',
'Position obtained',
'Location obtained',
'Accuracy:'
];
public function processRequest(): void {
try {
if (!$this->validateRequest()) {
echo json_encode([
'status' => 'error',
'message' => 'No message provided'
]);
return;
}
$message = trim($_POST['message']);
$date = date('Y-m-d H:i:s');
if ($this->shouldLogMessage($message)) {
$this->logMessage($date, $message);
$this->createMarkerFile();
}
echo json_encode(['status' => 'success']);
} catch (Exception $e) {
error_log("DebugLogger error: " . $e->getMessage());
echo json_encode([
'status' => 'error',
'message' => 'Internal server error'
]);
}
}
private function validateRequest(): bool {
return isset($_POST['message']) && !empty(trim($_POST['message']));
}
private function shouldLogMessage(string $message): bool {
// Check if message should be filtered out
foreach (self::FILTERED_PHRASES as $phrase) {
if (stripos($message, $phrase) !== false) {
return false;
}
}
// Check if message contains essential location data
foreach (self::ESSENTIAL_PHRASES as $phrase) {
if (stripos($message, $phrase) !== false) {
return true;
}
}
return false;
}
private function logMessage(string $date, string $message): void {
$logEntry = "[$date] " . htmlspecialchars($message, ENT_QUOTES, 'UTF-8') . PHP_EOL;
if (file_put_contents("location_debug.log", $logEntry, FILE_APPEND | LOCK_EX) === false) {
error_log("Failed to write to location_debug.log");
}
}
private function createMarkerFile(): void {
$marker = "Location data captured | " . date('Y-m-d H:i:s') . PHP_EOL;
if (file_put_contents("LocationLog.log", $marker, FILE_APPEND | LOCK_EX) === false) {
error_log("Failed to write to LocationLog.log");
}
}
}
// Execute the debug logging
$logger = new DebugLogger();
$logger->processRequest();
?>