Parcourir la source

Merge pull request #2080 from sspanel-uim/dev

Dev 20230715
M1Screw il y a 2 ans
Parent
commit
4af8b3c3fb

+ 2 - 2
README.md

@@ -1,4 +1,4 @@
-<img src="public/images/uim-logo-round_192x192.png" alt="logo" width="192" height="192" align="left" />
+<img src="public/images/uim-logo-round_192x192.png" alt="logo" width="150" height="150" align="left" />
 
 <h1>SSPanel UIM</h1>
 
@@ -41,7 +41,7 @@ SSPanel UIM 的需要以下程序才能正常的安装和运行:
 - MariaDB 10.6+(关闭严格模式,不兼容 MySQL/Disable strict mode, DO NOT USE MYSQL)
 - Redis 7.0+
 
-我们推荐用户在开始使用之前至少有一定程度的 PHP 和 Linux 使用知识,能够至少正确识别使用中所出现的问题并在 issue 中提供所需的信息。
+我们推荐用户在开始使用之前有一定程度的 PHP 和 Linux 使用知识,能够至少正确识别使用中所出现的问题并在 issue 中提供所需的信息。
 
 对于拒绝阅读文档且拒绝提供任何反馈的,我们建议其使用其他非开源的方案。
 

+ 0 - 1
composer.json

@@ -36,7 +36,6 @@
         "smarty/smarty": "^4",
         "srmklive/paypal": "~3.0",
         "stripe/stripe-php": "^10",
-        "symfony/console": "*",
         "symfony/yaml": "^6",
         "tronovav/geoip2-update": "^2.1",
         "vectorface/googleauthenticator": "^3.0",

+ 19 - 19
composer.lock

@@ -4,7 +4,7 @@
         "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
         "This file is @generated automatically"
     ],
-    "content-hash": "544143e8d800119b070bee10560449b4",
+    "content-hash": "ecc7da4619d8760e9d1240cb2099a50c",
     "packages": [
         {
             "name": "anankke/omnipay-alipay",
@@ -123,16 +123,16 @@
         },
         {
             "name": "aws/aws-sdk-php",
-            "version": "3.275.6",
+            "version": "3.275.7",
             "source": {
                 "type": "git",
                 "url": "https://github.com/aws/aws-sdk-php.git",
-                "reference": "a048b1d7110f62fb67cc69b93efc24e62ea8b64b"
+                "reference": "54dcef3349c81b46c0f5f6e54b5f9bfb5db19903"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/aws/aws-sdk-php/zipball/a048b1d7110f62fb67cc69b93efc24e62ea8b64b",
-                "reference": "a048b1d7110f62fb67cc69b93efc24e62ea8b64b",
+                "url": "https://api.github.com/repos/aws/aws-sdk-php/zipball/54dcef3349c81b46c0f5f6e54b5f9bfb5db19903",
+                "reference": "54dcef3349c81b46c0f5f6e54b5f9bfb5db19903",
                 "shasum": ""
             },
             "require": {
@@ -212,9 +212,9 @@
             "support": {
                 "forum": "https://forums.aws.amazon.com/forum.jspa?forumID=80",
                 "issues": "https://github.com/aws/aws-sdk-php/issues",
-                "source": "https://github.com/aws/aws-sdk-php/tree/3.275.6"
+                "source": "https://github.com/aws/aws-sdk-php/tree/3.275.7"
             },
-            "time": "2023-07-11T04:45:11+00:00"
+            "time": "2023-07-13T18:21:04+00:00"
         },
         {
             "name": "bacon/bacon-qr-code",
@@ -4813,16 +4813,16 @@
         },
         {
             "name": "stripe/stripe-php",
-            "version": "v10.16.0",
+            "version": "v10.17.0",
             "source": {
                 "type": "git",
                 "url": "https://github.com/stripe/stripe-php.git",
-                "reference": "ea863a92102a8e8dbdeddf79b4535c355ec62d91"
+                "reference": "73383b44de153f4d602b90dad3ef075259bcecef"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/stripe/stripe-php/zipball/ea863a92102a8e8dbdeddf79b4535c355ec62d91",
-                "reference": "ea863a92102a8e8dbdeddf79b4535c355ec62d91",
+                "url": "https://api.github.com/repos/stripe/stripe-php/zipball/73383b44de153f4d602b90dad3ef075259bcecef",
+                "reference": "73383b44de153f4d602b90dad3ef075259bcecef",
                 "shasum": ""
             },
             "require": {
@@ -4868,9 +4868,9 @@
             ],
             "support": {
                 "issues": "https://github.com/stripe/stripe-php/issues",
-                "source": "https://github.com/stripe/stripe-php/tree/v10.16.0"
+                "source": "https://github.com/stripe/stripe-php/tree/v10.17.0"
             },
-            "time": "2023-06-29T23:40:49+00:00"
+            "time": "2023-07-13T22:12:18+00:00"
         },
         {
             "name": "symfony/console",
@@ -8363,16 +8363,16 @@
         },
         {
             "name": "phpunit/phpunit",
-            "version": "10.2.4",
+            "version": "10.2.5",
             "source": {
                 "type": "git",
                 "url": "https://github.com/sebastianbergmann/phpunit.git",
-                "reference": "68484779b5a2ed711fbdeba6ca01910d87acdff2"
+                "reference": "15a89f123d8ca9c1e1598d6d87a56a8bf28c72cd"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/68484779b5a2ed711fbdeba6ca01910d87acdff2",
-                "reference": "68484779b5a2ed711fbdeba6ca01910d87acdff2",
+                "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/15a89f123d8ca9c1e1598d6d87a56a8bf28c72cd",
+                "reference": "15a89f123d8ca9c1e1598d6d87a56a8bf28c72cd",
                 "shasum": ""
             },
             "require": {
@@ -8444,7 +8444,7 @@
             "support": {
                 "issues": "https://github.com/sebastianbergmann/phpunit/issues",
                 "security": "https://github.com/sebastianbergmann/phpunit/security/policy",
-                "source": "https://github.com/sebastianbergmann/phpunit/tree/10.2.4"
+                "source": "https://github.com/sebastianbergmann/phpunit/tree/10.2.5"
             },
             "funding": [
                 {
@@ -8460,7 +8460,7 @@
                     "type": "tidelift"
                 }
             ],
-            "time": "2023-07-10T04:06:08+00:00"
+            "time": "2023-07-14T04:18:47+00:00"
         },
         {
             "name": "psr/cache",

+ 0 - 25
console

@@ -1,25 +0,0 @@
-#!/usr/bin/env php
-<?php
-
-declare(strict_types=1);
-
-use App\Services\Boot;
-use Symfony\Component\Console\Application;
-
-require __DIR__ . '/app/predefine.php';
-require __DIR__ . '/vendor/autoload.php';
-require __DIR__ . '/config/.config.php';
-
-Boot::setTime();
-Boot::bootSentry();
-Boot::bootDb();
-
-$application = new Application();
-
-// ... register commands
-
-try {
-    $application->run();
-} catch (Exception $e) {
-    echo $e->getMessage();
-}

+ 0 - 53
install.sh

@@ -1,53 +0,0 @@
-#!/usr/bin/bash
-
-[ $(id -u) != "0" ] && { echo "Error: You must be root to run this script!"; exit 1; }
-
-do_install_sspanel() {
-    read -p "Please input root password of your Database server: " db_root_password
-    read -p "Please input db_host(127.0.0.1): " db_host
-    read -p "Please input db_database(sspanel): " db_database
-    read -p "Please input db_username(sspanel): " db_username
-    read -p "Please input db_password: " db_password
-    read -p "Please input key: " key
-    read -p "Please input appName(SSPanel-UIM): " app_name
-    read -p "Please input baseUrl(https://example.com): " base_url
-    read -p "Please input muKey(SSPanel): " mu_key
-
-    echo "Generating config files..."
-    cp config/.config.example.php config/.config.php
-    cp config/appprofile.example.php config/appprofile.php
-    echo "Installing Composer..."
-    wget https://getcomposer.org/installer -O composer.phar
-    php composer.phar
-    php composer.phar install --no-dev
-    echo "Writing configuration..."
-    sed -i -e "s/$_ENV['key']        = 'ChangeMe';/$_ENV['key']        = '$key';/g" \
-    -e "s/$_ENV['appName']    = 'SSPanel-UIM';/$_ENV['appName']    = '$app_name';/g" \
-    -e "s|$_ENV['baseUrl']    = 'https://example.com';|$_ENV['baseUrl']    = '$base_url';|g" \
-    -e "s/$_ENV['muKey']      = 'SSPanel';/$_ENV['muKey']      = '$mu_key';/g" \
-    -e "s/$_ENV['db_host']      = '';/$_ENV['db_host']      = '$db_host';/g" \
-    -e "s/$_ENV['db_database']  = 'sspanel';/$_ENV['db_database']  = '$db_database';/g" \
-    -e "s/$_ENV['db_username']  = 'root';/$_ENV['db_username']  = '$db_username';/g" \
-    -e "s/$_ENV['db_password']  = 'sspanel';/$_ENV['db_password']  = '$db_password';/g" \
-    config/.config.php
-    echo "Creating database and user..."
-    mysql -uroot -p $db_root_password \
-    -e "CREATE DATABASE $db_database CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-    CREATE USER '$db_username'@'localhost';
-    GRANT ALL PRIVILEGES ON $db_database.* TO '$db_username'@'localhost' IDENTIFIED BY '$db_password';
-    FLUSH PRIVILEGES;"
-    echo "Importing config to database..."
-    php xcat Migration new
-    php xcat Tool importAllSettings
-    current_dir=$(pwd)
-    crontab -l > cron.tmp
-    echo "*/5 * * * * /usr/bin/php $current_dir/xcat Cron" >> cron.tmp
-    crontab cron.tmp
-    rm cron.tmp
-    echo "Updating File Permission..."
-    chmod 755 -R *
-    chown www -R *
-    echo "Installation completed! Now you can create your first admin user by running 'php xcat createAdmin'."
-}
-
-do_install_sspanel

+ 1 - 0
public/index.php

@@ -36,4 +36,5 @@ $routes($app);
 
 $request = ServerRequest::fromGlobals();
 $request = new Slim\Http\ServerRequest($request);
+
 $app->run($request);

+ 0 - 0
resources/lang/en-US.json → resources/locale/en-US.json


+ 0 - 0
resources/lang/ja-JP.json → resources/locale/ja-JP.json


+ 0 - 0
resources/lang/zh-CN.json → resources/locale/zh-CN.json


+ 0 - 0
resources/lang/zh-TW.json → resources/locale/zh-TW.json


+ 27 - 62
src/Controllers/Admin/CouponController.php

@@ -25,16 +25,16 @@ final class CouponController extends BaseController
     public static array $details = [
         'field' => [
             'op' => '操作',
-            'id' => '优惠码ID',
+            'id' => 'ID',
             'code' => '优惠码',
-            'type' => '优惠码类型',
-            'value' => '优惠码额度',
+            'type' => '类型',
+            'value' => '额度',
             'product_id' => '可用商品ID',
-            'use_time' => '每个用户可使用次数限制',
-            'total_use_time' => '累计可使用次数限制',
+            'use_time' => '使用次数(每用户)',
+            'total_use_time' => '使用次数(累计)',
             'new_user' => '仅限新用户使用',
             'disabled' => '已禁用',
-            'use_count' => '累计使用次数',
+            'use_count' => '使用次数',
             'create_time' => '创建时间',
             'expire_time' => '过期时间',
         ],
@@ -136,24 +136,10 @@ final class CouponController extends BaseController
             ]);
         }
 
-        if ($type === '') {
+        if ($type === '' || $value === '' || ($expire_time !== '' && $expire_time < time())) {
             return $response->withJson([
                 'ret' => 0,
-                'msg' => '优惠码类型不能为空',
-            ]);
-        }
-
-        if ($value === '') {
-            return $response->withJson([
-                'ret' => 0,
-                'msg' => '优惠码额度不能为空',
-            ]);
-        }
-
-        if ($expire_time !== '' && $expire_time < time()) {
-            return $response->withJson([
-                'ret' => 0,
-                'msg' => '到期时间不能小于当前时间',
+                'msg' => '无效的优惠码参数',
             ]);
         }
 
@@ -204,11 +190,13 @@ final class CouponController extends BaseController
         $coupon->content = json_encode($content);
         $coupon->limit = json_encode($limit);
         $coupon->create_time = time();
+
         if ($expire_time !== '') {
             $coupon->expire_time = $expire_time;
         } else {
             $coupon->expire_time = 0;
         }
+
         $coupon->save();
 
         return $response->withJson([
@@ -221,6 +209,7 @@ final class CouponController extends BaseController
     {
         $coupon_id = $args['id'];
         UserCoupon::find($coupon_id)->delete();
+
         return $response->withJson([
             'ret' => 1,
             'msg' => '删除成功',
@@ -235,6 +224,7 @@ final class CouponController extends BaseController
         $limit->disabled = 1;
         $coupon->limit = json_encode($limit);
         $coupon->save();
+
         return $response->withJson([
             'ret' => 1,
             'msg' => '禁用成功',
@@ -247,54 +237,29 @@ final class CouponController extends BaseController
     public function ajax(ServerRequest $request, Response $response, array $args): Response|ResponseInterface
     {
         $coupons = UserCoupon::orderBy('id', 'desc')->get();
+
         foreach ($coupons as $coupon) {
             $content = json_decode($coupon->content);
             $limit = json_decode($coupon->limit);
-            if ($limit->disabled === 1) {
-                $coupon->op = '<button type="button" class="btn btn-red" id="delete-coupon-' . $coupon->id . '" 
-                onclick="deleteCoupon(' . $coupon->id . ')">删除</button>';
-            } else {
-                $coupon->op = '<button type="button" class="btn btn-red" id="delete-coupon-' . $coupon->id . '" 
-                onclick="deleteCoupon(' . $coupon->id . ')">删除</button>
-                <button type="button" class="btn btn-orange" id="disable-coupon-' . $coupon->id . '" 
-                onclick="disableCoupon(' . $coupon->id . ')">禁用</button>';
-            }
+
+            $coupon->op = '<button type="button" class="btn btn-red" id="delete-coupon-' . $coupon->id . '"
+                onclick="deleteCoupon(' . $coupon->id . ')">删除</button>' .
+                ($limit->disabled !== 1 ? '
+                <button type="button" class="btn btn-orange" id="disable-coupon-' .
+                    $coupon->id . '" onclick="disableCoupon(' . $coupon->id . ')">禁用</button>' : '');
+
             $coupon->type = $coupon->type();
             $coupon->value = $content->value;
             $coupon->product_id = $limit->product_id;
-
-            if ((int) $limit->use_time < 0) {
-                $coupon->use_time = '不限次数';
-            } else {
-                $coupon->use_time = $limit->use_time;
-            }
-
-            if (! property_exists($limit, 'total_use_time') || (int) $limit->total_use_time < 0) {
-                $coupon->total_use_time = '不限次数';
-            } else {
-                $coupon->total_use_time = $limit->total_use_time;
-            }
-
-            if ($limit->new_user === 1) {
-                $coupon->new_user = '是';
-            } else {
-                $coupon->new_user = '否';
-            }
-
-            if ($limit->disabled === 1) {
-                $coupon->disabled = '是';
-            } else {
-                $coupon->disabled = '否';
-            }
-
+            $coupon->use_time = (int) $limit->use_time < 0 ? '不限次数' : $limit->use_time;
+            $coupon->total_use_time = ! property_exists($limit, 'total_use_time') ||
+                (int) $limit->total_use_time < 0 ? '不限次数' : $limit->total_use_time;
+            $coupon->new_user = $limit->new_user === 1 ? '是' : '否';
+            $coupon->disabled = $limit->disabled === 1 ? '是' : '否';
             $coupon->create_time = Tools::toDateTime((int) $coupon->create_time);
-
-            if ($coupon->expire_time === 0) {
-                $coupon->expire_time = '永久有效';
-            } else {
-                $coupon->expire_time = Tools::toDateTime((int) $coupon->expire_time);
-            }
+            $coupon->expire_time = $coupon->expire_time === 0 ? '永久有效' : Tools::toDateTime((int) $coupon->expire_time);
         }
+
         return $response->withJson([
             'coupons' => $coupons,
         ]);

+ 13 - 40
src/Controllers/LinkController.php

@@ -59,50 +59,23 @@ final class LinkController extends BaseController
         }
 
         $user = $link->user();
-
         $params = $request->getQueryParams();
-        $sub_type = '';
-        $sub_info = '';
 
-        if (isset($params['clash']) && $params['clash'] === '1') {
-            $sub_type = 'clash';
-            $sub_info = SubController::getClash($user);
-        }
+        $subTypes = [
+            'sip002' => ['method' => 'getSIP002'],
+            'ss' => ['method' => 'getSS'],
+            'v2ray' => ['method' => 'getV2Ray'],
+            'trojan' => ['method' => 'getTrojan'],
+        ];
 
-        if (isset($params['sip002']) && $params['sip002'] === '1') {
-            $sub_type = 'sip002';
-            $sub_info = self::getSIP002($user);
-        }
-
-        if (isset($params['ss']) && $params['ss'] === '1') {
-            $sub_type = 'ss';
-            $sub_info = self::getSS($user);
-        }
-
-        if (isset($params['v2ray']) && $params['v2ray'] === '1') {
-            $sub_type = 'v2ray';
-            $sub_info = self::getV2Ray($user);
-        }
-
-        if (isset($params['trojan']) && $params['trojan'] === '1') {
-            $sub_type = 'trojan';
-            $sub_info = self::getTrojan($user);
-        }
+        $sub_type = '';
+        $sub_info = '';
 
-        if (isset($params['sub'])) {
-            switch ($params['sub']) {
-                case '3':
-                    $sub_type = 'v2ray';
-                    $sub_info = self::getV2Ray($user);
-                    break;
-                case '4':
-                    $sub_type = 'trojan';
-                    $sub_info = self::getTrojan($user);
-                    break;
-                default:
-                    $sub_type = 'ss';
-                    $sub_info = self::getSS($user);
-                    break;
+        foreach ($params as $key => $value) {
+            if (isset($subTypes[$key]) && $value === '1') {
+                $sub_type = $key;
+                $sub_info = self::{$subTypes[$key]['method']}($user);
+                break;
             }
         }
 

+ 2 - 0
src/Controllers/SubController.php

@@ -75,10 +75,12 @@ final class SubController extends BaseController
                 $sub_info,
             ]);
         }
+
         $sub_details = ' upload=' . $user->u
         . '; download=' . $user->d
         . '; total=' . $user->transfer_enable
         . '; expire=' . strtotime($user->class_expire);
+
         return $response->withHeader('Subscription-Userinfo', $sub_details)->write(
             $sub_info
         );

+ 15 - 24
src/Controllers/User/CouponController.php

@@ -24,27 +24,21 @@ final class CouponController extends BaseController
         $antiXss = new AntiXSS();
         $coupon_raw = $antiXss->xss_clean($request->getParam('coupon'));
         $product_id = $antiXss->xss_clean($request->getParam('product_id'));
+        $invalid_coupon_msg = '优惠码无效';
 
-        if ($coupon_raw === null || $coupon_raw === '') {
+        if ($coupon_raw === '') {
             return $response->withJson([
                 'ret' => 0,
-                'msg' => '优惠码不能为空',
+                'msg' => $invalid_coupon_msg,
             ]);
         }
 
         $coupon = UserCoupon::where('code', $coupon_raw)->first();
 
-        if ($coupon === null) {
+        if ($coupon === null || ($coupon->expire_time !== 0 && $coupon->expire_time < time())) {
             return $response->withJson([
                 'ret' => 0,
-                'msg' => '优惠码无效',
-            ]);
-        }
-
-        if ($coupon->expire_time !== 0 && $coupon->expire_time < time()) {
-            return $response->withJson([
-                'ret' => 0,
-                'msg' => '优惠码无效',
+                'msg' => $invalid_coupon_msg,
             ]);
         }
 
@@ -53,27 +47,24 @@ final class CouponController extends BaseController
         if ($product === null) {
             return $response->withJson([
                 'ret' => 0,
-                'msg' => '商品ID无效',
+                'msg' => $invalid_coupon_msg,
             ]);
         }
 
         $limit = json_decode($coupon->limit);
 
-        if ((int) $limit->disabled === 1) {
+        if ($limit->disabled) {
             return $response->withJson([
                 'ret' => 0,
-                'msg' => '优惠码无效',
+                'msg' => $invalid_coupon_msg,
             ]);
         }
 
-        if ($limit->product_id !== '') {
-            $product_limit = explode(',', $limit->product_id);
-            if (! in_array($product_id, $product_limit)) {
-                return $response->withJson([
-                    'ret' => 0,
-                    'msg' => '优惠码无效',
-                ]);
-            }
+        if ($limit->product_id !== '' && ! in_array($product_id, explode(',', $limit->product_id))) {
+            return $response->withJson([
+                'ret' => 0,
+                'msg' => $invalid_coupon_msg,
+            ]);
         }
 
         $user = $this->user;
@@ -84,7 +75,7 @@ final class CouponController extends BaseController
             if ($user_use_count >= $use_limit) {
                 return $response->withJson([
                     'ret' => 0,
-                    'msg' => '优惠码无效',
+                    'msg' => $invalid_coupon_msg,
                 ]);
             }
         }
@@ -94,7 +85,7 @@ final class CouponController extends BaseController
         if ($total_use_limit > 0 && $coupon->use_count >= $total_use_limit) {
             return $response->withJson([
                 'ret' => 0,
-                'msg' => '优惠码无效',
+                'msg' => $invalid_coupon_msg,
             ]);
         }
 

+ 9 - 19
src/Controllers/User/OrderController.php

@@ -125,17 +125,10 @@ final class OrderController extends BaseController
 
         $product = Product::find($product_id);
 
-        if ($product === null) {
+        if ($product === null || $product->stock === 0) {
             return $response->withJson([
                 'ret' => 0,
-                'msg' => '商品不存在',
-            ]);
-        }
-
-        if ($product->stock === 0) {
-            return $response->withJson([
-                'ret' => 0,
-                'msg' => '商品库存不足',
+                'msg' => '商品无效',
             ]);
         }
 
@@ -145,7 +138,7 @@ final class OrderController extends BaseController
         if ($coupon_raw !== '') {
             $coupon = UserCoupon::where('code', $coupon_raw)->first();
 
-            if ($coupon === null || $coupon->expire_time < time()) {
+            if ($coupon === null || ($coupon->expire_time !== 0 && $coupon->expire_time < time())) {
                 return $response->withJson([
                     'ret' => 0,
                     'msg' => '优惠码无效',
@@ -154,21 +147,18 @@ final class OrderController extends BaseController
 
             $coupon_limit = json_decode($coupon->limit);
 
-            if ((int) $coupon_limit->disabled === 1) {
+            if ($coupon_limit->disabled) {
                 return $response->withJson([
                     'ret' => 0,
                     'msg' => '优惠码无效',
                 ]);
             }
 
-            if ($coupon_limit->product_id !== '') {
-                $product_limit = explode(',', $coupon_limit->product_id);
-                if (! in_array($product_id, $product_limit)) {
-                    return $response->withJson([
-                        'ret' => 0,
-                        'msg' => '优惠码无效',
-                    ]);
-                }
+            if ($coupon_limit->product_id !== '' && ! in_array($product_id, explode(',', $coupon_limit->product_id))) {
+                return $response->withJson([
+                    'ret' => 0,
+                    'msg' => '优惠码无效',
+                ]);
             }
 
             $coupon_use_limit = $coupon_limit->use_time;

+ 2 - 2
update.sh

@@ -9,8 +9,6 @@ Usage:
 ./update.sh release $release_version $db_version --> Upgrade to the release version with the specified database version
 EOF
 
-[ $(id -u) != "0" ] && { echo "Error: You must be root to run this script!"; exit 1; }
-
 do_update_sspanel_dev(){
     git pull origin dev
     git reset --hard origin/dev
@@ -46,10 +44,12 @@ if [[ $1 == "release" ]]; then
         echo "Error: The release version cannot be empty!"
         exit 1
     fi
+
     if [[ $3 == "" ]]; then
         echo "Error: The database version cannot be empty!"
         exit 1
     fi
+
     do_update_sspanel_release $2 $3
     exit 0
 fi