| 1 | #!/bin/sh |
|---|
| 2 | ###################################################################### |
|---|
| 3 | # This program is free software; you can redistribute it and/or # |
|---|
| 4 | # modify it under the terms of the GNU General Public License as # |
|---|
| 5 | # published by the Free Software Foundation; either version 2 of the # |
|---|
| 6 | # License, or (at your option) any later version. # |
|---|
| 7 | # # |
|---|
| 8 | # This program is distributed in the hope that it will be useful, # |
|---|
| 9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # |
|---|
| 10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # |
|---|
| 11 | # GNU General Public License for more details. # |
|---|
| 12 | # # |
|---|
| 13 | # You should have received a copy of the GNU General Public License # |
|---|
| 14 | # along with this program; if not, write to the # |
|---|
| 15 | # Free Software Foundation, Inc., # |
|---|
| 16 | # 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # |
|---|
| 17 | ###################################################################### |
|---|
| 18 | # This file is part of a Milkfish Embedded OpenSER SIP Router Setup # |
|---|
| 19 | # More information can be found at http://www.milkfish.org # |
|---|
| 20 | # # |
|---|
| 21 | # The Milkfish Environment - /etc/config/milkfish.netup # |
|---|
| 22 | # # |
|---|
| 23 | # Built/Version: 20070505 # |
|---|
| 24 | # Author/Contact: Michael Poehnl <budrus@sipwerk.com> # |
|---|
| 25 | # Copyright (C) 2007 by sipwerk - All rights reserved. # |
|---|
| 26 | # # |
|---|
| 27 | # Please note that this software is under development and comes with # |
|---|
| 28 | # absolutely no warranty, to the extend permitted by applicable law. # |
|---|
| 29 | ###################################################################### |
|---|
| 30 | |
|---|
| 31 | # get the network addresses and netmasks |
|---|
| 32 | # openwrt with sleep for wan to come up |
|---|
| 33 | #sleep 10 |
|---|
| 34 | #WAN=$(/usr/sbin/nvram get wan_ifname) |
|---|
| 35 | # dd-wrt |
|---|
| 36 | WAN=$(/usr/sbin/nvram get wan_iface) |
|---|
| 37 | LAN=$(/usr/sbin/nvram get lan_ifname) |
|---|
| 38 | LANADDR=$(/sbin/ifconfig $LAN|awk 'sub("inet addr:","") {print $1}') |
|---|
| 39 | WANADDR=$(/sbin/ifconfig $WAN|awk 'sub("inet addr:","") {print $1}') |
|---|
| 40 | MASK=$(/sbin/ifconfig $LAN|awk 'sub("Mask:","") {print $4}') |
|---|
| 41 | |
|---|
| 42 | # needed for milkfish implementation of scheduled pppoe reconnects |
|---|
| 43 | /bin/date +'%H:%M:%S %y-%m-%d - ip-up' >> /var/log/ip-up.log |
|---|
| 44 | |
|---|
| 45 | # kill openser and rtpproxy if running |
|---|
| 46 | if [ -e /var/run/openser.pid ] ; then |
|---|
| 47 | /usr/sbin/openserctl stop |
|---|
| 48 | fi |
|---|
| 49 | if [ -e /var/run/rtpproxy.pid ]; then |
|---|
| 50 | /usr/bin/killall rtpproxy |
|---|
| 51 | fi |
|---|
| 52 | sleep 3 |
|---|
| 53 | |
|---|
| 54 | # start rtpproxy |
|---|
| 55 | /usr/bin/rtpproxy -l $LANADDR/$WANADDR |
|---|
| 56 | # pimp openser.cfg and start openser |
|---|
| 57 | /bin/sed "s/fix_nated_contact(\"[0-9.]*\"/fix_nated_contact(\"$WANADDR\"/g" /etc/openser/milkfish_openser.cfg > /var/openser/milkfish_openser.cfg.tmp |
|---|
| 58 | /bin/sed "s/listen=udp:\w*:5060 #lan/listen=udp:$LAN:5060 #lan/g" /var/openser/milkfish_openser.cfg.tmp > /var/openser/milkfish_openser.cfg.tmp2 |
|---|
| 59 | /bin/sed "s/listen=udp:\w*:5060 #wan/listen=udp:$WAN:5060 #wan/g" /var/openser/milkfish_openser.cfg.tmp2 > /var/openser/milkfish_openser.cfg.tmp |
|---|
| 60 | /bin/sed "s/listen=tcp:\w*:5061/listen=tcp:$WAN:5061/g" /var/openser/milkfish_openser.cfg.tmp > /var/openser/milkfish_openser.cfg.tmp2 |
|---|
| 61 | /bin/sed "s/(src_ip==[0-9./]*/(src_ip==$LANADDR\/$MASK/g" /var/openser/milkfish_openser.cfg.tmp2 > /var/openser/milkfish_openser.cfg.tmp |
|---|
| 62 | if [ "$MASK" = 255.0.0.0 ]; then |
|---|
| 63 | NET=$(/sbin/ifconfig $LAN|awk 'sub("inet addr:","") {print $1}' | cut -f1 -d.) |
|---|
| 64 | elif [ "$MASK" = 255.255.0.0 ]; then |
|---|
| 65 | NET=$(/sbin/ifconfig $LAN|awk 'sub("inet addr:","") {print $1}' | cut -f1-2 -d.) |
|---|
| 66 | elif [ "$MASK" = 255.255.255.0 ]; then |
|---|
| 67 | NET=$(/sbin/ifconfig $LAN|awk 'sub("inet addr:","") {print $1}' | cut -f1-3 -d.) |
|---|
| 68 | fi |
|---|
| 69 | NET=$(/bin/echo $NET | /bin/sed "s/[.]/.0*/g") |
|---|
| 70 | NET=0*$NET |
|---|
| 71 | /bin/sed "s/sip:\.\*[0-9.*]*/sip:.*$NET/g" /var/openser/milkfish_openser.cfg.tmp > /var/openser/milkfish_openser.cfg.tmp2 |
|---|
| 72 | /bin/sed "s/sip:(.+)@[0-9.*]*/sip:(.+)@$NET/g" /var/openser/milkfish_openser.cfg.tmp2 > /var/openser/milkfish_openser.cfg.tmp |
|---|
| 73 | if [ $(/usr/sbin/nvram get milkfish_fromswitch) = on ] ; then |
|---|
| 74 | /bin/sed "s/2@[a-zA-Z0-9.]*/2@$(/usr/sbin/nvram get milkfish_fromdomain)/g;s/#alias=/alias=\"$(/usr/sbin/nvram get milkfish_fromdomain)\"/g" /var/openser/milkfish_openser.cfg.tmp > /var/openser/milkfish_openser.cfg |
|---|
| 75 | else |
|---|
| 76 | /bin/sed "s/2@[a-zA-Z0-9.]*/2@$WANADDR/g" /var/openser/milkfish_openser.cfg.tmp > /var/openser/milkfish_openser.cfg |
|---|
| 77 | fi |
|---|
| 78 | rm /var/openser/milkfish_openser.cfg.tmp |
|---|
| 79 | rm /var/openser/milkfish_openser.cfg.tmp2 |
|---|
| 80 | sleep 3 |
|---|
| 81 | # start openser |
|---|
| 82 | /usr/sbin/openserctl start |
|---|
| 83 | |
|---|