| 1 | #file:Apache2/AMFCommonLib.pm; | ||
| 2 | #-------------------------------- | ||
| 3 | |||
| 4 | # | ||
| 5 | # Created by Idel Fuschini | ||
| 6 | # Date: 15/12/09 | ||
| 7 | # Site: http://www.idelfuschini.it | ||
| 8 | # Mail: idel.fuschini@gmail.com | ||
| 9 | |||
| 10 | package Apache2::AMFCommonLib; | ||
| 11 | use strict; | ||
| 12 | use warnings; | ||
| 13 | use vars qw($VERSION); | ||
| 14 | $VERSION= "2.21"; | ||
| 15 | |||
| 16 | sub new { | ||
| 17 | my $package = shift; | ||
| 18 | return bless({}, $package); | ||
| 19 | } | ||
| 20 | |||
| 21 | |||
| 22 | sub Data { | ||
| 23 | my $_sec; | ||
| 24 | my $_min; | ||
| 25 | my $_hour; | ||
| 26 | my $_mday; | ||
| 27 | my $_day; | ||
| 28 | my $_mon; | ||
| 29 | my $_year; | ||
| 30 | my $_wday; | ||
| 31 | my $_yday; | ||
| 32 | my $_isdst; | ||
| 33 | my $_data; | ||
| 34 | ($_sec,$_min,$_hour,$_mday,$_mon,$_year,$_wday,$_yday,$_isdst) = localtime(time); | ||
| 35 | $_mon=$_mon+1; | ||
| 36 | $_year=substr($_year,1); | ||
| 37 | $_mon=&correct_number($_mon); | ||
| 38 | $_mday=&correct_number($_mday); | ||
| 39 | $_hour=&correct_number($_hour); | ||
| 40 | $_min=&correct_number($_min); | ||
| 41 | $_sec=&correct_number($_sec); | ||
| 42 | $_data="$_mday/$_mon/$_year - $_hour:$_min:$_sec"; | ||
| 43 | return $_data; | ||
| 44 | } | ||
| 45 | sub correct_number { | ||
| 46 | my ($number) = @_; | ||
| 47 | if ($number < 10) { | ||
| 48 | $number="0$number"; | ||
| 49 | } | ||
| 50 | return $number; | ||
| 51 | } | ||
| 52 | sub printLog { | ||
| 53 | my $self = shift; | ||
| 54 | if (@_) { | ||
| 55 | $self->{'printLog'} = shift; | ||
| 56 | } | ||
| 57 | my $data=Data(); | ||
| 58 | print "$data - $self->{'printLog'}\n"; | ||
| 59 | } | ||
| 60 | sub GetMultipleUa { | ||
| 61 | my $self = shift; | ||
| 62 | my $UserAgent; | ||
| 63 | if (@_) { | ||
| 64 | $UserAgent = shift; | ||
| 65 | } | ||
| 66 | my %ArrayPM; | ||
| 67 | my $pair; | ||
| 68 | my $ind=0; | ||
| 69 | my $pairs3; | ||
| 70 | my %ArrayUAparse; | ||
| 71 | my @pairs = split(/\ /, $UserAgent); | ||
| 72 | foreach $pair (@pairs) | ||
| 73 | { | ||
| 74 | if ($ind==0) { | ||
| 75 | if ($pair =~ /\//o) { | ||
| 76 | my @pairs2 = split(/\//, $pair); | ||
| 77 | foreach $pairs3 (@pairs2) { | ||
| 78 | if ($ind==0) { | ||
| 79 | $ind=$ind+1; | ||
| 80 | $ArrayUAparse{$ind}=$pairs3; | ||
| 81 | } else { | ||
| 82 | $ind=$ind+1; | ||
| 83 | $ArrayUAparse{$ind}="$ArrayUAparse{$ind-1}\/$pairs3"; | ||
| 84 | } | ||
| 85 | } | ||
| 86 | } else { | ||
| 87 | $ind=$ind+1; | ||
| 88 | $ArrayUAparse{$ind}="$pair"; | ||
| 89 | } | ||
| 90 | } else { | ||
| 91 | if ($pair =~ /\//o) { | ||
| 92 | my $ind2=0; | ||
| 93 | my @pairs2 = split(/\//, $pair); | ||
| 94 | foreach $pairs3 (@pairs2) { | ||
| 95 | if ($ind2==0) { | ||
| 96 | $ind=$ind+1; | ||
| 97 | $ind2=1; | ||
| 98 | $ArrayUAparse{$ind}="$ArrayUAparse{$ind-1} $pairs3"; | ||
| 99 | } else { | ||
| 100 | $ind=$ind+1; | ||
| 101 | $ArrayUAparse{$ind}="$ArrayUAparse{$ind-1}\/$pairs3"; | ||
| 102 | } | ||
| 103 | } | ||
| 104 | } else { | ||
| 105 | $ind=$ind+1; | ||
| 106 | $ArrayUAparse{$ind}="$ArrayUAparse{$ind-1} $pair"; | ||
| 107 | } | ||
| 108 | } | ||
| 109 | } | ||
| 110 | |||
| 111 | return %ArrayUAparse; | ||
| 112 | |||
| 113 | } | ||
| 114 | sub readCookie { | ||
| 115 | my $self = shift; | ||
| 116 | my $cookie_search; | ||
| 117 | if (@_) { | ||
| 118 | $cookie_search = shift; | ||
| 119 | } | ||
| 120 | my $param_tofound; | ||
| 121 | my $string_tofound; | ||
| 122 | my $value=""; | ||
| 123 | my $id_return=""; | ||
| 124 | my @pairs = split(/;/, $cookie_search); | ||
| 125 | my $name; | ||
| 126 | foreach $param_tofound (@pairs) { | ||
| 127 | ($string_tofound,$value)=split(/=/, $param_tofound); | ||
| 128 | if ($string_tofound eq "amf") { | ||
| 129 | $id_return=$value; | ||
| 130 | } | ||
| 131 | } | ||
| 132 | return $id_return; | ||
| 133 | } | ||
| 134 | sub extValueTag { | ||
| 135 | my $self = shift; | ||
| 136 | my ($tag,$string); | ||
| 137 | if (@_) { | ||
| 138 | $tag = shift; | ||
| 139 | $string = shift; | ||
| 140 | } | ||
| 141 | #my ($tag,$string) = @_; | ||
| 142 | my $a_tag="\<$tag"; | ||
| 143 | my $b_tag="\<\/$tag\>"; | ||
| 144 | my $finish=index($string,"\>") + 1; | ||
| 145 | my $x=$finish; | ||
| 146 | my $y=index($string,$b_tag); | ||
| 147 | my $return_tag=substr($string,$x,$y - $x); | ||
| 148 | return $return_tag; | ||
| 149 | } | ||
| 150 | |||
| 151 | |||
| 152 | |||
| 153 | =head1 NAME | ||
| 154 | |||
| 155 | Apache2::AMFCommonLib - Common Library That AMF uses. | ||
| 156 | |||
| 157 | =head1 DESCRIPTION | ||
| 158 | |||
| 159 | Is a simple Common Library for AMF | ||
| 160 | |||
| 161 | =head1 SEE ALSO | ||
| 162 | |||
| 163 | For more details: http://www.idelfuschini.it/apache-mobile-filter-v2x.html | ||
| 164 | |||
| 165 | Mobile Demo page of the filter: http://apachemobilefilter.nogoogle.it (thanks Ivan alias sigmund) | ||
| 166 | |||
| 167 | Demo page of the filter: http://apachemobilefilter.nogoogle.it/php_test.php (thanks Ivan alias sigmund) | ||
| 168 | |||
| 169 | =head1 AUTHOR | ||
| 170 | |||
| 171 | Idel Fuschini (idel.fuschini [at] gmail [dot] com) | ||
| 172 | |||
| 173 | =cut |