Skip to content

Instantly share code, notes, and snippets.

@anikishov
Last active February 26, 2020 21:23
Show Gist options
  • Save anikishov/d7604e88c7dd9f0841ec19b07bc06bac to your computer and use it in GitHub Desktop.
Save anikishov/d7604e88c7dd9f0841ec19b07bc06bac to your computer and use it in GitHub Desktop.

Revisions

  1. anikishov revised this gist May 21, 2019. 1 changed file with 6 additions and 0 deletions.
    6 changes: 6 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -33,6 +33,10 @@ server {
    fastcgi_pass unix:/run/php/php7.2-fpm.sock;
    }
    }

    # turn on auth_backend site in nginx (create simlink)

    ln -s /etc/nginx/sites-available/auth_backend /etc/nginx/sites-enabled/

    # Create a directory for the site and put here auth_backend script

    @@ -97,6 +101,8 @@ user3:token3
    # Ctrl+O - for save file
    # Ctrl+X - close editor

    chmod 755 -R /var/www/auth_backend/

    # For apply changes restart nginx
    service nginx restart

  2. anikishov revised this gist May 20, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    Hi,

    For configuring auth_backend & inserting ads on PHP needed to create an external web server, for example, nginx
    For configuring auth_backend & inserting ads on PHP needed to use web server, for example, nginx

    # install php and nginx
    apt update
  3. anikishov revised this gist May 20, 2019. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -6,6 +6,9 @@ For configuring auth_backend & inserting ads on PHP needed to create an external
    apt update
    apt install nginx php7.2-fpm

    # turn on socket listening in php-fpm

    echo "listen = /run/php/php7.2-fpm.sock" >> /etc/php/7.2/fpm/php-fpm.conf

    # type next command:

  4. anikishov revised this gist May 18, 2019. 1 changed file with 3 additions and 2 deletions.
    5 changes: 3 additions & 2 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,8 @@
    Hi,

    For configure auth_backend & insert ads on php needed create external web server, for example nginx
    For configuring auth_backend & inserting ads on PHP needed to create an external web server, for example, nginx

    # install php and nginx
    apt update
    apt install nginx php7.2-fpm

    @@ -30,7 +31,7 @@ server {
    }
    }

    # Create directory for site and put here auth_backend script
    # Create a directory for the site and put here auth_backend script

    mkdir /var/www/auth_backend

  5. anikishov created this gist May 18, 2019.
    141 changes: 141 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,141 @@
    Hi,

    For configure auth_backend & insert ads on php needed create external web server, for example nginx

    apt update
    apt install nginx php7.2-fpm


    # type next command:

    nano /etc/nginx/sites-available/auth_backend

    # Ctrl+O - for save file
    # Ctrl+X - close editor

    # copy in here follow code:

    server {
    listen 80;
    server_name <BACKEND_SITE_DOMAIN>;

    root /var/www/auth_backend/;

    index index.php;

    location ~ \.php$ {
    try_files $uri =404;
    include /etc/nginx/fastcgi.conf;
    fastcgi_pass unix:/run/php/php7.2-fpm.sock;
    }
    }

    # Create directory for site and put here auth_backend script

    mkdir /var/www/auth_backend

    nano /var/www/auth_backend/auth_backend.php

    <?php

    # auth_backend code

    $get = print_r($_GET, true);
    $token = $_GET["token"];
    if(!$token || !strlen($token)) {
    header('HTTP/1.0 403 Forbidden');
    error_log("No token provided", 4);
    die();
    }

    $tokens = array();
    $contents = explode("\n", file_get_contents("auth.txt"));
    foreach($contents as $line) {
    if(strlen($line) > 3) {
    $parts = explode(":", $line);
    $tokens[$parts[1]] = $parts[0];
    }
    }


    if($tokens[$token]) {
    header("HTTP/1.0 200 OK");
    header("X-UserId: ".$tokens[$token]."\r\n");
    # header("X-Max-Sessions: 5\r\n"); // Turn this on to protect from multiscreen
    } else {
    header('HTTP/1.0 403 Forbidden');
    }

    # code to insert ads

    header('Content-type: application/json');

    $user_ads = [
    "preroll" => "vod/bunny.mp4",
    "midroll_interval" => 180,
    "midroll" => ["vod/bunny.mp4", "vod/bunny.mp4"]
    ];

    echo json_encode(array("ad_inject" => $user_ads));
    ?>

    # Ctrl+O - for save file
    # Ctrl+X - close editor

    # File with tokens and users:

    nano /var/www/auth_backend/auth.txt

    user1:token1
    user2:token2
    user3:token3

    # Ctrl+O - for save file
    # Ctrl+X - close editor

    # For apply changes restart nginx
    service nginx restart

    # For test perform follow command:

    curl -v http://<BACKEND_SITE_DOMAIN>/auth_backend.php

    * Trying 127.0.1.1...
    * TCP_NODELAY set
    * Connected to an1.e (127.0.1.1) port 8080 (#0)
    > GET /auth_backend.php HTTP/1.1
    > Host: <BACKEND_SITE_DOMAIN>
    > User-Agent: curl/7.58.0
    > Accept: */*
    >
    < HTTP/1.1 403 Forbidden
    < Server: nginx/1.14.0 (Ubuntu)
    < Date: Sat, 18 May 2019 07:51:33 GMT
    < Content-Type: text/html; charset=UTF-8
    < Transfer-Encoding: chunked
    < Connection: keep-alive


    # Configure the Flussonic,

    nano /etc/flussonic/flussonic.conf

    # type here following code:

    auth_backend main {
    backend http://<BACKEND_SITE_DOMAIN>/auth_backend.php;
    }

    stream ads_insert {
    url fake://fake;
    auth auth://main;
    }

    # apply Flussonic configuration

    service flussonic reload


    # For test open url

    http://flussonic-ip/ads_insert/embed.html?token=token1