ogcore/src/Controller/ServerInfoController.php

40 lines
1.2 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Attribute\AsController;
use Symfony\Component\Routing\Annotation\Route;
#[AsController]
class ServerInfoController extends AbstractController
{
private const string RELEASE_FILE = '/opt/opengnsys/release';
#[Route('/opengnsys/server/release', methods: ['GET'])]
public function release(): JsonResponse
{
if (!file_exists(self::RELEASE_FILE) || !is_readable(self::RELEASE_FILE)) {
return new JsonResponse(['error' => 'Release file not found'], Response::HTTP_NOT_FOUND);
}
$content = file_get_contents(self::RELEASE_FILE);
$lines = array_filter(explode("\n", trim($content)));
$versions = [];
foreach ($lines as $line) {
if (!str_contains($line, ':')) {
continue;
}
[$key, $value] = explode(':', $line, 2);
$versions[trim($key)] = trim($value);
}
return new JsonResponse($versions);
}
}