# HG changeset patch # User Michiel Broek # Date 1713193575 -7200 # Node ID ecfcb1104b546fece54b67114b30f667ff54d69c # Parent cc49115e769e14f5d88a9e085931e8213ed8110e Added getglobal.php script diff -r cc49115e769e -r ecfcb1104b54 www/getglobal.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/www/getglobal.php Mon Apr 15 17:06:15 2024 +0200 @@ -0,0 +1,60 @@ + 15, 'usec' => 0)); + } else { + socket_close($sock); + } + } + return $sock; +} + + +/** + * @param string $command to send to the server. + * @return string with the complete reply from the + * server. This can be a multiline reply. + */ +function send_cmd($command) +{ + $sock = open_socket(); + if ($sock == false) { + return ""; + } + socket_write($sock, $command . "\r\n", 4096); + + $answer = ""; + while (1) { + $line = socket_read($sock, 4096); + if ($line === '') + break; + $answer .= $line; + } + socket_close($sock); + + return $answer; +} + + +function startsWith($haystack, $needle) +{ + return !strncmp($haystack, $needle, strlen($needle)); +} + + +$answer = send_cmd("GLOBAL JSON"); +header("Content-type: application/json"); + +$arr = explode("\r\n", $answer); +if (startsWith($arr[0], "213")) { + echo $arr[1]; +} else { + echo '{}'; +} +