Description
RefreshSIP is a service which refreshes the externip configuration parameter needed for the SIP channel driver of an Asterisk PBX running behind a NAT router.
RefreshSIP waits for TCP connections on a predefined port (default 9999). The connected client should write the IP address in the socket. When the IP adress is received, the RefreshSIP writes it in the sip.conf file and instructs the running Asterisk PBX to reload the SIP configuration, using the command:
asterisk -rx "sip reload"
Example
Here is an example of a client which runs in the IPCop Router/Firewall from the AmatixOffice distribution:
#!/bin/bash
# The IP Address and the PORT where the server is listening
SERVIP="$1"
if [ "$SERVIP" = "" ]; then
SERVIP="pbx"
fi
SERVPORT="$2"
if [ "$SERVPORT" = "" ]; then
SERVPORT="9999"
fi
# The red interface
rediface=`cat /var/ipcop/red/iface`
if [ "$rediface" = "" ]; then
# No interface => exit
exit 0
fi
# Get the IP Address of the RED interface
if [ "${rediface:0:3}" = "eth" ]; then
line=`/sbin/ifconfig $rediface | grep "inet addr:" | cut -c "21-"`
if [ "$line" = "" ]; then
# The interface is not configured
exit 0
fi
read redip relax<<<$(echo $line)
else
redip=`cat /var/ipcop/red/local-ipaddress`
fi
if [ "$redip" = "" ]; then
# The interface is not configured
exit 0
fi
# Send the configuration to the server
logger -t refreshsip "Send the new IP address $redip to the PBX ($SERVIP:$SERVPORT)"
retstr=`socket -p "echo $redip" -q "$SERVIP" "$SERVPORT" 2>&1`
if [ "$retstr" = "" ]; then
retstr="OK"
fi
logger -t refreshsip "$retstr"
exit 0
