Parcourir la source

1.阻止大陆或者海外IP访问
2.修正BUG
3.更新纯真IP库

admin il y a 7 ans
Parent
commit
201eba19f8

+ 18 - 0
app/Http/Middleware/Forbidden.php

@@ -2,6 +2,7 @@
 
 namespace App\Http\Middleware;
 
+use App\Components\QQWry;
 use App\Http\Models\Config;
 use Response;
 use Agent;
@@ -31,7 +32,24 @@ class Forbidden
         }
 
         // 拒绝受限IP访问
+        $ip = getClientIP();
+        $qqwry = new QQWry();
+        $ipInfo = $qqwry->ip($ip);
+        if ($ipInfo && is_array($ipInfo) && $ipInfo['country']) {
+            $forbidChina = Config::query()->where('name', 'is_forbid_china')->first();
+            if ($forbidChina && $forbidChina->value && $ipInfo['country'] == '中国') {
+                Log::info('识别到大陆IP,拒绝访问:' . $ip);
 
+                return Response::view('403', [], 403);
+            }
+
+            $forbidOversea = Config::query()->where('name', 'is_forbid_oversea')->first();
+            if ($forbidOversea && $forbidOversea->value && $ipInfo['country'] != '中国') {
+                Log::info('识别到海外IP,拒绝访问:' . $ip . ' - ' . $ipInfo['country']);
+
+                return Response::view('403', [], 403);
+            }
+        }
 
         return $next($request);
     }

+ 44 - 0
resources/views/admin/system.blade.php

@@ -127,6 +127,20 @@
                                                             </div>
                                                         </div>
                                                     </div>
+                                                    <div class="form-group">
+                                                        <div class="col-md-6">
+                                                            <label for="is_forbid_china" class="col-md-3 control-label">阻止大陆访问</label>
+                                                            <div class="col-md-9">
+                                                                <input type="checkbox" class="make-switch" @if($is_forbid_china) checked @endif id="is_forbid_china" data-on-color="success" data-off-color="danger" data-on-text="启用" data-off-text="关闭">
+                                                            </div>
+                                                        </div>
+                                                        <div class="col-md-6">
+                                                            <label for="is_forbid_oversea" class="col-md-3 control-label">阻止海外访问</label>
+                                                            <div class="col-md-9">
+                                                                <input type="checkbox" class="make-switch" @if($is_forbid_oversea) checked @endif id="is_forbid_oversea" data-on-color="success" data-off-color="danger" data-on-text="启用" data-off-text="关闭">
+                                                            </div>
+                                                        </div>
+                                                    </div>
                                                     <div class="form-group">
                                                         <div class="col-md-6">
                                                             <label for="is_forbid_robot" class="col-md-3 control-label">阻止机器人访问</label>
@@ -866,6 +880,36 @@
             }
         });
 
+        // 启用、禁用屏蔽大陆访问
+        $('#is_forbid_china').on({
+            'switchChange.bootstrapSwitch': function(event, state) {
+                var is_forbid_china = state ? 1 : 0;
+
+                $.post("{{url('admin/setConfig')}}", {_token:'{{csrf_token()}}', name:'is_forbid_china', value:is_forbid_china}, function (ret) {
+                    layer.msg(ret.message, {time:1000}, function() {
+                        if (ret.status == 'fail') {
+                            window.location.reload();
+                        }
+                    });
+                });
+            }
+        });
+
+        // 启用、禁用屏蔽海外访问
+        $('#is_forbid_oversea').on({
+            'switchChange.bootstrapSwitch': function(event, state) {
+                var is_forbid_oversea = state ? 1 : 0;
+
+                $.post("{{url('admin/setConfig')}}", {_token:'{{csrf_token()}}', name:'is_forbid_oversea', value:is_forbid_oversea}, function (ret) {
+                    layer.msg(ret.message, {time:1000}, function() {
+                        if (ret.status == 'fail') {
+                            window.location.reload();
+                        }
+                    });
+                });
+            }
+        });
+
         // 启用、禁用机器人访问
         $('#is_forbid_robot').on({
             'switchChange.bootstrapSwitch': function(event, state) {

+ 1 - 1
resources/views/shop/editGoods.blade.php

@@ -144,7 +144,7 @@
                                 <div class="form-group">
                                     <label for="sort" class="col-md-3 control-label">排序</label>
                                     <div class="col-md-8">
-                                        <input type="text" class="form-control" name="sort" value="1" id="sort" placeholder="">
+                                        <input type="text" class="form-control" name="sort" value="{{$goods->sort}}" id="sort" placeholder="">
                                         <span class="help-block"> 值越大排越前 </span>
                                     </div>
                                 </div>

+ 1 - 1
resources/views/user/layouts.blade.php

@@ -157,7 +157,7 @@
                 @endif
                 <li class="nav-item {{in_array(Request::path(), ['help', 'article']) ? 'active open' : ''}}">
                     <a href="{{url('help')}}" class="nav-link nav-toggle">
-                        <i class="fa fa-bank"></i>
+                        <i class="icon-doc"></i>
                         <span class="title">{{trans('home.help')}}</span>
                     </a>
                 </li>

+ 3 - 0
sql/update/20180917.sql

@@ -0,0 +1,3 @@
+-- 屏蔽大陆访问、屏蔽海外访问
+INSERT INTO `config` VALUES ('69', 'is_forbid_china', 0);
+INSERT INTO `config` VALUES ('70', 'is_forbid_oversea', 0);

BIN
storage/qqwry.dat