Skip to content

Instantly share code, notes, and snippets.

Last active January 29, 2023 20:47
What would you like to do?
DTMF to Firewall Trusted Zone
; Dialplan for a feature code to add ; an IP address to the FreePBX trusted zone
; Dial F-I-R-E-W-A-L-L from an internal extension and enter an IPv4 address using
; DTMF with * as the dot character.
; License: GNU GPL3+
; latest version:
; version history 2023-01-21 First commit working
exten => 34739255,1,Noop(Entering user defined context from-internal-custom in extensions_custom.conf)
exten => 34739255,n,Read(address,please-enter-your&address&followed_pound) ; use dtmf to enter IPv4 address, accept * for the .
exten => 34739255,n,Noop(${address})
; Was thinking to add a regex to validate dtmf input here
; but the fwconsole will validate the address anyway
; there is no easy way to read back an IP address, so slice up into octets
exten => 34739255,n,Set(address1=${CUT(address,*,1)})
exten => 34739255,n,Set(address2=${CUT(address,*,2)})
exten => 34739255,n,Set(address3=${CUT(address,*,3)})
exten => 34739255,n,Set(address4=${CUT(address,*,4)})
; read back in octets
exten => 34739255,n,ExecIf($["${address1}"!=""]?SayDigits(${address1})
exten => 34739255,n,ExecIf($["${address2}"!=""]?Playback(point))
exten => 34739255,n,ExecIf($["${address2}"!=""]?SayDigits(${address2})
exten => 34739255,n,ExecIf($["${address3}"!=""]?Playback(point))
exten => 34739255,n,ExecIf($["${address3}"!=""]?SayDigits(${address3})
exten => 34739255,n,ExecIf($["${address4}"!=""]?Playback(point))
exten => 34739255,n,ExecIf($["${address4}"!=""]?SayDigits(${address4})
; fix up address, replace *'s with dots
exten => 34739255,n,Set(address=${STRREPLACE(address,*,.)})
; use fwconsole to add address to firewall as trusted
exten => 34739255,n,Set(foo=${SHELL(fwconsole firewall trust ${address})})
; check result and indicate pass/fail to caller
exten => 34739255,n,ExecIf($[${REGEX("Success" ${foo})}]?Flite(Firewall command successful):Flite(firewall command failed))
exten => 34739255,n,hangup
Copy link

lgaetz commented Jan 20, 2023

ToDo: add email notification to system administrator at end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment