Ejemplo n.º 1
0
        public Agent GetConnectAgent(string agentId, string requestIp, ConnectAgentViewModel request)
        {
            Agent agent = agentRepo.GetOne(Guid.Parse(agentId));

            if (agent == null)
            {
                return(agent);
            }

            if (agent.IsEnhancedSecurity == true)
            {
                if (agent.IPAddresses != requestIp)
                {
                    throw new UnauthorizedAccessException("The IP address provided does not match this Agent's IP address");
                }
                if (agent.MacAddresses != request.MacAddresses)
                {
                    throw new UnauthorizedAccessException("The MAC address provided does not match this Agent's MAC address");
                }
            }

            if (agent.MachineName != request.MachineName)
            {
                throw new UnauthorizedAccessException("The machine name provided does not match this Agent's machine name");
            }

            return(agent);
        }
        public async Task <IActionResult> Disconnect(string agentID, [FromQuery] ConnectAgentViewModel request)
        {
            try
            {
                Guid?agentGuid = new Guid(agentID);
                var  requestIp = _accessor.HttpContext.Connection.RemoteIpAddress.ToString();
                var  agent     = _agentManager.GetConnectAgent(agentID, requestIp, request);

                if (agent == null)
                {
                    return(NotFound());
                }
                if (agent.IsConnected == false)
                {
                    return(Ok());
                }

                JsonPatchDocument <Agent> disconnectPatch = new JsonPatchDocument <Agent>();

                disconnectPatch.Replace(e => e.IsConnected, false);
                await base.PatchEntity(agentID, disconnectPatch);

                return(Ok());
            }
            catch (Exception ex)
            {
                return(ex.GetActionResult());
            }
        }
        public async Task <IActionResult> Connect(string agentID, [FromQuery] ConnectAgentViewModel request)
        {
            try
            {
                Guid entityId = new Guid(agentID);

                ConnectedViewModel connectedViewModel = new ConnectedViewModel();
                var requestIp = _accessor.HttpContext.Connection.RemoteIpAddress.ToString();
                var agent     = _agentManager.GetConnectAgent(agentID, requestIp, request);

                if (agent == null)
                {
                    return(NotFound());
                }

                if (agent.IsConnected == false)
                {
                    JsonPatchDocument <Agent> connectPatch = new JsonPatchDocument <Agent>();

                    connectPatch.Replace(e => e.IsConnected, true);
                    await base.PatchEntity(agent.Id.ToString(), connectPatch);
                }

                return(new OkObjectResult(connectedViewModel.Map(agent)));
            }
            catch (Exception ex)
            {
                return(ex.GetActionResult());
            }
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> Connect([FromQuery] ConnectAgentViewModel request = null)
        {
            try
            {
                ConnectedViewModel connectedViewModel = new ConnectedViewModel();
                var requestIp = _accessor.HttpContext.Connection.RemoteIpAddress.ToString();
                var agent     = agentRepo.FindAgent(request.MachineName, request.MacAddresses, requestIp);

                if (agent == null)
                {
                    ModelState.AddModelError("Connect", "Record does not exist or you do not have authorized access.");
                    return(BadRequest(ModelState));
                }
                if (agent.IsConnected == false)
                {
                    JsonPatchDocument <AgentModel> connectPatch = new JsonPatchDocument <AgentModel>();

                    connectPatch.Replace(e => e.IsConnected, true);
                    await base.PatchEntity(agent.Id.ToString(), connectPatch);
                }

                return(new OkObjectResult(connectedViewModel.Map(agent)));
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("Connect", ex.Message);
                return(ex.GetActionResult());
            }
        }
Ejemplo n.º 5
0
        public static void DisconnectAgent(UserInfo userInfo, string agentId, ConnectAgentViewModel connectAgentViewModel, int count = 0)
        {
            var agentsApi = GetApiInstance(userInfo.Token, userInfo.ServerUrl);

            try
            {
                agentsApi.ApiVapiVersionAgentsAgentIDDisconnectPatchWithHttpInfo(agentId, userInfo.ApiVersion, userInfo.OrganizationId, connectAgentViewModel);
            }
            catch (Exception ex)
            {
                if (ex.GetType().GetProperty("ErrorCode").GetValue(ex, null).ToString() == "401" && count < 2)
                {
                    UtilityMethods.RefreshToken(userInfo);
                    count++;
                    DisconnectAgent(userInfo, agentId, connectAgentViewModel, count);
                }
                else if (ex.Message != "One or more errors occurred.")
                {
                    throw new InvalidOperationException("Exception when calling AgentsApi.DisconnectAgent: " + ex.Message);
                }
                else
                {
                    throw new InvalidOperationException(ex.InnerException.Message);
                }
            }
        }
Ejemplo n.º 6
0
        public async Task <IActionResult> Disconnect(string agentID, [FromQuery] ConnectAgentViewModel request)
        {
            try
            {
                Guid?agentGuid = new Guid(agentID);
                var  requestIp = _accessor.HttpContext.Connection.RemoteIpAddress.ToString();
                _agentManager.DisconnectAgent(agentGuid, requestIp, request);

                return(Ok());
            }
            catch (Exception ex)
            {
                return(ex.GetActionResult());
            }
        }
Ejemplo n.º 7
0
        public static void DisconnectAgent(UserInfo userInfo, string agentId, ConnectAgentViewModel connectAgentViewModel)
        {
            var agentsApi = GetApiInstance(userInfo.Token, userInfo.ServerUrl);

            try
            {
                agentsApi.ApiVapiVersionAgentsAgentIDDisconnectPatchWithHttpInfo(agentId, connectAgentViewModel.MachineName, connectAgentViewModel.MacAddresses);
            }
            catch (Exception ex)
            {
                if (ex.Message != "One or more errors occurred.")
                {
                    throw new InvalidOperationException("Exception when calling AgentsApi.DisconnectAgent: " + ex.Message);
                }
                else
                {
                    throw new InvalidOperationException(ex.InnerException.Message);
                }
            }
        }