getRequest()->getParam('tunnel_id', '')); if ($tunnelId === '') { $json = $this->resultFactory->create(ResultFactory::TYPE_JSON); $json->setData(['lines' => [], 'error' => 'missing_tunnel_id']); return $json; } $path = $this->tunnelStatus->getLogFilePath($tunnelId); $lines = []; if (\is_readable($path)) { $size = filesize($path); if ($size !== false && $size > 0) { $fp = fopen($path, 'rb'); if ($fp) { $start = max(0, $size - self::BYTES); fseek($fp, $start); if ($start > 0) { fgets($fp); } $chunk = stream_get_contents($fp) ?: ''; fclose($fp); $lines = preg_split('/\R/', $chunk) ?: []; $lines = array_values(array_filter($lines, static fn ($l) => $l !== '')); if (\count($lines) > self::LINES) { $lines = \array_slice($lines, -self::LINES); } } } } $json = $this->resultFactory->create(ResultFactory::TYPE_JSON); $json->setData(['lines' => $lines]); return $json; } protected function _isAllowed() { return $this->_authorization->isAllowed('MageSail_Magesail::tunnel') || $this->_authorization->isAllowed('MageSail_Magesail::tunnel_view') || $this->_authorization->isAllowed('MageSail_Magesail::tunnel_manage'); } }