Results 1 to 4 of 4

Thread: Determine whether onConnect call is made by encoder or player

  1. #1

    Default Determine whether onConnect call is made by encoder or player

    Hi folks!

    I'm making a custom hotlink denial module (one that doesn't look for an authorized encoder & IP address), and I'm trying to determine whether onConnect is being called from encoders or players. Right now I just check this value for null (the value it gets when encoders call):

    String pageUrl = client.getProperties().getPropertyStr("connectpageUrl");
    However, I realize that a null value could be passed for other reasons too. So I'm looking for a better way to tell whether it's a player calling (in which case, use the domain lock) or an encoder (skip the domain lock).

    This is the code for my custom hotlink denial 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) { 
    		String clientip = client.getIp(); 
    		getLogger().info("onConnect HotlinkDenial Module: " + client.getClientId()); 
    		getLogger().info("onConnect HotlinkDenial Module Client IP: " + clientip); 
    	   
    		client.acceptConnection(); 
    
    		String[] domainLocks = null; 
    		String[] domainUrl = null; 
    	    
    		Boolean reject = true; 
    		try {  
    			domainLocks = client.getAppInstance().getProperties().getPropertyStr("domainLock").toLowerCase().split(","); 
    			String pageUrl = client.getProperties().getPropertyStr("connectpageUrl"); 
    			
    			if (pageUrl == null){
    				return;
    			}
    			
    			pageUrl = pageUrl.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("onConnect HotlinkDenial Module: rejected client "+client.getClientId()+" IP " + client.getIp()); 
    			client.rejectConnection(); 
    		} 
    	} 
    }
    Thanks very much for your help!

  2. #2

    Default

    Don't use "onConnect"! Use "play" and "publish".

  3. #3

    Default

    Oh, geez - didn't even think of that! I guess they used "onConnect" in the original hotlink denial module because they were checking for both play and publish information. But since I only need "play" information (since we don't need domainLock checks for encoders) I switched to using "play" and it works fine now Thanks very much!

    This is the final code, in case anybody's trying to do something similar:

    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 play(IClient client, RequestFunction function, AMFDataList params) {
    		String clientip = client.getIp(); 
    		getLogger().info("onConnect HotlinkDenial Module: " + client.getClientId()); 
    		getLogger().info("onConnect HotlinkDenial Module Client IP: " + clientip); 
    		
    		String[] domainLocks = null; 
    		String[] domainUrl = null; 
    	    
    		Boolean reject = true; 
    		try {  
    			domainLocks = client.getAppInstance().getProperties().getPropertyStr("domainLock").toLowerCase().split(","); 
    			String pageUrl = client.getProperties().getPropertyStr("connectpageUrl"); 
    			
    			if (pageUrl != null){
    				pageUrl = pageUrl.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("onConnect HotlinkDenial Module: rejected client "+client.getClientId()+" IP " + client.getIp()); 
    			client.rejectConnection(); 
    			return;
    		} 
    		
    		this.invokePrevious(client, function, params);
    	}
    }

  4. #4
    Join Date
    Dec 2007
    Posts
    21,962

    Default

    Why not use the source here:

    http://www.wowza.com/forums/content....-your-SWF-file

    There is no IP checking. You can look at client.flashVer() to see if the client is a swf file or an encoder

    Richard

Similar Threads

  1. Replies: 3
    Last Post: 07-15-2014, 01:59 PM
  2. Willow | Wowza Media Server Management made easy
    By GraemeBull in forum Showcase
    Replies: 15
    Last Post: 03-18-2014, 02:49 AM
  3. Modifications made to module not executed by WMS
    By jpicaude in forum Tutorials Discussion
    Replies: 2
    Last Post: 09-07-2012, 12:05 AM
  4. Replies: 2
    Last Post: 10-23-2011, 11:24 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •