Lines
83.33%
20 / 24
Methods
66.66%
2 / 3
Classes
0.00%
0 / 1
| Name | Lines | Methods | CRAP | ||||
|---|---|---|---|---|---|---|---|
| readResponse | 73.33% | 11 / 15 | 0.00% | 0 / 1 | 2.08 | ||
| assertStatusAccess | 100.00% | 6 / 6 | 100.00% | 1 / 1 | 4 | ||
| [BO\Zmsbackend\Api\BaseController] __invoke | 100.00% | 3 / 3 | 100.00% | 1 / 1 | 1 | ||
| 16 | class StatusGet extends \BO\Zmsbackend\Api\BaseController | |
| 17 | { | |
| 18 | /** | |
| 19 | * @SuppressWarnings(Param) | |
| 20 | * @return \Psr\Http\Message\ResponseInterface | |
| 21 | */ | |
| 22 | #[\Override] | |
| 23 | public function readResponse( | |
| 24 | \Psr\Http\Message\RequestInterface $request, | |
| 25 | \Psr\Http\Message\ResponseInterface $response, | |
| 26 | array $args | |
| 27 | ) { | |
| 28 | $this->assertStatusAccess($request); | |
| 29 | ||
| 30 | $validator = $request->getAttribute('validator'); | |
| 31 | $includeProcessStats = $validator->getParameter('includeProcessStats')->isNumber()->setDefault(1)->getValue(); | |
| 32 | $status = (new \BO\Zmsbackend\Status\Service\Status())->readEntity(\App::$now, $includeProcessStats); | |
| 33 | $status['version'] = \BO\Zmsbackend\Helper\Version::getArray(); | |
| 34 | if (\App::DEBUG) { | |
| 35 | $status['opcache'] = [ | |
| 36 | 'config' => opcache_get_configuration(), | |
| 37 | 'status' => opcache_get_status(false) | |
| 38 | ]; | |
| 39 | } | |
| 40 | ||
| 41 | $message = \BO\Zmsbackend\Api\Response\Message::create($request); | |
| 42 | $message->data = $status; | |
| 43 | ||
| 44 | $response = Render::withLastModified($response, time(), '0'); | |
| 45 | $response = Render::withJson($response, $message->setUpdatedMetaData(), $message->getStatuscode()); | |
| 46 | return $response; | |
| 47 | } | |
| 48 | ||
| 49 | /** | |
| 50 | * Allow access with a logged-in workstation (admin UI) or X-Token matching | |
| 51 | * ZMS_CONFIG_SECURE_TOKEN (Grafana / status-logger). Same idea as ConfigGet, | |
| 52 | * with strict token comparison and a narrow auth-exception catch. | |
| 53 | */ | |
| 54 | private function assertStatusAccess(\Psr\Http\Message\RequestInterface $request): void | |
| 55 | { | |
| 56 | try { | |
| 57 | (new \BO\Zmsbackend\Helper\User($request))->checkPermissions(); | |
| 58 | return; | |
| 59 | } catch (UserAccountMissingLogin | UserAccountMissingRights $exception) { | |
| 60 | // Fall through to X-Token for scrapers / unauthenticated callers. | |
| 61 | } | |
| 62 | ||
| 63 | $token = $request->getHeaderLine('X-Token'); | |
| 64 | if ($token === '' || !hash_equals((string) \App::SECURE_TOKEN, $token)) { | |
| 65 | throw new StatusAuthenticationFailed(); | |
| 66 | } | |
| 67 | } | |
| 68 | } |
Inherited from BO\Zmsbackend\Api\BaseController
| 20 | public function __invoke(RequestInterface $request, ResponseInterface $response, array $args) | |
| 21 | { | |
| 22 | $request = $this->initRequest($request); | |
| 23 | $noCacheResponse = \BO\Slim\Render::withLastModified($response, time(), '0'); | |
| 24 | return $this->readResponse($request, $noCacheResponse, $args); | |
| 25 | } |