Skip to content

Instantly share code, notes, and snippets.

@hgaibor
Last active March 15, 2021 18:05
Show Gist options
  • Save hgaibor/8fa18e95715fbd78e304101f398c5ab5 to your computer and use it in GitHub Desktop.
Save hgaibor/8fa18e95715fbd78e304101f398c5ab5 to your computer and use it in GitHub Desktop.
Limit internal extension to extension dialing custom dialplan
; Restrict extension-to-extension dialing on a PBX, allowing only to dial operator extension (100).
; NOTE: This code is in early stages, it has not considered the 911 dialing that has become mandatory for the US.
; See this link for further information: https://wiki.freepbx.org/display/FOP/Set+up+Emergency+Service%28E911%29+calling+requirements
;
; Latest version:
; https://gist.github.com/hgaibor/8fa18e95715fbd78e304101f398c5ab5
;
;
; Usage:
; 1. On FreePBX/PBXact GUI, add this to extensions_custom.conf file. This will use the predial hook to validate dialing for each call.
;
; 2. Replace 100 extension to whatever extension number you require to be valid for dialing within the PBX.
;
; License: GNU GPL2
;
; Version History
; 2021-03-08 First public commit by hgaibor
;
[macro-dialout-one-predial-hook]
exten => s,1,GoSub(sub-check-allowed-extension,s,1)
exten => s,n,MacroExit
[macro-dialout-dundi-predial-hook]
exten => s,1,GoSub(sub-check-allowed-extension,s,1)
exten => s,n,MacroExit
[macro-dial-ringall-predial-hook]
exten => s,1,GoSub(sub-check-allowed-extension,s,1)
exten => s,n,MacroExit
[macro-dial-hunt-predial-hook]
exten => s,1,GoSub(sub-check-allowed-extension,s,1)
exten => s,n,MacroExit
[sub-check-allowed-extension]
; this has not been well tested, more of a framework for future
exten => s,1,NoOp(Entering user defined context sub-check-allowed-extension in extensions_custom.conf)
;exten => s,n,DumpChan
exten => s,n,NoOp(From Extension: ${FROMEXTEN})
exten => s,n,NoOp(To Extension: ${EXTTOCALL})
exten => s,n,GotoIf($["${FROMEXTEN}" = "100"]?AllowRepCall:CheckExt2ExtCall)
exten => s,n(AllowRepCall),Return
exten => s,n(CheckExt2ExtCall),NoOp(Entering user defined context to CheckExt2ExtCall: ${EXTTOCALL})
;exten => s,n,GotoIf($["${EXTTOCALL}" != "100"]?DenyRepCall:AllowExtCall)
exten => s,n,GotoIf($["${EXTTOCALL}" != "100"]?CheckExternalDID:AllowExtCall)
exten => s,n(CheckExternalDID),NoOp(This seems like external number?)
exten => s,n,GotoIf($["${LEN(${EXTTOCALL})}" <= "4"]?DenyRepCall:AllowExtCall)
exten => s,n(DenyRepCall),Playtones(busy)
exten => s,n,Busy(10)
exten => s,n,Hangup()
exten => s,n,Return
exten => s,n(AllowExtCall),NoOp(AllowExtCall Allowing call to ext100 : ${EXTTOCALL})
exten => s,n,Return
; end context [sub-check-allowed-extension]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment