From b0d3be773e29ec00bf9cedbf5a2a61768a2d3729 Mon Sep 17 00:00:00 2001 From: david082321 <7046617+david082321@users.noreply.github.com> Date: Sat, 18 Dec 2021 09:12:13 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9C=80=E4=BD=8E=E5=85=81=E8=AE=B8=E6=BC=AB?= =?UTF-8?q?=E6=B8=B8=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. 设置最低允许漫游版本,详情看哔哩漫游仓库 versionCode --- config.php | 1 + utils/auth.php | 15 +++++---- utils/lock_area.php | 9 ++--- utils/process.php | 80 ++++++++++++++------------------------------- 4 files changed, 37 insertions(+), 68 deletions(-) diff --git a/config.php b/config.php index d751e58..a36c391 100644 --- a/config.php +++ b/config.php @@ -14,6 +14,7 @@ define('WEB_ON', 0); // 是否开启web接口 0 否, 1 是 目前Web接口不受 define('LOCK_AREA', 0); // 服务器锁区,须设置$SERVER_AREA。0 否, 1 是 $BLACKLIST = array('1', '2', '3'); // 本地黑名单,填写 uid,可自行添加、删除,注意使用英文,和' $WHITELIST = array('1', '2', '3'); // 本地白名单,填写 uid,可自行添加、删除,注意使用英文,和' +define('ROAMING_MIN_VER', 0); // 设置最低允许漫游版本,详情看哔哩漫游仓库 versionCode // 封锁指定epid视频 define('BAN_EP', 0); // 是否开启ban特定视频 diff --git a/utils/auth.php b/utils/auth.php index 9ed5aa7..347d35f 100644 --- a/utils/auth.php +++ b/utils/auth.php @@ -34,16 +34,14 @@ if (ACCESS_KEY != "" && SAVE_CACHE == 1) { } // key已过期 或 服务器不允许未登录用户 if ($uid == "0" && (NEED_LOGIN == 1 || $expired == "1")) { - $baned = 20; - block($baned); + block(20, "访问密钥已过期或不存在(脚本设置左下角重新授权)"); } } elseif (ACCESS_KEY != "") { $out = get_userinfo(); $uid = $out[0]; $due = $out[1]; if ($uid == "0" && NEED_LOGIN == 1) { - $baned = 20; - block($baned); + block(20, "访问密钥已过期或不存在(脚本设置左下角重新授权)"); } } @@ -68,24 +66,28 @@ if (ACCESS_KEY != "") { // access_key 存在 if ($is_blacklist) { $is_baned = true; $baned = 21; + $reason = "uid黑名单"; } break; case "whitelist": // 在线白名单 if (!$is_whitelist) { $is_baned = true; $baned = 22; + $reason = "uid不在白名单"; } break; case "local_blacklist": // 本地黑名单 if (in_array($uid, $BLACKLIST)) { $is_baned = true; $baned = 21; + $reason = "uid黑名单"; } break; case "local_whitelist": // 本地白名单 if (!in_array($uid, $WHITELIST)) { $is_baned = true; $baned = 22; + $reason = "uid不在白名单"; } break; default: @@ -98,15 +100,14 @@ if (ACCESS_KEY != "") { // access_key 存在 include (ROOT_PATH."utils/replace_playurl.php"); replace_playurl(); } else { - block($baned); + block($baned, $reason); } } } else { // access_key 不存在 if (CID == "13073143" || CID == "120453316") { // 漫游测速 //pass } else if (BLOCK_TYPE == "whitelist" || BLOCK_TYPE == "local_whitelist" || NEED_LOGIN == 1) { // 白名单模式 或 黑名单模式+需要登录 - $baned = 23; - block($baned); + block(23, "未提供访问密钥(漫游需要登录、脚本需要授权)"); } } ?> diff --git a/utils/lock_area.php b/utils/lock_area.php index d205f8c..2aca66c 100644 --- a/utils/lock_area.php +++ b/utils/lock_area.php @@ -5,19 +5,16 @@ if(!defined('SYSTEM')) {exit();} // 锁区、web接口、X-From-Biliroaming if ($cache_type == "app"){ if ($type == 1 && LOCK_AREA == 1 && !empty($SERVER_AREA) && !in_array(AREA, $SERVER_AREA)) { - $baned = 30; - block($baned); // 判断服务器锁区 + block(30, "area黑名单"); } if (BILIROAMING_VERSION == "" && BILIROAMING == 1) { if (WEB_ON == 1 && $path == "/intl/gateway/v2/ogv/view/app/season"){ // web接口会用到东南亚season,特殊放行 } else { - $baned = 31; - block($baned); // 没带上 X-From-Biliroaming 的请求头 + block(31, "此API仅限漫游用户,若误封请到这里提出 github.com/david082321/BiliRoaming-PHP-Server/issues"); } } } elseif ($cache_type == "web" && WEB_ON == 0) { - $baned = 32; - block($baned); // 服务器不开web接口 + block(32, "服务器未开放web接口"); } ?> diff --git a/utils/process.php b/utils/process.php index 7425481..892443e 100644 --- a/utils/process.php +++ b/utils/process.php @@ -12,31 +12,39 @@ define('EP_ID', @$_GET['ep_id']); define('SS_ID', @$_GET['season_id']); define('QN', @$_GET['qn']); define('BILIROAMING_VERSION', @$_SERVER['HTTP_X_FROM_BILIROAMING']); +define('BILIROAMING_VERSION_CODE', @$_SERVER['HTTP_BUILD']); $baned = 0; $th_paths = array("/intl/gateway/v2/app/search/type","/intl/gateway/v2/app/search/v2","/intl/gateway/v2/app/subtitle","/intl/gateway/web/v2/subtitle","/intl/gateway/v2/ogv/view/app/season","/intl/gateway/v2/ogv/view/app/season2","/intl/gateway/v2/ogv/playurl"); -if (BILIROAMING_VERSION == '') { +$get_area = @$_GET['area']; +if (BILIROAMING_VERSION == '' && BILIROAMING_VERSION_CODE == '') { if (BILIROAMING == 1 && WEB_ON == 0) { //仅限漫游用户,且未开放web脚本 - $baned = 10; - block($baned); + block(10, "服务器限漫游使用"); } - if (@$_GET['area'] == '' || @$_GET['area'] == 'false') { //web脚本,兼容泰区无area情况 + if ($get_area == '' || $get_area == 'false') { //web脚本,兼容泰区无area情况 if (in_array($path, $th_paths)) { define('AREA', 'th'); } else { define('AREA', 'noarea'); } } else { - define('AREA', @$_GET['area']); + define('AREA', $get_area); } -} else if (@$_GET['area'] == '') { //适配老漫游版本,兼容泰区无area情况 - - if (in_array($path, $th_paths)) { - define('AREA', 'th'); +} else if (BILIROAMING_VERSION != '' && BILIROAMING_VERSION_CODE != '') { + if ((int)BILIROAMING_VERSION_CODE < ROAMING_MIN_VER) { + block(14, "哔哩漫游模块版本过低"); + } + //适配老漫游版本,兼容泰区无area情况 + if ($get_area == '') { + if (in_array($path, $th_paths)) { + define('AREA', 'th'); + } else { + define('AREA', 'oldversion'); + } } else { - define('AREA', 'oldversion'); + define('AREA', $get_area); } } else { - define('AREA', @$_GET['area']); + block(15, "错误请求头"); } if (@$_GET['ts'] == '') { define('TS', time()); @@ -44,55 +52,17 @@ if (@$_GET['ts'] == '') { define('TS', @$_GET['ts']); } if (in_array(EP_ID, $epid_list) && BAN_EP == 1) { - $baned = 11; - block($baned); + block(11, "ep_id黑名单"); } if (in_array(CID, $cid_list) && BAN_CID == 1) { - $baned = 12; - block($baned); + block(12, "cid黑名单"); } if (in_array(AREA, $BAN_SERVER_AREA)) { - $baned = 13; - block($baned); + block(13, "area黑名单"); } -function block($baned){ - switch ($baned) { - case 10: - $reason = "服务器限漫游使用"; - break; - case 11: - $reason = "ep_id黑名单"; - break; - case 12: - $reason = "cid黑名单"; - break; - case 13: - case 30: - $reason = "area黑名单"; - break; - case 20: - $reason = "访问密钥已过期或不存在(脚本设置左下角重新授权)"; - break; - case 21: - $reason = "uid黑名单"; - break; - case 22: - $reason = "uid不在白名单"; - break; - case 23: - $reason = "未提供访问密钥(漫游需要登录、脚本需要授权)"; - break; - case 31: - $reason = "此API仅限漫游用户,若误封请到这里提出 github.com/david082321/BiliRoaming-PHP-Server/issues"; - break; - case 32: - $reason = "服务器未开放web接口"; - break; - default: - $reason = "未知错误"; - } - http_response_code(404); - exit('{"code":-418,"message":"'.$reason.'"}'); +function block($code, $reason){ + http_response_code(200); // B站就是都返回200 + exit('{"code":-'.$code.',"message":"'.$reason.'"}'); } ?>