System information

Remember that in a traditional phone system all extensions must be
numbers, but in Asterisk, extensions can have names as well. A possible
advantage of using an extension that’s not a number is that it will be
much harder for a user to dial it from her phone and, thus, more secure.
We’re going to use several named extensions in this example. If you
want to be absolutely sure that a malicious user cannot access those
named extensions, simply use the trick that the AEL loader uses: start
with a priority other than 1. You can access the first line of the extension
by assigning it a priority label and referencing it via the extension name/
priority label combination.
The login extension runs some initial checks to verify the pin code entered by the agent.
We allow him three tries to enter the correct pin, and if all tries are invalid we send the
call to the login_fail extension (which we will be writing later):
exten => login,1,NoOp() ; set initial counter values
same => n,Set(PIN_TRIES=1) ; pin tries counter
same => n,Set(MAX_PIN_TRIES=3) ; set max number of login attempts
same => n,Playback(silence/1) ; play back some silence so first prompt is
; not cut off
same => n(get_pin),NoOp()
same => n,Set(PIN_TRIES=$[${PIN_TRIES} + 1]) ; increase pin try counter
same => n,Read(PIN_ENTERED,enter-password,${LEN(${${E}_PIN})})
same => n,GotoIf($["${PIN_ENTERED}" = "${${E}_PIN}"]?valid_login,1)
same => n,Playback(pin-invalid)
same => n,GotoIf($[${PIN_TRIES} <= ${MAX_PIN_TRIES}]?get_pin:login_fail,1)
If the pin entered matches, we validate the login with the valid_login extension. First
we utilize the CHANNEL variable to figure out which phone device the agent is calling
from. The CHANNEL variable is usually populated with something like SIP/0000FFFF0001-
ab4034c, so we make use of the CUT() function to first pull off the SIP/ portion of the
string and assign that to LOCATION. We then strip off the -ab4034c part of the string,
discard it, and assign the remainder (0000FFFF0001) to the LOCATION variable:
exten => valid_login,1,NoOp()
; CUT off the channel technology and assign it to the LOCATION variable
same => n,Set(LOCATION=${CUT(CHANNEL,/,2)})
; CUT off the unique identifier and save the remainder to the LOCATION variable
same => n,Set(LOCATION=${CUT(LOCATION,-,1)})
We utilize yet another custom function created in the func_odbc.conf file, HOT
DESK_CHECK_PHONE_LOGINS(), to check if any other users were previously logged into this
phone and forgot to log out. If the number of logged-in users is greater than 0 (it should
never be more than 1, but we check for higher values anyway and reset those, too), it
runs the logic in the logout_login extension:
; func_odbc.conf
[CHECK_PHONE_LOGINS]
prefix=HOTDESK
dsn=asterisk
Getting Funky with func_odbc: Hot-Desking | 363