From d02a441cb749182c0d4cf6e73e1cb412208d8d83 Mon Sep 17 00:00:00 2001 From: Terranom674 Date: Mon, 17 Aug 2026 22:26:18 +0200 Subject: [PATCH] NC Connector: add admin status polling endpoint --- nc-connector-status.php | 59 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 nc-connector-status.php diff --git a/nc-connector-status.php b/nc-connector-status.php new file mode 100644 index 0000000..b8f8a05 --- /dev/null +++ b/nc-connector-status.php @@ -0,0 +1,59 @@ +'unavailable','message'=>'Bratonien Tools ist nicht aktiv.')); + exit; +} +if (!function_exists('is_admin') || !is_admin()) +{ + http_response_code(403); + echo json_encode(array('state'=>'forbidden','message'=>'Administratorrechte erforderlich.')); + exit; +} + +$dir = PHPWG_ROOT_PATH.'_data/bratonien-tools/nc-connector-status'; +$latest = array( + 'state'=>'idle', + 'message'=>'Noch kein Connector-Status verfügbar.', + 'timestamp'=>0, + 'auth_mode'=>'', + 'api'=>array('state'=>'not_run','message'=>''), + 'fallback'=>array('state'=>'not_run','message'=>''), + 'error_detail'=>'', +); + +if (is_dir($dir)) +{ + foreach (glob($dir.'/connection-*.json') ?: array() as $file) + { + if (!is_readable($file)) + { + continue; + } + $decoded = json_decode((string)@file_get_contents($file), true); + if (!is_array($decoded)) + { + continue; + } + if ((int)($decoded['timestamp'] ?? 0) >= (int)$latest['timestamp']) + { + $latest = array_merge($latest, $decoded); + $latest['connection_file'] = basename($file); + } + } +} + +echo json_encode($latest, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);