I have an kml source that needs multiple parameters, like:
http://www.thesite.com/ws?var1=a&var2=b

The map is not showing the contents of the kml file because my html source containts:
http://www.thesite.com/ws?var1=a\x26var2=b

So the & sign is replaced by \x26. I cannot find where this replacement is done in the module.

Is this a bug, or am I doing something wrong?

Comments

phayes’s picture

1. Where in your html do you see this url?

2. Are you trying to access kml that is on a different domain name from the page that is requesting it1. ?

3. Do you have firebug installed? Could you check for errors in the console with it?

cronix’s picture

1. I see the url when I do a view source of the page that should show the map. The url is in the jQuery.extend(Drupal.settings,.... line

2. Yes the domain is on a different server. I am using a service that returns a kml file based on the input parameters that I am trying to send.

3. I am not getting any additional errors. Its just that the & sign is substituted and I think it shouldn't be substituted.

Is there a place in the code that substitutes the & sign? Maybe I can try a hardcoded fix in order to check things out?

phayes’s picture

Category: bug » feature

Your problem is not with the URL encoding. It's the cross site request.

1. jQuery.extend(Drupal.settings,.... line encodes special characters, and will decode them properly when that is run through jquery.

2. Your problem is you may not request KML on a different domain. This is considered an XSS vulnerability, and all modern browsers prevent it. See http://en.wikipedia.org/wiki/Cross-site_scripting for more details.

Your only solution at this point is to use a local proxy on the same domain that will make the request to the foreign domain for you.

tmcw’s picture

I would argue that in the 'easy KML' mode of 0.x.2.x.whatever, we should support ProxyHost so that if anyone builds a simple proxy in Drupal then we can immediately support remote KML.

phayes’s picture

I agree. I wonder if there are any good php based proxies out there? That might actually make a good standalone module quite apart from openlayers.

cronix’s picture

I have solved the problemy by building a poor-mans-cache. The code needs more work, error handling is not included yet. I am not a php developer, but the following is what I am working on:

function openlayers_get_cache($url, $filetype)
{
  $drupal_install_dir = '/var/www/httpdocs';
  $openlayers_cache_dir = '/sites/default/files/openlayers_ws_cache/'; // Directory must exist 

  $result = db_query("select redirect_url from openlayers_ws_caches where url = '%s' ", $url);

  while ($cache = db_fetch_object($result )) {
    return $cache->redirect_url;
  }

  // File not found in cache. Lets create it
  $filename = $openlayers_cache_dir . substr(md5(uniqid(rand(), true)), 0, 20) . '.' . $filetype; // 20 should be enough
  $fp = fopen($drupal_install_dir . $filename , 'w') or die("can't open file:" . $drupal_install_dir . $filename . "<br>"); 
  fwrite ($fp, file_get_contents($url));
  fclose($fp);

  db_query("insert into openlayers_ws_caches(url, cache_file, redirect_url) values ('%s', '%s', '%s')", $url, $drupal_install_dir . $filename, $filename);

  return $filename;
}

This is based on the following table

create table openlayers_ws_caches(
  url          varchar(1000) primary key,
  cache_file   varchar(500),
  redirect_url varchar(250),
  date_created timestamp(8) default now()
);

Current issues that I need to implement:

  • Cache clearing code. My kml don't need to be refreshed very often. I am thinking about making this configurable per service that I am using.
  • It's not a module. I am using this code directly in my panels page.
  • Off-topic. I had to hard code the $drupal_install_dir because $base_path doesn't return a value in my page.

I think a proxy like functionality would be great to have in OpenLayers, but maybe something like this based on simple caching can be considered too?

zzolo’s picture

Status: Active » Closed (fixed)

Closing. It seems like @conix has begun to solve his own problem, and proxy support is not in scope of 1.x. Started issue here for 2.x: #615968: Document Proxy Possibilty