2

I am setting up an Asterisk VoIP server (using FreePBX) and I need to identify all numbers that end with a particular pattern.

This is required for routing purposes, that is, to find out whether they come from an outbound trunk or an internal phone.

For example, local number 777777 may appear as 777777, 01222777777, 441222777777, 00441222777777, or +441222777777.

A few searches didn't help me to figure it out. How can it be done?

peterh
  • 4,953
  • 13
  • 30
  • 44
  • 3
    Unfortunately, this is probably a question better asked of [FreePBX](http://community.freepbx.org/) than us. Sorry! – Katherine Villyard Apr 19 '15 at 21:23
  • 1
    Interesting. There is no where on the web that really brings together the various aspects of pbx configuration - which would be extremely useful to those who do it, it seems to me. When I proposed in area51 that this would be a good addition to the SE collection, I was told that all such questions would find a place here. What gives? – Neil Townsend Apr 20 '15 at 06:34
  • 1
    ps. Also a little surprised given that both 'freepbx' and 'asterisk' are recognised tags here. – Neil Townsend Apr 20 '15 at 06:35

1 Answers1

2

If you work with FreePBX you will most likely need to go under the hood and add a context like below to /etc/asterisk/extensions_custom.conf

[check-ending]
exten => _!,1,GotoIf($[${EXTEN:-6} = 777777]?gotcha)
exten => _!,n,Goto(inbound)
exten => _!,n,Hangup()
exten => _!,n(gotcha),Goto(inbound-from-777777)
exten => _!,n,Hangup()
exten => h,1,Hangup()

Now, if there are 6 sevens in the end, the call will go to gotcha label and will be redirected to inbound-from-777777, otherwise it will go further through the dial plan and will be redirected to inbound.

Then run asterisk -x "dialplan reload" to load the new config into asterisk. Afterwards in UI you will have to set check-ending context as a call receiver for the trunk (as you usually do).

  • Irritatingly, FreePbx doesn't allow the "_!" in the fields, so I can't test it. – Neil Townsend Apr 23 '15 at 09:18
  • @NeilTownsend that's why I don't like all those add-ins like freepbx. See how I updated the answer. – Misha Slyusarev Apr 23 '15 at 14:04
  • @NeilTownsend does it help? If yes please accept the answer. If no, let me know and we can find out what is wrong. – Misha Slyusarev Apr 24 '15 at 19:34
  • ~Sorry I'm not responding very quickly - I only do about an hour or so on this project every 2-3 days. I'm trying it out now. – Neil Townsend Apr 25 '15 at 10:25
  • SAdly, it doesn't work. After many 'nearly but not quite' attempts and variations on the theme, I found the following, "Asterisk treats a period or exclamation mark as the end of a pattern." here: https://wiki.asterisk.org/wiki/display/AST/Pattern+Matching - this means that the pattern you propose effectively matches everything! – Neil Townsend Apr 25 '15 at 11:57
  • @NeilTownsend Yes, you're right. Sorry for this. I think there is a way around this. I will rewrite the answer. – Misha Slyusarev Apr 27 '15 at 16:30