123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184 |
- #!/bin/sh
- ETHPATH=/etc/network
- ETH0=$ETHPATH/interfaces
- NETCONF=/etc/asterisk/network.conf
- case $1 in
- getconfig)
- cat /etc/rc.conf | sed 's/\[network\]/\;\[network\]/g' | tr \; \# | sed '/#!/d' | tr -d ' ' > /tmp/network.conf
- . /tmp/network.conf
- echo [network] > $NETCONF
- echo HOSTNAME="`hostname`">> $NETCONF
- if [ "$IPASSIGN" = "dhcp" ]
- then
- echo IPASSIGN=dhcp >> $NETCONF
- ADDR="`/sbin/ifconfig eth0|grep 'inet addr:'|cut -d: -f2|awk '{print $1}'`"
- echo IPADDRESS=$ADDR >> $NETCONF
- MASK="`/sbin/ifconfig eth0|grep 'Mask:'|cut -d: -f4|awk '{print $1}'`"
- echo NETMASK="$MASK" >> $NETCONF
- GATEWAY="`route -n|grep '^0.0.0.0'|grep 'eth0'|awk '{print $2}'`"
- echo GATEWAY=$GATEWAY >> $NETCONF
- DNS1="`cat /etc/resolv.conf|grep '^nameserver'|sed '1!d;s/.* //'`"
- echo PrimaryDNS="$DNS1" >> $NETCONF
- DNS2="`cat /etc/resolv.conf|grep '^nameserver'|sed '2!d;s/.* //'`"
- echo AlternateDNS="$DNS2" >> $NETCONF
- else
- echo IPASSIGN=static >> $NETCONF
- echo IPADDRESS="$IPADDRESS" >> $NETCONF
- echo NETMASK="$NETMASK" >> $NETCONF
- echo GATEWAY="$GATEWAY" >> $NETCONF
- DNS1="`cat /etc/resolv.conf|grep '^nameserver'|sed '1!d;s/.* //'`"
- echo PrimaryDNS="$DNS1" >> $NETCONF
- DNS2="`cat /etc/resolv.conf|grep '^nameserver'|sed '2!d;s/.* //'`"
- echo AlternateDNS="$DNS2" >> $NETCONF
- fi
- echo IPADDRESSLAN="$IPADDRESSLAN" >> $NETCONF
- echo NETMASKLAN="$NETMASKLAN" >> $NETCONF
- echo LANV1ENABLE="$LANV1ENABLE" >> $NETCONF
- echo IPADDRESSLV1="$IPADDRESSLV1" >> $NETCONF
- echo NETMASKLV1="$NETMASKLV1" >> $NETCONF
- echo LANV2ENABLE="$LANV2ENABLE" >> $NETCONF
- echo IPADDRESSLV2="$IPADDRESSLV2" >> $NETCONF
- echo NETMASKLV2="$NETMASKLV2" >> $NETCONF
- ;;
- setconfig)
- cat /etc/rc.conf | sed 's/\[network\]/\;\[network\]/g' | tr \; \# | sed '/#!/d' | tr -d ' ' > /tmp/network.conf
- . /tmp/network.conf
- #Set WAN Interface
- touch /tmp/interfaces.tmp
- echo "auto lo" > /tmp/interfaces.tmp
- echo "iface lo inet loopback" >> /tmp/interfaces.tmp
- if [ "$IPASSIGN" = "dhcp" ]
- then
- echo "auto eth0" >> /tmp/interfaces.tmp
- echo "iface eth0 inet dhcp" >> /tmp/interfaces.tmp
- else
- echo "auto eth0" >> /tmp/interfaces.tmp
- echo "iface eth0 inet static" >> /tmp/interfaces.tmp
- echo " address $IPADDRESS" >> /tmp/interfaces.tmp
- echo " netmask $NETMASK" >> /tmp/interfaces.tmp
- echo " gateway $GATEWAY" >> /tmp/interfaces.tmp
- [ "$PrimaryDNS" ] && echo "nameserver $PrimaryDNS" > /etc/resolv.conf
- [ "$AlternateDNS" ] && echo "nameserver $AlternateDNS" >> /etc/resolv.conf
- fi
- #Set LAN Interface
- echo "auto eth1" >> /tmp/interfaces.tmp
- echo "iface eth1 inet static" >> /tmp/interfaces.tmp
- echo " address $IPADDRESSLAN" >> /tmp/interfaces.tmp
- echo " netmask $NETMASKLAN" >> /tmp/interfaces.tmp
- #Set LANv1 Interface
- if [ "$LANV1ENABLE" = "yes" ]
- then
- ifconfig eth1:0 down
- echo "auto eth1:0" >> /tmp/interfaces.tmp
- echo "iface eth1:0 inet static" >> /tmp/interfaces.tmp
- echo " address $IPADDRESSLV1" >> /tmp/interfaces.tmp
- echo " netmask $NETMASKLV1" >> /tmp/interfaces.tmp
- else
- ifconfig eth1:0 down
- fi
- #Set LANv2 Interface
- if [ "$LANV2ENABLE" = "yes" ]
- then
- ifconfig eth1:1 down
- echo "auto eth1:1" >> /tmp/interfaces.tmp
- echo "iface eth1:1 inet static" >> /tmp/interfaces.tmp
- echo " address $IPADDRESSLV2" >> /tmp/interfaces.tmp
- echo " netmask $NETMASKLV2" >> /tmp/interfaces.tmp
- else
- ifconfig eth1:1 down
- fi
- mv -f /tmp/interfaces.tmp $ETH0
- ;;
- setvlan)
- cat /etc/rc.conf | sed 's/\[network\]/\;\[network\]/g' | tr \; \# | sed '/#!/d' | tr -d ' ' > /tmp/network.conf
- . /tmp/network.conf
- #RM ALL VLAN
- cat /etc/network/interfaces > /tmp/interfaces.tmp
- #sed -i 12',$d' /etc/network/interfaces
- for i in `grep "eth" /proc/net/vlan/config|cut -d ' ' -f1`
- do
- vconfig rem $i
- done
- #Set WAN VLAN 1
- if [ "$VLANENABLE" = "yes" ]
- then
- vconfig add eth0 $VLANID
- echo "auto eth0.$VLANID" >> /tmp/interfaces.tmp
- echo "iface eth0.$VLANID inet static" >> /tmp/interfaces.tmp
- echo " address $VLANIPADDRESS" >> /tmp/interfaces.tmp
- echo " netmask $VLANNNETMASK" >> /tmp/interfaces.tmp
- fi
- #Set WAN VLAN 2
- if [ "$VLANENABLE2" = "yes" ]
- then
- vconfig add eth0 $VLANID2
- echo "auto eth0.$VLANID2" >> /tmp/interfaces.tmp
- echo "iface eth0.$VLANID2 inet static" >> /tmp/interfaces.tmp
- echo " address $VLANIPADDRESS2" >> /tmp/interfaces.tmp
- echo " netmask $VLANNNETMASK2" >> /tmp/interfaces.tmp
- fi
- #Set LAN VLAN 1
- if [ "$VLANENABLEL" = "yes" ]
- then
- vconfig add eth1 $VLANIDL
- echo "auto eth1.$VLANIDL" >> /tmp/interfaces.tmp
- echo "iface eth1.$VLANIDL inet static" >> /tmp/interfaces.tmp
- echo " address $VLANIPADDRESSL" >> /tmp/interfaces.tmp
- echo " netmask $VLANNNETMASKL" >> /tmp/interfaces.tmp
- fi
- #Set LAN VLAN 2
- if [ "$VLANENABLEL2" = "yes" ]
- then
- vconfig add eth1 $VLANIDL2
- echo "auto eth1.$VLANIDL2" >> /tmp/interfaces.tmp
- echo "iface eth1.$VLANIDL2 inet static" >> /tmp/interfaces.tmp
- echo " address $VLANIPADDRESSL2" >> /tmp/interfaces.tmp
- echo " netmask $VLANNNETMASKL2" >> /tmp/interfaces.tmp
- fi
- mv -f /tmp/interfaces.tmp $ETH0
- rm -rf /tmp/interfaces.tmp
- ;;
- restart)
- ifconfig eth0 down
- ifconfig eth1 down
- ifconfig lo down
- $0 setconfig
- $0 setvlan
- /etc/init.d/networking restart
- ifconfig eth0 up
- ifconfig eth1 up
- ifconfig lo up
- /etc/scripts/phonesinit.sh
- /etc/scripts/pnp.sh
- ;;
- setstaticroute)
- #set WAN static routes
- if [ -f /etc/asterisk/staticroutes.conf ];then
- i=`cat /etc/asterisk/staticroutes.conf |grep "^[\[A-Za-z]"|tr -d " "|wc -l`
- if [ "$i" -ge 4 ];then
- i=`expr $i / 4`
- j=0
- while [ "$i" -gt 0 ]
- do
- line_Start=`expr $j \* 4 + 2`
- line_End=`expr $line_Start + 2`
- cat /etc/asterisk/staticroutes.conf |grep "^[\[A-Za-z]"|tr -d " "|sed -n "${line_Start},${line_End}p" >/tmp/staticroutes.conf.tmp
- . /tmp/staticroutes.conf.tmp
- if [ -z "$Destination" -o -z "$Netmask" -o -z "$Gateway" ];then
- echo "error"
- else
- /sbin/route add -net ${Destination} netmask ${Netmask} gw ${Gateway} 2>/dev/null
- fi
- i=`expr $i - 1`
- j=`expr $j + 1`
- done
- fi
- fi
- ;;
- esac
|