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/utils/auth.php

113 lines
2.8 KiB
PHP

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<?php
// 防止外部破解
if(!defined('SYSTEM')) {exit();}
// 判断登录状态
if (ACCESS_KEY != "" && SAVE_CACHE == 1) {
// 从数据库获取
$out = get_userinfo_fromsql();
$uid = $out[0];
$add_time = $out[1];
$due = $out[2];
$expired = $out[3];
// 判断是否不在数据库里
$insert = 0;
if ($add_time == "0") {
$insert = 1; // INSERT 添加内容
}
if ($uid == "0" && $expired == "0") {
$out = get_userinfo();
$uid = $out[0];
$due = $out[1];
$expired = "0";
if ($insert == 1 && $uid != "0") {
// 写入新 key
$sql = "INSERT INTO `keys` (`add_time`,`uid`,`access_key`,`due_date`) VALUES (now(),'$uid','".ACCESS_KEY."','$due')";
$dbh -> exec($sql);
}
} elseif (time() - strtotime($add_time) >= CACHE_TIME_USER) {
// 超时,开始刷新
$out = refresh_userinfo();
$uid = $out[0];
$due = $out[1];
$expired = $out[2];
}
// key已过期 或 服务器不允许未登录用户
if ($uid == "0" && (NEED_LOGIN == 1 || $expired == "1")) {
$baned = 20;
block($baned);
}
} elseif (ACCESS_KEY != "") {
$out = get_userinfo();
$uid = $out[0];
$due = $out[1];
if ($uid == "0" && NEED_LOGIN == 1) {
$baned = 20;
block($baned);
}
}
// 开始鉴权
if (ACCESS_KEY != "") { // access_key 存在
// resign.php 可能会用到
$is_blacklist = false;
$is_whitelist = false;
if (BLOCK_TYPE == "blacklist" || BLOCK_TYPE == "whitelist") {
$url = "https://black.qimo.ink/status.php?access_key=".ACCESS_KEY;
$status = json_decode(get_webpage($url), true);
$code = $status['code'];
if ((string)$code == "0") {
$is_blacklist = $status['data']['is_blacklist'];
$is_whitelist = $status['data']['is_whitelist'];
//$reason = $status['data']['reason'];
}
}
$is_baned = false;
switch (BLOCK_TYPE) {
case "blacklist": // 在线黑名单
if ($is_blacklist) {
$is_baned = true;
$baned = 21;
}
break;
case "whitelist": // 在线白名单
if (!$is_whitelist) {
$is_baned = true;
$baned = 22;
}
break;
case "local_blacklist": // 本地黑名单
if (in_array($uid, $BLACKLIST)) {
$is_baned = true;
$baned = 21;
}
break;
case "local_whitelist": // 本地白名单
if (!in_array($uid, $WHITELIST)) {
$is_baned = true;
$baned = 22;
}
break;
default:
// pass
}
// 开始ban
$support_replace_type = array("hlw","tom","txbb","xyy","all","random"); // 允许替换的类型兼容旧版config
if ($is_baned) {
if (in_array(REPLACE_TYPE, $support_replace_type)) {
include (ROOT_PATH."utils/replace_playurl.php");
replace_playurl();
} else {
block($baned);
}
}
} 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);
}
}
?>