[Kamailio-Users] Check if a user is calling from aregistered device and if not, deny the call!

Daniel-Constantin Mierla miconda at gmail.com
Mon Oct 20 12:08:39 CEST 2008



On 10/20/08 12:58, arif.zaman wrote:
> miconda wrote:
>   
>> Hello,
>>
>> On 10/19/08 14:32, Arif-Uz-Zaman wrote:
>>     
>>> Hi,
>>>
>>> Here is a tricky sample config to check if a user is calling from a
>>> registered device and if not, deny the call:
>>>
>>> $var(temp) = $ruri;
>>> $ruri = $fu;
>>> if(!registered("location")) {		
>>> 	sl_send_reply("403","Forbidden auth ID");
>>> 	xlog("<ARIF> Not Found\n");
>>> 	exit;
>>> }
>>> $ruri = $var(temp);
>>>   
>>>       
>> in the trunk (so available with upcoming 1.5.0) you can do more strict 
>> checks. While you are sure an user is registered, you cannot detect if 
>> he is calling from registered device or a different one. You just know 
>> it has a valid contact in location database.
>>
>> Here is an example to check Contact address in INVITE is same as one in 
>> location table:
>> http://openser.blogspot.com/2008/10/registrar-enhancements.html
>>
>> As you get access to all attributes stored for a location record, you 
>> can do many other tests, like source IP and port, etc.
>>
>> Cheers,
>> Daniel
>>
>>     
>
> Yes, i've tested trunk and it works for me!
>
> if(!reg_fetch_contacts("location", "$fu", "caller")) {
>    sl_send_reply("403", "Please register first");   
>    exit;
> }
>   
if you just want to see if that user is registered or not, the 
alternative you used before is better. registered() returns as soon as 
it finds a valid contact. reg_fetch_contacts() does more operations to 
make available attributes associated with registered contacts (e.g., 
contact address, Q value, received socket, a.s.o):
http://www.kamailio.org/docs/modules/devel/registrar.html#id2506813

Cheers,
Daniel

-- 
Daniel-Constantin Mierla
http://www.asipto.com





More information about the Users mailing list