| 1 | #file:Apache2/AMFDeviceMonitor.pm; | ||
| 2 | #-------------------------------- | ||
| 3 | |||
| 4 | # | ||
| 5 | # Created by Idel Fuschini | ||
| 6 | # Date: 01/08/10 | ||
| 7 | # Site: http://www.apachemobilefilter.org | ||
| 8 | # Mail: idel.fuschini@gmail.com | ||
| 9 | |||
| 10 | package Apache2::AMFDeviceMonitor; | ||
| 11 | |||
| 12 | use strict; | ||
| 13 | use warnings; | ||
| 14 | use Apache2::AMFCommonLib (); | ||
| 15 | |||
| 16 | use Apache2::Filter (); | ||
| 17 | use Apache2::RequestRec (); | ||
| 18 | use APR::Table (); | ||
| 19 | use Cache::FileBackend; | ||
| 20 | |||
| 21 | use Apache2::Const -compile => qw(OK); | ||
| 22 | |||
| 23 | use constant BUFF_LEN => 1024; | ||
| 24 | use vars qw($VERSION); | ||
| 25 | $VERSION= "4.33";;; | ||
| 26 | # | ||
| 27 | # Define the global environment | ||
| 28 | # | ||
| 29 | my $CommonLib = new Apache2::AMFCommonLib (); | ||
| 30 | my $cachedirectorystore="notdefined"; | ||
| 31 | |||
| 32 | $CommonLib->printLog("---------------------------------------------------------------------------"); | ||
| 33 | $CommonLib->printLog("AMFDeviceMonitor Version $VERSION"); | ||
| 34 | |||
| 35 | if ($ENV{CacheDirectoryStore}) { | ||
| 36 | $cachedirectorystore=$ENV{CacheDirectoryStore}; | ||
| 37 | $CommonLib->printLog("CacheDirectoryStore is: $cachedirectorystore"); | ||
| 38 | } else { | ||
| 39 | $CommonLib->printLog("CacheDirectoryStore not exist. Please set the variable CacheDirectoryStore into httpd.conf, (the directory must be writeable)"); | ||
| 40 | ModPerl::Util::exit(); | ||
| 41 | } | ||
| 42 | my $cacheSystem = new Cache::FileBackend( $cachedirectorystore, 3, 000 ); | ||
| 43 | |||
| 44 | sub handler { | ||
| 45 | my $f = shift; | ||
| 46 | my $query_string=$f->args; | ||
| 47 | my $id; | ||
| 48 | my $ua; | ||
| 49 | my $capab; | ||
| 50 | my %ArrayQuery; | ||
| 51 | my %ArrayForSort; | ||
| 52 | $ArrayQuery{page}=0; | ||
| 53 | if ($query_string) { | ||
| 54 | my @vars = split(/&/, $query_string); | ||
| 55 | foreach my $var (sort @vars){ | ||
| 56 | if ($var) { | ||
| 57 | my ($v,$i) = split(/=/, $var); | ||
| 58 | $v =~ tr/+/ /; | ||
| 59 | $v =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; | ||
| 60 | $i =~ tr/+/ /; | ||
| 61 | $i =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; | ||
| 62 | $i =~ s/<!--(.|\n)*-->//g; | ||
| 63 | $ArrayQuery{$v}=$i; | ||
| 64 | } | ||
| 65 | } | ||
| 66 | } | ||
| 67 | |||
| 68 | my $page_html="<title>Apache Mobile Filter - Device Monitor System V$VERSION</title>"; | ||
| 69 | $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 "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif;text-align: right;}th {font: bold 11px "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif;color: #4f6b72;border-right: 1px solid #C1DAD7;border-bottom: 1px solid #C1DAD7;border-top: 1px solid #C1DAD7;letter-spacing: 2px;text-transform: uppercase;text-align: left;padding: 6px 6px 6px 12px;background: #CAE8EA url(images/bg_header.jpg) no-repeat;}th.nobg {border-top: 0;border-left: 0;border-right: 1px solid #C1DAD7;background: none;}td {border-right: 1px solid #C1DAD7;border-bottom: 1px solid #C1DAD7;background: #fff;padding: 6px 6px 6px 12px;color: #4f6b72;}td.alt {background: #F5FAFA;color: #797268;}th.spec {border-left: 1px solid #C1DAD7;border-top: 0;background: #fff url(images/bullet1.gif) no-repeat;font: bold 10px "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif;}th.specalt {border-left: 1px solid #C1DAD7;border-top: 0;background: #f5fafa url(images/bullet2.gif) no-repeat;font: bold 10px "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif;color: #797268;}</style>'; | ||
| 70 | $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>"; | ||
| 71 | my $dummy="null"; | ||
| 72 | my $count=0; | ||
| 73 | my $page_number=30; | ||
| 74 | my $min=$ArrayQuery{page}; | ||
| 75 | my $max=$ArrayQuery{page} + $page_number; | ||
| 76 | my $back=$ArrayQuery{page}-$page_number; | ||
| 77 | my $forward=$ArrayQuery{page}+$page_number; | ||
| 78 | |||
| 79 | if ($ArrayQuery{form}) { | ||
| 80 | if ($ArrayQuery{form} eq "3") { | ||
| 81 | my @pairs = split(/&/, $cacheSystem->restore( 'wurfl-id', $ArrayQuery{deviceid})); | ||
| 82 | my $param_tofound; | ||
| 83 | my $string_tofound; | ||
| 84 | $page_html=$page_html."<table><tr><td>Parameter</td><td>Value</td></tr>"; | ||
| 85 | foreach $param_tofound (@pairs) { | ||
| 86 | ($string_tofound,$dummy)=split(/=/, $param_tofound); | ||
| 87 | $page_html=$page_html."<tr><td>$string_tofound</td><td>$dummy</td></tr>"; | ||
| 88 | } | ||
| 89 | $page_html=$page_html."</table>"; | ||
| 90 | } else { | ||
| 91 | if ($ArrayQuery{form} eq "1") { | ||
| 92 | $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>'; | ||
| 93 | } | ||
| 94 | $page_html=$page_html."<table>"; | ||
| 95 | $page_html=$page_html."<tr><td>n.</td><td>device id</td><td>User Agent</td></tr>"; | ||
| 96 | foreach $ua ( sort $cacheSystem->get_keys( 'wurfl-ua' ) ) | ||
| 97 | { | ||
| 98 | $id =$cacheSystem->restore( 'wurfl-ua', $ua ); | ||
| 99 | if ($ArrayQuery{form} eq "2" && $id eq 'device_not_found'){ | ||
| 100 | $count++; | ||
| 101 | if ($count > $min - 1 && $count < $max + 1) { | ||
| 102 | |||
| 103 | $page_html=$page_html."<tr><td>$count</td><td>$id</td><td>$ua</td></tr>"; | ||
| 104 | } | ||
| 105 | |||
| 106 | } | ||
| 107 | if ($ArrayQuery{form} eq "1" && $id ne 'device_not_found') { | ||
| 108 | if ($ArrayQuery{search}) { | ||
| 109 | if ($id =~ m/$ArrayQuery{search}/i) { | ||
| 110 | $count++; | ||
| 111 | if ($count > $min && $count < $max + 1) { | ||
| 112 | $page_html=$page_html."<tr><td>$count</td><td><a href=\"?form=3&deviceid=$id\">$id</a></td><td>$ua</td></tr>"; | ||
| 113 | } | ||
| 114 | |||
| 115 | } | ||
| 116 | } else { | ||
| 117 | $count++; | ||
| 118 | if ($count > $min - 1 && $count < $max + 1) { | ||
| 119 | $page_html=$page_html."<tr><td>$count</td><td><a href=\"?form=3&deviceid=$id\">$id</a></td><td>$ua</td></tr>"; | ||
| 120 | } | ||
| 121 | } | ||
| 122 | |||
| 123 | } | ||
| 124 | } | ||
| 125 | } | ||
| 126 | $page_html=$page_html."</table><center><table><tr>"; | ||
| 127 | |||
| 128 | if ( $min > 0) { | ||
| 129 | $page_html=$page_html."<td><a href=\"?form=$ArrayQuery{form}&page=$back\">back</a></td>"; | ||
| 130 | } | ||
| 131 | if ($forward < $count) { | ||
| 132 | $page_html=$page_html."<td><a href=\"?form=$ArrayQuery{form}&page=$forward\">forward></a></td>"; | ||
| 133 | } | ||
| 134 | $page_html=$page_html."</tr></table></center>"; | ||
| 135 | } else { | ||
| 136 | $page_html=$page_html.'<br><br><br><br><center><table><tr><td><H1>Apache Mobile Filter</H1>Open Source Project: <a href="http://www.idelfuschini.it/en/apache-mobile-filter-v2x.html">http://www.idelfuschini.it/en/apache-mobile-filter-v2x.html</a></td></tr></table>'; | ||
| 137 | } | ||
| 138 | my $len_bytes=length $page_html; | ||
| 139 | $f->headers_out->set("Content-Length"=>$len_bytes); | ||
| 140 | $f->headers_out->set("Last-Modified" => time()); | ||
| 141 | $f->content_type('text/html'); | ||
| 142 | $f->print($page_html); | ||
| 143 | return Apache2::Const::OK; | ||
| 144 | } | ||
| 145 | 1; | ||
| 146 | |||
| 147 | |||
| 148 | =head1 NAME | ||
| 149 | |||
| 150 | Apache2::AMFDeviceMonitor - This module is an admin tool to control the devices access that Apache Mobile Filter has detected. | ||
| 151 | |||
| 152 | =head1 DESCRIPTION | ||
| 153 | |||
| 154 | This module is an admin tool to control the devices access that Apache Mobile Filter has detected. | ||
| 155 | |||
| 156 | =head1 AMF PROJECT SITE | ||
| 157 | |||
| 158 | http://www.apachemobilefilter.org | ||
| 159 | |||
| 160 | =head1 DOCUMENTATION | ||
| 161 | |||
| 162 | http://wiki.apachemobilefilter.org | ||
| 163 | |||
| 164 | Perl Module Documentation: http://wiki.apachemobilefilter.org/index.php/AMFDeviceMonitor | ||
| 165 | |||
| 166 | =head1 AUTHOR | ||
| 167 | |||
| 168 | Idel Fuschini (idel.fuschini [at] gmail [dot] com) | ||
| 169 | |||
| 170 | =head1 COPYRIGHT | ||
| 171 | |||
| 172 | You may distribute under the terms of either the GNU General Public | ||
| 173 | License or the Artistic License, as specified in the Perl README file. | ||
| 174 | |||
| 175 | =cut |