Skip to content

Commit

Permalink
Change access control to implement more of CORS. Change so OPTIONS re…
Browse files Browse the repository at this point in the history
…quests don't do an actual search/reverse request
  • Loading branch information
twain47 committed Dec 17, 2012
1 parent 89af917 commit 0dd10c3
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 7 deletions.
8 changes: 8 additions & 0 deletions lib/init-website.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
<?php
require_once('init.php');

if (CONST_NoAccessControl)
{
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Methods: OPTIONS,GET");
header("Access-Control-Allow-Headers: ".$_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']);
}
if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') exit;

if (CONST_ClosedForIndexing && strpos(CONST_ClosedForIndexingExceptionIPs, ','.$_SERVER["REMOTE_ADDR"].',') === false)
{
echo "Closed for re-indexing...";
Expand Down
7 changes: 3 additions & 4 deletions lib/template/address-xml.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php
header("content-type: text/xml; charset=UTF-8");
header("Access-Control-Allow-Origin: *");

echo "<";
echo "?xml version=\"1.0\" encoding=\"UTF-8\" ?";
Expand Down Expand Up @@ -29,7 +28,7 @@
if (isset($aPlace['lon'])) echo ' lon="'.htmlspecialchars($aPlace['lon']).'"';
echo ">".htmlspecialchars($aPlace['langaddress'])."</result>";

if ($bShowAddressDetails) {
if ($bShowAddressDetails) {
echo "<addressparts>";
foreach($aAddress as $sKey => $sValue)
{
Expand All @@ -39,7 +38,7 @@
echo "</$sKey>";
}
echo "</addressparts>";
}
}
}

echo "</reversegeocode>";
2 changes: 2 additions & 0 deletions lib/template/search-json.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php
header("content-type: application/json; charset=UTF-8");

$aFilteredPlaces = array();
foreach($aSearchResults as $iResNum => $aPointDetails)
{
Expand Down
1 change: 0 additions & 1 deletion lib/template/search-xml.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php
header("content-type: text/xml; charset=UTF-8");
header("Access-Control-Allow-Origin: *");

echo "<";
echo "?xml version=\"1.0\" encoding=\"UTF-8\" ?";
Expand Down
2 changes: 1 addition & 1 deletion osm2pgsql
1 change: 1 addition & 0 deletions settings/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ function user_busy_cost()
}

// Website settings
@define('CONST_NoAccessControl', true);
@define('CONST_ClosedForIndexing', false);
@define('CONST_ClosedForIndexingExceptionIPs', '');
@define('CONST_BlockedIPs', '');
Expand Down
3 changes: 2 additions & 1 deletion website/reverse.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,9 @@
$sSQL .= " get_name_by_language(name, ARRAY['ref']) as ref,";
$sSQL .= " st_y(st_centroid(geometry)) as lat, st_x(st_centroid(geometry)) as lon";
$sSQL .= " from placex where place_id = $iPlaceID ";
//var_dump($sSQL);

$aPlace = $oDB->getRow($sSQL);
//var_dump($sSQL, $aPlace); exit;

if ($bShowAddressDetails)
{
Expand Down

0 comments on commit 0dd10c3

Please sign in to comment.