[asterisk-users] SQLite3 astdb back-end

2014-05-02 Thread thufir

How do you load the contact list?  It's a database?  Sqlite3?

https://wiki.asterisk.org/wiki/display/AST/SQLite3+astdb+back-end

I'm not clear on what this specific database does.  If it's not this 
specific database which has contact information, which database does?



thanks,

Thufir

--
_
-- Bandwidth and Colocation Provided by http://www.api-digital.com --
New to Asterisk? Join us for a live introductory webinar every Thurs:
  http://www.asterisk.org/hello

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
  http://lists.digium.com/mailman/listinfo/asterisk-users


[asterisk-users] Elastix Architecture

2014-05-02 Thread upendra
Hi ALL,


Am new to Elastix and wanted to try build new modules in the Elastix , so i
want to know how the PHP is running ?? as i see no Apache server inside ??
so wanted to know how its running ? which server and architecture?

*--*
*Thanks  Regards*
*Upendra*
-- 
_
-- Bandwidth and Colocation Provided by http://www.api-digital.com --
New to Asterisk? Join us for a live introductory webinar every Thurs:
   http://www.asterisk.org/hello

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-users

Re: [asterisk-users] Elastix Architecture

2014-05-02 Thread Steven Howes
On 2 May 2014, at 10:07, upendra uppi...@gmail.com wrote:
 Am new to Elastix and wanted to try build new modules in the Elastix , so i 
 want to know how the PHP is running ?? as i see no Apache server inside ?? so 
 wanted to know how its running ? which server and architecture?

This is not an Elastix mailing list, and even if it was I doubt there is 
sufficient information there for anyone to help you. There are multiple 
appliances and software versions, without you saying what you’ve actually got, 
it’s going to be hard to help.

Steve-- 
_
-- Bandwidth and Colocation Provided by http://www.api-digital.com --
New to Asterisk? Join us for a live introductory webinar every Thurs:
   http://www.asterisk.org/hello

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-users

[asterisk-users] CDR billsec issue with calls forwarded through the Local channel

2014-05-02 Thread Ishfaq Malik
Hi

I'm using asterisk 1.8.23.1 but I've seen this same issue in previous
versions of 1.8. I have created some work arounds but the behaviour is
incorrect.

This is the scenario:
Call comes in and goes to appropriate dialplan
In the dialplan the call is forwarded to another number using a Local
channel (and using /n ) e.g.
Dial(Local/my-number@outbound-context/n,60)
The number is dialled and the call is all fine.

In the CDR we have 2 entries, one for the inbound leg and one for the
outbound leg as is expected by the use of the /n

However, the outbound leg CDR entry has a billsec of 0. The CDR for the
inbound leg has the correct duration of the call in the billsec column (I'm
writing CDRs to MySQL)

This is causing issues in my billing module for obvious reasons. I'm having
to find the inbound call by matching the channel in one leg with the
dstchannel in the other leg and that is quite messy.

Would others agree that this behaviour is incorrect? Has anyone else seen
this or be able to replicate it? Am I just missing something obvious?

Thanks in Advance

Ish

-- 

Ishfaq Malik
Department: VOIP Support
Company: Packnet Limited
t: +44 (0)845 004 4994
f: +44 (0)161 660 9825
e: i...@pack-net.co.uk
w: http://www.pack-net.co.uk

Registered Address: PACKNET LIMITED, Duplex 2, Ducie House
37 Ducie Street
Manchester, M1 2JW
COMPANY REG NO. 04920552
-- 
_
-- Bandwidth and Colocation Provided by http://www.api-digital.com --
New to Asterisk? Join us for a live introductory webinar every Thurs:
   http://www.asterisk.org/hello

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-users

Re: [asterisk-users] CDR billsec issue with calls forwarded through the Local channel

2014-05-02 Thread Ishfaq Malik
A big correction to the above!

This 0 billsec entry happens when someone forwards a call from their phone
using an auto forward (which then uses a Local channel on the asterisk
server). The phone in question is a Snom.

If I use a Local channel in the dial plan, the entry has a the correct
billsec.




On 2 May 2014 11:23, Ishfaq Malik i...@pack-net.co.uk wrote:

 Hi

 I'm using asterisk 1.8.23.1 but I've seen this same issue in previous
 versions of 1.8. I have created some work arounds but the behaviour is
 incorrect.

 This is the scenario:
 Call comes in and goes to appropriate dialplan
 In the dialplan the call is forwarded to another number using a Local
 channel (and using /n ) e.g.
 Dial(Local/my-number@outbound-context/n,60)
 The number is dialled and the call is all fine.

 In the CDR we have 2 entries, one for the inbound leg and one for the
 outbound leg as is expected by the use of the /n

 However, the outbound leg CDR entry has a billsec of 0. The CDR for the
 inbound leg has the correct duration of the call in the billsec column (I'm
 writing CDRs to MySQL)

 This is causing issues in my billing module for obvious reasons. I'm
 having to find the inbound call by matching the channel in one leg with the
 dstchannel in the other leg and that is quite messy.

 Would others agree that this behaviour is incorrect? Has anyone else seen
 this or be able to replicate it? Am I just missing something obvious?

 Thanks in Advance

 Ish

 --

 Ishfaq Malik
 Department: VOIP Support
 Company: Packnet Limited
 t: +44 (0)845 004 4994
 f: +44 (0)161 660 9825
 e: i...@pack-net.co.uk
 w: http://www.pack-net.co.uk

 Registered Address: PACKNET LIMITED, Duplex 2, Ducie House
 37 Ducie Street
 Manchester, M1 2JW
 COMPANY REG NO. 04920552




-- 

Ishfaq Malik
Department: VOIP Support
Company: Packnet Limited
t: +44 (0)845 004 4994
f: +44 (0)161 660 9825
e: i...@pack-net.co.uk
w: http://www.pack-net.co.uk

Registered Address: PACKNET LIMITED, Duplex 2, Ducie House
37 Ducie Street
Manchester, M1 2JW
COMPANY REG NO. 04920552
-- 
_
-- Bandwidth and Colocation Provided by http://www.api-digital.com --
New to Asterisk? Join us for a live introductory webinar every Thurs:
   http://www.asterisk.org/hello

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-users

[asterisk-users] Other Allison prompts?

2014-05-02 Thread Tony Mountifield
I was wondering whether there are any other collections of Asterisk-
compatible prompts recorded by Allison, that people might have kindly
made available for free download.

I found mention of some in an article at 
http://www.venturevoip.com/news.php?rssid=2690
but the links referred to on www.asterisk.org appear no longer to exist.

I already have the core- (good quality) and extra- (poor quality) sets
of standard prompts.

On a related note, the extra- set appears to have been converted from
the old GSM format. Are there any plans to have them re-recorded in
good quality?

Cheers
Tony
-- 
Tony Mountifield
Work: t...@softins.co.uk - http://www.softins.co.uk
Play: t...@mountifield.org - http://tony.mountifield.org

-- 
_
-- Bandwidth and Colocation Provided by http://www.api-digital.com --
New to Asterisk? Join us for a live introductory webinar every Thurs:
   http://www.asterisk.org/hello

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-users


Re: [asterisk-users] Putting a notice in the logs from the dialplan

2014-05-02 Thread Matthew Jordan
On Thu, May 1, 2014 at 9:39 AM, Ishfaq Malik i...@pack-net.co.uk wrote:

 That works a treat, thank you.


 On 1 May 2014 15:28, Steven Wheeler swhee...@usinternet.com wrote:

 On Thu, May 1, 2014 at 8:37 AM, Ishfaq Malik i...@pack-net.co.uk wrote:

 Hi



 Using asterisk 1.8



 NoOp and Verbose both put messages into the logs as VERBOSE, is there any 
 way to put a message into the logs as NOTICE from within a dial plan?



 Thanks in advance



 What about the Log application? It is available on our Asterisk 1.8.26 box.


 Connected to Asterisk 1.8.26.0

 Verbosity is at least 3

 CLI core show application Log



   -= Info about application 'Log' =-



 [Synopsis]

 Send arbitrary text to a selected log level.



 [Description]

 Sends an arbitrary text message to a selected log level.



 [Syntax]

 Log(level,message)



 [Arguments]

 level

 Level must be one of 'ERROR', 'WARNING', 'NOTICE', 'DEBUG', 'VERBOSE'

 or 'DTMF'.

 message

 Output text message.



 [See Also]

 Not available




Ha! Just when you think you've found every corner of Asterisk, you
turn around and there's something else.

Just goes to show, you learn something new every day.

-- 
Matthew Jordan
Digium, Inc. | Engineering Manager
445 Jan Davis Drive NW - Huntsville, AL 35806 - USA
Check us out at: http://digium.com  http://asterisk.org

-- 
_
-- Bandwidth and Colocation Provided by http://www.api-digital.com --
New to Asterisk? Join us for a live introductory webinar every Thurs:
   http://www.asterisk.org/hello

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-users


Re: [asterisk-users] Putting a notice in the logs from the dialplan

2014-05-02 Thread Kevin Larsen
 From: Matthew Jordan mjor...@digium.com

 Ha! Just when you think you've found every corner of Asterisk, you
 turn around and there's something else.
 
 Just goes to show, you learn something new every day.

Look on the bright side, you did say it would be easy to write just such a 
module...-- 
_
-- Bandwidth and Colocation Provided by http://www.api-digital.com --
New to Asterisk? Join us for a live introductory webinar every Thurs:
   http://www.asterisk.org/hello

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-users

Re: [asterisk-users] SQLite3 astdb back-end

2014-05-02 Thread Matthew Jordan
On Fri, May 2, 2014 at 1:11 AM, thufir hawat.thu...@gmail.com wrote:
 How do you load the contact list?  It's a database?  Sqlite3?

 https://wiki.asterisk.org/wiki/display/AST/SQLite3+astdb+back-end

 I'm not clear on what this specific database does.  If it's not this
 specific database which has contact information, which database does?


Prior to Asterisk 10, Asterisk's internal database was a Berkeley
database. For a variety of reasons, in Asterisk 10, we moved to using
SQLite. Generally, this change was under the hood, but people
upgrading from Asterisk 1.8 to a later version needed to be aware of
it.

The database really has two purposes:
(1) Asterisk uses it to store information that needs to persist
between reloads/restarts. Various modules use it for this purpose
automatically.
(2) Users can use it to store arbitrary data. This is done using a
variety of dialplan applications and functions:

* https://wiki.asterisk.org/wiki/display/AST/Asterisk+11+Function_DB
* https://wiki.asterisk.org/wiki/display/AST/Asterisk+11+Function_DB_DELETE
* https://wiki.asterisk.org/wiki/display/AST/Asterisk+11+Function_DB_EXISTS
* https://wiki.asterisk.org/wiki/display/AST/Asterisk+11+Function_DB_KEYS
* https://wiki.asterisk.org/wiki/display/AST/Asterisk+11+Application_DBdeltree

Whether or not you store 'contact information' (and that could have a
variety of meanings, so I won't interpret it specifically) is up to
you.

-- 
Matthew Jordan
Digium, Inc. | Engineering Manager
445 Jan Davis Drive NW - Huntsville, AL 35806 - USA
Check us out at: http://digium.com  http://asterisk.org

-- 
_
-- Bandwidth and Colocation Provided by http://www.api-digital.com --
New to Asterisk? Join us for a live introductory webinar every Thurs:
   http://www.asterisk.org/hello

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-users


Re: [asterisk-users] Proper way to make Asterisk recognize SIP trunk of incoming INVITE when IP is not available

2014-05-02 Thread Alex Villací­s Lasso

El 27/04/14 07:47, Barry Flanagan escribió:

On 26 April 2014 00:29, Alex Villací­s Lasso a_villa...@palosanto.com 
mailto:a_villa...@palosanto.com wrote:

I am currently preparing a kamailio-asterisk combination. The asterisk 
installation uses realtime for SIP. The kamailio configuration was based on the 
reference at 
http://kb.asipto.com/asterisk:realtime:kamailio-4.0.x-asterisk-11.3.0-astdb but 
has
been heavily modified. Currently asterisk runs on localhost and only 
listens on SIP/RTP at 127.0.0.1 . Therefore, all of the SIP traffic appears to 
come from localhost, from the point of view of asterisk.

Currently I have a model on which internal SIP phones get identified by the 
authentication username, and then the contact names at From: and To: get 
massaged to incorporate the SIP domain, in order to emulate multiple-domain 
support. The 'sip' table
in Asterisk defines all such contacts as SIP accounts of the form name_domain.com 
http://name_domain.com, and the SIP phones are configured to use 'name' as 
authentication username for domain 'domain.com http://domain.com'. However, SIP 
providers
that register on the server with authentication names are left with their 
original names, since in the model, SIP trunks are available to all domains.

Now I have to add support for SIP providers which are to be authorized on 
the basis of IP only. Apparently, the kamailio module permissions.so 
(WITH_IPAUTH) is made for just this purpose, so I enabled it. After 
authentication, I need to route the
INVITE to asterisk, and asterisk must somehow match the account for the SIP 
trunk from the available information on the INVITE request.



What I have done in a similar situation is to use  force_send_socket in Kamailio when sending INVITEs from your trusted host (your trunks) so that it is coming in to Asterisk from a different port (say 5070), and then in your Asterisk sip.conf settings 
create a new peer for this like so:


[peer-incoming]
context=peercontext
type=peer
host=127.0.0.1
port=5070

Now, when Asterisk receives an INVITE from 127.0.0.1:5070 http://127.0.0.1:5070 it 
will match this peer, whereas the rest, coming from 127.0.0.1:5060 
http://127.0.0.1:5060, will match your other subscribers.

Here is a bit of the Kamailio config:

if (is_method(INVITE))
{
# If call is coming from a trusted source (Trunk/PSTN) then we send it 
to Asterisk from port 5070
# so that Asterisk knows this is not coming from a subscriber. The peer 
in Asterisk needs to be set with port=5070
# as well as the host=ip address
if (allow_trusted())
{
xlog(L_INFO,Inbound to Asterisk from Trusted Source IP $si, Caller: 
$fU, Callee: $rU with Call-ID $hdr(Call-ID));
force_send_socket(127.0.0.1:5070 http://127.0.0.1:5070);
} else {
# This is a call from a registered subscriber.
xlog(L_INFO,Inbound to Asterisk from $fU to $rU with Call-ID 
$hdr(Call-ID));
}
}
route(RELAY);
exit;
}

NOTE: Kamailio must be set to listen on 127.0.0.1:5070 http://127.0.0.1:5070 as well as your usual ports for this to work! Also, your SIP Trunk trusted peers need to be in the Kamailio trusted table, or explicitly test for the src_ip rather than use 
allow_trusted().



I would rather have a solution that does not involve allocating a new UDP port 
every time a new IP-trusted SIP trunk is configured.

I tried appending a P-Asserted Identity header to the incoming INVITE before 
routing it to asterisk, like this:

#!ifdef WITH_IPAUTH
if((!is_method(REGISTER))  allow_source_address()  $au == )
{
# Attempt to create a P-Asserted-Identity if none exists, to preserve
# incoming Caller-ID
if (!is_present_hf(P-Asserted-Identity))
{
append_hf(P-Asserted-Identity: sip:$fU@$fd\r\n);
}

# Loading $fU from database using IP
sql_pvquery(elxpbx, SELECT name FROM sip WHERE host = '$si' AND sippasswd IS 
NULL, $fU);

# source IP allowed
return;
}
#!endif

With tcpdump, I can see that the header is indeed appended to the SIP headers of the INVITE, but there is no effect in Asterisk. From examination of the Asterisk 11.8.1 source code, I see that channels/chan_sip.c contains a get_pai() function that is 
supposed to process P-Asserted-Identity and extract a caller ID. I am still studying the code, but I would appreciate help on this issue, to see why my attempt is not working.
-- 
_
-- Bandwidth and Colocation Provided by http://www.api-digital.com --
New to Asterisk? Join us for a live introductory webinar every Thurs:
   http://www.asterisk.org/hello

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-users

Re: [asterisk-users] Proper way to make Asterisk recognize SIP trunk of incoming INVITE when IP is not available

2014-05-02 Thread Alex Villací­s Lasso

El 02/05/14 10:49, Alex Villací­s Lasso escribió:

El 27/04/14 07:47, Barry Flanagan escribió:

On 26 April 2014 00:29, Alex Villací­s Lasso a_villa...@palosanto.com 
mailto:a_villa...@palosanto.com wrote:

I am currently preparing a kamailio-asterisk combination. The asterisk 
installation uses realtime for SIP. The kamailio configuration was based on the 
reference at 
http://kb.asipto.com/asterisk:realtime:kamailio-4.0.x-asterisk-11.3.0-astdb but 
has
been heavily modified. Currently asterisk runs on localhost and only 
listens on SIP/RTP at 127.0.0.1 . Therefore, all of the SIP traffic appears to 
come from localhost, from the point of view of asterisk.

Currently I have a model on which internal SIP phones get identified by the 
authentication username, and then the contact names at From: and To: get 
massaged to incorporate the SIP domain, in order to emulate multiple-domain 
support. The 'sip' table
in Asterisk defines all such contacts as SIP accounts of the form name_domain.com 
http://name_domain.com, and the SIP phones are configured to use 'name' as 
authentication username for domain 'domain.com http://domain.com'. However, SIP
providers that register on the server with authentication names are left 
with their original names, since in the model, SIP trunks are available to all 
domains.

Now I have to add support for SIP providers which are to be authorized on 
the basis of IP only. Apparently, the kamailio module permissions.so 
(WITH_IPAUTH) is made for just this purpose, so I enabled it. After 
authentication, I need to route the
INVITE to asterisk, and asterisk must somehow match the account for the SIP 
trunk from the available information on the INVITE request.



What I have done in a similar situation is to use  force_send_socket in Kamailio when sending INVITEs from your trusted host (your trunks) so that it is coming in to Asterisk from a different port (say 5070), and then in your Asterisk sip.conf settings 
create a new peer for this like so:


[peer-incoming]
context=peercontext
type=peer
host=127.0.0.1
port=5070

Now, when Asterisk receives an INVITE from 127.0.0.1:5070 http://127.0.0.1:5070 it 
will match this peer, whereas the rest, coming from 127.0.0.1:5060 
http://127.0.0.1:5060, will match your other subscribers.

Here is a bit of the Kamailio config:

if (is_method(INVITE))
{
# If call is coming from a trusted source (Trunk/PSTN) then we send it 
to Asterisk from port 5070
# so that Asterisk knows this is not coming from a subscriber. The peer 
in Asterisk needs to be set with port=5070
# as well as the host=ip address
if (allow_trusted())
{
xlog(L_INFO,Inbound to Asterisk from Trusted Source IP $si, Caller: 
$fU, Callee: $rU with Call-ID $hdr(Call-ID));
force_send_socket(127.0.0.1:5070 http://127.0.0.1:5070);
} else {
# This is a call from a registered subscriber.
xlog(L_INFO,Inbound to Asterisk from $fU to $rU with Call-ID 
$hdr(Call-ID));
}
}
route(RELAY);
exit;
}

NOTE: Kamailio must be set to listen on 127.0.0.1:5070 http://127.0.0.1:5070 as well as your usual ports for this to work! Also, your SIP Trunk trusted peers need to be in the Kamailio trusted table, or explicitly test for the src_ip rather than use 
allow_trusted().



I would rather have a solution that does not involve allocating a new UDP port 
every time a new IP-trusted SIP trunk is configured.

I tried appending a P-Asserted Identity header to the incoming INVITE before 
routing it to asterisk, like this:

#!ifdef WITH_IPAUTH
if((!is_method(REGISTER))  allow_source_address()  $au == )
{
# Attempt to create a P-Asserted-Identity if none exists, to preserve
# incoming Caller-ID
if (!is_present_hf(P-Asserted-Identity))
{
append_hf(P-Asserted-Identity: sip:$fU@$fd\r\n);
}

# Loading $fU from database using IP
sql_pvquery(elxpbx, SELECT name FROM sip WHERE host = '$si' AND sippasswd IS 
NULL, $fU);

# source IP allowed
return;
}
#!endif

With tcpdump, I can see that the header is indeed appended to the SIP headers of the INVITE, but there is no effect in Asterisk. From examination of the Asterisk 11.8.1 source code, I see that channels/chan_sip.c contains a get_pai() function that is 
supposed to process P-Asserted-Identity and extract a caller ID. I am still studying the code, but I would appreciate help on this issue, to see why my attempt is not working.



By placing debugging statements, I think get_pai() is not being called when receiving an incoming INVITE, corresponding to an incoming call from the IP-authenticated trunk being handled by an IVR, but not yet routed to an internal extension. Why is this 
so? Is this by design?
-- 
_
-- Bandwidth and Colocation Provided by 

Re: [asterisk-users] Other Allison prompts?

2014-05-02 Thread Rusty Newton
On Fri, May 2, 2014 at 6:48 AM, Tony Mountifield t...@softins.co.uk wrote:
 I was wondering whether there are any other collections of Asterisk-
 compatible prompts recorded by Allison, that people might have kindly
 made available for free download.

 I found mention of some in an article at 
 http://www.venturevoip.com/news.php?rssid=2690
 but the links referred to on www.asterisk.org appear no longer to exist.

These sounds were integrated into the 1.4.12 version of our Extra
sounds release.


 I already have the core- (good quality) and extra- (poor quality) sets
 of standard prompts.

 On a related note, the extra- set appears to have been converted from
 the old GSM format. Are there any plans to have them re-recorded in
 good quality?

Not at this time, you are welcome to contact Allison and ask her if
she would be willing to do that.

-- 
Rusty Newton
Digium, Inc. | Community Support Manager
445 Jan Davis Drive NW - Huntsville, AL 35806 - US
direct: +1 256 428 6200

Check us out at: http://digium.com  http://asterisk.org

-- 
_
-- Bandwidth and Colocation Provided by http://www.api-digital.com --
New to Asterisk? Join us for a live introductory webinar every Thurs:
   http://www.asterisk.org/hello

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-users


[asterisk-users] SOLVED: Re: Proper way to make Asterisk recognize SIP trunk of incoming INVITE when IP is not available

2014-05-02 Thread Alex Villací­s Lasso

El 02/05/14 11:41, Alex Villací­s Lasso escribió:

El 02/05/14 10:49, Alex Villací­s Lasso escribió:

El 27/04/14 07:47, Barry Flanagan escribió:

On 26 April 2014 00:29, Alex Villací­s Lasso a_villa...@palosanto.com 
mailto:a_villa...@palosanto.com wrote:

I am currently preparing a kamailio-asterisk combination. The asterisk 
installation uses realtime for SIP. The kamailio configuration was based on the 
reference at 
http://kb.asipto.com/asterisk:realtime:kamailio-4.0.x-asterisk-11.3.0-astdb but 
has
been heavily modified. Currently asterisk runs on localhost and only 
listens on SIP/RTP at 127.0.0.1 . Therefore, all of the SIP traffic appears to 
come from localhost, from the point of view of asterisk.

Currently I have a model on which internal SIP phones get identified by the 
authentication username, and then the contact names at From: and To: get 
massaged to incorporate the SIP domain, in order to emulate multiple-domain 
support. The 'sip'
table in Asterisk defines all such contacts as SIP accounts of the form name_domain.com 
http://name_domain.com, and the SIP phones are configured to use 'name' as 
authentication username for domain 'domain.com http://domain.com'. However, SIP
providers that register on the server with authentication names are left 
with their original names, since in the model, SIP trunks are available to all 
domains.

Now I have to add support for SIP providers which are to be authorized on 
the basis of IP only. Apparently, the kamailio module permissions.so 
(WITH_IPAUTH) is made for just this purpose, so I enabled it. After 
authentication, I need to route the
INVITE to asterisk, and asterisk must somehow match the account for the SIP 
trunk from the available information on the INVITE request.



What I have done in a similar situation is to use  force_send_socket in Kamailio when sending INVITEs from your trusted host (your trunks) so that it is coming in to Asterisk from a different port (say 5070), and then in your Asterisk sip.conf settings 
create a new peer for this like so:


[peer-incoming]
context=peercontext
type=peer
host=127.0.0.1
port=5070

Now, when Asterisk receives an INVITE from 127.0.0.1:5070 http://127.0.0.1:5070 it 
will match this peer, whereas the rest, coming from 127.0.0.1:5060 
http://127.0.0.1:5060, will match your other subscribers.

Here is a bit of the Kamailio config:

if (is_method(INVITE))
{
# If call is coming from a trusted source (Trunk/PSTN) then we send it 
to Asterisk from port 5070
# so that Asterisk knows this is not coming from a subscriber. The peer 
in Asterisk needs to be set with port=5070
# as well as the host=ip address
if (allow_trusted())
{
xlog(L_INFO,Inbound to Asterisk from Trusted Source IP $si, Caller: 
$fU, Callee: $rU with Call-ID $hdr(Call-ID));
force_send_socket(127.0.0.1:5070 http://127.0.0.1:5070);
} else {
# This is a call from a registered subscriber.
xlog(L_INFO,Inbound to Asterisk from $fU to $rU with Call-ID 
$hdr(Call-ID));
}
}
route(RELAY);
exit;
}

NOTE: Kamailio must be set to listen on 127.0.0.1:5070 http://127.0.0.1:5070 as well as your usual ports for this to work! Also, your SIP Trunk trusted peers need to be in the Kamailio trusted table, or explicitly test for the src_ip rather than use 
allow_trusted().



I would rather have a solution that does not involve allocating a new UDP port 
every time a new IP-trusted SIP trunk is configured.

I tried appending a P-Asserted Identity header to the incoming INVITE before 
routing it to asterisk, like this:

#!ifdef WITH_IPAUTH
if((!is_method(REGISTER))  allow_source_address()  $au == )
{
# Attempt to create a P-Asserted-Identity if none exists, to preserve
# incoming Caller-ID
if (!is_present_hf(P-Asserted-Identity))
{
append_hf(P-Asserted-Identity: sip:$fU@$fd\r\n);
}

# Loading $fU from database using IP
sql_pvquery(elxpbx, SELECT name FROM sip WHERE host = '$si' AND sippasswd IS 
NULL, $fU);

# source IP allowed
return;
}
#!endif

With tcpdump, I can see that the header is indeed appended to the SIP headers of the INVITE, but there is no effect in Asterisk. From examination of the Asterisk 11.8.1 source code, I see that channels/chan_sip.c contains a get_pai() function that is 
supposed to process P-Asserted-Identity and extract a caller ID. I am still studying the code, but I would appreciate help on this issue, to see why my attempt is not working.



By placing debugging statements, I think get_pai() is not being called when receiving an incoming INVITE, corresponding to an incoming call from the IP-authenticated trunk being handled by an IVR, but not yet routed to an internal extension. Why is this 
so? Is this by design?




SOLVED: asterisk needs to be configured with trustrpid=yes in the affected