]>
Commit | Line | Data |
---|---|---|
d56fc335 MT |
1 | #!/bin/sh |
2 | # Begin $rc_base/init.d/squid | |
3 | ||
4 | . /etc/sysconfig/rc | |
5 | . $rc_functions | |
6 | ||
7 | transparent() { | |
8 | DEVICE=$1 | |
9 | ||
10 | eval $(/usr/local/bin/readhash /var/ipfire/ethernet/settings) | |
11 | eval $(/usr/local/bin/readhash /var/ipfire/proxy/settings) | |
12 | ||
13 | # If the proxy port is not set we set the default to 800. | |
14 | if [ -z $PROXY_PORT ]; then | |
15 | PROXY_PORT=800 | |
16 | fi | |
17 | ||
18 | LOCALIP=`cat /var/ipfire/red/local-ipaddress | tr -d \n` | |
19 | if [ -z $LOCALIP ]; then | |
20 | boot_mesg "Couldn't read local-ipaddress" ${FAILURE} | |
21 | exit 1 | |
22 | fi | |
23 | ||
24 | COUNT=1 | |
25 | FILE=/var/ipfire/vpn/config | |
26 | ||
27 | while read LINE; do | |
28 | let COUNT=$COUNT+1 | |
29 | CONN_TYPE=`echo "$LINE" | awk -F, '{ print $5 }'` | |
30 | if [ "$CONN_TYPE" != "net" ]; then | |
31 | continue | |
32 | fi | |
33 | iptables -t nat -A SQUID -i $1 -p tcp -d `echo "$LINE" | awk -F, '{ print $13 }'` --dport 80 -j RETURN | |
34 | done < $FILE | |
35 | ||
36 | if [ "$RED_TYPE" == "STATIC" ]; then | |
37 | iptables -t nat -A SQUID -i $1 -p tcp -d $RED_NETADDRESS/$RED_NETMASK --dport 80 -j RETURN | |
38 | fi | |
39 | ||
40 | iptables -t nat -A SQUID -i $1 -p tcp -d $LOCALIP --dport 80 -j RETURN | |
41 | ||
42 | iptables -t nat -A SQUID -i $1 -p tcp --dport 80 -j REDIRECT --to-port $PROXY_PORT | |
43 | } | |
44 | ||
45 | case "$1" in | |
46 | start) | |
47 | boot_mesg "Starting Squid Proxy Server..." | |
48 | ||
49 | if [ -e /var/ipfire/proxy/enable -o -e /var/ipfire/proxy/enable_blue ]; then | |
50 | loadproc /usr/sbin/squid -D -z >/dev/null 2>&1 | |
51 | loadproc /usr/sbin/squid -D | |
52 | fi | |
53 | ||
54 | eval $(/usr/local/bin/readhash /var/ipfire/ethernet/settings) | |
55 | ||
56 | if [ -e /var/ipfire/proxy/transparent ]; then | |
57 | transparent $GREEN_DEV | |
58 | fi | |
59 | if [ -e /var/ipfire/proxy/transparent_blue ]; then | |
60 | transparent $BLUE_DEV | |
61 | fi | |
62 | ;; | |
63 | ||
64 | stop) | |
65 | boot_mesg "Stopping Squid Proxy Server..." | |
66 | iptables -t nat -F SQUID | |
67 | squid -k shutdown >/dev/null 2>&1 | |
68 | evaluate_retval | |
69 | killproc /usr/sbin/squid >/dev/null | |
70 | killproc /usr/bin/squidGuard >/dev/null | |
71 | ;; | |
72 | ||
73 | restart) | |
74 | $0 stop | |
75 | sleep 1 | |
76 | $0 start | |
77 | ;; | |
78 | ||
79 | status) | |
80 | statusproc /usr/sbin/squid | |
81 | statusproc /usr/lib/squid/unlinkd | |
82 | ;; | |
83 | ||
84 | flush) | |
85 | $0 stop | |
86 | echo > /var/log/cache/swap.state | |
87 | chown squid.squid /var/log/cache/swap.state | |
88 | sleep 1 | |
89 | $0 start | |
90 | ;; | |
91 | ||
92 | *) | |
93 | echo "Usage: $0 {start|stop|restart|status|flush}" | |
94 | exit 1 | |
95 | ;; | |
96 | esac | |
97 | ||
98 | # End $rc_base/init.d/squid |