Apache2-ApacheMobileFilter
view release on metacpan or search on metacpan
lib/Apache2/AMFDeviceMonitor.pm view on Meta::CPAN
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= "4.33";;;
#
# 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->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/<!--(.|\n)*-->//g;
$ArrayQuery{$v}=$i;
}
}
}
my $page_html="<title>Apache Mobile Filter - Device Monitor System V$VERSION</title>";
$page_html=$page_html.'<style type="text/css">body {font: normal 11px auto "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif;color: #4f6b72;background: #E6EAE9}a {color: #c75f3e}caption {padding: 0 0 5px 0;width: 700px; font: italic 11px "...
$page_html=$page_html."<b>Apache Mobile Filter</b><br>Device Monitor System V$VERSION<HR><a href=\"?\">home</a> | <a href=\"?form=1\">detected devices</a> | <a href=\"?form=2\">devices not found</a><hr>";
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;
$page_html=$page_html."<table><tr><td>Parameter</td><td>Value</td></tr>";
foreach $param_tofound (@pairs) {
($string_tofound,$dummy)=split(/=/, $param_tofound);
$page_html=$page_html."<tr><td>$string_tofound</td><td>$dummy</td></tr>";
}
$page_html=$page_html."</table>";
} else {
if ($ArrayQuery{form} eq "1") {
$page_html=$page_html.'<form action="" method=get>Search device id <input type="text" name="search"><input type="hidden" name="form" value="1"><input type=submit></form>';
}
$page_html=$page_html."<table>";
$page_html=$page_html."<tr><td>n.</td><td>device id</td><td>User Agent</td></tr>";
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) {
$page_html=$page_html."<tr><td>$count</td><td>$id</td><td>$ua</td></tr>";
}
}
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) {
$page_html=$page_html."<tr><td>$count</td><td><a href=\"?form=3&deviceid=$id\">$id</a></td><td>$ua</td></tr>";
}
}
} else {
$count++;
if ($count > $min - 1 && $count < $max + 1) {
$page_html=$page_html."<tr><td>$count</td><td><a href=\"?form=3&deviceid=$id\">$id</a></td><td>$ua</td></tr>";
}
}
}
}
}
$page_html=$page_html."</table><center><table><tr>";
if ( $min > 0) {
$page_html=$page_html."<td><a href=\"?form=$ArrayQuery{form}&page=$back\">back</a></td>";
( run in 2.258 seconds using v1.01-cache-2.11-cpan-d8267643d1d )