Autopsy  4.14.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
HTMLReport.java
Go to the documentation of this file.
1 /*
2  *
3  * Autopsy Forensic Browser
4  *
5  * Copyright 2012-2018 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.modules.html;
24 
27 import java.awt.image.BufferedImage;
28 import java.io.BufferedWriter;
29 import java.io.File;
30 import java.io.FileNotFoundException;
31 import java.io.FileOutputStream;
32 import java.io.IOException;
33 import java.io.InputStream;
34 import java.io.OutputStream;
35 import java.io.OutputStreamWriter;
36 import java.io.UnsupportedEncodingException;
37 import java.io.Writer;
38 import java.nio.file.Files;
39 import java.nio.file.Path;
40 import java.nio.file.Paths;
41 import java.text.DateFormat;
42 import java.text.SimpleDateFormat;
43 import java.util.ArrayList;
44 import java.util.Date;
45 import java.util.HashMap;
46 import java.util.List;
47 import java.util.Map;
48 import java.util.Set;
49 import java.util.TreeMap;
50 import java.util.concurrent.ExecutionException;
51 import java.util.logging.Level;
52 import javax.imageio.ImageIO;
53 import javax.swing.JPanel;
54 import org.apache.commons.io.FilenameUtils;
55 import org.apache.commons.lang3.StringEscapeUtils;
56 import org.openide.filesystems.FileUtil;
57 import org.openide.util.NbBundle;
58 import org.openide.util.NbBundle.Messages;
74 import org.sleuthkit.datamodel.AbstractFile;
75 import org.sleuthkit.datamodel.BlackboardArtifact;
76 import org.sleuthkit.datamodel.BlackboardArtifact.ARTIFACT_TYPE;
77 import org.sleuthkit.datamodel.Content;
78 import org.sleuthkit.datamodel.ContentTag;
79 import org.sleuthkit.datamodel.Image;
80 import org.sleuthkit.datamodel.IngestJobInfo;
81 import org.sleuthkit.datamodel.IngestModuleInfo;
82 import org.sleuthkit.datamodel.SleuthkitCase;
83 import org.sleuthkit.datamodel.TskCoreException;
84 import org.sleuthkit.datamodel.TskData;
85 import org.sleuthkit.datamodel.TskData.TSK_DB_FILES_TYPE_ENUM;
86 
87 public class HTMLReport implements TableReportModule {
88 
89  private static final Logger logger = Logger.getLogger(HTMLReport.class.getName());
90  private static final String THUMBS_REL_PATH = "thumbs" + File.separator; //NON-NLS
91  private static HTMLReport instance;
92  private static final int MAX_THUMBS_PER_PAGE = 1000;
93  private static final String HTML_SUBDIR = "content";
94  private Case currentCase;
95  public static Integer THUMBNAIL_COLUMNS = 5;
96 
97  private Map<String, Integer> dataTypes;
98  private String path;
99  private String thumbsPath;
100  private String subPath;
101  private String currentDataType; // name of current data type
102  private Integer rowCount; // number of rows (aka artifacts or tags) for the current data type
103  private Writer out;
104 
105  private HTMLReportConfigurationPanel configPanel;
106 
108 
109  // Get the default instance of this report
110  public static synchronized HTMLReport getDefault() {
111  if (instance == null) {
112  instance = new HTMLReport();
113  }
114  return instance;
115  }
116 
117  // Hidden constructor
118  private HTMLReport() {
119  reportBranding = new ReportBranding();
120  }
121 
122  @Override
123  public JPanel getConfigurationPanel() {
124  initializePanel();
125  return configPanel;
126  }
127 
128  private void initializePanel() {
129  if (configPanel == null) {
130  configPanel = new HTMLReportConfigurationPanel();
131  }
132  }
133 
139  @Override
141  return new HTMLReportModuleSettings();
142  }
143 
149  @Override
151  initializePanel();
152  return configPanel.getConfiguration();
153  }
154 
160  @Override
161  public void setConfiguration(ReportModuleSettings settings) {
162  initializePanel();
163  if (settings == null || settings instanceof NoReportModuleSettings) {
164  configPanel.setConfiguration((HTMLReportModuleSettings) getDefaultConfiguration());
165  return;
166  }
167 
168  if (settings instanceof HTMLReportModuleSettings) {
169  configPanel.setConfiguration((HTMLReportModuleSettings) settings);
170  return;
171  }
172 
173  throw new IllegalArgumentException("Expected settings argument to be an instance of HTMLReportModuleSettings");
174  }
175 
176  // Refesh the member variables
177  private void refresh() throws NoCurrentCaseException {
178  currentCase = Case.getCurrentCaseThrows();
179 
180  dataTypes = new TreeMap<>();
181 
182  path = "";
183  thumbsPath = "";
184  subPath = "";
185  currentDataType = "";
186  rowCount = 0;
187 
188  if (out != null) {
189  try {
190  out.close();
191  } catch (IOException ex) {
192  }
193  }
194  out = null;
195  }
196 
203  private String dataTypeToFileName(String dataType) {
204 
205  String fileName = org.sleuthkit.autopsy.coreutils.FileUtil.escapeFileName(dataType);
206  // replace all ' ' with '_'
207  fileName = fileName.replaceAll(" ", "_");
208 
209  return fileName;
210  }
211 
216  private String useDataTypeIcon(String dataType) {
217  String iconFilePath;
218  String iconFileName;
219  InputStream in;
220  OutputStream output = null;
221 
222  logger.log(Level.INFO, "useDataTypeIcon: dataType = {0}", dataType); //NON-NLS
223 
224  // find the artifact with matching display name
225  BlackboardArtifact.ARTIFACT_TYPE artifactType = null;
226  for (ARTIFACT_TYPE v : ARTIFACT_TYPE.values()) {
227  if (v.getDisplayName().equals(dataType)) {
228  artifactType = v;
229  }
230  }
231 
232  if (null != artifactType) {
233  // set the icon file name
234  iconFileName = dataTypeToFileName(artifactType.getDisplayName()) + ".png"; //NON-NLS
235  iconFilePath = subPath + File.separator + iconFileName;
236 
237  // determine the source image to use
238  switch (artifactType) {
239  case TSK_WEB_BOOKMARK:
240  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/report/images/bookmarks.png"); //NON-NLS
241  break;
242  case TSK_WEB_COOKIE:
243  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/report/images/cookies.png"); //NON-NLS
244  break;
245  case TSK_WEB_HISTORY:
246  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/report/images/history.png"); //NON-NLS
247  break;
248  case TSK_WEB_DOWNLOAD:
249  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/report/images/downloads.png"); //NON-NLS
250  break;
251  case TSK_RECENT_OBJECT:
252  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/report/images/recent.png"); //NON-NLS
253  break;
254  case TSK_INSTALLED_PROG:
255  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/report/images/installed.png"); //NON-NLS
256  break;
257  case TSK_KEYWORD_HIT:
258  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/report/images/keywords.png"); //NON-NLS
259  break;
260  case TSK_HASHSET_HIT:
261  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/report/images/hash.png"); //NON-NLS
262  break;
263  case TSK_DEVICE_ATTACHED:
264  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/report/images/devices.png"); //NON-NLS
265  break;
266  case TSK_WEB_SEARCH_QUERY:
267  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/report/images/search.png"); //NON-NLS
268  break;
269  case TSK_METADATA_EXIF:
270  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/report/images/exif.png"); //NON-NLS
271  break;
272  case TSK_TAG_FILE:
273  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/report/images/userbookmarks.png"); //NON-NLS
274  break;
275  case TSK_TAG_ARTIFACT:
276  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/report/images/userbookmarks.png"); //NON-NLS
277  break;
278  case TSK_SERVICE_ACCOUNT:
279  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/report/images/account-icon-16.png"); //NON-NLS
280  break;
281  case TSK_CONTACT:
282  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/report/images/contact.png"); //NON-NLS
283  break;
284  case TSK_MESSAGE:
285  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/report/images/message.png"); //NON-NLS
286  break;
287  case TSK_CALLLOG:
288  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/report/images/calllog.png"); //NON-NLS
289  break;
290  case TSK_CALENDAR_ENTRY:
291  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/report/images/calendar.png"); //NON-NLS
292  break;
293  case TSK_SPEED_DIAL_ENTRY:
294  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/report/images/speeddialentry.png"); //NON-NLS
295  break;
296  case TSK_BLUETOOTH_PAIRING:
297  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/report/images/bluetooth.png"); //NON-NLS
298  break;
299  case TSK_GPS_BOOKMARK:
300  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/report/images/gpsfav.png"); //NON-NLS
301  break;
302  case TSK_GPS_LAST_KNOWN_LOCATION:
303  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/report/images/gps-lastlocation.png"); //NON-NLS
304  break;
305  case TSK_GPS_SEARCH:
306  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/report/images/gps-search.png"); //NON-NLS
307  break;
308  case TSK_OS_INFO:
309  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/report/images/computer.png"); //NON-NLS
310  break;
311  case TSK_GPS_TRACKPOINT:
312  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/report/images/gps_trackpoint.png"); //NON-NLS
313  break;
314  case TSK_GPS_ROUTE:
315  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/report/images/gps_trackpoint.png"); //NON-NLS
316  break;
317  case TSK_EMAIL_MSG:
318  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/images/mail-icon-16.png"); //NON-NLS
319  break;
320  case TSK_ENCRYPTION_SUSPECTED:
321  case TSK_ENCRYPTION_DETECTED:
322  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/images/encrypted-file.png"); //NON-NLS
323  break;
324  case TSK_EXT_MISMATCH_DETECTED:
325  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/images/mismatch-16.png"); //NON-NLS
326  break;
327  case TSK_INTERESTING_ARTIFACT_HIT:
328  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/images/interesting_item.png"); //NON-NLS
329  break;
330  case TSK_INTERESTING_FILE_HIT:
331  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/images/interesting_item.png"); //NON-NLS
332  break;
333  case TSK_PROG_RUN:
334  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/report/images/installed.png"); //NON-NLS
335  break;
336  case TSK_REMOTE_DRIVE:
337  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/report/images/drive_network.png"); //NON-NLS
338  break;
339  case TSK_ACCOUNT:
340  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/report/images/accounts.png"); //NON-NLS
341  break;
342  case TSK_WIFI_NETWORK:
343  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/images/network-wifi.png"); //NON-NLS
344  break;
345  case TSK_WIFI_NETWORK_ADAPTER:
346  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/images/network-wifi.png"); //NON-NLS
347  break;
348  case TSK_SIM_ATTACHED:
349  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/images/sim_card.png"); //NON-NLS
350  break;
351  case TSK_BLUETOOTH_ADAPTER:
352  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/images/Bluetooth.png"); //NON-NLS
353  break;
354  case TSK_DEVICE_INFO:
355  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/images/devices.png"); //NON-NLS
356  break;
357  case TSK_VERIFICATION_FAILED:
358  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/images/validationFailed.png"); //NON-NLS
359  break;
360  default:
361  logger.log(Level.WARNING, "useDataTypeIcon: unhandled artifact type = {0}", dataType); //NON-NLS
362  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/report/images/star.png"); //NON-NLS
363  iconFileName = "star.png"; //NON-NLS
364  iconFilePath = subPath + File.separator + iconFileName;
365  break;
366  }
367  } else if (dataType.startsWith(ARTIFACT_TYPE.TSK_ACCOUNT.getDisplayName())) {
368  /*
369  * TSK_ACCOUNT artifacts get separated by their TSK_ACCOUNT_TYPE
370  * attribute, with a synthetic compound dataType name, so they are
371  * not caught by the switch statement above. For now we just give
372  * them all the general account icon, but we could do something else
373  * in the future.
374  */
375  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/report/images/accounts.png"); //NON-NLS
376  iconFileName = "accounts.png"; //NON-NLS
377  iconFilePath = subPath + File.separator + iconFileName;
378  } else { // no defined artifact found for this dataType
379  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/report/images/star.png"); //NON-NLS
380  iconFileName = "star.png"; //NON-NLS
381  iconFilePath = subPath + File.separator + iconFileName;
382  }
383 
384  try {
385  output = new FileOutputStream(iconFilePath);
386  FileUtil.copy(in, output);
387  in.close();
388  output.close();
389  } catch (IOException ex) {
390  logger.log(Level.SEVERE, "Failed to extract images for HTML report.", ex); //NON-NLS
391  } finally {
392  if (output != null) {
393  try {
394  output.flush();
395  output.close();
396  } catch (IOException ex) {
397  }
398  }
399  if (in != null) {
400  try {
401  in.close();
402  } catch (IOException ex) {
403  }
404  }
405  }
406 
407  return iconFileName;
408  }
409 
416  @Override
417  public void startReport(String baseReportDir) {
418 
419  // Refresh the HTML report
420  try {
421  refresh();
422  } catch (NoCurrentCaseException ex) {
423  logger.log(Level.SEVERE, "Exception while getting open case."); //NON-NLS
424  return;
425  }
426  // Setup the path for the HTML report
427  this.path = baseReportDir; //NON-NLS
428  this.subPath = this.path + HTML_SUBDIR + File.separator;
429  this.thumbsPath = this.subPath + THUMBS_REL_PATH; //NON-NLS
430  try {
431  FileUtil.createFolder(new File(this.subPath));
432  FileUtil.createFolder(new File(this.thumbsPath));
433  } catch (IOException ex) {
434  logger.log(Level.SEVERE, "Unable to make HTML report folder."); //NON-NLS
435  }
436  // Write the basic files
437  writeCss();
438  writeIndex();
439  writeSummary();
440  }
441 
446  @Override
447  public void endReport() {
448  writeNav();
449  if (out != null) {
450  try {
451  out.close();
452  } catch (IOException ex) {
453  logger.log(Level.WARNING, "Could not close the output writer when ending report.", ex); //NON-NLS
454  }
455  }
456  }
457 
466  @Override
467  public void startDataType(String name, String description) {
468  String title = dataTypeToFileName(name);
469  try {
470  out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(subPath + title + ".html"), "UTF-8")); //NON-NLS
471  } catch (FileNotFoundException ex) {
472  logger.log(Level.SEVERE, "File not found: {0}", ex); //NON-NLS
473  } catch (UnsupportedEncodingException ex) {
474  logger.log(Level.SEVERE, "Unrecognized encoding"); //NON-NLS
475  }
476 
477  try {
478  StringBuilder page = new StringBuilder();
479  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
480  .append(writePageHeader())
481  .append("<div id=\"header\">").append(name).append("</div>\n")
482  .append("<div id=\"content\">\n"); //NON-NLS
483  if (!description.isEmpty()) {
484  page.append("<p><strong>"); //NON-NLS
485  page.append(description);
486  page.append("</strong></p>\n"); //NON-NLS
487  }
488  out.write(page.toString());
489  currentDataType = name;
490  rowCount = 0;
491  } catch (IOException ex) {
492  logger.log(Level.SEVERE, "Failed to write page head: {0}", ex); //NON-NLS
493  }
494  }
495 
500  @Override
501  public void endDataType() {
502  dataTypes.put(currentDataType, rowCount);
503  try {
504  StringBuilder builder = new StringBuilder();
505  builder.append(writePageFooter());
506  builder.append("</div>\n</body>\n</html>\n"); //NON-NLS
507  out.write(builder.toString());
508  } catch (IOException ex) {
509  logger.log(Level.SEVERE, "Failed to write end of HTML report.", ex); //NON-NLS
510  } finally {
511  if (out != null) {
512  try {
513  out.flush();
514  out.close();
515  } catch (IOException ex) {
516  logger.log(Level.WARNING, "Could not close the output writer when ending data type.", ex); //NON-NLS
517  }
518  out = null;
519  }
520  }
521  }
522 
529  private String writePageHeader() {
530  StringBuilder output = new StringBuilder();
531  String pageHeader = configPanel.getHeader();
532  if (pageHeader.isEmpty() == false) {
533  output.append("<div id=\"pageHeaderFooter\">")
534  .append(StringEscapeUtils.escapeHtml4(pageHeader))
535  .append("</div>\n"); //NON-NLS
536  }
537  return output.toString();
538  }
539 
546  private String writePageFooter() {
547  StringBuilder output = new StringBuilder();
548  String pageFooter = configPanel.getFooter();
549  if (pageFooter.isEmpty() == false) {
550  output.append("<br/><div id=\"pageHeaderFooter\">")
551  .append(StringEscapeUtils.escapeHtml4(pageFooter))
552  .append("</div>"); //NON-NLS
553  }
554  return output.toString();
555  }
556 
562  @Override
563  public void startSet(String setName) {
564  StringBuilder set = new StringBuilder();
565  set.append("<h1><a name=\"").append(setName).append("\">").append(setName).append("</a></h1>\n"); //NON-NLS
566  set.append("<div class=\"keyword_list\">\n"); //NON-NLS
567 
568  try {
569  out.write(set.toString());
570  } catch (IOException ex) {
571  logger.log(Level.SEVERE, "Failed to write set: {0}", ex); //NON-NLS
572  }
573  }
574 
578  @Override
579  public void endSet() {
580  try {
581  out.write("</div>\n"); //NON-NLS
582  } catch (IOException ex) {
583  logger.log(Level.SEVERE, "Failed to write end of set: {0}", ex); //NON-NLS
584  }
585  }
586 
592  @Override
593  public void addSetIndex(List<String> sets) {
594  StringBuilder index = new StringBuilder();
595  index.append("<ul>\n"); //NON-NLS
596  for (String set : sets) {
597  index.append("\t<li><a href=\"#").append(set).append("\">").append(set).append("</a></li>\n"); //NON-NLS
598  }
599  index.append("</ul>\n"); //NON-NLS
600  try {
601  out.write(index.toString());
602  } catch (IOException ex) {
603  logger.log(Level.SEVERE, "Failed to add set index: {0}", ex); //NON-NLS
604  }
605  }
606 
612  @Override
613  public void addSetElement(String elementName) {
614  try {
615  out.write("<h4>" + elementName + "</h4>\n"); //NON-NLS
616  } catch (IOException ex) {
617  logger.log(Level.SEVERE, "Failed to write set element: {0}", ex); //NON-NLS
618  }
619  }
620 
626  @Override
627  public void startTable(List<String> titles) {
628  StringBuilder ele = new StringBuilder();
629  ele.append("<table>\n<thead>\n\t<tr>\n"); //NON-NLS
630  for (String title : titles) {
631  ele.append("\t\t<th>").append(title).append("</th>\n"); //NON-NLS
632  }
633  ele.append("\t</tr>\n</thead>\n"); //NON-NLS
634 
635  try {
636  out.write(ele.toString());
637  } catch (IOException ex) {
638  logger.log(Level.SEVERE, "Failed to write table start: {0}", ex); //NON-NLS
639  }
640  }
641 
648  public void startContentTagsTable(List<String> columnHeaders) {
649  StringBuilder htmlOutput = new StringBuilder();
650  htmlOutput.append("<table>\n<thead>\n\t<tr>\n"); //NON-NLS
651 
652  // Add the specified columns.
653  for (String columnHeader : columnHeaders) {
654  htmlOutput.append("\t\t<th>").append(columnHeader).append("</th>\n"); //NON-NLS
655  }
656 
657  // Add a column for a hyperlink to a local copy of the tagged content.
658  htmlOutput.append("\t\t<th></th>\n"); //NON-NLS
659 
660  htmlOutput.append("\t</tr>\n</thead>\n"); //NON-NLS
661 
662  try {
663  out.write(htmlOutput.toString());
664  } catch (IOException ex) {
665  logger.log(Level.SEVERE, "Failed to write table start: {0}", ex); //NON-NLS
666  }
667  }
668 
672  @Override
673  public void endTable() {
674  try {
675  out.write("</table>\n"); //NON-NLS
676  } catch (IOException ex) {
677  logger.log(Level.SEVERE, "Failed to write end of table: {0}", ex); //NON-NLS
678  }
679  }
680 
687  @Override
688  public void addRow(List<String> row) {
689  addRow(row, true);
690  }
691 
699  private void addRow(List<String> row, boolean escapeText) {
700  StringBuilder builder = new StringBuilder();
701  builder.append("\t<tr>\n"); //NON-NLS
702  for (String cell : row) {
703  String cellText = escapeText ? EscapeUtil.escapeHtml(cell) : cell;
704  builder.append("\t\t<td>").append(cellText).append("</td>\n"); //NON-NLS
705  }
706  builder.append("\t</tr>\n"); //NON-NLS
707  rowCount++;
708 
709  try {
710  out.write(builder.toString());
711  } catch (IOException ex) {
712  logger.log(Level.SEVERE, "Failed to write row to out.", ex); //NON-NLS
713  } catch (NullPointerException ex) {
714  logger.log(Level.SEVERE, "Output writer is null. Page was not initialized before writing.", ex); //NON-NLS
715  }
716  }
717 
725  public void addRowWithTaggedContentHyperlink(List<String> row, ContentTag contentTag) {
726  Content content = contentTag.getContent();
727  if (content instanceof AbstractFile == false) {
728  addRow(row, true);
729  return;
730  }
731  AbstractFile file = (AbstractFile) content;
732  // Add the hyperlink to the row. A column header for it was created in startTable().
733  StringBuilder localFileLink = new StringBuilder();
734  // Don't make a local copy of the file if it is a directory or unallocated space.
735  if (!(file.isDir()
736  || file.getType() == TSK_DB_FILES_TYPE_ENUM.UNALLOC_BLOCKS
737  || file.getType() == TSK_DB_FILES_TYPE_ENUM.UNUSED_BLOCKS)) {
738  localFileLink.append("<a href=\""); //NON-NLS
739  // save it in a folder based on the tag name
740  String localFilePath = saveContent(file, contentTag.getName().getDisplayName());
741  localFileLink.append(localFilePath);
742  localFileLink.append("\" target=\"_top\">");
743  }
744 
745  StringBuilder builder = new StringBuilder();
746  builder.append("\t<tr>\n"); //NON-NLS
747  int positionCounter = 0;
748  for (String cell : row) {
749  // position-dependent code used to format this report. Not great, but understandable for formatting.
750  switch (positionCounter) {
751  case 1:
752  // Convert the file name to a hyperlink and left-align it
753  builder.append("\t\t<td class=\"left_align_cell\">").append(localFileLink.toString()).append(cell).append("</a></td>\n"); //NON-NLS
754  break;
755  case 7:
756  // Right-align the bytes column.
757  builder.append("\t\t<td class=\"right_align_cell\">").append(cell).append("</td>\n"); //NON-NLS
758  break;
759  default:
760  // Regular case, not a file name nor a byte count
761  builder.append("\t\t<td>").append(cell).append("</td>\n"); //NON-NLS
762  break;
763  }
764  ++positionCounter;
765  }
766  builder.append("\t</tr>\n"); //NON-NLS
767  rowCount++;
768 
769  try {
770  out.write(builder.toString());
771  } catch (IOException ex) {
772  logger.log(Level.SEVERE, "Failed to write row to out.", ex); //NON-NLS
773  } catch (NullPointerException ex) {
774  logger.log(Level.SEVERE, "Output writer is null. Page was not initialized before writing.", ex); //NON-NLS
775  }
776  }
777 
784  private List<ImageTagRegion> getTaggedRegions(List<ContentTag> contentTags) {
785  ArrayList<ImageTagRegion> tagRegions = new ArrayList<>();
786  contentTags.forEach((contentTag) -> {
787  try {
789  .getTag(contentTag, ImageTagRegion.class);
790  if (contentViewerTag != null) {
791  tagRegions.add(contentViewerTag.getDetails());
792  }
793  } catch (TskCoreException | NoCurrentCaseException ex) {
794  logger.log(Level.WARNING, "Could not get content viewer tag "
795  + "from case db for content_tag with id %d", contentTag.getId());
796  }
797  });
798  return tagRegions;
799  }
800 
806  public void addThumbnailRows(Set<Content> images) {
807  List<String> currentRow = new ArrayList<>();
808  int totalCount = 0;
809  int pages = 1;
810  for (Content content : images) {
811  if (currentRow.size() == THUMBNAIL_COLUMNS) {
812  addRow(currentRow, false);
813  currentRow.clear();
814  }
815 
816  if (totalCount == MAX_THUMBS_PER_PAGE) {
817  // manually set the row count so the count of items shown in the
818  // navigation page reflects the number of thumbnails instead of
819  // the number of rows.
820  rowCount = totalCount;
821  totalCount = 0;
822  pages++;
823  endTable();
824  endDataType();
825  startDataType(NbBundle.getMessage(this.getClass(), "ReportHTML.addThumbRows.dataType.title", pages),
826  NbBundle.getMessage(this.getClass(), "ReportHTML.addThumbRows.dataType.msg"));
827  List<String> emptyHeaders = new ArrayList<>();
828  for (int i = 0; i < THUMBNAIL_COLUMNS; i++) {
829  emptyHeaders.add("");
830  }
831  startTable(emptyHeaders);
832  }
833 
834  if (failsContentCheck(content)) {
835  continue;
836  }
837 
838  AbstractFile file = (AbstractFile) content;
839  List<ContentTag> contentTags = new ArrayList<>();
840 
841  String thumbnailPath = null;
842  String imageWithTagsFullPath = null;
843  try {
844  //Get content tags and all image tags
845  contentTags = Case.getCurrentCase().getServices()
847  List<ImageTagRegion> imageTags = getTaggedRegions(contentTags);
848 
849  if (!imageTags.isEmpty()) {
850  //Write the tags to the fullsize and thumbnail images
851  BufferedImage fullImageWithTags = ImageTagsUtil.getImageWithTags(file, imageTags);
852 
853  BufferedImage thumbnailWithTags = ImageTagsUtil.getThumbnailWithTags(file,
854  imageTags, ImageTagsUtil.IconSize.MEDIUM);
855 
856  String fileName = org.sleuthkit.autopsy.coreutils.FileUtil.escapeFileName(file.getName());
857 
858  //Create paths in report to write tagged images
859  File thumbnailImageWithTagsFile = Paths.get(thumbsPath, FilenameUtils.removeExtension(fileName) + ".png").toFile();
860  String fullImageWithTagsPath = makeCustomUniqueFilePath(file, "thumbs_fullsize");
861  fullImageWithTagsPath = FilenameUtils.removeExtension(fullImageWithTagsPath) + ".png";
862  File fullImageWithTagsFile = Paths.get(fullImageWithTagsPath).toFile();
863 
864  //Save images
865  ImageIO.write(thumbnailWithTags, "png", thumbnailImageWithTagsFile);
866  ImageIO.write(fullImageWithTags, "png", fullImageWithTagsFile);
867 
868  thumbnailPath = THUMBS_REL_PATH + thumbnailImageWithTagsFile.getName();
869  //Relative path
870  imageWithTagsFullPath = fullImageWithTagsPath.substring(subPath.length());
871  }
872  } catch (TskCoreException ex) {
873  logger.log(Level.WARNING, "Could not get tags for file.", ex); //NON-NLS
874  } catch (IOException | InterruptedException | ExecutionException ex) {
875  logger.log(Level.WARNING, "Could make marked up thumbnail.", ex); //NON-NLS
876  }
877 
878  // save copies of the orginal image and thumbnail image
879  if (thumbnailPath == null) {
880  thumbnailPath = prepareThumbnail(file);
881  }
882 
883  if (thumbnailPath == null) {
884  continue;
885  }
886  String contentPath = saveContent(file, "original"); //NON-NLS
887  String nameInImage;
888  try {
889  nameInImage = file.getUniquePath();
890  } catch (TskCoreException ex) {
891  nameInImage = file.getName();
892  }
893 
894  StringBuilder linkToThumbnail = new StringBuilder();
895  linkToThumbnail.append("<div id='thumbnail_link'><a href=\"")
896  .append((imageWithTagsFullPath != null) ? imageWithTagsFullPath : contentPath)
897  .append("\" target=\"_top\"><img src=\"")
898  .append(thumbnailPath).append("\" title=\"").append(nameInImage).append("\"/></a><br>") //NON-NLS
899  .append(file.getName()).append("<br>"); //NON-NLS
900  if (imageWithTagsFullPath != null) {
901  linkToThumbnail.append("<a href=\"").append(contentPath).append("\" target=\"_top\">View Original</a><br>");
902  }
903 
904  if (!contentTags.isEmpty()) {
905  linkToThumbnail.append(NbBundle.getMessage(this.getClass(), "ReportHTML.thumbLink.tags"));
906  }
907  for (int i = 0; i < contentTags.size(); i++) {
908  ContentTag tag = contentTags.get(i);
909  String notableString = tag.getName().getKnownStatus() == TskData.FileKnown.BAD ? TagsManager.getNotableTagLabel() : "";
910  linkToThumbnail.append(tag.getName().getDisplayName()).append(notableString);
911  if (i != contentTags.size() - 1) {
912  linkToThumbnail.append(", ");
913  }
914  }
915 
916  linkToThumbnail.append("</div>");
917  currentRow.add(linkToThumbnail.toString());
918 
919  totalCount++;
920  }
921 
922  if (currentRow.isEmpty() == false) {
923  int extraCells = THUMBNAIL_COLUMNS - currentRow.size();
924  for (int i = 0; i < extraCells; i++) {
925  // Finish out the row.
926  currentRow.add("");
927  }
928  addRow(currentRow, false);
929  }
930 
931  // manually set rowCount to be the total number of images.
932  rowCount = totalCount;
933  }
934 
935  private boolean failsContentCheck(Content c) {
936  if (c instanceof AbstractFile == false) {
937  return true;
938  }
939  AbstractFile file = (AbstractFile) c;
940  return file.isDir()
941  || file.getType() == TSK_DB_FILES_TYPE_ENUM.UNALLOC_BLOCKS
942  || file.getType() == TSK_DB_FILES_TYPE_ENUM.UNUSED_BLOCKS;
943  }
944 
945  private String makeCustomUniqueFilePath(AbstractFile file, String dirName) {
946  // clean up the dir name passed in
947  String dirName2 = org.sleuthkit.autopsy.coreutils.FileUtil.escapeFileName(dirName);
948 
949  // Make a folder for the local file with the same tagName as the tag.
950  StringBuilder localFilePath = new StringBuilder(); // full path
951 
952  localFilePath.append(subPath);
953  localFilePath.append(dirName2);
954  File localFileFolder = new File(localFilePath.toString());
955  if (!localFileFolder.exists()) {
956  localFileFolder.mkdirs();
957  }
958 
959  /*
960  * Construct a file tagName for the local file that incorporates the
961  * file ID to ensure uniqueness.
962  *
963  * Note: File name is normalized to account for possible attribute name
964  * which will be separated by a ':' character.
965  */
966  String fileName = org.sleuthkit.autopsy.coreutils.FileUtil.escapeFileName(file.getName());
967  String objectIdSuffix = "_" + file.getId();
968  int lastDotIndex = fileName.lastIndexOf(".");
969  if (lastDotIndex != -1 && lastDotIndex != 0) {
970  // The file tagName has a conventional extension. Insert the object id before the '.' of the extension.
971  fileName = fileName.substring(0, lastDotIndex) + objectIdSuffix + fileName.substring(lastDotIndex, fileName.length());
972  } else {
973  // The file has no extension or the only '.' in the file is an initial '.', as in a hidden file.
974  // Add the object id to the end of the file tagName.
975  fileName += objectIdSuffix;
976  }
977  localFilePath.append(File.separator);
978  localFilePath.append(fileName);
979 
980  return localFilePath.toString();
981  }
982 
992  public String saveContent(AbstractFile file, String dirName) {
993 
994  String localFilePath = makeCustomUniqueFilePath(file, dirName);
995 
996  // If the local file doesn't already exist, create it now.
997  // The existence check is necessary because it is possible to apply multiple tags with the same tagName to a file.
998  File localFile = new File(localFilePath);
999  if (!localFile.exists()) {
1000  ExtractFscContentVisitor.extract(file, localFile, null, null);
1001  }
1002 
1003  // get the relative path
1004  return localFilePath.substring(subPath.length());
1005  }
1006 
1014  @Override
1015  public String dateToString(long date) {
1016  SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
1017  return sdf.format(new java.util.Date(date * 1000));
1018  }
1019 
1020  @Override
1021  public String getRelativeFilePath() {
1022  return "report.html"; //NON-NLS
1023  }
1024 
1025  @Override
1026  public String getName() {
1027  return NbBundle.getMessage(this.getClass(), "ReportHTML.getName.text");
1028  }
1029 
1030  @Override
1031  public String getDescription() {
1032  return NbBundle.getMessage(this.getClass(), "ReportHTML.getDesc.text");
1033  }
1034 
1038  private void writeCss() {
1039  Writer cssOut = null;
1040  try {
1041  cssOut = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(subPath + "index.css"), "UTF-8")); //NON-NLS NON-NLS
1042  String css = "body {margin: 0px; padding: 0px; background: #FFFFFF; font: 13px/20px Arial, Helvetica, sans-serif; color: #535353;}\n"
1043  + //NON-NLS
1044  "#content {padding: 30px;}\n"
1045  + //NON-NLS
1046  "#header {width:100%; padding: 10px; line-height: 25px; background: #07A; color: #FFF; font-size: 20px;}\n"
1047  + //NON-NLS
1048  "#pageHeaderFooter {width: 100%; padding: 10px; line-height: 25px; text-align: center; font-size: 20px;}\n"
1049  + //NON-NLS
1050  "h1 {font-size: 20px; font-weight: normal; color: #07A; padding: 0 0 7px 0; margin-top: 25px; border-bottom: 1px solid #D6D6D6;}\n"
1051  + //NON-NLS
1052  "h2 {font-size: 20px; font-weight: bolder; color: #07A;}\n"
1053  + //NON-NLS
1054  "h3 {font-size: 16px; color: #07A;}\n"
1055  + //NON-NLS
1056  "h4 {background: #07A; color: #FFF; font-size: 16px; margin: 0 0 0 25px; padding: 0; padding-left: 15px;}\n"
1057  + //NON-NLS
1058  "ul.nav {list-style-type: none; line-height: 35px; padding: 0px; margin-left: 15px;}\n"
1059  + //NON-NLS
1060  "ul li a {font-size: 14px; color: #444; text-decoration: none; padding-left: 25px;}\n"
1061  + //NON-NLS
1062  "ul li a:hover {text-decoration: underline;}\n"
1063  + //NON-NLS
1064  "p {margin: 0 0 20px 0;}\n"
1065  + //NON-NLS
1066  "table {white-space:nowrap; min-width: 700px; padding: 2; margin: 0; border-collapse: collapse; border-bottom: 2px solid #e5e5e5;}\n"
1067  + //NON-NLS
1068  ".keyword_list table {margin: 0 0 25px 25px; border-bottom: 2px solid #dedede;}\n"
1069  + //NON-NLS
1070  "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"
1071  + //NON-NLS
1072  "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"
1073  + //NON-NLS
1074  "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"
1075  + //NON-NLS
1076  "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; vertical-align: text-top;}\n"
1077  + //NON-NLS
1078  "table tr:nth-child(even) td {background: #f3f3f3;}\n"
1079  + //NON-NLS
1080  "div#thumbnail_link {max-width: 200px; white-space: pre-wrap; white-space: -moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; word-wrap: break-word;}";
1081  cssOut.write(css);
1082  } catch (FileNotFoundException ex) {
1083  logger.log(Level.SEVERE, "Could not find index.css file to write to.", ex); //NON-NLS
1084  } catch (UnsupportedEncodingException ex) {
1085  logger.log(Level.SEVERE, "Did not recognize encoding when writing index.css.", ex); //NON-NLS
1086  } catch (IOException ex) {
1087  logger.log(Level.SEVERE, "Error creating Writer for index.css.", ex); //NON-NLS
1088  } finally {
1089  try {
1090  if (cssOut != null) {
1091  cssOut.flush();
1092  cssOut.close();
1093  }
1094  } catch (IOException ex) {
1095  }
1096  }
1097  }
1098 
1102  private void writeIndex() {
1103  Writer indexOut = null;
1104  String indexFilePath = path + "report.html"; //NON-NLS
1105  Case openCase;
1106  try {
1107  openCase = Case.getCurrentCaseThrows();
1108  } catch (NoCurrentCaseException ex) {
1109  logger.log(Level.SEVERE, "Exception while getting open case.", ex); //NON-NLS
1110  return;
1111  }
1112  try {
1113  indexOut = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(indexFilePath), "UTF-8")); //NON-NLS
1114  StringBuilder index = new StringBuilder();
1115  final String reportTitle = reportBranding.getReportTitle();
1116  String iconPath = reportBranding.getAgencyLogoPath();
1117  if (iconPath == null) {
1118  // use default Autopsy icon if custom icon is not set
1119  iconPath = HTML_SUBDIR + "favicon.ico";
1120  } else {
1121  iconPath = Paths.get(reportBranding.getAgencyLogoPath()).getFileName().toString(); //ref to writeNav() for agency_logo
1122  }
1123  index.append("<head>\n<title>").append(reportTitle).append(" ").append(
1124  NbBundle.getMessage(this.getClass(), "ReportHTML.writeIndex.title", currentCase.getDisplayName())).append(
1125  "</title>\n"); //NON-NLS
1126  index.append("<link rel=\"icon\" type=\"image/ico\" href=\"")
1127  .append(iconPath).append("\" />\n"); //NON-NLS
1128  index.append("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\n"); //NON-NLS
1129  index.append("</head>\n"); //NON-NLS
1130  index.append("<frameset cols=\"350px,*\">\n"); //NON-NLS
1131  index.append("<frame src=\"" + HTML_SUBDIR).append(File.separator).append("nav.html\" name=\"nav\">\n"); //NON-NLS
1132  index.append("<frame src=\"" + HTML_SUBDIR).append(File.separator).append("summary.html\" name=\"content\">\n"); //NON-NLS
1133  index.append("<noframes>").append(NbBundle.getMessage(this.getClass(), "ReportHTML.writeIndex.noFrames.msg")).append("<br />\n"); //NON-NLS
1134  index.append(NbBundle.getMessage(this.getClass(), "ReportHTML.writeIndex.noFrames.seeNav")).append("<br />\n"); //NON-NLS
1135  index.append(NbBundle.getMessage(this.getClass(), "ReportHTML.writeIndex.seeSum")).append("</noframes>\n"); //NON-NLS
1136  index.append("</frameset>\n"); //NON-NLS
1137  index.append("</html>"); //NON-NLS
1138  indexOut.write(index.toString());
1139  openCase.addReport(indexFilePath, NbBundle.getMessage(this.getClass(),
1140  "ReportHTML.writeIndex.srcModuleName.text"), "");
1141  } catch (IOException ex) {
1142  logger.log(Level.SEVERE, "Error creating Writer for report.html: {0}", ex); //NON-NLS
1143  } catch (TskCoreException ex) {
1144  String errorMessage = String.format("Error adding %s to case as a report", indexFilePath); //NON-NLS
1145  logger.log(Level.SEVERE, errorMessage, ex);
1146  } finally {
1147  try {
1148  if (indexOut != null) {
1149  indexOut.flush();
1150  indexOut.close();
1151  }
1152  } catch (IOException ex) {
1153  }
1154  }
1155  }
1156 
1160  private void writeNav() {
1161  Writer navOut = null;
1162  try {
1163  navOut = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(subPath + "nav.html"), "UTF-8")); //NON-NLS
1164  StringBuilder nav = new StringBuilder();
1165  nav.append("<html>\n<head>\n\t<title>").append( //NON-NLS
1166  NbBundle.getMessage(this.getClass(), "ReportHTML.writeNav.title"))
1167  .append("</title>\n\t<link rel=\"stylesheet\" type=\"text/css\" href=\"index.css\" />\n"); //NON-NLS
1168  nav.append("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\n</head>\n<body>\n"); //NON-NLS
1169  nav.append("<div id=\"content\">\n<h1>").append( //NON-NLS
1170  NbBundle.getMessage(this.getClass(), "ReportHTML.writeNav.h1")).append("</h1>\n"); //NON-NLS
1171  nav.append("<ul class=\"nav\">\n"); //NON-NLS
1172  nav.append("<li style=\"background: url(summary.png) left center no-repeat;\"><a href=\"summary.html\" target=\"content\">") //NON-NLS
1173  .append(NbBundle.getMessage(this.getClass(), "ReportHTML.writeNav.summary")).append("</a></li>\n"); //NON-NLS
1174 
1175  for (String dataType : dataTypes.keySet()) {
1176  String dataTypeEsc = dataTypeToFileName(dataType);
1177  String iconFileName = useDataTypeIcon(dataType);
1178  nav.append("<li style=\"background: url('").append(iconFileName) //NON-NLS
1179  .append("') left center no-repeat;\"><a href=\"") //NON-NLS
1180  .append(dataTypeEsc).append(".html\" target=\"content\">") //NON-NLS
1181  .append(dataType).append(" (").append(dataTypes.get(dataType))
1182  .append(")</a></li>\n"); //NON-NLS
1183  }
1184  nav.append("</ul>\n"); //NON-NLS
1185  nav.append("</div>\n</body>\n</html>"); //NON-NLS
1186  navOut.write(nav.toString());
1187  } catch (IOException ex) {
1188  logger.log(Level.SEVERE, "Failed to write end of report navigation menu: {0}", ex); //NON-NLS
1189  } finally {
1190  if (navOut != null) {
1191  try {
1192  navOut.flush();
1193  navOut.close();
1194  } catch (IOException ex) {
1195  logger.log(Level.WARNING, "Could not close navigation out writer."); //NON-NLS
1196  }
1197  }
1198  }
1199 
1200  InputStream in = null;
1201  OutputStream output = null;
1202  try {
1203 
1204  //pull generator and agency logo from branding, and the remaining resources from the core jar
1205  String generatorLogoPath = reportBranding.getGeneratorLogoPath();
1206  if (generatorLogoPath != null && !generatorLogoPath.isEmpty()) {
1207  File from = new File(generatorLogoPath);
1208  File to = new File(subPath);
1209  FileUtil.copyFile(FileUtil.toFileObject(from), FileUtil.toFileObject(to), "generator_logo"); //NON-NLS
1210  }
1211 
1212  String agencyLogoPath = reportBranding.getAgencyLogoPath();
1213  if (agencyLogoPath != null && !agencyLogoPath.isEmpty()) {
1214  Path destinationPath = Paths.get(subPath);
1215  Files.copy(Files.newInputStream(Paths.get(agencyLogoPath)), destinationPath.resolve(Paths.get(agencyLogoPath).getFileName())); //NON-NLS
1216  }
1217 
1218  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/report/images/favicon.ico"); //NON-NLS
1219  output = new FileOutputStream(new File(subPath + "favicon.ico"));
1220  FileUtil.copy(in, output);
1221  in.close();
1222  output.close();
1223 
1224  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/report/images/summary.png"); //NON-NLS
1225  output = new FileOutputStream(new File(subPath + "summary.png"));
1226  FileUtil.copy(in, output);
1227  in.close();
1228  output.close();
1229 
1230  } catch (IOException ex) {
1231  logger.log(Level.SEVERE, "Failed to extract images for HTML report.", ex); //NON-NLS
1232  } finally {
1233  if (output != null) {
1234  try {
1235  output.flush();
1236  output.close();
1237  } catch (IOException ex) {
1238  }
1239  }
1240  if (in != null) {
1241  try {
1242  in.close();
1243  } catch (IOException ex) {
1244  }
1245  }
1246  }
1247  }
1248 
1252  private void writeSummary() {
1253  Writer output = null;
1254  try {
1255  output = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(subPath + "summary.html"), "UTF-8")); //NON-NLS
1256  StringBuilder head = new StringBuilder();
1257  head.append("<html>\n<head>\n<title>").append( //NON-NLS
1258  NbBundle.getMessage(this.getClass(), "ReportHTML.writeSum.title")).append("</title>\n"); //NON-NLS
1259  head.append("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\n"); //NON-NLS
1260  head.append("<style type=\"text/css\">\n"); //NON-NLS
1261  head.append("#pageHeaderFooter {width: 100%; padding: 10px; line-height: 25px; text-align: center; font-size: 20px;}\n"); //NON-NLS
1262  head.append("body { padding: 0px; margin: 0px; font: 13px/20px Arial, Helvetica, sans-serif; color: #535353; }\n"); //NON-NLS
1263  head.append("#wrapper { width: 90%; margin: 0px auto; margin-top: 35px; }\n"); //NON-NLS
1264  head.append("h1 { color: #07A; font-size: 36px; line-height: 42px; font-weight: normal; margin: 0px; border-bottom: 1px solid #81B9DB; }\n"); //NON-NLS
1265  head.append("h1 span { color: #F00; display: block; font-size: 16px; font-weight: bold; line-height: 22px;}\n"); //NON-NLS
1266  head.append("h2 { padding: 0 0 3px 0; margin: 0px; color: #07A; font-weight: normal; border-bottom: 1px dotted #81B9DB; }\n"); //NON-NLS
1267  head.append("h3 { padding: 5 0 3px 0; margin: 0px; color: #07A; font-weight: normal; }\n");
1268  head.append("table td { padding: 5px 25px 5px 0px; vertical-align:top;}\n"); //NON-NLS
1269  head.append("p.subheadding { padding: 0px; margin: 0px; font-size: 11px; color: #B5B5B5; }\n"); //NON-NLS
1270  head.append(".title { width: 660px; margin-bottom: 50px; }\n"); //NON-NLS
1271  head.append(".left { float: left; width: 250px; margin-top: 20px; text-align: center; }\n"); //NON-NLS
1272  head.append(".left img { max-width: 250px; max-height: 250px; min-width: 200px; min-height: 200px; }\n"); //NON-NLS
1273  head.append(".right { float: right; width: 385px; margin-top: 25px; font-size: 14px; }\n"); //NON-NLS
1274  head.append(".clear { clear: both; }\n"); //NON-NLS
1275  head.append(".info { padding: 10px 0;}\n");
1276  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
1277  head.append(".info table { margin: 10px 25px 10px 25px; }\n"); //NON-NLS
1278  head.append("ul {padding: 0;margin: 0;list-style-type: none;}");
1279  head.append("li {padding-bottom: 5px;}");
1280  head.append("</style>\n"); //NON-NLS
1281  head.append("</head>\n<body>\n"); //NON-NLS
1282  output.write(head.toString());
1283 
1284  DateFormat datetimeFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
1285  Date date = new Date();
1286  String datetime = datetimeFormat.format(date);
1287 
1288  StringBuilder summary = new StringBuilder();
1289  boolean running = false;
1291  running = true;
1292  }
1293  SleuthkitCase skCase = Case.getCurrentCaseThrows().getSleuthkitCase();
1294  List<IngestJobInfo> ingestJobs = skCase.getIngestJobs();
1295  final String reportTitle = reportBranding.getReportTitle();
1296  final String reportFooter = reportBranding.getReportFooter();
1297  final boolean generatorLogoSet = reportBranding.getGeneratorLogoPath() != null && !reportBranding.getGeneratorLogoPath().isEmpty();
1298 
1299  summary.append("<div id=\"wrapper\">\n"); //NON-NLS
1300  summary.append(writePageHeader());
1301  summary.append("<h1>").append(reportTitle) //NON-NLS
1302  .append(running ? NbBundle.getMessage(this.getClass(), "ReportHTML.writeSum.warningMsg") : "")
1303  .append("</h1>\n"); //NON-NLS
1304  summary.append("<p class=\"subheadding\">").append( //NON-NLS
1305  NbBundle.getMessage(this.getClass(), "ReportHTML.writeSum.reportGenOn.text", datetime)).append("</p>\n"); //NON-NLS
1306  summary.append("<div class=\"title\">\n"); //NON-NLS
1307  summary.append(writeSummaryCaseDetails());
1308  summary.append(writeSummaryImageInfo());
1309  summary.append(writeSummarySoftwareInfo(skCase, ingestJobs));
1310  summary.append(writeSummaryIngestHistoryInfo(skCase, ingestJobs));
1311  if (generatorLogoSet) {
1312  summary.append("<div class=\"left\">\n"); //NON-NLS
1313  summary.append("<img src=\"generator_logo.png\" />\n"); //NON-NLS
1314  summary.append("</div>\n"); //NON-NLS
1315  }
1316  summary.append("<div class=\"clear\"></div>\n"); //NON-NLS
1317  if (reportFooter != null) {
1318  summary.append("<p class=\"subheadding\">").append(reportFooter).append("</p>\n"); //NON-NLS
1319  }
1320  summary.append("</div>\n"); //NON-NLS
1321  summary.append(writePageFooter());
1322  summary.append("</body></html>"); //NON-NLS
1323  output.write(summary.toString());
1324  } catch (FileNotFoundException ex) {
1325  logger.log(Level.SEVERE, "Could not find summary.html file to write to."); //NON-NLS
1326  } catch (UnsupportedEncodingException ex) {
1327  logger.log(Level.SEVERE, "Did not recognize encoding when writing summary.hmtl."); //NON-NLS
1328  } catch (IOException ex) {
1329  logger.log(Level.SEVERE, "Error creating Writer for summary.html."); //NON-NLS
1330  } catch (NoCurrentCaseException | TskCoreException ex) {
1331  logger.log(Level.WARNING, "Unable to get current sleuthkit Case for the HTML report.");
1332  } finally {
1333  try {
1334  if (output != null) {
1335  output.flush();
1336  output.close();
1337  }
1338  } catch (IOException ex) {
1339  }
1340  }
1341  }
1342 
1343  @Messages({
1344  "ReportHTML.writeSum.case=Case:",
1345  "ReportHTML.writeSum.caseNumber=Case Number:",
1346  "ReportHTML.writeSum.caseNumImages=Number of Images:",
1347  "ReportHTML.writeSum.caseNotes=Notes:",
1348  "ReportHTML.writeSum.examiner=Examiner:"
1349  })
1355  private StringBuilder writeSummaryCaseDetails() {
1356  StringBuilder summary = new StringBuilder();
1357 
1358  final boolean agencyLogoSet = reportBranding.getAgencyLogoPath() != null && !reportBranding.getAgencyLogoPath().isEmpty();
1359 
1360  // Case
1361  String caseName = currentCase.getDisplayName();
1362  String caseNumber = currentCase.getNumber();
1363  int imagecount;
1364  try {
1365  imagecount = currentCase.getDataSources().size();
1366  } catch (TskCoreException ex) {
1367  imagecount = 0;
1368  }
1369  String caseNotes = currentCase.getCaseNotes();
1370 
1371  // Examiner
1372  String examinerName = currentCase.getExaminer();
1373 
1374  // Start the layout.
1375  summary.append("<div class=\"title\">\n"); //NON-NLS
1376  if (agencyLogoSet) {
1377  summary.append("<div class=\"left\">\n"); //NON-NLS
1378  summary.append("<img src=\"");
1379  summary.append(Paths.get(reportBranding.getAgencyLogoPath()).getFileName().toString());
1380  summary.append("\" />\n"); //NON-NLS
1381  summary.append("</div>\n"); //NON-NLS
1382  }
1383  final String align = agencyLogoSet ? "right" : "left"; //NON-NLS NON-NLS
1384  summary.append("<div class=\"").append(align).append("\">\n"); //NON-NLS
1385  summary.append("<table>\n"); //NON-NLS
1386 
1387  // Case details
1388  summary.append("<tr><td>").append(Bundle.ReportHTML_writeSum_case()).append("</td><td>") //NON-NLS
1389  .append(formatHtmlString(caseName)).append("</td></tr>\n"); //NON-NLS
1390 
1391  if (!caseNumber.isEmpty()) {
1392  summary.append("<tr><td>").append(Bundle.ReportHTML_writeSum_caseNumber()).append("</td><td>") //NON-NLS
1393  .append(formatHtmlString(caseNumber)).append("</td></tr>\n"); //NON-NLS
1394  }
1395 
1396  summary.append("<tr><td>").append(Bundle.ReportHTML_writeSum_caseNumImages()).append("</td><td>") //NON-NLS
1397  .append(imagecount).append("</td></tr>\n"); //NON-NLS
1398 
1399  if (!caseNotes.isEmpty()) {
1400  summary.append("<tr><td>").append(Bundle.ReportHTML_writeSum_caseNotes()).append("</td><td>") //NON-NLS
1401  .append(formatHtmlString(caseNotes)).append("</td></tr>\n"); //NON-NLS
1402  }
1403 
1404  // Examiner details
1405  if (!examinerName.isEmpty()) {
1406  summary.append("<tr><td>").append(Bundle.ReportHTML_writeSum_examiner()).append("</td><td>") //NON-NLS
1407  .append(formatHtmlString(examinerName)).append("</td></tr>\n"); //NON-NLS
1408  }
1409 
1410  // End the layout.
1411  summary.append("</table>\n"); //NON-NLS
1412  summary.append("</div>\n"); //NON-NLS
1413  summary.append("<div class=\"clear\"></div>\n"); //NON-NLS
1414  summary.append("</div>\n"); //NON-NLS
1415  return summary;
1416  }
1417 
1423  private StringBuilder writeSummaryImageInfo() {
1424  StringBuilder summary = new StringBuilder();
1425  summary.append(NbBundle.getMessage(this.getClass(), "ReportHTML.writeSum.imageInfoHeading"));
1426  summary.append("<div class=\"info\">\n"); //NON-NLS
1427  try {
1428  for (Content c : currentCase.getDataSources()) {
1429  summary.append("<p>").append(c.getName()).append("</p>\n"); //NON-NLS
1430  if (c instanceof Image) {
1431  Image img = (Image) c;
1432 
1433  summary.append("<table>\n"); //NON-NLS
1434  summary.append("<tr><td>").append( //NON-NLS
1435  NbBundle.getMessage(this.getClass(), "ReportHTML.writeSum.timezone"))
1436  .append("</td><td>").append(img.getTimeZone()).append("</td></tr>\n"); //NON-NLS
1437  for (String imgPath : img.getPaths()) {
1438  summary.append("<tr><td>").append( //NON-NLS
1439  NbBundle.getMessage(this.getClass(), "ReportHTML.writeSum.path"))
1440  .append("</td><td>").append(imgPath).append("</td></tr>\n"); //NON-NLS
1441  }
1442  summary.append("</table>\n"); //NON-NLS
1443  }
1444  }
1445  } catch (TskCoreException ex) {
1446  logger.log(Level.WARNING, "Unable to get image information for the HTML report."); //NON-NLS
1447  }
1448  summary.append("</div>\n"); //NON-NLS
1449  return summary;
1450  }
1451 
1457  private StringBuilder writeSummarySoftwareInfo(SleuthkitCase skCase, List<IngestJobInfo> ingestJobs) {
1458  StringBuilder summary = new StringBuilder();
1459  summary.append(NbBundle.getMessage(this.getClass(), "ReportHTML.writeSum.softwareInfoHeading"));
1460  summary.append("<div class=\"info\">\n");
1461  summary.append("<table>\n");
1462  summary.append("<tr><td>").append(NbBundle.getMessage(this.getClass(), "ReportHTML.writeSum.autopsyVersion"))
1463  .append("</td><td>").append(Version.getVersion()).append("</td></tr>\n");
1464  Map<Long, IngestModuleInfo> moduleInfoHashMap = new HashMap<>();
1465  for (IngestJobInfo ingestJob : ingestJobs) {
1466  List<IngestModuleInfo> ingestModules = ingestJob.getIngestModuleInfo();
1467  for (IngestModuleInfo ingestModule : ingestModules) {
1468  if (!moduleInfoHashMap.containsKey(ingestModule.getIngestModuleId())) {
1469  moduleInfoHashMap.put(ingestModule.getIngestModuleId(), ingestModule);
1470  }
1471  }
1472  }
1473  TreeMap<String, String> modules = new TreeMap<>();
1474  for (IngestModuleInfo moduleinfo : moduleInfoHashMap.values()) {
1475  modules.put(moduleinfo.getDisplayName(), moduleinfo.getVersion());
1476  }
1477  for (Map.Entry<String, String> module : modules.entrySet()) {
1478  summary.append("<tr><td>").append(module.getKey()).append(" Module:")
1479  .append("</td><td>").append(module.getValue()).append("</td></tr>\n");
1480  }
1481  summary.append("</table>\n");
1482  summary.append("</div>\n");
1483  summary.append("<div class=\"clear\"></div>\n"); //NON-NLS
1484  return summary;
1485  }
1486 
1492  private StringBuilder writeSummaryIngestHistoryInfo(SleuthkitCase skCase, List<IngestJobInfo> ingestJobs) {
1493  StringBuilder summary = new StringBuilder();
1494  try {
1495  summary.append(NbBundle.getMessage(this.getClass(), "ReportHTML.writeSum.ingestHistoryHeading"));
1496  summary.append("<div class=\"info\">\n");
1497  int jobnumber = 1;
1498 
1499  for (IngestJobInfo ingestJob : ingestJobs) {
1500  summary.append("<h3>Job ").append(jobnumber).append(":</h3>\n");
1501  summary.append("<table>\n");
1502  summary.append("<tr><td>").append("Data Source:")
1503  .append("</td><td>").append(skCase.getContentById(ingestJob.getObjectId()).getName()).append("</td></tr>\n");
1504  summary.append("<tr><td>").append("Status:")
1505  .append("</td><td>").append(ingestJob.getStatus()).append("</td></tr>\n");
1506  summary.append("<tr><td>").append(NbBundle.getMessage(this.getClass(), "ReportHTML.writeSum.modulesEnabledHeading"))
1507  .append("</td><td>");
1508  List<IngestModuleInfo> ingestModules = ingestJob.getIngestModuleInfo();
1509  summary.append("<ul>\n");
1510  for (IngestModuleInfo ingestModule : ingestModules) {
1511  summary.append("<li>").append(ingestModule.getDisplayName()).append("</li>");
1512  }
1513  summary.append("</ul>\n");
1514  jobnumber++;
1515  summary.append("</td></tr>\n");
1516  summary.append("</table>\n");
1517  }
1518  summary.append("</div>\n");
1519  } catch (TskCoreException ex) {
1520  logger.log(Level.WARNING, "Unable to get ingest jobs for the HTML report.");
1521  }
1522  return summary;
1523  }
1524 
1533  private String prepareThumbnail(AbstractFile file) {
1534  BufferedImage bufferedThumb = ImageUtils.getThumbnail(file, ImageUtils.ICON_SIZE_MEDIUM);
1535 
1536  /*
1537  * File name is normalized to account for possible attribute name which
1538  * will be separated by a ':' character.
1539  */
1540  String fileName = org.sleuthkit.autopsy.coreutils.FileUtil.escapeFileName(file.getName());
1541 
1542  File thumbFile = Paths.get(thumbsPath, fileName + ".png").toFile();
1543  if (bufferedThumb == null) {
1544  return null;
1545  }
1546  try {
1547  ImageIO.write(bufferedThumb, "png", thumbFile);
1548  } catch (IOException ex) {
1549  logger.log(Level.WARNING, "Failed to write thumb file to report directory.", ex); //NON-NLS
1550  return null;
1551  }
1552  if (thumbFile.exists()
1553  == false) {
1554  return null;
1555  }
1556  return THUMBS_REL_PATH
1557  + thumbFile.getName();
1558  }
1559 
1568  private String formatHtmlString(String text) {
1569  String formattedString = StringEscapeUtils.escapeHtml4(text);
1570  return formattedString.replaceAll("(\r\n|\r|\n|\n\r)", "<br>");
1571  }
1572 
1573 }
List< Content > getDataSources()
Definition: Case.java:1438
static String escapeHtml(String toEscape)
Definition: EscapeUtil.java:75
void startContentTagsTable(List< String > columnHeaders)
List< ImageTagRegion > getTaggedRegions(List< ContentTag > contentTags)
static synchronized IngestManager getInstance()
void addRow(List< String > row, boolean escapeText)
void setConfiguration(ReportModuleSettings settings)
List< ContentTag > getContentTagsByContent(Content content)
void addReport(String localPath, String srcModuleName, String reportName)
Definition: Case.java:1630
static BufferedImage getImageWithTags(AbstractFile file, Collection< ImageTagRegion > tagRegions)
static< T > ContentViewerTag< T > getTag(ContentTag contentTag, Class< T > clazz)
static BufferedImage getThumbnailWithTags(AbstractFile file, Collection< ImageTagRegion > tagRegions, IconSize iconSize)
void startDataType(String name, String description)
void addRowWithTaggedContentHyperlink(List< String > row, ContentTag contentTag)
static< T, V > void extract(Content cntnt, java.io.File dest, ProgressHandle progress, SwingWorker< T, V > worker)
static synchronized HTMLReport getDefault()
StringBuilder writeSummaryIngestHistoryInfo(SleuthkitCase skCase, List< IngestJobInfo > ingestJobs)
void close(ProgressIndicator progressIndicator)
Definition: Case.java:2565
static String escapeFileName(String fileName)
Definition: FileUtil.java:169
StringBuilder writeSummarySoftwareInfo(SleuthkitCase skCase, List< IngestJobInfo > ingestJobs)
synchronized static Logger getLogger(String name)
Definition: Logger.java:124
String makeCustomUniqueFilePath(AbstractFile file, String dirName)
String saveContent(AbstractFile file, String dirName)
static BufferedImage getThumbnail(Content content, int iconSize)

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