Since my 9700 now reports its location to the server, I made a simple batch + perl script to locate a users phone, and display it in the browser/BB-maps.
below the script, feel free to use it or enhance it (if you make enhancements, please post them back).
The perl script should run on a web server which has access to the data supplied by a commandline sql query, which runs at regular intervals on the Server hosting the BESmgmt database.
It must be called with the parameter ?user=username
it then tries to find the user in the dump of the current Enterprise location enabled users. If more then one user matches the search, only the first is used.
Then, it constructs a url string for use with a standard browser or an xml file for the a Blackberry handheld.
This is sent to the users browser, which renders the map or, if you use a Blackberry, Blackberry-Maps will be opend.
With one klick, you can locate a Handheld more or less accurately, depending on the frequency the location tracking gets the data from the handhelds. No track of waypoints is drawn, but this was not my intention. I needed something to locate a lost device, or, to check someones location.
Code:
Code:
#!/usr/bin/perl
use LWP::Simple;
use CGI;
$browser = $ENV{'HTTP_USER_AGENT'};
$URL='http://192.168.0.1/bbmaps/bbmaps.txt';
$cur_timezone = " CET Time";
my $q = CGI->new;
@myparams = $q->param;
$the_username = $q->param('user');
if ( !$the_username ) {
print "Content-type: text/html\n\n";
print "<html>\n";
print "wrong arguments: must die \n";
print "</html>\n";
die;
}
unless (defined ($content = get $URL)) { die "could not get $URL\n"; }
@teststr = split(/\n/, $content);
@foundstr = grep( /$the_username/, @teststr);
@locationstr = split(/,/, @foundstr[0]);
if ( !@locationstr ) {
print "Content-type: text/html\n\n";
print "<html>\n";
print "wrong arguments: must die \n";
print "</html>\n";
die;
}
$lat = $locationstr[0] / 1;
$lon = $locationstr[1] / 1;
$my_time= $locationstr[2];
$time_string = scalar localtime($my_time);
$time_mod = scalar gmtime($my_time);
$label = $the_username." location:".$time_string.$cur_timezone;
if ( $browser =~ /BlackBerry/ )
{
$bbmaps_lbsloc = "<lbs><location lon=\'".$lon."\' lat=\'".$lat."\' label=\'$the_username ".$time_string."\' description=\'".$label."\' zoom=\'5\'/></lbs>\n";
$ll = length $bbmaps_lbsloc;
print "Content-Length: $ll\n";
print "Cache-Control: max-age=300, must-revalidate\n";
print "Last-Modified: $time_mod\n";
print "Content-Type: text/vnd.rim.location\n\n";
print "$bbmaps_lbsloc";
}
else
{
$lat = $locationstr[0] / 100000;
$lon = $locationstr[1] / 100000;
print "Content-type: text/html\n\n";
print "<HTML>\n";
print "U are using a PC ... One moment please ... transferring you to blackberry Map Gen<br>\n";
print "<META HTTP-EQUIV=\"Refresh\" Content=\"1;URL=http://maps.blackberry.com?lat=$lat&lon=$lon&z=2&label=$label\">\n";
print "<HTML>\n";
} to make the script work, you have to customize the:
Code:
$cur_timezone = " CET Time";
This is just a text which tells the Timezone on the map to look nicer. The current local time is calculated automatically.
Code:
$URL='http://192.168.0.1/bbmaps/bbmaps.txt';
The script expects that it finds here a dump of the LBS database extracted from the BES server database. It loads it using http.
In my setup, the BES server is inside a protected network, however, the server where the perl script runs, is accessible from the outside, and has http access to the BES server.
Also, I found it safer to store no actual files on the web server running the perl script.
the dump is done by this batch file:
Code:
osql -w 1000 -d BESMGMT -E -i lbs.qry -s "," -h-1 -n -o c:\bbmaps\bbmaps.txt
The "lbs.qry":
Code:
select
Latitude,
Longitude,
ServerTime,
UserConfigID,
DisplayName,
PIN
FROM SyncLBS JOIN UserConfig
ON SyncLBS.UserConfigID = UserConfig.Id
It should be enough to execute the batch file twice as often as the Enterprise location tracking frequency is set.
I found one problem: if you use a device which runs OS5.x, the correct map might not be displayed in all cases. If anyone knows why, please let me know. But, using OS6 or a standard PC/Mac works nice.
I dont know, how the batch script behaves/how much load it puts on the server if you have more then a couple of users, but given the currently availible hardware I guess there wont be a problem even with a larger user base.