Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #in /etc/freeswitch/vars.xml we are changing the IP values and updating the database:
- #<X-PRE-PROCESS cmd="set" data="external_rtp_ip=1.2.3.4" />
- #<X-PRE-PROCESS cmd="set" data="external_sip_ip=1.2.3.4" />
- #NOTE: if you are behind nat, you'll (which you are if you are doing this
- #you also need to go here and do this, or the script checks WILL NOT WORK, nor will your system
- # advanced -> sip profiles
- # edit the internal and extneral profiles so that these values are set to:
- # ext-rtp-ip = autonat:$${external_rtp_ip}
- # ext-sip-ip = autonat:$${external_sip_ip}
- #you'll probably also want a cronjob for this
- #cat /etc/cron.d/fix_fs_ip
- # */10 * * * * root /usr/local/bin/fix_fs_ext_ip
- wanip=$(dig @resolver4.opendns.com myip.opendns.com +short -4)
- #echo "WanIP=$wanip"
- grep external_rtp_ip /etc/freeswitch/vars.xml | grep $wanip > /dev/null
- rtp_status=$?
- grep external_sip_ip /etc/freeswitch/vars.xml | grep $wanip > /dev/null
- sip_status=$?
- let ip_check_status=$rtp_status+$sip_status
- #echo "ip_check_status=$ip_check_status"
- if [ $ip_check_status -eq 0 ]; then
- #we match
- logger -s "[fix_fs_ext_ip] all good, IP $wanip has not changed"
- else
- #echo "IP was not found in vars.xml"
- rm /var/cache/fusionpbx/configuration.sofia.conf.voip
- sed -i /etc/freeswitch/vars.xml -e s,external_rtp_ip=.*\/\>,external_rtp_ip=$wanip\"\ \/\>,g > /dev/null
- sed -i /etc/freeswitch/vars.xml -e s,external_sip_ip=.*\/\>,external_sip_ip=$wanip\"\ \/\>,g > /dev/null
- #change the database too
- su postgres -c "psql -d fusionpbx -c \"UPDATE v_vars SET var_value = '$wanip' WHERE var_name = 'external_rtp_ip';\"" > /dev/null
- su postgres -c "psql -d fusionpbx -c \"UPDATE v_vars SET var_value = '$wanip' WHERE var_name = 'external_sip_ip';\"" > /dev/null
- #reload FS
- /usr/bin/fs_cli -x 'sofia profile external rescan reloadxml' > /dev/null
- /usr/bin/fs_cli -x 'sofia profile internal rescan reloadxml' > /dev/null
- #check that the IP is there
- /usr/bin/fs_cli -x 'sofia status profile external' | grep Ext-RTP-IP | grep $wanip > /dev/null
- ext_rtp_status=$?
- /usr/bin/fs_cli -x 'sofia status profile external' | grep Ext-SIP-IP | grep $wanip > /dev/null
- ext_sip_status=$?
- /usr/bin/fs_cli -x 'sofia status profile internal' | grep Ext-RTP-IP | grep $wanip > /dev/null
- int_rtp_status=$?
- /usr/bin/fs_cli -x 'sofia status profile internal' | grep Ext-SIP-IP | grep $wanip > /dev/null
- int_sip_status=$?
- let CheckStatus=$ext_rtp_status+$ext_sip_status+$int_rtp_status+$int_sip_status
- #echo "check-status=$CheckStatus"
- if [ $CheckStatus -eq 0 ]; then
- #wanip & FS updated correctly
- logger -s "[fix_fs_ext_ip] SUCCESS: External & Internal Profiles: Ext-RTP|SIP-IP=$wanip"
- else
- logger -s "[fix_fs_ext_ip] FAILURE: something went awry when we tried to change $wanip. you should check out why."
- fi
- fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement