|
@@ -39,7 +39,7 @@ final class SubController extends BaseController
|
|
|
$err_msg = '订阅链接无效';
|
|
|
|
|
|
$subtype = $args['subtype'];
|
|
|
- $subtype_list = ['json', 'clash', 'sip008', 'singbox'];
|
|
|
+ $subtype_list = ['json', 'clash', 'sip008', 'singbox', 'sip002', 'ss', 'v2ray', 'trojan'];
|
|
|
|
|
|
if (! $_ENV['Subscribe'] ||
|
|
|
! in_array($subtype, $subtype_list) ||
|
|
@@ -69,7 +69,8 @@ final class SubController extends BaseController
|
|
|
|
|
|
$content_type = match ($subtype) {
|
|
|
'clash' => 'application/yaml',
|
|
|
- default => 'application/json',
|
|
|
+ 'json','sip008','singbox' => 'application/json',
|
|
|
+ default => 'text/plain',
|
|
|
};
|
|
|
|
|
|
$sub_details = ' upload=' . $user->u
|
|
@@ -86,81 +87,6 @@ final class SubController extends BaseController
|
|
|
->write($sub_info);
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * @param $request
|
|
|
- * @param $response
|
|
|
- * @param $args
|
|
|
- *
|
|
|
- * @return ResponseInterface
|
|
|
- *
|
|
|
- * @throws RedisException
|
|
|
- * @throws GuzzleException
|
|
|
- * @throws ClientExceptionInterface
|
|
|
- * @throws TelegramSDKException
|
|
|
- */
|
|
|
- public static function getTraditionalSubContent($request, $response, $args): ResponseInterface
|
|
|
- {
|
|
|
- $err_msg = '订阅链接无效';
|
|
|
-
|
|
|
- if (! $_ENV['Subscribe'] ||
|
|
|
- ! Config::obtain('enable_traditional_sub') ||
|
|
|
- 'https://' . $request->getHeaderLine('Host') !== $_ENV['subUrl']
|
|
|
- ) {
|
|
|
- return ResponseHelper::error($response, $err_msg);
|
|
|
- }
|
|
|
-
|
|
|
- $antiXss = new AntiXSS();
|
|
|
- $token = $antiXss->xss_clean($args['token']);
|
|
|
-
|
|
|
- if ($_ENV['enable_rate_limit'] &&
|
|
|
- (! RateLimit::checkIPLimit($request->getServerParam('REMOTE_ADDR')) ||
|
|
|
- ! RateLimit::checkSubLimit($token))
|
|
|
- ) {
|
|
|
- return ResponseHelper::error($response, $err_msg);
|
|
|
- }
|
|
|
-
|
|
|
- $link = Link::where('token', $token)->first();
|
|
|
-
|
|
|
- if ($link === null || ! $link->isValid()) {
|
|
|
- return ResponseHelper::error($response, $err_msg);
|
|
|
- }
|
|
|
-
|
|
|
- $user = $link->user();
|
|
|
- $params = $request->getQueryParams();
|
|
|
-
|
|
|
- $sub_types = [
|
|
|
- 'sip002',
|
|
|
- 'ss',
|
|
|
- 'v2ray',
|
|
|
- 'trojan',
|
|
|
- ];
|
|
|
-
|
|
|
- $sub_type = '';
|
|
|
- $sub_info = '';
|
|
|
-
|
|
|
- foreach ($params as $key => $value) {
|
|
|
- if (in_array($key, $sub_types) && $value === '1') {
|
|
|
- $sub_type = $key;
|
|
|
- $sub_info = Subscribe::getContent($user, $sub_type);
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // 记录订阅日志
|
|
|
- if (Config::obtain('subscribe_log')) {
|
|
|
- (new SubscribeLog())->add($user, $sub_type, $antiXss->xss_clean($request->getHeaderLine('User-Agent')));
|
|
|
- }
|
|
|
-
|
|
|
- $sub_details = ' upload=' . $user->u
|
|
|
- . '; download=' . $user->d
|
|
|
- . '; total=' . $user->transfer_enable
|
|
|
- . '; expire=' . strtotime($user->class_expire);
|
|
|
-
|
|
|
- return $response->withHeader('Subscription-Userinfo', $sub_details)->write(
|
|
|
- $sub_info
|
|
|
- );
|
|
|
- }
|
|
|
-
|
|
|
public static function getUniversalSubLink($user): string
|
|
|
{
|
|
|
$userid = $user->id;
|
|
@@ -175,12 +101,4 @@ final class SubController extends BaseController
|
|
|
|
|
|
return $_ENV['subUrl'] . '/sub/' . $token->token;
|
|
|
}
|
|
|
-
|
|
|
- public static function getTraditionalSubLink($user): string
|
|
|
- {
|
|
|
- $userid = $user->id;
|
|
|
- $token = Link::where('userid', $userid)->first();
|
|
|
-
|
|
|
- return $_ENV['subUrl'] . '/link/' . $token->token;
|
|
|
- }
|
|
|
}
|