use fsockopen for admin check, consistent with checkUpstream
This commit is contained in:
1 parent
05b9ab6d3b
commit
1b97c681e0
1 file changed
+6
-13
+6
-13
@@ -91,19 +91,12 @@ if (isset($_GET['action'])) {
|
||||
switch ($_GET['action']) {
|
||||
|
||||
case 'check_admin':
|
||||
$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; }
|
||||
echo json_encode(['ok' => true]);
|
||||
$parsed = parse_url(CADDY_ADMIN_URL);
|
||||
$host = $parsed['host'] ?? 'localhost';
|
||||
$port = $parsed['port'] ?? 2019;
|
||||
$fp = @fsockopen($host, $port, $errno, $errstr, 3);
|
||||
if ($fp) { fclose($fp); echo json_encode(['ok' => true]); }
|
||||
else { echo json_encode(['ok' => false, 'error' => "Cannot reach {$host}:{$port} — {$errstr}"]); }
|
||||
exit;
|
||||
|
||||
case 'load':
|
||||
|
||||
Reference in new issue
Block a user