Netzwerkscripts erweitert.
[ipfire-2.x.git] / src / initscripts / init.d / net / red / update
CommitLineData
bf7c473f
MT
1#!/bin/sh
2########################################################################
3# Begin $network_devices/red/update
4#
5# Description : Update red interface
6#
7# Authors : Michael Tremer - mitch@ipfire.org
8#
9# Version : 01.00
10#
11# Notes : update the settings if red goes up or down
12#
13########################################################################
14
15eval $(/usr/local/bin/readhash /var/ipfire/vpn/settings)
16eval $(/usr/local/bin/readhash /var/ipfire/dhcp/settings)
17eval $(/usr/local/bin/readhash /var/ipfire/ethernet/settings)
18eval $(/usr/local/bin/readhash /var/ipfire/ppp/settings)
19
20if [ ! -e /var/lock/red.lock ]; then
21 touch /var/lock/red.lock
22 logger -p local0.info -t red[$$] "$0 locking for $$"
23else
24 count=0
25 while [ ! $count = 5 ]; do
26 sleep 3
27 if [ ! -e /var/lock/red.lock ]; then
28 break
29 else
30 /usr/bin/logger -p local0.info -t red[$$] "$0 $$ waiting unlock"
31 fi
32 ((++count))
33 done
34fi
35
36IFACE=`cat /var/ipfire/red/iface 2>/dev/null | tr -d '\012'`
37REMOTE=`cat /var/ipfire/red/remote-ipaddress 2>/dev/null | tr -d '\012'`
38
39### DNS Settings
40DNS1=`cat /var/ipfire/red/dns1 2>/dev/null | tr -d '\012'`
41DNS2=`cat /var/ipfire/red/dns2 2>/dev/null | tr -d '\012'`
42echo > /var/ipfire/red/resolv.conf #clear it
43[ "$DNS1" != "" ] && echo "nameserver $DNS1" > /var/ipfire/red/resolv.conf
44[ "$DNS2" != "" ] && echo "nameserver $DNS2" >> /var/ipfire/red/resolv.conf
45
46### Restart DNSMASQ
47killall -KILL dnsmasq 2> /dev/null
48sleep 1
49ARGS=""
50[ "$DOMAIN_NAME_GREEN" ] && ARGS="-s $DOMAIN_NAME_GREEN"
51if [ -e "/var/ipfire/red/dial-on-demand" -a "$DIALONDEMANDDNS" == "on" -a ! -e "/var/ipfire/red/active" ]; then
52 /usr/sbin/dnsmasq -l /var/state/dhcp/dhcpd.leases $ARGS -r /var/ipfire/ppp/fake-resolv.conf
53else
54 /usr/sbin/dnsmasq -l /var/state/dhcp/dhcpd.leases $ARGS -r /var/ipfire/red/resolv.conf
55fi
56unset ARGS
57
58### Reset default route to ippp0 for dial on demand
59if [ -e "/var/ipfire/red/dial-on-demand" -a "$TYPE" == "isdn" -a ! -e "/var/ipfire/red/active" ]; then
60 ip route del default 2> /dev/null
61 if [ ! -z "$REMOTE" ]; then
62 ip route add default gw $REMOTE 2> /dev/null
63 else
64 ip route add default dev ippp0 2> /dev/null
65 fi
66fi
67
68if ( echo $0 | /bin/grep -q 'dhcpcd.exe' ); then
69 eval $(/usr/local/bin/readhash "$1")
70 case "$2" in
71 up)
72 logger -p local0.info -t dhcpcd.exe[$$] "${INTERFACE} has been configured with old IP=${IPADDR}"
73 if [ "$RED_TYPE" != 'PPTP' ]; then
74 touch /var/ipfire/red/active
75 fi
76 ;;
77 new)
78 logger -p local0.info -t dhcpcd.exe[$$] "${INTERFACE} has been configured with new IP=${IPADDR}"
79 if [ -e "/var/ipfire/red/active" ]; then
80 /usr/local/bin/setfilters
81 /usr/local/bin/setportfw
82 /usr/local/bin/setxtaccess
83 /usr/local/bin/setddns.pl -f
84 /usr/local/bin/restartsnort red
85 sleep $VPN_DELAYED_START && /usr/local/bin/ipsecctrl S &
86 /bin/rm -f /var/lock/red.lock
87 logger -p local0.info -t red[$$] "unlocking from $$"
88 exit 0
89 else
90 if [ "$RED_TYPE" != 'PPTP' ]; then
91 touch /var/ipfire/red/active
92 fi
93 fi
94 ;;
95 down)
96 logger -p local0.info -t dhcpcd.exe[$$] "${INTERFACE} has been brought down"
97 rm -f /var/ipfire/red/active
98 ;;
99 esac
100fi
101
102if [ -e "/var/ipfire/red/active" ]; then
103 [ "$IFACE" != "" ] && ifconfig $IFACE -multicast
104 /etc/rc.d/init.d/firewall reload
105 /usr/local/bin/setfilters
106 /usr/local/bin/restartsnort red
107 /usr/local/bin/qosctrl start
108 /usr/local/bin/setportfw
109 /usr/local/bin/setxtaccess
110 /usr/local/bin/setddns.pl -f
111 /etc/rc.d/helper/writeipac.pl
112 /usr/sbin/fetchipac -S
113 sleep $VPN_DELAYED_START && /usr/local/bin/ipsecctrl S &
114else
115 /usr/local/bin/ipsecctrl D
116 /etc/rc.d/init.d/firewall reload
117fi
118/bin/rm -f /var/lock/red.lock
119/usr/bin/logger -p local0.info -t red[$$] "unlocking from $$"
120
121# End $network_devices/red/update