#!/bin/bash
# ------------------------------------------------------
# This program will manage dansguardian on your system.
# Copyright (C) 2005 Jean-Paul Gigo <popaul77_chez_free.fr>
# This program is free software; you can redistribute it and/or modify 
# it under the terms of the GNU General Public License as published
# by the Free Software Foundation; either version 2 of the License. 
# This program is distributed in the hope that it will be useful, but 
# WITHOUT ANY WARRANTY; without even the implied warranty of 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
# See the GNU General Public License for more details. You should have 
# received a copy of the GNU General Public License along with this 
# program; if not, write to the 
# Free Software Foundation, Inc., 
# 675 Mass Ave, Cambridge, MA 02139, USA.
# ---------------------------------------


FILTRE="/etc/dansguardian/lists"
#GRP_COMMUN="commun"
LOG="/tmp/filtrix.log"                  ; export LOG

if [ -z $DISPLAY ]
   then
      DIALOG=dialog
   else
      DIALOG=Xdialog
fi

fichtemp=`tempfile 2>/dev/null` || fichtemp=/tmp/test$$
trap "rm -f $fichtemp" 0 1 2 5 15


$DIALOG --title " Filtrix" \
        --menu "Choisissez une action a accomplir sur le filtre Web  " 20 61 6 \
	 "1" "Interdire l'acces a un site" \
	 "2" "Autoriser l'acces a un site" \
	 "3" "Interdire l'usage d'un mot" \
	 "4" "Autoriser l'usage d'une partie de site" \
	 "5" "autoriser la navigation non filtree d'un PC local" 2> $fichtemp

valret=$?
CHOIX=`cat $fichtemp`
echo $CHOIX
case $valret in
  0)
    echo "choix nÂ°'$CHOIX' " ;;
  1)
    exit 0 ;;
  255)
    echo "Box closed." ;;
esac

#---------------------------------------------
int_site ()

{

# choisir un domaine :
$DIALOG --backtitle "Choisissez un domaine" \
--title " Filtrix" \
 --inputbox "Entrez le nom du domaine a interdire \n en minuscule et sans www \n exp: windowsupdate.com :" 16 51 2> $fichtemp
valret=$?
cat $fichtemp

		echo `cat $fichtemp` >> $FILTRE/bannedsitelist
}

#---------------------------------------------
#---------------------------------------------
aut_site ()

{

# choisir un domaine :
$DIALOG --backtitle "Choisissez un domaine" \
--title " Filtrix" \
 --inputbox "Entrez le nom du domaine a autoriser \n en minuscule et sans www \n exp: windowsupdate.com :" 16 51 2> $fichtemp
valret=$?
cat $fichtemp

		echo `cat $fichtemp` >> $FILTRE/exceptionsitelist
}
#----------------------------------------------
#---------------------------------------------
int_mot ()

{

# choisir un domaine :
$DIALOG --backtitle "Choisissez un mot" \
--title " Filtrix" \
 --inputbox "Entrez le mot a interdire en minuscule \n entre chevron exp: < porno > \n L'effet est different suivant les espaces \n avant et aprÃ¨s le mot:" 16 51 2> $fichtemp
valret=$?
cat $fichtemp

		echo `cat $fichtemp` >> $FILTRE/bannedphraselist
}
#---------------------------------------------
aut_mot ()

{

# choisir un domaine :
$DIALOG --backtitle "Choisissez un domaine" \
--title " Filtrix" \
 --inputbox "Entrez le chemin de la partie du \n site que vous desirez debloquer sans www. \n exemple:windowsupdate.fr/updatexppro/fr/:" 16 51 2> $fichtemp
valret=$?
cat $fichtemp

		echo `cat $fichtemp` >> $FILTRE/greysitelist
}
#---------------------------------------------
aut_ip ()

{
# choisir un domaine :
$DIALOG --backtitle "Choisissez une IP" \
--title " Filtrix" \
 --inputbox "Entrez l'adresse IP de la machine \n autorisee a naviguer sans filtrage \n exp: 192.168.111.55 :" 16 51 2> $fichtemp
valret=$?
cat $fichtemp

		echo `cat $fichtemp` >> $FILTRE/exceptioniplist
}
#

# main
# ------------------------
if [ $CHOIX = "1" ] ; then
	int_site
elif [ $CHOIX = "2" ] ; then
	aut_site
elif [ $CHOIX = "3" ] ; then
	int_mot
elif [ $CHOIX = "4" ] ; then
	aut_mot
elif [ $CHOIX = "5" ] ; then
	aut_ip
fi

#redemarrage de dansguardian
/etc/init.d/dansguardian restart

