You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
BiliRoaming-PHP-Server/index.php

95 lines
2.5 KiB
PHTML

4 years ago
<?php
// 防止外部破解
define('SYSTEM', TRUE);
define('VERSION', '2.9.4');
// 加上json的Header
header('Content-Type: application/json; charset=utf-8');
// 加载配置
include ("config.php");
4 years ago
// 缓存用
if (SAVE_CACHE==1) {
4 years ago
include ("log.php");
}
// 判断要转发的host
$path = explode('/index.php', $_SERVER['PHP_SELF'])[0];
if ($path=="/intl/gateway/v2/ogv/playurl") {
$host = CUSTOM_HOST_TH;
lock_area();
} elseif ($path=="/intl/gateway/v2/app/search/type") {
$host = CUSTOM_HOST_SUB;
} elseif ($path=="/intl/gateway/v2/app/subtitle") {
$host = CUSTOM_HOST_SUB;
} elseif ($path=="/pgc/player/api/playurl") {
if (AREA=="cn") {
$host = CUSTOM_HOST_CN;
} else if (AREA=="hk") {
$host = CUSTOM_HOST_HK;
} else if (AREA=="tw") {
$host = CUSTOM_HOST_TW;
} else {
$host = CUSTOM_HOST_DEFAULT;
}
lock_area();
} else {
4 years ago
// 欢迎语
exit(WELCOME);
}
// 模块请求都会带上X-From-Biliroaming的请求头为了防止被盗用可以加上请求头判断
$headerStringValue = $_SERVER['HTTP_X_FROM_BILIROAMING'];
if ($headerStringValue=="" && BILIROAMING==1) {
exit(BLOCK_RETURN);
}
// 服务器锁区
function lock_area() {
if ( LOCK_AREA=="1" ) {
if ( !empty($SERVER_AREA) && !in_array(AREA, $SERVER_AREA)) {
exit(BLOCK_RETURN);
}
}
4 years ago
}
4 years ago
// 鉴权
if ($path=="/intl/gateway/v2/ogv/playurl" || $path=="/pgc/player/api/playurl"){
include ("auth.php");
4 years ago
}
4 years ago
// 获取缓存
if (SAVE_CACHE==1) {
4 years ago
include ("cache.php");
4 years ago
$cache = get_cache();
if ($cache != "") {
4 years ago
exit($cache);
}
4 years ago
}
// 指定ip回源
if (IP_RESOLVE==1) {
$host = $hosts[array_rand($hosts)];
$ip = $ips[array_rand($ips)];
}
4 years ago
// 转发到指定服务器
4 years ago
$url = "https://".$host.$path."?".$_SERVER['QUERY_STRING'];
if (IP_RESOLVE==1) {
$output = get_webpage($url,$host,$ip);
}else {
$output = get_webpage($url);
}
print($output);
// 写入缓存
if (SAVE_CACHE==1) {
write_cache();
}
function get_webpage($url,$host="",$ip=""){
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
4 years ago
if (IP_RESOLVE==1) { // 指定ip回源
curl_setopt($ch,CURLOPT_RESOLVE,[$host.":443:".$ip]);
}
curl_setopt($ch,CURLOPT_FOLLOWLOCATION,true);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch,CURLOPT_HTTPHEADER, array(
'User-Agent: '.@$_SERVER["HTTP_USER_AGENT"]
));
$output = curl_exec($ch);
curl_close($ch);
return $output;
4 years ago
}
?>