#!/bin/bash

if [ "$UID" != "0" ]; then
  sudo -k
  if exec gksudo "$0"
  then
  echo > /dev/null 2>&1
  else
  exit 0
  fi
fi 

check_redirection_status ()
{
if sudo iptables -t nat -L | grep 8080 > /dev/null 2>&1;
then
	if sudo iptables -t nat -L | grep 127.0.0.1 > /dev/null 2>&1;
		then
		title_text1="Redirection      : <span foreground=\"#00FF00\" >ON</span>    ";
		else 
		title_text1="Redirection      : <span foreground=\"#CC0000\" >OFF</span>    ";
	fi;
else
title_text1="Redirection      : <span foreground=\"#CC0000\" >OFF</span>    ";
fi
}

check_tiny_status ()
{
    ## TinyProxy
    pid_tp="`pidof tinyproxy | tr -d [:space:]`"
    if (test -z $pid_tp);
    then title_text2="Tinyproxy            : <span foreground=\"#CC0000\" >OFF</span>    ";
    else title_text2="Tinyproxy            : <span foreground=\"#00FF00\" >ON</span>    ";
    fi
}

check_dans_status ()
{
## Check dansguardian status 
pid_dg="`pidof dansguardian | tr -d [:space:]`"
if (test -z $pid_dg);
then title_text3="DansGuardian : <span foreground=\"#CC0000\" >OFF</span>    ";
else title_text3="DansGuardian : <span foreground=\"#00FF00\" >ON</span>    ";
fi
}

check_internet_sharing_status ()
{
if grep 'net.ipv4.conf.default.forwarding=1' /etc/sysctl.conf> /dev/null 2>&1
then
title_text4="Internet Sharing : <span foreground=\"#00FF00\" >ON</span>"
else
title_text4="Internet Sharing : <span foreground=\"#CC0000\" >OFF</span>"
fi
}

check_filter_status ()
{
## Check filter
# Read current status
DATA=`grep "naughtynesslimit =" /etc/dansguardian/dansguardianf1.conf`
FILTER_LEVEL=`echo $DATA | sed s/"naughtynesslimit = "//`

	if [ "$FILTER_LEVEL" -le 75 ];
	then
	filter_status="Current Filter   : Filter for young children"
	else 
		if [ "$FILTER_LEVEL" -le 125 ];
		then
		filter_status="Current Filter   : Filter for old children"
		else 
		filter_status="Current Filter   : Filter for young adult"
		fi
	fi

}

check_firefox_status ()
{
## Check firefox proxy lock status
FIREFOX_VERSION=`firefox --version | sed s/"Mozilla Firefox "// | sed s/", Copyright (c) 1998 - 2009 mozilla.org"//`
FF_VERSION=`echo $FIREFOX_VERSION | sed 's/\([0-9]*.[0-9]*\).*/\1/'`
if grep 'lockPref("network.proxy.type", 0);' /usr/lib/firefox-$FIREFOX_VERSION/firefox.cfg > /dev/null 2>&1;
then
LOCK_STATUS=`grep 'lockPref("network.proxy.type", 0);' /usr/lib/firefox-$FIREFOX_VERSION/firefox.cfg | wc -l`
if [ "$LOCK_STATUS" = "0" ];
then
lock_status="<span foreground=\"#CC0000\" >Firefox proxy is unlocked</span>"
else
lock_status="<span foreground=\"#00FF00\" >Firefox proxy is locked</span>"
fi
else
lock_status="<span foreground=\"#CC0000\" >Firefox proxy is unlocked</span>"
fi
}

while true; do
check_redirection_status
check_tiny_status
check_dans_status
check_internet_sharing_status
check_filter_status
check_firefox_status
## Open First level menu
choice="$(zenity --window-icon=/usr/share/pixmaps/ucepc.png --width=300 --height=500 --list --column "" --title="Ubuntu CE Dansguardian GUI" --text="                                               <span foreground=\"#0000FF\" underline=\"double\" >CURRENT STATUS</span>\n\n$title_text1                                        $title_text2 \n\n$title_text3                                         $title_text4 \n\n$filter_status                Filter value         : $FILTER_LEVEL                \n\n                                         $lock_status\n"   \
        "Autoconfigure/Reset Dansguardian and Tinyproxy." \
        "Filter setting" \
        "Start Dansguardian" \
        "Stop Dansguardian" \
        "Lock Firefox Proxy" \
        "Unlock Firefox Proxy" \
        "Internet connection sharing" \
        "View denied log" \
	"Advance Setting" \
        "Exit")"

        case "${choice}" in

	"Autoconfigure/Reset Dansguardian and Tinyproxy." )
	## Backup original configuration
	zenity --info --title "Alert"  --text="dansguardian and tinyproxy configuration are overrides. They are moved to program.conf.original."
	sudo cp /etc/dansguardian/dansguardian.conf /etc/dansguardian/dansguardian.conf.original
	sudo cp /etc/tinyproxy/tinyproxy.conf /etc/tinyproxy/tinyproxy.conf.original

	## Automatic configuration of iptables, dansguardian and tinyproxy
	# Edit template
	LINE_NO_TEMPLATE=`grep -n 'You are seeing this error' /etc/dansguardian/languages/ukenglish/template.html | cut -f1 -d:`
	if grep 'Full Reason (debug/configure):' /etc/dansguardian/languages/ukenglish/template.html> /dev/null 2>&1
	then
	echo > /dev/null 2>&1
	else
	sudo perl -pi -e 'print "	<br><br><br><br>\n" if $. == '$LINE_NO_TEMPLATE'' /etc/dansguardian/languages/ukenglish/template.html
	sudo perl -pi -e 'print "	<textarea>-REASONLOGGED-</textarea>\n" if $. == '$LINE_NO_TEMPLATE'' /etc/dansguardian/languages/ukenglish/template.html
	sudo perl -pi -e 'print "	Full Reason (debug/configure):\n" if $. == '$LINE_NO_TEMPLATE'' /etc/dansguardian/languages/ukenglish/template.html
	fi
	sudo perl -pi -e 's/YOUR ORG NAME/Ubuntu Christian Edition/g;' /etc/dansguardian/languages/ukenglish/template.html
	sudo perl -pi -e 's/If you have any queries contact your ICT Coordinator or Network Manager./If you have issues with false positives, please request the system administrator to whitelist the domain./g;' /etc/dansguardian/languages/ukenglish/template.html

	# Configure transparent proxy
	LINE_NO=`grep -n 'iptables -P INPUT DROP' /etc/init.d/ubuntu_ce_firewall | cut -f1 -d:`
	if grep 'iptables -A OUTPUT -t nat ! -d 127.0.0.1 -p tcp --dport 80 -m owner ! --uid-owner root -j REDIRECT --to-ports 8080' /etc/init.d/ubuntu_ce_firewall> /dev/null 2>&1
	then
	echo > /dev/null 2>&1
	else
	sudo perl -pi -e 'print "iptables -A OUTPUT -t nat ! -d 127.0.0.1 -p tcp --dport 80 -m owner ! --uid-owner root -j REDIRECT --to-ports 8080\n" if $. == '$LINE_NO'' /etc/init.d/ubuntu_ce_firewall
	fi
	if grep 'iptables -A POSTROUTING -t nat -o lo -p tcp --dport 8080 -j SNAT --to 127.0.0.1' /etc/init.d/ubuntu_ce_firewall> /dev/null 2>&1
	then
	echo > /dev/null 2>&1
	else
	sudo perl -pi -e 'print "iptables -A POSTROUTING -t nat -o lo -p tcp --dport 8080 -j SNAT --to 127.0.0.1\n" if $. == '$LINE_NO'' /etc/init.d/ubuntu_ce_firewall
	fi
	sudo /etc/init.d/ubuntu_ce_firewall restart 2>&1 | zenity --width=500 --progress --pulsate --auto-close --title="Restarting firewall...." 
	## Configure tinyproxy
	USER=`grep ^User /etc/tinyproxy/tinyproxy.conf`
	GROUP=`grep ^Group /etc/tinyproxy/tinyproxy.conf`
	PORT=`grep ^Port /etc/tinyproxy/tinyproxy.conf`
	sudo perl -pi -e "s/$USER/User root/g;" /etc/tinyproxy/tinyproxy.conf
	sudo perl -pi -e "s/$GROUP/Group root/g;" /etc/tinyproxy/tinyproxy.conf
	sudo perl -pi -e "s/$PORT/Port 3128/g;" /etc/tinyproxy/tinyproxy.conf
	check3=`ls /etc/rc2.d/ | grep tinyproxy | grep K`
	if [ "$check3" = "" ];
	then
		pid_tp="`pidof tinyproxy | tr -d [:space:]`"
		if (test -z $pid_tp);
		then sudo /etc/init.d/tinyproxy start;
		fi
	else
	for n in `seq 2 5`;
	do 
	stopname=`ls /etc/rc$n.d/ | grep tinyproxy`
	knumber=`ls /etc/rc$n.d/ | grep tinyproxy | sed s/K// | sed s/tinyproxy//`
	snumber=`echo $((100-$knumber))`
	startname=`ls /etc/rc$n.d/ | grep tinyproxy | sed s/K/S/ | sed s/$knumber/$snumber/`
	sudo mv /etc/rc$n.d/$stopname /etc/rc$n.d/$startname
	done
	sudo /etc/init.d/tinyproxy start
	fi
	##Configure dansguardian.conf
	unconfigured=`grep UNCONFIGURED /etc/dansguardian/dansguardian.conf`
	sudo perl -pi -e "s/$unconfigured/# UNCONFIGURED - configured using dansguardian_gui auto/g;" /etc/dansguardian/dansguardian.conf
	sudo perl -pi -e 's/^\./#\./g' /etc/dansguardian/lists/bannedextensionlist 
	sudo sed -i 's/\(^[a-z]\)\(.*\)/#\1\2/' /etc/dansguardian/lists/bannedmimetypelist
	sudo perl -pi -e "s/$DATA/naughtynesslimit = 100/g;" /etc/dansguardian/dansguardianf1.conf
	check4=`ls /etc/rc2.d/ | grep dansguardian | grep K`
	if [ "$check4" = "" ];
	then
	pid_dg="`pidof dansguardian | tr -d [:space:]`"
	if (test -z $pid_dg);
	then sudo /etc/init.d/dansguardian start 2>&1 | zenity --width=500 --progress --pulsate --auto-close --title="Starting dansguardian...." ;
	fi
	else
	for n in `seq 2 5`;
	do 
	stopname=`ls /etc/rc$n.d/ | grep dansguardian`
	knumber=`ls /etc/rc$n.d/ | grep dansguardian | sed s/K// | sed s/dansguardian//`
	snumber=`echo $((100-$knumber))`
	startname=`ls /etc/rc$n.d/ | grep dansguardian | sed s/K/S/ | sed s/$knumber/$snumber/`
	sudo mv /etc/rc$n.d/$stopname /etc/rc$n.d/$startname
	done
	sudo /etc/init.d/dansguardian start 2>&1 | zenity --width=500 --progress --pulsate --auto-close --title="Starting dansguardian...." 
	fi
	;;

	"Filter setting" )
	output=$(zenity --title="Select filter level" --text="Please choose one of the filtering levels, or choose a custom level." --list --column="Levels:" "50: for young children" "100: for old children" "160: for young adults" "Custom" --height=230)

	if [ "$output" = "Custom" ]; then
	FILTER_LEVEL=$(zenity --title="Slide to choose filter level" --scale --text "Strict                                     Less Strict" --min-value=50 --max-value=160 --value="$FILTER_LEVEL")
	else
    FILTER_LEVEL="`echo $output | grep -o ^[^:]*`"
	fi

	if [ "$FILTER_LEVEL" = "" ]; then
	echo  > /dev/null 2>&1	
	else
	sudo perl -pi -e "s/$DATA/naughtynesslimit = $FILTER_LEVEL/g;" /etc/dansguardian/dansguardianf1.conf
	sudo /etc/init.d/dansguardian restart 2>&1 | zenity --width=500 --progress --pulsate --auto-close --title="Restarting dansguardian...." 
	fi
	;;

	"Start Dansguardian" )
	# Check whether internet is shared to LAN
	if grep 'net.ipv4.conf.default.forwarding=1' /etc/sysctl.conf> /dev/null 2>&1
	then
	##Load transparent proxy at boot on LAN, Below should be written to /etc/init.d/ubuntu_ce_firewall, check to avoid double
	wan=`route | grep default | awk '{print $NF}'`
	proxy_ip=`ifconfig $wan | grep "inet addr" |  awk '{print $2}' | sed 's/addr://'`
	lan_ip=`echo $proxy_ip | sed 's/\([0-9]*\.[0-9]*\.[0-9]*\)\.\([0-9]\)*/\1\.0\/24/'`
	lan=`grep static /etc/network/interfaces | awk '{print $2}'`

		if grep 'iptables -A INPUT -p tcp -s '$lan_ip' --dport 8080 -j ACCEPT' /etc/init.d/ubuntu_ce_firewall> /dev/null 2>&1
		then
		echo > /dev/null 2>&1
		else

		LINE_NO=`grep -n 'iptables -P INPUT DROP' /etc/init.d/ubuntu_ce_firewall| cut -f1 -d:`
			if grep 'iptables -A PREROUTING -t nat -i '$lan' -p tcp --dport 80 -j REDIRECT --to-ports 8080' /etc/init.d/ubuntu_ce_firewall> /dev/null 2>&1
			then
			echo > /dev/null 2>&1
			else
			sudo perl -pi -e 'print "iptables -A PREROUTING -t nat -i '$lan' -p tcp --dport 80 -j REDIRECT --to-ports 8080\n" if $. == '$LINE_NO'' /etc/init.d/ubuntu_ce_firewall
			fi
			if grep 'iptables -A INPUT -i '$lan' -p tcp --dport 8080 -j ACCEPT' /etc/init.d/ubuntu_ce_firewall> /dev/null 2>&1
			then
			echo > /dev/null 2>&1
			else
			sudo perl -pi -e 'print "iptables -A INPUT -i '$lan' -p tcp --dport 8080 -j ACCEPT\n" if $. == '$LINE_NO'' /etc/init.d/ubuntu_ce_firewall
			fi
			if grep 'iptables -A INPUT -i '$lan' -p tcp --dport 80 -j ACCEPT' /etc/init.d/ubuntu_ce_firewall> /dev/null 2>&1
			then
			echo > /dev/null 2>&1
			else
			sudo perl -pi -e 'print "iptables -A INPUT -i '$lan' -p tcp --dport 80 -j ACCEPT\n" if $. == '$LINE_NO'' /etc/init.d/ubuntu_ce_firewall
			fi
		fi
	fi
	# Configure transparent proxy
	LINE_NO=`grep -n 'iptables -P INPUT DROP' /etc/init.d/ubuntu_ce_firewall | cut -f1 -d:`
	if grep 'iptables -A OUTPUT -t nat ! -d 127.0.0.1 -p tcp --dport 80 -m owner ! --uid-owner root -j REDIRECT --to-ports 8080' /etc/init.d/ubuntu_ce_firewall> /dev/null 2>&1
	then
	echo > /dev/null 2>&1
	else
	sudo perl -pi -e 'print "iptables -A OUTPUT -t nat ! -d 127.0.0.1 -p tcp --dport 80 -m owner ! --uid-owner root -j REDIRECT --to-ports 8080\n" if $. == '$LINE_NO'' /etc/init.d/ubuntu_ce_firewall
	fi
	if grep 'iptables -A POSTROUTING -t nat -o lo -p tcp --dport 8080 -j SNAT --to 127.0.0.1' /etc/init.d/ubuntu_ce_firewall> /dev/null 2>&1
	then
	echo > /dev/null 2>&1
	else
	sudo perl -pi -e 'print "iptables -A POSTROUTING -t nat -o lo -p tcp --dport 8080 -j SNAT --to 127.0.0.1\n" if $. == '$LINE_NO'' /etc/init.d/ubuntu_ce_firewall
	fi
	sudo /etc/init.d/ubuntu_ce_firewall restart 2>&1 | zenity --width=500 --progress --pulsate --auto-close --title="Restarting firewall...." 


	
	## Loading tinyproxy at boot
	check=`ls /etc/rc2.d/ | grep tinyproxy | grep K`
	if [ "$check" = "" ];
	then
	zenity --info --title "Alert"  --text='tinyproxy is already enabled, please file a bug if it is disabled on boot.'
	else
	for n in `seq 2 5`;
	do 
	stopname=`ls /etc/rc$n.d/ | grep tinyproxy`
	knumber=`ls /etc/rc$n.d/ | grep tinyproxy | sed s/K// | sed s/tinyproxy//`
	snumber=`echo $((100-$knumber))`
	startname=`ls /etc/rc$n.d/ | grep tinyproxy | sed s/K/S/ | sed s/$knumber/$snumber/`
	sudo mv /etc/rc$n.d/$stopname /etc/rc$n.d/$startname
	done
	sudo /etc/init.d/tinyproxy start 2>&1 | zenity --width=500 --progress --pulsate --auto-close --title="Starting tinyproxy...." 
	fi

	## Loading dansguardian at boot
	check=`ls /etc/rc2.d/ | grep dansguardian | grep K`
	if [ "$check" = "" ];
	then
	pid_dg="`pidof dansguardian | tr -d [:space:]`"
	if (test -z $pid_dg);
	then sudo /etc/init.d/dansguardian start 2>&1 | zenity --width=500 --progress --pulsate --auto-close --title="Starting dansguardian...." ;
	fi
	zenity --info --title "Alert"  --text='Dansguardian is already enabled, please file a bug if it is disabled on boot.'
	else
	for n in `seq 2 5`;
	do 
	stopname=`ls /etc/rc$n.d/ | grep dansguardian`
	knumber=`ls /etc/rc$n.d/ | grep dansguardian | sed s/K// | sed s/dansguardian//`
	snumber=`echo $((100-$knumber))`
	startname=`ls /etc/rc$n.d/ | grep dansguardian | sed s/K/S/ | sed s/$knumber/$snumber/`
	sudo mv /etc/rc$n.d/$stopname /etc/rc$n.d/$startname
	done
	sudo /etc/init.d/dansguardian start 2>&1 | zenity --width=500 --progress --pulsate --auto-close --title="Starting dansguardian...."
	fi
	;;

	"Stop Dansguardian" )
	# Check whether internet is shared to LAN
	if grep 'net.ipv4.conf.default.forwarding=1' /etc/sysctl.conf> /dev/null 2>&1
	then
	wan=`route | grep default | awk '{print $NF}'`
	proxy_ip=`ifconfig $wan | grep "inet addr" |  awk '{print $2}' | sed 's/addr://'`
	lan_ip=`echo $proxy_ip | sed 's/\([0-9]*\.[0-9]*\.[0-9]*\)\.\([0-9]\)*/\1\.0\/24/'`
	lan=`grep static /etc/network/interfaces | awk '{print $2}'`			
		## Remove transparent proxy at boot on LAN
		if grep 'iptables -A PREROUTING -t nat -i '$lan' -p tcp --dport 80 -j REDIRECT --to-ports 8080' /etc/init.d/ubuntu_ce_firewall> /dev/null 2>&1
		then
		LINE_NO2=`grep -n 'iptables -A PREROUTING -t nat -i '$lan' -p tcp --dport 80 -j REDIRECT --to-ports 8080' /etc/init.d/ubuntu_ce_firewall| cut -f1 -d:`
		sudo perl -ni -e 'print unless $. == '$LINE_NO2'' /etc/init.d/ubuntu_ce_firewall
		fi		
	fi
	sudo /etc/init.d/dansguardian stop 2>&1 | zenity --width=500 --progress --pulsate --auto-close --title="Stopping dansguardian...."
	sudo /etc/init.d/tinyproxy stop 2>&1 | zenity --width=500 --progress --pulsate --auto-close --title="Stopping tinyproxy...."
	## Prevent loading dansguardian at boot

	check=`ls /etc/rc2.d/ | grep dansguardian | grep S`
	if [ "$check" = "" ];
	then
	zenity --info --title "Alert"  --text='Dansguardian is already disabled, please file a bug if it is enabled on boot.'
	else
	for n in `seq 2 5`;
	do 
	startname=`ls /etc/rc$n.d/ | grep dansguardian`
	snumber=`ls /etc/rc$n.d/ | grep dansguardian | sed s/S// | sed s/dansguardian//`
	knumber=`echo $((100-$snumber))`
	stopname=`ls /etc/rc$n.d/ | grep dansguardian | sed s/S/K/ | sed s/$snumber/$knumber/`
	sudo mv /etc/rc$n.d/$startname /etc/rc$n.d/$stopname
	done
	fi
	## Prevent loading tinyproxy at boot

	check=`ls /etc/rc2.d/ | grep tinyproxy | grep S`
	if [ "$check" = "" ];
	then
	zenity --info --title "Alert"  --text='tinyproxy is already disabled, please file a bug if it is enabled on boot.'
	else
	for n in `seq 2 5`;
	do 
	startname=`ls /etc/rc$n.d/ | grep tinyproxy`
	snumber=`ls /etc/rc$n.d/ | grep tinyproxy | sed s/S// | sed s/tinyproxy//`
	knumber=`echo $((100-$snumber))`
	stopname=`ls /etc/rc$n.d/ | grep tinyproxy | sed s/S/K/ | sed s/$snumber/$knumber/`
	sudo mv /etc/rc$n.d/$startname /etc/rc$n.d/$stopname
	done
	fi
	## Prevent configuring port redirection on boot
	if grep 'iptables -A OUTPUT -t nat ! -d 127.0.0.1 -p tcp --dport 80 -m owner ! --uid-owner root -j REDIRECT --to-ports 8080' /etc/init.d/ubuntu_ce_firewall> /dev/null 2>&1;
	then
	LINE_NO1=`grep -n 'iptables -A OUTPUT -t nat ! -d 127.0.0.1 -p tcp --dport 80 -m owner ! --uid-owner root -j REDIRECT --to-ports 8080' /etc/init.d/ubuntu_ce_firewall| cut -f1 -d:`
	sudo perl -ni -e 'print unless $. == '$LINE_NO1'' /etc/init.d/ubuntu_ce_firewall
	fi
	if grep 'iptables -A POSTROUTING -t nat -o lo -p tcp --dport 8080 -j SNAT --to 127.0.0.1' /etc/init.d/ubuntu_ce_firewall> /dev/null 2>&1;
	then
	LINE_NO2=`grep -n 'iptables -A POSTROUTING -t nat -o lo -p tcp --dport 8080 -j SNAT --to 127.0.0.1' /etc/init.d/ubuntu_ce_firewall| cut -f1 -d:`
	sudo perl -ni -e 'print unless $. == '$LINE_NO2'' /etc/init.d/ubuntu_ce_firewall
	fi
	sudo /etc/init.d/ubuntu_ce_firewall restart 2>&1 | zenity --width=500 --progress --pulsate --auto-close --title="Restarting firewall...."
	;;

	"Lock Firefox Proxy" )
	FIREFOX_VERSION=`firefox --version | sed s/"Mozilla Firefox "// | sed s/", Copyright (c) 1998 - 2009 mozilla.org"//`
	FF_VERSION=`echo $FIREFOX_VERSION | sed 's/\([0-9]*.[0-9]*\).*/\1/'`
	if grep 'lockPref("network.proxy.type", 0);' /usr/lib/firefox-$FIREFOX_VERSION/firefox.cfg > /dev/null 2>&1;
	then
	zenity --info --title "Alert"  --text='Firefox Proxy is already lock, please restart your browser and file a bug if it is still unlock.'
	else
	LOCK_STATUS=`grep 'lockPref("network.proxy.type", 0);' /usr/lib/firefox-$FIREFOX_VERSION/firefox.cfg | wc -l`
	if [ "$LOCK_STATUS" = "0" ];
	then
	echo 'lockPref("network.proxy.type", 0);' | sudo tee -a /usr/lib/firefox-$FIREFOX_VERSION/firefox.cfg > /dev/null 2>&1
	echo 'lockPref("network.proxy.type", 0);' | sudo tee -a /etc/firefox-$FF_VERSION/pref/firefox.js > /dev/null 2>&1
	zenity --info --title "Alert"  --text='Please restart your browser to complete the process.'
	else
	zenity --info --title "Alert"  --text='Firefox Proxy is already lock, please restart your browser and file a bug if it is still unlock.'
	fi
	fi
    	;;

	"Unlock Firefox Proxy" )
	FIREFOX_VERSION=`firefox --version | sed s/"Mozilla Firefox "// | sed s/", Copyright (c) 1998 - 2009 mozilla.org"//`
	FF_VERSION=`echo $FIREFOX_VERSION | sed 's/\([0-9]*.[0-9]*\).*/\1/'`
	if grep 'lockPref("network.proxy.type", 0);' /usr/lib/firefox-$FIREFOX_VERSION/firefox.cfg > /dev/null 2>&1;
	then
		LOCK_STATUS=`grep 'lockPref("network.proxy.type", 0);' /usr/lib/firefox-$FIREFOX_VERSION/firefox.cfg | wc -l`
		if [ "$LOCK_STATUS" = "0" ];
		then
		zenity --info --title "Alert"  --text='Firefox Proxy is already unlock, please restart your browser and file a bug if it is still lock.'
		else
		LINE_NO1=`grep -n 'lockPref("network.proxy.type", 0);' /usr/lib/firefox-$FIREFOX_VERSION/firefox.cfg | cut -f1 -d:`
		sudo perl -ni -e 'print unless $. == '$LINE_NO1'' /usr/lib/firefox-$FIREFOX_VERSION/firefox.cfg
		LINE_NO2=`grep -n 'lockPref("network.proxy.type", 0);' /etc/firefox-$FF_VERSION/pref/firefox.js | cut -f1 -d:`
		sudo perl -ni -e 'print unless $. == '$LINE_NO2'' /etc/firefox-$FF_VERSION/pref/firefox.js
		fi
	else
	zenity --info --title "Alert"  --text='Firefox Proxy is already unlock, please restart your browser and file a bug if it is still lock.'
	fi
	;;

        "Internet connection sharing" )
	while true; do
	check_internet_sharing_status
	choice="$(zenity --width=400 --height=210 --list --column "" --title="Please select one:" --text="$title_text4"   \
        "Start sharing: I have two or more network cards" \
        "Start sharing: I only have one network card" \
        "Stop internet connection sharing" \
        "Back")"
	case "${choice}" in

        "Start sharing: I have two or more network cards" )
	# Capturing default route
	wan=`route | grep default | awk '{print $NF}'`

	## Capturing eth
	option=`ifconfig | grep eth | awk '{print $1}' | sed "s/$wan//"`

	# Get the interface need to give internet (LAN interface)
	if [ "$option" = "" ];
	then
	zenity --info --title "Alert"  --text="You do not have any ethernet card connected to LAN. You should choose 'Start sharing: I only have one network card' instead. Please file a bug report if this is not the case."
	else
	while [ "$lan" = "" ]
	do
	lan="$(zenity --width=400 --height=50 --list --column "" --title="Select a private network connection" --text="Select a network interface from the list below" $option)"
	done

	## Close port 8080 on wan, just in case it is already open for 1 network card only
	proxy_ip=`ifconfig $wan | grep "inet addr" |  awk '{print $2}' | sed 's/addr://'`
	lan_ip=`echo $proxy_ip | sed 's/\([0-9]*\.[0-9]*\.[0-9]*\)\.\([0-9]\)*/\1\.0\/24/'`
	if grep 'iptables -A INPUT -p tcp -s '$lan_ip' --dport 8080 -j ACCEPT' /etc/init.d/ubuntu_ce_firewall> /dev/null 2>&1;
	then
	LINE_NO5=`grep -n 'iptables -A INPUT -p tcp -s '$lan_ip' --dport 8080 -j ACCEPT' /etc/init.d/ubuntu_ce_firewall| cut -f1 -d:`
	sudo perl -ni -e 'print unless $. == '$LINE_NO5'' /etc/init.d/ubuntu_ce_firewall
	fi

	# Below should be written to BLANK /etc/network/interfaces, copy first to backup
	if [ -f /etc/network/interfaces.original ]
		then
		echo > /dev/null 2>&1
		else
		sudo cp /etc/network/interfaces /etc/network/interfaces.original
	fi
	echo 'auto lo' | sudo tee /etc/network/interfaces > /dev/null 2>&1
	echo 'iface lo inet loopback' | sudo tee -a /etc/network/interfaces > /dev/null 2>&1
	echo | sudo tee -a /etc/network/interfaces > /dev/null 2>&1
	echo 'auto '$lan'' | sudo tee -a /etc/network/interfaces > /dev/null 2>&1
	echo 'iface '$lan' inet static' | sudo tee -a /etc/network/interfaces > /dev/null 2>&1
	echo '        address 10.8.16.1' | sudo tee -a /etc/network/interfaces > /dev/null 2>&1
	echo '        netmask 255.255.255.0' | sudo tee -a /etc/network/interfaces > /dev/null 2>&1
	echo '        broadcast 10.8.16.0' | sudo tee -a /etc/network/interfaces > /dev/null 2>&1
	echo '        network 10.8.16.0' | sudo tee -a /etc/network/interfaces > /dev/null 2>&1

	# to activate now instead of reboot:
	sudo ifconfig $lan 10.8.16.1

	# Capture the default gateway
	# router=` ifconfig | grep "inet addr" |  awk '{print $2}' | sed 's/addr://' | sed 's/127.0.0.1//' | sed -e :0 -e '/,.*,.*,/b' -e N -e 's/\n/,/' -e b0 | sed '$s/,$//'`
	router1=`ifconfig $wan | grep "inet addr" |  awk '{print $2}' | sed 's/addr://'`
	router2=`ifconfig $lan | grep "inet addr" |  awk '{print $2}' | sed 's/addr://'`
	# Capture dns
	dns=`grep nameserver /etc/resolv.conf  | awk '{print $NF}'`

	# Below setting should be written to BLANK /etc/dhcp3/dhcpd.conf, copy first to backup
	if [ -f /etc/dhcp3/dhcpd.conf.original ]
	then
	echo > /dev/null 2>&1
	else
	sudo cp /etc/dhcp3/dhcpd.conf /etc/dhcp3/dhcpd.conf.original
	fi
	echo 'ddns-update-style none;' | sudo tee /etc/dhcp3/dhcpd.conf > /dev/null 2>&1
	echo 'option domain-name "mynetwork";' | sudo tee -a /etc/dhcp3/dhcpd.conf > /dev/null 2>&1
	echo 'option domain-name-servers '$dns';' | sudo tee -a /etc/dhcp3/dhcpd.conf > /dev/null 2>&1
#	echo 'option routers '$router';' | sudo tee -a /etc/dhcp3/dhcpd.conf > /dev/null 2>&1
	echo 'option routers '$router1','$router2';' | sudo tee -a /etc/dhcp3/dhcpd.conf > /dev/null 2>&1
	echo  | sudo tee -a /etc/dhcp3/dhcpd.conf > /dev/null 2>&1
	echo 'default-lease-time 42300;' | sudo tee -a /etc/dhcp3/dhcpd.conf > /dev/null 2>&1
	echo 'max-lease-time 84600;' | sudo tee -a /etc/dhcp3/dhcpd.conf > /dev/null 2>&1
	echo 'authoritative;' | sudo tee -a /etc/dhcp3/dhcpd.conf > /dev/null 2>&1
	echo  | sudo tee -a /etc/dhcp3/dhcpd.conf > /dev/null 2>&1
	echo 'log-facility local7;' | sudo tee -a /etc/dhcp3/dhcpd.conf > /dev/null 2>&1
	echo  | sudo tee -a /etc/dhcp3/dhcpd.conf > /dev/null 2>&1
	echo 'subnet 10.8.16.0 netmask 255.255.255.0 {' | sudo tee -a /etc/dhcp3/dhcpd.conf > /dev/null 2>&1
	echo '  range 10.8.16.50 10.8.16.150;' | sudo tee -a /etc/dhcp3/dhcpd.conf > /dev/null 2>&1
	echo } | sudo tee -a /etc/dhcp3/dhcpd.conf > /dev/null 2>&1


	# Below setting should be written to BLANK /etc/default/dhcp3-server, copy first to backup
	if [ -f /etc/default/dhcp3-server.original ]
	then
	echo > /dev/null 2>&1
	else
	sudo cp /etc/default/dhcp3-server /etc/default/dhcp3-server.original
	fi
	echo INTERFACES='"'$lan'"' | sudo tee /etc/default/dhcp3-server > /dev/null 2>&1
	sudo /etc/init.d/dhcp3-server restart 2>&1 | zenity --width=500 --progress --pulsate --auto-close --title="Restarting dhcp server...."

	# Below should be written to /etc/sysctl.conf, check to replace #net.ipv4.conf.default.forwarding=1
	if grep net.ipv4.conf.default.forwarding= /etc/sysctl.conf > /dev/null 2>&1
		then 
		forward=`grep net.ipv4.conf.default.forwarding= /etc/sysctl.conf`
		sudo perl -pi -e "s/$forward/net.ipv4.conf.default.forwarding=1/g;" /etc/sysctl.conf > /dev/null 2>&1
		else
		echo net.ipv4.conf.default.forwarding=1 | sudo tee -a /etc/sysctl.conf > /dev/null 2>&1
	fi
	if grep net.ipv4.ip_forward= /etc/sysctl.conf > /dev/null 2>&1
		then 
		forward1=`grep net.ipv4.ip_forward= /etc/sysctl.conf`
		sudo perl -pi -e "s/$forward1/net.ipv4.ip_forward=1/g;" /etc/sysctl.conf > /dev/null 2>&1
		else
		echo net.ipv4.ip_forward=1 | sudo tee -a /etc/sysctl.conf > /dev/null 2>&1
	fi
	# to activate now instead of reboot:
	sudo sysctl -w net.ipv4.ip_forward=1  > /dev/null 2>&1

	# Below should be written to /etc/init.d/ubuntu_ce_firewall, check to avoid double
	# echo /sbin/iptables --table nat -A POSTROUTING -o $wan -j MASQUERADE

	LINE_NO=`grep -n 'iptables -P INPUT DROP' /etc/init.d/ubuntu_ce_firewall| cut -f1 -d:`
	if grep 'iptables --table nat -A POSTROUTING -o '$wan' -j MASQUERADE' /etc/init.d/ubuntu_ce_firewall> /dev/null 2>&1
	then
	echo > /dev/null 2>&1
	else
	sudo perl -pi -e 'print "iptables --table nat -A POSTROUTING -o '$wan' -j MASQUERADE\n" if $. == '$LINE_NO'' /etc/init.d/ubuntu_ce_firewall
	fi

pid_dg="`pidof dansguardian | tr -d [:space:]`"
if (test -z $pid_dg);
then 	echo > /dev/null 2>&1 ;
else
	##Load transparent proxy at boot on LAN, Below should be written to /etc/init.d/ubuntu_ce_firewall, check to avoid double
	LINE_NO=`grep -n 'iptables -P INPUT DROP' /etc/init.d/ubuntu_ce_firewall| cut -f1 -d:`
	if grep 'iptables -A PREROUTING -t nat -i '$lan' -p tcp 	wan=`route | grep default | awk '{print $NF}'`
	proxy_ip=`ifconfig $wan | grep "inet addr" |  awk '{print $2}' | sed 's/addr://'`
	lan_ip=`echo $proxy_ip | sed 's/\([0-9]*\.[0-9]*\.[0-9]*\)\.\([0-9]\)*/\1\.0\/24/'`--dport 80 -j REDIRECT --to-ports 8080' /etc/init.d/ubuntu_ce_firewall> /dev/null 2>&1
	then
	echo > /dev/null 2>&1
	else
	sudo perl -pi -e 'print "iptables -A PREROUTING -t nat -i '$lan' -p tcp --dport 80 -j REDIRECT --to-ports 8080\n" if $. == '$LINE_NO'' /etc/init.d/ubuntu_ce_firewall
	fi
	if grep 'iptables -A INPUT -i '$lan' -p tcp --dport 8080 -j ACCEPT' /etc/init.d/ubuntu_ce_firewall> /dev/null 2>&1
	then
	echo > /dev/null 2>&1
	else
	sudo perl -pi -e 'print "iptables -A INPUT -i '$lan' -p tcp --dport 8080 -j ACCEPT\n" if $. == '$LINE_NO'' /etc/init.d/ubuntu_ce_firewall
	fi
	if grep 'iptables -A INPUT -i '$lan' -p tcp --dport 80 -j ACCEPT' /etc/init.d/ubuntu_ce_firewall> /dev/null 2>&1
	then
	echo > /dev/null 2>&1
	else
	sudo perl -pi -e 'print "iptables -A INPUT -i '$lan' -p tcp --dport 80 -j ACCEPT\n" if $. == '$LINE_NO'' /etc/init.d/ubuntu_ce_firewall
	fi
fi
	sudo /etc/init.d/ubuntu_ce_firewall restart 2>&1 | zenity --width=500 --progress --pulsate --auto-close --title="Restarting firewall...."
fi
	;;

        "Start sharing: I only have one network card" )
	pid_dg="`pidof dansguardian | tr -d [:space:]`"
if (test -z $pid_dg);
then zenity --warning --title="Please enable Dansguardian First" --text="You must enable dansguardian before you could share internet filtering." ;
else


	wan=`route | grep default | awk '{print $NF}'`
	proxy_ip=`ifconfig $wan | grep "inet addr" |  awk '{print $2}' | sed 's/addr://'`
	lan_ip=`echo $proxy_ip | sed 's/\([0-9]*\.[0-9]*\.[0-9]*\)\.\([0-9]\)*/\1\.0\/24/'`

	## Just in case already enable for two cards, prevent forwarding from LAN to internet
	if grep 'iptables --table nat -A POSTROUTING -o '$wan' -j MASQUERADE' /etc/init.d/ubuntu_ce_firewall> /dev/null 2>&1;
	then
	LINE_NO1=`grep -n 'iptables --table nat -A POSTROUTING -o '$wan' -j MASQUERADE' /etc/init.d/ubuntu_ce_firewall| cut -f1 -d:`
	sudo perl -ni -e 'print unless $. == '$LINE_NO1'' /etc/init.d/ubuntu_ce_firewall
	fi
	## Remove transparent proxy at boot on LAN in case of 2 or more network cards, just in case already enabled
	if grep 'iptables -A PREROUTING -t nat -i '$lan' -p tcp --dport 80 -j REDIRECT --to-ports 8080' /etc/init.d/ubuntu_ce_firewall> /dev/null 2>&1;
	then
	LINE_NO2=`grep -n 'iptables -A PREROUTING -t nat -i '$lan' -p tcp --dport 80 -j REDIRECT --to-ports 8080' /etc/init.d/ubuntu_ce_firewall| cut -f1 -d:`
	sudo perl -ni -e 'print unless $. == '$LINE_NO2'' /etc/init.d/ubuntu_ce_firewall
	fi
	if grep 'iptables -A INPUT -i '$lan' -p tcp --dport 8080 -j ACCEPT' /etc/init.d/ubuntu_ce_firewall> /dev/null 2>&1;
	then
	LINE_NO3=`grep -n 'iptables -A INPUT -i '$lan' -p tcp --dport 8080 -j ACCEPT' /etc/init.d/ubuntu_ce_firewall| cut -f1 -d:`
	sudo perl -ni -e 'print unless $. == '$LINE_NO3'' /etc/init.d/ubuntu_ce_firewall
	fi
	if grep 'iptables -A INPUT -i '$lan' -p tcp --dport 80 -j ACCEPT' /etc/init.d/ubuntu_ce_firewall> /dev/null 2>&1;
	then
	LINE_NO4=`grep -n 'iptables -A INPUT -i '$lan' -p tcp --dport 80 -j ACCEPT' /etc/init.d/ubuntu_ce_firewall| cut -f1 -d:`
	sudo perl -ni -e 'print unless $. == '$LINE_NO4'' /etc/init.d/ubuntu_ce_firewall
	fi

	# Below should be written to /etc/sysctl.conf, check to replace #net.ipv4.conf.default.forwarding=1
	if grep net.ipv4.conf.default.forwarding= /etc/sysctl.conf > /dev/null 2>&1
		then 
		forward=`grep net.ipv4.conf.default.forwarding= /etc/sysctl.conf`
		sudo perl -pi -e "s/$forward/net.ipv4.conf.default.forwarding=1/g;" /etc/sysctl.conf > /dev/null 2>&1
		else
		echo net.ipv4.conf.default.forwarding=1 | sudo tee -a /etc/sysctl.conf > /dev/null 2>&1
	fi
	if grep net.ipv4.ip_forward= /etc/sysctl.conf > /dev/null 2>&1
		then 
		forward1=`grep net.ipv4.ip_forward= /etc/sysctl.conf`
		sudo perl -pi -e "s/$forward1/net.ipv4.ip_forward=1/g;" /etc/sysctl.conf > /dev/null 2>&1
		else
		echo net.ipv4.ip_forward=1 | sudo tee -a /etc/sysctl.conf > /dev/null 2>&1
	fi
	# to activate now instead of reboot:
	sudo sysctl -w net.ipv4.ip_forward=1  > /dev/null 2>&1

	# Below should be written to /etc/init.d/ubuntu_ce_firewall, check to avoid double
	LINE_NO=`grep -n 'iptables -P INPUT DROP' /etc/init.d/ubuntu_ce_firewall| cut -f1 -d:`
	if grep 'iptables -A INPUT -p tcp -s '$lan_ip' --dport 8080 -j ACCEPT' /etc/init.d/ubuntu_ce_firewall> /dev/null 2>&1
	then
	echo > /dev/null 2>&1
	else
	sudo perl -pi -e 'print "iptables -A INPUT -p tcp -s '$lan_ip' --dport 8080 -j ACCEPT\n" if $. == '$LINE_NO'' /etc/init.d/ubuntu_ce_firewall
	fi
	sudo /etc/init.d/ubuntu_ce_firewall restart 2>&1 | zenity --width=500 --progress --pulsate --auto-close --title="Restarting firewall...."
	zenity --info --title="Job complete" --text="To share internet filtering, change proxy on client browser to $proxy_ip:8080." 
fi
	;;

        "Stop internet connection sharing" )

	lan=`grep static /etc/network/interfaces | awk '{print $2}'`
	wan=`route | grep default | awk '{print $NF}'`
	proxy_ip=`ifconfig $wan | grep "inet addr" |  awk '{print $2}' | sed 's/addr://'`
	lan_ip=`echo $proxy_ip | sed 's/\([0-9]*\.[0-9]*\.[0-9]*\)\.\([0-9]\)*/\1\.0\/24/'`
	# Below should be written to /etc/sysctl.conf, check to replace #net.ipv4.conf.default.forwarding=1
	if grep net.ipv4.conf.default.forwarding= /etc/sysctl.conf > /dev/null 2>&1
		then 
		forward=`grep net.ipv4.conf.default.forwarding= /etc/sysctl.conf`
		sudo perl -pi -e "s/$forward/net.ipv4.conf.default.forwarding=0/g;" /etc/sysctl.conf > /dev/null 2>&1
		else
		echo net.ipv4.conf.default.forwarding=0 | sudo tee -a /etc/sysctl.conf > /dev/null 2>&1
	fi
	if grep net.ipv4.ip_forward= /etc/sysctl.conf > /dev/null 2>&1
		then 
		forward1=`grep net.ipv4.ip_forward= /etc/sysctl.conf`
		sudo perl -pi -e "s/$forward1/net.ipv4.ip_forward=0/g;" /etc/sysctl.conf > /dev/null 2>&1
		else
		echo net.ipv4.ip_forward=0 | sudo tee -a /etc/sysctl.conf > /dev/null 2>&1
	fi
	# to disable now instead of reboot:
	sudo sysctl -w net.ipv4.ip_forward=0  > /dev/null 2>&1
	## Prevent forwarding from LAN to internet
	if grep 'iptables --table nat -A POSTROUTING -o '$wan' -j MASQUERADE' /etc/init.d/ubuntu_ce_firewall> /dev/null 2>&1;
	then
	LINE_NO1=`grep -n 'iptables --table nat -A POSTROUTING -o '$wan' -j MASQUERADE' /etc/init.d/ubuntu_ce_firewall| cut -f1 -d:`
	sudo perl -ni -e 'print unless $. == '$LINE_NO1'' /etc/init.d/ubuntu_ce_firewall
	fi
	## Remove transparent proxy at boot on LAN in case of 2 or more network cards
	if grep 'iptables -A PREROUTING -t nat -i '$lan' -p tcp --dport 80 -j REDIRECT --to-ports 8080' /etc/init.d/ubuntu_ce_firewall> /dev/null 2>&1;
	then
	LINE_NO2=`grep -n 'iptables -A PREROUTING -t nat -i '$lan' -p tcp --dport 80 -j REDIRECT --to-ports 8080' /etc/init.d/ubuntu_ce_firewall| cut -f1 -d:`
	sudo perl -ni -e 'print unless $. == '$LINE_NO2'' /etc/init.d/ubuntu_ce_firewall
	fi
	if grep 'iptables -A INPUT -i '$lan' -p tcp --dport 8080 -j ACCEPT' /etc/init.d/ubuntu_ce_firewall> /dev/null 2>&1;
	then
	LINE_NO3=`grep -n 'iptables -A INPUT -i '$lan' -p tcp --dport 8080 -j ACCEPT' /etc/init.d/ubuntu_ce_firewall| cut -f1 -d:`
	sudo perl -ni -e 'print unless $. == '$LINE_NO3'' /etc/init.d/ubuntu_ce_firewall
	fi
	if grep 'iptables -A INPUT -i '$lan' -p tcp --dport 80 -j ACCEPT' /etc/init.d/ubuntu_ce_firewall> /dev/null 2>&1;
	then
	LINE_NO4=`grep -n 'iptables -A INPUT -i '$lan' -p tcp --dport 80 -j ACCEPT' /etc/init.d/ubuntu_ce_firewall| cut -f1 -d:`
	sudo perl -ni -e 'print unless $. == '$LINE_NO4'' /etc/init.d/ubuntu_ce_firewall
	fi
	## Close port 8080 in case of 1 network card only
	if grep 'iptables -A INPUT -p tcp -s '$lan_ip' --dport 8080 -j ACCEPT' /etc/init.d/ubuntu_ce_firewall> /dev/null 2>&1;
	then
	LINE_NO5=`grep -n 'iptables -A INPUT -p tcp -s '$lan_ip' --dport 8080 -j ACCEPT' /etc/init.d/ubuntu_ce_firewall| cut -f1 -d:`
	sudo perl -ni -e 'print unless $. == '$LINE_NO5'' /etc/init.d/ubuntu_ce_firewall
	fi
	sudo /etc/init.d/ubuntu_ce_firewall restart 2>&1 | zenity --width=500 --progress --pulsate --auto-close --title="Restarting firewall...."
	## Revert dhcp-server to original state
	if [ -f /etc/network/interfaces.original ]
		then
		sudo mv /etc/network/interfaces.original /etc/network/interfaces
		else
		echo > /dev/null 2>&1
	fi
	if [ -f /etc/dhcp3/dhcpd.conf.original ]
		then
		sudo mv /etc/dhcp3/dhcpd.conf.original /etc/dhcp3/dhcpd.conf
		else
		echo > /dev/null 2>&1
	fi
	if [ -f /etc/network/interfaces.original ]
		then
		sudo mv /etc/default/dhcp3-server.original /etc/default/dhcp3-server
		else
		echo > /dev/null 2>&1
	fi
	# If dhcp3 server never been setup before dansguardian gui installed (unconfigured), it will throw error but no harm.
	sudo /etc/init.d/dhcp3-server restart 2>&1 | zenity --width=500 --progress --pulsate --auto-close --title="Restarting dhcp server...."
	;;

        *)
	break
	;;
	esac
	done
	;;

        "View denied log" )
	'/usr/lib/cgi-bin/dansguardian_log.pl' 
	xdg-open '/tmp/denied_log.html' 
	;;

	"Advance Setting" )
	title_text="Advance setting"
	while true; do
	choice="$(zenity --width=300 --height=190 --list --column "" --title="$title_text" --text="Please select category"   \
        "Blacklists" \
        "Whitelists" \
        "Back")"
	case "${choice}" in

	"Blacklists" )
		while true; do
			choice="$(zenity --width=300 --height=280 --list --column "" --title="$title_text" --text="Please be carefull when editing below file"   \
        	"Banned IPs" \
        	"Banned Sites" \
        	"Banned URLs" \
        	"Banned Phrases" \
        	"Banned MIME Types" \
        	"Banned File Extensions" \
        	"Back")"
		case "${choice}" in
        	"Banned IPs" )
		gksudo gedit /etc/dansguardian/lists/bannediplist
		sudo /etc/init.d/dansguardian restart
		;;
        	"Banned Sites" )
		gksudo gedit /etc/dansguardian/lists/bannedsitelist
		sudo /etc/init.d/dansguardian restart
		;;
        	"Banned URLs" )
		gksudo gedit /etc/dansguardian/lists/bannedurllist
		sudo /etc/init.d/dansguardian restart
		;;
        	"Banned Phrases" )
		gksudo gedit /etc/dansguardian/lists/bannedphraselist
		sudo /etc/init.d/dansguardian restart
		;;
        	"Banned MIME Types" )
		gksudo gedit /etc/dansguardian/lists/bannedmimetypelist
		sudo /etc/init.d/dansguardian restart
		;;
        	"Banned File Extensions" )
		gksudo gedit /etc/dansguardian/lists/bannedextensionlist
		sudo /etc/init.d/dansguardian restart
		;;
        	*)
		break
		;;
		esac
		done
		;;
	"Whitelists" )
		while true; do
			choice="$(zenity --width=300 --height=280 --list --column "" --title="$title_text" --text="Please be carefull when editing below file"   \
        	"Allowed IPs" \
        	"Allowed Sites" \
        	"Allowed URLs" \
        	"Allowed Phrases" \
        	"Allowed MIME Types" \
        	"Allowed File Extensions" \
        	"Back")"
		case "${choice}" in
        	"Allowed IPs" )
		gksudo gedit /etc/dansguardian/lists/exceptioniplist
		sudo /etc/init.d/dansguardian restart
		;;
        	"Allowed Sites" )
		gksudo gedit /etc/dansguardian/lists/exceptionsitelist
		sudo /etc/init.d/dansguardian restart
		;;
        	"Allowed URLs" )
		gksudo gedit /etc/dansguardian/lists/exceptionurllist
		sudo /etc/init.d/dansguardian restart
		;;
        	"Allowed Phrases" )
		gksudo gedit /etc/dansguardian/lists/exceptionphraselist
		sudo /etc/init.d/dansguardian restart
		;;
        	"Allowed MIME Types" )
		gksudo gedit /etc/dansguardian/lists/exceptionmimetypelist
		sudo /etc/init.d/dansguardian restart
		;;
        	"Allowed File Extensions" )
		gksudo gedit /etc/dansguardian/lists/exceptionextensionlist
		sudo /etc/init.d/dansguardian restart
		;;
        	*)
		break
		;;
		esac
		done
	;;
	*)
      break    
	;;
	esac
	done

	;;
	*)

break
esac
done
rm -f '/tmp/denied_log.html'
