File Dansguardian.spec of Package Dansguardian

# $Id: dansguardian.spec 1741 2004-07-24 04:30:14Z dag $
# Authority: dag
# Upstream: Daniel Barron <author$dansguardian,org>

%define real_name DansGuardian

Summary: Content filtering web proxy
Name: dansguardian
BuildRequires: gcc-c++
Version: 2.9.8.1
Release: 2.dpv
License: GPL
Group: System Environment/Daemons
URL: http://www.dansguardian.org/

Packager: Don Vosburg <don@vosburgs.org>
Vendor: openSUSE Build Service

Source: dansguardian-2.9.8.1.tar.gz
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root


%description
DansGuardian is a web filtering engine that checks the content within
the page itself in addition to the more traditional URL filtering.

DansGuardian is a content filtering proxy. It filters using multiple methods,
including URL and domain filtering, content phrase filtering, PICS filtering,
MIME filtering, file extension filtering, POST filtering.

%prep
%setup




%{__cat} <<'EOF' >dansguardian.init
#!/bin/sh
#
# Startup script for dansguardian
# Modified extensively for SUSE Linux by Don Vosburg <don@vosburgs.org>
#
# chkconfig: 35 92 8
# description: A web content filtering plugin for web \
#              proxies, developed to filter using lists of \
#              banned phrases, MIME types, filename \
#              extensions and PICS labelling.
# processname: dansguardian
# pidfile: /var/run/dansguardian.pid
# config: /etc/dansguardian/dansguardian.conf

### BEGIN INIT INFO
# Provides:			dansguardian
# Required-Start:		$local_fs $remote_fs $network $named $time
# X-UnitedLinux-Should-Start:	squid
# Required-Stop:		$local_fs $remote_fs $network
# X-UnitedLinux-Should-Stop:	
# Default-Start:		3 5
# Default-Stop:			0 1 2 6
# Short-Description:		DansGuardian web content filter
# Description:			Start the DansGuardian web content filter
#				providing HTTP and other filtering services in conjunction with squid
### END INIT INFO


CONFFILELOCATION=/etc/dansguardian/
BINARYLOCATION=/usr/sbin/
PIDDIR=/var/run/
SQUID_BIN=/usr/sbin/squid
SQUID_PID=/var/run/squid.pid

. /etc/rc.status
RC_OPTIONS='-v'
rc_reset


# File includes changes by Thomas Jarosch
function wait_for_pid()
{
    local PID=$1
    local RET=0
    
    if [ $PID -eq 0 ] ; then
        return $RET
    fi
    
    # give 60 secs then KILL
    local COUNTDOWN=60

    while [ -d /proc/${PID} ] && [ $COUNTDOWN -gt 0 ] ; do
        sleep 1
        COUNTDOWN=$[$COUNTDOWN-1]
    done

    if [ -d /proc/${PID} ]; then
        COMMAND=`ps h -o command ${PID}`
        logger "dansguardian: timeout waiting for PID ${PID}: ${COMMAND}; sending SIGKILL"
        kill -KILL $PID >/dev/null 2>&1
        RET=1
    fi
    
    return $RET
}

# See how we were called.

case "$1" in
start)  if [ -e $SQUID_PID ] ; then 
         if [ -f ${BINARYLOCATION}dansguardian ] &&
           [ -f ${CONFFILELOCATION}dansguardian.conf ]; then
                echo -n "Starting dansguardian: "
                if ${BINARYLOCATION}dansguardian 2> /dev/null; then
                 rc_status $RC_OPTIONS
                 [ -d /var/lock/subsys ] && touch /var/lock/subsys/dansguardian
                 else
                 rc_failed
		 rc_status -v
		 rc_exit                
		fi
         fi
	else 
	   echo -n "- Warning: squid not running! DansGuardian requires squid!"
	   rc_failed 7
	fi
        ;;
stop)
        echo -n "Shutting down dansguardian: "
        WAITPID=0
        if [ -f ${PIDDIR}dansguardian.pid ] ; then
            WAITPID=`cat ${PIDDIR}dansguardian.pid`
        fi
        if ${BINARYLOCATION}dansguardian -q 2> /dev/null; then
                if wait_for_pid $WAITPID ; then
                  rc_status $RC_OPTIONS 
                else
                 rc_failed
		 rc_status -v
		 rc_exit  
                fi
                /bin/rm -f ${PIDDIR}dansguardian.pid
                /bin/rm -f /tmp/.dguardianipc
                [ -d /var/lock/subsys ] && /bin/rm -f /var/lock/subsys/dansguardian
        else
                rc_failed
		rc_status -v
		rc_exit
        fi
        ;;
restart)
        $0 stop
        $0 start
        ;;
#status)
#        if [ -f ${BINARYLOCATION}dansguardian ]; then
#                ${BINARYLOCATION}dansguardian -s
#        fi
#        ;;
 status)
        echo -n "Checking for dansguardian "
        checkproc ${BINARYLOCATION}dansguardian
        rc_status -v
        ;;       
*)

        echo "Usage: $0 {start|stop|restart|status}" >&2
        ;;
esac

exit 0
EOF

%{__cat} <<'EOF2' >squid_DG.init
#! /bin/sh
# Copyright (c) 1996, 1997, 1998 S.u.S.E. GmbH
# Copyright (c) 1998, 1999, 2000, 2001 SuSE GmbH
# Copyright (c) 2002 SuSE Linux AG
#
# Author: Frank Bodammer, Peter Poeml, Klaus Singvogel <feedback@suse.de>
# Modified extensively to add dansguardian info by Don Vosburg <don@vosburgs.org>
#
# init.d/squid_DG
#
### BEGIN INIT INFO
# Provides:			squid_DG
# Required-Start:		$local_fs $remote_fs $network $named $time
# X-UnitedLinux-Should-Start:	apache
# Required-Stop:		$local_fs $remote_fs $network
# X-UnitedLinux-Should-Stop:	
# Default-Start:		3 5
# Default-Stop:			0 1 2 6
# Short-Description:		Squid web cache, DansGuardian content filtering
# Description:			Start the Squid web cache, providing
#				HTTP, FTP and other proxy services
#				along with dansguardian content filter
### END INIT INFO


SQUID_BIN=/usr/sbin/squid
SQUID_PID=/var/run/squid.pid
SQUID_CONF=/etc/squid/squid.conf
CONFFILELOCATION=/etc/dansguardian/
BINARYLOCATION=/usr/sbin/
PIDDIR=/var/run/


if [ ! -x $SQUID_BIN ] ; then
	echo -n "WWW-proxy squid not installed ! "
	exit 5
fi

. /etc/rc.status
RC_OPTIONS='-v'
rc_reset

ulimit -n 4096

# determine which one is the cache_swap directory
CACHE_SWAP=`perl -n -e \
 '/^cache_dir\s+\S+\s+(.*)\s+\d+\s+\d+\s+\d+/ && print "\$1 "' \
  /etc/squid/squid.conf`
[ -z "$CACHE_SWAP" ] && CACHE_SWAP=/var/cache/squid

# File includes changes by Thomas Jarosch
function wait_for_pid()
{
    local PID=$1
    local RET=0
    
    if [ $PID -eq 0 ] ; then
        return $RET
    fi
    
    # give 60 secs then KILL
    local COUNTDOWN=60

    while [ -d /proc/${PID} ] && [ $COUNTDOWN -gt 0 ] ; do
        sleep 1
        COUNTDOWN=$[$COUNTDOWN-1]
    done

    if [ -d /proc/${PID} ]; then
        COMMAND=`ps h -o command ${PID}`
        logger "dansguardian: timeout waiting for PID ${PID}: ${COMMAND}; sending SIGKILL"
        kill -KILL $PID >/dev/null 2>&1
        RET=1
    fi
    
    return $RET
}

case "$1" in
    start)
        echo -n "Starting WWW-proxy squid "
	checkproc $SQUID_BIN

        if [ $? -eq 0 ] ; then
	   echo -n "- Warning: squid already running ! "
	   rc_failed
           rc_status -v
	else
	   [ -e $SQUID_PID ] && echo -n "- Warning: $SQUID_PID exists ! "
	   for adir in $CACHE_SWAP ; do
	     if [ ! -d $adir/00 ]; then # create missing cache directories
	        umask 027             # prevent users reading any cache data
	        echo -n " ($adir)"
	        $SQUID_BIN -z -F > /dev/null 2>&1
	     fi
	     if [ ! -d $adir/00 ]; then
	        echo " - Could not create cache_dir ! "
	        rc_failed
		rc_status -v
		rc_exit
	     fi
	   done
	   sleep 2
	   rc_status $RC_OPTIONS
	fi
	startproc -l /var/log/squid/rcsquid.log $SQUID_BIN -sYD
	echo -n "Starting dansguardian "
	if [ -f ${BINARYLOCATION}dansguardian ] &&
           [ -f ${CONFFILELOCATION}dansguardian.conf ]; then
                if ${BINARYLOCATION}dansguardian 2> /dev/null; then
                 rc_status $RC_OPTIONS
                 [ -d /var/lock/subsys ] && touch /var/lock/subsys/dansguardian
                 else
                 echo -n "- Warning: dansguardian already running ! "
                 rc_failed 
		 rc_status -v
		 rc_exit
                fi
         fi
	;;
    stop)
	echo -n "Shutting down dansguardian "
        WAITPID=0
        if [ -f ${PIDDIR}dansguardian.pid ] ; then
            WAITPID=`cat ${PIDDIR}dansguardian.pid`
        fi
        if ${BINARYLOCATION}dansguardian -q 2> /dev/null; then
                if wait_for_pid $WAITPID ; then
                  rc_status $RC_OPTIONS 
                else
                 rc_failed
		 rc_status -v
		 rc_exit  
                fi
                /bin/rm -f ${PIDDIR}dansguardian.pid
                /bin/rm -f /tmp/.dguardianipc
                [ -d /var/lock/subsys ] && /bin/rm -f /var/lock/subsys/dansguardian
        else
	   echo -n "- Warning: dansguardian not running ! "
	   rc_failed 7
           rc_status -v
        fi
	echo -n "Shutting down WWW-proxy squid "
	if checkproc $SQUID_BIN ; then
	   $SQUID_BIN -k shutdown
	   sleep 2
	   if [ -e $SQUID_PID ] ; then 
	      echo -n "- wait a minute "
	      i=60
	      while [ -e $SQUID_PID ] && [ $i -gt 0 ] ; do
	         sleep 2
	         i=$[$i-1]
	         echo -n "."
	         [ $i -eq 41 ] && echo
	      done
	   fi
	   if checkproc $SQUID_BIN ; then
	      killproc -TERM $SQUID_BIN
	      echo -n " Warning: squid killed !"
	   fi
	else
	   echo -n "- Warning: squid not running ! "
	   rc_failed 7
	fi
	rc_status -v
	;;
    try-restart)
	$0 status >/dev/null && $0 restart
	rc_status
	;;
    restart)
	$0 stop
	$0 start
	rc_status
	;;
    force-reload)
	$0 stop
	$0 start
	$0 reload
	rc_status
	;;
    reload)
        echo -n "Shutting down dansguardian: "
        WAITPID=0
        if [ -f ${PIDDIR}dansguardian.pid ] ; then
            WAITPID=`cat ${PIDDIR}dansguardian.pid`
        fi
        if ${BINARYLOCATION}dansguardian -q 2> /dev/null; then
                if wait_for_pid $WAITPID ; then
                  rc_status $RC_OPTIONS 
                else
                 rc_failed
		 rc_status -v
                fi
                /bin/rm -f ${PIDDIR}dansguardian.pid
                /bin/rm -f /tmp/.dguardianipc
                [ -d /var/lock/subsys ] && /bin/rm -f /var/lock/subsys/dansguardian
        else
                rc_failed
		rc_status -v
        fi
        echo -n "Reloading WWW-proxy squid "
	if checkproc $SQUID_BIN ; then
	   $SQUID_BIN -k rotate
	   sleep 2
	   $SQUID_BIN -k reconfigure
	   rc_status -v
	else
	   echo -n "- Warning: squid not running ! "
	   rc_failed 7
           rc_status -v
           rc_exit
	fi
	if [ -f ${BINARYLOCATION}dansguardian ] &&
           [ -f ${CONFFILELOCATION}dansguardian.conf ]; then
                echo -n "Starting dansguardian: "
                if ${BINARYLOCATION}dansguardian 2> /dev/null; then
                 rc_status $RC_OPTIONS
                 [ -d /var/lock/subsys ] && touch /var/lock/subsys/dansguardian
                 else
                 rc_failed
		 rc_status -v
		 rc_exit
                fi
         fi
	;;
    status)
	echo -n "Checking for dansguardian "
        checkproc ${BINARYLOCATION}dansguardian
        rc_status -v
        echo -n "Checking for WWW-proxy squid "
        checkproc $SQUID_BIN
        rc_status -v
        ;;
    probe)
	test $SQUID_CONF -nt $SQUID_PID && echo reload
	;;
    *)
	echo "Usage: $0 {start|stop|status|try-restart|restart|force-reload|reload|probe}"
	exit 1
	;;
esac
rc_exit

EOF2



%build
./configure \
	--bindir="%{_sbindir}/" \
	--sbindir="%{_sbindir}/" \
	--prefix="%{buildroot}" \
        --enable-pcre=no \
        --with-logdir="/var/log/dansguardian/" \
	--mandir="%{_mandir}/" \
        --datadir=/usr/share/dansguardian \
	--sysconfdir="%{_sysconfdir}" \

 
%{__perl} -pi.orig -e '
		s|^(CHKCONFIG) =.*$|$1 = :|;
                s|^\tchown|#\tchown|;
		s|/usr/lib|%{_libdir}|g;
        ' Makefile

%{__make} %{?_smp_mflags}

%install
%{__rm} -rf %{buildroot}


%makeinstall
%{__install} -D -m0755 dansguardian.init %{buildroot}%{_initrddir}/dansguardian
%{__install} -D -m0755 squid_DG.init %{buildroot}%{_initrddir}/squid_DG

%post


%preun
if [ $1 -eq 0 ]; then
        /etc/init.d/dansguardian stop &>/dev/null || :

fi

%postun


%clean
%{__rm} -rf %{buildroot}

%files
%defattr(-, root, root, 0755)
%doc INSTALL README
%doc %{_mandir}/man?/*
%dir %{_sysconfdir}/dansguardian/
%{_sysconfdir}/dansguardian/*
%dir /usr/share/dansguardian
/usr/share/dansguardian/*
%{_sbindir}/dansguardian
/etc/init.d/dansguardian
/etc/init.d/squid_DG









%changelog
* Mon Dec 18 2006 Don Vosburg <don@vosburgs.org> - 2.9.8.1
- Updated to release 2.9.8.1, added to openSUSE build service
* Sat Oct 23 2004 Don Vosburg <don@vosburgs.org> - 2.8.0.3-1
- Updated to release 2.8.0.3

* Fri Jul 30 2004 Dag Wieers <dag@wieers.com> - 2.8.0.2-1
- Updated to release 2.8.0.2.

* Wed Jul 21 2004 Dag Wieers <dag@wieers.com> - 2.8.0-1
- Updated to release 2.8.0-0.

* Thu Apr 15 2004 Dag Wieers <dag@wieers.com> - 2.6.1.13-1
- Updated to release 2.6.1-13.

* Fri Mar 26 2004 Dag Wieers <dag@wieers.com> - 2.6.1.12-1
- Initial package. (using DAR)
openSUSE Build Service is sponsored by