]> git.ipfire.org Git - ipfire-2.x.git/blob - src/initscripts/init.d/squid
abed90aef653569737edf06ca1ee3786e0a68307
[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 "${TRANSPARENT_PORT}" ]; then
19 TRANSPARENT_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 "${TRANSPARENT_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 eval $(/usr/local/bin/readhash /var/ipfire/proxy/advanced/settings)
61 eval $(/usr/local/bin/readhash /var/ipfire/ethernet/settings)
62
63 if [ -e /var/ipfire/proxy/enable -o -e /var/ipfire/proxy/enable_blue ]; then
64 # Add Address to errorpage stylesheet
65 sed "s|XXXhostXXX|$GREEN_ADDRESS|g" /var/ipfire/proxy/errorpage-$ERR_DESIGN.css > \
66 /etc/squid/errorpage.css
67
68 boot_mesg "Creating Squid swap directories..."
69 /usr/sbin/squid -z >/dev/null 2>&1
70 evaluate_retval
71
72 # Make sure, that the process above has finished.
73 counter=5
74 while [ ${counter} -gt 0 ]; do
75 if pidofproc -s /usr/sbin/squid; then
76 sleep 1
77 else
78 break
79 fi
80 done
81
82 boot_mesg "Starting Squid Proxy Server..."
83 loadproc /usr/sbin/squid
84 fi
85
86 if [ -e /var/ipfire/proxy/transparent ]; then
87 transparent $GREEN_DEV
88 fi
89 if [ -e /var/ipfire/proxy/transparent_blue ]; then
90 transparent $BLUE_DEV
91 fi
92 ;;
93
94 stop)
95 iptables -t nat -F SQUID
96 if [ -e /var/run/squid.pid ]; then
97 boot_mesg "Stopping Squid Proxy Server..."
98 squid -k shutdown >/dev/null 2>&1
99 evaluate_retval
100
101 # Stop squidGuard, updxlrator, squidclamav
102 # and redirect_wrappers.
103 killproc /usr/bin/squidGuard >/dev/null &
104 killproc /usr/sbin/updxlrator >/dev/null &
105 killproc /usr/bin/squidclamav >/dev/null &
106 killproc /usr/sbin/redirect_wrapper >/dev/null &
107
108 # Wait until all redirectors have been stopped.
109 wait
110
111 # If squid is still running, wait up to 30 seconds
112 # before we go on to kill it.
113 counter=30
114
115 while [ ${counter} -gt 0 ]; do
116 statusproc /usr/sbin/squid >/dev/null && break;
117 sleep 1
118 counter=$(( ${counter} - 1))
119 done
120
121 # Kill squid service, if still running.
122 killproc /usr/sbin/squid >/dev/null
123
124 # Trash remain pid file from squid.
125 rm -rf /var/run/squid.pid
126 fi
127 ;;
128
129 restart)
130 $0 stop
131 sleep 5
132 $0 start
133 ;;
134
135 reconfigure)
136 /usr/sbin/squid -k reconfigure
137 ;;
138
139 status)
140 statusproc /usr/sbin/squid
141 statusproc /usr/lib/squid/unlinkd
142 ;;
143
144 flush)
145 $0 stop
146 echo > /var/log/cache/swap.state
147 chown squid.squid /var/log/cache/swap.state
148 sleep 1
149 $0 start
150 ;;
151
152 setperms)
153 chown -R nobody.squid /var/updatecache/
154 ;;
155
156 *)
157 echo "Usage: $0 {start|stop|restart|status|flush}"
158 exit 1
159 ;;
160 esac
161
162 # End $rc_base/init.d/squid