Schneur,<div><br></div><div>Not disagreeing with the way you are doing it, but you can use the permissions module for the pbxs only. This way you can add the ips in the address table and keep track of who is allowed and block any other requests. There won&#39;t be any script change or reload required. A new pbx would require a new ip address in the table and a reload command. </div>
<div><br></div><div>Regards,</div><div>Ali Pey<br><br><div class="gmail_quote">On Mon, Jul 30, 2012 at 7:39 PM, Schneur Rosenberg <span dir="ltr">&lt;<a href="mailto:rosenberg11219@gmail.com" target="_blank">rosenberg11219@gmail.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Ali I can&#39;t compare PBX addresses, we are a voip company and I can&#39;t<br>
manually edit my script for every PBX our customer installs, I ended<br>
up doing the avp_db_query() and then rewriting the from header with<br>
uac_replace_from(&quot;&quot;,&quot;sip:$au@$si&quot;) which will retrieve the username<br>
from the Proxy-Authorization: field, I had to use uac_replace_from<br>
because $fu is read only.<br>
<div class="HOEnZb"><div class="h5"><br>
On Wed, Jul 25, 2012 at 11:58 PM, Ali Pey &lt;<a href="mailto:alipey@gmail.com">alipey@gmail.com</a>&gt; wrote:<br>
&gt; This would work too. Here though you do a db query for each call and can<br>
&gt; slow down the performance if that&#39;s important to you. Examining usernames&#39;<br>
&gt; patterns can be faster.<br>
&gt;<br>
&gt; You can also use the registered function instead of a db query:<br>
&gt;<br>
&gt; if (registered(&quot;location&quot;,&quot;$fu&quot;)) {<br>
&gt; xlog(&quot;caller is registered\n&quot;);<br>
&gt; }<br>
&gt;<br>
&gt; <a href="http://www.opensips.org/html/docs/modules/1.8.x/registrar.html#id293162" target="_blank">http://www.opensips.org/html/docs/modules/1.8.x/registrar.html#id293162</a><br>
&gt;<br>
&gt; Regards,<br>
&gt; Ali Pey<br>
&gt;<br>
&gt;<br>
&gt; On Wed, Jul 25, 2012 at 4:23 PM, Schneur Rosenberg<br>
&gt; &lt;<a href="mailto:rosenberg11219@gmail.com">rosenberg11219@gmail.com</a>&gt; wrote:<br>
&gt;&gt;<br>
&gt;&gt; I already did something similar look at snippet bellow so any call<br>
&gt;&gt; coming from a IP thats registered to our server will always do<br>
&gt;&gt; proxy_authorize(), other calls will assume that its a unauthenticated<br>
&gt;&gt; DID call or a call going to a local call<br>
&gt;&gt;<br>
&gt;&gt;  if (!(method==&quot;REGISTER&quot;))<br>
&gt;&gt;         {<br>
&gt;&gt;                 avp_db_query(&quot;select username from location where<br>
&gt;&gt; contact regexp &#39;$si&#39; or received like<br>
&gt;&gt; &#39;sip:$si%&#39;&quot;,&quot;$avp(is_registered)&quot;);<br>
&gt;&gt;         }<br>
&gt;&gt;         if (!(method==&quot;REGISTER&quot;) &amp;&amp; avp_check(&quot;$avp(is_registered)&quot;,<br>
&gt;&gt; &quot;gt/1/g&quot;))<br>
&gt;&gt;         {<br>
&gt;&gt;                    if(!is_from_gw())<br>
&gt;&gt;                 {<br>
&gt;&gt;                         if (!proxy_authorize(&quot;sosglobal&quot;, &quot;subscriber&quot;))<br>
&gt;&gt;                         {<br>
&gt;&gt;                                 append_hf(&quot;P-hint: Proxy auth<br>
&gt;&gt; failed\r\n&quot;);<br>
&gt;&gt;                                 proxy_challenge(&quot;sosglobal&quot;, &quot;0&quot;);<br>
&gt;&gt;                                 exit;<br>
&gt;&gt;                         }<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt;                 }<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; On Wed, Jul 25, 2012 at 8:48 PM, Ali Pey &lt;<a href="mailto:alipey@gmail.com">alipey@gmail.com</a>&gt; wrote:<br>
&gt;&gt; &gt; Schneur,<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; You can examine the src_ip first to see if the call if from your pbx or<br>
&gt;&gt; &gt; not.<br>
&gt;&gt; &gt; Then you can also examine to request-uri to distinguish the call between<br>
&gt;&gt; &gt; a<br>
&gt;&gt; &gt; pstn call or a sip client - assuming your sip clients have a different<br>
&gt;&gt; &gt; sip<br>
&gt;&gt; &gt; address/pattern than pstn numbers. Things like this:<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; if ( src_ip == pbx1_ip || src_ip == pbx2_ip ){<br>
&gt;&gt; &gt; # From PBXs<br>
&gt;&gt; &gt; }<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; if ($rU=~&quot;^\+?[0-9]{3,18}&quot;) {<br>
&gt;&gt; &gt; # request-uri is for a PSTN number, send the message to whatever<br>
&gt;&gt; &gt; route(1)<br>
&gt;&gt; &gt; }<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; Basically you need to find a difference between the call attributes and<br>
&gt;&gt; &gt; examine that, it can be the src_ip, ruri pattern, etc.<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; Regards,<br>
&gt;&gt; &gt; Ali Pey<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; On Wed, Jul 25, 2012 at 9:41 AM, Schneur Rosenberg<br>
&gt;&gt; &gt; &lt;<a href="mailto:rosenberg11219@gmail.com">rosenberg11219@gmail.com</a>&gt; wrote:<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; check_source_address won&#39;t work for me, my clients are behind Dynamic<br>
&gt;&gt; &gt;&gt; ip&#39;s, there is no way for me to know in advance their ip address<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; On Mon, Jul 23, 2012 at 8:55 PM, Brett Nemeroff &lt;<a href="mailto:brett@nemeroff.com">brett@nemeroff.com</a>&gt;<br>
&gt;&gt; &gt;&gt; wrote:<br>
&gt;&gt; &gt;&gt; &gt; Scot,<br>
&gt;&gt; &gt;&gt; &gt; the function &quot;is_from_local&quot; uses the From URI and as such, will not<br>
&gt;&gt; &gt;&gt; &gt; work if<br>
&gt;&gt; &gt;&gt; &gt; the originator mangles the from uri (as in the case of your example<br>
&gt;&gt; &gt;&gt; &gt; below).<br>
&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt; &gt; A more secure way to do this that may suit your needs is to use the<br>
&gt;&gt; &gt;&gt; &gt; permissions module and actually check the source IP of the request:<br>
&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt; &gt; <a href="http://www.opensips.org/html/docs/modules/1.8.x/permissions.html#id293503" target="_blank">http://www.opensips.org/html/docs/modules/1.8.x/permissions.html#id293503</a><br>
&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt; &gt; Look at the &quot;check_source_address&quot; and or &quot;get_source_group&quot;. Either<br>
&gt;&gt; &gt;&gt; &gt; of<br>
&gt;&gt; &gt;&gt; &gt; these can compare the source IP of the originator to a known list.<br>
&gt;&gt; &gt;&gt; &gt; From<br>
&gt;&gt; &gt;&gt; &gt; there, you can perform script logic based on where the request came<br>
&gt;&gt; &gt;&gt; &gt; from.<br>
&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt; &gt; Hope that helps!<br>
&gt;&gt; &gt;&gt; &gt; -Brett<br>
&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt; &gt; On Mon, Jul 23, 2012 at 11:38 AM, Schneur Rosenberg<br>
&gt;&gt; &gt;&gt; &gt; &lt;<a href="mailto:rosenberg11219@gmail.com">rosenberg11219@gmail.com</a>&gt; wrote:<br>
&gt;&gt; &gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; &gt;&gt; I&#39;m using opensips as a registrar server and as a loadbalancer, all<br>
&gt;&gt; &gt;&gt; &gt;&gt; phones are registered to opensips and all incoming and outgoing<br>
&gt;&gt; &gt;&gt; &gt;&gt; calls<br>
&gt;&gt; &gt;&gt; &gt;&gt; go to Asterisk boxes via load balancing, therefore I have 3 kinds of<br>
&gt;&gt; &gt;&gt; &gt;&gt; calls going to opensips,<br>
&gt;&gt; &gt;&gt; &gt;&gt; 1) outgoing calls coming from one of the phones Registered to<br>
&gt;&gt; &gt;&gt; &gt;&gt; opensips,<br>
&gt;&gt; &gt;&gt; &gt;&gt; 2) incoming calls (we allow all incoming calls no matter from where<br>
&gt;&gt; &gt;&gt; &gt;&gt; they come, I call them unauthenticated DID)<br>
&gt;&gt; &gt;&gt; &gt;&gt; 3) Calls ringing to a phone registered to opensips, the Asterisk<br>
&gt;&gt; &gt;&gt; &gt;&gt; boxes<br>
&gt;&gt; &gt;&gt; &gt;&gt; will send the calls to the phone either after getting a call from a<br>
&gt;&gt; &gt;&gt; &gt;&gt; DID, or when a internal user wants to call another internal user<br>
&gt;&gt; &gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; &gt;&gt; The way I differentiate between the calls is  I do a      if<br>
&gt;&gt; &gt;&gt; &gt;&gt; (!(method==&quot;REGISTER&quot;) &amp;&amp; is_from_local()) this will check<br>
&gt;&gt; &gt;&gt; &gt;&gt; credentials<br>
&gt;&gt; &gt;&gt; &gt;&gt; and send call to asterisk to process outgoing call, then I do a<br>
&gt;&gt; &gt;&gt; &gt;&gt; else<br>
&gt;&gt; &gt;&gt; &gt;&gt; if ((method==&quot;INVITE&quot;))  which will check if the call is going to a<br>
&gt;&gt; &gt;&gt; &gt;&gt; local phone by doing  if (!lookup(&quot;location&quot;, &quot;m&quot;)) if that fails<br>
&gt;&gt; &gt;&gt; &gt;&gt; that<br>
&gt;&gt; &gt;&gt; &gt;&gt; it assumes its a incoming did call, and it will send it to asterisk<br>
&gt;&gt; &gt;&gt; &gt;&gt; with a prefix so asterisk knows its a unauthenticated incoming call,<br>
&gt;&gt; &gt;&gt; &gt;&gt; bellow I pasted a skeleton of the code I&#39;m using.<br>
&gt;&gt; &gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; &gt;&gt; Everything worked fine, until I connected a PBX to my opensips, then<br>
&gt;&gt; &gt;&gt; &gt;&gt; the from came in with the address of the PBX and the<br>
&gt;&gt; &gt;&gt; &gt;&gt; is_from_local()<br>
&gt;&gt; &gt;&gt; &gt;&gt; test was not true, so it did not work, I had the same problem when<br>
&gt;&gt; &gt;&gt; &gt;&gt; sending a call from a SPA3000 and blocking caller id, in that case<br>
&gt;&gt; &gt;&gt; &gt;&gt; it<br>
&gt;&gt; &gt;&gt; &gt;&gt; also obscured the from address, as follows &quot;From: Anonymous<br>
&gt;&gt; &gt;&gt; &gt;&gt; &lt;sip:anonymous@localhost&gt;;tag=ea3ee097cd947aeeo0.&quot; , the only<br>
&gt;&gt; &gt;&gt; &gt;&gt; reference of the user or domain was in the RPID field  and calls did<br>
&gt;&gt; &gt;&gt; &gt;&gt; not go through.<br>
&gt;&gt; &gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; &gt;&gt; Is there anyway to check if a source IP is registered to our system<br>
&gt;&gt; &gt;&gt; &gt;&gt; and only then it should send a 407? this way if I have a BPX<br>
&gt;&gt; &gt;&gt; &gt;&gt; registered it will then ask for credentials, all others it will<br>
&gt;&gt; &gt;&gt; &gt;&gt; assume<br>
&gt;&gt; &gt;&gt; &gt;&gt; that either a call to the local phone or unauthenticated DID, I<br>
&gt;&gt; &gt;&gt; &gt;&gt; understand that I wont be able to send calls to the system only if<br>
&gt;&gt; &gt;&gt; &gt;&gt; registration was done before, but I have no problem with that,  I<br>
&gt;&gt; &gt;&gt; &gt;&gt; could do it with avp_db_query() on the subscriber table, but I want<br>
&gt;&gt; &gt;&gt; &gt;&gt; to<br>
&gt;&gt; &gt;&gt; &gt;&gt; know if there is a better way.<br>
&gt;&gt; &gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; &gt;&gt; If there is there a better solution then the above solution please<br>
&gt;&gt; &gt;&gt; &gt;&gt; let<br>
&gt;&gt; &gt;&gt; &gt;&gt; me<br>
&gt;&gt; &gt;&gt; &gt;&gt; know<br>
&gt;&gt; &gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; &gt;&gt;         if (!(method==&quot;REGISTER&quot;) &amp;&amp; is_from_local())<br>
&gt;&gt; &gt;&gt; &gt;&gt;         {<br>
&gt;&gt; &gt;&gt; &gt;&gt;                #check credentials<br>
&gt;&gt; &gt;&gt; &gt;&gt;         }<br>
&gt;&gt; &gt;&gt; &gt;&gt;          else if ((method==&quot;INVITE&quot;))   #unathenticated did or call<br>
&gt;&gt; &gt;&gt; &gt;&gt; going to phone registered to opensips<br>
&gt;&gt; &gt;&gt; &gt;&gt;         {<br>
&gt;&gt; &gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; &gt;&gt;                 if (!lookup(&quot;location&quot;, &quot;m&quot;))   #calling local phone<br>
&gt;&gt; &gt;&gt; &gt;&gt;                 {<br>
&gt;&gt; &gt;&gt; &gt;&gt;                          #send to phone registered to opensips<br>
&gt;&gt; &gt;&gt; &gt;&gt;                 }<br>
&gt;&gt; &gt;&gt; &gt;&gt;                 else<br>
&gt;&gt; &gt;&gt; &gt;&gt;                 {<br>
&gt;&gt; &gt;&gt; &gt;&gt;                          #incoming did send call to asterisk to<br>
&gt;&gt; &gt;&gt; &gt;&gt; process<br>
&gt;&gt; &gt;&gt; &gt;&gt;                 }<br>
&gt;&gt; &gt;&gt; &gt;&gt;         }<br>
&gt;&gt; &gt;&gt; &gt;&gt;         else<br>
&gt;&gt; &gt;&gt; &gt;&gt;         {<br>
&gt;&gt; &gt;&gt; &gt;&gt;                #outgoing calls route continues here<br>
&gt;&gt; &gt;&gt; &gt;&gt;         }<br>
&gt;&gt; &gt;&gt; &gt;&gt; ...................................<br>
&gt;&gt; &gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; &gt;&gt; _______________________________________________<br>
&gt;&gt; &gt;&gt; &gt;&gt; Users mailing list<br>
&gt;&gt; &gt;&gt; &gt;&gt; <a href="mailto:Users@lists.opensips.org">Users@lists.opensips.org</a><br>
&gt;&gt; &gt;&gt; &gt;&gt; <a href="http://lists.opensips.org/cgi-bin/mailman/listinfo/users" target="_blank">http://lists.opensips.org/cgi-bin/mailman/listinfo/users</a><br>
&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt; &gt; _______________________________________________<br>
&gt;&gt; &gt;&gt; &gt; Users mailing list<br>
&gt;&gt; &gt;&gt; &gt; <a href="mailto:Users@lists.opensips.org">Users@lists.opensips.org</a><br>
&gt;&gt; &gt;&gt; &gt; <a href="http://lists.opensips.org/cgi-bin/mailman/listinfo/users" target="_blank">http://lists.opensips.org/cgi-bin/mailman/listinfo/users</a><br>
&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; _______________________________________________<br>
&gt;&gt; &gt;&gt; Users mailing list<br>
&gt;&gt; &gt;&gt; <a href="mailto:Users@lists.opensips.org">Users@lists.opensips.org</a><br>
&gt;&gt; &gt;&gt; <a href="http://lists.opensips.org/cgi-bin/mailman/listinfo/users" target="_blank">http://lists.opensips.org/cgi-bin/mailman/listinfo/users</a><br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; _______________________________________________<br>
&gt;&gt; &gt; Users mailing list<br>
&gt;&gt; &gt; <a href="mailto:Users@lists.opensips.org">Users@lists.opensips.org</a><br>
&gt;&gt; &gt; <a href="http://lists.opensips.org/cgi-bin/mailman/listinfo/users" target="_blank">http://lists.opensips.org/cgi-bin/mailman/listinfo/users</a><br>
&gt;&gt; &gt;<br>
&gt;&gt;<br>
&gt;&gt; _______________________________________________<br>
&gt;&gt; Users mailing list<br>
&gt;&gt; <a href="mailto:Users@lists.opensips.org">Users@lists.opensips.org</a><br>
&gt;&gt; <a href="http://lists.opensips.org/cgi-bin/mailman/listinfo/users" target="_blank">http://lists.opensips.org/cgi-bin/mailman/listinfo/users</a><br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; _______________________________________________<br>
&gt; Users mailing list<br>
&gt; <a href="mailto:Users@lists.opensips.org">Users@lists.opensips.org</a><br>
&gt; <a href="http://lists.opensips.org/cgi-bin/mailman/listinfo/users" target="_blank">http://lists.opensips.org/cgi-bin/mailman/listinfo/users</a><br>
&gt;<br>
<br>
_______________________________________________<br>
Users mailing list<br>
<a href="mailto:Users@lists.opensips.org">Users@lists.opensips.org</a><br>
<a href="http://lists.opensips.org/cgi-bin/mailman/listinfo/users" target="_blank">http://lists.opensips.org/cgi-bin/mailman/listinfo/users</a><br>
</div></div></blockquote></div><br></div>