From 0b62ae8591b84ca4b0aacfbde70d14054b6ae9d4 Mon Sep 17 00:00:00 2001 From: Anonymous Date: Wed, 23 Oct 2019 18:13:54 +0800 Subject: [PATCH] update --- .../Controllers/Admin/ConfigController.php | 38 +++++++------- app/Http/Controllers/ClientController.php | 51 ++++++++++++++++++- .../Controllers/Guest/OrderController.php | 4 +- app/Http/Controllers/InviteController.php | 2 +- app/Http/Controllers/OrderController.php | 32 ++++++------ .../Controllers/Passport/CommController.php | 6 +-- .../Passport/RegisterController.php | 10 ++-- app/Http/Controllers/UserController.php | 4 +- app/Http/Middleware/Server.php | 2 +- routes/web.php | 2 +- 10 files changed, 100 insertions(+), 51 deletions(-) diff --git a/app/Http/Controllers/Admin/ConfigController.php b/app/Http/Controllers/Admin/ConfigController.php index 1be4ddaf..803b22fb 100755 --- a/app/Http/Controllers/Admin/ConfigController.php +++ b/app/Http/Controllers/Admin/ConfigController.php @@ -19,31 +19,31 @@ class ConfigController extends Controller return response([ 'data' => [ 'invite' => [ - 'invite_force' => (int)config('v2panel.invite_force', env('DEFAULT_INVITE_FORCE')), - 'invite_commission' => config('v2panel.invite_commission', env('DEFAULT_INVITE_COMMISSION')), - 'invite_gen_limit' => config('v2panel.invite_gen_limit', env('DEFAULT_INVITE_GEN_LIMIT')) + '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('v2panel.stop_register', env('DEFAULT_STOP_REGISTER')), - 'email_verify' => (int)config('v2panel.email_verify', env('DEFAULT_EMAIL_VERIFY')), - 'app_name' => config('v2panel.app_name', env('APP_NAME')), - 'app_url' => config('v2panel.app_url', env('APP_URL')) + '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('v2panel.alipay_enable'), - 'alipay_appid' => config('v2panel.alipay_appid'), - 'alipay_pubkey' => config('v2panel.alipay_pubkey'), - 'alipay_privkey' => config('v2panel.alipay_privkey'), + '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('v2panel.stripe_sk_live'), - 'stripe_pk_live' => config('v2panel.stripe_pk_live'), - 'stripe_alipay_enable' => (int)config('v2panel.stripe_alipay_enable'), - 'stripe_wepay_enable' => (int)config('v2panel.stripe_wepay_enable'), - 'stripe_webhook_key' => config('v2panel.stripe_webhook_key') + '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('v2panel.server_token') + 'server_token' => config('v2board.server_token') ] ] ]); @@ -51,7 +51,7 @@ class ConfigController extends Controller public function save (ConfigSave $request) { $data = $request->input(); - $array = \Config::get('v2panel'); + $array = \Config::get('v2board'); foreach ($data as $k => $v) { if (!in_array($k, ConfigSave::filter())) { abort(500, '禁止修改'); @@ -59,7 +59,7 @@ class ConfigController extends Controller $array[$k] = $v; } $data = var_export($array, 1); - if(!\File::put(base_path() . '/config/v2panel.php', "quantumult($user, $server)); } + if(strpos($_SERVER['HTTP_USER_AGENT'], 'clash_win') !== false) { + die($this->clash($user, $server)); + } die($this->origin($user, $server)); } @@ -43,7 +46,7 @@ class ClientController extends Controller $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('v2panel.app_name', 'V2Board'))."\r\n"; + $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); } @@ -66,4 +69,50 @@ class ClientController extends Controller } return base64_encode($uri); } + + private function clash ($user, $server) { + $proxy = []; + $proxyGroup = []; + $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') + ] + ]; + foreach ($server as $item) { + $obj = new \StdClass(); + $obj->name = $item->name; + $obj->type = 'vmess'; + $obj->server = $item->host; + $obj->port = $item->port; + $obj->uuid = $user->v2ray_uuid; + $obj->alterId = $user->v2ray_alter_id; + $obj->cipher = 'auto'; + if ($item->tls) { + $obj->tls = true; + } + array_push($proxy, $obj); + array_push($proxies, $item->name); + } + array_push($proxyGroup, [ + 'name' => config('v2board.app_name', 'V2Board'), + 'type' => 'select', + 'proxies' => $proxies + ]); + } } diff --git a/app/Http/Controllers/Guest/OrderController.php b/app/Http/Controllers/Guest/OrderController.php index f858513c..6896ed40 100644 --- a/app/Http/Controllers/Guest/OrderController.php +++ b/app/Http/Controllers/Guest/OrderController.php @@ -12,12 +12,12 @@ class OrderController extends Controller public function stripeNotify (Request $request) { Log::info('stripeNotifyData: ' . json_encode($request->input())); - \Stripe\Stripe::setApiKey(config('v2panel.stripe_sk_live')); + \Stripe\Stripe::setApiKey(config('v2board.stripe_sk_live')); try { $event = \Stripe\Webhook::constructEvent( file_get_contents('php://input'), $_SERVER['HTTP_STRIPE_SIGNATURE'], - config('v2panel.stripe_webhook_key') + config('v2board.stripe_webhook_key') ); } catch (\Stripe\Error\SignatureVerification $e) { abort(400); diff --git a/app/Http/Controllers/InviteController.php b/app/Http/Controllers/InviteController.php index c5906e0e..7ae1ed86 100644 --- a/app/Http/Controllers/InviteController.php +++ b/app/Http/Controllers/InviteController.php @@ -28,7 +28,7 @@ class InviteController extends Controller ->where('status', 0) ->get(); for ($i = 0; $i < count($codes); $i++) { - $codes[$i]['invite_url'] = config('v2panel.app_url', env('APP_URL')) . '/#/register?code=' . $codes[$i]['code']; + $codes[$i]['invite_url'] = config('v2board.app_url', env('APP_URL')) . '/#/register?code=' . $codes[$i]['code']; } $stat = [ //已注册用户数 diff --git a/app/Http/Controllers/OrderController.php b/app/Http/Controllers/OrderController.php index fb6eaf41..07e02ece 100755 --- a/app/Http/Controllers/OrderController.php +++ b/app/Http/Controllers/OrderController.php @@ -67,7 +67,7 @@ class OrderController extends Controller $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('v2panel.invite_commission', env('DEFAULT_INVITE_COMMISSION')) / 100); + $order->commission_balance = $order->total_amount * (config('v2board.invite_commission', env('DEFAULT_INVITE_COMMISSION')) / 100); } if (!$order->save()) { abort(500, '订单创建失败'); @@ -92,7 +92,7 @@ class OrderController extends Controller // return type => 0: QRCode / 1: URL case 0: // alipayF2F - if (!(int)config('v2panel.alipay_enable')) { + if (!(int)config('v2board.alipay_enable')) { abort(500, '支付方式不可用'); } return response([ @@ -101,7 +101,7 @@ class OrderController extends Controller ]); case 2: // stripeAlipay - if (!(int)config('v2panel.stripe_alipay_enable')) { + if (!(int)config('v2board.stripe_alipay_enable')) { abort(500, '支付方式不可用'); } return response([ @@ -110,7 +110,7 @@ class OrderController extends Controller ]); case 3: // stripeWepay - if (!(int)config('v2panel.stripe_wepay_enable')) { + if (!(int)config('v2board.stripe_wepay_enable')) { abort(500, '支付方式不可用'); } return response([ @@ -137,7 +137,7 @@ class OrderController extends Controller public function getPaymentMethod () { $data = []; - if ((int)config('v2panel.alipay_enable')) { + if ((int)config('v2board.alipay_enable')) { $alipayF2F = new \StdClass(); $alipayF2F->name = '支付宝'; $alipayF2F->method = 0; @@ -145,7 +145,7 @@ class OrderController extends Controller array_push($data, $alipayF2F); } - if ((int)config('v2panel.stripe_alipay_enable')) { + if ((int)config('v2board.stripe_alipay_enable')) { $stripeAlipay = new \StdClass(); $stripeAlipay->name = '支付宝'; $stripeAlipay->method = 2; @@ -153,7 +153,7 @@ class OrderController extends Controller array_push($data, $stripeAlipay); } - if ((int)config('v2panel.stripe_wepay_enable')) { + if ((int)config('v2board.stripe_wepay_enable')) { $stripeWepay = new \StdClass(); $stripeWepay->name = '微信'; $stripeWepay->method = 3; @@ -169,13 +169,13 @@ class OrderController extends Controller private function alipayF2F ($tradeNo, $totalAmount) { $gateway = Omnipay::create('Alipay_AopF2F'); $gateway->setSignType('RSA2'); //RSA/RSA2 - $gateway->setAppId(config('v2panel.alipay_appid')); - $gateway->setPrivateKey(config('v2panel.alipay_privkey')); // 可以是路径,也可以是密钥内容 - $gateway->setAlipayPublicKey(config('v2panel.alipay_pubkey')); // 可以是路径,也可以是密钥内容 - $gateway->setNotifyUrl(config('v2panel.app_url', env('APP_URL')) . '/api/v1/guest/order/alipayNotify'); + $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('v2panel.app_name') . ' - 订阅', + 'subject' => config('v2board.app_name') . ' - 订阅', 'out_trade_no' => $tradeNo, 'total_amount' => $totalAmount / 100 ]); @@ -194,13 +194,13 @@ class OrderController extends Controller if (!$exchange) { abort(500, '货币转换超时,请稍后再试'); } - Stripe::setApiKey(config('v2panel.stripe_sk_live')); + Stripe::setApiKey(config('v2board.stripe_sk_live')); $source = Source::create([ 'amount' => floor($order->total_amount * $exchange), 'currency' => 'hkd', 'type' => 'alipay', 'redirect' => [ - 'return_url' => config('v2panel.app_url', env('APP_URL')) . '/api/v1/guest/order/stripeReturn' + 'return_url' => config('v2board.app_url', env('APP_URL')) . '/api/v1/guest/order/stripeReturn' ] ]); if (!$source['redirect']['url']) { @@ -218,13 +218,13 @@ class OrderController extends Controller if (!$exchange) { abort(500, '货币转换超时,请稍后再试'); } - Stripe::setApiKey(config('v2panel.stripe_sk_live')); + Stripe::setApiKey(config('v2board.stripe_sk_live')); $source = Source::create([ 'amount' => floor($order->total_amount * $exchange), 'currency' => 'hkd', 'type' => 'wechat', 'redirect' => [ - 'return_url' => config('v2panel.app_url', env('APP_URL')) . '/api/v1/guest/order/stripeReturn' + 'return_url' => config('v2board.app_url', env('APP_URL')) . '/api/v1/guest/order/stripeReturn' ] ]); if (!$source['wechat']['qr_code_url']) { diff --git a/app/Http/Controllers/Passport/CommController.php b/app/Http/Controllers/Passport/CommController.php index ce490e91..c6b70a9c 100644 --- a/app/Http/Controllers/Passport/CommController.php +++ b/app/Http/Controllers/Passport/CommController.php @@ -13,7 +13,7 @@ class CommController extends Controller { public function isEmailVerify () { return response([ - 'data' => (int)config('v2panel.email_verify', env('DEFAULT_EMAIL_VERIFY')) ? 1 : 0 + 'data' => (int)config('v2board.email_verify', env('DEFAULT_EMAIL_VERIFY')) ? 1 : 0 ]); } @@ -24,12 +24,12 @@ class CommController extends Controller abort(500, '验证码已发送,请过一会在请求'); } $code = rand(100000, 999999); - $subject = config('v2panel.app_name', 'V2Panel') . '邮箱验证码'; + $subject = config('v2board.app_name', 'V2Panel') . '邮箱验证码'; Mail::send( 'mail.sendEmailVerify', [ 'code' => $code, - 'name' => config('v2panel.app_name', 'V2Panel') + 'name' => config('v2board.app_name', 'V2Panel') ], function ($message) use($email, $subject) { $message->to($email)->subject($subject); diff --git a/app/Http/Controllers/Passport/RegisterController.php b/app/Http/Controllers/Passport/RegisterController.php index b003316c..6baf92f3 100755 --- a/app/Http/Controllers/Passport/RegisterController.php +++ b/app/Http/Controllers/Passport/RegisterController.php @@ -15,15 +15,15 @@ use App\Models\InviteCode; class RegisterController extends Controller { public function index (RegisterIndex $request) { - if ((int)config('v2panel.stop_register', env('DEFAULT_STOP_REGISTER'))) { + if ((int)config('v2board.stop_register', env('DEFAULT_STOP_REGISTER'))) { abort(500, '本站已关闭注册'); } - if ((int)config('v2panel.invite_force', env('DEFAULT_INVITE_FOCE'))) { + if ((int)config('v2board.invite_force', env('DEFAULT_INVITE_FOCE'))) { if (empty($request->input('invite_code'))) { abort(500, '必须使用邀请码才可以注册'); } } - if ((int)config('v2panel.email_verify', env('DEFAULT_EMAIL_VERIFY'))) { + if ((int)config('v2board.email_verify', env('DEFAULT_EMAIL_VERIFY'))) { $redisKey = 'sendEmailVerify:' . $request->input('email'); if (empty($request->input('email_code'))) { abort(500, '邮箱验证码不能为空'); @@ -49,7 +49,7 @@ class RegisterController extends Controller ->where('status', 0) ->first(); if (!$inviteCode) { - if ((int)config('v2panel.invite_force', env('DEFAULT_INVITE_FOCE'))) { + if ((int)config('v2board.invite_force', env('DEFAULT_INVITE_FOCE'))) { abort(500, '邀请码无效'); } } @@ -61,7 +61,7 @@ class RegisterController extends Controller if (!$user->save()) { abort(500, '注册失败'); } - if ((int)config('v2panel.email_verify', env('DEFAULT_EMAIL_VERIFY'))) { + if ((int)config('v2board.email_verify', env('DEFAULT_EMAIL_VERIFY'))) { Redis::del($redisKey); } return response()->json([ diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php index 4946bb18..bf79b93b 100755 --- a/app/Http/Controllers/UserController.php +++ b/app/Http/Controllers/UserController.php @@ -45,7 +45,7 @@ class UserController extends Controller if ($user->plan_id) { $user['plan'] = Plan::find($user->plan_id); } - $user['subscribe_url'] = config('v2panel.app_url', env('APP_URL')) . '/api/v1/client/subscribe?token=' . $user['token']; + $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')) @@ -80,7 +80,7 @@ class UserController extends Controller } } } - $user['subscribe_url'] = config('v2panel.app_url', env('APP_URL')) . '/api/v1/client/subscribe?token=' . $user['token']; + $user['subscribe_url'] = config('v2board.app_url', env('APP_URL')) . '/api/v1/client/subscribe?token=' . $user['token']; return response([ 'data' => [ 'user' => $user, diff --git a/app/Http/Middleware/Server.php b/app/Http/Middleware/Server.php index 29e8ab2d..b44a7a8c 100644 --- a/app/Http/Middleware/Server.php +++ b/app/Http/Middleware/Server.php @@ -20,7 +20,7 @@ class Server if (empty($token)) { abort(500, 'token is null'); } - if ($token !== config('v2panel.server_token')) { + if ($token !== config('v2board.server_token')) { abort(500, 'token is error'); } return $next($request); diff --git a/routes/web.php b/routes/web.php index bbcbcf12..c79e66ff 100755 --- a/routes/web.php +++ b/routes/web.php @@ -13,6 +13,6 @@ Route::get('/', function () { return view('app', [ - 'title' => config('v2panel.app_name', env('APP_NAME')) + 'title' => config('v2board.app_name', env('APP_NAME')) ]); });