Example #1
0
        private static string saveFirewallRule(AddFirewallRuleViewModel rule)
        {
            var ruleName = (string.IsNullOrEmpty(rule.RuleName)) ? getNewRestrictionRuleName() : rule.RuleName;

            SshConnection.WriteStream($"uci set firewall.{ruleName}=rule");
            SshConnection.WriteStream($"uci set firewall.{ruleName}.src='*'");
            SshConnection.WriteStream($"uci set firewall.{ruleName}.dest='*'");
            SshConnection.WriteStream($"uci set firewall.{ruleName}.name='{rule.FriendlyName}'");
            if (!string.IsNullOrEmpty(rule.SourceMacs))
            {
                SshConnection.WriteStream($"uci set firewall.{ruleName}.src_mac='{rule.SourceMacs}'");
            }
            if (!string.IsNullOrEmpty(rule.SourceIPs))
            {
                SshConnection.WriteStream($"uci set firewall.{ruleName}.src_ip='{rule.SourceIPs}'");
            }
            if (!string.IsNullOrEmpty(rule.SourcePorts))
            {
                SshConnection.WriteStream($"uci set firewall.{ruleName}.src_port='{rule.SourcePorts}'");
            }
            if (!string.IsNullOrEmpty(rule.DestinationIPs))
            {
                SshConnection.WriteStream($"uci set firewall.{ruleName}.dest_ip='{rule.DestinationIPs}'");
            }
            if (!string.IsNullOrEmpty(rule.DestinationPorts))
            {
                SshConnection.WriteStream($"uci set firewall.{ruleName}.dest_port='{rule.DestinationPorts}'");
            }
            SshConnection.WriteStream($"uci set firewall.{ruleName}.target='DROP'");
            SshConnection.WriteStream($"uci set firewall.{ruleName}.enabled='{rule.Enabled}'");

            return(ruleName);
        }
Example #2
0
        public static void Send_DeleteFirewallRule(string ruleName)
        {
            SshConnection.WriteStream($"uci delete firewall.{ruleName}");
            SshConnection.WriteStream($"uci commit firewall");
            SshConnection.Send_CustomCommand($"/etc/init.d/firewall restart");

            Thread.Sleep(1500);
        }
Example #3
0
        public static string Send_SaveFirewallRule(AddFirewallRuleViewModel rule)
        {
            var ruleName = saveFirewallRule(rule);

            SshConnection.WriteStream($"uci commit firewall");
            SshConnection.Send_CustomCommand($"/etc/init.d/firewall restart");

            Thread.Sleep(1500);
            SshConnection.Send_CustomCommand($"clear");

            return(ruleName);
        }