@Override public void initOptions() { String[] bannedIps = FilterSettings.BLACK_LISTED_IP_ADDRESSES.get(); FilterModel model = new FilterModel(new ArrayList<String>(Arrays.asList(bannedIps))); filterTable.setModel(model); backListCheckBox.setSelected(FilterSettings.USE_NETWORK_FILTER.getValue()); }
/** Does the work of setting new good & bad hosts. */ private void refreshHostsImpl() { LOG.debug("refreshing hosts"); // Load the local blacklist, stripping out invalid entries IPList newBad = new IPList(); String[] allHosts = FilterSettings.BLACK_LISTED_IP_ADDRESSES.get(); ArrayList<String> valid = new ArrayList<String>(allHosts.length); for (int i = 0; i < allHosts.length; i++) { if (newBad.add(allHosts[i])) valid.add(allHosts[i]); } if (valid.size() != allHosts.length) { allHosts = valid.toArray(new String[0]); FilterSettings.BLACK_LISTED_IP_ADDRESSES.set(allHosts); } // Load the local whitelist, stripping out invalid entries IPList newGood = new IPList(); allHosts = FilterSettings.WHITE_LISTED_IP_ADDRESSES.get(); valid = new ArrayList<String>(allHosts.length); for (int i = 0; i < allHosts.length; i++) { if (newGood.add(allHosts[i])) valid.add(allHosts[i]); } if (valid.size() != allHosts.length) { allHosts = valid.toArray(new String[0]); FilterSettings.WHITE_LISTED_IP_ADDRESSES.set(allHosts); } // Load data from hostiles.txt (if it wasn't already loaded!)... if (shouldLoadHostiles) { shouldLoadHostiles = false; LOG.debug("loading hostiles"); File hostiles = new File(CommonUtils.getUserSettingsDir(), "hostiles.txt"); BufferedReader reader = null; try { reader = new BufferedReader(new FileReader(hostiles)); String read = null; while ((read = reader.readLine()) != null) { hostilesTXTHosts.add(read); } } catch (IOException ignored) { LOG.debug("iox loading hostiles", ignored); } finally { IOUtils.close(reader); } } badHosts = new MultiIPList(newBad, hostilesTXTHosts); goodHosts = newGood; }
@Override boolean hasChanged() { List model = Arrays.asList(FilterSettings.BLACK_LISTED_IP_ADDRESSES.get()); return backListCheckBox.isSelected() != FilterSettings.USE_NETWORK_FILTER.getValue() || !model.equals(filterTable.getFilterModel().getModel()); }