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