Here is a complete Wowza Module to deny hotlinking server-side. Compile this in the Wowza IDE:
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 ModuleHotlinkDenial extends ModuleBase {
public void onConnect(IClient client, RequestFunction function,
AMFDataList params) {
getLogger().info("ModuleHotlinkDenial onConnect: " + client.getClientId());
String flashver = client.getFlashVer().toLowerCase();
getLogger().info("ModuleHotlinkDenial Client Flashver: " + flashver);
try
{
String[] allowedEncoder = null;
allowedEncoder = client.getAppInstance().getProperties().getPropertyStr("AllowEncoder","").toLowerCase().split(",");
if ( allowedEncoder != null )
{
for (int i = 0; i < allowedEncoder.length; i++)
{
if (flashver.startsWith(allowedEncoder[i].trim()) && allowedEncoder[i].length()>0)
{
getLogger().info("ModuleHotlinkDenial Encoder Allowed: "+flashver+" matches "+allowedEncoder[i]);
client.acceptConnection();
return;
}
}
}
}
catch (Exception e)
{
getLogger().info("ModuleHotlinkDenial Exception: " + e.getMessage());
}
boolean reject = true;
String[] domainLocks = null;
String[] domainUrl = null;;
try
{
domainLocks = client.getAppInstance().getProperties().getPropertyStr("domainLock").toLowerCase().split(",");
String pageUrl = client.getProperties().getPropertyStr("connectpageUrl").toLowerCase();
domainUrl = pageUrl.split("/");
getLogger().info("domainLock: " + client.getAppInstance().getProperties().getPropertyStr("domainLock").toLowerCase());
getLogger().info("pageUrl: " + pageUrl);
for (int i = 0; i < domainLocks.length; i++)
{
if (domainLocks[i].trim().startsWith("*"))
{
String lock = domainLocks[i].trim().substring(1);
if (domainUrl[2].endsWith(lock))
{
reject = false;
}
}
else if (domainUrl[2].equalsIgnoreCase(domainLocks[i].trim()))
{
reject = false;
}
}
}
catch(Exception ex)
{
reject = true;
}
if (reject)
{
getLogger().info("Client Rejected. IP: " + client.getIp());
client.rejectConnection();
}
}
}
Code:
<Module> <Name>Hotlink Denial</Name> <Description>Hotlink Denial Module</Description> <Class>com.wowza.wms.plugin.collection.module.ModuleHotlinkDenial</Class> </Module>
Code:
<Property> <Name>domainLock</Name> <Value>localhost,mysite.com</Value> </Property> <Property> <Name>AllowEncoder</Name> <Value>Wirecast</Value> <!--FM, Wirecast--> </Property>
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.
- Click here, if you are having problems or would like to discuss this article.
- Leave a comment below, if there is some aspect of this article you would like to see changed or improved.


Article List
Categories
Wowza Media