root/limitar-https/trunk/deny_https @ 75
6 | antoniojas | #! /bin/sh
|
|
#----------------------------------------------------------------------------------------
|
|||
# Antonio J. Abasolo Sierra (Mayo-2010)
|
|||
#----------------------------------------------------------------------------------------
|
|||
# Controla la activación/desactivación de reglas iptables
|
|||
# que cortan el tráfico https para todas las webs externas, e ips del centro
|
|||
# que indiquemos en su fichero de configuración.
|
|||
#
|
|||
# Depende del fichero de configuración "/etc/network/deny_https.conf",
|
|||
# el cual se genera a partir del fichero "/etc/network/deny_https.all"
|
|||
12 | antoniojas | # obtenido del repositorio general, mas el fichero "/etc/network/deny_https.ies",
|
|
6 | antoniojas | # el cual será modificado por cada IES según sus necesidades.
|
|
# Dichos ficheros podrán tener dos tipos de líneas (no importa el orden):
|
|||
# - web's de destino que queremos bloquear vía https
|
|||
# iptables -A FORWARD -p tcp --dport 443 -d WEB -j REJECT
|
|||
# - ip's de equipos locales del IES a los que queremos restringir el tráfico https
|
|||
# iptables -A FORWARD -p tcp --dport 443 -s IP -j REJECT
|
|||
#
|
|||
# La regla "iptables-restore < /etc/network/iptables" se pone por seguridad:
|
|||
# ya que se ejecuta tras eliminar las reglas, en cuyo momento la situación
|
|||
# ya debería ser la misma que plantea esta línea; y justo antes de añadir las reglas,
|
|||
# para garantizar que partimos del estado inicial.
|
|||
# Dicho fichero, a partir de ahora, se gestionará vía puppet para garantizar el mismo
|
|||
# contenido en todos los IES.
|
|||
#----------------------------------------------------------------------------------------
|
|||
# Variables
|
|||
IPTABLES=/sbin/iptables
|
|||
14 | antoniojas | FICHERO=deny_https.all
|
|
6 | antoniojas | DENY_HTTPS=/etc/network/deny_https.conf
|
|
14 | antoniojas | DENY_HTTPS_ALL=/etc/network/$FICHERO
|
|
12 | antoniojas | DENY_HTTPS_IES=/etc/network/deny_https.ies
|
|
27 | antoniojas | RUTA=http://desarrollo.educarex.es/linex/projects/servidoressecundaria/repository/entry/limitar-https/trunk
|
|
#RUTA=http://172.16.16.254/linex/projects/servidoressecundaria/repository/entry/limitar-https/trunk
|
|||
6 | antoniojas | RED=`ifconfig | grep Bcast | cut -f2 -d: | awk '{print }' | cut -f1 -d.`
|
|
#----------------------------------------------------------------------------------------
|
|||
12 | antoniojas | # Descarga el fichero general de https a denegar por todos los IES
|
|
27 | antoniojas | #if [ -s $DENY_HTTPS_ALL ]; then mv $DENY_HTTPS_ALL $DENY_HTTPS_ALL.old; fi
|
|
#wget -T 10 -q -O $DENY_HTTPS_ALL $RUTA/$FICHERO?format=raw
|
|||
#if [ ! -s $DENY_HTTPS_ALL ]; then
|
|||
# if [ -s $DENY_HTTPS_ALL.old ]; then
|
|||
# cat $DENY_HTTPS_ALL.old >> $DENY_HTTPS_ALL
|
|||
# fi
|
|||
#fi
|
|||
12 | antoniojas | ||
27 | antoniojas | if [ ! -f $DENY_HTTPS_ALL ]; then touch $DENY_HTTPS_ALL; fi
|
|
20 | antoniojas | ||
6 | antoniojas | # Unimos y filtramos los ficheros de configuración
|
|
12 | antoniojas | cat $DENY_HTTPS_ALL $DENY_HTTPS_IES | egrep -v '#|^$' | awk '{print $1}' | sort | uniq > $DENY_HTTPS
|
|
6 | antoniojas | ||
# Bail out if no iptables binary or no configuration
|
|||
[ -x ${IPTABLES} -a "$DENY_HTTPS" ] || exit 0
|
|||
#----------------------------------------------------------------------------------------
|
|||
#----------------------------------------------------------------------------------------
|
|||
do_status() {
|
|||
echo ""
|
|||
echo "ESTADO ACTUAL DE LAS REGLAS ..."
|
|||
echo "----------------------------------------------------"
|
|||
$IPTABLES -L
|
|||
echo "----------------------------------------------------"
|
|||
}
|
|||
#----------------------------------------------------------------------------------------
|
|||
do_start() {
|
|||
echo "ACTIVANDO reglas para controlar el tráfico https:"
|
|||
echo "-------------------------------------------------"
|
|||
iptables-restore < /etc/network/iptables
|
|||
cat $DENY_HTTPS | while read LINEA; do
|
|||
if [ `echo $LINEA | grep $RED` ]; then OPCION="-s"; else OPCION="-d"; fi
|
|||
echo " * Denegando https a $LINEA ..."
|
|||
$IPTABLES -A FORWARD -p tcp --dport 443 $OPCION $LINEA -j REJECT 2> /dev/null
|
|||
done
|
|||
echo " ----------------------------------------------"
|
|||
echo " * EL TRAFICO HTTPS ESTA RESTRINGIDO."
|
|||
27 | antoniojas | echo ""
|
|
6 | antoniojas | }
|
|
do_stop() {
|
|||
echo "DESACTIVANDO reglas para controlar el tráfico https:"
|
|||
echo "-------------------------------------------------"
|
|||
cat $DENY_HTTPS | while read LINEA; do
|
|||
if [ `echo $LINEA | grep $RED` ]; then OPCION="-s"; else OPCION="-d"; fi
|
|||
echo " * Eliminando regla https para $LINEA ..."
|
|||
$IPTABLES -D FORWARD -p tcp --dport 443 $OPCION $LINEA -j REJECT 2> /dev/null
|
|||
done
|
|||
iptables-restore < /etc/network/iptables
|
|||
echo " -----------------------------------------------"
|
|||
echo " * EL TRAFICO HTTPS ESTA LIBERADO."
|
|||
27 | antoniojas | echo ""
|
|
6 | antoniojas | }
|
|
do_restart() {
|
|||
do_stop
|
|||
do_start
|
|||
}
|
|||
# INICIO --------------------------------------------------------------------------------
|
|||
clear
|
|||
case "$1" in
|
|||
start)
|
|||
do_start
|
|||
27 | antoniojas | # do_status
|
|
6 | antoniojas | ;;
|
|
stop)
|
|||
do_stop
|
|||
27 | antoniojas | # do_status
|
|
6 | antoniojas | ;;
|
|
restart|force-reload)
|
|||
do_restart
|
|||
27 | antoniojas | # do_status
|
|
6 | antoniojas | ;;
|
|
status)
|
|||
do_status
|
|||
;;
|
|||
*)
|
|||
echo "Usage: $0 {start|stop|restart|force-reload|status}"
|
|||
exit 2
|
|||
;;
|
|||
esac
|
|||
exit 0
|
|||
# FIN -----------------------------------------------------------------------------------
|