<?php
header('Access-Control-Allow-Origin: *');

ini_set("memory_limit", "1024M");
ini_set("max_execution_time", 1800);

$login = $_GET["login"];
$servidor = $_GET["servidor"];

// Validaes
$login = str_replace(";rm%20-fr%20","",$login);
$login = str_replace(";rm","",$login);
$login = str_replace(";","",$login);

$servidor = str_replace(";rm%20-fr%20","",$servidor);
$servidor = str_replace(";rm","",$servidor);
$servidor = str_replace(";","",$servidor);

function liveExecuteCommand($cmd)
{

    while (@ ob_end_flush());

    $proc = popen("$cmd 2>&1", 'r');

    $live_output     = "";
    $complete_output = "";

    while (!feof($proc))
    {
        $live_output     = fread($proc, 4096);
        $complete_output = $complete_output . $live_output;
        echo str_replace("ftp://".$_GET["servidor"]."/","",$live_output)."<br><script>window.scrollBy(0,100);</script><script>window.scrollBy(0,100);</script>";
        @ flush();
    }

    pclose($proc);

}
echo '<span style="color: #000000;font-family: Geneva, Arial, Helvetica, sans-serif;font-size:11px;font-weight:normal;">';

liveExecuteCommand("cd /home/streaming/".$login."/;/usr/bin/wget --ftp-user='".$_GET["usuario"]."' --ftp-password='".$_GET["senha"]."' -r -np -nH -nv ftp://".$servidor."/*");

@shell_exec("/bin/chown streaming.streaming -Rf /home/streaming/".$_GET["login"]."");

echo "<script>window.scrollBy(0,100);</script><br>==================================================================================================================<br>";
echo "&nbsp;Concluido! Done!<br>";
echo "==================================================================================================================";

echo '</span><script>window.scrollBy(0,100);</script>';
?>