TRY THIS SIP URI Calling

kdthomas

Member
Joined
May 13, 2016
Messages
57
Reaction score
11
So I'm running latest Incredible PBX and I could have sworn I was able to do this in the past in previous versions of PBXIAF/Incredible. I'm trying to call SIP addresses like
[email protected] or [email protected]. I use X-Lite as my softphone, but I'm getting failures on any SIP address I try calling. I've tried adding "sip:" but the same result. I don't care about recieving SIP URI calls, just to be able to call them. Is this possible?
 

wardmundy

Nerd Uno
Joined
Oct 12, 2007
Messages
19,198
Reaction score
5,218
@kdthomas: It's possible, but it's a two-step process. With FreePBX, you have to have a matching outbound route, or it has to be an internal call. So you have to set up custom extensions either in the GUI or you can add lines to extensions_custom.conf in the [from-internal-custom] context like this:
Code:
exten => 1415,1,Dial(SIP/[email protected])

Then you dial the internal extension number (1415) from your softphone.
 
Last edited:

wardmundy

Nerd Uno
Joined
Oct 12, 2007
Messages
19,198
Reaction score
5,218
@kdthomas: Here's a workaround that we developed based upon these tips. Just add this code to the end of extensions_custom.conf and reload Asterisk dialplan.

NOTE: Don't use the SIP: prefix with any SIP URI call. For SIP URIs starting with a letter of the alphabet, you can dial them as is without the SIP: prefix. For SIP URIs starting with a number, prefix them with an asterisk (*) and don't use the SIP: prefix. All regular calls (all numbers) will be processed using usual dialplan rules and outbound routes.

UPDATE: This design has been superseded by the approach documented in the new Nerd Vittles article.

For example, if you dial [email protected], only the numeric portion of the SIP URI will be used, and it will be processed using your standard outbound routes. If you dial *[email protected], the * will be stripped off and the remaining dial string will be processed as a SIP URI outbound call. [email protected] will be processed as a SIP URI call, and 18005551212 will be processed using your existing outbound routing rules.

Code:
[ext-local-custom]
exten => _[a-z].,1,Macro(uridial,${EXTEN}@${SIPDOMAIN})
exten => _[A-Z].,1,Macro(uridial,${EXTEN}@${SIPDOMAIN})
exten => _*X.,1,Macro(uridial,${EXTEN:1}@${SIPDOMAIN})

[macro-uridial];; Cut out the “;user=phone….” bits at the end of SIP URI that some clients add
;; requires SRVLOOKUP=yes setting in your SIP configuration which is Incredible PBX default
exten => s,1,Set(dialuri=${CUT(ARG1,\;,1)})
;; corrrect outgoing caller ID from DB name:
exten => s,n,ExecIf($["${DB(${CALLERID(number)}/user_sipname)}" != ""],Set,CALLERID(number)=${DB(${CALLERID(number)}/user_sipname)})
exten => s,n,NoOp(Calling SIP URI ${dialuri})
exten => s,n,NoOp(— From: ${CALLERID(all)} —)
exten => s,n,Dial(SIP/${dialuri},120,tr)
exten => s,n,Congestion()
exten => s,n,Return

You can set the outbound CallerID for your SIP URI calls from an extension (701 in example) like this using the Asterisk CLI:
Code:
database put 701 user_sipname "Nerd Uno"
 
Last edited:

wardmundy

Nerd Uno
Joined
Oct 12, 2007
Messages
19,198
Reaction score
5,218
New version coming Monday to Nerd Vittles. No dial prefix required for SIP URI calling any longer.
 

chris_c_

Active Member
Joined
Aug 19, 2010
Messages
509
Reaction score
67
Pretty soon, everyone will have a thing that looks like an email address ("SIP address"?) as their SIP direct "number".
SIP address could even be exactly the same as your email address.
[email protected] to call him on his cisco voip desk phone or smartphone sip app.
[email protected] to ring him on his google duo app or google hangouts app - google would need to build this bridge from sip into their services, maybe they will maybe they won't.
 

wardmundy

Nerd Uno
Joined
Oct 12, 2007
Messages
19,198
Reaction score
5,218
Pretty soon, everyone will have a thing that looks like an email address ("SIP address"?) as their SIP direct "number".
SIP address could even be exactly the same as your email address.
[email protected] to call him on his cisco voip desk phone or smartphone sip app.
[email protected] to ring him on his google duo app or google hangouts app - google would need to build this bridge from sip into their services, maybe they will maybe they won't.

If Google doesn't, somebody else will. :santa:
 

wardmundy

Nerd Uno
Joined
Oct 12, 2007
Messages
19,198
Reaction score
5,218
SECURITY ALERT: Never use the SIP URI MOD on a server with a publicly-exposed SIP port as it is possible for some nefarious individual to spoof your FQDN in the headers of a SIP packet and easily gain outbound calling access using your server’s trunk credentials.
 

billsimon

Well-Known Member
Joined
Jan 2, 2011
Messages
1,540
Reaction score
729
SECURITY ALERT: Never use the SIP URI MOD on a server with a publicly-exposed SIP port as it is possible for some nefarious individual to spoof your FQDN in the headers of a SIP packet and easily gain outbound calling access using your server’s trunk credentials.

Yeah, don't put that dialplan in the ext-local-custom context. Put it in a context that is only exposed to authenticated users (from-internal or one of its includes).
 

rjbrown99

New Member
Joined
Jul 2, 2021
Messages
3
Reaction score
0
Sorry to revive a dead thread, but it's on topic.

Ward's dialplan from the NerdVittles link isn't working for me. I pasted a portion of it below, with the part in bold as my area of focus when debugging.

When entering the flow below, SIPDOMAIN starts its life at the very top of this process by being set to the URI that was submitted, let's say for the URI [email protected] the SIPDOMAIN is set to sip5060.net.

Then when it hits those 3 lines, SIPDOMAIN is reset to $DB(MyDomain/FQDN). But MyDomain is ALSO set to $DB(MyDomain/FQDN), the very same value. The next line states that if MyDomain = SIPDOMAIN we should continue to OutAllRoutes. That will be true in 100% of the cases because we just set those two variables to be the same thing.

The net result of the logic below is no matter what URI I submit, I never hit the macro uridial. My question to Ward and the thread is this: should we just remove that second set where we make SIPDOMAIN = MyDomain/FQDN? Or am I missing something here? Thanks :)

; AT THIS POINT, SIPDOMAIN = sip5060.net, as entered from my softphone
;# // BEGIN SIP URI Mod1
; Portions of the following code are Copyright (c) 2019, Ward Mundy & Associates LLC
; Licensed for use pursuant to GPL2: https://www.gnu.org/licenses/old-licenses/gpl-2.0.en.html
exten => _.,1,Set(MyDomain=${CUT(SIPCALLID,@,2)})
exten => _.,n,NoOp(SIPDOMAIN: ${SIPDOMAIN})
exten => _.,n,GotoIf($["foo${MyDomain}" != "foo"]?FoundDomain)
exten => _.,n,Set(MyDomain=${DB(MyDomain/FQDN)})
exten => _.,n,Set(SIPDOMAIN=${DB(MyDomain/FQDN)})
exten => _.,n(FoundDomain),GotoIf($["${MyDomain}" = "${SIPDOMAIN}"]?OutAllRoutes)

exten => _.,n,Macro(uridial,${EXTEN}@${SIPDOMAIN})
exten => _.,n(OutAllRoutes),Set(DSTRING=${LEN(${EXTEN})})
exten => _.,n,ExecIf($[${DSTRING} > 5]?Goto(outbound-allroutes,${EXTEN},1)
exten => _.,n,ExecIf($["${EXTEN}" = "911"]?Goto(outbound-allroutes,${EXTEN},1)
exten => _.,n,ExecIf($["${EXTEN}" = "933"]?Goto(outbound-allroutes,${EXTEN},1)
exten => _.,n,Dial(local/${EXTEN}@from-internal-additional)
;# // END SIP URI Mod1
 

rjbrown99

New Member
Joined
Jul 2, 2021
Messages
3
Reaction score
0
Update, here's what works for me with Asterisk 17 / FreePBX 15 and PJSIP. I removed that second Set command and it allowed the process to proceed. I also had to adjust the Dial string to use PJSIP. The one part highlighted below is the hardcoded name of my trunk, which I can't figure out how to obtain via variable. If any of you have input there I'm open to it.

I'm also seeing a warning "Macro() is deprecated and will be removed from a future version of Asterisk", with a suggestion to rewrite with Gosub instead. I have not yet tackled that piece.

Oh, and that sip5060.net URI I was using to test with originally is not working. The nerdvittles URI however is working, so if you are testing this in 2021 try [email protected] for test calls.

;# // BEGIN SIP URI Mod1
; Portions of the following code are Copyright (c) 2019, Ward Mundy & Associates LLC
; Licensed for use pursuant to GPL2: https://www.gnu.org/licenses/old-licenses/gpl-2.0.en.html
[enable-sipuri-dialing]
exten => _.,1,Set(MyDomain=${CUT(SIPCALLID,@,2)})
exten => _.,n,NoOp(SIPDOMAIN: ${SIPDOMAIN})
exten => _.,n,GotoIf($["foo${MyDomain}" != "foo"]?FoundDomain)
exten => _.,n,Set(MyDomain=${DB(MyDomain/FQDN)})
exten => _.,n(FoundDomain),GotoIf($["${MyDomain}" = "${SIPDOMAIN}"]?OutAllRoutes)
exten => _.,n,Macro(uridial,${EXTEN}@${SIPDOMAIN})
exten => _.,n(OutAllRoutes),Set(DSTRING=${LEN(${EXTEN})})
exten => _.,n,ExecIf($[${DSTRING} > 5]?Goto(outbound-allroutes,${EXTEN},1)
exten => _.,n,ExecIf($["${EXTEN}" = "911"]?Goto(outbound-allroutes,${EXTEN},1)
exten => _.,n,ExecIf($["${EXTEN}" = "933"]?Goto(outbound-allroutes,${EXTEN},1)
exten => _.,n,Dial(local/${EXTEN}@from-internal-additional)
;# // END SIP URI Mod1

;# // BEGIN SIP URI Mod2
; Portions of the following code are Copyright (c) 2019, Ward Mundy & Associates LLC
; Licensed for use pursuant to GPL2: https://www.gnu.org/licenses/old-licenses/gpl-2.0.en.html
[macro-uridial]
exten => s,1,Set(dialuri=${CUT(ARG1,\;,1)})
exten => s,n,NoOp(DIALURI: ${dialuri})
exten => s,n,Set(CALLERID(number)=${DB(${CALLERID(number)}/user_sipname)})
exten => s,n,ExecIf($["${CALLERID(number)}" = ""]?Set(CALLERID(number)=Anonymous))
exten => s,n,NoOp(Called SIP URI: ${dialuri})
exten => s,n,NoOp(Calling From : ${CALLERID(all)} ?^?^?)
exten => s,n,Dial(PJSIP/VoipMS_SIP/sip:${dialuri},60,tr)
exten => s,n,Congestion()
exten => s,n,Return
;# // END SIP URI Mod2
 
Last edited:

wardmundy

Nerd Uno
Joined
Oct 12, 2007
Messages
19,198
Reaction score
5,218
The net result of the logic below is no matter what URI I submit, I never hit the macro uridial. My question to Ward and the thread is this: should we just remove that second set where we make SIPDOMAIN = MyDomain/FQDN? Or am I missing something here? Thanks :)

; AT THIS POINT, SIPDOMAIN = sip5060.net, as entered from my softphone
;# // BEGIN SIP URI Mod1
; Portions of the following code are Copyright (c) 2019, Ward Mundy & Associates LLC
; Licensed for use pursuant to GPL2: https://www.gnu.org/licenses/old-licenses/gpl-2.0.en.html
exten => _.,1,Set(MyDomain=${CUT(SIPCALLID,@,2)})
exten => _.,n,NoOp(SIPDOMAIN: ${SIPDOMAIN})
exten => _.,n,GotoIf($["foo${MyDomain}" != "foo"]?FoundDomain)

exten => _.,n,Set(MyDomain=${DB(MyDomain/FQDN)})
exten => _.,n,Set(SIPDOMAIN=${DB(MyDomain/FQDN)})
exten => _.,n(FoundDomain),GotoIf($["${MyDomain}" = "${SIPDOMAIN}"]?OutAllRoutes)
exten => _.,n,Macro(uridial,${EXTEN}@${SIPDOMAIN})
exten => _.,n(OutAllRoutes),Set(DSTRING=${LEN(${EXTEN})})
exten => _.,n,ExecIf($[${DSTRING} > 5]?Goto(outbound-allroutes,${EXTEN},1)
exten => _.,n,ExecIf($["${EXTEN}" = "911"]?Goto(outbound-allroutes,${EXTEN},1)
exten => _.,n,ExecIf($["${EXTEN}" = "933"]?Goto(outbound-allroutes,${EXTEN},1)
exten => _.,n,Dial(local/${EXTEN}@from-internal-additional)
;# // END SIP URI Mod1

Actually, if a CallerID is found and set in line 1, then line 3 would send the call to the Macro and skip the 3 lines you highlighted above.
 

rjbrown99

New Member
Joined
Jul 2, 2021
Messages
3
Reaction score
0
Hi Ward, thanks for the reply. You hit upon something important that I overlooked.

chan_sip Channel Variables

  • ${SIPCALLID} * - SIP Call-ID: header verbatim (for logging or CDR matching)
That variable in line 1 is specific to CHAN_SIP, not CHAN_PJSIP. What happens is that it never contains the expected string, it always contains the name of my local server. That means the call flow continues to the other lines and doesn't jump down to the macro.

I'm not entirely clear on what data was expected in this field when using chan_sip. The asterisk docs don't seem to be as easy to come by for chan_pjsip.

Here's the best I could work out so far to get the call ID. The following variable gets me a 49 character long string mixed with numbers and letters.
${CHANNEL(pjsip,call-id)}

Have you (or anyone else) ported this to PJSIP yet or am I blazing a new trail here? Thanks.
 

Members online

Forum statistics

Threads
25,801
Messages
167,719
Members
19,232
Latest member
voiplads
Get 3CX - Absolutely Free!

Link up your team and customers Phone System Live Chat Video Conferencing

Hosted or Self-managed. Up to 10 users free forever. No credit card. Try risk free.

3CX
A 3CX Account with that email already exists. You will be redirected to the Customer Portal to sign in or reset your password if you've forgotten it.
Top