Files
html/api/claw-code-api.php
2026-04-12 22:57:03 +02:00

21 lines
853 B
PHP

<?php
header('Content-Type: application/json');
header('Access-Control-Allow-Origin: *');
$action = $_GET['action'] ?? 'status';
if ($action === 'status') {
$fp = @fsockopen('127.0.0.1', 3900, $e1, $e2, 2);
$up = $fp ? true : false;
if ($fp) fclose($fp);
echo json_encode(['service'=>'Claw Code','version'=>'1.2.9','port'=>3900,'running'=>$up,'github'=>'nicepkg/gpt-runner','path'=>'/opt/claw-code']);
} elseif ($action === 'health') {
$ch = curl_init('http://127.0.0.1:3900/');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 3);
$r = curl_exec($ch);
$c = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
echo json_encode(['http_code'=>$c, 'alive'=>$c>0, 'body_len'=>strlen($r)]);
} else {
echo json_encode(['error'=>'Unknown','actions'=>['status','health']]);
}