#!/bin/bash
domain=$1
ssl_support=$2
# make awstats directory
mkdir -p /home/httpd/vhosts/$domain/statistics/awstats/
# remove previously added awstats to avoid dupe
if [ -e /home/httpd/vhosts/$domain/conf/vhost_ssl.conf ]; then
cat /home/httpd/vhosts/$domain/conf/vhost_ssl.conf |grep -v "Include /home/httpd/vhosts/$domain/conf/awstats.conf" > /home/httpd/vhosts/$domain/conf/vhost_ssl.conf.tmp
mv /home/httpd/vhosts/$domain/conf/vhost_ssl.conf.tmp /home/httpd/vhosts/$domain/conf/vhost_ssl.conf
fi
# add awstats to SSL domain if SSL was specified
if [ "$ssl_support" -eq 1 ] && [ -e /home/httpd/vhosts/$domain/conf/vhost_ssl.conf ]; then
cat >> /home/httpd/vhosts/$domain/conf/vhost_ssl.conf <<EOF
Include /home/httpd/vhosts/$domain/conf/awstats.conf
EOF
fi
# remove previously added awstats to avoid dupe
if [ -e /home/httpd/vhosts/$domain/conf/vhost.conf ]; then
cat /home/httpd/vhosts/$domain/conf/vhost.conf |grep -v "Include /home/httpd/vhosts/$domain/conf/awstats.conf" > /home/httpd/vhosts/$domain/conf/vhost.conf.tmp
mv /home/httpd/vhosts/$domain/conf/vhost.conf.tmp /home/httpd/vhosts/$domain/conf/vhost.conf
fi
# add awstats to non-SSL domain if SSL is disabled
if [ "$ssl_support" -eq 0 ] && [ -e /home/httpd/vhosts/$domain/conf/vhost.conf ]; then
cat >> /home/httpd/vhosts/$domain/conf/vhost.conf <<EOF
Include /home/httpd/vhosts/$domain/conf/awstats.conf
EOF
fi
# generate apache awstats config
cat > /home/httpd/vhosts/$domain/conf/awstats.conf <<EOF
Alias /awstatscss /usr/local/awstats/wwwroot/css/
Alias /awstatsicons /usr/local/awstats/wwwroot/icon/
Alias /awstatscgi /usr/local/awstats/wwwroot/cgi-bin/
<Directory /usr/local/awstats/wwwroot/cgi-bin/>
<IfModule mod_perl.c>
<Files ~ (\.pl$)>
SetHandler perl-script
PerlHandler ModPerl::Registry
Options ExecCGI
allow from all
PerlSendHeader On
</Files>
</IfModule>
</Directory>
EOF
# generate awstats mail config
cat > /etc/awstats/awstats.mail.$domain.conf <<EOF
Include "/etc/awstats/awstats.model.conf"
DNSLookup=0
DirData="/home/httpd/vhosts/$domain/statistics/awstats/"
SiteDomain="mail.$domain"
LogFile="/usr/local/awstats/tools/maillogconvert.pl vadmin $domain < /usr/local/psa/var/log/maillog.processed |"
LogType=M
LogFormat="%time2 %email %email_r %host %host_r %method %url %code %bytesd"
LevelForBrowsersDetection=0
LevelForOSDetection=0
LevelForRefererAnalyze=0
LevelForRobotsDetection=0
LevelForWormsDetection=0
LevelForSearchEnginesDetection=0
LevelForFileTypesDetection=0
ShowMenu=1
ShowSummary=HB
ShowMonthStats=HB
ShowDaysOfMonthStats=HB
ShowDaysOfWeekStats=HB
ShowHoursStats=HB
ShowDomainsStats=0
ShowHostsStats=HBL
ShowAuthenticatedUsers=0
ShowRobotsStats=0
ShowEMailSenders=HBML
ShowEMailReceivers=HBML
ShowSessionsStats=0
ShowPagesStats=0
ShowFileTypesStats=0
ShowFileSizesStats=0
ShowBrowsersStats=0
ShowOSStats=0
ShowOriginStats=0
ShowKeyphrasesStats=0
ShowKeywordsStats=0
ShowMiscStats=0
ShowHTTPErrorsStats=0
ShowSMTPErrorsStats=1
EOF
# generate awstats anonymous ftp config
cat > /etc/awstats/awstats.anonftp.$domain.conf <<EOF
Include "/etc/awstats/awstats.model.conf"
DirData="/home/httpd/vhosts/$domain/statistics/awstats/"
SiteDomain="ftp.$domain"
LogFile="/home/httpd/vhosts/$domain/statistics/logs/xferlog_anonymous.processed"
LogType=F
LogFormat="%time3 %other %host %bytesd %url %other %other %method %other %logname %other %code %other %other"
LogSeparator="\s"
NotPageList=""
LevelForBrowsersDetection=0
LevelForOSDetection=0
LevelForRefererAnalyze=0
LevelForRobotsDetection=0
LevelForWormsDetection=0
LevelForSearchEnginesDetection=0
ShowLinksOnUrl=0
ShowSummary=UVHB
ShowMonthStats=UVHB
ShowDaysOfMonthStats=HB
ShowDaysOfWeekStats=HB
ShowHoursStats=HB
ShowDomainsStats=HB
ShowHostsStats=HBL
ShowAuthenticatedUsers=HBL
ShowRobotsStats=0
ShowEMailSenders=0
ShowEMailReceivers=0
ShowSessionsStats=1
ShowPagesStats=PBEX
ShowFileTypesStats=HB
ShowFileSizesStats=0
ShowBrowsersStats=0
ShowOSStats=0
ShowOriginStats=0
ShowKeyphrasesStats=0
ShowKeywordsStats=0
ShowMiscStats=0
ShowHTTPErrorsStats=0
ShowSMTPErrorsStats=0
EOF
# generate awstats ftp config
cat > /etc/awstats/awstats.ftp.$domain.conf <<EOF
Include "/etc/awstats/awstats.model.conf"
DirData="/home/httpd/vhosts/$domain/statistics/awstats/"
SiteDomain="ftp.$domain"
LogFile="/home/httpd/vhosts/$domain/statistics/logs/xferlog_regular.processed"
LogType=F
LogFormat="%time3 %other %host %bytesd %url %other %other %method %other %logname %other %code %other %other"
LogSeparator="\s"
NotPageList=""
LevelForBrowsersDetection=0
LevelForOSDetection=0
LevelForRefererAnalyze=0
LevelForRobotsDetection=0
LevelForWormsDetection=0
LevelForSearchEnginesDetection=0
ShowLinksOnUrl=0
ShowSummary=UVHB
ShowMonthStats=UVHB
ShowDaysOfMonthStats=HB
ShowDaysOfWeekStats=HB
ShowHoursStats=HB
ShowDomainsStats=HB
ShowHostsStats=HBL
ShowAuthenticatedUsers=HBL
ShowRobotsStats=0
ShowEMailSenders=0
ShowEMailReceivers=0
ShowSessionsStats=1
ShowPagesStats=PBEX
ShowFileTypesStats=HB
ShowFileSizesStats=0
ShowBrowsersStats=0
ShowOSStats=0
ShowOriginStats=0
ShowKeyphrasesStats=0
ShowKeywordsStats=0
ShowMiscStats=0
ShowHTTPErrorsStats=0
ShowSMTPErrorsStats=0
EOF
# generate awstats http config
cat > /etc/awstats/awstats.http.$domain.conf <<EOF
Include "/etc/awstats/awstats.model.conf"
DirData="/home/httpd/vhosts/$domain/statistics/awstats/"
LogFile="/home/httpd/vhosts/$domain/statistics/logs/access_log.processed"
LogType=W
LogFormat=1
SiteDomain="www.$domain"
HostAliases="$domain www.$domain"
EOF
# generate awstats ssl https config
cat > /etc/awstats/awstats.https.$domain.conf <<EOF
Include "/etc/awstats/awstats.model.conf"
DirData="/home/httpd/vhosts/$domain/statistics/awstats/"
LogFile="/home/httpd/vhosts/$domain/statistics/logs/access_ssl_log.processed"
LogType=W
LogFormat=1
SiteDomain="www.$domain"
HostAliases="$domain www.$domain"
UseHTTPSLinkForUrl="/"
EOF
# generate index.html frameset page
cat > /home/httpd/vhosts/$domain/statistics/index.html <<EOF
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">
<html>
<head>
<title>$domain Statistics</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<frameset rows="30,*" frameborder="NO" border="0" framespacing="0">
<frame src="menu.html" name="topFrame" scrolling="NO" noresize >
<frame src="/awstatscgi/awstats.pl?config=http.$domain" name="mainFrame">
</frameset>
<noframes><body>
</body></noframes>
</html>
EOF
# generate top menu for frame with links to awstats & webalizer stats
cat > /home/httpd/vhosts/$domain/statistics/menu.html <<EOF
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
BODY { font-family: Tahoma, Verdana, Arial; font-size: 8pt; }
A { color: #404040; text-decoration: none; font-weight: bold; font-size: 8pt; }
A:hover { text-decoration: none; color: #808080; }
</style>
</head>
<body>
<table width="100%" cellpadding="0" cellspacing="0"><tr><td align="left">
[ <b>awstats</b> ]
<a href="/awstatscgi/awstats.pl?config=anonftp.$domain" target="mainFrame" title="Anonymous FTP Statistics for $domain">anonymous ftp</a> <small>|</small>
<a href="/awstatscgi/awstats.pl?config=ftp.$domain" target="mainFrame" title="FTP Statistics for $domain">ftp</a> <small>|</small>
<a href="/awstatscgi/awstats.pl?config=mail.$domain" target="mainFrame" title="Mail Statistics for $domain">mail</a> <small>|</small>
<a href="/awstatscgi/awstats.pl?config=https.$domain" target="mainFrame" title="SSL Statistics for $domain">ssl</a> <small>|</small>
<a href="/awstatscgi/awstats.pl?config=http.$domain" target="mainFrame" title="Web Statistics for $domain">web</a>
</td><td align="right">
[ <b>webalizer</b> ]
<a href="/anon_ftpstat" target="mainFrame" title="Anonymous FTP Statistics for $domain">anonymous ftp</a> <small>|</small>
<a href="/ftpstat" target="mainFrame" title="FTP Statistics for $domain">ftp</a> <small>|</small>
<a href="/webstat-ssl" target="mainFrame" title="SSL Statistics for $domain">ssl</a> <small>|</small>
<a href="/webstat" target="mainFrame" title="Web Statistics for $domain">web</a>
</td></tr></table>
</body>
</html>
EOF
# make sure vhost.conf or vhost_ssl.conf is included by httpd.include
/usr/local/psa/admin/bin/websrvmng --vhost-name=$domain