diff --git a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchConfigurationPanel1.java b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchConfigurationPanel1.java index d22390f0a9..f40185e96b 100644 --- a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchConfigurationPanel1.java +++ b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchConfigurationPanel1.java @@ -80,7 +80,7 @@ public class KeywordSearchConfigurationPanel1 extends javax.swing.JPanel impleme public void actionPerformed(ActionEvent e) { final String FEATURE_NAME = "Save Keyword List"; KeywordSearchListsXML writer = KeywordSearchListsXML.getCurrent(); - KeywordSearchList currentKeywordList = editListPanel.getCurrentKeywordList(); + KeywordSearchListsAbstract.KeywordSearchList currentKeywordList = editListPanel.getCurrentKeywordList(); List keywords = currentKeywordList.getKeywords(); if (keywords.isEmpty()) { diff --git a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchEditListPanel.java b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchEditListPanel.java index c8657a0026..a720dde3ba 100644 --- a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchEditListPanel.java +++ b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchEditListPanel.java @@ -57,7 +57,7 @@ class KeywordSearchEditListPanel extends javax.swing.JPanel implements ListSelec private static Logger logger = Logger.getLogger(KeywordSearchEditListPanel.class.getName()); private KeywordTableModel tableModel; - private KeywordSearchList currentKeywordList; + private KeywordSearchListsAbstract.KeywordSearchList currentKeywordList; private boolean ingestRunning; @@ -608,7 +608,7 @@ class KeywordSearchEditListPanel extends javax.swing.JPanel implements ListSelec KeywordSearchListsXML reader = KeywordSearchListsXML.getCurrent(); - List toWrite = new ArrayList(); + List toWrite = new ArrayList(); toWrite.add(reader.getList(currentKeywordList.getName())); final KeywordSearchListsXML exporter = new KeywordSearchListsXML(fileAbs); boolean written = exporter.saveLists(toWrite); @@ -693,11 +693,11 @@ private void useForIngestCheckboxActionPerformed(java.awt.event.ActionEvent evt) // Implemented by parent panel } - KeywordSearchList getCurrentKeywordList() { + KeywordSearchListsAbstract.KeywordSearchList getCurrentKeywordList() { return currentKeywordList; } - void setCurrentKeywordList(KeywordSearchList list) { + void setCurrentKeywordList(KeywordSearchListsAbstract.KeywordSearchList list) { currentKeywordList = list; } diff --git a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchIngestModule.java b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchIngestModule.java index 0545b7c97f..4bb259b9b7 100644 --- a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchIngestModule.java +++ b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchIngestModule.java @@ -101,7 +101,7 @@ public final class KeywordSearchIngestModule implements IngestModuleAbstractFile private volatile boolean runSearcher = false; //whether to run searcher next time private List keywords; //keywords to search private List keywordLists; // lists currently being searched - private Map keywordToList; //keyword to list name mapping + private Map keywordToList; //keyword to list name mapping private Timer commitTimer; private Timer searchTimer; private Indexer indexer; @@ -380,7 +380,7 @@ public final class KeywordSearchIngestModule implements IngestModuleAbstractFile keywords = new ArrayList(); keywordLists = new ArrayList(); - keywordToList = new HashMap(); + keywordToList = new HashMap(); initKeywords(); @@ -566,7 +566,7 @@ public final class KeywordSearchIngestModule implements IngestModuleAbstractFile StringBuilder sb = new StringBuilder(); - for (KeywordSearchList list : loader.getListsL()) { + for (KeywordSearchListsAbstract.KeywordSearchList list : loader.getListsL()) { final String listName = list.getName(); if (list.getUseForIngest() == true || (listsToAdd != null && listsToAdd.contains(listName))) { @@ -798,7 +798,7 @@ public final class KeywordSearchIngestModule implements IngestModuleAbstractFile */ private List keywords; //keywords to search private List keywordLists; // lists currently being searched - private Map keywordToList; //keyword to list name mapping + private Map keywordToList; //keyword to list name mapping private AggregateProgressHandle progressGroup; private final Logger logger = Logger.getLogger(Searcher.class.getName()); private boolean finalRun = false; @@ -806,7 +806,7 @@ public final class KeywordSearchIngestModule implements IngestModuleAbstractFile Searcher(List keywordLists) { this.keywordLists = new ArrayList(keywordLists); this.keywords = new ArrayList(); - this.keywordToList = new HashMap(); + this.keywordToList = new HashMap(); //keywords are populated as searcher runs } @@ -874,7 +874,7 @@ public final class KeywordSearchIngestModule implements IngestModuleAbstractFile } final String queryStr = keywordQuery.getQuery(); - final KeywordSearchList list = keywordToList.get(queryStr); + final KeywordSearchListsAbstract.KeywordSearchList list = keywordToList.get(queryStr); final String listName = list.getName(); //new subProgress will be active after the initial query @@ -1110,7 +1110,7 @@ public final class KeywordSearchIngestModule implements IngestModuleAbstractFile this.keywordToList.clear(); for (String name : this.keywordLists) { - KeywordSearchList list = loader.getList(name); + KeywordSearchListsAbstract.KeywordSearchList list = loader.getList(name); for (Keyword k : list.getKeywords()) { this.keywords.add(k); this.keywordToList.put(k.getQuery(), list); diff --git a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchIngestSimplePanel.java b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchIngestSimplePanel.java index e3e91e5e57..35b9459405 100644 --- a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchIngestSimplePanel.java +++ b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchIngestSimplePanel.java @@ -38,12 +38,12 @@ public class KeywordSearchIngestSimplePanel extends javax.swing.JPanel { private final static Logger logger = Logger.getLogger(KeywordSearchIngestSimplePanel.class.getName()); public static final String PROP_OPTIONS = "Keyword Search_Options"; private KeywordTableModel tableModel; - private List lists; + private List lists; /** Creates new form KeywordSearchIngestSimplePanel */ public KeywordSearchIngestSimplePanel() { tableModel = new KeywordTableModel(); - lists = new ArrayList(); + lists = new ArrayList(); reloadLists(); initComponents(); customizeComponents(); @@ -222,7 +222,7 @@ public class KeywordSearchIngestSimplePanel extends javax.swing.JPanel { @Override public Object getValueAt(int rowIndex, int columnIndex) { - KeywordSearchList list = KeywordSearchIngestSimplePanel.this.lists.get(rowIndex); + KeywordSearchListsAbstract.KeywordSearchList list = KeywordSearchIngestSimplePanel.this.lists.get(rowIndex); if(columnIndex == 0) { return list.getUseForIngest(); } else { @@ -238,7 +238,7 @@ public class KeywordSearchIngestSimplePanel extends javax.swing.JPanel { @Override public void setValueAt(Object aValue, int rowIndex, int columnIndex) { - KeywordSearchList list = KeywordSearchIngestSimplePanel.this.lists.get(rowIndex); + KeywordSearchListsAbstract.KeywordSearchList list = KeywordSearchIngestSimplePanel.this.lists.get(rowIndex); if(columnIndex == 0){ KeywordSearchListsXML loader = KeywordSearchListsXML.getCurrent(); loader.addList(list.getName(), list.getKeywords(), (Boolean) aValue, false); diff --git a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchListsAbstract.java b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchListsAbstract.java index de8e96dae8..23193818f1 100644 --- a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchListsAbstract.java +++ b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchListsAbstract.java @@ -1,526 +1,526 @@ -/* - * Autopsy Forensic Browser - * - * Copyright 2011 Basis Technology Corp. - * Contact: carrier sleuthkit org - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.sleuthkit.autopsy.keywordsearch; - -import java.beans.PropertyChangeListener; -import java.beans.PropertyChangeSupport; -import java.io.File; -import java.util.ArrayList; -import java.util.Date; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; -import org.sleuthkit.autopsy.coreutils.Logger; -import org.sleuthkit.autopsy.coreutils.PlatformUtil; -import org.sleuthkit.datamodel.BlackboardAttribute; - -/** - * Keyword list saving, loading, and editing abstract class. - */ -public abstract class KeywordSearchListsAbstract { - - protected String filePath; - Map theLists; //the keyword data - static KeywordSearchListsXML currentInstance = null; - private static final String CUR_LISTS_FILE_NAME = "keywords.xml"; - private static String CUR_LISTS_FILE = PlatformUtil.getUserConfigDirectory() + File.separator + CUR_LISTS_FILE_NAME; - protected static final Logger logger = Logger.getLogger(KeywordSearchListsAbstract.class.getName()); - PropertyChangeSupport changeSupport; - protected List lockedLists; - - public KeywordSearchListsAbstract(String filePath) { - this.filePath = filePath; - theLists = new LinkedHashMap(); - lockedLists = new ArrayList(); - changeSupport = new PropertyChangeSupport(this); - } - - //property support - public enum ListsEvt { - - LIST_ADDED, LIST_DELETED, LIST_UPDATED - }; - - /** - * get instance for managing the current keyword list of the application - */ - static KeywordSearchListsXML getCurrent() { - if (currentInstance == null) { - currentInstance = new KeywordSearchListsXML(CUR_LISTS_FILE); - currentInstance.reload(); - } - return currentInstance; - } - - void addPropertyChangeListener(PropertyChangeListener l) { - changeSupport.addPropertyChangeListener(l); - } - - private void prepopulateLists() { - if (! theLists.isEmpty()) { - return; - } - //phone number - List phones = new ArrayList(); - phones.add(new Keyword("[(]{0,1}\\d\\d\\d[)]{0,1}[\\.-]\\d\\d\\d[\\.-]\\d\\d\\d\\d", false, BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PHONE_NUMBER)); - //phones.add(new Keyword("\\d{8,10}", false)); - //IP address - List ips = new ArrayList(); - ips.add(new Keyword("(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])", false, BlackboardAttribute.ATTRIBUTE_TYPE.TSK_IP_ADDRESS)); - //email - List emails = new ArrayList(); - emails.add(new Keyword("[A-Z0-9._%-]+@[A-Z0-9.-]+\\.[A-Z]{2,4}", false, BlackboardAttribute.ATTRIBUTE_TYPE.TSK_EMAIL)); - //URL - List urls = new ArrayList(); - //urls.add(new Keyword("http://|https://|^www\\.", false, BlackboardAttribute.ATTRIBUTE_TYPE.TSK_URL)); - urls.add(new Keyword("((((ht|f)tp(s?))\\://)|www\\.)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,5})(\\:[0-9]+)*(/($|[a-zA-Z0-9\\.\\,\\;\\?\\'\\\\+&%\\$#\\=~_\\-]+))*", false, BlackboardAttribute.ATTRIBUTE_TYPE.TSK_URL)); - - //urls.add(new Keyword("ssh://", false, BlackboardAttribute.ATTRIBUTE_TYPE.TSK_URL)); - - //disable messages for harcoded/locked lists - String name; - - name = "Phone Numbers"; - lockedLists.add(name); - addList(name, phones, false, false, true); - - name = "IP Addresses"; - lockedLists.add(name); - addList(name, ips, false, false, true); - - name = "Email Addresses"; - lockedLists.add(name); - addList(name, emails, true, false, true); - - name = "URLs"; - lockedLists.add(name); - addList(name, urls, false, false, true); - } - - /** - * load the file or create new - */ - public void reload() { - boolean created = false; - - //theLists.clear(); - //populate only the first time - prepopulateLists(); - - //reset all the lists other than locked lists (we don't save them to XML) - //we want to preserve state of locked lists - List toClear = new ArrayList(); - for (String list : theLists.keySet()) { - if (theLists.get(list).isLocked() == false) { - toClear.add(list); - } - } - for (String clearList : toClear) { - theLists.remove(clearList); - } - - if (!this.listFileExists()) { - //create new if it doesn't exist - save(); - created = true; - } - - //load, if fails to laod create new - if (!load() && !created) { - //create new if failed to load - save(); - } - - - } - - List getListsL() { - List ret = new ArrayList(); - for (KeywordSearchList list : theLists.values()) { - ret.add(list); - } - return ret; - } - - List getListsL(boolean locked) { - List ret = new ArrayList(); - for (KeywordSearchList list : theLists.values()) { - if (list.isLocked().equals(locked)) { - ret.add(list); - } - } - return ret; - } - - /** - * Get list names of all loaded keyword list names - * - * @return List of keyword list names - */ - List getListNames() { - return new ArrayList(theLists.keySet()); - } - - /** - * Get list names of all locked or unlocked loaded keyword list names - * - * @param locked true if look for locked lists, false otherwise - * @return List of keyword list names - */ - List getListNames(boolean locked) { - ArrayList lists = new ArrayList(); - for (String listName : theLists.keySet()) { - KeywordSearchList list = theLists.get(listName); - if (locked == list.isLocked()) { - lists.add(listName); - } - } - - return lists; - } - - /** - * return first list that contains the keyword - * - * @param keyword - * @return found list or null - */ - KeywordSearchList getListWithKeyword(Keyword keyword) { - KeywordSearchList found = null; - for (KeywordSearchList list : theLists.values()) { - if (list.hasKeyword(keyword)) { - found = list; - break; - } - } - return found; - } - - /** - * return first list that contains the keyword - * - * @param keyword - * @return found list or null - */ - KeywordSearchList getListWithKeyword(String keyword) { - KeywordSearchList found = null; - for (KeywordSearchList list : theLists.values()) { - if (list.hasKeyword(keyword)) { - found = list; - break; - } - } - return found; - } - - /** - * get number of lists currently stored - * - * @return number of lists currently stored - */ - int getNumberLists() { - return theLists.size(); - } - - /** - * get number of unlocked or locked lists currently stored - * - * @param locked true if look for locked lists, false otherwise - * @return number of unlocked lists currently stored - */ - int getNumberLists(boolean locked) { - int numLists = 0; - for (String listName : theLists.keySet()) { - KeywordSearchList list = theLists.get(listName); - if (locked == list.isLocked()) { - ++numLists; - } - } - return numLists; - } - - /** - * get list by name or null - * - * @param name id of the list - * @return keyword list representation - */ - KeywordSearchList getList(String name) { - return theLists.get(name); - } - - /** - * check if list with given name id exists - * - * @param name id to check - * @return true if list already exists or false otherwise - */ - boolean listExists(String name) { - return getList(name) != null; - } - - /** - * adds the new word list using name id replacing old one if exists with the - * same name - * - * @param name the name of the new list or list to replace - * @param newList list of keywords - * @param useForIngest should this list be used for ingest - * @return true if old list was replaced - */ - boolean addList(String name, List newList, boolean useForIngest, boolean ingestMessages, boolean locked) { - boolean replaced = false; - KeywordSearchList curList = getList(name); - final Date now = new Date(); - - if (curList == null) { - theLists.put(name, new KeywordSearchList(name, now, now, useForIngest, ingestMessages, newList, locked)); -// if (!locked) { -// save(); -// } - changeSupport.firePropertyChange(ListsEvt.LIST_ADDED.toString(), null, name); - } else { - theLists.put(name, new KeywordSearchList(name, curList.getDateCreated(), now, useForIngest, ingestMessages, newList, locked)); -// if (!locked) { -// save(); -// } - replaced = true; - changeSupport.firePropertyChange(ListsEvt.LIST_UPDATED.toString(), null, name); - } - - return replaced; - } - - boolean addList(String name, List newList, boolean useForIngest, boolean ingestMessages) { - //make sure that the list is readded as a locked/built in list - boolean isLocked = this.lockedLists.contains(name); - return addList(name, newList, useForIngest, ingestMessages, isLocked); - } - - boolean addList(String name, List newList) { - boolean isLocked = this.lockedLists.contains(name); - return addList(name, newList, true, isLocked); - } - - boolean addList(KeywordSearchList list) { - return addList(list.getName(), list.getKeywords(), list.getUseForIngest(), list.getIngestMessages(), list.isLocked()); - } - - /** - * save multiple lists - * - * @param lists - * @return - */ - boolean saveLists(List lists) { - int oldSize = this.getNumberLists(); - - List overwritten = new ArrayList(); - List newLists = new ArrayList(); - for (KeywordSearchList list : lists) { - if (this.listExists(list.getName())) { - overwritten.add(list); - } else { - newLists.add(list); - } - theLists.put(list.getName(), list); - } - boolean saved = save(true); - if (saved) { - for (KeywordSearchList list : newLists) { - changeSupport.firePropertyChange(ListsEvt.LIST_ADDED.toString(), null, list.getName()); - } - for (KeywordSearchList over : overwritten) { - changeSupport.firePropertyChange(ListsEvt.LIST_UPDATED.toString(), null, over.getName()); - } - } - - return saved; - } - - /** - * write out multiple lists - * - * @param lists - * @return - */ - boolean writeLists(List lists) { - int oldSize = this.getNumberLists(); - - List overwritten = new ArrayList(); - List newLists = new ArrayList(); - for (KeywordSearchList list : lists) { - if (this.listExists(list.getName())) { - overwritten.add(list); - } else { - newLists.add(list); - } - theLists.put(list.getName(), list); - } - //boolean saved = save(); - - for (KeywordSearchList list : newLists) { - changeSupport.firePropertyChange(ListsEvt.LIST_ADDED.toString(), null, list.getName()); - } - for (KeywordSearchList over : overwritten) { - changeSupport.firePropertyChange(ListsEvt.LIST_UPDATED.toString(), null, over.getName()); - } - - return true; - } - - /** - * delete list if exists and save new list - * - * @param name of list to delete - * @return true if deleted - */ - boolean deleteList(String name) { - boolean deleted = false; - KeywordSearchList delList = getList(name); - if (delList != null && !delList.isLocked()) { - theLists.remove(name); - //deleted = save(); - } - changeSupport.firePropertyChange(ListsEvt.LIST_DELETED.toString(), null, name); - return true; - - } - - /** - * writes out current list replacing the last lists file - */ - public abstract boolean save(); - - /** - * writes out current list replacing the last lists file - * @param isExport true is this save operation is an export and not a 'Save - * As' - */ - public abstract boolean save(boolean isExport); - - /** - * load and parse List, then dispose - */ - public abstract boolean load(); - - private boolean listFileExists() { - File f = new File(filePath); - return f.exists() && f.canRead() && f.canWrite(); - } -} - -/** - * a representation of a single keyword list created or loaded - */ -class KeywordSearchList { - - private String name; - private Date created; - private Date modified; - private Boolean useForIngest; - private Boolean ingestMessages; - private List keywords; - private Boolean locked; - - KeywordSearchList(String name, Date created, Date modified, Boolean useForIngest, Boolean ingestMessages, List keywords, boolean locked) { - this.name = name; - this.created = created; - this.modified = modified; - this.useForIngest = useForIngest; - this.ingestMessages = ingestMessages; - this.keywords = keywords; - this.locked = locked; - } - - KeywordSearchList(String name, Date created, Date modified, Boolean useForIngest, Boolean ingestMessages, List keywords) { - this(name, created, modified, useForIngest, ingestMessages, keywords, false); - } - - @Override - public boolean equals(Object obj) { - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { - return false; - } - final KeywordSearchList other = (KeywordSearchList) obj; - if ((this.name == null) ? (other.name != null) : !this.name.equals(other.name)) { - return false; - } - return true; - } - - @Override - public int hashCode() { - int hash = 5; - return hash; - } - - String getName() { - return name; - } - - Date getDateCreated() { - return created; - } - - Date getDateModified() { - return modified; - } - - Boolean getUseForIngest() { - return useForIngest; - } - - void setUseForIngest(boolean use) { - this.useForIngest = use; - } - - Boolean getIngestMessages() { - return ingestMessages; - } - - void setIngestMessages(boolean ingestMessages) { - this.ingestMessages = ingestMessages; - } - - List getKeywords() { - return keywords; - } - - boolean hasKeyword(Keyword keyword) { - return keywords.contains(keyword); - } - - boolean hasKeyword(String keyword) { - //note, this ignores isLiteral - for (Keyword k : keywords) { - if (k.getQuery().equals(keyword)) { - return true; - } - } - return false; - } - - Boolean isLocked() { - return locked; - } +/* + * Autopsy Forensic Browser + * + * Copyright 2011 Basis Technology Corp. + * Contact: carrier sleuthkit org + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.sleuthkit.autopsy.keywordsearch; + +import java.beans.PropertyChangeListener; +import java.beans.PropertyChangeSupport; +import java.io.File; +import java.util.ArrayList; +import java.util.Date; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import org.sleuthkit.autopsy.coreutils.Logger; +import org.sleuthkit.autopsy.coreutils.PlatformUtil; +import org.sleuthkit.datamodel.BlackboardAttribute; + +/** + * Keyword list saving, loading, and editing abstract class. + */ +public abstract class KeywordSearchListsAbstract { + + protected String filePath; + public Map theLists; //the keyword data + static KeywordSearchListsXML currentInstance = null; + private static final String CUR_LISTS_FILE_NAME = "keywords.xml"; + private static String CUR_LISTS_FILE = PlatformUtil.getUserConfigDirectory() + File.separator + CUR_LISTS_FILE_NAME; + protected static final Logger logger = Logger.getLogger(KeywordSearchListsAbstract.class.getName()); + PropertyChangeSupport changeSupport; + protected List lockedLists; + + public KeywordSearchListsAbstract(String filePath) { + this.filePath = filePath; + theLists = new LinkedHashMap(); + lockedLists = new ArrayList(); + changeSupport = new PropertyChangeSupport(this); + } + + //property support + public enum ListsEvt { + + LIST_ADDED, LIST_DELETED, LIST_UPDATED + }; + + /** + * get instance for managing the current keyword list of the application + */ + public static KeywordSearchListsXML getCurrent() { + if (currentInstance == null) { + currentInstance = new KeywordSearchListsXML(CUR_LISTS_FILE); + currentInstance.reload(); + } + return currentInstance; + } + + void addPropertyChangeListener(PropertyChangeListener l) { + changeSupport.addPropertyChangeListener(l); + } + + private void prepopulateLists() { + if (! theLists.isEmpty()) { + return; + } + //phone number + List phones = new ArrayList(); + phones.add(new Keyword("[(]{0,1}\\d\\d\\d[)]{0,1}[\\.-]\\d\\d\\d[\\.-]\\d\\d\\d\\d", false, BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PHONE_NUMBER)); + //phones.add(new Keyword("\\d{8,10}", false)); + //IP address + List ips = new ArrayList(); + ips.add(new Keyword("(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])", false, BlackboardAttribute.ATTRIBUTE_TYPE.TSK_IP_ADDRESS)); + //email + List emails = new ArrayList(); + emails.add(new Keyword("[A-Z0-9._%-]+@[A-Z0-9.-]+\\.[A-Z]{2,4}", false, BlackboardAttribute.ATTRIBUTE_TYPE.TSK_EMAIL)); + //URL + List urls = new ArrayList(); + //urls.add(new Keyword("http://|https://|^www\\.", false, BlackboardAttribute.ATTRIBUTE_TYPE.TSK_URL)); + urls.add(new Keyword("((((ht|f)tp(s?))\\://)|www\\.)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,5})(\\:[0-9]+)*(/($|[a-zA-Z0-9\\.\\,\\;\\?\\'\\\\+&%\\$#\\=~_\\-]+))*", false, BlackboardAttribute.ATTRIBUTE_TYPE.TSK_URL)); + + //urls.add(new Keyword("ssh://", false, BlackboardAttribute.ATTRIBUTE_TYPE.TSK_URL)); + + //disable messages for harcoded/locked lists + String name; + + name = "Phone Numbers"; + lockedLists.add(name); + addList(name, phones, false, false, true); + + name = "IP Addresses"; + lockedLists.add(name); + addList(name, ips, false, false, true); + + name = "Email Addresses"; + lockedLists.add(name); + addList(name, emails, true, false, true); + + name = "URLs"; + lockedLists.add(name); + addList(name, urls, false, false, true); + } + + /** + * load the file or create new + */ + public void reload() { + boolean created = false; + + //theLists.clear(); + //populate only the first time + prepopulateLists(); + + //reset all the lists other than locked lists (we don't save them to XML) + //we want to preserve state of locked lists + List toClear = new ArrayList(); + for (String list : theLists.keySet()) { + if (theLists.get(list).isLocked() == false) { + toClear.add(list); + } + } + for (String clearList : toClear) { + theLists.remove(clearList); + } + + if (!this.listFileExists()) { + //create new if it doesn't exist + save(); + created = true; + } + + //load, if fails to laod create new + if (!load() && !created) { + //create new if failed to load + save(); + } + + + } + + List getListsL() { + List ret = new ArrayList(); + for (KeywordSearchList list : theLists.values()) { + ret.add(list); + } + return ret; + } + + List getListsL(boolean locked) { + List ret = new ArrayList(); + for (KeywordSearchList list : theLists.values()) { + if (list.isLocked().equals(locked)) { + ret.add(list); + } + } + return ret; + } + + /** + * Get list names of all loaded keyword list names + * + * @return List of keyword list names + */ + List getListNames() { + return new ArrayList(theLists.keySet()); + } + + /** + * Get list names of all locked or unlocked loaded keyword list names + * + * @param locked true if look for locked lists, false otherwise + * @return List of keyword list names + */ + List getListNames(boolean locked) { + ArrayList lists = new ArrayList(); + for (String listName : theLists.keySet()) { + KeywordSearchList list = theLists.get(listName); + if (locked == list.isLocked()) { + lists.add(listName); + } + } + + return lists; + } + + /** + * return first list that contains the keyword + * + * @param keyword + * @return found list or null + */ + KeywordSearchList getListWithKeyword(Keyword keyword) { + KeywordSearchList found = null; + for (KeywordSearchList list : theLists.values()) { + if (list.hasKeyword(keyword)) { + found = list; + break; + } + } + return found; + } + + /** + * return first list that contains the keyword + * + * @param keyword + * @return found list or null + */ + KeywordSearchList getListWithKeyword(String keyword) { + KeywordSearchList found = null; + for (KeywordSearchList list : theLists.values()) { + if (list.hasKeyword(keyword)) { + found = list; + break; + } + } + return found; + } + + /** + * get number of lists currently stored + * + * @return number of lists currently stored + */ + int getNumberLists() { + return theLists.size(); + } + + /** + * get number of unlocked or locked lists currently stored + * + * @param locked true if look for locked lists, false otherwise + * @return number of unlocked lists currently stored + */ + int getNumberLists(boolean locked) { + int numLists = 0; + for (String listName : theLists.keySet()) { + KeywordSearchList list = theLists.get(listName); + if (locked == list.isLocked()) { + ++numLists; + } + } + return numLists; + } + + /** + * get list by name or null + * + * @param name id of the list + * @return keyword list representation + */ + KeywordSearchList getList(String name) { + return theLists.get(name); + } + + /** + * check if list with given name id exists + * + * @param name id to check + * @return true if list already exists or false otherwise + */ + boolean listExists(String name) { + return getList(name) != null; + } + + /** + * adds the new word list using name id replacing old one if exists with the + * same name + * + * @param name the name of the new list or list to replace + * @param newList list of keywords + * @param useForIngest should this list be used for ingest + * @return true if old list was replaced + */ + boolean addList(String name, List newList, boolean useForIngest, boolean ingestMessages, boolean locked) { + boolean replaced = false; + KeywordSearchList curList = getList(name); + final Date now = new Date(); + + if (curList == null) { + theLists.put(name, new KeywordSearchList(name, now, now, useForIngest, ingestMessages, newList, locked)); +// if (!locked) { +// save(); +// } + changeSupport.firePropertyChange(ListsEvt.LIST_ADDED.toString(), null, name); + } else { + theLists.put(name, new KeywordSearchList(name, curList.getDateCreated(), now, useForIngest, ingestMessages, newList, locked)); +// if (!locked) { +// save(); +// } + replaced = true; + changeSupport.firePropertyChange(ListsEvt.LIST_UPDATED.toString(), null, name); + } + + return replaced; + } + + boolean addList(String name, List newList, boolean useForIngest, boolean ingestMessages) { + //make sure that the list is readded as a locked/built in list + boolean isLocked = this.lockedLists.contains(name); + return addList(name, newList, useForIngest, ingestMessages, isLocked); + } + + boolean addList(String name, List newList) { + boolean isLocked = this.lockedLists.contains(name); + return addList(name, newList, true, isLocked); + } + + boolean addList(KeywordSearchList list) { + return addList(list.getName(), list.getKeywords(), list.getUseForIngest(), list.getIngestMessages(), list.isLocked()); + } + + /** + * save multiple lists + * + * @param lists + * @return + */ + boolean saveLists(List lists) { + int oldSize = this.getNumberLists(); + + List overwritten = new ArrayList(); + List newLists = new ArrayList(); + for (KeywordSearchList list : lists) { + if (this.listExists(list.getName())) { + overwritten.add(list); + } else { + newLists.add(list); + } + theLists.put(list.getName(), list); + } + boolean saved = save(true); + if (saved) { + for (KeywordSearchList list : newLists) { + changeSupport.firePropertyChange(ListsEvt.LIST_ADDED.toString(), null, list.getName()); + } + for (KeywordSearchList over : overwritten) { + changeSupport.firePropertyChange(ListsEvt.LIST_UPDATED.toString(), null, over.getName()); + } + } + + return saved; + } + + /** + * write out multiple lists + * + * @param lists + * @return + */ + boolean writeLists(List lists) { + int oldSize = this.getNumberLists(); + + List overwritten = new ArrayList(); + List newLists = new ArrayList(); + for (KeywordSearchList list : lists) { + if (this.listExists(list.getName())) { + overwritten.add(list); + } else { + newLists.add(list); + } + theLists.put(list.getName(), list); + } + //boolean saved = save(); + + for (KeywordSearchList list : newLists) { + changeSupport.firePropertyChange(ListsEvt.LIST_ADDED.toString(), null, list.getName()); + } + for (KeywordSearchList over : overwritten) { + changeSupport.firePropertyChange(ListsEvt.LIST_UPDATED.toString(), null, over.getName()); + } + + return true; + } + + /** + * delete list if exists and save new list + * + * @param name of list to delete + * @return true if deleted + */ + boolean deleteList(String name) { + boolean deleted = false; + KeywordSearchList delList = getList(name); + if (delList != null && !delList.isLocked()) { + theLists.remove(name); + //deleted = save(); + } + changeSupport.firePropertyChange(ListsEvt.LIST_DELETED.toString(), null, name); + return true; + + } + + /** + * writes out current list replacing the last lists file + */ + public abstract boolean save(); + + /** + * writes out current list replacing the last lists file + * @param isExport true is this save operation is an export and not a 'Save + * As' + */ + public abstract boolean save(boolean isExport); + + /** + * load and parse List, then dispose + */ + public abstract boolean load(); + + private boolean listFileExists() { + File f = new File(filePath); + return f.exists() && f.canRead() && f.canWrite(); + } + + /** + * a representation of a single keyword list created or loaded + */ + public class KeywordSearchList { + + private String name; + private Date created; + private Date modified; + private Boolean useForIngest; + private Boolean ingestMessages; + private List keywords; + private Boolean locked; + + KeywordSearchList(String name, Date created, Date modified, Boolean useForIngest, Boolean ingestMessages, List keywords, boolean locked) { + this.name = name; + this.created = created; + this.modified = modified; + this.useForIngest = useForIngest; + this.ingestMessages = ingestMessages; + this.keywords = keywords; + this.locked = locked; + } + + KeywordSearchList(String name, Date created, Date modified, Boolean useForIngest, Boolean ingestMessages, List keywords) { + this(name, created, modified, useForIngest, ingestMessages, keywords, false); + } + + @Override + public boolean equals(Object obj) { + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + final KeywordSearchList other = (KeywordSearchList) obj; + if ((this.name == null) ? (other.name != null) : !this.name.equals(other.name)) { + return false; + } + return true; + } + + @Override + public int hashCode() { + int hash = 5; + return hash; + } + + public String getName() { + return name; + } + + public Date getDateCreated() { + return created; + } + + public Date getDateModified() { + return modified; + } + + public Boolean getUseForIngest() { + return useForIngest; + } + + public void setUseForIngest(boolean use) { + this.useForIngest = use; + } + + public Boolean getIngestMessages() { + return ingestMessages; + } + + public void setIngestMessages(boolean ingestMessages) { + this.ingestMessages = ingestMessages; + } + + public List getKeywords() { + return keywords; + } + + public boolean hasKeyword(Keyword keyword) { + return keywords.contains(keyword); + } + + public boolean hasKeyword(String keyword) { + //note, this ignores isLiteral + for (Keyword k : keywords) { + if (k.getQuery().equals(keyword)) { + return true; + } + } + return false; + } + + public Boolean isLocked() { + return locked; + } + } } \ No newline at end of file diff --git a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchListsManagementPanel.form b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchListsManagementPanel.form index f3b8306b06..cb2629ae11 100644 --- a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchListsManagementPanel.form +++ b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchListsManagementPanel.form @@ -37,7 +37,7 @@ - + diff --git a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchListsManagementPanel.java b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchListsManagementPanel.java index ae73ef504e..3e64ad20d3 100644 --- a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchListsManagementPanel.java +++ b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchListsManagementPanel.java @@ -243,12 +243,12 @@ class KeywordSearchListsManagementPanel extends javax.swing.JPanel implements Op return; } - List toImport = reader.getListsL(); - List toImportConfirmed = new ArrayList(); + List toImport = reader.getListsL(); + List toImportConfirmed = new ArrayList(); final KeywordSearchListsXML writer = KeywordSearchListsXML.getCurrent(); - for (KeywordSearchList list : toImport) { + for (KeywordSearchListsAbstract.KeywordSearchList list : toImport) { //check name collisions if (writer.listExists(list.getName())) { Object[] options = {"Yes, overwrite", diff --git a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchListsViewerPanel.java b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchListsViewerPanel.java index bf27605fcd..e124ef44e2 100644 --- a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchListsViewerPanel.java +++ b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchListsViewerPanel.java @@ -105,7 +105,7 @@ class KeywordSearchListsViewerPanel extends AbstractKeywordSearchPerformer { ListSelectionModel listSelectionModel = (ListSelectionModel) e.getSource(); if (!listSelectionModel.isSelectionEmpty()) { int index = listSelectionModel.getMinSelectionIndex(); - KeywordSearchList list = listsTableModel.getListAt(index); + KeywordSearchListsAbstract.KeywordSearchList list = listsTableModel.getListAt(index); keywordsTableModel.resync(list); } else { keywordsTableModel.deleteAll(); @@ -307,13 +307,13 @@ class KeywordSearchListsViewerPanel extends AbstractKeywordSearchPerformer { @Override public List getQueryList() { List ret = new ArrayList(); - for (KeywordSearchList list : getSelectedLists()) { + for (KeywordSearchListsAbstract.KeywordSearchList list : getSelectedLists()) { ret.addAll(list.getKeywords()); } return ret; } - private List getSelectedLists() { + private List getSelectedLists() { return listsTableModel.getSelectedListsL(); } @@ -427,7 +427,7 @@ class KeywordSearchListsViewerPanel extends AbstractKeywordSearchPerformer { return ret; } - KeywordSearchList getListAt(int rowIndex) { + KeywordSearchListsAbstract.KeywordSearchList getListAt(int rowIndex) { return listsHandle.getList((String) getValueAt(rowIndex, 1)); } @@ -441,8 +441,8 @@ class KeywordSearchListsViewerPanel extends AbstractKeywordSearchPerformer { return ret; } - List getSelectedListsL() { - List ret = new ArrayList(); + List getSelectedListsL() { + List ret = new ArrayList(); for (String s : getSelectedLists()) { ret.add(listsHandle.getList(s)); } @@ -462,8 +462,8 @@ class KeywordSearchListsViewerPanel extends AbstractKeywordSearchPerformer { } //add lists to the model - private void addLists(List lists) { - for (KeywordSearchList list : lists) { + private void addLists(List lists) { + for (KeywordSearchListsAbstract.KeywordSearchList list : lists) { if (!listExists(list.getName())) { listData.add(new ListTableEntry(list, ingestRunning)); } @@ -476,7 +476,7 @@ class KeywordSearchListsViewerPanel extends AbstractKeywordSearchPerformer { String name; Boolean selected; - ListTableEntry(KeywordSearchList list, boolean ingestRunning) { + ListTableEntry(KeywordSearchListsAbstract.KeywordSearchList list, boolean ingestRunning) { this.name = list.getName(); if (ingestRunning) { this.selected = list.getUseForIngest(); @@ -558,7 +558,7 @@ class KeywordSearchListsViewerPanel extends AbstractKeywordSearchPerformer { return getValueAt(0, c).getClass(); } - void resync(KeywordSearchList list) { + void resync(KeywordSearchListsAbstract.KeywordSearchList list) { listData.clear(); for (Keyword k : list.getKeywords()) { listData.add(new KeywordTableEntry(k)); diff --git a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchResultFactory.java b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchResultFactory.java index 634ac92402..36975c9cda 100644 --- a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchResultFactory.java +++ b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchResultFactory.java @@ -236,7 +236,7 @@ public class KeywordSearchResultFactory extends ChildFactory { //get listname String listName = ""; - KeywordSearchList list = KeywordSearchListsXML.getCurrent().getListWithKeyword(tcq.getQueryString()); + KeywordSearchListsAbstract.KeywordSearchList list = KeywordSearchListsXML.getCurrent().getListWithKeyword(tcq.getQueryString()); if (list != null) { listName = list.getName(); } diff --git a/Testing/nbproject/project.xml b/Testing/nbproject/project.xml index 2de5ca7b67..6b7be2ee79 100644 --- a/Testing/nbproject/project.xml +++ b/Testing/nbproject/project.xml @@ -15,6 +15,15 @@ 5.0 + + org.sleuthkit.autopsy.keywordsearch + + + + 5 + 3.0 + + diff --git a/Testing/test/qa-functional/src/org/sleuthkit/autopsy/testing/RegressionTest.java b/Testing/test/qa-functional/src/org/sleuthkit/autopsy/testing/RegressionTest.java index 3746f52abb..33a5480573 100644 --- a/Testing/test/qa-functional/src/org/sleuthkit/autopsy/testing/RegressionTest.java +++ b/Testing/test/qa-functional/src/org/sleuthkit/autopsy/testing/RegressionTest.java @@ -52,6 +52,7 @@ import org.netbeans.jemmy.operators.JTableOperator; import org.netbeans.jemmy.operators.JTextFieldOperator; import org.netbeans.junit.NbModuleSuite; import org.sleuthkit.autopsy.ingest.IngestManager; +import org.sleuthkit.autopsy.keywordsearch.*; /** * This test expects the following system properties to be set: * img_path: The fully qualified path to the image file (if split, the first file) @@ -207,6 +208,8 @@ public class RegressionTest extends TestCase{ logger.info("Search Configure"); JDialog jd = JDialogOperator.waitJDialog("Advanced Keyword Search Configuration", false, false); JDialogOperator jdo = new JDialogOperator(jd); + KeywordSearchListsXML curr = KeywordSearchListsXML.getCurrent(); + curr.theLists.get("URLs").setUseForIngest(true); String words = System.getProperty("keyword_path"); JButtonOperator jbo0 = new JButtonOperator(jdo, "Import List", 0); jbo0.pushNoBlock();