From 05b9ab6d3b302d16bfd723f049f17a44fe730a71 Mon Sep 17 00:00:00 2001 From: Daniel Date: Mon, 6 Apr 2026 22:39:22 +0200 Subject: [PATCH] fix admin check: isolate error handling, match caddyLoad curl config --- app/index.php | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/app/index.php b/app/index.php index 5d2fb86..f202a61 100644 --- a/app/index.php +++ b/app/index.php @@ -91,14 +91,18 @@ if (isset($_GET['action'])) { switch ($_GET['action']) { case 'check_admin': - $ch = curl_init(rtrim(CADDY_ADMIN_URL, '/') . '/config/'); - curl_setopt_array($ch, [CURLOPT_RETURNTRANSFER => true, CURLOPT_TIMEOUT => 3]); + $ch = curl_init(rtrim(CADDY_ADMIN_URL, '/') . '/load'); + curl_setopt_array($ch, [ + CURLOPT_CUSTOMREQUEST => 'GET', + CURLOPT_RETURNTRANSFER => true, + CURLOPT_TIMEOUT => 10, + ]); curl_exec($ch); $code = curl_getinfo($ch, CURLINFO_HTTP_CODE); $err = curl_error($ch); curl_close($ch); - if ($err) { echo json_encode(['ok' => false, 'error' => $err]); exit; } - if (!$code) { echo json_encode(['ok' => false, 'error' => 'No response from Caddy admin API']); exit; } + if ($err) { echo json_encode(['ok' => false, 'error' => $err]); exit; } + if (!$code) { echo json_encode(['ok' => false, 'error' => 'No response from Caddy admin API']); exit; } echo json_encode(['ok' => true]); exit; @@ -492,12 +496,18 @@ async function init() { syncAdminToggle(); renderSites(); - const admin = await adminRes.json(); - if (!admin.ok) { - setEditable(false, admin.error || 'Caddy admin API unreachable'); - } else { - setStatus('Ready', ''); + try { + const admin = await adminRes.json(); + if (!admin.ok) { + setEditable(false, admin.error || 'Caddy admin API unreachable'); + return; + } + } catch (e) { + setEditable(false, 'Caddy admin API unreachable'); + return; } + + setStatus('Ready', ''); } catch (e) { setStatus('Load error: ' + e.message, 'error'); }