Skip to content

Commit

Permalink
节点鉴权失败原因写节点历史
Browse files Browse the repository at this point in the history
  • Loading branch information
nnhy committed Jul 10, 2024
1 parent 08d4d6e commit bd18491
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 13 deletions.
8 changes: 6 additions & 2 deletions Stardust.Server/Controllers/NodeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,12 @@ public LoginResponse Login(LoginInfo inf)
if (node != null && !node.Enable) throw new ApiException(99, "禁止登录");

// 设备不存在或者验证失败,执行注册流程
if (node == null || !_nodeService.Auth(node, inf.Secret, inf, ip, _setting))
node = _nodeService.Register(inf, ip, _setting);
if (node != null && !_nodeService.Auth(node, inf.Secret, inf, ip, _setting))
{
node = null;
}

node ??= _nodeService.Register(inf, ip, _setting);

if (node == null) throw new ApiException(12, "节点鉴权失败");

Expand Down
38 changes: 28 additions & 10 deletions Stardust.Server/Services/NodeService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using NewLife;
using System.Xml.Linq;
using NewLife;
using NewLife.Caching;
using NewLife.Log;
using NewLife.Remoting;
Expand Down Expand Up @@ -34,11 +35,21 @@ public Boolean Auth(Node node, String secret, LoginInfo inf, String ip, StarServ
if (node == null) return false;

node = CheckNode(node, inf.Node, inf.ProductCode, ip, setting.NodeCodeLevel);
if (node == null) return false;
if (node == null)
{
WriteHistory(node, "节点鉴权", false, "硬件信息变动过大", ip);
return false;
}

if (node.Secret.IsNullOrEmpty()) return true;
//return !secret.IsNullOrEmpty() && !secret.IsNullOrEmpty() && (node.Secret == secret || node.Secret.MD5() == secret);
return _passwordProvider.Verify(node.Secret, secret);
if (!_passwordProvider.Verify(node.Secret, secret))
{
WriteHistory(node, "节点鉴权", false, "密钥校验失败", ip);
return false;
}

return true;
}

public Node Register(LoginInfo inf, String ip, StarServerSetting setting)
Expand All @@ -55,13 +66,14 @@ public Node Register(LoginInfo inf, String ip, StarServerSetting setting)
}
else
{
// 登录密码未设置或者未提交,则执行动态注册
if (node == null || node.Secret.IsNullOrEmpty() || secret.IsNullOrEmpty())
node = AutoRegister(node, inf, ip, setting);
else if (node.Secret.MD5() != secret)
node = AutoRegister(node, inf, ip, setting);
else if (setting.NodeCodeLevel > 0)
node = AutoRegister(node, inf, ip, setting);
//// 登录密码未设置或者未提交,则执行动态注册
//if (node == null || node.Secret.IsNullOrEmpty() || secret.IsNullOrEmpty())
// node = AutoRegister(node, inf, ip, setting);
//else if (node.Secret.MD5() != secret)
// node = AutoRegister(node, inf, ip, setting);
//else if (setting.NodeCodeLevel > 0)
// node = AutoRegister(node, inf, ip, setting);
node = AutoRegister(node, inf, ip, setting);
}

return node;
Expand Down Expand Up @@ -786,6 +798,12 @@ public async Task<NodeCommand> SendCommand(Node node, CommandInModel model, Stri

return (node, ex);
}

private void WriteHistory(Node node, String action, Boolean success, String remark, String ip = null)
{
var hi = NodeHistory.Create(node, action, success, remark, Environment.MachineName, ip);
hi.Insert();
}
#endregion
}

Expand Down
1 change: 0 additions & 1 deletion Stardust/AppClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ public AppClient()
{
Features = Features.Ping | Features.Notify | Features.CommandReply;
SetActions("App/");
Actions[Features.CommandReply] = "App/CommandReply";

PasswordProvider = new PasswordProvider();

Expand Down

0 comments on commit bd18491

Please sign in to comment.