?? 126.php
字號(hào):
<?php
///////////////////////
// 126.com 郵箱共享
// ver: 3.0
// date: 2005-10-02
// 程序編譯:資源共享網(wǎng)絡(luò)小組 ShareSource.NET 請(qǐng)尊重原創(chuàng)權(quán)益!
//
// 安裝說明:
// 1. 在web使用界面下創(chuàng)建一個(gè)文件夾
// 2. 留意該文件夾的鏈接,如http://m142.mail.126.com/coremail/fcg/ldapapp?funcid=mails&sid=BAzOaVKskuhAAcEW&fid=1116136394
// &fid=........ 為要獲得的fid值
// 3. 將欲共享的文件放到該新建文件夾下即可;
//
// 使用說明:
// 1. 程序不帶參數(shù)運(yùn)行,顯示附件列表
// 2. 參數(shù)g,如http://your.host.name/126.php?g=abc.rar,直接下載abc.rar文件
// 注:遇同名文件附件,下載新近文件
//
// 注意事項(xiàng):
// 1. 一封郵件只能附帶一個(gè)附件
// 2. 目前只能讀取文件夾內(nèi)第一頁的郵件,可適當(dāng)增加:每頁最多顯示郵件數(shù)
// 3. 為保安全,不要用該信箱存放重要資料
//
// 更新記錄:
// 2005-10-02 v3.0 修正連接部分問題
// 2005-09-25 v2.9 修正/重寫了獲取主題和下載鏈接的代碼,支持gmail郵件附件,
// 2005-05-22 v2.5 修正固定鏈接下載的錯(cuò)誤,添加模板功能,可自行編輯template.htm頁面更變顯示效果
// 2005-05-16 v2.0 添加固定鏈接下載功能
// 2005-05-15 v1.0
//
//
// 聲明:本程序僅作為學(xué)習(xí)、測(cè)試用途,不保證安全,請(qǐng)勿濫用。敬請(qǐng)通過正常方式使用信箱,保障雙方權(quán)益。
//////////////////////////////////////////////
/////////////////////////////////////////////
$user = ""; // 126.com mailbox username, exp. peter
$password = ""; // your password.
$fid = ""; //
$templatefile = "template.htm";
define("VERSION", "3.0");
///////////////////////
////////////////////// DO NOT MODIFY BELOW ////////////////////////
////////////////////// 切勿更改下述內(nèi)容 /////////////////////////////
/////// 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, "<!--郵件內(nèi)容部分start-->"), strpos($getText, "<!--內(nèi)容部分end-->") - strpos($getText, "<!--郵件內(nèi)容部分start-->"));
$getText = str_replace("\n", " ", $getText);
preg_match_all("/div class=\"list4\".*?(mid=.*?)&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;
}
?>
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -