Skip to content

Commit cfb4b8f

Browse files
authored
Merge pull request #217 from nextcloud/copilot/add-enterprise-version-endpoint
Add /enterprise-version endpoint to return enterprise version as JSON
2 parents a30423a + e2539d8 commit cfb4b8f

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

index.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,34 @@
99
require_once __DIR__ . '/vendor/autoload.php';
1010
require_once __DIR__ . '/src/Response.php';
1111

12+
// Check if this is a request for the enterprise version endpoint
13+
if (isset($_SERVER['PATH_INFO']) && $_SERVER['PATH_INFO'] === '/enterprise-version') {
14+
// Set Content-Type to JSON
15+
header('Content-Type: application/json');
16+
// Enforce browser based XSS filters
17+
header('X-XSS-Protection: 1; mode=block');
18+
// Disable sniffing the content type for IE
19+
header('X-Content-Type-Options: nosniff');
20+
// Disallow iFraming from other domains
21+
header('X-Frame-Options: Sameorigin');
22+
// https://developers.google.com/webmasters/control-crawl-index/docs/robots_meta_tag
23+
header('X-Robots-Tag: none');
24+
25+
// Extract enterpriseVersion from the config file by parsing it
26+
$configContent = file_get_contents(__DIR__ . '/config/config.php');
27+
if ($configContent === false) {
28+
http_response_code(500);
29+
echo json_encode(['error' => 'Failed to read configuration file'], JSON_THROW_ON_ERROR);
30+
exit();
31+
}
32+
33+
preg_match('/\$enterpriseVersion\s*=\s*[\'"]([^\'"\r\n]+)[\'"]/', $configContent, $matches);
34+
$enterpriseVersion = isset($matches[1]) ? $matches[1] : null;
35+
36+
echo json_encode(['enterpriseVersion' => $enterpriseVersion], JSON_THROW_ON_ERROR);
37+
exit();
38+
}
39+
1240
// Set Content-Type to XML
1341
header('Content-Type: application/xml');
1442
// Enforce browser based XSS filters

0 commit comments

Comments
 (0)