Asterisk Dialplan – Lock Virtual Extensions Remotely

Today we had a customer who wanted to use the phone unlock feature for their virtual extension which had no physical phones. Normally phone lock feature works directly from the extension physical phone. So I had to do some customisation in the asterisk dialplan. Here is the code:

Note: For this example I’m using FreePBX 2.4. Simply copy the following code to /etc/asterisk/extensions_custom.conf under [from-internal-custom]

;;;;;;;;;; This is to Lock the Virtual Extension
exten => *57,1,NoOP(== Dialplan to Lock phones remotely ==)
exten => *57,n,PlayBack(silence/1&please-enter-your&extension)
exten => *57,n,Read(EXT)
exten => *57,n,SET(DB(AMPUSER/${EXT}/KEYLOCK)=1)
exten => *57,n,playback(extension)
exten => *57,n,SayDigits(${EXT})
exten => *57,n,playback(ha/locked)

exten => _*57.,1,NoOP(== Dialplan to Lock phones remotely ==)
exten => _*57.,n,set(EXT=${EXTEN:3}
exten => _*57.,n,SET(DB(AMPUSER/${EXT}/KEYLOCK)=1)
exten => _*57.,n,playback(extension)
exten => _*57.,n,SayDigits(${EXT})
exten => _*57.,n,playback(ha/locked) 

;;;;;;;;;;; This is to unLock the Virtual Extension
exten => *58,1,NoOP(== Dialplan to UnLock phones remotely  ==)
exten => *58,n,PlayBack(silence/1&please-enter-your&extension)
exten => *58,n,Read(EXT)
exten => *58,n,DBDel(AMPUSER/${EXT}/KEYLOCK)
exten => *58,n,playback(extension)
exten => *58,n,SayDigits(${EXT})
exten => *58,n,playback(ha/unlocked)

exten => _*58.,1,NoOP(== Dialplan to Lock phones remotely ==)
exten => _*58.,n,set(EXT=${EXTEN:3}
exten => _*58.,n,DBDel(AMPUSER/${EXT}/KEYLOCK)
exten => _*58.,n,playback(extension)
exten => _*58.,n,SayDigits(${EXT})
exten => _*58.,n,playback(ha/unlocked)

You may also like