Example #1
0
        private void bindData()
        {
            var firewallRule = FirewallConnection.Get_FirewallRuleByName(ruleName);

            editRuleNameEditText.Text            = firewallRule.FriendlyName;
            editRuleSourceMacEditText.Text       = (firewallRule.Src_mac != null) ? string.Join(", ", firewallRule.Src_mac) : string.Empty;
            editRuleSourceIpEditText.Text        = (firewallRule.Src_ip != null) ? string.Join(", ", firewallRule.Src_ip) : string.Empty;
            editRuleSourcePortEditText.Text      = (firewallRule.Src_port != null) ? string.Join(", ", firewallRule.Src_port) : string.Empty;
            editRuleDestinationIpEditText.Text   = (firewallRule.Dest_ip != null) ? string.Join(", ", firewallRule.Dest_ip) : string.Empty;
            editRuleDestinationPortEditText.Text = (firewallRule.Dest_port != null) ? string.Join(", ", firewallRule.Dest_port) : string.Empty;

            editRuleEnabledCheckBox.Checked = firewallRule.Enabled.Contains('1');
        }
Example #2
0
        private void bindData()
        {
            var firewallRule = FirewallConnection.Get_FirewallRuleByName(ruleName);

            showRuleNameTextView.Text            = firewallRule.FriendlyName;
            showRuleSourceMacTextView.Text       = (firewallRule.Src_mac != null) ? string.Join(", ", firewallRule.Src_mac) : string.Empty;
            showRuleSourceIpTextView.Text        = (firewallRule.Src_ip != null) ? string.Join(", ", firewallRule.Src_ip) : string.Empty;
            showRuleSourcePortTextView.Text      = (firewallRule.Src_port != null) ? string.Join(", ", firewallRule.Src_port) : string.Empty;
            showRuleDestinationIpTextView.Text   = (firewallRule.Dest_ip != null) ? string.Join(", ", firewallRule.Dest_ip) : string.Empty;
            showRuleDestinationPortTextView.Text = (firewallRule.Dest_port != null) ? string.Join(", ", firewallRule.Dest_port) : string.Empty;

            showRuleEnabledTextView.Text = firewallRule.Enabled.Contains('1') ? "true" : "false";
        }
Example #3
0
 private void deleteRuleButton_Click(object sender, EventArgs e)
 {
     try
     {
         FirewallConnection.Send_DeleteFirewallRule(ruleName);
     }
     catch (Exception ex)
     {
         Toast.MakeText(this, $"Error occured when deleting firewall rule. Error content: {ex.Message}", ToastLength.Short).Show();
     }
     StartActivity(typeof(FirewallActivity));
     Finish();
 }
Example #4
0
        private void bindData()
        {
            firewallNames = FirewallConnection.Get_AllFirewallRestrictionRules()
                            .Select((ruleName, friendlyName) => new { ruleName.RuleName, ruleName.FriendlyName })
                            .ToDictionary(it => it.RuleName, x => x.FriendlyName);

            var adapter = new ArrayAdapter <string>(this, Android.Resource.Layout.SimpleListItem1, firewallNames.Select(rule => rule.Value).ToArray());

            if (adapter.Count <= 0)
            {
                return;
            }
            firewall.Adapter = adapter;
        }
Example #5
0
        private void SaveModifiedRuleButtonClick(object sender, EventArgs e)
        {
            var valid = true;

            if (FirewallConnection.Get_RestrictionRulesNames().Contains(addRuleNameEditText.Text))
            {
                Toast.MakeText(this, $"Rule with this name already exist.", ToastLength.Short).Show();
                valid = false;
            }

            if (string.IsNullOrEmpty(addRuleNameEditText.Text))
            {
                Toast.MakeText(this, $"Rule name can't be empty.", ToastLength.Short).Show();
                valid = false;
            }

            if (!addRuleSourceMacEditText.Text.Any() &&
                !addRuleSourceIpEditText.Text.Any() &&
                !addRuleSourcePortEditText.Text.Any() &&
                !addRuleDestinationIpEditText.Text.Any() &&
                !addRuleDestinationPortEditText.Text.Any())
            {
                Toast.MakeText(this, $"You have to type at least one condition.", ToastLength.Short).Show();
                valid = false;
            }

            const string validateMacPattern  = @"^$|^(((([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})[,])*)(([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})))$";
            const string validateIpPattern   = @"^$|^((((([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])[,])*)((([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])))$";
            const string validatePortPattern = @"^$|^((([0-9]{1,4}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5])[,])|((([0-9]{1,4}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5])([-])([0-9]{1,4}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5]))[,]))*((([0-9]{1,4}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5]))|(([0-9]{1,4}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5])([-])([0-9]{1,4}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5])))$";

            if (!Regex.Match(addRuleSourceMacEditText.Text, validateMacPattern, RegexOptions.IgnoreCase).Success)
            {
                Toast.MakeText(this, $"You have typed source Mac in not proper format.", ToastLength.Short).Show();
                valid = false;
            }

            if (!Regex.Match(addRuleSourceIpEditText.Text, validateIpPattern, RegexOptions.IgnoreCase).Success)
            {
                Toast.MakeText(this, $"You have typed source IP in not proper format.", ToastLength.Short).Show();
                valid = false;
            }

            if (!Regex.Match(addRuleSourcePortEditText.Text, validatePortPattern, RegexOptions.IgnoreCase).Success)
            {
                Toast.MakeText(this, $"You have typed source port in not proper format.", ToastLength.Short).Show();
                valid = false;
            }

            if (!Regex.Match(addRuleDestinationIpEditText.Text, validateIpPattern, RegexOptions.IgnoreCase).Success)
            {
                Toast.MakeText(this, $"You have typed destination IP in not proper format.", ToastLength.Short).Show();
                valid = false;
            }

            if (!Regex.Match(addRuleDestinationPortEditText.Text, validatePortPattern, RegexOptions.IgnoreCase).Success)
            {
                Toast.MakeText(this, $"You have typed destination port in not proper format.", ToastLength.Short).Show();
                valid = false;
            }

            if (!valid)
            {
                return;
            }

            var newRule = new AddFirewallRuleViewModel
            {
                RuleName         = null,
                FriendlyName     = addRuleNameEditText.Text,
                SourceMacs       = addRuleSourceMacEditText.Text,
                SourceIPs        = addRuleSourceIpEditText.Text,
                SourcePorts      = addRuleSourcePortEditText.Text,
                DestinationIPs   = addRuleDestinationIpEditText.Text,
                DestinationPorts = addRuleDestinationPortEditText.Text,
                Enabled          = addRuleEnabledCheckBox.Enabled ? "1" : "0"
            };

            FirewallConnection.Send_SaveFirewallRule(newRule);

            StartActivity(typeof(FirewallActivity));
            Finish();
        }