فهرست منبع

refactor: backend captcha logic

Cat 3 سال پیش
والد
کامیت
cec8ba59da

+ 0 - 1
app/routes.php

@@ -126,7 +126,6 @@ return function (SlimApp $app): void {
         $this->post('/send', App\Controllers\AuthController::class . ':sendVerify');
         $this->get('/logout', App\Controllers\AuthController::class . ':logout');
         $this->get('/telegram_oauth', App\Controllers\AuthController::class . ':telegramOauth');
-        $this->get('/login_getCaptcha', App\Controllers\AuthController::class . ':getCaptcha');
     })->add(new Guest());
 
     // Password

+ 0 - 6
config/.config.example.php

@@ -205,12 +205,6 @@ $_ENV['flag_regex']           = '/.*?(?=\s)/';   //从站点全名中匹配【
 #捐赠
 $_ENV['enable_donate']        = true;          //是否显示用户捐赠(所有收入将被公开)
 
-#iOS账户显示
-$_ENV['display_ios_class']    = -1;        //至少等级为多少的用户可以看见,小于0时关闭此功能
-$_ENV['display_ios_topup']    = 0;         //满足等级要求后,累计充值高于多少的用户可以看见
-$_ENV['ios_account']          = '';        //iOS账户
-$_ENV['ios_password']         = '';        //iOS密码
-
 //节点检测-----------------------------------------------------------------------------------------------
 #GFW检测,请通过crontab进行【开启/关闭】
 $_ENV['detect_gfw_interval']             = 3600;                                                               //检测间隔,单位:秒,低于推荐值会爆炸

+ 0 - 1
phpinsights.php

@@ -44,6 +44,5 @@ return [
 
     'exclude' => [
         'storage',
-        'src/Utils/GeetestLib.php',
     ],
 ];

+ 0 - 4
public/theme/material/css/auth.css

@@ -161,10 +161,6 @@ a.boardtop-left:hover {
   position: relative;
 }
 
-.labelgeetest {
-  justify-content: center;
-}
-
 .auth-top a div:last-of-type {
   font-size: 13px;
 }

+ 0 - 17
public/theme/material/css/base.css

@@ -6833,23 +6833,6 @@ html.no-touchevents .tile:hover .tile-action {
   background: white;
 }
 
-/* geetest */
-
-#embed-captcha .geetest_holder.geetest_wind,
-#popup-captcha .geetest_holder.geetest_wind {
-  width: 100% !important;
-  min-width: unset;
-}
-
-#embed-captcha .geetest_holder.geetest_wind .geetest_radar_btn,
-#popup-captcha .geetest_holder.geetest_wind .geetest_radar_btn {
-  background: white;
-  background-image: unset;
-  box-shadow: 2px 3px 5px #e0e0e0;
-  border-radius: 5px;
-  min-width: unset;
-}
-
 .tgme_widget_login.large button.tgme_widget_login_button {
   max-width: 80%;
 }

+ 0 - 6
public/theme/material/css/index.css

@@ -471,12 +471,6 @@ select {
   min-height: 44px;
 }
 
-#embed-captcha-reg .geetest_btn {
-  margin-left: auto;
-  margin-right: auto;
-  width: 87%;
-}
-
 .auth-tg {
   margin-top: 2rem;
 }

+ 1 - 49
resources/views/material/auth/login.tpl

@@ -34,15 +34,10 @@
                     </div>
                 </div>
 
-                {if $config['enable_login_captcha'] == true && $config['captcha_provider'] == 'geetest'}
-                    <div class="form-group-label labelgeetest auth-row">
-                        <div id="embed-captcha"></div>
-                    </div>
-                {/if}
                 {if $config['enable_login_captcha'] == true && $config['captcha_provider'] == 'turnstile'}
                     <div class="form-group-label auth-row">
                         <div class="row">
-                            <div align="center" class="cf-turnstile" data-sitekey="{$turnstile_sitekey}" data-theme="light"></div>
+                            <div align="center" class="cf-turnstile" data-sitekey="{$captcha['turnstile_sitekey']}" data-theme="light"></div>
                         </div>
                     </div>
                 {/if}
@@ -104,14 +99,6 @@
 <script>
     $(document).ready(function () {
         function login() {
-            {if $geetest_html != null}
-            if (typeof validate === 'undefined' || !validate) {
-                $("#result").modal();
-                $$.getElementById('msg').innerHTML = '请滑动验证码来完成验证';
-                return;
-            }
-            {/if}
-
             document.getElementById("login").disabled = true;
 
             $.ajax({
@@ -122,11 +109,6 @@
                     {if $config['enable_login_captcha'] == true && $config['captcha_provider'] == 'turnstile'}
                     turnstile: turnstile.getResponse(),
                     {/if}
-                    {if $geetest_html != null}
-                    geetest_challenge: validate.geetest_challenge,
-                    geetest_validate: validate.geetest_validate,
-                    geetest_seccode: validate.geetest_seccode,
-                    {/if}
                     code: $$getValue('code'),
                     email: $$getValue('email'),
                     passwd: $$getValue('passwd'),
@@ -141,9 +123,6 @@
                         $("#result").modal();
                         $$.getElementById('msg').innerHTML = data.msg;
                         document.getElementById("login").disabled = false;
-                        {if $geetest_html != null}
-                        captcha.refresh();
-                        {/if}
                     }
                 },
                 error: (jqXHR) => {
@@ -153,9 +132,6 @@
                         jqXHR.status
                     }`;
                     document.getElementById("login").disabled = false;
-                    {if $geetest_html != null}
-                    captcha.refresh();
-                    {/if}
                 }
             });
         }
@@ -179,30 +155,6 @@
     })
 </script>
 
-{if $geetest_html != null}
-    <script>
-        var handlerEmbed = function (captchaObj) {
-            // 将验证码加到id为captcha的元素里
-
-            captchaObj.onSuccess(function () {
-                validate = captchaObj.getValidate();
-            });
-
-            captchaObj.appendTo("#embed-captcha");
-
-            captcha = captchaObj;
-            // 更多接口参考:http://www.geetest.com/install/sections/idx-client-sdk.html
-        };
-
-        initGeetest({
-            gt: "{$geetest_html->gt}",
-            challenge: "{$geetest_html->challenge}",
-            product: "embed", // 产品形式,包括:float,embed,popup。注意只对PC版验证码有效
-            offline: {if $geetest_html->success}0{else}1{/if} // 表示用户后台检测极验服务器是否宕机,与SDK配合,用户一般不需要关注
-        }, handlerEmbed);
-    </script>
-{/if}
-
 {if $config['enable_login_captcha'] == true && $config['captcha_provider'] == 'turnstile'}
 <script src="https://challenges.cloudflare.com/turnstile/v0/api.js?compat=recaptcha" async defer></script>
 {/if}

+ 1 - 64
resources/views/material/auth/register.tpl

@@ -111,17 +111,10 @@
                             </div>
                         </div>
                     {/if}
-                    {if $geetest_html != null}
-                        <div class="rowtocol">
-                            <div class="form-group form-group-label">
-                                <div id="embed-captcha"></div>
-                            </div>
-                        </div>
-                    {/if}
                     {if $config['enable_reg_captcha'] == true && $config['captcha_provider'] == 'turnstile'}
                         <div class="form-group form-group-label">
                             <div class="row">
-                                <div align="center" class="cf-turnstile" data-sitekey="{$turnstile_sitekey}" data-theme="light"></div>
+                                <div align="center" class="cf-turnstile" data-sitekey="{$captcha['turnstile_sitekey']}" data-theme="light"></div>
                             </div>
                         </div>
                     {/if}
@@ -263,11 +256,6 @@ document.getElementById('passwd').addEventListener('input', checkStrong);
                         {if $config['enable_reg_captcha'] == true && $config['captcha_provider'] == 'turnstile'}
                         turnstile: turnstile.getResponse(),
                         {/if}
-                        {if $geetest_html != null}
-                        geetest_challenge: validate.geetest_challenge,
-                        geetest_validate: validate.geetest_validate,
-                        geetest_seccode: validate.geetest_seccode,
-                        {/if}
                         {if $config['enable_reg_im'] == true}
                         im_value: $$getValue('im_value'),
                         im_type: $$getValue('im_type'),
@@ -292,9 +280,6 @@ document.getElementById('passwd').addEventListener('input', checkStrong);
                             setCookie('code', '', 0);
                             $("#code").val(getCookie('code'));
                             document.getElementById("tos").disabled = false;
-                            {if $geetest_html != null}
-                            captcha.refresh();
-                            {/if}
                         }
                     },
                     error: (jqXHR) => {
@@ -304,9 +289,6 @@ document.getElementById('passwd').addEventListener('input', checkStrong);
                                 jqXHR.status
                                 }`;
                         document.getElementById("tos").disabled = false;
-                        {if $geetest_html != null}
-                        captcha.refresh();
-                        {/if}
                     }
                 });
             }
@@ -317,32 +299,11 @@ document.getElementById('passwd').addEventListener('input', checkStrong);
                 }
             });
 
-            {if $geetest_html != null}
-            $('div.modal').on('shown.bs.modal', function () {
-                $("div.gt_slider_knob").hide();
-            });
-
-
-            $('div.modal').on('hidden.bs.modal', function () {
-                $("div.gt_slider_knob").show();
-            });
-
-
-            {/if}
-
             $("#reg").click(function () {
                 register();
             });
 
             $("#tos").click(function () {
-                {if $geetest_html != null}
-                if (typeof validate === 'undefined' || !validate) {
-                    $("#result").modal();
-                    $$.getElementById('msg').innerHTML = '请滑动验证码来完成验证'
-                    return;
-                }
-
-                {/if}
                 $("#tos_modal").modal();
             });
         })
@@ -402,30 +363,6 @@ document.getElementById('passwd').addEventListener('input', checkStrong);
     </script>
 {/if}
 
-{if $geetest_html != null}
-    <script>
-        var handlerEmbed = function (captchaObj) {
-            // 将验证码加到id为captcha的元素里
-
-            captchaObj.onSuccess(function () {
-                validate = captchaObj.getValidate();
-            });
-
-            captchaObj.appendTo("#embed-captcha");
-
-            captcha = captchaObj;
-            // 更多接口参考:http://www.geetest.com/install/sections/idx-client-sdk.html
-        };
-
-        initGeetest({
-            gt: "{$geetest_html->gt}",
-            challenge: "{$geetest_html->challenge}",
-            product: "embed", // 产品形式,包括:float,embed,popup。注意只对PC版验证码有效
-            offline: {if $geetest_html->success}0{else}1{/if} // 表示用户后台检测极验服务器是否宕机,与SDK配合,用户一般不需要关注
-        }, handlerEmbed);
-    </script>
-{/if}
-
 {if $config['enable_reg_captcha'] == true && $config['captcha_provider'] == 'turnstile'}
 <script src="https://challenges.cloudflare.com/turnstile/v0/api.js?compat=recaptcha" async defer></script>
 {/if}

+ 0 - 3
resources/views/material/footer.tpl

@@ -7,9 +7,6 @@
 
 <!-- js -->
 <script src="https://cdn.staticfile.org/jquery/3.6.1/jquery.min.js"></script>
-{if isset($geetest_html)}
-    <script src="//static.geetest.com/static/tools/gt.js"></script>
-{/if}
 <script src="/theme/material/js/base.min.js"></script>
 <script src="/theme/material/js/project.min.js"></script>
 

+ 1 - 1
resources/views/material/password/reset.tpl

@@ -25,7 +25,7 @@
             {if $config['enable_reset_password_captcha'] == true && $config['captcha_provider'] == 'turnstile'}
             <div class="form-group-label auth-row">
                 <div class="row">
-                    <div align="center" class="cf-turnstile" data-sitekey="{$turnstile_sitekey}" data-theme="light"></div>
+                    <div align="center" class="cf-turnstile" data-sitekey="{$captcha['turnstile_sitekey']}" data-theme="light"></div>
                 </div>
             </div>
             {/if}

+ 0 - 3
resources/views/material/user/footer.tpl

@@ -6,9 +6,6 @@
 </footer>
 
 <!-- js -->
-{if isset($geetest_html)}
-    <script src="//static.geetest.com/static/tools/gt.js"></script>
-{/if}
 <script src="/theme/material/js/base.min.js"></script>
 <script src="/theme/material/js/project.min.js"></script>
 <script src="//cdn.staticfile.org/clipboard.js/2.0.11/clipboard.min.js"></script>

+ 2 - 74
resources/views/material/user/index.tpl

@@ -212,11 +212,8 @@
                                 <p class="card-heading"><i class="mdi mdi-account-circle icon-md"></i> 签到</p>
                                 <p>上次签到时间:{$user->lastCheckInTime()}</p>
                                 <p id="checkin-msg"></p>
-                                {if $geetest_html != null}
-                                    <div id="popup-captcha"></div>
-                                {/if}
                                 {if $config['enable_checkin_captcha'] == true && $config['captcha_provider'] == 'turnstile' && $user->isAbleToCheckin()}
-                                    <div class="cf-turnstile" data-sitekey="{$turnstile_sitekey}" data-theme="light"></div>
+                                    <div class="cf-turnstile" data-sitekey="{$captcha['turnstile_sitekey']}" data-theme="light"></div>
                                 {/if}
                                 <div class="card-action">
                                     <div class="usercheck pull-left">
@@ -489,24 +486,6 @@
                                                 <hr/>
                                             </div>
                                             <div class="tab-pane fade" id="sub_center_ios">
-                                            {if $display_ios_class>=0}
-                                                {if $user->class>=$display_ios_class && $user->getTopUp()>=$display_ios_topup}
-                                                <div><span class="mdi mdi-account-box icon-lg text-white"></span> 本站iOS账户:</div>
-                                                <div class="float-clear">
-                                                    <input type="text" class="input form-control form-control-monospace cust-link col-xx-12 col-sm-8 col-lg-7" name="input1" readonly value="{$ios_account}" readonly="true">
-                                                    <button class="copy-text btn btn-subscription col-xx-12 col-sm-3 col-lg-2" type="button" data-clipboard-text="{$ios_account}">点击复制</button>
-                                                    <br>
-                                                </div>
-                                                <div><span class="mdi mdi-account-lock icon-lg text-white"></span> 本站iOS密码:</div>
-                                                <div class="float-clear">
-                                                    <input type="text" class="input form-control form-control-monospace cust-link col-xx-12 col-sm-8 col-lg-7" name="input1" readonly value="{$ios_password}" readonly="true">
-                                                    <button class="copy-text btn btn-subscription col-xx-12 col-sm-3 col-lg-2" type="button" data-clipboard-text="{$ios_password}">点击复制</button>
-                                                    <br>
-                                                </div>
-                                                <p><span class="mdi mdi-alert icon-lg text-white"></span><strong>禁止将账户分享给他人或登录 iCloud!</strong></p>
-                                                <hr/>
-                                                {/if}
-                                            {/if}
                                                 <p>Surge - [ SS/VMess ]:</p>
                                                     <p>
                                                         应用下载:
@@ -726,7 +705,6 @@
         $$.getElementById('msg').innerHTML = '您的流量已经用完或账户已经过期了,如需继续使用,请进入商店选购新的套餐~';
     };
     {/if}
-    {if $geetest_html == null}
     var checkedmsgGE = '<p><a class="btn btn-brand disabled btn-flat waves-attach" href="#"><span class="mdi mdi-check"></span>&nbsp;已签到</a></p>';
     $(document).ready(function () {
         $("#checkin").click(function () {
@@ -761,58 +739,8 @@
             })
         })
     })
-    {else}
-    var checkedmsgGE = '<p><a class="btn btn-brand disabled btn-flat waves-attach" href="#"><span class="mdi mdi-check"></span>&nbsp;已签到</a></p>';
-    var handlerPopup = function (captchaObj) {
-        c = captchaObj;
-        captchaObj.onSuccess(function () {
-            var validate = captchaObj.getValidate();
-            $.ajax({
-                url: "/user/checkin", // 进行二次验证
-                type: "post",
-                dataType: "json",
-                data: {
-                    // 二次验证所需的三个值
-                    geetest_challenge: validate.geetest_challenge,
-                    geetest_validate: validate.geetest_validate,
-                    geetest_seccode: validate.geetest_seccode
-                },
-                success: (data) => {
-                    if (data.ret) {
-                        $$.getElementById('checkin-msg').innerHTML = data.msg;
-                        $$.getElementById('checkin-btn').innerHTML = checkedmsgGE;
-                        $("#result").modal();
-                        $$.getElementById('msg').innerHTML = data.msg;
-                        $$.getElementById('remain').innerHTML = data.trafficInfo['unUsedTraffic'];
-                        $('.bar.remain.color').css('width', (data.unflowtraffic - ({$user->u}+{$user->d})) / data.unflowtraffic * 100 + '%');
-                    } else {
-                        $("#result").modal();
-                        $$.getElementById('msg').innerHTML = data.msg;
-                    }
-                },
-                error: (jqXHR) => {
-                    $("#result").modal();
-                    $$.getElementById('msg').innerHTML = `发生错误:${
-                            jqXHR.status
-                            }`;
-                }
-            });
-        });
-        // 弹出式需要绑定触发验证码弹出按钮
-        //captchaObj.bindOn("#checkin")
-        // 将验证码加到id为captcha的元素里
-        captchaObj.appendTo("#popup-captcha");
-        // 更多接口参考:http://www.geetest.com/install/sections/idx-client-sdk.html
-    };
-    initGeetest({
-        gt: "{$geetest_html->gt}",
-        challenge: "{$geetest_html->challenge}",
-        product: "popup", // 产品形式,包括:float,embed,popup。注意只对PC版验证码有效
-        offline: {if $geetest_html->success}0{else}1{/if} // 表示用户后台检测极验服务器是否宕机,与SDK配合,用户一般不需要关注
-    }, handlerPopup);
-    {/if}
 </script>
 
 {if $config['enable_checkin_captcha'] == true && $config['captcha_provider'] == 'turnstile'}
-    <script src="https://challenges.cloudflare.com/turnstile/v0/api.js?compat=recaptcha" async defer></script>
+<script src="https://challenges.cloudflare.com/turnstile/v0/api.js?compat=recaptcha" async defer></script>
 {/if}

+ 1 - 1
resources/views/tabler/auth/login.tpl

@@ -39,7 +39,7 @@
                     {if $config['enable_login_captcha'] == true && $config['captcha_provider'] == 'turnstile'}
                     <div class="mb-2">
                         <div class="input-group mb-2">
-                            <div class="cf-turnstile" data-sitekey="{$turnstile_sitekey}" data-theme="light"></div>
+                            <div class="cf-turnstile" data-sitekey="{$captcha['turnstile_sitekey']}" data-theme="light"></div>
                         </div>
                     </div>
                     {/if}

+ 1 - 1
resources/views/tabler/auth/register.tpl

@@ -70,7 +70,7 @@
                         {if $config['enable_reg_captcha'] == true && $config['captcha_provider'] == 'turnstile'}
                         <div class="mb-3">
                             <div class="input-group mb-2">
-                                <div class="cf-turnstile" data-sitekey="{$turnstile_sitekey}" data-theme="light"></div>
+                                <div class="cf-turnstile" data-sitekey="{$captcha['turnstile_sitekey']}" data-theme="light"></div>
                             </div>
                         </div>
                         {/if}

+ 0 - 3
resources/views/tabler/footer.tpl

@@ -7,9 +7,6 @@
 
 <!-- js -->
 <script src="https://cdn.staticfile.org/jquery/3.6.1/jquery.min.js"></script>
-{if isset($geetest_html)}
-    <script src="//static.geetest.com/static/tools/gt.js"></script>
-{/if}
 <script src="/theme/material/js/base.min.js"></script>
 <script src="/theme/material/js/project.min.js"></script>
 

+ 1 - 1
resources/views/tabler/password/reset.tpl

@@ -21,7 +21,7 @@
                     {if $config['enable_reg_captcha'] == true && $config['captcha_provider'] == 'turnstile'}
                     <div class="mb-3">
                         <div class="input-group mb-3">
-                            <div class="cf-turnstile" data-sitekey="{$turnstile_sitekey}" data-theme="light"></div>
+                            <div class="cf-turnstile" data-sitekey="{$captcha['turnstile_sitekey']}" data-theme="light"></div>
                         </div>
                     </div>
                     {/if}

+ 0 - 3
resources/views/tabler/user/footer.tpl

@@ -5,9 +5,6 @@
 </footer>
 
 <!-- js -->
-{if isset($geetest_html)}
-    <script src="//static.geetest.com/static/tools/gt.js"></script>
-{/if}
 <script src="/theme/material/js/base.min.js"></script>
 <script src="/theme/material/js/project.min.js"></script>
 <script src="https://cdn.staticfile.org/clipboard.js/2.0.6/clipboard.min.js"></script>

+ 1 - 1
resources/views/tabler/user/index.tpl

@@ -401,7 +401,7 @@
                             <div class="card-footer">
                                 <div class="d-flex">
                                     {if $config['enable_checkin_captcha'] == true && $config['captcha_provider'] == 'turnstile' && $user->isAbleToCheckin()}
-                                    <div class="cf-turnstile" data-sitekey="{$turnstile_sitekey}" data-theme="light"></div>
+                                    <div class="cf-turnstile" data-sitekey="{$captcha['turnstile_sitekey']}" data-theme="light"></div>
                                     {/if}
                                     {if !$user->isAbleToCheckin()}
                                     <button id="check-in" class="btn btn-primary ms-auto" disabled>已签到</button>

+ 13 - 32
src/Controllers/AuthController.php

@@ -33,7 +33,11 @@ final class AuthController extends BaseController
      */
     public function login(Request $request, Response $response, array $args)
     {
-        $captcha = Captcha::generate();
+        $captcha = [];
+
+        if (Setting::obtain('enable_login_captcha') === true) {
+            $captcha = Captcha::generate();
+        }
 
         if ($_ENV['enable_telegram_login'] === true) {
             $login_text = TelegramSessionManager::addLoginSession();
@@ -45,35 +49,15 @@ final class AuthController extends BaseController
             $login_number = '';
         }
 
-        if (Setting::obtain('enable_login_captcha') === true) {
-            $geetest_html = $captcha['geetest'];
-        } else {
-            $geetest_html = null;
-        }
-
         return $this->view()
             ->assign('login_token', $login_token)
-            ->assign('geetest_html', $geetest_html)
             ->assign('login_number', $login_number)
             ->assign('base_url', $_ENV['baseUrl'])
             ->assign('telegram_bot', $_ENV['telegram_bot'])
-            ->assign('turnstile_sitekey', $captcha['turnstile'])
+            ->assign('captcha', $captcha)
             ->display('auth/login.tpl');
     }
 
-    /**
-     * @param array     $args
-     */
-    public function getCaptcha(Request $request, Response $response, array $args)
-    {
-        $captcha = Captcha::generate();
-        return $response->withJson([
-            'turnstileKey' => $captcha['turnstile'],
-            'GtSdk' => $captcha['geetest'],
-            'respon' => 1,
-        ]);
-    }
-
     /**
      * @param array     $args
      */
@@ -163,6 +147,12 @@ final class AuthController extends BaseController
      */
     public function register(Request $request, Response $response, $next)
     {
+        $captcha = [];
+
+        if (Setting::obtain('enable_reg_captcha') === true) {
+            $captcha = Captcha::generate();
+        }
+
         $ary = $request->getQueryParams();
         $code = '';
         if (isset($ary['code'])) {
@@ -170,8 +160,6 @@ final class AuthController extends BaseController
             $code = $antiXss->xss_clean($ary['code']);
         }
 
-        $captcha = Captcha::generate();
-
         if ($_ENV['enable_telegram_login'] === true) {
             $login_text = TelegramSessionManager::addLoginSession();
             $login = explode('|', $login_text);
@@ -182,21 +170,14 @@ final class AuthController extends BaseController
             $login_number = '';
         }
 
-        if (Setting::obtain('enable_reg_captcha') === true) {
-            $geetest_html = $captcha['geetest'];
-        } else {
-            $geetest_html = null;
-        }
-
         return $this->view()
             ->assign('code', $code)
             ->assign('base_url', $_ENV['baseUrl'])
             ->assign('login_token', $login_token)
             ->assign('login_number', $login_number)
-            ->assign('geetest_html', $geetest_html)
             ->assign('telegram_bot', $_ENV['telegram_bot'])
-            ->assign('turnstile_sitekey', $captcha['turnstile'])
             ->assign('enable_email_verify', Setting::obtain('reg_email_verify'))
+            ->assign('captcha', $captcha)
             ->display('auth/register.tpl');
     }
 

+ 9 - 1
src/Controllers/PasswordController.php

@@ -27,8 +27,16 @@ final class PasswordController extends BaseController
      */
     public function reset(Request $request, Response $response, array $args)
     {
+        $captcha = [];
+
+        if (Setting::obtain('enable_login_captcha') === true) {
+            $captcha = Captcha::generate();
+        }
+
         return $response->write(
-            $this->view()->display('password/reset.tpl')
+            $this->view()
+                ->assign('captcha', $captcha)
+                ->display('password/reset.tpl')
         );
     }
 

+ 6 - 14
src/Controllers/UserController.php

@@ -50,7 +50,11 @@ final class UserController extends BaseController
      */
     public function index(Request $request, Response $response, array $args)
     {
-        $captcha = Captcha::generate();
+        $captcha = [];
+
+        if (Setting::obtain('enable_checkin_captcha') === true) {
+            $captcha = Captcha::generate();
+        }
 
         if ($_ENV['subscribe_client_url'] !== '') {
             $getClient = new Token();
@@ -70,12 +74,6 @@ final class UserController extends BaseController
             $token = '';
         }
 
-        if (Setting::obtain('enable_checkin_captcha') === true) {
-            $geetest_html = $captcha['geetest'];
-        } else {
-            $geetest_html = null;
-        }
-
         $data = [
             'today_traffic_usage' => (int) $this->user->transfer_enable === 0 ? 0 : ($this->user->u + $this->user->d - $this->user->last_day_t) / $this->user->transfer_enable * 100,
             'past_traffic_usage' => (int) $this->user->transfer_enable === 0 ? 0 : $this->user->last_day_t / $this->user->transfer_enable * 100,
@@ -85,20 +83,15 @@ final class UserController extends BaseController
         return $response->write(
             $this->view()
                 ->assign('ssr_sub_token', $this->user->getSublink())
-                ->assign('display_ios_class', $_ENV['display_ios_class'])
-                ->assign('display_ios_topup', $_ENV['display_ios_topup'])
-                ->assign('ios_account', $_ENV['ios_account'])
-                ->assign('ios_password', $_ENV['ios_password'])
                 ->assign('ann', Ann::orderBy('date', 'desc')->first())
-                ->assign('geetest_html', $geetest_html)
                 ->assign('mergeSub', $_ENV['mergeSub'])
                 ->assign('subUrl', $_ENV['subUrl'] . '/link/')
                 ->registerClass('URL', URL::class)
-                ->assign('turnstile_sitekey', $captcha['turnstile'])
                 ->assign('subInfo', LinkController::getSubinfo($this->user, 0))
                 ->assign('getUniversalSub', SubController::getUniversalSub($this->user))
                 ->assign('getClient', $token)
                 ->assign('data', $data)
+                ->assign('captcha', $captcha)
                 ->display('user/index.tpl')
         );
     }
@@ -120,7 +113,6 @@ final class UserController extends BaseController
             $this->view()
                 ->assign('codes', $codes)
                 ->assign('payments', Payment::getPaymentsEnabled())
-                // ->assign('pmw', Payment::purchaseHTML())
                 ->assign('render', $render)
                 ->display('user/code.tpl')
         );

+ 17 - 24
src/Services/Captcha.php

@@ -5,7 +5,6 @@ declare(strict_types=1);
 namespace App\Services;
 
 use App\Models\Setting;
-use App\Utils\Geetest;
 
 final class Captcha
 {
@@ -19,7 +18,7 @@ final class Captcha
                 $turnstile = Setting::obtain('turnstile_sitekey');
                 break;
             case 'geetest':
-                $geetest = Geetest::get(\time() . random_int(1, 10000));
+                $geetest = Setting::obtain('geetest_id');
                 break;
         }
 
@@ -38,31 +37,25 @@ final class Captcha
 
         switch (Setting::obtain('captcha_provider')) {
             case 'turnstile':
-                if (isset($param['turnstile'])) {
-                    if ($param['turnstile'] !== '') {
-                        $postdata = http_build_query(
-                            [
-                                'secret' => Setting::obtain('turnstile_secret'),
-                                'response' => $param['turnstile'],
-                            ]
-                        );
-
-                        $opts = ['http' => [
-                            'method' => 'POST',
-                            'header' => 'Content-Type: application/x-www-form-urlencoded',
-                            'content' => $postdata,
-                        ],
-                        ];
-
-                        $json = file_get_contents('https://challenges.cloudflare.com/turnstile/v0/siteverify', false, stream_context_create($opts));
-                        $result = \json_decode($json)->success;
-                    }
+                if ($param['turnstile'] !== '') {
+                    $postdata = http_build_query(
+                        [
+                            'secret' => Setting::obtain('turnstile_secret'),
+                            'response' => $param['turnstile'],
+                        ]
+                    );
+                    $opts = ['http' => [
+                        'method' => 'POST',
+                        'header' => 'Content-Type: application/x-www-form-urlencoded',
+                        'content' => $postdata,
+                    ],
+                    ];
+                    $json = file_get_contents('https://challenges.cloudflare.com/turnstile/v0/siteverify', false, stream_context_create($opts));
+                    $result = \json_decode($json)->success;
                 }
                 break;
             case 'geetest':
-                if (isset($param['geetest_challenge']) && isset($param['geetest_validate']) && isset($param['geetest_seccode'])) {
-                    $result = Geetest::verify($param['geetest_challenge'], $param['geetest_validate'], $param['geetest_seccode']);
-                }
+                // Todo https://github.com/GeeTeam/gt4-php-demo/blob/master/LoginController.php
                 break;
         }
 

+ 0 - 49
src/Utils/Geetest.php

@@ -1,49 +0,0 @@
-<?php
-
-declare(strict_types=1);
-
-namespace App\Utils;
-
-use App\Models\Setting;
-
-/**
- * 极验行为式验证安全平台,php 网站主后台包含的库文件
- *
- * @author Tanxu
- */
-final class Geetest
-{
-    public static function get($user_id = null)
-    {
-        $configs = Setting::getClass('geetest');
-        $GtSdk = new GeetestLib($configs['geetest_id'], $configs['geetest_key']);
-        $status = $GtSdk->preProcess($user_id);
-        $ret = \json_decode($GtSdk->getResponseStr());
-        session_start();
-        $_SESSION['gtserver'] = $status;
-        $_SESSION['user_id'] = $user_id;
-        return $ret;
-    }
-
-    public static function verify($geetest_challenge, $geetest_validate, $geetest_seccode)
-    {
-        session_start();
-        $configs = Setting::getClass('geetest');
-        $GtSdk = new GeetestLib($configs['geetest_id'], $configs['geetest_key']);
-        $user_id = $_SESSION['user_id'];
-        if ($_SESSION['gtserver'] === 1) {
-            $result = $GtSdk->successValidate($geetest_challenge, $geetest_validate, $geetest_seccode, $user_id);
-            if ($result) {
-                return true;
-            }
-
-            return false;
-        }
-
-        if ($GtSdk->failValidate($geetest_challenge, $geetest_validate, $geetest_seccode)) {
-            return true;
-        }
-
-        return false;
-    }
-}

+ 0 - 343
src/Utils/GeetestLib.php

@@ -1,343 +0,0 @@
-<?php
-
-declare(strict_types=1);
-
-namespace App\Utils;
-
-/**
- * 极验行为式验证安全平台,php 网站主后台包含的库文件
- *
- * @author Tanxu
- */
-final class GeetestLib
-{
-    public const GT_SDK_VERSION = 'php_3.2.0';
-
-    public static $connectTimeout = 3;
-    public static $socketTimeout = 3;
-
-    private $response;
-
-    public function __construct($captcha_id, $private_key)
-    {
-        $this->captcha_id = $captcha_id;
-        $this->private_key = $private_key;
-    }
-
-    /**
-     * 判断极验服务器是否down机
-     *
-     * @param null $user_id
-     */
-    public function preProcess($user_id = null): int
-    {
-        $url = 'http://api.geetest.com/register.php?gt=' . $this->captcha_id;
-        if (($user_id !== null) and is_string($user_id)) {
-            $url .= '&user_id=' . $user_id;
-        }
-        $challenge = $this->sendRequest($url);
-
-        if (strlen($challenge) !== 32) {
-            $this->failbackProcess();
-
-            return 0;
-        }
-        $this->successProcess($challenge);
-
-        return 1;
-    }
-
-    /**
-     * @return mixed
-     */
-    public function getResponseStr()
-    {
-        return \json_encode($this->response);
-    }
-
-    /**
-     * 返回数组方便扩展
-     *
-     * @return mixed
-     */
-    public function getResponse()
-    {
-        return $this->response;
-    }
-
-    /**
-     * 正常模式获取验证结果
-     *
-     * @param      $challenge
-     * @param      $validate
-     * @param      $seccode
-     * @param null $user_id
-     */
-    public function successValidate($challenge, $validate, $seccode, $user_id = null): int
-    {
-        if (! $this->checkValidate($challenge, $validate)) {
-            return 0;
-        }
-        $data = [
-            'seccode' => $seccode,
-            'sdk' => self::GT_SDK_VERSION,
-        ];
-        if (($user_id !== null) and is_string($user_id)) {
-            $data['user_id'] = $user_id;
-        }
-        $url = 'http://api.geetest.com/validate.php';
-        $codevalidate = $this->postRequest($url, $data);
-        if ($codevalidate === md5($seccode)) {
-            return 1;
-        }
-
-        if ($codevalidate === 'false') {
-            return 0;
-        }
-
-        return 0;
-    }
-
-    /**
-     * 宕机模式获取验证结果
-     *
-     * @param $challenge
-     * @param $validate
-     * @param $seccode
-     */
-    public function failValidate($challenge, $validate, $seccode): int
-    {
-        if ($validate) {
-            $value = explode('_', $validate);
-            $ans = $this->decodeResponse($challenge, $value['0']);
-            $bg_idx = $this->decodeResponse($challenge, $value['1']);
-            $grp_idx = $this->decodeResponse($challenge, $value['2']);
-            $x_pos = $this->getFailbackPicAns($bg_idx, $grp_idx);
-            $answer = abs($ans - $x_pos);
-            if ($answer < 4) {
-                return 1;
-            }
-
-            return 0;
-        }
-
-        return 0;
-    }
-
-    private function successProcess($challenge): void
-    {
-        $challenge = md5($challenge . $this->private_key);
-        $result = [
-            'success' => 1,
-            'gt' => $this->captcha_id,
-            'challenge' => $challenge,
-        ];
-        $this->response = $result;
-    }
-
-    private function failbackProcess(): void
-    {
-        $rnd1 = md5(random_int(0, 100));
-        $rnd2 = md5(random_int(0, 100));
-        $challenge = $rnd1 . substr($rnd2, 0, 2);
-        $result = [
-            'success' => 0,
-            'gt' => $this->captcha_id,
-            'challenge' => $challenge,
-        ];
-        $this->response = $result;
-    }
-
-    private function checkValidate($challenge, $validate): bool
-    {
-        if (strlen($validate) !== 32) {
-            return false;
-        }
-        if (md5($this->private_key . 'geetest' . $challenge) !== $validate) {
-            return false;
-        }
-
-        return true;
-    }
-
-    /**
-     * GET 请求
-     *
-     * @param $url
-     *
-     * @return mixed|string
-     */
-    private function sendRequest($url)
-    {
-        if (function_exists('curl_exec')) {
-            $ch = curl_init();
-            curl_setopt($ch, CURLOPT_URL, $url);
-            curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, self::$connectTimeout);
-            curl_setopt($ch, CURLOPT_TIMEOUT, self::$socketTimeout);
-            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
-
-            $data = curl_exec($ch);
-
-            if (curl_errno($ch)) {
-                $err = sprintf('curl[%s] error[%s]', $url, curl_errno($ch) . ':' . curl_error($ch));
-                $this->triggerError($err);
-            }
-
-            curl_close($ch);
-        } else {
-            $opts = [
-                'http' => [
-                    'method' => 'GET',
-                    'timeout' => self::$connectTimeout + self::$socketTimeout,
-                ],
-            ];
-            $context = stream_context_create($opts);
-            $data = file_get_contents($url, false, $context);
-        }
-
-        return $data;
-    }
-
-    /**
-     * @param       $url
-     * @param array $postdata
-     *
-     * @return mixed|string
-     */
-    private function postRequest($url, array $postdata = [])
-    {
-        if (! $postdata) {
-            return false;
-        }
-
-        $data = http_build_query($postdata);
-        if (function_exists('curl_exec')) {
-            $ch = curl_init();
-            curl_setopt($ch, CURLOPT_URL, $url);
-            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
-            curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, self::$connectTimeout);
-            curl_setopt($ch, CURLOPT_TIMEOUT, self::$socketTimeout);
-
-            //不可能执行到的代码
-            if (! $postdata) {
-                curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
-            } else {
-                curl_setopt($ch, CURLOPT_POST, 1);
-                curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
-            }
-            $data = curl_exec($ch);
-
-            if (curl_errno($ch)) {
-                $err = sprintf('curl[%s] error[%s]', $url, curl_errno($ch) . ':' . curl_error($ch));
-                $this->triggerError($err);
-            }
-
-            curl_close($ch);
-        } elseif ($postdata) {
-            $opts = [
-                'http' => [
-                    'method' => 'POST',
-                    'header' => "Content-type: application/x-www-form-urlencoded\r\n" . 'Content-Length: ' . strlen($data) . "\r\n",
-                    'content' => $data,
-                    'timeout' => self::$connectTimeout + self::$socketTimeout,
-                ],
-            ];
-            $context = stream_context_create($opts);
-            $data = file_get_contents($url, false, $context);
-        }
-
-        return $data;
-    }
-
-    /**
-     * 解码随机参数
-     *
-     * @param $challenge
-     * @param $string
-     */
-    private function decodeResponse($challenge, $string): int
-    {
-        if (strlen($string) > 100) {
-            return 0;
-        }
-        $key = [];
-        $chongfu = [];
-        $shuzi = ['0' => 1, '1' => 2, '2' => 5, '3' => 10, '4' => 50];
-        $count = 0;
-        $res = 0;
-        $array_challenge = str_split($challenge);
-        $array_value = str_split($string);
-        for ($i = 0, $iMax = strlen($challenge); $i < $iMax; $i++) {
-            $item = $array_challenge[$i];
-            if (\in_array($item, $chongfu)) {
-                continue;
-            }
-
-            $value = $shuzi[$count % 5];
-            $chongfu[] = $item;
-            $count++;
-            $key[$item] = $value;
-        }
-
-        for ($j = 0, $jMax = strlen($string); $j < $jMax; $j++) {
-            $res += $key[$array_value[$j]];
-        }
-        $res -= $this->decodeRandBase($challenge);
-
-        return $res;
-    }
-
-    private function getXPosFromStr($x_str): int
-    {
-        if (strlen($x_str) !== 5) {
-            return 0;
-        }
-        $sum_val = 0;
-        $x_pos_sup = 200;
-        $sum_val = base_convert($x_str, 16, 10);
-        $result = $sum_val % $x_pos_sup;
-        return $result < 40 ? 40 : $result;
-    }
-
-    private function getFailbackPicAns($full_bg_index, $img_grp_index): int
-    {
-        $full_bg_name = substr(md5($full_bg_index), 0, 9);
-        $bg_name = substr(md5($img_grp_index), 10, 9);
-
-        $answer_decode = '';
-        // 通过两个字符串奇数和偶数位拼接产生答案位
-        for ($i = 0; $i < 9; $i++) {
-            if ($i % 2 === 0) {
-                $answer_decode .= $full_bg_name[$i];
-            } elseif ($i % 2 === 1) {
-                $answer_decode .= $bg_name[$i];
-            }
-        }
-        $x_decode = substr($answer_decode, 4, 5);
-        return $this->getXPosFromStr($x_decode);
-    }
-
-    /**
-     * 输入的两位的随机数字,解码出偏移量
-     *
-     * @param $challenge
-     *
-     * @return mixed
-     */
-    private function decodeRandBase($challenge)
-    {
-        $base = substr($challenge, 32, 2);
-        $tempArray = [];
-        for ($i = 0, $iMax = strlen($base); $i < $iMax; $i++) {
-            $tempAscii = ord($base[$i]);
-            $result = $tempAscii > 57 ? $tempAscii - 87 : $tempAscii - 48;
-            $tempArray[] = $result;
-        }
-        return $tempArray['0'] * 36 + $tempArray['1'];
-    }
-
-    private function triggerError($err): void
-    {
-        trigger_error($err);
-    }
-}