Пример #1
0
        public IActionResult CreatePolicyRule(string id, Agent.Generic.Models.Rule rule)
        {
            try
            {
                rule.LocalAddress  = Agent.Generic.Models.Rule.ANY_IP_ADDRESS;
                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 - Correct Address
            if (rule.Direction == Agent.Generic.Models.Direction.In)
            {
                rule.RemotePort = Agent.Generic.Models.Rule.ANY_PORT;
            }
            else
            {
                rule.RemotePort = rule.LocalPort;
                rule.LocalPort  = Agent.Generic.Models.Rule.ANY_PORT;
            }

            var policyRule = Mapper.Map <PolicyRule>(rule);

            policyRule.PolicyId = id;

            policyRepo.AddPolicyRule(policyRule);
            return(RedirectToAction("Index", new { id = id }));
        }