From b39129682711833811301d73b578da2fbeff08c4 Mon Sep 17 00:00:00 2001 From: yuantuo666 <44130602+yuantuo666@users.noreply.github.com> Date: Sat, 29 Aug 2020 17:26:43 +0800 Subject: [PATCH] =?UTF-8?q?1.4.2=E7=89=88=E6=9C=AC=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 35 +++-- config.php | 23 ++-- functions.php | 101 +++++++++++---- index.php | 302 ++++++++++++++++++++++++-------------------- static/functions.js | 17 ++- 5 files changed, 294 insertions(+), 184 deletions(-) diff --git a/README.md b/README.md index fe80784e..7f7decfd 100644 --- a/README.md +++ b/README.md @@ -5,8 +5,10 @@ PanDownload 网页复刻版,PHP 语言版
因为作者开学了,所以项目将不再频繁更新。 +注意!使用 `1.3.6` 版本及以前的站长,请及时更新到最新版本,老版本存在安全问题,可能导致SVIP账号被盗用。
+[演示](https://i.loli.net/2020/08/29/hdjEKGzTZBu6yQI.gif) + ## Blacklists -- http://pan-jx.kosr.cn/ (版本1.3.3 作者以3元出售密码) - http://byu5.cn/baiduwp/ 以上网站使用本项目源码,未与作者联系而删除作者信息。 @@ -31,23 +33,26 @@ PanDownload 网页复刻版,PHP 语言版
``` define('BDUSS', ''); define('STOKEN', ''); +define('SVIP_BDUSS', ''); define('IsCheckPassword', true); define('Password', '请在这里填写密码啦!ヾ(≧▽≦*)o'); ``` -- 前两项填入你自己的 SVIP 信息就行,获取 cookie 方法见 [PD官网](https://pandownload.com/faq/cookie.html) -- 第三项是是否需要密码的选项 -- 第四项是首页需要输入的密码,但是如果第三项为 `false` 则无效 +- 前两项填入`你自己的百度账号信息`*(SVIP也可)*,用于获取下载列表,获取 cookie 方法见 [PD官网](https://pandownload.com/faq/cookie.html) +- 第三项必须填入`SVIP的BDUSS`,用于获取下载链接,获取cookie方法同上。 +- 第四项是是否需要密码的选项 +- 第五项是首页需要输入的密码,但是如果第三项为 `false` 则无效 - 详细信息可见 `config.php` 的注释 --- -例如,你的SVIP的BDUSS是 `123` ,STOKEN是 `456` ,开启密码并且设置为 `789` ,那么应该将 `config.php` 中设置成以下的代码: +例如,你的BDUSS是 `123` ,STOKEN是 `456` ,SVIP的BDUSS是 `789` ,开启密码并且设置为 `666` ,那么应该将 `config.php` 中设置成以下的代码: ``` define('BDUSS', '123'); define('STOKEN', '456'); +define('SVIP_BDUSS', '789'); define('IsCheckPassword', true); -define('Password', '789'); +define('Password', '666'); ``` ## Thanks @@ -55,14 +60,20 @@ define('Password', '789'); - [PanDownload 网站](https://pandownload.com/ "PanDownload 网站") - [KinhDown 客户端](https://t.me/kinhdown/ "KinhDown 客户端") - [PNL 下载方式](https://www.lanzous.com/u/pnl "PNL 下载方式") -- [LC优化版](https://github.com/lc6464 "LC") +- [LC 优化版](https://github.com/lc6464 "LC") ## New Changes -- 当前版本:`1.4.1` -- 更新日期:2020-8-27 +- 当前版本:`1.4.2` +- 更新日期:2020-8-29 - 修改内容 - - 修改POST内容,让调用接口暂时失效 - - 增加直链解析,可以不设置UA下载(不过并不稳定,且只支持50MB以下文件) + - 列表页面新增超时提醒,5min后弹窗提示。 + - 修复在线播放功能,在设置UA情况下可以播放50MB以上文件。 + - 优化代码,删除打开文件夹每次查询密码是否正确代码。 + - 加入运行时间计算,在控制台中可以查看。 + - 将SVIP的BDUSS分离开,便于后期维护。 + - 隐藏旧链接显示的sharelinkXXX-XXX文件夹(此文件夹无法正常打开)。 + - 增加调试模式,便于反馈问题。 + - 增加自动从分享文本中提取验证密码功能。 ## About #### JavaScript版作者 @@ -82,4 +93,4 @@ B站UP主影视后期系统教学(uid250610800)分享了这个网站,分享的 #### 吾爱破解小工具 在8.25晚上吾爱破解上kemiok作者发布了制作的[度盘IDM高速下载](https://www.52pojie.cn/thread-1254032-1-1.html)小工具。
-关于接口引用,因为论坛的规定,不能留下其他的网站网址,但联系作者得知他也很想去感谢那些站长。
+关于接口引用,因为论坛的规定,不能留下其他的网站网址,但联系作者得知他也很想去感谢那些站长。
\ No newline at end of file diff --git a/config.php b/config.php index ff045247..8471a2d1 100644 --- a/config.php +++ b/config.php @@ -1,4 +1,5 @@ * @link https://imwcr.cn/ * @link https://space.bilibili.com/88197958 * */ -define('programVersion', '1.4.1'); -if (!defined('init')){ // 直接访问处理程序 - http_response_code(403); header('Content-Type: text/plain; charset=utf-8'); header('Refresh: 3;url=./'); +define('programVersion', '1.4.2'); +if (!defined('init')) { // 直接访问处理程序 + http_response_code(403); + header('Content-Type: text/plain; charset=utf-8'); + header('Refresh: 3;url=./'); die("HTTP 403 禁止访问!\r\n此文件是 PanDownload 网页复刻版 PHP 语言版项目版本 " . programVersion . " 的配置文件!\r\n禁止直接访问!"); } -define('BDUSS', ''); // 你的 SVIP BDUSS -define('STOKEN', ''); // 你的 SVIP STOKEN -define('IsCheckPassword', true); // 设为 true 则要求密码为变量 Password 的值,否则提示密码错误;设为 false 则不需要密码。 +define('BDUSS', ''); // 你的 BDUSS +define('STOKEN', ''); // 你的 STOKEN +define('SVIP_BDUSS', ''); // 你的 SVIP BDUSS +define('IsCheckPassword', false); // 设为 true 则要求密码为变量 Password 的值,否则提示密码错误;设为 false 则不需要密码。 define('Password', '请在这里填写密码啦!ヾ(≧▽≦*)o'); // 在下载器首页需要输入的密码,如果将 IsCheckPassWord 设为 false 则无论设置什么都会失效。 -define('Footer',''); // 页脚统计代码放置处 \ No newline at end of file +define('Footer', ''); // 页脚统计代码放置处 + +define('APP_ID', '250528'); // 推荐应用ID:498065、309847、778750(油猴脚本默认)、250528(官方)、265486、266719; +define('DEBUG', false);//WARNING! 请勿随意打开此模式,可能造成你的信息泄露。 打开此模式前请先修改密码。 \ No newline at end of file diff --git a/functions.php b/functions.php index 15a92ae8..04a1ccd8 100644 --- a/functions.php +++ b/functions.php @@ -7,7 +7,7 @@ * * 请勿随意修改此文件!如需更改相关配置请到 config.php ! * - * @version 1.4.1 + * @version 1.4.2 * * @author Yuan_Tuo * @link https://imwcr.cn/ @@ -111,20 +111,18 @@ function formatSize(float $size, int $times = 0) default: $unit = '单位未知'; } - return sprintf('%.3f', $size) . $unit; + return sprintf('%.2f', $size) . $unit; } } function CheckPassword() { // 校验密码 if (IsCheckPassword) { if (!isset($_POST["Password"])) { - if (isset($_SESSION["Password"])) { - if ($_SESSION["Password"] === Password) { - echo (isset($_POST["dir"]) || isset($_SESSION["ShowAlert"])) ? '' - : ''; - $_SESSION['ShowAlert'] = true; - return; - } + if (isset($_SESSION["Password"]) and $_SESSION["Password"] === Password) { + echo (isset($_POST["dir"]) || isset($_SESSION["ShowAlert"])) ? '' + : ''; + $_SESSION['ShowAlert'] = true; + return; } } else { if ($_POST["Password"] === Password) { @@ -147,6 +145,11 @@ function verifyPwd(string $surl_1, string $pwd) $data = "pwd=$pwd"; $header = array("User-Agent: netdisk", "Referer: https://pan.baidu.com/disk/home"); $result = json_decode(post($url, $data, $header), true); // -12 提取码错误 + if (DEBUG) { + echo '
verifyPwd():';
+		var_dump($result);
+		echo '
'; + } if ($result["errno"] === 0) return $result["randsk"]; else return 1; } @@ -158,10 +161,22 @@ function getSign(string $surl, $randsk) "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.514.1919.810 Safari/537.36", "Cookie: BDUSS=" . BDUSS . ";STOKEN=" . STOKEN . ";BDCLND=" . $randsk . ";" ); - // if (preg_match('/yunData.setData\((\{.*?\})\);/', get($url, $header), $matches)) return json_decode($matches[1], true); //如果不修改这里,则要修改配置文件ini - if (preg_match('/yunData.setData\((\{.*?\})\);/', get($url, $header), $matches)) return json_decode($matches[1], true, 512, JSON_BIGINT_AS_STRING); - else return 1; + $result = get($url, $header); + if (preg_match('/yunData.setData\((\{.*?\})\);/', $result, $matches)) { + $result = json_decode($matches[1], true, 512, JSON_BIGINT_AS_STRING); + if (DEBUG) { + echo '
getSign():';
+			var_dump($result);
+			echo '
'; + } + return $result; + } else { + if (DEBUG) { + echo '
getSign():no match
'; + } + return 1; + } } function FileList($sign) { @@ -176,32 +191,42 @@ function GetDir(string $dir, string $randsk, string $shareid, string $uk) "Cookie: BDUSS=" . BDUSS . ";STOKEN=" . STOKEN . ";BDCLND=" . $randsk . ";", "Referer: https://pan.baidu.com/disk/home" ); - return json_decode(get($url, $header), true); + $result = json_decode(get($url, $header), true); + if (DEBUG) { + echo '
GetDir():';
+		var_dump($result);
+		echo '
'; + } + return $result; } function FileInfo(string $filename, float $size, string $md5, int $server_ctime) { // 输出 HTML 字符串 return '

文件名:' . $filename . '

文件大小:' . formatSize($size) . '

文件MD5:' . $md5 . '

上传时间:' . date("Y年m月d日 H:i:s", $server_ctime) . '

'; } -function getDlink(string $fs_id, string $timestamp, string $sign, string $randsk, string $share_id, string $uk, string $bdstoken,bool $isnoualink) +function getDlink(string $fs_id, string $timestamp, string $sign, string $randsk, string $share_id, string $uk, string $bdstoken, bool $isnoualink, int $app_id = 250528) { // 获取下载链接 - $app_id = 250528; - //推荐应用ID:498065、309847、778750、250528(官方)、265486、266719; - - if($isnoualink){ - $url = 'https://pan.baidu.com/api/sharedownload?app_id=' . $app_id . '&channel=chunlei&clienttype=0&sign=' . $sign . '×tamp=' . $timestamp . '&web=1&bdstoken='.$bdstoken;//获取直链 50MB以内 - }else{ - $url = 'https://pan.baidu.com/api/sharedownload?app_id=' . $app_id . '&channel=chunlei&clienttype=12&sign=' . $sign . '×tamp=' . $timestamp . '&web=1';//获取下载链接 + + if ($isnoualink) { + $url = 'https://pan.baidu.com/api/sharedownload?app_id=' . $app_id . '&channel=chunlei&clienttype=0&sign=' . $sign . '×tamp=' . $timestamp . '&web=1&bdstoken=' . $bdstoken; //获取直链 50MB以内 + } else { + $url = 'https://pan.baidu.com/api/sharedownload?app_id=' . $app_id . '&channel=chunlei&clienttype=12&sign=' . $sign . '×tamp=' . $timestamp . '&web=1'; //获取下载链接 } - + $data = "encrypt=0" . "&extra=" . urlencode('{"sekey":"' . urldecode($randsk) . '"}') . "&fid_list=[$fs_id]" . "&primaryid=$share_id" . "&uk=$uk" . "&product=share&type=nolimit"; $header = array( "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.514.1919.810 Safari/537.36", "Cookie: BDUSS=" . BDUSS . ";STOKEN=" . STOKEN . ";BDCLND=" . $randsk . ";", "Referer: https://pan.baidu.com/disk/home" ); - return json_decode(post($url, $data, $header), true); - + $result = json_decode(post($url, $data, $header), true); + if (DEBUG) { + echo '
getDlink():';
+		var_dump($result);
+		echo '
'; + } + return $result; + //没有 referer 就 112 ,然后没有 sekey 参数就 118 -20出现验证码 // 参数 类型 描述 // list json array 文件信息列表 @@ -218,9 +243,33 @@ function getDlink(string $fs_id, string $timestamp, string $sign, string $randsk // list[0]["width"] int 图片宽度 // list[0]["date_taken"] int 图片拍摄时间 } -function dl_error(string $title, string $content) +function dl_error(string $title, string $content, bool $jumptip = false) { echo '
'; +
' . $title . '

' . $content; + if ($jumptip) { + echo '
请打开调试模式,并将错误信息复制提交issue到github项目。'; + } + echo '

'; return 0; } +function get_BDCLND($surl) +{ + $header = head("https://pan.baidu.com/s/" . $surl, []); + $bdclnd = preg_match('/BDCLND=(.+?);/', $header, $matches); + if ($bdclnd) { + if (DEBUG) { + echo '
get_BDCLND():';
+			var_dump($matches[1]);
+			echo '
'; + } + return $matches[1]; + } else { + if (DEBUG) { + echo '
get_BDCLND():';
+			var_dump($header);
+			echo '
'; + } + return ''; + } +} \ No newline at end of file diff --git a/index.php b/index.php index ff2d2642..f2c1bee5 100644 --- a/index.php +++ b/index.php @@ -12,7 +12,7 @@ * * 此项目 GitHub 地址:https://github.com/yuantuo666/baiduwp-php * - * @version 1.4.1 + * @version 1.4.2 * * @author Yuan_Tuo * @link https://imwcr.cn/ @@ -33,18 +33,27 @@ header('Refresh: 5;url=https://github.com/yuantuo666/baiduwp-php'); die("HTTP 503 服务不可用!\r\n缺少相关配置和定义文件!无法正常运行程序!\r\n请重新 Clone 项目并配置!\r\n将在五秒内跳转到 GitHub 储存库!"); } +//保存启动时间 +$system_start_time = microtime(true); // 导入配置和函数 require('config.php'); require('functions.php'); // 通用响应头 header('Content-Type: text/html; charset=utf-8'); header('X-UA-Compatible: IE=edge,chrome=1'); +//隐藏错误代码,保护信息安全 +if (DEBUG) { + error_reporting(E_ALL); +} else { + error_reporting(0); //关闭错误报告 +} ?> + @@ -79,7 +88,15 @@
- $_GET:'; + var_dump($_GET); + echo '$_POST:'; + var_dump($_POST); + echo ''; + } + if (isset($_GET["help"])) { // 帮助页 ?>
@@ -154,14 +171,17 @@
- - + setTimeout("sweetAlert(\'提示\',\'当前页面已失效,请刷新重新获取。\',\'info\');",300000);'; CheckPassword(); $surl = $_POST["surl"]; $pwd = $_POST["pwd"]; if (isset($_POST["dir"])) { - if ($pwd !== '') $randsk = verifyPwd($surl, $pwd); - else $randsk = ''; + //文件夹页面 + if (isset($_POST["randsk"])) $randsk = $_POST["randsk"]; + elseif ($pwd !== '') $randsk = verifyPwd($surl, $pwd); + else $randsk = get_BDCLND('1' . $surl); $shareid = $_POST["share_id"]; $root = getSign($surl, $randsk); if ($root !== 1) { @@ -178,8 +198,9 @@ '; $dir_list = explode("/", $_POST["dir"]); for ($i = 1; $i <= count($dir_list) - 2; $i++) { + if($i == 1 AND strstr($dir_list[$i],"sharelink")) continue; $fullsrc = strstr($_POST["dir"], $dir_list[$i], true) . $dir_list[$i]; - $filecontent .= ''; + $filecontent .= ''; } $filecontent .= '' . '
  • 已全部加载,共' . count($filejson["list"]) . '个
  • '; @@ -191,16 +212,18 @@ ' . $file["server_filename"] . ' ' . formatSize($file["size"]) . ''; else $filecontent .= '
  • - ' . $file["server_filename"] . '
  • '; + ' . $file["server_filename"] . ''; } echo $filecontent . ""; } } else echo '
    '; } else { + //根页面 $surl_1 = substr($surl, 1); - if ($pwd !== '') $randsk = verifyPwd($surl_1, $pwd); - else $randsk = ''; + if (isset($_POST["randsk"])) $randsk = $_POST["randsk"]; + elseif ($pwd !== '') $randsk = verifyPwd($surl_1, $pwd); + else $randsk = get_BDCLND($surl); $root = getSign($surl_1, $randsk); $filejson = FileList($root); if ($filejson !== 1) { @@ -225,7 +248,7 @@ ' . $file["server_filename"] . ' ' . formatSize($file["size"]) . ''; else $filecontent .= '
  • - ' . $file["server_filename"] . '
  • '; + ' . $file["server_filename"] . ''; } echo $filecontent . ""; } @@ -243,23 +266,23 @@ $randsk = $_POST["randsk"]; $share_id = $_POST["share_id"]; $uk = $_POST["uk"]; - $bdstoken=$_POST["bdstoken"]; - $filesize=$_POST["filesize"]; - $nouarealLink="";//重置 - if((int)$filesize<=52428800){ - $json5 = getDlink($fs_id, $timestamp, $sign, $randsk, $share_id, $uk ,$bdstoken,true); - if ($json5["errno"] == 0) { - $nouadlink = $json5["list"][0]["dlink"]; - //开始获取真实链接 - $headerArray = array('User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.514.1919.810 Safari/537.36', 'Cookie: BDUSS=' . BDUSS . ';'); - $getRealLink = head($nouadlink, $headerArray); // 禁止重定向 - $getRealLink = strstr($getRealLink, "Location"); - $getRealLink = substr($getRealLink, 10); - $nouarealLink = getSubstr($getRealLink, "http://", "\r\n"); // 删除 http:// - } - } - $json4 = getDlink($fs_id, $timestamp, $sign, $randsk, $share_id, $uk ,$bdstoken,false); - + $bdstoken = $_POST["bdstoken"]; + $filesize = $_POST["filesize"]; + // 文件小于50MB可以使用这种方法获取: + // $nouarealLink="";//重置 + // if((int)$filesize<=52428800){ + // $json5 = getDlink($fs_id, $timestamp, $sign, $randsk, $share_id, $uk ,$bdstoken,true); + // if ($json5["errno"] == 0) { + // $nouadlink = $json5["list"][0]["dlink"]; + // //开始获取真实链接 + // $headerArray = array('User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.514.1919.810 Safari/537.36', 'Cookie: BDUSS=' . BDUSS . ';'); + // $getRealLink = head($nouadlink, $headerArray); // 禁止重定向 + // $getRealLink = strstr($getRealLink, "Location"); + // $getRealLink = substr($getRealLink, 10); + // $nouarealLink = getSubstr($getRealLink, "https://", "\r\n"); // 删除 https:// + // } + // } + $json4 = getDlink($fs_id, $timestamp, $sign, $randsk, $share_id, $uk, $bdstoken, false, APP_ID); if ($json4["errno"] == 0) { $dlink = $json4["list"][0]["dlink"]; //获取文件相关信息 @@ -268,133 +291,144 @@ $size = $json4["list"][0]["size"]; $server_ctime = (int)$json4["list"][0]["server_ctime"] + 28800; // 服务器创建时间 +8:00 //开始获取真实链接 - $headerArray = array('User-Agent: LogStatistic', 'Cookie: BDUSS=' . BDUSS . ';'); + $headerArray = array('User-Agent: LogStatistic', 'Cookie: BDUSS=' . SVIP_BDUSS . ';'); //仅此处用到SVIPBDUSS $getRealLink = head($dlink, $headerArray); // 禁止重定向 $getRealLink = strstr($getRealLink, "Location"); $getRealLink = substr($getRealLink, 10); $realLink = getSubstr($getRealLink, "http://", "\r\n"); // 删除 http:// - + // 1. 使用 dlink 下载文件 2. dlink 有效期为8小时 3. 必需要设置 User-Agent 字段 4. dlink 存在 HTTP 302 跳转 if ($realLink == "") echo '
    '; // 未配置 SVIP 账号 else { - ?> -
    -
    -