Squid konfigurálás PHPből (vagy valamiből)[GIFT]
Csökmei István Péter
csip at euro-oktaeder.hu
2010. Aug. 25., Sze, 21:42:30 CEST
Tisztelt Gazda társaim!
MiĂ©rt a squid-et csesztetjĂĽk, ĂşjraindĂtjuk, Ă©s mire restartol...
Amikor elég csak az INPUT-ban megadni egy iptables szabályt.
Én a következőt csináltam
Adott egy szkript (mellékletben).
Adott rá a jogosultság root.root 700
Sudo a gépen, az apache ezt a szkriptet sudoval futtathatja:
www-data ALL=NOPASSWD:/usr/local/sbin/squidset
Egy form-ról bekéred a termek állapotát (allow/deny):
Utána php-ben feldolgozod pl 2 sorban:
<?
$cmdstr="sudo squidset {$_POST["IF45"]} {$_POST["IF42"]} {$_POST["IF24"]}";
exec($cmdstr,$outstr);
?>
Ennyi.
Nem kell restart, semmi nyűg, kivárni mĂg a squid leáll-elindul.
CsIP
--------- következő rész ---------
#!/bin/bash
QUIETMODE=0
TEREMIPG3=192.168.2.160/27
TEREMIPG1=192.168.2.96/27
TEREMIPG2=192.168.2.128/27
STATE21=`iptables -L INPUT -n|grep -E "$TEREMIPG3.+dpt:3128" -c`
STATE23=`iptables -L INPUT -n|grep -E "$TEREMIPG1.+dpt:3128" -c`
STATE24=`iptables -L INPUT -n|grep -E "$TEREMIPG2.+dpt:3128" -c`
if [ "c$1c" = "cc" ] || [ "$1" = "state" ]
then
if [ $STATE23 == 0 ]
then
echo "G1 is allowed"
else
echo "G1 is denyed"
fi
if [ $STATE24 == 0 ]
then
echo "G2 is allowed"
else
echo "G2 is denyed"
fi
if [ $STATE21 == 0 ]
then
echo "G3 is allowed"
else
echo "G3 is denyed"
fi
else
while [ "$1" != "" ]
do
case "$1" in
-q)
QUIETMODE=1
;;
allow-G1)
if [ $STATE23 == 0 ] && [ $QUIETMODE == 0 ]
then
echo "G1 is allready allowed"
elif [ $STATE23 == 1 ]; then
STATE23=10
fi
;;
deny-G1)
if [ $STATE23 == 1 ] && [ $QUIETMODE == 0 ]
then
echo "G1 is allready denyed"
elif [ $STATE23 == 0 ]; then
STATE23=11
fi
;;
allow-G2)
if [ $STATE24 == 0 ] && [ $QUIETMODE == 0 ]
then
echo "G2 is allready allowed"
elif [ $STATE24 == 1 ]; then
STATE24=10
fi
;;
deny-G2)
if [ $STATE24 == 1 ] && [ $QUIETMODE == 0 ]
then
echo "G2 is allready denyed"
elif [ $STATE24 == 0 ]; then
STATE24=11
fi
;;
allow-G3)
if [ $STATE21 == 0 ] && [ $QUIETMODE == 0 ]
then
echo "G3 is allready allowed"
elif [ $STATE21 == 1 ]; then
STATE21=10
fi
;;
deny-G3)
if [ $STATE21 == 1 ] && [ $QUIETMODE == 0 ]
then
echo "G3 is allready denyed"
elif [ $STATE21 == 0 ]; then
STATE21=11
fi
;;
esac
shift
done
if [ $STATE21 == 10 ]
then
iptables -D INPUT -s $TEREMIPG3 -p tcp -m tcp --dport 3128 -j DROP
iptables -I FORWARD -s $TEREMIPG3 -j ACCEPT
fi
if [ $STATE21 == 11 ]
then
iptables -I INPUT -s $TEREMIPG3 -p tcp -m tcp --dport 3128 -j DROP
iptables -D FORWARD -s $TEREMIPG3 -j ACCEPT
fi
if [ $STATE23 == 10 ]
then
iptables -D INPUT -s $TEREMIPG1 -p tcp -m tcp --dport 3128 -j DROP
iptables -I FORWARD -s $TEREMIPG1 -j ACCEPT
fi
if [ $STATE23 == 11 ]
then
iptables -I INPUT -s $TEREMIPG1 -p tcp -m tcp --dport 3128 -j DROP
iptables -D FORWARD -s $TEREMIPG1 -j ACCEPT
fi
if [ $STATE24 == 10 ]
then
iptables -D INPUT -s $TEREMIPG2 -p tcp -m tcp --dport 3128 -j DROP
iptables -I FORWARD -s $TEREMIPG2 -j ACCEPT
fi
if [ $STATE24 == 11 ]
then
iptables -I INPUT -s $TEREMIPG2 -p tcp -m tcp --dport 3128 -j DROP
iptables -D FORWARD -s $TEREMIPG2 -j ACCEPT
fi
fi
További információk a(z) Techinfo levelezőlistáról