]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - src/initscripts/init.d/squid
75dbbfa6bb5c6e2ca69ff5b5a4403d60813d01cd
[people/pmueller/ipfire-2.x.git] / src / initscripts / init.d / squid
1 #!/bin/sh
2 # Begin $rc_base/init.d/squid
3
4 . /etc/sysconfig/rc
5 . $rc_functions
6
7 chown -R squid:squid /var/log/squid
8 chown -R squid:squid /var/log/squidGuard
9
10
11 transparent() {
12 DEVICE=$1
13
14 eval $(/usr/local/bin/readhash /var/ipfire/ethernet/settings)
15 eval $(/usr/local/bin/readhash /var/ipfire/proxy/settings)
16
17 # If the proxy port is not set we set the default to 800.
18 if [ -z $PROXY_PORT ]; then
19 PROXY_PORT=800
20 fi
21
22 LOCALIP=`cat /var/ipfire/red/local-ipaddress | tr -d \n`
23 if [ -z $LOCALIP ]; then
24 boot_mesg "Couldn't read local-ipaddress" ${FAILURE}
25 exit 1
26 fi
27
28 COUNT=1
29 FILE=/var/ipfire/vpn/config
30
31 while read LINE; do
32 let COUNT=$COUNT+1
33 CONN_TYPE=`echo "$LINE" | awk -F, '{ print $5 }'`
34 if [ "$CONN_TYPE" != "net" ]; then
35 continue
36 fi
37 iptables -t nat -A SQUID -i $1 -p tcp -d `echo "$LINE" | awk -F, '{ print $13 }'` --dport 80 -j RETURN
38 done < $FILE
39
40 if [ "$RED_TYPE" == "STATIC" ]; then
41 iptables -t nat -A SQUID -i $1 -p tcp -d $RED_NETADDRESS/$RED_NETMASK --dport 80 -j RETURN
42 fi
43
44 iptables -t nat -A SQUID -i $1 -p tcp -d $LOCALIP --dport 80 -j RETURN
45
46 iptables -t nat -A SQUID -i $1 -p tcp --dport 80 -j REDIRECT --to-port $PROXY_PORT
47 }
48
49 case "$1" in
50 start)
51 getpids "squid"
52
53 if [ -n "${pidlist}" ]; then
54 echo -e "Squid is already running with Process"\
55 "ID(s) ${pidlist}.${NORMAL}"
56 evaluate_retval
57 exit
58 fi
59
60
61 eval $(/usr/local/bin/readhash /var/ipfire/proxy/advanced/settings)
62 eval $(/usr/local/bin/readhash /var/ipfire/ethernet/settings)
63
64 if [ -e /var/ipfire/proxy/enable -o -e /var/ipfire/proxy/enable_blue ]; then
65
66 # Add Address to errorpage stylesheet
67 sed "s|XXXhostXXX|$GREEN_ADDRESS|g" /var/ipfire/proxy/errorpage-$ERR_DESIGN.css > \
68 /etc/squid/errorpage.css
69
70 boot_mesg "Starting Squid Proxy Server..."
71 loadproc /usr/sbin/squid -z >/dev/null 2>&1
72 loadproc /usr/sbin/squid
73 fi
74
75 if [ -e /var/ipfire/proxy/transparent ]; then
76 transparent $GREEN_DEV
77 fi
78 if [ -e /var/ipfire/proxy/transparent_blue ]; then
79 transparent $BLUE_DEV
80 fi
81 ;;
82
83 stop)
84 iptables -t nat -F SQUID
85 if [ -e /var/run/squid.pid ]; then
86 boot_mesg "Stopping Squid Proxy Server..."
87 squid -k shutdown >/dev/null 2>&1
88 evaluate_retval
89 killproc /usr/bin/squidGuard >/dev/null
90 killproc /usr/sbin/updxlrator >/dev/null
91 killproc /usr/sbin/squid >/dev/null
92 rm -rf /var/run/squid.pid
93 fi
94 ;;
95
96 restart)
97 $0 stop
98 sleep 5
99 $0 start
100 ;;
101
102 reconfigure)
103 /usr/sbin/squid -k reconfigure
104 ;;
105
106 status)
107 statusproc /usr/sbin/squid
108 statusproc /usr/lib/squid/unlinkd
109 ;;
110
111 flush)
112 $0 stop
113 echo > /var/log/cache/swap.state
114 chown squid.squid /var/log/cache/swap.state
115 sleep 1
116 $0 start
117 ;;
118 setperms)
119 chown -R nobody.squid /var/updatecache/
120 ;;
121
122 *)
123 echo "Usage: $0 {start|stop|restart|status|flush}"
124 exit 1
125 ;;
126 esac
127
128 # End $rc_base/init.d/squid