Browse Source

核价登录时检查当前IP是否在用户表中的IP白名单内[whiteIPs]

shuiping150 3 ngày trước cách đây
mục cha
commit
7f29859b2f

+ 4 - 0
JLHHJSvr/DBA/DBModle/u_user_jlhprice.cs

@@ -26,6 +26,10 @@ namespace JLHHJSvr.DBA.DBModle
         /// 密码
         /// </summary>
         public string psw { get; set; }
+        /// <summary>
+        /// IP白名单列表
+        /// </summary>
+        public string whiteIPs { get; set; }
         public string rightstring { get; set; }
         public string descrp { get; set; }
         public string deptstr { get; set; }

+ 4 - 1
JLHHJSvr/DBA/ParkDBVersion.cs

@@ -30,7 +30,7 @@ namespace JLHHJSvr.DBA
     {
         protected override string currentVersion
         {
-            get { return "1.0.180104"; }
+            get { return "1.0.250730"; }
         }
 
         protected override string dbname
@@ -209,6 +209,9 @@ ALTER TABLE fx_user_dwlayout ADD  CONSTRAINT DF_fx_user_dwlayout_column_width  D
 ALTER TABLE fx_user_dwlayout ADD  CONSTRAINT DF_fx_user_dwlayout_column_x  DEFAULT ('') FOR column_x
 ALTER TABLE fx_user_dwlayout ADD  CONSTRAINT DF_fx_user_dwlayout_column_autosize  DEFAULT (-1) FOR column_autosize
 ALTER TABLE fx_user_dwlayout ADD  CONSTRAINT DF_fx_user_dwlayout_column_detail_height  DEFAULT (0) FOR column_detail_height
+", ""),
+  new Script("1.0.250730", @"
+ALTER TABLE u_user_jlhprice ADD whiteIPs varchar(2000) NULL
 ", ""),
                 };
             }

+ 20 - 1
JLHHJSvr/Excutor/LoginExcutor.cs

@@ -27,6 +27,16 @@ namespace JLHHJSvr.Excutor
                 return;
             }
 
+            var remoteIP = string.Empty;
+            var remoteInfo = state as IRemoteInfoContainer;
+            var remoteEndPoint = remoteInfo?.RemoteInfo;
+            if (!string.IsNullOrEmpty(remoteEndPoint))
+            {
+                var pos = remoteEndPoint.LastIndexOf(":");
+                remoteIP = pos > 0 ? remoteEndPoint.Substring(0, pos).Trim() : remoteEndPoint;
+            }
+
+
             //if (string.IsNullOrEmpty(request.psw))
             //{
             //    rslt.ErrMsg = "密码不能为空";
@@ -43,7 +53,7 @@ namespace JLHHJSvr.Excutor
                 {
                     if (DbSqlHelper.SelectOne(cmd, "u_user_jlhprice", "userid = @usercode",
                     new Dictionary<string, object>() { { "@usercode", request.usercode } }, stUser,
-                    "userid, empid, username, usermode, psw, access_failed_count, last_failed_attempt_time") != 1)
+                    "userid, empid, username, usermode, psw, access_failed_count, last_failed_attempt_time,whiteIPs") != 1)
                     {
                         rslt.ErrMsg = "用户名不存在或密码错误";
                         return;
@@ -55,6 +65,15 @@ namespace JLHHJSvr.Excutor
                         throw new LJCommonException("登录连续错误5次,账号已锁定,请联系管理员解锁!");
                     }
 
+                    if (!string.IsNullOrEmpty(stUser.whiteIPs) && !string.IsNullOrEmpty(remoteIP))
+                    {
+                        var ipSet = new HashSet<string>(stUser.whiteIPs.Split(',', ','), StringComparer.OrdinalIgnoreCase);
+                        if (!ipSet.Contains(remoteIP))
+                        {
+                            throw new LJCommonException($"{request.usercode}当前使用的IP[{remoteIP}]不在白名单里,不允许登录");
+                        }
+                    }
+
                     psw_bczh3 pswhelper = new psw_bczh3();
                     if (pswhelper.GetEntrypt(request.psw, 0, "123457851239866") != stUser.psw)
                     {

+ 16 - 1
JLHHJSvr/LJLib.HttpServer/LJHttpProcessor.cs

@@ -1,16 +1,18 @@
 using System;
 using System.Collections;
 using System.Collections.Generic;
+using System.Diagnostics;
 using System.IO;
 using System.Linq;
 using System.Net.Sockets;
 using System.Text;
 using System.Threading;
 using System.Web;
+using LJLib.Net.SPI.Server;
 
 namespace LJLib.HttpServer
 {
-    public class LJHttpProcessor
+    public class LJHttpProcessor : IRemoteInfoContainer
     {
         private TcpClient socket;
         private LJHttpServer srv;
@@ -347,5 +349,18 @@ namespace LJLib.HttpServer
                 }
             }
         }
+
+        public string RemoteInfo
+        { get{
+            try
+            {
+                return socket.Client.RemoteEndPoint.ToString();
+            }
+            catch (Exception ex)
+            {
+                Trace.Write(ex.ToString());
+                return null;
+            }
+        } }
     }
 }

+ 1 - 1
JLHHJSvr/LJLib.HttpServer/SimpleHttpServer.cs

@@ -279,7 +279,7 @@ namespace LJLib.HttpServer
                 //requestlist = parser.JsonParse(requestType, body) as ILJRequest;
 
                 var dataReadTime = DateTime.Now; // 请求解析完成
-                responselist = server.DoExcute(requestlist, null);
+                responselist = server.DoExcute(requestlist, p);
                 var doneTime = DateTime.Now; // 接口处理完成
 
                 if (!string.IsNullOrEmpty(responselist.ErrMsg))