public void AddRule(FRule rule) { //create the rule in right syntax string ruleAsText; if (rule.chain == "OUTPUT") { rule.number = data.outputRules.Count; data.rawoutputRules.Add(rule); ruleAsText = rule.ToString(); data.outputRules.Add(ruleAsText); } else { //get the raw data,then process and get the nice text rule.number = data.inputRules.Count; data.rawinputRules.Add(rule); ruleAsText = rule.ToString(); data.inputRules.Add(ruleAsText); } RefreshRules(); }
public string Level7Check() { string finalString = ""; FRule correct = new FRule("INPUT", "77.75.77.20", 80, "DROP"); FRule wrong1 = new FRule("INPUT", "77.75.77.20", 80, "ACCEPT"); FRule wrong2 = new FRule("INPUT", "77.75.77.20", 80, "REJECT"); FRule correct2 = new FRule("OUTPUT", "177.75.77.12", 1433, "ACCEPT"); FRule wrong21 = new FRule("OUTPUT", "177.75.77.12", 1433, "REJECT"); FRule wrong22 = new FRule("OUTPUT", "177.75.77.12", 1443, "DROP"); FRule correct3 = new FRule("INPUT", "200.30.175.162", 1433, "ACCEPT"); FRule wrong31 = new FRule("INPUT", "200.30.175.162", 1433, "REJECT"); FRule wrong32 = new FRule("INPUT", "200.30.175.162", 1433, "DROP"); //check //inner List <FRule> rightGreen = new List <FRule> { correct, correct3, correct2 }; List <FRule> wrongRed = new List <FRule> { wrong1, wrong2, wrong21, wrong22, wrong31, wrong32 }; if (checker.LevelCheckInput(correct, wrong1, innerData) && checker.LevelCheckInput(correct, wrong2, innerData) && checker.LevelCheckOutput(correct2, wrong21, innerData) && checker.LevelCheckOutput(correct2, wrong22, innerData) && checker.LevelCheckInput(correct3, wrong31, innerData) && checker.LevelCheckInput(correct3, wrong32, innerData)) { levelComplete = true; return(finalString = "<size=48>Good Job</size>\n" + GenerateFeedback(rightGreen, wrongRed, innerData)); } else { return(finalString = "<size=48>Something is not right,try again</size>\n" + GenerateFeedback(rightGreen, wrongRed, innerData)); } }
public string TutorialCheck() { string finalString = ""; // string feedback = ""; FRule correct = new FRule("OUTPUT", "177.75.77.12", 22, "ACCEPT"); FRule wrong1 = new FRule("OUTPUT", "177.75.77.12", 22, "REJECT"); FRule wrong2 = new FRule("OUTPUT", "177.75.77.12", 22, "DROP"); List <FRule> rightGreen = new List <FRule> { correct }; List <FRule> wrongRed = new List <FRule> { wrong1, wrong2 }; print(levelComplete); //check if (checker.LevelCheckOutput(correct, wrong1, innerData) && checker.LevelCheckOutput(correct, wrong2, innerData)) { levelComplete = true; print(levelComplete); finalString = "<size=48>Good Job</size>\n" + GenerateFeedback(rightGreen, wrongRed, innerData); return(finalString); } else { finalString = "<size=48>Something is not right,try again</size>\n" + GenerateFeedback(rightGreen, wrongRed, innerData); print(levelComplete); return(finalString); } }
public string Level6Check() { string finalString = ""; FRule correct = new FRule("INPUT", "200.30.175.162", 2001, "DROP"); FRule wrong1 = new FRule("INPUT", "200.30.175.162", 2001, "ACCEPT"); FRule wrong2 = new FRule("INPUT", "200.30.175.162", 2001, "REJECT"); //check List <FRule> rightGreen = new List <FRule> { correct }; List <FRule> wrongRed = new List <FRule> { wrong1, wrong2 }; if (checker.LevelCheckInput(correct, wrong1, innerData) && checker.LevelCheckInput(correct, wrong2, innerData)) { levelComplete = true; return(finalString = "<size=48>Good Job</size>\n" + GenerateFeedback(rightGreen, wrongRed, innerData)); } else { return(finalString = "<size=48>Something is not right,try again</size>\n" + GenerateFeedback(rightGreen, wrongRed, innerData)); } }
//public FireWallData check; public bool Check(FRule rule1, FRule rule2) { if (rule1.chain == rule2.chain && rule1.ip == rule2.ip && rule1.port == rule2.port && rule1.policy.Equals(rule2.policy)) { return(true); } return(false); }
public string Level8Check() { string finalString = ""; //inner FRule correct1 = new FRule("OUTPUT", "177.75.77.12", 1433, "ACCEPT"); FRule wrong11 = new FRule("OUTPUT", "177.75.77.12", 1433, "REJECT"); FRule wrong12 = new FRule("OUTPUT", "177.75.77.12", 1433, "DROP"); FRule correct2 = new FRule("INPUT", "177.78.78.7", 1433, "DROP"); FRule wrong21 = new FRule("INPUT", "177.78.78.7", 1433, "ACCEPT"); FRule wrong22 = new FRule("INPUT", "177.78.78.7", 1443, "REJECT"); FRule correct3 = new FRule("INPUT", "177.78.78.6", 1433, "ACCEPT"); FRule wrong31 = new FRule("INPUT", "177.78.78.6", 1433, "REJECT"); FRule wrong32 = new FRule("INPUT", "177.78.78.6", 1433, "DROP"); //outer FRule correct4 = new FRule("INPUT", "200.30.175.162", 1433, "DROP"); FRule wrong41 = new FRule("INPUT", "200.30.175.162", 1433, "ACCEPT"); FRule wrong42 = new FRule("INPUT", "200.30.175.162", 1433, "DROP"); FRule correct6 = new FRule("INPUT", "155.55.80.77", 1433, "DROP"); FRule wrong61 = new FRule("INPUT", "155.55.80.77", 1433, "ACCEPT"); FRule wrong62 = new FRule("INPUT", "155.55.80.77", 1433, "REJECT"); //inner List <FRule> rightGreen = new List <FRule> { correct1, correct3, correct2 }; List <FRule> wrongRed = new List <FRule> { wrong11, wrong12, wrong21, wrong22, wrong31, wrong32 }; //outer List <FRule> rightGreenOut = new List <FRule> { correct4, correct6 }; List <FRule> wrongRedOut = new List <FRule> { wrong41, wrong42, wrong62, wrong62 }; if (checker.LevelCheckOutput(correct1, wrong11, innerData) && checker.LevelCheckOutput(correct1, wrong12, innerData) && checker.LevelCheckInput(correct2, wrong21, innerData) && checker.LevelCheckInput(correct2, wrong22, innerData) && checker.LevelCheckInput(correct3, wrong31, innerData) && checker.LevelCheckInput(correct3, wrong32, innerData) && checker.LevelCheckInput(correct4, wrong41, outerData) && checker.LevelCheckInput(correct4, wrong42, outerData) && checker.LevelCheckInput(correct6, wrong61, outerData) && checker.LevelCheckInput(correct6, wrong62, outerData)) { levelComplete = true; return(finalString = "<size=48>Good Job</size>\n" + GenerateFeedback(rightGreen, wrongRed, rightGreenOut, wrongRedOut, innerData, outerData)); } else { return(finalString = "<size=48>Something is not right,try again</size>\n" + GenerateFeedback(rightGreen, wrongRed, rightGreenOut, wrongRedOut, innerData, outerData)); } }
//give it right and bad, if right comes before bad its all good public bool LevelCheckInput(FRule goodRule, FRule badRule, FireWallData check) { Stack <FRule> inputCopy = new Stack <FRule>(); for (int i = 0; i < check.inputRules.Count; i++) { FRule x = check.rawinputRules[i]; // print (x.ToString ()); inputCopy.Push(x); } //sanity check,dont run without any rules if (inputCopy.Count == 0) { return(false); } //flags for hitting good/bad bool good = false; bool bad = false; //if we are dealing with input //check all input rules for (int i = 0; i <= inputCopy.Count; i++) { //print ("i# in " + i.ToString()); //make a local variable to avoid retyping FRule rule = inputCopy.Peek(); //look at the rule at the top of stack,if it matches the good rule if (Check(rule, goodRule)) { //if it matches, set good to true good = true; } //check the bad rule if (Check(rule, badRule)) { //if it matches, set good to true bad = true; } //MASTER CHECK IMPORTANT if (good && !bad) { return(true); } if (bad && !good) { return(false); } //pop the now checked rule inputCopy.Pop(); } // if we have not returned true by this point, the good rule doesnt exist return(false); }
public string Level4Check() { string finalString = ""; //inner FRule correct1 = new FRule("INPUT", "177.75.78.10", 587, "ACCEPT"); FRule wrong11 = new FRule("INPUT", "177.75.78.10", 587, "REJECT"); FRule wrong12 = new FRule("INPUT", "177.75.78.10", 587, "DROP"); FRule correct2 = new FRule("OUTPUT", "177.75.77.13", 587, "ACCEPT"); FRule wrong21 = new FRule("OUTPUT", "177.75.77.13", 587, "REJECT"); FRule wrong22 = new FRule("OUTPUT", "177.75.77.13", 587, "DROP"); FRule correct3 = new FRule("OUTPUT", "177.75.77.12", 587, "ACCEPT"); FRule wrong31 = new FRule("OUTPUT", "177.75.77.12", 587, "REJECT"); FRule wrong32 = new FRule("OUTPUT", "177.75.77.12", 587, "DROP"); //outer FRule correct4 = new FRule("INPUT", "77.75.77.20", 25, "ACCEPT"); FRule wrong41 = new FRule("INPUT", "77.75.77.20", 25, "REJECT"); FRule wrong42 = new FRule("INPUT", "77.75.77.20", 25, "DROP"); FRule correct5 = new FRule("OUTPUT", "177.75.78.10", 25, "ACCEPT"); FRule wrong51 = new FRule("OUTPUT", "177.75.78.10", 25, "REJECT"); FRule wrong52 = new FRule("OUTPUT", "177.75.78.10", 25, "DROP"); //inner List <FRule> rightGreen = new List <FRule> { correct1, correct3, correct2 }; List <FRule> wrongRed = new List <FRule> { wrong11, wrong12, wrong21, wrong22, wrong31, wrong32 }; //outer List <FRule> rightGreenOut = new List <FRule> { correct4 }; List <FRule> wrongRedOut = new List <FRule> { wrong41, wrong42 }; if (checker.LevelCheckInput(correct1, wrong11, innerData) && checker.LevelCheckInput(correct1, wrong12, innerData) && checker.LevelCheckOutput(correct2, wrong21, innerData) && checker.LevelCheckOutput(correct2, wrong22, innerData) && checker.LevelCheckOutput(correct3, wrong31, innerData) && checker.LevelCheckOutput(correct3, wrong32, innerData) && checker.LevelCheckInput(correct4, wrong41, outerData) && checker.LevelCheckInput(correct4, wrong42, outerData) && checker.LevelCheckInput(correct5, wrong51, outerData) && checker.LevelCheckInput(correct5, wrong52, outerData)) { levelComplete = true; return(finalString = "<size=48>Good Job</size>\n" + GenerateFeedback(rightGreen, wrongRed, rightGreenOut, wrongRedOut, innerData, outerData)); } else { return(finalString = "<size=48>Something is not right,try again</size>\n" + GenerateFeedback(rightGreen, wrongRed, rightGreenOut, wrongRedOut, innerData, outerData)); } }
public void Submit() { //make the rule FRule newRule = new FRule("", "", 0, ""); GetChain(newRule); GetIP(newRule); GetPort(newRule); GetPolicy(newRule); //add the rule firewall.AddRule(newRule); //data.RefreshRules (); }
public void GetPolicy(FRule rule) { //check if any are on if (policy.AnyTogglesOn()) { //if so,only one can be on, so get it Toggle activeToggle = policy.ActiveToggles().First(); rule.policy = (activeToggle.GetComponentInChildren <Text> ().text); } else { rule.policy = ("X"); } }
public string TestCheck() { FRule correct = new FRule("OUTPUT", "177.75.77.12", 22, "ACCEPT"); FRule wrong1 = new FRule("OUTPUT", "177.75.77.12", 22, "REJECT"); FRule wrong2 = new FRule("OUTPUT", "177.75.77.12", 22, "DROP"); //check if (checker.LevelCheckOutput(correct, wrong1, innerData) && checker.LevelCheckOutput(correct, wrong2, innerData)) { return("Good Job"); } else { return("Something is not right,try again"); } }
//helper function for generateFeedback, to test if a rule is in a list public bool CompareAgainstAList(FRule testRule, List <FRule> compareList) { bool isIn = false; for (int i = 0; i < compareList.Count; i++) { if (checker.Check(testRule, compareList[i])) { isIn = true; } else { continue; } } return(isIn); }
public void GetPort(FRule rule) { //check if any are on if (port.AnyTogglesOn()) { //if so,only one can be on, so get it Toggle activeToggle = port.ActiveToggles().First(); //for ranges set it to 2001 if (activeToggle.GetComponentInChildren <Text> ().text.Contains(":")) { rule.port = 2001; } else { rule.port = int.Parse((activeToggle.GetComponentInChildren <Text> ().text)); } } else { rule.port = 0; } }
//give it right and bad, if right comes before bad its all good public bool LevelCheckOutput(FRule goodRule, FRule badRule, FireWallData check) { //flags for hitting good/bad bool good = false; bool bad = false; //set up new queues/copies that we can pop from Stack <FRule> outputCopy = new Stack <FRule>(); //check if there are actually any rules for (int i = 0; i < check.outputRules.Count; i++) { FRule x = check.rawoutputRules[i]; //print ("push "+x.ToString ()); outputCopy.Push(x); } if (outputCopy.Count == 0) { return(false); } //if we are dealing with input //check all input rules //print("cyclecount " + outputCopy.Count.ToString()); for (int i = 0; i <= outputCopy.Count; i++) { //make a local variable to avoid retyping FRule rule = outputCopy.Peek(); //print ("currently checked rule "+rule.ToString ()); //print ("currentlt against rule "+goodRule.ToString ()); //look at the rule at the top of stack,if it matches the good rule if (Check(rule, goodRule)) { //if it matches, set good to true good = true; } //check the bad rule if (Check(rule, badRule)) { //if it matches, set good to true bad = true; } //MASTER CHECK IMPORTANT if (good && !bad) { return(true); } if (bad && !good) { return(false); } //pop the now checked rule outputCopy.Pop(); } // if we have not returned true by this point, the good rule doesnt exist // print("not exist in"); return(false); }