Skip to content

Commit

Permalink
changed files structure
Browse files Browse the repository at this point in the history
  • Loading branch information
WMSPanel committed Jul 14, 2015
1 parent fb99025 commit e7c13a1
Show file tree
Hide file tree
Showing 14 changed files with 108 additions and 112 deletions.
2 changes: 1 addition & 1 deletion CSharp/URLProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@ public static string BuildProtectedURLWithValidity(string password, string media

public static void Main()
{
Console.WriteLine(BuildProtectedURLWithValidity("defaultpassword", "http://127.0.0.1:1935/vod/sample.mp4/playlist.m3u8", "127.0.0.1", 20));
Console.WriteLine(BuildProtectedURLWithValidity("defaultpassword", "http://yourdomain.com:8081/vod/sample.mp4/playlist.m3u8", "127.0.0.1", 20));
}
}
27 changes: 17 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,20 @@ WMSAuth Paywall is a feature set of WMSPanel which is the admin and reporting pa

Please read Paywall section of WMSPanel website for details: https://wmspanel.com/paywall

Current sample code snippets are provided for quick and seamless integration of hot-linking protection.

- "CSharp" contains snippet for C# modofying RTSP stream URL
- "java" contains Java snippet for RTSP
- "javascript" has NodeJS JavaScript sample snippet
- "php" has snippet for PHP processing of RTSP URL
- "php-jwplayer" has a code which contains JWPlayer with HLS and RTMP streams. It also has example of PHP code for cases when your server works from behind the proxy.
- "php-rtmp-flowplayer" is a sample for flowpayer with RTMP stream
- "python" is obviously a Python sample
- "stream-signature" is an example of media stream signature with stream name in it
Current sample code snippets are provided for quick and seamless integration of hot-linking protection. The repository directories have the code as described below.

"CSharp" contains C# snippet

"java" contains Java snippet

"javascript" contains NodeJS JavaScript snippet

"python" contains Python snippet

"php" contains snippets for PHP:
- jwpayer-rtmp-hls.php - code sample for JWPlayer with RTMP and HLS
- jwpayer-rtmp-hls-with-proxy.php - code sample for JWPlayer with RTMP and HLS which has IP address obtained from various headers
- rtmp-flowplayer.php - Flowplayer sample with RTMP
- basic-hls-rtmp-obfuscation.php - basic sample for HLS and RTMP with code obfuscation agains grabbers.
- basic-hls-stream-based.php - basic sample for HLS where signature includes streams name
- basic-rtsp.php - basic sample for RTSP
2 changes: 1 addition & 1 deletion java/src/main/java/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public static void main(String[] args) throws UnsupportedEncodingException {
DateTimeFormatter timeFormatter = DateTimeFormat.forPattern("M/d/y h:m:s a").withZone(DateTimeZone.UTC).withLocale(Locale.US);
DateTime currentServerTime = new DateTime(DateTimeZone.UTC); // lets get localtime in UTC timezone
String today = timeFormatter.print(currentServerTime);
String initial_url = "rtsp://ec2-test-ip.compute.amazonaws.com:1935/live";
String initial_url = "http://yourdomain.com:8081/live";
String video_url = "/Stream1";
String ip = "127.0.0.1";
String key = "defaultpassword";
Expand Down
2 changes: 1 addition & 1 deletion javascript/wmsauth-example.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
var today = (new Date()).format("UTC:m/d/yyyy h/MM/ss TT");
var initial_url = "rtsp://ec2-test-ip.compute.amazonaws.com:1935/live/Stream1";
var initial_url = "http://yourdomain.com:8081/live/stream/playlist.m3u8";
var ip = req.connection.remoteAddress;
var key = "defaultpassword";
var validminutes = 20;
Expand Down
Binary file removed php-rtmp-flowplayer/bunny.jpg
Binary file not shown.
Binary file removed php-rtmp-flowplayer/play_text_large.png
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?php
/*
This code example for obfuscating URL and its WMSAuth paywall signature to avoid parsing.
*/
$today = gmdate("n/j/Y g:i:s A");
$ip = $_SERVER['REMOTE_ADDR'];
$key = "YOUR_PASSWORD";
Expand All @@ -9,11 +12,15 @@
$urlsignature = "server_time=" . $today ."&hash_value=" . $base64hash. "&validminutes=$validminutes";
$base64urlsignature = base64_encode($urlsignature);

$rtmpbegin = "rtmp://bestsite.my/mylive?wmsAuthSign=";
$rtmpend = "mystream";
//For RTMP, the signature is inserted after application name.
$rtmpurl = "rtmp://bestsite.my/mylive?wmsAuthSign=";
$rtmpstream = "mystream";
//For HLS, the signature is inserted at the end of the URL
$httpurl = "http://bestsite.my/mylive/mystream?wmsAuthSign=";

$rtmpbeginarray = str_split($rtmpbegin, 1);
$rtmpendarray = str_split($rtmpend, 1);
$rtmpurlarray = str_split($rtmpurl, 1);
$rtmpstreamarray = str_split($rtmpstream, 1);
$httpurlarray = str_split($httpurl, 1);

$firstsigpart = substr($base64urlsignature, 0, -48);
$lastsigpart = substr($base64urlsignature, -48);
Expand All @@ -23,7 +30,8 @@
$fakesignaturearray = str_split($firstsigpart, 3);

$getrtmptitle = str_shuffle("getRtmpUrl");
$getrtmpfiletitle = str_shuffle("getRtmpFile");
$getrtmpstreamtitle = str_shuffle("getRtmpStream");
$gethttptitle = str_shuffle("getHttpUrl");
$shiftbacktitle = str_shuffle("shiftBackSignature");
$fakeshiftbacktitle = str_shuffle("shiftBeckSignature");
$signaturetitle = str_shuffle("baseUrlSignatureArray");
Expand Down Expand Up @@ -65,22 +73,29 @@
?>

jwplayer("mediaspace").setup({
flashplayer: "player.swf",
sources: [{
file: <?php echo($getrtmptitle . "()"); ?> + '/' + <?php echo($getrtmpstreamtitle . "()"); ?>
},{
file: <?php echo($gethttptitle . "()"); ?>
}],
width: '468',
height: '380',
allowfullscreen: 'true',
allowscriptaccess: 'always',
streamer: <?php echo($getrtmptitle . "()"); ?>,
file: <?php echo($getrtmpfiletitle . "()"); ?>,
repeat: 'always'
});

function <?php echo($getrtmptitle . "()"); ?> {
return(<?php echo(json_encode($rtmpbeginarray)); ?>.join("") + <?php echo($signaturetitle); ?>.join("") + document.getElementById("<?php echo($shiftbacktitle); ?>").innerHTML);
return(<?php echo(json_encode($rtmpurlarray)); ?>.join("") + <?php echo($signaturetitle); ?>.join("") + document.getElementById("<?php echo($shiftbacktitle); ?>").innerHTML);
}

function <?php echo($getrtmpfiletitle . "()");?> {
return(<?php echo(json_encode($rtmpendarray)); ?>.join(""));
function <?php echo($getrtmpstreamtitle . "()");?> {
return(<?php echo(json_encode($rtmpstreamarray)); ?>.join(""));
}

</script>
function <?php echo($gethttptitle . "()"); ?> {
return(<?php echo(json_encode($httpurlarray)); ?>.join("") + <?php echo($signaturetitle); ?>.join("") + document.getElementById("<?php echo($shiftbacktitle); ?>").innerHTML);
}


</script>
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
<?php

# CAUTION:
# This example is applicable for the streams generated by Nimble Streamer only.
# This code will cause errors in case you use it for other media servers.
/*
This is a sample code for adding WMSAuth paywall signature to HLS stream.
THe signature is mapped to exact stream name as described in
http://blog.wmspanel.com/2014/10/stream-name-hotlink-protection.html
AUTION:
This example is applicable for the streams generated by Nimble Streamer only.
This code will cause errors in case you use it for other media servers.
*/

$today = gmdate("n/j/Y g:i:s A");
$initial_url = "http://video.wmspanel.com/live/stream/playlist.m3u8";

//Part of the stream name which is being use in signature
$signed_stream = "live/stream";

$ip = $_SERVER['REMOTE_ADDR'];
Expand Down
4 changes: 4 additions & 0 deletions php/sample.php → php/basic-rtsp.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
<?php
/*
This is a sample code for adding WMSAuth paywall signature to RTSP stream.
For RTSP, the signature is inserted after application name.
*/

$today = gmdate("n/j/Y g:i:s A");

Expand Down
61 changes: 0 additions & 61 deletions php/javascript_signature.php

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
<?php
/*
This is a sample code for adding WMSAuth paywall signature to RTMP and HLS streams.
The player is JWPlayer.
The IP address is obtained via any available header.
This includes headers from proxies and CloudFront.
For RTMP, the signature is inserted after application name.
For HLS, the signature is inserted at the end of the URL
*/

$today = gmdate("n/j/Y g:i:s A");

$ip = $_SERVER['REMOTE_ADDR'];
Expand Down
11 changes: 9 additions & 2 deletions php-jwplayer/jwpayer-sample.php → php/jwpayer-rtmp-hls.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
<?php
/*
This is a sample code for adding WMSAuth paywall signature to RTMP and HLS streams.
The player is JWPlayer.
For RTMP, the signature is inserted after application name.
For HLS, the signature is inserted at the end of the URL
*/
$today = gmdate("n/j/Y g:i:s A");
$ip = $_SERVER['REMOTE_ADDR'];
$key = "defaultpassword";
Expand All @@ -15,9 +22,9 @@
jwplayer("my-video").setup({
playlist: [{
sources: [{
file: "rtmp://streamserver.yourdomain.com/live?wmsAuthSign=<?php echo $base64urlsignature;?>/mp4:my-stream.sdp"
file: "rtmp://yourdomain.com/live?wmsAuthSign=<?php echo $base64urlsignature;?>/mp4:my-stream.sdp"
},{
file: "http://streamserver.yourdomain.com:1935/live/mp4:my-stream.sdp/playlist.m3u8?wmsAuthSign=<?php echo $base64urlsignature;?>"
file: "http://yourdomain.com:1935/live/mp4:my-stream.sdp/playlist.m3u8?wmsAuthSign=<?php echo $base64urlsignature;?>"
}]
}],
height: 480,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,26 @@
<?php
/*
This is a sample code for adding WMSAuth paywall signature to RTMP VOD stream.
The player is Flowplayer.
In this example the source media is located at
rtmp://server.test.com:1935/vod/mp4:sample.mp4
Flow player has the name split by 2 part. They are stored in respective variables below.
*/
$base_url = 'rtmp://server.test.com:1935/vod';
$video_url = 'mp4:sample.mp4';

$today = gmdate("n/j/Y g:i:s A");
$ip = $_SERVER['REMOTE_ADDR'];
$key = "default"; //enter your key here
$validminutes = 20;
$str2hash = $ip . $key . $today . $validminutes;
$md5raw = md5($str2hash, true);
$base64hash = base64_encode($md5raw);
$urlsignature = "server_time=" . $today ."&hash_value=" . $base64hash. "&validminutes=$validminutes";
$base64urlsignature = base64_encode($urlsignature);
?>

<!DOCTYPE html>
<html>
<head>
Expand Down Expand Up @@ -25,28 +48,10 @@

</head>
<body>
<?php
/*
In this example the source media is located at
rtmp://server.test.com:1935/vod/mp4:sample.mp4
Flow player has the name split by 2 part. They are stored in respective variables below.
*/
$base_url = 'rtmp://server.test.com:1935/vod';
$video_url = 'mp4:sample.mp4';

$today = gmdate("n/j/Y g:i:s A");
$ip = $_SERVER['REMOTE_ADDR'];
$key = "default"; //enter your key here
$validminutes = 20;
$str2hash = $ip . $key . $today . $validminutes;
$md5raw = md5($str2hash, true);
$base64hash = base64_encode($md5raw);
$urlsignature = "server_time=" . $today ."&hash_value=" . $base64hash. "&validminutes=$validminutes";
$base64urlsignature = base64_encode($urlsignature);
?>
<div class="box black">
<a class="rtmp" href="<?php echo $video_url; ?>" style="background-image:url(bunny.jpg)">
<img src="play_text_large.png" />
<a class="rtmp" href="<?php echo $video_url; ?>" style="background-image:url(placeholder.jpg)">
<img src="play_button.png" />
</a>
</div>

Expand Down
2 changes: 1 addition & 1 deletion python/wmsauth.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
ip = "127.0.0.1"
password = "defaultpassword"
validminutes = "10"
initial_url = "http://127.0.0.1:1935/vod/sample.mp4/playlist.m3u8"
initial_url = "http://yourdomain.com:8081/vod/sample.mp4/playlist.m3u8"

m = md5.new()
m.update(ip + password + today + validminutes)
Expand Down

0 comments on commit e7c13a1

Please sign in to comment.