Changes to awstats.pl 7.0 - code

Developers
Andres
2011-05-20
2012-10-11
  • Andres
    Andres
    2011-05-20

    Hi,

    First of all let me apologize if this is not the correct place to post any of
    this information. I really wish to share it with the project developers and
    hopefully get more familiar with helping with this tool.

    I was recently requested by work to generate statistics about mobile devices,
    now this is not the first time I modify the awstats.pl file, but this would be
    a first for sharing.

    on the area for "# Define precompiled regex" I added a few new variables:

        my $regverosiphone  = qr/iPhone[_+ ]OS[_+ ]([\d_]*)/i;      # iPhone OS version
        my $regverosipad    = qr/iPad.*CPU[_+ ]OS[_+ ]([\d_\.]+)/i;     # iPad OS Version
        my $regverosblackberry  = qr/blackberry[_+ ]*([\d]+)/i;         # Blackberry OS version
        my $regverosrimtablet   = qr/PlayBook.*RIM[_+ ]Tablet[_+ ]OS[_+ ]([\d\.]*)/i;   # Playbook RIM Tablet OS
        my $regverosandroid = qr/Linux.*Android[_+ ]([\d\.]+)/i;        # Android OS Version (No Build)
        my $regverosmac     = qr/mac[_+ ]os[_+ ]x[_+ ]([\d\._]+)/i;     # Mac OS X Version
    

    And my "# Analyze: OS" area looks something like this

                        # Analyze: OS
                        #------------
                        my $uaos = $TmpOS{$UserAgent};
                        if ( !$uaos ) {
                            my $found = 1;
    
                                                    # iPhone version
                                                    if ($UserAgent =~ /$regverosiphone/o) {
                                my $tmp = $1;
                                $tmp =~ s/_/\./g;
                                                            $_os_h{"iphone$tmp"}++;
                                                            $TmpOS{$UserAgent} = "iphone$tmp";
                                                    }
                            # iPad Version OS (Do Before MAC OS)
                            elsif ($UserAgent =~ /$regverosipad/o) {
                                my $tmp = $1;
                                $tmp =~ s/_/\./g;
                                $_os_h{"ipad$tmp"}++;
                                $TmpOS{$UserAgent} = "ipad$tmp";
                            }
                            # Blackberry Version OS
                            elsif ($UserAgent =~ /$regverosblackberry/o) {
                                $_os_h{"blackberry$1"}++;
                                $TmpOS{$UserAgent} = "blackberry$1";
    
                                # The following line is for troubleshooting
                                # print $UserAgent."----".$TmpOS{$UserAgent}."---".$1."\n";
                            }
                            # PlayBook RIM Tablet
                            elsif ($UserAgent =~ /$regverosrimtablet/o) {
                                $_os_h{"playbook$1"}++;
                                $TmpOS{$UserAgent} = "playbook$1";
                            }
                            # Android Version OS
                            elsif ($UserAgent =~ /$regverosandroid/o) {
                                $_os_h{"android$1"}++;
                                $TmpOS{$UserAgent} = "android$1";
                            }
                            # Mac OS X Version 
                            elsif ($UserAgent =~ /$regverosmac/o) {
                                my $tmp = $1;
                                $tmp =~ s/_/\./g;
                                $_os_h{"macosx$tmp"}++;
                                $TmpOS{$UserAgent} = "macosx$tmp";
                            }
    
                            else {
                                $found = 0;
    
                                # in OSHashID list ?
                                foreach (@OSSearchIDOrder)
                                {    # Search ID in order of OSSearchIDOrder
                                    if ( $UserAgent =~ /$_/ ) {
                                        my $osid = $OSHashID{ &UnCompileRegex($_) };
                                        $_os_h{"$osid"}++;
                                        $TmpOS{$UserAgent} = "$osid";
                                        $found = 1;
                                        last;
                                    }
                                }
                            }
    
                            # Unknown OS ?
                            if ( !$found ) {
                                $_os_h{'Unknown'}++;
                                $TmpOS{$UserAgent} = 'Unknown';
                                my $newua = $UserAgent;
                                $newua =~ tr/\+ /__/;
                                $_unknownreferer_l{$newua} = $timerecord;
                            }
                        }
                        else {
                            $_os_h{$uaos}++;
                            if ( $uaos eq 'Unknown' ) {
                                my $newua = $UserAgent;
                                $newua =~ tr/\+ /__/;
                                $_unknownreferer_l{$newua} = $timerecord;
                            }
                        }
    
                    }
    
                }
                else {
                    $_browser_h{'Unknown'}++;
                    $_os_h{'Unknown'}++;
                }
    

    Of course other changes have been made in the "operating_systems.pm" and the
    "browsers.pm".
    So far I have not come across any issues.