function upfileput($host, $port, $url, $referer = 0, $cookie = 0, $post = 0, $file, $filename, $fieldname, $field2name = '', $upagent = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.1) Gecko/2008070208 Firefox/3.1', $proxy = 0)
    {
        global $nn, $lastError, $sleep_time, $sleep_count;
        $saveToFile = 12;
        $fileSize = getSize($file);
        $fieldname = $fieldname ? $fieldname : file . md5($filename);
        if (!is_readable($file)) {
            $lastError = sprintf(lang(65), $file);
            return FALSE;
        }
        $cookies = '';
        if ($cookie) {
            if (is_array($cookie)) {
                $h = 12;
                while ($h < count($cookie)) {
                    $cookies .= 'Cookie: ' . trim($cookie[$h]) . $nn;
                    ++$h;
                }
            } else {
                $cookies = 'Cookie: ' . trim($cookie) . $nn;
            }
        }
        $referer = $referer ? 'Referer: ' . $referer . $nn . 'Origin: http://filejungle.com' . $nn : '';
        $posturl = ($proxyHost ? $scheme . $proxyHost : $scheme . $host) . ':' . ($proxyPort ? $proxyPort : $port);
        $zapros = 'PUT ' . str_replace(' ', '%20', $url) . ' HTTP/1.1' . $nn . 'Host: ' . $host . $nn . $cookies . 'X-File-Name: ' . $filename . $nn . 'X-File-Size: ' . $fileSize . $nn . 'Content-Length: ' . $fileSize . $nn . 'User-Agent: ' . $upagent . $nn . 'Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5' . $nn . 'Content-Type: multipart/form-data' . $nn . 'Accept-Language: en-en,en;q=0.5' . $nn . 'Accept-Charset: utf-8,windows-1251;koi8-r;q=0.7,*;q=0.7' . $nn . 'Connection: Close' . $nn . $auth . $referer . $nn;
        $errno = 12;
        $errstr = '';
        $fp = @stream_socket_client($posturl, $errno, $errstr, 120, STREAM_CLIENT_CONNECT);
        if ($errno || $errstr) {
            $lastError = $errstr;
            return false;
        }
        echo lang(104) . ' <b>' . $filename . '</b>, ' . lang(56) . ' <b>' . bytesToKbOrMb($fileSize) . '</b>...<br />';
        global $id;
        $id = md5(time() * rand(0, 10));
        require TEMPLATE_DIR . '/uploadui.php';
        flush();
        $timeStart = getmicrotime();
        $chunkSize = GetChunkSize($fileSize);
        fputs($fp, $zapros);
        fflush($fp);
        $fs = fopen($file, 'r');
        $local_sleep = $sleep_count;
        while (!feof($fs)) {
            $data = fread($fs, $chunkSize);
            if ($data === false) {
                fclose($fs);
                fclose($fp);
                html_error(lang(112));
            }
            if ($sleep_count !== false && $sleep_time !== false && is_numeric($sleep_time) && is_numeric($sleep_count) && 0 < $sleep_count && 0 < $sleep_time) {
                --$local_sleep;
                if ($local_sleep == 0) {
                    usleep($sleep_time);
                    $local_sleep = $sleep_count;
                }
            }
            $sendbyte = fputs($fp, $data);
            fflush($fp);
            if ($sendbyte === false) {
                fclose($fs);
                fclose($fp);
                html_error(lang(113));
            }
            $totalsend += $sendbyte;
            $time = getmicrotime() - $timeStart;
            $chunkTime = $time - $lastChunkTime;
            $chunkTime = $chunkTime ? $chunkTime : 1;
            $lastChunkTime = $time;
            $speed = round($sendbyte / 1024 / $chunkTime, 2);
            $percent = round($totalsend / $fileSize * 100, 2);
            echo '<script type=\'text/javascript\' language=\'javascript\'>pr(\'' . $percent . '\', \'' . bytesToKbOrMb($totalsend) . '\', \'' . $speed . '\');</script>
';
            flush();
        }
        fclose($fs);
        fflush($fp);
        while (!feof($fp)) {
            $data = fgets($fp, 1024);
            if ($data === false) {
                break;
            }
            $page .= $data;
        }
        fclose($fp);
        return $page;
    }
 public function upload()
 {
     require TEMPLATE_DIR . 'uploadui.php';
     $timeStart = getmicrotime();
     if (!($fh = fopen($this->file, 'r'))) {
         throw new Exception('Unable to open file: ' . $this->filename);
     }
     $rsip = gethostbyname($this->fulluploadserver['host']);
     $cursize = 0;
     while ($cursize < $this->fsize) {
         if ($this->fsize > $this->wantchunksize) {
             $chunksize = $this->fsize - $cursize;
             if ($chunksize > $this->wantchunksize) {
                 $chunksize = $this->wantchunksize;
             } else {
                 $this->complete = 1;
             }
         } else {
             $chunksize = $this->fsize;
             $this->complete = 1;
         }
         //echo "Upload chunk is $chunksize bytes starting at $cursize...<br />";
         $this->contentheader = "{$this->boundary}\r\nContent-Disposition: form-data; name=\"rsapi_v1\"\r\n\r\n1\r\n";
         if ($this->resumed) {
             $this->contentheader .= "{$this->boundary}\r\nContent-Disposition: form-data; name=\"fileid\"\r\n\r\n{$this->fileid}\r\n";
             $this->contentheader .= "{$this->boundary}\r\nContent-Disposition: form-data; name=\"killcode\"\r\n\r\n{$this->killcode}\r\n";
             if ($this->complete) {
                 $this->contentheader .= "{$this->boundary}\r\nContent-Disposition: form-data; name=\"complete\"\r\n\r\n1\r\n";
             }
         }
         if (!$this->resumed && $this->login && $this->password) {
             $this->contentheader .= "{$this->boundary}\r\nContent-Disposition: form-data; name=\"login\"\r\n\r\n{$this->login}\r\n";
             $this->contentheader .= "{$this->boundary}\r\nContent-Disposition: form-data; name=\"password\"\r\n\r\n{$this->password}\r\n";
         }
         if (!$this->complete) {
             $this->contentheader .= "{$this->boundary}\r\nContent-Disposition: form-data; name=\"incomplete\"\r\n\r\n1\r\n";
         }
         $this->contentheader .= "{$this->boundary}\r\nContent-Disposition: form-data; name=\"filecontent\"; filename=\"{$this->filename}\"\r\n\r\n";
         $contenttail = "\r\n{$this->boundary}--\r\n";
         $contentlength = strlen($this->contentheader) + $chunksize + strlen($contenttail);
         $header = 'POST /cgi-bin/' . ($this->resumed ? 'uploadresume.cgi' : 'upload.cgi') . " HTTP/1.1\r\nHost: {$this->fulluploadserver[host]}\r\nContent-Type: multipart/form-data; boundary={$this->boundary}\r\nContent-Length: {$contentlength}\r\nUser-Agent: {$this->useragent}\r\n\r\n";
         if (!($socket = fsockopen($rsip, 80, $errno, $errstr, 30))) {
             throw new Exception("Unable to open socket: {$errstr}");
         }
         fwrite($socket, "{$header}{$this->contentheader}");
         $buffer = fread($fh, $this->wantchunksize);
         $bufferlen = strlen($buffer);
         $cursize += $bufferlen;
         $sentbytes = fwrite($socket, "{$buffer}");
         //echo "Bytes written: $sentbytes<br />";
         $time = getmicrotime() - $timeStart;
         $chunkTime = $time - $lastChunkTime;
         $chunkTime = $chunkTime ? $chunkTime : 1;
         $lastChunkTime = $time;
         $speed = round($sentbytes / 1024 / $chunkTime, 2);
         $percent = round($cursize / $this->fsize * 100, 2);
         fwrite($socket, $contenttail);
         fflush($socket);
         $result = '';
         while (!feof($socket)) {
             $result .= fgets($socket, 16384);
         }
         //file_put_contents('rsresult.log', $result . "\r\n\r\n", FILE_APPEND);
         if (preg_match('#(ERROR: .+)#', $result, $errmat)) {
             throw new Exception($errmat[1]);
         }
         if (!$this->resumed) {
             preg_match('#/files/(\\d+)/#', $result, $fileid);
             preg_match('#killcode=(\\d+)\\r?\\n#', $result, $killcode);
             preg_match('%http://rapidshare\\.com/((?!killcode).)+$%mi', $result, $flink);
             preg_match('%http://rapidshare\\.com/.*killcode.*%i', $result, $dlink);
             $this->download_link = trim($flink[0]);
             $this->delete_link = trim($dlink[0]);
             $this->fileid = $fileid[1];
             $this->killcode = $killcode[1];
             $this->resumed = 1;
         }
         fclose($socket);
         echo "<script type='text/javascript' language='javascript'>pr('" . $percent . "', '" . bytesToKbOrMb($cursize) . "', '" . $speed . "');</script>\n";
         flush();
     }
     fclose($fh);
 }
Example #3
0
	border-top-style: dashed;
	border-right-style: dashed;
	border-bottom-style: dashed;
	border-left-style: dashed;
	border-top-color: #333333;
	border-right-color: #333333;
	border-bottom-color: #333333;
	border-left-color: #333333;
	font-size: 12px;
	font-family: Georgia, "Times New Roman", Times, serif;
}
								</style>
								</head>
								<body>
								';
        write_file(trim($lfile) . ".upload.html", $html_header . sprintf(lang(76), $lname, bytesToKbOrMb($fsize)), 0);
        if (!$options['upload_html_disable']) {
            $html_content = '<div class="host"><div class="title"><strong>' . $_REQUEST['uploaded'] . '</strong> - <span class="bluefont">' . date("Y-m-d H:i:s") . '</span></div>
				<div class="links">' . ($download_link ? '<strong>' . lang(68) . ': <a href="' . $download_link . '" target="_blank">' . $download_link . ' </a></strong>' : '') . ($delete_link ? '<br />' . lang(69) . ': <a href="' . $delete_link . '" target="_blank">' . $delete_link . ' </a>' : '') . ($stat_link ? '<br />' . lang(70) . ': <a href="' . $stat_link . '" target="_blank">' . $stat_link . ' </a>' : '') . ($adm_link ? '<br />' . lang(71) . ': <a href="' . $adm_link . '" target="_blank">' . $adm_link . ' </a>' : '') . ($user_id ? '<br />' . lang(72) . ': <a href="' . $user_id . '" target="_blank">' . $user_id . ' </a>' : '') . ($access_pass ? '<br />' . lang(74) . ': <a href="' . $access_pass . '" target="_blank">' . $access_pass . ' </a>' : '') . ($ftp_uplink ? '<br />' . lang(73) . ': <a href="' . $ftp_uplink . '" target="_blank">' . $ftp_uplink . ' </a>' : '') . '</div></div>';
            write_file(trim($lfile) . ".upload.html", $html_content, 0);
        }
    }
}
echo $not_done ? "" : '<p><center><b><a href="javascript:window.close();">' . lang(77) . '</a></b></center>';
?>
</body>
</html>
<?php 
if (isset($_GET['auul'])) {
    ?>
<script type="text/javascript">parent.nextlink<?php 
Example #4
0
function UploadToYoutube($host, $port, $url, $dkey, $uauth, $XMLReq, $file, $filename)
{
    global $nn, $lastError, $sleep_time, $sleep_count;
    if (!is_readable($file)) {
        $lastError = sprintf(lang(65), $file);
        return FALSE;
    }
    $fileSize = getSize($file);
    $bound = "--------" . md5(microtime());
    $saveToFile = 0;
    $postdata .= "--" . $bound . $nn;
    $postdata .= 'Content-Type: application/atom+xml; charset=UTF-8' . $nn . $nn;
    $postdata .= $XMLReq . $nn;
    $postdata .= "--" . $bound . $nn;
    $postdata .= "Content-Type: application/octet-stream" . $nn . $nn;
    $zapros = "POST " . str_replace(" ", "%20", $url) . " HTTP/1.1{$nn}Host: {$host}{$nn}Authorization: GoogleLogin auth={$uauth}{$nn}GData-Version: 2.1{$nn}X-GData-Key: key={$dkey}{$nn}Slug: {$filename}{$nn}Content-Type: multipart/related; boundary={$bound}{$nn}Content-Length: " . (strlen($postdata) + strlen($nn . "--{$bound}--{$nn}") + $fileSize) . "{$nn}Connection: Close{$nn}{$nn}{$postdata}";
    $errno = 0;
    $errstr = "";
    $fp = @stream_socket_client("{$host}:{$port}", $errno, $errstr, 120, STREAM_CLIENT_CONNECT);
    if (!$fp) {
        html_error(sprintf(lang(88), $host, $port));
    }
    if ($errno || $errstr) {
        $lastError = $errstr;
        return false;
    }
    echo "<p>";
    printf(lang(90), $host, $port);
    echo "</p>";
    echo lang(104) . ' <b>' . $filename . '</b>, ' . lang(56) . ' <b>' . bytesToKbOrMb($fileSize) . '</b>...<br />';
    global $id;
    $id = md5(time() * rand(0, 10));
    require TEMPLATE_DIR . '/uploadui.php';
    flush();
    $timeStart = getmicrotime();
    $chunkSize = GetChunkSize($fileSize);
    fputs($fp, $zapros);
    fflush($fp);
    $fs = fopen($file, 'r');
    $local_sleep = $sleep_count;
    while (!feof($fs)) {
        $data = fread($fs, $chunkSize);
        if ($data === false) {
            fclose($fs);
            fclose($fp);
            html_error(lang(112));
        }
        if ($sleep_count !== false && $sleep_time !== false && is_numeric($sleep_time) && is_numeric($sleep_count) && $sleep_count > 0 && $sleep_time > 0) {
            $local_sleep--;
            if ($local_sleep == 0) {
                usleep($sleep_time);
                $local_sleep = $sleep_count;
            }
        }
        $sendbyte = fputs($fp, $data);
        fflush($fp);
        if ($sendbyte === false) {
            fclose($fs);
            fclose($fp);
            html_error(lang(113));
        }
        $totalsend += $sendbyte;
        $time = getmicrotime() - $timeStart;
        $chunkTime = $time - $lastChunkTime;
        $chunkTime = $chunkTime ? $chunkTime : 1;
        $lastChunkTime = $time;
        $speed = round($sendbyte / 1024 / $chunkTime, 2);
        $percent = round($totalsend / $fileSize * 100, 2);
        echo '<script type="text/javascript">pr(' . "'" . $percent . "', '" . bytesToKbOrMb($totalsend) . "', '" . $speed . "');</script>\n";
        flush();
    }
    fclose($fs);
    fputs($fp, $nn . "--" . $bound . "--" . $nn);
    fflush($fp);
    while (!feof($fp)) {
        $data = fgets($fp, 16384);
        if ($data === false) {
            break;
        }
        $page .= $data;
    }
    fclose($fp);
    return $page;
}
Example #5
0
if ($download_link || $delete_link || $stat_link || $adm_link) {
    echo "\n<table width=100% border=0>";
    echo $download_link ? "<tr><td width=100 nowrap align=right><b>Download-Link:</b><td width=\"80%\"><input type='text' value='{$download_link}' onfocus='highlight(this)'; style=\"width: 470px;\" readonly /></tr>" : "";
    echo $delete_link ? "<tr><td width=100 nowrap align=right>Delete-Link:<td width=\"80%\"><input type='text' value='{$delete_link}' onfocus='highlight(this)'; style=\"width: 470px;\" readonly /></tr>" : "";
    echo $stat_link ? "<tr><td width=100 nowrap align=right>Stat-Link:<td width=\"80%\"><input type='text' value='{$stat_link}' onfocus='highlight(this)'; style=\"width: 470px;\" readonly /></tr>" : "";
    echo $adm_link ? "<tr><td width=100 nowrap align=right>Admin-Link:<td width=\"80%\"><input type='text' value='{$adm_link}' onfocus='highlight(this)'; style=\"width: 470px;\" readonly/ ></tr>" : "";
    echo $user_id ? "<tr><td width=100 nowrap align=right>USER-ID:<td width=\"80%\"><input type='text' value='{$user_id}' onfocus='highlight(this)'; style=\"width: 470px; \" readonly></tr>" : "";
    echo $ftp_uplink ? "<tr><td width=100 nowrap align=right>FTP UPLOAD:<td width=\"80%\"><input type='text' value='{$ftp_uplink}' onfocus='highlight(this)'; style=\"width: 470px;\" readonly /></tr>" : "";
    echo $access_pass ? "<tr><td width=100 nowrap align=right>PASSWD:<td width=\"80%\"><input type='text' value='{$access_pass}' onfocus='highlight(this)'; style=\"width: 470px;\" readonly /></tr>" : "";
    echo "</table>\n";
    //if(!file_exists(trim($lfile).".upload.html"))
    if (!file_exists(trim($lfile) . ".upload.html") && !isset($_GET['auul']) && !$options['upload_html_disable']) {
        $html_header = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n\t\t\t\t\t<html xmlns=\"http://www.w3.org/1999/xhtml\">\n\t\t\t\t\t<head>\n\t\t\t\t\t<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />\n\t\t\t\t\t<title>RapidleechPlugMod - UploadLinks</title>\n\t\t\t\t\t<style type=\"text/css\">\nbody {\n\tfont-family: tahoma, arial, \"times New Roman\", georgia, verdana, sans-serif;\n\tfont-size: 11px;\n\tcolor: #333333;\n\tbackground-color: #EFF0F4;\n\tmargin: 0px;\n\tpadding: 0px;\n}\n.linktitle {\n\twidth: 576px;\n\tbackground-color: #C291F9;\n\ttext-align: center;\n\tpadding:3px;\n\tmargin-top: 25px;\n\tmargin-right: auto;\n\tmargin-bottom: 0;\n\tmargin-left: auto;\n\tborder-top-width: 1px;\n\tborder-right-width: 1px;\n\tborder-bottom-width: 0px;\n\tborder-left-width: 1px;\n\tborder-top-style: solid;\n\tborder-right-style: solid;\n\tborder-bottom-style: solid;\n\tborder-left-style: solid;\n\tborder-top-color: #C7C4FB;\n\tborder-right-color: #C7C4FB;\n\tborder-bottom-color: #C7C4FB;\n\tborder-left-color: #C7C4FB;\n}\n.bluefont {\n\tcolor: #0E078F;\n\tfont-family: tahoma, arial, \"times New Roman\", georgia, verdana, sans-serif;\n\tfont-size: 11px;\n}\nhr {\n\tborder-top-width: 0px;\n\tborder-right-width: 0px;\n\tborder-bottom-width: 0px;\n\tborder-left-width: 0px;\n\tborder-top-style: solid;\n\theight: 1px;\n\tbackground-color: #046FC6;\n\tcolor: #046FC6;\n\tborder-right-style: solid;\n\tborder-bottom-style: solid;\n\tborder-left-style: solid;\n\twidth: 90%;\n}\n.host .links {\n\twidth: 95%;\n\tmargin:0 auto;\n\ttext-align:left;\n\tpadding:3px 0 3px 10px;\n\tborder: 1px dashed #666666;\n\tbackground-color: #F2F1FE;\n}\n.host {\n\twidth: 600px;\n\tmargin: 10px auto 10px;\n}\n.host .links a {\n\ttext-decoration:none;\n\tcolor: #666666;\n\tfont-size: 11px;\n}\n.host .links a:hover {\n\ttext-decoration:none;\n\tcolor:#E8740B\n}\n.host .title {\n\twidth: 95%;\n\tmargin:0 auto;\n\ttext-align:left;\n\tpadding:3px 0 3px 10px;\n\tbackground-color: #C7C4FB;\n\tcolor: #000000;\n\tborder-top-width: 1px;\n\tborder-right-width: 1px;\n\tborder-bottom-width: 0px;\n\tborder-left-width: 1px;\n\tborder-top-style: dashed;\n\tborder-right-style: dashed;\n\tborder-bottom-style: dashed;\n\tborder-left-style: dashed;\n\tborder-top-color: #333333;\n\tborder-right-color: #333333;\n\tborder-bottom-color: #333333;\n\tborder-left-color: #333333;\n\tfont-size: 12px;\n\tfont-family: Georgia, \"Times New Roman\", Times, serif;\n}\n\t\t\t\t\t</style>\n\t\t\t\t\t</head>\n\t\t\t\t\t<body>\n\t\t\t\t\t";
        $fp = fopen(trim($lfile) . ".upload.html", 'w');
        fwrite($fp, $html_header);
        fwrite($fp, "<div class=\"linktitle\">Upload Links for <strong>" . $lname . "</strong> - <span class=\"bluefont\">Size: <strong>" . bytesToKbOrMb($fsize) . "</strong></span></div>");
        fclose($fp);
    }
    if (!$options['upload_html_disable']) {
        $fr = fopen(trim($lfile) . ".upload.html", 'a+');
        if ($fr) {
            fwrite($fr, "<div class=\"host\"><div class=\"title\"><strong>" . $_REQUEST["uploaded"] . "</strong> - <span class=\"bluefont\">" . date("Y-m-d H:i:s") . "</span></div>");
            fwrite($fr, "<div class=\"links\">");
            if ($download_link) {
                fwrite($fr, "<strong>Download link: <a href=\"" . $download_link . "\" target=\"_blank\">" . $download_link . " </a></strong>");
            }
            if ($delete_link) {
                fwrite($fr, "<br />Delete link: <a href=\"" . $delete_link . "\" target=\"_blank\">" . $delete_link . " </a>");
            }
            if ($stat_link) {
                fwrite($fr, "<br />Stat link: <a href=\"" . $stat_link . "\" target=\"_blank\">" . $stat_link . " </a>");
Example #6
0
function upfile($host, $port, $url, $referer, $cookie, $post, $file, $filename, $fieldname, $field2name = '', $proxy = 0, $pauth = 0, $upagent = 0, $scheme = 'http')
{
    global $nn, $lastError, $sleep_time, $sleep_count, $L;
    if (empty($upagent)) {
        $upagent = 'Opera/9.80 (Windows NT 6.1) Presto/2.12.388 Version/12.12';
    }
    $scheme .= '://';
    $bound = '--------' . md5(microtime());
    $saveToFile = 0;
    $postdata = '';
    if ($post) {
        foreach ($post as $key => $value) {
            $postdata .= '--' . $bound . $nn;
            $postdata .= "Content-Disposition: form-data; name=\"{$key}\"{$nn}{$nn}";
            $postdata .= $value . $nn;
        }
    }
    $fileSize = getSize($file);
    $fieldname = $fieldname ? $fieldname : file . md5($filename);
    if (!is_readable($file)) {
        $lastError = $L->sprintf($L->say['_error_readfile'], $file);
        return FALSE;
    }
    if ($field2name != '') {
        $postdata .= '--' . $bound . $nn;
        $postdata .= "Content-Disposition: form-data; name=\"{$field2name}\"; filename=\"\"{$nn}";
        $postdata .= "Content-Type: application/octet-stream{$nn}{$nn}";
    }
    $postdata .= '--' . $bound . $nn;
    $postdata .= "Content-Disposition: form-data; name=\"{$fieldname}\"; filename=\"{$filename}\"{$nn}";
    $postdata .= "Content-Type: application/octet-stream{$nn}{$nn}";
    $cookies = '';
    if (!empty($cookie)) {
        if (is_array($cookie)) {
            if (count($cookie) > 0) {
                $cookies = 'Cookie: ' . CookiesToStr($cookie) . $nn;
            }
        } else {
            $cookies = 'Cookie: ' . trim($cookie) . $nn;
        }
    }
    $referer = $referer ? "Referer: {$referer}{$nn}" : '';
    if ($scheme == 'https://') {
        $scheme = 'ssl://';
        $port = 443;
    }
    if ($proxy) {
        list($proxyHost, $proxyPort) = explode(':', $proxy, 2);
        $host = $host . ($port != 80 && ($scheme != 'ssl://' || $port != 443) ? ':' . $port : '');
        $url = $scheme . $host . $url;
    }
    if ($scheme != 'ssl://') {
        $scheme = '';
    }
    $http_auth = !empty($auth) ? "Authorization: Basic {$auth}{$nn}" : '';
    $proxyauth = !empty($pauth) ? "Proxy-Authorization: Basic {$pauth}{$nn}" : '';
    $zapros = 'POST ' . str_replace(' ', "%20", $url) . ' HTTP/1.0' . $nn . 'Host: ' . $host . $nn . $cookies . "Content-Type: multipart/form-data; boundary=" . $bound . $nn . "Content-Length: " . (strlen($postdata) + strlen($nn . "--" . $bound . "--" . $nn) + $fileSize) . $nn . "User-Agent: " . $upagent . $nn . "Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5" . $nn . "Accept-Language: en-en,en;q=0.5" . $nn . "Accept-Charset: utf-8,windows-1251;koi8-r;q=0.7,*;q=0.7" . $nn . "Connection: Close" . $nn . $http_auth . $proxyauth . $referer . $nn . $postdata;
    $errno = 0;
    $errstr = '';
    $posturl = (!empty($proxyHost) ? $scheme . $proxyHost : $scheme . $host) . ':' . (!empty($proxyPort) ? $proxyPort : $port);
    $fp = @stream_socket_client($posturl, $errno, $errstr, 120, STREAM_CLIENT_CONNECT);
    //$fp = @fsockopen ( $host, $port, $errno, $errstr, 150 );
    //stream_set_timeout ( $fp, 300 );
    if (!$fp) {
        $dis_host = !empty($proxyHost) ? $proxyHost : $host;
        $dis_port = !empty($proxyPort) ? $proxyPort : $port;
        html_error($L->sprintf($L->say['_couldnt_con_to'], $dis_host, $dis_port));
    }
    if ($errno || $errstr) {
        $lastError = $errstr;
        return false;
    }
    if ($proxy) {
        echo '<p>' . $L->sprintf($L->say['_con_proxy'], $proxyHost, $proxyPort) . '<br />';
        echo "UPLOAD: <b>" . $url . "</b>...<br />\n";
    } else {
        echo "<p>";
        echo $L->sprintf($L->say['_con_to'], $host, $port);
        echo "</p>";
    }
    echo $L->sprintf($L->say['_uplprogres'], $filename, bytesToKbOrMb($fileSize)) . '<br />';
    global $id;
    $id = md5(TIME_NOW * rand(0, 10));
    require TEMPLATE_DIR . 'uploadui.php';
    flush();
    $timeStart = getmicrotime();
    //$chunkSize = 16384;		// Use this value no matter what (using this actually just causes massive cpu usage for large files, too much data is flushed to the browser!)
    $chunkSize = GetChunkSize($fileSize);
    fputs($fp, $zapros);
    fflush($fp);
    $fs = fopen($file, 'r');
    $local_sleep = $sleep_count;
    //echo('<script type="text/javascript">');
    $totalsend = $time = $lastChunkTime = 0;
    while (!feof($fs) && !$errno && !$errstr) {
        $data = fread($fs, $chunkSize);
        if ($data === false) {
            fclose($fs);
            fclose($fp);
            html_error($L->say['_error_readdata']);
        }
        if ($sleep_count !== false && $sleep_time !== false && is_numeric($sleep_time) && is_numeric($sleep_count) && $sleep_count > 0 && $sleep_time > 0) {
            $local_sleep--;
            if ($local_sleep == 0) {
                usleep($sleep_time);
                $local_sleep = $sleep_count;
            }
        }
        $sendbyte = @fputs($fp, $data);
        fflush($fp);
        if ($sendbyte === false || strlen($data) > $sendbyte) {
            fclose($fs);
            fclose($fp);
            html_error($L->say['_error_senddata']);
        }
        $totalsend += $sendbyte;
        $time = getmicrotime() - $timeStart;
        $chunkTime = $time - $lastChunkTime;
        $chunkTime = $chunkTime ? $chunkTime : 1;
        $lastChunkTime = $time;
        $speed = round($sendbyte / 1024 / $chunkTime, 2);
        $percent = round($totalsend / $fileSize * 100, 2);
        echo '<script type="text/javascript">pr(' . "'" . $percent . "', '" . bytesToKbOrMbOrGb($totalsend) . "', '" . $speed . "');</script>\n";
        flush();
    }
    //echo('</script>');
    if ($errno || $errstr) {
        $lastError = $errstr;
        return false;
    }
    fclose($fs);
    fputs($fp, $nn . "--" . $bound . "--" . $nn);
    fflush($fp);
    $page = '';
    while (!feof($fp)) {
        $data = fgets($fp, 16384);
        if ($data === false) {
            break;
        }
        $page .= $data;
    }
    fclose($fp);
    return $page;
}
Example #7
0
function upfile($host, $port, $url, $referer, $cookie, $post, $file, $filename, $fieldname, $field2name = "", $proxy = 0, $pauth = 0, $upagent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.1) Gecko/2008070208 Firefox/3.1")
{
    global $nn, $lastError, $sleep_time, $sleep_count;
    $scheme = "http://";
    $bound = "--------" . md5(microtime());
    $saveToFile = 0;
    foreach ($post as $key => $value) {
        $postdata .= "--" . $bound . $nn;
        $postdata .= 'Content-Disposition: form-data; name="' . $key . '"' . $nn . $nn;
        $postdata .= $value . $nn;
    }
    $fileSize = getSize($file);
    $fieldname = $fieldname ? $fieldname : file . md5($filename);
    if (!is_readable($file)) {
        $lastError = sprintf(lang(65), $file);
        return FALSE;
    }
    if ($field2name != '') {
        $postdata .= "--" . $bound . $nn;
        $postdata .= 'Content-Disposition: form-data; name="' . $field2name . '"; filename=""' . $nn;
        $postdata .= "Content-Type: application/octet-stream" . $nn . $nn;
    }
    $postdata .= "--" . $bound . $nn;
    $postdata .= 'Content-Disposition: form-data; name="' . $fieldname . '"; filename="' . $filename . '"' . $nn;
    $postdata .= "Content-Type: application/octet-stream" . $nn . $nn;
    $cookies = "";
    if ($cookie) {
        if (is_array($cookie)) {
            for ($h = 0; $h < count($cookie); $h++) {
                $cookies .= "Cookie: " . trim($cookie[$h]) . $nn;
            }
        } else {
            $cookies = "Cookie: " . trim($cookie) . $nn;
        }
    }
    $referer = $referer ? "Referer: " . $referer . $nn : "";
    if ($scheme == "https://") {
        $scheme = "ssl://";
        $port = 443;
    }
    if ($proxy) {
        list($proxyHost, $proxyPort) = explode(":", $proxy);
        $url = $scheme . $host . ":" . $port . $url;
        $host = $host . ":" . $port;
    }
    if ($scheme != "ssl://") {
        $scheme = "";
    }
    $http_auth = $auth ? "Authorization: Basic " . $auth . $nn : "";
    $proxyauth = $pauth ? "Proxy-Authorization: Basic " . $pauth . $nn : "";
    $zapros = "POST " . str_replace(" ", "%20", $url) . " HTTP/1.0" . $nn . "Host: " . $host . $nn . $cookies . "Content-Type: multipart/form-data; boundary=" . $bound . $nn . "Content-Length: " . (strlen($postdata) + strlen($nn . "--" . $bound . "--" . $nn) + $fileSize) . $nn . "User-Agent: " . $upagent . $nn . "Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5" . $nn . "Accept-Language: en-en,en;q=0.5" . $nn . "Accept-Charset: utf-8,windows-1251;koi8-r;q=0.7,*;q=0.7" . $nn . "Connection: Close" . $nn . $http_auth . $proxyauth . $referer . $nn . $postdata;
    $errno = 0;
    $errstr = "";
    $posturl = ($proxyHost ? $scheme . $proxyHost : $scheme . $host) . ':' . ($proxyPort ? $proxyPort : $port);
    $fp = @stream_socket_client($posturl, $errno, $errstr, 120, STREAM_CLIENT_CONNECT);
    //$fp = @fsockopen ( $host, $port, $errno, $errstr, 150 );
    //stream_set_timeout ( $fp, 300 );
    if (!$fp) {
        $dis_host = $proxyHost ? $proxyHost : $host;
        $dis_port = $proxyPort ? $proxyPort : $port;
        html_error(sprintf(lang(88), $dis_host, $dis_port));
    }
    if ($errno || $errstr) {
        $lastError = $errstr;
        return false;
    }
    if ($proxy) {
        echo '<p>' . sprintf(lang(89), $proxyHost, $proxyPort) . '<br />';
        echo "UPLOAD: <b>" . $url . "</b>...<br />\n";
    } else {
        echo "<p>";
        printf(lang(90), $host, $port);
        echo "</p>";
    }
    echo lang(104) . ' <b>' . $filename . '</b>, ' . lang(56) . ' <b>' . bytesToKbOrMb($fileSize) . '</b>...<br />';
    global $id;
    $id = md5(time() * rand(0, 10));
    require TEMPLATE_DIR . '/uploadui.php';
    flush();
    $timeStart = getmicrotime();
    //$chunkSize = 16384;		// Use this value no matter what (using this actually just causes massive cpu usage for large files, too much data is flushed to the browser!)
    $chunkSize = GetChunkSize($fileSize);
    fputs($fp, $zapros);
    fflush($fp);
    $fs = fopen($file, 'r');
    $local_sleep = $sleep_count;
    //echo('<script type="text/javascript">');
    while (!feof($fs)) {
        $data = fread($fs, $chunkSize);
        if ($data === false) {
            fclose($fs);
            fclose($fp);
            html_error(lang(112));
        }
        if ($sleep_count !== false && $sleep_time !== false && is_numeric($sleep_time) && is_numeric($sleep_count) && $sleep_count > 0 && $sleep_time > 0) {
            $local_sleep--;
            if ($local_sleep == 0) {
                usleep($sleep_time);
                $local_sleep = $sleep_count;
            }
        }
        $sendbyte = fputs($fp, $data);
        fflush($fp);
        if ($sendbyte === false) {
            fclose($fs);
            fclose($fp);
            html_error(lang(113));
        }
        $totalsend += $sendbyte;
        $time = getmicrotime() - $timeStart;
        $chunkTime = $time - $lastChunkTime;
        $chunkTime = $chunkTime ? $chunkTime : 1;
        $lastChunkTime = $time;
        $speed = round($sendbyte / 1024 / $chunkTime, 2);
        $percent = round($totalsend / $fileSize * 100, 2);
        echo '<script type="text/javascript">pr(' . "'" . $percent . "', '" . bytesToKbOrMb($totalsend) . "', '" . $speed . "');</script>\n";
        flush();
    }
    //echo('</script>');
    fclose($fs);
    fputs($fp, $nn . "--" . $bound . "--" . $nn);
    fflush($fp);
    while (!feof($fp)) {
        $data = fgets($fp, 16384);
        if ($data === false) {
            break;
        }
        $page .= $data;
    }
    fclose($fp);
    return $page;
}