← Back to team overview

olrait team mailing list archive

Re: Script Aggiornato (mitm)

 

Ciao a tutti. Ho aggiornato lo script di mitm con Rai 1/2/3 e Rai Sport 2.
Tutti i canali sono perfettamente funzionanti. :D

#!/usr/bin/php
<?php
class CURL {
        var $callback = false;
        var $secure = false;
        var $conn = false;
    var $cookiefile = false;

        function setCallback($func_name) {
                $this->callback = $func_name;
        }
        function close() {
                curl_close($this->conn);
        }

        function doRequest($method, $url, $vars, $ttauth) {
    $this->conn = curl_init();
        $ch = $this->conn;

        $user_agent = 'Mozilla/5.0 (X11; U; Linux x86_64; it; rv:1.9.1.7) Gecko/20100106 Ubuntu/9.10 (karmic) Firefox/3.5.7';

        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_HEADER, 1);
        curl_setopt($ch, CURLOPT_USERAGENT,$user_agent);

        if($this->secure) {
            curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,  0);
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
        }

        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_COOKIEJAR, $this->cookiefile);
        curl_setopt($ch, CURLOPT_COOKIEFILE, $this->cookiefile);

        if ($method == 'POST') {
                $this->headers[] = 'Connection: keep-alive';
                $this->headers[] = 'Keep-Alive: 300';
                if($ttauth) $this->headers[] = 'ttAuth: ' . $ttauth;
                $this->headers[] = 'Content-Length: 0';
                $this->headers[] = 'viaurl: www.rai.tv';
                curl_setopt($ch, CURLOPT_HTTPHEADER, $this->headers);
                curl_setopt($ch, CURLOPT_POST, 1);
                curl_setopt($ch, CURLOPT_POSTFIELDS, $vars);
        }
        $data = curl_exec($ch);
        if ($data) {
            if ($this->callback)
            {
                $callback = $this->callback;
                $this->callback = false;
                return call_user_func($callback, $data);
            } else {
                $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
                $body = substr($data, $header_size);
                return $body;
                //return $data;
            }
        } else {
            return curl_error($ch);
        }
    }

    function get($url) {
        return $this->doRequest('GET', $url, 'NULL');
    }
    function post($url, $vars) {
            return $this->doRequest('POST', $url, $vars, 'NULL');
    }
    function post_auth($url, $vars, $ttauth) {
            return $this->doRequest('POST', $url, $vars, $ttauth);
    }
}

$emittenti = array(
    'RAI'                   =>      'RAI',
    'MEDIASET'              =>      'MEDIASET');

$canali['RAI'] = array(
    "RaiUno"               =>      "http://mediapolis.rainet.it/relinker/relinkerServlet.htm?cont=180090";,
    "RaiDue"               =>      "http://mediapolis.rainet.it/relinker/relinkerServlet.htm?cont=180116";,
    "RaiTre"               =>      "http://mediapolis.rainet.it/relinker/relinkerServlet.htm?cont=180117";,
    "RaiQuattro"           =>      "http://mediapolis.rainet.it/relinker/relinkerServlet.htm?cont=75708";,
    "RaiSport"             =>      "http://mediapolis.rainet.it/relinker/relinkerServlet.htm?cont=4145";,
    "RaiSport2"            =>      "http://mediapolis.rai.it/relinker/relinkerServlet.htm?cont=179975";,
    "RaiNews24"            =>      "http://mediapolis.rainet.it/relinker/relinkerServlet.htm?cont=1";,
    "RaiStoria"            =>      "http://mediapolis.rainet.it/relinker/relinkerServlet.htm?cont=24269";,
    "RaiGulp"              =>      "http://mediapolis.rainet.it/relinker/relinkerServlet.htm?cont=4119";,
    "RaiScuola"            =>      "http://mediapolis.rainet.it/relinker/relinkerServlet.htm?cont=24268";,
    "RaiSatExtra"          =>      "http://mediapolis.rainet.it/relinker/relinkerServlet.htm?cont=72382";,
    "RaiSatPremium"        =>      "http://mediapolis.rainet.it/relinker/relinkerServlet.htm?cont=72383";,
    "RaiSatYoYo"           =>      "http://mediapolis.rainet.it/relinker/relinkerServlet.htm?cont=72384";,
    "RaiSatCinema"         =>      "http://mediapolis.rainet.it/relinker/relinkerServlet.htm?cont=72381";,
    "RaiMed"               =>      "http://mediapolis.rainet.it/relinker/relinkerServlet.htm?cont=87127";,
    "EuroNews"             =>      "http://mediapolis.rainet.it/relinker/relinkerServlet.htm?cont=113784";,
    "TG1"               =>      "http://link.rai.it/x/vod/ue/wmx/ultimo_tg1.asx";,
    "TG2"                  =>      "http://link.rai.it/x/vod/ue/wmx/ultimo_tg2.asx";,
    "TG3"                  =>      "http://link.rai.it/x/vod/ue/wmx/ultimo_tg3.asx";);

$canali['MEDIASET'] = array(
    "Mediaset"             =>      "mms://video.farm.mediaset.it/mediaset_cm_lq_source4",
    "Canale5"              =>      "mms://live.wm.p1.str3.com/003000_bc_v365_mediashopping_mi",
    "Italia1"              =>      "mms://95.154.227.148/liveencoder12");

function arrayToList($option, $optgroup = NULL)
{
    echo "Canali disponibili:\n";
    foreach ($optgroup as $optgroupKey => $optgroupValue) {
        echo "\nGruppo " . "$optgroupValue" . "\n";
        foreach ($option[$optgroupKey] as $optionKey => $optionValue) {
            echo "$optionKey" . "\n";
        }
    }
}

function encode1($tokenstring){
        $encoded = "";
        for($i = 0; $i < strlen($tokenstring); $i++){
                $ch = substr($tokenstring, $i, 1);
                $encoded .= chr(ord($ch)^1);
        }
        $encoded .= ";1";
        return $encoded;
}

function encode2($tokenstring, $chiave){
        $encoded = "";
        $i = strlen($tokenstring) - 1;
        $j = 0;

        while ($i >= 0){
                $ch1 = substr($tokenstring, $i, 1);
                $ch2 = substr($chiave, $j, 1);
                $enc = chr(ord($ch1)^ord($ch2));
                $encoded = $enc . $encoded;
                $i--;
                $j++;
        }
        return $encoded;
}

function encode3($tokenstring){
        $encoded = base64_encode(utf8_decode(utf8_encode($tokenstring)));
        return $encoded;
}

function getURL($url) {
    $data = new CURL();
    return $data->get("$url");
}

function postURL($url, $vars){
    $data = new CURL();
    return $data->post("$url", "$vars");
}

function authURL($url, $vars, $ttauth){
    $data = new CURL();
    return $data->post_auth("$url", "$vars", $ttauth);
}

function parseXML($data) {
    $start = strpos($data, "<REF HREF=\"") + 11;
    $end = strpos($data, "\"/>")?strpos($data, "\"/>"):strpos($data, "\" />");
    if($start && $end) {
        $url =  substr($data, $start, $end - $start);
        if (preg_match("/http/", $url)) {
            $url = str_replace("http", "mms", $url);
        }
    } else {
        $url = 'Stream not available';
    }
    return $url;
}

if ($argc < 2){
    $canale = "RaiUno";
    $gruppo = "RAI";
    # Lettore predefinito
    $player = "mplayer";
    echo "# $argv[0] <nome_canale> <gruppo> <player>\n";
    echo "# Valori di default:\n";
    echo "# $argv[0] RaiUno RAI mplayer\n";
    arrayToList($canali,$emittenti);
    echo "";
} else {
    $canale = $argv[1]?$argv[1]:"RaiUno";
    $gruppo = $argv[2]?$argv[2]:"RAI";
    # Lettore predefinito
    $player = $argv[3]?$argv[3]:"mplayer";
}

$url = $canali[$gruppo][$canale];
$pattern = "/RAI/";

if(preg_match($pattern, $gruppo)){
    $srvntp = "http://videowall.rai.it/cgi-bin/date";;
    $data = getURL($srvntp);
    $day = substr($data,0,2);
    $month = substr($data,3,2);
    //if(substr($month,0,1) == '0') $month = (substr($month,1,1));
    $year = substr($data,6,4);
    $hour = substr($data,11,2);
    $min = substr($data,14,2);
    $sec = substr($data,17,2);
    $pattern = "/.*=([0-9]*)/";
    preg_match($pattern, $url, $matches);
    $id = $matches[1];
    $rnd1 = rand(0, 1234);
    $rnd2 = rand(0, 1234);
    $tokenstring = $year . ';' . $id . ';' . $day . '-' . $month . '-' . $rnd1 . '-' . $hour . '-' . $min . '-' . $sec . '-' . $rnd2;
    $ttauth = '';
    $ttauth = encode3(encode2(encode1($tokenstring), 'hMrxuE2T8V0WRW0VmHaKMoFwy1XRc+hK7eBX2tTLVTw='));
    $data = authURL($url, null, $ttauth);
    $url = parseXML($data);
}

echo "\nCanale selezionato: $canale Gruppo: $gruppo\n";
echo "\nURL dello Stream  : $url\n";

$cmd = shell_exec("$player $url");

?>