Advertisement
soapee01

Change th

Jul 7th, 2021
1,260
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2.  
  3. #in /etc/freeswitch/vars.xml we are changing the IP values and updating the database:
  4. #<X-PRE-PROCESS cmd="set" data="external_rtp_ip=1.2.3.4" />
  5. #<X-PRE-PROCESS cmd="set" data="external_sip_ip=1.2.3.4" />
  6.  
  7. #NOTE: if you are behind nat, you'll (which you are if you are doing this
  8. #you also need to go here and do this, or the script checks WILL NOT WORK, nor will your system
  9. # advanced -> sip profiles
  10. #  edit the internal and extneral profiles so that these values are set to:
  11. #   ext-rtp-ip = autonat:$${external_rtp_ip}
  12. #   ext-sip-ip = autonat:$${external_sip_ip}
  13.  
  14. #you'll probably also want a cronjob for this
  15. #cat /etc/cron.d/fix_fs_ip
  16. # */10 * * * * root /usr/local/bin/fix_fs_ext_ip
  17.  
  18. wanip=$(dig @resolver4.opendns.com myip.opendns.com +short -4)
  19. #echo "WanIP=$wanip"
  20.  
  21.  
  22. grep external_rtp_ip /etc/freeswitch/vars.xml | grep $wanip > /dev/null
  23. rtp_status=$?
  24. grep external_sip_ip /etc/freeswitch/vars.xml | grep $wanip > /dev/null
  25. sip_status=$?
  26.  
  27. let ip_check_status=$rtp_status+$sip_status
  28. #echo "ip_check_status=$ip_check_status"
  29.  
  30. if [ $ip_check_status -eq 0 ]; then
  31.         #we match
  32.         logger -s "[fix_fs_ext_ip] all good, IP $wanip has not changed"
  33. else
  34.  
  35.         #echo "IP was not found in vars.xml"
  36.         rm /var/cache/fusionpbx/configuration.sofia.conf.voip
  37.         sed -i /etc/freeswitch/vars.xml -e s,external_rtp_ip=.*\/\>,external_rtp_ip=$wanip\"\ \/\>,g > /dev/null
  38.         sed -i /etc/freeswitch/vars.xml -e s,external_sip_ip=.*\/\>,external_sip_ip=$wanip\"\ \/\>,g > /dev/null
  39.  
  40.         #change the database too
  41.         su postgres -c "psql -d fusionpbx -c \"UPDATE v_vars SET var_value = '$wanip' WHERE var_name = 'external_rtp_ip';\"" > /dev/null
  42.         su postgres -c "psql -d fusionpbx -c \"UPDATE v_vars SET var_value = '$wanip' WHERE var_name = 'external_sip_ip';\"" > /dev/null
  43.  
  44.         #reload FS
  45.         /usr/bin/fs_cli -x 'sofia profile external rescan reloadxml' > /dev/null
  46.         /usr/bin/fs_cli -x 'sofia profile internal rescan reloadxml' > /dev/null
  47.  
  48.         #check that the IP is there
  49.         /usr/bin/fs_cli -x 'sofia status profile external' | grep Ext-RTP-IP | grep $wanip > /dev/null
  50.         ext_rtp_status=$?
  51.         /usr/bin/fs_cli -x 'sofia status profile external' | grep Ext-SIP-IP | grep $wanip > /dev/null
  52.         ext_sip_status=$?
  53.         /usr/bin/fs_cli -x 'sofia status profile internal' | grep Ext-RTP-IP | grep $wanip > /dev/null
  54.         int_rtp_status=$?
  55.         /usr/bin/fs_cli -x 'sofia status profile internal' | grep Ext-SIP-IP | grep $wanip > /dev/null
  56.         int_sip_status=$?
  57.  
  58.         let CheckStatus=$ext_rtp_status+$ext_sip_status+$int_rtp_status+$int_sip_status
  59.         #echo "check-status=$CheckStatus"
  60.  
  61.         if [ $CheckStatus -eq 0 ]; then
  62.                 #wanip & FS updated correctly
  63.                 logger -s "[fix_fs_ext_ip] SUCCESS: External & Internal Profiles: Ext-RTP|SIP-IP=$wanip"
  64.         else
  65.                 logger -s "[fix_fs_ext_ip] FAILURE: something went awry when we tried to change $wanip. you should check out why."
  66.         fi
  67.  
  68. fi
Advertisement
RAW Paste Data Copied
Advertisement