public static IEnumerable <string> Get_RestrictionRulesNames() { var answer = SshConnection.Send_CustomCommand("grep RouterManagementRule /etc/config/firewall"); return(from Match match in Regex.Matches(answer, "(RouterManagementRule_)([0-9]+)") select match.ToString()); }
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); }
public static FirewallRule Get_FirewallRuleByName(string ruleName) { if (string.IsNullOrEmpty(ruleName)) { throw new Exception("Can't get rule without name!"); } if (ruleName.Any(char.IsWhiteSpace)) { throw new Exception("Rule name contains whitespaces!"); } var routerConfig = SshConnection.Send_CustomCommand($"uci show firewall.{ruleName}"); var currentConfiguratrion = SshConnection.ParseAnswerToDictionary(routerConfig); var rule = new FirewallRule { RuleName = ruleName }; if (currentConfiguratrion.ContainsKey($"firewall.{ruleName}.name")) { rule.FriendlyName = currentConfiguratrion[$"firewall.{ruleName}.name"].Trim('\''); } if (currentConfiguratrion.ContainsKey($"firewall.{ruleName}.src_mac")) { rule.Src_mac = currentConfiguratrion[$"firewall.{ruleName}.src_mac"].Trim().Trim('\'').Split(','); } if (currentConfiguratrion.ContainsKey($"firewall.{ruleName}.src_ip")) { rule.Src_ip = currentConfiguratrion[$"firewall.{ruleName}.src_ip"].Trim().Trim('\'').Split(','); } if (currentConfiguratrion.ContainsKey($"firewall.{ruleName}.src_port")) { rule.Src_port = currentConfiguratrion[$"firewall.{ruleName}.src_port"].Trim().Trim('\'').Split(','); } if (currentConfiguratrion.ContainsKey($"firewall.{ruleName}.dest_ip")) { rule.Dest_ip = currentConfiguratrion[$"firewall.{ruleName}.dest_ip"].Trim().Trim('\'').Split(','); } if (currentConfiguratrion.ContainsKey($"firewall.{ruleName}.dest_port")) { rule.Dest_port = currentConfiguratrion[$"firewall.{ruleName}.dest_port"].Trim().Trim('\'').Split(','); } if (currentConfiguratrion.ContainsKey($"firewall.{ruleName}.enabled")) { rule.Enabled = currentConfiguratrion[$"firewall.{ruleName}.enabled"].Trim('\''); } return(rule); }
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); }