Hinzugefuegt:
[people/pmueller/ipfire-2.x.git] / src / rc.d / rc.updatered
1 #!/bin/sh
2 #
3 # $Id: rc.updatered,v 1.11.2.15 2005/12/01 16:20:37 franck78 Exp $
4 #
5
6 if [ ! -e /var/lock/rc.updatered.lock ]; then
7         /bin/touch /var/lock/rc.updatered.lock
8         /usr/bin/logger -s -p local0.info -t rc.updatered "$0 locking for $$"
9 else
10         count=0
11         while [ ! $count = 5 ]; do
12                 sleep 3
13                 if [ ! -e /var/lock/rc.updatered.lock ]; then
14                         break
15                 else
16                         /usr/bin/logger -s -p local0.info -t rc.updatered "$0 $$ waiting unlock"
17                 fi
18                 ((++count))
19         done
20 fi
21
22 eval $(/usr/local/bin/readhash CONFIG_ROOT/vpn/settings)
23 eval $(/usr/local/bin/readhash CONFIG_ROOT/dhcp/settings)
24 eval $(/usr/local/bin/readhash CONFIG_ROOT/ethernet/settings)
25 eval $(/usr/local/bin/readhash CONFIG_ROOT/ppp/settings)
26
27 IFACE=`/bin/cat CONFIG_ROOT/red/iface 2>/dev/null | /usr/bin/tr -d '\012'`
28 REMOTE=`/bin/cat CONFIG_ROOT/red/remote-ipaddress 2>/dev/null | /usr/bin/tr -d '\012'`
29
30 ###
31 ### Retrieve DHCP Settings
32 ###
33 if [ "$CONFIG_TYPE" = "2" -o "$CONFIG_TYPE" = "3"  -o "$CONFIG_TYPE" = "6" -o "$CONFIG_TYPE" = "7" ]; then
34         if [ "$RED_TYPE" = "DHCP" ]; then
35                 unset DNS1 DNS2
36                 eval $(/usr/local/bin/readhash CONFIG_ROOT/ethernet/settings)
37                 if [ "$DNS1" = "" ]; then
38                         echo -n `/etc/rc.d/helper/getdnsfromdhcpc.pl 1` > CONFIG_ROOT/red/dns1
39                         echo -n `/etc/rc.d/helper/getdnsfromdhcpc.pl 2` > CONFIG_ROOT/red/dns2
40                 else 
41                         echo "$DNS1" > CONFIG_ROOT/red/dns1
42                         echo "$DNS2" > CONFIG_ROOT/red/dns2
43                 fi
44                 . CONFIG_ROOT/dhcpc/dhcpcd-${RED_DEV}.info
45                 echo "$IPADDR"  > CONFIG_ROOT/red/local-ipaddress
46                 echo "$GATEWAY" > CONFIG_ROOT/red/remote-ipaddress
47         fi
48 else
49         if [ "$PROTOCOL" = "RFC1483" -a "$METHOD" = "DHCP" ]; then
50                 unset DNS1 DNS2
51                 eval $(/usr/local/bin/readhash CONFIG_ROOT/ppp/settings)
52                 if [ "$DNS" = "Automatic" ]; then
53                         echo -n `/etc/rc.d/helper/getdnsfromdhcpc.pl 1` > CONFIG_ROOT/red/dns1
54                         echo -n `/etc/rc.d/helper/getdnsfromdhcpc.pl 2` > CONFIG_ROOT/red/dns2
55                 else 
56                         echo "$DNS1" > CONFIG_ROOT/red/dns1
57                         echo "$DNS2" > CONFIG_ROOT/red/dns2
58                 fi
59                 . CONFIG_ROOT/dhcpc/dhcpcd-${IFACE}.info
60                 echo $IPADDR  > CONFIG_ROOT/red/local-ipaddress
61                 echo $GATEWAY > CONFIG_ROOT/red/remote-ipaddress
62         fi
63 fi
64
65 ###
66 ### Retrieve DNS settings
67 ###
68 DNS1=`/bin/cat CONFIG_ROOT/red/dns1 2>/dev/null | /usr/bin/tr -d '\012'`
69 DNS2=`/bin/cat CONFIG_ROOT/red/dns2 2>/dev/null | /usr/bin/tr -d '\012'`
70 echo > CONFIG_ROOT/red/resolv.conf    #clear it
71 [ "$DNS1" != "" ] && echo "nameserver $DNS1" >  CONFIG_ROOT/red/resolv.conf
72 [ "$DNS2" != "" ] && echo "nameserver $DNS2" >> CONFIG_ROOT/red/resolv.conf
73
74
75 ###
76 ### Restart DNSMASQ
77 ###
78 /bin/killall -KILL dnsmasq 2> /dev/null
79 sleep 1
80
81 DOMopt=""
82 [ "$DOMAIN_NAME_GREEN" ] && DOMopt="-s $DOMAIN_NAME_GREEN"
83 if [ -e "CONFIG_ROOT/red/dial-on-demand" -a "$DIALONDEMANDDNS" == "on" -a ! -e "CONFIG_ROOT/red/active" ]; then
84     /usr/sbin/dnsmasq -l /var/state/dhcp/dhcpd.leases $DOMopt -r CONFIG_ROOT/ppp/fake-resolv.conf
85 else
86     /usr/sbin/dnsmasq -l /var/state/dhcp/dhcpd.leases $DOMopt -r CONFIG_ROOT/red/resolv.conf
87 fi
88 unset DOMopt
89
90
91 # Reset default route to ippp0 for dial on demand
92 if [ -e "CONFIG_ROOT/red/dial-on-demand" -a "$TYPE" == "isdn" -a ! -e "CONFIG_ROOT/red/active" ]; then
93         /sbin/route del default 2> /dev/null
94         if [ ! -z "$REMOTE" ]; then
95                 /sbin/route add default gw $REMOTE 2> /dev/null
96         else
97                 /sbin/route add default dev ippp0  2> /dev/null
98         fi
99 fi
100
101 if ( echo $0 | /bin/grep -q 'dhcpcd.exe' ); then
102         eval $(/usr/local/bin/readhash "$1")
103         case "$2" in
104          up)    /usr/bin/logger -s -p local0.info -t dhcpcd.exe "${INTERFACE} has been configured with old IP=${IPADDR}"
105                 if [ "$RED_TYPE" != 'PPTP' ]; then
106                         /bin/touch CONFIG_ROOT/red/active
107                 fi
108                 ;;
109          new)   /usr/bin/logger -s -p local0.info -t dhcpcd.exe "${INTERFACE} has been configured with new IP=${IPADDR}"
110                 if [ -e "CONFIG_ROOT/red/active" ]; then
111                         /usr/local/bin/setfilters
112                         /usr/local/bin/setportfw
113                         /usr/local/bin/setxtaccess
114                         /usr/local/bin/setddns.pl -f
115                         /usr/local/bin/restartsnort red
116                         sleep $VPN_DELAYED_START && /usr/local/bin/ipsecctrl S &
117                         /bin/rm -f /var/lock/rc.updatered.lock
118                         /usr/bin/logger -s -p local0.info -t rc.updatered "unlocking from $$"
119                         exit 0
120                 else
121                         if [ "$RED_TYPE" != 'PPTP' ]; then
122                                 /bin/touch CONFIG_ROOT/red/active
123                         fi
124                 fi
125                 ;;
126          down)  /usr/bin/logger -s -p local0.info -t dhcpcd.exe "${INTERFACE} has been brought down"
127                 rm -f CONFIG_ROOT/red/active
128                 ;;
129         esac
130 fi
131
132 if [ -e "CONFIG_ROOT/red/active" ]; then
133         [ "$IFACE" != "" ] && /sbin/ifconfig $IFACE -multicast
134         /etc/rc.d/rc.firewall reload
135         /usr/local/bin/setfilters
136         /usr/local/bin/restartsnort red
137         /usr/local/bin/qosctrl restart
138         /usr/local/bin/setportfw
139         /usr/local/bin/setxtaccess
140         /usr/local/bin/setddns.pl -f
141         /etc/rc.d/helper/writeipac.pl
142         /usr/sbin/fetchipac -S
143         sleep $VPN_DELAYED_START && /usr/local/bin/ipsecctrl S &
144 else
145         /usr/local/bin/ipsecctrl D
146         /etc/rc.d/rc.firewall reload
147 fi
148 /bin/rm -f /var/lock/rc.updatered.lock
149 /usr/bin/logger -s -p local0.info -t rc.updatered "unlocking from $$"