Friday, September 8, 2017

Have callers approve their call being recorded in Asterisk.

This a demo, so I just used a default recording that says "this call may be monitored". You can easily replace this with one that makes more sense. "Press 1 to permit us to record this call, any other key to decline"
Pressing 1 will FORCE recording of the calls. Any other key, or if they press nothing after a couple of asks it will automatically set the recording to "NO"
This works for all calls marked as external. Internal calls I've bypassed it asking the question and set it to 'dontcare'. If you want internal extension to extension calls record, change 'dontcare' to 'force'
You've set all call recording options in FreePBX to "DONT CARE"
Thats how i tested it. In FreePBX Distro 10.13.66
Don't test this in production environment

Open up extension_additional.conf and look for the context
Copy that entire section (its probably about 100 lines) and ends with
;--== end of [sub-record-check] ==--;
Paste that into extensions_override_freepbx.conf
Find these two lines about 12 or so lines down.
exten => recordcheck,1,Noop(Starting recording check against ${ARG1})
exten => recordcheck,n,Goto(${ARG1})
INSERT these 4 lines in between the above two lines.
exten => recordcheck,n,GotoIf($["${CALLTYPE}" = "internal"]?dontcare)
exten => recordcheck,n,ExecIf($["${CALLTYPE}" = "external"]?Read(FOOrecord,this-call-may-be-monitored-or-recorded,1,,2,3))
exten => recordcheck,n,ExecIf($["${CALLTYPE}" = "external" | "${FOOrecord}" = "" ]?Set(ARG1=no)
exten => recordcheck,n,ExecIf($["${CALLTYPE}" = "external" | "${FOOrecord}" = "1" ]?Set(ARG1=force)
Save your changes
Reload the config
Make a test call.
Check to see if its an internal extension to extension call, we bypass it asking for permission to record and ring the phone.
exten => recordcheck,n,GotoIf($["${CALLTYPE}" = "internal"]?dontcare)
If this is an external call, we prompt the caller if they permit us to record the call. the syntax is:
READ(DTMFvariable, soundfile, max number of digits, number of times it will ask, how long it will wait for an answer
exten => recordcheck,n,ExecIf($["${CALLTYPE}" = "external"]?Read(FOOrecord,this-call-may-be-monitored-or-recorded,1,,2,3))
If the caller doesn't respond with any input, then we assume "no" and continue the call. 
exten => recordcheck,n,ExecIf($["${CALLTYPE}" = "external" | "${FOOrecord}" = "" ]?Set(ARG1=no)
If the callers presses 1, then we set the call recording to on and ring the extension
exten => recordcheck,n,ExecIf($["${CALLTYPE}" = "external" | "${FOOrecord}" = "1" ]?Set(ARG1=force)

Record the digits selected in an asterisk IVR for surveys

This records answers from a customer survey, but this one does it by modifying an existing IVR code.  For demo purposes it shows how to modify an IVR dialplan.


This records the IVR selections and save them into a file called survey.txt
The comma delimited file contain each IVR selection broken up in this manner:

Example output:

07092017-22:35:03,Jane Doe <5551238811>,1504834501.1207,ivr-7,custom/question1,1

CallerID=The callers CLID if available "Jane Doe <5551238811>"
UniqueID=This is the unique value for each call. This will help you sort indvidual calls that are in this file.
FreepbxIVRid=Each IVR you create is assigned an IVR. FreePBX doesn't store the descriptive name, this is here to help you know which one is which.
QuestionFilename=This is the sound file that you play for each IVR. This is to help you know what question was asked
Selection=This is the DTMF value they pick for their answer.


Don't throw this into production, put it in a test system, or just change 1 IVR.

Test in FreePBX Distro 10.13.66-64bit

You can either modify existing IVRs, or create some net new ones.
I suggest that your recorded questions file names allow you to reflect the question being asked because the way FreePBX builds the dialplans and references each IVR a unique ID number, the voicefile name is the only thing that easily lets you see which IVR is which.

open up /etc/asterisk/extensions_additional.conf
Copy all your IVR CONTEXT entries in this file that are relative to your IVR questions, and paste them into


If you have other production IVRs, I wouldn't copy them into this file. They will still work, but any changes in the GUI will not reflect in your production sytem, as the override file will do just that, override changes made by the GUI.

So below is a 'snipped' version of the 30 or 40 lines of code you would see. If you had 5 Ivrs, you would have to copy them all.
[ivr-7] ; ivr1
include => ivr-7-custom
include => from-ivr-directory-Disabled
exten => s,1,Set(TIMEOUT_LOOPCOUNT=0)
exten => hang,1,Playback(vm-goodbye)
exten => hang,n,Hangup
;--== end of [ivr-7] ==--;

copy everything from
[ivr-X] through to ;-== end of [ivr-X] ==--;

Paste it into

Now that you have all the IVRs that belong to your survey, you can now edit them. We move them here because manual changes in their home file location would be over written by future changes in the GUI.
Now go to each IVR in the _override.conf file and look for the entries that look similar to this:
exten => 1,1(ivrsel-1),Goto(ivr-8,s,1)
exten => 2,1(ivrsel-2),Goto(ivr-8,s,1)
These are the valid selections in each IVR you've configured in FreePBX. So in the above example callers in IVRx can press 1 or 2, and will take them to the next ivr for further questions.
We are going to modify each one of these lines with the same piece of code:
system(echo "${STRFTIME(${EPOCH},,%d%m%Y-%H:%M:%S)},${CALLERID(all)},${UNIQUEID},${IVR_CONTEXT},${IVR_MSG},${EXTEN}" >> /tmp/survey.txt)
We'll insert this into the exsting code
exten => 1,1(ivrsel-1),Goto(ivr-8,s,1)
turns into this:
exten => 1,1,system(echo "${STRFTIME(${EPOCH},,%d%m%Y-%H:%M:%S)},${CALLERID(all)},${UNIQUEID},${IVR_CONTEXT},${IVR_MSG},${EXTEN}" >> /tmp/survey.txt)
exten => 1,2(ivrsel-1),Goto(ivr-8,s,1)
exten => 2,1(ivrsel-2),Goto(ivr-8,s,1)
turns into this:
exten => 2,1,system(echo "${STRFTIME(${EPOCH},,%d%m%Y-%H:%M:%S)},${CALLERID(all)},${UNIQUEID},${IVR_CONTEXT},${IVR_MSG},${EXTEN}" >> /tmp/survey.txt)
exten => 2,2(ivrsel-2),Goto(ivr-8,s,1)
You'll need to repeat this entry for each entry you have in the IVRS.
Save your changes
in the CLI type
core reload
This will load these entries into your PBX.
Make a call to the IVR and test the functionality.
Look in /tmp/surevey.txt, there should be entries like:
07092017-22:35:03,Jane Doe <8862>,1504834501.4403,ivr-7,custom/question1,1
07092017-22:35:03,Jane Doe <8862>,1504834501.4403,ivr-5,custom/question2,2
07092017-22:35:03,Jane Doe <8862>,1504834501.1207,ivr-7,custom/question1,1
07092017-22:35:03,Jane Doe <8862>,1504834501.1207,ivr-5,custom/question2,2

Thursday, September 7, 2017

AudioCodes MP-112 or MP-118 or MP-124 working with Asterisk

Some help to get an MP-112, MP-118, MP-124 working with Asterisk. 

In my experience, these devices are robust and reliable, but the GUI configuration process is very convoluted.  I'm not sure if that is on purpose or not, but I hope this helps you.  

This method DOES work and the attached devices (mostly all Polycom Analog conference room phones) have handled thousands of minutes of voice calls without issue.

I've made these work directly with CallCentric as well, the change required are noted in the configuration below.  If it will work with them, you can probably make it work with any ITSP

Tested on an AudioCodes MP-112 on Firmware 6.60A.342.003    
Tested on an AudioCodes MP-118 on Firmware 6.60A.332.002    
Tested on an AudioCodes MP-124 on Firmware 6.60A.326.005      

!! USE Internet Explorer for GUI Changes/Updates !!

In asterisk (FreePBX) create a SIP extension and save/submit changes.

Note the extension and secret, you'll need these later.  Also, I've encountered situations where the random complex password that FreePBX GUI will generate is too long for the AudioCodes devices, so you may need to reduce the character count.

At time of writing I've really only done this with SIP, I haven't done any PJsip testing yet.

Login into your AudioCodes (Admin/Admin is the default user.  Note CAP "A")
VoIP -> SIP Definitions -> Proxy & Registration
"Use Default Proxy" = Yes 
"Enable Registration" = Enable

At the top of same window, select "PROXY SET TABLE", button (little arrow)
Under "PROXY ADDRESS" put in the IP address of your Asterisk server.
To the right of that entry, set Transport Type = UDP
Enable Proxy Keep Alive = Using Options

NOTE: I've found CALLCENTRIC worked better if you select "Using Register"


VoIP -> GW and IP to IP -> Analog Gateway -> Caller ID Permission

** This is an important step in the configuration process.  The system just doesn't seem to work without doing this step! **
Set to ENABLE for each FXS port (assuming you want them to have CLID display)|


For AudioCodes gateways that are already configured, start at this spot to ADD additional phones to the system.
VoIP -> GW and IP to IP -> Analog Gateway -> Authentication
Enter in your extension(s) and the password (aka secret) into these boxes.

VoIP -> GW and IP to IP -> Hunt Group -> EndPoint Phone Number

Enter in the extension (or Callcentric Account) for PHONE NUMBER
Channels     Phone Number    Hunt Group ID    Tel Profile ID
  1. 1                   1000                     [blank]                   0
  2. 2                   1002                     [blank]                   0

Press SUBMIT(If you are watching asterisk live log, your extensions should show as registered)

VoIP ->GW and IP to IP -> DTMF and Supplementary -> DTMF and Dialing
Change MAX DIGITS In phone Num = 15 (assuming you want to be able to dial long distance.)
You should now be able to make some test calls.  *43 will get you into an echo test on Asterisk


If all works, select BURN on to save these to memory.

Wednesday, September 6, 2017

Modify OUTBOUND callerID number in asterisk

Need to modify the Outbound callerID number that is presented to callers, here's a technique.

Test in FreePBX distro 10.13.66-64bit

Call being sent out a trunk and you need to modify CLID of a certain value and prepend or postpend numbers to it.  In the scenerio below, we look for 7 digit numbers and add 555 in front of the numbers.

Copy the [macro-outbound-callerid] context from /etc/asterisk/extensions_additional.conf

and paste it into /etc/asterisk/extensions_override_freepbx.conf

Now scroll down to line 7 approximately and you'll see code similar to this:

exten => s,n(normcid),Set(USEROUTCID=${DB(AMPUSER/${AMPUSER}/outboundcid)})
exten => s,n(bypass),Set(EMERGENCY=${DB(DEVICE/${REALCALLERID}/emergency_cid)})

Insert this line between them:
exten => s,n,Gosub(CIDcheck,s,1)

Now scroll to the bottom of the code you've just pasted, and then copy paste the code below between the ============== symbols at the very bottom of the file.


exten => s,1,NoOp(&&&&Checking CLID LENGTH (<7 digits?))

;take the current CLID and save it.  This will be used to tear apart and check syntax
exten => s,n,Set(FOOclid=${CALLERID(all)})
exten => s,n,Set(FOOprepend=506)
exten => s,n,Set(FOOpostpend=)

thi cut gives us the callerID name.  The format in DB looks like "First Last" <XXXxxxx>  The result will be "First Last"
exten => s,n,set(FOOname=${CUT(FOOclid,<,1)})

;this cut gets the callerid number.  It will look like: XXXxxxx>   -missing the first "<" as that was used as delimiter.  we'll put it back later
exten => s,n,set(FOOnumber1=${CUT(FOOclid,<,2)})

;this gets rid of the trailing ">" symbol, leaving us with only XXXxxxx
exten => s,n,set(FOOnumber=${CUT(FOOnumber1,>,1)})

;if the length of the CLIDnumber is equal to whatever value you set after the = sign, then it will look something like this <zzzXXXxxxxWWW>
exten => s,n,ExecIf($[${LEN(${FOOnumber})} = 7]?Set(USEROUTCID=${FOOname}<${FOOprepend}${FOOnumber}${FOOpostpend}>))
exten => s,n,ExecIf($[${LEN(${FOOnumber})} = 7]?NoOp( CLID CHANGED FROM ${FOOclid} to ${USEROUTCID} leng ${FOOnumber1}))
exten => s,n,return


Save your changes

In the asterisk CLI type
core reload

Make a test call.  Your CLID should now be modified.

Sunday, September 3, 2017

Reset Linux Root Password

1. Boot the system and press any key after you see the "Press any key to enter the menu" message. 
2. Press "e" to edit the boot command

3. Select vmlinuz using the arrow keys and press "e" to edit the line.
4. At the end of the line press space bar and type "single" then press ENTER.

6. If vmlinuz is not selected or highlighted, select it using the arrow key. Now press "b" to boot the system and wait for the bash shell.

7. Execute the password reset command by typing "passwd" and press Enter. Now type your new password at the command prompt.

8. Type "reboot" to reboot the system.