Friday, June 24, 2011

Blocking Calls in Lync Based on Caller ID

Sometimes you have to rely on others when you don’t poses the skills your self, well maybe this was more like hope someone comes to my rescue. This week I got a question about blocking caller ID. I knew what to use to solve it but didn’t know how to write the code. Luckily for me Keith from Got UC was able to help me out. Below is a MSPL script for blocking calls in Lync based on caller ID. Keith has also posted the code on gotUC as well.  I have also created a link to my SkyDrive so people can download it rather than copy and pasting from the post which can screw the code up.

One thing you will notice about the script is that you will need to create a text file called BlockedTelephoneNumbers.txt. This file contains the blocked telephone numbers with two columns. One is the telephone number and the second is the action which in this case only requires the word “block”. Also static="false" is set which means when you make a change to the script it will reload it so no need to do any manual restarts of the application in Lync.

This is a pretty simple script that only blocks on the inbound caller id and does no other checks. Hopefully you only block the right numbers. You can also add some checks to this script. Only invites from the mediation server is one that comes to mind. This would block only calls from the PSTN and would avoid the script checking every single invite against the file which could get quite large.

So the potential to add some more checks and balances are possible but this script presents a great base to build a more complex call blocking process.

<?xml version="1.0"?>
<r:applicationManifest r:appUri="http://www.gotuc.net/TelFilter" xmlns:r="http://schemas.microsoft.com/lcs/2006/05">
  <r:requestFilter methodNames="ALL" strictRoute="true"/>
    <r:responseFilter reasonCodes="NONE"/>
         <r:scriptOnly/>
    <r:file name="BlockedTelephoneNumbers" path="C:\Work\TelFilter\BlockedTelephoneNumbers.txt" delimitedBy="comma" keyColumnName="Phone" static="false">
        <r:column name="Phone" />
        <r:column name="Action" />
    </r:file>
  <r:splScript><![CDATA[

/*++
Module Name: TelFilter.am   
--*/
    //
    // Main program.
    //
    Log ("Debugr", false, "We have a request - ", sipRequest.Method);
    Log ("Debugr", false, "From - ", GetUserName(GetUri(sipRequest.From)));
    Log ("Debugr", false, "To - ", GetUserName(GetUri(sipRequest.To)));

    action = BlockedTelephoneNumbers[GetUserName(GetUri(sipRequest.From))].Action;
    if(action == "block")
    {
           Log ("Debugr", false, "Exit. Rejected by policy");
           Respond(403, "Forbidden");
    }
    else
    {
           Log ("Debugr", false, "Exit. Allowed by policy");
    }
    return;
]]></r:splScript>
</r:applicationManifest>

Click below to download code:

MSPL scripts are a great tool. If you want to learn more check here. If you have a script you are willing to share let me know. Here is another example of MSPL use here.

Comment welcomed.

VoIPNorm

2 comments:

  1. Hey Norman, great blog, just had a question about this script. We are trying to get this to work in our environment and want to run the script from a share on another server (so we don't have to update the caller id list multiple times for our front ends). Is UNC supported with this approach? I ask because we have the script running, phone numbers added in the same format as they appear coming from our Gateway, but nothing happens.

    ReplyDelete
  2. I would try without it first to see if it works first and that will tell you if the UNC is the issue. I see no reason why it shouldn't work as long as the script can access the share.

    ReplyDelete