From 7a80950ab57bc70421f5d70ed5af086154a9e20e Mon Sep 17 00:00:00 2001 From: tokumeikoi Date: Sun, 1 Aug 2021 23:56:11 +0900 Subject: [PATCH] update: laravel 7 --- app/Exceptions/Handler.php | 22 ++++++------ .../Controllers/User/ServerController.php | 8 ++--- app/Models/Coupon.php | 4 +++ app/Models/InviteCode.php | 4 +++ app/Models/Knowledge.php | 4 +++ app/Models/MailLog.php | 4 +++ app/Models/Notice.php | 4 +++ app/Models/Order.php | 4 +++ app/Models/Payment.php | 4 +++ app/Models/Plan.php | 4 +++ app/Models/Server.php | 4 +++ app/Models/ServerGroup.php | 4 +++ app/Models/ServerLog.php | 4 +++ app/Models/ServerShadowsocks.php | 4 +++ app/Models/ServerStat.php | 4 +++ app/Models/ServerTrojan.php | 4 +++ app/Models/StatOrder.php | 4 +++ app/Models/StatServer.php | 4 +++ app/Models/Ticket.php | 4 +++ app/Models/TicketMessage.php | 4 +++ app/Models/User.php | 4 +++ app/Services/OrderService.php | 2 +- composer.json | 26 ++++++++------ config/cors.php | 34 +++++++++++++++++++ database/update.sql | 4 +++ public/index.php | 4 +-- update.sh | 1 + update_dev.sh | 6 ++++ 28 files changed, 154 insertions(+), 29 deletions(-) create mode 100644 config/cors.php create mode 100755 update_dev.sh diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php index 2c973d14..5a53cd3b 100755 --- a/app/Exceptions/Handler.php +++ b/app/Exceptions/Handler.php @@ -2,8 +2,8 @@ namespace App\Exceptions; -use Exception; use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler; +use Throwable; class Handler extends ExceptionHandler { @@ -29,10 +29,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); } @@ -40,16 +42,14 @@ class Handler extends ExceptionHandler /** * Render an exception into an HTTP response. * - * @param \Illuminate\Http\Request $request - * @param \Exception $exception - * @return \Illuminate\Http\Response + * @param \Illuminate\Http\Request $request + * @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 \Illuminate\Http\Exceptions\ThrottleRequestsException) { - abort(429, '请求频繁,请稍后再试'); - } return parent::render($request, $exception); } - } diff --git a/app/Http/Controllers/User/ServerController.php b/app/Http/Controllers/User/ServerController.php index 4ab8890c..7602bc53 100644 --- a/app/Http/Controllers/User/ServerController.php +++ b/app/Http/Controllers/User/ServerController.php @@ -36,16 +36,16 @@ class ServerController extends Controller $current = $request->input('current') ? $request->input('current') : 1; $pageSize = $request->input('pageSize') >= 10 ? $request->input('pageSize') : 10; $serverLogModel = ServerLog::where('user_id', $request->session()->get('id')) - ->orderBy('created_at', 'DESC'); + ->orderBy('log_at', 'DESC'); switch ($type) { case 0: - $serverLogModel->where('created_at', '>=', strtotime(date('Y-m-d'))); + $serverLogModel->where('log_at', '>=', strtotime(date('Y-m-d'))); break; case 1: - $serverLogModel->where('created_at', '>=', strtotime(date('Y-m-d')) - 604800); + $serverLogModel->where('log_at', '>=', strtotime(date('Y-m-d')) - 604800); break; case 2: - $serverLogModel->where('created_at', '>=', strtotime(date('Y-m-1'))); + $serverLogModel->where('log_at', '>=', strtotime(date('Y-m-1'))); } $total = $serverLogModel->count(); $res = $serverLogModel->forPage($current, $pageSize) diff --git a/app/Models/Coupon.php b/app/Models/Coupon.php index f9a912fb..a8481d3f 100644 --- a/app/Models/Coupon.php +++ b/app/Models/Coupon.php @@ -9,4 +9,8 @@ class Coupon extends Model protected $table = 'v2_coupon'; protected $dateFormat = 'U'; protected $guarded = ['id']; + protected $casts = [ + 'created_at' => 'timestamp', + 'updated_at' => 'timestamp' + ]; } diff --git a/app/Models/InviteCode.php b/app/Models/InviteCode.php index 1f1228ea..8489897a 100644 --- a/app/Models/InviteCode.php +++ b/app/Models/InviteCode.php @@ -8,4 +8,8 @@ class InviteCode extends Model { protected $table = 'v2_invite_code'; protected $dateFormat = 'U'; + protected $casts = [ + 'created_at' => 'timestamp', + 'updated_at' => 'timestamp' + ]; } diff --git a/app/Models/Knowledge.php b/app/Models/Knowledge.php index a441172c..d24f46c6 100644 --- a/app/Models/Knowledge.php +++ b/app/Models/Knowledge.php @@ -9,4 +9,8 @@ class Knowledge extends Model protected $table = 'v2_knowledge'; protected $dateFormat = 'U'; protected $guarded = ['id']; + protected $casts = [ + 'created_at' => 'timestamp', + 'updated_at' => 'timestamp' + ]; } diff --git a/app/Models/MailLog.php b/app/Models/MailLog.php index 80b501f8..0aef380e 100644 --- a/app/Models/MailLog.php +++ b/app/Models/MailLog.php @@ -9,4 +9,8 @@ class MailLog extends Model protected $table = 'v2_mail_log'; protected $dateFormat = 'U'; protected $guarded = ['id']; + protected $casts = [ + 'created_at' => 'timestamp', + 'updated_at' => 'timestamp' + ]; } diff --git a/app/Models/Notice.php b/app/Models/Notice.php index 103642d0..e4d3485d 100644 --- a/app/Models/Notice.php +++ b/app/Models/Notice.php @@ -9,4 +9,8 @@ class Notice extends Model protected $table = 'v2_notice'; protected $dateFormat = 'U'; protected $guarded = ['id']; + protected $casts = [ + 'created_at' => 'timestamp', + 'updated_at' => 'timestamp' + ]; } diff --git a/app/Models/Order.php b/app/Models/Order.php index 9d414636..f7274b36 100755 --- a/app/Models/Order.php +++ b/app/Models/Order.php @@ -9,4 +9,8 @@ class Order extends Model protected $table = 'v2_order'; protected $dateFormat = 'U'; protected $guarded = ['id']; + protected $casts = [ + 'created_at' => 'timestamp', + 'updated_at' => 'timestamp' + ]; } diff --git a/app/Models/Payment.php b/app/Models/Payment.php index 58b92b20..de2dceab 100644 --- a/app/Models/Payment.php +++ b/app/Models/Payment.php @@ -9,4 +9,8 @@ class Payment extends Model protected $table = 'v2_payment'; protected $dateFormat = 'U'; protected $guarded = ['id']; + protected $casts = [ + 'created_at' => 'timestamp', + 'updated_at' => 'timestamp' + ]; } diff --git a/app/Models/Plan.php b/app/Models/Plan.php index 67054df0..46843964 100755 --- a/app/Models/Plan.php +++ b/app/Models/Plan.php @@ -9,4 +9,8 @@ class Plan extends Model protected $table = 'v2_plan'; protected $dateFormat = 'U'; protected $guarded = ['id']; + protected $casts = [ + 'created_at' => 'timestamp', + 'updated_at' => 'timestamp' + ]; } diff --git a/app/Models/Server.php b/app/Models/Server.php index c7bda2e1..2e60921a 100755 --- a/app/Models/Server.php +++ b/app/Models/Server.php @@ -9,4 +9,8 @@ class Server extends Model protected $table = 'v2_server'; protected $dateFormat = 'U'; protected $guarded = ['id']; + protected $casts = [ + 'created_at' => 'timestamp', + 'updated_at' => 'timestamp' + ]; } diff --git a/app/Models/ServerGroup.php b/app/Models/ServerGroup.php index 0f59d01f..24d38bf9 100755 --- a/app/Models/ServerGroup.php +++ b/app/Models/ServerGroup.php @@ -8,4 +8,8 @@ class ServerGroup extends Model { protected $table = 'v2_server_group'; protected $dateFormat = 'U'; + protected $casts = [ + 'created_at' => 'timestamp', + 'updated_at' => 'timestamp' + ]; } diff --git a/app/Models/ServerLog.php b/app/Models/ServerLog.php index 231e157e..ef3590c2 100644 --- a/app/Models/ServerLog.php +++ b/app/Models/ServerLog.php @@ -9,4 +9,8 @@ class ServerLog extends Model { protected $table = 'v2_server_log'; protected $dateFormat = 'U'; + protected $casts = [ + 'created_at' => 'timestamp', + 'updated_at' => 'timestamp' + ]; } diff --git a/app/Models/ServerShadowsocks.php b/app/Models/ServerShadowsocks.php index 3dcc082f..f263c5ea 100644 --- a/app/Models/ServerShadowsocks.php +++ b/app/Models/ServerShadowsocks.php @@ -9,4 +9,8 @@ class ServerShadowsocks extends Model protected $table = 'v2_server_shadowsocks'; protected $dateFormat = 'U'; protected $guarded = ['id']; + protected $casts = [ + 'created_at' => 'timestamp', + 'updated_at' => 'timestamp' + ]; } diff --git a/app/Models/ServerStat.php b/app/Models/ServerStat.php index 0a08640b..5006dedd 100644 --- a/app/Models/ServerStat.php +++ b/app/Models/ServerStat.php @@ -9,4 +9,8 @@ class ServerStat extends Model protected $table = 'v2_server_stat'; protected $dateFormat = 'U'; protected $guarded = ['id']; + protected $casts = [ + 'created_at' => 'timestamp', + 'updated_at' => 'timestamp' + ]; } diff --git a/app/Models/ServerTrojan.php b/app/Models/ServerTrojan.php index 28c7c9cf..52a1e882 100644 --- a/app/Models/ServerTrojan.php +++ b/app/Models/ServerTrojan.php @@ -9,4 +9,8 @@ class ServerTrojan extends Model protected $table = 'v2_server_trojan'; protected $dateFormat = 'U'; protected $guarded = ['id']; + protected $casts = [ + 'created_at' => 'timestamp', + 'updated_at' => 'timestamp' + ]; } diff --git a/app/Models/StatOrder.php b/app/Models/StatOrder.php index cf661616..f0340a21 100644 --- a/app/Models/StatOrder.php +++ b/app/Models/StatOrder.php @@ -9,4 +9,8 @@ class StatOrder extends Model protected $table = 'v2_stat_order'; protected $dateFormat = 'U'; protected $guarded = ['id']; + protected $casts = [ + 'created_at' => 'timestamp', + 'updated_at' => 'timestamp' + ]; } diff --git a/app/Models/StatServer.php b/app/Models/StatServer.php index 70d23b45..4ffa9b1a 100644 --- a/app/Models/StatServer.php +++ b/app/Models/StatServer.php @@ -9,4 +9,8 @@ class StatServer extends Model protected $table = 'v2_stat_server'; protected $dateFormat = 'U'; protected $guarded = ['id']; + protected $casts = [ + 'created_at' => 'timestamp', + 'updated_at' => 'timestamp' + ]; } diff --git a/app/Models/Ticket.php b/app/Models/Ticket.php index 7f1ead31..cd266639 100644 --- a/app/Models/Ticket.php +++ b/app/Models/Ticket.php @@ -9,4 +9,8 @@ class Ticket extends Model protected $table = 'v2_ticket'; protected $dateFormat = 'U'; protected $guarded = ['id']; + protected $casts = [ + 'created_at' => 'timestamp', + 'updated_at' => 'timestamp' + ]; } diff --git a/app/Models/TicketMessage.php b/app/Models/TicketMessage.php index c45110cb..4673b33e 100644 --- a/app/Models/TicketMessage.php +++ b/app/Models/TicketMessage.php @@ -9,4 +9,8 @@ class TicketMessage extends Model protected $table = 'v2_ticket_message'; protected $dateFormat = 'U'; protected $guarded = ['id']; + protected $casts = [ + 'created_at' => 'timestamp', + 'updated_at' => 'timestamp' + ]; } diff --git a/app/Models/User.php b/app/Models/User.php index cb118056..01c3eb51 100755 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -9,4 +9,8 @@ class User extends Model protected $table = 'v2_user'; protected $dateFormat = 'U'; protected $guarded = ['id']; + protected $casts = [ + 'created_at' => 'timestamp', + 'updated_at' => 'timestamp' + ]; } diff --git a/app/Services/OrderService.php b/app/Services/OrderService.php index e5fd0ff7..d7351282 100644 --- a/app/Services/OrderService.php +++ b/app/Services/OrderService.php @@ -196,7 +196,7 @@ class OrderService private function orderIsUsed(Order $order):bool { $month = self::STR_TO_TIME[$order->cycle]; - $orderExpireDay = strtotime('+' . $month . ' month', $order->created_at->timestamp); + $orderExpireDay = strtotime('+' . $month . ' month', $order->created_at); if ($orderExpireDay < time()) return true; return false; } diff --git a/composer.json b/composer.json index 5ca2c66c..ac57f427 100755 --- a/composer.json +++ b/composer.json @@ -1,31 +1,35 @@ { "name": "v2board/v2board", "type": "project", - "description": "v2board is a v2ray manage.", + "description": "v2board is a proxy protocol manage.", "keywords": [ "v2board", "v2ray", + "shadowsocks", + "trojan", "laravel" ], "license": "MIT", "require": { - "php": "^7.2", - "fideloper/proxy": "^4.0", + "php": "^7.2.5|^8.0", + "fideloper/proxy": "^4.4", + "fruitcake/laravel-cors": "^2.0", + "guzzlehttp/guzzle": "^6.3.1|^7.0.1", + "laravel/framework": "^7.29", + "laravel/tinker": "^2.5", "google/recaptcha": "^1.2", - "laravel/framework": "^6.0", - "laravel/tinker": "^1.0", - "lokielse/omnipay-alipay": "3.0.6", + "lokielse/omnipay-alipay": "3.1.2", "lokielse/omnipay-wechatpay": "^3.0", "php-curl-class/php-curl-class": "^8.6", "stripe/stripe-php": "^7.36.1", "symfony/yaml": "^4.3" }, "require-dev": { - "facade/ignition": "^1.4", - "fzaninotto/faker": "^1.4", - "mockery/mockery": "^1.0", - "nunomaduro/collision": "^3.0", - "phpunit/phpunit": "^8.0" + "facade/ignition": "^2.0", + "fakerphp/faker": "^1.9.1", + "mockery/mockery": "^1.3.1", + "nunomaduro/collision": "^4.3", + "phpunit/phpunit": "^8.5.8|^9.3.3" }, "config": { "optimize-autoloader": true, diff --git a/config/cors.php b/config/cors.php new file mode 100644 index 00000000..558369dc --- /dev/null +++ b/config/cors.php @@ -0,0 +1,34 @@ + ['api/*'], + + 'allowed_methods' => ['*'], + + 'allowed_origins' => ['*'], + + 'allowed_origins_patterns' => [], + + 'allowed_headers' => ['*'], + + 'exposed_headers' => [], + + 'max_age' => 0, + + 'supports_credentials' => false, + +]; diff --git a/database/update.sql b/database/update.sql index 9f35b429..feb36c38 100644 --- a/database/update.sql +++ b/database/update.sql @@ -428,3 +428,7 @@ ALTER TABLE `v2_user` ALTER TABLE `v2_order` ADD `paid_at` int(11) NULL AFTER `commission_balance`; + +ALTER TABLE `v2_server_log` + ADD INDEX `user_id` (`user_id`), +ADD INDEX `server_id` (`server_id`); diff --git a/public/index.php b/public/index.php index f9ea6927..4584cbcd 100755 --- a/public/index.php +++ b/public/index.php @@ -21,7 +21,7 @@ define('LARAVEL_START', microtime(true)); | */ -require __DIR__ . '/../vendor/autoload.php'; +require __DIR__.'/../vendor/autoload.php'; /* |-------------------------------------------------------------------------- @@ -35,7 +35,7 @@ require __DIR__ . '/../vendor/autoload.php'; | */ -$app = require_once __DIR__ . '/../bootstrap/app.php'; +$app = require_once __DIR__.'/../bootstrap/app.php'; /* |-------------------------------------------------------------------------- diff --git a/update.sh b/update.sh index ee46c6a6..82df02b8 100755 --- a/update.sh +++ b/update.sh @@ -1,4 +1,5 @@ git fetch --all && git reset --hard origin/master && git pull origin master +rm -rf composer.lock php composer.phar update -vvv php artisan v2board:update php artisan config:cache diff --git a/update_dev.sh b/update_dev.sh new file mode 100755 index 00000000..abbb094b --- /dev/null +++ b/update_dev.sh @@ -0,0 +1,6 @@ +git fetch --all && git reset --hard origin/dev && git pull origin dev +rm -rf composer.lock +php composer.phar update -vvv +php artisan v2board:update +php artisan config:cache +pm2 restart pm2.yaml