Change incoming caller ID infn freepbx

I have been using freepbx 2.11 for a long time but now changing to freepbx 15.

I have the following setup / problem.

Incoming sip line for NL BE and DE.

whenever someone from Germany calls my German number their caller id starts typically with 0 and than a number from 1-9.
when someone from Germany calls my Dutch number the caller id starts with 00 than a number from 1-9

The problem I have is that 2 extension a mobile cellphones and the caller id of the incoming number is also transferred to the cellphone.

So when a german call comes in and caller id is 0and than number 1-9 this is transferred to my cellphone. The problem is on the cellphone I am unable to see that this is a call from germany.
In the current setup I have therefore added 0049 to the incomming number. So whenever a call comes in where the number starts with 0 next number is 1-9 the 0 is stripped and replaced by 0049.
Whenever someone from say France calls the german number being an international call the number will already contain 0033 or +33. Thin than case the number show not be changed.

Freepbx has a mobile set cid to change the incoming caller if.
In freepbx 2.11 I used this syntax:
${IF( $[ ${CALLERID(num):0:2} : "00" ] ? "+${CALLERID(num):2}" :${IF( $[ ${CALLERID(num):0:2} : "0[1-9]" ] ? "+31${CALLERID(num):1}" :"${CALLERID(num)

Don’t know anymore how I came to this but it still works fine.

I can use IF before called ID and than set called ID if it is according to the if setting.

The freepbx 15 module seems to work different. I can use " anymore.

So far after some hours of testing syntaxes I have been able to do the following 2 lines that work when used individual

${IF${CALLERID(num)}0[1-9]}+31${CALLERID(num):1}
when incoming caller is is say 0101234567 it will replace this with +31101234567

${IF${CALLERID(num)}00}+${CALLERID(num):2}
when incoming caller is is 0031101234567 it will replace this with +31101234567

Next step is I need to combine these in 1 line

${IF${CALLERID(num)}0[1-9]}+31${CALLERID(num):1} 
${IF${CALLERID(num)}00}+${CALLERID(num):2}

but above doesn’t works. anyone know how I can do this.

Please mark up your expressions as pre-formatted text (using the forum </> button).

Even your supposed working example is syntactically invalid (unmatched "'s and unmatched parentheses), but your later examples are gibberish. I can’t tell to what extent that is because they really are that way, and to what extent it is the result of the forum software garbling them.

Thanks have changed the expressions.

I have no idea if the quotes are valid or not. I can’t find any info manual on the syntax for changing the caller id.
spent 4-5 hours trying, calling a test number and see what this does to the called id. The syntax above seems to work, only problem i can only use 1 syntax at the moment and would like to use 2 or 3 if than syntaxes in 1 line.
In the old freepbx this worked, in the new one not.
I have another solution but this but this makes it more complex as i have to forward the call multiple times via set caller id.

This is missing }")) at the end, although Asterisk tends to be tolerant of missing closing parentheses.

Your updated example is missing the regular expression match operator, so I can’t see how it could work at all, except if it is simply treating the logical expression as having no operator and always being true.

Personally, I can only look at this from a pure Asterisk point of view, so I don’t know how you are putting this into FreePBX, and I don’t know whether FreePBX officially supports that usage. I’m assuming that FreePBX was turning the initial example (with missing characters re-instated) into:

exten => ????,n,Set(CALLERID(num)=${IF( $[ ${CALLERID(num):0:2} : "00" ] ? "+${CALLERID(num):2}" 
:${IF( $[ ${CALLERID(num):0:2} : "0[1-9]" ] ? "+31${CALLERID(num):1}" 
:"${CALLERID(num)}")))

If I were doing it in pure Asterisk, or as custom dialplan, in FreePBX, I’d probably do:

exten => ?????/_00.,n,Set(CALLERID(num)=+${CALLERID(num):2})
exten => ?????/_0N.,s,Set(CALLERID(num)=+31${CALLERID(num):0:2})
exten => ?????,s,Noop()

Thanks and I think you are correct it’s probably easier to do this in asterisk. There is no freepbx manual so I am just doing trial and error but seem to get stuck now.

I have no clue on asterisk did find this
```
[globals]
DE_PREFIX=9876
UK_PREFIX=1234

[from-trunk-de-custom]
exten => _00X.,1,NoOp(Callerid is just fine)
exten => _0ZX.,1,Set(CALLERID(num)=00491${CALLERID(num):1})
exten => _ZX.,1,Set(CALLERID(num)=00492${DE_PREFIX}${CALLERID(num)})
exten => _X.,n,Goto(from-trunk,${EXTEN},1)
```

I assume I can use your solution.
is there a way I can do this at incoming trunk level and change the caller id on incoming trunks.
Thanks for your help so far
just read I need to set this in: extensions_custom.conf in order for freepbx not to overwrite this.

example in that thread (not my syntax)
[custom-inbound]
exten => _XXXX.,1,Set(CALLERID(num)=00${CALLERID(num)})
exten => _XXXX.,n,Goto(from-pstn,${EXTEN},1)

What I assume they are doing there is to assume that the request URI number is structured the same way as the callerID. That looks as though it is being done on an individual trunk basis, which should be even easier, as, in your case, the trunk may be sufficient on its own. They’ve achieved that by setting the initial context to a custom one for the trunk.

I used n and s assuming that the code wasn’t inserted at the first step. They’ve used an explicit step 1, and have repeated the number explicitly, although they could have used s.

_XXXX. will work as long as the called number always has at least five digits. That’s going to depend on details of your configuration that I don’t know. Doing it like your final suggestion means that all caller IDs on the trunk in question will get manipulated in the same way. That may or may not be an over-simplification.

So far I have added a section called [custom-cid] to extensions_custom.conf

[custom-cid]
exten => _0X.,1,Set(CALLERID(num)=+31${CALLERID(num):1})
exten => _00X.,1,Set(CALLERID(num)=+${CALLERID(num):2})
exten => _X.,n,Goto(from-trunk,${EXTEN},1)

if freepbx at the trunk I added

context=custom-cid

when calling calls do not go thru anymore. I assume the last line goto(from-trunk) has to be different or delete ?

[Removed caller ID pattern on catch all.]

It would need to contain the original context.

The example you had assumed that the request URI was a phone number in the same format as the caller ID. In many cases that won’t be true. It is quite likely that it will actually be s. The full log should show what it actually is.

What you are definitely missing, though , is a catch all entry, e.g.

exten => _X.,1,Noop()

If you can’t rely on caller ID being in the same format as called request URI user part, you probably need to use the “/” syntax that I used.

If for example, your calls end up addressed to extension s, at this stage of the processing, you would want:

exten => s/_0X.,1,Set....
exten => s/_00X.1,Set...... 
exten => s,1,Noop()
exten => s,n,Goto.....

Instead of s, it is probably possible to use “_.”, in this case, although it is not generally recommended because it matches some internally generated special values, as well as genuine numbers. Those special values should not arise here.

Calls on a trunk are forwarded to a ring group.

[custom-cid]
exten => s/_0X.,1,(CALLERID(num)=+$31{CALLERID(num):1})
exten => s/_00X.1,(CALLERID(num)=+${CALLERID(num):2})
exten => s,1,Noop()
exten => s,n,Goto(from-pstn,${EXTEN},1)

Call don’t come thru using this.

When using this:
exten => _XXXX.,1,Set(CALLERID(num)=00${CALLERID(num)})
exten => _XXXX.,n,Goto(from-pstn,${EXTEN},1)

calls come thru but when replacing XXXX with say 0XXX doesn’t work anymore.
I can use numbers for some reason 0 1 2 3 only X and Z

I would need to see the full log, preferably before the changes, to be certain I understood what was needed to correctly match the calls.

Found a script that seems to work in my setup

exten => _.,1,GotoIf($["${CALLERID(num):0:2}"!="00"]?5)
exten => _.,2,Log(notice,Inbound DID - ${CALLERID(num)}, Its international format change from 00 to +)
exten => _.,3,Set(CALLERID(all)="" <+${CALLERID(num):2}>)
exten => _.,4,Goto(17)
exten => _.,5,GotoIf($["${CALLERID(num):0:1}"!="0"]?9)
exten => _.,6,Log(notice,Inbound DID - ${CALLERID(num)}, Its local format starting with 0 than number from 1-9 change to internalformat +countrycode and strip the first 0 place this after the 00 line that caputures any number starting with 00)
exten => _.,7,Set(CALLERID(all)="" <+31${CALLERID(num):1}>)
exten => _.,8,Goto(17)
exten => _.,9,GotoIf($["${CALLERID(name):0:9}"="anonymous"]?11)
exten => _.,10,GotoIf($["${CALLERID(name):0:9}"!="Anonymous"]?13)
exten => _.,11,Set(CALLERID(all)="" <WITHHELD>)
exten => _.,12,Goto(17)
exten => _.,13,GotoIf($["${CALLERID(num):0:1}"!="1"]?16)
exten => _.,14,Set(CALLERID(all)="" <+31${CALLERID(num)}>)
exten => _.,15,Goto(17)
exten => _.,16,Set(CALLERID(all)="" <+${CALLERID(num)}>)
exten => _.,17,Log(notice,Inbound DID - Caller ID from ${CALLERID(num)} to ${CALLERID(DNID)})
exten => _.,18,Goto(from-pstn,${EXTEN},1)
1 Like

You didn’t mention Anonymous in your original requirement. That can’t be handled by the called/caller syntax, whereas most of the rest could be. You also didn’t mention removing the caller ID name. It could still be made a lot more compact using it where it is possible.

However, I would suggest that using symbolic labels would make this easier to maintain. And using same => would also help.

exten => _.,1,GotoIf($["${CALLERID(num):0:2}"!="00"]?not00)
same => n,Log(notice,Inbound DID - ${CALLERID(num)}, Its international format change from 00 to +)
same => n,Set(CALLERID(all)="" <+${CALLERID(num):2}>)
same => n,Goto(done)
same => n(not00),GotoIf($["${CALLERID(num):0:1}"!="0"]?not0)
same => n,Log(notice,Inbound DID - ${CALLERID(num)}, Its local format starting with 0 than number from 1-9 change to internalformat +countrycode and strip the first 0 place this after the 00 line that caputures any number starting with 00)
same => n,Set(CALLERID(all)="" <+31${CALLERID(num):1}>)
same => n,Goto(done)
same => n(not0),GotoIf($["${CALLERID(name):0:9}"="anonymous"]?anon)
same => n,GotoIf($["${CALLERID(name):0:9}"!="Anonymous"]?notanon)
same => n(anon),Set(CALLERID(all)="" <WITHHELD>)
same => n,Goto(done)
same => n(notanon),GotoIf($["${CALLERID(num):0:1}"!="1"]?not1)
same => n,Set(CALLERID(all)="" <+31${CALLERID(num)}>)
same => n,Goto(done)
same => n(not1),Set(CALLERID(all)="" <+${CALLERID(num)}>)
same => n(done),Log(notice,Inbound DID - Caller ID from ${CALLERID(num)} to ${CALLERID(DNID)})
same => n,Goto(from-pstn,${EXTEN},1)

At the expense of losing the log lines,you could also use ExecIf to simplify it, and get rid of most of the labels.

(In practice, people would probably add Noop calls to carry the labels.)

2 Likes

David, thanks again, found the original script here: https://www.irishvoip.com/index.php/knowledgebase/104/AsteriskorFreePBX-Settings-for-DIDs.html

Modified it a bit for my use but will try your version later today or this week when I have more time.

See that in your version I can add more lines as it doesn’t use the goto number but just goto done.
logo line I can drop.

Anonymous was in this version and I just used it but doesn’t really need to change the name just to pass which it seems to do.

David, tried your syntax and this also works fine. Tried calling using sever caller id’s.

now calls are also forwarded to my cellphone using the correct incoming caller id of the person calling.
whenever a german number calls my german number =49 is now added to the local number and first 0 is striped. Same for my Dutch and Belgium did numbers.

I can now start to move from old freepbx to incrediblepbx using freepbx 15 and asterisk 18.
Can copy modify the script to other did numbers.

Thanks again for the great help.
Bob

Unless you have a strong reason (please explain), use the FreePBX Distro instead. This is easier to install, has much better community support and gives you the options of installing commercial modules and purchasing Sangoma support.

1 Like

old freepbx was also based on the previous image of nerdvittles (2014) as it had build in firewall that worked very will, option for portknocker to access when at different location.
Before that I had elastix hacked 2 times so I wanted a secure option and their image has worked for more than 7 years. My vps provider is changing platforms otherwise I might have still used it for some years as it just worked and was save from hacking because of all ip blocks

The incrediblepbx image is also based on freepbx but for me their firewall and way it is setup is more secure as I am running it on a vps in the open.
Basically no ip has access and I can add my own ip or dyndns ip for locations that could have changing ip. For me this is very simple to use and configure.
This might all be possible using the freepbx firewall but will require some time and work and more knowledge.
The pbx is not for a huge company so I don’t need extra commercial modules and current solution is out of the box easy and works for my setup.

( and of course there is no weeks long angst about sysadmin/fail2ban(Intrusion Detection) just plain not working :wink: )

Take a look at
https://wiki.freepbx.org/display/FPG/Firewall
It’s somewhat old; also see
https://wiki.freepbx.org/display/FPG/New+features+for+>14.0.3.x+and+>+15.0.8.x
The Responsive Firewall will do what you want. Whitelisting a dynamic DNS address is also available.
Portknocker is IMO a kludge, because it is not supported by any IP phone, softphone or mobile app – you need to install an add-on that is a possible point of failure.

This actually presumes the firewall is actually starting and you are deployed on an AMD64 cpu using the SNG7 OS, apparently many folks still have a problem with that requirement. . . .

My original question has been solved, thanks to david55.

Stewart I have answered your question and reason of my choice. For me this works out of the box.
Server has been installed and should do the job the next 5 years.
I did not look at freepbx as I did not know it has improved and don’t want to spent time configuring things I have no knowledge on.
That said the current solution works for me and I feel the discussion seems to go in a direction where I should have chosen differently or freepbx can do the same.

In the end it’s up to anyone to choose the solution they want as long as it works for them and they are happy using this solution.