my execif variable ignored in Asterisk dialplan - asterisk

For Extension 4111 I want to rewrite the caller id, if is 4111 must become 4442
I put this in dialplan reload and..is ignored.
Why?
exten => 4111,1,ExecIf($["${CALLERID(num)}" = "4111"]?Set(${CALLERID(num)=4442))
exten => 4111,n(dial),Dial(DAHDI/g7/${EXTEN},10)
exten => 4111,n,Hangup()

Solution found, must be posted in the "called" number, not in caller number.
The correct syntax is
exten => 4112,1,ExecIf($["${CALLERID(num)}" = "4111"]?set(CALLERID(all)=My company<1234489>))

Related

Asterisk block incoming call from specific country only

I am trying to make a dial plan to block incoming call coming from let say bangladesh where country code is 88
Here is my dial plan
exten => _X.,1,NoOp(${CALLERID(num)})
same => n,Set(regx=^(88)[0-9]$)
same => n,GotoIf($[${REGEX("${regx}" ${CALLERID(num)})} = 1]?blacklisted,s,1)
same => n,Dial(SIP/8.8.8.8/${EXTEN}
[blacklisted]
exten => s,1,Wait(9)
what i want to do is anything that comes from 88 should be sent to blacklist. At the moment if I test call with Caller ID 88 it works but if the call comes from 88XXXXXXX this does not work what can I do to make my dial plan block anything coming from 88XXXXXXXX to goto black list
Why do you use the complex REGEX function? Just do something like that:
exten => _X.,1,NoOp(CallerID is: ${CALLERID(num)})
exten => _X.,n,Set(number=${CALLERID(num)})
exten => _X.,n,ExecIf($[${number:2} = 88],Hangup())
exten => _X.,n,NoOp(Call is being continued)
This will save the callerid num into the "number" variable. Then it will check if the first 2 characters of the variable are equal to 88. If so, the call will be hung up. You can also use GoToIf instead of ExecIf if you want to send the blacklisted call to a specific context where you want to do something else with it.
Asterisk dialplan is regexp itself. Why you use other regexp?
exten => _X.,1,NoOp(${CALLERID(num)})
same => n,Gosub(cid-blacklist,${CALLERID(num)},1)
same => n,Dial(SIP/8.8.8.8/${EXTEN}
[cid_blacklist]
exten => _88.,1,Noop(bangladesh)
same => n,Wait(100)
; this works only when not found match in context.
include=> cid_blacklist_not_found
[cid_blacklist_not_found]
exten => _X.,1,Return;not found in cid blacklist

How to get caller id variable?

I am receiving call in one trunk and forwarding that call by second trunk with following
[from-trunk1]
exten => _X.,1,Dial(SIP/trunk2/12345678)
Now I'd like to add IF condition. If callerid of a user calling to trunk1 is 112233, then I'd like to forward it to 445566 from trunk2.
You can just specify the caller ID as part of the extension pattern.
exten => _X./112233,1,Dial(SIP/trunk2/445566)
The CID pattern can accept all the same special characters as the destination pattern if you prefix it with _.
If anyone interested
[from-trunk1]
; if caller is 112233 go 50
exten => _X.,1,NoOp(${CALLERID(num)})
exten => _X.,n,GotoIf($["${CALLERID(num)}" = "112233"]?50)
; if not code below
exten => _X.,n,Playback(tt-monkeys)
; if condition where true, start from 50
exten => _X.,50,Dial(SIP/trunk2/445566)
Please suggest, if you have better code.

Asterisk "monitor" command records calls but throws away recorded files on premature hangup

I am using the "monitor" command to record full calls. This works well, but only when the user goes through the entire callflow. I tried monitoring the recorded file size as the call progresses. Once the call starts, the file sizes start increasing (of both the "in" and "out" sides of the call). However, if the user hangs up prematurely in the middle of the call, whatever has been recorded thus far is inexplicably dropped and stubs (44 bytes) are left in its place. Any insight into why this behavior occurs will be appreciated.
I am reproducing a snippet from the dialplan I used in my extensions.conf file below:
exten => 7611,1,Answer()
exten => 7611,n,Playback(/var/lib/asterisk/sounds/custom/transferring_with_record_wa rning)
exten => 7611,n,Set(GROUP()=outgoing)
exten => 7611,n,NoOp(The current group count : ${GROUP_COUNT(outgoing)})
exten => 7611,n,GotoIf($[${GROUP_COUNT(outgoing)}>1]?15)
exten => 7611,n,Set(GLOBAL(current_timestamp_7611)=${STRFTIME(${EPOCH},GMT+1,%s)})
exten => 7611,n,Set(GLOBAL(current_full_format_timestamp_7611)=${STRFTIME(${EPOCH},G MT-8,%d%m%Y_%H%M%S)})
exten => 7611,n,NoOp(The current timestamp : ${current_timestamp_7611})
exten => 7611,n,NoOp(The last timestamp : ${last_timestamp_7611})
exten => 7611,n,GotoIf($[(${last_timestamp_7611}+20>${current_timestamp_7611})]?15)
exten => 7611,n,NoOp(All cases passed)
exten => 7611,n,Ringing()
exten => 7611,n,Wait(2)
exten => 7611,n,Monitor(wav,HALEF_audio_ext_7611_${current_full_format_timestamp_761 1})
exten => 7611,n,Dial(SIP/1200#JVXML97,,XgF(default^7611^14))
exten => 7611,n,Set(GLOBAL(last_timestamp_7611)=${STRFTIME(${EPOCH},GMT+1,%s)})
exten => 7611,n,Hangup()
exten => 7611,n,Ringing()
exten => 7611,n,Wait(2)
exten => 7611,n,Playback(/var/lib/asterisk/sounds/custom/busy_later)
exten => 7611,n,Wait(1)
exten => 7611,n,Hangup()
I understand that the "record" command has a "k" parameter which keeps the recorded file upon hangup, but I'm not able to find any similar functionality with the Monitor command. (I'd use "record", but I'd like to record the full call (duplex) and do it automatically, without any user input requirement).
Thanks!
Use MixMonitor command.
Check you have permissions needed for write files.
Check debug if you unsure.
PS. using diaplan WITH n, without labels and goto to EXACT priority is very bad practice, can result hard-catchable bugs. Using GLOBAL variables without need also not so nice idea.

Waiting for extra digit when it's clear that there's no other matching rule

I'm a beginner on Asterisk, but already have my PBX working connected to the PSTN. The issue I'm having is that I have this rule
exten => _*X.*,1,Log(DEBUG, Calling through provider one to ${EXTEN:1:-1})
same => n,Dial(SIP/${EXTEN:1:-1}#oneProvider,60)
There are no other extensions that start with *. What I want to achieve is to dial out as soon as the second * is pressed (and there's nothing the user can press to go to a valid extension), right now it waits a few seconds and dial. I also tried adding ! at the end of the extension, but nothing changed.
Am I missing something? Is this feasible?
Thanks!
This task is not doable in current asterisk.
It will not work beacuase * matched .(dot) in your dialplan.
Except dialplan like this(very ugly one beacuase it will go dialplan for every new digit)
[originalcontext]
exten => *,1,Goto(collect_number,s,1)
[collect_number]
exten => s,1,WaitExten(); wait for single digit
exten => *,1,Set(stars=${stars}*);save stars
exten => *,2,GotoIF($[ "${stars}" == "**" ]?dial,1); if 2 star already,go dial.
exten =>_X,1,Set(digits=${digits}${EXTEN});save digits
exten => _.,3,WaitExten(); wait enother input;
exten => _.,4,Goto(dial,1); go dial if no new digits
exten => dial,1,Dial(SIP/${digits}#oneProvider,60)
Correct solution - use Read application and ask user use # to end number instead of *.
You also can try dialplan like this:
exten => _*X*!,1,Goto(dial,${EXTEN:1:-1},1)
exten => _*XXX*!,1,Goto(dial,${EXTEN:1:-1},1)
exten => _*XXXX*!,1,Goto(dial,${EXTEN:1:-1},1)
exten => _*XXXXX*!,1,Goto(dial,${EXTEN:1:-1},1)
exten => _*XXXXXX*!,1,Goto(dial,${EXTEN:1:-1},1)
exten => _*XXXXXXX*!,1,Goto(dial,${EXTEN:1:-1},1)
exten => _*XXXXXXXX*!,1,Goto(dial,${EXTEN:1:-1},1); continue upto max number length
[dial]
exten =>_.,1,Dial(SIP/${EXTEN}#oneProvider,,);
But i not fully sure that will work. If works, will be less load(but more lines)

How to work with BlackList?

I am new to asterisk. i am working under ubuntu 9.10. I use asterisk 1.8. I want to create a conference room.
in meetme.conf
conf => 1234,1234
in extensions.conf
exten =>1234,1,MeetMe(1234)
Is the pin number a secure one? How to create a secure pin number (do i have to use numbers and characters too)? Secondly how to create a blacklist? If a person tries to register 3 times..and the passed is incorrect how can I put him/her on the blacklist?
Passwords are numbers, however, '1234' is not a good password choice.
Asterisk's dialplan is extremely dynamic; there is no single definition of 'Blacklist'. However, try something like this:
== meetme.conf
conf => 1234
== extensions.conf
exten => 1234,1,GotoIf(${BLACKLIST()}?hangup)
exten => 1234,n(loop),Set(TRIES=$[0${TRIES} + 1]);
exten => 1234,n,GotoIf($["$TRIES" = "3"]?blacklist)
exten => 1234,n,Read(PIN,enter-conf-pin-number,4)
exten => 1234,n,GotoIf($["$PIN" = "9999"]?meetme)
exten => 1234,n,Goto(loop)
exten => 1234,n(meetme),MeetMe(1234)
exten => 1234,n,Hangup
exten => 1234,n(blacklist),Set(CALLERID(num)=${FILTER(0-9\-,${CALLERID(num):-10})})
exten => 1234,n,Set(DB(blacklist/${CALLERID(num)})="Some Comment")
exten => 1234,n(hangup),Hangup
there are all sorts of other ways. this particular setup will only keep the caller from trying to authenticate into that one conference room. if you'd rather ban him from ever touching your automated attendant, you can move the first line to your incoming context.
If you're already sanitizing your callerid (you should be) you can remove the FILTER line and bump the (blacklist) to the next line.

Resources