BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 03-08-2011, 06:39 PM   #1 (permalink)
BlackBerry Extraordinaire
 
Join Date: Mar 2006
Model: 9700
Carrier: t-mobile Germany
Posts: 1,366
Post Thanks: 11
Thanked 69 Times in 66 Posts
Lightbulb A simple "find a user/device" script for Enterprise location Tracking:

Please Login to Remove!

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.

Last edited by nobody7290 : 03-08-2011 at 06:42 PM.
Offline  
Old 03-08-2011, 09:34 PM   #2 (permalink)
BlackBerry Elite
 
knottyrope's Avatar
 
Join Date: Jan 2008
Location: Massachusetts
Model: Passp
OS: 10.2.1
PIN: t of blood has been taken
Carrier: AT&T-US with I dee ten tee errors
Posts: 6,796
Post Thanks: 283
Thanked 300 Times in 284 Posts
Default Re: A simple "find a user/device" script for Enterprise location Tracking:

Can you make it so it will update a google map?

I would llike to have this be shown on a big screen monitor in our office to show our customers were our techs are. make it look like we care more.
__________________
irony : many old timer posters have de-evolved into the trolls they once fought
I am on http://supportforums.blackberry.com
BES 10 running sweet for my Passport, Z30, Z10 and Q10
Offline  
Old 03-09-2011, 04:46 AM   #3 (permalink)
BlackBerry Extraordinaire
 
Join Date: Mar 2006
Model: 9700
Carrier: t-mobile Germany
Posts: 1,366
Post Thanks: 11
Thanked 69 Times in 66 Posts
Default Re: A simple "find a user/device" script for Enterprise location Tracking:

If you want to use gmaps for rendering the map use this:
However, Blackberry maps will work also, even if you do not use a Blackberry.

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";
# set to 1 to use google maps for rendering the location if you use a Desktop PC
$use_gmaps = 1;

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";
        if ( $use_gmaps == 1) 
	{
		print "U are using a PC ... One moment please ... transferring you to googlemaps<br>\n";
		print "<META HTTP-EQUIV=\"Refresh\" Content=\"1;URL=http://maps.google.com?q=$lat,$lon\">\n";
	}
	else
        {
		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";

}

Last edited by nobody7290 : 03-09-2011 at 04:47 AM.
Offline  
Old 03-09-2011, 06:53 AM   #4 (permalink)
BlackBerry Extraordinaire
 
Join Date: Mar 2006
Model: 9700
Carrier: t-mobile Germany
Posts: 1,366
Post Thanks: 11
Thanked 69 Times in 66 Posts
Default Re: A simple "find a user/device" script for Enterprise location Tracking:

where it reads:
Code:
print "<META HTTP-EQUIV=\"Refresh\" Content=\"1;URL=http://maps.google.com?q=$lat,$lon\">\n";
replace with:
Code:
print "<META HTTP-EQUIV=\"Refresh\" Content=\"1;URL=http://maps.google.com?q=$lat,$lon\($label\)\">\n";
to see the user/time information in the google maps link
Offline  
Old 07-05-2011, 09:25 AM   #5 (permalink)
New Member
 
Join Date: Jun 2009
Model: 9700
PIN: N/A
Carrier: T-Mobile
Posts: 3
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default Re: A simple "find a user/device" script for Enterprise location Tracking:

Hi,
I am having a little difficulty in getting this script to work as you suggest, I wonder if you would be able to highlight where I am going wrong.
What doesn't help is I have never looked at Perl before, so a ground up reply would be great.

Firstly I have Perl installed and after testing it is reporting fine.
{
#!/usr/bin/perl
print "Hello World.\n";
}
How do I build your script in to a working file? Should I run it from a command prompt or via HTTP? If http how do I do that?
How do you tell it which user you want it to report on?

Also how do you get the blackberry server to respond to http requests for the osql query? It works fine if I run that file locally on the BES, populates a text file but with only two users. But it is something I can copy across to the desktop that runs the perl. Also I am planning to run this only internally.

Kindest regards,

K.
Offline  
Old 07-05-2011, 11:02 AM   #6 (permalink)
BlackBerry Extraordinaire
 
Join Date: Mar 2006
Model: 9700
Carrier: t-mobile Germany
Posts: 1,366
Post Thanks: 11
Thanked 69 Times in 66 Posts
Default Re: A simple "find a user/device" script for Enterprise location Tracking:

to access the perl script you have to install a webserver.
That might be a linux/apache based or Windows IIS server.
I have never setup perl with IIS, but here:
HOW TOxxx58; Configure and Test a PERL Script with IIS 4.0, 5.0, 5.1, and 6.0
is something from microsoft how to integrate perl and IIS

If you run perl within apache, you typically have a directory /cgi-bin/ where your scripts are located. A standard install of linux and apache should also install perl.
accessing the server with http://some.interet.addr.com/cgi-bin/scriptname.cgi
will execute the script.

The dump of the sql database most likely only gives you 2 records, because only for 2 users currently the enterprise location tracking is enabled.
Let a cronjob execute the dump every 5 minutes on the Windows machine where the database is runnin, and, dump it in a directory where someone is able to access the file using a browser (create a new virtual directory in IIIS, make sure, only authorized people can access it), and, in the perl script replace:
$URL='http://192.168.0.1/bbmaps/bbmaps.txt'
with the location of the actual URL

if you then access the server where the perl script is located by:

http://some.interet.addr.com/cgi-bin...?user=username

you should see a map either generated by blackberry maps or by google maps with the location of the username user.

Does that help for a start ?
Offline  
Old 07-26-2011, 10:45 AM   #7 (permalink)
New Member
 
Join Date: Jun 2009
Model: 9700
PIN: N/A
Carrier: T-Mobile
Posts: 3
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default Re: A simple "find a user/device" script for Enterprise location Tracking:

Hi,
I have installed Apache2.2 and Php 5.2.5 on to Windows 7 desktop computer, which is working when I test it with the PHP script, however the script to view the map just returns a server error.
Can you advise where I might be going wrong?
Internal Server Error

"The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator, admin@********** and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log."

I had a look and couldn't see anything.
If you could offer some assistance that would be great.
Offline  
Old 07-26-2011, 02:55 PM   #8 (permalink)
BlackBerry Extraordinaire
 
Join Date: Mar 2006
Model: 9700
Carrier: t-mobile Germany
Posts: 1,366
Post Thanks: 11
Thanked 69 Times in 66 Posts
Default Re: A simple "find a user/device" script for Enterprise location Tracking:

the script needs no php but perl.
But from your previous post, it looks like you sucessful installed perl.

Maybe you do not have set the "script Alias" in apache for the execution of scripts.
Or the "ExecCgi" statment is not added to the directory where your script is located ?

here:
How to install Perl on Windows | ricocheting.com
Offline  
Closed Thread


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads for: A simple "find a user/device" script for Enterprise location Tracking:
Thread Thread Starter Forum Replies Last Post
Enterprise location tracking now working with 6.0.0.461 nobody7290 BES Admin Corner 13 04-07-2011 04:21 PM
bbTracker - a simple GPS tracking software saua GPS & Mapping 473 03-22-2010 08:39 AM
Location based tracking rlafata GPS & Mapping 0 07-01-2009 04:03 PM
Location Based Services (LBS) otherwise known as GPS Policies TargetIT BES Admin Corner 5 01-12-2009 08:54 AM
usage of location tracking f0rd42 BES Admin Corner 7 10-07-2008 12:24 PM





Copyright 2004-2014 BlackBerryForums.com.
The names RIM and BlackBerry are registered Trademarks of BlackBerry Inc.