Checking internal dial number and ask for pin


I’d like to configure a way to ask for a PIN from one SIP only.

How can I check what internal extension number is used in my extension.conf and then make Asterisk ask for a specific PIN?

Use the CALLERID(num) with GotoIF and authenticate, or create another context for that peer.

I was hoping for some examples on how to do it. However I have found a solution that works for me. It’s most likely not the most elegant way, but did solve my problem.

I found a way to detect which internal caller ID is making the call and asking the user for a preset PIN. In my extensions.conf I have the following for outgoing calls to any 6 digit phone number (I only allow calling 6 digit numbers):

exten => _NXXXXX,1,Answer(500)
; Play a message asking user to enter a 4 digit PIN to allow calling out
; However, only ask this for internal caller ID 19
exten => _NXXXXX/19,2,Playback(askforpin)
; All other internal IDs are not asked for validation
exten => _NXXXXX,2,NoOp()
; Read 4 digits from user at internal ID 19
exten => _NXXXXX/19,3,Read(PINCODE,4)
; For all other lines except line 19 skip this step
exten => _NXXXXX,3,NoOp()
; Verify PIN user gave us.
; If it doesn’t matches 1234 go to step 6 of this routine (Hangup)
; (and I found out the hard way it’s not supposed to be “1234” as in a string)
exten => _NXXXXX/19,4,GotoIf($[${PINCODE} != 1234]?6)
; For all other lines except 19 skip this step as well
exten => _NXXXXX,4,NoOp()
; Make the call, but give up after 120 seconds if nobody answers
exten => _NXXXXX,5,Dial(SIP/{$EXTEN}@provider1,120,r)
; Disconnect the dialer
exten => _NXXXXX,6,Hangup

To ID the caller internal ID I had this in my sip.conf

callerid=Line 19 <19>
allow = g729,g723,ulaw,alaw,gsm

The 19 in the <19> portion identified the caller in the “callerid” line as can be found using CALLERID(num) as well.

I did the same for this users voicemail and created similar steps that makes this user require a PIN for voicemail access. Other users are automatically allowed into their voicemail. Since line 19 is a public handset I wanted to limit it’s abilities this way.