• How to limit publishing of live streams by IP list

    Use this in a live application to limit publishing to allowed IP addresses. IP list is set in Application.xml property.
    Code:
    package com.wowza.wms.plugin.collection.module;
    
    import com.wowza.wms.amf.*;
    import com.wowza.wms.client.*;
    import com.wowza.wms.module.*;
    import com.wowza.wms.request.*;
    
    public class ModuleOverridePublishRestrictIP extends ModuleBase {
    	
    	public void publish(IClient client, RequestFunction function,
    	        AMFDataList params) {
    		getLogger().info("Overriding Publish");
    		
    		boolean reject = true;
    		String[] ipList = null;
    			
    		try 
    		{ 
    		ipList = client.getAppInstance().getProperties().getPropertyStr("ipList").toLowerCase().split(",");
    		String clientIP = client.getIp();
    		for (int i = 0; i < ipList.length; i++)
    		{ 
    			if (clientIP.equalsIgnoreCase(ipList[i].trim()))
    			{
    				reject = false; 
    			}
    		} 
    		} 
    		catch(Exception ex)
    		{
    			reject = true;
    		}
    		if (reject)
    		{	
    			sendClientOnStatusError(client, "NetStream.Publish.Denied", "The publisher's IP was rejected");
    			getLogger().info("Client Rejected. IP: " + client.getIp());
    		} 
    		else
    		{	
    			invokePrevious(client, function, params);
    		}		
    	}
    	
    	public void releaseStream(IClient client, RequestFunction function, AMFDataList params)
    	{
    		getLogger().info("Overriding streamRelease");
    		
    		boolean reject = true;
    		String[] ipList = null;
    			
    		try 
    		{ 
    		ipList = client.getAppInstance().getProperties().getPropertyStr("ipList").toLowerCase().split(",");
    		String clientIP = client.getIp();
    		for (int i = 0; i < ipList.length; i++)
    		{ 
    			if (clientIP.equalsIgnoreCase(ipList[i].trim()))
    			{
    				reject = false; 
    			}
    		} 
    		} 
    		catch(Exception ex)
    		{
    			reject = true;
    		}
    		if (reject)
    		{
    			sendClientOnStatusError(client, "NetStream.Publish.Denied", "The publisher's IP was rejected");
    			getLogger().info("Client Rejected. IP: " + client.getIp());
    		} 
    		else
    		{			
    			invokePrevious(client, function, params);	
    		}		
    		
    	}
    	
    }
    A compiled version of this module is included in the Wowza Modules Collection. Download and unzip the collection, then copy /lib/wms-plugin-collection.jar from the package to the Wowza /lib folder. Then restart Wowza.

    Add the following module to the Modules list of your Application.xml.

    Code:
    <Module>
    	<Name>OverridePublishLimitIP</Name>
    	<Description>Override publish</Description>
    	<Class>com.wowza.wms.plugin.collection.module.ModuleOverridePublishRestrictIP</Class>
    </Module>
    And add this Property to the Properties section of your Application.xml, below the Modules list:

    Code:
    <Property>
    	<Name>ipList</Name>
    	<Value>127.0.0.1</Value>
    </Property>

    Comments 4 Comments
    1. project3 -
      How to add the first part where exactly does that go?
    1. rrlanham -
      You need the Wowza IDE:

      http://wowzamedia.com/ide.html

      Richard
    1. musarano -
      Hi,

      Its been long time that i do not post around here.
      But, seen this, i would like to know IF there is a easy way to instead of limiting a given xml IPaddress, but to limit encoder(s) sessions to be only 1 (first started for example)

      * If an encoder is already connected/encoding then to denny connections from all the others, no matter the stream name. *

      Is it possible to do this with an add-on on the application.xml and using the collection already?

      Thank You

      -Musarano.
    1. daren_j -
      You should be able to adapt ModuleLimitConnectionsToApplication from the module collection to do what you need:

      http://www.wowza.com/forums/content....an-application

      Best regards,
      Daren