3 * SPDX-License-Identifier: GPL-2.0-only
5 * This file is part of Nominatim. (https://nominatim.org)
7 * Copyright (C) 2022 by the Nominatim developer community.
8 * For a full list of authors see the git log.
11 require_once(CONST_LibDir.'/init-website.php');
12 require_once(CONST_LibDir.'/ParameterParser.php');
13 require_once(CONST_LibDir.'/Status.php');
15 $oParams = new Nominatim\ParameterParser();
16 $sOutputFormat = $oParams->getSet('format', array('text', 'json'), 'text');
18 $oDB = new Nominatim\DB(CONST_Database_DSN);
20 if ($sOutputFormat == 'json') {
21 header('content-type: application/json; charset=UTF-8');
26 $oStatus = new Nominatim\Status($oDB);
29 if ($sOutputFormat == 'json') {
30 $epoch = $oStatus->dataDate();
34 'server' => gethostname(),
35 'data_updated' => (new DateTime('@'.$epoch))->format(DateTime::RFC3339),
36 'software_version' => CONST_NominatimVersion
38 $sDatabaseVersion = $oStatus->databaseVersion();
39 if ($sDatabaseVersion) {
40 $aResponse['database_version'] = $sDatabaseVersion;
42 javascript_renderData($aResponse);
46 } catch (Exception $oErr) {
47 if ($sOutputFormat == 'json') {
49 'status' => $oErr->getCode(),
50 'message' => $oErr->getMessage(),
51 'server' => gethostname()
53 javascript_renderData($aResponse);
55 header('HTTP/1.0 500 Internal Server Error');
56 echo 'ERROR: '.$oErr->getMessage();