#!/bin/sh -x
# /bin/setnewip
# David Rowe Nov 18 2007
# Modified for Openwrt's uci interface by Elektra
# Sets a new IP based on DTMF digits collected by Asterisk
# Asterisk places it's collected IP in /tmp/newip.txt

if [ ! -f /tmp/newip.txt ]; then
  exit
fi

# convert * seperated IP like 192*168*1*32 to 192.168.1.32

cat /tmp/newip.txt | sed 's/\*/\./g' > /tmp/newip_dot.txt
uci set network.lan.ipaddr=`cat /tmp/newip_dot.txt`

#uci set network.wifi0.ipaddr=`cat /tmp/newip_dot.txt`
uci commit network

OCTET_A=`uci show network.lan.ipaddr | cut -d = -f2 | cut -d . -f1`                                                                                                                                                              
OCTET_B=`uci show network.lan.ipaddr | cut -d = -f2 | cut -d . -f2`                                                                      
OCTET_C=`uci show network.lan.ipaddr | cut -d = -f2 | cut -d . -f3`

uci set network.lan.gateway=$OCTET_A.$OCTET_B.$OCTET_C.1
uci commit network

reboot

