Hi, i was able to accomplish this and i figured to share it just in case somebody else has a similar need.
Step #1: Create Custom Destination, set the target to macro-dial-in,1,1
Step #2: Use the Config Edit to create a new file with your passcodes and contexts. Ours is “/etc/asterisk/disa_file.conf” with this sample content:
1234
5678
;1234|context1|
;5678|context2|
Step #3: Modify extensions_custom.conf and add this code:
[macro-dial-in]
exten => 1,1,Answer
exten => 1,n,Authenticate(/etc/asterisk/disa_file.conf,a,4)
exten => 1,n,Set(passcode=${CDR(accountcode)})
exten => 1,n,Noop(Passcode Code: ${passcode})
exten => 1,n,Set(regex="(${passcode}(\|.*?))")
exten => 1,n,Set(filetext=${FILE(/etc/asterisk/disa_file.conf)})
exten => 1,n,Set(linetext=$["${filetext}" =~ ${regex}])
exten => 1,n,Set(contextname=${CUT(linetext,|,2)})
exten => 1,n,Noop(Context Name: ${contextname})
exten => 1,n,Gosub(sub-record-check,s,1(disa,${EXTEN},dontcare))
exten => 1,n,Set(_DISA=disa^1^newcall)
exten => 1,n(newcall),Set(_DISACONTEXT=${contextname})
exten => 1,n,Set(_KEEPCID=TRUE)
exten => 1,n,Set(_HANGUP=${TRUNK_OPTIONS})
exten => 1,n,Set(TIMEOUT(digit)=5)
exten => 1,n,Set(TIMEOUT(response)=10)
exten => 1,n,DISA(no-password,disa-dial)
exten => 1,n(end),Hangup
This is how it works: Authenticate will match the entered passcode by the caller to a number in the file. If valid, this number will become the CDR(accountcode)
A regular expression is created to match the passcode + “|”
The same file that has the passcodes (etc/asterisk/disa_file.conf) is read completely, the bottom section has some comments that matches a passcode to a context (unfortunately you cannot have this as a comment on the same line as the passcode since Authenticate will try to match the input to each full line.
Then the regular expression is applied to the whole file to get the line that matches the passcode (which came from the account code) and the pipe (|) . CUT is used to strip the pipe which leaves the context we need.
The rest of the function is pretty much the standard DISA call from FreePBX, but we just change the context to our contextname variable.
Step #4: Create the Entry on your IVR for the Custom Destination created on Step #1
Enjoy and good luck!
Camilo