Update dynamic IP on FreePBX box
Post ReplyUpdate dynamic IP on FreePBX boxPosted: Wednesday, March 7, 2018 [20:52:08] - 1
If trunk requires an "externip" to be provided in SIP settings, every time your WAN IP changes it has to be reflected in settings. Using a pfSense it is easy to read a WAN IP, say once an hour: chomp $current_wan_ip; if(-f '/http/current.wan.ip.txt') {$was_ip_wan = `cat /http/current.wan.ip.txt`;} else {open(TXWW,">/http/current.wan.ip.txt"); ## If IP is new - write a trigger file for FreePBX update unless(($was_ip_wan eq $current_wan_ip) && $was_ip_wan) { open(AST,">/http/asteriskchange.txt"); } Then if trigger file present - run an Asterisk update script. You can verify which Asterisk files your need to update by running a find on FreePBX: List of those files to be included in update script below: ## If run by cron - making sure the path is set unless($ENV{'SECURITYSESSIONID'}) { $ENV{'PATH'} = '/bin:/sbin:/usr/bin:/usr/sbin:/usr/local:/usr/local/bin'; } ## Do not run unless change is required unless(-f "/http/asteriskchange.txt") {print "No source file present - exit\n"; $ips = `cat /http/asteriskchange.txt`; $ips=''; ## We need both (old and new) IP addresses to process, if one missing - exit unless($was_ip && $now_ip) {print "At least one IP is missing - exit\n"; ## Asterisk files to be updated by the script provided by "find" search @allfiles = ('/etc/asterisk/sip_additional.conf', '/etc/asterisk/sip_general_additional.conf', '/etc/asterisk/pjsip.transports.conf'); ## Keep the old files, just in-case if(-f "/http/asteriskchange.old.txt") {unlink "/http/asteriskchange.old.txt";} `mv /http/asteriskchange.txt /http/asteriskchange.old.txt`; ## Now update Asterisk config files foreach $file (@allfiles) {$localfile=$file; if(-f "/http/ipLogD/$localfile") {unlink "/http/ipLogD/$localfile";} `scp root\@192.168.2.50:$file /http/temp/$localfile`; $d = `cat /http/temp/$localfile`; if($d =~ m/$was_ip/) { $d =~ s#$was_ip#$now_ip#gs; open(TXT,">/http/temp/$localfile"); `scp /http/ipLogD/$localfile root\@FreePBX_IP_Address:$file`; } ## END IF FILE MATCHES OLD IP } ## END FOREACH FILE ## If something changed - restart Asterisk if($donefiles) { ############# `ssh root\@FreePBX_IP_Address '/usr/sbin/fwconsole restart'`; } ## END IF FILES UPDATED #### It is safe to run this script from cron once an hour or so. All scripts above require password-less login to your FreePBX and pfSense boxes. More on password-less login: https://www.codemacs.com/coding/applescript/ftp-like-commands-and-remote-osascript-on-macs.5918921.htm |
RE: Update dynamic IP on FreePBX boxPosted: Friday, March 9, 2018 [15:18:32] - 2