mirror of
https://github.com/v2board/v2board.git
synced 2025-06-05 00:54:54 +08:00
Compare commits
No commits in common. "0.1.0" and "master" have entirely different histories.
18
.env.example
18
.env.example
@ -1,22 +1,22 @@
|
||||
APP_NAME=V2Board
|
||||
APP_ENV=local
|
||||
APP_KEY=
|
||||
APP_DEBUG=true
|
||||
APP_DEBUG=false
|
||||
APP_URL=http://localhost
|
||||
|
||||
LOG_CHANNEL=stack
|
||||
|
||||
DB_CONNECTION=mysql
|
||||
DB_HOST=127.0.0.1
|
||||
DB_HOST=localhost
|
||||
DB_PORT=3306
|
||||
DB_DATABASE=laravel
|
||||
DB_USERNAME=root
|
||||
DB_PASSWORD=
|
||||
DB_PASSWORD=123456
|
||||
|
||||
BROADCAST_DRIVER=log
|
||||
CACHE_DRIVER=file
|
||||
QUEUE_CONNECTION=sync
|
||||
SESSION_DRIVER=file
|
||||
QUEUE_CONNECTION=redis
|
||||
SESSION_DRIVER=redis
|
||||
SESSION_LIFETIME=120
|
||||
|
||||
REDIS_HOST=127.0.0.1
|
||||
@ -31,6 +31,8 @@ MAIL_PASSWORD=null
|
||||
MAIL_ENCRYPTION=null
|
||||
MAIL_FROM_ADDRESS=null
|
||||
MAIL_FROM_NAME=null
|
||||
MAILGUN_DOMAIN=
|
||||
MAILGUN_SECRET=
|
||||
|
||||
AWS_ACCESS_KEY_ID=
|
||||
AWS_SECRET_ACCESS_KEY=
|
||||
@ -44,9 +46,3 @@ PUSHER_APP_CLUSTER=mt1
|
||||
|
||||
MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
|
||||
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
|
||||
|
||||
DEFAULT_INVITE_FORCE=0
|
||||
DEFAULT_INVITE_COMMISSION=10
|
||||
DEFAULT_INVITE_GEN_LIMIT=5
|
||||
DEFAULT_STOP_REGISTER=0
|
||||
DEFAULT_EMAIL_VERIFY=0
|
39
.github/ISSUE_TEMPLATE/bug-report----问题反馈.md
vendored
Normal file
39
.github/ISSUE_TEMPLATE/bug-report----问题反馈.md
vendored
Normal file
@ -0,0 +1,39 @@
|
||||
---
|
||||
name: Bug report | 问题反馈
|
||||
about: Tell us what problems you have encountered
|
||||
title: "[BUG]"
|
||||
labels: ''
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
🙇♂️🙇♂️🙇♂️注意:XrayR等非V2Board问题请前往项目方提问
|
||||
🙇♂️🙇♂️🙇♂️Note: XrayR and other non-V2Board issues please go to the project side to ask questions
|
||||
|
||||
|
||||
The V2Board version number you are using
|
||||
当前使用的V2Board版本号
|
||||
--------
|
||||
|
||||
|
||||
Briefly describe the problem you are experiencing
|
||||
简单描述你遇到的问题
|
||||
--------
|
||||
|
||||
|
||||
|
||||
Screenshot of the reported error(Please do desensitization)
|
||||
报告错误的截图(请做脱敏处理)
|
||||
--------
|
||||
|
||||
|
||||
|
||||
Screenshot of the reported error(Please do desensitization)
|
||||
报告错误的截图(请做脱敏处理)
|
||||
--------
|
||||
|
||||
|
||||
|
||||
The latest log files in the storage/logs directory report from #1 (Please do desensitization)
|
||||
storage/logs 目录下最新的日志文件从 #1 开始报告(请做脱敏处理)
|
||||
--------
|
11
.github/ISSUE_TEMPLATE/feature-request---功能请求.md
vendored
Normal file
11
.github/ISSUE_TEMPLATE/feature-request---功能请求.md
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
---
|
||||
name: Feature request | 功能请求
|
||||
about: Tell us what you need
|
||||
title: "[Feature request]"
|
||||
labels: ''
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
Please describe in detail the problems or needs you have encountered.
|
||||
请详细描述你遇到的问题或需求。
|
7
.gitignore
vendored
7
.gitignore
vendored
@ -1,16 +1,21 @@
|
||||
/node_modules
|
||||
/config/v2panel.php
|
||||
/config/v2board.php
|
||||
/public/hot
|
||||
/public/storage
|
||||
/public/env.example.js
|
||||
/storage/*.key
|
||||
/vendor
|
||||
.env
|
||||
.env.backup
|
||||
.phpunit.result.cache
|
||||
.idea
|
||||
.lock
|
||||
Homestead.json
|
||||
Homestead.yaml
|
||||
npm-debug.log
|
||||
yarn-error.log
|
||||
composer.phar
|
||||
composer.lock
|
||||
yarn.lock
|
||||
docker-compose.yml
|
||||
.DS_Store
|
||||
|
16
.styleci.yml
16
.styleci.yml
@ -1,16 +0,0 @@
|
||||
php:
|
||||
preset: laravel
|
||||
enabled:
|
||||
- alpha_ordered_imports
|
||||
disabled:
|
||||
- length_ordered_imports
|
||||
- unused_use
|
||||
finder:
|
||||
not-name:
|
||||
- index.php
|
||||
- server.php
|
||||
js:
|
||||
finder:
|
||||
not-name:
|
||||
- webpack.mix.js
|
||||
css: true
|
21
LICENSE
Normal file
21
LICENSE
Normal file
@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2019 Tokumeikoi
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
@ -2,9 +2,11 @@
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Models\CommissionLog;
|
||||
use Illuminate\Console\Command;
|
||||
use App\Models\Order;
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class CheckCommission extends Command
|
||||
{
|
||||
@ -39,20 +41,87 @@ class CheckCommission extends Command
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$order = Order::where('commission_status', 0)
|
||||
$this->autoCheck();
|
||||
$this->autoPayCommission();
|
||||
}
|
||||
|
||||
public function autoCheck()
|
||||
{
|
||||
if ((int)config('v2board.commission_auto_check_enable', 1)) {
|
||||
Order::where('commission_status', 0)
|
||||
->where('invite_user_id', '!=', NULL)
|
||||
->where('status', 3)
|
||||
->get();
|
||||
foreach ($order as $item) {
|
||||
if ($order->invite_user_id) {
|
||||
$inviter = User::find($order->invite_user_id);
|
||||
if (!$inviter) continue;
|
||||
$inviter->commission_balance = $inviter->commission_balance + $order->commission_balance;
|
||||
if ($inviter->save()) {
|
||||
$item->commission_status = 1;
|
||||
$item->save();
|
||||
}
|
||||
}
|
||||
->where('updated_at', '<=', strtotime('-3 day', time()))
|
||||
->update([
|
||||
'commission_status' => 1
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
public function autoPayCommission()
|
||||
{
|
||||
$orders = Order::where('commission_status', 1)
|
||||
->where('invite_user_id', '!=', NULL)
|
||||
->get();
|
||||
foreach ($orders as $order) {
|
||||
DB::beginTransaction();
|
||||
if (!$this->payHandle($order->invite_user_id, $order)) {
|
||||
DB::rollBack();
|
||||
continue;
|
||||
}
|
||||
$order->commission_status = 2;
|
||||
if (!$order->save()) {
|
||||
DB::rollBack();
|
||||
continue;
|
||||
}
|
||||
DB::commit();
|
||||
}
|
||||
}
|
||||
|
||||
public function payHandle($inviteUserId, Order $order)
|
||||
{
|
||||
$level = 3;
|
||||
if ((int)config('v2board.commission_distribution_enable', 0)) {
|
||||
$commissionShareLevels = [
|
||||
0 => (int)config('v2board.commission_distribution_l1'),
|
||||
1 => (int)config('v2board.commission_distribution_l2'),
|
||||
2 => (int)config('v2board.commission_distribution_l3')
|
||||
];
|
||||
} else {
|
||||
$commissionShareLevels = [
|
||||
0 => 100
|
||||
];
|
||||
}
|
||||
for ($l = 0; $l < $level; $l++) {
|
||||
$inviter = User::find($inviteUserId);
|
||||
if (!$inviter) continue;
|
||||
if (!isset($commissionShareLevels[$l])) continue;
|
||||
$commissionBalance = $order->commission_balance * ($commissionShareLevels[$l] / 100);
|
||||
if (!$commissionBalance) continue;
|
||||
if ((int)config('v2board.withdraw_close_enable', 0)) {
|
||||
$inviter->balance = $inviter->balance + $commissionBalance;
|
||||
} else {
|
||||
$inviter->commission_balance = $inviter->commission_balance + $commissionBalance;
|
||||
}
|
||||
if (!$inviter->save()) {
|
||||
DB::rollBack();
|
||||
return false;
|
||||
}
|
||||
if (!CommissionLog::create([
|
||||
'invite_user_id' => $inviteUserId,
|
||||
'user_id' => $order->user_id,
|
||||
'trade_no' => $order->trade_no,
|
||||
'order_amount' => $order->total_amount,
|
||||
'get_amount' => $commissionBalance
|
||||
])) {
|
||||
DB::rollBack();
|
||||
return false;
|
||||
}
|
||||
$inviteUserId = $inviter->invite_user_id;
|
||||
// update order actual commission balance
|
||||
$order->actual_commission_balance = $order->actual_commission_balance + $commissionBalance;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -2,11 +2,13 @@
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Jobs\OrderHandleJob;
|
||||
use App\Services\OrderService;
|
||||
use Illuminate\Console\Command;
|
||||
use App\Models\Order;
|
||||
use App\Models\User;
|
||||
use App\Models\Plan;
|
||||
use App\Utils\Helper;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class CheckOrder extends Command
|
||||
{
|
||||
@ -41,52 +43,12 @@ class CheckOrder extends Command
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$order = Order::get();
|
||||
foreach ($order as $item) {
|
||||
switch ($item->status) {
|
||||
case 0:
|
||||
if (strtotime($item->created_at) <= (time() - 1800)) {
|
||||
$item->status = 2;
|
||||
$item->save();
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
$this->orderHandle($item);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private function orderHandle ($order) {
|
||||
$user = User::find($order->user_id);
|
||||
if (!$user->plan_id || $order->plan_id == $user->plan_id) {
|
||||
return $this->buy($order, $user);
|
||||
}
|
||||
}
|
||||
|
||||
private function buy ($order, $user) {
|
||||
$plan = Plan::find($order->plan_id);
|
||||
$user->transfer_enable = $plan->transfer_enable * 1073741824;
|
||||
$user->enable = 1;
|
||||
$user->plan_id = $plan->id;
|
||||
$user->group_id = $plan->group_id;
|
||||
$user->expired_at = $this->getTime($order->cycle, $user->expired_at);
|
||||
if ($user->save()) {
|
||||
$order->status = 3;
|
||||
$order->save();
|
||||
}
|
||||
}
|
||||
|
||||
private function getTime ($str, $timestamp) {
|
||||
if ($timestamp < time()) {
|
||||
$timestamp = time();
|
||||
}
|
||||
switch ($str) {
|
||||
case 'month_price': return strtotime('+1 month', $timestamp);
|
||||
case 'quarter_price': return strtotime('+3 month', $timestamp);
|
||||
case 'quarter_price': return strtotime('+6 month', $timestamp);
|
||||
case 'quarter_price': return strtotime('+12 month', $timestamp);
|
||||
ini_set('memory_limit', -1);
|
||||
$orders = Order::whereIn('status', [0, 1])
|
||||
->orderBy('created_at', 'ASC')
|
||||
->get();
|
||||
foreach ($orders as $order) {
|
||||
OrderHandleJob::dispatch($order->trade_no);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
65
app/Console/Commands/CheckServer.php
Normal file
65
app/Console/Commands/CheckServer.php
Normal file
@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Services\ServerService;
|
||||
use App\Services\TelegramService;
|
||||
use App\Utils\CacheKey;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
class CheckServer extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'check:server';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = '节点检查任务';
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$this->checkOffline();
|
||||
}
|
||||
|
||||
private function checkOffline()
|
||||
{
|
||||
$serverService = new ServerService();
|
||||
$servers = $serverService->getAllServers();
|
||||
foreach ($servers as $server) {
|
||||
if ($server['parent_id']) continue;
|
||||
if ($server['last_check_at'] && (time() - $server['last_check_at']) > 1800) {
|
||||
$telegramService = new TelegramService();
|
||||
$message = sprintf(
|
||||
"节点掉线通知\r\n----\r\n节点名称:%s\r\n节点地址:%s\r\n",
|
||||
$server['name'],
|
||||
$server['host']
|
||||
);
|
||||
$telegramService->sendMessageWithAdmin($message);
|
||||
Cache::forget(CacheKey::get(sprintf("SERVER_%s_LAST_CHECK_AT", strtoupper($server['type'])), $server->id));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
52
app/Console/Commands/CheckTicket.php
Normal file
52
app/Console/Commands/CheckTicket.php
Normal file
@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Models\Ticket;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
class CheckTicket extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'check:ticket';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = '工单检查任务';
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
ini_set('memory_limit', -1);
|
||||
$tickets = Ticket::where('status', 0)
|
||||
->where('updated_at', '<=', time() - 24 * 3600)
|
||||
->where('reply_status', 0)
|
||||
->get();
|
||||
foreach ($tickets as $ticket) {
|
||||
if ($ticket->user_id === $ticket->last_reply_user_id) continue;
|
||||
$ticket->status = 1;
|
||||
$ticket->save();
|
||||
}
|
||||
}
|
||||
}
|
51
app/Console/Commands/ClearUser.php
Normal file
51
app/Console/Commands/ClearUser.php
Normal file
@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Models\Ticket;
|
||||
use App\Models\User;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
class ClearUser extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'clear:user';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = '清理用户';
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$builder = User::where('plan_id', NULL)
|
||||
->where('transfer_enable', 0)
|
||||
->where('expired_at', 0)
|
||||
->where('last_login_at', NULL);
|
||||
$count = $builder->count();
|
||||
if ($builder->delete()) {
|
||||
$this->info("已删除${count}位没有任何数据的用户");
|
||||
}
|
||||
}
|
||||
}
|
52
app/Console/Commands/ResetLog.php
Normal file
52
app/Console/Commands/ResetLog.php
Normal file
@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Models\Log;
|
||||
use App\Models\Plan;
|
||||
use App\Models\StatServer;
|
||||
use App\Models\StatUser;
|
||||
use App\Utils\Helper;
|
||||
use Illuminate\Console\Command;
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class ResetLog extends Command
|
||||
{
|
||||
protected $builder;
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'reset:log';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = '清空日志';
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
StatUser::where('record_at', '<', strtotime('-2 month', time()))->delete();
|
||||
StatServer::where('record_at', '<', strtotime('-2 month', time()))->delete();
|
||||
Log::where('created_at', '<', strtotime('-1 month', time()))->delete();
|
||||
}
|
||||
}
|
54
app/Console/Commands/ResetPassword.php
Normal file
54
app/Console/Commands/ResetPassword.php
Normal file
@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Models\Plan;
|
||||
use App\Utils\Helper;
|
||||
use Illuminate\Console\Command;
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class ResetPassword extends Command
|
||||
{
|
||||
protected $builder;
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'reset:password {email}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = '重置用户密码';
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$user = User::where('email', $this->argument('email'))->first();
|
||||
if (!$user) abort(500, '邮箱不存在');
|
||||
$password = Helper::guid(false);
|
||||
$user->password = password_hash($password, PASSWORD_DEFAULT);
|
||||
$user->password_algo = null;
|
||||
if (!$user->save()) abort(500, '重置失败');
|
||||
$this->info("!!!重置成功!!!");
|
||||
$this->info("新密码为:{$password},请尽快修改密码。");
|
||||
}
|
||||
}
|
164
app/Console/Commands/ResetTraffic.php
Normal file
164
app/Console/Commands/ResetTraffic.php
Normal file
@ -0,0 +1,164 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Models\Plan;
|
||||
use Illuminate\Console\Command;
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class ResetTraffic extends Command
|
||||
{
|
||||
protected $builder;
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'reset:traffic';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = '流量清空';
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->builder = User::where('expired_at', '!=', NULL)
|
||||
->where('expired_at', '>', time());
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
ini_set('memory_limit', -1);
|
||||
$resetMethods = Plan::select(
|
||||
DB::raw("GROUP_CONCAT(`id`) as plan_ids"),
|
||||
DB::raw("reset_traffic_method as method")
|
||||
)
|
||||
->groupBy('reset_traffic_method')
|
||||
->get()
|
||||
->toArray();
|
||||
foreach ($resetMethods as $resetMethod) {
|
||||
$planIds = explode(',', $resetMethod['plan_ids']);
|
||||
switch (true) {
|
||||
case ($resetMethod['method'] === NULL): {
|
||||
$resetTrafficMethod = config('v2board.reset_traffic_method', 0);
|
||||
$builder = with(clone($this->builder))->whereIn('plan_id', $planIds);
|
||||
switch ((int)$resetTrafficMethod) {
|
||||
// month first day
|
||||
case 0:
|
||||
$this->resetByMonthFirstDay($builder);
|
||||
break;
|
||||
// expire day
|
||||
case 1:
|
||||
$this->resetByExpireDay($builder);
|
||||
break;
|
||||
// no action
|
||||
case 2:
|
||||
break;
|
||||
// year first day
|
||||
case 3:
|
||||
$this->resetByYearFirstDay($builder);
|
||||
// year expire day
|
||||
case 4:
|
||||
$this->resetByExpireYear($builder);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case ($resetMethod['method'] === 0): {
|
||||
$builder = with(clone($this->builder))->whereIn('plan_id', $planIds);
|
||||
$this->resetByMonthFirstDay($builder);
|
||||
break;
|
||||
}
|
||||
case ($resetMethod['method'] === 1): {
|
||||
$builder = with(clone($this->builder))->whereIn('plan_id', $planIds);
|
||||
$this->resetByExpireDay($builder);
|
||||
break;
|
||||
}
|
||||
case ($resetMethod['method'] === 2): {
|
||||
break;
|
||||
}
|
||||
case ($resetMethod['method'] === 3): {
|
||||
$builder = with(clone($this->builder))->whereIn('plan_id', $planIds);
|
||||
$this->resetByYearFirstDay($builder);
|
||||
break;
|
||||
}
|
||||
case ($resetMethod['method'] === 4): {
|
||||
$builder = with(clone($this->builder))->whereIn('plan_id', $planIds);
|
||||
$this->resetByExpireYear($builder);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function resetByExpireYear($builder):void
|
||||
{
|
||||
$users = [];
|
||||
foreach ($builder->get() as $item) {
|
||||
$expireDay = date('m-d', $item->expired_at);
|
||||
$today = date('m-d');
|
||||
if ($expireDay === $today) {
|
||||
array_push($users, $item->id);
|
||||
}
|
||||
}
|
||||
User::whereIn('id', $users)->update([
|
||||
'u' => 0,
|
||||
'd' => 0
|
||||
]);
|
||||
}
|
||||
|
||||
private function resetByYearFirstDay($builder):void
|
||||
{
|
||||
if ((string)date('md') === '0101') {
|
||||
$builder->update([
|
||||
'u' => 0,
|
||||
'd' => 0
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
private function resetByMonthFirstDay($builder):void
|
||||
{
|
||||
if ((string)date('d') === '01') {
|
||||
$builder->update([
|
||||
'u' => 0,
|
||||
'd' => 0
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
private function resetByExpireDay($builder):void
|
||||
{
|
||||
$lastDay = date('d', strtotime('last day of +0 months'));
|
||||
$users = [];
|
||||
foreach ($builder->get() as $item) {
|
||||
$expireDay = date('d', $item->expired_at);
|
||||
$today = date('d');
|
||||
if ($expireDay === $today) {
|
||||
array_push($users, $item->id);
|
||||
}
|
||||
|
||||
if (($today === $lastDay) && $expireDay >= $lastDay) {
|
||||
array_push($users, $item->id);
|
||||
}
|
||||
}
|
||||
User::whereIn('id', $users)->update([
|
||||
'u' => 0,
|
||||
'd' => 0
|
||||
]);
|
||||
}
|
||||
}
|
58
app/Console/Commands/ResetUser.php
Normal file
58
app/Console/Commands/ResetUser.php
Normal file
@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Models\Plan;
|
||||
use App\Utils\Helper;
|
||||
use Illuminate\Console\Command;
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class ResetUser extends Command
|
||||
{
|
||||
protected $builder;
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'reset:user';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = '重置所有用户信息';
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
if (!$this->confirm("确定要重置所有用户安全信息吗?")) {
|
||||
return;
|
||||
}
|
||||
ini_set('memory_limit', -1);
|
||||
$users = User::all();
|
||||
foreach ($users as $user)
|
||||
{
|
||||
$user->token = Helper::guid();
|
||||
$user->uuid = Helper::guid(true);
|
||||
$user->save();
|
||||
$this->info("已重置用户{$user->email}的安全信息");
|
||||
}
|
||||
}
|
||||
}
|
51
app/Console/Commands/SendRemindMail.php
Normal file
51
app/Console/Commands/SendRemindMail.php
Normal file
@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Services\MailService;
|
||||
use Illuminate\Console\Command;
|
||||
use App\Models\User;
|
||||
use App\Models\MailLog;
|
||||
use App\Jobs\SendEmailJob;
|
||||
|
||||
class SendRemindMail extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'send:remindMail';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = '发送提醒邮件';
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$users = User::all();
|
||||
$mailService = new MailService();
|
||||
foreach ($users as $user) {
|
||||
if ($user->remind_expire) $mailService->remindExpire($user);
|
||||
if ($user->remind_traffic) $mailService->remindTraffic($user);
|
||||
}
|
||||
}
|
||||
}
|
@ -3,24 +3,22 @@
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use App\Models\Order;
|
||||
use App\Models\User;
|
||||
|
||||
class CheckExpire extends Command
|
||||
class Test extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'check:expire';
|
||||
protected $signature = 'test';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = '过期检查';
|
||||
protected $description = '';
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
@ -39,15 +37,5 @@ class CheckExpire extends Command
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$user = User::all();
|
||||
foreach ($user as $item) {
|
||||
if ($user->expired_at < time()) {
|
||||
$user->enable = 0;
|
||||
} else {
|
||||
$user->enable = 1;
|
||||
}
|
||||
$item->save();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
155
app/Console/Commands/V2boardInstall.php
Normal file
155
app/Console/Commands/V2boardInstall.php
Normal file
@ -0,0 +1,155 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Encryption\Encrypter;
|
||||
use App\Models\User;
|
||||
use App\Utils\Helper;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class V2boardInstall extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'v2board:install';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'v2board 安装';
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
try {
|
||||
$this->info("__ ______ ____ _ ");
|
||||
$this->info("\ \ / /___ \| __ ) ___ __ _ _ __ __| | ");
|
||||
$this->info(" \ \ / / __) | _ \ / _ \ / _` | '__/ _` | ");
|
||||
$this->info(" \ V / / __/| |_) | (_) | (_| | | | (_| | ");
|
||||
$this->info(" \_/ |_____|____/ \___/ \__,_|_| \__,_| ");
|
||||
if (\File::exists(base_path() . '/.env')) {
|
||||
$securePath = config('v2board.secure_path', config('v2board.frontend_admin_path', hash('crc32b', config('app.key'))));
|
||||
$this->info("访问 http(s)://你的站点/{$securePath} 进入管理面板,你可以在用户中心修改你的密码。");
|
||||
abort(500, '如需重新安装请删除目录下.env文件');
|
||||
}
|
||||
|
||||
if (!copy(base_path() . '/.env.example', base_path() . '/.env')) {
|
||||
abort(500, '复制环境文件失败,请检查目录权限');
|
||||
}
|
||||
$this->saveToEnv([
|
||||
'APP_KEY' => 'base64:' . base64_encode(Encrypter::generateKey('AES-256-CBC')),
|
||||
'DB_HOST' => $this->ask('请输入数据库地址(默认:localhost)', 'localhost'),
|
||||
'DB_DATABASE' => $this->ask('请输入数据库名'),
|
||||
'DB_USERNAME' => $this->ask('请输入数据库用户名'),
|
||||
'DB_PASSWORD' => $this->ask('请输入数据库密码')
|
||||
]);
|
||||
\Artisan::call('config:clear');
|
||||
\Artisan::call('config:cache');
|
||||
try {
|
||||
DB::connection()->getPdo();
|
||||
} catch (\Exception $e) {
|
||||
abort(500, '数据库连接失败');
|
||||
}
|
||||
$file = \File::get(base_path() . '/database/install.sql');
|
||||
if (!$file) {
|
||||
abort(500, '数据库文件不存在');
|
||||
}
|
||||
$sql = str_replace("\n", "", $file);
|
||||
$sql = preg_split("/;/", $sql);
|
||||
if (!is_array($sql)) {
|
||||
abort(500, '数据库文件格式有误');
|
||||
}
|
||||
$this->info('正在导入数据库请稍等...');
|
||||
foreach ($sql as $item) {
|
||||
try {
|
||||
DB::select(DB::raw($item));
|
||||
} catch (\Exception $e) {
|
||||
}
|
||||
}
|
||||
$this->info('数据库导入完成');
|
||||
$email = '';
|
||||
while (!$email) {
|
||||
$email = $this->ask('请输入管理员邮箱?');
|
||||
}
|
||||
$password = Helper::guid(false);
|
||||
if (!$this->registerAdmin($email, $password)) {
|
||||
abort(500, '管理员账号注册失败,请重试');
|
||||
}
|
||||
|
||||
$this->info('一切就绪');
|
||||
$this->info("管理员邮箱:{$email}");
|
||||
$this->info("管理员密码:{$password}");
|
||||
|
||||
$defaultSecurePath = hash('crc32b', config('app.key'));
|
||||
$this->info("访问 http(s)://你的站点/{$defaultSecurePath} 进入管理面板,你可以在用户中心修改你的密码。");
|
||||
} catch (\Exception $e) {
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private function registerAdmin($email, $password)
|
||||
{
|
||||
$user = new User();
|
||||
$user->email = $email;
|
||||
if (strlen($password) < 8) {
|
||||
abort(500, '管理员密码长度最小为8位字符');
|
||||
}
|
||||
$user->password = password_hash($password, PASSWORD_DEFAULT);
|
||||
$user->uuid = Helper::guid(true);
|
||||
$user->token = Helper::guid();
|
||||
$user->is_admin = 1;
|
||||
return $user->save();
|
||||
}
|
||||
|
||||
private function saveToEnv($data = [])
|
||||
{
|
||||
function set_env_var($key, $value)
|
||||
{
|
||||
if (! is_bool(strpos($value, ' '))) {
|
||||
$value = '"' . $value . '"';
|
||||
}
|
||||
$key = strtoupper($key);
|
||||
|
||||
$envPath = app()->environmentFilePath();
|
||||
$contents = file_get_contents($envPath);
|
||||
|
||||
preg_match("/^{$key}=[^\r\n]*/m", $contents, $matches);
|
||||
|
||||
$oldValue = count($matches) ? $matches[0] : '';
|
||||
|
||||
if ($oldValue) {
|
||||
$contents = str_replace("{$oldValue}", "{$key}={$value}", $contents);
|
||||
} else {
|
||||
$contents = $contents . "\n{$key}={$value}\n";
|
||||
}
|
||||
|
||||
$file = fopen($envPath, 'w');
|
||||
fwrite($file, $contents);
|
||||
return fclose($file);
|
||||
}
|
||||
foreach($data as $key => $value) {
|
||||
set_env_var($key, $value);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
131
app/Console/Commands/V2boardStatistics.php
Normal file
131
app/Console/Commands/V2boardStatistics.php
Normal file
@ -0,0 +1,131 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Models\StatServer;
|
||||
use App\Models\StatUser;
|
||||
use App\Models\User;
|
||||
use App\Services\StatisticalService;
|
||||
use Illuminate\Console\Command;
|
||||
use App\Models\Order;
|
||||
use App\Models\Stat;
|
||||
use App\Models\CommissionLog;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class V2boardStatistics extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'v2board:statistics';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = '统计任务';
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$startAt = microtime(true);
|
||||
ini_set('memory_limit', -1);
|
||||
$this->statUser();
|
||||
$this->statServer();
|
||||
$this->stat();
|
||||
$this->info('耗时' . (microtime(true) - $startAt));
|
||||
}
|
||||
|
||||
private function statServer()
|
||||
{
|
||||
$createdAt = time();
|
||||
$recordAt = strtotime('-1 day', strtotime(date('Y-m-d')));
|
||||
$statService = new StatisticalService();
|
||||
$statService->setStartAt($recordAt);
|
||||
$statService->setServerStats();
|
||||
$stats = $statService->getStatServer();
|
||||
DB::beginTransaction();
|
||||
foreach ($stats as $stat) {
|
||||
if (!StatServer::insert([
|
||||
'server_id' => $stat['server_id'],
|
||||
'server_type' => $stat['server_type'],
|
||||
'u' => $stat['u'],
|
||||
'd' => $stat['d'],
|
||||
'created_at' => $createdAt,
|
||||
'updated_at' => $createdAt,
|
||||
'record_type' => 'd',
|
||||
'record_at' => $recordAt
|
||||
])) {
|
||||
DB::rollback();
|
||||
throw new \Exception('stat server fail');
|
||||
}
|
||||
}
|
||||
DB::commit();
|
||||
$statService->clearStatServer();
|
||||
}
|
||||
|
||||
private function statUser()
|
||||
{
|
||||
$createdAt = time();
|
||||
$recordAt = strtotime('-1 day', strtotime(date('Y-m-d')));
|
||||
$statService = new StatisticalService();
|
||||
$statService->setStartAt($recordAt);
|
||||
$statService->setUserStats();
|
||||
$stats = $statService->getStatUser();
|
||||
DB::beginTransaction();
|
||||
foreach ($stats as $stat) {
|
||||
if (!StatUser::insert([
|
||||
'user_id' => $stat['user_id'],
|
||||
'u' => $stat['u'],
|
||||
'd' => $stat['d'],
|
||||
'server_rate' => $stat['server_rate'],
|
||||
'created_at' => $createdAt,
|
||||
'updated_at' => $createdAt,
|
||||
'record_type' => 'd',
|
||||
'record_at' => $recordAt
|
||||
])) {
|
||||
DB::rollback();
|
||||
throw new \Exception('stat user fail');
|
||||
}
|
||||
}
|
||||
DB::commit();
|
||||
$statService->clearStatUser();
|
||||
}
|
||||
|
||||
private function stat()
|
||||
{
|
||||
$endAt = strtotime(date('Y-m-d'));
|
||||
$startAt = strtotime('-1 day', $endAt);
|
||||
$statisticalService = new StatisticalService();
|
||||
$statisticalService->setStartAt($startAt);
|
||||
$statisticalService->setEndAt($endAt);
|
||||
$data = $statisticalService->generateStatData();
|
||||
$data['record_at'] = $startAt;
|
||||
$data['record_type'] = 'd';
|
||||
$statistic = Stat::where('record_at', $startAt)
|
||||
->where('record_type', 'd')
|
||||
->first();
|
||||
if ($statistic) {
|
||||
$statistic->update($data);
|
||||
return;
|
||||
}
|
||||
Stat::create($data);
|
||||
}
|
||||
}
|
63
app/Console/Commands/V2boardUpdate.php
Normal file
63
app/Console/Commands/V2boardUpdate.php
Normal file
@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class V2boardUpdate extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'v2board:update';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'v2board 更新';
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
\Artisan::call('config:cache');
|
||||
DB::connection()->getPdo();
|
||||
$file = \File::get(base_path() . '/database/update.sql');
|
||||
if (!$file) {
|
||||
abort(500, '数据库文件不存在');
|
||||
}
|
||||
$sql = str_replace("\n", "", $file);
|
||||
$sql = preg_split("/;/", $sql);
|
||||
if (!is_array($sql)) {
|
||||
abort(500, '数据库文件格式有误');
|
||||
}
|
||||
$this->info('正在导入数据库请稍等...');
|
||||
foreach ($sql as $item) {
|
||||
if (!$item) continue;
|
||||
try {
|
||||
DB::select(DB::raw($item));
|
||||
} catch (\Exception $e) {
|
||||
}
|
||||
}
|
||||
\Artisan::call('horizon:terminate');
|
||||
$this->info('更新完毕,队列服务已重启,你无需进行任何操作。');
|
||||
}
|
||||
}
|
19
app/Console/Kernel.php
Executable file → Normal file
19
app/Console/Kernel.php
Executable file → Normal file
@ -2,8 +2,10 @@
|
||||
|
||||
namespace App\Console;
|
||||
|
||||
use App\Utils\CacheKey;
|
||||
use Illuminate\Console\Scheduling\Schedule;
|
||||
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
class Kernel extends ConsoleKernel
|
||||
{
|
||||
@ -24,11 +26,20 @@ class Kernel extends ConsoleKernel
|
||||
*/
|
||||
protected function schedule(Schedule $schedule)
|
||||
{
|
||||
Cache::put(CacheKey::get('SCHEDULE_LAST_CHECK_AT', null), time());
|
||||
// v2board
|
||||
$schedule->command('v2board:statistics')->dailyAt('0:10');
|
||||
// check
|
||||
$schedule->command('check:order')->everyMinute();
|
||||
$schedule->command('check:expire')->everyMinute();
|
||||
$schedule->command('check:commission')->daily();
|
||||
// $schedule->command('inspire')
|
||||
// ->hourly();
|
||||
$schedule->command('check:commission')->everyMinute();
|
||||
$schedule->command('check:ticket')->everyMinute();
|
||||
// reset
|
||||
$schedule->command('reset:traffic')->daily();
|
||||
$schedule->command('reset:log')->daily();
|
||||
// send
|
||||
$schedule->command('send:remindMail')->dailyAt('11:30');
|
||||
// horizon metrics
|
||||
$schedule->command('horizon:snapshot')->everyFiveMinutes();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -2,8 +2,11 @@
|
||||
|
||||
namespace App\Exceptions;
|
||||
|
||||
use Exception;
|
||||
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
|
||||
use Illuminate\Support\Arr;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
use Throwable;
|
||||
use Facade\Ignition\Exceptions\ViewException;
|
||||
|
||||
class Handler extends ExceptionHandler
|
||||
{
|
||||
@ -29,10 +32,12 @@ class Handler extends ExceptionHandler
|
||||
/**
|
||||
* Report or log an exception.
|
||||
*
|
||||
* @param \Exception $exception
|
||||
* @param \Throwable $exception
|
||||
* @return void
|
||||
*
|
||||
* @throws \Throwable
|
||||
*/
|
||||
public function report(Exception $exception)
|
||||
public function report(Throwable $exception)
|
||||
{
|
||||
parent::report($exception);
|
||||
}
|
||||
@ -41,12 +46,32 @@ class Handler extends ExceptionHandler
|
||||
* Render an exception into an HTTP response.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Exception $exception
|
||||
* @return \Illuminate\Http\Response
|
||||
* @param \Throwable $exception
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
*
|
||||
* @throws \Throwable
|
||||
*/
|
||||
public function render($request, Exception $exception)
|
||||
public function render($request, Throwable $exception)
|
||||
{
|
||||
if ($exception instanceof ViewException) {
|
||||
abort(500, "主题渲染失败。如更新主题,参数可能发生变化请重新配置主题后再试。");
|
||||
}
|
||||
return parent::render($request, $exception);
|
||||
}
|
||||
|
||||
|
||||
protected function convertExceptionToArray(Throwable $e)
|
||||
{
|
||||
return config('app.debug') ? [
|
||||
'message' => $e->getMessage(),
|
||||
'exception' => get_class($e),
|
||||
'file' => $e->getFile(),
|
||||
'line' => $e->getLine(),
|
||||
'trace' => collect($e->getTrace())->map(function ($trace) {
|
||||
return Arr::except($trace, ['args']);
|
||||
})->all(),
|
||||
] : [
|
||||
'message' => $this->isHttpException($e) ? $e->getMessage() : __("Uh-oh, we've had some problems, we're working on it."),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@ -3,66 +3,198 @@
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Requests\Admin\ConfigSave;
|
||||
use App\Jobs\SendEmailJob;
|
||||
use App\Services\TelegramService;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Utils\Dict;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Plan;
|
||||
use App\Models\Order;
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
use Illuminate\Support\Facades\File;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
|
||||
class ConfigController extends Controller
|
||||
{
|
||||
public function init () {
|
||||
|
||||
}
|
||||
|
||||
public function index () {
|
||||
public function getEmailTemplate()
|
||||
{
|
||||
$path = resource_path('views/mail/');
|
||||
$files = array_map(function ($item) use ($path) {
|
||||
return str_replace($path, '', $item);
|
||||
}, glob($path . '*'));
|
||||
return response([
|
||||
'data' => [
|
||||
'invite' => [
|
||||
'invite_force' => (int)config('v2board.invite_force', env('DEFAULT_INVITE_FORCE')),
|
||||
'invite_commission' => config('v2board.invite_commission', env('DEFAULT_INVITE_COMMISSION')),
|
||||
'invite_gen_limit' => config('v2board.invite_gen_limit', env('DEFAULT_INVITE_GEN_LIMIT'))
|
||||
],
|
||||
'site' => [
|
||||
'stop_register' => (int)config('v2board.stop_register', env('DEFAULT_STOP_REGISTER')),
|
||||
'email_verify' => (int)config('v2board.email_verify', env('DEFAULT_EMAIL_VERIFY')),
|
||||
'app_name' => config('v2board.app_name', env('APP_NAME')),
|
||||
'app_url' => config('v2board.app_url', env('APP_URL'))
|
||||
],
|
||||
'pay' => [
|
||||
// alipay
|
||||
'alipay_enable' => (int)config('v2board.alipay_enable'),
|
||||
'alipay_appid' => config('v2board.alipay_appid'),
|
||||
'alipay_pubkey' => config('v2board.alipay_pubkey'),
|
||||
'alipay_privkey' => config('v2board.alipay_privkey'),
|
||||
// stripe
|
||||
'stripe_sk_live' => config('v2board.stripe_sk_live'),
|
||||
'stripe_pk_live' => config('v2board.stripe_pk_live'),
|
||||
'stripe_alipay_enable' => (int)config('v2board.stripe_alipay_enable'),
|
||||
'stripe_wepay_enable' => (int)config('v2board.stripe_wepay_enable'),
|
||||
'stripe_webhook_key' => config('v2board.stripe_webhook_key')
|
||||
],
|
||||
'server' => [
|
||||
'server_token' => config('v2board.server_token')
|
||||
]
|
||||
]
|
||||
'data' => $files
|
||||
]);
|
||||
}
|
||||
|
||||
public function save (ConfigSave $request) {
|
||||
$data = $request->input();
|
||||
$array = \Config::get('v2board');
|
||||
foreach ($data as $k => $v) {
|
||||
if (!in_array($k, ConfigSave::filter())) {
|
||||
abort(500, '禁止修改');
|
||||
public function getThemeTemplate()
|
||||
{
|
||||
$path = public_path('theme/');
|
||||
$files = array_map(function ($item) use ($path) {
|
||||
return str_replace($path, '', $item);
|
||||
}, glob($path . '*'));
|
||||
return response([
|
||||
'data' => $files
|
||||
]);
|
||||
}
|
||||
$array[$k] = $v;
|
||||
|
||||
public function testSendMail(Request $request)
|
||||
{
|
||||
$obj = new SendEmailJob([
|
||||
'email' => $request->user['email'],
|
||||
'subject' => 'This is v2board test email',
|
||||
'template_name' => 'notify',
|
||||
'template_value' => [
|
||||
'name' => config('v2board.app_name', 'V2Board'),
|
||||
'content' => 'This is v2board test email',
|
||||
'url' => config('v2board.app_url')
|
||||
]
|
||||
]);
|
||||
return response([
|
||||
'data' => true,
|
||||
'log' => $obj->handle()
|
||||
]);
|
||||
}
|
||||
$data = var_export($array, 1);
|
||||
if(!\File::put(base_path() . '/config/v2board.php', "<?php\n return $data ;")) {
|
||||
|
||||
public function setTelegramWebhook(Request $request)
|
||||
{
|
||||
$hookUrl = url('/api/v1/guest/telegram/webhook?access_token=' . md5(config('v2board.telegram_bot_token', $request->input('telegram_bot_token'))));
|
||||
$telegramService = new TelegramService($request->input('telegram_bot_token'));
|
||||
$telegramService->getMe();
|
||||
$telegramService->setWebhook($hookUrl);
|
||||
return response([
|
||||
'data' => true
|
||||
]);
|
||||
}
|
||||
|
||||
public function fetch(Request $request)
|
||||
{
|
||||
$key = $request->input('key');
|
||||
$data = [
|
||||
'invite' => [
|
||||
'invite_force' => (int)config('v2board.invite_force', 0),
|
||||
'invite_commission' => config('v2board.invite_commission', 10),
|
||||
'invite_gen_limit' => config('v2board.invite_gen_limit', 5),
|
||||
'invite_never_expire' => config('v2board.invite_never_expire', 0),
|
||||
'commission_first_time_enable' => config('v2board.commission_first_time_enable', 1),
|
||||
'commission_auto_check_enable' => config('v2board.commission_auto_check_enable', 1),
|
||||
'commission_withdraw_limit' => config('v2board.commission_withdraw_limit', 100),
|
||||
'commission_withdraw_method' => config('v2board.commission_withdraw_method', Dict::WITHDRAW_METHOD_WHITELIST_DEFAULT),
|
||||
'withdraw_close_enable' => config('v2board.withdraw_close_enable', 0),
|
||||
'commission_distribution_enable' => config('v2board.commission_distribution_enable', 0),
|
||||
'commission_distribution_l1' => config('v2board.commission_distribution_l1'),
|
||||
'commission_distribution_l2' => config('v2board.commission_distribution_l2'),
|
||||
'commission_distribution_l3' => config('v2board.commission_distribution_l3')
|
||||
],
|
||||
'site' => [
|
||||
'logo' => config('v2board.logo'),
|
||||
'force_https' => (int)config('v2board.force_https', 0),
|
||||
'stop_register' => (int)config('v2board.stop_register', 0),
|
||||
'app_name' => config('v2board.app_name', 'V2Board'),
|
||||
'app_description' => config('v2board.app_description', 'V2Board is best!'),
|
||||
'app_url' => config('v2board.app_url'),
|
||||
'subscribe_url' => config('v2board.subscribe_url'),
|
||||
'try_out_plan_id' => (int)config('v2board.try_out_plan_id', 0),
|
||||
'try_out_hour' => (int)config('v2board.try_out_hour', 1),
|
||||
'tos_url' => config('v2board.tos_url'),
|
||||
'currency' => config('v2board.currency', 'CNY'),
|
||||
'currency_symbol' => config('v2board.currency_symbol', '¥'),
|
||||
],
|
||||
'subscribe' => [
|
||||
'plan_change_enable' => (int)config('v2board.plan_change_enable', 1),
|
||||
'reset_traffic_method' => (int)config('v2board.reset_traffic_method', 0),
|
||||
'surplus_enable' => (int)config('v2board.surplus_enable', 1),
|
||||
'new_order_event_id' => (int)config('v2board.new_order_event_id', 0),
|
||||
'renew_order_event_id' => (int)config('v2board.renew_order_event_id', 0),
|
||||
'change_order_event_id' => (int)config('v2board.change_order_event_id', 0),
|
||||
'show_info_to_server_enable' => (int)config('v2board.show_info_to_server_enable', 0)
|
||||
],
|
||||
'frontend' => [
|
||||
'frontend_theme' => config('v2board.frontend_theme', 'v2board'),
|
||||
'frontend_theme_sidebar' => config('v2board.frontend_theme_sidebar', 'light'),
|
||||
'frontend_theme_header' => config('v2board.frontend_theme_header', 'dark'),
|
||||
'frontend_theme_color' => config('v2board.frontend_theme_color', 'default'),
|
||||
'frontend_background_url' => config('v2board.frontend_background_url'),
|
||||
],
|
||||
'server' => [
|
||||
'server_token' => config('v2board.server_token'),
|
||||
'server_pull_interval' => config('v2board.server_pull_interval', 60),
|
||||
'server_push_interval' => config('v2board.server_push_interval', 60),
|
||||
],
|
||||
'email' => [
|
||||
'email_template' => config('v2board.email_template', 'default'),
|
||||
'email_host' => config('v2board.email_host'),
|
||||
'email_port' => config('v2board.email_port'),
|
||||
'email_username' => config('v2board.email_username'),
|
||||
'email_password' => config('v2board.email_password'),
|
||||
'email_encryption' => config('v2board.email_encryption'),
|
||||
'email_from_address' => config('v2board.email_from_address')
|
||||
],
|
||||
'telegram' => [
|
||||
'telegram_bot_enable' => config('v2board.telegram_bot_enable', 0),
|
||||
'telegram_bot_token' => config('v2board.telegram_bot_token'),
|
||||
'telegram_discuss_link' => config('v2board.telegram_discuss_link')
|
||||
],
|
||||
'app' => [
|
||||
'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')
|
||||
],
|
||||
'safe' => [
|
||||
'email_verify' => (int)config('v2board.email_verify', 0),
|
||||
'safe_mode_enable' => (int)config('v2board.safe_mode_enable', 0),
|
||||
'secure_path' => config('v2board.secure_path', config('v2board.frontend_admin_path', hash('crc32b', config('app.key')))),
|
||||
'email_whitelist_enable' => (int)config('v2board.email_whitelist_enable', 0),
|
||||
'email_whitelist_suffix' => config('v2board.email_whitelist_suffix', Dict::EMAIL_WHITELIST_SUFFIX_DEFAULT),
|
||||
'email_gmail_limit_enable' => config('v2board.email_gmail_limit_enable', 0),
|
||||
'recaptcha_enable' => (int)config('v2board.recaptcha_enable', 0),
|
||||
'recaptcha_key' => config('v2board.recaptcha_key'),
|
||||
'recaptcha_site_key' => config('v2board.recaptcha_site_key'),
|
||||
'register_limit_by_ip_enable' => (int)config('v2board.register_limit_by_ip_enable', 0),
|
||||
'register_limit_count' => config('v2board.register_limit_count', 3),
|
||||
'register_limit_expire' => config('v2board.register_limit_expire', 60),
|
||||
'password_limit_enable' => (int)config('v2board.password_limit_enable', 1),
|
||||
'password_limit_count' => config('v2board.password_limit_count', 5),
|
||||
'password_limit_expire' => config('v2board.password_limit_expire', 60)
|
||||
]
|
||||
];
|
||||
if ($key && isset($data[$key])) {
|
||||
return response([
|
||||
'data' => [
|
||||
$key => $data[$key]
|
||||
]
|
||||
]);
|
||||
};
|
||||
// TODO: default should be in Dict
|
||||
return response([
|
||||
'data' => $data
|
||||
]);
|
||||
}
|
||||
|
||||
public function save(ConfigSave $request)
|
||||
{
|
||||
$data = $request->validated();
|
||||
$config = config('v2board');
|
||||
foreach (ConfigSave::RULES as $k => $v) {
|
||||
if (!in_array($k, array_keys(ConfigSave::RULES))) {
|
||||
unset($config[$k]);
|
||||
continue;
|
||||
}
|
||||
if (array_key_exists($k, $data)) {
|
||||
$config[$k] = $data[$k];
|
||||
}
|
||||
}
|
||||
$data = var_export($config, 1);
|
||||
if (!File::put(base_path() . '/config/v2board.php', "<?php\n return $data ;")) {
|
||||
abort(500, '修改失败');
|
||||
}
|
||||
\Artisan::call('config:cache');
|
||||
if (function_exists('opcache_reset')) {
|
||||
if (opcache_reset() === false) {
|
||||
abort(500, '缓存清除失败,请卸载或检查opcache配置状态');
|
||||
}
|
||||
}
|
||||
Artisan::call('config:cache');
|
||||
return response([
|
||||
'data' => true
|
||||
]);
|
||||
|
137
app/Http/Controllers/Admin/CouponController.php
Normal file
137
app/Http/Controllers/Admin/CouponController.php
Normal file
@ -0,0 +1,137 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Requests\Admin\CouponSave;
|
||||
use App\Http\Requests\Admin\CouponGenerate;
|
||||
use App\Models\Plan;
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Coupon;
|
||||
use App\Utils\Helper;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class CouponController extends Controller
|
||||
{
|
||||
public function fetch(Request $request)
|
||||
{
|
||||
$current = $request->input('current') ? $request->input('current') : 1;
|
||||
$pageSize = $request->input('pageSize') >= 10 ? $request->input('pageSize') : 10;
|
||||
$sortType = in_array($request->input('sort_type'), ['ASC', 'DESC']) ? $request->input('sort_type') : 'DESC';
|
||||
$sort = $request->input('sort') ? $request->input('sort') : 'id';
|
||||
$builder = Coupon::orderBy($sort, $sortType);
|
||||
$total = $builder->count();
|
||||
$coupons = $builder->forPage($current, $pageSize)
|
||||
->get();
|
||||
return response([
|
||||
'data' => $coupons,
|
||||
'total' => $total
|
||||
]);
|
||||
}
|
||||
|
||||
public function show(Request $request)
|
||||
{
|
||||
if (empty($request->input('id'))) {
|
||||
abort(500, '参数有误');
|
||||
}
|
||||
$coupon = Coupon::find($request->input('id'));
|
||||
if (!$coupon) {
|
||||
abort(500, '优惠券不存在');
|
||||
}
|
||||
$coupon->show = $coupon->show ? 0 : 1;
|
||||
if (!$coupon->save()) {
|
||||
abort(500, '保存失败');
|
||||
}
|
||||
|
||||
return response([
|
||||
'data' => true
|
||||
]);
|
||||
}
|
||||
|
||||
public function generate(CouponGenerate $request)
|
||||
{
|
||||
if ($request->input('generate_count')) {
|
||||
$this->multiGenerate($request);
|
||||
return;
|
||||
}
|
||||
|
||||
$params = $request->validated();
|
||||
if (!$request->input('id')) {
|
||||
if (!isset($params['code'])) {
|
||||
$params['code'] = Helper::randomChar(8);
|
||||
}
|
||||
if (!Coupon::create($params)) {
|
||||
abort(500, '创建失败');
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
Coupon::find($request->input('id'))->update($params);
|
||||
} catch (\Exception $e) {
|
||||
abort(500, '保存失败');
|
||||
}
|
||||
}
|
||||
|
||||
return response([
|
||||
'data' => true
|
||||
]);
|
||||
}
|
||||
|
||||
private function multiGenerate(CouponGenerate $request)
|
||||
{
|
||||
$coupons = [];
|
||||
$coupon = $request->validated();
|
||||
$coupon['created_at'] = $coupon['updated_at'] = time();
|
||||
$coupon['show'] = 1;
|
||||
unset($coupon['generate_count']);
|
||||
for ($i = 0;$i < $request->input('generate_count');$i++) {
|
||||
$coupon['code'] = Helper::randomChar(8);
|
||||
array_push($coupons, $coupon);
|
||||
}
|
||||
DB::beginTransaction();
|
||||
if (!Coupon::insert(array_map(function ($item) use ($coupon) {
|
||||
// format data
|
||||
if (isset($item['limit_plan_ids']) && is_array($item['limit_plan_ids'])) {
|
||||
$item['limit_plan_ids'] = json_encode($coupon['limit_plan_ids']);
|
||||
}
|
||||
if (isset($item['limit_period']) && is_array($item['limit_period'])) {
|
||||
$item['limit_period'] = json_encode($coupon['limit_period']);
|
||||
}
|
||||
return $item;
|
||||
}, $coupons))) {
|
||||
DB::rollBack();
|
||||
abort(500, '生成失败');
|
||||
}
|
||||
DB::commit();
|
||||
$data = "名称,类型,金额或比例,开始时间,结束时间,可用次数,可用于订阅,券码,生成时间\r\n";
|
||||
foreach($coupons as $coupon) {
|
||||
$type = ['', '金额', '比例'][$coupon['type']];
|
||||
$value = ['', ($coupon['value'] / 100),$coupon['value']][$coupon['type']];
|
||||
$startTime = date('Y-m-d H:i:s', $coupon['started_at']);
|
||||
$endTime = date('Y-m-d H:i:s', $coupon['ended_at']);
|
||||
$limitUse = $coupon['limit_use'] ?? '不限制';
|
||||
$createTime = date('Y-m-d H:i:s', $coupon['created_at']);
|
||||
$limitPlanIds = isset($coupon['limit_plan_ids']) ? implode("/", $coupon['limit_plan_ids']) : '不限制';
|
||||
$data .= "{$coupon['name']},{$type},{$value},{$startTime},{$endTime},{$limitUse},{$limitPlanIds},{$coupon['code']},{$createTime}\r\n";
|
||||
}
|
||||
echo $data;
|
||||
}
|
||||
|
||||
public function drop(Request $request)
|
||||
{
|
||||
if (empty($request->input('id'))) {
|
||||
abort(500, '参数有误');
|
||||
}
|
||||
$coupon = Coupon::find($request->input('id'));
|
||||
if (!$coupon) {
|
||||
abort(500, '优惠券不存在');
|
||||
}
|
||||
if (!$coupon->delete()) {
|
||||
abort(500, '删除失败');
|
||||
}
|
||||
|
||||
return response([
|
||||
'data' => true
|
||||
]);
|
||||
}
|
||||
}
|
113
app/Http/Controllers/Admin/KnowledgeController.php
Normal file
113
app/Http/Controllers/Admin/KnowledgeController.php
Normal file
@ -0,0 +1,113 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Requests\Admin\KnowledgeSave;
|
||||
use App\Http\Requests\Admin\KnowledgeSort;
|
||||
use App\Models\Knowledge;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class KnowledgeController extends Controller
|
||||
{
|
||||
public function fetch(Request $request)
|
||||
{
|
||||
if ($request->input('id')) {
|
||||
$knowledge = Knowledge::find($request->input('id'))->toArray();
|
||||
if (!$knowledge) abort(500, '知识不存在');
|
||||
return response([
|
||||
'data' => $knowledge
|
||||
]);
|
||||
}
|
||||
return response([
|
||||
'data' => Knowledge::select(['title', 'id', 'updated_at', 'category', 'show'])
|
||||
->orderBy('sort', 'ASC')
|
||||
->get()
|
||||
]);
|
||||
}
|
||||
|
||||
public function getCategory(Request $request)
|
||||
{
|
||||
return response([
|
||||
'data' => array_keys(Knowledge::get()->groupBy('category')->toArray())
|
||||
]);
|
||||
}
|
||||
|
||||
public function save(KnowledgeSave $request)
|
||||
{
|
||||
$params = $request->validated();
|
||||
|
||||
if (!$request->input('id')) {
|
||||
if (!Knowledge::create($params)) {
|
||||
abort(500, '创建失败');
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
Knowledge::find($request->input('id'))->update($params);
|
||||
} catch (\Exception $e) {
|
||||
abort(500, '保存失败');
|
||||
}
|
||||
}
|
||||
|
||||
return response([
|
||||
'data' => true
|
||||
]);
|
||||
}
|
||||
|
||||
public function show(Request $request)
|
||||
{
|
||||
if (empty($request->input('id'))) {
|
||||
abort(500, '参数有误');
|
||||
}
|
||||
$knowledge = Knowledge::find($request->input('id'));
|
||||
if (!$knowledge) {
|
||||
abort(500, '知识不存在');
|
||||
}
|
||||
$knowledge->show = $knowledge->show ? 0 : 1;
|
||||
if (!$knowledge->save()) {
|
||||
abort(500, '保存失败');
|
||||
}
|
||||
|
||||
return response([
|
||||
'data' => true
|
||||
]);
|
||||
}
|
||||
|
||||
public function sort(KnowledgeSort $request)
|
||||
{
|
||||
DB::beginTransaction();
|
||||
try {
|
||||
foreach ($request->input('knowledge_ids') as $k => $v) {
|
||||
$knowledge = Knowledge::find($v);
|
||||
$knowledge->timestamps = false;
|
||||
$knowledge->update(['sort' => $k + 1]);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
DB::rollBack();
|
||||
abort(500, '保存失败');
|
||||
}
|
||||
DB::commit();
|
||||
return response([
|
||||
'data' => true
|
||||
]);
|
||||
}
|
||||
|
||||
public function drop(Request $request)
|
||||
{
|
||||
if (empty($request->input('id'))) {
|
||||
abort(500, '参数有误');
|
||||
}
|
||||
$knowledge = Knowledge::find($request->input('id'));
|
||||
if (!$knowledge) {
|
||||
abort(500, '知识不存在');
|
||||
}
|
||||
if (!$knowledge->delete()) {
|
||||
abort(500, '删除失败');
|
||||
}
|
||||
|
||||
return response([
|
||||
'data' => true
|
||||
]);
|
||||
}
|
||||
}
|
81
app/Http/Controllers/Admin/NoticeController.php
Normal file
81
app/Http/Controllers/Admin/NoticeController.php
Normal file
@ -0,0 +1,81 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Requests\Admin\NoticeSave;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Notice;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
class NoticeController extends Controller
|
||||
{
|
||||
public function fetch(Request $request)
|
||||
{
|
||||
return response([
|
||||
'data' => Notice::orderBy('id', 'DESC')->get()
|
||||
]);
|
||||
}
|
||||
|
||||
public function save(NoticeSave $request)
|
||||
{
|
||||
$data = $request->only([
|
||||
'title',
|
||||
'content',
|
||||
'img_url',
|
||||
'tags'
|
||||
]);
|
||||
if (!$request->input('id')) {
|
||||
if (!Notice::create($data)) {
|
||||
abort(500, '保存失败');
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
Notice::find($request->input('id'))->update($data);
|
||||
} catch (\Exception $e) {
|
||||
abort(500, '保存失败');
|
||||
}
|
||||
}
|
||||
return response([
|
||||
'data' => true
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function show(Request $request)
|
||||
{
|
||||
if (empty($request->input('id'))) {
|
||||
abort(500, '参数有误');
|
||||
}
|
||||
$notice = Notice::find($request->input('id'));
|
||||
if (!$notice) {
|
||||
abort(500, '公告不存在');
|
||||
}
|
||||
$notice->show = $notice->show ? 0 : 1;
|
||||
if (!$notice->save()) {
|
||||
abort(500, '保存失败');
|
||||
}
|
||||
|
||||
return response([
|
||||
'data' => true
|
||||
]);
|
||||
}
|
||||
|
||||
public function drop(Request $request)
|
||||
{
|
||||
if (empty($request->input('id'))) {
|
||||
abort(500, '参数错误');
|
||||
}
|
||||
$notice = Notice::find($request->input('id'));
|
||||
if (!$notice) {
|
||||
abort(500, '公告不存在');
|
||||
}
|
||||
if (!$notice->delete()) {
|
||||
abort(500, '删除失败');
|
||||
}
|
||||
return response([
|
||||
'data' => true
|
||||
]);
|
||||
}
|
||||
}
|
@ -2,44 +2,189 @@
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Requests\Admin\OrderAssign;
|
||||
use App\Http\Requests\Admin\OrderUpdate;
|
||||
use App\Http\Requests\Admin\OrderFetch;
|
||||
use App\Models\CommissionLog;
|
||||
use App\Services\OrderService;
|
||||
use App\Services\UserService;
|
||||
use App\Utils\Helper;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Order;
|
||||
use App\Models\User;
|
||||
use App\Models\Plan;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class OrderController extends Controller
|
||||
{
|
||||
public function index (Request $request) {
|
||||
private function filter(Request $request, &$builder)
|
||||
{
|
||||
if ($request->input('filter')) {
|
||||
foreach ($request->input('filter') as $filter) {
|
||||
if ($filter['key'] === 'email') {
|
||||
$user = User::where('email', "%{$filter['value']}%")->first();
|
||||
if (!$user) continue;
|
||||
$builder->where('user_id', $user->id);
|
||||
continue;
|
||||
}
|
||||
if ($filter['condition'] === '模糊') {
|
||||
$filter['condition'] = 'like';
|
||||
$filter['value'] = "%{$filter['value']}%";
|
||||
}
|
||||
$builder->where($filter['key'], $filter['condition'], $filter['value']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function detail(Request $request)
|
||||
{
|
||||
$order = Order::find($request->input('id'));
|
||||
if (!$order) abort(500, '订单不存在');
|
||||
$order['commission_log'] = CommissionLog::where('trade_no', $order->trade_no)->get();
|
||||
if ($order->surplus_order_ids) {
|
||||
$order['surplus_orders'] = Order::whereIn('id', $order->surplus_order_ids)->get();
|
||||
}
|
||||
return response([
|
||||
'data' => $order
|
||||
]);
|
||||
}
|
||||
|
||||
public function fetch(OrderFetch $request)
|
||||
{
|
||||
$current = $request->input('current') ? $request->input('current') : 1;
|
||||
$pageSize = $request->input('pageSize') >= 10 ? $request->input('pageSize') : 10;
|
||||
$orderModel = Order::orderBy('created_at', 'DESC');
|
||||
if ($request->input('trade_no')) {
|
||||
$orderModel->where('trade_no', $request->input('trade_no'));
|
||||
if ($request->input('is_commission')) {
|
||||
$orderModel->where('invite_user_id', '!=', NULL);
|
||||
$orderModel->whereNotIn('status', [0, 2]);
|
||||
$orderModel->where('commission_balance', '>', 0);
|
||||
}
|
||||
$this->filter($request, $orderModel);
|
||||
$total = $orderModel->count();
|
||||
$res = $orderModel->forPage($current, $pageSize)
|
||||
->get();
|
||||
$plan = Plan::get();
|
||||
for ($i = 0; $i < count($res); $i++) {
|
||||
for ($k = 0; $k < count($plan); $k++) {
|
||||
if ($plan[$k]['id'] == $res[$i]['plan_id']) {
|
||||
$res[$i]['plan_name'] = $plan[$k]['name'];
|
||||
}
|
||||
}
|
||||
}
|
||||
return response([
|
||||
'data' => $orderModel->forPage($current, $pageSize)
|
||||
->get(),
|
||||
'data' => $res,
|
||||
'total' => $total
|
||||
]);
|
||||
}
|
||||
|
||||
public function repair (Request $request) {
|
||||
if (empty($request->input('trade_no'))) {
|
||||
abort(500, '参数错误');
|
||||
}
|
||||
public function paid(Request $request)
|
||||
{
|
||||
$order = Order::where('trade_no', $request->input('trade_no'))
|
||||
->where('status', 0)
|
||||
->first();
|
||||
if (!$order) {
|
||||
abort(500, '订单不存在或订单已支付');
|
||||
abort(500, '订单不存在');
|
||||
}
|
||||
$order->status = 1;
|
||||
if (!$order->save()) {
|
||||
abort(500, '保存失败');
|
||||
if ($order->status !== 0) abort(500, '只能对待支付的订单进行操作');
|
||||
|
||||
$orderService = new OrderService($order);
|
||||
if (!$orderService->paid('manual_operation')) {
|
||||
abort(500, '更新失败');
|
||||
}
|
||||
return response([
|
||||
'data' => true
|
||||
]);
|
||||
}
|
||||
|
||||
public function cancel(Request $request)
|
||||
{
|
||||
$order = Order::where('trade_no', $request->input('trade_no'))
|
||||
->first();
|
||||
if (!$order) {
|
||||
abort(500, '订单不存在');
|
||||
}
|
||||
if ($order->status !== 0) abort(500, '只能对待支付的订单进行操作');
|
||||
|
||||
$orderService = new OrderService($order);
|
||||
if (!$orderService->cancel()) {
|
||||
abort(500, '更新失败');
|
||||
}
|
||||
return response([
|
||||
'data' => true
|
||||
]);
|
||||
}
|
||||
|
||||
public function update(OrderUpdate $request)
|
||||
{
|
||||
$params = $request->only([
|
||||
'commission_status'
|
||||
]);
|
||||
|
||||
$order = Order::where('trade_no', $request->input('trade_no'))
|
||||
->first();
|
||||
if (!$order) {
|
||||
abort(500, '订单不存在');
|
||||
}
|
||||
|
||||
try {
|
||||
$order->update($params);
|
||||
} catch (\Exception $e) {
|
||||
abort(500, '更新失败');
|
||||
}
|
||||
|
||||
return response([
|
||||
'data' => true
|
||||
]);
|
||||
}
|
||||
|
||||
public function assign(OrderAssign $request)
|
||||
{
|
||||
$plan = Plan::find($request->input('plan_id'));
|
||||
$user = User::where('email', $request->input('email'))->first();
|
||||
|
||||
if (!$user) {
|
||||
abort(500, '该用户不存在');
|
||||
}
|
||||
|
||||
if (!$plan) {
|
||||
abort(500, '该订阅不存在');
|
||||
}
|
||||
|
||||
$userService = new UserService();
|
||||
if ($userService->isNotCompleteOrderByUserId($user->id)) {
|
||||
abort(500, '该用户还有待支付的订单,无法分配');
|
||||
}
|
||||
|
||||
DB::beginTransaction();
|
||||
$order = new Order();
|
||||
$orderService = new OrderService($order);
|
||||
$order->user_id = $user->id;
|
||||
$order->plan_id = $plan->id;
|
||||
$order->period = $request->input('period');
|
||||
$order->trade_no = Helper::guid();
|
||||
$order->total_amount = $request->input('total_amount');
|
||||
|
||||
if ($order->period === 'reset_price') {
|
||||
$order->type = 4;
|
||||
} else if ($user->plan_id !== NULL && $order->plan_id !== $user->plan_id) {
|
||||
$order->type = 3;
|
||||
} else if ($user->expired_at > time() && $order->plan_id == $user->plan_id) {
|
||||
$order->type = 2;
|
||||
} else {
|
||||
$order->type = 1;
|
||||
}
|
||||
|
||||
$orderService->setInvite($user);
|
||||
|
||||
if (!$order->save()) {
|
||||
DB::rollback();
|
||||
abort(500, '订单创建失败');
|
||||
}
|
||||
|
||||
DB::commit();
|
||||
|
||||
return response([
|
||||
'data' => $order->trade_no
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
133
app/Http/Controllers/Admin/PaymentController.php
Normal file
133
app/Http/Controllers/Admin/PaymentController.php
Normal file
@ -0,0 +1,133 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Requests\Admin\PaymentSave;
|
||||
use App\Services\PaymentService;
|
||||
use App\Utils\Helper;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Payment;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class PaymentController extends Controller
|
||||
{
|
||||
public function getPaymentMethods()
|
||||
{
|
||||
$methods = [];
|
||||
foreach (glob(base_path('app//Payments') . '/*.php') as $file) {
|
||||
array_push($methods, pathinfo($file)['filename']);
|
||||
}
|
||||
return response([
|
||||
'data' => $methods
|
||||
]);
|
||||
}
|
||||
|
||||
public function fetch()
|
||||
{
|
||||
$payments = Payment::orderBy('sort', 'ASC')->get();
|
||||
foreach ($payments as $k => $v) {
|
||||
$notifyUrl = url("/api/v1/guest/payment/notify/{$v->payment}/{$v->uuid}");
|
||||
if ($v->notify_domain) {
|
||||
$parseUrl = parse_url($notifyUrl);
|
||||
$notifyUrl = $v->notify_domain . $parseUrl['path'];
|
||||
}
|
||||
$payments[$k]['notify_url'] = $notifyUrl;
|
||||
}
|
||||
return response([
|
||||
'data' => $payments
|
||||
]);
|
||||
}
|
||||
|
||||
public function getPaymentForm(Request $request)
|
||||
{
|
||||
$paymentService = new PaymentService($request->input('payment'), $request->input('id'));
|
||||
return response([
|
||||
'data' => $paymentService->form()
|
||||
]);
|
||||
}
|
||||
|
||||
public function show(Request $request)
|
||||
{
|
||||
$payment = Payment::find($request->input('id'));
|
||||
if (!$payment) abort(500, '支付方式不存在');
|
||||
$payment->enable = !$payment->enable;
|
||||
if (!$payment->save()) abort(500, '保存失败');
|
||||
return response([
|
||||
'data' => true
|
||||
]);
|
||||
}
|
||||
|
||||
public function save(Request $request)
|
||||
{
|
||||
if (!config('v2board.app_url')) {
|
||||
abort(500, '请在站点配置中配置站点地址');
|
||||
}
|
||||
$params = $request->validate([
|
||||
'name' => 'required',
|
||||
'icon' => 'nullable',
|
||||
'payment' => 'required',
|
||||
'config' => 'required',
|
||||
'notify_domain' => 'nullable|url',
|
||||
'handling_fee_fixed' => 'nullable|integer',
|
||||
'handling_fee_percent' => 'nullable|numeric|between:0.1,100'
|
||||
], [
|
||||
'name.required' => '显示名称不能为空',
|
||||
'payment.required' => '网关参数不能为空',
|
||||
'config.required' => '配置参数不能为空',
|
||||
'notify_domain.url' => '自定义通知域名格式有误',
|
||||
'handling_fee_fixed.integer' => '固定手续费格式有误',
|
||||
'handling_fee_percent.between' => '百分比手续费范围须在0.1-100之间'
|
||||
]);
|
||||
if ($request->input('id')) {
|
||||
$payment = Payment::find($request->input('id'));
|
||||
if (!$payment) abort(500, '支付方式不存在');
|
||||
try {
|
||||
$payment->update($params);
|
||||
} catch (\Exception $e) {
|
||||
abort(500, $e->getMessage());
|
||||
}
|
||||
return response([
|
||||
'data' => true
|
||||
]);
|
||||
}
|
||||
$params['uuid'] = Helper::randomChar(8);
|
||||
if (!Payment::create($params)) {
|
||||
abort(500, '保存失败');
|
||||
}
|
||||
return response([
|
||||
'data' => true
|
||||
]);
|
||||
}
|
||||
|
||||
public function drop(Request $request)
|
||||
{
|
||||
$payment = Payment::find($request->input('id'));
|
||||
if (!$payment) abort(500, '支付方式不存在');
|
||||
return response([
|
||||
'data' => $payment->delete()
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
public function sort(Request $request)
|
||||
{
|
||||
$request->validate([
|
||||
'ids' => 'required|array'
|
||||
], [
|
||||
'ids.required' => '参数有误',
|
||||
'ids.array' => '参数有误'
|
||||
]);
|
||||
DB::beginTransaction();
|
||||
foreach ($request->input('ids') as $k => $v) {
|
||||
if (!Payment::find($v)->update(['sort' => $k + 1])) {
|
||||
DB::rollBack();
|
||||
abort(500, '保存失败');
|
||||
}
|
||||
}
|
||||
DB::commit();
|
||||
return response([
|
||||
'data' => true
|
||||
]);
|
||||
}
|
||||
}
|
@ -3,50 +3,71 @@
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Requests\Admin\PlanSave;
|
||||
use App\Http\Requests\Admin\PlanSort;
|
||||
use App\Http\Requests\Admin\PlanUpdate;
|
||||
use App\Services\PlanService;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Plan;
|
||||
use App\Models\Order;
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class PlanController extends Controller
|
||||
{
|
||||
public function index (Request $request) {
|
||||
public function fetch(Request $request)
|
||||
{
|
||||
$counts = PlanService::countActiveUsers();
|
||||
$plans = Plan::orderBy('sort', 'ASC')->get();
|
||||
foreach ($plans as $k => $v) {
|
||||
$plans[$k]->count = 0;
|
||||
foreach ($counts as $kk => $vv) {
|
||||
if ($plans[$k]->id === $counts[$kk]->plan_id) $plans[$k]->count = $counts[$kk]->count;
|
||||
}
|
||||
}
|
||||
return response([
|
||||
'data' => Plan::get()
|
||||
'data' => $plans
|
||||
]);
|
||||
}
|
||||
|
||||
public function save (PlanSave $request) {
|
||||
public function save(PlanSave $request)
|
||||
{
|
||||
$params = $request->validated();
|
||||
if ($request->input('id')) {
|
||||
$plan = Plan::find($request->input('id'));
|
||||
if (!$plan) {
|
||||
abort(500, '该订阅不存在');
|
||||
}
|
||||
} else {
|
||||
$plan = new Plan();
|
||||
DB::beginTransaction();
|
||||
// update user group id and transfer
|
||||
try {
|
||||
if ($request->input('force_update')) {
|
||||
User::where('plan_id', $plan->id)->update([
|
||||
'group_id' => $params['group_id'],
|
||||
'transfer_enable' => $params['transfer_enable'] * 1073741824,
|
||||
'speed_limit' => $params['speed_limit']
|
||||
]);
|
||||
}
|
||||
$plan->name = $request->input('name');
|
||||
$plan->content = $request->input('content');
|
||||
if ($plan->content) {
|
||||
$plan->content = str_replace(PHP_EOL, '', $plan->content);
|
||||
$plan->update($params);
|
||||
} catch (\Exception $e) {
|
||||
DB::rollBack();
|
||||
abort(500, '保存失败');
|
||||
}
|
||||
$plan->show = $request->input('show');
|
||||
$plan->renew = $request->input('renew');
|
||||
$plan->transfer_enable = $request->input('transfer_enable');
|
||||
$plan->group_id = $request->input('group_id');
|
||||
$plan->month_price = $request->input('month_price');
|
||||
$plan->quarter_price = $request->input('quarter_price');
|
||||
$plan->half_year_price = $request->input('half_year_price');
|
||||
$plan->year_price = $request->input('year_price');
|
||||
|
||||
DB::commit();
|
||||
return response([
|
||||
'data' => $plan->save()
|
||||
'data' => true
|
||||
]);
|
||||
}
|
||||
if (!Plan::create($params)) {
|
||||
abort(500, '创建失败');
|
||||
}
|
||||
return response([
|
||||
'data' => true
|
||||
]);
|
||||
}
|
||||
|
||||
public function drop (Request $request) {
|
||||
public function drop(Request $request)
|
||||
{
|
||||
if (Order::where('plan_id', $request->input('id'))->first()) {
|
||||
abort(500, '该订阅下存在订单无法删除');
|
||||
}
|
||||
@ -64,7 +85,8 @@ class PlanController extends Controller
|
||||
]);
|
||||
}
|
||||
|
||||
public function update (PlanUpdate $request) {
|
||||
public function update(PlanUpdate $request)
|
||||
{
|
||||
$updateData = $request->only([
|
||||
'show',
|
||||
'renew'
|
||||
@ -74,7 +96,10 @@ class PlanController extends Controller
|
||||
if (!$plan) {
|
||||
abort(500, '该订阅不存在');
|
||||
}
|
||||
if (!$plan->update($updateData)) {
|
||||
|
||||
try {
|
||||
$plan->update($updateData);
|
||||
} catch (\Exception $e) {
|
||||
abort(500, '保存失败');
|
||||
}
|
||||
|
||||
@ -82,4 +107,19 @@ class PlanController extends Controller
|
||||
'data' => true
|
||||
]);
|
||||
}
|
||||
|
||||
public function sort(PlanSort $request)
|
||||
{
|
||||
DB::beginTransaction();
|
||||
foreach ($request->input('plan_ids') as $k => $v) {
|
||||
if (!Plan::find($v)->update(['sort' => $k + 1])) {
|
||||
DB::rollBack();
|
||||
abort(500, '保存失败');
|
||||
}
|
||||
}
|
||||
DB::commit();
|
||||
return response([
|
||||
'data' => true
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
85
app/Http/Controllers/Admin/Server/GroupController.php
Normal file
85
app/Http/Controllers/Admin/Server/GroupController.php
Normal file
@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin\Server;
|
||||
|
||||
use App\Models\Plan;
|
||||
use App\Models\ServerShadowsocks;
|
||||
use App\Models\ServerTrojan;
|
||||
use App\Models\ServerVmess;
|
||||
use App\Models\ServerGroup;
|
||||
use App\Models\User;
|
||||
use App\Services\ServerService;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
|
||||
class GroupController extends Controller
|
||||
{
|
||||
public function fetch(Request $request)
|
||||
{
|
||||
if ($request->input('group_id')) {
|
||||
return response([
|
||||
'data' => [ServerGroup::find($request->input('group_id'))]
|
||||
]);
|
||||
}
|
||||
$serverGroups = ServerGroup::get();
|
||||
$serverService = new ServerService();
|
||||
$servers = $serverService->getAllServers();
|
||||
foreach ($serverGroups as $k => $v) {
|
||||
$serverGroups[$k]['user_count'] = User::where('group_id', $v['id'])->count();
|
||||
$serverGroups[$k]['server_count'] = 0;
|
||||
foreach ($servers as $server) {
|
||||
if (in_array($v['id'], $server['group_id'])) {
|
||||
$serverGroups[$k]['server_count'] = $serverGroups[$k]['server_count']+1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return response([
|
||||
'data' => $serverGroups
|
||||
]);
|
||||
}
|
||||
|
||||
public function save(Request $request)
|
||||
{
|
||||
if (empty($request->input('name'))) {
|
||||
abort(500, '组名不能为空');
|
||||
}
|
||||
|
||||
if ($request->input('id')) {
|
||||
$serverGroup = ServerGroup::find($request->input('id'));
|
||||
} else {
|
||||
$serverGroup = new ServerGroup();
|
||||
}
|
||||
|
||||
$serverGroup->name = $request->input('name');
|
||||
return response([
|
||||
'data' => $serverGroup->save()
|
||||
]);
|
||||
}
|
||||
|
||||
public function drop(Request $request)
|
||||
{
|
||||
if ($request->input('id')) {
|
||||
$serverGroup = ServerGroup::find($request->input('id'));
|
||||
if (!$serverGroup) {
|
||||
abort(500, '组不存在');
|
||||
}
|
||||
}
|
||||
|
||||
$servers = ServerVmess::all();
|
||||
foreach ($servers as $server) {
|
||||
if (in_array($request->input('id'), $server->group_id)) {
|
||||
abort(500, '该组已被节点所使用,无法删除');
|
||||
}
|
||||
}
|
||||
|
||||
if (Plan::where('group_id', $request->input('id'))->first()) {
|
||||
abort(500, '该组已被订阅所使用,无法删除');
|
||||
}
|
||||
if (User::where('group_id', $request->input('id'))->first()) {
|
||||
abort(500, '该组已被用户所使用,无法删除');
|
||||
}
|
||||
return response([
|
||||
'data' => $serverGroup->delete()
|
||||
]);
|
||||
}
|
||||
}
|
113
app/Http/Controllers/Admin/Server/HysteriaController.php
Normal file
113
app/Http/Controllers/Admin/Server/HysteriaController.php
Normal file
@ -0,0 +1,113 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin\Server;
|
||||
|
||||
use App\Http\Requests\Admin\ServerVmessSave;
|
||||
use App\Http\Requests\Admin\ServerVmessUpdate;
|
||||
use App\Models\ServerHysteria;
|
||||
use App\Services\ServerService;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\ServerVmess;
|
||||
|
||||
class HysteriaController extends Controller
|
||||
{
|
||||
public function save(Request $request)
|
||||
{
|
||||
$params = $request->validate([
|
||||
'show' => '',
|
||||
'name' => 'required',
|
||||
'group_id' => 'required|array',
|
||||
'route_id' => 'nullable|array',
|
||||
'parent_id' => 'nullable|integer',
|
||||
'host' => 'required',
|
||||
'port' => 'required',
|
||||
'server_port' => 'required',
|
||||
'tags' => 'nullable|array',
|
||||
'rate' => 'required|numeric',
|
||||
'up_mbps' => 'required|numeric|min:1',
|
||||
'down_mbps' => 'required|numeric|min:1',
|
||||
'server_name' => 'nullable',
|
||||
'insecure' => 'required|in:0,1'
|
||||
]);
|
||||
|
||||
if ($request->input('id')) {
|
||||
$server = ServerHysteria::find($request->input('id'));
|
||||
if (!$server) {
|
||||
abort(500, '服务器不存在');
|
||||
}
|
||||
try {
|
||||
$server->update($params);
|
||||
} catch (\Exception $e) {
|
||||
abort(500, '保存失败');
|
||||
}
|
||||
return response([
|
||||
'data' => true
|
||||
]);
|
||||
}
|
||||
|
||||
if (!ServerHysteria::create($params)) {
|
||||
abort(500, '创建失败');
|
||||
}
|
||||
|
||||
return response([
|
||||
'data' => true
|
||||
]);
|
||||
}
|
||||
|
||||
public function drop(Request $request)
|
||||
{
|
||||
if ($request->input('id')) {
|
||||
$server = ServerHysteria::find($request->input('id'));
|
||||
if (!$server) {
|
||||
abort(500, '节点ID不存在');
|
||||
}
|
||||
}
|
||||
return response([
|
||||
'data' => $server->delete()
|
||||
]);
|
||||
}
|
||||
|
||||
public function update(Request $request)
|
||||
{
|
||||
$request->validate([
|
||||
'show' => 'in:0,1'
|
||||
], [
|
||||
'show.in' => '显示状态格式不正确'
|
||||
]);
|
||||
$params = $request->only([
|
||||
'show',
|
||||
]);
|
||||
|
||||
$server = ServerHysteria::find($request->input('id'));
|
||||
|
||||
if (!$server) {
|
||||
abort(500, '该服务器不存在');
|
||||
}
|
||||
try {
|
||||
$server->update($params);
|
||||
} catch (\Exception $e) {
|
||||
abort(500, '保存失败');
|
||||
}
|
||||
|
||||
return response([
|
||||
'data' => true
|
||||
]);
|
||||
}
|
||||
|
||||
public function copy(Request $request)
|
||||
{
|
||||
$server = ServerHysteria::find($request->input('id'));
|
||||
$server->show = 0;
|
||||
if (!$server) {
|
||||
abort(500, '服务器不存在');
|
||||
}
|
||||
if (!ServerHysteria::create($server->toArray())) {
|
||||
abort(500, '复制失败');
|
||||
}
|
||||
|
||||
return response([
|
||||
'data' => true
|
||||
]);
|
||||
}
|
||||
}
|
44
app/Http/Controllers/Admin/Server/ManageController.php
Normal file
44
app/Http/Controllers/Admin/Server/ManageController.php
Normal file
@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin\Server;
|
||||
|
||||
use App\Services\ServerService;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class ManageController extends Controller
|
||||
{
|
||||
public function getNodes(Request $request)
|
||||
{
|
||||
$serverService = new ServerService();
|
||||
return response([
|
||||
'data' => $serverService->getAllServers()
|
||||
]);
|
||||
}
|
||||
|
||||
public function sort(Request $request)
|
||||
{
|
||||
ini_set('post_max_size', '1m');
|
||||
$params = $request->only(
|
||||
'shadowsocks',
|
||||
'vmess',
|
||||
'trojan',
|
||||
'hysteria'
|
||||
) ?? [];
|
||||
DB::beginTransaction();
|
||||
foreach ($params as $k => $v) {
|
||||
$model = 'App\\Models\\Server' . ucfirst($k);
|
||||
foreach($v as $id => $sort) {
|
||||
if (!$model::find($id)->update(['sort' => $sort])) {
|
||||
DB::rollBack();
|
||||
abort(500, '保存失败');
|
||||
}
|
||||
}
|
||||
}
|
||||
DB::commit();
|
||||
return response([
|
||||
'data' => true
|
||||
]);
|
||||
}
|
||||
}
|
72
app/Http/Controllers/Admin/Server/RouteController.php
Normal file
72
app/Http/Controllers/Admin/Server/RouteController.php
Normal file
@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin\Server;
|
||||
|
||||
use App\Http\Requests\Admin\ServerShadowsocksSave;
|
||||
use App\Http\Requests\Admin\ServerShadowsocksUpdate;
|
||||
use App\Models\ServerRoute;
|
||||
use App\Models\ServerShadowsocks;
|
||||
use App\Services\ServerService;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
|
||||
class RouteController extends Controller
|
||||
{
|
||||
public function fetch(Request $request)
|
||||
{
|
||||
$routes = ServerRoute::get();
|
||||
// TODO: remove on 1.8.0
|
||||
foreach ($routes as $k => $route) {
|
||||
$array = json_decode($route->match, true);
|
||||
if (is_array($array)) $routes[$k]['match'] = $array;
|
||||
}
|
||||
// TODO: remove on 1.8.0
|
||||
return [
|
||||
'data' => $routes
|
||||
];
|
||||
}
|
||||
|
||||
public function save(Request $request)
|
||||
{
|
||||
$params = $request->validate([
|
||||
'remarks' => 'required',
|
||||
'match' => 'required|array',
|
||||
'action' => 'required|in:block,dns',
|
||||
'action_value' => 'nullable'
|
||||
], [
|
||||
'remarks.required' => '备注不能为空',
|
||||
'match.required' => '匹配值不能为空',
|
||||
'action.required' => '动作类型不能为空',
|
||||
'action.in' => '动作类型参数有误'
|
||||
]);
|
||||
$params['match'] = array_filter($params['match']);
|
||||
// TODO: remove on 1.8.0
|
||||
$params['match'] = json_encode($params['match']);
|
||||
// TODO: remove on 1.8.0
|
||||
if ($request->input('id')) {
|
||||
try {
|
||||
$route = ServerRoute::find($request->input('id'));
|
||||
$route->update($params);
|
||||
return [
|
||||
'data' => true
|
||||
];
|
||||
} catch (\Exception $e) {
|
||||
abort(500, '保存失败');
|
||||
}
|
||||
}
|
||||
if (!ServerRoute::create($params)) abort(500, '创建失败');
|
||||
return [
|
||||
'data' => true
|
||||
];
|
||||
}
|
||||
|
||||
public function drop(Request $request)
|
||||
{
|
||||
$route = ServerRoute::find($request->input('id'));
|
||||
if (!$route) abort(500, '路由不存在');
|
||||
if (!$route->delete()) abort(500, '删除失败');
|
||||
return [
|
||||
'data' => true
|
||||
];
|
||||
}
|
||||
}
|
91
app/Http/Controllers/Admin/Server/ShadowsocksController.php
Normal file
91
app/Http/Controllers/Admin/Server/ShadowsocksController.php
Normal file
@ -0,0 +1,91 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin\Server;
|
||||
|
||||
use App\Http\Requests\Admin\ServerShadowsocksSave;
|
||||
use App\Http\Requests\Admin\ServerShadowsocksUpdate;
|
||||
use App\Models\ServerShadowsocks;
|
||||
use App\Services\ServerService;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
|
||||
class ShadowsocksController extends Controller
|
||||
{
|
||||
public function save(ServerShadowsocksSave $request)
|
||||
{
|
||||
$params = $request->validated();
|
||||
if ($request->input('id')) {
|
||||
$server = ServerShadowsocks::find($request->input('id'));
|
||||
if (!$server) {
|
||||
abort(500, '服务器不存在');
|
||||
}
|
||||
try {
|
||||
$server->update($params);
|
||||
} catch (\Exception $e) {
|
||||
abort(500, '保存失败');
|
||||
}
|
||||
return response([
|
||||
'data' => true
|
||||
]);
|
||||
}
|
||||
|
||||
if (!ServerShadowsocks::create($params)) {
|
||||
abort(500, '创建失败');
|
||||
}
|
||||
|
||||
return response([
|
||||
'data' => true
|
||||
]);
|
||||
}
|
||||
|
||||
public function drop(Request $request)
|
||||
{
|
||||
if ($request->input('id')) {
|
||||
$server = ServerShadowsocks::find($request->input('id'));
|
||||
if (!$server) {
|
||||
abort(500, '节点ID不存在');
|
||||
}
|
||||
}
|
||||
return response([
|
||||
'data' => $server->delete()
|
||||
]);
|
||||
}
|
||||
|
||||
public function update(ServerShadowsocksUpdate $request)
|
||||
{
|
||||
$params = $request->only([
|
||||
'show',
|
||||
]);
|
||||
|
||||
$server = ServerShadowsocks::find($request->input('id'));
|
||||
|
||||
if (!$server) {
|
||||
abort(500, '该服务器不存在');
|
||||
}
|
||||
try {
|
||||
$server->update($params);
|
||||
} catch (\Exception $e) {
|
||||
abort(500, '保存失败');
|
||||
}
|
||||
|
||||
return response([
|
||||
'data' => true
|
||||
]);
|
||||
}
|
||||
|
||||
public function copy(Request $request)
|
||||
{
|
||||
$server = ServerShadowsocks::find($request->input('id'));
|
||||
$server->show = 0;
|
||||
if (!$server) {
|
||||
abort(500, '服务器不存在');
|
||||
}
|
||||
if (!ServerShadowsocks::create($server->toArray())) {
|
||||
abort(500, '复制失败');
|
||||
}
|
||||
|
||||
return response([
|
||||
'data' => true
|
||||
]);
|
||||
}
|
||||
}
|
99
app/Http/Controllers/Admin/Server/TrojanController.php
Normal file
99
app/Http/Controllers/Admin/Server/TrojanController.php
Normal file
@ -0,0 +1,99 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin\Server;
|
||||
|
||||
use App\Http\Requests\Admin\ServerTrojanSave;
|
||||
use App\Http\Requests\Admin\ServerTrojanUpdate;
|
||||
use App\Services\ServerService;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\ServerTrojan;
|
||||
|
||||
class TrojanController extends Controller
|
||||
{
|
||||
public function save(ServerTrojanSave $request)
|
||||
{
|
||||
$params = $request->validated();
|
||||
if ($request->input('id')) {
|
||||
$server = ServerTrojan::find($request->input('id'));
|
||||
if (!$server) {
|
||||
abort(500, '服务器不存在');
|
||||
}
|
||||
try {
|
||||
$server->update($params);
|
||||
} catch (\Exception $e) {
|
||||
abort(500, '保存失败');
|
||||
}
|
||||
return response([
|
||||
'data' => true
|
||||
]);
|
||||
}
|
||||
|
||||
if (!ServerTrojan::create($params)) {
|
||||
abort(500, '创建失败');
|
||||
}
|
||||
|
||||
return response([
|
||||
'data' => true
|
||||
]);
|
||||
}
|
||||
|
||||
public function drop(Request $request)
|
||||
{
|
||||
if ($request->input('id')) {
|
||||
$server = ServerTrojan::find($request->input('id'));
|
||||
if (!$server) {
|
||||
abort(500, '节点ID不存在');
|
||||
}
|
||||
}
|
||||
return response([
|
||||
'data' => $server->delete()
|
||||
]);
|
||||
}
|
||||
|
||||
public function update(ServerTrojanUpdate $request)
|
||||
{
|
||||
$params = $request->only([
|
||||
'show',
|
||||
]);
|
||||
|
||||
$server = ServerTrojan::find($request->input('id'));
|
||||
|
||||
if (!$server) {
|
||||
abort(500, '该服务器不存在');
|
||||
}
|
||||
try {
|
||||
$server->update($params);
|
||||
} catch (\Exception $e) {
|
||||
abort(500, '保存失败');
|
||||
}
|
||||
|
||||
return response([
|
||||
'data' => true
|
||||
]);
|
||||
}
|
||||
|
||||
public function copy(Request $request)
|
||||
{
|
||||
$server = ServerTrojan::find($request->input('id'));
|
||||
$server->show = 0;
|
||||
if (!$server) {
|
||||
abort(500, '服务器不存在');
|
||||
}
|
||||
if (!ServerTrojan::create($server->toArray())) {
|
||||
abort(500, '复制失败');
|
||||
}
|
||||
|
||||
return response([
|
||||
'data' => true
|
||||
]);
|
||||
}
|
||||
public function viewConfig(Request $request)
|
||||
{
|
||||
$serverService = new ServerService();
|
||||
$config = $serverService->getTrojanConfig($request->input('node_id'), 23333);
|
||||
return response([
|
||||
'data' => $config
|
||||
]);
|
||||
}
|
||||
}
|
92
app/Http/Controllers/Admin/Server/VmessController.php
Normal file
92
app/Http/Controllers/Admin/Server/VmessController.php
Normal file
@ -0,0 +1,92 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin\Server;
|
||||
|
||||
use App\Http\Requests\Admin\ServerVmessSave;
|
||||
use App\Http\Requests\Admin\ServerVmessUpdate;
|
||||
use App\Services\ServerService;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\ServerVmess;
|
||||
|
||||
class VmessController extends Controller
|
||||
{
|
||||
public function save(ServerVmessSave $request)
|
||||
{
|
||||
$params = $request->validated();
|
||||
|
||||
if ($request->input('id')) {
|
||||
$server = ServerVmess::find($request->input('id'));
|
||||
if (!$server) {
|
||||
abort(500, '服务器不存在');
|
||||
}
|
||||
try {
|
||||
$server->update($params);
|
||||
} catch (\Exception $e) {
|
||||
abort(500, '保存失败');
|
||||
}
|
||||
return response([
|
||||
'data' => true
|
||||
]);
|
||||
}
|
||||
|
||||
if (!ServerVmess::create($params)) {
|
||||
abort(500, '创建失败');
|
||||
}
|
||||
|
||||
return response([
|
||||
'data' => true
|
||||
]);
|
||||
}
|
||||
|
||||
public function drop(Request $request)
|
||||
{
|
||||
if ($request->input('id')) {
|
||||
$server = ServerVmess::find($request->input('id'));
|
||||
if (!$server) {
|
||||
abort(500, '节点ID不存在');
|
||||
}
|
||||
}
|
||||
return response([
|
||||
'data' => $server->delete()
|
||||
]);
|
||||
}
|
||||
|
||||
public function update(ServerVmessUpdate $request)
|
||||
{
|
||||
$params = $request->only([
|
||||
'show',
|
||||
]);
|
||||
|
||||
$server = ServerVmess::find($request->input('id'));
|
||||
|
||||
if (!$server) {
|
||||
abort(500, '该服务器不存在');
|
||||
}
|
||||
try {
|
||||
$server->update($params);
|
||||
} catch (\Exception $e) {
|
||||
abort(500, '保存失败');
|
||||
}
|
||||
|
||||
return response([
|
||||
'data' => true
|
||||
]);
|
||||
}
|
||||
|
||||
public function copy(Request $request)
|
||||
{
|
||||
$server = ServerVmess::find($request->input('id'));
|
||||
$server->show = 0;
|
||||
if (!$server) {
|
||||
abort(500, '服务器不存在');
|
||||
}
|
||||
if (!ServerVmess::create($server->toArray())) {
|
||||
abort(500, '复制失败');
|
||||
}
|
||||
|
||||
return response([
|
||||
'data' => true
|
||||
]);
|
||||
}
|
||||
}
|
@ -1,109 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Requests\Admin\ServerSave;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\ServerGroup;
|
||||
use App\Models\Server;
|
||||
use App\Models\Plan;
|
||||
use App\Models\User;
|
||||
|
||||
class ServerController extends Controller
|
||||
{
|
||||
public function index (Request $request) {
|
||||
return response([
|
||||
'data' => Server::get()
|
||||
]);
|
||||
}
|
||||
|
||||
public function save (ServerSave $request) {
|
||||
if ($request->input('id')) {
|
||||
$server = Server::find($request->input('id'));
|
||||
if (!$server) {
|
||||
abort(500, '服务器不存在');
|
||||
}
|
||||
} else {
|
||||
$server = new Server();
|
||||
}
|
||||
$server->group_id = json_encode($request->input('group_id'));
|
||||
$server->name = $request->input('name');
|
||||
$server->host = $request->input('host');
|
||||
$server->port = $request->input('port');
|
||||
$server->server_port = $request->input('server_port');
|
||||
$server->tls = $request->input('tls');
|
||||
$server->tags = json_encode($request->input('tags'));
|
||||
$server->rate = $request->input('rate');
|
||||
return response([
|
||||
'data' => $server->save()
|
||||
]);
|
||||
}
|
||||
|
||||
public function group (Request $request) {
|
||||
if ($request->input('group_id')) {
|
||||
return response([
|
||||
'data' => [ServerGroup::find($request->input('group_id'))]
|
||||
]);
|
||||
}
|
||||
return response([
|
||||
'data' => ServerGroup::get()
|
||||
]);
|
||||
}
|
||||
|
||||
public function groupSave (Request $request) {
|
||||
if (empty($request->input('name'))) {
|
||||
abort(500, '组名不能为空');
|
||||
}
|
||||
|
||||
if ($request->input('id')) {
|
||||
$serverGroup = ServerGroup::find($request->input('id'));
|
||||
} else {
|
||||
$serverGroup = new ServerGroup();
|
||||
}
|
||||
|
||||
$serverGroup->name = $request->input('name');
|
||||
return response([
|
||||
'data' => $serverGroup->save()
|
||||
]);
|
||||
}
|
||||
|
||||
public function groupDrop (Request $request) {
|
||||
if ($request->input('id')) {
|
||||
$serverGroup = ServerGroup::find($request->input('id'));
|
||||
if (!$serverGroup) {
|
||||
abort(500, '组不存在');
|
||||
}
|
||||
}
|
||||
|
||||
$servers = Server::all();
|
||||
foreach ($servers as $server) {
|
||||
$groupId = json_decode($server->group_id);
|
||||
if (in_array($request->input('id'), $groupId)) {
|
||||
abort(500, '该组已被节点所使用,无法删除');
|
||||
}
|
||||
}
|
||||
|
||||
if (Plan::where('group_id', $request->input('id'))->first()) {
|
||||
abort(500, '该组已被订阅所使用,无法删除');
|
||||
}
|
||||
if (User::where('group_id', $request->input('id'))->first()) {
|
||||
abort(500, '该组已被用户所使用,无法删除');
|
||||
}
|
||||
return response([
|
||||
'data' => $serverGroup->delete()
|
||||
]);
|
||||
}
|
||||
|
||||
public function drop (Request $request) {
|
||||
if ($request->input('id')) {
|
||||
$server = Server::find($request->input('id'));
|
||||
if (!$server) {
|
||||
abort(500, '节点ID不存在');
|
||||
}
|
||||
}
|
||||
return response([
|
||||
'data' => $server->delete()
|
||||
]);
|
||||
}
|
||||
}
|
225
app/Http/Controllers/Admin/StatController.php
Normal file
225
app/Http/Controllers/Admin/StatController.php
Normal file
@ -0,0 +1,225 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Models\CommissionLog;
|
||||
use App\Models\ServerShadowsocks;
|
||||
use App\Models\ServerTrojan;
|
||||
use App\Models\StatUser;
|
||||
use App\Services\ServerService;
|
||||
use App\Services\StatisticalService;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\ServerGroup;
|
||||
use App\Models\ServerVmess;
|
||||
use App\Models\Plan;
|
||||
use App\Models\User;
|
||||
use App\Models\Ticket;
|
||||
use App\Models\Order;
|
||||
use App\Models\Stat;
|
||||
use App\Models\StatServer;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class StatController extends Controller
|
||||
{
|
||||
public function getStat(Request $request)
|
||||
{
|
||||
$params = $request->validate([
|
||||
'start_at' => '',
|
||||
'end_at' => ''
|
||||
]);
|
||||
|
||||
if (isset($params['start_at']) && isset($params['end_at'])) {
|
||||
$stats = Stat::where('record_at', '>=', $params['start_at'])
|
||||
->where('record_at', '<', $params['end_at'])
|
||||
->get()
|
||||
->makeHidden(['record_at', 'created_at', 'updated_at', 'id', 'record_type'])
|
||||
->toArray();
|
||||
} else {
|
||||
$statisticalService = new StatisticalService();
|
||||
return [
|
||||
'data' => $statisticalService->generateStatData()
|
||||
];
|
||||
}
|
||||
|
||||
$stats = array_reduce($stats, function($carry, $item) {
|
||||
foreach($item as $key => $value) {
|
||||
if(isset($carry[$key]) && $carry[$key]) {
|
||||
$carry[$key] += $value;
|
||||
} else {
|
||||
$carry[$key] = $value;
|
||||
}
|
||||
}
|
||||
return $carry;
|
||||
}, []);
|
||||
|
||||
return [
|
||||
'data' => $stats
|
||||
];
|
||||
}
|
||||
|
||||
public function getStatRecord(Request $request)
|
||||
{
|
||||
$request->validate([
|
||||
'type' => 'required|in:paid_total,commission_total,register_count',
|
||||
'start_at' => '',
|
||||
'end_at' => ''
|
||||
]);
|
||||
|
||||
$statisticalService = new StatisticalService();
|
||||
$statisticalService->setStartAt($request->input('start_at'));
|
||||
$statisticalService->setEndAt($request->input('end_at'));
|
||||
return [
|
||||
'data' => $statisticalService->getStatRecord($request->input('type'))
|
||||
];
|
||||
}
|
||||
|
||||
public function getRanking(Request $request)
|
||||
{
|
||||
$request->validate([
|
||||
'type' => 'required|in:server_traffic_rank,user_consumption_rank,invite_rank',
|
||||
'start_at' => '',
|
||||
'end_at' => '',
|
||||
'limit' => 'nullable|integer'
|
||||
]);
|
||||
|
||||
$statisticalService = new StatisticalService();
|
||||
$statisticalService->setStartAt($request->input('start_at'));
|
||||
$statisticalService->setEndAt($request->input('end_at'));
|
||||
return [
|
||||
'data' => $statisticalService->getRanking($request->input('type'), $request->input('limit') ?? 20)
|
||||
];
|
||||
}
|
||||
|
||||
public function getOverride(Request $request)
|
||||
{
|
||||
return [
|
||||
'data' => [
|
||||
'month_income' => Order::where('created_at', '>=', strtotime(date('Y-m-1')))
|
||||
->where('created_at', '<', time())
|
||||
->whereNotIn('status', [0, 2])
|
||||
->sum('total_amount'),
|
||||
'month_register_total' => User::where('created_at', '>=', strtotime(date('Y-m-1')))
|
||||
->where('created_at', '<', time())
|
||||
->count(),
|
||||
'ticket_pending_total' => Ticket::where('status', 0)
|
||||
->count(),
|
||||
'commission_pending_total' => Order::where('commission_status', 0)
|
||||
->where('invite_user_id', '!=', NULL)
|
||||
->whereNotIn('status', [0, 2])
|
||||
->where('commission_balance', '>', 0)
|
||||
->count(),
|
||||
'day_income' => Order::where('created_at', '>=', strtotime(date('Y-m-d')))
|
||||
->where('created_at', '<', time())
|
||||
->whereNotIn('status', [0, 2])
|
||||
->sum('total_amount'),
|
||||
'last_month_income' => Order::where('created_at', '>=', strtotime('-1 month', strtotime(date('Y-m-1'))))
|
||||
->where('created_at', '<', strtotime(date('Y-m-1')))
|
||||
->whereNotIn('status', [0, 2])
|
||||
->sum('total_amount'),
|
||||
'commission_month_payout' => CommissionLog::where('created_at', '>=', strtotime(date('Y-m-1')))
|
||||
->where('created_at', '<', time())
|
||||
->sum('get_amount'),
|
||||
'commission_last_month_payout' => CommissionLog::where('created_at', '>=', strtotime('-1 month', strtotime(date('Y-m-1'))))
|
||||
->where('created_at', '<', strtotime(date('Y-m-1')))
|
||||
->sum('get_amount'),
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
public function getOrder(Request $request)
|
||||
{
|
||||
$statistics = Stat::where('record_type', 'd')
|
||||
->limit(31)
|
||||
->orderBy('record_at', 'DESC')
|
||||
->get()
|
||||
->toArray();
|
||||
$result = [];
|
||||
foreach ($statistics as $statistic) {
|
||||
$date = date('m-d', $statistic['record_at']);
|
||||
$result[] = [
|
||||
'type' => '收款金额',
|
||||
'date' => $date,
|
||||
'value' => $statistic['paid_total'] / 100
|
||||
];
|
||||
$result[] = [
|
||||
'type' => '收款笔数',
|
||||
'date' => $date,
|
||||
'value' => $statistic['paid_count']
|
||||
];
|
||||
$result[] = [
|
||||
'type' => '佣金金额(已发放)',
|
||||
'date' => $date,
|
||||
'value' => $statistic['commission_total'] / 100
|
||||
];
|
||||
$result[] = [
|
||||
'type' => '佣金笔数(已发放)',
|
||||
'date' => $date,
|
||||
'value' => $statistic['commission_count']
|
||||
];
|
||||
}
|
||||
$result = array_reverse($result);
|
||||
return [
|
||||
'data' => $result
|
||||
];
|
||||
}
|
||||
|
||||
public function getServerLastRank()
|
||||
{
|
||||
$servers = [
|
||||
'shadowsocks' => ServerShadowsocks::where('parent_id', null)->get()->toArray(),
|
||||
'v2ray' => ServerVmess::where('parent_id', null)->get()->toArray(),
|
||||
'trojan' => ServerTrojan::where('parent_id', null)->get()->toArray(),
|
||||
'vmess' => ServerVmess::where('parent_id', null)->get()->toArray()
|
||||
];
|
||||
$startAt = strtotime('-1 day', strtotime(date('Y-m-d')));
|
||||
$endAt = strtotime(date('Y-m-d'));
|
||||
$statistics = StatServer::select([
|
||||
'server_id',
|
||||
'server_type',
|
||||
'u',
|
||||
'd',
|
||||
DB::raw('(u+d) as total')
|
||||
])
|
||||
->where('record_at', '>=', $startAt)
|
||||
->where('record_at', '<', $endAt)
|
||||
->where('record_type', 'd')
|
||||
->limit(10)
|
||||
->orderBy('total', 'DESC')
|
||||
->get()
|
||||
->toArray();
|
||||
foreach ($statistics as $k => $v) {
|
||||
foreach ($servers[$v['server_type']] as $server) {
|
||||
if ($server['id'] === $v['server_id']) {
|
||||
$statistics[$k]['server_name'] = $server['name'];
|
||||
}
|
||||
}
|
||||
$statistics[$k]['total'] = $statistics[$k]['total'] / 1073741824;
|
||||
}
|
||||
array_multisort(array_column($statistics, 'total'), SORT_DESC, $statistics);
|
||||
return [
|
||||
'data' => $statistics
|
||||
];
|
||||
}
|
||||
|
||||
public function getStatUser(Request $request)
|
||||
{
|
||||
$request->validate([
|
||||
'user_id' => 'required|integer'
|
||||
]);
|
||||
$current = $request->input('current') ? $request->input('current') : 1;
|
||||
$pageSize = $request->input('pageSize') >= 10 ? $request->input('pageSize') : 10;
|
||||
$builder = StatUser::orderBy('record_at', 'DESC')->where('user_id', $request->input('user_id'));
|
||||
|
||||
$total = $builder->count();
|
||||
$records = $builder->forPage($current, $pageSize)
|
||||
->get();
|
||||
return [
|
||||
'data' => $records,
|
||||
'total' => $total
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
|
105
app/Http/Controllers/Admin/SystemController.php
Normal file
105
app/Http/Controllers/Admin/SystemController.php
Normal file
@ -0,0 +1,105 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Utils\CacheKey;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Laravel\Horizon\Contracts\JobRepository;
|
||||
use Laravel\Horizon\Contracts\MasterSupervisorRepository;
|
||||
use Laravel\Horizon\Contracts\MetricsRepository;
|
||||
use Laravel\Horizon\Contracts\SupervisorRepository;
|
||||
use Laravel\Horizon\Contracts\WorkloadRepository;
|
||||
use Laravel\Horizon\WaitTimeCalculator;
|
||||
|
||||
class SystemController extends Controller
|
||||
{
|
||||
public function getSystemStatus()
|
||||
{
|
||||
return response([
|
||||
'data' => [
|
||||
'schedule' => $this->getScheduleStatus(),
|
||||
'horizon' => $this->getHorizonStatus(),
|
||||
'schedule_last_runtime' => Cache::get(CacheKey::get('SCHEDULE_LAST_CHECK_AT', null))
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
||||
public function getQueueWorkload(WorkloadRepository $workload)
|
||||
{
|
||||
return response([
|
||||
'data' => collect($workload->get())->sortBy('name')->values()->toArray()
|
||||
]);
|
||||
}
|
||||
|
||||
protected function getScheduleStatus():bool
|
||||
{
|
||||
return (time() - 120) < Cache::get(CacheKey::get('SCHEDULE_LAST_CHECK_AT', null));
|
||||
}
|
||||
|
||||
protected function getHorizonStatus():bool
|
||||
{
|
||||
if (! $masters = app(MasterSupervisorRepository::class)->all()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return collect($masters)->contains(function ($master) {
|
||||
return $master->status === 'paused';
|
||||
}) ? false : true;
|
||||
}
|
||||
|
||||
public function getQueueStats()
|
||||
{
|
||||
return response([
|
||||
'data' => [
|
||||
'failedJobs' => app(JobRepository::class)->countRecentlyFailed(),
|
||||
'jobsPerMinute' => app(MetricsRepository::class)->jobsProcessedPerMinute(),
|
||||
'pausedMasters' => $this->totalPausedMasters(),
|
||||
'periods' => [
|
||||
'failedJobs' => config('horizon.trim.recent_failed', config('horizon.trim.failed')),
|
||||
'recentJobs' => config('horizon.trim.recent'),
|
||||
],
|
||||
'processes' => $this->totalProcessCount(),
|
||||
'queueWithMaxRuntime' => app(MetricsRepository::class)->queueWithMaximumRuntime(),
|
||||
'queueWithMaxThroughput' => app(MetricsRepository::class)->queueWithMaximumThroughput(),
|
||||
'recentJobs' => app(JobRepository::class)->countRecent(),
|
||||
'status' => $this->getHorizonStatus(),
|
||||
'wait' => collect(app(WaitTimeCalculator::class)->calculate())->take(1),
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the total process count across all supervisors.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
protected function totalProcessCount()
|
||||
{
|
||||
$supervisors = app(SupervisorRepository::class)->all();
|
||||
|
||||
return collect($supervisors)->reduce(function ($carry, $supervisor) {
|
||||
return $carry + collect($supervisor->processes)->sum();
|
||||
}, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of master supervisors that are currently paused.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
protected function totalPausedMasters()
|
||||
{
|
||||
if (! $masters = app(MasterSupervisorRepository::class)->all()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return collect($masters)->filter(function ($master) {
|
||||
return $master->status === 'paused';
|
||||
})->count();
|
||||
}
|
||||
}
|
||||
|
91
app/Http/Controllers/Admin/ThemeController.php
Normal file
91
app/Http/Controllers/Admin/ThemeController.php
Normal file
@ -0,0 +1,91 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Services\ThemeService;
|
||||
use Illuminate\Support\Facades\File;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class ThemeController extends Controller
|
||||
{
|
||||
private $themes;
|
||||
private $path;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->path = $path = public_path('theme/');
|
||||
$this->themes = array_map(function ($item) use ($path) {
|
||||
return str_replace($path, '', $item);
|
||||
}, glob($path . '*'));
|
||||
}
|
||||
|
||||
public function getThemes()
|
||||
{
|
||||
$themeConfigs = [];
|
||||
foreach ($this->themes as $theme) {
|
||||
$themeConfigFile = $this->path . "{$theme}/config.json";
|
||||
if (!File::exists($themeConfigFile)) continue;
|
||||
$themeConfig = json_decode(File::get($themeConfigFile), true);
|
||||
if (!isset($themeConfig['configs']) || !is_array($themeConfig)) continue;
|
||||
$themeConfigs[$theme] = $themeConfig;
|
||||
if (config("theme.{$theme}")) continue;
|
||||
$themeService = new ThemeService($theme);
|
||||
$themeService->init();
|
||||
}
|
||||
return response([
|
||||
'data' => [
|
||||
'themes' => $themeConfigs,
|
||||
'active' => config('v2board.frontend_theme', 'v2board')
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
||||
public function getThemeConfig(Request $request)
|
||||
{
|
||||
$payload = $request->validate([
|
||||
'name' => 'required|in:' . join(',', $this->themes)
|
||||
]);
|
||||
return response([
|
||||
'data' => config("theme.{$payload['name']}")
|
||||
]);
|
||||
}
|
||||
|
||||
public function saveThemeConfig(Request $request)
|
||||
{
|
||||
$payload = $request->validate([
|
||||
'name' => 'required|in:' . join(',', $this->themes),
|
||||
'config' => 'required'
|
||||
]);
|
||||
$payload['config'] = json_decode(base64_decode($payload['config']), true);
|
||||
if (!$payload['config'] || !is_array($payload['config'])) abort(500, '参数有误');
|
||||
$themeConfigFile = public_path("theme/{$payload['name']}/config.json");
|
||||
if (!File::exists($themeConfigFile)) abort(500, '主题不存在');
|
||||
$themeConfig = json_decode(File::get($themeConfigFile), true);
|
||||
if (!isset($themeConfig['configs']) || !is_array($themeConfig)) abort(500, '主题配置文件有误');
|
||||
$validateFields = array_column($themeConfig['configs'], 'field_name');
|
||||
$config = [];
|
||||
foreach ($validateFields as $validateField) {
|
||||
$config[$validateField] = isset($payload['config'][$validateField]) ? $payload['config'][$validateField] : '';
|
||||
}
|
||||
|
||||
File::ensureDirectoryExists(base_path() . '/config/theme/');
|
||||
|
||||
$data = var_export($config, 1);
|
||||
if (!File::put(base_path() . "/config/theme/{$payload['name']}.php", "<?php\n return $data ;")) {
|
||||
abort(500, '修改失败');
|
||||
}
|
||||
|
||||
try {
|
||||
Artisan::call('config:cache');
|
||||
// sleep(2);
|
||||
} catch (\Exception $e) {
|
||||
abort(500, '保存失败');
|
||||
}
|
||||
|
||||
return response([
|
||||
'data' => $config
|
||||
]);
|
||||
}
|
||||
}
|
96
app/Http/Controllers/Admin/TicketController.php
Normal file
96
app/Http/Controllers/Admin/TicketController.php
Normal file
@ -0,0 +1,96 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Jobs\SendEmailJob;
|
||||
use App\Services\TicketService;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Ticket;
|
||||
use App\Models\User;
|
||||
use App\Models\TicketMessage;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class TicketController extends Controller
|
||||
{
|
||||
public function fetch(Request $request)
|
||||
{
|
||||
if ($request->input('id')) {
|
||||
$ticket = Ticket::where('id', $request->input('id'))
|
||||
->first();
|
||||
if (!$ticket) {
|
||||
abort(500, '工单不存在');
|
||||
}
|
||||
$ticket['message'] = TicketMessage::where('ticket_id', $ticket->id)->get();
|
||||
for ($i = 0; $i < count($ticket['message']); $i++) {
|
||||
if ($ticket['message'][$i]['user_id'] !== $ticket->user_id) {
|
||||
$ticket['message'][$i]['is_me'] = true;
|
||||
} else {
|
||||
$ticket['message'][$i]['is_me'] = false;
|
||||
}
|
||||
}
|
||||
return response([
|
||||
'data' => $ticket
|
||||
]);
|
||||
}
|
||||
$current = $request->input('current') ? $request->input('current') : 1;
|
||||
$pageSize = $request->input('pageSize') >= 10 ? $request->input('pageSize') : 10;
|
||||
$model = Ticket::orderBy('updated_at', 'DESC');
|
||||
if ($request->input('status') !== NULL) {
|
||||
$model->where('status', $request->input('status'));
|
||||
}
|
||||
if ($request->input('reply_status') !== NULL) {
|
||||
$model->whereIn('reply_status', $request->input('reply_status'));
|
||||
}
|
||||
if ($request->input('email') !== NULL) {
|
||||
$user = User::where('email', $request->input('email'))->first();
|
||||
if ($user) $model->where('user_id', $user->id);
|
||||
}
|
||||
$total = $model->count();
|
||||
$res = $model->forPage($current, $pageSize)
|
||||
->get();
|
||||
return response([
|
||||
'data' => $res,
|
||||
'total' => $total
|
||||
]);
|
||||
}
|
||||
|
||||
public function reply(Request $request)
|
||||
{
|
||||
if (empty($request->input('id'))) {
|
||||
abort(500, '参数错误');
|
||||
}
|
||||
if (empty($request->input('message'))) {
|
||||
abort(500, '消息不能为空');
|
||||
}
|
||||
$ticketService = new TicketService();
|
||||
$ticketService->replyByAdmin(
|
||||
$request->input('id'),
|
||||
$request->input('message'),
|
||||
$request->user['id']
|
||||
);
|
||||
return response([
|
||||
'data' => true
|
||||
]);
|
||||
}
|
||||
|
||||
public function close(Request $request)
|
||||
{
|
||||
if (empty($request->input('id'))) {
|
||||
abort(500, '参数错误');
|
||||
}
|
||||
$ticket = Ticket::where('id', $request->input('id'))
|
||||
->first();
|
||||
if (!$ticket) {
|
||||
abort(500, '工单不存在');
|
||||
}
|
||||
$ticket->status = 1;
|
||||
if (!$ticket->save()) {
|
||||
abort(500, '关闭失败');
|
||||
}
|
||||
return response([
|
||||
'data' => true
|
||||
]);
|
||||
}
|
||||
}
|
@ -2,56 +2,293 @@
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Requests\Admin\UserFetch;
|
||||
use App\Http\Requests\Admin\UserGenerate;
|
||||
use App\Http\Requests\Admin\UserSendMail;
|
||||
use App\Http\Requests\Admin\UserUpdate;
|
||||
use App\Jobs\SendEmailJob;
|
||||
use App\Services\AuthService;
|
||||
use App\Services\UserService;
|
||||
use App\Utils\Helper;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Order;
|
||||
use App\Models\User;
|
||||
use App\Models\Plan;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class UserController extends Controller
|
||||
{
|
||||
public function index (Request $request) {
|
||||
public function resetSecret(Request $request)
|
||||
{
|
||||
$user = User::find($request->input('id'));
|
||||
if (!$user) abort(500, '用户不存在');
|
||||
$user->token = Helper::guid();
|
||||
$user->uuid = Helper::guid(true);
|
||||
return response([
|
||||
'data' => $user->save()
|
||||
]);
|
||||
}
|
||||
|
||||
private function filter(Request $request, $builder)
|
||||
{
|
||||
$filters = $request->input('filter');
|
||||
if ($filters) {
|
||||
foreach ($filters as $k => $filter) {
|
||||
if ($filter['condition'] === '模糊') {
|
||||
$filter['condition'] = 'like';
|
||||
$filter['value'] = "%{$filter['value']}%";
|
||||
}
|
||||
if ($filter['key'] === 'd' || $filter['key'] === 'transfer_enable') {
|
||||
$filter['value'] = $filter['value'] * 1073741824;
|
||||
}
|
||||
if ($filter['key'] === 'invite_by_email') {
|
||||
$user = User::where('email', $filter['condition'], $filter['value'])->first();
|
||||
$inviteUserId = isset($user->id) ? $user->id : 0;
|
||||
$builder->where('invite_user_id', $inviteUserId);
|
||||
unset($filters[$k]);
|
||||
continue;
|
||||
}
|
||||
$builder->where($filter['key'], $filter['condition'], $filter['value']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function fetch(UserFetch $request)
|
||||
{
|
||||
$current = $request->input('current') ? $request->input('current') : 1;
|
||||
$pageSize = $request->input('pageSize') >= 10 ? $request->input('pageSize') : 10;
|
||||
$userModel = User::orderBy('created_at', 'DESC');
|
||||
if ($request->input('email')) {
|
||||
$userModel->where('email', $request->input('email'));
|
||||
}
|
||||
$sortType = in_array($request->input('sort_type'), ['ASC', 'DESC']) ? $request->input('sort_type') : 'DESC';
|
||||
$sort = $request->input('sort') ? $request->input('sort') : 'created_at';
|
||||
$userModel = User::select(
|
||||
DB::raw('*'),
|
||||
DB::raw('(u+d) as total_used')
|
||||
)
|
||||
->orderBy($sort, $sortType);
|
||||
$this->filter($request, $userModel);
|
||||
$total = $userModel->count();
|
||||
$res = $userModel->forPage($current, $pageSize)
|
||||
->get();
|
||||
$plan = Plan::get();
|
||||
for ($i = 0; $i < count($res); $i++) {
|
||||
for ($k = 0; $k < count($plan); $k++) {
|
||||
if ($plan[$k]['id'] == $res[$i]['plan_id']) {
|
||||
$res[$i]['plan_name'] = $plan[$k]['name'];
|
||||
}
|
||||
}
|
||||
$res[$i]['subscribe_url'] = Helper::getSubscribeUrl('/api/v1/client/subscribe?token=' . $res[$i]['token']);
|
||||
}
|
||||
return response([
|
||||
'data' => $userModel->forPage($current, $pageSize)
|
||||
->get(),
|
||||
'data' => $res,
|
||||
'total' => $total
|
||||
]);
|
||||
}
|
||||
|
||||
public function update (UserUpdate $request) {
|
||||
$updateData = $request->only([
|
||||
'email',
|
||||
'password',
|
||||
'transfer_enable',
|
||||
'expired_at',
|
||||
'banned',
|
||||
'is_admin'
|
||||
public function getUserInfoById(Request $request)
|
||||
{
|
||||
if (empty($request->input('id'))) {
|
||||
abort(500, '参数错误');
|
||||
}
|
||||
$user = User::find($request->input('id'));
|
||||
if ($user->invite_user_id) {
|
||||
$user['invite_user'] = User::find($user->invite_user_id);
|
||||
}
|
||||
return response([
|
||||
'data' => $user
|
||||
]);
|
||||
}
|
||||
|
||||
public function update(UserUpdate $request)
|
||||
{
|
||||
$params = $request->validated();
|
||||
$user = User::find($request->input('id'));
|
||||
if (!$user) {
|
||||
abort(500, '用户不存在');
|
||||
}
|
||||
if (User::where('email', $updateData['email'])->first() && $user->email !== $updateData['email']) {
|
||||
if (User::where('email', $params['email'])->first() && $user->email !== $params['email']) {
|
||||
abort(500, '邮箱已被使用');
|
||||
}
|
||||
if ($updateData['password']) {
|
||||
$updateData['password'] = password_hash($updateData['password'], PASSWORD_DEFAULT);
|
||||
if (isset($params['password'])) {
|
||||
$params['password'] = password_hash($params['password'], PASSWORD_DEFAULT);
|
||||
$params['password_algo'] = NULL;
|
||||
} else {
|
||||
unset($updateData['password']);
|
||||
unset($params['password']);
|
||||
}
|
||||
$updateData['transfer_enable'] = $updateData['transfer_enable'] * 1073741824;
|
||||
if (!$user->update($updateData)) {
|
||||
if (isset($params['plan_id'])) {
|
||||
$plan = Plan::find($params['plan_id']);
|
||||
if (!$plan) {
|
||||
abort(500, '订阅计划不存在');
|
||||
}
|
||||
$params['group_id'] = $plan->group_id;
|
||||
}
|
||||
if ($request->input('invite_user_email')) {
|
||||
$inviteUser = User::where('email', $request->input('invite_user_email'))->first();
|
||||
if ($inviteUser) {
|
||||
$params['invite_user_id'] = $inviteUser->id;
|
||||
}
|
||||
} else {
|
||||
$params['invite_user_id'] = null;
|
||||
}
|
||||
|
||||
if (isset($params['banned']) && (int)$params['banned'] === 1) {
|
||||
$authService = new AuthService($user);
|
||||
$authService->removeAllSession();
|
||||
}
|
||||
|
||||
try {
|
||||
$user->update($params);
|
||||
} catch (\Exception $e) {
|
||||
abort(500, '保存失败');
|
||||
}
|
||||
return response([
|
||||
'data' => true
|
||||
]);
|
||||
}
|
||||
|
||||
public function dumpCSV(Request $request)
|
||||
{
|
||||
$userModel = User::orderBy('id', 'asc');
|
||||
$this->filter($request, $userModel);
|
||||
$res = $userModel->get();
|
||||
$plan = Plan::get();
|
||||
for ($i = 0; $i < count($res); $i++) {
|
||||
for ($k = 0; $k < count($plan); $k++) {
|
||||
if ($plan[$k]['id'] == $res[$i]['plan_id']) {
|
||||
$res[$i]['plan_name'] = $plan[$k]['name'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$data = "邮箱,余额,推广佣金,总流量,剩余流量,套餐到期时间,订阅计划,订阅地址\r\n";
|
||||
foreach($res as $user) {
|
||||
$expireDate = $user['expired_at'] === NULL ? '长期有效' : date('Y-m-d H:i:s', $user['expired_at']);
|
||||
$balance = $user['balance'] / 100;
|
||||
$commissionBalance = $user['commission_balance'] / 100;
|
||||
$transferEnable = $user['transfer_enable'] ? $user['transfer_enable'] / 1073741824 : 0;
|
||||
$notUseFlow = (($user['transfer_enable'] - ($user['u'] + $user['d'])) / 1073741824) ?? 0;
|
||||
$planName = $user['plan_name'] ?? '无订阅';
|
||||
$subscribeUrl = Helper::getSubscribeUrl('/api/v1/client/subscribe?token=' . $user['token']);
|
||||
$data .= "{$user['email']},{$balance},{$commissionBalance},{$transferEnable},{$notUseFlow},{$expireDate},{$planName},{$subscribeUrl}\r\n";
|
||||
}
|
||||
echo "\xEF\xBB\xBF" . $data;
|
||||
}
|
||||
|
||||
public function generate(UserGenerate $request)
|
||||
{
|
||||
if ($request->input('email_prefix')) {
|
||||
if ($request->input('plan_id')) {
|
||||
$plan = Plan::find($request->input('plan_id'));
|
||||
if (!$plan) {
|
||||
abort(500, '订阅计划不存在');
|
||||
}
|
||||
}
|
||||
$user = [
|
||||
'email' => $request->input('email_prefix') . '@' . $request->input('email_suffix'),
|
||||
'plan_id' => isset($plan->id) ? $plan->id : NULL,
|
||||
'group_id' => isset($plan->group_id) ? $plan->group_id : NULL,
|
||||
'transfer_enable' => isset($plan->transfer_enable) ? $plan->transfer_enable * 1073741824 : 0,
|
||||
'expired_at' => $request->input('expired_at') ?? NULL,
|
||||
'uuid' => Helper::guid(true),
|
||||
'token' => Helper::guid()
|
||||
];
|
||||
if (User::where('email', $user['email'])->first()) {
|
||||
abort(500, '邮箱已存在于系统中');
|
||||
}
|
||||
$user['password'] = password_hash($request->input('password') ?? $user['email'], PASSWORD_DEFAULT);
|
||||
if (!User::create($user)) {
|
||||
abort(500, '生成失败');
|
||||
}
|
||||
return response([
|
||||
'data' => true
|
||||
]);
|
||||
}
|
||||
if ($request->input('generate_count')) {
|
||||
$this->multiGenerate($request);
|
||||
}
|
||||
}
|
||||
|
||||
private function multiGenerate(Request $request)
|
||||
{
|
||||
if ($request->input('plan_id')) {
|
||||
$plan = Plan::find($request->input('plan_id'));
|
||||
if (!$plan) {
|
||||
abort(500, '订阅计划不存在');
|
||||
}
|
||||
}
|
||||
$users = [];
|
||||
for ($i = 0;$i < $request->input('generate_count');$i++) {
|
||||
$user = [
|
||||
'email' => Helper::randomChar(6) . '@' . $request->input('email_suffix'),
|
||||
'plan_id' => isset($plan->id) ? $plan->id : NULL,
|
||||
'group_id' => isset($plan->group_id) ? $plan->group_id : NULL,
|
||||
'transfer_enable' => isset($plan->transfer_enable) ? $plan->transfer_enable * 1073741824 : 0,
|
||||
'expired_at' => $request->input('expired_at') ?? NULL,
|
||||
'uuid' => Helper::guid(true),
|
||||
'token' => Helper::guid(),
|
||||
'created_at' => time(),
|
||||
'updated_at' => time()
|
||||
];
|
||||
$user['password'] = password_hash($request->input('password') ?? $user['email'], PASSWORD_DEFAULT);
|
||||
array_push($users, $user);
|
||||
}
|
||||
DB::beginTransaction();
|
||||
if (!User::insert($users)) {
|
||||
DB::rollBack();
|
||||
abort(500, '生成失败');
|
||||
}
|
||||
DB::commit();
|
||||
$data = "账号,密码,过期时间,UUID,创建时间,订阅地址\r\n";
|
||||
foreach($users as $user) {
|
||||
$expireDate = $user['expired_at'] === NULL ? '长期有效' : date('Y-m-d H:i:s', $user['expired_at']);
|
||||
$createDate = date('Y-m-d H:i:s', $user['created_at']);
|
||||
$password = $request->input('password') ?? $user['email'];
|
||||
$subscribeUrl = Helper::getSubscribeUrl('/api/v1/client/subscribe?token=' . $user['token']);
|
||||
$data .= "{$user['email']},{$password},{$expireDate},{$user['uuid']},{$createDate},{$subscribeUrl}\r\n";
|
||||
}
|
||||
echo $data;
|
||||
}
|
||||
|
||||
public function sendMail(UserSendMail $request)
|
||||
{
|
||||
$sortType = in_array($request->input('sort_type'), ['ASC', 'DESC']) ? $request->input('sort_type') : 'DESC';
|
||||
$sort = $request->input('sort') ? $request->input('sort') : 'created_at';
|
||||
$builder = User::orderBy($sort, $sortType);
|
||||
$this->filter($request, $builder);
|
||||
$users = $builder->get();
|
||||
foreach ($users as $user) {
|
||||
SendEmailJob::dispatch([
|
||||
'email' => $user->email,
|
||||
'subject' => $request->input('subject'),
|
||||
'template_name' => 'notify',
|
||||
'template_value' => [
|
||||
'name' => config('v2board.app_name', 'V2Board'),
|
||||
'url' => config('v2board.app_url'),
|
||||
'content' => $request->input('content')
|
||||
]
|
||||
],
|
||||
'send_email_mass');
|
||||
}
|
||||
|
||||
return response([
|
||||
'data' => true
|
||||
]);
|
||||
}
|
||||
|
||||
public function ban(Request $request)
|
||||
{
|
||||
$sortType = in_array($request->input('sort_type'), ['ASC', 'DESC']) ? $request->input('sort_type') : 'DESC';
|
||||
$sort = $request->input('sort') ? $request->input('sort') : 'created_at';
|
||||
$builder = User::orderBy($sort, $sortType);
|
||||
$this->filter($request, $builder);
|
||||
try {
|
||||
$builder->update([
|
||||
'banned' => 1
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
abort(500, '处理失败');
|
||||
}
|
||||
|
||||
return response([
|
||||
'data' => true
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
95
app/Http/Controllers/Client/AppController.php
Normal file
95
app/Http/Controllers/Client/AppController.php
Normal file
@ -0,0 +1,95 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Client;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Services\ServerService;
|
||||
use App\Services\UserService;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\File;
|
||||
use Symfony\Component\Yaml\Yaml;
|
||||
|
||||
class AppController extends Controller
|
||||
{
|
||||
public function getConfig(Request $request)
|
||||
{
|
||||
$servers = [];
|
||||
$user = $request->user;
|
||||
$userService = new UserService();
|
||||
if ($userService->isAvailable($user)) {
|
||||
$serverService = new ServerService();
|
||||
$servers = $serverService->getAvailableServers($user);
|
||||
}
|
||||
$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);
|
||||
}
|
||||
$proxy = [];
|
||||
$proxies = [];
|
||||
|
||||
foreach ($servers as $item) {
|
||||
if ($item['type'] === 'shadowsocks'
|
||||
&& in_array($item['cipher'], [
|
||||
'aes-128-gcm',
|
||||
'aes-192-gcm',
|
||||
'aes-256-gcm',
|
||||
'chacha20-ietf-poly1305'
|
||||
])
|
||||
) {
|
||||
array_push($proxy, Protocols\Clash::buildShadowsocks($user['uuid'], $item));
|
||||
array_push($proxies, $item['name']);
|
||||
}
|
||||
if ($item['type'] === 'vmess') {
|
||||
array_push($proxy, Protocols\Clash::buildVmess($user['uuid'], $item));
|
||||
array_push($proxies, $item['name']);
|
||||
}
|
||||
if ($item['type'] === 'trojan') {
|
||||
array_push($proxy, Protocols\Clash::buildTrojan($user['uuid'], $item));
|
||||
array_push($proxies, $item['name']);
|
||||
}
|
||||
}
|
||||
|
||||
$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);
|
||||
}
|
||||
die(Yaml::dump($config));
|
||||
}
|
||||
|
||||
public function getVersion(Request $request)
|
||||
{
|
||||
if (strpos($request->header('user-agent'), 'tidalab/4.0.0') !== false
|
||||
|| strpos($request->header('user-agent'), 'tunnelab/4.0.0') !== false
|
||||
) {
|
||||
if (strpos($request->header('user-agent'), 'Win64') !== false) {
|
||||
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;
|
||||
}
|
||||
return response([
|
||||
'data' => [
|
||||
'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')
|
||||
]
|
||||
]);
|
||||
}
|
||||
}
|
62
app/Http/Controllers/Client/ClientController.php
Normal file
62
app/Http/Controllers/Client/ClientController.php
Normal file
@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Client;
|
||||
|
||||
use App\Http\Controllers\Client\Protocols\General;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Services\ServerService;
|
||||
use App\Utils\Helper;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Services\UserService;
|
||||
|
||||
class ClientController extends Controller
|
||||
{
|
||||
public function subscribe(Request $request)
|
||||
{
|
||||
$flag = $request->input('flag')
|
||||
?? ($_SERVER['HTTP_USER_AGENT'] ?? '');
|
||||
$flag = strtolower($flag);
|
||||
$user = $request->user;
|
||||
// account not expired and is not banned.
|
||||
$userService = new UserService();
|
||||
if ($userService->isAvailable($user)) {
|
||||
$serverService = new ServerService();
|
||||
$servers = $serverService->getAvailableServers($user);
|
||||
$this->setSubscribeInfoToServers($servers, $user);
|
||||
if ($flag) {
|
||||
foreach (array_reverse(glob(app_path('Http//Controllers//Client//Protocols') . '/*.php')) as $file) {
|
||||
$file = 'App\\Http\\Controllers\\Client\\Protocols\\' . basename($file, '.php');
|
||||
$class = new $file($user, $servers);
|
||||
if (strpos($flag, $class->flag) !== false) {
|
||||
die($class->handle());
|
||||
}
|
||||
}
|
||||
}
|
||||
$class = new General($user, $servers);
|
||||
die($class->handle());
|
||||
}
|
||||
}
|
||||
|
||||
private function setSubscribeInfoToServers(&$servers, $user)
|
||||
{
|
||||
if (!isset($servers[0])) return;
|
||||
if (!(int)config('v2board.show_info_to_server_enable', 0)) return;
|
||||
$useTraffic = $user['u'] + $user['d'];
|
||||
$totalTraffic = $user['transfer_enable'];
|
||||
$remainingTraffic = Helper::trafficConvert($totalTraffic - $useTraffic);
|
||||
$expiredDate = $user['expired_at'] ? date('Y-m-d', $user['expired_at']) : '长期有效';
|
||||
$userService = new UserService();
|
||||
$resetDay = $userService->getResetDay($user);
|
||||
array_unshift($servers, array_merge($servers[0], [
|
||||
'name' => "套餐到期:{$expiredDate}",
|
||||
]));
|
||||
if ($resetDay) {
|
||||
array_unshift($servers, array_merge($servers[0], [
|
||||
'name' => "距离下次重置剩余:{$resetDay} 天",
|
||||
]));
|
||||
}
|
||||
array_unshift($servers, array_merge($servers[0], [
|
||||
'name' => "剩余流量:{$remainingTraffic}",
|
||||
]));
|
||||
}
|
||||
}
|
186
app/Http/Controllers/Client/Protocols/Clash.php
Normal file
186
app/Http/Controllers/Client/Protocols/Clash.php
Normal file
@ -0,0 +1,186 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Client\Protocols;
|
||||
|
||||
use App\Utils\Dict;
|
||||
use phpDocumentor\Reflection\Types\Self_;
|
||||
use Symfony\Component\Yaml\Yaml;
|
||||
|
||||
class Clash
|
||||
{
|
||||
public $flag = 'clash';
|
||||
private $servers;
|
||||
private $user;
|
||||
|
||||
public function __construct($user, $servers)
|
||||
{
|
||||
$this->user = $user;
|
||||
$this->servers = $servers;
|
||||
}
|
||||
|
||||
public function handle()
|
||||
{
|
||||
$servers = $this->servers;
|
||||
$user = $this->user;
|
||||
$appName = config('v2board.app_name', 'V2Board');
|
||||
header("subscription-userinfo: upload={$user['u']}; download={$user['d']}; total={$user['transfer_enable']}; expire={$user['expired_at']}");
|
||||
header('profile-update-interval: 24');
|
||||
header("content-disposition:attachment;filename*=UTF-8''".rawurlencode($appName));
|
||||
header("profile-web-page-url:" . config('v2board.app_url'));
|
||||
$defaultConfig = base_path() . '/resources/rules/default.clash.yaml';
|
||||
$customConfig = base_path() . '/resources/rules/custom.clash.yaml';
|
||||
if (\File::exists($customConfig)) {
|
||||
$config = Yaml::parseFile($customConfig);
|
||||
} else {
|
||||
$config = Yaml::parseFile($defaultConfig);
|
||||
}
|
||||
$proxy = [];
|
||||
$proxies = [];
|
||||
|
||||
foreach ($servers as $item) {
|
||||
if ($item['type'] === 'shadowsocks'
|
||||
&& in_array($item['cipher'], [
|
||||
'aes-128-gcm',
|
||||
'aes-192-gcm',
|
||||
'aes-256-gcm',
|
||||
'chacha20-ietf-poly1305'
|
||||
])
|
||||
) {
|
||||
array_push($proxy, self::buildShadowsocks($user['uuid'], $item));
|
||||
array_push($proxies, $item['name']);
|
||||
}
|
||||
if ($item['type'] === 'vmess') {
|
||||
array_push($proxy, self::buildVmess($user['uuid'], $item));
|
||||
array_push($proxies, $item['name']);
|
||||
}
|
||||
if ($item['type'] === 'trojan') {
|
||||
array_push($proxy, self::buildTrojan($user['uuid'], $item));
|
||||
array_push($proxies, $item['name']);
|
||||
}
|
||||
}
|
||||
|
||||
$config['proxies'] = array_merge($config['proxies'] ? $config['proxies'] : [], $proxy);
|
||||
foreach ($config['proxy-groups'] as $k => $v) {
|
||||
if (!is_array($config['proxy-groups'][$k]['proxies'])) $config['proxy-groups'][$k]['proxies'] = [];
|
||||
$isFilter = false;
|
||||
foreach ($config['proxy-groups'][$k]['proxies'] as $src) {
|
||||
foreach ($proxies as $dst) {
|
||||
if (!$this->isRegex($src)) continue;
|
||||
$isFilter = true;
|
||||
$config['proxy-groups'][$k]['proxies'] = array_values(array_diff($config['proxy-groups'][$k]['proxies'], [$src]));
|
||||
if ($this->isMatch($src, $dst)) {
|
||||
array_push($config['proxy-groups'][$k]['proxies'], $dst);
|
||||
}
|
||||
}
|
||||
if ($isFilter) continue;
|
||||
}
|
||||
if ($isFilter) continue;
|
||||
$config['proxy-groups'][$k]['proxies'] = array_merge($config['proxy-groups'][$k]['proxies'], $proxies);
|
||||
}
|
||||
|
||||
$config['proxy-groups'] = array_filter($config['proxy-groups'], function($group) {
|
||||
return $group['proxies'];
|
||||
});
|
||||
$config['proxy-groups'] = array_values($config['proxy-groups']);
|
||||
// Force the current subscription domain to be a direct rule
|
||||
$subsDomain = $_SERVER['HTTP_HOST'];
|
||||
if ($subsDomain) {
|
||||
array_unshift($config['rules'], "DOMAIN,{$subsDomain},DIRECT");
|
||||
}
|
||||
|
||||
$yaml = Yaml::dump($config, 2, 4, Yaml::DUMP_EMPTY_ARRAY_AS_SEQUENCE);
|
||||
$yaml = str_replace('$app_name', config('v2board.app_name', 'V2Board'), $yaml);
|
||||
return $yaml;
|
||||
}
|
||||
|
||||
public static function buildShadowsocks($uuid, $server)
|
||||
{
|
||||
$array = [];
|
||||
$array['name'] = $server['name'];
|
||||
$array['type'] = 'ss';
|
||||
$array['server'] = $server['host'];
|
||||
$array['port'] = $server['port'];
|
||||
$array['cipher'] = $server['cipher'];
|
||||
$array['password'] = $uuid;
|
||||
$array['udp'] = true;
|
||||
return $array;
|
||||
}
|
||||
|
||||
public static function buildVmess($uuid, $server)
|
||||
{
|
||||
$array = [];
|
||||
$array['name'] = $server['name'];
|
||||
$array['type'] = 'vmess';
|
||||
$array['server'] = $server['host'];
|
||||
$array['port'] = $server['port'];
|
||||
$array['uuid'] = $uuid;
|
||||
$array['alterId'] = 0;
|
||||
$array['cipher'] = 'auto';
|
||||
$array['udp'] = true;
|
||||
|
||||
if ($server['tls']) {
|
||||
$array['tls'] = true;
|
||||
if ($server['tlsSettings']) {
|
||||
$tlsSettings = $server['tlsSettings'];
|
||||
if (isset($tlsSettings['allowInsecure']) && !empty($tlsSettings['allowInsecure']))
|
||||
$array['skip-cert-verify'] = ($tlsSettings['allowInsecure'] ? true : false);
|
||||
if (isset($tlsSettings['serverName']) && !empty($tlsSettings['serverName']))
|
||||
$array['servername'] = $tlsSettings['serverName'];
|
||||
}
|
||||
}
|
||||
if ($server['network'] === 'tcp') {
|
||||
$tcpSettings = $server['networkSettings'];
|
||||
if (isset($tcpSettings['header']['type'])) $array['network'] = $tcpSettings['header']['type'];
|
||||
if (isset($tcpSettings['header']['request']['path'][0])) $array['http-opts']['path'] = $tcpSettings['header']['request']['path'][0];
|
||||
}
|
||||
if ($server['network'] === 'ws') {
|
||||
$array['network'] = 'ws';
|
||||
if ($server['networkSettings']) {
|
||||
$wsSettings = $server['networkSettings'];
|
||||
$array['ws-opts'] = [];
|
||||
if (isset($wsSettings['path']) && !empty($wsSettings['path']))
|
||||
$array['ws-opts']['path'] = $wsSettings['path'];
|
||||
if (isset($wsSettings['headers']['Host']) && !empty($wsSettings['headers']['Host']))
|
||||
$array['ws-opts']['headers'] = ['Host' => $wsSettings['headers']['Host']];
|
||||
if (isset($wsSettings['path']) && !empty($wsSettings['path']))
|
||||
$array['ws-path'] = $wsSettings['path'];
|
||||
if (isset($wsSettings['headers']['Host']) && !empty($wsSettings['headers']['Host']))
|
||||
$array['ws-headers'] = ['Host' => $wsSettings['headers']['Host']];
|
||||
}
|
||||
}
|
||||
if ($server['network'] === 'grpc') {
|
||||
$array['network'] = 'grpc';
|
||||
if ($server['networkSettings']) {
|
||||
$grpcSettings = $server['networkSettings'];
|
||||
$array['grpc-opts'] = [];
|
||||
if (isset($grpcSettings['serviceName'])) $array['grpc-opts']['grpc-service-name'] = $grpcSettings['serviceName'];
|
||||
}
|
||||
}
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
public static function buildTrojan($password, $server)
|
||||
{
|
||||
$array = [];
|
||||
$array['name'] = $server['name'];
|
||||
$array['type'] = 'trojan';
|
||||
$array['server'] = $server['host'];
|
||||
$array['port'] = $server['port'];
|
||||
$array['password'] = $password;
|
||||
$array['udp'] = true;
|
||||
if (!empty($server['server_name'])) $array['sni'] = $server['server_name'];
|
||||
if (!empty($server['allow_insecure'])) $array['skip-cert-verify'] = ($server['allow_insecure'] ? true : false);
|
||||
return $array;
|
||||
}
|
||||
|
||||
private function isMatch($exp, $str)
|
||||
{
|
||||
return @preg_match($exp, $str);
|
||||
}
|
||||
|
||||
private function isRegex($exp)
|
||||
{
|
||||
return @preg_match($exp, null) !== false;
|
||||
}
|
||||
}
|
186
app/Http/Controllers/Client/Protocols/ClashMeta.php
Normal file
186
app/Http/Controllers/Client/Protocols/ClashMeta.php
Normal file
@ -0,0 +1,186 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Client\Protocols;
|
||||
|
||||
use App\Utils\Helper;
|
||||
use Symfony\Component\Yaml\Yaml;
|
||||
|
||||
class ClashMeta
|
||||
{
|
||||
public $flag = 'meta';
|
||||
private $servers;
|
||||
private $user;
|
||||
|
||||
public function __construct($user, $servers)
|
||||
{
|
||||
$this->user = $user;
|
||||
$this->servers = $servers;
|
||||
}
|
||||
|
||||
public function handle()
|
||||
{
|
||||
$servers = $this->servers;
|
||||
$user = $this->user;
|
||||
$appName = config('v2board.app_name', 'V2Board');
|
||||
header("subscription-userinfo: upload={$user['u']}; download={$user['d']}; total={$user['transfer_enable']}; expire={$user['expired_at']}");
|
||||
header('profile-update-interval: 24');
|
||||
header("content-disposition:attachment;filename*=UTF-8''".rawurlencode($appName));
|
||||
$defaultConfig = base_path() . '/resources/rules/default.clash.yaml';
|
||||
$customConfig = base_path() . '/resources/rules/custom.clash.yaml';
|
||||
if (\File::exists($customConfig)) {
|
||||
$config = Yaml::parseFile($customConfig);
|
||||
} else {
|
||||
$config = Yaml::parseFile($defaultConfig);
|
||||
}
|
||||
$proxy = [];
|
||||
$proxies = [];
|
||||
|
||||
foreach ($servers as $item) {
|
||||
if ($item['type'] === 'shadowsocks') {
|
||||
array_push($proxy, self::buildShadowsocks($user['uuid'], $item));
|
||||
array_push($proxies, $item['name']);
|
||||
}
|
||||
if ($item['type'] === 'vmess') {
|
||||
array_push($proxy, self::buildVmess($user['uuid'], $item));
|
||||
array_push($proxies, $item['name']);
|
||||
}
|
||||
if ($item['type'] === 'trojan') {
|
||||
array_push($proxy, self::buildTrojan($user['uuid'], $item));
|
||||
array_push($proxies, $item['name']);
|
||||
}
|
||||
}
|
||||
|
||||
$config['proxies'] = array_merge($config['proxies'] ? $config['proxies'] : [], $proxy);
|
||||
foreach ($config['proxy-groups'] as $k => $v) {
|
||||
if (!is_array($config['proxy-groups'][$k]['proxies'])) $config['proxy-groups'][$k]['proxies'] = [];
|
||||
$isFilter = false;
|
||||
foreach ($config['proxy-groups'][$k]['proxies'] as $src) {
|
||||
foreach ($proxies as $dst) {
|
||||
if (!$this->isRegex($src)) continue;
|
||||
$isFilter = true;
|
||||
$config['proxy-groups'][$k]['proxies'] = array_values(array_diff($config['proxy-groups'][$k]['proxies'], [$src]));
|
||||
if ($this->isMatch($src, $dst)) {
|
||||
array_push($config['proxy-groups'][$k]['proxies'], $dst);
|
||||
}
|
||||
}
|
||||
if ($isFilter) continue;
|
||||
}
|
||||
if ($isFilter) continue;
|
||||
$config['proxy-groups'][$k]['proxies'] = array_merge($config['proxy-groups'][$k]['proxies'], $proxies);
|
||||
}
|
||||
$config['proxy-groups'] = array_filter($config['proxy-groups'], function($group) {
|
||||
return $group['proxies'];
|
||||
});
|
||||
$config['proxy-groups'] = array_values($config['proxy-groups']);
|
||||
// Force the current subscription domain to be a direct rule
|
||||
$subsDomain = $_SERVER['HTTP_HOST'];
|
||||
if ($subsDomain) {
|
||||
array_unshift($config['rules'], "DOMAIN,{$subsDomain},DIRECT");
|
||||
}
|
||||
|
||||
$yaml = Yaml::dump($config, 2, 4, Yaml::DUMP_EMPTY_ARRAY_AS_SEQUENCE);
|
||||
$yaml = str_replace('$app_name', config('v2board.app_name', 'V2Board'), $yaml);
|
||||
return $yaml;
|
||||
}
|
||||
|
||||
public static function buildShadowsocks($password, $server)
|
||||
{
|
||||
if ($server['cipher'] === '2022-blake3-aes-128-gcm') {
|
||||
$serverKey = Helper::getServerKey($server['created_at'], 16);
|
||||
$userKey = Helper::uuidToBase64($password, 16);
|
||||
$password = "{$serverKey}:{$userKey}";
|
||||
}
|
||||
if ($server['cipher'] === '2022-blake3-aes-256-gcm') {
|
||||
$serverKey = Helper::getServerKey($server['created_at'], 32);
|
||||
$userKey = Helper::uuidToBase64($password, 32);
|
||||
$password = "{$serverKey}:{$userKey}";
|
||||
}
|
||||
$array = [];
|
||||
$array['name'] = $server['name'];
|
||||
$array['type'] = 'ss';
|
||||
$array['server'] = $server['host'];
|
||||
$array['port'] = $server['port'];
|
||||
$array['cipher'] = $server['cipher'];
|
||||
$array['password'] = $password;
|
||||
$array['udp'] = true;
|
||||
return $array;
|
||||
}
|
||||
|
||||
public static function buildVmess($uuid, $server)
|
||||
{
|
||||
$array = [];
|
||||
$array['name'] = $server['name'];
|
||||
$array['type'] = 'vmess';
|
||||
$array['server'] = $server['host'];
|
||||
$array['port'] = $server['port'];
|
||||
$array['uuid'] = $uuid;
|
||||
$array['alterId'] = 0;
|
||||
$array['cipher'] = 'auto';
|
||||
$array['udp'] = true;
|
||||
|
||||
if ($server['tls']) {
|
||||
$array['tls'] = true;
|
||||
if ($server['tlsSettings']) {
|
||||
$tlsSettings = $server['tlsSettings'];
|
||||
if (isset($tlsSettings['allowInsecure']) && !empty($tlsSettings['allowInsecure']))
|
||||
$array['skip-cert-verify'] = ($tlsSettings['allowInsecure'] ? true : false);
|
||||
if (isset($tlsSettings['serverName']) && !empty($tlsSettings['serverName']))
|
||||
$array['servername'] = $tlsSettings['serverName'];
|
||||
}
|
||||
}
|
||||
if ($server['network'] === 'tcp') {
|
||||
$tcpSettings = $server['networkSettings'];
|
||||
if (isset($tcpSettings['header']['type'])) $array['network'] = $tcpSettings['header']['type'];
|
||||
if (isset($tcpSettings['header']['request']['path'][0])) $array['http-opts']['path'] = $tcpSettings['header']['request']['path'][0];
|
||||
}
|
||||
if ($server['network'] === 'ws') {
|
||||
$array['network'] = 'ws';
|
||||
if ($server['networkSettings']) {
|
||||
$wsSettings = $server['networkSettings'];
|
||||
$array['ws-opts'] = [];
|
||||
if (isset($wsSettings['path']) && !empty($wsSettings['path']))
|
||||
$array['ws-opts']['path'] = $wsSettings['path'];
|
||||
if (isset($wsSettings['headers']['Host']) && !empty($wsSettings['headers']['Host']))
|
||||
$array['ws-opts']['headers'] = ['Host' => $wsSettings['headers']['Host']];
|
||||
if (isset($wsSettings['path']) && !empty($wsSettings['path']))
|
||||
$array['ws-path'] = $wsSettings['path'];
|
||||
if (isset($wsSettings['headers']['Host']) && !empty($wsSettings['headers']['Host']))
|
||||
$array['ws-headers'] = ['Host' => $wsSettings['headers']['Host']];
|
||||
}
|
||||
}
|
||||
if ($server['network'] === 'grpc') {
|
||||
$array['network'] = 'grpc';
|
||||
if ($server['networkSettings']) {
|
||||
$grpcSettings = $server['networkSettings'];
|
||||
$array['grpc-opts'] = [];
|
||||
if (isset($grpcSettings['serviceName'])) $array['grpc-opts']['grpc-service-name'] = $grpcSettings['serviceName'];
|
||||
}
|
||||
}
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
public static function buildTrojan($password, $server)
|
||||
{
|
||||
$array = [];
|
||||
$array['name'] = $server['name'];
|
||||
$array['type'] = 'trojan';
|
||||
$array['server'] = $server['host'];
|
||||
$array['port'] = $server['port'];
|
||||
$array['password'] = $password;
|
||||
$array['udp'] = true;
|
||||
if (!empty($server['server_name'])) $array['sni'] = $server['server_name'];
|
||||
if (!empty($server['allow_insecure'])) $array['skip-cert-verify'] = ($server['allow_insecure'] ? true : false);
|
||||
return $array;
|
||||
}
|
||||
|
||||
private function isMatch($exp, $str)
|
||||
{
|
||||
return @preg_match($exp, $str);
|
||||
}
|
||||
|
||||
private function isRegex($exp)
|
||||
{
|
||||
return @preg_match($exp, null) !== false;
|
||||
}
|
||||
}
|
113
app/Http/Controllers/Client/Protocols/General.php
Normal file
113
app/Http/Controllers/Client/Protocols/General.php
Normal file
@ -0,0 +1,113 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Client\Protocols;
|
||||
|
||||
|
||||
use App\Utils\Helper;
|
||||
|
||||
class General
|
||||
{
|
||||
public $flag = 'general';
|
||||
private $servers;
|
||||
private $user;
|
||||
|
||||
public function __construct($user, $servers)
|
||||
{
|
||||
$this->user = $user;
|
||||
$this->servers = $servers;
|
||||
}
|
||||
|
||||
public function handle()
|
||||
{
|
||||
$servers = $this->servers;
|
||||
$user = $this->user;
|
||||
$uri = '';
|
||||
|
||||
foreach ($servers as $item) {
|
||||
if ($item['type'] === 'vmess') {
|
||||
$uri .= self::buildVmess($user['uuid'], $item);
|
||||
}
|
||||
if ($item['type'] === 'shadowsocks') {
|
||||
$uri .= self::buildShadowsocks($user['uuid'], $item);
|
||||
}
|
||||
if ($item['type'] === 'trojan') {
|
||||
$uri .= self::buildTrojan($user['uuid'], $item);
|
||||
}
|
||||
}
|
||||
return base64_encode($uri);
|
||||
}
|
||||
|
||||
public static function buildShadowsocks($password, $server)
|
||||
{
|
||||
if ($server['cipher'] === '2022-blake3-aes-128-gcm') {
|
||||
$serverKey = Helper::getServerKey($server['created_at'], 16);
|
||||
$userKey = Helper::uuidToBase64($password, 16);
|
||||
$password = "{$serverKey}:{$userKey}";
|
||||
}
|
||||
if ($server['cipher'] === '2022-blake3-aes-256-gcm') {
|
||||
$serverKey = Helper::getServerKey($server['created_at'], 32);
|
||||
$userKey = Helper::uuidToBase64($password, 32);
|
||||
$password = "{$serverKey}:{$userKey}";
|
||||
}
|
||||
$name = rawurlencode($server['name']);
|
||||
$str = str_replace(
|
||||
['+', '/', '='],
|
||||
['-', '_', ''],
|
||||
base64_encode("{$server['cipher']}:{$password}")
|
||||
);
|
||||
return "ss://{$str}@{$server['host']}:{$server['port']}#{$name}\r\n";
|
||||
}
|
||||
|
||||
public static function buildVmess($uuid, $server)
|
||||
{
|
||||
$config = [
|
||||
"v" => "2",
|
||||
"ps" => $server['name'],
|
||||
"add" => $server['host'],
|
||||
"port" => (string)$server['port'],
|
||||
"id" => $uuid,
|
||||
"aid" => '0',
|
||||
"net" => $server['network'],
|
||||
"type" => "none",
|
||||
"host" => "",
|
||||
"path" => "",
|
||||
"tls" => $server['tls'] ? "tls" : "",
|
||||
];
|
||||
if ($server['tls']) {
|
||||
if ($server['tlsSettings']) {
|
||||
$tlsSettings = $server['tlsSettings'];
|
||||
if (isset($tlsSettings['serverName']) && !empty($tlsSettings['serverName']))
|
||||
$config['sni'] = $tlsSettings['serverName'];
|
||||
}
|
||||
}
|
||||
if ((string)$server['network'] === 'tcp') {
|
||||
$tcpSettings = $server['networkSettings'];
|
||||
if (isset($tcpSettings['header']['type'])) $config['type'] = $tcpSettings['header']['type'];
|
||||
if (isset($tcpSettings['header']['request']['path'][0])) $config['path'] = $tcpSettings['header']['request']['path'][0];
|
||||
}
|
||||
if ((string)$server['network'] === 'ws') {
|
||||
$wsSettings = $server['networkSettings'];
|
||||
if (isset($wsSettings['path'])) $config['path'] = $wsSettings['path'];
|
||||
if (isset($wsSettings['headers']['Host'])) $config['host'] = $wsSettings['headers']['Host'];
|
||||
}
|
||||
if ((string)$server['network'] === 'grpc') {
|
||||
$grpcSettings = $server['networkSettings'];
|
||||
if (isset($grpcSettings['serviceName'])) $config['path'] = $grpcSettings['serviceName'];
|
||||
}
|
||||
return "vmess://" . base64_encode(json_encode($config)) . "\r\n";
|
||||
}
|
||||
|
||||
public static function buildTrojan($password, $server)
|
||||
{
|
||||
$name = rawurlencode($server['name']);
|
||||
$query = http_build_query([
|
||||
'allowInsecure' => $server['allow_insecure'],
|
||||
'peer' => $server['server_name'],
|
||||
'sni' => $server['server_name']
|
||||
]);
|
||||
$uri = "trojan://{$password}@{$server['host']}:{$server['port']}?{$query}#{$name}";
|
||||
$uri .= "\r\n";
|
||||
return $uri;
|
||||
}
|
||||
|
||||
}
|
137
app/Http/Controllers/Client/Protocols/Loon.php
Normal file
137
app/Http/Controllers/Client/Protocols/Loon.php
Normal file
@ -0,0 +1,137 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Client\Protocols;
|
||||
|
||||
use App\Utils\Helper;
|
||||
|
||||
class Loon
|
||||
{
|
||||
public $flag = 'loon';
|
||||
private $servers;
|
||||
private $user;
|
||||
|
||||
public function __construct($user, $servers)
|
||||
{
|
||||
$this->user = $user;
|
||||
$this->servers = $servers;
|
||||
}
|
||||
|
||||
public function handle()
|
||||
{
|
||||
$servers = $this->servers;
|
||||
$user = $this->user;
|
||||
|
||||
$uri = '';
|
||||
header("Subscription-Userinfo: upload={$user['u']}; download={$user['d']}; total={$user['transfer_enable']}; expire={$user['expired_at']}");
|
||||
|
||||
foreach ($servers as $item) {
|
||||
if ($item['type'] === 'shadowsocks'
|
||||
&& in_array($item['cipher'], [
|
||||
'aes-128-gcm',
|
||||
'aes-192-gcm',
|
||||
'aes-256-gcm',
|
||||
'chacha20-ietf-poly1305'
|
||||
])
|
||||
) {
|
||||
$uri .= self::buildShadowsocks($user['uuid'], $item);
|
||||
}
|
||||
if ($item['type'] === 'vmess') {
|
||||
$uri .= self::buildVmess($user['uuid'], $item);
|
||||
}
|
||||
if ($item['type'] === 'trojan') {
|
||||
$uri .= self::buildTrojan($user['uuid'], $item);
|
||||
}
|
||||
}
|
||||
return $uri;
|
||||
}
|
||||
|
||||
|
||||
public static function buildShadowsocks($password, $server)
|
||||
{
|
||||
$config = [
|
||||
"{$server['name']}=Shadowsocks",
|
||||
"{$server['host']}",
|
||||
"{$server['port']}",
|
||||
"{$server['cipher']}",
|
||||
"{$password}",
|
||||
'fast-open=false',
|
||||
'udp=true'
|
||||
];
|
||||
$config = array_filter($config);
|
||||
$uri = implode(',', $config);
|
||||
$uri .= "\r\n";
|
||||
return $uri;
|
||||
}
|
||||
|
||||
public static function buildVmess($uuid, $server)
|
||||
{
|
||||
$config = [
|
||||
"{$server['name']}=vmess",
|
||||
"{$server['host']}",
|
||||
"{$server['port']}",
|
||||
'auto',
|
||||
"{$uuid}",
|
||||
'fast-open=false',
|
||||
'udp=true',
|
||||
"alterId=0"
|
||||
];
|
||||
|
||||
if ($server['network'] === 'tcp') {
|
||||
array_push($config, 'transport=tcp');
|
||||
if ($server['networkSettings']) {
|
||||
$tcpSettings = $server['networkSettings'];
|
||||
if (isset($tcpSettings['header']['type']) && !empty($tcpSettings['header']['type']))
|
||||
$config = str_replace('transport=tcp', "transport={$tcpSettings['header']['type']}", $config);
|
||||
if (isset($tcpSettings['header']['request']['path'][0]) && !empty($tcpSettings['header']['request']['path'][0]))
|
||||
array_push($config, "path={$tcpSettings['header']['request']['path'][0]}");
|
||||
if (isset($tcpSettings['header']['Host']) && !empty($tcpSettings['header']['Host']))
|
||||
array_push($config, "host={$tcpSettings['header']['Host']}");
|
||||
}
|
||||
}
|
||||
if ($server['tls']) {
|
||||
if ($server['network'] === 'tcp')
|
||||
array_push($config, 'over-tls=true');
|
||||
if ($server['tlsSettings']) {
|
||||
$tlsSettings = $server['tlsSettings'];
|
||||
if (isset($tlsSettings['allowInsecure']) && !empty($tlsSettings['allowInsecure']))
|
||||
array_push($config, 'skip-cert-verify=' . ($tlsSettings['allowInsecure'] ? 'true' : 'false'));
|
||||
if (isset($tlsSettings['serverName']) && !empty($tlsSettings['serverName']))
|
||||
array_push($config, "tls-name={$tlsSettings['serverName']}");
|
||||
}
|
||||
}
|
||||
if ($server['network'] === 'ws') {
|
||||
array_push($config, 'transport=ws');
|
||||
if ($server['networkSettings']) {
|
||||
$wsSettings = $server['networkSettings'];
|
||||
if (isset($wsSettings['path']) && !empty($wsSettings['path']))
|
||||
array_push($config, "path={$wsSettings['path']}");
|
||||
if (isset($wsSettings['headers']['Host']) && !empty($wsSettings['headers']['Host']))
|
||||
array_push($config, "host={$wsSettings['headers']['Host']}");
|
||||
}
|
||||
}
|
||||
|
||||
$uri = implode(',', $config);
|
||||
$uri .= "\r\n";
|
||||
return $uri;
|
||||
}
|
||||
|
||||
public static function buildTrojan($password, $server)
|
||||
{
|
||||
$config = [
|
||||
"{$server['name']}=trojan",
|
||||
"{$server['host']}",
|
||||
"{$server['port']}",
|
||||
"{$password}",
|
||||
$server['server_name'] ? "tls-name={$server['server_name']}" : "",
|
||||
'fast-open=false',
|
||||
'udp=true'
|
||||
];
|
||||
if (!empty($server['allow_insecure'])) {
|
||||
array_push($config, $server['allow_insecure'] ? 'skip-cert-verify=true' : 'skip-cert-verify=false');
|
||||
}
|
||||
$config = array_filter($config);
|
||||
$uri = implode(',', $config);
|
||||
$uri .= "\r\n";
|
||||
return $uri;
|
||||
}
|
||||
}
|
101
app/Http/Controllers/Client/Protocols/Passwall.php
Normal file
101
app/Http/Controllers/Client/Protocols/Passwall.php
Normal file
@ -0,0 +1,101 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Client\Protocols;
|
||||
|
||||
|
||||
class Passwall
|
||||
{
|
||||
public $flag = 'passwall';
|
||||
private $servers;
|
||||
private $user;
|
||||
|
||||
public function __construct($user, $servers)
|
||||
{
|
||||
$this->user = $user;
|
||||
$this->servers = $servers;
|
||||
}
|
||||
|
||||
public function handle()
|
||||
{
|
||||
$servers = $this->servers;
|
||||
$user = $this->user;
|
||||
$uri = '';
|
||||
|
||||
foreach ($servers as $item) {
|
||||
if ($item['type'] === 'vmess') {
|
||||
$uri .= self::buildVmess($user['uuid'], $item);
|
||||
}
|
||||
if ($item['type'] === 'shadowsocks') {
|
||||
$uri .= self::buildShadowsocks($user['uuid'], $item);
|
||||
}
|
||||
if ($item['type'] === 'trojan') {
|
||||
$uri .= self::buildTrojan($user['uuid'], $item);
|
||||
}
|
||||
}
|
||||
return base64_encode($uri);
|
||||
}
|
||||
|
||||
public static function buildShadowsocks($password, $server)
|
||||
{
|
||||
$name = rawurlencode($server['name']);
|
||||
$str = str_replace(
|
||||
['+', '/', '='],
|
||||
['-', '_', ''],
|
||||
base64_encode("{$server['cipher']}:{$password}")
|
||||
);
|
||||
return "ss://{$str}@{$server['host']}:{$server['port']}#{$name}\r\n";
|
||||
}
|
||||
|
||||
public static function buildVmess($uuid, $server)
|
||||
{
|
||||
$config = [
|
||||
"v" => "2",
|
||||
"ps" => $server['name'],
|
||||
"add" => $server['host'],
|
||||
"port" => (string)$server['port'],
|
||||
"id" => $uuid,
|
||||
"aid" => '0',
|
||||
"net" => $server['network'],
|
||||
"type" => "none",
|
||||
"host" => "",
|
||||
"path" => "",
|
||||
"tls" => $server['tls'] ? "tls" : "",
|
||||
];
|
||||
if ($server['tls']) {
|
||||
if ($server['tlsSettings']) {
|
||||
$tlsSettings = $server['tlsSettings'];
|
||||
if (isset($tlsSettings['serverName']) && !empty($tlsSettings['serverName']))
|
||||
$config['sni'] = $tlsSettings['serverName'];
|
||||
}
|
||||
}
|
||||
if ((string)$server['network'] === 'tcp') {
|
||||
$tcpSettings = $server['networkSettings'];
|
||||
if (isset($tcpSettings['header']['type'])) $config['type'] = $tcpSettings['header']['type'];
|
||||
if (isset($tcpSettings['header']['request']['path'][0])) $config['path'] = $tcpSettings['header']['request']['path'][0];
|
||||
}
|
||||
if ((string)$server['network'] === 'ws') {
|
||||
$wsSettings = $server['networkSettings'];
|
||||
if (isset($wsSettings['path'])) $config['path'] = $wsSettings['path'];
|
||||
if (isset($wsSettings['headers']['Host'])) $config['host'] = $wsSettings['headers']['Host'];
|
||||
}
|
||||
if ((string)$server['network'] === 'grpc') {
|
||||
$grpcSettings = $server['networkSettings'];
|
||||
if (isset($grpcSettings['serviceName'])) $config['path'] = $grpcSettings['serviceName'];
|
||||
}
|
||||
return "vmess://" . base64_encode(json_encode($config)) . "\r\n";
|
||||
}
|
||||
|
||||
public static function buildTrojan($password, $server)
|
||||
{
|
||||
$name = rawurlencode($server['name']);
|
||||
$query = http_build_query([
|
||||
'allowInsecure' => $server['allow_insecure'],
|
||||
'peer' => $server['server_name'],
|
||||
'sni' => $server['server_name']
|
||||
]);
|
||||
$uri = "trojan://{$password}@{$server['host']}:{$server['port']}?{$query}#{$name}";
|
||||
$uri .= "\r\n";
|
||||
return $uri;
|
||||
}
|
||||
|
||||
}
|
116
app/Http/Controllers/Client/Protocols/QuantumultX.php
Normal file
116
app/Http/Controllers/Client/Protocols/QuantumultX.php
Normal file
@ -0,0 +1,116 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Client\Protocols;
|
||||
|
||||
|
||||
class QuantumultX
|
||||
{
|
||||
public $flag = 'quantumult%20x';
|
||||
private $servers;
|
||||
private $user;
|
||||
|
||||
public function __construct($user, $servers)
|
||||
{
|
||||
$this->user = $user;
|
||||
$this->servers = $servers;
|
||||
}
|
||||
|
||||
public function handle()
|
||||
{
|
||||
$servers = $this->servers;
|
||||
$user = $this->user;
|
||||
$uri = '';
|
||||
header("subscription-userinfo: upload={$user['u']}; download={$user['d']}; total={$user['transfer_enable']}; expire={$user['expired_at']}");
|
||||
foreach ($servers as $item) {
|
||||
if ($item['type'] === 'shadowsocks') {
|
||||
$uri .= self::buildShadowsocks($user['uuid'], $item);
|
||||
}
|
||||
if ($item['type'] === 'vmess') {
|
||||
$uri .= self::buildVmess($user['uuid'], $item);
|
||||
}
|
||||
if ($item['type'] === 'trojan') {
|
||||
$uri .= self::buildTrojan($user['uuid'], $item);
|
||||
}
|
||||
}
|
||||
return base64_encode($uri);
|
||||
}
|
||||
|
||||
public static function buildShadowsocks($password, $server)
|
||||
{
|
||||
$config = [
|
||||
"shadowsocks={$server['host']}:{$server['port']}",
|
||||
"method={$server['cipher']}",
|
||||
"password={$password}",
|
||||
'fast-open=true',
|
||||
'udp-relay=true',
|
||||
"tag={$server['name']}"
|
||||
];
|
||||
$config = array_filter($config);
|
||||
$uri = implode(',', $config);
|
||||
$uri .= "\r\n";
|
||||
return $uri;
|
||||
}
|
||||
|
||||
public static function buildVmess($uuid, $server)
|
||||
{
|
||||
$config = [
|
||||
"vmess={$server['host']}:{$server['port']}",
|
||||
'method=chacha20-poly1305',
|
||||
"password={$uuid}",
|
||||
'fast-open=true',
|
||||
'udp-relay=true',
|
||||
"tag={$server['name']}"
|
||||
];
|
||||
|
||||
if ($server['tls']) {
|
||||
if ($server['network'] === 'tcp')
|
||||
array_push($config, 'obfs=over-tls');
|
||||
if ($server['tlsSettings']) {
|
||||
$tlsSettings = $server['tlsSettings'];
|
||||
if (isset($tlsSettings['allowInsecure']) && !empty($tlsSettings['allowInsecure']))
|
||||
array_push($config, 'tls-verification=' . ($tlsSettings['allowInsecure'] ? 'false' : 'true'));
|
||||
if (isset($tlsSettings['serverName']) && !empty($tlsSettings['serverName']))
|
||||
$host = $tlsSettings['serverName'];
|
||||
}
|
||||
}
|
||||
if ($server['network'] === 'ws') {
|
||||
if ($server['tls'])
|
||||
array_push($config, 'obfs=wss');
|
||||
else
|
||||
array_push($config, 'obfs=ws');
|
||||
if ($server['networkSettings']) {
|
||||
$wsSettings = $server['networkSettings'];
|
||||
if (isset($wsSettings['path']) && !empty($wsSettings['path']))
|
||||
array_push($config, "obfs-uri={$wsSettings['path']}");
|
||||
if (isset($wsSettings['headers']['Host']) && !empty($wsSettings['headers']['Host']) && !isset($host))
|
||||
$host = $wsSettings['headers']['Host'];
|
||||
}
|
||||
}
|
||||
if (isset($host)) {
|
||||
array_push($config, "obfs-host={$host}");
|
||||
}
|
||||
|
||||
$uri = implode(',', $config);
|
||||
$uri .= "\r\n";
|
||||
return $uri;
|
||||
}
|
||||
|
||||
public static function buildTrojan($password, $server)
|
||||
{
|
||||
$config = [
|
||||
"trojan={$server['host']}:{$server['port']}",
|
||||
"password={$password}",
|
||||
'over-tls=true',
|
||||
$server['server_name'] ? "tls-host={$server['server_name']}" : "",
|
||||
// Tips: allowInsecure=false = tls-verification=true
|
||||
$server['allow_insecure'] ? 'tls-verification=false' : 'tls-verification=true',
|
||||
'fast-open=true',
|
||||
'udp-relay=true',
|
||||
"tag={$server['name']}"
|
||||
];
|
||||
$config = array_filter($config);
|
||||
$uri = implode(',', $config);
|
||||
$uri .= "\r\n";
|
||||
return $uri;
|
||||
}
|
||||
}
|
96
app/Http/Controllers/Client/Protocols/SSRPlus.php
Normal file
96
app/Http/Controllers/Client/Protocols/SSRPlus.php
Normal file
@ -0,0 +1,96 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Client\Protocols;
|
||||
|
||||
|
||||
class SSRPlus
|
||||
{
|
||||
public $flag = 'ssrplus';
|
||||
private $servers;
|
||||
private $user;
|
||||
|
||||
public function __construct($user, $servers)
|
||||
{
|
||||
$this->user = $user;
|
||||
$this->servers = $servers;
|
||||
}
|
||||
|
||||
public function handle()
|
||||
{
|
||||
$servers = $this->servers;
|
||||
$user = $this->user;
|
||||
$uri = '';
|
||||
|
||||
foreach ($servers as $item) {
|
||||
if ($item['type'] === 'vmess') {
|
||||
$uri .= self::buildVmess($user['uuid'], $item);
|
||||
}
|
||||
if ($item['type'] === 'shadowsocks') {
|
||||
$uri .= self::buildShadowsocks($user['uuid'], $item);
|
||||
}
|
||||
if ($item['type'] === 'trojan') {
|
||||
$uri .= self::buildTrojan($user['uuid'], $item);
|
||||
}
|
||||
}
|
||||
return base64_encode($uri);
|
||||
}
|
||||
|
||||
public static function buildShadowsocks($password, $server)
|
||||
{
|
||||
$name = rawurlencode($server['name']);
|
||||
$str = str_replace(
|
||||
['+', '/', '='],
|
||||
['-', '_', ''],
|
||||
base64_encode("{$server['cipher']}:{$password}")
|
||||
);
|
||||
return "ss://{$str}@{$server['host']}:{$server['port']}#{$name}\r\n";
|
||||
}
|
||||
|
||||
public static function buildVmess($uuid, $server)
|
||||
{
|
||||
$config = [
|
||||
"v" => "2",
|
||||
"ps" => $server['name'],
|
||||
"add" => $server['host'],
|
||||
"port" => (string)$server['port'],
|
||||
"id" => $uuid,
|
||||
"aid" => '0',
|
||||
"net" => $server['network'],
|
||||
"type" => "none",
|
||||
"host" => "",
|
||||
"path" => "",
|
||||
"tls" => $server['tls'] ? "tls" : "",
|
||||
];
|
||||
if ($server['tls']) {
|
||||
if ($server['tlsSettings']) {
|
||||
$tlsSettings = $server['tlsSettings'];
|
||||
if (isset($tlsSettings['serverName']) && !empty($tlsSettings['serverName']))
|
||||
$config['sni'] = $tlsSettings['serverName'];
|
||||
}
|
||||
}
|
||||
if ((string)$server['network'] === 'ws') {
|
||||
$wsSettings = $server['networkSettings'];
|
||||
if (isset($wsSettings['path'])) $config['path'] = $wsSettings['path'];
|
||||
if (isset($wsSettings['headers']['Host'])) $config['host'] = $wsSettings['headers']['Host'];
|
||||
}
|
||||
if ((string)$server['network'] === 'grpc') {
|
||||
$grpcSettings = $server['networkSettings'];
|
||||
if (isset($grpcSettings['serviceName'])) $config['path'] = $grpcSettings['serviceName'];
|
||||
}
|
||||
return "vmess://" . base64_encode(json_encode($config)) . "\r\n";
|
||||
}
|
||||
|
||||
public static function buildTrojan($password, $server)
|
||||
{
|
||||
$name = rawurlencode($server['name']);
|
||||
$query = http_build_query([
|
||||
'allowInsecure' => $server['allow_insecure'],
|
||||
'peer' => $server['server_name'],
|
||||
'sni' => $server['server_name']
|
||||
]);
|
||||
$uri = "trojan://{$password}@{$server['host']}:{$server['port']}?{$query}#{$name}";
|
||||
$uri .= "\r\n";
|
||||
return $uri;
|
||||
}
|
||||
|
||||
}
|
104
app/Http/Controllers/Client/Protocols/SagerNet.php
Normal file
104
app/Http/Controllers/Client/Protocols/SagerNet.php
Normal file
@ -0,0 +1,104 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Client\Protocols;
|
||||
|
||||
class SagerNet
|
||||
{
|
||||
public $flag = 'sagernet';
|
||||
private $servers;
|
||||
private $user;
|
||||
|
||||
public function __construct($user, $servers)
|
||||
{
|
||||
$this->user = $user;
|
||||
$this->servers = $servers;
|
||||
}
|
||||
|
||||
public function handle()
|
||||
{
|
||||
$servers = $this->servers;
|
||||
$user = $this->user;
|
||||
$uri = '';
|
||||
|
||||
foreach ($servers as $item) {
|
||||
if ($item['type'] === 'vmess') {
|
||||
$uri .= self::buildVmess($user['uuid'], $item);
|
||||
}
|
||||
if ($item['type'] === 'shadowsocks') {
|
||||
$uri .= self::buildShadowsocks($user['uuid'], $item);
|
||||
}
|
||||
if ($item['type'] === 'trojan') {
|
||||
$uri .= self::buildTrojan($user['uuid'], $item);
|
||||
}
|
||||
}
|
||||
return base64_encode($uri);
|
||||
}
|
||||
|
||||
public static function buildShadowsocks($uuid, $server)
|
||||
{
|
||||
$name = rawurlencode($server['name']);
|
||||
$str = str_replace(
|
||||
['+', '/', '='],
|
||||
['-', '_', ''],
|
||||
base64_encode("{$server['cipher']}:{$uuid}")
|
||||
);
|
||||
return "ss://{$str}@{$server['host']}:{$server['port']}#{$name}\r\n";
|
||||
}
|
||||
|
||||
public static function buildShadowsocksSIP008($uuid, $server)
|
||||
{
|
||||
$config = [
|
||||
"id" => $server['id'],
|
||||
"remarks" => $server['name'],
|
||||
"server" => $server['host'],
|
||||
"server_port" => $server['port'],
|
||||
"password" => $uuid,
|
||||
"method" => $server['cipher']
|
||||
];
|
||||
return $config;
|
||||
}
|
||||
|
||||
public static function buildVmess($uuid, $server)
|
||||
{
|
||||
$config = [
|
||||
"encryption" => "none",
|
||||
"type" => urlencode($server['network']),
|
||||
"security" => $server['tls'] ? "tls" : "",
|
||||
];
|
||||
if ($server['tls']) {
|
||||
if ($server['tlsSettings']) {
|
||||
$tlsSettings = $server['tlsSettings'];
|
||||
if (isset($tlsSettings['serverName']) && !empty($tlsSettings['serverName']))
|
||||
$config['sni'] = urlencode($tlsSettings['serverName']);
|
||||
}
|
||||
}
|
||||
if ((string)$server['network'] === 'tcp') {
|
||||
$tcpSettings = $server['networkSettings'];
|
||||
if (isset($tcpSettings['header']['type'])) $config['type'] = $tcpSettings['header']['type'];
|
||||
if (isset($tcpSettings['header']['request']['path'][0])) $config['path'] = $tcpSettings['header']['request']['path'][0];
|
||||
}
|
||||
if ((string)$server['network'] === 'ws') {
|
||||
$wsSettings = $server['networkSettings'];
|
||||
if (isset($wsSettings['path'])) $config['path'] = $wsSettings['path'];
|
||||
if (isset($wsSettings['headers']['Host'])) $config['host'] = urlencode($wsSettings['headers']['Host']);
|
||||
}
|
||||
if ((string)$server['network'] === 'grpc') {
|
||||
$grpcSettings = $server['networkSettings'];
|
||||
if (isset($grpcSettings['serviceName'])) $config['serviceName'] = urlencode($grpcSettings['serviceName']);
|
||||
}
|
||||
return "vmess://" . $uuid . "@" . $server['host'] . ":" . $server['port'] . "?" . http_build_query($config) . "#" . urlencode($server['name']) . "\r\n";
|
||||
}
|
||||
|
||||
public static function buildTrojan($uuid, $server)
|
||||
{
|
||||
$name = rawurlencode($server['name']);
|
||||
$query = http_build_query([
|
||||
'allowInsecure' => $server['allow_insecure'],
|
||||
'peer' => $server['server_name'],
|
||||
'sni' => $server['server_name']
|
||||
]);
|
||||
$uri = "trojan://{$uuid}@{$server['host']}:{$server['port']}?{$query}#{$name}";
|
||||
$uri .= "\r\n";
|
||||
return $uri;
|
||||
}
|
||||
}
|
134
app/Http/Controllers/Client/Protocols/Shadowrocket.php
Normal file
134
app/Http/Controllers/Client/Protocols/Shadowrocket.php
Normal file
@ -0,0 +1,134 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Client\Protocols;
|
||||
|
||||
use App\Utils\Helper;
|
||||
|
||||
class Shadowrocket
|
||||
{
|
||||
public $flag = 'shadowrocket';
|
||||
private $servers;
|
||||
private $user;
|
||||
|
||||
public function __construct($user, $servers)
|
||||
{
|
||||
$this->user = $user;
|
||||
$this->servers = $servers;
|
||||
}
|
||||
|
||||
public function handle()
|
||||
{
|
||||
$servers = $this->servers;
|
||||
$user = $this->user;
|
||||
|
||||
$uri = '';
|
||||
//display remaining traffic and expire date
|
||||
$upload = round($user['u'] / (1024*1024*1024), 2);
|
||||
$download = round($user['d'] / (1024*1024*1024), 2);
|
||||
$totalTraffic = round($user['transfer_enable'] / (1024*1024*1024), 2);
|
||||
$expiredDate = date('Y-m-d', $user['expired_at']);
|
||||
$uri .= "STATUS=🚀↑:{$upload}GB,↓:{$download}GB,TOT:{$totalTraffic}GB💡Expires:{$expiredDate}\r\n";
|
||||
foreach ($servers as $item) {
|
||||
if ($item['type'] === 'shadowsocks') {
|
||||
$uri .= self::buildShadowsocks($user['uuid'], $item);
|
||||
}
|
||||
if ($item['type'] === 'vmess') {
|
||||
$uri .= self::buildVmess($user['uuid'], $item);
|
||||
}
|
||||
if ($item['type'] === 'trojan') {
|
||||
$uri .= self::buildTrojan($user['uuid'], $item);
|
||||
}
|
||||
}
|
||||
return base64_encode($uri);
|
||||
}
|
||||
|
||||
|
||||
public static function buildShadowsocks($password, $server)
|
||||
{
|
||||
if ($server['cipher'] === '2022-blake3-aes-128-gcm') {
|
||||
$serverKey = Helper::getServerKey($server['created_at'], 16);
|
||||
$userKey = Helper::uuidToBase64($password, 16);
|
||||
$password = "{$serverKey}:{$userKey}";
|
||||
}
|
||||
if ($server['cipher'] === '2022-blake3-aes-256-gcm') {
|
||||
$serverKey = Helper::getServerKey($server['created_at'], 32);
|
||||
$userKey = Helper::uuidToBase64($password, 32);
|
||||
$password = "{$serverKey}:{$userKey}";
|
||||
}
|
||||
$name = rawurlencode($server['name']);
|
||||
$str = str_replace(
|
||||
['+', '/', '='],
|
||||
['-', '_', ''],
|
||||
base64_encode("{$server['cipher']}:{$password}")
|
||||
);
|
||||
return "ss://{$str}@{$server['host']}:{$server['port']}#{$name}\r\n";
|
||||
}
|
||||
|
||||
public static function buildVmess($uuid, $server)
|
||||
{
|
||||
$userinfo = base64_encode('auto:' . $uuid . '@' . $server['host'] . ':' . $server['port']);
|
||||
$config = [
|
||||
'tfo' => 1,
|
||||
'remark' => $server['name'],
|
||||
'alterId' => 0
|
||||
];
|
||||
if ($server['tls']) {
|
||||
$config['tls'] = 1;
|
||||
if ($server['tlsSettings']) {
|
||||
$tlsSettings = $server['tlsSettings'];
|
||||
if (isset($tlsSettings['allowInsecure']) && !empty($tlsSettings['allowInsecure']))
|
||||
$config['allowInsecure'] = (int)$tlsSettings['allowInsecure'];
|
||||
if (isset($tlsSettings['serverName']) && !empty($tlsSettings['serverName']))
|
||||
$config['peer'] = $tlsSettings['serverName'];
|
||||
}
|
||||
}
|
||||
if ($server['network'] === 'tcp') {
|
||||
if ($server['networkSettings']) {
|
||||
$tcpSettings = $server['networkSettings'];
|
||||
if (isset($tcpSettings['header']['type']) && !empty($tcpSettings['header']['type']))
|
||||
$config['obfs'] = $tcpSettings['header']['type'];
|
||||
if (isset($tcpSettings['header']['request']['path'][0]) && !empty($tcpSettings['header']['request']['path'][0]))
|
||||
$config['path'] = $tcpSettings['header']['request']['path'][0];
|
||||
}
|
||||
}
|
||||
if ($server['network'] === 'ws') {
|
||||
$config['obfs'] = "websocket";
|
||||
if ($server['networkSettings']) {
|
||||
$wsSettings = $server['networkSettings'];
|
||||
if (isset($wsSettings['path']) && !empty($wsSettings['path']))
|
||||
$config['path'] = $wsSettings['path'];
|
||||
if (isset($wsSettings['headers']['Host']) && !empty($wsSettings['headers']['Host']))
|
||||
$config['obfsParam'] = $wsSettings['headers']['Host'];
|
||||
}
|
||||
}
|
||||
if ($server['network'] === 'grpc') {
|
||||
$config['obfs'] = "grpc";
|
||||
if ($server['networkSettings']) {
|
||||
$grpcSettings = $server['networkSettings'];
|
||||
if (isset($grpcSettings['serviceName']) && !empty($grpcSettings['serviceName']))
|
||||
$config['path'] = $grpcSettings['serviceName'];
|
||||
}
|
||||
if (isset($tlsSettings)) {
|
||||
$config['host'] = $tlsSettings['serverName'];
|
||||
} else {
|
||||
$config['host'] = $server['host'];
|
||||
}
|
||||
}
|
||||
$query = http_build_query($config, '', '&', PHP_QUERY_RFC3986);
|
||||
$uri = "vmess://{$userinfo}?{$query}";
|
||||
$uri .= "\r\n";
|
||||
return $uri;
|
||||
}
|
||||
|
||||
public static function buildTrojan($password, $server)
|
||||
{
|
||||
$name = rawurlencode($server['name']);
|
||||
$query = http_build_query([
|
||||
'allowInsecure' => $server['allow_insecure'],
|
||||
'peer' => $server['server_name']
|
||||
]);
|
||||
$uri = "trojan://{$password}@{$server['host']}:{$server['port']}?{$query}&tfo=1#{$name}";
|
||||
$uri .= "\r\n";
|
||||
return $uri;
|
||||
}
|
||||
}
|
59
app/Http/Controllers/Client/Protocols/Shadowsocks.php
Normal file
59
app/Http/Controllers/Client/Protocols/Shadowsocks.php
Normal file
@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Client\Protocols;
|
||||
|
||||
class Shadowsocks
|
||||
{
|
||||
public $flag = 'shadowsocks';
|
||||
private $servers;
|
||||
private $user;
|
||||
|
||||
public function __construct($user, $servers)
|
||||
{
|
||||
$this->user = $user;
|
||||
$this->servers = $servers;
|
||||
}
|
||||
|
||||
public function handle()
|
||||
{
|
||||
$servers = $this->servers;
|
||||
$user = $this->user;
|
||||
|
||||
$configs = [];
|
||||
$subs = [];
|
||||
$subs['servers'] = [];
|
||||
$subs['bytes_used'] = '';
|
||||
$subs['bytes_remaining'] = '';
|
||||
|
||||
$bytesUsed = $user['u'] + $user['d'];
|
||||
$bytesRemaining = $user['transfer_enable'] - $bytesUsed;
|
||||
|
||||
foreach ($servers as $item) {
|
||||
if ($item['type'] === 'shadowsocks'
|
||||
&& in_array($item['cipher'], ['aes-128-gcm', 'aes-256-gcm', 'aes-192-gcm', 'chacha20-ietf-poly1305'])
|
||||
) {
|
||||
array_push($configs, self::SIP008($item, $user));
|
||||
}
|
||||
}
|
||||
|
||||
$subs['version'] = 1;
|
||||
$subs['bytes_used'] = $bytesUsed;
|
||||
$subs['bytes_remaining'] = $bytesRemaining;
|
||||
$subs['servers'] = array_merge($subs['servers'] ? $subs['servers'] : [], $configs);
|
||||
|
||||
return json_encode($subs, JSON_UNESCAPED_SLASHES|JSON_PRETTY_PRINT);
|
||||
}
|
||||
|
||||
public static function SIP008($server, $user)
|
||||
{
|
||||
$config = [
|
||||
"id" => $server['id'],
|
||||
"remarks" => $server['name'],
|
||||
"server" => $server['host'],
|
||||
"server_port" => $server['port'],
|
||||
"password" => $user['uuid'],
|
||||
"method" => $server['cipher']
|
||||
];
|
||||
return $config;
|
||||
}
|
||||
}
|
187
app/Http/Controllers/Client/Protocols/Stash.php
Normal file
187
app/Http/Controllers/Client/Protocols/Stash.php
Normal file
@ -0,0 +1,187 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Client\Protocols;
|
||||
|
||||
use Symfony\Component\Yaml\Yaml;
|
||||
|
||||
class Stash
|
||||
{
|
||||
public $flag = 'stash';
|
||||
private $servers;
|
||||
private $user;
|
||||
|
||||
public function __construct($user, $servers)
|
||||
{
|
||||
$this->user = $user;
|
||||
$this->servers = $servers;
|
||||
}
|
||||
|
||||
public function handle()
|
||||
{
|
||||
$servers = $this->servers;
|
||||
$user = $this->user;
|
||||
$appName = config('v2board.app_name', 'V2Board');
|
||||
header("subscription-userinfo: upload={$user['u']}; download={$user['d']}; total={$user['transfer_enable']}; expire={$user['expired_at']}");
|
||||
header('profile-update-interval: 24');
|
||||
header("content-disposition: filename*=UTF-8''".rawurlencode($appName));
|
||||
// 暂时使用clash配置文件,后续根据Stash更新情况更新
|
||||
$defaultConfig = base_path() . '/resources/rules/default.clash.yaml';
|
||||
$customConfig = base_path() . '/resources/rules/custom.clash.yaml';
|
||||
if (\File::exists($customConfig)) {
|
||||
$config = Yaml::parseFile($customConfig);
|
||||
} else {
|
||||
$config = Yaml::parseFile($defaultConfig);
|
||||
}
|
||||
$proxy = [];
|
||||
$proxies = [];
|
||||
|
||||
foreach ($servers as $item) {
|
||||
if ($item['type'] === 'shadowsocks'
|
||||
&& in_array($item['cipher'], [
|
||||
'aes-128-gcm',
|
||||
'aes-192-gcm',
|
||||
'aes-256-gcm',
|
||||
'chacha20-ietf-poly1305'
|
||||
])
|
||||
) {
|
||||
array_push($proxy, self::buildShadowsocks($user['uuid'], $item));
|
||||
array_push($proxies, $item['name']);
|
||||
}
|
||||
if ($item['type'] === 'vmess') {
|
||||
array_push($proxy, self::buildVmess($user['uuid'], $item));
|
||||
array_push($proxies, $item['name']);
|
||||
}
|
||||
if ($item['type'] === 'trojan') {
|
||||
array_push($proxy, self::buildTrojan($user['uuid'], $item));
|
||||
array_push($proxies, $item['name']);
|
||||
}
|
||||
}
|
||||
|
||||
$config['proxies'] = array_merge($config['proxies'] ? $config['proxies'] : [], $proxy);
|
||||
foreach ($config['proxy-groups'] as $k => $v) {
|
||||
if (!is_array($config['proxy-groups'][$k]['proxies'])) continue;
|
||||
$isFilter = false;
|
||||
foreach ($config['proxy-groups'][$k]['proxies'] as $src) {
|
||||
foreach ($proxies as $dst) {
|
||||
if (!$this->isRegex($src)) continue;
|
||||
$isFilter = true;
|
||||
$config['proxy-groups'][$k]['proxies'] = array_values(array_diff($config['proxy-groups'][$k]['proxies'], [$src]));
|
||||
if ($this->isMatch($src, $dst)) {
|
||||
array_push($config['proxy-groups'][$k]['proxies'], $dst);
|
||||
}
|
||||
}
|
||||
if ($isFilter) continue;
|
||||
}
|
||||
if ($isFilter) continue;
|
||||
$config['proxy-groups'][$k]['proxies'] = array_merge($config['proxy-groups'][$k]['proxies'], $proxies);
|
||||
}
|
||||
$config['proxy-groups'] = array_filter($config['proxy-groups'], function($group) {
|
||||
return $group['proxies'];
|
||||
});
|
||||
$config['proxy-groups'] = array_values($config['proxy-groups']);
|
||||
// Force the current subscription domain to be a direct rule
|
||||
$subsDomain = $_SERVER['HTTP_HOST'];
|
||||
if ($subsDomain) {
|
||||
array_unshift($config['rules'], "DOMAIN,{$subsDomain},DIRECT");
|
||||
}
|
||||
|
||||
$yaml = Yaml::dump($config, 2, 4, Yaml::DUMP_EMPTY_ARRAY_AS_SEQUENCE);
|
||||
$yaml = str_replace('$app_name', config('v2board.app_name', 'V2Board'), $yaml);
|
||||
return $yaml;
|
||||
}
|
||||
|
||||
public static function buildShadowsocks($uuid, $server)
|
||||
{
|
||||
$array = [];
|
||||
$array['name'] = $server['name'];
|
||||
$array['type'] = 'ss';
|
||||
$array['server'] = $server['host'];
|
||||
$array['port'] = $server['port'];
|
||||
$array['cipher'] = $server['cipher'];
|
||||
$array['password'] = $uuid;
|
||||
$array['udp'] = true;
|
||||
return $array;
|
||||
}
|
||||
|
||||
public static function buildVmess($uuid, $server)
|
||||
{
|
||||
$array = [];
|
||||
$array['name'] = $server['name'];
|
||||
$array['type'] = 'vmess';
|
||||
$array['server'] = $server['host'];
|
||||
$array['port'] = $server['port'];
|
||||
$array['uuid'] = $uuid;
|
||||
$array['alterId'] = 0;
|
||||
$array['cipher'] = 'auto';
|
||||
$array['udp'] = true;
|
||||
|
||||
if ($server['tls']) {
|
||||
$array['tls'] = true;
|
||||
if ($server['tlsSettings']) {
|
||||
$tlsSettings = $server['tlsSettings'];
|
||||
if (isset($tlsSettings['allowInsecure']) && !empty($tlsSettings['allowInsecure']))
|
||||
$array['skip-cert-verify'] = ($tlsSettings['allowInsecure'] ? true : false);
|
||||
if (isset($tlsSettings['serverName']) && !empty($tlsSettings['serverName']))
|
||||
$array['servername'] = $tlsSettings['serverName'];
|
||||
}
|
||||
}
|
||||
if ($server['network'] === 'tcp') {
|
||||
$tcpSettings = $server['networkSettings'];
|
||||
if (isset($tcpSettings['header']['type'])) $array['network'] = $tcpSettings['header']['type'];
|
||||
if (isset($tcpSettings['header']['request']['path'][0])) $array['http-opts']['path'] = $tcpSettings['header']['request']['path'][0];
|
||||
}
|
||||
if ($server['network'] === 'ws') {
|
||||
$array['network'] = 'ws';
|
||||
if ($server['networkSettings']) {
|
||||
$wsSettings = $server['networkSettings'];
|
||||
$array['ws-opts'] = [];
|
||||
if (isset($wsSettings['path']) && !empty($wsSettings['path']))
|
||||
$array['ws-opts']['path'] = $wsSettings['path'];
|
||||
if (isset($wsSettings['headers']['Host']) && !empty($wsSettings['headers']['Host']))
|
||||
$array['ws-opts']['headers'] = ['Host' => $wsSettings['headers']['Host']];
|
||||
if (isset($wsSettings['path']) && !empty($wsSettings['path']))
|
||||
$array['ws-path'] = $wsSettings['path'];
|
||||
if (isset($wsSettings['headers']['Host']) && !empty($wsSettings['headers']['Host']))
|
||||
$array['ws-headers'] = ['Host' => $wsSettings['headers']['Host']];
|
||||
}
|
||||
}
|
||||
if ($server['network'] === 'grpc') {
|
||||
$array['network'] = 'grpc';
|
||||
if ($server['networkSettings']) {
|
||||
$grpcSettings = $server['networkSettings'];
|
||||
$array['grpc-opts'] = [];
|
||||
if (isset($grpcSettings['serviceName'])) $array['grpc-opts']['grpc-service-name'] = $grpcSettings['serviceName'];
|
||||
}
|
||||
}
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
public static function buildTrojan($password, $server)
|
||||
{
|
||||
$array = [];
|
||||
$array['name'] = $server['name'];
|
||||
$array['type'] = 'trojan';
|
||||
$array['server'] = $server['host'];
|
||||
$array['port'] = $server['port'];
|
||||
$array['password'] = $password;
|
||||
$array['udp'] = true;
|
||||
if (!empty($server['server_name'])) $array['sni'] = $server['server_name'];
|
||||
if (!empty($server['allow_insecure'])) $array['skip-cert-verify'] = ($server['allow_insecure'] ? true : false);
|
||||
return $array;
|
||||
}
|
||||
|
||||
private function isRegex($exp)
|
||||
{
|
||||
return @preg_match($exp, null) !== false;
|
||||
}
|
||||
|
||||
private function isMatch($exp, $str)
|
||||
{
|
||||
try {
|
||||
return preg_match($exp, $str);
|
||||
} catch (\Exception $e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
161
app/Http/Controllers/Client/Protocols/Surfboard.php
Normal file
161
app/Http/Controllers/Client/Protocols/Surfboard.php
Normal file
@ -0,0 +1,161 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Client\Protocols;
|
||||
|
||||
use App\Utils\Helper;
|
||||
|
||||
class Surfboard
|
||||
{
|
||||
public $flag = 'surfboard';
|
||||
private $servers;
|
||||
private $user;
|
||||
|
||||
public function __construct($user, $servers)
|
||||
{
|
||||
$this->user = $user;
|
||||
$this->servers = $servers;
|
||||
}
|
||||
|
||||
public function handle()
|
||||
{
|
||||
$servers = $this->servers;
|
||||
$user = $this->user;
|
||||
|
||||
$appName = config('v2board.app_name', 'V2Board');
|
||||
header("content-disposition:attachment;filename*=UTF-8''".rawurlencode($appName).".conf");
|
||||
|
||||
$proxies = '';
|
||||
$proxyGroup = '';
|
||||
|
||||
foreach ($servers as $item) {
|
||||
if ($item['type'] === 'shadowsocks'
|
||||
&& in_array($item['cipher'], [
|
||||
'aes-128-gcm',
|
||||
'aes-192-gcm',
|
||||
'aes-256-gcm',
|
||||
'chacha20-ietf-poly1305'
|
||||
])
|
||||
) {
|
||||
// [Proxy]
|
||||
$proxies .= self::buildShadowsocks($user['uuid'], $item);
|
||||
// [Proxy Group]
|
||||
$proxyGroup .= $item['name'] . ', ';
|
||||
}
|
||||
if ($item['type'] === 'vmess') {
|
||||
// [Proxy]
|
||||
$proxies .= self::buildVmess($user['uuid'], $item);
|
||||
// [Proxy Group]
|
||||
$proxyGroup .= $item['name'] . ', ';
|
||||
}
|
||||
if ($item['type'] === 'trojan') {
|
||||
// [Proxy]
|
||||
$proxies .= self::buildTrojan($user['uuid'], $item);
|
||||
// [Proxy Group]
|
||||
$proxyGroup .= $item['name'] . ', ';
|
||||
}
|
||||
}
|
||||
|
||||
$defaultConfig = base_path() . '/resources/rules/default.surfboard.conf';
|
||||
$customConfig = base_path() . '/resources/rules/custom.surfboard.conf';
|
||||
if (\File::exists($customConfig)) {
|
||||
$config = file_get_contents("$customConfig");
|
||||
} else {
|
||||
$config = file_get_contents("$defaultConfig");
|
||||
}
|
||||
|
||||
// Subscription link
|
||||
$subsURL = Helper::getSubscribeUrl("/api/v1/client/subscribe?token={$user['token']}");
|
||||
$subsDomain = $_SERVER['HTTP_HOST'];
|
||||
|
||||
$config = str_replace('$subs_link', $subsURL, $config);
|
||||
$config = str_replace('$subs_domain', $subsDomain, $config);
|
||||
$config = str_replace('$proxies', $proxies, $config);
|
||||
$config = str_replace('$proxy_group', rtrim($proxyGroup, ', '), $config);
|
||||
|
||||
$upload = round($user['u'] / (1024*1024*1024), 2);
|
||||
$download = round($user['d'] / (1024*1024*1024), 2);
|
||||
$useTraffic = $upload + $download;
|
||||
$totalTraffic = round($user['transfer_enable'] / (1024*1024*1024), 2);
|
||||
$expireDate = $user['expired_at'] === NULL ? '长期有效' : date('Y-m-d H:i:s', $user['expired_at']);
|
||||
$subscribeInfo = "title={$appName}订阅信息, content=上传流量:{$upload}GB\\n下载流量:{$download}GB\\n剩余流量:{$useTraffic}GB\\n套餐流量:{$totalTraffic}GB\\n到期时间:{$expireDate}";
|
||||
$config = str_replace('$subscribe_info', $subscribeInfo, $config);
|
||||
|
||||
return $config;
|
||||
}
|
||||
|
||||
|
||||
public static function buildShadowsocks($password, $server)
|
||||
{
|
||||
$config = [
|
||||
"{$server['name']}=ss",
|
||||
"{$server['host']}",
|
||||
"{$server['port']}",
|
||||
"encrypt-method={$server['cipher']}",
|
||||
"password={$password}",
|
||||
'tfo=true',
|
||||
'udp-relay=true'
|
||||
];
|
||||
$config = array_filter($config);
|
||||
$uri = implode(',', $config);
|
||||
$uri .= "\r\n";
|
||||
return $uri;
|
||||
}
|
||||
|
||||
public static function buildVmess($uuid, $server)
|
||||
{
|
||||
$config = [
|
||||
"{$server['name']}=vmess",
|
||||
"{$server['host']}",
|
||||
"{$server['port']}",
|
||||
"username={$uuid}",
|
||||
"vmess-aead=true",
|
||||
'tfo=true',
|
||||
'udp-relay=true'
|
||||
];
|
||||
|
||||
if ($server['tls']) {
|
||||
array_push($config, 'tls=true');
|
||||
if ($server['tlsSettings']) {
|
||||
$tlsSettings = $server['tlsSettings'];
|
||||
if (isset($tlsSettings['allowInsecure']) && !empty($tlsSettings['allowInsecure']))
|
||||
array_push($config, 'skip-cert-verify=' . ($tlsSettings['allowInsecure'] ? 'true' : 'false'));
|
||||
if (isset($tlsSettings['serverName']) && !empty($tlsSettings['serverName']))
|
||||
array_push($config, "sni={$tlsSettings['serverName']}");
|
||||
}
|
||||
}
|
||||
if ($server['network'] === 'ws') {
|
||||
array_push($config, 'ws=true');
|
||||
if ($server['networkSettings']) {
|
||||
$wsSettings = $server['networkSettings'];
|
||||
if (isset($wsSettings['path']) && !empty($wsSettings['path']))
|
||||
array_push($config, "ws-path={$wsSettings['path']}");
|
||||
if (isset($wsSettings['headers']['Host']) && !empty($wsSettings['headers']['Host']))
|
||||
array_push($config, "ws-headers=Host:{$wsSettings['headers']['Host']}");
|
||||
}
|
||||
}
|
||||
|
||||
$uri = implode(',', $config);
|
||||
$uri .= "\r\n";
|
||||
return $uri;
|
||||
}
|
||||
|
||||
public static function buildTrojan($password, $server)
|
||||
{
|
||||
$config = [
|
||||
"{$server['name']}=trojan",
|
||||
"{$server['host']}",
|
||||
"{$server['port']}",
|
||||
"password={$password}",
|
||||
$server['server_name'] ? "sni={$server['server_name']}" : "",
|
||||
'tfo=true',
|
||||
'udp-relay=true'
|
||||
];
|
||||
if (!empty($server['allow_insecure'])) {
|
||||
array_push($config, $server['allow_insecure'] ? 'skip-cert-verify=true' : 'skip-cert-verify=false');
|
||||
}
|
||||
$config = array_filter($config);
|
||||
$uri = implode(',', $config);
|
||||
$uri .= "\r\n";
|
||||
return $uri;
|
||||
}
|
||||
}
|
162
app/Http/Controllers/Client/Protocols/Surge.php
Normal file
162
app/Http/Controllers/Client/Protocols/Surge.php
Normal file
@ -0,0 +1,162 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Client\Protocols;
|
||||
|
||||
use App\Utils\Helper;
|
||||
|
||||
class Surge
|
||||
{
|
||||
public $flag = 'surge';
|
||||
private $servers;
|
||||
private $user;
|
||||
|
||||
public function __construct($user, $servers)
|
||||
{
|
||||
$this->user = $user;
|
||||
$this->servers = $servers;
|
||||
}
|
||||
|
||||
public function handle()
|
||||
{
|
||||
$servers = $this->servers;
|
||||
$user = $this->user;
|
||||
|
||||
$appName = config('v2board.app_name', 'V2Board');
|
||||
header("content-disposition:attachment;filename*=UTF-8''".rawurlencode($appName).".conf");
|
||||
|
||||
$proxies = '';
|
||||
$proxyGroup = '';
|
||||
|
||||
foreach ($servers as $item) {
|
||||
if ($item['type'] === 'shadowsocks'
|
||||
&& in_array($item['cipher'], [
|
||||
'aes-128-gcm',
|
||||
'aes-192-gcm',
|
||||
'aes-256-gcm',
|
||||
'chacha20-ietf-poly1305'
|
||||
])
|
||||
) {
|
||||
// [Proxy]
|
||||
$proxies .= self::buildShadowsocks($user['uuid'], $item);
|
||||
// [Proxy Group]
|
||||
$proxyGroup .= $item['name'] . ', ';
|
||||
}
|
||||
if ($item['type'] === 'vmess') {
|
||||
// [Proxy]
|
||||
$proxies .= self::buildVmess($user['uuid'], $item);
|
||||
// [Proxy Group]
|
||||
$proxyGroup .= $item['name'] . ', ';
|
||||
}
|
||||
if ($item['type'] === 'trojan') {
|
||||
// [Proxy]
|
||||
$proxies .= self::buildTrojan($user['uuid'], $item);
|
||||
// [Proxy Group]
|
||||
$proxyGroup .= $item['name'] . ', ';
|
||||
}
|
||||
}
|
||||
|
||||
$defaultConfig = base_path() . '/resources/rules/default.surge.conf';
|
||||
$customConfig = base_path() . '/resources/rules/custom.surge.conf';
|
||||
if (\File::exists($customConfig)) {
|
||||
$config = file_get_contents("$customConfig");
|
||||
} else {
|
||||
$config = file_get_contents("$defaultConfig");
|
||||
}
|
||||
|
||||
// Subscription link
|
||||
$subsURL = Helper::getSubscribeUrl("/api/v1/client/subscribe?token={$user['token']}");
|
||||
$subsDomain = $_SERVER['HTTP_HOST'];
|
||||
$subsURL = 'https://' . $subsDomain . '/api/v1/client/subscribe?token=' . $user['token'];
|
||||
|
||||
$config = str_replace('$subs_link', $subsURL, $config);
|
||||
$config = str_replace('$subs_domain', $subsDomain, $config);
|
||||
$config = str_replace('$proxies', $proxies, $config);
|
||||
$config = str_replace('$proxy_group', rtrim($proxyGroup, ', '), $config);
|
||||
|
||||
$upload = round($user['u'] / (1024*1024*1024), 2);
|
||||
$download = round($user['d'] / (1024*1024*1024), 2);
|
||||
$useTraffic = $upload + $download;
|
||||
$totalTraffic = round($user['transfer_enable'] / (1024*1024*1024), 2);
|
||||
$expireDate = $user['expired_at'] === NULL ? '长期有效' : date('Y-m-d H:i:s', $user['expired_at']);
|
||||
$subscribeInfo = "title={$appName}订阅信息, content=上传流量:{$upload}GB\\n下载流量:{$download}GB\\n剩余流量:{$useTraffic}GB\\n套餐流量:{$totalTraffic}GB\\n到期时间:{$expireDate}";
|
||||
$config = str_replace('$subscribe_info', $subscribeInfo, $config);
|
||||
|
||||
return $config;
|
||||
}
|
||||
|
||||
|
||||
public static function buildShadowsocks($password, $server)
|
||||
{
|
||||
$config = [
|
||||
"{$server['name']}=ss",
|
||||
"{$server['host']}",
|
||||
"{$server['port']}",
|
||||
"encrypt-method={$server['cipher']}",
|
||||
"password={$password}",
|
||||
'tfo=true',
|
||||
'udp-relay=true'
|
||||
];
|
||||
$config = array_filter($config);
|
||||
$uri = implode(',', $config);
|
||||
$uri .= "\r\n";
|
||||
return $uri;
|
||||
}
|
||||
|
||||
public static function buildVmess($uuid, $server)
|
||||
{
|
||||
$config = [
|
||||
"{$server['name']}=vmess",
|
||||
"{$server['host']}",
|
||||
"{$server['port']}",
|
||||
"username={$uuid}",
|
||||
"vmess-aead=true",
|
||||
'tfo=true',
|
||||
'udp-relay=true'
|
||||
];
|
||||
|
||||
if ($server['tls']) {
|
||||
array_push($config, 'tls=true');
|
||||
if ($server['tlsSettings']) {
|
||||
$tlsSettings = $server['tlsSettings'];
|
||||
if (isset($tlsSettings['allowInsecure']) && !empty($tlsSettings['allowInsecure']))
|
||||
array_push($config, 'skip-cert-verify=' . ($tlsSettings['allowInsecure'] ? 'true' : 'false'));
|
||||
if (isset($tlsSettings['serverName']) && !empty($tlsSettings['serverName']))
|
||||
array_push($config, "sni={$tlsSettings['serverName']}");
|
||||
}
|
||||
}
|
||||
if ($server['network'] === 'ws') {
|
||||
array_push($config, 'ws=true');
|
||||
if ($server['networkSettings']) {
|
||||
$wsSettings = $server['networkSettings'];
|
||||
if (isset($wsSettings['path']) && !empty($wsSettings['path']))
|
||||
array_push($config, "ws-path={$wsSettings['path']}");
|
||||
if (isset($wsSettings['headers']['Host']) && !empty($wsSettings['headers']['Host']))
|
||||
array_push($config, "ws-headers=Host:{$wsSettings['headers']['Host']}");
|
||||
}
|
||||
}
|
||||
|
||||
$uri = implode(',', $config);
|
||||
$uri .= "\r\n";
|
||||
return $uri;
|
||||
}
|
||||
|
||||
public static function buildTrojan($password, $server)
|
||||
{
|
||||
$config = [
|
||||
"{$server['name']}=trojan",
|
||||
"{$server['host']}",
|
||||
"{$server['port']}",
|
||||
"password={$password}",
|
||||
$server['server_name'] ? "sni={$server['server_name']}" : "",
|
||||
'tfo=true',
|
||||
'udp-relay=true'
|
||||
];
|
||||
if (!empty($server['allow_insecure'])) {
|
||||
array_push($config, $server['allow_insecure'] ? 'skip-cert-verify=true' : 'skip-cert-verify=false');
|
||||
}
|
||||
$config = array_filter($config);
|
||||
$uri = implode(',', $config);
|
||||
$uri .= "\r\n";
|
||||
return $uri;
|
||||
}
|
||||
}
|
113
app/Http/Controllers/Client/Protocols/V2rayN.php
Normal file
113
app/Http/Controllers/Client/Protocols/V2rayN.php
Normal file
@ -0,0 +1,113 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Client\Protocols;
|
||||
|
||||
|
||||
use App\Utils\Helper;
|
||||
|
||||
class V2rayN
|
||||
{
|
||||
public $flag = 'v2rayn';
|
||||
private $servers;
|
||||
private $user;
|
||||
|
||||
public function __construct($user, $servers)
|
||||
{
|
||||
$this->user = $user;
|
||||
$this->servers = $servers;
|
||||
}
|
||||
|
||||
public function handle()
|
||||
{
|
||||
$servers = $this->servers;
|
||||
$user = $this->user;
|
||||
$uri = '';
|
||||
|
||||
foreach ($servers as $item) {
|
||||
if ($item['type'] === 'vmess') {
|
||||
$uri .= self::buildVmess($user['uuid'], $item);
|
||||
}
|
||||
if ($item['type'] === 'shadowsocks') {
|
||||
$uri .= self::buildShadowsocks($user['uuid'], $item);
|
||||
}
|
||||
if ($item['type'] === 'trojan') {
|
||||
$uri .= self::buildTrojan($user['uuid'], $item);
|
||||
}
|
||||
}
|
||||
return base64_encode($uri);
|
||||
}
|
||||
|
||||
public static function buildShadowsocks($password, $server)
|
||||
{
|
||||
if ($server['cipher'] === '2022-blake3-aes-128-gcm') {
|
||||
$serverKey = Helper::getServerKey($server['created_at'], 16);
|
||||
$userKey = Helper::uuidToBase64($password, 16);
|
||||
$password = "{$serverKey}:{$userKey}";
|
||||
}
|
||||
if ($server['cipher'] === '2022-blake3-aes-256-gcm') {
|
||||
$serverKey = Helper::getServerKey($server['created_at'], 32);
|
||||
$userKey = Helper::uuidToBase64($password, 32);
|
||||
$password = "{$serverKey}:{$userKey}";
|
||||
}
|
||||
$name = rawurlencode($server['name']);
|
||||
$str = str_replace(
|
||||
['+', '/', '='],
|
||||
['-', '_', ''],
|
||||
base64_encode("{$server['cipher']}:{$password}")
|
||||
);
|
||||
return "ss://{$str}@{$server['host']}:{$server['port']}#{$name}\r\n";
|
||||
}
|
||||
|
||||
public static function buildVmess($uuid, $server)
|
||||
{
|
||||
$config = [
|
||||
"v" => "2",
|
||||
"ps" => $server['name'],
|
||||
"add" => $server['host'],
|
||||
"port" => (string)$server['port'],
|
||||
"id" => $uuid,
|
||||
"aid" => '0',
|
||||
"net" => $server['network'],
|
||||
"type" => "none",
|
||||
"host" => "",
|
||||
"path" => "",
|
||||
"tls" => $server['tls'] ? "tls" : "",
|
||||
];
|
||||
if ($server['tls']) {
|
||||
if ($server['tlsSettings']) {
|
||||
$tlsSettings = $server['tlsSettings'];
|
||||
if (isset($tlsSettings['serverName']) && !empty($tlsSettings['serverName']))
|
||||
$config['sni'] = $tlsSettings['serverName'];
|
||||
}
|
||||
}
|
||||
if ((string)$server['network'] === 'tcp') {
|
||||
$tcpSettings = $server['networkSettings'];
|
||||
if (isset($tcpSettings['header']['type'])) $config['type'] = $tcpSettings['header']['type'];
|
||||
if (isset($tcpSettings['header']['request']['path'][0])) $config['path'] = $tcpSettings['header']['request']['path'][0];
|
||||
}
|
||||
if ((string)$server['network'] === 'ws') {
|
||||
$wsSettings = $server['networkSettings'];
|
||||
if (isset($wsSettings['path'])) $config['path'] = $wsSettings['path'];
|
||||
if (isset($wsSettings['headers']['Host'])) $config['host'] = $wsSettings['headers']['Host'];
|
||||
}
|
||||
if ((string)$server['network'] === 'grpc') {
|
||||
$grpcSettings = $server['networkSettings'];
|
||||
if (isset($grpcSettings['serviceName'])) $config['path'] = $grpcSettings['serviceName'];
|
||||
}
|
||||
return "vmess://" . base64_encode(json_encode($config)) . "\r\n";
|
||||
}
|
||||
|
||||
public static function buildTrojan($password, $server)
|
||||
{
|
||||
$name = rawurlencode($server['name']);
|
||||
$query = http_build_query([
|
||||
'allowInsecure' => $server['allow_insecure'],
|
||||
'peer' => $server['server_name'],
|
||||
'sni' => $server['server_name']
|
||||
]);
|
||||
$uri = "trojan://{$password}@{$server['host']}:{$server['port']}?{$query}#{$name}";
|
||||
$uri .= "\r\n";
|
||||
return $uri;
|
||||
}
|
||||
|
||||
}
|
102
app/Http/Controllers/Client/Protocols/V2rayNG.php
Normal file
102
app/Http/Controllers/Client/Protocols/V2rayNG.php
Normal file
@ -0,0 +1,102 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Client\Protocols;
|
||||
|
||||
|
||||
class V2rayNG
|
||||
{
|
||||
public $flag = 'v2rayng';
|
||||
private $servers;
|
||||
private $user;
|
||||
|
||||
public function __construct($user, $servers)
|
||||
{
|
||||
$this->user = $user;
|
||||
$this->servers = $servers;
|
||||
}
|
||||
|
||||
public function handle()
|
||||
{
|
||||
$servers = $this->servers;
|
||||
$user = $this->user;
|
||||
$uri = '';
|
||||
|
||||
foreach ($servers as $item) {
|
||||
if ($item['type'] === 'vmess') {
|
||||
$uri .= self::buildVmess($user['uuid'], $item);
|
||||
}
|
||||
if ($item['type'] === 'shadowsocks') {
|
||||
$uri .= self::buildShadowsocks($user['uuid'], $item);
|
||||
}
|
||||
if ($item['type'] === 'trojan') {
|
||||
$uri .= self::buildTrojan($user['uuid'], $item);
|
||||
}
|
||||
}
|
||||
return base64_encode($uri);
|
||||
}
|
||||
|
||||
public static function buildShadowsocks($password, $server)
|
||||
{
|
||||
$name = rawurlencode($server['name']);
|
||||
$str = str_replace(
|
||||
['+', '/', '='],
|
||||
['-', '_', ''],
|
||||
base64_encode("{$server['cipher']}:{$password}")
|
||||
);
|
||||
return "ss://{$str}@{$server['host']}:{$server['port']}#{$name}\r\n";
|
||||
}
|
||||
|
||||
public static function buildVmess($uuid, $server)
|
||||
{
|
||||
$config = [
|
||||
"v" => "2",
|
||||
"ps" => $server['name'],
|
||||
"add" => $server['host'],
|
||||
"port" => (string)$server['port'],
|
||||
"id" => $uuid,
|
||||
"aid" => '0',
|
||||
"net" => $server['network'],
|
||||
"type" => "none",
|
||||
"host" => "",
|
||||
"path" => "",
|
||||
"tls" => $server['tls'] ? "tls" : "",
|
||||
];
|
||||
if ($server['tls']) {
|
||||
if ($server['tlsSettings']) {
|
||||
$tlsSettings = $server['tlsSettings'];
|
||||
if (isset($tlsSettings['serverName']) && !empty($tlsSettings['serverName']))
|
||||
$config['sni'] = $tlsSettings['serverName'];
|
||||
}
|
||||
}
|
||||
if ((string)$server['network'] === 'tcp') {
|
||||
$tcpSettings = $server['networkSettings'];
|
||||
if (isset($tcpSettings['header']['type'])) $config['type'] = $tcpSettings['header']['type'];
|
||||
if (isset($tcpSettings['header']['request']['path'][0])) $config['path'] = $tcpSettings['header']['request']['path'][0];
|
||||
}
|
||||
if ((string)$server['network'] === 'ws') {
|
||||
$wsSettings = $server['networkSettings'];
|
||||
if (isset($wsSettings['path'])) $config['path'] = $wsSettings['path'];
|
||||
if (isset($wsSettings['headers']['Host'])) $config['host'] = $wsSettings['headers']['Host'];
|
||||
}
|
||||
if ((string)$server['network'] === 'grpc') {
|
||||
$grpcSettings = $server['networkSettings'];
|
||||
if (isset($grpcSettings['serviceName'])) $config['path'] = $grpcSettings['serviceName'];
|
||||
}
|
||||
return "vmess://" . base64_encode(json_encode($config)) . "\r\n";
|
||||
}
|
||||
|
||||
public static function buildTrojan($password, $server)
|
||||
{
|
||||
$name = rawurlencode($server['name']);
|
||||
$query = http_build_query([
|
||||
'allowInsecure' => $server['allow_insecure'],
|
||||
'peer' => $server['server_name'],
|
||||
'sni' => $server['server_name']
|
||||
]);
|
||||
$uri = "trojan://{$password}@{$server['host']}:{$server['port']}?{$query}#{$name}";
|
||||
$uri .= "\r\n";
|
||||
return $uri;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,121 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\User;
|
||||
use App\Models\Plan;
|
||||
use App\Models\Server;
|
||||
use Symfony\Component\Yaml\Yaml;
|
||||
|
||||
class ClientController extends Controller
|
||||
{
|
||||
public function subscribe (Request $request) {
|
||||
$user = $request->user;
|
||||
$server = [];
|
||||
if ($user->expired_at > time()) {
|
||||
$servers = Server::all();
|
||||
foreach ($servers as $item) {
|
||||
$groupId = json_decode($item['group_id']);
|
||||
if (in_array($user->group_id, $groupId)) {
|
||||
array_push($server, $item);
|
||||
}
|
||||
}
|
||||
}
|
||||
if(strpos($_SERVER['HTTP_USER_AGENT'], 'Quantumult%20X') !== false) {
|
||||
die($this->quantumultX($user, $server));
|
||||
}
|
||||
if(strpos($_SERVER['HTTP_USER_AGENT'], 'Quantumult') !== false) {
|
||||
die($this->quantumult($user, $server));
|
||||
}
|
||||
if(strpos($_SERVER['HTTP_USER_AGENT'], 'clash_win') !== false) {
|
||||
die($this->clash($user, $server));
|
||||
}
|
||||
die($this->origin($user, $server));
|
||||
}
|
||||
|
||||
private function quantumultX ($user, $server) {
|
||||
$uri = '';
|
||||
foreach($server as $item) {
|
||||
$uri .= "vmess=".$item->host.":".$item->port.", method=none, password=".$user->v2ray_uuid.", over-tls=".($item->tls?'true':'false').", certificate=0, fast-open=false, udp-relay=false, tag=".$item->name."\r\n";
|
||||
}
|
||||
return base64_encode($uri);
|
||||
}
|
||||
|
||||
private function quantumult ($user, $server) {
|
||||
$uri = '';
|
||||
header('subscription-userinfo: upload='.$user->u.'; download='.$user->d.';total='.$user->transfer_enable);
|
||||
foreach($server as $item) {
|
||||
$uri .= "vmess://".base64_encode($item->name.'= vmess, '.$item->host.', '.$item->port.', chacha20-ietf-poly1305, "'.$user->v2ray_uuid.'", over-tls='.($item->tls?"true":"false").', certificate=0, group='.config('v2board.app_name', 'V2Board'))."\r\n";
|
||||
}
|
||||
return base64_encode($uri);
|
||||
}
|
||||
|
||||
private function origin ($user, $server) {
|
||||
$uri = '';
|
||||
foreach($server as $item) {
|
||||
$config = [
|
||||
"ps" => $item->name,
|
||||
"add" => $item->host,
|
||||
"port" => $item->port,
|
||||
"id" => $user->v2ray_uuid,
|
||||
"aid" => "2",
|
||||
"net" => "tcp",
|
||||
"type" => "chacha20-poly1305",
|
||||
"host" => "",
|
||||
"tls" => $item->tls?"tls":"",
|
||||
];
|
||||
$uri .= "vmess://".base64_encode(json_encode($config))."\r\n";
|
||||
}
|
||||
return base64_encode($uri);
|
||||
}
|
||||
|
||||
private function clash ($user, $server) {
|
||||
$proxy = [];
|
||||
$proxyGroup = [];
|
||||
$proxies = [];
|
||||
foreach ($server as $item) {
|
||||
$array = [];
|
||||
$array['name'] = $item->name;
|
||||
$array['type'] = 'vmess';
|
||||
$array['server'] = $item->host;
|
||||
$array['port'] = $item->port;
|
||||
$array['uuid'] = $user->v2ray_uuid;
|
||||
$array['alterId'] = $user->v2ray_alter_id;
|
||||
$array['cipher'] = 'auto';
|
||||
if ($item->tls) {
|
||||
$array['tls'] = true;
|
||||
}
|
||||
array_push($proxy, $array);
|
||||
array_push($proxies, $item->name);
|
||||
}
|
||||
array_push($proxyGroup, [
|
||||
'name' => config('v2board.app_name', 'V2Board'),
|
||||
'type' => 'select',
|
||||
'proxies' => $proxies
|
||||
]);
|
||||
|
||||
$config = [
|
||||
'port' => 7890,
|
||||
'socks-port' => 0,
|
||||
'allow-lan' => false,
|
||||
'mode' => 'Rule',
|
||||
'log-level' => 'info',
|
||||
'external-controller' => '0.0.0.0:9090',
|
||||
'secret' => '',
|
||||
'Proxy' => $proxy,
|
||||
'Proxy Group' => $proxyGroup,
|
||||
'Rule' => [
|
||||
'DOMAIN-SUFFIX,google.com,'.config('v2board.app_name', 'V2Board'),
|
||||
'DOMAIN-KEYWORD,google,'.config('v2board.app_name', 'V2Board'),
|
||||
'DOMAIN,google.com,'.config('v2board.app_name', 'V2Board'),
|
||||
'DOMAIN-SUFFIX,ad.com,REJECT',
|
||||
'IP-CIDR,127.0.0.0/8,DIRECT',
|
||||
'GEOIP,CN,DIRECT',
|
||||
'MATCH,'.config('v2board.app_name', 'V2Board')
|
||||
]
|
||||
];
|
||||
return Yaml::dump($config);
|
||||
}
|
||||
}
|
38
app/Http/Controllers/Guest/CommController.php
Normal file
38
app/Http/Controllers/Guest/CommController.php
Normal file
@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Guest;
|
||||
|
||||
use App\Utils\Dict;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
|
||||
class CommController extends Controller
|
||||
{
|
||||
public function config()
|
||||
{
|
||||
return response([
|
||||
'data' => [
|
||||
'tos_url' => config('v2board.tos_url'),
|
||||
'is_email_verify' => (int)config('v2board.email_verify', 0) ? 1 : 0,
|
||||
'is_invite_force' => (int)config('v2board.invite_force', 0) ? 1 : 0,
|
||||
'email_whitelist_suffix' => (int)config('v2board.email_whitelist_enable', 0)
|
||||
? $this->getEmailSuffix()
|
||||
: 0,
|
||||
'is_recaptcha' => (int)config('v2board.recaptcha_enable', 0) ? 1 : 0,
|
||||
'recaptcha_site_key' => config('v2board.recaptcha_site_key'),
|
||||
'app_description' => config('v2board.app_description'),
|
||||
'app_url' => config('v2board.app_url'),
|
||||
'logo' => config('v2board.logo'),
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
||||
private function getEmailSuffix()
|
||||
{
|
||||
$suffix = config('v2board.email_whitelist_suffix', Dict::EMAIL_WHITELIST_SUFFIX_DEFAULT);
|
||||
if (!is_array($suffix)) {
|
||||
return preg_split('/,/', $suffix);
|
||||
}
|
||||
return $suffix;
|
||||
}
|
||||
}
|
@ -1,47 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Guest;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Order;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class OrderController extends Controller
|
||||
{
|
||||
public function stripeNotify (Request $request) {
|
||||
Log::info('stripeNotifyData: ' . json_encode($request->input()));
|
||||
|
||||
\Stripe\Stripe::setApiKey(config('v2board.stripe_sk_live'));
|
||||
try {
|
||||
$event = \Stripe\Webhook::constructEvent(
|
||||
file_get_contents('php://input'),
|
||||
$_SERVER['HTTP_STRIPE_SIGNATURE'],
|
||||
config('v2board.stripe_webhook_key')
|
||||
);
|
||||
} catch (\Stripe\Error\SignatureVerification $e) {
|
||||
abort(400);
|
||||
}
|
||||
|
||||
$obj = $event->data->object;
|
||||
if ($obj['status'] == 'succeeded') {
|
||||
$order = Order::where('callback_no', $obj['source']['id'])->first();
|
||||
if (!$order) {
|
||||
abort(500, 'ERROR');
|
||||
}
|
||||
if ($order->status !== 0) {
|
||||
die('SUCCESS');
|
||||
}
|
||||
$order->status = 1;
|
||||
if (!$order->save()) {
|
||||
abort(500, 'ERROR');
|
||||
}
|
||||
die('SUCCESS');
|
||||
}
|
||||
}
|
||||
|
||||
public function stripeReturn (Request $request) {
|
||||
Log::info('stripeReturnData: ' . json_encode($request->input()));
|
||||
header('Location:' . '/#/dashboard');
|
||||
}
|
||||
}
|
49
app/Http/Controllers/Guest/PaymentController.php
Normal file
49
app/Http/Controllers/Guest/PaymentController.php
Normal file
@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Guest;
|
||||
|
||||
use App\Models\Order;
|
||||
use App\Services\OrderService;
|
||||
use App\Services\PaymentService;
|
||||
use App\Services\TelegramService;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
|
||||
class PaymentController extends Controller
|
||||
{
|
||||
public function notify($method, $uuid, Request $request)
|
||||
{
|
||||
try {
|
||||
$paymentService = new PaymentService($method, null, $uuid);
|
||||
$verify = $paymentService->notify($request->input());
|
||||
if (!$verify) abort(500, 'verify error');
|
||||
if (!$this->handle($verify['trade_no'], $verify['callback_no'])) {
|
||||
abort(500, 'handle error');
|
||||
}
|
||||
die(isset($verify['custom_result']) ? $verify['custom_result'] : 'success');
|
||||
} catch (\Exception $e) {
|
||||
abort(500, 'fail');
|
||||
}
|
||||
}
|
||||
|
||||
private function handle($tradeNo, $callbackNo)
|
||||
{
|
||||
$order = Order::where('trade_no', $tradeNo)->first();
|
||||
if (!$order) {
|
||||
abort(500, 'order is not found');
|
||||
}
|
||||
if ($order->status !== 0) return true;
|
||||
$orderService = new OrderService($order);
|
||||
if (!$orderService->paid($callbackNo)) {
|
||||
return false;
|
||||
}
|
||||
$telegramService = new TelegramService();
|
||||
$message = sprintf(
|
||||
"💰成功收款%s元\n———————————————\n订单号:%s",
|
||||
$order->total_amount / 100,
|
||||
$order->trade_no
|
||||
);
|
||||
$telegramService->sendMessageWithAdmin($message);
|
||||
return true;
|
||||
}
|
||||
}
|
@ -8,7 +8,8 @@ use App\Models\Plan;
|
||||
|
||||
class PlanController extends Controller
|
||||
{
|
||||
public function index (Request $request) {
|
||||
public function fetch(Request $request)
|
||||
{
|
||||
$plan = Plan::where('show', 1)->get();
|
||||
return response([
|
||||
'data' => $plan
|
||||
|
123
app/Http/Controllers/Guest/TelegramController.php
Normal file
123
app/Http/Controllers/Guest/TelegramController.php
Normal file
@ -0,0 +1,123 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Guest;
|
||||
|
||||
use App\Services\TelegramService;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
|
||||
class TelegramController extends Controller
|
||||
{
|
||||
protected $msg;
|
||||
protected $commands = [];
|
||||
protected $telegramService;
|
||||
|
||||
public function __construct(Request $request)
|
||||
{
|
||||
if ($request->input('access_token') !== md5(config('v2board.telegram_bot_token'))) {
|
||||
abort(401);
|
||||
}
|
||||
|
||||
$this->telegramService = new TelegramService();
|
||||
}
|
||||
|
||||
public function webhook(Request $request)
|
||||
{
|
||||
$this->formatMessage($request->input());
|
||||
$this->formatChatJoinRequest($request->input());
|
||||
$this->handle();
|
||||
}
|
||||
|
||||
public function handle()
|
||||
{
|
||||
if (!$this->msg) return;
|
||||
$msg = $this->msg;
|
||||
$commandName = explode('@', $msg->command);
|
||||
|
||||
// To reduce request, only commands contains @ will get the bot name
|
||||
if (count($commandName) == 2) {
|
||||
$botName = $this->getBotName();
|
||||
if ($commandName[1] === $botName){
|
||||
$msg->command = $commandName[0];
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
foreach (glob(base_path('app//Plugins//Telegram//Commands') . '/*.php') as $file) {
|
||||
$command = basename($file, '.php');
|
||||
$class = '\\App\\Plugins\\Telegram\\Commands\\' . $command;
|
||||
if (!class_exists($class)) continue;
|
||||
$instance = new $class();
|
||||
if ($msg->message_type === 'message') {
|
||||
if (!isset($instance->command)) continue;
|
||||
if ($msg->command !== $instance->command) continue;
|
||||
$instance->handle($msg);
|
||||
return;
|
||||
}
|
||||
if ($msg->message_type === 'reply_message') {
|
||||
if (!isset($instance->regex)) continue;
|
||||
if (!preg_match($instance->regex, $msg->reply_text, $match)) continue;
|
||||
$instance->handle($msg, $match);
|
||||
return;
|
||||
}
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
$this->telegramService->sendMessage($msg->chat_id, $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function getBotName()
|
||||
{
|
||||
$response = $this->telegramService->getMe();
|
||||
return $response->result->username;
|
||||
}
|
||||
|
||||
private function formatMessage(array $data)
|
||||
{
|
||||
if (!isset($data['message'])) return;
|
||||
if (!isset($data['message']['text'])) return;
|
||||
$obj = new \StdClass();
|
||||
$text = explode(' ', $data['message']['text']);
|
||||
$obj->command = $text[0];
|
||||
$obj->args = array_slice($text, 1);
|
||||
$obj->chat_id = $data['message']['chat']['id'];
|
||||
$obj->message_id = $data['message']['message_id'];
|
||||
$obj->message_type = 'message';
|
||||
$obj->text = $data['message']['text'];
|
||||
$obj->is_private = $data['message']['chat']['type'] === 'private';
|
||||
if (isset($data['message']['reply_to_message']['text'])) {
|
||||
$obj->message_type = 'reply_message';
|
||||
$obj->reply_text = $data['message']['reply_to_message']['text'];
|
||||
}
|
||||
$this->msg = $obj;
|
||||
}
|
||||
|
||||
private function formatChatJoinRequest(array $data)
|
||||
{
|
||||
if (!isset($data['chat_join_request'])) return;
|
||||
if (!isset($data['chat_join_request']['from']['id'])) return;
|
||||
if (!isset($data['chat_join_request']['chat']['id'])) return;
|
||||
$user = \App\Models\User::where('telegram_id', $data['chat_join_request']['from']['id'])
|
||||
->first();
|
||||
if (!$user) {
|
||||
$this->telegramService->declineChatJoinRequest(
|
||||
$data['chat_join_request']['chat']['id'],
|
||||
$data['chat_join_request']['from']['id']
|
||||
);
|
||||
return;
|
||||
}
|
||||
$userService = new \App\Services\UserService();
|
||||
if (!$userService->isAvailable($user)) {
|
||||
$this->telegramService->declineChatJoinRequest(
|
||||
$data['chat_join_request']['chat']['id'],
|
||||
$data['chat_join_request']['from']['id']
|
||||
);
|
||||
return;
|
||||
}
|
||||
$userService = new \App\Services\UserService();
|
||||
$this->telegramService->approveChatJoinRequest(
|
||||
$data['chat_join_request']['chat']['id'],
|
||||
$data['chat_join_request']['from']['id']
|
||||
);
|
||||
}
|
||||
}
|
@ -1,57 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\User;
|
||||
use App\Models\Order;
|
||||
use App\Models\InviteCode;
|
||||
use App\Utils\Helper;
|
||||
|
||||
class InviteController extends Controller
|
||||
{
|
||||
public function save (Request $request) {
|
||||
if (InviteCode::where('user_id', $request->session()->get('id'))->where('status', 0)->count() >= 5) {
|
||||
abort(500, '已达到创建数量上限');
|
||||
}
|
||||
$inviteCode = new InviteCode();
|
||||
$inviteCode->user_id = $request->session()->get('id');
|
||||
$inviteCode->code = Helper::randomChar(8);
|
||||
return response([
|
||||
'data' => $inviteCode->save()
|
||||
]);
|
||||
}
|
||||
|
||||
public function index (Request $request) {
|
||||
$codes = InviteCode::where('user_id', $request->session()->get('id'))
|
||||
->where('status', 0)
|
||||
->get();
|
||||
for ($i = 0; $i < count($codes); $i++) {
|
||||
$codes[$i]['invite_url'] = config('v2board.app_url', env('APP_URL')) . '/#/register?code=' . $codes[$i]['code'];
|
||||
}
|
||||
$stat = [
|
||||
//已注册用户数
|
||||
(int)User::where('invite_user_id', $request->session()->get('id'))->count(),
|
||||
//有效的佣金
|
||||
(int)Order::where('status', 3)
|
||||
->where('commission_status', 1)
|
||||
->where('invite_user_id', $request->session()->get('id'))
|
||||
->sum('commission_balance'),
|
||||
//确认中的佣金
|
||||
(int)Order::where('status', 3)
|
||||
->where('commission_status', 0)
|
||||
->where('invite_user_id', $request->session()->get('id'))
|
||||
->sum('commission_balance'),
|
||||
//已提现佣金
|
||||
0
|
||||
|
||||
];
|
||||
return response([
|
||||
'data' => [
|
||||
'codes' => $codes,
|
||||
'stat' => $stat
|
||||
]
|
||||
]);
|
||||
}
|
||||
}
|
@ -1,244 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Http\Requests\OrderSave;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Order;
|
||||
use App\Models\Plan;
|
||||
use App\Models\User;
|
||||
use App\Utils\Helper;
|
||||
use Omnipay\Omnipay;
|
||||
use Stripe\Stripe;
|
||||
use Stripe\Source;
|
||||
|
||||
class OrderController extends Controller
|
||||
{
|
||||
public function index (Request $request) {
|
||||
$order = Order::where('user_id', $request->session()->get('id'))
|
||||
->orderBy('created_at', 'DESC')
|
||||
->get();
|
||||
$plan = Plan::get();
|
||||
for($i = 0; $i < count($order); $i++) {
|
||||
for($x = 0; $x < count($plan); $x++) {
|
||||
if ($order[$i]['plan_id'] === $plan[$x]['id']) {
|
||||
$order[$i]['plan'] = $plan[$x];
|
||||
}
|
||||
}
|
||||
}
|
||||
return response([
|
||||
'data' => $order
|
||||
]);
|
||||
}
|
||||
|
||||
public function details (Request $request) {
|
||||
$order = Order::where('user_id', $request->session()->get('id'))
|
||||
->where('trade_no', $request->input('trade_no'))
|
||||
->first();
|
||||
if (!$order) {
|
||||
abort(500, '订单不存在');
|
||||
}
|
||||
$order['plan'] = Plan::find($order->plan_id);
|
||||
if (!$order['plan']) {
|
||||
abort(500, '订阅不存在');
|
||||
}
|
||||
return response([
|
||||
'data' => $order
|
||||
]);
|
||||
}
|
||||
|
||||
public function save (OrderSave $request) {
|
||||
$plan = Plan::find($request->input('plan_id'));
|
||||
$user = User::find($request->session()->get('id'));
|
||||
|
||||
if (!$plan) {
|
||||
abort(500, '该订阅不存在');
|
||||
}
|
||||
|
||||
if (!($plan->show || $user->plan_id == $plan->id)) {
|
||||
abort(500, '该订阅已售罄');
|
||||
}
|
||||
|
||||
if (!$plan->show && !$plan->renew) {
|
||||
abort(500, '该订阅无法续费,请更换其他订阅');
|
||||
}
|
||||
|
||||
$order = new Order();
|
||||
$order->user_id = $request->session()->get('id');
|
||||
$order->plan_id = $plan->id;
|
||||
$order->cycle = $request->input('cycle');
|
||||
$order->trade_no = Helper::guid();
|
||||
$order->total_amount = $plan[$request->input('cycle')];
|
||||
if ($user->invite_user_id) {
|
||||
$order->invite_user_id = $user->invite_user_id;
|
||||
$order->commission_balance = $order->total_amount * (config('v2board.invite_commission', env('DEFAULT_INVITE_COMMISSION')) / 100);
|
||||
}
|
||||
if (!$order->save()) {
|
||||
abort(500, '订单创建失败');
|
||||
}
|
||||
|
||||
return response([
|
||||
'data' => $order->trade_no
|
||||
]);
|
||||
}
|
||||
|
||||
public function checkout (Request $request) {
|
||||
$tradeNo = $request->input('trade_no');
|
||||
$method = $request->input('method');
|
||||
$order = Order::where('trade_no', $tradeNo)
|
||||
->where('user_id', $request->session()->get('id'))
|
||||
->where('status', 0)
|
||||
->first();
|
||||
if (!$order) {
|
||||
abort(500, '订单不存在或以支付');
|
||||
}
|
||||
switch ($method) {
|
||||
// return type => 0: QRCode / 1: URL
|
||||
case 0:
|
||||
// alipayF2F
|
||||
if (!(int)config('v2board.alipay_enable')) {
|
||||
abort(500, '支付方式不可用');
|
||||
}
|
||||
return response([
|
||||
'type' => 0,
|
||||
'data' => $this->alipayF2F($tradeNo, $order->total_amount)
|
||||
]);
|
||||
case 2:
|
||||
// stripeAlipay
|
||||
if (!(int)config('v2board.stripe_alipay_enable')) {
|
||||
abort(500, '支付方式不可用');
|
||||
}
|
||||
return response([
|
||||
'type' => 1,
|
||||
'data' => $this->stripeAlipay($order)
|
||||
]);
|
||||
case 3:
|
||||
// stripeWepay
|
||||
if (!(int)config('v2board.stripe_wepay_enable')) {
|
||||
abort(500, '支付方式不可用');
|
||||
}
|
||||
return response([
|
||||
'type' => 0,
|
||||
'data' => $this->stripeWepay($order)
|
||||
]);
|
||||
default:
|
||||
abort(500, '支付方式不存在');
|
||||
}
|
||||
}
|
||||
|
||||
public function check (Request $request) {
|
||||
$tradeNo = $request->input('trade_no');
|
||||
$order = Order::where('trade_no', $tradeNo)
|
||||
->where('user_id', $request->session()->get('id'))
|
||||
->first();
|
||||
if (!$order) {
|
||||
abort(500, '订单不存在');
|
||||
}
|
||||
return response([
|
||||
'data' => $order->status
|
||||
]);
|
||||
}
|
||||
|
||||
public function getPaymentMethod () {
|
||||
$data = [];
|
||||
if ((int)config('v2board.alipay_enable')) {
|
||||
$alipayF2F = new \StdClass();
|
||||
$alipayF2F->name = '支付宝';
|
||||
$alipayF2F->method = 0;
|
||||
$alipayF2F->icon = 'alipay';
|
||||
array_push($data, $alipayF2F);
|
||||
}
|
||||
|
||||
if ((int)config('v2board.stripe_alipay_enable')) {
|
||||
$stripeAlipay = new \StdClass();
|
||||
$stripeAlipay->name = '支付宝';
|
||||
$stripeAlipay->method = 2;
|
||||
$stripeAlipay->icon = 'alipay';
|
||||
array_push($data, $stripeAlipay);
|
||||
}
|
||||
|
||||
if ((int)config('v2board.stripe_wepay_enable')) {
|
||||
$stripeWepay = new \StdClass();
|
||||
$stripeWepay->name = '微信';
|
||||
$stripeWepay->method = 3;
|
||||
$stripeWepay->icon = 'wechat';
|
||||
array_push($data, $stripeWepay);
|
||||
}
|
||||
|
||||
return response([
|
||||
'data' => $data
|
||||
]);
|
||||
}
|
||||
|
||||
private function alipayF2F ($tradeNo, $totalAmount) {
|
||||
$gateway = Omnipay::create('Alipay_AopF2F');
|
||||
$gateway->setSignType('RSA2'); //RSA/RSA2
|
||||
$gateway->setAppId(config('v2board.alipay_appid'));
|
||||
$gateway->setPrivateKey(config('v2board.alipay_privkey')); // 可以是路径,也可以是密钥内容
|
||||
$gateway->setAlipayPublicKey(config('v2board.alipay_pubkey')); // 可以是路径,也可以是密钥内容
|
||||
$gateway->setNotifyUrl(config('v2board.app_url', env('APP_URL')) . '/api/v1/guest/order/alipayNotify');
|
||||
$request = $gateway->purchase();
|
||||
$request->setBizContent([
|
||||
'subject' => config('v2board.app_name') . ' - 订阅',
|
||||
'out_trade_no' => $tradeNo,
|
||||
'total_amount' => $totalAmount / 100
|
||||
]);
|
||||
/** @var \Omnipay\Alipay\Responses\AopTradePreCreateResponse $response */
|
||||
$response = $request->send();
|
||||
$result = $response->getAlipayResponse();
|
||||
if ($result['code'] !== '10000') {
|
||||
abort(500, $result['sub_msg']);
|
||||
}
|
||||
// 获取收款二维码内容
|
||||
return $response->getQrCode();
|
||||
}
|
||||
|
||||
private function stripeAlipay ($order) {
|
||||
$exchange = Helper::exchange('CNY', 'HKD');
|
||||
if (!$exchange) {
|
||||
abort(500, '货币转换超时,请稍后再试');
|
||||
}
|
||||
Stripe::setApiKey(config('v2board.stripe_sk_live'));
|
||||
$source = Source::create([
|
||||
'amount' => floor($order->total_amount * $exchange),
|
||||
'currency' => 'hkd',
|
||||
'type' => 'alipay',
|
||||
'redirect' => [
|
||||
'return_url' => config('v2board.app_url', env('APP_URL')) . '/api/v1/guest/order/stripeReturn'
|
||||
]
|
||||
]);
|
||||
if (!$source['redirect']['url']) {
|
||||
abort(500, '支付网关请求失败');
|
||||
}
|
||||
$order->callback_no = $source['id'];
|
||||
if (!$order->save()) {
|
||||
abort(500, '订单更新失败');
|
||||
}
|
||||
return $source['redirect']['url'];
|
||||
}
|
||||
|
||||
private function stripeWepay ($order) {
|
||||
$exchange = Helper::exchange('CNY', 'HKD');
|
||||
if (!$exchange) {
|
||||
abort(500, '货币转换超时,请稍后再试');
|
||||
}
|
||||
Stripe::setApiKey(config('v2board.stripe_sk_live'));
|
||||
$source = Source::create([
|
||||
'amount' => floor($order->total_amount * $exchange),
|
||||
'currency' => 'hkd',
|
||||
'type' => 'wechat',
|
||||
'redirect' => [
|
||||
'return_url' => config('v2board.app_url', env('APP_URL')) . '/api/v1/guest/order/stripeReturn'
|
||||
]
|
||||
]);
|
||||
if (!$source['wechat']['qr_code_url']) {
|
||||
abort(500, '支付网关请求失败');
|
||||
}
|
||||
$order->callback_no = $source['id'];
|
||||
if (!$order->save()) {
|
||||
abort(500, '订单更新失败');
|
||||
}
|
||||
return $source['wechat']['qr_code_url'];
|
||||
}
|
||||
}
|
307
app/Http/Controllers/Passport/AuthController.php
Normal file
307
app/Http/Controllers/Passport/AuthController.php
Normal file
@ -0,0 +1,307 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Passport;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Passport\AuthRegister;
|
||||
use App\Http\Requests\Passport\AuthForget;
|
||||
use App\Http\Requests\Passport\AuthLogin;
|
||||
use App\Jobs\SendEmailJob;
|
||||
use App\Services\AuthService;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use App\Models\Plan;
|
||||
use App\Models\User;
|
||||
use App\Models\InviteCode;
|
||||
use App\Utils\Helper;
|
||||
use App\Utils\Dict;
|
||||
use App\Utils\CacheKey;
|
||||
use ReCaptcha\ReCaptcha;
|
||||
|
||||
class AuthController extends Controller
|
||||
{
|
||||
public function loginWithMailLink(Request $request)
|
||||
{
|
||||
if (!(int)config('v2board.login_with_mail_link_enable')) {
|
||||
abort(404);
|
||||
}
|
||||
$params = $request->validate([
|
||||
'email' => 'required|email:strict',
|
||||
'redirect' => 'nullable'
|
||||
]);
|
||||
|
||||
if (Cache::get(CacheKey::get('LAST_SEND_LOGIN_WITH_MAIL_LINK_TIMESTAMP', $params['email']))) {
|
||||
abort(500, __('Sending frequently, please try again later'));
|
||||
}
|
||||
|
||||
$user = User::where('email', $params['email'])->first();
|
||||
if (!$user) {
|
||||
return response([
|
||||
'data' => true
|
||||
]);
|
||||
}
|
||||
|
||||
$code = Helper::guid();
|
||||
$key = CacheKey::get('TEMP_TOKEN', $code);
|
||||
Cache::put($key, $user->id, 300);
|
||||
Cache::put(CacheKey::get('LAST_SEND_LOGIN_WITH_MAIL_LINK_TIMESTAMP', $params['email']), time(), 60);
|
||||
|
||||
|
||||
$redirect = '/#/login?verify=' . $code . '&redirect=' . ($request->input('redirect') ? $request->input('redirect') : 'dashboard');
|
||||
if (config('v2board.app_url')) {
|
||||
$link = config('v2board.app_url') . $redirect;
|
||||
} else {
|
||||
$link = url($redirect);
|
||||
}
|
||||
|
||||
SendEmailJob::dispatch([
|
||||
'email' => $user->email,
|
||||
'subject' => __('Login to :name', [
|
||||
'name' => config('v2board.app_name', 'V2Board')
|
||||
]),
|
||||
'template_name' => 'login',
|
||||
'template_value' => [
|
||||
'name' => config('v2board.app_name', 'V2Board'),
|
||||
'link' => $link,
|
||||
'url' => config('v2board.app_url')
|
||||
]
|
||||
]);
|
||||
|
||||
return response([
|
||||
'data' => $link
|
||||
]);
|
||||
|
||||
}
|
||||
|
||||
public function register(AuthRegister $request)
|
||||
{
|
||||
if ((int)config('v2board.register_limit_by_ip_enable', 0)) {
|
||||
$registerCountByIP = Cache::get(CacheKey::get('REGISTER_IP_RATE_LIMIT', $request->ip())) ?? 0;
|
||||
if ((int)$registerCountByIP >= (int)config('v2board.register_limit_count', 3)) {
|
||||
abort(500, __('Register frequently, please try again after :minute minute', [
|
||||
'minute' => config('v2board.register_limit_expire', 60)
|
||||
]));
|
||||
}
|
||||
}
|
||||
if ((int)config('v2board.recaptcha_enable', 0)) {
|
||||
$recaptcha = new ReCaptcha(config('v2board.recaptcha_key'));
|
||||
$recaptchaResp = $recaptcha->verify($request->input('recaptcha_data'));
|
||||
if (!$recaptchaResp->isSuccess()) {
|
||||
abort(500, __('Invalid code is incorrect'));
|
||||
}
|
||||
}
|
||||
if ((int)config('v2board.email_whitelist_enable', 0)) {
|
||||
if (!Helper::emailSuffixVerify(
|
||||
$request->input('email'),
|
||||
config('v2board.email_whitelist_suffix', Dict::EMAIL_WHITELIST_SUFFIX_DEFAULT))
|
||||
) {
|
||||
abort(500, __('Email suffix is not in the Whitelist'));
|
||||
}
|
||||
}
|
||||
if ((int)config('v2board.email_gmail_limit_enable', 0)) {
|
||||
$prefix = explode('@', $request->input('email'))[0];
|
||||
if (strpos($prefix, '.') !== false || strpos($prefix, '+') !== false) {
|
||||
abort(500, __('Gmail alias is not supported'));
|
||||
}
|
||||
}
|
||||
if ((int)config('v2board.stop_register', 0)) {
|
||||
abort(500, __('Registration has closed'));
|
||||
}
|
||||
if ((int)config('v2board.invite_force', 0)) {
|
||||
if (empty($request->input('invite_code'))) {
|
||||
abort(500, __('You must use the invitation code to register'));
|
||||
}
|
||||
}
|
||||
if ((int)config('v2board.email_verify', 0)) {
|
||||
if (empty($request->input('email_code'))) {
|
||||
abort(500, __('Email verification code cannot be empty'));
|
||||
}
|
||||
if ((string)Cache::get(CacheKey::get('EMAIL_VERIFY_CODE', $request->input('email'))) !== (string)$request->input('email_code')) {
|
||||
abort(500, __('Incorrect email verification code'));
|
||||
}
|
||||
}
|
||||
$email = $request->input('email');
|
||||
$password = $request->input('password');
|
||||
$exist = User::where('email', $email)->first();
|
||||
if ($exist) {
|
||||
abort(500, __('Email already exists'));
|
||||
}
|
||||
$user = new User();
|
||||
$user->email = $email;
|
||||
$user->password = password_hash($password, PASSWORD_DEFAULT);
|
||||
$user->uuid = Helper::guid(true);
|
||||
$user->token = Helper::guid();
|
||||
if ($request->input('invite_code')) {
|
||||
$inviteCode = InviteCode::where('code', $request->input('invite_code'))
|
||||
->where('status', 0)
|
||||
->first();
|
||||
if (!$inviteCode) {
|
||||
if ((int)config('v2board.invite_force', 0)) {
|
||||
abort(500, __('Invalid invitation code'));
|
||||
}
|
||||
} else {
|
||||
$user->invite_user_id = $inviteCode->user_id ? $inviteCode->user_id : null;
|
||||
if (!(int)config('v2board.invite_never_expire', 0)) {
|
||||
$inviteCode->status = 1;
|
||||
$inviteCode->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// try out
|
||||
if ((int)config('v2board.try_out_plan_id', 0)) {
|
||||
$plan = Plan::find(config('v2board.try_out_plan_id'));
|
||||
if ($plan) {
|
||||
$user->transfer_enable = $plan->transfer_enable * 1073741824;
|
||||
$user->plan_id = $plan->id;
|
||||
$user->group_id = $plan->group_id;
|
||||
$user->expired_at = time() + (config('v2board.try_out_hour', 1) * 3600);
|
||||
$user->speed_limit = $plan->speed_limit;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$user->save()) {
|
||||
abort(500, __('Register failed'));
|
||||
}
|
||||
if ((int)config('v2board.email_verify', 0)) {
|
||||
Cache::forget(CacheKey::get('EMAIL_VERIFY_CODE', $request->input('email')));
|
||||
}
|
||||
|
||||
$user->last_login_at = time();
|
||||
$user->save();
|
||||
|
||||
if ((int)config('v2board.register_limit_by_ip_enable', 0)) {
|
||||
Cache::put(
|
||||
CacheKey::get('REGISTER_IP_RATE_LIMIT', $request->ip()),
|
||||
(int)$registerCountByIP + 1,
|
||||
(int)config('v2board.register_limit_expire', 60) * 60
|
||||
);
|
||||
}
|
||||
|
||||
$authService = new AuthService($user);
|
||||
|
||||
return response()->json([
|
||||
'data' => $authService->generateAuthData($request)
|
||||
]);
|
||||
}
|
||||
|
||||
public function login(AuthLogin $request)
|
||||
{
|
||||
$email = $request->input('email');
|
||||
$password = $request->input('password');
|
||||
|
||||
if ((int)config('v2board.password_limit_enable', 1)) {
|
||||
$passwordErrorCount = (int)Cache::get(CacheKey::get('PASSWORD_ERROR_LIMIT', $email), 0);
|
||||
if ($passwordErrorCount >= (int)config('v2board.password_limit_count', 5)) {
|
||||
abort(500, __('There are too many password errors, please try again after :minute minutes.', [
|
||||
'minute' => config('v2board.password_limit_expire', 60)
|
||||
]));
|
||||
}
|
||||
}
|
||||
|
||||
$user = User::where('email', $email)->first();
|
||||
if (!$user) {
|
||||
abort(500, __('Incorrect email or password'));
|
||||
}
|
||||
if (!Helper::multiPasswordVerify(
|
||||
$user->password_algo,
|
||||
$user->password_salt,
|
||||
$password,
|
||||
$user->password)
|
||||
) {
|
||||
if ((int)config('v2board.password_limit_enable')) {
|
||||
Cache::put(
|
||||
CacheKey::get('PASSWORD_ERROR_LIMIT', $email),
|
||||
(int)$passwordErrorCount + 1,
|
||||
60 * (int)config('v2board.password_limit_expire', 60)
|
||||
);
|
||||
}
|
||||
abort(500, __('Incorrect email or password'));
|
||||
}
|
||||
|
||||
if ($user->banned) {
|
||||
abort(500, __('Your account has been suspended'));
|
||||
}
|
||||
|
||||
$authService = new AuthService($user);
|
||||
return response([
|
||||
'data' => $authService->generateAuthData($request)
|
||||
]);
|
||||
}
|
||||
|
||||
public function token2Login(Request $request)
|
||||
{
|
||||
if ($request->input('token')) {
|
||||
$redirect = '/#/login?verify=' . $request->input('token') . '&redirect=' . ($request->input('redirect') ? $request->input('redirect') : 'dashboard');
|
||||
if (config('v2board.app_url')) {
|
||||
$location = config('v2board.app_url') . $redirect;
|
||||
} else {
|
||||
$location = url($redirect);
|
||||
}
|
||||
return redirect()->to($location)->send();
|
||||
}
|
||||
|
||||
if ($request->input('verify')) {
|
||||
$key = CacheKey::get('TEMP_TOKEN', $request->input('verify'));
|
||||
$userId = Cache::get($key);
|
||||
if (!$userId) {
|
||||
abort(500, __('Token error'));
|
||||
}
|
||||
$user = User::find($userId);
|
||||
if (!$user) {
|
||||
abort(500, __('The user does not '));
|
||||
}
|
||||
if ($user->banned) {
|
||||
abort(500, __('Your account has been suspended'));
|
||||
}
|
||||
Cache::forget($key);
|
||||
$authService = new AuthService($user);
|
||||
return response([
|
||||
'data' => $authService->generateAuthData($request)
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
public function getQuickLoginUrl(Request $request)
|
||||
{
|
||||
$authorization = $request->input('auth_data') ?? $request->header('authorization');
|
||||
if (!$authorization) abort(403, '未登录或登陆已过期');
|
||||
|
||||
$user = AuthService::decryptAuthData($authorization);
|
||||
if (!$user) abort(403, '未登录或登陆已过期');
|
||||
|
||||
$code = Helper::guid();
|
||||
$key = CacheKey::get('TEMP_TOKEN', $code);
|
||||
Cache::put($key, $user['id'], 60);
|
||||
$redirect = '/#/login?verify=' . $code . '&redirect=' . ($request->input('redirect') ? $request->input('redirect') : 'dashboard');
|
||||
if (config('v2board.app_url')) {
|
||||
$url = config('v2board.app_url') . $redirect;
|
||||
} else {
|
||||
$url = url($redirect);
|
||||
}
|
||||
return response([
|
||||
'data' => $url
|
||||
]);
|
||||
}
|
||||
|
||||
public function forget(AuthForget $request)
|
||||
{
|
||||
if ((string)Cache::get(CacheKey::get('EMAIL_VERIFY_CODE', $request->input('email'))) !== (string)$request->input('email_code')) {
|
||||
abort(500, __('Incorrect email verification code'));
|
||||
}
|
||||
$user = User::where('email', $request->input('email'))->first();
|
||||
if (!$user) {
|
||||
abort(500, __('This email is not registered in the system'));
|
||||
}
|
||||
$user->password = password_hash($request->input('password'), PASSWORD_DEFAULT);
|
||||
$user->password_algo = NULL;
|
||||
$user->password_salt = NULL;
|
||||
if (!$user->save()) {
|
||||
abort(500, __('Reset failed'));
|
||||
}
|
||||
Cache::forget(CacheKey::get('EMAIL_VERIFY_CODE', $request->input('email')));
|
||||
return response([
|
||||
'data' => true
|
||||
]);
|
||||
}
|
||||
}
|
@ -7,43 +7,76 @@ use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Exceptions\HttpResponseException;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Illuminate\Support\Facades\Redis;
|
||||
use App\Utils\Helper;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use App\Jobs\SendEmailJob;
|
||||
use App\Models\InviteCode;
|
||||
use App\Utils\Dict;
|
||||
use App\Utils\CacheKey;
|
||||
use ReCaptcha\ReCaptcha;
|
||||
|
||||
class CommController extends Controller
|
||||
{
|
||||
public function isEmailVerify () {
|
||||
private function isEmailVerify()
|
||||
{
|
||||
return response([
|
||||
'data' => (int)config('v2board.email_verify', env('DEFAULT_EMAIL_VERIFY')) ? 1 : 0
|
||||
'data' => (int)config('v2board.email_verify', 0) ? 1 : 0
|
||||
]);
|
||||
}
|
||||
|
||||
public function sendEmailVerify (CommSendEmailVerify $request) {
|
||||
public function sendEmailVerify(CommSendEmailVerify $request)
|
||||
{
|
||||
if ((int)config('v2board.recaptcha_enable', 0)) {
|
||||
$recaptcha = new ReCaptcha(config('v2board.recaptcha_key'));
|
||||
$recaptchaResp = $recaptcha->verify($request->input('recaptcha_data'));
|
||||
if (!$recaptchaResp->isSuccess()) {
|
||||
abort(500, __('Invalid code is incorrect'));
|
||||
}
|
||||
}
|
||||
$email = $request->input('email');
|
||||
$redisKey = 'sendEmailVerify:' . $email;
|
||||
if (Redis::get($redisKey)) {
|
||||
abort(500, '验证码已发送,请过一会在请求');
|
||||
if (Cache::get(CacheKey::get('LAST_SEND_EMAIL_VERIFY_TIMESTAMP', $email))) {
|
||||
abort(500, __('Email verification code has been sent, please request again later'));
|
||||
}
|
||||
$code = rand(100000, 999999);
|
||||
$subject = config('v2board.app_name', 'V2Panel') . '邮箱验证码';
|
||||
Mail::send(
|
||||
'mail.sendEmailVerify',
|
||||
[
|
||||
'code' => $code,
|
||||
'name' => config('v2board.app_name', 'V2Panel')
|
||||
],
|
||||
function ($message) use($email, $subject) {
|
||||
$message->to($email)->subject($subject);
|
||||
}
|
||||
);
|
||||
if (count(Mail::failures()) >= 1) {
|
||||
// 发送失败
|
||||
abort(500, '发送失败');
|
||||
}
|
||||
$subject = config('v2board.app_name', 'V2Board') . __('Email verification code');
|
||||
|
||||
Redis::set($redisKey, $code);
|
||||
Redis::expire($redisKey, 600);
|
||||
SendEmailJob::dispatch([
|
||||
'email' => $email,
|
||||
'subject' => $subject,
|
||||
'template_name' => 'verify',
|
||||
'template_value' => [
|
||||
'name' => config('v2board.app_name', 'V2Board'),
|
||||
'code' => $code,
|
||||
'url' => config('v2board.app_url')
|
||||
]
|
||||
]);
|
||||
|
||||
Cache::put(CacheKey::get('EMAIL_VERIFY_CODE', $email), $code, 300);
|
||||
Cache::put(CacheKey::get('LAST_SEND_EMAIL_VERIFY_TIMESTAMP', $email), time(), 60);
|
||||
return response([
|
||||
'data' => true
|
||||
]);
|
||||
}
|
||||
|
||||
public function pv(Request $request)
|
||||
{
|
||||
$inviteCode = InviteCode::where('code', $request->input('invite_code'))->first();
|
||||
if ($inviteCode) {
|
||||
$inviteCode->pv = $inviteCode->pv + 1;
|
||||
$inviteCode->save();
|
||||
}
|
||||
|
||||
return response([
|
||||
'data' => true
|
||||
]);
|
||||
}
|
||||
|
||||
private function getEmailSuffix()
|
||||
{
|
||||
$suffix = config('v2board.email_whitelist_suffix', Dict::EMAIL_WHITELIST_SUFFIX_DEFAULT);
|
||||
if (!is_array($suffix)) {
|
||||
return preg_split('/,/', $suffix);
|
||||
}
|
||||
return $suffix;
|
||||
}
|
||||
}
|
||||
|
@ -1,29 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Passport;
|
||||
|
||||
use App\Http\Requests\Passport\ForgetIndex;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Illuminate\Support\Facades\Redis;
|
||||
|
||||
class ForgetController extends Controller
|
||||
{
|
||||
public function index (ForgetIndex $request) {
|
||||
$redisKey = 'sendEmailVerify:' . $request->input('email');
|
||||
if (Redis::get($redisKey) !== $request->input('email_code')) {
|
||||
abort(500, '邮箱验证码有误');
|
||||
}
|
||||
$user = User::where('email', $request->input('email'))->first();
|
||||
$user->password = password_hash($request->input('password'), PASSWORD_DEFAULT);
|
||||
if (!$user->save()) {
|
||||
abort(500, '重置失败');
|
||||
}
|
||||
Redis::del($redisKey);
|
||||
return response([
|
||||
'data' => true
|
||||
]);
|
||||
}
|
||||
}
|
@ -1,33 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Passport;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Requests\Passport\LoginIndex;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\User;
|
||||
|
||||
class LoginController extends Controller
|
||||
{
|
||||
public function index (LoginIndex $request) {
|
||||
$email = $request->input('email');
|
||||
$password = $request->input('password');
|
||||
|
||||
$user = User::where('email', $email)->first();
|
||||
if (!$user) {
|
||||
abort(500, '用户名或密码错误');
|
||||
}
|
||||
if (!password_verify($password, $user->password)) {
|
||||
abort(500, '用户名或密码错误');
|
||||
}
|
||||
|
||||
$request->session()->put('email', $user->email);
|
||||
$request->session()->put('id', $user->id);
|
||||
if ($user->is_admin) {
|
||||
$request->session()->put('is_admin', true);
|
||||
}
|
||||
return response([
|
||||
'data' => true
|
||||
]);
|
||||
}
|
||||
}
|
@ -1,71 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Passport;
|
||||
|
||||
use App\Http\Requests\Passport\RegisterIndex;
|
||||
use App\Http\Requests\Passport\RegisterSendEmailVerify;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\Exceptions\HttpResponseException;
|
||||
use Illuminate\Support\Facades\Redis;
|
||||
use App\Utils\Helper;
|
||||
use App\Models\InviteCode;
|
||||
|
||||
class RegisterController extends Controller
|
||||
{
|
||||
public function index (RegisterIndex $request) {
|
||||
if ((int)config('v2board.stop_register', env('DEFAULT_STOP_REGISTER'))) {
|
||||
abort(500, '本站已关闭注册');
|
||||
}
|
||||
if ((int)config('v2board.invite_force', env('DEFAULT_INVITE_FOCE'))) {
|
||||
if (empty($request->input('invite_code'))) {
|
||||
abort(500, '必须使用邀请码才可以注册');
|
||||
}
|
||||
}
|
||||
if ((int)config('v2board.email_verify', env('DEFAULT_EMAIL_VERIFY'))) {
|
||||
$redisKey = 'sendEmailVerify:' . $request->input('email');
|
||||
if (empty($request->input('email_code'))) {
|
||||
abort(500, '邮箱验证码不能为空');
|
||||
}
|
||||
if (Redis::get($redisKey) !== $request->input('email_code')) {
|
||||
abort(500, '邮箱验证码有误');
|
||||
}
|
||||
}
|
||||
$email = $request->input('email');
|
||||
$password = $request->input('password');
|
||||
$exist = User::where('email', $email)->first();
|
||||
if ($exist) {
|
||||
abort(500, '邮箱已存在系统中');
|
||||
}
|
||||
$user = new User();
|
||||
$user->email = $email;
|
||||
$user->password = password_hash($password, PASSWORD_DEFAULT);
|
||||
$user->last_login_at = time();
|
||||
$user->v2ray_uuid = Helper::guid(true);
|
||||
$user->token = Helper::guid();
|
||||
if ($request->input('invite_code')) {
|
||||
$inviteCode = InviteCode::where('code', $request->input('invite_code'))
|
||||
->where('status', 0)
|
||||
->first();
|
||||
if (!$inviteCode) {
|
||||
if ((int)config('v2board.invite_force', env('DEFAULT_INVITE_FOCE'))) {
|
||||
abort(500, '邀请码无效');
|
||||
}
|
||||
}
|
||||
$user->invite_user_id = $inviteCode->user_id ? $inviteCode->user_id : null;
|
||||
$inviteCode->status = 1;
|
||||
$inviteCode->save();
|
||||
}
|
||||
|
||||
if (!$user->save()) {
|
||||
abort(500, '注册失败');
|
||||
}
|
||||
if ((int)config('v2board.email_verify', env('DEFAULT_EMAIL_VERIFY'))) {
|
||||
Redis::del($redisKey);
|
||||
}
|
||||
return response()->json([
|
||||
'data' => true
|
||||
]);
|
||||
}
|
||||
}
|
@ -1,25 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Plan;
|
||||
use App\Models\User;
|
||||
|
||||
class PlanController extends Controller
|
||||
{
|
||||
public function info (Request $request) {
|
||||
if (empty($request->input('plan_id'))) {
|
||||
abort(500, '参数错误');
|
||||
}
|
||||
$plan = Plan::find($request->input('plan_id'));
|
||||
if (!$plan) {
|
||||
abort(500, '该订阅不存在');
|
||||
}
|
||||
$user = User::find($request->session()->get('id'));
|
||||
return response([
|
||||
'data' => $plan
|
||||
]);
|
||||
}
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Server;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller as BaseController;
|
||||
|
||||
class Controller extends BaseController
|
||||
{
|
||||
public function __construct(Request $request) {
|
||||
$token = $request->input('token');
|
||||
if (empty($token)) {
|
||||
abort(500, 'token is null');
|
||||
}
|
||||
if ($token !== config('v2board.server_token')) {
|
||||
abort(500, 'token is error');
|
||||
}
|
||||
}
|
||||
}
|
@ -2,83 +2,92 @@
|
||||
|
||||
namespace App\Http\Controllers\Server;
|
||||
|
||||
use App\Services\ServerService;
|
||||
use App\Services\StatisticalService;
|
||||
use App\Services\UserService;
|
||||
use App\Utils\CacheKey;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Server\Controller;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\User;
|
||||
use App\Models\Plan;
|
||||
use App\Models\Server;
|
||||
use App\Models\ServerVmess;
|
||||
use App\Models\ServerLog;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
/*
|
||||
* V2ray Aurora
|
||||
* Github: https://github.com/tokumeikoi/aurora
|
||||
*/
|
||||
class DeepbworkController extends Controller
|
||||
{
|
||||
CONST SERVER_CONFIG = '{"api":{"services":["HandlerService","StatsService"],"tag":"api"},"stats":{},"inbound":{"port":443,"protocol":"vmess","settings":{"clients":[]},"streamSettings":{"network":"tcp"},"tag":"proxy"},"inboundDetour":[{"listen":"0.0.0.0","port":23333,"protocol":"dokodemo-door","settings":{"address":"0.0.0.0"},"tag":"api"}],"log":{"loglevel":"debug","access":"access.log","error":"error.log"},"outbound":{"protocol":"freedom","settings":{}},"routing":{"settings":{"rules":[{"inboundTag":["api"],"outboundTag":"api","type":"field"}]},"strategy":"rules"},"policy":{"levels":{"0":{"handshake":4,"connIdle":300,"uplinkOnly":5,"downlinkOnly":30,"statsUserUplink":true,"statsUserDownlink":true}}}}';
|
||||
CONST V2RAY_CONFIG = '{"log":{"loglevel":"debug","access":"access.log","error":"error.log"},"api":{"services":["HandlerService","StatsService"],"tag":"api"},"dns":{},"stats":{},"inbounds":[{"port":443,"protocol":"vmess","settings":{"clients":[]},"sniffing":{"enabled":true,"destOverride":["http","tls"]},"streamSettings":{"network":"tcp"},"tag":"proxy"},{"listen":"127.0.0.1","port":23333,"protocol":"dokodemo-door","settings":{"address":"0.0.0.0"},"tag":"api"}],"outbounds":[{"protocol":"freedom","settings":{}},{"protocol":"blackhole","settings":{},"tag":"block"}],"routing":{"rules":[{"type":"field","inboundTag":"api","outboundTag":"api"}]},"policy":{"levels":{"0":{"handshake":4,"connIdle":300,"uplinkOnly":5,"downlinkOnly":30,"statsUserUplink":true,"statsUserDownlink":true}}}}';
|
||||
public function __construct(Request $request)
|
||||
{
|
||||
$token = $request->input('token');
|
||||
if (empty($token)) {
|
||||
abort(500, 'token is null');
|
||||
}
|
||||
if ($token !== config('v2board.server_token')) {
|
||||
abort(500, 'token is error');
|
||||
}
|
||||
}
|
||||
|
||||
// 后端获取用户
|
||||
public function user (Request $request) {
|
||||
public function user(Request $request)
|
||||
{
|
||||
ini_set('memory_limit', -1);
|
||||
$nodeId = $request->input('node_id');
|
||||
$server = Server::find($nodeId);
|
||||
$users = User::whereIn('group_id', json_decode($server->group_id))
|
||||
->select([
|
||||
'id',
|
||||
'email',
|
||||
't',
|
||||
'u',
|
||||
'd',
|
||||
'transfer_enable',
|
||||
'enable',
|
||||
'v2ray_uuid',
|
||||
'v2ray_alter_id',
|
||||
'v2ray_level'
|
||||
])
|
||||
->get();
|
||||
$server = ServerVmess::find($nodeId);
|
||||
if (!$server) {
|
||||
abort(500, 'fail');
|
||||
}
|
||||
Cache::put(CacheKey::get('SERVER_VMESS_LAST_CHECK_AT', $server->id), time(), 3600);
|
||||
$serverService = new ServerService();
|
||||
$users = $serverService->getAvailableUsers($server->group_id);
|
||||
$result = [];
|
||||
foreach ($users as $user) {
|
||||
$user->v2ray_user = [
|
||||
"uuid" => $user->v2ray_uuid,
|
||||
"email" => sprintf("%s@v2panel.user", $user->v2ray_uuid),
|
||||
"alter_id" => $user->v2ray_alter_id,
|
||||
"level" => $user->v2ray_level,
|
||||
"uuid" => $user->uuid,
|
||||
"email" => sprintf("%s@v2board.user", $user->uuid),
|
||||
"alter_id" => 0,
|
||||
"level" => 0,
|
||||
];
|
||||
unset($user['v2ray_uuid']);
|
||||
unset($user['v2ray_alter_id']);
|
||||
unset($user['v2ray_level']);
|
||||
unset($user['uuid']);
|
||||
array_push($result, $user);
|
||||
}
|
||||
$eTag = sha1(json_encode($result));
|
||||
if (strpos($request->header('If-None-Match'), $eTag) !== false ) {
|
||||
abort(304);
|
||||
}
|
||||
return response([
|
||||
'msg' => 'ok',
|
||||
'data' => $result,
|
||||
]);
|
||||
])->header('ETag', "\"{$eTag}\"");
|
||||
}
|
||||
|
||||
// 后端提交数据
|
||||
public function submit (Request $request) {
|
||||
Log::info('serverSubmitData:' . $request->input('node_id') . ':' . file_get_contents('php://input'));
|
||||
$server = Server::find($request->input('node_id'));
|
||||
public function submit(Request $request)
|
||||
{
|
||||
// Log::info('serverSubmitData:' . $request->input('node_id') . ':' . file_get_contents('php://input'));
|
||||
$server = ServerVmess::find($request->input('node_id'));
|
||||
if (!$server) {
|
||||
return response([
|
||||
'ret' => 1,
|
||||
'msg' => 'ok'
|
||||
'ret' => 0,
|
||||
'msg' => 'server is not found'
|
||||
]);
|
||||
}
|
||||
$data = file_get_contents('php://input');
|
||||
$data = json_decode($data, true);
|
||||
foreach ($data as $item) {
|
||||
$u = $item['u'] * $server->rate;
|
||||
$d = $item['d'] * $server->rate;
|
||||
$user = User::find($item['user_id']);
|
||||
$user->t = time();
|
||||
$user->u = $user->u + $u;
|
||||
$user->d = $user->d + $d;
|
||||
$user->save();
|
||||
Cache::put(CacheKey::get('SERVER_VMESS_ONLINE_USER', $server->id), count($data), 3600);
|
||||
Cache::put(CacheKey::get('SERVER_VMESS_LAST_PUSH_AT', $server->id), time(), 3600);
|
||||
$userService = new UserService();
|
||||
$formatData = [];
|
||||
|
||||
$serverLog = new ServerLog();
|
||||
$serverLog->user_id = $item['user_id'];
|
||||
$serverLog->node_id = $request->input('node_id');
|
||||
$serverLog->u = $item['u'];
|
||||
$serverLog->d = $item['d'];
|
||||
$serverLog->rate = $server->rate;
|
||||
$serverLog->save();
|
||||
foreach ($data as $item) {
|
||||
$formatData[$item['user_id']] = [$item['u'], $item['d']];
|
||||
}
|
||||
$userService->trafficFetch($server->toArray(), 'vmess', $formatData);
|
||||
|
||||
return response([
|
||||
'ret' => 1,
|
||||
@ -87,19 +96,140 @@ class DeepbworkController extends Controller
|
||||
}
|
||||
|
||||
// 后端获取配置
|
||||
public function config (Request $request) {
|
||||
public function config(Request $request)
|
||||
{
|
||||
$nodeId = $request->input('node_id');
|
||||
$localPort = $request->input('local_port');
|
||||
$server = Server::find($nodeId);
|
||||
$jsonData = json_decode(self::SERVER_CONFIG);
|
||||
$jsonData->inboundDetour[0]->port = (int)$localPort;
|
||||
$jsonData->inbound->port = (int)$server->server_port;
|
||||
if ((int)$server->tls) {
|
||||
$jsonData->inbound->streamSettings->security = "tls";
|
||||
$tls = (object) array("certificateFile" => "/home/v2ray.crt", "keyFile" => "/home/v2ray.key");
|
||||
$jsonData->inbound->streamSettings->tlsSettings->certificates[0] = $tls;
|
||||
if (empty($nodeId) || empty($localPort)) {
|
||||
abort(500, '参数错误');
|
||||
}
|
||||
try {
|
||||
$json = $this->getV2RayConfig($nodeId, $localPort);
|
||||
} catch (\Exception $e) {
|
||||
abort(500, $e->getMessage());
|
||||
}
|
||||
|
||||
die(json_encode($jsonData, JSON_UNESCAPED_UNICODE));
|
||||
die(json_encode($json, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
|
||||
private function getV2RayConfig(int $nodeId, int $localPort)
|
||||
{
|
||||
$server = ServerVmess::find($nodeId);
|
||||
if (!$server) {
|
||||
abort(500, '节点不存在');
|
||||
}
|
||||
$json = json_decode(self::V2RAY_CONFIG);
|
||||
$json->log->loglevel = (int)config('v2board.server_log_enable') ? 'debug' : 'none';
|
||||
$json->inbounds[1]->port = (int)$localPort;
|
||||
$json->inbounds[0]->port = (int)$server->server_port;
|
||||
$json->inbounds[0]->streamSettings->network = $server->network;
|
||||
$this->setDns($server, $json);
|
||||
$this->setNetwork($server, $json);
|
||||
$this->setRule($server, $json);
|
||||
$this->setTls($server, $json);
|
||||
|
||||
return $json;
|
||||
}
|
||||
|
||||
private function setDns(ServerVmess $server, object $json)
|
||||
{
|
||||
if ($server->dnsSettings) {
|
||||
$dns = $server->dnsSettings;
|
||||
if (isset($dns->servers)) {
|
||||
array_push($dns->servers, '1.1.1.1');
|
||||
array_push($dns->servers, 'localhost');
|
||||
}
|
||||
$json->dns = $dns;
|
||||
$json->outbounds[0]->settings->domainStrategy = 'UseIP';
|
||||
}
|
||||
}
|
||||
|
||||
private function setNetwork(ServerVmess $server, object $json)
|
||||
{
|
||||
if ($server->networkSettings) {
|
||||
switch ($server->network) {
|
||||
case 'tcp':
|
||||
$json->inbounds[0]->streamSettings->tcpSettings = $server->networkSettings;
|
||||
break;
|
||||
case 'kcp':
|
||||
$json->inbounds[0]->streamSettings->kcpSettings = $server->networkSettings;
|
||||
break;
|
||||
case 'ws':
|
||||
$json->inbounds[0]->streamSettings->wsSettings = $server->networkSettings;
|
||||
break;
|
||||
case 'http':
|
||||
$json->inbounds[0]->streamSettings->httpSettings = $server->networkSettings;
|
||||
break;
|
||||
case 'domainsocket':
|
||||
$json->inbounds[0]->streamSettings->dsSettings = $server->networkSettings;
|
||||
break;
|
||||
case 'quic':
|
||||
$json->inbounds[0]->streamSettings->quicSettings = $server->networkSettings;
|
||||
break;
|
||||
case 'grpc':
|
||||
$json->inbounds[0]->streamSettings->grpcSettings = $server->networkSettings;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function setRule(ServerVmess $server, object $json)
|
||||
{
|
||||
$domainRules = array_filter(explode(PHP_EOL, config('v2board.server_v2ray_domain')));
|
||||
$protocolRules = array_filter(explode(PHP_EOL, config('v2board.server_v2ray_protocol')));
|
||||
if ($server->ruleSettings) {
|
||||
$ruleSettings = $server->ruleSettings;
|
||||
// domain
|
||||
if (isset($ruleSettings->domain)) {
|
||||
$ruleSettings->domain = array_filter($ruleSettings->domain);
|
||||
if (!empty($ruleSettings->domain)) {
|
||||
$domainRules = array_merge($domainRules, $ruleSettings->domain);
|
||||
}
|
||||
}
|
||||
// protocol
|
||||
if (isset($ruleSettings->protocol)) {
|
||||
$ruleSettings->protocol = array_filter($ruleSettings->protocol);
|
||||
if (!empty($ruleSettings->protocol)) {
|
||||
$protocolRules = array_merge($protocolRules, $ruleSettings->protocol);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!empty($domainRules)) {
|
||||
$domainObj = new \StdClass();
|
||||
$domainObj->type = 'field';
|
||||
$domainObj->domain = $domainRules;
|
||||
$domainObj->outboundTag = 'block';
|
||||
array_push($json->routing->rules, $domainObj);
|
||||
}
|
||||
if (!empty($protocolRules)) {
|
||||
$protocolObj = new \StdClass();
|
||||
$protocolObj->type = 'field';
|
||||
$protocolObj->protocol = $protocolRules;
|
||||
$protocolObj->outboundTag = 'block';
|
||||
array_push($json->routing->rules, $protocolObj);
|
||||
}
|
||||
if (empty($domainRules) && empty($protocolRules)) {
|
||||
$json->inbounds[0]->sniffing->enabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
private function setTls(ServerVMess $server, object $json)
|
||||
{
|
||||
if ((int)$server->tls) {
|
||||
$tlsSettings = $server->tlsSettings;
|
||||
$json->inbounds[0]->streamSettings->security = 'tls';
|
||||
$tls = (object)[
|
||||
'certificateFile' => '/root/.cert/server.crt',
|
||||
'keyFile' => '/root/.cert/server.key'
|
||||
];
|
||||
$json->inbounds[0]->streamSettings->tlsSettings = new \StdClass();
|
||||
if (isset($tlsSettings->serverName)) {
|
||||
$json->inbounds[0]->streamSettings->tlsSettings->serverName = (string)$tlsSettings->serverName;
|
||||
}
|
||||
if (isset($tlsSettings->allowInsecure)) {
|
||||
$json->inbounds[0]->streamSettings->tlsSettings->allowInsecure = (int)$tlsSettings->allowInsecure ? true : false;
|
||||
}
|
||||
$json->inbounds[0]->streamSettings->tlsSettings->certificates[0] = $tls;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
89
app/Http/Controllers/Server/ShadowsocksTidalabController.php
Normal file
89
app/Http/Controllers/Server/ShadowsocksTidalabController.php
Normal file
@ -0,0 +1,89 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Server;
|
||||
|
||||
use App\Models\ServerShadowsocks;
|
||||
use App\Services\ServerService;
|
||||
use App\Services\StatisticalService;
|
||||
use App\Services\UserService;
|
||||
use App\Utils\CacheKey;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
/*
|
||||
* Tidal Lab Shadowsocks
|
||||
* Github: https://github.com/tokumeikoi/tidalab-ss
|
||||
*/
|
||||
class ShadowsocksTidalabController extends Controller
|
||||
{
|
||||
public function __construct(Request $request)
|
||||
{
|
||||
$token = $request->input('token');
|
||||
if (empty($token)) {
|
||||
abort(500, 'token is null');
|
||||
}
|
||||
if ($token !== config('v2board.server_token')) {
|
||||
abort(500, 'token is error');
|
||||
}
|
||||
}
|
||||
|
||||
// 后端获取用户
|
||||
public function user(Request $request)
|
||||
{
|
||||
ini_set('memory_limit', -1);
|
||||
$nodeId = $request->input('node_id');
|
||||
$server = ServerShadowsocks::find($nodeId);
|
||||
if (!$server) {
|
||||
abort(500, 'fail');
|
||||
}
|
||||
Cache::put(CacheKey::get('SERVER_SHADOWSOCKS_LAST_CHECK_AT', $server->id), time(), 3600);
|
||||
$serverService = new ServerService();
|
||||
$users = $serverService->getAvailableUsers($server->group_id);
|
||||
$result = [];
|
||||
foreach ($users as $user) {
|
||||
array_push($result, [
|
||||
'id' => $user->id,
|
||||
'port' => $server->server_port,
|
||||
'cipher' => $server->cipher,
|
||||
'secret' => $user->uuid
|
||||
]);
|
||||
}
|
||||
$eTag = sha1(json_encode($result));
|
||||
if (strpos($request->header('If-None-Match'), $eTag) !== false ) {
|
||||
abort(304);
|
||||
}
|
||||
return response([
|
||||
'data' => $result
|
||||
])->header('ETag', "\"{$eTag}\"");
|
||||
}
|
||||
|
||||
// 后端提交数据
|
||||
public function submit(Request $request)
|
||||
{
|
||||
// Log::info('serverSubmitData:' . $request->input('node_id') . ':' . file_get_contents('php://input'));
|
||||
$server = ServerShadowsocks::find($request->input('node_id'));
|
||||
if (!$server) {
|
||||
return response([
|
||||
'ret' => 0,
|
||||
'msg' => 'server is not found'
|
||||
]);
|
||||
}
|
||||
$data = file_get_contents('php://input');
|
||||
$data = json_decode($data, true);
|
||||
Cache::put(CacheKey::get('SERVER_SHADOWSOCKS_ONLINE_USER', $server->id), count($data), 3600);
|
||||
Cache::put(CacheKey::get('SERVER_SHADOWSOCKS_LAST_PUSH_AT', $server->id), time(), 3600);
|
||||
$userService = new UserService();
|
||||
$formatData = [];
|
||||
|
||||
foreach ($data as $item) {
|
||||
$formatData[$item['user_id']] = [$item['u'], $item['d']];
|
||||
}
|
||||
$userService->trafficFetch($server->toArray(), 'shadowsocks', $formatData);
|
||||
|
||||
return response([
|
||||
'ret' => 1,
|
||||
'msg' => 'ok'
|
||||
]);
|
||||
}
|
||||
}
|
126
app/Http/Controllers/Server/TrojanTidalabController.php
Normal file
126
app/Http/Controllers/Server/TrojanTidalabController.php
Normal file
@ -0,0 +1,126 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Server;
|
||||
|
||||
use App\Services\ServerService;
|
||||
use App\Services\StatisticalService;
|
||||
use App\Services\UserService;
|
||||
use App\Utils\CacheKey;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\User;
|
||||
use App\Models\ServerTrojan;
|
||||
use App\Models\ServerLog;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
/*
|
||||
* Tidal Lab Trojan
|
||||
* Github: https://github.com/tokumeikoi/tidalab-trojan
|
||||
*/
|
||||
class TrojanTidalabController extends Controller
|
||||
{
|
||||
CONST TROJAN_CONFIG = '{"run_type":"server","local_addr":"0.0.0.0","local_port":443,"remote_addr":"www.taobao.com","remote_port":80,"password":[],"ssl":{"cert":"server.crt","key":"server.key","sni":"domain.com"},"api":{"enabled":true,"api_addr":"127.0.0.1","api_port":10000}}';
|
||||
public function __construct(Request $request)
|
||||
{
|
||||
$token = $request->input('token');
|
||||
if (empty($token)) {
|
||||
abort(500, 'token is null');
|
||||
}
|
||||
if ($token !== config('v2board.server_token')) {
|
||||
abort(500, 'token is error');
|
||||
}
|
||||
}
|
||||
|
||||
// 后端获取用户
|
||||
public function user(Request $request)
|
||||
{
|
||||
ini_set('memory_limit', -1);
|
||||
$nodeId = $request->input('node_id');
|
||||
$server = ServerTrojan::find($nodeId);
|
||||
if (!$server) {
|
||||
abort(500, 'fail');
|
||||
}
|
||||
Cache::put(CacheKey::get('SERVER_TROJAN_LAST_CHECK_AT', $server->id), time(), 3600);
|
||||
$serverService = new ServerService();
|
||||
$users = $serverService->getAvailableUsers($server->group_id);
|
||||
$result = [];
|
||||
foreach ($users as $user) {
|
||||
$user->trojan_user = [
|
||||
"password" => $user->uuid,
|
||||
];
|
||||
unset($user['uuid']);
|
||||
array_push($result, $user);
|
||||
}
|
||||
$eTag = sha1(json_encode($result));
|
||||
if (strpos($request->header('If-None-Match'), $eTag) !== false ) {
|
||||
abort(304);
|
||||
}
|
||||
return response([
|
||||
'msg' => 'ok',
|
||||
'data' => $result,
|
||||
])->header('ETag', "\"{$eTag}\"");
|
||||
}
|
||||
|
||||
// 后端提交数据
|
||||
public function submit(Request $request)
|
||||
{
|
||||
// Log::info('serverSubmitData:' . $request->input('node_id') . ':' . file_get_contents('php://input'));
|
||||
$server = ServerTrojan::find($request->input('node_id'));
|
||||
if (!$server) {
|
||||
return response([
|
||||
'ret' => 0,
|
||||
'msg' => 'server is not found'
|
||||
]);
|
||||
}
|
||||
$data = file_get_contents('php://input');
|
||||
$data = json_decode($data, true);
|
||||
Cache::put(CacheKey::get('SERVER_TROJAN_ONLINE_USER', $server->id), count($data), 3600);
|
||||
Cache::put(CacheKey::get('SERVER_TROJAN_LAST_PUSH_AT', $server->id), time(), 3600);
|
||||
$userService = new UserService();
|
||||
$formatData = [];
|
||||
foreach ($data as $item) {
|
||||
$formatData[$item['user_id']] = [$item['u'], $item['d']];
|
||||
}
|
||||
$userService->trafficFetch($server->toArray(), 'trojan', $formatData);
|
||||
|
||||
return response([
|
||||
'ret' => 1,
|
||||
'msg' => 'ok'
|
||||
]);
|
||||
}
|
||||
|
||||
// 后端获取配置
|
||||
public function config(Request $request)
|
||||
{
|
||||
$nodeId = $request->input('node_id');
|
||||
$localPort = $request->input('local_port');
|
||||
if (empty($nodeId) || empty($localPort)) {
|
||||
abort(500, '参数错误');
|
||||
}
|
||||
try {
|
||||
$json = $this->getTrojanConfig($nodeId, $localPort);
|
||||
} catch (\Exception $e) {
|
||||
abort(500, $e->getMessage());
|
||||
}
|
||||
|
||||
die(json_encode($json, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
|
||||
private function getTrojanConfig(int $nodeId, int $localPort)
|
||||
{
|
||||
$server = ServerTrojan::find($nodeId);
|
||||
if (!$server) {
|
||||
abort(500, '节点不存在');
|
||||
}
|
||||
|
||||
$json = json_decode(self::TROJAN_CONFIG);
|
||||
$json->local_port = $server->server_port;
|
||||
$json->ssl->sni = $server->server_name ? $server->server_name : $server->host;
|
||||
$json->ssl->cert = "/root/.cert/server.crt";
|
||||
$json->ssl->key = "/root/.cert/server.key";
|
||||
$json->api->api_port = $localPort;
|
||||
return $json;
|
||||
}
|
||||
}
|
133
app/Http/Controllers/Server/UniProxyController.php
Normal file
133
app/Http/Controllers/Server/UniProxyController.php
Normal file
@ -0,0 +1,133 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Server;
|
||||
|
||||
use App\Services\ServerService;
|
||||
use App\Services\StatisticalService;
|
||||
use App\Services\UserService;
|
||||
use App\Utils\CacheKey;
|
||||
use App\Utils\Helper;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\ServerShadowsocks;
|
||||
use App\Models\ServerVmess;
|
||||
use App\Models\ServerTrojan;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
class UniProxyController extends Controller
|
||||
{
|
||||
private $nodeType;
|
||||
private $nodeInfo;
|
||||
private $nodeId;
|
||||
private $serverService;
|
||||
|
||||
public function __construct(Request $request)
|
||||
{
|
||||
$token = $request->input('token');
|
||||
if (empty($token)) {
|
||||
abort(500, 'token is null');
|
||||
}
|
||||
if ($token !== config('v2board.server_token')) {
|
||||
abort(500, 'token is error');
|
||||
}
|
||||
$this->nodeType = $request->input('node_type');
|
||||
if ($this->nodeType === 'v2ray') $this->nodeType = 'vmess';
|
||||
$this->nodeId = $request->input('node_id');
|
||||
$this->serverService = new ServerService();
|
||||
$this->nodeInfo = $this->serverService->getServer($this->nodeId, $this->nodeType);
|
||||
if (!$this->nodeInfo) abort(500, 'server is not exist');
|
||||
}
|
||||
|
||||
// 后端获取用户
|
||||
public function user(Request $request)
|
||||
{
|
||||
ini_set('memory_limit', -1);
|
||||
Cache::put(CacheKey::get('SERVER_' . strtoupper($this->nodeType) . '_LAST_CHECK_AT', $this->nodeInfo->id), time(), 3600);
|
||||
$users = $this->serverService->getAvailableUsers($this->nodeInfo->group_id);
|
||||
$users = $users->toArray();
|
||||
|
||||
$response['users'] = $users;
|
||||
|
||||
$eTag = sha1(json_encode($response));
|
||||
if (strpos($request->header('If-None-Match'), $eTag) !== false ) {
|
||||
abort(304);
|
||||
}
|
||||
|
||||
return response($response)->header('ETag', "\"{$eTag}\"");
|
||||
}
|
||||
|
||||
// 后端提交数据
|
||||
public function push(Request $request)
|
||||
{
|
||||
$data = file_get_contents('php://input');
|
||||
$data = json_decode($data, true);
|
||||
Cache::put(CacheKey::get('SERVER_' . strtoupper($this->nodeType) . '_ONLINE_USER', $this->nodeInfo->id), count($data), 3600);
|
||||
Cache::put(CacheKey::get('SERVER_' . strtoupper($this->nodeType) . '_LAST_PUSH_AT', $this->nodeInfo->id), time(), 3600);
|
||||
$userService = new UserService();
|
||||
$userService->trafficFetch($this->nodeInfo->toArray(), $this->nodeType, $data);
|
||||
|
||||
return response([
|
||||
'data' => true
|
||||
]);
|
||||
}
|
||||
|
||||
// 后端获取配置
|
||||
public function config(Request $request)
|
||||
{
|
||||
switch ($this->nodeType) {
|
||||
case 'shadowsocks':
|
||||
$response = [
|
||||
'server_port' => $this->nodeInfo->server_port,
|
||||
'cipher' => $this->nodeInfo->cipher,
|
||||
'obfs' => $this->nodeInfo->obfs,
|
||||
'obfs_settings' => $this->nodeInfo->obfs_settings
|
||||
];
|
||||
|
||||
if ($this->nodeInfo->cipher === '2022-blake3-aes-128-gcm') {
|
||||
$response['server_key'] = Helper::getServerKey($this->nodeInfo->created_at, 16);
|
||||
}
|
||||
if ($this->nodeInfo->cipher === '2022-blake3-aes-256-gcm') {
|
||||
$response['server_key'] = Helper::getServerKey($this->nodeInfo->created_at, 32);
|
||||
}
|
||||
break;
|
||||
case 'vmess':
|
||||
$response = [
|
||||
'server_port' => $this->nodeInfo->server_port,
|
||||
'network' => $this->nodeInfo->network,
|
||||
'networkSettings' => $this->nodeInfo->networkSettings,
|
||||
'tls' => $this->nodeInfo->tls
|
||||
];
|
||||
break;
|
||||
case 'trojan':
|
||||
$response = [
|
||||
'host' => $this->nodeInfo->host,
|
||||
'server_port' => $this->nodeInfo->server_port,
|
||||
'server_name' => $this->nodeInfo->server_name,
|
||||
];
|
||||
break;
|
||||
case 'hysteria':
|
||||
$response = [
|
||||
'host' => $this->nodeInfo->host,
|
||||
'server_port' => $this->nodeInfo->server_port,
|
||||
'server_name' => $this->nodeInfo->server_name,
|
||||
'up_mbps' => $this->nodeInfo->up_mbps,
|
||||
'down_mbps' => $this->nodeInfo->down_mbps,
|
||||
'obfs' => Helper::getServerKey($this->nodeInfo->created_at, 16)
|
||||
];
|
||||
break;
|
||||
}
|
||||
$response['base_config'] = [
|
||||
'push_interval' => (int)config('v2board.server_push_interval', 60),
|
||||
'pull_interval' => (int)config('v2board.server_pull_interval', 60)
|
||||
];
|
||||
if ($this->nodeInfo['route_id']) {
|
||||
$response['routes'] = $this->serverService->getRoutes($this->nodeInfo['route_id']);
|
||||
}
|
||||
$eTag = sha1(json_encode($response));
|
||||
if (strpos($request->header('If-None-Match'), $eTag) !== false ) {
|
||||
abort(304);
|
||||
}
|
||||
|
||||
return response($response)->header('ETag', "\"{$eTag}\"");
|
||||
}
|
||||
}
|
59
app/Http/Controllers/Staff/NoticeController.php
Normal file
59
app/Http/Controllers/Staff/NoticeController.php
Normal file
@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Staff;
|
||||
|
||||
use App\Http\Requests\Admin\NoticeSave;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Notice;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
class NoticeController extends Controller
|
||||
{
|
||||
public function fetch(Request $request)
|
||||
{
|
||||
return response([
|
||||
'data' => Notice::orderBy('id', 'DESC')->get()
|
||||
]);
|
||||
}
|
||||
|
||||
public function save(NoticeSave $request)
|
||||
{
|
||||
$data = $request->only([
|
||||
'title',
|
||||
'content',
|
||||
'img_url'
|
||||
]);
|
||||
if (!$request->input('id')) {
|
||||
if (!Notice::create($data)) {
|
||||
abort(500, '保存失败');
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
Notice::find($request->input('id'))->update($data);
|
||||
} catch (\Exception $e) {
|
||||
abort(500, '保存失败');
|
||||
}
|
||||
}
|
||||
return response([
|
||||
'data' => true
|
||||
]);
|
||||
}
|
||||
|
||||
public function drop(Request $request)
|
||||
{
|
||||
if (empty($request->input('id'))) {
|
||||
abort(500, '参数错误');
|
||||
}
|
||||
$notice = Notice::find($request->input('id'));
|
||||
if (!$notice) {
|
||||
abort(500, '公告不存在');
|
||||
}
|
||||
if (!$notice->delete()) {
|
||||
abort(500, '删除失败');
|
||||
}
|
||||
return response([
|
||||
'data' => true
|
||||
]);
|
||||
}
|
||||
}
|
41
app/Http/Controllers/Staff/PlanController.php
Executable file
41
app/Http/Controllers/Staff/PlanController.php
Executable file
@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Staff;
|
||||
|
||||
use App\Http\Requests\Admin\PlanSave;
|
||||
use App\Http\Requests\Admin\PlanSort;
|
||||
use App\Http\Requests\Admin\PlanUpdate;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Plan;
|
||||
use App\Models\Order;
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class PlanController extends Controller
|
||||
{
|
||||
public function fetch(Request $request)
|
||||
{
|
||||
$counts = User::select(
|
||||
DB::raw("plan_id"),
|
||||
DB::raw("count(*) as count")
|
||||
)
|
||||
->where('plan_id', '!=', NULL)
|
||||
->where(function ($query) {
|
||||
$query->where('expired_at', '>=', time())
|
||||
->orWhere('expired_at', NULL);
|
||||
})
|
||||
->groupBy("plan_id")
|
||||
->get();
|
||||
$plans = Plan::orderBy('sort', 'ASC')->get();
|
||||
foreach ($plans as $k => $v) {
|
||||
$plans[$k]->count = 0;
|
||||
foreach ($counts as $kk => $vv) {
|
||||
if ($plans[$k]->id === $counts[$kk]->plan_id) $plans[$k]->count = $counts[$kk]->count;
|
||||
}
|
||||
}
|
||||
return response([
|
||||
'data' => $plans
|
||||
]);
|
||||
}
|
||||
}
|
85
app/Http/Controllers/Staff/TicketController.php
Normal file
85
app/Http/Controllers/Staff/TicketController.php
Normal file
@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Staff;
|
||||
|
||||
use App\Services\TicketService;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Ticket;
|
||||
use App\Models\TicketMessage;
|
||||
|
||||
class TicketController extends Controller
|
||||
{
|
||||
public function fetch(Request $request)
|
||||
{
|
||||
if ($request->input('id')) {
|
||||
$ticket = Ticket::where('id', $request->input('id'))
|
||||
->first();
|
||||
if (!$ticket) {
|
||||
abort(500, '工单不存在');
|
||||
}
|
||||
$ticket['message'] = TicketMessage::where('ticket_id', $ticket->id)->get();
|
||||
for ($i = 0; $i < count($ticket['message']); $i++) {
|
||||
if ($ticket['message'][$i]['user_id'] !== $ticket->user_id) {
|
||||
$ticket['message'][$i]['is_me'] = true;
|
||||
} else {
|
||||
$ticket['message'][$i]['is_me'] = false;
|
||||
}
|
||||
}
|
||||
return response([
|
||||
'data' => $ticket
|
||||
]);
|
||||
}
|
||||
$current = $request->input('current') ? $request->input('current') : 1;
|
||||
$pageSize = $request->input('pageSize') >= 10 ? $request->input('pageSize') : 10;
|
||||
$model = Ticket::orderBy('created_at', 'DESC');
|
||||
if ($request->input('status') !== NULL) {
|
||||
$model->where('status', $request->input('status'));
|
||||
}
|
||||
$total = $model->count();
|
||||
$res = $model->forPage($current, $pageSize)
|
||||
->get();
|
||||
return response([
|
||||
'data' => $res,
|
||||
'total' => $total
|
||||
]);
|
||||
}
|
||||
|
||||
public function reply(Request $request)
|
||||
{
|
||||
if (empty($request->input('id'))) {
|
||||
abort(500, '参数错误');
|
||||
}
|
||||
if (empty($request->input('message'))) {
|
||||
abort(500, '消息不能为空');
|
||||
}
|
||||
$ticketService = new TicketService();
|
||||
$ticketService->replyByAdmin(
|
||||
$request->input('id'),
|
||||
$request->input('message'),
|
||||
$request->user['id']
|
||||
);
|
||||
return response([
|
||||
'data' => true
|
||||
]);
|
||||
}
|
||||
|
||||
public function close(Request $request)
|
||||
{
|
||||
if (empty($request->input('id'))) {
|
||||
abort(500, '参数错误');
|
||||
}
|
||||
$ticket = Ticket::where('id', $request->input('id'))
|
||||
->first();
|
||||
if (!$ticket) {
|
||||
abort(500, '工单不存在');
|
||||
}
|
||||
$ticket->status = 1;
|
||||
if (!$ticket->save()) {
|
||||
abort(500, '关闭失败');
|
||||
}
|
||||
return response([
|
||||
'data' => true
|
||||
]);
|
||||
}
|
||||
}
|
107
app/Http/Controllers/Staff/UserController.php
Normal file
107
app/Http/Controllers/Staff/UserController.php
Normal file
@ -0,0 +1,107 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Staff;
|
||||
|
||||
use App\Http\Requests\Admin\UserSendMail;
|
||||
use App\Http\Requests\Staff\UserUpdate;
|
||||
use App\Jobs\SendEmailJob;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\User;
|
||||
use App\Models\Plan;
|
||||
|
||||
class UserController extends Controller
|
||||
{
|
||||
public function getUserInfoById(Request $request)
|
||||
{
|
||||
if (empty($request->input('id'))) {
|
||||
abort(500, '参数错误');
|
||||
}
|
||||
$user = User::where('is_admin', 0)
|
||||
->where('id', $request->input('id'))
|
||||
->where('is_staff', 0)
|
||||
->first();
|
||||
if (!$user) abort(500, '用户不存在');
|
||||
return response([
|
||||
'data' => $user
|
||||
]);
|
||||
}
|
||||
|
||||
public function update(UserUpdate $request)
|
||||
{
|
||||
$params = $request->validated();
|
||||
$user = User::find($request->input('id'));
|
||||
if (!$user) {
|
||||
abort(500, '用户不存在');
|
||||
}
|
||||
if (User::where('email', $params['email'])->first() && $user->email !== $params['email']) {
|
||||
abort(500, '邮箱已被使用');
|
||||
}
|
||||
if (isset($params['password'])) {
|
||||
$params['password'] = password_hash($params['password'], PASSWORD_DEFAULT);
|
||||
$params['password_algo'] = NULL;
|
||||
} else {
|
||||
unset($params['password']);
|
||||
}
|
||||
if (isset($params['plan_id'])) {
|
||||
$plan = Plan::find($params['plan_id']);
|
||||
if (!$plan) {
|
||||
abort(500, '订阅计划不存在');
|
||||
}
|
||||
$params['group_id'] = $plan->group_id;
|
||||
}
|
||||
|
||||
try {
|
||||
$user->update($params);
|
||||
} catch (\Exception $e) {
|
||||
abort(500, '保存失败');
|
||||
}
|
||||
return response([
|
||||
'data' => true
|
||||
]);
|
||||
}
|
||||
|
||||
public function sendMail(UserSendMail $request)
|
||||
{
|
||||
$sortType = in_array($request->input('sort_type'), ['ASC', 'DESC']) ? $request->input('sort_type') : 'DESC';
|
||||
$sort = $request->input('sort') ? $request->input('sort') : 'created_at';
|
||||
$builder = User::orderBy($sort, $sortType);
|
||||
$this->filter($request, $builder);
|
||||
$users = $builder->get();
|
||||
foreach ($users as $user) {
|
||||
SendEmailJob::dispatch([
|
||||
'email' => $user->email,
|
||||
'subject' => $request->input('subject'),
|
||||
'template_name' => 'notify',
|
||||
'template_value' => [
|
||||
'name' => config('v2board.app_name', 'V2Board'),
|
||||
'url' => config('v2board.app_url'),
|
||||
'content' => $request->input('content')
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
||||
return response([
|
||||
'data' => true
|
||||
]);
|
||||
}
|
||||
|
||||
public function ban(Request $request)
|
||||
{
|
||||
$sortType = in_array($request->input('sort_type'), ['ASC', 'DESC']) ? $request->input('sort_type') : 'DESC';
|
||||
$sort = $request->input('sort') ? $request->input('sort') : 'created_at';
|
||||
$builder = User::orderBy($sort, $sortType);
|
||||
$this->filter($request, $builder);
|
||||
try {
|
||||
$builder->update([
|
||||
'banned' => 1
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
abort(500, '处理失败');
|
||||
}
|
||||
|
||||
return response([
|
||||
'data' => true
|
||||
]);
|
||||
}
|
||||
}
|
41
app/Http/Controllers/User/CommController.php
Normal file
41
app/Http/Controllers/User/CommController.php
Normal file
@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\User;
|
||||
|
||||
use App\Models\Payment;
|
||||
use App\Utils\Dict;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
|
||||
class CommController extends Controller
|
||||
{
|
||||
public function config()
|
||||
{
|
||||
return response([
|
||||
'data' => [
|
||||
'is_telegram' => (int)config('v2board.telegram_bot_enable', 0),
|
||||
'telegram_discuss_link' => config('v2board.telegram_discuss_link'),
|
||||
'stripe_pk' => config('v2board.stripe_pk_live'),
|
||||
'withdraw_methods' => config('v2board.commission_withdraw_method', Dict::WITHDRAW_METHOD_WHITELIST_DEFAULT),
|
||||
'withdraw_close' => (int)config('v2board.withdraw_close_enable', 0),
|
||||
'currency' => config('v2board.currency', 'CNY'),
|
||||
'currency_symbol' => config('v2board.currency_symbol', '¥'),
|
||||
'commission_distribution_enable' => (int)config('v2board.commission_distribution_enable', 0),
|
||||
'commission_distribution_l1' => config('v2board.commission_distribution_l1'),
|
||||
'commission_distribution_l2' => config('v2board.commission_distribution_l2'),
|
||||
'commission_distribution_l3' => config('v2board.commission_distribution_l3')
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
||||
public function getStripePublicKey(Request $request)
|
||||
{
|
||||
$payment = Payment::where('id', $request->input('id'))
|
||||
->where('payment', 'StripeCredit')
|
||||
->first();
|
||||
if (!$payment) abort(500, 'payment is not found');
|
||||
return response([
|
||||
'data' => $payment->config['stripe_pk_live']
|
||||
]);
|
||||
}
|
||||
}
|
25
app/Http/Controllers/User/CouponController.php
Normal file
25
app/Http/Controllers/User/CouponController.php
Normal file
@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\User;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Services\CouponService;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\Coupon;
|
||||
|
||||
class CouponController extends Controller
|
||||
{
|
||||
public function check(Request $request)
|
||||
{
|
||||
if (empty($request->input('code'))) {
|
||||
abort(500, __('Coupon cannot be empty'));
|
||||
}
|
||||
$couponService = new CouponService($request->input('code'));
|
||||
$couponService->setPlanId($request->input('plan_id'));
|
||||
$couponService->setUserId($request->user['id']);
|
||||
$couponService->check();
|
||||
return response([
|
||||
'data' => $couponService->getCoupon()
|
||||
]);
|
||||
}
|
||||
}
|
88
app/Http/Controllers/User/InviteController.php
Normal file
88
app/Http/Controllers/User/InviteController.php
Normal file
@ -0,0 +1,88 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\User;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\CommissionLog;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\User;
|
||||
use App\Models\Order;
|
||||
use App\Models\InviteCode;
|
||||
use App\Utils\Helper;
|
||||
|
||||
class InviteController extends Controller
|
||||
{
|
||||
public function save(Request $request)
|
||||
{
|
||||
if (InviteCode::where('user_id', $request->user['id'])->where('status', 0)->count() >= config('v2board.invite_gen_limit', 5)) {
|
||||
abort(500, __('The maximum number of creations has been reached'));
|
||||
}
|
||||
$inviteCode = new InviteCode();
|
||||
$inviteCode->user_id = $request->user['id'];
|
||||
$inviteCode->code = Helper::randomChar(8);
|
||||
return response([
|
||||
'data' => $inviteCode->save()
|
||||
]);
|
||||
}
|
||||
|
||||
public function details(Request $request)
|
||||
{
|
||||
$current = $request->input('current') ? $request->input('current') : 1;
|
||||
$pageSize = $request->input('page_size') >= 10 ? $request->input('page_size') : 10;
|
||||
$builder = CommissionLog::where('invite_user_id', $request->user['id'])
|
||||
->where('get_amount', '>', 0)
|
||||
->select([
|
||||
'id',
|
||||
'trade_no',
|
||||
'order_amount',
|
||||
'get_amount',
|
||||
'created_at'
|
||||
])
|
||||
->orderBy('created_at', 'DESC');
|
||||
$total = $builder->count();
|
||||
$details = $builder->forPage($current, $pageSize)
|
||||
->get();
|
||||
return response([
|
||||
'data' => $details,
|
||||
'total' => $total
|
||||
]);
|
||||
}
|
||||
|
||||
public function fetch(Request $request)
|
||||
{
|
||||
$codes = InviteCode::where('user_id', $request->user['id'])
|
||||
->where('status', 0)
|
||||
->get();
|
||||
$commission_rate = config('v2board.invite_commission', 10);
|
||||
$user = User::find($request->user['id']);
|
||||
if ($user->commission_rate) {
|
||||
$commission_rate = $user->commission_rate;
|
||||
}
|
||||
$uncheck_commission_balance = (int)Order::where('status', 3)
|
||||
->where('commission_status', 0)
|
||||
->where('invite_user_id', $request->user['id'])
|
||||
->sum('commission_balance');
|
||||
if (config('v2board.commission_distribution_enable', 0)) {
|
||||
$uncheck_commission_balance = $uncheck_commission_balance * (config('v2board.commission_distribution_l1') / 100);
|
||||
}
|
||||
$stat = [
|
||||
//已注册用户数
|
||||
(int)User::where('invite_user_id', $request->user['id'])->count(),
|
||||
//有效的佣金
|
||||
(int)CommissionLog::where('invite_user_id', $request->user['id'])
|
||||
->sum('get_amount'),
|
||||
//确认中的佣金
|
||||
$uncheck_commission_balance,
|
||||
//佣金比例
|
||||
(int)$commission_rate,
|
||||
//可用佣金
|
||||
(int)$user->commission_balance
|
||||
];
|
||||
return response([
|
||||
'data' => [
|
||||
'codes' => $codes,
|
||||
'stat' => $stat
|
||||
]
|
||||
]);
|
||||
}
|
||||
}
|
73
app/Http/Controllers/User/KnowledgeController.php
Normal file
73
app/Http/Controllers/User/KnowledgeController.php
Normal file
@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\User;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\User;
|
||||
use App\Services\UserService;
|
||||
use App\Utils\Helper;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\Knowledge;
|
||||
|
||||
class KnowledgeController extends Controller
|
||||
{
|
||||
public function fetch(Request $request)
|
||||
{
|
||||
if ($request->input('id')) {
|
||||
$knowledge = Knowledge::where('id', $request->input('id'))
|
||||
->where('show', 1)
|
||||
->first()
|
||||
->toArray();
|
||||
if (!$knowledge) abort(500, __('Article does not exist'));
|
||||
$user = User::find($request->user['id']);
|
||||
$userService = new UserService();
|
||||
if (!$userService->isAvailable($user)) {
|
||||
$this->formatAccessData($knowledge['body']);
|
||||
}
|
||||
$subscribeUrl = Helper::getSubscribeUrl("/api/v1/client/subscribe?token={$user['token']}");
|
||||
$knowledge['body'] = str_replace('{{siteName}}', config('v2board.app_name', 'V2Board'), $knowledge['body']);
|
||||
$knowledge['body'] = str_replace('{{subscribeUrl}}', $subscribeUrl, $knowledge['body']);
|
||||
$knowledge['body'] = str_replace('{{urlEncodeSubscribeUrl}}', urlencode($subscribeUrl), $knowledge['body']);
|
||||
$knowledge['body'] = str_replace(
|
||||
'{{safeBase64SubscribeUrl}}',
|
||||
str_replace(
|
||||
array('+', '/', '='),
|
||||
array('-', '_', ''),
|
||||
base64_encode($subscribeUrl)
|
||||
),
|
||||
$knowledge['body']
|
||||
);
|
||||
return response([
|
||||
'data' => $knowledge
|
||||
]);
|
||||
}
|
||||
$builder = Knowledge::select(['id', 'category', 'title', 'updated_at'])
|
||||
->where('language', $request->input('language'))
|
||||
->where('show', 1)
|
||||
->orderBy('sort', 'ASC');
|
||||
$keyword = $request->input('keyword');
|
||||
if ($keyword) {
|
||||
$builder = $builder->where(function ($query) use ($keyword) {
|
||||
$query->where('title', 'LIKE', "%{$keyword}%")
|
||||
->orWhere('body', 'LIKE', "%{$keyword}%");
|
||||
});
|
||||
}
|
||||
|
||||
$knowledges = $builder->get()
|
||||
->groupBy('category');
|
||||
return response([
|
||||
'data' => $knowledges
|
||||
]);
|
||||
}
|
||||
|
||||
private function formatAccessData(&$body)
|
||||
{
|
||||
function getBetween($input, $start, $end){$substr = substr($input, strlen($start)+strpos($input, $start),(strlen($input) - strpos($input, $end))*(-1));return $start . $substr . $end;}
|
||||
while (strpos($body, '<!--access start-->') !== false) {
|
||||
$accessData = getBetween($body, '<!--access start-->', '<!--access end-->');
|
||||
if ($accessData) {
|
||||
$body = str_replace($accessData, '<div class="v2board-no-access">'. __('You must have a valid subscription to view content in this area') .'</div>', $body);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
26
app/Http/Controllers/User/NoticeController.php
Normal file
26
app/Http/Controllers/User/NoticeController.php
Normal file
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\User;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\Notice;
|
||||
use App\Utils\Helper;
|
||||
|
||||
class NoticeController extends Controller
|
||||
{
|
||||
public function fetch(Request $request)
|
||||
{
|
||||
$current = $request->input('current') ? $request->input('current') : 1;
|
||||
$pageSize = 5;
|
||||
$model = Notice::orderBy('created_at', 'DESC')
|
||||
->where('show', 1);
|
||||
$total = $model->count();
|
||||
$res = $model->forPage($current, $pageSize)
|
||||
->get();
|
||||
return response([
|
||||
'data' => $res,
|
||||
'total' => $total
|
||||
]);
|
||||
}
|
||||
}
|
267
app/Http/Controllers/User/OrderController.php
Executable file
267
app/Http/Controllers/User/OrderController.php
Executable file
@ -0,0 +1,267 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\User;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\User\OrderSave;
|
||||
use App\Models\CommissionLog;
|
||||
use App\Models\Payment;
|
||||
use App\Services\CouponService;
|
||||
use App\Services\OrderService;
|
||||
use App\Services\PaymentService;
|
||||
use App\Services\PlanService;
|
||||
use App\Services\UserService;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use App\Models\Order;
|
||||
use App\Models\Plan;
|
||||
use App\Models\User;
|
||||
use App\Utils\Helper;
|
||||
use Omnipay\Omnipay;
|
||||
use Stripe\Stripe;
|
||||
use Stripe\Source;
|
||||
use Library\BitpayX;
|
||||
use Library\MGate;
|
||||
use Library\Epay;
|
||||
|
||||
class OrderController extends Controller
|
||||
{
|
||||
public function fetch(Request $request)
|
||||
{
|
||||
$model = Order::where('user_id', $request->user['id'])
|
||||
->orderBy('created_at', 'DESC');
|
||||
if ($request->input('status') !== null) {
|
||||
$model->where('status', $request->input('status'));
|
||||
}
|
||||
$order = $model->get();
|
||||
$plan = Plan::get();
|
||||
for ($i = 0; $i < count($order); $i++) {
|
||||
for ($x = 0; $x < count($plan); $x++) {
|
||||
if ($order[$i]['plan_id'] === $plan[$x]['id']) {
|
||||
$order[$i]['plan'] = $plan[$x];
|
||||
}
|
||||
}
|
||||
}
|
||||
return response([
|
||||
'data' => $order->makeHidden(['id', 'user_id'])
|
||||
]);
|
||||
}
|
||||
|
||||
public function detail(Request $request)
|
||||
{
|
||||
$order = Order::where('user_id', $request->user['id'])
|
||||
->where('trade_no', $request->input('trade_no'))
|
||||
->first();
|
||||
if (!$order) {
|
||||
abort(500, __('Order does not exist or has been paid'));
|
||||
}
|
||||
$order['plan'] = Plan::find($order->plan_id);
|
||||
$order['try_out_plan_id'] = (int)config('v2board.try_out_plan_id');
|
||||
if (!$order['plan']) {
|
||||
abort(500, __('Subscription plan does not exist'));
|
||||
}
|
||||
if ($order->surplus_order_ids) {
|
||||
$order['surplus_orders'] = Order::whereIn('id', $order->surplus_order_ids)->get();
|
||||
}
|
||||
return response([
|
||||
'data' => $order
|
||||
]);
|
||||
}
|
||||
|
||||
public function save(OrderSave $request)
|
||||
{
|
||||
$userService = new UserService();
|
||||
if ($userService->isNotCompleteOrderByUserId($request->user['id'])) {
|
||||
abort(500, __('You have an unpaid or pending order, please try again later or cancel it'));
|
||||
}
|
||||
|
||||
$planService = new PlanService($request->input('plan_id'));
|
||||
|
||||
$plan = $planService->plan;
|
||||
$user = User::find($request->user['id']);
|
||||
|
||||
if (!$plan) {
|
||||
abort(500, __('Subscription plan does not exist'));
|
||||
}
|
||||
|
||||
if ($user->plan_id !== $plan->id && !$planService->haveCapacity() && $request->input('period') !== 'reset_price') {
|
||||
abort(500, __('Current product is sold out'));
|
||||
}
|
||||
|
||||
if ($plan[$request->input('period')] === NULL) {
|
||||
abort(500, __('This payment period cannot be purchased, please choose another period'));
|
||||
}
|
||||
|
||||
if ($request->input('period') === 'reset_price') {
|
||||
if (!$userService->isAvailable($user) || $plan->id !== $user->plan_id) {
|
||||
abort(500, __('Subscription has expired or no active subscription, unable to purchase Data Reset Package'));
|
||||
}
|
||||
}
|
||||
|
||||
if ((!$plan->show && !$plan->renew) || (!$plan->show && $user->plan_id !== $plan->id)) {
|
||||
if ($request->input('period') !== 'reset_price') {
|
||||
abort(500, __('This subscription has been sold out, please choose another subscription'));
|
||||
}
|
||||
}
|
||||
|
||||
if (!$plan->renew && $user->plan_id == $plan->id && $request->input('period') !== 'reset_price') {
|
||||
abort(500, __('This subscription cannot be renewed, please change to another subscription'));
|
||||
}
|
||||
|
||||
|
||||
if (!$plan->show && $plan->renew && !$userService->isAvailable($user)) {
|
||||
abort(500, __('This subscription has expired, please change to another subscription'));
|
||||
}
|
||||
|
||||
DB::beginTransaction();
|
||||
$order = new Order();
|
||||
$orderService = new OrderService($order);
|
||||
$order->user_id = $request->user['id'];
|
||||
$order->plan_id = $plan->id;
|
||||
$order->period = $request->input('period');
|
||||
$order->trade_no = Helper::generateOrderNo();
|
||||
$order->total_amount = $plan[$request->input('period')];
|
||||
|
||||
if ($request->input('coupon_code')) {
|
||||
$couponService = new CouponService($request->input('coupon_code'));
|
||||
if (!$couponService->use($order)) {
|
||||
DB::rollBack();
|
||||
abort(500, __('Coupon failed'));
|
||||
}
|
||||
$order->coupon_id = $couponService->getId();
|
||||
}
|
||||
|
||||
$orderService->setVipDiscount($user);
|
||||
$orderService->setOrderType($user);
|
||||
$orderService->setInvite($user);
|
||||
|
||||
if ($user->balance && $order->total_amount > 0) {
|
||||
$remainingBalance = $user->balance - $order->total_amount;
|
||||
$userService = new UserService();
|
||||
if ($remainingBalance > 0) {
|
||||
if (!$userService->addBalance($order->user_id, - $order->total_amount)) {
|
||||
DB::rollBack();
|
||||
abort(500, __('Insufficient balance'));
|
||||
}
|
||||
$order->balance_amount = $order->total_amount;
|
||||
$order->total_amount = 0;
|
||||
} else {
|
||||
if (!$userService->addBalance($order->user_id, - $user->balance)) {
|
||||
DB::rollBack();
|
||||
abort(500, __('Insufficient balance'));
|
||||
}
|
||||
$order->balance_amount = $user->balance;
|
||||
$order->total_amount = $order->total_amount - $user->balance;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$order->save()) {
|
||||
DB::rollback();
|
||||
abort(500, __('Failed to create order'));
|
||||
}
|
||||
|
||||
DB::commit();
|
||||
|
||||
return response([
|
||||
'data' => $order->trade_no
|
||||
]);
|
||||
}
|
||||
|
||||
public function checkout(Request $request)
|
||||
{
|
||||
$tradeNo = $request->input('trade_no');
|
||||
$method = $request->input('method');
|
||||
$order = Order::where('trade_no', $tradeNo)
|
||||
->where('user_id', $request->user['id'])
|
||||
->where('status', 0)
|
||||
->first();
|
||||
if (!$order) {
|
||||
abort(500, __('Order does not exist or has been paid'));
|
||||
}
|
||||
// free process
|
||||
if ($order->total_amount <= 0) {
|
||||
$orderService = new OrderService($order);
|
||||
if (!$orderService->paid($order->trade_no)) abort(500, '');
|
||||
return response([
|
||||
'type' => -1,
|
||||
'data' => true
|
||||
]);
|
||||
}
|
||||
$payment = Payment::find($method);
|
||||
if (!$payment || $payment->enable !== 1) abort(500, __('Payment method is not available'));
|
||||
$paymentService = new PaymentService($payment->payment, $payment->id);
|
||||
$order->handling_amount = NULL;
|
||||
if ($payment->handling_fee_fixed || $payment->handling_fee_percent) {
|
||||
$order->handling_amount = round(($order->total_amount * ($payment->handling_fee_percent / 100)) + $payment->handling_fee_fixed);
|
||||
}
|
||||
$order->payment_id = $method;
|
||||
if (!$order->save()) abort(500, __('Request failed, please try again later'));
|
||||
$result = $paymentService->pay([
|
||||
'trade_no' => $tradeNo,
|
||||
'total_amount' => isset($order->handling_amount) ? ($order->total_amount + $order->handling_amount) : $order->total_amount,
|
||||
'user_id' => $order->user_id,
|
||||
'stripe_token' => $request->input('token')
|
||||
]);
|
||||
return response([
|
||||
'type' => $result['type'],
|
||||
'data' => $result['data']
|
||||
]);
|
||||
}
|
||||
|
||||
public function check(Request $request)
|
||||
{
|
||||
$tradeNo = $request->input('trade_no');
|
||||
$order = Order::where('trade_no', $tradeNo)
|
||||
->where('user_id', $request->user['id'])
|
||||
->first();
|
||||
if (!$order) {
|
||||
abort(500, __('Order does not exist'));
|
||||
}
|
||||
return response([
|
||||
'data' => $order->status
|
||||
]);
|
||||
}
|
||||
|
||||
public function getPaymentMethod()
|
||||
{
|
||||
$methods = Payment::select([
|
||||
'id',
|
||||
'name',
|
||||
'payment',
|
||||
'icon',
|
||||
'handling_fee_fixed',
|
||||
'handling_fee_percent'
|
||||
])
|
||||
->where('enable', 1)
|
||||
->orderBy('sort', 'ASC')
|
||||
->get();
|
||||
|
||||
return response([
|
||||
'data' => $methods
|
||||
]);
|
||||
}
|
||||
|
||||
public function cancel(Request $request)
|
||||
{
|
||||
if (empty($request->input('trade_no'))) {
|
||||
abort(500, __('Invalid parameter'));
|
||||
}
|
||||
$order = Order::where('trade_no', $request->input('trade_no'))
|
||||
->where('user_id', $request->user['id'])
|
||||
->first();
|
||||
if (!$order) {
|
||||
abort(500, __('Order does not exist'));
|
||||
}
|
||||
if ($order->status !== 0) {
|
||||
abort(500, __('You can only cancel pending orders'));
|
||||
}
|
||||
$orderService = new OrderService($order);
|
||||
if (!$orderService->cancel()) {
|
||||
abort(500, __('Cancel failed'));
|
||||
}
|
||||
return response([
|
||||
'data' => true
|
||||
]);
|
||||
}
|
||||
}
|
43
app/Http/Controllers/User/PlanController.php
Executable file
43
app/Http/Controllers/User/PlanController.php
Executable file
@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\User;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\User;
|
||||
use App\Services\PlanService;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\Plan;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class PlanController extends Controller
|
||||
{
|
||||
public function fetch(Request $request)
|
||||
{
|
||||
$user = User::find($request->user['id']);
|
||||
if ($request->input('id')) {
|
||||
$plan = Plan::where('id', $request->input('id'))->first();
|
||||
if (!$plan) {
|
||||
abort(500, __('Subscription plan does not exist'));
|
||||
}
|
||||
if ((!$plan->show && !$plan->renew) || (!$plan->show && $user->plan_id !== $plan->id)) {
|
||||
abort(500, __('Subscription plan does not exist'));
|
||||
}
|
||||
return response([
|
||||
'data' => $plan
|
||||
]);
|
||||
}
|
||||
|
||||
$counts = PlanService::countActiveUsers();
|
||||
$plans = Plan::where('show', 1)
|
||||
->orderBy('sort', 'ASC')
|
||||
->get();
|
||||
foreach ($plans as $k => $v) {
|
||||
if ($plans[$k]->capacity_limit === NULL) continue;
|
||||
if (!isset($counts[$plans[$k]->id])) continue;
|
||||
$plans[$k]->capacity_limit = $plans[$k]->capacity_limit - $counts[$plans[$k]->id]->count;
|
||||
}
|
||||
return response([
|
||||
'data' => $plans
|
||||
]);
|
||||
}
|
||||
}
|
38
app/Http/Controllers/User/ServerController.php
Normal file
38
app/Http/Controllers/User/ServerController.php
Normal file
@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\User;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Services\ServerService;
|
||||
use App\Services\UserService;
|
||||
use App\Utils\CacheKey;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use App\Models\ServerVmess;
|
||||
use App\Models\ServerLog;
|
||||
use App\Models\User;
|
||||
|
||||
use App\Utils\Helper;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class ServerController extends Controller
|
||||
{
|
||||
public function fetch(Request $request)
|
||||
{
|
||||
$user = User::find($request->user['id']);
|
||||
$servers = [];
|
||||
$userService = new UserService();
|
||||
if ($userService->isAvailable($user)) {
|
||||
$serverService = new ServerService();
|
||||
$servers = $serverService->getAvailableServers($user);
|
||||
}
|
||||
$eTag = sha1(json_encode(array_column($servers, 'cache_key')));
|
||||
if (strpos($request->header('If-None-Match'), $eTag) !== false ) {
|
||||
abort(304);
|
||||
}
|
||||
|
||||
return response([
|
||||
'data' => $servers
|
||||
])->header('ETag', "\"{$eTag}\"");
|
||||
}
|
||||
}
|
28
app/Http/Controllers/User/StatController.php
Normal file
28
app/Http/Controllers/User/StatController.php
Normal file
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\User;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\StatUser;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class StatController extends Controller
|
||||
{
|
||||
public function getTrafficLog(Request $request)
|
||||
{
|
||||
$builder = StatUser::select([
|
||||
'u',
|
||||
'd',
|
||||
'record_at',
|
||||
'user_id',
|
||||
'server_rate'
|
||||
])
|
||||
->where('user_id', $request->user['id'])
|
||||
->where('record_at', '>=', strtotime(date('Y-m-1')))
|
||||
->orderBy('record_at', 'DESC');
|
||||
return response([
|
||||
'data' => $builder->get()
|
||||
]);
|
||||
}
|
||||
}
|
27
app/Http/Controllers/User/TelegramController.php
Normal file
27
app/Http/Controllers/User/TelegramController.php
Normal file
@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\User;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\User;
|
||||
use App\Services\TelegramService;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class TelegramController extends Controller
|
||||
{
|
||||
public function getBotInfo()
|
||||
{
|
||||
$telegramService = new TelegramService();
|
||||
$response = $telegramService->getMe();
|
||||
return response([
|
||||
'data' => [
|
||||
'username' => $response->result->username
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
||||
public function unbind(Request $request)
|
||||
{
|
||||
$user = User::where('user_id', $request->user['id'])->first();
|
||||
}
|
||||
}
|
198
app/Http/Controllers/User/TicketController.php
Normal file
198
app/Http/Controllers/User/TicketController.php
Normal file
@ -0,0 +1,198 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\User;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\User\TicketSave;
|
||||
use App\Http\Requests\User\TicketWithdraw;
|
||||
use App\Jobs\SendTelegramJob;
|
||||
use App\Models\User;
|
||||
use App\Services\TelegramService;
|
||||
use App\Services\TicketService;
|
||||
use App\Utils\Dict;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\Ticket;
|
||||
use App\Models\TicketMessage;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class TicketController extends Controller
|
||||
{
|
||||
public function fetch(Request $request)
|
||||
{
|
||||
if ($request->input('id')) {
|
||||
$ticket = Ticket::where('id', $request->input('id'))
|
||||
->where('user_id', $request->user['id'])
|
||||
->first();
|
||||
if (!$ticket) {
|
||||
abort(500, __('Ticket does not exist'));
|
||||
}
|
||||
$ticket['message'] = TicketMessage::where('ticket_id', $ticket->id)->get();
|
||||
for ($i = 0; $i < count($ticket['message']); $i++) {
|
||||
if ($ticket['message'][$i]['user_id'] == $ticket->user_id) {
|
||||
$ticket['message'][$i]['is_me'] = true;
|
||||
} else {
|
||||
$ticket['message'][$i]['is_me'] = false;
|
||||
}
|
||||
}
|
||||
return response([
|
||||
'data' => $ticket
|
||||
]);
|
||||
}
|
||||
$ticket = Ticket::where('user_id', $request->user['id'])
|
||||
->orderBy('created_at', 'DESC')
|
||||
->get();
|
||||
return response([
|
||||
'data' => $ticket
|
||||
]);
|
||||
}
|
||||
|
||||
public function save(TicketSave $request)
|
||||
{
|
||||
DB::beginTransaction();
|
||||
if ((int)Ticket::where('status', 0)->where('user_id', $request->user['id'])->lockForUpdate()->count()) {
|
||||
abort(500, __('There are other unresolved tickets'));
|
||||
}
|
||||
$ticket = Ticket::create(array_merge($request->only([
|
||||
'subject',
|
||||
'level'
|
||||
]), [
|
||||
'user_id' => $request->user['id']
|
||||
]));
|
||||
if (!$ticket) {
|
||||
DB::rollback();
|
||||
abort(500, __('Failed to open ticket'));
|
||||
}
|
||||
$ticketMessage = TicketMessage::create([
|
||||
'user_id' => $request->user['id'],
|
||||
'ticket_id' => $ticket->id,
|
||||
'message' => $request->input('message')
|
||||
]);
|
||||
if (!$ticketMessage) {
|
||||
DB::rollback();
|
||||
abort(500, __('Failed to open ticket'));
|
||||
}
|
||||
DB::commit();
|
||||
$this->sendNotify($ticket, $request->input('message'));
|
||||
return response([
|
||||
'data' => true
|
||||
]);
|
||||
}
|
||||
|
||||
public function reply(Request $request)
|
||||
{
|
||||
if (empty($request->input('id'))) {
|
||||
abort(500, __('Invalid parameter'));
|
||||
}
|
||||
if (empty($request->input('message'))) {
|
||||
abort(500, __('Message cannot be empty'));
|
||||
}
|
||||
$ticket = Ticket::where('id', $request->input('id'))
|
||||
->where('user_id', $request->user['id'])
|
||||
->first();
|
||||
if (!$ticket) {
|
||||
abort(500, __('Ticket does not exist'));
|
||||
}
|
||||
if ($ticket->status) {
|
||||
abort(500, __('The ticket is closed and cannot be replied'));
|
||||
}
|
||||
if ($request->user['id'] == $this->getLastMessage($ticket->id)->user_id) {
|
||||
abort(500, __('Please wait for the technical enginneer to reply'));
|
||||
}
|
||||
$ticketService = new TicketService();
|
||||
if (!$ticketService->reply(
|
||||
$ticket,
|
||||
$request->input('message'),
|
||||
$request->user['id']
|
||||
)) {
|
||||
abort(500, __('Ticket reply failed'));
|
||||
}
|
||||
$this->sendNotify($ticket, $request->input('message'));
|
||||
return response([
|
||||
'data' => true
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
public function close(Request $request)
|
||||
{
|
||||
if (empty($request->input('id'))) {
|
||||
abort(500, __('Invalid parameter'));
|
||||
}
|
||||
$ticket = Ticket::where('id', $request->input('id'))
|
||||
->where('user_id', $request->user['id'])
|
||||
->first();
|
||||
if (!$ticket) {
|
||||
abort(500, __('Ticket does not exist'));
|
||||
}
|
||||
$ticket->status = 1;
|
||||
if (!$ticket->save()) {
|
||||
abort(500, __('Close failed'));
|
||||
}
|
||||
return response([
|
||||
'data' => true
|
||||
]);
|
||||
}
|
||||
|
||||
private function getLastMessage($ticketId)
|
||||
{
|
||||
return TicketMessage::where('ticket_id', $ticketId)
|
||||
->orderBy('id', 'DESC')
|
||||
->first();
|
||||
}
|
||||
|
||||
public function withdraw(TicketWithdraw $request)
|
||||
{
|
||||
if ((int)config('v2board.withdraw_close_enable', 0)) {
|
||||
abort(500, 'user.ticket.withdraw.not_support_withdraw');
|
||||
}
|
||||
if (!in_array(
|
||||
$request->input('withdraw_method'),
|
||||
config(
|
||||
'v2board.commission_withdraw_method',
|
||||
Dict::WITHDRAW_METHOD_WHITELIST_DEFAULT
|
||||
)
|
||||
)) {
|
||||
abort(500, __('Unsupported withdrawal method'));
|
||||
}
|
||||
$user = User::find($request->user['id']);
|
||||
$limit = config('v2board.commission_withdraw_limit', 100);
|
||||
if ($limit > ($user->commission_balance / 100)) {
|
||||
abort(500, __('The current required minimum withdrawal commission is :limit', ['limit' => $limit]));
|
||||
}
|
||||
DB::beginTransaction();
|
||||
$subject = __('[Commission Withdrawal Request] This ticket is opened by the system');
|
||||
$ticket = Ticket::create([
|
||||
'subject' => $subject,
|
||||
'level' => 2,
|
||||
'user_id' => $request->user['id']
|
||||
]);
|
||||
if (!$ticket) {
|
||||
DB::rollback();
|
||||
abort(500, __('Failed to open ticket'));
|
||||
}
|
||||
$message = sprintf("%s\r\n%s",
|
||||
__('Withdrawal method') . ":" . $request->input('withdraw_method'),
|
||||
__('Withdrawal account') . ":" . $request->input('withdraw_account')
|
||||
);
|
||||
$ticketMessage = TicketMessage::create([
|
||||
'user_id' => $request->user['id'],
|
||||
'ticket_id' => $ticket->id,
|
||||
'message' => $message
|
||||
]);
|
||||
if (!$ticketMessage) {
|
||||
DB::rollback();
|
||||
abort(500, __('Failed to open ticket'));
|
||||
}
|
||||
DB::commit();
|
||||
$this->sendNotify($ticket, $message);
|
||||
return response([
|
||||
'data' => true
|
||||
]);
|
||||
}
|
||||
|
||||
private function sendNotify(Ticket $ticket, string $message)
|
||||
{
|
||||
$telegramService = new TelegramService();
|
||||
$telegramService->sendMessageWithAdmin("📮工单提醒 #{$ticket->id}\n———————————————\n主题:\n`{$ticket->subject}`\n内容:\n`{$message}`", true);
|
||||
}
|
||||
}
|
239
app/Http/Controllers/User/UserController.php
Executable file
239
app/Http/Controllers/User/UserController.php
Executable file
@ -0,0 +1,239 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\User;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\User\UserTransfer;
|
||||
use App\Http\Requests\User\UserUpdate;
|
||||
use App\Http\Requests\User\UserChangePassword;
|
||||
use App\Services\AuthService;
|
||||
use App\Services\UserService;
|
||||
use App\Utils\CacheKey;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\User;
|
||||
use App\Models\Plan;
|
||||
use App\Models\Ticket;
|
||||
use App\Utils\Helper;
|
||||
use App\Models\Order;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
class UserController extends Controller
|
||||
{
|
||||
public function getActiveSession(Request $request)
|
||||
{
|
||||
$user = User::find($request->user['id']);
|
||||
if (!$user) {
|
||||
abort(500, __('The user does not exist'));
|
||||
}
|
||||
$authService = new AuthService($user);
|
||||
return response([
|
||||
'data' => $authService->getSessions()
|
||||
]);
|
||||
}
|
||||
|
||||
public function removeActiveSession(Request $request)
|
||||
{
|
||||
$user = User::find($request->user['id']);
|
||||
if (!$user) {
|
||||
abort(500, __('The user does not exist'));
|
||||
}
|
||||
$authService = new AuthService($user);
|
||||
return response([
|
||||
'data' => $authService->removeSession($request->input('session_id'))
|
||||
]);
|
||||
}
|
||||
|
||||
public function checkLogin(Request $request)
|
||||
{
|
||||
$data = [
|
||||
'is_login' => $request->user['id'] ? true : false
|
||||
];
|
||||
if ($request->user['is_admin']) {
|
||||
$data['is_admin'] = true;
|
||||
}
|
||||
return response([
|
||||
'data' => $data
|
||||
]);
|
||||
}
|
||||
|
||||
public function changePassword(UserChangePassword $request)
|
||||
{
|
||||
$user = User::find($request->user['id']);
|
||||
if (!$user) {
|
||||
abort(500, __('The user does not exist'));
|
||||
}
|
||||
if (!Helper::multiPasswordVerify(
|
||||
$user->password_algo,
|
||||
$user->password_salt,
|
||||
$request->input('old_password'),
|
||||
$user->password)
|
||||
) {
|
||||
abort(500, __('The old password is wrong'));
|
||||
}
|
||||
$user->password = password_hash($request->input('new_password'), PASSWORD_DEFAULT);
|
||||
$user->password_algo = NULL;
|
||||
$user->password_salt = NULL;
|
||||
if (!$user->save()) {
|
||||
abort(500, __('Save failed'));
|
||||
}
|
||||
return response([
|
||||
'data' => true
|
||||
]);
|
||||
}
|
||||
|
||||
public function info(Request $request)
|
||||
{
|
||||
$user = User::where('id', $request->user['id'])
|
||||
->select([
|
||||
'email',
|
||||
'transfer_enable',
|
||||
'last_login_at',
|
||||
'created_at',
|
||||
'banned',
|
||||
'remind_expire',
|
||||
'remind_traffic',
|
||||
'expired_at',
|
||||
'balance',
|
||||
'commission_balance',
|
||||
'plan_id',
|
||||
'discount',
|
||||
'commission_rate',
|
||||
'telegram_id',
|
||||
'uuid'
|
||||
])
|
||||
->first();
|
||||
if (!$user) {
|
||||
abort(500, __('The user does not exist'));
|
||||
}
|
||||
$user['avatar_url'] = 'https://cdn.v2ex.com/gravatar/' . md5($user->email) . '?s=64&d=identicon';
|
||||
return response([
|
||||
'data' => $user
|
||||
]);
|
||||
}
|
||||
|
||||
public function getStat(Request $request)
|
||||
{
|
||||
$stat = [
|
||||
Order::where('status', 0)
|
||||
->where('user_id', $request->user['id'])
|
||||
->count(),
|
||||
Ticket::where('status', 0)
|
||||
->where('user_id', $request->user['id'])
|
||||
->count(),
|
||||
User::where('invite_user_id', $request->user['id'])
|
||||
->count()
|
||||
];
|
||||
return response([
|
||||
'data' => $stat
|
||||
]);
|
||||
}
|
||||
|
||||
public function getSubscribe(Request $request)
|
||||
{
|
||||
$user = User::where('id', $request->user['id'])
|
||||
->select([
|
||||
'plan_id',
|
||||
'token',
|
||||
'expired_at',
|
||||
'u',
|
||||
'd',
|
||||
'transfer_enable',
|
||||
'email',
|
||||
'uuid'
|
||||
])
|
||||
->first();
|
||||
if (!$user) {
|
||||
abort(500, __('The user does not exist'));
|
||||
}
|
||||
if ($user->plan_id) {
|
||||
$user['plan'] = Plan::find($user->plan_id);
|
||||
if (!$user['plan']) {
|
||||
abort(500, __('Subscription plan does not exist'));
|
||||
}
|
||||
}
|
||||
$user['subscribe_url'] = Helper::getSubscribeUrl("/api/v1/client/subscribe?token={$user['token']}");
|
||||
$userService = new UserService();
|
||||
$user['reset_day'] = $userService->getResetDay($user);
|
||||
return response([
|
||||
'data' => $user
|
||||
]);
|
||||
}
|
||||
|
||||
public function resetSecurity(Request $request)
|
||||
{
|
||||
$user = User::find($request->user['id']);
|
||||
if (!$user) {
|
||||
abort(500, __('The user does not exist'));
|
||||
}
|
||||
$user->uuid = Helper::guid(true);
|
||||
$user->token = Helper::guid();
|
||||
if (!$user->save()) {
|
||||
abort(500, __('Reset failed'));
|
||||
}
|
||||
return response([
|
||||
'data' => Helper::getSubscribeUrl('/api/v1/client/subscribe?token=' . $user->token)
|
||||
]);
|
||||
}
|
||||
|
||||
public function update(UserUpdate $request)
|
||||
{
|
||||
$updateData = $request->only([
|
||||
'remind_expire',
|
||||
'remind_traffic'
|
||||
]);
|
||||
|
||||
$user = User::find($request->user['id']);
|
||||
if (!$user) {
|
||||
abort(500, __('The user does not exist'));
|
||||
}
|
||||
try {
|
||||
$user->update($updateData);
|
||||
} catch (\Exception $e) {
|
||||
abort(500, __('Save failed'));
|
||||
}
|
||||
|
||||
return response([
|
||||
'data' => true
|
||||
]);
|
||||
}
|
||||
|
||||
public function transfer(UserTransfer $request)
|
||||
{
|
||||
$user = User::find($request->user['id']);
|
||||
if (!$user) {
|
||||
abort(500, __('The user does not exist'));
|
||||
}
|
||||
if ($request->input('transfer_amount') > $user->commission_balance) {
|
||||
abort(500, __('Insufficient commission balance'));
|
||||
}
|
||||
$user->commission_balance = $user->commission_balance - $request->input('transfer_amount');
|
||||
$user->balance = $user->balance + $request->input('transfer_amount');
|
||||
if (!$user->save()) {
|
||||
abort(500, __('Transfer failed'));
|
||||
}
|
||||
return response([
|
||||
'data' => true
|
||||
]);
|
||||
}
|
||||
|
||||
public function getQuickLoginUrl(Request $request)
|
||||
{
|
||||
$user = User::find($request->user['id']);
|
||||
if (!$user) {
|
||||
abort(500, __('The user does not exist'));
|
||||
}
|
||||
|
||||
$code = Helper::guid();
|
||||
$key = CacheKey::get('TEMP_TOKEN', $code);
|
||||
Cache::put($key, $user->id, 60);
|
||||
$redirect = '/#/login?verify=' . $code . '&redirect=' . ($request->input('redirect') ? $request->input('redirect') : 'dashboard');
|
||||
if (config('v2board.app_url')) {
|
||||
$url = config('v2board.app_url') . $redirect;
|
||||
} else {
|
||||
$url = url($redirect);
|
||||
}
|
||||
return response([
|
||||
'data' => $url
|
||||
]);
|
||||
}
|
||||
}
|
@ -1,145 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Http\Requests\UserUpdate;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\User;
|
||||
use App\Models\Plan;
|
||||
use App\Models\Server;
|
||||
use App\Utils\Helper;
|
||||
use App\Models\Order;
|
||||
|
||||
class UserController extends Controller
|
||||
{
|
||||
public function logout (Request $request) {
|
||||
return response([
|
||||
'data' => $request->session()->flush()
|
||||
]);
|
||||
}
|
||||
|
||||
public function changePassword (Request $request) {
|
||||
if (empty($request->input('old_password'))) {
|
||||
abort(500, '旧密码不能为空');
|
||||
}
|
||||
if (empty($request->input('new_password'))) {
|
||||
abort(500, '新密码不能为空');
|
||||
}
|
||||
$user = User::find($request->session()->get('id'));
|
||||
if (!password_verify($request->input('old_password'), $user->password)) {
|
||||
abort(500, '旧密码有误');
|
||||
}
|
||||
$user->password = password_hash($request->input('new_password'), PASSWORD_DEFAULT);
|
||||
if (!$user->save()) {
|
||||
abort(500, '保存失败');
|
||||
}
|
||||
$request->session()->flush();
|
||||
return response([
|
||||
'data' => true
|
||||
]);
|
||||
}
|
||||
|
||||
public function index (Request $request) {
|
||||
}
|
||||
|
||||
public function save (Request $request) {
|
||||
}
|
||||
|
||||
public function info (Request $request) {
|
||||
$user = User::where('id', $request->session()->get('id'))
|
||||
->select([
|
||||
'email',
|
||||
'last_login_at',
|
||||
'created_at',
|
||||
'enable',
|
||||
'is_admin',
|
||||
'remind_expire',
|
||||
'remind_traffic'
|
||||
])
|
||||
->first();
|
||||
$user['avatar_url'] = 'https://cdn.v2ex.com/gravatar/' . md5($user->email) . '?s=64&d=identicon';
|
||||
return response([
|
||||
'data' => $user
|
||||
]);
|
||||
}
|
||||
|
||||
public function dashboard (Request $request) {
|
||||
$user = User::find($request->session()->get('id'));
|
||||
if ($user->plan_id) {
|
||||
$user['plan'] = Plan::find($user->plan_id);
|
||||
}
|
||||
$user['subscribe_url'] = config('v2board.app_url', env('APP_URL')) . '/api/v1/client/subscribe?token=' . $user['token'];
|
||||
$stat = [
|
||||
Order::where('status', 0)
|
||||
->where('user_id', $request->session()->get('id'))
|
||||
->count(),
|
||||
0,
|
||||
User::where('invite_user_id', $request->session()->get('id'))
|
||||
->count()
|
||||
];
|
||||
return response([
|
||||
'data' => [
|
||||
'user' => $user,
|
||||
'stat' => $stat
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
||||
public function subscribe (Request $request) {
|
||||
$user = User::find($request->session()->get('id'));
|
||||
$server = [];
|
||||
if ($user->plan_id) {
|
||||
$user['plan'] = Plan::find($user->plan_id);
|
||||
if (!$user['plan']) {
|
||||
abort(500, '订阅计划不存在');
|
||||
}
|
||||
if ($user->expired_at > time()) {
|
||||
$servers = Server::all();
|
||||
foreach ($servers as $item) {
|
||||
$groupId = json_decode($item['group_id']);
|
||||
if (in_array($user->group_id, $groupId)) {
|
||||
array_push($server, $item);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$user['subscribe_url'] = config('v2board.app_url', env('APP_URL')) . '/api/v1/client/subscribe?token=' . $user['token'];
|
||||
return response([
|
||||
'data' => [
|
||||
'user' => $user,
|
||||
'server' => $server
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
||||
public function resetUUID (Request $request) {
|
||||
$user = User::find($request->session()->get('id'));
|
||||
$user->v2ray_uuid = Helper::guid(true);
|
||||
if (!$user->save()) {
|
||||
abort(500, '重置失败');
|
||||
}
|
||||
return response([
|
||||
'data' => true
|
||||
]);
|
||||
}
|
||||
|
||||
public function update (UserUpdate $request) {
|
||||
$updateData = $request->only([
|
||||
'remind_expire',
|
||||
'remind_traffic'
|
||||
]);
|
||||
|
||||
$user = User::find($request->session()->get('id'));
|
||||
if (!$user) {
|
||||
abort(500, '该用户不存在');
|
||||
}
|
||||
if (!$user->update($updateData)) {
|
||||
abort(500, '保存失败');
|
||||
}
|
||||
|
||||
return response([
|
||||
'data' => true
|
||||
]);
|
||||
}
|
||||
}
|
@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Http;
|
||||
|
||||
use Fruitcake\Cors\HandleCors;
|
||||
use Illuminate\Foundation\Http\Kernel as HttpKernel;
|
||||
|
||||
class Kernel extends HttpKernel
|
||||
@ -14,6 +15,7 @@ class Kernel extends HttpKernel
|
||||
* @var array
|
||||
*/
|
||||
protected $middleware = [
|
||||
\App\Http\Middleware\CORS::class,
|
||||
\App\Http\Middleware\TrustProxies::class,
|
||||
\App\Http\Middleware\CheckForMaintenanceMode::class,
|
||||
\Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,
|
||||
@ -28,22 +30,21 @@ class Kernel extends HttpKernel
|
||||
*/
|
||||
protected $middlewareGroups = [
|
||||
'web' => [
|
||||
\App\Http\Middleware\EncryptCookies::class,
|
||||
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
|
||||
\Illuminate\Session\Middleware\StartSession::class,
|
||||
// \App\Http\Middleware\EncryptCookies::class,
|
||||
// \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
|
||||
// \Illuminate\Session\Middleware\StartSession::class,
|
||||
// \Illuminate\Session\Middleware\AuthenticateSession::class,
|
||||
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
|
||||
\App\Http\Middleware\VerifyCsrfToken::class,
|
||||
\Illuminate\Routing\Middleware\SubstituteBindings::class,
|
||||
// \Illuminate\View\Middleware\ShareErrorsFromSession::class,
|
||||
// \App\Http\Middleware\VerifyCsrfToken::class,
|
||||
// \Illuminate\Routing\Middleware\SubstituteBindings::class,
|
||||
],
|
||||
|
||||
'api' => [
|
||||
\App\Http\Middleware\EncryptCookies::class,
|
||||
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
|
||||
\Illuminate\Session\Middleware\StartSession::class,
|
||||
// \App\Http\Middleware\EncryptCookies::class,
|
||||
// \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
|
||||
// \Illuminate\Session\Middleware\StartSession::class,
|
||||
\App\Http\Middleware\ForceJson::class,
|
||||
\App\Http\Middleware\CORS::class,
|
||||
'throttle:60,1',
|
||||
\App\Http\Middleware\Language::class,
|
||||
'bindings',
|
||||
],
|
||||
];
|
||||
@ -68,7 +69,8 @@ class Kernel extends HttpKernel
|
||||
'user' => \App\Http\Middleware\User::class,
|
||||
'admin' => \App\Http\Middleware\Admin::class,
|
||||
'client' => \App\Http\Middleware\Client::class,
|
||||
'server' => \App\Http\Middleware\Server::class,
|
||||
'staff' => \App\Http\Middleware\Staff::class,
|
||||
'log' => \App\Http\Middleware\RequestLog::class
|
||||
];
|
||||
|
||||
/**
|
||||
|
@ -2,7 +2,9 @@
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use App\Services\AuthService;
|
||||
use Closure;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
class Admin
|
||||
{
|
||||
@ -15,9 +17,14 @@ class Admin
|
||||
*/
|
||||
public function handle($request, Closure $next)
|
||||
{
|
||||
if (!$request->session()->get('is_admin')) {
|
||||
abort(403, '权限不足');
|
||||
}
|
||||
$authorization = $request->input('auth_data') ?? $request->header('authorization');
|
||||
if (!$authorization) abort(403, '未登录或登陆已过期');
|
||||
|
||||
$user = AuthService::decryptAuthData($authorization);
|
||||
if (!$user || !$user['is_admin']) abort(403, '未登录或登陆已过期');
|
||||
$request->merge([
|
||||
'user' => $user
|
||||
]);
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
|
@ -17,8 +17,8 @@ class CORS
|
||||
}
|
||||
$response = $next($request);
|
||||
$response->header('Access-Control-Allow-Origin', trim($origin, '/'));
|
||||
$response->header('Access-Control-Allow-Methods', 'GET,POST,OPTIONS');
|
||||
$response->header('Access-Control-Allow-Headers', 'Content-Type,X-Requested-With');
|
||||
$response->header('Access-Control-Allow-Methods', 'GET,POST,OPTIONS,HEAD');
|
||||
$response->header('Access-Control-Allow-Headers', 'Origin,Content-Type,Accept,Authorization,X-Request-With');
|
||||
$response->header('Access-Control-Allow-Credentials', 'true');
|
||||
$response->header('Access-Control-Max-Age', 10080);
|
||||
|
||||
|
@ -2,8 +2,10 @@
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use App\Utils\CacheKey;
|
||||
use Closure;
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
class Client
|
||||
{
|
||||
@ -18,13 +20,15 @@ class Client
|
||||
{
|
||||
$token = $request->input('token');
|
||||
if (empty($token)) {
|
||||
abort(500, 'token is null');
|
||||
abort(403, 'token is null');
|
||||
}
|
||||
$user = User::where('token', $token)->first();
|
||||
if (!$user) {
|
||||
abort(500, 'token is error');
|
||||
abort(403, 'token is error');
|
||||
}
|
||||
$request->user = $user;
|
||||
$request->merge([
|
||||
'user' => $user
|
||||
]);
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
|
17
app/Http/Middleware/Language.php
Executable file
17
app/Http/Middleware/Language.php
Executable file
@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Support\Facades\App;
|
||||
|
||||
class Language
|
||||
{
|
||||
public function handle($request, Closure $next)
|
||||
{
|
||||
if ($request->header('content-language')) {
|
||||
App::setLocale($request->header('content-language'));
|
||||
}
|
||||
return $next($request);
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user