Asterisk & Freepbx : Multiple Day Night Toggles? - asterisk

I am in a situation where I often need to change the active call flow control (which can only be one..right?).
I find that netsting call flow controls is very unhandy if you have 4 different scenarios.
So what I would like to do is to create an 4 different extensions that set the appropriate call flow as the inbound route destination.
To make an example:
I have
CALL FLOW NR 1
CALL FLOW NR 2
CALL FLOW NR 3
CALL FLOW NR 4
I would like to create:
extension *881 -> Toggles Call Flow nr 1 and sets it as destination
of the inbound route
extension *882 -> Toggles Call Flow nr 2 and sets it as destination
of the inbound route
extension *883 -> Toggles Call Flow nr 3 and sets it as destination
of the inbound route
extension *884 -> Toggles Call Flow nr 4 and sets it as destination
of the inbound route
Is something like that possible?
If so...how would you achieve it?
My system is based asterisk 11 and freepbx 2.11.
Thank you in advance for your time and effort.

You can put as many time conditions as needed.
You can use special code to turn on/off time condition(used for holidays). You can check exact code on timecondition page.
You also can create custom module which will change flow, more info see on dev.freepbx.org. As option you can hire someone do your condition module.

I figured it out
edit /etc/asterisk/extensions_custom.com and paste the following
[from-internal-custom]
include => enable-switch
[check-active-switch]
exten => s,1,NoOp("This context loops through all the switches and checks which one is ON. Than it follows its destination")
exten => s,n,GoSub(sub-get-nr-of-switches,s,1)
exten => s,n,Set(nrofs=${GOSUB_RETVAL})
exten => s,n,Set(i=0)
exten => s,n,Set(default-dest=app-daynight,${switchnr},1)
exten => s,n,Set(switchnr="NULL")
exten => s,n,While($[$[${i} < ${nrofs}] & $[${switchnr} = "NULL"]])
exten => s,n,Set(switchnr=${IF($["${DB(DAYNIGHT/C${i})}" = "NIGHT"]?${i}:"NULL")})
exten => s,n,Set(i=$[${i} + 1])
exten => s,n,EndWhile
exten => s,n,GotoIf($[${switchnr}!="NULL"]?app-daynight,${switchnr},1:${default-dest})
exten => s,n,Hangup()
[sub-get-nr-of-switches]
exten => s,1,Set(nr_of_s=0)
exten => s,n,Set(exten_state="NOT_ACQUIRED")
exten => s,n,While($[${exten_state}!=0])
exten => s,n,Set(exten_state=$[${VALID_EXTEN(app-daynight,${nr_of_s},1)}])
exten => s,n,NoOp(Exten nr ${nr_of_s} of app-daynight is ${exten_state})
exten => s,n,Set(nr_of_s=${IF($[${exten_state}=1]?$[${nr_of_s}+1]:${nr_of_s})})
exten => s,n,EndWhile
exten => s,n,NoOp(${nr_of_s} switches found)
exten => s,n,Return(${nr_of_s})
[enable-switch]
exten =>_*20X,1,NoOp("Abilita Switch selezionato e disabilita altre")
same => n,GoSub(sub-get-nr-of-switches,s,1)
same => n,Set(nrofs=${GOSUB_RETVAL})
same => n,Set(switchtoactivate=${EXTEN:3})
same => n,NoOp(Activated Switch nr ${switchtoactivate})
same => n,Set(i=0)
same => n,While($[${i}<${nrofs}])
same => n,Set(DB(DAYNIGHT/C${i})=DAY)
same => n,Set(i=$[${i}+1])
same => n,EndWhile
same => n,Set(freepbx_toggle_dest=*28${switchtoactivate})
same => n,Goto(app-daynight-toggle,${freepbx_toggle_dest},1)
same => n,Hangup
Next go to freepbx and create a custom destination -> check-active-switch,s,1 and set it as destination of the inbound route

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

Can't combine DongleStatus with different dial plans

We have 2 two major mobile carriers in our country - (1) beginning with 818927, 818937, 818929 and (2) beginning with 818917, 818919, 818987, 818989.
I have 4 usb modems (huawei) and I want 2 different lines to be used for each of those mobile carriers.
I am using DongleStatus because 2 simultaneous calls must be allowed on the same prefix (e.g. when there's two the same SIP agents are calling the same direction e.g. both of them trying to call two different numbers from 818927* range simultaneously)
Here I mention the extensions configuration which doesn't works!
But if you will remove all exten lines and only 1 of them will be remaining, then the whole DongleStatus script mentioned bellow works perfectly (it allows to use 4 lines subsequently by 4 SIP agents simultaneously)
I need your help to find a mistake in mentioned bellow configuration or your suggestion on alternate ways to achieve the same goal. I'm relatively new to asterisk, and I would appreciate not over-complicated answers.
; buklau
exten => _818927XXXXXXX,1,DongleStatus(GSM-001,Dongle0_Status)
exten => _818937XXXXXXX,1,DongleStatus(GSM-001,Dongle0_Status)
exten => _818929XXXXXXX,1,DongleStatus(GSM-001,Dongle0_Status)
exten => _818917XXXXXXX,1,DongleStatus(GSM-003,Dongle2_Status)
exten => _818919XXXXXXX,1,DongleStatus(GSM-003,Dongle2_Status)
exten => _818987XXXXXXX,1,DongleStatus(GSM-003,Dongle2_Status)
exten => _818989XXXXXXX,1,DongleStatus(GSM-003,Dongle2_Status)
same => n,DongleStatus(GSM-002,Dongle1_Status)
same => n,DongleStatus(GSM-003,Dongle2_Status)
same => n,DongleStatus(GSM-004,Dongle3_Status)
same => n,GotoIf($[${Dongle0_Status} = 2]?dongle0dial:dongle1check)
same => n(dongle0dial),Dial(Dongle/GSM-001/${EXTEN:2},60,tT)
same => n,Hangup
same => n(dongle1check),GotoIf($[${Dongle1_Status} = 2]?dongle1dial:dongle2check)
same => n(dongle1dial),Dial(Dongle/GSM-002/${EXTEN:2},60,tT)
same => n,Hangup
same => n(dongle2check),GotoIf($[${Dongle2_Status} = 2]?dongle2dial:dongle3check)
same => n(dongle2dial),Dial(Dongle/GSM-003/${EXTEN:2},60,tT)
same => n,Hangup
same => n(dongle3check),GotoIf($[${Dongle3_Status} = 2]?dongle3dial:utel)
same => n(dongle3dial),Dial(Dongle/GSM-004/${EXTEN:2},60,tT)
same => n,Hangup
This part:
exten => _818989XXXXXXX,1,DongleStatus(GSM-003,Dongle2_Status)
same => n,DongleStatus(GSM-002,Dongle1_Status)
is equal to
exten => _818989XXXXXXX,1,DongleStatus(GSM-003,Dongle2_Status)
exten => _818989XXXXXXX,2,DongleStatus(GSM-002,Dongle1_Status)
So it will not work with any other patern used above. If you need part be for all above, use something like
exten => _8189XXXXXXXXX,2,DongleStatus(GSM-002,Dongle1_Status)
Hint: You always can ask asterisk show how it understand dialplan, for that do
asterisk -rx "dialplan show number#context"

what entries need to do in .conf files for call forwarding

I'm using Asterisk 10,centos 6. and I'V done changes in conf file as below for call forwarding
"extension.conf"
exten => 0010,1,Wait(0.05)
exten => 0010,2,Queue(0010)
exten => 0010,n,Dial(SIP/0011,15)
exten => 0010,n,Dial(SIP/0012,15)
exten => 0110,1,Dial(SIP/0110)
exten => 0210,1,Dial(SIP/0210)
"queues.conf"
;----------------------QUEUE TIMING OPTIONS------------------------------------
timeout = 15
retry = 5
;timeoutpriority = app|conf
timeoutpriority = conf
[0010]
member => SIP/0010
[0011]
member => SIP/0011
[0012]
member => SIP/0012
Please suggest wheather i'm right if not then please suggest some answer based on given .conf files
No your are completly wrong here.
I think better read some book about queue and dialplan
http://www.asteriskdocs.org/en/3rd_Edition/asterisk-book-html-chunk/asterisk-ACD.html
http://www.voip-info.org/wiki/view/Asterisk+howto+dial+plan

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.

Dialplan execution order

I have the following context in my asterisk dialplan.
[start-call]
exten => _X.,1,AGI(agi://localhost:4000)
exten => _X.,n,GotoIf($["${AGISTATUS}" = "FAILURE"]?redirect)
exten => _X.,1000(redirect),Hangup(31)
exten => 900,n,Goto(start-call,${EXTEN},1)
exten => h,n,Hangup
I have an AGI app which connects the call and collects DTMF inputs, and set that number as the extension using the SET EXTENSION agi command (line 1). I set the AGISTATUS to FAILURE only when there is no DTMF input. If there is no input, I timeout, and hangup (line 3). But if 900 is entered I go back to start-call context and do some magic in the AGI application (line 4).
The problem is that, right now even if I enter 900 the call just gets hung up. And not from line 3 but the last line. So its skipping line 4 somehow. If I move the 900 extension (line 4) before the one labelled redirect (line 3), it works.
I thought asterisk increments the 'n' priority automatically, and would expect this to work in the order listed above. Am I wrong here?
n iterates automatically - it adds 1 to the previous priority. This is also why you have to initialize the incrementor with priority 1 in the first line.
When you put priority 1000 somewhere in the middle (which is totally valid) the next line with n will add 1 to this, resulting in priority 1001 - which is never hit as already explained by others.
Your dialplan can be read like below:
[start-call]
exten => _X.,1,AGI(agi://localhost:4000)
exten => _X.,2,GotoIf($["${AGISTATUS}" = "FAILURE"]?redirect)
exten => _X.,1000(redirect),Hangup(31)
exten => 900,1001,Something() ; not 3!
exten => h,1,Hangup
To fix this you must either reorder your extensions as explained by others or use the + operator for priorities:
[start-call]
exten => _X.,1,AGI(agi://localhost:4000) ; 1
exten => _X.,n,GotoIf($["${AGISTATUS}" = "FAILURE"]?redirect) ; 2
exten => _X.,n+1000(redirect),Hangup(31) ; 1002
exten => 900,n,Something() ; 3
exten => h,1,Hangup
By the way, you can also use text labels as extensions, which will make your dialplans more readable:
[start-call]
exten => _X.,1,AGI(agi://localhost:4000) ; 1
exten => _X.,n,GotoIf($["${AGISTATUS}" = "FAILURE"]?agi_failure,1) ; 2
exten => 900,n,Something() ; 3
exten => agi_failure,1,DoSomething()
exten => agi_failure,n,DoEvenMore()
exten => h,1,Hangup
Dialplan must be consecutive. Ext 1000 is never hit - hence asterisk falls through to the h exten.
Yes the dialplan must be consecutive, and once you start the "n" series you need to stick with it. I am assuming extension 900 is an example of the DTMF input -- this new extension must always start with a priority of 1. The "h" extension must also start with a priority of 1
[start-call]
exten => _X.,1,AGI(agi://localhost:4000)
exten => _X.,n,GotoIf($["${AGISTATUS}" = "FAILURE"]?redirect)
exten => _X.,n,**if input received do something here**
exten => _X.,n(redirect),Hangup(31)
exten => 900,1,Goto(start-call,${EXTEN},1)
exten => h,1,Hangup

Resources