All posts by Manish

Playing RTMP in Browser without FLASH

RTMP is used for streaming live video. With a bit of manipulation of the frontend codes it can also be used to play audio only (the below code does that)

Now the thing is playing RTMP link in browser requires Flash which is not supported by Apple and Linux based OS. The solution is to use the HLS link instead of the RTMP link. The HLS format is supported by most browsers and by Apple and Linux based OS also.

One thing to note is the MIME type of the source.

There are various Javascript libraries that can be used to build the player. Below is an example using Video.js

This internally uses the http-streaming library of Videojs. Details of the library can be found here  This library is included in video.js 7 by default. Hence in the below code  it has not been added separately

<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Live Streaming</title>
    <link href="https://vjs.zencdn.net/7.6.6/video-js.css" rel="stylesheet" />

	<!-- If you'd like to support IE8 (for Video.js versions prior to v7) -->
	<script src="https://vjs.zencdn.net/ie8/1.1.2/videojs-ie8.min.js"></script>
	<script src="https://vjs.zencdn.net/7.6.6/video.js"></script>
</head>
<body>
<audio id="player" class="video-js vjs-default-skin" height="70" width="300" controls autoplay preload="none">
    <source src="https://rtmpserverBaseUrl/path/streamName.m3u8" type="application/x-mpegURL" />
</audio>

<script>
    var player = videojs('#player');
    videojs('player').ready(function() {
       this.play();
    });
</script>

<style>
.vjs-seek-to-live-control,
.vjs-fullscreen-control,
.vjs-picture-in-picture-control
 {
   display: none;
 }
</style>

</body>
</html>

Code courtesy – https://github.com/videojs/http-streaming

Both libraries used in the code can be downloaded from here
videojs version 7.6.6
videojs-ie8.min version 1.1.2

JS library for Image Manipulation

The below links has various image processing functionality implemented using Javascript. They can be useful to implement various image processing functionality in website frontend.

www.marvinj.org/en/index.html

gitHub.com/inspirit/jsfeat
Some features of this library are

  • Basic image processing methods (grayscale, derivatives, box-blur, resample, etc.)
  • Grayscale
  • Box blur
  • Gaussian blur
  • Equalize histogram
  • Fast Corners feature detector
  • YAPE06 feature detector
  • YAPE feature detector
  • ORB feature descriptor
  • HAAR object detector
  • BBF object detector

Adding IPv6 to existing server (DigitalOcean)

While creating the server I didn’t add any IPv6 address. Later from the Control Panel I enabled IPv6 but the address didn’t get attached to ETH0.

Needed to do:

  • Edit the /etc/network/interfaces.d/50-cloud-init.cfg file
  • Add
# control-alias eth0
iface eth0 inet6 static
address 2400:xxxx:xxxx:xxxx:xxxx:xxxx:0000:6001/64
gateway 2400:xxxx:xxxx:xx::x
autoconf 0
dns-nameservers 2001:xxxx:xxxx::xxxx 2001:xxxx:xxxx::xxxx
  • The gateway and nameservers are important.
  • The NameServers are that of the server provider

Check DNS with DIG command

General Query

dig @ns2.dnsserver.com TXT domain.com +short   

With the +short it will show only the value of the queried field(s). Without +short  it will show the full result

 

Querying CNAME records 

dig @ns2.dnsserver.com CNAME 4xugchxxxxxxxxxxxxxxxxxx3eread3uc._domainkey.domain.com +short

This will return the value of that particular CNAME field.

 

Querying particular entry

dig @ns2.dnsserver.com TXT domain.com +short
dig @ns2.dnsserver.com NS domain.com +short

 

Bind server not responding to external queries

Recently I ran into a problem where one DNS server setup using Bind9 was not responding to external queries.

systemctl status bind9 –no-pager –full  shows “Denied

Common issues (listed below) that can cause the problem were not there.

  1. Bind9 was running properly
  2. The server was listening on both IPv4 and IPv6
  3. Port 53 was open
  4. The DNS server or port 53 could be connected using Telnet

 

The issue was with “recursive query” permissions. To allow external queries needed to add the following option

options {
   ...
   ...
     allow-recursion { any; };
   ...
   ...
}

The options are commonly stored in /etc/bind/named.conf.options for Bind9 servers.

Manually adding a DNS Zone to Bind9 server

  • Create a Zone file in /etc/bind/  Example – /etc/bind/pri.domain.com
  • Add the entries . Example below
    $TTL 3600
    @ IN SOA ns2.dnserver.net. manish.gmail.com. (
    2019051606 ; serial, todays date + todays serial #
    7200 ; refresh, seconds
    540 ; retry, seconds
    604800 ; expire, seconds
    3600 ) ; minimum, seconds
    ;
    
    domain.com. 3600 A xxx.xxx.xxx.xxx
    mail 3600 A xxx.xxx.xxx.xxx
    www 3600 A xxx.xxx.xxx.xxx
    domain.com. 3600 AAAA xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx
    mail 3600 AAAA xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx
    www 3600 AAAA xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx
    domain.com. 3600 MX 10 mail.domain.net.
    domain.com. 3600 NS ns1.dnserver.net.
    domain.com. 3600 NS ns2.dnserver.net.
    domain.com. 3600 TXT "v=spf1 mx a ~all"
    default._domainkey.domain.com. 3600 TXT "v=DKIM1; t=s; p=......NBgkqhki................................................"
    _dmarc.domain.com. 3600 TXT "v=DMARC1; p=quarantine"
  • Add the zone to /etc/bind/named.conf.local . Example below

    zone "domain.com" {
        type master;
        allow-transfer {none;};
        file "/etc/bind/pri.domain.com";
    };
  • service bind9 restart for Ubuntu and likes. For CentOS and likes service named restart

Two Way Encryption or Hashing using Key

This is using PHP and openssl_decrypt/openssl_encrypt

Encrypting the string

$key = "xxxxxxxxxxx"; //11 characters
$ivlen = openssl_cipher_iv_length("aes-256-cbc-hmac-sha256");
$iv = openssl_random_pseudo_bytes($ivlen);
$hash = openssl_encrypt(STRING TO HASH,"aes-256-cbc-hmac-sha256",$key,0,$iv);
$iv = bin2hex($iv); // iv generated is in binary - converted to HEX for passing through SESSION or POST or URL

Decrypting back the string

$key = "xxxxxxxxxxx";
$hash = HASH FROM ENCRYPTION;
$iv = IV FROM ENCRYPTION STEP; //note this is in HEX and needs to be converted back to BIN 
$iv = hex2bin($iv); //convert the IV in HEX to BIN

$decryptedString = openssl_decrypt($hash,"aes-256-cbc-hmac-sha256",$key,0,$iv);

Feel free to explore other algorithms