File: gpsmap-helper-earthamaps

package info (click to toggle)
kismet 2008-05-R1-4
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 3,232 kB
  • ctags: 3,998
  • sloc: cpp: 33,568; sh: 5,544; ansic: 459; makefile: 457; perl: 62; sql: 41
file content (97 lines) | stat: -rwxr-xr-x 2,640 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/usr/bin/perl -w

=begin comment info
 +-----------------------------------------------------------------------------+
 | Copyright 2004, Ryan W. Maple
 | $Id: gpsmap-helper-earthamaps,v 1.1 2004/03/19 20:36:00 dragorn Exp $
 |
 | This script is free software; you can redistribute it and/or modify it under
 | the terms of the GNU General Public License as published by the Free Software
 | Foundation; either version 2 of the License, or (at your option) any later
 | version.
 |
 | Ryan W. Maple <ryan@guardiandigital.com>
 |
 | By using this script you agree to the terms and conditions of Earthamaps.com
 |
 +-----------------------------------------------------------------------------+
=end comment info
=cut

  # use perl;
  use HTTP::Cookies;
  use LWP;
  use strict;

  #
  # Local prototypes.
  #
  sub USAGE();
  sub init_cookie_jar($);

  #
  # Constants
  #
  use constant DEBUG		=> 0;
  use constant EARTHAMAP_FORMAT	=> 'http://esmap1.earthamaps.com:80/map-engine/NetMap.dll?MFCISAPICommand=GeoDraw&maglevel=%d&latitude=%f&longitude=%f&session=%s&width=%d&height=%d&dataID=(null)';

  #
  # Read our arguments.
  #
  my $mapname	= shift || USAGE();
  my $lat	= shift || USAGE();
  my $long	= shift || USAGE();
  my $width	= shift || 1280;
  my $height	= shift || 1024;
  my $mag	= shift || 12;

  #
  # Instantiate our browser (LWP::UserAgent object), and initialize
  # our cookie jar.
  #
  my $browser	= new LWP::UserAgent;
  init_cookie_jar($browser);

  #
  # Do our initial GET for our cookie... yummy.
  #
  my $response	= $browser->get('http://www.earthamaps.com/');

  #
  # Extract the x-meta-mapservername header -- we'll need to pass it as
  # 'session' in our second GET, and build up our second $url.
  #
  my $tmp	= $response->{'_headers'}->{'x-meta-mapservername'};
  my ($session)	= ($tmp =~ m/session=([^\&]+)\&/);
  my $url	= sprintf(EARTHAMAP_FORMAT, $mag, $lat, $long, $session, $width,
			  $height);

  #
  # Get the map and store in $mapname.
  #
  print "Fetching URL: $url\n" if (DEBUG);
  $response	= $browser->get($url);
  open OUT, ">$mapname"; print OUT $response->{'_content'}; close OUT;

  #
  # Exit quietly.
  #
  print "Wrote: $mapname\n" if (DEBUG);
  exit 0;

################################################################################
sub USAGE() {
  print "Usage: $0 <output> <lat> <long> [<width> <height> <mag>]\n";
  exit 0;
}

################################################################################
sub init_cookie_jar($) {
  my $ref	= shift;
  my $cj	= HTTP::Cookies->new(
	'file'		=> './lwp_cookies.dat',
	'autosave'	=> 1,
  );

  return $ref->cookie_jar($cj);
}