]> git.ipfire.org Git - people/mfischer/ipfire-2.x.git/blob - src/initscripts/system/squid
core164: exclude boot/uEnv.txt
[people/mfischer/ipfire-2.x.git] / src / initscripts / system / 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 ulimit -n 32768
52 getpids "squid"
53
54 if [ -n "${pidlist}" ]; then
55 echo -e "Squid is already running with Process"\
56 "ID(s) ${pidlist}.${NORMAL}"
57 evaluate_retval
58 exit
59 fi
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 # Add Address to errorpage stylesheet
66 sed "s|XXXhostXXX|$GREEN_ADDRESS|g" /var/ipfire/proxy/errorpage-$ERR_DESIGN.css > \
67 /etc/squid/errorpage.css
68
69 boot_mesg "Creating Squid swap directories..."
70 /usr/sbin/squid -z >/dev/null 2>&1
71 evaluate_retval
72
73 # Make sure, that the process above has finished.
74 counter=5
75 while [ ${counter} -gt 0 ]; do
76 if pidofproc -s /usr/sbin/squid; then
77 sleep 1
78 else
79 break
80 fi
81 done
82
83 boot_mesg "Starting Squid Proxy Server..."
84 loadproc /usr/sbin/squid
85 fi
86
87 if [ -e /var/ipfire/proxy/transparent ]; then
88 transparent $GREEN_DEV
89 fi
90 if [ -e /var/ipfire/proxy/transparent_blue ]; then
91 transparent $BLUE_DEV
92 fi
93 ;;
94
95 stop)
96 iptables -t nat -F SQUID
97
98 if [ -e /var/run/squid.pid ]; then
99 boot_mesg -n "Stopping Squid Proxy Server (this may take up to a few minutes)..."
100 squid -k shutdown >/dev/null 2>&1
101
102 # If some squid processes are still running, wait up to 360 seconds
103 # before we go on to kill the remaining process(es) and delete damaged
104 # '/var/log/cache/swap.state'.
105 n=0
106 while squid -k check &>/dev/null && [ $n -lt 360 ]; do
107 # Print a dot every 6 seconds
108 [ $(( ${n} % 6 )) -eq 0 ] && boot_mesg -n .
109
110 n=$(( ${n} + 1 ))
111 sleep 1
112 done
113 boot_mesg "" # end line
114
115 # If (squid-1) is still running, kill all squid processes
116 if squid -k check &>/dev/null || pgrep -fl "(squid-1)" >/dev/null 2>&1; then
117 killproc /usr/sbin/squid >/dev/null
118 echo_failure
119
120 # Remove damaged journal of cache index
121 rm -f /var/log/cache/swap.state
122
123 boot_mesg -n "WARNING: squid could not be gracefully shut down." ${WARNING}
124 boot_mesg -n " The cache index was damaged and has been removed."
125 boot_mesg -n " The cache data has not been lost and the index will be"
126 boot_mesg -n " recreated at the next start."
127 boot_mesg "" ${NORMAL}
128 echo_warning
129 else
130 logger -t squid "squid shutdown time: ${n} seconds"
131
132 echo_ok
133 fi
134
135 # Kill any redirector processes that might have been left running
136 killproc /usr/bin/squidGuard >/dev/null &
137 killproc /usr/sbin/updxlrator >/dev/null &
138 killproc /usr/bin/squidclamav >/dev/null &
139 killproc /usr/sbin/redirect_wrapper >/dev/null &
140 wait
141 fi
142
143 # Trash remain pid file from squid.
144 rm -f /var/run/squid.pid
145 ;;
146
147 restart)
148 $0 stop
149 sleep 5
150 $0 start
151 ;;
152
153 reconfigure)
154 /usr/sbin/squid -k reconfigure
155 ;;
156
157 status)
158 statusproc /usr/sbin/squid
159 statusproc /usr/lib/squid/unlinkd
160 ;;
161
162 flush)
163 $0 stop
164 rm -rf /var/log/cache/*
165 sleep 1
166 $0 start
167 ;;
168
169 setperms)
170 chown -R nobody.squid /var/updatecache/
171 ;;
172
173 *)
174 echo "Usage: $0 {start|stop|restart|status|flush}"
175 exit 1
176 ;;
177 esac
178
179 # End $rc_base/init.d/squid