AWStats

AWStats is a free powerful and featureful tool that generates advanced web, streaming, ftp or mail server statistics, graphically. This log analyzer works as a CGI or from command line and shows you all possible information your log contains, in few graphical web pages.

                                                                                        http://www.awstats.org

[root@mail ~]#  yum --enablerepo=epel -y install awstats GeoIP*

# "awstas.(your hostname).conf" is generated automatically #

                    # cp /etc/awstats/awstats.localhost.localdomain.conf /etc/awstats/awstats.mail.worldcm.net.conf

[root@mail ~]#  vi /etc/awstats/awstats.mail.worldcm.net.conf

# line 51: change

LogFile="/usr/bin/maillogconvert.pl standard < /var/log/maillog |"                  # [Centos 6 ]

                           OR

LogFile="/usr/share/awstats/tools/maillogconvert.pl standard < /var/log/maillog |"         #[ For centos 7 ]

# line 63: change

LogType=M

# line 122 comment out and the line below

#LogFormat=1

LogFormat="%time2 %email %email_r %host %host_r %method %url %code %bytesd"

# line 154&169: change

SiteDomain="worldcm.net"

HostAliases="worldcm.net mail.worldcm.net"

OR

HostAliases="REGEX[^.*mail\.worldcm\.com$]"

# Line 203

DirData="/var/www/awstats"

OR

DirData="/var/www/awstats/lib"

## Line no

839 LevelForBrowsersDetection=0 # 0 disables Browsers detection.

842 LevelForOSDetection=0 # 0 disables OS detection.

844 LevelForRefererAnalyze=0 # 0 disables Origin detection.

846 LevelForRobotsDetection=0 # 0 disables Robots detection.

848 LevelForSearchEnginesDetection=0 # 0 disables Search engines detection.

850 LevelForKeywordsDetection=0 # 0 disables Keyphrases/Keywords detection.

852 LevelForFileTypesDetection=0 # 0 disables File types detection.

854 LevelForWormsDetection=0 # 0 disables Worms detection.

951 ShowSummary=UVPHB

956 ShowMonthStats=UHB

961 ShowDaysOfMonthStats=HB

966 ShowDaysOfWeekStats=HB

971 ShowHoursStats=HB

976 ShowDomainsStats=0

981 ShowHostsStats=HBL

986 ShowAuthenticatedUsers=0

991 ShowRobotsStats=0

996 ShowWormsStats=0

1001 ShowEMailSenders=HBML

1006 ShowEMailReceivers=HBML

1011 ShowSessionsStats=0

1016 ShowPagesStats=0

1021 ShowFileTypesStats=0

1026 ShowFileSizesStats=0

1031 ShowDownloadsStats=HB

1036 ShowOSStats=0

1041 ShowBrowsersStats=0

1046 ShowScreenSizeStats=0

1051 ShowOriginStats=0

1056 ShowKeyphrasesStats=0

1061 ShowKeywordsStats=0

1066 ShowMiscStats=0

1071 ShowHTTPErrorsStats=0

1076 ShowSMTPErrorsStats=1

1081 ShowClusterStats=0

[root@mail ~]# vi /etc/httpd/conf.d/awstats.conf                                

Alias /awstats/icon/ /var/www/awstats/icon/

ScriptAlias /awstats/ /var/www/awstats/

<Directory /var/www/awstats/>                                              # [ Centos 6 ]

DirectoryIndex awstats.pl

Options ExecCGI

order deny,allow

deny from all

# allow from 127.0.0.1

allow from all

</Directory>

Alias /css/ /var/www/awstats/css/

Alias /js/ /var/www/awstats/js/

# Additional Perl modules

<IfModule mod_env.c>

   SetEnv PERL5LIB /var/www/awstats/lib:/var/www/awstats/plugins

</IfModule>

#### passwd log in

<directory /var/www/awstats/>

    AuthType Basic

    AuthName "AWStats Admin Access Required"

    AuthUserFile /var/www/awstats/awstats-htpasswd

    require valid-user

    ExpiresActive On

    ExpiresDefault M310

</directory>

  

                                 ---

[root@mail ~]#  htpasswd -cm /var/www/awstats/awstats-htpasswd admin

New password:

Re-type new password:

                  ---------------OR  Centos 7--------------

# Note that path "/usr/share/awstats/" must reflect your AWStats install path.

#

Alias /awstatsclasses "/usr/share/awstats/wwwroot/classes/"

Alias /awstatscss "/usr/share/awstats/wwwroot/css/"

Alias /awstatsicons "/usr/share/awstats/wwwroot/icon/"

ScriptAlias /awstats/ "/usr/share/awstats/wwwroot/cgi-bin/"

#

# This is to permit URL access to scripts/files in AWStats directory.

#

<Directory "/usr/share/awstats/wwwroot">

    Options None

    AllowOverride None

    <IfModule mod_authz_core.c>

        # Apache 2.4

        Require local

    </IfModule>

    <IfModule !mod_authz_core.c>

        # Apache 2.2

        Order allow,deny

#        Allow from 127.0.0.1

#        Allow from ::1

        allow from all

    </IfModule>

</Directory>

# Additional Perl modules

<IfModule mod_env.c>

    SetEnv PERL5LIB /usr/share/awstats/lib:/usr/share/awstats/plugins

</IfModule>

#### passwd log in

<Location /awstats>

AuthType Basic

AuthName "AWStats Admin Access Required"

AuthUserFile /etc/httpd/conf.d/awstats.passwd

require valid-user

</Location>

                           --------------------------------------------------

                     

                    

[root@mail ~]#   htpasswd -c  /etc/httpd/conf.d/awstats.passwd admin

New password:

Re-type new password:

[root@mail ~]# /etc/rc.d/init.d/httpd restart

Stopping httpd: [ OK ]

Starting httpd: [ OK ]

LOG refresh:

                   # /usr/share/awstats/wwwroot/cgi-bin/awstats.pl -update -config=mail.worldcm.net -configdir=/etc/awstats                  #[Centos 7 ]

                        # perl /usr/share/awstats/wwwroot/cgi-bin/awstats.pl -update -config=mail.worldcm.net -configdir=/etc/awstats

                                                        OR

                    # /var/www/awstats/awstats.pl -update -config=mail.worldcm.net -configdir=/etc/awstats                  # [ Centos 6 ]

WEB Site

            http://mail.worldcm.net/awstats/awstats.pl

            http://192.168.80.81/awstats/awstats.pl?config=mail.worldcm.net

### ADD log update Cron

# crontab –e

0 2 * * * /var/www/awstats/awstats.pl -update -config=mail.worldcm.net -configdir=/etc/awstats

*/30 * * * * root /var/www/awstats/awstats.pl -update -config=mail.worldcm.net -configdir=/etc/awstats

# vi /etc/crontab

*/30 * * * * root /usr/share/awstats/wwwroot/cgi-bin/awstats.pl -update -config=mail.worldcm.net -configdir=/etc/awstats            #[Centos 7 ]

redirect pages

# vi /etc/httpd/conf/httpd.conf

<VirtualHost *:80>

   Servername mail.worldcm.net

#   Redirect /mailreports/ http://mail.worldcm.net/awstats/awstats.pl

   RedirectPermanent /mailreports http://mail.worldcm.net/awstats/awstats.pl

</VirtualHost>

OR Multiple Pages

<VirtualHost *:80>

   Servername mail.world.net

#   Redirect /mailreports/ http://mail.world.net/awstats/awstats.pl

   RedirectPermanent /mailreports http://mail.world.net/awstats/awstats.pl

  RedirectTemp /index.html https://mail.world.net:20000/

  RedirectPermanent /welcomepage https://mail.world.net:20000/

</VirtualHost>

#  service httpd restart

systemctl restart httpd

WEB Site

http://mail.worldcm.net/mailreports

            http://mail.worldcm.net/awstats/awstats.pl

            http://192.168.80.81/awstats/awstats.pl?config=mail.worldcm.net

#################################################################################

#yum -y install awstats              [ Download attach under]

LogFile="/usr/bin/maillogconvert.pl standard < /var/log/maillog |"

DirData="/var/www/awstats/lib"

[root@mail conf.d]# vi /etc/httpd/conf.d/awstats.conf

#

# Directives to add to your Apache conf file to allow use of AWStats as a CGI.

# Note that path "/usr/share/awstats/" must reflect your AWStats install path.

#

Alias /awstatsclasses "/var/www/awstats/classes/"

Alias /awstatscss "/var/www/awstats/css/"

Alias /awstatsicons "/var/www/awstats/icon/"

ScriptAlias /awstats/ "/var/www/awstats/"

#

# This is to permit URL access to scripts/files in AWStats directory.

#

<Directory "/var/www/awstats">

    Options None

    AllowOverride None

    Order allow,deny

    Allow from 127.0.0.1 192.168.0.0/16 202.22.0.0/16 202.161.189.0/24

</Directory>

# Additional Perl modules

<IfModule mod_env.c>

    SetEnv PERL5LIB /var/www/awstats/lib:/var/www/awstats/plugins

</IfModule>

-------------------------------------------------------------------------

Alias /awstats/icon/ /var/www/awstats/icon/  ScriptAlias /awstats/ /var/www/awstats/ <Directory /var/www/awstats/>         DirectoryIndex awstats.pl         Options ExecCGI         order deny,allow         allow from all </Directory>  Alias /awstatsclasses "/var/www/awstats/lib/" Alias /awstats-icon/ "/var/www/awstats/icon/" Alias /awstatscss "/var/www/awstats/examples/css"

------------------------------------------------------------------

Alias /awstats/icon/ /var/www/awstats/icon/  ScriptAlias /awstats/ /var/www/awstats/ <Directory /var/www/awstats/>         DirectoryIndex awstats.pl         Options ExecCGI         order deny,allow         allow from all </Directory>  Alias /awstatsclasses "/var/www/awstats/lib/" Alias /awstats-icon/ "/var/www/awstats/icon/" Alias /awstatscss "/var/www/awstats/examples/css"

----------------------------------------

[root@mail ~]# vi /etc/httpd/conf.d/awstats.conf Alias /awstats/icon/ /var/www/awstats/icon/ Alias /awstatsclasses "/var/www/awstats/lib/"   ScriptAlias /awstats/ /var/www/awstats/ <Directory /var/www/awstats/>     DirectoryIndex awstats.pl     Options ExecCGI     order deny,allow     allow from all </Directory>   Alias /css/ /var/www/awstats/css/ Alias /js/ /var/www/awstats/js/ Alias /awstatscss "/var/www/awstats/examples/css"  # Additional Perl modules <IfModule mod_env.c>     SetEnv PERL5LIB /var/www/awstats/lib:/var/www/awstats/plugins </IfModule>

--------------------------------             -------------------------------------------------

OR  attach file under  wstats.conf

---------------------------------------------------------------

#wq

[root@ho ~]# vi /etc/awstats/awstats.mail.worldcm.com.conf

51 #LogFile="/var/log/httpd/access_log"

53 LogFile="/usr/bin/maillogconvert.pl standard < /var/log/maillog |"

DirData="/var/www/awstats/lib"

pls download and copy pest  file -location: /etc/awstats/   (awstats.mail.worldcm.com.conf)

#wq

Then run the script

/var/www/awstats/awstats.pl  -config=mail.worldcm.com -update

                                                     OR

/var/www/awstats/awstats.pl  -update -config=mail.worldcm.com -configdir=/etc/awstats

Open web Browser

Link is:   http://mail.worldcm.com/awstats/awstats.pl?config=mail.worldcm.com

How To Install, Secure, And Automate AWStats (CentOS/RHEL)

AWStats is a free and very powerful tool that generates advanced web, streaming, ftp or mail server statistics, graphically. It can analyze log files from all major server tools and convert them into nice graphical display. There are a lot of articles out there for AWStats, the reason I decided to write this one was to consolidate all the different tips and tricks I've learned through my journey into one comprehensive article associating the fantastic efforts of so many out there. There are a few methods of installing AWStats, this article will describe the simpler method of the two utilizing YUM.

This article assumes that you have root/sudo access to achieve all the goals required for a functional setup. This article also assumes you have SELinux set to permissive or disabled and that IPTables configuration is either disabled or customized for AWStats. Let's begin.

 

Install

Add RPMForge Yum Repository:

For x86 (32-bit) systems:

rpm -Uhv http://apt.sw.be/redhat/el5/en/i386/rpmforge/RPMS/rpmforge-release-0.3.6-1.el5.rf.i386.rpm

For x64 (64-bit) systems:

rpm -Uhv http://apt.sw.be/redhat/el5/en/x86_64/rpmforge/RPMS//rpmforge-release-0.3.6-1.el5.rf.x86_64.rpm

 

Install & Configure Prerequisites

Install Apache:

yum install httpd

Configure Apache to start on boot:

/sbin/chkconfig --levels 345 httpd on

Configure iptables to allow Apache traffic:

/sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT

/etc/init.d/iptables save

/etc/init.d/iptables restart

 

Install & Configure AWStats

Now that YUM has its additional repository we are ready to install. From the commandline type:

yum install awstats

Modify AWStats Apache Configuration:

Edit /etc/httpd/conf.d/awstats.conf (Note: When putting your conf file in the /etc/httpd/conf.d/ folder it's automatically loaded as part of the Apache configuration. There is no need to add it again into httpd.conf. This setup is usually for one of two reasons; A cleaner approach and separating of different applications in their own configuration files, or you are in a hosted environment that does not allow for direct editing of httpd.conf):

Alias /awstats/icon/ /var/www/awstats/icon/  ScriptAlias /awstats/ /var/www/awstats/ <Directory /var/www/awstats/>         DirectoryIndex awstats.pl         Options ExecCGI         order deny,allow         allow from all </Directory>  Alias /awstatsclasses "/var/www/awstats/lib/" Alias /awstats-icon/ "/var/www/awstats/icon/" Alias /awstatscss "/var/www/awstats/examples/css"

Note: the mod_cgi module of Apache must be pre-loaded into Apache otherwise Apache will not try to view the file, it will try to execute it. This can be done in two ways, either enable for the entire web server, or utilizing VirtualHosts, enable for AWStats.

Edit the following lines in the default awstats configuration file /etc/awstats/awstats.localhost.localdomain.conf:

SiteDomain="<server name>.<domain>" HostAliases="<any aliases for the server>"

Rename config file:

mv /etc/awstats/awstats.localhost.localdomain.conf /etc/awstats/awstats.<server name>.<domain>.conf

Update Statistics (Note: By default, statistics will be updated every hour.):

/usr/bin/awstats_updateall.pl now -confdir="/etc" -awstatsprog="/var/www/awstats/awstats.pl"

Start Apache:

/etc/init.d/httpd start

To automate startup of Apache on boot up, type

chkconfig --add httpd

 

Verify Install

Go to http://<server name>.<domain>/awstats/awstats.pl?config=<server name>.<domain>

 

Securing AWStats

Setting File System Permissions

The webserver needs only read-access to your files in order for you to be able to access AWStats from the browser. Limiting your own permissions will keep you from accidentally messing with files. Just remember that with this setup you will have to run Perl to execute scripts rather than executing the scripts themselves.

$ find ./awstats -type d -exec chmod 701 '{}' \;

$ find ./awstats -not -type d -exec chmod 404 '{}' \;

Apache doesn't need direct access to AWStats configuration files therefore we can secure them tightly and not affect the relationship between them. To ensure that your .htaccess files are not readable via browser:

chmod 400 /etc/awstats/*.conf

 

Protecting The AWStats Directory With And Adding .htaccess

To secure the Awstats folder(s), is a measured process. Ensuring ownership of the AWStats folder is owned by the user that needs access to it, creating an htpasswd.users file and adding the corresponding .htaccess file to authenticate against it. Let's first secure the AWStats folder by typing the below from the command-line:

find ./awstats -type d -exec chmod 701 '{}' \;

find ./awstats -not -type d -exec chmod 404 '{}' \;

Now that our folders have been secured, we'll need to create the .htpasswd.users file. Go to the /etc/awstats folder and execute the following command:

htpasswd -c /etc/awstats/htpasswd.users user

(Select whatever username you'd like.)

It'll ask you to add a password for the user you've selected, add it and re-type it for confirmation and then save. The final step is to create a .htaccess file pointing to the .htpasswd file for authentication. Go to /var/www/awstats/ and create a new file called .htaccess using your favorite editor, typically nano or vi tend to be the more popular ones. In this example, we'll use vi. From the command line type

vi .htaccess

An alternate method of creating a .htaccess file is using the Htaccess Password Generator. Add the following content to your newly created .htaccess file:

AuthName "STOP - Do not continue unless you are authorized to view this site! - Server Access" AuthType Basic AuthUserFile /etc/awstats/htpasswd.users Require valid-user htpasswd -c /etc/awstat/htpasswd.users awstats_online

Once done, secure the .htaccess file by typing:

chmod 404 awstats/.htaccess