Ejemplo n.º 1
0
        public async Task <IActionResult> CrossDeviceRule(Agent.Generic.Models.Rule rule)
        {
            var f    = Request.Form;
            var devs = f["Device"];

            try
            {
                rule.LocalPort     = rule.LocalPort ?? Agent.Generic.Models.Rule.ANY_PORT;
                rule.RemoteAddress = System.Net.IPAddress.Parse(rule.RemoteAddress).ToString();
            }
            catch (FormatException)
            {
                rule.RemoteAddress = Agent.Generic.Models.Rule.ANY_IP_ADDRESS;
            }

            // TODO: Add to UI
            if (rule.Direction == Agent.Generic.Models.Direction.In)
            {
                rule.RemotePort   = Agent.Generic.Models.Rule.ANY_PORT;
                rule.LocalAddress = Agent.Generic.Models.Rule.ANY_IP_ADDRESS;
            }
            else
            {
                rule.RemotePort = rule.LocalPort;

                rule.LocalPort    = Agent.Generic.Models.Rule.ANY_PORT;
                rule.LocalAddress = Agent.Generic.Models.Rule.ANY_IP_ADDRESS;
            }

            var dtoRule = new SetRuleRequest();

            dtoRule.GenericRequest = rule;

            var client = new AgentApiClient();

            var tasks = new List <Task>(devs.Count);

            foreach (var device in devs)
            {
                var d = deviceRepo.GetDevice(device);
                tasks.Add(client.NewRule(d.Address, dtoRule));
            }

            await Task.WhenAll(tasks);

            return(RedirectToAction("Index"));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Create(string id, Agent.Generic.Models.Rule rule)
        {
            var device = repo.GetDevice(id);

            try
            {
                rule.LocalPort     = rule.LocalPort ?? Agent.Generic.Models.Rule.ANY_PORT;
                rule.RemoteAddress = System.Net.IPAddress.Parse(rule.RemoteAddress).ToString();
            }
            catch (FormatException)
            {
                rule.RemoteAddress = Agent.Generic.Models.Rule.ANY_IP_ADDRESS;
            }

            // TODO: Add to UI
            if (rule.Direction == Agent.Generic.Models.Direction.In)
            {
                rule.RemotePort   = Agent.Generic.Models.Rule.ANY_PORT;
                rule.LocalAddress = Agent.Generic.Models.Rule.ANY_IP_ADDRESS;
            }
            else
            {
                rule.RemotePort = rule.LocalPort;

                rule.LocalPort    = Agent.Generic.Models.Rule.ANY_PORT;
                rule.LocalAddress = Agent.Generic.Models.Rule.ANY_IP_ADDRESS;
            }

            var dtoRule = new SetRuleRequest();

            dtoRule.GenericRequest = rule;

            var client = new AgentApiClient();
            await client.NewRule(device.Address, dtoRule);

            return(RedirectToAction("Index"));
        }