Total Pageviews

Saturday 2 July 2016

Rapidleech架设&Mega_co_nz下载插件


rapidleech是一款基于PHP的网盘中转程序(主要支持国外网盘),使用rapidleech下载网盘中的文件后,可以获得一个该文件的链接,然后用户可以用该链接进行下载,如果搭建rapidleech的服务器够给力,下载速度必定比直接从网盘下载快很多~~~
rapidleech官网:http://www.rapidleech.com/
google code项目主页:http://code.google.com/p/rapidleech/

搭建过程:
1.下载rapid leech主程序.

2.进入安装

3.注意事项
至此安装完毕,但是可能有部分文件or文件夹需要设置下权限比如configs文件夹,files文件夹,还有个什么文件来着…..我忘了(一般linux下才会有这问题)

添加mega.co.nz下载插件(暂无上传插件)
进入rapidleech目录下的hosts\download目录新建一个mega_co_nz.php,将以下内容粘贴进去并保存即可
注意:这个插件需要php的mcrypt模块.

<?php
if (!defined('RAPIDLEECH')) {
require_once('index.html');
exit;
}
// Using functions from: http://julien-marchand.fr/blog/using-the-mega-api-with-php-examples/
class mega_co_nz extends DownloadClass {
private $seqno;
public function Download($link) {
if (!extension_loaded('mcrypt') || !function_exists('mcrypt_decrypt') || !in_array('rijndael-128', mcrypt_list_algorithms(), true)) html_error("Mcrypt module isn't installed or it doesn't have support for the needed encryption.");
$this->RLCheck();
$this->seqno = mt_rand();
$this->changeMesg(lang(300).'<br />Mega.co.nz plugin by Th3-822'); // Please, do not remove or change this line contents. - Th3-822
if (!preg_match('@^!([^!]{8})!([\w\-\,]{43})$@i', parse_url($link, PHP_URL_FRAGMENT), $fid)) html_error('FileID or Key not found at link.');
$reply = $this->apiReq(array('a' => 'g', 'g' => '1', 'p' => $fid[1], 'ssl'=> '0'));
if (is_numeric($reply[0])) {
switch ($reply[0]) {
default: $msg = '*No message for this error*';break;
case -1: $msg = 'An internal error has occurred';break;
case -2: $msg = 'You have passed invalid arguments to this command, your rapidleech is outdated?';break;
case -3: $msg = 'A temporary congestion or server malfunction prevented your request from being processed';break;
case -4: $msg = 'You have exceeded your command weight per time quota. Please wait a few seconds, then try again';break;
case -9: $msg = 'File not found';break;
case -11: $msg = 'Access violation';break;
case -13: $msg = 'Trying to access an incomplete file';break;
case -14: $msg = 'A decryption operation failed';break;
case -16: $msg = 'User blocked';break;
case -17: $msg = 'Request over quota';break;
case -18: $msg = 'File temporarily not available, please try again later';break;
// Confirmed at page:
case -6: $msg = 'File not found, account was deleted';break;
}
html_error('[Error: '.$reply[0]."] $msg.");
}
$key = $this->base64_to_a32($fid[2]);
$iv = array_merge(array_slice($key, 4, 2), array(0, 0));
$key = array($key[0] ^ $key[4], $key[1] ^ $key[5], $key[2] ^ $key[6], $key[3] ^ $key[7]);
$attr = $this->dec_attr($this->base64url_decode($reply[0]['at']), $key);
$this->RedirectDownload($reply[0]['g'], $attr['n'], 0, 0, $link, 0, 0, array('T8[fkey]' => $fid[2]));
}
private function RLCheck() {
if (!function_exists('cURL') || (!function_exists('host_matchs') && !function_exists('host_matches')) || !function_exists('GetDefaultParams')) html_error("Your rapidleech version is outdated and it doesn't support this plugin.");
}
private function apiReq($atrr) {
if (!function_exists('json_encode')) html_error('Error: Please enable JSON in php.');
$page = $this->GetPage('https://g.api.mega.co.nz/cs?id=' . ($this->seqno++), 0, json_encode(array($atrr)), "https://mega.co.nz/\r\nContent-Type: application/json");
if (strpos($page, "\r\n\r\n-2") === (strlen($page) - 6)) return array(-2);
return $this->Get_Reply($page);
}
private function Get_Reply($content) {
if (!function_exists('json_decode')) html_error('Error: Please enable JSON in php.');
if (($pos = strpos($content, "\r\n\r\n")) > 0) $content = substr($content, $pos + 4);
$cb_pos = strpos($content, '{');
$sb_pos = strpos($content, '[');
if ($cb_pos === false && $sb_pos === false) html_error('Json start braces not found.');
$sb = ($cb_pos === false || $sb_pos < $cb_pos) ? true : false;
$content = substr($content, strpos($content, ($sb ? '[' : '{')));$content = substr($content, 0, strrpos($content, ($sb ? ']' : '}')) + 1);
if (empty($content)) html_error('No json content.');
$rply = json_decode($content, true);
if (!$rply || count($rply) == 0) html_error('Error reading json.');
return $rply;
}
private function base64url_decode($data) {
if (($s = (2 - strlen($data) * 3) % 4) < 2) $data .= substr(',,', $s);
return base64_decode(strtr($data, '-_,', '+/='));
}
private function base64_to_a32($s) {
return $this->str_to_a32($this->base64url_decode($s));
}
private function str_to_a32($b) {
// Add padding, we need a string with a length multiple of 4
$b = str_pad($b, 4 * ceil(strlen($b) / 4), "\0");
return array_values(unpack('N*', $b));
}
private function a32_to_str($hex) {
return call_user_func_array('pack', array_merge(array('N*'), $hex));
}
private function aes_cbc_decrypt($data, $key) {
return mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $key, $data, MCRYPT_MODE_CBC, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0");
}
private function dec_attr($attr, $key) {
$attr = trim($this->aes_cbc_decrypt($attr, $this->a32_to_str($key)));
if (substr($attr, 0, 6) != 'MEGA{"') return false;
$attr = substr($attr, 4);$attr = substr($attr, 0, strrpos($attr, '}') + 1);
return $this->Get_Reply($attr);
}
public function CheckBack($header) {
$statuscode = intval(substr($header, 9, 3));
if ($statuscode != 200) switch ($statuscode) {
case 509: html_error('[Mega] Transfer quota exeeded.');
case 503: html_error('Too many connections for this download.');
case 403: html_error('Link used/expired.');
case 404: html_error('Link expired.');
default : html_error('[HTTP] '.trim(substr($header, 9, strpos($header, "\n") - 8)));
}
global $fp;
if (empty($fp) || !is_resource($fp)) html_error("Error: Your rapidleech version is outdated and it doesn't support this plugin.");
if (!empty($_GET['T8']['fkey'])) $key = $this->base64_to_a32(urldecode($_GET['T8']['fkey']));
elseif (preg_match('@^!([^!]{8})!([\w\-\,]{43})$@i', parse_url($_GET['referer'], PHP_URL_FRAGMENT), $dat)) $key = $this->base64_to_a32($dat[2]);
else html_error("[CB] File's key not found.");
$iv = array_merge(array_slice($key, 4, 2), array(0, 0));
$key = array($key[0] ^ $key[4], $key[1] ^ $key[5], $key[2] ^ $key[6], $key[3] ^ $key[7]);
$opts = array('iv' => $this->a32_to_str($iv), 'key' => $this->a32_to_str($key), 'mode' => 'ctr');
stream_filter_register('MegaDlDecrypt', 'Th3822_MegaDlDecrypt');
stream_filter_prepend($fp, 'MegaDlDecrypt', STREAM_FILTER_READ, $opts);
}
}
class Th3822_MegaDlDecrypt extends php_user_filter {
private $_td, $_data, $_dlen, $_clen, $bucket;
public function onCreate() {
if (empty($this->params['iv']) || empty($this->params['key']) || empty($this->params['mode'])) return false;
$this->_td = mcrypt_module_open('rijndael-128', '', $this->params['mode'], '');
$init = mcrypt_generic_init($this->_td, $this->params['key'], $this->params['iv']);
if ($init === false || $init < 0) return false;
return true;
}
public function filter($in, $out, &$consumed, $stop) {
while ($bucket = stream_bucket_make_writeable($in)) {
if ($bucket->datalen == 0) continue;
$this->bucket = $bucket;
$this->bucket->data = mdecrypt_generic($this->_td, $this->bucket->data);
$consumed += $bucket->datalen;
stream_bucket_append($out, $this->bucket);
}
return PSFS_PASS_ON;
}
public function onClose() {
mcrypt_generic_deinit($this->_td);
mcrypt_module_close($this->_td);
}
}
//[24-2-2013] Written by Th3-822. (Rapidleech r415 or newer required)
//[02-3-2013] Added "checks" for validating rapidleech version & added 2 error msg. - Th3-822
//[27-3-2013] Simplified Stream decrypt function (The other one was not working well... After many tests looks like it's better now :D). - Th3-822
?>

PS:配合cookies可以下载各种站点的东西.
----------------------------------
 
相关帖子:https://briteming.blogspot.com/2011/12/centos-vpsrapidleech.html
https://github.com/Th3-822/rapidleech