Autopsy  4.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
ReportHTML.java
Go to the documentation of this file.
1  /*
2  *
3  * Autopsy Forensic Browser
4  *
5  * Copyright 2012-2014 Basis Technology Corp.
6  *
7  * Copyright 2012 42six Solutions.
8  * Contact: aebadirad <at> 42six <dot> com
9  * Project Contact/Architect: carrier <at> sleuthkit <dot> org
10  *
11  * Licensed under the Apache License, Version 2.0 (the "License");
12  * you may not use this file except in compliance with the License.
13  * You may obtain a copy of the License at
14  *
15  * http://www.apache.org/licenses/LICENSE-2.0
16  *
17  * Unless required by applicable law or agreed to in writing, software
18  * distributed under the License is distributed on an "AS IS" BASIS,
19  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20  * See the License for the specific language governing permissions and
21  * limitations under the License.
22  */
23 package org.sleuthkit.autopsy.report;
24 
25 import java.io.BufferedWriter;
26 import java.io.File;
27 import java.io.FileNotFoundException;
28 import java.io.FileOutputStream;
29 import java.io.IOException;
30 import java.io.InputStream;
31 import java.io.OutputStream;
32 import java.io.OutputStreamWriter;
33 import java.io.UnsupportedEncodingException;
34 import java.io.Writer;
35 import java.text.DateFormat;
36 import java.text.SimpleDateFormat;
37 import java.util.ArrayList;
38 import java.util.Date;
39 import java.util.List;
40 import java.util.Map;
41 import java.util.TreeMap;
42 import java.util.logging.Level;
43 import org.openide.filesystems.FileObject;
44 import org.openide.filesystems.FileUtil;
45 import org.openide.util.NbBundle;
53 import org.sleuthkit.datamodel.AbstractFile;
54 import org.sleuthkit.datamodel.BlackboardArtifact;
55 import org.sleuthkit.datamodel.BlackboardArtifact.ARTIFACT_TYPE;
56 import org.sleuthkit.datamodel.Content;
57 import org.sleuthkit.datamodel.ContentTag;
58 import org.sleuthkit.datamodel.Image;
59 import org.sleuthkit.datamodel.SleuthkitCase;
60 import org.sleuthkit.datamodel.TskCoreException;
61 import org.sleuthkit.datamodel.TskData.TSK_DB_FILES_TYPE_ENUM;
62 
63 class ReportHTML implements TableReportModule {
64 
65  private static final Logger logger = Logger.getLogger(ReportHTML.class.getName());
66  private static final String THUMBS_REL_PATH = "thumbs" + File.separator; //NON-NLS
67  private static ReportHTML instance;
68  private static final int MAX_THUMBS_PER_PAGE = 1000;
69  private Case currentCase;
70  private SleuthkitCase skCase;
71  static Integer THUMBNAIL_COLUMNS = 5;
72 
73  private Map<String, Integer> dataTypes;
74  private String path;
75  private String thumbsPath;
76  private String currentDataType; // name of current data type
77  private Integer rowCount; // number of rows (aka artifacts or tags) for the current data type
78  private Writer out;
79 
80  private final ReportBranding reportBranding;
81 
82  // Get the default instance of this report
83  public static synchronized ReportHTML getDefault() {
84  if (instance == null) {
85  instance = new ReportHTML();
86  }
87  return instance;
88  }
89 
90  // Hidden constructor
91  private ReportHTML() {
92  reportBranding = new ReportBranding();
93  }
94 
95  // Refesh the member variables
96  private void refresh() {
97  currentCase = Case.getCurrentCase();
98  skCase = currentCase.getSleuthkitCase();
99 
100  dataTypes = new TreeMap<>();
101 
102  path = "";
103  thumbsPath = "";
104  currentDataType = "";
105  rowCount = 0;
106 
107  if (out != null) {
108  try {
109  out.close();
110  } catch (IOException ex) {
111  }
112  }
113  out = null;
114  }
115 
122  private String dataTypeToFileName(String dataType) {
123 
124  String fileName = org.sleuthkit.autopsy.coreutils.FileUtil.escapeFileName(dataType);
125  // replace all ' ' with '_'
126  fileName = fileName.replaceAll(" ", "_");
127 
128  return fileName;
129  }
130 
135  private String useDataTypeIcon(String dataType) {
136  String iconFilePath;
137  String iconFileName;
138  InputStream in;
139  OutputStream output = null;
140 
141  logger.log(Level.INFO, "useDataTypeIcon: dataType = {0}", dataType); //NON-NLS
142 
143  // find the artifact with matching display name
144  BlackboardArtifact.ARTIFACT_TYPE artifactType = null;
145  for (ARTIFACT_TYPE v : ARTIFACT_TYPE.values()) {
146  if (v.getDisplayName().equals(dataType)) {
147  artifactType = v;
148  }
149  }
150 
151  if (null != artifactType) {
152  // set the icon file name
153  iconFileName = dataTypeToFileName(artifactType.getDisplayName()) + ".png"; //NON-NLS
154  iconFilePath = path + File.separator + iconFileName;
155 
156  // determine the source image to use
157  switch (artifactType) {
158  case TSK_WEB_BOOKMARK:
159  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/report/images/bookmarks.png"); //NON-NLS
160  break;
161  case TSK_WEB_COOKIE:
162  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/report/images/cookies.png"); //NON-NLS
163  break;
164  case TSK_WEB_HISTORY:
165  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/report/images/history.png"); //NON-NLS
166  break;
167  case TSK_WEB_DOWNLOAD:
168  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/report/images/downloads.png"); //NON-NLS
169  break;
170  case TSK_RECENT_OBJECT:
171  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/report/images/recent.png"); //NON-NLS
172  break;
173  case TSK_INSTALLED_PROG:
174  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/report/images/installed.png"); //NON-NLS
175  break;
176  case TSK_KEYWORD_HIT:
177  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/report/images/keywords.png"); //NON-NLS
178  break;
179  case TSK_HASHSET_HIT:
180  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/report/images/hash.png"); //NON-NLS
181  break;
182  case TSK_DEVICE_ATTACHED:
183  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/report/images/devices.png"); //NON-NLS
184  break;
185  case TSK_WEB_SEARCH_QUERY:
186  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/report/images/search.png"); //NON-NLS
187  break;
188  case TSK_METADATA_EXIF:
189  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/report/images/exif.png"); //NON-NLS
190  break;
191  case TSK_TAG_FILE:
192  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/report/images/userbookmarks.png"); //NON-NLS
193  break;
194  case TSK_TAG_ARTIFACT:
195  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/report/images/userbookmarks.png"); //NON-NLS
196  break;
197  case TSK_SERVICE_ACCOUNT:
198  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/report/images/account-icon-16.png"); //NON-NLS
199  break;
200  case TSK_CONTACT:
201  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/report/images/contact.png"); //NON-NLS
202  break;
203  case TSK_MESSAGE:
204  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/report/images/message.png"); //NON-NLS
205  break;
206  case TSK_CALLLOG:
207  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/report/images/calllog.png"); //NON-NLS
208  break;
209  case TSK_CALENDAR_ENTRY:
210  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/report/images/calendar.png"); //NON-NLS
211  break;
212  case TSK_SPEED_DIAL_ENTRY:
213  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/report/images/speeddialentry.png"); //NON-NLS
214  break;
215  case TSK_BLUETOOTH_PAIRING:
216  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/report/images/bluetooth.png"); //NON-NLS
217  break;
218  case TSK_GPS_BOOKMARK:
219  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/report/images/gpsfav.png"); //NON-NLS
220  break;
221  case TSK_GPS_LAST_KNOWN_LOCATION:
222  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/report/images/gps-lastlocation.png"); //NON-NLS
223  break;
224  case TSK_GPS_SEARCH:
225  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/report/images/gps-search.png"); //NON-NLS
226  break;
227  case TSK_OS_INFO:
228  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/report/images/computer.png"); //NON-NLS
229  break;
230  case TSK_GPS_TRACKPOINT:
231  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/report/images/gps_trackpoint.png"); //NON-NLS
232  break;
233  case TSK_GPS_ROUTE:
234  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/report/images/gps_trackpoint.png"); //NON-NLS
235  break;
236  case TSK_EMAIL_MSG:
237  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/images/mail-icon-16.png"); //NON-NLS
238  break;
239  case TSK_ENCRYPTION_DETECTED:
240  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/images/encrypted-file.png"); //NON-NLS
241  break;
242  case TSK_EXT_MISMATCH_DETECTED:
243  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/images/mismatch-16.png"); //NON-NLS
244  break;
245  case TSK_INTERESTING_ARTIFACT_HIT:
246  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/images/interesting_item.png"); //NON-NLS
247  break;
248  case TSK_INTERESTING_FILE_HIT:
249  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/images/interesting_item.png"); //NON-NLS
250  break;
251  case TSK_PROG_RUN:
252  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/report/images/installed.png"); //NON-NLS
253  break;
254  case TSK_REMOTE_DRIVE:
255  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/report/images/drive_network.png"); //NON-NLS
256  break;
257  default:
258  logger.log(Level.WARNING, "useDataTypeIcon: unhandled artifact type = " + dataType); //NON-NLS
259  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/report/images/star.png"); //NON-NLS
260  iconFileName = "star.png"; //NON-NLS
261  iconFilePath = path + File.separator + iconFileName;
262  break;
263  }
264  } else { // no defined artifact found for this dataType
265  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/report/images/star.png"); //NON-NLS
266  iconFileName = "star.png"; //NON-NLS
267  iconFilePath = path + File.separator + iconFileName;
268  }
269 
270  try {
271  output = new FileOutputStream(iconFilePath);
272  FileUtil.copy(in, output);
273  in.close();
274  output.close();
275  } catch (IOException ex) {
276  logger.log(Level.SEVERE, "Failed to extract images for HTML report.", ex); //NON-NLS
277  } finally {
278  if (output != null) {
279  try {
280  output.flush();
281  output.close();
282  } catch (IOException ex) {
283  }
284  }
285  if (in != null) {
286  try {
287  in.close();
288  } catch (IOException ex) {
289  }
290  }
291  }
292 
293  return iconFileName;
294  }
295 
302  @Override
303  public void startReport(String baseReportDir) {
304  // Refresh the HTML report
305  refresh();
306  // Setup the path for the HTML report
307  this.path = baseReportDir + "HTML Report" + File.separator; //NON-NLS
308  this.thumbsPath = this.path + "thumbs" + File.separator; //NON-NLS
309  try {
310  FileUtil.createFolder(new File(this.path));
311  FileUtil.createFolder(new File(this.thumbsPath));
312  } catch (IOException ex) {
313  logger.log(Level.SEVERE, "Unable to make HTML report folder."); //NON-NLS
314  }
315  // Write the basic files
316  writeCss();
317  writeIndex();
318  writeSummary();
319  }
320 
325  @Override
326  public void endReport() {
327  writeNav();
328  if (out != null) {
329  try {
330  out.close();
331  } catch (IOException ex) {
332  logger.log(Level.WARNING, "Could not close the output writer when ending report.", ex); //NON-NLS
333  }
334  }
335  }
336 
345  @Override
346  public void startDataType(String name, String description) {
347  String title = dataTypeToFileName(name);
348  try {
349  out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(path + title + ".html"), "UTF-8")); //NON-NLS
350  } catch (FileNotFoundException ex) {
351  logger.log(Level.SEVERE, "File not found: {0}", ex); //NON-NLS
352  } catch (UnsupportedEncodingException ex) {
353  logger.log(Level.SEVERE, "Unrecognized encoding"); //NON-NLS
354  }
355 
356  try {
357  StringBuilder page = new StringBuilder();
358  page.append("<html>\n<head>\n\t<title>").append(name).append("</title>\n\t<link rel=\"stylesheet\" type=\"text/css\" href=\"index.css\" />\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\n</head>\n<body>\n"); //NON-NLS
359  page.append("<div id=\"header\">").append(name).append("</div>\n<div id=\"content\">\n"); //NON-NLS
360  if (!description.isEmpty()) {
361  page.append("<p><strong>"); //NON-NLS
362  page.append(description);
363  page.append("</string></p>\n"); //NON-NLS
364  }
365  out.write(page.toString());
366  currentDataType = name;
367  rowCount = 0;
368  } catch (IOException ex) {
369  logger.log(Level.SEVERE, "Failed to write page head: {0}", ex); //NON-NLS
370  }
371  }
372 
377  @Override
378  public void endDataType() {
379  dataTypes.put(currentDataType, rowCount);
380  try {
381  out.write("</div>\n</body>\n</html>\n"); //NON-NLS
382  } catch (IOException ex) {
383  logger.log(Level.SEVERE, "Failed to write end of HTML report.", ex); //NON-NLS
384  } finally {
385  if (out != null) {
386  try {
387  out.flush();
388  out.close();
389  } catch (IOException ex) {
390  logger.log(Level.WARNING, "Could not close the output writer when ending data type.", ex); //NON-NLS
391  }
392  out = null;
393  }
394  }
395  }
396 
402  @Override
403  public void startSet(String setName) {
404  StringBuilder set = new StringBuilder();
405  set.append("<h1><a name=\"").append(setName).append("\">").append(setName).append("</a></h1>\n"); //NON-NLS
406  set.append("<div class=\"keyword_list\">\n"); //NON-NLS
407 
408  try {
409  out.write(set.toString());
410  } catch (IOException ex) {
411  logger.log(Level.SEVERE, "Failed to write set: {0}", ex); //NON-NLS
412  }
413  }
414 
418  @Override
419  public void endSet() {
420  try {
421  out.write("</div>\n"); //NON-NLS
422  } catch (IOException ex) {
423  logger.log(Level.SEVERE, "Failed to write end of set: {0}", ex); //NON-NLS
424  }
425  }
426 
432  @Override
433  public void addSetIndex(List<String> sets) {
434  StringBuilder index = new StringBuilder();
435  index.append("<ul>\n"); //NON-NLS
436  for (String set : sets) {
437  index.append("\t<li><a href=\"#").append(set).append("\">").append(set).append("</a></li>\n"); //NON-NLS
438  }
439  index.append("</ul>\n"); //NON-NLS
440  try {
441  out.write(index.toString());
442  } catch (IOException ex) {
443  logger.log(Level.SEVERE, "Failed to add set index: {0}", ex); //NON-NLS
444  }
445  }
446 
452  @Override
453  public void addSetElement(String elementName) {
454  try {
455  out.write("<h4>" + elementName + "</h4>\n"); //NON-NLS
456  } catch (IOException ex) {
457  logger.log(Level.SEVERE, "Failed to write set element: {0}", ex); //NON-NLS
458  }
459  }
460 
466  @Override
467  public void startTable(List<String> titles) {
468  StringBuilder ele = new StringBuilder();
469  ele.append("<table>\n<thead>\n\t<tr>\n"); //NON-NLS
470  for (String title : titles) {
471  ele.append("\t\t<th>").append(title).append("</th>\n"); //NON-NLS
472  }
473  ele.append("\t</tr>\n</thead>\n"); //NON-NLS
474 
475  try {
476  out.write(ele.toString());
477  } catch (IOException ex) {
478  logger.log(Level.SEVERE, "Failed to write table start: {0}", ex); //NON-NLS
479  }
480  }
481 
489  public void startContentTagsTable(List<String> columnHeaders) {
490  StringBuilder htmlOutput = new StringBuilder();
491  htmlOutput.append("<table>\n<thead>\n\t<tr>\n"); //NON-NLS
492 
493  // Add the specified columns.
494  for (String columnHeader : columnHeaders) {
495  htmlOutput.append("\t\t<th>").append(columnHeader).append("</th>\n"); //NON-NLS
496  }
497 
498  // Add a column for a hyperlink to a local copy of the tagged content.
499  htmlOutput.append("\t\t<th></th>\n"); //NON-NLS
500 
501  htmlOutput.append("\t</tr>\n</thead>\n"); //NON-NLS
502 
503  try {
504  out.write(htmlOutput.toString());
505  } catch (IOException ex) {
506  logger.log(Level.SEVERE, "Failed to write table start: {0}", ex); //NON-NLS
507  }
508  }
509 
513  @Override
514  public void endTable() {
515  try {
516  out.write("</table>\n"); //NON-NLS
517  } catch (IOException ex) {
518  logger.log(Level.SEVERE, "Failed to write end of table: {0}", ex); //NON-NLS
519  }
520  }
521 
527  @Override
528  public void addRow(List<String> row) {
529  StringBuilder builder = new StringBuilder();
530  builder.append("\t<tr>\n"); //NON-NLS
531  for (String cell : row) {
532  builder.append("\t\t<td>").append(cell).append("</td>\n"); //NON-NLS
533  }
534  builder.append("\t</tr>\n"); //NON-NLS
535  rowCount++;
536 
537  try {
538  out.write(builder.toString());
539  } catch (IOException ex) {
540  logger.log(Level.SEVERE, "Failed to write row to out.", ex); //NON-NLS
541  } catch (NullPointerException ex) {
542  logger.log(Level.SEVERE, "Output writer is null. Page was not initialized before writing.", ex); //NON-NLS
543  }
544  }
545 
556  public void addRowWithTaggedContentHyperlink(List<String> row, ContentTag contentTag) {
557  Content content = contentTag.getContent();
558  if (content instanceof AbstractFile == false) {
559  addRow(row);
560  return;
561  }
562  AbstractFile file = (AbstractFile) content;
563  // Add the hyperlink to the row. A column header for it was created in startTable().
564  StringBuilder localFileLink = new StringBuilder();
565  // Don't make a local copy of the file if it is a directory or unallocated space.
566  if (!(file.isDir()
567  || file.getType() == TSK_DB_FILES_TYPE_ENUM.UNALLOC_BLOCKS
568  || file.getType() == TSK_DB_FILES_TYPE_ENUM.UNUSED_BLOCKS)) {
569  localFileLink.append("<a href=\""); //NON-NLS
570  // save it in a folder based on the tag name
571  String localFilePath = saveContent(file, contentTag.getName().getDisplayName());
572  localFileLink.append(localFilePath);
573  localFileLink.append("\">");
574  }
575 
576  StringBuilder builder = new StringBuilder();
577  builder.append("\t<tr>\n"); //NON-NLS
578  int positionCounter = 0;
579  for (String cell : row) {
580  // position-dependent code used to format this report. Not great, but understandable for formatting.
581  if (positionCounter == 1) { // Convert the file name to a hyperlink and left-align it
582  builder.append("\t\t<td class=\"left_align_cell\">").append(localFileLink.toString()).append(cell).append("</a></td>\n"); //NON-NLS
583  } else if (positionCounter == 7) { // Right-align the bytes column.
584  builder.append("\t\t<td class=\"right_align_cell\">").append(cell).append("</td>\n"); //NON-NLS
585  } else { // Regular case, not a file name nor a byte count
586  builder.append("\t\t<td>").append(cell).append("</td>\n"); //NON-NLS
587  }
588  ++positionCounter;
589  }
590  builder.append("\t</tr>\n"); //NON-NLS
591  rowCount++;
592 
593  try {
594  out.write(builder.toString());
595  } catch (IOException ex) {
596  logger.log(Level.SEVERE, "Failed to write row to out.", ex); //NON-NLS
597  } catch (NullPointerException ex) {
598  logger.log(Level.SEVERE, "Output writer is null. Page was not initialized before writing.", ex); //NON-NLS
599  }
600  }
601 
607  public void addThumbnailRows(List<Content> images) {
608  List<String> currentRow = new ArrayList<>();
609  int totalCount = 0;
610  int pages = 0;
611  for (Content content : images) {
612  if (currentRow.size() == THUMBNAIL_COLUMNS) {
613  addRow(currentRow);
614  currentRow.clear();
615  }
616 
617  if (totalCount == MAX_THUMBS_PER_PAGE) {
618  // manually set the row count so the count of items shown in the
619  // navigation page reflects the number of thumbnails instead of
620  // the number of rows.
621  rowCount = totalCount;
622  totalCount = 0;
623  pages++;
624  endTable();
625  endDataType();
626  startDataType(NbBundle.getMessage(this.getClass(), "ReportHTML.addThumbRows.dataType.title", pages),
627  NbBundle.getMessage(this.getClass(), "ReportHTML.addThumbRows.dataType.msg"));
628  List<String> emptyHeaders = new ArrayList<>();
629  for (int i = 0; i < THUMBNAIL_COLUMNS; i++) {
630  emptyHeaders.add("");
631  }
632  startTable(emptyHeaders);
633  }
634 
635  if (failsContentCheck(content)) {
636  continue;
637  }
638 
639  AbstractFile file = (AbstractFile) content;
640 
641  // save copies of the orginal image and thumbnail image
642  String thumbnailPath = prepareThumbnail(file);
643  if (thumbnailPath == null) {
644  continue;
645  }
646  String contentPath = saveContent(file, "thumbs_fullsize"); //NON-NLS
647  String nameInImage;
648  try {
649  nameInImage = file.getUniquePath();
650  } catch (TskCoreException ex) {
651  nameInImage = file.getName();
652  }
653 
654  StringBuilder linkToThumbnail = new StringBuilder();
655  linkToThumbnail.append("<a href=\""); //NON-NLS
656  linkToThumbnail.append(contentPath);
657  linkToThumbnail.append("\">");
658  linkToThumbnail.append("<img src=\"").append(thumbnailPath).append("\" title=\"").append(nameInImage).append("\"/>"); //NON-NLS
659  linkToThumbnail.append("</a><br>"); //NON-NLS
660  linkToThumbnail.append(file.getName()).append("<br>"); //NON-NLS
661 
662  Services services = currentCase.getServices();
663  TagsManager tagsManager = services.getTagsManager();
664  try {
665  List<ContentTag> tags = tagsManager.getContentTagsByContent(content);
666  if (tags.size() > 0) {
667  linkToThumbnail.append(NbBundle.getMessage(this.getClass(), "ReportHTML.thumbLink.tags"));
668  }
669  for (int i = 0; i < tags.size(); i++) {
670  ContentTag tag = tags.get(i);
671  linkToThumbnail.append(tag.getName().getDisplayName());
672  if (i != tags.size() - 1) {
673  linkToThumbnail.append(", ");
674  }
675  }
676  } catch (TskCoreException ex) {
677  logger.log(Level.WARNING, "Could not find get tags for file.", ex); //NON-NLS
678  }
679 
680  currentRow.add(linkToThumbnail.toString());
681 
682  totalCount++;
683  }
684 
685  if (currentRow.isEmpty() == false) {
686  int extraCells = THUMBNAIL_COLUMNS - currentRow.size();
687  for (int i = 0; i < extraCells; i++) {
688  // Finish out the row.
689  currentRow.add("");
690  }
691  addRow(currentRow);
692  }
693 
694  // manually set rowCount to be the total number of images.
695  rowCount = totalCount;
696  }
697 
698  private boolean failsContentCheck(Content c) {
699  if (c instanceof AbstractFile == false) {
700  return true;
701  }
702  AbstractFile file = (AbstractFile) c;
703  if (file.isDir()
704  || file.getType() == TSK_DB_FILES_TYPE_ENUM.UNALLOC_BLOCKS
705  || file.getType() == TSK_DB_FILES_TYPE_ENUM.UNUSED_BLOCKS) {
706  return true;
707  }
708  return false;
709  }
710 
720  public String saveContent(AbstractFile file, String dirName) {
721  // clean up the dir name passed in
722  String dirName2 = dirName.replace("/", "_");
723  dirName2 = dirName2.replace("\\", "_");
724 
725  // Make a folder for the local file with the same tagName as the tag.
726  StringBuilder localFilePath = new StringBuilder(); // full path
727 
728  localFilePath.append(path);
729  localFilePath.append(dirName2);
730  File localFileFolder = new File(localFilePath.toString());
731  if (!localFileFolder.exists()) {
732  localFileFolder.mkdirs();
733  }
734 
735  // Construct a file tagName for the local file that incorporates the file id to ensure uniqueness.
736  String fileName = file.getName();
737  String objectIdSuffix = "_" + file.getId();
738  int lastDotIndex = fileName.lastIndexOf(".");
739  if (lastDotIndex != -1 && lastDotIndex != 0) {
740  // The file tagName has a conventional extension. Insert the object id before the '.' of the extension.
741  fileName = fileName.substring(0, lastDotIndex) + objectIdSuffix + fileName.substring(lastDotIndex, fileName.length());
742  } else {
743  // The file has no extension or the only '.' in the file is an initial '.', as in a hidden file.
744  // Add the object id to the end of the file tagName.
745  fileName += objectIdSuffix;
746  }
747  localFilePath.append(File.separator);
748  localFilePath.append(fileName);
749 
750  // If the local file doesn't already exist, create it now.
751  // The existence check is necessary because it is possible to apply multiple tags with the same tagName to a file.
752  File localFile = new File(localFilePath.toString());
753  if (!localFile.exists()) {
754  ExtractFscContentVisitor.extract(file, localFile, null, null);
755  }
756 
757  // get the relative path
758  return localFilePath.toString().substring(path.length());
759  }
760 
768  @Override
769  public String dateToString(long date) {
770  SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
771  return sdf.format(new java.util.Date(date * 1000));
772  }
773 
774  @Override
775  public String getRelativeFilePath() {
776  return "HTML Report" + File.separator + "index.html"; //NON-NLS
777  }
778 
779  @Override
780  public String getName() {
781  return NbBundle.getMessage(this.getClass(), "ReportHTML.getName.text");
782  }
783 
784  @Override
785  public String getDescription() {
786  return NbBundle.getMessage(this.getClass(), "ReportHTML.getDesc.text");
787  }
788 
792  private void writeCss() {
793  Writer cssOut = null;
794  try {
795  cssOut = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(path + "index.css"), "UTF-8")); //NON-NLS NON-NLS
796  String css = "body {margin: 0px; padding: 0px; background: #FFFFFF; font: 13px/20px Arial, Helvetica, sans-serif; color: #535353;}\n" + //NON-NLS
797  "#content {padding: 30px;}\n" + //NON-NLS
798  "#header {width:100%; padding: 10px; line-height: 25px; background: #07A; color: #FFF; font-size: 20px;}\n" + //NON-NLS
799  "h1 {font-size: 20px; font-weight: normal; color: #07A; padding: 0 0 7px 0; margin-top: 25px; border-bottom: 1px solid #D6D6D6;}\n" + //NON-NLS
800  "h2 {font-size: 20px; font-weight: bolder; color: #07A;}\n" + //NON-NLS
801  "h3 {font-size: 16px; color: #07A;}\n" + //NON-NLS
802  "h4 {background: #07A; color: #FFF; font-size: 16px; margin: 0 0 0 25px; padding: 0; padding-left: 15px;}\n" + //NON-NLS
803  "ul.nav {list-style-type: none; line-height: 35px; padding: 0px; margin-left: 15px;}\n" + //NON-NLS
804  "ul li a {font-size: 14px; color: #444; text-decoration: none; padding-left: 25px;}\n" + //NON-NLS
805  "ul li a:hover {text-decoration: underline;}\n" + //NON-NLS
806  "p {margin: 0 0 20px 0;}\n" + //NON-NLS
807  "table {white-space:nowrap; min-width: 700px; padding: 2; margin: 0; border-collapse: collapse; border-bottom: 2px solid #e5e5e5;}\n" + //NON-NLS
808  ".keyword_list table {margin: 0 0 25px 25px; border-bottom: 2px solid #dedede;}\n" + //NON-NLS
809  "table th {white-space:nowrap; display: table-cell; text-align: center; padding: 2px 4px; background: #e5e5e5; color: #777; font-size: 11px; text-shadow: #e9f9fd 0 1px 0; border-top: 1px solid #dedede; border-bottom: 2px solid #e5e5e5;}\n" + //NON-NLS
810  "table .left_align_cell{display: table-cell; padding: 2px 4px; font: 13px/20px Arial, Helvetica, sans-serif; min-width: 125px; overflow: auto; text-align: left; }\n" + //NON-NLS
811  "table .right_align_cell{display: table-cell; padding: 2px 4px; font: 13px/20px Arial, Helvetica, sans-serif; min-width: 125px; overflow: auto; text-align: right; }\n" + //NON-NLS
812  "table td {white-space:nowrap; display: table-cell; padding: 2px 3px; font: 13px/20px Arial, Helvetica, sans-serif; min-width: 125px; overflow: auto; text-align:left; }\n" + //NON-NLS
813  "table tr:nth-child(even) td {background: #f3f3f3;}"; //NON-NLS
814  cssOut.write(css);
815  } catch (FileNotFoundException ex) {
816  logger.log(Level.SEVERE, "Could not find index.css file to write to.", ex); //NON-NLS
817  } catch (UnsupportedEncodingException ex) {
818  logger.log(Level.SEVERE, "Did not recognize encoding when writing index.css.", ex); //NON-NLS
819  } catch (IOException ex) {
820  logger.log(Level.SEVERE, "Error creating Writer for index.css.", ex); //NON-NLS
821  } finally {
822  try {
823  if (cssOut != null) {
824  cssOut.flush();
825  cssOut.close();
826  }
827  } catch (IOException ex) {
828  }
829  }
830  }
831 
835  private void writeIndex() {
836  Writer indexOut = null;
837  String indexFilePath = path + "index.html"; //NON-NLS
838  try {
839  indexOut = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(indexFilePath), "UTF-8")); //NON-NLS
840  StringBuilder index = new StringBuilder();
841  index.append("<head>\n<title>").append( //NON-NLS
842  NbBundle.getMessage(this.getClass(), "ReportHTML.writeIndex.title", currentCase.getName())).append(
843  "</title>\n"); //NON-NLS
844  index.append("<link rel=\"icon\" type=\"image/ico\" href=\"favicon.ico\" />\n"); //NON-NLS
845  index.append("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\n"); //NON-NLS
846  index.append("</head>\n"); //NON-NLS
847  index.append("<frameset cols=\"350px,*\">\n"); //NON-NLS
848  index.append("<frame src=\"nav.html\" name=\"nav\">\n"); //NON-NLS
849  index.append("<frame src=\"summary.html\" name=\"content\">\n"); //NON-NLS
850  index.append("<noframes>").append(NbBundle.getMessage(this.getClass(), "ReportHTML.writeIndex.noFrames.msg")).append("<br />\n"); //NON-NLS
851  index.append(NbBundle.getMessage(this.getClass(), "ReportHTML.writeIndex.noFrames.seeNav")).append("<br />\n"); //NON-NLS
852  index.append(NbBundle.getMessage(this.getClass(), "ReportHTML.writeIndex.seeSum")).append("</noframes>\n"); //NON-NLS
853  index.append("</frameset>\n"); //NON-NLS
854  index.append("</html>"); //NON-NLS
855  indexOut.write(index.toString());
856  Case.getCurrentCase().addReport(indexFilePath, NbBundle.getMessage(this.getClass(),
857  "ReportHTML.writeIndex.srcModuleName.text"), "");
858  } catch (IOException ex) {
859  logger.log(Level.SEVERE, "Error creating Writer for index.html: {0}", ex); //NON-NLS
860  } catch (TskCoreException ex) {
861  String errorMessage = String.format("Error adding %s to case as a report", indexFilePath); //NON-NLS
862  logger.log(Level.SEVERE, errorMessage, ex);
863  } finally {
864  try {
865  if (indexOut != null) {
866  indexOut.flush();
867  indexOut.close();
868  }
869  } catch (IOException ex) {
870  }
871  }
872  }
873 
877  private void writeNav() {
878  Writer navOut = null;
879  try {
880  navOut = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(path + "nav.html"), "UTF-8")); //NON-NLS
881  StringBuilder nav = new StringBuilder();
882  nav.append("<html>\n<head>\n\t<title>").append( //NON-NLS
883  NbBundle.getMessage(this.getClass(), "ReportHTML.writeNav.title"))
884  .append("</title>\n\t<link rel=\"stylesheet\" type=\"text/css\" href=\"index.css\" />\n"); //NON-NLS
885  nav.append("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\n</head>\n<body>\n"); //NON-NLS
886  nav.append("<div id=\"content\">\n<h1>").append( //NON-NLS
887  NbBundle.getMessage(this.getClass(), "ReportHTML.writeNav.h1")).append("</h1>\n"); //NON-NLS
888  nav.append("<ul class=\"nav\">\n"); //NON-NLS
889  nav.append("<li style=\"background: url(summary.png) left center no-repeat;\"><a href=\"summary.html\" target=\"content\">") //NON-NLS
890  .append(NbBundle.getMessage(this.getClass(), "ReportHTML.writeNav.summary")).append("</a></li>\n"); //NON-NLS
891 
892  for (String dataType : dataTypes.keySet()) {
893  String dataTypeEsc = dataTypeToFileName(dataType);
894  String iconFileName = useDataTypeIcon(dataType);
895  nav.append("<li style=\"background: url('").append(iconFileName) //NON-NLS
896  .append("') left center no-repeat;\"><a href=\"") //NON-NLS
897  .append(dataTypeEsc).append(".html\" target=\"content\">") //NON-NLS
898  .append(dataType).append(" (").append(dataTypes.get(dataType))
899  .append(")</a></li>\n"); //NON-NLS
900  }
901  nav.append("</ul>\n"); //NON-NLS
902  nav.append("</div>\n</body>\n</html>"); //NON-NLS
903  navOut.write(nav.toString());
904  } catch (IOException ex) {
905  logger.log(Level.SEVERE, "Failed to write end of report navigation menu: {0}", ex); //NON-NLS
906  } finally {
907  if (navOut != null) {
908  try {
909  navOut.flush();
910  navOut.close();
911  } catch (IOException ex) {
912  logger.log(Level.WARNING, "Could not close navigation out writer."); //NON-NLS
913  }
914  }
915  }
916 
917  InputStream in = null;
918  OutputStream output = null;
919  try {
920 
921  //pull generator and agency logo from branding, and the remaining resources from the core jar
922  String generatorLogoPath = reportBranding.getGeneratorLogoPath();
923  if (generatorLogoPath != null && !generatorLogoPath.isEmpty()) {
924  File from = new File(generatorLogoPath);
925  File to = new File(path);
926  FileUtil.copyFile(FileUtil.toFileObject(from), FileUtil.toFileObject(to), "generator_logo"); //NON-NLS
927  }
928 
929  String agencyLogoPath = reportBranding.getAgencyLogoPath();
930  if (agencyLogoPath != null && !agencyLogoPath.isEmpty()) {
931  File from = new File(agencyLogoPath);
932  File to = new File(path);
933  FileUtil.copyFile(FileUtil.toFileObject(from), FileUtil.toFileObject(to), "agency_logo"); //NON-NLS
934  }
935 
936  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/report/images/favicon.ico"); //NON-NLS
937  output = new FileOutputStream(new File(path + File.separator + "favicon.ico"));
938  FileUtil.copy(in, output);
939  in.close();
940  output.close();
941 
942  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/report/images/summary.png"); //NON-NLS
943  output = new FileOutputStream(new File(path + File.separator + "summary.png"));
944  FileUtil.copy(in, output);
945  in.close();
946  output.close();
947 
948  } catch (IOException ex) {
949  logger.log(Level.SEVERE, "Failed to extract images for HTML report.", ex); //NON-NLS
950  } finally {
951  if (output != null) {
952  try {
953  output.flush();
954  output.close();
955  } catch (IOException ex) {
956  }
957  }
958  if (in != null) {
959  try {
960  in.close();
961  } catch (IOException ex) {
962  }
963  }
964  }
965  }
966 
970  private void writeSummary() {
971  Writer out = null;
972  try {
973  out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(path + "summary.html"), "UTF-8")); //NON-NLS
974  StringBuilder head = new StringBuilder();
975  head.append("<html>\n<head>\n<title>").append( //NON-NLS
976  NbBundle.getMessage(this.getClass(), "ReportHTML.writeSum.title")).append("</title>\n"); //NON-NLS
977  head.append("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\n"); //NON-NLS
978  head.append("<style type=\"text/css\">\n"); //NON-NLS
979  head.append("body { padding: 0px; margin: 0px; font: 13px/20px Arial, Helvetica, sans-serif; color: #535353; }\n"); //NON-NLS
980  head.append("#wrapper { width: 90%; margin: 0px auto; margin-top: 35px; }\n"); //NON-NLS
981  head.append("h1 { color: #07A; font-size: 36px; line-height: 42px; font-weight: normal; margin: 0px; border-bottom: 1px solid #81B9DB; }\n"); //NON-NLS
982  head.append("h1 span { color: #F00; display: block; font-size: 16px; font-weight: bold; line-height: 22px;}\n"); //NON-NLS
983  head.append("h2 { padding: 0 0 3px 0; margin: 0px; color: #07A; font-weight: normal; border-bottom: 1px dotted #81B9DB; }\n"); //NON-NLS
984  head.append("table td { padding-right: 25px; }\n"); //NON-NLS
985  head.append("p.subheadding { padding: 0px; margin: 0px; font-size: 11px; color: #B5B5B5; }\n"); //NON-NLS
986  head.append(".title { width: 660px; margin-bottom: 50px; }\n"); //NON-NLS
987  head.append(".left { float: left; width: 250px; margin-top: 20px; text-align: center; }\n"); //NON-NLS
988  head.append(".left img { max-width: 250px; max-height: 250px; min-width: 200px; min-height: 200px; }\n"); //NON-NLS
989  head.append(".right { float: right; width: 385px; margin-top: 25px; font-size: 14px; }\n"); //NON-NLS
990  head.append(".clear { clear: both; }\n"); //NON-NLS
991  head.append(".info p { padding: 3px 10px; background: #e5e5e5; color: #777; font-size: 12px; font-weight: bold; text-shadow: #e9f9fd 0 1px 0; border-top: 1px solid #dedede; border-bottom: 2px solid #dedede; }\n"); //NON-NLS
992  head.append(".info table { margin: 0 25px 20px 25px; }\n"); //NON-NLS
993  head.append("</style>\n"); //NON-NLS
994  head.append("</head>\n<body>\n"); //NON-NLS
995  out.write(head.toString());
996 
997  DateFormat datetimeFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
998  Date date = new Date();
999  String datetime = datetimeFormat.format(date);
1000 
1001  String caseName = currentCase.getName();
1002  String caseNumber = currentCase.getNumber();
1003  String examiner = currentCase.getExaminer();
1004  int imagecount;
1005  try {
1006  imagecount = currentCase.getDataSources().size();
1007  } catch (TskCoreException ex) {
1008  imagecount = 0;
1009  }
1010 
1011  StringBuilder summary = new StringBuilder();
1012  boolean running = false;
1013  if (IngestManager.getInstance().isIngestRunning()) {
1014  running = true;
1015  }
1016 
1017  final String reportTitle = reportBranding.getReportTitle();
1018  final String reportFooter = reportBranding.getReportFooter();
1019  final boolean agencyLogoSet = reportBranding.getAgencyLogoPath() != null && !reportBranding.getAgencyLogoPath().isEmpty();
1020  final boolean generatorLogoSet = reportBranding.getGeneratorLogoPath() != null && !reportBranding.getGeneratorLogoPath().isEmpty();
1021 
1022  summary.append("<div id=\"wrapper\">\n"); //NON-NLS
1023  summary.append("<h1>").append(reportTitle) //NON-NLS
1024  .append(running ? NbBundle.getMessage(this.getClass(), "ReportHTML.writeSum.warningMsg") : "")
1025  .append("</h1>\n"); //NON-NLS
1026  summary.append("<p class=\"subheadding\">").append( //NON-NLS
1027  NbBundle.getMessage(this.getClass(), "ReportHTML.writeSum.reportGenOn.text", datetime)).append("</p>\n"); //NON-NLS
1028  summary.append("<div class=\"title\">\n"); //NON-NLS
1029  if (agencyLogoSet) {
1030  summary.append("<div class=\"left\">\n"); //NON-NLS
1031  summary.append("<img src=\"agency_logo.png\" />\n"); //NON-NLS
1032  summary.append("</div>\n"); //NON-NLS
1033  }
1034  final String align = agencyLogoSet ? "right" : "left"; //NON-NLS NON-NLS
1035  summary.append("<div class=\"").append(align).append("\">\n"); //NON-NLS
1036  summary.append("<table>\n"); //NON-NLS
1037  summary.append("<tr><td>").append(NbBundle.getMessage(this.getClass(), "ReportHTML.writeSum.caseName")) //NON-NLS
1038  .append("</td><td>").append(caseName).append("</td></tr>\n"); //NON-NLS NON-NLS
1039  summary.append("<tr><td>").append(NbBundle.getMessage(this.getClass(), "ReportHTML.writeSum.caseNum")) //NON-NLS
1040  .append("</td><td>").append(!caseNumber.isEmpty() ? caseNumber : NbBundle //NON-NLS
1041  .getMessage(this.getClass(), "ReportHTML.writeSum.noCaseNum")).append("</td></tr>\n"); //NON-NLS
1042  summary.append("<tr><td>").append(NbBundle.getMessage(this.getClass(), "ReportHTML.writeSum.examiner")).append("</td><td>") //NON-NLS
1043  .append(!examiner.isEmpty() ? examiner : NbBundle
1044  .getMessage(this.getClass(), "ReportHTML.writeSum.noExaminer"))
1045  .append("</td></tr>\n"); //NON-NLS
1046  summary.append("<tr><td>").append(NbBundle.getMessage(this.getClass(), "ReportHTML.writeSum.numImages")) //NON-NLS
1047  .append("</td><td>").append(imagecount).append("</td></tr>\n"); //NON-NLS
1048  summary.append("</table>\n"); //NON-NLS
1049  summary.append("</div>\n"); //NON-NLS
1050  summary.append("<div class=\"clear\"></div>\n"); //NON-NLS
1051  summary.append("</div>\n"); //NON-NLS
1052  summary.append(NbBundle.getMessage(this.getClass(), "ReportHTML.writeSum.imageInfoHeading"));
1053  summary.append("<div class=\"info\">\n"); //NON-NLS
1054  try {
1055  for (Content c : currentCase.getDataSources()) {
1056  summary.append("<p>").append(c.getName()).append("</p>\n"); //NON-NLS
1057  if (c instanceof Image) {
1058  Image img = (Image) c;
1059 
1060  summary.append("<table>\n"); //NON-NLS
1061  summary.append("<tr><td>").append( //NON-NLS
1062  NbBundle.getMessage(this.getClass(), "ReportHTML.writeSum.timezone"))
1063  .append("</td><td>").append(img.getTimeZone()).append("</td></tr>\n"); //NON-NLS
1064  for (String imgPath : img.getPaths()) {
1065  summary.append("<tr><td>").append( //NON-NLS
1066  NbBundle.getMessage(this.getClass(), "ReportHTML.writeSum.path"))
1067  .append("</td><td>").append(imgPath).append("</td></tr>\n"); //NON-NLS
1068  }
1069  summary.append("</table>\n"); //NON-NLS
1070  }
1071  }
1072  } catch (TskCoreException ex) {
1073  logger.log(Level.WARNING, "Unable to get image information for the HTML report."); //NON-NLS
1074  }
1075  summary.append("</div>\n"); //NON-NLS
1076  if (generatorLogoSet) {
1077  summary.append("<div class=\"left\">\n"); //NON-NLS
1078  summary.append("<img src=\"generator_logo.png\" />\n"); //NON-NLS
1079  summary.append("</div>\n"); //NON-NLS
1080  }
1081  summary.append("<div class=\"clear\"></div>\n"); //NON-NLS
1082  if (reportFooter != null) {
1083  summary.append("<p class=\"subheadding\">").append(reportFooter).append("</p>\n"); //NON-NLS
1084  }
1085  summary.append("</div>\n"); //NON-NLS
1086  summary.append("</body></html>"); //NON-NLS
1087  out.write(summary.toString());
1088  } catch (FileNotFoundException ex) {
1089  logger.log(Level.SEVERE, "Could not find summary.html file to write to."); //NON-NLS
1090  } catch (UnsupportedEncodingException ex) {
1091  logger.log(Level.SEVERE, "Did not recognize encoding when writing summary.hmtl."); //NON-NLS
1092  } catch (IOException ex) {
1093  logger.log(Level.SEVERE, "Error creating Writer for summary.html."); //NON-NLS
1094  } finally {
1095  try {
1096  if (out != null) {
1097  out.flush();
1098  out.close();
1099  }
1100  } catch (IOException ex) {
1101  }
1102  }
1103  }
1104 
1105  private String prepareThumbnail(AbstractFile file) {
1106  File thumbFile = ImageUtils.getCachedThumbnailFile(file, ImageUtils.ICON_SIZE_MEDIUM);
1107  if (thumbFile.exists() == false) {
1108  return null;
1109  }
1110  try {
1111  File to = new File(thumbsPath);
1112  FileObject from = FileUtil.toFileObject(thumbFile);
1113  FileObject dest = FileUtil.toFileObject(to);
1114  FileUtil.copyFile(from, dest, thumbFile.getName(), "");
1115  } catch (IOException ex) {
1116  logger.log(Level.SEVERE, "Failed to write thumb file to report directory.", ex); //NON-NLS
1117  }
1118 
1119  return THUMBS_REL_PATH + thumbFile.getName();
1120  }
1121 
1122 }
static String escapeFileName(String fileName)
Definition: FileUtil.java:169

Copyright © 2012-2015 Basis Technology. Generated on: Wed Apr 6 2016
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.