Wowza Live Cam Secure Expired Token


Hits: 5645  
Wowza Live Cam Secure Expired Token
Wowza Live Cam Secure Expired Token

wowza-live-cam-secure-expired-token.php
// Encrypt original stream URL http://wowza-server:port/stream/playlist.m3u8
$base64ized = encryptDecrypt($secret_key, $streamURL, 0);

// Decrypt stream URL
$streamURL = encryptDecrypt($secret_key, $base64ized, 1);

stream.php

// Expire stream URL after time interval & check secure token
if (($current – $timestamp) <= $expired && ($checkhash == $hash)) { include("m3u8.php"); } m3u8.php

header(“content-type: application/vnd.apple.mpegurl”);
echo file_get_contents(“http://wowza-server:port/stream/playlist.m3u8”);

Best PHP Encryption Decryption


Hits: 5710  

I was working on Secured & Expired MP3 Link in HTML5 MP3 Player. Hope you already read previous article “Amazon S3 Expiring Link”

You can use below code for hiding real mp3 link inside html source using base64_encode, mcrypt_encrypt, base64_decode, mcrypt_decrypt and md5.

This function is also useful when you need to secure & expire media links …

Remote Secure Token
Secure Token Plugin with PHP
JavaScript Encryption Library

<?php

function encryptDecrypt($key, $string, $decrypt)
{
    if($decrypt)
    {
        
        $string = str_replace("|", "/", $string);
        
        $decrypted = rtrim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, md5($key), base64_decode($string), MCRYPT_MODE_CBC, md5(md5($key))), "12");
        return $decrypted;
    }else{
        $encrypted = base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, md5($key), $string, MCRYPT_MODE_CBC, md5(md5($key))));        
        
        $stripping = true;
        while ($stripping){
         if(substr($encrypted, -1) == "="){
         $encrypted = substr($encrypted, 0, strlen($encrypted)-1);
        } else {
         $stripping = false;
        }
        }
        return str_replace("/", "|", $encrypted);
    }
}


$echo = encryptDecrypt("123", "http://www.svnlabs.com/mp3/svnlabs1.mp3", 0);
echo $echo."<br>";
echo encryptDecrypt("123", $echo, 1);

?>

 

Output:
yTWxdWnzTqh2OHxrfVX5Xxa+K8vGso9|upjRs+oQJLTDmKNyzVfLCvEcvd3ube|Mk+bxxMpijLjAgusr0EDawQ

Reference: http://commons.oreilly.com/wiki/index.php/PHP_Cookbook/Encryption_and_Security

Amazon S3 Expiring Link


Hits: 9706  

I was working on Amazon S3 Cloud HTML5 MP3 Player for S3 Bucket security and Expiring Media links.

Amazon S3 Cloud HTML5 MP3 Player
Amazon S3 Cloud HTML5 MP3 Player
<?php

  if(!function_exists('el_crypto_hmacSHA1')){
      /**
      * Calculate the HMAC SHA1 hash of a string.
      *
      * @param string $key The key to hash against
      * @param string $data The data to hash
      * @param int $blocksize Optional blocksize
      * @return string HMAC SHA1
      */
      function el_crypto_hmacSHA1($key,$data,$blocksize=64){
          if(strlen($key)>$blocksize)$key=pack('H*',sha1($key));
          $key=str_pad($key,$blocksize,chr(0x00));
          $ipad=str_repeat(chr(0x36),$blocksize);
          $opad=str_repeat(chr(0x5c),$blocksize);
          $hmac=pack('H*',sha1(
              ($key^$opad).pack('H*',sha1(
                  ($key^$ipad).$data
              ))
          ));
          returnbase64_encode($hmac);
      }
  }

  if(!function_exists('el_s3_getTemporaryLink')){
      /**
      * Create temporary URLs to your protected Amazon S3 files.
      *
      * @param string $accessKey Your Amazon S3 access key
      * @param string $secretKey Your Amazon S3 secret key
      * @param string $bucket The bucket (bucket.s3.amazonaws.com)
      * @param string $path The target file path
      * @param int $expires In minutes
      * @return string Temporary Amazon S3 URL
      * @see http://awsdocs.s3.amazonaws.com/S3/20060301/s3-dg-20060301.pdf
      */
      function el_s3_getTemporaryLink($accessKey,$secretKey,$bucket,$path,$expires=5){
          // Calculate expiry time
          $expires=time()+intval(floatval($expires)*60);
          // Fix the path; encode and sanitize
          $path=str_replace('%2F','/',rawurlencode($path=ltrim($path,'/')));
          // Path for signature starts with the bucket
          $signpath='/'.$bucket.'/'.$path;
          // S3 friendly string to sign
          $signsz=implode("\n",$pieces=array('GET',null,null,$expires,$signpath));
          // Calculate the hash
          $signature= el_crypto_hmacSHA1($secretKey,$signsz);
          // Glue the URL ...
          $url=sprintf('http://%s.s3.amazonaws.com/%s',$bucket,$path);
          // ... to the query string ...
          $qs=http_build_query($pieces=array(
              'AWSAccessKeyId'=>$accessKey,
              'Expires'=>$expires,
              'Signature'=>$signature,
          ));a
          // ... and return the URL!
          return$url.'?'.$qs;
      }
  }

  ?>

Uses:

$ExpiringLink = el_s3_getTemporaryLink(‘AWS-KEY’, ‘AWS-SECRET-KEY’, ‘BUCKET’, ‘FILENAME’, ‘EXPIRING-TIME’);

Demo Amazon S3 Cloud HTML5 MP3 Player

Reference: http://snipplr.com/view/46753.57507/

PHP Run Background Process using Exec


Hits: 8832  

If you need to start process in background and get its PID to manage it later using PHP.

<?php

function runInBackground($command,$log,$priority=0)
{
if($priority)
   $PID=shell_exec("nohup nice -n $priority $command > $log 2>&1 & echo $!");
else
   $PID=shell_exec("nohup $command > $log 2>&1 & echo $!");
return($PID);
}

?>
PHP Process
PHP Process

echo $! will return process ID
# Command & echo $!

 

Check if process is running

<?php

function isProcessRunning($PID)
{

if($PID==0)return false;
if($PID=="")return false;

exec("ps -p $PID 2>&1",$state);
return(count($state)>=2);

}

?>

 

Display Process Logs

<?php

function displayProcessLog($logfile)
{

exec('cat $logfile 2>&1',$log);
return implode("\r\n",$log);

}

?>

 

Kill Process

<?php

function killProcess($PID)
{
 exec('kill '.$PID.' 2>&1',$status);
 return implode("\r\n",$status);
}

?>

 

Save Process ID to file

#!/bin/bash
Command &
echo $! >/path/to/pid.file

Facebook Adding an App to a Page


Hits: 6542  

You can provide App to Fan Page Tab using URL, but you must check below options to get App (Page Tab) Added Page ID?

https://www.facebook.com/dialog/pagetab?app_id=YOUR_APP_ID&next=YOUR_URL

After successful authorization users will redirect to your Site URL with pageID

http://www.domain.com/?tabs_added[pageID]=1#_=_

App Page Tab Settings
App Page Tab Settings
Add Page Tab Dialog
Add Page Tab Dialog

Integrating with Facebook APIs

When a user selects Page Tab and authorize your application, you receive the signed_request parameter with one additional parameter, page.

JSON object
id (the page id of the current page)
admin (if the user is a admin of the page)
liked (if the user has liked the page).

Option 1: Canvas Page
$signedRequest = $facebook->getSignedRequest();

Option 2: App Domain / Site URL
if(array_key_exists(‘tabs_added’, $_REQUEST)) {
$id = array_keys($_REQUEST[‘tabs_added’]);
$pageId = $id[0];
echo $pageId;
}

Option 3: Page Tab URL
if (!empty($_REQUEST[‘signed_request’])) {
list($encodedSig, $payload) = explode(‘.’, $_REQUEST[‘signed_request’], 2);
$requestData = json_decode(base64_decode(strtr($payload, ‘-_’, ‘+/’)), true);
if (!empty($requestData[‘page’]) && isset($requestData[‘page’][‘id’])) {
$pageId = $requestData[‘page’][‘id’];
echo $pageId;
}
}

Option 4: App Domain / Site URL

<div id='fb-root'></div>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script src='http://connect.facebook.net/en_US/all.js'></script>
<p><a onclick='addToPage(); return false;'>Add to Page</a></p>
<p id='msg'></p>

<script> 
  FB.init({appId: "APP_ID", status: true, cookie: true});

   function addToPage() {

  // calling the API ...
  FB.ui(
    {
        method: 'pagetab'
    },
    function(response) {
        if (response != null && response.tabs_added != null) {

            $.each(response.tabs_added, function(pageid) {
                  alert(pageid);
            });
        }
    }
  );


  }

</script>

Your app will also receive string parameter app_data as part of signed_request if app_data parameter was set in the original query string in the URL your tab is loaded on.

“https://www.facebook.com/YourPage?v=app_APP_ID&app_data=STRING”

Amazon S3 Cloud HTML5 MP3 Player


Hits: 4601  

Amazon S3 Cloud HTML5 Player plugin that allows you to link to your amazon S3 bucket and sets up a HTML5 Player playlist (horizontal or vertical). This plugin will support MP3 files only.

Amazon S3 Cloud HTML5 MP3 Player is not associated in any way to amazon.com

Get Self Hosted Amazon S3 Cloud HTML5 MP3 Player for WordPress just in $24

You will need an amazon account to use this.

AWS access info

Add your amazon information amazon key and amazon secret key. Then just add the bucket to your account add folders.

Amazon S3 Cloud HTML5 MP3 Player Options
Amazon S3 Cloud HTML5 MP3 Player Options

Make sure you have public permission for all your music in your S3 buckets and folders.

S3 Management Console
S3 Management Console

Shortcode for Page or Post

[html5aws3mp3 player=”horizontal” bucket=”BUCKET” endpoint=”BUCKET-ENDPINT” folder=”FOLDER/”]

Plugin Page

Amazon S3 Error Handling

AWS CloudFront with PHP

Create sub buckets on amazon s3

Amazon S3 Cloud HTML5 MP3 Player is not associated in any way to amazon.com

Amazon S3 Error Handling


Hits: 6048  

Amazon S3 PHP Class A standalone Amazon S3 (REST) client for PHP 5.2.x using CURL that does not require PEAR.

AWS Management Console Home
AWS Management Console Home

AMAZON S3 (Scalable Storage in the Cloud) PHP CLASS

AWS access info
AWS access info

// AWS access info
if (!defined(‘awsAccessKey’)) define(‘awsAccessKey’, ‘CHANGE-KEY’);
if (!defined(‘awsSecretKey’)) define(‘awsSecretKey’, ‘CHANGE-KEY’);

OO method (e,g; $s3->getObject(…)):
$s3 = new S3(awsAccessKey, awsSecretKey);

Statically (e,g; S3::getObject(…)):
S3::setAuth(awsAccessKey, awsSecretKey);

Warning: S3::getBucket(): [PermanentRedirect] The bucket you are attempting to access must be addressed using the specified endpoint. Please send all future requests to this endpoint.

We need to End Point for our S3 Buckets by default it’s s3.amazonaws.com

$s3 = new S3(awsAccessKey, awsSecretKey);

S3 Management Console
S3 Management Console

Else we need to specify here… s3-ap-southeast-1.amazonaws.com

S3 Management Console
S3 Management Console

$s3 = new S3(awsAccessKey, awsSecretKey, true, ‘s3-ap-southeast-1.amazonaws.com‘);

Warning: S3::getBucket(): [60] SSL certificate problem, verify that the CA cert is OK. Details: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed

We need SSL enabled with CURL 😉

OpenSSL phpinfo()
OpenSSL phpinfo()
CURL With OpenSSL phpinfo()
CURL With OpenSSL phpinfo()

For class documentation see:
http://undesigned.org.za/files/s3-class-documentation/index.html

HTML5 MP3 Lyrics Player


Hits: 6216  

HTML5 Lyrics Karaoke Player Plugin enable wordpress users to sing and play song text lyrics.

Free Features

  • Supports MP3 formats
  • Supports Text Song Lyrics
  • Social Links Facebook / Twitter
  • Works in IE, Safari, Firefox, Chrome, Opera
  • Player have shortcode for post/page [html5lyrics id=ID] i.e. [html5lyrics id=1]

Paid Features

  • Supports MP3 formats
  • Supports Text Song Lyrics
  • Support Images on song’s cue points
  • Color / Size Customization
  • Supports Unicode
  • Social Link Customization
  • Multiple player on same page / post
  • Works in IE, Safari, Firefox, Chrome, Opera, mobile devices including Android/iOS
  • Supports Wowza / Amazon Cloud Front / S3 HTTP Streaming
  • Facebook page customization with player
  • Player have shortcode for post/page [html5lyrics id=ID … ] i.e. [html5lyrics id=1 … ]
  • Best support on email / skype

Note: It uses native <audio> where available and an invisible flash player to emulate <audio> for other browsers.
It provides a consistent html player UI to all browsers which can be styled used standard css.

Browser & format support

With Flash as a fallback, it should work pretty much anywhere.

It has been verified to work across:

– Mobile Safari (iOS 3+)
– Android (2.2+, w/Flash), Android (4.0+)
– Safari (4+)
– Chrome (7+)
– Firefox (3+, w/ Flash)
– Opera (10+, w/ Flash)
– IE (6, 7, 8, w/ Flash)

Demo

Get fully customized HTML5 Lyrics Karaoke Player for Website Buy Now or Contact Us

Standalone

  

Screenshots

html5-lyrics-karaoke-player screenshot 2

Create HTML5 Lyrics Karaoke Player with MP3 & text

html5-lyrics-karaoke-player screenshot 3

Manage other HTML5 Lyrics Karaoke Songs

html5-lyrics-karaoke-player screenshot 4

Proccess HTML5 Lyrics Karaoke Song -> Listen then click same lyrics text

html5-lyrics-karaoke-player screenshot 5

WordPress Shortcode for HTML5 Lyrics Karaoke Player

Credit

Audio.js Player

HTML5 Audio Read-Along

Javascript Widget versues iFrame


Hits: 3677  

I was creating a HTML5 Video Ads widget for my clients websites. So if I need to make it in JavaScript or iFrame?

<iframe src=”http://html5.svnlabs.com/videoads/16″></iframe>

But I don’t think iFrame would be the best method, if I need to hide URL from direct access.

Another option is something like this:

<script type=”text/javascript”>id = ’16’;</script>

<script src=”http://html5.svnlabs.com/videoads/” type=”text/javascript”></script>

 

iFrame

– Resizing is typical to the parent window without smart work.
– Better isolation cannot access anything on the parent page.
– No JavaScript experience required.
– Own independent CSS styles.
– Functional on scripting disabled.

 

JavaScript

– Full access to the parent page.
– Slow down page as script load before rendering the rest of the page.
– Experience with JavaScript needed on parent page.
– Experience with CSS styles needed on parent page.

 

So here is conclusion 😉

* You have more control on the design in case of an iFrame.
* iFrame is better in terms of security because cookies stored are different.
* JavaScript widget needs more care on other JavaScript conflict.
* Use JavaScript that writes an iFrame dynamically to avoid direct URL access.