/** * Allows setting of subnet mask * * @param fmJson The Subnet Mask in JSON format. * @return A string status message */ @Post public String handlePost(String fmJson) { IMonitorService firewall = (IMonitorService) getContext().getAttributes().get(IMonitorService.class.getCanonicalName()); String newMask; try { newMask = jsonExtractSubnetMask(fmJson); } catch (IOException e) { log.error("Error parsing new subnet mask: " + fmJson, e); e.printStackTrace(); return "{\"status\" : \"Error! Could not parse new subnet mask, see log for details.\"}"; } firewall.setSubnetMask(newMask); return ("{\"status\" : \"subnet mask set\"}"); }
@Get("json") public Object handleRequest() { IMonitorService firewall = (IMonitorService) getContext().getAttributes().get(IMonitorService.class.getCanonicalName()); String op = (String) getRequestAttributes().get("op"); // REST API check status if (op.equalsIgnoreCase("status")) { if (firewall.isEnabled()) return "{\"result\" : \"firewall enabled\"}"; else return "{\"result\" : \"firewall disabled\"}"; } // REST API enable firewall if (op.equalsIgnoreCase("enable")) { firewall.enableFirewall(true); return "{\"status\" : \"success\", \"details\" : \"firewall running\"}"; } // REST API disable firewall if (op.equalsIgnoreCase("disable")) { firewall.enableFirewall(false); return "{\"status\" : \"success\", \"details\" : \"firewall stopped\"}"; } // REST API retrieving rules from storage // currently equivalent to /wm/firewall/rules/json if (op.equalsIgnoreCase("storageRules")) { return firewall.getStorageRules(); } // REST API set local subnet mask -- this only makes sense for one subnet // will remove later if (op.equalsIgnoreCase("subnet-mask")) { return firewall.getSubnetMask(); } // no known options found return "{\"status\" : \"failure\", \"details\" : \"invalid operation\"}"; }