#file:Apache2/AMFDeviceMonitor.pm;
#--------------------------------
#
# Created by Idel Fuschini
# Date: 15/12/09
# Site: http://www.idelfuschini.it
# Mail: idel.fuschini@gmail.com
package Apache2::AMFDeviceMonitor;
use strict;
use warnings;
use Apache2::AMFCommonLib ();
use Apache2::Filter ();
use Apache2::RequestRec ();
use APR::Table ();
use Cache::FileBackend;
use Apache2::Const -compile => qw(OK);
use constant BUFF_LEN => 1024;
use vars qw($VERSION);
$VERSION= "2.21";
#
# Define the global environment
#
my $CommonLib = new Apache2::AMFCommonLib ();
my $cachedirectorystore="notdefined";
$CommonLib->printLog("---------------------------------------------------------------------------");
$CommonLib->printLog("AMFDeviceMonitor Version $VERSION");
if ($ENV{CacheDirectoryStore}) {
$cachedirectorystore=$ENV{CacheDirectoryStore};
$CommonLib->printLog("CacheDirectoryStore is: $cachedirectorystore");
} else {
$CommonLib->printLog("CacheDirectoryStore not exist. Please set the variable CacheDirectoryStore into httpd.conf, (the directory must be writeable)");
ModPerl::Util::exit();
}
my $cacheSystem = new Cache::FileBackend( $cachedirectorystore, 3, 000 );
sub handler {
my $f = shift;
my $query_string=$f->r->args;
my $id;
my $ua;
my $capab;
my %ArrayQuery;
my %ArrayForSort;
$ArrayQuery{page}=0;
if ($query_string) {
my @vars = split(/&/, $query_string);
foreach my $var (sort @vars){
if ($var) {
my ($v,$i) = split(/=/, $var);
$v =~ tr/+/ /;
$v =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$i =~ tr/+/ /;
$i =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$i =~ s///g;
$ArrayQuery{$v}=$i;
}
}
}
unless ($f->ctx) {
$f->r->headers_out->unset('Content-Length');
$f->ctx(1);
}
$f->r->content_type('text/html');
$f->print("
Apache Mobile Filter - Device Monitor System V$VERSION");
$f->print('');
$f->print("Apache Mobile Filter
Device Monitor System V$VERSION
home | detected devices | devices not found
");
my $dummy="null";
my $count=0;
my $page_number=30;
my $min=$ArrayQuery{page};
my $max=$ArrayQuery{page} + $page_number;
my $back=$ArrayQuery{page}-$page_number;
my $forward=$ArrayQuery{page}+$page_number;
if ($ArrayQuery{form}) {
if ($ArrayQuery{form} eq "3") {
my @pairs = split(/&/, $cacheSystem->restore( 'wurfl-id', $ArrayQuery{deviceid}));
my $param_tofound;
my $string_tofound;
$f->print("| Parameter | Value |
");
foreach $param_tofound (@pairs) {
($string_tofound,$dummy)=split(/=/, $param_tofound);
$f->print("| $string_tofound | $dummy |
");
}
$f->print("
");
} else {
if ($ArrayQuery{form} eq "1") {
$f->print('');
}
$f->print("");
$f->print("| n. | device id | User Agent |
");
foreach $ua ( sort $cacheSystem->get_keys( 'wurfl-ua' ) )
{
$id =$cacheSystem->restore( 'wurfl-ua', $ua );
if ($ArrayQuery{form} eq "2" && $id eq 'device_not_found'){
$count++;
if ($count > $min - 1 && $count < $max + 1) {
$f->print("| $count | $id | $ua |
");
}
}
if ($ArrayQuery{form} eq "1" && $id ne 'device_not_found') {
if ($ArrayQuery{search}) {
if ($id =~ m/$ArrayQuery{search}/i) {
$count++;
if ($count > $min && $count < $max + 1) {
$f->print("| $count | $id | $ua |
");
}
}
} else {
$count++;
if ($count > $min - 1 && $count < $max + 1) {
$f->print("| $count | $id | $ua |
");
}
}
}
}
}
$f->print("
");
if ( $min > 0) {
$f->print("| back | ");
}
if ($forward < $count) {
$f->print("forward> | ");
}
$f->print("
");
} else {
$f->print('
');
}
return Apache2::Const::OK;
}
1;
=head1 NAME
Apache2::AMFDeviceMonitor - This module is an admin tool to control the devices access that Apache Mobile Filter has detected.
=head1 COREQUISITES
Apache2::Filter ();
Apache2::RequestRec ();
APR::Table ();
Cache::FileBackend;
=head1 DESCRIPTION
This module is an admin tool to control the devices access that Apache Mobile Filter has detected.
For more details: http://www.idelfuschini.it/apache-mobile-filter-v2x.html
An example of how to set the httpd.conf is below:
=over 4
=item C
=back
NOTE: this software need carrier-data.txt you can download it directly from this site: http://www.andymoore.info/carrier-data.txt or you can set the filter to download it directly.
=head1 SEE ALSO
For more details: http://www.idelfuschini.it/apache-mobile-filter-v2x.html
Mobile Demo page of the filter: http://apachemobilefilter.nogoogle.it (thanks Ivan alias sigmund)
Demo page of the filter: http://apachemobilefilter.nogoogle.it/php_test.php (thanks Ivan alias sigmund)
=head1 AUTHOR
Idel Fuschini (idel.fuschini [at] gmail [dot] com)
=cut