2019-12-02 17:07:44 +08:00
|
|
|
<?php
|
|
|
|
|
2020-01-29 16:08:50 +08:00
|
|
|
namespace App\Http\Controllers\Client;
|
2019-12-02 17:07:44 +08:00
|
|
|
|
|
|
|
use App\Http\Controllers\Controller;
|
2020-06-18 16:26:50 +08:00
|
|
|
use App\Services\ServerService;
|
2020-06-11 20:47:02 +08:00
|
|
|
use App\Services\UserService;
|
2020-06-18 16:26:50 +08:00
|
|
|
use App\Utils\Clash;
|
2020-01-29 16:08:50 +08:00
|
|
|
use Illuminate\Http\Request;
|
2021-09-21 18:07:53 +08:00
|
|
|
use App\Models\ServerV2ray;
|
2021-06-12 00:56:39 +08:00
|
|
|
use Illuminate\Support\Facades\File;
|
2020-06-11 20:47:02 +08:00
|
|
|
use Symfony\Component\Yaml\Yaml;
|
2019-12-02 17:07:44 +08:00
|
|
|
|
|
|
|
class AppController extends Controller
|
|
|
|
{
|
2020-07-04 17:09:57 +08:00
|
|
|
public function getConfig(Request $request)
|
2020-01-11 13:36:52 +08:00
|
|
|
{
|
2020-09-08 13:58:58 +08:00
|
|
|
$servers = [];
|
2019-12-02 17:07:44 +08:00
|
|
|
$user = $request->user;
|
2020-06-11 20:47:02 +08:00
|
|
|
$userService = new UserService();
|
|
|
|
if ($userService->isAvailable($user)) {
|
2020-06-18 16:26:50 +08:00
|
|
|
$serverService = new ServerService();
|
2020-11-14 17:26:17 +08:00
|
|
|
$servers = $serverService->getAvailableServers($user);
|
2020-06-11 20:47:02 +08:00
|
|
|
}
|
2021-06-12 00:56:39 +08:00
|
|
|
$defaultConfig = base_path() . '/resources/rules/app.clash.yaml';
|
|
|
|
$customConfig = base_path() . '/resources/rules/custom.app.clash.yaml';
|
|
|
|
if (File::exists($customConfig)) {
|
|
|
|
$config = Yaml::parseFile($customConfig);
|
|
|
|
} else {
|
|
|
|
$config = Yaml::parseFile($defaultConfig);
|
|
|
|
}
|
2020-06-11 20:47:02 +08:00
|
|
|
$proxy = [];
|
|
|
|
$proxies = [];
|
2020-06-18 16:26:50 +08:00
|
|
|
|
2020-11-14 23:04:11 +08:00
|
|
|
foreach ($servers as $item) {
|
2022-11-18 20:45:00 +08:00
|
|
|
if ($item['type'] === 'shadowsocks'
|
2022-11-24 17:43:02 +08:00
|
|
|
&& in_array($item['cipher'], [
|
|
|
|
'aes-128-gcm',
|
|
|
|
'aes-192-gcm',
|
|
|
|
'aes-256-gcm',
|
|
|
|
'chacha20-ietf-poly1305'
|
|
|
|
])
|
2022-11-18 20:45:00 +08:00
|
|
|
) {
|
2021-07-03 02:31:28 +08:00
|
|
|
array_push($proxy, Protocols\Clash::buildShadowsocks($user['uuid'], $item));
|
2020-11-15 17:10:32 +08:00
|
|
|
array_push($proxies, $item['name']);
|
2020-11-14 23:04:11 +08:00
|
|
|
}
|
|
|
|
if ($item['type'] === 'v2ray') {
|
2021-07-03 02:31:28 +08:00
|
|
|
array_push($proxy, Protocols\Clash::buildVmess($user['uuid'], $item));
|
2020-11-15 17:10:32 +08:00
|
|
|
array_push($proxies, $item['name']);
|
2020-11-14 23:04:11 +08:00
|
|
|
}
|
|
|
|
if ($item['type'] === 'trojan') {
|
2021-07-03 02:31:28 +08:00
|
|
|
array_push($proxy, Protocols\Clash::buildTrojan($user['uuid'], $item));
|
2020-11-15 17:10:32 +08:00
|
|
|
array_push($proxies, $item['name']);
|
2020-11-14 23:04:11 +08:00
|
|
|
}
|
2020-06-11 20:47:02 +08:00
|
|
|
}
|
|
|
|
|
2020-07-04 17:40:23 +08:00
|
|
|
$config['proxies'] = array_merge($config['proxies'] ? $config['proxies'] : [], $proxy);
|
|
|
|
foreach ($config['proxy-groups'] as $k => $v) {
|
|
|
|
$config['proxy-groups'][$k]['proxies'] = array_merge($config['proxy-groups'][$k]['proxies'], $proxies);
|
2019-12-02 17:07:44 +08:00
|
|
|
}
|
2020-06-11 20:47:02 +08:00
|
|
|
die(Yaml::dump($config));
|
2019-12-02 17:07:44 +08:00
|
|
|
}
|
2019-12-10 09:53:34 +08:00
|
|
|
|
2020-11-19 21:21:21 +08:00
|
|
|
public function getVersion(Request $request)
|
2020-07-04 17:09:57 +08:00
|
|
|
{
|
2020-11-22 16:25:56 +08:00
|
|
|
if (strpos($request->header('user-agent'), 'tidalab/4.0.0') !== false
|
|
|
|
|| strpos($request->header('user-agent'), 'tunnelab/4.0.0') !== false
|
|
|
|
) {
|
2020-11-22 02:01:44 +08:00
|
|
|
if (strpos($request->header('user-agent'), 'Win64') !== false) {
|
2020-11-19 21:21:21 +08:00
|
|
|
return response([
|
|
|
|
'data' => [
|
|
|
|
'version' => config('v2board.windows_version'),
|
|
|
|
'download_url' => config('v2board.windows_download_url')
|
|
|
|
]
|
|
|
|
]);
|
|
|
|
} else {
|
|
|
|
return response([
|
|
|
|
'data' => [
|
|
|
|
'version' => config('v2board.macos_version'),
|
|
|
|
'download_url' => config('v2board.macos_download_url')
|
|
|
|
]
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2020-07-04 17:09:57 +08:00
|
|
|
return response([
|
2020-08-13 14:27:12 +08:00
|
|
|
'data' => [
|
2020-11-19 21:21:21 +08:00
|
|
|
'windows_version' => config('v2board.windows_version'),
|
|
|
|
'windows_download_url' => config('v2board.windows_download_url'),
|
|
|
|
'macos_version' => config('v2board.macos_version'),
|
|
|
|
'macos_download_url' => config('v2board.macos_download_url'),
|
|
|
|
'android_version' => config('v2board.android_version'),
|
|
|
|
'android_download_url' => config('v2board.android_download_url')
|
2020-08-13 14:27:12 +08:00
|
|
|
]
|
2020-07-04 17:09:57 +08:00
|
|
|
]);
|
|
|
|
}
|
2019-12-02 17:07:44 +08:00
|
|
|
}
|