]> git.openstreetmap.org Git - nominatim.git/blob - lib/init-website.php
d8c012a422152232853b07c09f431352398b54b7
[nominatim.git] / lib / init-website.php
1 <?php
2
3 require_once('init.php');
4 require_once('ParameterParser.php');
5
6 /***************************************************************************
7  *
8  * Error handling functions
9  *
10  */
11
12
13 function chksql($oSql, $sMsg = 'Database request failed')
14 {
15     if (!PEAR::isError($oSql)) return $oSql;
16
17     header('HTTP/1.0 500 Internal Server Error');
18     header('Content-type: text/html; charset=utf-8');
19
20     $sSqlError = $oSql->getMessage();
21
22     echo <<<INTERNALFAIL
23 <html>
24   <head><title>Internal Server Error</title></head>
25   <body>
26     <h1>Internal Server Error</h1>
27     <p>Nominatim has encountered an internal error while accessing the database.
28        This may happen because the database is broken or because of a bug in
29        the software. If you think it is a bug, feel free to report
30        it over on <a href="https://github.com/openstreetmap/Nominatim/issues">
31        Github</a>. Please include the URL that caused the problem and the
32        complete error details below.</p>
33     <p><b>Message:</b> $sMsg</p>
34     <p><b>SQL Error:</b> $sSqlError</p>
35     <p><b>Details:</b> <pre>
36 INTERNALFAIL;
37
38     if (CONST_Debug) {
39         var_dump($oSql);
40     } else {
41         echo "<pre>\n".$oSql->getUserInfo().'</pre>';
42     }
43
44     echo '</pre></p></body></html>';
45     exit;
46 }
47
48 function failInternalError($sError, $sSQL = false, $vDumpVar = false)
49 {
50     header('HTTP/1.0 500 Internal Server Error');
51     header('Content-type: text/html; charset=utf-8');
52     echo '<html><body><h1>Internal Server Error</h1>';
53     echo '<p>Nominatim has encountered an internal error while processing your request. This is most likely because of a bug in the software.</p>';
54     echo '<p><b>Details:</b> '.$sError,'</p>';
55     echo '<p>Feel free to file an issue on <a href="https://github.com/openstreetmap/Nominatim/issues">Github</a>. ';
56     echo 'Please include the error message above and the URL you used.</p>';
57     if (CONST_Debug) {
58         echo '<hr><h2>Debugging Information</h2><br>';
59         if ($sSQL) {
60             echo '<h3>SQL query</h3><code>'.$sSQL.'</code>';
61         }
62         if ($vDumpVar) {
63             echo '<h3>Result</h3> <code>';
64             var_dump($vDumpVar);
65             echo '</code>';
66         }
67     }
68     echo "\n</body></html>\n";
69     exit;
70 }
71
72
73 function userError($sError)
74 {
75     header('HTTP/1.0 400 Bad Request');
76     header('Content-type: text/html; charset=utf-8');
77     echo '<html><body><h1>Bad Request</h1>';
78     echo '<p>Nominatim has encountered an error with your request.</p>';
79     echo '<p><b>Details:</b> '.$sError.'</p>';
80     echo '<p>If you feel this error is incorrect feel file an issue on <a href="https://github.com/openstreetmap/Nominatim/issues">Github</a>. ';
81     echo 'Please include the error message above and the URL you used.</p>';
82     echo "\n</body></html>\n";
83     exit;
84 }
85
86
87 /***************************************************************************
88  * HTTP Reply header setup
89  */
90
91 if (CONST_NoAccessControl) {
92     header('Access-Control-Allow-Origin: *');
93     header('Access-Control-Allow-Methods: OPTIONS,GET');
94     if (!empty($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS'])) {
95         header('Access-Control-Allow-Headers: '.$_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']);
96     }
97 }
98 if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') exit;
99
100 if (CONST_Debug) header('Content-type: text/html; charset=utf-8');