Freepbx (for|while)loop to read lines and add to dialplan

hi i have freepbx 12

i want a custom dial plan that will read Caller IDs from external file in /root/cid.txt
now i have the dial plan works fine when the CIDs i put them my self in the custom file .as below :

[ahmad]
exten => s,1,NoOp(Context : ${CONTEXT} : “Heyyyyy you are in custom”)
exten => s,n,GotoIf($["${CALLERID(num)}" = “2832930”]?next:end)
exten => s,n,GotoIf($["${CALLERID(num)}" = “2832940”]?next:end)
exten => s,n,GotoIf($["${CALLERID(num)}" = “2832950”]?next:end)
exten => s,n,GotoIf($["${CALLERID(num)}" = “2832960”]?next:end)
exten => s,n(next),goto(from-internal,30,1)
exten => s,n(end),system(echo “${DATETIME} - ${CALLERID} - ${CHANNEL}” >> /var/log/asterisk/calls)

as we see i put the CID myself —> 2832930" ,2832940 2832940 2832950 28329360.

so what i need is i want to create a file /root/cid.txt that will be updated dynamically from outside .

and i want to have a for loop or while loop in asterisk that will sweep all the lines line by line and create the rules automatically .

so if there was 1 line in the file /var/log/asterisk/calls with 1 CID like 123456

my dial plan should be equivalent to below :

[ahmad]
exten => s,1,NoOp(Context : ${CONTEXT} : “Heyyyyy you are in custom”)
exten => s,n,GotoIf($["${CALLERID(num)}" = “123456”]?next:end)
exten => s,n(next),goto(from-internal,30,1)
exten => s,n(end),system(echo “${DATETIME} - ${CALLERID} - ${CHANNEL}” >> /var/log/asterisk/calls)

if i had 2 CID ( 2 lines in the file/var/log/asterisk/calls) —> , 123456 & 123455 , then it should be equivalent to

[ahmad]
exten => s,1,NoOp(Context : ${CONTEXT} : “Heyyyyy you are in custom”)
exten => s,n,GotoIf($["${CALLERID(num)}" = “123456”]?next:end)
exten => s,n,GotoIf($["${CALLERID(num)}" = “123455”]?next:end)
exten => s,n(next),goto(from-internal,30,1)
exten => s,n(end),system(echo “${DATETIME} - ${CALLERID} - ${CHANNEL}” >> /var/log/asterisk/calls)

so again
all i need is just replace adding the CID rules with 1 single rule that will automatically sweep the external file lines.

thank you

I have to be honest there are simple ways but I am hesitant to be helpful because this sounds like it is for a robodialer or some sort of shady telemarketing thing which I am not a fan of.

hi

i need it because there is no way in freepbx to add inbound rules for 1000 CID as 1 operation .
as you see in gui , i can only match 1 CID for each incoming rule

say i want to add 1000 rules based on CID
its gonna be madness to me .

thats why I’m asking to do this
im wiling to do a context that sweep the CID in external file instead of creating 1000 inbound rule in the freepbx GUI

does that make sense ?

can you help ?

cheers

This doesn’t sound so much like a robo-dialer - it sounds like implementing a blacklist without using the blacklist module. If that’s the case, just use the method the blacklist module does - load the numbers into your AST-DB and walk through the database using a while loop. This way, you avoid hammering the crap out of your system on every incoming call.

yes I’m willing to do that
can you just guide me with any hints with asterisk cli commands that would help me to sweep a db that has like 1000 rows of CID ??

cheers

Rather than post a bunch of code that you’ll have to figure out, search for “asterisk database functions”. There are lots of good articles that talk about setting up the database and getting data from it into variables.

Once you’ve got that, your code above is a couple of lines short of doing what you want.

Hint: set up the variable, do the “GotoIf()” and “Goto()” loop, and you should be golden.

For extra credit, sort the caller IDs and use a comparison to see when you’ve gone past where your number should be.

The way I read it he is randomly setting outbound caller id from a list.

@jfinstrom yeah, I could see that. I read it the other way.

One of us is probably right :smile:

If it is inbound I push people to use the superfecta framework. If it is outbound you better make a good case as to not being a telemarketer

1 Like