From 1829b12f81a7c6c1b364c7d8bba93d800672c499 Mon Sep 17 00:00:00 2001 From: Karl Mortensen Date: Fri, 12 Jun 2015 15:04:11 -0400 Subject: [PATCH 1/2] Postgre-ize some SQL --- .../autopsy/filesearch/Bundle.properties | 1 + .../autopsy/filesearch/DateSearchFilter.java | 18 +++++++------ .../autopsy/filesearch/FileSearchPanel.java | 25 ++++++++++++------- .../filesearch/KnownStatusSearchFilter.java | 8 +++--- 4 files changed, 31 insertions(+), 21 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/filesearch/Bundle.properties b/Core/src/org/sleuthkit/autopsy/filesearch/Bundle.properties index ea78d740c9..99c61a24ca 100644 --- a/Core/src/org/sleuthkit/autopsy/filesearch/Bundle.properties +++ b/Core/src/org/sleuthkit/autopsy/filesearch/Bundle.properties @@ -47,6 +47,7 @@ FileSearchPanel.search.results.msg=File Search\: {0} matches found FileSearchPanel.search.results.details=Large number of matches may impact performance on some operations FileSearchPanel.search.exception.noFilterSelected.msg=At least one filter must be selected. FileSearchPanel.search.validationErr.msg=Validation Error\: {0} +FileSearchPanel.emptyWhereClause.text=Invalid options, nothing to show. KnownStatusSearchFilter.noneSelectedMsg.text=At least one known status must be selected\! NameSearchFilter.emptyNameMsg.text=Must enter something for name search. SearchNode.getName.text=Search Result diff --git a/Core/src/org/sleuthkit/autopsy/filesearch/DateSearchFilter.java b/Core/src/org/sleuthkit/autopsy/filesearch/DateSearchFilter.java index 7939c0956d..4a053d4acb 100644 --- a/Core/src/org/sleuthkit/autopsy/filesearch/DateSearchFilter.java +++ b/Core/src/org/sleuthkit/autopsy/filesearch/DateSearchFilter.java @@ -72,7 +72,7 @@ class DateSearchFilter extends AbstractFileSearchFilter { @Override public String getPredicate() throws FilterValidationException { - String addQuery = "1"; + String addQuery = ""; DateSearchPanel panel = this.getComponent(); // first, get the selected timeZone from the dropdown list @@ -127,25 +127,27 @@ class DateSearchFilter extends AbstractFileSearchFilter { if (modifiedChecked || changedChecked || accessedChecked || createdChecked) { - String subQuery = "0"; + String subQuery = ""; if (modifiedChecked) { - subQuery += " or mtime between " + fromDate + " and " + toDate; //NON-NLS + subQuery += " OR mtime BETWEEN " + fromDate + " AND " + toDate; //NON-NLS } if (changedChecked) { - subQuery += " or ctime between " + fromDate + " and " + toDate; //NON-NLS + subQuery += " OR ctime BETWEEN " + fromDate + " AND " + toDate; //NON-NLS } if (accessedChecked) { - subQuery += " or atime between " + fromDate + " and " + toDate; //NON-NLS + subQuery += " OR atime BETWEEN " + fromDate + " AND " + toDate; //NON-NLS } if (createdChecked) { - subQuery += " or crtime between " + fromDate + " and " + toDate; //NON-NLS + subQuery += " OR crtime BETWEEN " + fromDate + " AND " + toDate; //NON-NLS + } + + if (!subQuery.isEmpty()) { + addQuery += " AND (" + subQuery + ")"; //NON-NLS } - - addQuery += " and (" + subQuery + ")"; //NON-NLS } else { throw new FilterValidationException(NONE_SELECTED_MESSAGE); } diff --git a/Core/src/org/sleuthkit/autopsy/filesearch/FileSearchPanel.java b/Core/src/org/sleuthkit/autopsy/filesearch/FileSearchPanel.java index e2ae8bb6c2..9ee6e6511a 100644 --- a/Core/src/org/sleuthkit/autopsy/filesearch/FileSearchPanel.java +++ b/Core/src/org/sleuthkit/autopsy/filesearch/FileSearchPanel.java @@ -63,7 +63,8 @@ import org.sleuthkit.datamodel.TskCoreException; private List filterAreas = new ArrayList(); private JButton searchButton; private static int resultWindowCount = 0; //keep track of result windows so they get unique names - + private static final String EMPTY_WHERE_CLAUSE = NbBundle.getMessage(DateSearchFilter.class, "FileSearchPanel.emptyWhereClause.text"); + /** * Creates new form FileSearchPanel */ @@ -202,17 +203,23 @@ import org.sleuthkit.datamodel.TskCoreException; * org.sleuthkit.autopsy.filesearch.FileSearchFilter.FilterValidationException * if an enabled filter is in an invalid state */ - private String getQuery() throws FilterValidationException { + private String getQuery() throws FilterValidationException { - //String query = "SELECT " + tempQuery + " FROM tsk_files WHERE 1"; - String query = " 1"; + //String query = "SELECT " + tempQuery + " FROM tsk_files WHERE "; + String query = ""; - for (FileSearchFilter f : this.getEnabledFilters()) { - query += " AND (" + f.getPredicate() + ")"; //NON-NLS - } + for (FileSearchFilter f : this.getEnabledFilters()) { + String result = f.getPredicate(); + if (!result.isEmpty()) { + query += " AND (" + result + ")"; //NON-NLS + } + } - return query; - } + if (query.isEmpty()) { + throw new FilterValidationException(EMPTY_WHERE_CLAUSE); + } + return query; + } private Collection getFilters() { Collection filters = new ArrayList(); diff --git a/Core/src/org/sleuthkit/autopsy/filesearch/KnownStatusSearchFilter.java b/Core/src/org/sleuthkit/autopsy/filesearch/KnownStatusSearchFilter.java index 247faa87db..66d1daae6b 100644 --- a/Core/src/org/sleuthkit/autopsy/filesearch/KnownStatusSearchFilter.java +++ b/Core/src/org/sleuthkit/autopsy/filesearch/KnownStatusSearchFilter.java @@ -56,15 +56,15 @@ class KnownStatusSearchFilter extends AbstractFileSearchFilter Date: Fri, 12 Jun 2015 16:04:02 -0400 Subject: [PATCH 2/2] fix sql --- .../autopsy/filesearch/DateSearchFilter.java | 30 ++++++++++--------- .../autopsy/filesearch/FileSearchPanel.java | 10 +++++-- .../filesearch/KnownStatusSearchFilter.java | 4 +-- 3 files changed, 26 insertions(+), 18 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/filesearch/DateSearchFilter.java b/Core/src/org/sleuthkit/autopsy/filesearch/DateSearchFilter.java index 4a053d4acb..f1df56f8ac 100644 --- a/Core/src/org/sleuthkit/autopsy/filesearch/DateSearchFilter.java +++ b/Core/src/org/sleuthkit/autopsy/filesearch/DateSearchFilter.java @@ -72,9 +72,9 @@ class DateSearchFilter extends AbstractFileSearchFilter { @Override public String getPredicate() throws FilterValidationException { - String addQuery = ""; + String query = "NULL"; DateSearchPanel panel = this.getComponent(); - + // first, get the selected timeZone from the dropdown list String tz = this.getComponent().getTimeZoneComboBox().getSelectedItem().toString(); String tzID = tz.substring(tz.indexOf(" ") + 1); // 1 index after the space is the ID @@ -92,7 +92,7 @@ class DateSearchFilter extends AbstractFileSearchFilter { startDate = Calendar.getInstance(new SimpleTimeZone(0, "GMT")); //NON-NLS startDate.setTime(temp); // convert to GMT } catch (ParseException ex) { - // for now, no need to show the error message to the user her + // for now, no need to show the error message to the user here } if (!startDateValue.equals("")) { if (startDate != null) { @@ -120,6 +120,13 @@ class DateSearchFilter extends AbstractFileSearchFilter { } } + // If they put the dates in backwards, help them out. + if (fromDate > toDate) { + long temp = toDate; + toDate = fromDate; + fromDate = temp; + } + final boolean modifiedChecked = panel.getModifiedCheckBox().isSelected(); final boolean changedChecked = panel.getChangedCheckBox().isSelected(); final boolean accessedChecked = panel.getAccessedCheckBox().isSelected(); @@ -127,32 +134,27 @@ class DateSearchFilter extends AbstractFileSearchFilter { if (modifiedChecked || changedChecked || accessedChecked || createdChecked) { - String subQuery = ""; - if (modifiedChecked) { - subQuery += " OR mtime BETWEEN " + fromDate + " AND " + toDate; //NON-NLS + query += " OR (mtime BETWEEN " + fromDate + " AND " + toDate + ")"; //NON-NLS } if (changedChecked) { - subQuery += " OR ctime BETWEEN " + fromDate + " AND " + toDate; //NON-NLS + query += " OR (ctime BETWEEN " + fromDate + " AND " + toDate + ")"; //NON-NLS } if (accessedChecked) { - subQuery += " OR atime BETWEEN " + fromDate + " AND " + toDate; //NON-NLS + query += " OR (atime BETWEEN " + fromDate + " AND " + toDate + ")"; //NON-NLS } if (createdChecked) { - subQuery += " OR crtime BETWEEN " + fromDate + " AND " + toDate; //NON-NLS - } - - if (!subQuery.isEmpty()) { - addQuery += " AND (" + subQuery + ")"; //NON-NLS + query += " OR (crtime BETWEEN " + fromDate + " AND " + toDate + ")"; //NON-NLS } + } else { throw new FilterValidationException(NONE_SELECTED_MESSAGE); } - return addQuery; + return query; } diff --git a/Core/src/org/sleuthkit/autopsy/filesearch/FileSearchPanel.java b/Core/src/org/sleuthkit/autopsy/filesearch/FileSearchPanel.java index 9ee6e6511a..a68a0a1903 100644 --- a/Core/src/org/sleuthkit/autopsy/filesearch/FileSearchPanel.java +++ b/Core/src/org/sleuthkit/autopsy/filesearch/FileSearchPanel.java @@ -207,11 +207,17 @@ import org.sleuthkit.datamodel.TskCoreException; //String query = "SELECT " + tempQuery + " FROM tsk_files WHERE "; String query = ""; - + int i=0; for (FileSearchFilter f : this.getEnabledFilters()) { String result = f.getPredicate(); if (!result.isEmpty()) { - query += " AND (" + result + ")"; //NON-NLS + if(i>0) { + query += " AND (" + result + ")"; //NON-NLS + } + else { + query += " (" + result + ")"; //NON-NLS + } + ++i; } } diff --git a/Core/src/org/sleuthkit/autopsy/filesearch/KnownStatusSearchFilter.java b/Core/src/org/sleuthkit/autopsy/filesearch/KnownStatusSearchFilter.java index 66d1daae6b..5565553ebc 100644 --- a/Core/src/org/sleuthkit/autopsy/filesearch/KnownStatusSearchFilter.java +++ b/Core/src/org/sleuthkit/autopsy/filesearch/KnownStatusSearchFilter.java @@ -56,7 +56,7 @@ class KnownStatusSearchFilter extends AbstractFileSearchFilter