[Tutorial] Configuring Lync Server 2013 to block calls based on Caller ID

Synopsis: Out of the box, Lync Server 2013 does not have any way to block specific calls destined to any user or specific user inside of an organization.  However, Microsoft added in the ability for users/partners/etc. to write custom scripts to help allow flexibility in Lync.  That being said, this tutorial will go over deploying a custom script to allow Lync Server to block calls based on caller ID.

Before we begin, I would like to give credit to a few individuals.  This guide will make use of David Paulino's guide/script for Lync Server 2013 (http://uclobby.com/2014/07/31/calleridblock/), which was a converted script from VoIP Norm's original Lync Server 2010 script (http://voipnorm.blogspot.co.uk/2011/06/blocking-calls-in-lync-based-on-caller.html).  The only changes in this article is a more step-by-step deployment guide as well as the ability to control blocking of numbers at a user level and the ability to optionally leave comments on why a rule was added.

Tutorial

  1. Download a copy of the CallerIDBlock.am.txt script (or copy and paste this script into a file called CallerIDBlock.am) (if you downloaded this file, make sure you remove the .txt at the end)
    1. <?xml version="1.0" ?>
      <lc:applicationManifest
      lc:appUri="http://jackstromberg.com/2015/02/CallerIDBlock"
      xmlns:lc="http://schemas.microsoft.com/lcs/2006/05">
      <lc:requestFilter methodNames="ALL" strictRoute="true"/>
      <lc:responseFilter reasonCodes="NONE"/>
      <lc:scriptOnly/>
      <lc:file name="BlockedTelephoneNumbers"
      path="\\<Lync Share Path>\CallerIDBlock\BlockedTelephoneNumbers.txt"
      delimitedBy="comma"
      keyColumnName="FromSIP"
      static="false">
      <lc:column name="FromSIP" />
      <lc:column name="ToSIP" />
      <lc:column name="Action" />
      <lc:column name="Comments" />
      </lc:file>
      <lc:splScript><![CDATA[
      /*
      Module Name: CallerIDBlock.am
      */if(sipRequest.Method == "INVITE"){
      fromSIPUser = GetUserName(GetUri(sipRequest.From));
      toSIPUser = GetUserName(GetUri(sipRequest.To));
      sep = IndexOfString(fromSIPUser, ";");Log ("Debugr", false, "CallerIDBlock processing request:");
      Log ("Debugr", false, "From - ", fromSIPUser);
      Log ("Debugr", false, "To - ", toSIPUser);
      if(sep != -1) {
      fromSIPUser = SubString(fromSIPUser, 0, sep);
      }

      action = BlockedTelephoneNumbers[fromSIPUser].Action;
      if(action == "block") {
      if(BlockedTelephoneNumbers[fromSIPUser].ToSIP == "*" || BlockedTelephoneNumbers[fromSIPUser].ToSIP == toSIPUser){
      Log ("Debugr", false, "Rejected by CallerIDBlock");
      Respond(403, "Forbidden");
      }
      } else {
      Log ("Debugr", false, "Allowed by CallerIDBlock");
      }
      }
      return;
      ]]></lc:splScript>
      </lc:applicationManifest>

  2. Download a copy of the BlockedTelephoneNumbers.txt file (or copy and paste the code below into a file called BlockedTelephoneNumbers.txt)
    1. FromSIP,ToSIP,Action,Comments
  3. Edit the CallerIDBlock.am file and change the BlockedTelephoneNumbers path to be your fileshare
    CallerIDBlock - LyncPath - Notepad
  4. Edit the list of blocked numbers inside the BlockedTelephoneNumbers.txt file
    1. Notes: The FromSIP address is the Caller ID of the incoming call; the ToSIP is the individual that is trying to be reached (side-note, in this particular script, if you set this field so an asterisk (*), this will be a wildcard for any/every user; the Action should be set to "block" to block the call; the Comments field is an optional field to document when/why the number was added to be blocked
      BlockedTelephoneNumbers Example
  5. Create a new folder where your Lync share is
    LyncShare - CallerIDBlock
  6. Copy the CallerIDBlock.am and BlcokedTelephoneNumbers.txt files to your Lync Share where your new CallerIDBlock folder is
    LyncShare - CallerIDBlock - Script and Numbers
  7. Add the CallerIDBlock script as a Lync Server Application
    1. Open up the Lync Server Manage Shell as an Administrator
      Lync Server Management Shell - Run as administrator
    2. New-CsServerApplication -Identity "Service:Registrar:<Lync Front End Pool>/CallerIDBlock" -Uri http://jackstromberg.com/2015/02/CallerIDBlock -Critical $false -ScriptName "\\<Lync Share Path>\CallerIDBlock\CallerIDBlock.am"
      New-CsServerApplication -Identity CallerIDBlock
  8. Enable the CallerIDBlockLync Server Application
    1. Set-CsServerApplication -Identity "Service:Registrar:<Lync Front End Pool>/CallerIDBlock" -Enabled $true
      Set-CsServerApplication -Identity CallerIDBlock
  9. Verify the script is actively listening for calls
    1. Open up Event Viewer, navigate to Applications and Services Logs, Lync Server, and verify you see Event ID 30208
      Event Viewer - Applications and Services Logs - Lync Server - Event ID 30208

3 thoughts on “[Tutorial] Configuring Lync Server 2013 to block calls based on Caller ID

  1. James

    Hi Jack, Great article and well written easy step by step. I have 2 x front ends (fe-01 & fe-02) and a single pool on each. I have duplicated the scripts and powershell commands on both servers changing paths etc to reflect the server used. I can see the successful creation of the app in the event log on each server but filtering just does not seem to work. There are no event log errors or any sign of a problem other than blocked numbers call in without being blocked. Is there some number context or normalisation required in the BlockedTelephoneNumbers.txt?
    Cheers

    Reply
    1. Jack Post author

      Hi James,

      Make sure you copy and paste the code into notepad first or download the attached text file. Sometimes the character encoding can prevent the scripts from running properly.

      Hope this helps!
      Jack

      Reply

Leave a Reply

Your email address will not be published. Required fields are marked *