Name: awstats
Version: 6.7
Release: 4%{?dist}
Summary: Advanced Web Statistics
License: GPLv2
Group: Applications/Internet
URL: http://awstats.sourceforge.net
Source0: http://dl.sf.net/awstats/awstats-%{version}.tar.gz
Source1: awstats.README.SELinux
# Fix XML output for history files
# http://awstats.cvs.sourceforge.net/awstats/awstats/wwwroot/cgi-bin/awstats.pl?r1=1.892&r2=1.894&view=patch
Patch0: awstats-6.7-xmlhistory.patch
Patch1: awstats-6.7-CVE-2008-3714.patch
BuildArch: noarch
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
Requires: perl
Requires(post): perl
Requires(postun): /sbin/service
%description
Advanced Web Statistics is a powerful and featureful tool that generates
advanced web server graphic statistics. This server log analyzer works
from command line or as a CGI and shows you all information your log contains,
in graphical web pages. It can analyze a lot of web/wap/proxy servers like
Apache, IIS, Weblogic, Webstar, Squid, ... but also mail or ftp servers.
This program can measure visits, unique vistors, authenticated users, pages,
domains/countries, OS busiest times, robot visits, type of files, search
engines/keywords used, visits duration, HTTP errors and more...
Statistics can be updated from a browser or your scheduler.
The program also supports virtual servers, plugins and a lot of features.
With the default configuration, the statistics are available:
http://localhost/awstats/awstats.pl
%prep
%setup -q
%patch0 -p0
%patch1 -p1
# patch creates backups even though it shouldn't
rm wwwroot/cgi-bin/awstats.pl.orig
# Fix style sheets.
perl -pi -e 's,/icon,/awstatsicons,g' wwwroot/css/*
# Fix some bad file permissions here for convenience.
chmod -x tools/httpd_conf
find tools/xslt -type f | xargs chmod -x
# Remove \r in various files
perl -pi -e 's/\r//g' docs/COPYING.TXT docs/LICENSE.TXT docs/pad_awstats.xml docs/awstats_changelog.txt docs/styles.css tools/httpd_conf tools/logresolvemerge.pl tools/awstats_exportlib.pl tools/awstats_buildstaticpages.pl tools/maillogconvert.pl tools/urlaliasbuilder.pl wwwroot/cgi-bin/awredir.pl
# SELinux README
cp -a %{SOURCE1} README.SELinux
%install
rm -rf $RPM_BUILD_ROOT
### Create cron job
cat <<EOF >awstats.cron
#!/bin/bash
exec %{_datadir}/awstats/tools/awstats_updateall.pl now \
-configdir="%{_sysconfdir}/awstats" \
-awstatsprog="%{_datadir}/awstats/wwwroot/cgi-bin/awstats.pl" >/dev/null
exit 0
EOF
### Create folders
mkdir -p $RPM_BUILD_ROOT%{_sysconfdir}/{httpd/conf.d,%{name},cron.hourly}
mkdir -p $RPM_BUILD_ROOT%{_localstatedir}/lib/%{name}
mkdir -p $RPM_BUILD_ROOT%{_datadir}/%{name}
### Install files
cp -pr tools $RPM_BUILD_ROOT%{_datadir}/%{name}
chmod 755 $RPM_BUILD_ROOT%{_datadir}/%{name}/tools/*.pl
chmod 644 $RPM_BUILD_ROOT%{_datadir}/%{name}/tools/httpd_conf
cp -pr wwwroot $RPM_BUILD_ROOT%{_datadir}/%{name}
chmod 755 $RPM_BUILD_ROOT%{_datadir}/%{name}/wwwroot/cgi-bin/*.pl
rm -rf $RPM_BUILD_ROOT%{_datadir}/%{name}/wwwroot/classes/src
### We want these outside CGI path.
rm -rf $RPM_BUILD_ROOT%{_datadir}/%{name}/wwwroot/cgi-bin/{lang,lib,plugins}
cp -pr wwwroot/cgi-bin/{lang,lib,plugins} $RPM_BUILD_ROOT%{_datadir}/%{name}
rm -f $RPM_BUILD_ROOT%{_datadir}/%{name}/wwwroot/cgi-bin/awstats.model.conf
### Commit permanent changes to default configuration
install -p -m 644 wwwroot/cgi-bin/awstats.model.conf \
$RPM_BUILD_ROOT/%{_sysconfdir}/%{name}/%{name}.model.conf
perl -pi -e '
s|^LogFile=.*$|LogFile="%{_localstatedir}/log/httpd/access_log"|;
s|^DirData=.*$|DirData="%{_localstatedir}/lib/awstats"|;
s|^DirCgi=.*$|DirCgi="/awstats"|;
s|^DirIcons=.*$|DirIcons="/awstatsicons"|;
s|^SiteDomain=.*$|SiteDomain="localhost.localdomain"|;
s|^HostAliases=.*$|HostAliases="localhost 127.0.0.1"|;
s|^EnableLockForUpdate=.*$|EnableLockForUpdate=1|;
s|^SaveDatabaseFilesWithPermissionsForEveryone=.*$|SaveDatabaseFilesWithPermissionsForEveryone=0|;
s|^SkipHosts=.*$|SkipHosts="127.0.0.1"|;
s|^Expires=.*$|Expires=3600|;
' $RPM_BUILD_ROOT/%{_sysconfdir}/%{name}/%{name}.model.conf
install -p -m 644 $RPM_BUILD_ROOT/%{_sysconfdir}/%{name}/%{name}.{model,localhost.localdomain}.conf
# Fix scripts
perl -pi -e 's|/usr/local/awstats|%{_datadir}/awstats|g' \
$RPM_BUILD_ROOT%{_datadir}/%{name}/tools/{*.pl,httpd_conf}
# Remove some upstream version control files
find $RPM_BUILD_ROOT%{_datadir} -name .cvsignore | xargs rm -f
find docs/ -name .cvsignore | xargs rm -f
# Fix encoding of changelog
iconv -f iso-8859-1 -t utf-8 < docs/awstats_changelog.txt > docs/awstats_changelog.txt.utf8
mv docs/awstats_changelog.txt.utf8 docs/awstats_changelog.txt
# Apache configuration
install -p -m 644 tools/httpd_conf $RPM_BUILD_ROOT/%{_sysconfdir}/httpd/conf.d/%{name}.conf
perl -pi -e 's|/usr/local|%{_datadir}|g;s|Allow from all|Allow from 127.0.0.1|g' \
$RPM_BUILD_ROOT/%{_sysconfdir}/httpd/conf.d/%{name}.conf
echo "# Additional Perl modules
<IfModule mod_env.c>
SetEnv PERL5LIB %{_datadir}/awstats/lib:%{_datadir}/awstats/plugins
</IfModule>" >> $RPM_BUILD_ROOT/%{_sysconfdir}/httpd/conf.d/%{name}.conf
# Cron job
install -m 0755 awstats.cron $RPM_BUILD_ROOT%{_sysconfdir}/cron.hourly/%{name}
%clean
rm -rf $RPM_BUILD_ROOT
%post
if [ $1 -eq 1 ]; then
if [ ! -f %{_sysconfdir}/%{name}/%{name}.`hostname`.conf ]; then
%{__cat} %{_sysconfdir}/%{name}/%{name}.model.conf | \
%{__perl} -p -e 's|^SiteDomain=.*$|SiteDomain="'`hostname`'"|;
s|^HostAliases=.*$|HostAliases="REGEX[^.*'${HOSTNAME//./\\\\.}'\$]"|;
' > %{_sysconfdir}/%{name}/%{name}.`hostname`.conf || :
fi
fi
# SELinux support
# Change the file context
chcon -R -t httpd_sys_script_exec_t %{_datadir}/awstats/wwwroot/cgi-bin || :
chcon -R -t var_log_t /usr/share/awstats/wwwroot/cgi-bin/awstats.pl
chcon -R -t httpd_sys_script_rw_t %{_localstatedir}/lib/awstats || :
%postun
if [ $1 -ne 0 ]; then
/sbin/service httpd condrestart >/dev/null 2>&1
fi
%files
%defattr(-,root,root,755)
# Apache configuration file
%config(noreplace) %{_sysconfdir}/httpd/conf.d/%{name}.conf
%config(noreplace) %attr(755,root,root) %{_sysconfdir}/cron.hourly/%{name}
%config(noreplace) %{_sysconfdir}/%{name}/
%{_localstatedir}/lib/%{name}
%dir %{_datadir}/%{name}
%dir %{_datadir}/%{name}/wwwroot
%{_datadir}/%{name}/tools
%{_datadir}/%{name}/wwwroot/cgi-bin
# Different defattr to fix lots of files which should not be +x.
%defattr(644,root,root,755)
%doc README.TXT docs/* README.SELinux
%{_datadir}/%{name}/lang
%{_datadir}/%{name}/lib
%{_datadir}/%{name}/plugins
%{_datadir}/%{name}/wwwroot/classes
%{_datadir}/%{name}/wwwroot/css
%{_datadir}/%{name}/wwwroot/icon
%{_datadir}/%{name}/wwwroot/js
%changelog
* Sat Dec 06 2008 Tim Jackson <rpm@timj.co.uk> 6.7-4
- Use Debian's patch for CVE-2008-3714 (#474396)
* Fri Aug 29 2008 Tim Jackson <rpm@timj.co.uk> 6.7-3
- Fix CVE-2008-3714: cross-site scripting security issue (#459605)
* Tue May 13 2008 Tim Jackson <rpm@timj.co.uk> 6.7-2
- awstats does not actually require httpd (#406901)
- Fix cron script to be compatible with SELinux (#435101)
- Mark httpd config as noreplace
- Fix encoding of awstats_changelog.txt
- Remove some stray upstream temp files
- Fix EOL encoding of documentation to be consistent
* Tue Sep 18 2007 Tim Jackson <rpm@timj.co.uk> 6.7-1
- initial import to EPEL-4, from Fedora