⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 126.php

📁 这段源码把126邮箱做成一个下载站点
💻 PHP
字号:
<?php

///////////////////////
// 126.com 邮箱共享
// ver: 3.0
// date: 2005-10-02
// 程序编译:资源共享网络小组 ShareSource.NET 请尊重原创权益!
//
// 安装说明:
// 1. 在web使用界面下创建一个文件夹
// 2. 留意该文件夹的链接,如http://m142.mail.126.com/coremail/fcg/ldapapp?funcid=mails&sid=BAzOaVKskuhAAcEW&fid=1116136394
//    &fid=........ 为要获得的fid值
// 3. 将欲共享的文件放到该新建文件夹下即可;
//
// 使用说明:
// 1. 程序不带参数运行,显示附件列表
// 2. 参数g,如http://your.host.name/126.php?g=abc.rar,直接下载abc.rar文件
//    注:遇同名文件附件,下载新近文件
//
// 注意事项:
// 1. 一封邮件只能附带一个附件
// 2. 目前只能读取文件夹内第一页的邮件,可适当增加:每页最多显示邮件数
// 3. 为保安全,不要用该信箱存放重要资料
//
// 更新记录:
// 2005-10-02 v3.0 修正连接部分问题
// 2005-09-25 v2.9 修正/重写了获取主题和下载链接的代码,支持gmail邮件附件,
// 2005-05-22 v2.5 修正固定链接下载的错误,添加模板功能,可自行编辑template.htm页面更变显示效果
// 2005-05-16 v2.0  添加固定链接下载功能
// 2005-05-15 v1.0
//
//
// 声明:本程序仅作为学习、测试用途,不保证安全,请勿滥用。敬请通过正常方式使用信箱,保障双方权益。
//////////////////////////////////////////////


/////////////////////////////////////////////

$user = "";        // 126.com mailbox username, exp. peter
$password = "";  // your password.
$fid = "";	//
$templatefile = "template.htm";	

define("VERSION", "3.0");

///////////////////////


////////////////////// DO NOT MODIFY BELOW ////////////////////////
////////////////////// 切勿更改下述内容 /////////////////////////////

/////// Step.1 Login ////////////////
$host = "entry.126.com";
$predata = "POST /cgi/login?language=0&style=-1 HTTP/1.1\r\nHost: ".$host."\r\n";
$postdata = "domain=126.com&language=0&bCookie=&user=".$user."&pass=".$password."&style=-1&enter.x=%B5%C7%A1%A1%C2%BC";
$subdata = "Referer: http://www.126.com/\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: ".strlen($postdata)."\r\n\r\nData found after header end:\r\n\r\n".$postdata."\r\n";

$getText = conn($host, $predata, $subdata);
preg_match("/Location: http:\/\/(.*?)\.mail\.126\.com.*sid=(.*)\r\n/i", $getText, $match1);

/////////
// Array
// (
//     [0] => Location: http://m151.mail.126.com/cgi/ldapapp?funcid=main&sid=WAyamYHPWRYAMBZd
//     [1] => m151
//     [2] => WAyamYHPWRYAMBZd
// )
///////////////////////



/////// Step.2 Share Mailbox ////////////////
$host = $match1[1].".mail.126.com";
$predata = "GET /coremail/fcg/ldapapp?funcid=mails&sid=".$match1[2]."&fid=".$fid." HTTP/1.1\r\nHost: ".$host."\r\n";
$subdata = "\r\n";
$getText = conn($host, $predata, $subdata);
$getText = substr($getText, strpos($getText, "<!--邮件内容部分start-->"), strpos($getText, "<!--内容部分end-->") - strpos($getText, "<!--邮件内容部分start-->"));
$getText = str_replace("\n", " ", $getText);
preg_match_all("/div class=\"list4\".*?(mid=.*?)&amp;fid=.*?>/", $getText, $match2, PREG_SET_ORDER);


///////////
// Array
// (
//     [0] => Array
//         (
//             [1] => mid=1tbiXASnz0Jwx1CAvwAAs%252B%520A92%250A8388762%250A1116077941
//         )
//     ......
//     [n] =>
// )
/////////////////////////////////


/////// Step.3 Get Attachment Url ////////////////
$attach = 1;
foreach ($match2 as $att) {
	$predata = "GET /coremail/fcg/ldmsapp?funcid=readlett&sid=".$match1[2]."&".$att[1]."&fid=".$fid."&ord=0&desc=1&start=0&tempname=onepageread.htm HTTP/1.1\r\nHost: ".$host."\r\n";
	$getText = conn($host, $predata, $subdata);
	$getText1 = substr($getText, strpos($getText, "id=\"txtSubject\""), strpos($getText, "id=\"aAddAdress\"") - strpos($getText, "id=\"txtSubject\""));
	$getText1 = substr($getText1, strpos($getText1, "textsubject") + 16, strpos($getText1, "</td>") - strpos($getText1, "textsubject") - 16);
	$getText2 = substr($getText, strpos($getText, "打开:"), strpos($getText, "<font color=\"blue\">下载</font>") - strpos($getText, "打开:"));
	preg_match("/<a href=\"(.*filename=(.*)&download.*)\" target=\"_new\"/", $getText2, $match3);
	$attachment[$attach]['subject'] = $getText1;
	$attachment[$attach]['filename'] = $match3[2];
	$attachment[$attach]['url'] = $match3[1];
	$attach ++;
}
//////////
// Array
// (
//     [1] => Array
//         (
//             [subject] => test
//             [filename] => 426755.jpg
//             [url] => http://m138.mail.126.com/coremail/fcg/ldmsapp/126.rar?lettsid=JANgkANzpSqAEuZc&mid=1tbiJhSv1kJyIN1yNgABsD%250A38%250A16539%250A1116136394&funcid=readpart&part=3&filename=126.rar&download=1
//         )
//     ......
//     [n] =>
// )
////////////////////////////////////////


/////// Step.4 Display ////////////////
if (!empty($_GET['g'])) {
	foreach($attachment as $item) {
		if ($item['filename'] == trim($_GET['g'])) {
			header("Location: ".$item['url']);
			exit;
		}
	}
	print "File Not Found.\n";
	exit;
} else {
	$fp = fopen($templatefile, "rb");
	if (!$fp) {
		die("Can't open template file.");
	}
	$template = fread($fp, filesize($templatefile));
	fclose($fp);
	$template = str_replace("{version}", VERSION, $template);
	preg_match("/<div class=\"url\">(.*)<\/div>/", $template, $match_template);
	$attach = 1;
	$output = null;
	foreach($attachment as $item) {
		$tmp = str_replace("#", $item['url'], $match_template[1]);
		$tmp = str_replace("{no}", $attach, $tmp);
		$tmp = str_replace("{subject}", $item['subject'], $tmp);
		$tmp = str_replace("{file}", $item['filename'], $tmp);
		$output .= "<div class=\"url\">".$tmp."</div>\n";
		$attach ++;
	}
	print str_replace($match_template[0], trim($output), $template);
}
////////////////////////////////////////


function conn($host, $predata, $subdata) {

	$text = null;
	$data="User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.7) Gecko/20050414 Firefox/1.0.4\r\n";
	$data.="Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5\r\n";
	$data.="Accept-Language: en-us,en;q=0.5\r\nAccept-Encoding: gzip,deflate\r\nAccept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7\r\n";
	$data.="Keep-Alive: 300\r\nConnection: Close\r\n";

	$alldata = $predata.$data.$subdata;

//	print $alldata."\n";

	$start_time = time();
	$fp=fsockopen($host, 80, $errno, $errstr, 5);
	if (!$fp) {
		die("Connect Timeout.\n");
	} else {
		socket_set_blocking($fp, True);
		socket_set_timeout($fp, 5);
		
		fputs($fp, $alldata);
		while (!feof($fp)) {
			$text .= fread($fp, 2000);

			$diff = time() - $start_time;
			if ($diff > 24) {
				die("Timeout!\n");
			}

			$status = socket_get_status($fp);
			if ($status['timed_out']) {
				die("Stream Timeout!\n");
			}
		}
	}
	fclose($fp);
	return $text;
}

?>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -