From 61dba172ec1934c9bdcc9d6c61e62ff88998d400 Mon Sep 17 00:00:00 2001
From: Alex Ebadirad <aebadirad@42six.com>
Date: Mon, 14 May 2012 09:45:39 -0700
Subject: [PATCH] Tweaks to report/Report.java

---
 RecentActivity/nbproject/genfiles.properties  |  8 ++--
 RecentActivity/nbproject/project.properties   |  1 +
 RecentActivity/nbproject/project.xml          | 10 ++---
 .../autopsy/recentactivity/Bundle.properties  |  1 +
 .../autopsy/recentactivity/dbconnect.java     |  3 --
 Report/nbproject/genfiles.properties          |  8 ++--
 Report/nbproject/project.xml                  |  8 ++++
 .../org/sleuthkit/autopsy/report/Report.java  | 44 +++++++++++++++----
 .../autopsy/report/ReportFilter.form          |  2 +-
 .../autopsy/report/ReportFilter.java          |  1 +
 .../sleuthkit/autopsy/report/ReportUtils.java | 20 +++++++++
 .../sleuthkit/autopsy/report/ReportXML.java   |  8 +++-
 .../org/sleuthkit/autopsy/report/layer.xml    | 13 +++---
 13 files changed, 92 insertions(+), 35 deletions(-)

diff --git a/RecentActivity/nbproject/genfiles.properties b/RecentActivity/nbproject/genfiles.properties
index 9e5bb239dc..ac6636ed07 100644
--- a/RecentActivity/nbproject/genfiles.properties
+++ b/RecentActivity/nbproject/genfiles.properties
@@ -1,8 +1,8 @@
-build.xml.data.CRC32=dacaa05a
+build.xml.data.CRC32=f4b57a2d
 build.xml.script.CRC32=d323407a
-build.xml.stylesheet.CRC32=a56c6a5b@1.46.1
+build.xml.stylesheet.CRC32=a56c6a5b@1.46.2
 # This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
 # Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
-nbproject/build-impl.xml.data.CRC32=dacaa05a
+nbproject/build-impl.xml.data.CRC32=f4b57a2d
 nbproject/build-impl.xml.script.CRC32=aef16a21
-nbproject/build-impl.xml.stylesheet.CRC32=238281d1@1.46.1
+nbproject/build-impl.xml.stylesheet.CRC32=238281d1@1.46.2
diff --git a/RecentActivity/nbproject/project.properties b/RecentActivity/nbproject/project.properties
index c2587f0f66..87fc09e95f 100644
--- a/RecentActivity/nbproject/project.properties
+++ b/RecentActivity/nbproject/project.properties
@@ -1,5 +1,6 @@
 file.reference.gson-2.1.jar=release/modules/ext/gson-2.1.jar
 file.reference.jdom-1.1.2.jar=release/modules/ext/jdom-1.1.2.jar
 file.reference.sqlite-jdbc-3.7.6.3-20110609.081603-3.jar=release/modules/ext/sqlite-jdbc-3.7.6.3-20110609.081603-3.jar
+is.autoload=true
 javac.source=1.6
 javac.compilerargs=-Xlint -Xlint:-serial
diff --git a/RecentActivity/nbproject/project.xml b/RecentActivity/nbproject/project.xml
index c6387afb84..8b4a1e91da 100644
--- a/RecentActivity/nbproject/project.xml
+++ b/RecentActivity/nbproject/project.xml
@@ -178,14 +178,10 @@
                         <specification-version>0.0</specification-version>
                     </run-dependency>
                 </dependency>
-                <dependency>
-                    <code-name-base>org.sleuthkit.autopsy.report</code-name-base>
-                    <run-dependency>
-                        <specification-version>1.0</specification-version>
-                    </run-dependency>
-                </dependency>
             </module-dependencies>
-            <public-packages/>
+            <public-packages>
+                <package>org.sleuthkit.autopsy.recentactivity</package>
+            </public-packages>
             <class-path-extension>
                 <runtime-relative-path>ext/sqlite-jdbc-3.7.6.3-20110609.081603-3.jar</runtime-relative-path>
                 <binary-origin>release/modules/ext/sqlite-jdbc-3.7.6.3-20110609.081603-3.jar</binary-origin>
diff --git a/RecentActivity/src/org/sleuthkit/autopsy/recentactivity/Bundle.properties b/RecentActivity/src/org/sleuthkit/autopsy/recentactivity/Bundle.properties
index fc21672edd..3e1a5cd2cb 100644
--- a/RecentActivity/src/org/sleuthkit/autopsy/recentactivity/Bundle.properties
+++ b/RecentActivity/src/org/sleuthkit/autopsy/recentactivity/Bundle.properties
@@ -1,3 +1,4 @@
+OpenIDE-Module-Display-Category=Java
 OpenIDE-Module-Name=RecentActivity
 RecentActivityTopComponent.makeNodesButton.text=Get Recent Activity
 RecentActivityTopComponent.jLabel1.text=Filter Options
diff --git a/RecentActivity/src/org/sleuthkit/autopsy/recentactivity/dbconnect.java b/RecentActivity/src/org/sleuthkit/autopsy/recentactivity/dbconnect.java
index 67272f5900..19064301f8 100644
--- a/RecentActivity/src/org/sleuthkit/autopsy/recentactivity/dbconnect.java
+++ b/RecentActivity/src/org/sleuthkit/autopsy/recentactivity/dbconnect.java
@@ -15,9 +15,6 @@ public class dbconnect extends sqlitedbconnect{
         public dbconnect(String sDriverForClass, String sUrlKey) throws Exception
         { 
             init(sDriverForClass, sUrlKey); 
-            //Statement stmt = conn.createStatement();
-            //String selecthistory = "SELECT moz_historyvisits.id,url,title,visit_count,visit_date,from_visit,rev_host FROM moz_places, moz_historyvisits WHERE moz_places.id = moz_historyvisits.place_id AND hidden = 0";
-           // ResultSet rs = stmt.executeQuery(selecthistory); 
            
         }
         
diff --git a/Report/nbproject/genfiles.properties b/Report/nbproject/genfiles.properties
index 03f0e6b880..2e8895c1f4 100644
--- a/Report/nbproject/genfiles.properties
+++ b/Report/nbproject/genfiles.properties
@@ -1,8 +1,8 @@
-build.xml.data.CRC32=38c0b1aa
+build.xml.data.CRC32=d88c1ca9
 build.xml.script.CRC32=bbb1c310
-build.xml.stylesheet.CRC32=a56c6a5b@1.46.1
+build.xml.stylesheet.CRC32=a56c6a5b@1.46.2
 # This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
 # Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
-nbproject/build-impl.xml.data.CRC32=38c0b1aa
+nbproject/build-impl.xml.data.CRC32=d88c1ca9
 nbproject/build-impl.xml.script.CRC32=1562aec2
-nbproject/build-impl.xml.stylesheet.CRC32=238281d1@1.46.1
+nbproject/build-impl.xml.stylesheet.CRC32=238281d1@1.46.2
diff --git a/Report/nbproject/project.xml b/Report/nbproject/project.xml
index b7a7ee39b9..6deb5c1af8 100644
--- a/Report/nbproject/project.xml
+++ b/Report/nbproject/project.xml
@@ -135,6 +135,14 @@
                         <specification-version>0.0</specification-version>
                     </run-dependency>
                 </dependency>
+                <dependency>
+                    <code-name-base>org.sleuthkit.autopsy.recentactivity</code-name-base>
+                    <build-prerequisite/>
+                    <compile-dependency/>
+                    <run-dependency>
+                        <specification-version>1.0</specification-version>
+                    </run-dependency>
+                </dependency>
             </module-dependencies>
             <public-packages/>
             <class-path-extension>
diff --git a/Report/src/org/sleuthkit/autopsy/report/Report.java b/Report/src/org/sleuthkit/autopsy/report/Report.java
index 847a16c6d5..43a5f7a52c 100644
--- a/Report/src/org/sleuthkit/autopsy/report/Report.java
+++ b/Report/src/org/sleuthkit/autopsy/report/Report.java
@@ -20,7 +20,9 @@
  */
 package org.sleuthkit.autopsy.report;
 
-import java.sql.ResultSet;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.Map;
@@ -30,6 +32,8 @@
 import org.sleuthkit.datamodel.BlackboardArtifact;
 import org.sleuthkit.datamodel.BlackboardAttribute;
 import org.sleuthkit.datamodel.SleuthkitCase;
+import java.sql.*;
+import org.sleuthkit.autopsy.recentactivity.dbconnect;
 
 /**
  *
@@ -37,7 +41,7 @@
  */
 public class Report {
 
-    private void report() {
+    private void Report() {
     }
 
     public String getGroupedKeywordHit() {
@@ -46,30 +50,52 @@ public String getGroupedKeywordHit() {
         Case currentCase = Case.getCurrentCase(); // get the most updated case
         SleuthkitCase tempDb = currentCase.getSleuthkitCase();
         try {
+           ReportUtils util = new ReportUtils();
+           util.copy(new FileInputStream(currentCase.getCaseDirectory()+File.separator+"autopsy.db"), new FileOutputStream(currentCase.getCaseDirectory()+File.separator+"autopsy-copy.db"));
+            dbconnect tempdbconnect = new dbconnect("org.sqlite.JDBC", "jdbc:sqlite:"+currentCase.getCaseDirectory()+File.separator+"autopsy-copy.db");
+           tempdbconnect.executeStmt("DROP TABLE IF EXISTS report_keyword;"); 
+           tempdbconnect.executeStmt("DROP TABLE IF EXISTS report_preview;");
+           tempdbconnect.executeStmt("DROP TABLE IF EXISTS report_exp;");
+           tempdbconnect.executeStmt("DROP TABLE IF EXISTS report_name;");
+           tempdbconnect.executeStmt("DROP TABLE IF EXISTS report;");
             String temp1 = "CREATE TABLE report_keyword AS SELECT value_text as keyword,blackboard_attributes.attribute_type_id, blackboard_attributes.artifact_id FROM blackboard_attributes WHERE attribute_type_id = 10;";
             String temp2 = "CREATE TABLE report_preview AS SELECT value_text as preview, blackboard_attributes.attribute_type_id, blackboard_attributes.artifact_id FROM blackboard_attributes WHERE attribute_type_id = 11;";
             String temp3 = "CREATE TABLE report_exp AS SELECT value_text as exp, blackboard_attributes.attribute_type_id, blackboard_attributes.artifact_id FROM blackboard_attributes WHERE attribute_type_id = 12;";
             String temp4 = "CREATE TABLE report_name AS SELECT name, report_keyword.artifact_id from tsk_files,blackboard_artifacts, report_keyword WHERE blackboard_artifacts.artifact_id = report_keyword.artifact_id AND blackboard_artifacts.obj_id = tsk_files.obj_id;";
-            String temp5 = "CREATE table report AS SELECT keyword,preview,exp, name from report_keyword INNER JOIN report_preview ON report_keyword.artifact_id=report_preview.artifact_id INNER JOIN report_exp ON report_preview.artifact_id=report_exp.artifact_id INNER JOIN report_name ON report_exp.artifact_id=report_name.artifact_id;";
-            tempDb.runQuery(temp1+temp2+temp3+temp4+temp5);
-            ResultSet uniqueresults = tempDb.runQuery("select keyword, preview, exp, name FROM report ORDER BY keyword ASC");
+            String temp5 = "CREATE TABLE report AS SELECT keyword,preview,exp, name from report_keyword INNER JOIN report_preview ON report_keyword.artifact_id=report_preview.artifact_id INNER JOIN report_exp ON report_preview.artifact_id=report_exp.artifact_id INNER JOIN report_name ON report_exp.artifact_id=report_name.artifact_id;";
+           tempdbconnect.executeStmt(temp1);
+           tempdbconnect.executeStmt(temp2);
+           tempdbconnect.executeStmt(temp3);
+           tempdbconnect.executeStmt(temp4);
+           tempdbconnect.executeStmt(temp5);
+            ResultSet uniqueresults =  tempdbconnect.executeQry("SELECT keyword, preview, exp, name FROM report ORDER BY keyword ASC");
            String keyword = "";
             while (uniqueresults.next()) { 
-                if(uniqueresults.getString("value_text") == null ? keyword == null : uniqueresults.getString("keyword").equals(keyword))
+                if(uniqueresults.getString("keyword") == null ? keyword == null : uniqueresults.getString("keyword").equals(keyword))
                 {
       
                 }
                 else{
+               table.append("</tbody></table><br /><br />");
                keyword = uniqueresults.getString("keyword");
                table.append("<strong>").append(keyword).append("</strong>");
                table.append("<table><thead><tr><th>").append("File Name").append("</th><th>Preview</th><th>Keyword List</th></tr><tbody>");
                 }
                table.append("<tr><td>").append(uniqueresults.getString("name")).append("</td>");
                 table.append("<td>").append(uniqueresults.getString("preview")).append("</td>").append("<td>").append(uniqueresults.getString("exp")).append("</td>").append("</tr>");
-               table.append("</tbody></table><br /><br />");
+              
             }
-            tempDb.runQuery("DROP TABLE report_keyword; DROP TABLE report_preview; DROP TABLE report_exp; DROP TABLE report_name; DROP TABLE report;");
-            
+            tempDb.close();
+           tempdbconnect.executeStmt("DROP TABLE IF EXISTS report_keyword;"); 
+           tempdbconnect.executeStmt("DROP TABLE IF EXISTS report_preview;");
+           tempdbconnect.executeStmt("DROP TABLE IF EXISTS report_exp;");
+           tempdbconnect.executeStmt("DROP TABLE IF EXISTS report_name;");
+           tempdbconnect.executeStmt("DROP TABLE IF EXISTS report;");
+           tempdbconnect.closeConnection();
+           
+             File f1 = new File(currentCase.getCaseDirectory()+File.separator+"autopsy-copy.db");
+             boolean success = f1.delete();
+          
         } catch (Exception e) {
             Logger.getLogger(Report.class.getName()).log(Level.WARNING, "Exception occurred", e);
         }
diff --git a/Report/src/org/sleuthkit/autopsy/report/ReportFilter.form b/Report/src/org/sleuthkit/autopsy/report/ReportFilter.form
index 53b9485c2f..0718f0450a 100644
--- a/Report/src/org/sleuthkit/autopsy/report/ReportFilter.form
+++ b/Report/src/org/sleuthkit/autopsy/report/ReportFilter.form
@@ -1,4 +1,4 @@
-<?xml version="1.0" encoding="UTF-8" ?>
+<?xml version="1.1" encoding="UTF-8" ?>
 
 <Form version="1.5" maxVersion="1.7" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
   <NonVisualComponents>
diff --git a/Report/src/org/sleuthkit/autopsy/report/ReportFilter.java b/Report/src/org/sleuthkit/autopsy/report/ReportFilter.java
index 88c236ecb9..84ffaf3bf5 100644
--- a/Report/src/org/sleuthkit/autopsy/report/ReportFilter.java
+++ b/Report/src/org/sleuthkit/autopsy/report/ReportFilter.java
@@ -195,6 +195,7 @@ private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRS
     progBar.setStringPainted(true);
     progBar.setValue(0);
     filters.clear();
+    config.resetGenArtifactTypes();
     if (jCheckBox1.isSelected()) {
         try {
             config.setGenArtifactType(BlackboardArtifact.ARTIFACT_TYPE.TSK_WEB_BOOKMARK, true);
diff --git a/Report/src/org/sleuthkit/autopsy/report/ReportUtils.java b/Report/src/org/sleuthkit/autopsy/report/ReportUtils.java
index ba3dd55969..8c5b86f554 100644
--- a/Report/src/org/sleuthkit/autopsy/report/ReportUtils.java
+++ b/Report/src/org/sleuthkit/autopsy/report/ReportUtils.java
@@ -20,6 +20,12 @@
  */
 package org.sleuthkit.autopsy.report;
 
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
 /**
  *
  * @author Alex
@@ -52,4 +58,18 @@ public static String insertPeriodically(String text, String insert, int period)
         }
         return builder.toString();
     }
+    
+    public static void copy(InputStream in, OutputStream out) throws IOException {
+
+    BufferedInputStream bin = new BufferedInputStream(in);
+    BufferedOutputStream bout = new BufferedOutputStream(out);
+
+    while (true) {
+      int datum = bin.read();
+      if (datum == -1)
+        break;
+      bout.write(datum);
+    }
+    bout.flush();
+  }
 }
\ No newline at end of file
diff --git a/Report/src/org/sleuthkit/autopsy/report/ReportXML.java b/Report/src/org/sleuthkit/autopsy/report/ReportXML.java
index 5f28552675..90d980ae66 100644
--- a/Report/src/org/sleuthkit/autopsy/report/ReportXML.java
+++ b/Report/src/org/sleuthkit/autopsy/report/ReportXML.java
@@ -106,10 +106,14 @@ public String generateReport(ReportConfiguration reportconfig, ReportFilter rr)
                 Long objId = entry.getKey().getObjectID();
                 Content cont = skCase.getContentById(objId);
                 Long filesize = cont.getSize();
-                artifact.setAttribute("ID", objId.toString());
+                try{
+                 artifact.setAttribute("ID", objId.toString());                
                 artifact.setAttribute("Name", cont.accept(new NameVisitor()));
                 artifact.setAttribute("Size", filesize.toString());
-
+                }
+                catch(Exception e){
+                     Logger.getLogger(ReportXML.class.getName()).log(Level.WARNING, "Visitor content exception occurred:", e);
+                }
                 // Get all the attributes for this guy
                 for (BlackboardAttribute tempatt : entry.getValue()) {
                     if (ReportFilter.cancel == true) {
diff --git a/Report/src/org/sleuthkit/autopsy/report/layer.xml b/Report/src/org/sleuthkit/autopsy/report/layer.xml
index 5888a01825..700d9fc5ff 100644
--- a/Report/src/org/sleuthkit/autopsy/report/layer.xml
+++ b/Report/src/org/sleuthkit/autopsy/report/layer.xml
@@ -4,8 +4,11 @@
        <folder name="Actions">
         <folder name="Tools">
             <file name="org-sleuthkit-autopsy-report-ReportAction.instance"/>
-            <file name="org-sleuthkit-autopsy-report-ReportAction.instance_hidden"/>
-            <file name="org-sleuthkit-autopsy-report-ReportAction.instance_hidden"/>
+        </folder>
+    </folder>
+    <folder name="Menu">
+        <folder name="Tools">
+            <file name="org-sleuthkit-autopsy-report-ReportAction.shadow"/>
         </folder>
     </folder>
     <folder name="Services">
@@ -16,10 +19,10 @@
         </file>
         </folder>
     <folder name="Toolbars">
-            <file name="sep2.instance">
+            <!-- <file name="sep2.instance">
                 <attr name="instanceClass" stringvalue="javax.swing.JToolBar$Separator"/>
             <attr name="position" intvalue="600"/>
-           </file>
+           </file> -->
           <folder name="File">
             <file name="org-sleuthkit-autopsy-report-ReportAction.shadow">
                 <attr name="displayName" bundlevalue="org.sleuthkit.autopsy.report.Bundle#Toolbars/Reports/org-sleuthkit-autopsy-report-ReportAction.shadow"/>
@@ -29,4 +32,4 @@
         </folder>
     </folder>
     
-</filesystem>
+</filesystem>
\ No newline at end of file
-- 
GitLab