File squidanalyzer.spec of Package SquidAnalyzer

#
# spec file for package squidanalyzer
#
# Copyright (c) by Lars Vogdt, Nuremberg
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.
#

%define version_ma 6
%define version_mi 6

Name:          squidanalyzer
Summary:       Squid proxy log analyzer and report generator
Url:           http://squidanalyzer.darold.net/   
Group:         Productivity/Networking/Web/Proxy 
License:       GPL-3.0+
Version:       %{version_ma}.%{version_mi}
Release:       0
Source0:       http://downloads.sourceforge.net/project/squid-report/squid-report/%{version_ma}.%{version_mi}/%{name}-%{version_ma}.%{version_mi}.tar.gz
Source1:       %{name}.http 
Source2:       %{name}.cron
Source3:       squidanalyzer-rpmlintrc
Obsoletes:     SquidAnalyzer < 4.4
Provides:      SquidAnalyzer = %{version}-%{release}
Requires:      gzip
Requires:      cron
BuildRequires: perl(Pod::Man)
%if 0%{?suse_version}
Requires:      apache2
BuildRequires: apache2-devel
BuildRequires: apache-rpm-macros
%if 0%{?suse_version} > 1500
# On Tumbleweed the /etc/cron.d is owned by the cron package
BuildRequires: cron
%endif
%else
Requires:      httpd
BuildRequires: httpd-devel
%endif
Requires:      perl(IO::File)
Requires:      perl(Socket)
Requires:      perl(Time::HiRes)
%if 0%{?suse_version}
Recommends:    squid
%endif
BuildArch:     noarch
%if 0%{?suse_version}
BuildRequires: perl-macros
%{perl_requires}
%else
BuildRequires: perl
Requires:      perl
BuildRequires: perl(ExtUtils::MakeMaker)
%endif

BuildRoot:     %{_tmppath}/%{name}-%{version}-build


%if 0%{?suse_version}
%define        webdir /srv/www/squidanalyzer
%define apache2_sysconfdir %{apache_sysconfdir}
%else
# this should be rhel compatible
%define        webdir /var/www/squidanalyzer
%define apache2_sysconfdir %(%{_sbindir}/apxs -q SYSCONFDIR|sed -e 's,/conf,,g')
%endif

%description
SquidAnalyzer parse native access log format of the Squid proxy and
generate general statistics about hits, bytes, users, networks, top url
and top second level domain.

Statistic reports are oriented to user and bandwidth control, this is
not a pure cache statistics generator.

This analyzer is incremental so it should be run in a daily cron. Take
care if you have rotate log enable to run it before rotation is done.

The HTML output need a huge size for large number of user. Here on my
pentium III 500 MHz with 15Mb of free memory, for 600 users and an
access.log of 72 Mb it takes 20 minutes to run and generate 70 Mb of
HTML output by month. If you have an older system than this and want to
save space and time, you can disable url details feature that logs and
reports statistics for every URL and domain.


%prep
%setup -q -n %{name}-%{version_ma}.%{version_mi}

%build
perl Makefile.PL \
                INSTALLDIRS=vendor \
                QUIET=yes \
                LOGFILE="%{_var}/log/squid/access.log" \
                BINDIR="%{_bindir}" \
                CONFDIR="%{_sysconfdir}/%{name}" \
                BASEDIR="%{_localstatedir}/lib/%{uname}" \
                HTMLDIR="%{webdir}" \
                MANDIR="%{_mandir}/man3" \
                DOCDIR="%{_defaultdocdir}/%{name}" \
                DESTDIR="%{buildroot}" 
make %{?_smp_mflags} 

%install
# prepare
sed -i "s|/etc/squidanalyzer|%{_sysconfdir}/squidanalyzer|g; \
        s|^Output.*|Output  %{webdir}|g; \
        s|^LogFile.*|LogFile  %{_var}/log/squid/access.log|g; \
        s|^WebUrl.*|WebUrl  /squidreport|g" etc/squidanalyzer.conf squid-analyzer

sed -i "s|^\$ZCAT_PROG.*|\$ZCAT_PROG = \"%{_bindir}/zcat\";|g" SquidAnalyzer.pm

sed -i 's|^Alias.*|Alias /squidreport %{webdir}|g; s|^.Directory.*|<Directory %{webdir}>|g' %{SOURCE1}

mkdir -p %{buildroot}%{webdir} %{buildroot}%{_sysconfdir}/%{name}
# install
make DESTDIR="%{buildroot}" install install_vendor
# install own configs and cron job
install -Dm644 %{SOURCE1} %{buildroot}%{apache2_sysconfdir}/conf.d/%{name}.conf
install -Dm644 %{SOURCE2} %{buildroot}%{_sysconfdir}/cron.d/%{name}
# make rpmlint happy: remove orig files:
rm %{buildroot}%{_defaultdocdir}/%{name}/INSTALL
# make it noarch: remove unneeded files:
rm -rf %{buildroot}%{perl_vendorarch}/auto/SquidAnalyzer
rm -rf %{buildroot}%{perl_archlib}/perllocal.pod

%files
%defattr(-, root, root)
%dir %{_defaultdocdir}/%{name}
%doc %{_defaultdocdir}/%{name}/*
%dir %{_sysconfdir}/%{name}
%dir %{_sysconfdir}/%{name}/lang
%config(noreplace) %{_sysconfdir}/%{name}/*
%config(noreplace) %{apache2_sysconfdir}/conf.d/%{name}.conf
%config(noreplace) %{_sysconfdir}/cron.d/%{name}
%attr(-,wwwrun,www) %dir %{webdir}
%{webdir}/*
%{_mandir}/man3/*quid*nalyzer.3*
%{_bindir}/squid-analyzer
%{perl_vendorlib}/SquidAnalyzer.pm

%changelog 
openSUSE Build Service is sponsored by