static void printRuleSet(HostFirewallRuleset rule) { System.out.println("\nKey:" + rule.getKey()); System.out.println("Label:" + rule.getLabel()); System.out.println("Required:" + rule.isRequired()); System.out.println("Service:" + rule.getService()); System.out.print("Rules:"); HostFirewallRule[] rules = rule.getRule(); for(int j=0; rules!=null && j<rules.length; j++) { System.out.println("Protocol:" + rules[j].getProtocol()); System.out.println("Port:" + rules[j].getPort()); System.out.println("Direction:" + rules[j].getDirection()); System.out.println("EndPort:" + rules[j].getEndPort()); } System.out.println("Enabled:" + rule.isEnabled()); }
public void enableVncOnHostFirewall() throws Exception { HostFirewallSystemMO firewallMo = getHostFirewallSystemMO(); boolean bRefresh = false; if (firewallMo != null) { HostFirewallInfo firewallInfo = firewallMo.getFirewallInfo(); if (firewallInfo != null && firewallInfo.getRuleset() != null) { for (HostFirewallRuleset rule : firewallInfo.getRuleset()) { if ("vncServer".equalsIgnoreCase(rule.getKey())) { bRefresh = true; firewallMo.enableRuleset("vncServer"); } else if ("gdbserver".equalsIgnoreCase(rule.getKey())) { bRefresh = true; firewallMo.enableRuleset("gdbserver"); } } } if (bRefresh) firewallMo.refreshFirewall(); } }