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.
Malio/app/Controllers/HomeController.php

244 lines
8.0 KiB
PHTML

9 years ago
<?php
namespace App\Controllers;
use App\Models\InviteCode;
use App\Services\Auth;
9 years ago
use App\Services\Config;
use App\Utils\AliPay;
9 years ago
use App\Utils\TelegramSessionManager;
use App\Utils\TelegramProcess;
use App\Utils\Spay_tool;
use App\Utils\Geetest;
9 years ago
/**
* HomeController
*/
class HomeController extends BaseController
{
public function index()
{
$GtSdk = null;
$recaptcha_sitekey = null;
8 years ago
if (Config::get('captcha_provider') != '') {
switch (Config::get('captcha_provider')) {
case 'recaptcha':
$recaptcha_sitekey = Config::get('recaptcha_sitekey');
break;
case 'geetest':
8 years ago
$uid = time() . random_int(1, 10000);
$GtSdk = Geetest::get($uid);
break;
}
}
if (Config::get('enable_telegram') == 'true') {
$login_text = TelegramSessionManager::add_login_session();
8 years ago
$login = explode('|', $login_text);
$login_token = $login[0];
$login_number = $login[1];
} else {
$login_token = '';
$login_number = '';
}
8 years ago
if (Config::get('newIndex')!='true' && Config::get('theme')=='material') {
return $this->view()->display('indexold.tpl');
} else {
return $this->view()
8 years ago
->assign('geetest_html', $GtSdk)
->assign('login_token', $login_token)
->assign('login_number', $login_number)
->assign('telegram_bot', Config::get('telegram_bot'))
->assign('enable_logincaptcha', Config::get('enable_login_captcha'))
->assign('enable_regcaptcha', Config::get('enable_reg_captcha'))
->assign('base_url', Config::get('baseUrl'))
->assign('recaptcha_sitekey', $recaptcha_sitekey)
->display('index.tpl');
}
9 years ago
}
8 years ago
public function indexold()
{
return $this->view()->display('indexold.tpl');
}
9 years ago
public function code()
{
$codes = InviteCode::where('user_id', '=', '0')->take(10)->get();
return $this->view()->assign('codes', $codes)->display('code.tpl');
}
public function down()
{
}
public function tos()
{
return $this->view()->display('tos.tpl');
}
8 years ago
9 years ago
public function staff()
{
return $this->view()->display('staff.tpl');
}
8 years ago
9 years ago
public function telegram($request, $response, $args)
{
8 years ago
$token = $request->getQueryParams()['token'] ?? '';
8 years ago
9 years ago
if ($token == Config::get('telegram_request_token')) {
TelegramProcess::process();
} else {
8 years ago
echo('不正确请求!');
9 years ago
}
}
8 years ago
9 years ago
public function page404($request, $response, $args)
{
return $this->view()->display('404.tpl');
9 years ago
}
8 years ago
9 years ago
public function page405($request, $response, $args)
{
return $this->view()->display('405.tpl');
9 years ago
}
8 years ago
9 years ago
public function page500($request, $response, $args)
{
8 years ago
return $this->view()->display('500.tpl');
9 years ago
}
8 years ago
public function getOrderList($request, $response, $args)
{
$key = $request->getParam('key');
if (!$key || $key != Config::get('key')) {
$res['ret'] = 0;
8 years ago
$res['msg'] = '错误';
8 years ago
return $response->getBody()->write(json_encode($res));
}
return $response->getBody()->write(json_encode(['data' => AliPay::getList()]));
}
public function setOrder($request, $response, $args)
{
$key = $request->getParam('key');
$sn = $request->getParam('sn');
$url = $request->getParam('url');
if (!$key || $key != Config::get('key')) {
$res['ret'] = 0;
8 years ago
$res['msg'] = '错误';
8 years ago
return $response->getBody()->write(json_encode($res));
}
return $response->getBody()->write(json_encode(['res' => AliPay::setOrder($sn, $url)]));
}
8 years ago
public function getDocCenter($request, $response, $args)
8 years ago
{
$user = Auth::getUser();
if (!$user->isLogin && Config::get('enable_documents') != 'true') {
$newResponse = $response->withStatus(302)->withHeader('Location', '/');
return $newResponse;
}
8 years ago
$basePath = Config::get('remote_documents') == 'true' ? Config::get('documents_source') : '/docs/GeekQu';
return $this->view()
->assign('appName', Config::get('documents_name'))
->assign('basePath', $basePath)
->display('doc/index.tpl');
8 years ago
}
8 years ago
public function getSubLink($request, $response, $args)
8 years ago
{
$user = Auth::getUser();
8 years ago
$msg = '';
8 years ago
if (!$user->isLogin) {
8 years ago
$msg .= '₍₍ ◝(・ω・)◟ ⁾⁾ 您没有登录噢,登录之后再刷新就阔以了啦';
8 years ago
} else {
8 years ago
$msg .= '```' . PHP_EOL;
$subInfo = LinkController::GetSubinfo($user, 0);
8 years ago
switch ($request->getParam('type')) {
case 'ss':
8 years ago
$msg .= '订阅链接:' . $subInfo['ss'];
break;
case 'ssr':
8 years ago
$msg = '订阅链接:' . $subInfo['ssr'];
break;
case 'v2ray':
// v2rayN 格式
8 years ago
$msg = '订阅链接:' . $subInfo['v2ray'];
break;
// APPs~
case 'ssd':
8 years ago
$msg = '订阅链接:' . $subInfo['ssd'];
break;
case 'clash':
8 years ago
$msg = '订阅链接:' . $subInfo['clash'];
break;
case 'surge':
8 years ago
$msg = '// Surge Version 2.x' .
PHP_EOL .
'订阅链接:' .
$subInfo['surge2'] .
'// Surge Version 3.x' .
PHP_EOL .
'订阅链接:' .
$subInfo['surge3'];
break;
case 'kitsunebi':
8 years ago
$msg = '// v2ray 订阅' .
PHP_EOL .
'订阅链接' .
$subInfo['v2ray'] .
'// 合并订阅,包含 ss、v2ray' .
PHP_EOL .
'订阅链接' . $subInfo['v2ray_ss'];
8 years ago
break;
case 'surfboard':
8 years ago
$msg = '订阅链接' . $subInfo['surfboard'];
break;
case 'quantumult_sub':
// Quantumult V2ray 专属格式
8 years ago
$msg = '// ssr 订阅' .
PHP_EOL .
'订阅链接' .
$subInfo['ssr'] .
'// V2ray 订阅' .
PHP_EOL .
'订阅链接' .
$subInfo['quantumult_v2'];
break;
case 'quantumult_conf':
8 years ago
$msg = '// 导入 ss、ssr、v2ray 以及分流规则的配置' .
PHP_EOL .
'订阅链接' .
$subInfo['quantumult_sub'] .
'// 使用自定义策略组的配置,类似 Surge、Clash' .
PHP_EOL .
'订阅链接' .
$subInfo['quantumult_conf'];
break;
case 'shadowrocket':
8 years ago
$msg = '// ssr 订阅' .
PHP_EOL .
'订阅链接' .
$subInfo['ssr'] .
'// v2ray 订阅' .
PHP_EOL .
'订阅链接' .
$subInfo['v2ray'] .
'// 合并订阅,包含 ss、ssr、v2ray' .
PHP_EOL .
'订阅链接' .
$subInfo['v2ray_ss_ssr'];
8 years ago
break;
default:
$msg = '获取失败了呢...,请联系管理员。';
8 years ago
break;
}
8 years ago
$msg .= PHP_EOL . '```';
8 years ago
}
return $msg;
}
9 years ago
}