XFEExtension.NetCore.ServerInteractive
[DLL] Server interaction extension, including user identity verification and querying in conjunction with AutoConfig
关注
0
Fork
0
Star
0
返回提交历史
Modified
XFEExtension.NetCore.ServerInteractive/Utilities/DataTable/XFEDataTable.cs
+4
-4
Modified
XFEExtension.NetCore.ServerInteractive/Utilities/Helpers/UserHelper.cs
+8
-12
Modified
XFEExtension.NetCore.ServerInteractive/Utilities/Server/Services/CoreService/CoreLogService.cs
+2
-2
Modified
XFEExtension.NetCore.ServerInteractive/Utilities/Server/Services/CoreService/IpBannerService.cs
+3
-3
Modified
XFEExtension.NetCore.ServerInteractive/Utilities/Server/Services/CoreService/UserReloginService.cs
+1
-1
Modified
XFEExtension.NetCore.ServerInteractive/Utilities/Server/Services/ServerService/ServerIpInitializer.cs
+3
-1
Modified
XFEExtension.NetCore.ServerInteractive/Utilities/Server/Services/ServerService/XFECoreServerProcessService.cs
+2
-2
Modified
XFEExtension.NetCore.ServerInteractive/XFEExtension.NetCore.ServerInteractive.csproj
+3
-3
XFEstudio/XFEExtension.NetCore.ServerInteractive
修复用户登录模型的Json转换问题
fe63a93
代码差异
8 个文件
+26
-28
@@ -136,7 +136,7 @@ public class XFEDataTable<T> : IXFEDataTable where T : IIDModel
136
136
{
137
137
case "get":
138
138
Console.Write($"【{r.Args.ClientIP}】获取{TableShowName}列表请求");
139
UserHelper.ValidatePermission(requestJsonNode["session"], requestJsonNode["computerInfo"], r.Args.ClientIP, GetPermissionLevel, UserJsonSerializerOptions, GetEncryptedUserLoginModelFunction(), GetUsersFunction(), r);
139
UserHelper.ValidatePermission(requestJsonNode["session"], requestJsonNode["computerInfo"], r.Args.ClientIP, GetPermissionLevel, GetEncryptedUserLoginModelFunction(), GetUsersFunction(), r);
140
140
List<T> tableList = [.. GetTableFunction()];
141
141
int pageCount = requestJsonNode["pageCount"].GetValue<int>();
142
142
if (pageCount == -1)
@@ -168,7 +168,7 @@ public class XFEDataTable<T> : IXFEDataTable where T : IIDModel
168
168
throw new StopAction(() => { }, $"\n无法使用Json转换目标{TableShowName}信息");
169
169
}
170
170
Console.Write($":{item.ID}");
171
UserHelper.ValidatePermission(requestJsonNode["session"], requestJsonNode["computerInfo"], r.Args.ClientIP, AddPermissionLevel, UserJsonSerializerOptions, GetEncryptedUserLoginModelFunction(), GetUsersFunction(), r);
171
UserHelper.ValidatePermission(requestJsonNode["session"], requestJsonNode["computerInfo"], r.Args.ClientIP, AddPermissionLevel, GetEncryptedUserLoginModelFunction(), GetUsersFunction(), r);
172
172
if (item.ID.IsNullOrWhiteSpace())
173
173
{
174
174
statusCode = HttpStatusCode.BadRequest;
@@ -183,7 +183,7 @@ public class XFEDataTable<T> : IXFEDataTable where T : IIDModel
183
183
Console.Write($"【{r.Args.ClientIP}】删除{TableShowName}请求");
184
184
var id = requestJsonNode["id"].ToString();
185
185
Console.Write($":{id}");
186
UserHelper.ValidatePermission(requestJsonNode["session"], requestJsonNode["computerInfo"], r.Args.ClientIP, RemovePermissionLevel, UserJsonSerializerOptions, GetEncryptedUserLoginModelFunction(), GetUsersFunction(), r);
186
UserHelper.ValidatePermission(requestJsonNode["session"], requestJsonNode["computerInfo"], r.Args.ClientIP, RemovePermissionLevel, GetEncryptedUserLoginModelFunction(), GetUsersFunction(), r);
187
187
if (id.IsNullOrWhiteSpace())
188
188
{
189
189
statusCode = HttpStatusCode.BadRequest;
@@ -211,7 +211,7 @@ public class XFEDataTable<T> : IXFEDataTable where T : IIDModel
211
211
statusCode = HttpStatusCode.BadRequest;
212
212
throw new StopAction(() => { }, $"\n{TableShowName}ID不能为空");
213
213
}
214
UserHelper.ValidatePermission(requestJsonNode["session"], requestJsonNode["computerInfo"], r.Args.ClientIP, ChangePermissionLevel, UserJsonSerializerOptions, GetEncryptedUserLoginModelFunction(), GetUsersFunction(), r);
214
UserHelper.ValidatePermission(requestJsonNode["session"], requestJsonNode["computerInfo"], r.Args.ClientIP, ChangePermissionLevel, GetEncryptedUserLoginModelFunction(), GetUsersFunction(), r);
215
215
Change(item);
216
216
r.Args.Close();
217
217
break;
@@ -26,17 +26,16 @@ public static class UserHelper
26
26
/// <param name="sessionId"></param>
27
27
/// <param name="computerInfo"></param>
28
28
/// <param name="ipAddress"></param>
29
/// <param name="jsonSerializerOptions"></param>
30
29
/// <param name="encryptedUserLoginModels"></param>
31
30
/// <param name="userInfoList"></param>
32
31
/// <param name="user"></param>
33
32
/// <returns></returns>
34
public static UserOperateResult GetUser(string sessionId, string computerInfo, string ipAddress, JsonSerializerOptions? jsonSerializerOptions, IEnumerable<EncryptedUserLoginModel> encryptedUserLoginModels, IEnumerable<IUserFaceInfo> userInfoList, out IUserInfo? user)
33
public static UserOperateResult GetUser(string sessionId, string computerInfo, string ipAddress, IEnumerable<EncryptedUserLoginModel> encryptedUserLoginModels, IEnumerable<IUserFaceInfo> userInfoList, out IUserInfo? user)
35
34
{
36
35
user = null;
37
36
if (encryptedUserLoginModels.FirstOrDefault(user => user.UserLoginModel.ComputerInfo == computerInfo) is not EncryptedUserLoginModel encryptedUserLoginModel)
38
37
return UserOperateResult.LoginExpired;
39
if (Decrypt<UserLoginModel>(encryptedUserLoginModel.Key, sessionId, jsonSerializerOptions) is not UserLoginModel targetUserLoginModel || encryptedUserLoginModel.UserLoginModel.UID != targetUserLoginModel.UID)
38
if (Decrypt<UserLoginModel>(encryptedUserLoginModel.Key, sessionId) is not UserLoginModel targetUserLoginModel || encryptedUserLoginModel.UserLoginModel.UID != targetUserLoginModel.UID)
40
39
return UserOperateResult.UserNotFound;
41
40
if (encryptedUserLoginModel.UserLoginModel.EndDateTime < DateTime.Now || (encryptedUserLoginModel.UserLoginModel.LastIPAddress != ipAddress && !((encryptedUserLoginModel.UserLoginModel.LastIPAddress == "127.0.0.1" || encryptedUserLoginModel.UserLoginModel.LastIPAddress == "::1") && (ipAddress == "127.0.0.1" || ipAddress == "::1"))))
42
41
return UserOperateResult.LoginExpired;
@@ -147,13 +146,12 @@ public static class UserHelper
147
146
/// <param name="computerInfo"></param>
148
147
/// <param name="ipAddress"></param>
149
148
/// <param name="requiredPermissionLevel"></param>
150
/// <param name="jsonSerializerOptions"></param>
151
149
/// <param name="encryptedUserLoginModels"></param>
152
150
/// <param name="userInfoList"></param>
153
151
/// <returns></returns>
154
public static UserOperateResult ValidateUserPermission(string sessionId, string computerInfo, string ipAddress, int requiredPermissionLevel, JsonSerializerOptions? jsonSerializerOptions, IEnumerable<EncryptedUserLoginModel> encryptedUserLoginModels, IEnumerable<IUserInfo> userInfoList)
152
public static UserOperateResult ValidateUserPermission(string sessionId, string computerInfo, string ipAddress, int requiredPermissionLevel, IEnumerable<EncryptedUserLoginModel> encryptedUserLoginModels, IEnumerable<IUserInfo> userInfoList)
155
153
{
156
var result = GetUser(sessionId, computerInfo, ipAddress, jsonSerializerOptions, encryptedUserLoginModels, userInfoList, out var user);
154
var result = GetUser(sessionId, computerInfo, ipAddress, encryptedUserLoginModels, userInfoList, out var user);
157
155
if (result != UserOperateResult.Success)
158
156
return result;
159
157
if (user!.PermissionLevel < requiredPermissionLevel)
@@ -206,14 +204,13 @@ public static class UserHelper
206
204
/// <param name="computerInfo"></param>
207
205
/// <param name="ipAddress"></param>
208
206
/// <param name="requiredPermissionLevel"></param>
209
/// <param name="jsonSerializerOptions"></param>
210
207
/// <param name="encryptedUserLoginModels"></param>
211
208
/// <param name="userInfoList"></param>
212
209
/// <param name="r"></param>
213
210
/// <exception cref="StopAction"></exception>
214
public static void ValidatePermission(string sessionId, string computerInfo, string ipAddress, int requiredPermissionLevel, JsonSerializerOptions? jsonSerializerOptions, IEnumerable<EncryptedUserLoginModel> encryptedUserLoginModels, IEnumerable<IUserInfo> userInfoList, ServerCoreReturnArgs r)
211
public static void ValidatePermission(string sessionId, string computerInfo, string ipAddress, int requiredPermissionLevel, IEnumerable<EncryptedUserLoginModel> encryptedUserLoginModels, IEnumerable<IUserInfo> userInfoList, ServerCoreReturnArgs r)
215
212
{
216
var result = ValidateUserPermission(sessionId, computerInfo, ipAddress, requiredPermissionLevel, jsonSerializerOptions, encryptedUserLoginModels, userInfoList);
213
var result = ValidateUserPermission(sessionId, computerInfo, ipAddress, requiredPermissionLevel, encryptedUserLoginModels, userInfoList);
217
214
if (result != UserOperateResult.Success)
218
215
r.Error(OutPutResult(result), HttpStatusCode.Forbidden);
219
216
}
@@ -239,14 +236,13 @@ public static class UserHelper
239
236
/// <param name="key"></param>
240
237
/// <param name="model"></param>
241
238
/// <returns></returns>
242
public static string Encrypt<T>(string key, T model) where T : class => AESHelper.Encrypt(model.ToJson(), key);
239
public static string Encrypt<T>(string key, T model) where T : class => AESHelper.Encrypt(JsonSerializer.Serialize(model), key);
243
240
244
241
/// <summary>
245
242
/// 解密用户登录模型
246
243
/// </summary>
247
244
/// <param name="key"></param>
248
245
/// <param name="encryptedModel"></param>
249
/// <param name="jsonSerializerOptions"></param>
250
246
/// <returns></returns>
251
public static T Decrypt<T>(string key, string encryptedModel, JsonSerializerOptions? jsonSerializerOptions = null) where T : class, new() => JsonSerializer.Deserialize<T>(AESHelper.Decrypt(encryptedModel, key), jsonSerializerOptions) ?? new();
247
public static T Decrypt<T>(string key, string encryptedModel) where T : class, new() => JsonSerializer.Deserialize<T>(AESHelper.Decrypt(encryptedModel, key)) ?? new();
252
248
}
@@ -25,14 +25,14 @@ public class CoreLogService : ServerCoreUserServiceBase
25
25
switch (execute)
26
26
{
27
27
case "get_log":
28
UserHelper.ValidatePermission(queryableJsonNode["session"], queryableJsonNode["computerInfo"], r.Args.ClientIP, GetPermission, JsonSerializerOptions, GetEncryptedUserLoginModelFunction(), GetUserFunction(), r);
28
UserHelper.ValidatePermission(queryableJsonNode["session"], queryableJsonNode["computerInfo"], r.Args.ClientIP, GetPermission, GetEncryptedUserLoginModelFunction(), GetUserFunction(), r);
29
29
if (!DateTime.TryParse(queryableJsonNode["startDateTime"], out var startDatetime)) r.Error("起始日期格式不正确", HttpStatusCode.BadRequest);
30
30
if (!DateTime.TryParse(queryableJsonNode["endDateTime"], out var endDatetime)) r.Error("结束日期格式不正确", HttpStatusCode.BadRequest);
31
31
await r.Args.ReplyAndClose(XFEConsole.XFEConsole.Log.Export(startDatetime, endDatetime));
32
32
break;
33
33
case "clear_log":
34
34
Console.Write($"【{r.Args.ClientIP}】清除服务器日志请求");
35
UserHelper.ValidatePermission(queryableJsonNode["session"], queryableJsonNode["computerInfo"], r.Args.ClientIP, ClearPermission, JsonSerializerOptions, GetEncryptedUserLoginModelFunction(), GetUserFunction(), r);
35
UserHelper.ValidatePermission(queryableJsonNode["session"], queryableJsonNode["computerInfo"], r.Args.ClientIP, ClearPermission, GetEncryptedUserLoginModelFunction(), GetUserFunction(), r);
36
36
if (File.Exists("server.log"))
37
37
File.Delete("server.log");
38
38
XFEConsole.XFEConsole.Log.Clear();
@@ -31,12 +31,12 @@ public class IpBannerService : ServerCoreUserServiceBase
31
31
{
32
32
case "get_bannedIpList":
33
33
Console.Write($"【{r.Args.ClientIP}】获取禁止的IP地址列表请求");
34
UserHelper.ValidatePermission(queryableJsonNode["session"], queryableJsonNode["computerInfo"], r.Args.ClientIP, GetPermission, JsonSerializerOptions, GetEncryptedUserLoginModelFunction(), GetUserFunction(), r);
34
UserHelper.ValidatePermission(queryableJsonNode["session"], queryableJsonNode["computerInfo"], r.Args.ClientIP, GetPermission, GetEncryptedUserLoginModelFunction(), GetUserFunction(), r);
35
35
await r.Args.ReplyAndClose(ServerBaseProfile.BannedIPAddressList.ToJson());
36
36
break;
37
37
case "add_bannedIp":
38
38
Console.WriteLine($"【{r.Args.ClientIP}】添加禁止的IP地址请求 添加:{queryableJsonNode["bannedIp"]}");
39
UserHelper.ValidatePermission(queryableJsonNode["session"], queryableJsonNode["computerInfo"], r.Args.ClientIP, AddPermission, JsonSerializerOptions, GetEncryptedUserLoginModelFunction(), GetUserFunction(), r);
39
UserHelper.ValidatePermission(queryableJsonNode["session"], queryableJsonNode["computerInfo"], r.Args.ClientIP, AddPermission, GetEncryptedUserLoginModelFunction(), GetUserFunction(), r);
40
40
if (queryableJsonNode["bannedIp"] is null) r.Error("无IP地址传入", HttpStatusCode.BadRequest);
41
41
ServerBaseProfile.BannedIPAddressList.Add(new()
42
42
{
@@ -47,7 +47,7 @@ public class IpBannerService : ServerCoreUserServiceBase
47
47
break;
48
48
case "remove_bannedIp":
49
49
Console.WriteLine($"【{r.Args.ClientIP}】删除禁止的IP地址请求 移除:{queryableJsonNode["bannedIp"]}");
50
UserHelper.ValidatePermission(queryableJsonNode["session"], queryableJsonNode["computerInfo"], r.Args.ClientIP, RemovePermission, JsonSerializerOptions, GetEncryptedUserLoginModelFunction(), GetUserFunction(), r);
50
UserHelper.ValidatePermission(queryableJsonNode["session"], queryableJsonNode["computerInfo"], r.Args.ClientIP, RemovePermission, GetEncryptedUserLoginModelFunction(), GetUserFunction(), r);
51
51
var targetIp = ServerBaseProfile.BannedIPAddressList.FirstOrDefault(ip => ip.IPAddress == queryableJsonNode["bannedIp"].ToString()) ?? throw r.GetError("无IP地址传入", HttpStatusCode.BadRequest);
52
52
await r.Args.ReplyAndClose(ServerBaseProfile.BannedIPAddressList.Remove(targetIp).ToString());
53
53
break;
@@ -25,7 +25,7 @@ public class UserReloginService<T> : ServerCoreUserServiceBase where T : IUserFa
25
25
if (session.IsNullOrWhiteSpace()) r.Error("Session值不能为空", HttpStatusCode.BadRequest);
26
26
if (computerInfo.IsNullOrWhiteSpace()) r.Error("电脑信息不能为空", HttpStatusCode.BadRequest);
27
27
if (GetEncryptedUserLoginModelFunction().FirstOrDefault(user => user.UserLoginModel.ComputerInfo == computerInfo) is not EncryptedUserLoginModel encryptedUserLoginModel) throw r.GetError("Session值不正确或已过期", HttpStatusCode.Forbidden);
28
var userLoginModel = UserHelper.Decrypt<UserLoginModel>(encryptedUserLoginModel.Key, session, JsonSerializerOptions);
28
var userLoginModel = UserHelper.Decrypt<UserLoginModel>(encryptedUserLoginModel.Key, session);
29
29
if (userLoginModel.UID.IsNullOrWhiteSpace() || userLoginModel.UID != encryptedUserLoginModel.UserLoginModel.UID)
30
30
r.Error("登录用户ID不匹配", HttpStatusCode.Forbidden);
31
31
var user = UserHelper.GetUser(userLoginModel.UID, GetUserFunction()) ?? throw r.GetError("用户ID未注册", HttpStatusCode.Forbidden);
@@ -19,7 +19,9 @@ public class ServerIpInitializer : ServerInitializerServiceBase
19
19
{
20
20
Console.WriteLine($"正在设置服务器:{coreServerService.CoreServerName}");
21
21
Console.WriteLine($"是否绑定上一次IP:{ipAddress}?(Y/N)");
22
if (Console.ReadKey().Key == ConsoleKey.N)
22
var key = Console.ReadKey();
23
Console.WriteLine(key.Key.ToString());
24
if (key.Key == ConsoleKey.N)
23
25
{
24
26
ipAddress = string.Empty;
25
27
while (ipAddress.IsNullOrWhiteSpace())
@@ -51,7 +51,7 @@ public class XFECoreServerProcessService : CoreServerProcessServiceBase
51
51
}
52
52
catch (Exception ex)
53
53
{
54
Console.WriteLine($"[ERROR]服务器({coreServerService.CoreServerName})错误:{ex.Message}");
54
Console.WriteLine($"[ERROR]服务器({coreServerService.CoreServerName})错误:{ex.Message}:{ex.InnerException?.Message}");
55
55
Console.WriteLine($"[TRACE]{ex.StackTrace}");
56
56
Console.WriteLine($"[DEBUG]准备重启服务器({coreServerService.CoreServerName})");
57
57
await Task.Delay(1000);
@@ -87,4 +87,4 @@ public class XFECoreServerProcessService : CoreServerProcessServiceBase
87
87
}
88
88
}
89
89
}
90
}
90
}
@@ -5,7 +5,7 @@
5
5
<ImplicitUsings>enable</ImplicitUsings>
6
6
<Nullable>enable</Nullable>
7
7
<GenerateDocumentationFile>True</GenerateDocumentationFile>
8
<Version>1.0.4</Version>
8
<Version>1.0.5</Version>
9
9
<Title>XFEExtension.NetCore.ServerInteractive</Title>
10
10
<RepositoryUrl>https://github.com/XFEstudio/XFEExtension.NetCore.ServerInteractive</RepositoryUrl>
11
11
<AnalysisLevel>latest</AnalysisLevel>
@@ -21,7 +21,7 @@
21
21
<PackageReleaseNotes>
22
22
## 调整
23
23
24
为服务器和客户端的用户校验登录服务添加泛型T,用以在校验登录时返回用户信息
24
修复用户登录模型的Json转换问题
25
25
26
26
## 新增
27
27
@@ -55,7 +55,7 @@
55
55
56
56
<ItemGroup>
57
57
<PackageReference Include="System.Management" Version="9.0.9" />
58
<PackageReference Include="XFEExtension.NetCore" Version="3.3.8" />
58
<PackageReference Include="XFEExtension.NetCore" Version="3.3.9" />
59
59
<PackageReference Include="XFEExtension.NetCore.AutoConfig" Version="2.0.*" />
60
60
<PackageReference Include="XFEExtension.NetCore.AutoImplement" Version="1.1.*" />
61
61
<PackageReference Include="XFEExtension.NetCore.XFEConsole" Version="1.1.*" />