]>
Commit | Line | Data |
---|---|---|
d56fc335 MT |
1 | #!/bin/sh |
2 | # Begin $rc_base/init.d/squid | |
3 | ||
4 | . /etc/sysconfig/rc | |
5 | . $rc_functions | |
6 | ||
18322edf CS |
7 | chown -R squid:squid /var/log/squid |
8 | chown -R squid:squid /var/log/squidGuard | |
9 | ||
ab4a5a35 | 10 | |
d56fc335 MT |
11 | transparent() { |
12 | DEVICE=$1 | |
ab4a5a35 | 13 | |
d56fc335 MT |
14 | eval $(/usr/local/bin/readhash /var/ipfire/ethernet/settings) |
15 | eval $(/usr/local/bin/readhash /var/ipfire/proxy/settings) | |
ab4a5a35 | 16 | |
d56fc335 MT |
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) | |
8b202790 CS |
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 | |
ab4a5a35 AF |
59 | |
60 | ||
61 | eval $(/usr/local/bin/readhash /var/ipfire/proxy/advanced/settings) | |
62 | eval $(/usr/local/bin/readhash /var/ipfire/ethernet/settings) | |
63 | ||
d56fc335 | 64 | if [ -e /var/ipfire/proxy/enable -o -e /var/ipfire/proxy/enable_blue ]; then |
ab4a5a35 AF |
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 | ||
203c2787 | 70 | boot_mesg "Starting Squid Proxy Server..." |
d4c6ba21 AF |
71 | loadproc /usr/sbin/squid -z >/dev/null 2>&1 |
72 | loadproc /usr/sbin/squid | |
d56fc335 MT |
73 | fi |
74 | ||
d56fc335 MT |
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) | |
a332b303 | 84 | iptables -t nat -F SQUID |
af95dec5 | 85 | if [ -e /var/run/squid.pid ]; then |
09b58b25 | 86 | boot_mesg "Stopping Squid Proxy Server..." |
09b58b25 CS |
87 | squid -k shutdown >/dev/null 2>&1 |
88 | evaluate_retval | |
517d02ab SS |
89 | |
90 | # Stop squidGuard, updxlrator, squidclamav | |
91 | # and redirect_wrappers. | |
92 | killproc /usr/bin/squidGuard >/dev/null & | |
93 | killproc /usr/sbin/updxlrator >/dev/null & | |
94 | killproc /usr/bin/squidclamav >/dev/null & | |
95 | killproc /usr/sbin/redirect_wrapper >/dev/null & | |
96 | ||
97 | # Wait until all redirectors have been stopped. | |
98 | wait | |
99 | ||
100 | # If squid is still running, wait up to 30 seconds | |
101 | # before we go on to kill it. | |
102 | counter=30 | |
103 | ||
104 | while [ ${counter} -gt 0 ]; do | |
105 | statusproc /usr/sbin/squid >/dev/null && break; | |
106 | sleep 1 | |
107 | counter=$(( ${counter} - 1)) | |
108 | done | |
109 | ||
110 | # Kill squid service, if still running. | |
09b58b25 | 111 | killproc /usr/sbin/squid >/dev/null |
517d02ab SS |
112 | |
113 | # Trash remain pid file from squid. | |
a332b303 | 114 | rm -rf /var/run/squid.pid |
09b58b25 | 115 | fi |
d56fc335 MT |
116 | ;; |
117 | ||
118 | restart) | |
119 | $0 stop | |
186e3d2c | 120 | sleep 5 |
d56fc335 MT |
121 | $0 start |
122 | ;; | |
123 | ||
fe1656d2 CS |
124 | reconfigure) |
125 | /usr/sbin/squid -k reconfigure | |
126 | ;; | |
127 | ||
d56fc335 MT |
128 | status) |
129 | statusproc /usr/sbin/squid | |
130 | statusproc /usr/lib/squid/unlinkd | |
131 | ;; | |
132 | ||
133 | flush) | |
134 | $0 stop | |
135 | echo > /var/log/cache/swap.state | |
136 | chown squid.squid /var/log/cache/swap.state | |
137 | sleep 1 | |
138 | $0 start | |
139 | ;; | |
2b5b6b9e CS |
140 | setperms) |
141 | chown -R nobody.squid /var/updatecache/ | |
142 | ;; | |
d56fc335 MT |
143 | |
144 | *) | |
145 | echo "Usage: $0 {start|stop|restart|status|flush}" | |
146 | exit 1 | |
147 | ;; | |
148 | esac | |
149 | ||
150 | # End $rc_base/init.d/squid |