aboutsummaryrefslogtreecommitdiff
path: root/api/debug/config.php
diff options
context:
space:
mode:
Diffstat (limited to 'api/debug/config.php')
-rw-r--r--api/debug/config.php59
1 files changed, 59 insertions, 0 deletions
diff --git a/api/debug/config.php b/api/debug/config.php
new file mode 100644
index 0000000..4a2bd05
--- /dev/null
+++ b/api/debug/config.php
@@ -0,0 +1,59 @@
+<?php
+// api/debug/config.php — Shared config for debug backend
+header('Content-Type: application/json; charset=utf-8');
+header('Access-Control-Allow-Origin: https://webx11.duckdns.org');
+header('Access-Control-Allow-Methods: GET, POST, OPTIONS');
+header('Access-Control-Allow-Headers: Content-Type');
+header('Access-Control-Max-Age: 86400');
+
+// Handle preflight
+if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
+ http_response_code(204);
+ exit;
+}
+
+date_default_timezone_set('UTC');
+
+define('DEBUG_DATA_DIR', __DIR__ . '/../../data/debug');
+define('MAX_ERRORS_PER_BATCH', 100);
+define('MAX_BATCH_SIZE_KB', 64);
+define('CLUSTER_SIMILARITY_THRESHOLD', 0.35);
+define('ERRORS_FILE', DEBUG_DATA_DIR . '/errors.json');
+define('SESSIONS_FILE', DEBUG_DATA_DIR . '/sessions.json');
+define('CLUSTERS_FILE', DEBUG_DATA_DIR . '/clusters.json');
+
+if (!is_dir(DEBUG_DATA_DIR)) {
+ mkdir(DEBUG_DATA_DIR, 0755, true);
+}
+
+function load_json($path) {
+ if (!file_exists($path)) return [];
+ $data = json_decode(file_get_contents($path), true);
+ return is_array($data) ? $data : [];
+}
+
+function save_json($path, $data) {
+ $encoded = json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
+ $fp = fopen($path, 'c');
+ if ($fp && flock($fp, LOCK_EX)) {
+ ftruncate($fp, 0);
+ fwrite($fp, $encoded);
+ fflush($fp);
+ flock($fp, LOCK_UN);
+ fclose($fp);
+ } else {
+ // Fallback: write without lock
+ file_put_contents($path, $encoded);
+ }
+ @chmod($path, 0664);
+}
+
+function json_response($data, $code = 200) {
+ http_response_code($code);
+ echo json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
+ exit;
+}
+
+function error_response($msg, $code = 400) {
+ json_response(['success' => false, 'error' => $msg], $code);
+}