public bool ConfigDNP3Rules(DNP3RulesForm dnp3rf, bool log_flag, bool add_delete) { string flag = null; String dnp3_rules_from_client_to_server_new = "iptables -A FORWARD -p tcp -s " + dnp3rf.getSrc_IP() + " -d " + dnp3rf.getDst_IP() + " --dport 20000 -m state --state NEW -j ACCEPT"; // String dnp3_rules_from_server_to_client_new = "iptables -A FORWARD -p tcp -s " + dnp3rf.getDst_IP() + " -d " + dnp3rf.getSrc_IP() + " --sport 20000 -m state --state NEW -j ACCEPT"; String dnp3_rules_from_client_to_server_established = "iptables -A FORWARD -p tcp -s " + dnp3rf.getSrc_IP() + " -d " + dnp3rf.getDst_IP() + " --dport 20000 -m state --state ESTABLISHED -j ACCEPT"; String dnp3_rules_from_client_to_server_back = "iptables -A FORWARD -p tcp -d " + dnp3rf.getSrc_IP() + " -s " + dnp3rf.getDst_IP(); string dnp3_rules_from_client_to_server_log = "iptables -A FORWARD -p tcp -s " + dnp3rf.getSrc_IP() + " -d " + dnp3rf.getDst_IP() + " --dport 20000 -m state --state ESTABLISHED -j LOG --log-prefix " + "\"" + "ACCEPT&DNP3&ESTABLISHED " + "\""; // String dnp3_rules_from_server_to_client_established = "iptables -A FORWARD -p tcp -s " + dnp3rf.getDst_IP() + " -d " + dnp3rf.getSrc_IP() + " --sport 20000 -m state --state ESTABLISHED -j ACCEPT"; if (add_delete == true) { flag = "DPI1"; string frule = devform.getDev_IP() + " " + dnp3rf.getDst_IP() + " " + dnp3rf.getSrc_IP() + " ACCEPT " + log_flag.ToString(); of.SaveRules(frule, "dnp3"); } else if (add_delete == false) { flag = "DPI0"; string frule = devform.getDev_IP() + " " + dnp3rf.getDst_IP() + " " + dnp3rf.getSrc_IP() + " ACCEPT " + log_flag.ToString(); of.DeleteRules(frule, "dnp3"); } string rule = flag + dnp3_rules_from_client_to_server_log + " && " + dnp3_rules_from_client_to_server_new + " && " + dnp3_rules_from_client_to_server_established; SendInfo sendcmd = new SendInfo(devform); return(sendcmd.SendConfigInfo(rule)); }
public bool ConfigDNP3Rules(DNP3RulesForm dnp3rf, bool log_flag, bool add_delete) { string flag = null; string sql_rule = null; String dnp3_rules_from_client_to_server_new = "iptables -A FORWARD -p tcp -s " + dnp3rf.getSrc_IP() + " -d " + dnp3rf.getDst_IP() + " --dport 20000 -m state --state NEW -j ACCEPT"; // String dnp3_rules_from_server_to_client_new = "iptables -A FORWARD -p tcp -s " + dnp3rf.getDst_IP() + " -d " + dnp3rf.getSrc_IP() + " --sport 20000 -m state --state NEW -j ACCEPT"; String dnp3_rules_from_client_to_server_established = "iptables -A FORWARD -p tcp -s " + dnp3rf.getSrc_IP() + " -d " + dnp3rf.getDst_IP() + " --dport 20000 -m state --state ESTABLISHED -j ACCEPT"; String dnp3_rules_from_client_to_server_back = "iptables -A FORWARD -p tcp -d " + dnp3rf.getSrc_IP() + " -s " + dnp3rf.getDst_IP(); string dnp3_rules_from_client_to_server_log = "iptables -A FORWARD -p tcp -s " + dnp3rf.getSrc_IP() + " -d " + dnp3rf.getDst_IP() + " --dport 20000 -m state --state ESTABLISHED -j LOG --log-prefix " + "\"" + "ACCEPT&DNP3&ESTABLISHED " + "\""; // String dnp3_rules_from_server_to_client_established = "iptables -A FORWARD -p tcp -s " + dnp3rf.getDst_IP() + " -d " + dnp3rf.getSrc_IP() + " --sport 20000 -m state --state ESTABLISHED -j ACCEPT"; if (add_delete == true) { flag = "DPI1"; sql_rule = "INSERT INTO DNP3 values " + "('" + devform.getDev_IP() + "','" + dnp3rf.getDst_IP() + "','" + dnp3rf.getSrc_IP() + "','ACCEPT','" + log_flag + "')"; } else if (add_delete == false) { flag = "DPI0"; sql_rule = "DELETE FROM DNP3 where (dev_IP='" + devform.getDev_IP() + "' and dst_IP='" + dnp3rf.getDst_IP() + "' and src_IP='" + dnp3rf.getSrc_IP() + "' and method='ACCEPT')"; } string rule = flag + dnp3_rules_from_client_to_server_log + " && " + dnp3_rules_from_client_to_server_new + " && " + dnp3_rules_from_client_to_server_established; DPIdb_operate.dboperate(sql_rule); SendInfo sendcmd = new SendInfo(devform); return(sendcmd.SendConfigInfo(rule)); }