Ejemplo n.º 1
0
        public ConfigureResponse Configure(ConfigureRequest request)
        {
            ToastHelper.PopToast("Configure");

            if (request.FirewallEnabled)
            {
                FirewallHelper.Enable();
            }
            else
            {
                FirewallHelper.Disable();
            }

            return(new ConfigureResponse()
            {
                FirewallEnabled = FirewallHelper.IsEnabled()
            });
        }
Ejemplo n.º 2
0
        public SetRuleResponse NewRule(SetRuleRequest rule)
        {
            ToastHelper.PopToast("New rule");

            Linux.Models.Rule newEntry = null;

            if (rule.GenericRequest != null)
            {
                newEntry = (Linux.Models.Rule)(new LinuxRuleAdapter(rule.GenericRequest).NativeType);
            }
            else if (rule.UfwRequest != null)
            {
                newEntry = rule.UfwRequest;
            }

            //var st = Mapper.Map<FirewallAPI.Rule>(newEntry);
            FirewallHelper.NewRule(newEntry);
            return(new SetRuleResponse()
            {
                Success = true
            });
        }
Ejemplo n.º 3
0
        public void OnStart(string[] args)
        {
            try
            {
                ToastHelper.PopToast("Starting...");

                Console.WriteLine("Starting API");
                var api = Task.Run(delegate { API.Program.Main(args, new ApiCallbacks(), new ApiConfiguration()); });

                Console.WriteLine("Starting Netfilter Listener");
                var logHelper = Task.Run(delegate { netfilterLogHelper.Start(); });

                Console.WriteLine("Starting UFW Listener");
                var ufwLogHelperTask = Task.Run(delegate { ufwLogHelper.Start(); });

                Task.Run(delegate { snmpClient.Start(); });

                Task.WhenAll(api, logHelper, ufwLogHelperTask).Wait();
            }
            catch (Exception e)
            {
                StringBuilder sb = new StringBuilder();
                sb.AppendLine(e.Message);
                sb.AppendLine("\n\n");
                sb.AppendLine(e.StackTrace);

                if (e.InnerException != null)
                {
                    sb.AppendLine("\n\n\n\n");
                    sb.AppendLine(e.InnerException.Message);
                    sb.AppendLine("\n\n");
                    sb.AppendLine(e.InnerException.StackTrace);
                }

                ExceptionHelper.WriteFile("Global", sb.ToString());
            }
        }
Ejemplo n.º 4
0
 public void DeleteRule(string id)
 {
     ToastHelper.PopToast("Delete rule");
     FirewallHelper.DeleteRule(Convert.ToUInt32(id));
 }