before server asp convertion
This commit is contained in:
parent
ce99053a10
commit
a4ed1a5956
82 changed files with 3802 additions and 444 deletions
|
|
@ -1,5 +1,8 @@
|
|||
using Insight.Domain.Interfaces;
|
||||
using Insight.Agent.Services;
|
||||
using Insight.Domain.Constants;
|
||||
using Insight.Domain.Interfaces;
|
||||
using Insight.Domain.Network;
|
||||
using Insight.Domain.Network.Agent.Messages;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Vaitr.Network;
|
||||
|
||||
|
|
@ -31,6 +34,11 @@ public class AgentSession(IEnumerable<IMessageHandler<AgentSession>> handlers, I
|
|||
{
|
||||
await base.OnReceivedAsync(context, cancellationToken);
|
||||
|
||||
// catch authentication request
|
||||
if (context.Packet is AuthenticationRequest)
|
||||
await OnAuthenticationAsync(cancellationToken);
|
||||
|
||||
// pass message to handlers
|
||||
foreach (var handler in _handlers)
|
||||
{
|
||||
try
|
||||
|
|
@ -49,4 +57,31 @@ public class AgentSession(IEnumerable<IMessageHandler<AgentSession>> handlers, I
|
|||
_logger.LogInformation("Agent ({ep?}) Heartbeat", RemoteEndPoint);
|
||||
return default;
|
||||
}
|
||||
|
||||
private async ValueTask OnAuthenticationAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
Config? config = null;
|
||||
|
||||
try
|
||||
{
|
||||
config = await Configurator.ReadAsync<Config>(Configuration.DefaultConfig, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError("Config ({config}) read error ({exception})", Configuration.DefaultConfig, ex);
|
||||
}
|
||||
|
||||
if (config is null)
|
||||
{
|
||||
config = new Config { Serial = Guid.NewGuid() };
|
||||
await Configurator.WriteAsync(config, Configuration.DefaultConfig, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
await SendAsync(new AuthenticationResponse
|
||||
{
|
||||
Serial = config.Serial ?? throw new InvalidDataException(nameof(config.Serial)),
|
||||
Version = Configuration.Version,
|
||||
Hostname = Configuration.Hostname
|
||||
}, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,43 +0,0 @@
|
|||
using Insight.Agent.Models;
|
||||
using Insight.Agent.Services;
|
||||
using Insight.Domain.Constants;
|
||||
using Insight.Domain.Interfaces;
|
||||
using Insight.Domain.Network;
|
||||
using Insight.Domain.Network.Agent.Messages;
|
||||
|
||||
namespace Insight.Agent.Network.Handlers;
|
||||
|
||||
public class AuthenticationHandler : IMessageHandler<AgentSession>
|
||||
{
|
||||
public async ValueTask HandleAsync<TMessage>(AgentSession sender, TMessage message, CancellationToken cancellationToken) where TMessage : IMessage
|
||||
{
|
||||
switch (message)
|
||||
{
|
||||
case AuthenticationRequest:
|
||||
{
|
||||
Config? config = null;
|
||||
|
||||
try
|
||||
{
|
||||
config = await Configurator.ReadAsync<Config>(Configuration.DefaultConfig, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
catch (Exception) { }
|
||||
|
||||
if (config is null)
|
||||
{
|
||||
config = new Config { Serial = Guid.NewGuid() };
|
||||
await Configurator.WriteAsync(config, Configuration.DefaultConfig, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
await sender.SendAsync(new AuthenticationResponse
|
||||
{
|
||||
Serial = config.Serial ?? throw new InvalidDataException(nameof(config.Serial)),
|
||||
Version = Configuration.Version,
|
||||
Hostname = Configuration.Hostname
|
||||
}, cancellationToken);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -51,7 +51,7 @@ public class OperationSystemHandler : IMessageHandler<AgentSession>
|
|||
|
||||
if (@object.TryGetValue<string>(properties, "osarchitecture", out var architecture))
|
||||
{
|
||||
if (architecture is not null && architecture.Contains("64", StringComparison.CurrentCultureIgnoreCase))
|
||||
if (architecture is not null && architecture.Contains("64", StringComparison.CurrentCultureIgnoreCase))
|
||||
os.Architecture = Architecture.X64;
|
||||
}
|
||||
else
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue