77 if (!empty($inQuery)) {
79 $path = $inIsCLI ? dirname($_SERVER[
'argv'][0]) :
"";
80 if (!empty($inQuery)) {
81 $queryArray = explode(
'&', $inQuery);
83 foreach ($queryArray as $param) {
88 $parts = explode(
'=', $param, 2);
90 if (1 < count($parts)) {
91 $key = trim($parts[0]);
92 $value = trim($parts[1]);
100 $queries[$key] = $value;
104 if (!empty($queries)) {
105 $authorized = !isset($g_server_secret) || $g_server_secret ===
'' ||
106 (isset($queries[
'secret']) && is_string($queries[
'secret']) && hash_equals((
string)$g_server_secret, $queries[
'secret']));
108 $db_object =
new LGV_TZ_Lookup_Database($g_dbName, $g_dbUserName, $g_dbPassword, $g_dbType, $g_dbHost, $g_dbPort);
109 if (isset($queries[
'test'])) {
110 $ret =
'<html><head><style>.pass{color:green}.fail{color:red}</style></head><body>'.test_server().
'</body></html>';
111 } elseif (isset($queries[
'load'])) {
114 $stream = fopen(
"$path/combined-with-oceans.json",
'r');
118 require_once __DIR__.
'/Sources/LGV_TZ_Lookup_Loader.class.php';
120 $parser = new \JsonStreamingParser\Parser($stream, $listener);
124 }
catch (Exception $e) {
129 $ret =
'Only Available Through CLI';
130 header(
'HTTP/1.1 403 Not Authorized');
132 } elseif (!empty($queries[
'll'])) {
133 $long_lat = explode(
',', $queries[
'll']);
134 if (2 == count($long_lat) && isset($long_lat[0]) && isset($long_lat[1])) {
135 $lng = floatval($long_lat[0]);
136 $lat = floatval($long_lat[1]);
139 while (-180 > $lng) { $lng += 360; }
140 while (180 < $lng) { $lng -= 360; }
141 while (-90 > $lat) { $lat += 180; }
142 while (90 < $lat) { $lat -= 180; }
145 $ret =
$lookup->get_tz($lng, $lat);
150 $ret =
'Malformed Query';
151 header(
'HTTP/1.1 400 Malformed Query');
154 } elseif (isset($g_server_secret)) {
155 $ret =
'Ah - Ah - Aaaah! You didn\'t say the magic word!';
156 if (
"cli" != php_sapi_name()) {
157 header(
'HTTP/1.1 403 Not Authorized');
160 $ret =
'Illegal Query';
161 if (
"cli" != php_sapi_name()) {
162 header(
'HTTP/1.1 400 Illegal Query');
167 $ret =
'Illegal Query';
168 header(
'HTTP/1.1 400 Illegal Query');
175 $secret_note = isset($g_server_secret) && !empty($g_server_secret) ?
"\n\n\tNOTE: This server has a \"secret\" set\n\n\tThis means that you will need to provide an additional string in each call. Please contact the administrator of this server to obtain the secret." :
"";
176 $ret =
"Usage: \$> php ".__FILE__.
" load\n\n\tInitializes the database from the GeoJSON file.\n\tIt will return 1, if successful, 0, if not. It may take some time.$secret_note\n";
178 $s = (isset($_SERVER[
'HTTPS']) && !empty($_SERVER[
'HTTPS'])) ?
"s" :
"";
179 $secret_note = isset($g_server_secret) && !empty($g_server_secret) ?
"<em><h4>NOTE: This server has a \"secret\" set</h4><p>This means that you will need to provide an additional string in each call. Please contact the administrator of this server to obtain the secret.</p></em>" :
"";
180 $ret =
"<html><head><title>Using LGV_TZ_Lookup</title></head><body><pre>Usage: http$s://".$_SERVER[
'HTTP_HOST'].$_SERVER[
'REQUEST_URI'].
"?ll=<em style='color:gray'><LONG>,<LAT></em>\n\n\tThis is the standard query. Provide the requested long/lat, as comma-delimited floating-point numbers, between -180 and 180.\n\tThe response will be <a href='https://en.wikipedia.org/wiki/List_of_tz_database_time_zones'>the TZ name</a> of the timezone that contains that point. It will be a simple string.</pre>$secret_note</body></html>";