Autopsy  4.18.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  @SuppressWarnings( "deprecation" )
217  private String useDataTypeIcon(String dataType) {
218  String iconFilePath;
219  String iconFileName;
220  InputStream in;
221  OutputStream output = null;
222 
223  logger.log(Level.INFO, "useDataTypeIcon: dataType = {0}", dataType); //NON-NLS
224 
225  // find the artifact with matching display name
226  BlackboardArtifact.ARTIFACT_TYPE artifactType = null;
227  for (ARTIFACT_TYPE v : ARTIFACT_TYPE.values()) {
228  if (v.getDisplayName().equals(dataType)) {
229  artifactType = v;
230  }
231  }
232 
233  if (null != artifactType) {
234  // set the icon file name
235  iconFileName = dataTypeToFileName(artifactType.getDisplayName()) + ".png"; //NON-NLS
236  iconFilePath = subPath + File.separator + iconFileName;
237 
238  // determine the source image to use
239  switch (artifactType) {
240  case TSK_WEB_BOOKMARK:
241  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/report/images/bookmarks.png"); //NON-NLS
242  break;
243  case TSK_WEB_COOKIE:
244  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/report/images/cookies.png"); //NON-NLS
245  break;
246  case TSK_WEB_HISTORY:
247  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/report/images/history.png"); //NON-NLS
248  break;
249  case TSK_WEB_DOWNLOAD:
250  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/report/images/downloads.png"); //NON-NLS
251  break;
252  case TSK_RECENT_OBJECT:
253  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/report/images/recent.png"); //NON-NLS
254  break;
255  case TSK_INSTALLED_PROG:
256  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/report/images/installed.png"); //NON-NLS
257  break;
258  case TSK_KEYWORD_HIT:
259  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/report/images/keywords.png"); //NON-NLS
260  break;
261  case TSK_HASHSET_HIT:
262  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/report/images/hash.png"); //NON-NLS
263  break;
264  case TSK_DEVICE_ATTACHED:
265  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/report/images/devices.png"); //NON-NLS
266  break;
267  case TSK_WEB_SEARCH_QUERY:
268  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/report/images/search.png"); //NON-NLS
269  break;
270  case TSK_METADATA_EXIF:
271  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/report/images/exif.png"); //NON-NLS
272  break;
273  case TSK_TAG_FILE:
274  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/report/images/userbookmarks.png"); //NON-NLS
275  break;
276  case TSK_TAG_ARTIFACT:
277  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/report/images/userbookmarks.png"); //NON-NLS
278  break;
279  case TSK_SERVICE_ACCOUNT:
280  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/report/images/account-icon-16.png"); //NON-NLS
281  break;
282  case TSK_CONTACT:
283  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/report/images/contact.png"); //NON-NLS
284  break;
285  case TSK_MESSAGE:
286  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/report/images/message.png"); //NON-NLS
287  break;
288  case TSK_CALLLOG:
289  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/report/images/calllog.png"); //NON-NLS
290  break;
291  case TSK_CALENDAR_ENTRY:
292  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/report/images/calendar.png"); //NON-NLS
293  break;
294  case TSK_SPEED_DIAL_ENTRY:
295  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/report/images/speeddialentry.png"); //NON-NLS
296  break;
297  case TSK_BLUETOOTH_PAIRING:
298  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/report/images/bluetooth.png"); //NON-NLS
299  break;
300  case TSK_GPS_BOOKMARK:
301  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/report/images/gpsfav.png"); //NON-NLS
302  break;
303  case TSK_GPS_LAST_KNOWN_LOCATION:
304  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/report/images/gps-lastlocation.png"); //NON-NLS
305  break;
306  case TSK_GPS_SEARCH:
307  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/report/images/gps-search.png"); //NON-NLS
308  break;
309  case TSK_OS_INFO:
310  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/report/images/computer.png"); //NON-NLS
311  break;
312  case TSK_GPS_TRACKPOINT:
313  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/report/images/gps_trackpoint.png"); //NON-NLS
314  break;
315  case TSK_GPS_ROUTE:
316  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/report/images/gps_trackpoint.png"); //NON-NLS
317  break;
318  case TSK_EMAIL_MSG:
319  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/images/mail-icon-16.png"); //NON-NLS
320  break;
321  case TSK_ENCRYPTION_SUSPECTED:
322  case TSK_ENCRYPTION_DETECTED:
323  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/images/encrypted-file.png"); //NON-NLS
324  break;
325  case TSK_EXT_MISMATCH_DETECTED:
326  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/images/mismatch-16.png"); //NON-NLS
327  break;
328  case TSK_INTERESTING_ARTIFACT_HIT:
329  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/images/interesting_item.png"); //NON-NLS
330  break;
331  case TSK_INTERESTING_FILE_HIT:
332  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/images/interesting_item.png"); //NON-NLS
333  break;
334  case TSK_PROG_RUN:
335  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/report/images/installed.png"); //NON-NLS
336  break;
337  case TSK_REMOTE_DRIVE:
338  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/report/images/drive_network.png"); //NON-NLS
339  break;
340  case TSK_OS_ACCOUNT:
341  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/images/os-account.png"); //NON-NLS
342  break;
343  case TSK_OBJECT_DETECTED:
344  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/images/objects.png"); //NON-NLS
345  break;
346  case TSK_WEB_FORM_AUTOFILL:
347  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/images/web-form.png"); //NON-NLS
348  break;
349  case TSK_WEB_CACHE:
350  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/images/cache.png"); //NON-NLS
351  break;
352  case TSK_USER_CONTENT_SUSPECTED:
353  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/images/user-content.png"); //NON-NLS
354  break;
355  case TSK_METADATA:
356  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/images/metadata.png"); //NON-NLS
357  break;
358  case TSK_CLIPBOARD_CONTENT:
359  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/images/clipboard.png"); //NON-NLS
360  break;
361  case TSK_ACCOUNT:
362  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/report/images/accounts.png"); //NON-NLS
363  break;
364  case TSK_WIFI_NETWORK:
365  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/images/network-wifi.png"); //NON-NLS
366  break;
367  case TSK_WIFI_NETWORK_ADAPTER:
368  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/images/network-wifi.png"); //NON-NLS
369  break;
370  case TSK_SIM_ATTACHED:
371  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/images/sim_card.png"); //NON-NLS
372  break;
373  case TSK_BLUETOOTH_ADAPTER:
374  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/images/Bluetooth.png"); //NON-NLS
375  break;
376  case TSK_DEVICE_INFO:
377  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/images/devices.png"); //NON-NLS
378  break;
379  case TSK_VERIFICATION_FAILED:
380  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/images/validationFailed.png"); //NON-NLS
381  break;
382  case TSK_WEB_ACCOUNT_TYPE:
383  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/images/web-account-type.png"); //NON-NLS
384  break;
385  case TSK_WEB_FORM_ADDRESS:
386  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/images/web-form-address.png"); //NON-NLS
387  break;
388  case TSK_GPS_AREA:
389  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/images/gps-area.png"); //NON-NLS
390  break;
391  case TSK_WEB_CATEGORIZATION:
392  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/images/domain-16.png"); //NON-NLS
393  break;
394  case TSK_YARA_HIT:
395  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/images/yara_16.png"); //NON-NLS
396  break;
397  default:
398  logger.log(Level.WARNING, "useDataTypeIcon: unhandled artifact type = {0}", dataType); //NON-NLS
399  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/report/images/star.png"); //NON-NLS
400  iconFileName = "star.png"; //NON-NLS
401  iconFilePath = subPath + File.separator + iconFileName;
402  break;
403  }
404  } else if (dataType.startsWith(ARTIFACT_TYPE.TSK_ACCOUNT.getDisplayName())) {
405  /*
406  * TSK_ACCOUNT artifacts get separated by their TSK_ACCOUNT_TYPE
407  * attribute, with a synthetic compound dataType name, so they are
408  * not caught by the switch statement above. For now we just give
409  * them all the general account icon, but we could do something else
410  * in the future.
411  */
412  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/report/images/accounts.png"); //NON-NLS
413  iconFileName = "accounts.png"; //NON-NLS
414  iconFilePath = subPath + File.separator + iconFileName;
415  } else { // no defined artifact found for this dataType
416  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/report/images/star.png"); //NON-NLS
417  iconFileName = "star.png"; //NON-NLS
418  iconFilePath = subPath + File.separator + iconFileName;
419  }
420 
421  try {
422  output = new FileOutputStream(iconFilePath);
423  FileUtil.copy(in, output);
424  in.close();
425  output.close();
426  } catch (IOException ex) {
427  logger.log(Level.SEVERE, "Failed to extract images for HTML report.", ex); //NON-NLS
428  } finally {
429  if (output != null) {
430  try {
431  output.flush();
432  output.close();
433  } catch (IOException ex) {
434  }
435  }
436  if (in != null) {
437  try {
438  in.close();
439  } catch (IOException ex) {
440  }
441  }
442  }
443 
444  return iconFileName;
445  }
446 
453  @Override
454  public void startReport(String baseReportDir) {
455 
456  // Refresh the HTML report
457  try {
458  refresh();
459  } catch (NoCurrentCaseException ex) {
460  logger.log(Level.SEVERE, "Exception while getting open case."); //NON-NLS
461  return;
462  }
463  // Setup the path for the HTML report
464  this.path = baseReportDir; //NON-NLS
465  this.subPath = this.path + HTML_SUBDIR + File.separator;
466  this.thumbsPath = this.subPath + THUMBS_REL_PATH; //NON-NLS
467  try {
468  FileUtil.createFolder(new File(this.subPath));
469  FileUtil.createFolder(new File(this.thumbsPath));
470  } catch (IOException ex) {
471  logger.log(Level.SEVERE, "Unable to make HTML report folder."); //NON-NLS
472  }
473  // Write the basic files
474  writeCss();
475  writeIndex();
476  writeSummary();
477  }
478 
483  @Override
484  public void endReport() {
485  writeNav();
486  if (out != null) {
487  try {
488  out.close();
489  } catch (IOException ex) {
490  logger.log(Level.WARNING, "Could not close the output writer when ending report.", ex); //NON-NLS
491  }
492  }
493  }
494 
503  @Override
504  public void startDataType(String name, String description) {
505  String title = dataTypeToFileName(name);
506  try {
507  out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(subPath + title + ".html"), "UTF-8")); //NON-NLS
508  } catch (FileNotFoundException ex) {
509  logger.log(Level.SEVERE, "File not found: {0}", ex); //NON-NLS
510  } catch (UnsupportedEncodingException ex) {
511  logger.log(Level.SEVERE, "Unrecognized encoding"); //NON-NLS
512  }
513 
514  try {
515  StringBuilder page = new StringBuilder();
516  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
517  .append(writePageHeader())
518  .append("<div id=\"header\">").append(name).append("</div>\n")
519  .append("<div id=\"content\">\n"); //NON-NLS
520  if (!description.isEmpty()) {
521  page.append("<p><strong>"); //NON-NLS
522  page.append(description);
523  page.append("</strong></p>\n"); //NON-NLS
524  }
525  out.write(page.toString());
526  currentDataType = name;
527  rowCount = 0;
528  } catch (IOException ex) {
529  logger.log(Level.SEVERE, "Failed to write page head: {0}", ex); //NON-NLS
530  }
531  }
532 
537  @Override
538  public void endDataType() {
539  dataTypes.put(currentDataType, rowCount);
540  try {
541  StringBuilder builder = new StringBuilder();
542  builder.append(writePageFooter());
543  builder.append("</div>\n</body>\n</html>\n"); //NON-NLS
544  out.write(builder.toString());
545  } catch (IOException ex) {
546  logger.log(Level.SEVERE, "Failed to write end of HTML report.", ex); //NON-NLS
547  } finally {
548  if (out != null) {
549  try {
550  out.flush();
551  out.close();
552  } catch (IOException ex) {
553  logger.log(Level.WARNING, "Could not close the output writer when ending data type.", ex); //NON-NLS
554  }
555  out = null;
556  }
557  }
558  }
559 
566  private String writePageHeader() {
567  StringBuilder output = new StringBuilder();
568  String pageHeader = configPanel.getHeader();
569  if (pageHeader.isEmpty() == false) {
570  output.append("<div id=\"pageHeaderFooter\">")
571  .append(StringEscapeUtils.escapeHtml4(pageHeader))
572  .append("</div>\n"); //NON-NLS
573  }
574  return output.toString();
575  }
576 
583  private String writePageFooter() {
584  StringBuilder output = new StringBuilder();
585  String pageFooter = configPanel.getFooter();
586  if (pageFooter.isEmpty() == false) {
587  output.append("<br/><div id=\"pageHeaderFooter\">")
588  .append(StringEscapeUtils.escapeHtml4(pageFooter))
589  .append("</div>"); //NON-NLS
590  }
591  return output.toString();
592  }
593 
599  @Override
600  public void startSet(String setName) {
601  StringBuilder set = new StringBuilder();
602  set.append("<h1><a name=\"").append(setName).append("\">").append(setName).append("</a></h1>\n"); //NON-NLS
603  set.append("<div class=\"keyword_list\">\n"); //NON-NLS
604 
605  try {
606  out.write(set.toString());
607  } catch (IOException ex) {
608  logger.log(Level.SEVERE, "Failed to write set: {0}", ex); //NON-NLS
609  }
610  }
611 
615  @Override
616  public void endSet() {
617  try {
618  out.write("</div>\n"); //NON-NLS
619  } catch (IOException ex) {
620  logger.log(Level.SEVERE, "Failed to write end of set: {0}", ex); //NON-NLS
621  }
622  }
623 
629  @Override
630  public void addSetIndex(List<String> sets) {
631  StringBuilder index = new StringBuilder();
632  index.append("<ul>\n"); //NON-NLS
633  for (String set : sets) {
634  index.append("\t<li><a href=\"#").append(set).append("\">").append(set).append("</a></li>\n"); //NON-NLS
635  }
636  index.append("</ul>\n"); //NON-NLS
637  try {
638  out.write(index.toString());
639  } catch (IOException ex) {
640  logger.log(Level.SEVERE, "Failed to add set index: {0}", ex); //NON-NLS
641  }
642  }
643 
649  @Override
650  public void addSetElement(String elementName) {
651  try {
652  out.write("<h4>" + elementName + "</h4>\n"); //NON-NLS
653  } catch (IOException ex) {
654  logger.log(Level.SEVERE, "Failed to write set element: {0}", ex); //NON-NLS
655  }
656  }
657 
663  @Override
664  public void startTable(List<String> titles) {
665  StringBuilder ele = new StringBuilder();
666  ele.append("<table>\n<thead>\n\t<tr>\n"); //NON-NLS
667  for (String title : titles) {
668  ele.append("\t\t<th>").append(title).append("</th>\n"); //NON-NLS
669  }
670  ele.append("\t</tr>\n</thead>\n"); //NON-NLS
671 
672  try {
673  out.write(ele.toString());
674  } catch (IOException ex) {
675  logger.log(Level.SEVERE, "Failed to write table start: {0}", ex); //NON-NLS
676  }
677  }
678 
685  public void startContentTagsTable(List<String> columnHeaders) {
686  StringBuilder htmlOutput = new StringBuilder();
687  htmlOutput.append("<table>\n<thead>\n\t<tr>\n"); //NON-NLS
688 
689  // Add the specified columns.
690  for (String columnHeader : columnHeaders) {
691  htmlOutput.append("\t\t<th>").append(columnHeader).append("</th>\n"); //NON-NLS
692  }
693 
694  // Add a column for a hyperlink to a local copy of the tagged content.
695  htmlOutput.append("\t\t<th></th>\n"); //NON-NLS
696 
697  htmlOutput.append("\t</tr>\n</thead>\n"); //NON-NLS
698 
699  try {
700  out.write(htmlOutput.toString());
701  } catch (IOException ex) {
702  logger.log(Level.SEVERE, "Failed to write table start: {0}", ex); //NON-NLS
703  }
704  }
705 
709  @Override
710  public void endTable() {
711  try {
712  out.write("</table>\n"); //NON-NLS
713  } catch (IOException ex) {
714  logger.log(Level.SEVERE, "Failed to write end of table: {0}", ex); //NON-NLS
715  }
716  }
717 
724  @Override
725  public void addRow(List<String> row) {
726  addRow(row, true);
727  }
728 
736  private void addRow(List<String> row, boolean escapeText) {
737  StringBuilder builder = new StringBuilder();
738  builder.append("\t<tr>\n"); //NON-NLS
739  for (String cell : row) {
740  String cellText = escapeText ? EscapeUtil.escapeHtml(cell) : cell;
741  builder.append("\t\t<td>").append(cellText).append("</td>\n"); //NON-NLS
742  }
743  builder.append("\t</tr>\n"); //NON-NLS
744  rowCount++;
745 
746  try {
747  out.write(builder.toString());
748  } catch (IOException ex) {
749  logger.log(Level.SEVERE, "Failed to write row to out.", ex); //NON-NLS
750  } catch (NullPointerException ex) {
751  logger.log(Level.SEVERE, "Output writer is null. Page was not initialized before writing.", ex); //NON-NLS
752  }
753  }
754 
762  public void addRowWithTaggedContentHyperlink(List<String> row, ContentTag contentTag) {
763  Content content = contentTag.getContent();
764  if (content instanceof AbstractFile == false) {
765  addRow(row, true);
766  return;
767  }
768  AbstractFile file = (AbstractFile) content;
769  // Add the hyperlink to the row. A column header for it was created in startTable().
770  StringBuilder localFileLink = new StringBuilder();
771  // Don't make a local copy of the file if it is a directory or unallocated space.
772  if (!(file.isDir()
773  || file.getType() == TSK_DB_FILES_TYPE_ENUM.UNALLOC_BLOCKS
774  || file.getType() == TSK_DB_FILES_TYPE_ENUM.UNUSED_BLOCKS)) {
775  localFileLink.append("<a href=\""); //NON-NLS
776  // save it in a folder based on the tag name
777  String localFilePath = saveContent(file, contentTag.getName().getDisplayName());
778  localFileLink.append(localFilePath);
779  localFileLink.append("\" target=\"_top\">");
780  }
781 
782  StringBuilder builder = new StringBuilder();
783  builder.append("\t<tr>\n"); //NON-NLS
784  int positionCounter = 0;
785  for (String cell : row) {
786  // position-dependent code used to format this report. Not great, but understandable for formatting.
787  switch (positionCounter) {
788  case 1:
789  // Convert the file name to a hyperlink and left-align it
790  builder.append("\t\t<td class=\"left_align_cell\">").append(localFileLink.toString()).append(cell).append("</a></td>\n"); //NON-NLS
791  break;
792  case 7:
793  // Right-align the bytes column.
794  builder.append("\t\t<td class=\"right_align_cell\">").append(cell).append("</td>\n"); //NON-NLS
795  break;
796  default:
797  // Regular case, not a file name nor a byte count
798  builder.append("\t\t<td>").append(cell).append("</td>\n"); //NON-NLS
799  break;
800  }
801  ++positionCounter;
802  }
803  builder.append("\t</tr>\n"); //NON-NLS
804  rowCount++;
805 
806  try {
807  out.write(builder.toString());
808  } catch (IOException ex) {
809  logger.log(Level.SEVERE, "Failed to write row to out.", ex); //NON-NLS
810  } catch (NullPointerException ex) {
811  logger.log(Level.SEVERE, "Output writer is null. Page was not initialized before writing.", ex); //NON-NLS
812  }
813  }
814 
821  private List<ImageTagRegion> getTaggedRegions(List<ContentTag> contentTags) {
822  ArrayList<ImageTagRegion> tagRegions = new ArrayList<>();
823  contentTags.forEach((contentTag) -> {
824  try {
826  .getTag(contentTag, ImageTagRegion.class);
827  if (contentViewerTag != null) {
828  tagRegions.add(contentViewerTag.getDetails());
829  }
830  } catch (TskCoreException | NoCurrentCaseException ex) {
831  logger.log(Level.WARNING, "Could not get content viewer tag "
832  + "from case db for content_tag with id %d", contentTag.getId());
833  }
834  });
835  return tagRegions;
836  }
837 
843  public void addThumbnailRows(Set<Content> images) {
844  List<String> currentRow = new ArrayList<>();
845  int totalCount = 0;
846  int pages = 1;
847  for (Content content : images) {
848  if (currentRow.size() == THUMBNAIL_COLUMNS) {
849  addRow(currentRow, false);
850  currentRow.clear();
851  }
852 
853  if (totalCount == MAX_THUMBS_PER_PAGE) {
854  // manually set the row count so the count of items shown in the
855  // navigation page reflects the number of thumbnails instead of
856  // the number of rows.
857  rowCount = totalCount;
858  totalCount = 0;
859  pages++;
860  endTable();
861  endDataType();
862  startDataType(NbBundle.getMessage(this.getClass(), "ReportHTML.addThumbRows.dataType.title", pages),
863  NbBundle.getMessage(this.getClass(), "ReportHTML.addThumbRows.dataType.msg"));
864  List<String> emptyHeaders = new ArrayList<>();
865  for (int i = 0; i < THUMBNAIL_COLUMNS; i++) {
866  emptyHeaders.add("");
867  }
868  startTable(emptyHeaders);
869  }
870 
871  if (failsContentCheck(content)) {
872  continue;
873  }
874 
875  AbstractFile file = (AbstractFile) content;
876  List<ContentTag> contentTags = new ArrayList<>();
877 
878  String thumbnailPath = null;
879  String imageWithTagsFullPath = null;
880  try {
881  //Get content tags and all image tags
882  contentTags = Case.getCurrentCase().getServices()
884  List<ImageTagRegion> imageTags = getTaggedRegions(contentTags);
885 
886  if (!imageTags.isEmpty()) {
887  //Write the tags to the fullsize and thumbnail images
888  BufferedImage fullImageWithTags = ImageTagsUtil.getImageWithTags(file, imageTags);
889 
890  BufferedImage thumbnailWithTags = ImageTagsUtil.getThumbnailWithTags(file,
891  imageTags, ImageTagsUtil.IconSize.MEDIUM);
892 
893  String fileName = org.sleuthkit.autopsy.coreutils.FileUtil.escapeFileName(file.getName());
894 
895  //Create paths in report to write tagged images
896  File thumbnailImageWithTagsFile = Paths.get(thumbsPath, FilenameUtils.removeExtension(fileName) + ".png").toFile();
897  String fullImageWithTagsPath = makeCustomUniqueFilePath(file, "thumbs_fullsize");
898  fullImageWithTagsPath = FilenameUtils.removeExtension(fullImageWithTagsPath) + ".png";
899  File fullImageWithTagsFile = Paths.get(fullImageWithTagsPath).toFile();
900 
901  //Save images
902  ImageIO.write(thumbnailWithTags, "png", thumbnailImageWithTagsFile);
903  ImageIO.write(fullImageWithTags, "png", fullImageWithTagsFile);
904 
905  thumbnailPath = THUMBS_REL_PATH + thumbnailImageWithTagsFile.getName();
906  //Relative path
907  imageWithTagsFullPath = fullImageWithTagsPath.substring(subPath.length());
908  }
909  } catch (TskCoreException ex) {
910  logger.log(Level.WARNING, "Could not get tags for file.", ex); //NON-NLS
911  } catch (IOException | InterruptedException | ExecutionException ex) {
912  logger.log(Level.WARNING, "Could make marked up thumbnail.", ex); //NON-NLS
913  }
914 
915  // save copies of the orginal image and thumbnail image
916  if (thumbnailPath == null) {
917  thumbnailPath = prepareThumbnail(file);
918  }
919 
920  if (thumbnailPath == null) {
921  continue;
922  }
923  String contentPath = saveContent(file, "original"); //NON-NLS
924  String nameInImage;
925  try {
926  nameInImage = file.getUniquePath();
927  } catch (TskCoreException ex) {
928  nameInImage = file.getName();
929  }
930 
931  StringBuilder linkToThumbnail = new StringBuilder();
932  linkToThumbnail.append("<div id='thumbnail_link'><a href=\"")
933  .append((imageWithTagsFullPath != null) ? imageWithTagsFullPath : contentPath)
934  .append("\" target=\"_top\"><img src=\"")
935  .append(thumbnailPath).append("\" title=\"").append(nameInImage).append("\"/></a><br>") //NON-NLS
936  .append(file.getName()).append("<br>"); //NON-NLS
937  if (imageWithTagsFullPath != null) {
938  linkToThumbnail.append("<a href=\"").append(contentPath).append("\" target=\"_top\">View Original</a><br>");
939  }
940 
941  if (!contentTags.isEmpty()) {
942  linkToThumbnail.append(NbBundle.getMessage(this.getClass(), "ReportHTML.thumbLink.tags"));
943  }
944  for (int i = 0; i < contentTags.size(); i++) {
945  ContentTag tag = contentTags.get(i);
946  String notableString = tag.getName().getKnownStatus() == TskData.FileKnown.BAD ? TagsManager.getNotableTagLabel() : "";
947  linkToThumbnail.append(tag.getName().getDisplayName()).append(notableString);
948  if (i != contentTags.size() - 1) {
949  linkToThumbnail.append(", ");
950  }
951  }
952 
953  linkToThumbnail.append("</div>");
954  currentRow.add(linkToThumbnail.toString());
955 
956  totalCount++;
957  }
958 
959  if (currentRow.isEmpty() == false) {
960  int extraCells = THUMBNAIL_COLUMNS - currentRow.size();
961  for (int i = 0; i < extraCells; i++) {
962  // Finish out the row.
963  currentRow.add("");
964  }
965  addRow(currentRow, false);
966  }
967 
968  // manually set rowCount to be the total number of images.
969  rowCount = totalCount;
970  }
971 
972  private boolean failsContentCheck(Content c) {
973  if (c instanceof AbstractFile == false) {
974  return true;
975  }
976  AbstractFile file = (AbstractFile) c;
977  return file.isDir()
978  || file.getType() == TSK_DB_FILES_TYPE_ENUM.UNALLOC_BLOCKS
979  || file.getType() == TSK_DB_FILES_TYPE_ENUM.UNUSED_BLOCKS;
980  }
981 
982  private String makeCustomUniqueFilePath(AbstractFile file, String dirName) {
983  // clean up the dir name passed in
984  String dirName2 = org.sleuthkit.autopsy.coreutils.FileUtil.escapeFileName(dirName);
985 
986  // Make a folder for the local file with the same tagName as the tag.
987  StringBuilder localFilePath = new StringBuilder(); // full path
988 
989  localFilePath.append(subPath);
990  localFilePath.append(dirName2);
991  File localFileFolder = new File(localFilePath.toString());
992  if (!localFileFolder.exists()) {
993  localFileFolder.mkdirs();
994  }
995 
996  /*
997  * Construct a file tagName for the local file that incorporates the
998  * file ID to ensure uniqueness.
999  *
1000  * Note: File name is normalized to account for possible attribute name
1001  * which will be separated by a ':' character.
1002  */
1003  String fileName = org.sleuthkit.autopsy.coreutils.FileUtil.escapeFileName(file.getName());
1004  String objectIdSuffix = "_" + file.getId();
1005  int lastDotIndex = fileName.lastIndexOf(".");
1006  if (lastDotIndex != -1 && lastDotIndex != 0) {
1007  // The file tagName has a conventional extension. Insert the object id before the '.' of the extension.
1008  fileName = fileName.substring(0, lastDotIndex) + objectIdSuffix + fileName.substring(lastDotIndex, fileName.length());
1009  } else {
1010  // The file has no extension or the only '.' in the file is an initial '.', as in a hidden file.
1011  // Add the object id to the end of the file tagName.
1012  fileName += objectIdSuffix;
1013  }
1014  localFilePath.append(File.separator);
1015  localFilePath.append(fileName);
1016 
1017  return localFilePath.toString();
1018  }
1019 
1029  public String saveContent(AbstractFile file, String dirName) {
1030 
1031  String localFilePath = makeCustomUniqueFilePath(file, dirName);
1032 
1033  // If the local file doesn't already exist, create it now.
1034  // The existence check is necessary because it is possible to apply multiple tags with the same tagName to a file.
1035  File localFile = new File(localFilePath);
1036  if (!localFile.exists()) {
1037  ExtractFscContentVisitor.extract(file, localFile, null, null);
1038  }
1039 
1040  // get the relative path
1041  return localFilePath.substring(subPath.length());
1042  }
1043 
1051  @Override
1052  public String dateToString(long date) {
1053  SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
1054  return sdf.format(new java.util.Date(date * 1000));
1055  }
1056 
1057  @Override
1058  public String getRelativeFilePath() {
1059  return "report.html"; //NON-NLS
1060  }
1061 
1062  @Override
1063  public String getName() {
1064  return NbBundle.getMessage(this.getClass(), "ReportHTML.getName.text");
1065  }
1066 
1067  @Override
1068  public String getDescription() {
1069  return NbBundle.getMessage(this.getClass(), "ReportHTML.getDesc.text");
1070  }
1071 
1075  private void writeCss() {
1076  Writer cssOut = null;
1077  try {
1078  cssOut = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(subPath + "index.css"), "UTF-8")); //NON-NLS NON-NLS
1079  String css = "body {margin: 0px; padding: 0px; background: #FFFFFF; font: 13px/20px Arial, Helvetica, sans-serif; color: #535353;}\n"
1080  + //NON-NLS
1081  "#content {padding: 30px;}\n"
1082  + //NON-NLS
1083  "#header {width:100%; padding: 10px; line-height: 25px; background: #07A; color: #FFF; font-size: 20px;}\n"
1084  + //NON-NLS
1085  "#pageHeaderFooter {width: 100%; padding: 10px; line-height: 25px; text-align: center; font-size: 20px;}\n"
1086  + //NON-NLS
1087  "h1 {font-size: 20px; font-weight: normal; color: #07A; padding: 0 0 7px 0; margin-top: 25px; border-bottom: 1px solid #D6D6D6;}\n"
1088  + //NON-NLS
1089  "h2 {font-size: 20px; font-weight: bolder; color: #07A;}\n"
1090  + //NON-NLS
1091  "h3 {font-size: 16px; color: #07A;}\n"
1092  + //NON-NLS
1093  "h4 {background: #07A; color: #FFF; font-size: 16px; margin: 0 0 0 25px; padding: 0; padding-left: 15px;}\n"
1094  + //NON-NLS
1095  "ul.nav {list-style-type: none; line-height: 35px; padding: 0px; margin-left: 15px;}\n"
1096  + //NON-NLS
1097  "ul li a {font-size: 14px; color: #444; text-decoration: none; padding-left: 25px;}\n"
1098  + //NON-NLS
1099  "ul li a:hover {text-decoration: underline;}\n"
1100  + //NON-NLS
1101  "p {margin: 0 0 20px 0;}\n"
1102  + //NON-NLS
1103  "table {white-space:nowrap; min-width: 700px; padding: 2; margin: 0; border-collapse: collapse; border-bottom: 2px solid #e5e5e5;}\n"
1104  + //NON-NLS
1105  ".keyword_list table {margin: 0 0 25px 25px; border-bottom: 2px solid #dedede;}\n"
1106  + //NON-NLS
1107  "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"
1108  + //NON-NLS
1109  "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"
1110  + //NON-NLS
1111  "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"
1112  + //NON-NLS
1113  "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"
1114  + //NON-NLS
1115  "table tr:nth-child(even) td {background: #f3f3f3;}\n"
1116  + //NON-NLS
1117  "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;}";
1118  cssOut.write(css);
1119  } catch (FileNotFoundException ex) {
1120  logger.log(Level.SEVERE, "Could not find index.css file to write to.", ex); //NON-NLS
1121  } catch (UnsupportedEncodingException ex) {
1122  logger.log(Level.SEVERE, "Did not recognize encoding when writing index.css.", ex); //NON-NLS
1123  } catch (IOException ex) {
1124  logger.log(Level.SEVERE, "Error creating Writer for index.css.", ex); //NON-NLS
1125  } finally {
1126  try {
1127  if (cssOut != null) {
1128  cssOut.flush();
1129  cssOut.close();
1130  }
1131  } catch (IOException ex) {
1132  }
1133  }
1134  }
1135 
1139  private void writeIndex() {
1140  Writer indexOut = null;
1141  String indexFilePath = path + "report.html"; //NON-NLS
1142  Case openCase;
1143  try {
1144  openCase = Case.getCurrentCaseThrows();
1145  } catch (NoCurrentCaseException ex) {
1146  logger.log(Level.SEVERE, "Exception while getting open case.", ex); //NON-NLS
1147  return;
1148  }
1149  try {
1150  indexOut = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(indexFilePath), "UTF-8")); //NON-NLS
1151  StringBuilder index = new StringBuilder();
1152  final String reportTitle = reportBranding.getReportTitle();
1153  String iconPath = reportBranding.getAgencyLogoPath();
1154  if (iconPath == null) {
1155  // use default Autopsy icon if custom icon is not set
1156  iconPath = HTML_SUBDIR + "favicon.ico";
1157  } else {
1158  iconPath = Paths.get(reportBranding.getAgencyLogoPath()).getFileName().toString(); //ref to writeNav() for agency_logo
1159  }
1160  index.append("<head>\n<title>").append(reportTitle).append(" ").append(
1161  NbBundle.getMessage(this.getClass(), "ReportHTML.writeIndex.title", currentCase.getDisplayName())).append(
1162  "</title>\n"); //NON-NLS
1163  index.append("<link rel=\"icon\" type=\"image/ico\" href=\"")
1164  .append(iconPath).append("\" />\n"); //NON-NLS
1165  index.append("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\n"); //NON-NLS
1166  index.append("</head>\n"); //NON-NLS
1167  index.append("<frameset cols=\"350px,*\">\n"); //NON-NLS
1168  index.append("<frame src=\"" + HTML_SUBDIR).append(File.separator).append("nav.html\" name=\"nav\">\n"); //NON-NLS
1169  index.append("<frame src=\"" + HTML_SUBDIR).append(File.separator).append("summary.html\" name=\"content\">\n"); //NON-NLS
1170  index.append("<noframes>").append(NbBundle.getMessage(this.getClass(), "ReportHTML.writeIndex.noFrames.msg")).append("<br />\n"); //NON-NLS
1171  index.append(NbBundle.getMessage(this.getClass(), "ReportHTML.writeIndex.noFrames.seeNav")).append("<br />\n"); //NON-NLS
1172  index.append(NbBundle.getMessage(this.getClass(), "ReportHTML.writeIndex.seeSum")).append("</noframes>\n"); //NON-NLS
1173  index.append("</frameset>\n"); //NON-NLS
1174  index.append("</html>"); //NON-NLS
1175  indexOut.write(index.toString());
1176  openCase.addReport(indexFilePath, NbBundle.getMessage(this.getClass(),
1177  "ReportHTML.writeIndex.srcModuleName.text"), "");
1178  } catch (IOException ex) {
1179  logger.log(Level.SEVERE, "Error creating Writer for report.html: {0}", ex); //NON-NLS
1180  } catch (TskCoreException ex) {
1181  String errorMessage = String.format("Error adding %s to case as a report", indexFilePath); //NON-NLS
1182  logger.log(Level.SEVERE, errorMessage, ex);
1183  } finally {
1184  try {
1185  if (indexOut != null) {
1186  indexOut.flush();
1187  indexOut.close();
1188  }
1189  } catch (IOException ex) {
1190  }
1191  }
1192  }
1193 
1197  private void writeNav() {
1198  Writer navOut = null;
1199  try {
1200  navOut = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(subPath + "nav.html"), "UTF-8")); //NON-NLS
1201  StringBuilder nav = new StringBuilder();
1202  nav.append("<html>\n<head>\n\t<title>").append( //NON-NLS
1203  NbBundle.getMessage(this.getClass(), "ReportHTML.writeNav.title"))
1204  .append("</title>\n\t<link rel=\"stylesheet\" type=\"text/css\" href=\"index.css\" />\n"); //NON-NLS
1205  nav.append("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\n</head>\n<body>\n"); //NON-NLS
1206  nav.append("<div id=\"content\">\n<h1>").append( //NON-NLS
1207  NbBundle.getMessage(this.getClass(), "ReportHTML.writeNav.h1")).append("</h1>\n"); //NON-NLS
1208  nav.append("<ul class=\"nav\">\n"); //NON-NLS
1209  nav.append("<li style=\"background: url(summary.png) left center no-repeat;\"><a href=\"summary.html\" target=\"content\">") //NON-NLS
1210  .append(NbBundle.getMessage(this.getClass(), "ReportHTML.writeNav.summary")).append("</a></li>\n"); //NON-NLS
1211 
1212  for (String dataType : dataTypes.keySet()) {
1213  String dataTypeEsc = dataTypeToFileName(dataType);
1214  String iconFileName = useDataTypeIcon(dataType);
1215  nav.append("<li style=\"background: url('").append(iconFileName) //NON-NLS
1216  .append("') left center no-repeat;\"><a href=\"") //NON-NLS
1217  .append(dataTypeEsc).append(".html\" target=\"content\">") //NON-NLS
1218  .append(dataType).append(" (").append(dataTypes.get(dataType))
1219  .append(")</a></li>\n"); //NON-NLS
1220  }
1221  nav.append("</ul>\n"); //NON-NLS
1222  nav.append("</div>\n</body>\n</html>"); //NON-NLS
1223  navOut.write(nav.toString());
1224  } catch (IOException ex) {
1225  logger.log(Level.SEVERE, "Failed to write end of report navigation menu: {0}", ex); //NON-NLS
1226  } finally {
1227  if (navOut != null) {
1228  try {
1229  navOut.flush();
1230  navOut.close();
1231  } catch (IOException ex) {
1232  logger.log(Level.WARNING, "Could not close navigation out writer."); //NON-NLS
1233  }
1234  }
1235  }
1236 
1237  InputStream in = null;
1238  OutputStream output = null;
1239  try {
1240 
1241  //pull generator and agency logo from branding, and the remaining resources from the core jar
1242  String generatorLogoPath = reportBranding.getGeneratorLogoPath();
1243  if (generatorLogoPath != null && !generatorLogoPath.isEmpty()) {
1244  File from = new File(generatorLogoPath);
1245  File to = new File(subPath);
1246  FileUtil.copyFile(FileUtil.toFileObject(from), FileUtil.toFileObject(to), "generator_logo"); //NON-NLS
1247  }
1248 
1249  String agencyLogoPath = reportBranding.getAgencyLogoPath();
1250  if (agencyLogoPath != null && !agencyLogoPath.isEmpty()) {
1251  Path destinationPath = Paths.get(subPath);
1252  Files.copy(Files.newInputStream(Paths.get(agencyLogoPath)), destinationPath.resolve(Paths.get(agencyLogoPath).getFileName())); //NON-NLS
1253  }
1254 
1255  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/report/images/favicon.ico"); //NON-NLS
1256  output = new FileOutputStream(new File(subPath + "favicon.ico"));
1257  FileUtil.copy(in, output);
1258  in.close();
1259  output.close();
1260 
1261  in = getClass().getResourceAsStream("/org/sleuthkit/autopsy/report/images/summary.png"); //NON-NLS
1262  output = new FileOutputStream(new File(subPath + "summary.png"));
1263  FileUtil.copy(in, output);
1264  in.close();
1265  output.close();
1266 
1267  } catch (IOException ex) {
1268  logger.log(Level.SEVERE, "Failed to extract images for HTML report.", ex); //NON-NLS
1269  } finally {
1270  if (output != null) {
1271  try {
1272  output.flush();
1273  output.close();
1274  } catch (IOException ex) {
1275  }
1276  }
1277  if (in != null) {
1278  try {
1279  in.close();
1280  } catch (IOException ex) {
1281  }
1282  }
1283  }
1284  }
1285 
1289  private void writeSummary() {
1290  Writer output = null;
1291  try {
1292  output = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(subPath + "summary.html"), "UTF-8")); //NON-NLS
1293  StringBuilder head = new StringBuilder();
1294  head.append("<html>\n<head>\n<title>").append( //NON-NLS
1295  NbBundle.getMessage(this.getClass(), "ReportHTML.writeSum.title")).append("</title>\n"); //NON-NLS
1296  head.append("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\n"); //NON-NLS
1297  head.append("<style type=\"text/css\">\n"); //NON-NLS
1298  head.append("#pageHeaderFooter {width: 100%; padding: 10px; line-height: 25px; text-align: center; font-size: 20px;}\n"); //NON-NLS
1299  head.append("body { padding: 0px; margin: 0px; font: 13px/20px Arial, Helvetica, sans-serif; color: #535353; }\n"); //NON-NLS
1300  head.append("#wrapper { width: 90%; margin: 0px auto; margin-top: 35px; }\n"); //NON-NLS
1301  head.append("h1 { color: #07A; font-size: 36px; line-height: 42px; font-weight: normal; margin: 0px; border-bottom: 1px solid #81B9DB; }\n"); //NON-NLS
1302  head.append("h1 span { color: #F00; display: block; font-size: 16px; font-weight: bold; line-height: 22px;}\n"); //NON-NLS
1303  head.append("h2 { padding: 0 0 3px 0; margin: 0px; color: #07A; font-weight: normal; border-bottom: 1px dotted #81B9DB; }\n"); //NON-NLS
1304  head.append("h3 { padding: 5 0 3px 0; margin: 0px; color: #07A; font-weight: normal; }\n");
1305  head.append("table td { padding: 5px 25px 5px 0px; vertical-align:top;}\n"); //NON-NLS
1306  head.append("p.subheadding { padding: 0px; margin: 0px; font-size: 11px; color: #B5B5B5; }\n"); //NON-NLS
1307  head.append(".title { width: 660px; margin-bottom: 50px; }\n"); //NON-NLS
1308  head.append(".left { float: left; width: 250px; margin-top: 20px; text-align: center; }\n"); //NON-NLS
1309  head.append(".left img { max-width: 250px; max-height: 250px; min-width: 200px; min-height: 200px; }\n"); //NON-NLS
1310  head.append(".right { float: right; width: 385px; margin-top: 25px; font-size: 14px; }\n"); //NON-NLS
1311  head.append(".clear { clear: both; }\n"); //NON-NLS
1312  head.append(".info { padding: 10px 0;}\n");
1313  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
1314  head.append(".info table { margin: 10px 25px 10px 25px; }\n"); //NON-NLS
1315  head.append("ul {padding: 0;margin: 0;list-style-type: none;}");
1316  head.append("li {padding-bottom: 5px;}");
1317  head.append("</style>\n"); //NON-NLS
1318  head.append("</head>\n<body>\n"); //NON-NLS
1319  output.write(head.toString());
1320 
1321  DateFormat datetimeFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
1322  Date date = new Date();
1323  String datetime = datetimeFormat.format(date);
1324 
1325  StringBuilder summary = new StringBuilder();
1326  boolean running = false;
1328  running = true;
1329  }
1330  SleuthkitCase skCase = Case.getCurrentCaseThrows().getSleuthkitCase();
1331  List<IngestJobInfo> ingestJobs = skCase.getIngestJobs();
1332  final String reportTitle = reportBranding.getReportTitle();
1333  final String reportFooter = reportBranding.getReportFooter();
1334  final boolean generatorLogoSet = reportBranding.getGeneratorLogoPath() != null && !reportBranding.getGeneratorLogoPath().isEmpty();
1335 
1336  summary.append("<div id=\"wrapper\">\n"); //NON-NLS
1337  summary.append(writePageHeader());
1338  summary.append("<h1>").append(reportTitle) //NON-NLS
1339  .append(running ? NbBundle.getMessage(this.getClass(), "ReportHTML.writeSum.warningMsg") : "")
1340  .append("</h1>\n"); //NON-NLS
1341  summary.append("<p class=\"subheadding\">").append( //NON-NLS
1342  NbBundle.getMessage(this.getClass(), "ReportHTML.writeSum.reportGenOn.text", datetime)).append("</p>\n"); //NON-NLS
1343  summary.append("<div class=\"title\">\n"); //NON-NLS
1344  summary.append(writeSummaryCaseDetails());
1345  summary.append(writeSummaryImageInfo());
1346  summary.append(writeSummarySoftwareInfo(skCase, ingestJobs));
1347  summary.append(writeSummaryIngestHistoryInfo(skCase, ingestJobs));
1348  if (generatorLogoSet) {
1349  summary.append("<div class=\"left\">\n"); //NON-NLS
1350  summary.append("<img src=\"generator_logo.png\" />\n"); //NON-NLS
1351  summary.append("</div>\n"); //NON-NLS
1352  }
1353  summary.append("<div class=\"clear\"></div>\n"); //NON-NLS
1354  if (reportFooter != null) {
1355  summary.append("<p class=\"subheadding\">").append(reportFooter).append("</p>\n"); //NON-NLS
1356  }
1357  summary.append("</div>\n"); //NON-NLS
1358  summary.append(writePageFooter());
1359  summary.append("</body></html>"); //NON-NLS
1360  output.write(summary.toString());
1361  } catch (FileNotFoundException ex) {
1362  logger.log(Level.SEVERE, "Could not find summary.html file to write to."); //NON-NLS
1363  } catch (UnsupportedEncodingException ex) {
1364  logger.log(Level.SEVERE, "Did not recognize encoding when writing summary.hmtl."); //NON-NLS
1365  } catch (IOException ex) {
1366  logger.log(Level.SEVERE, "Error creating Writer for summary.html."); //NON-NLS
1367  } catch (NoCurrentCaseException | TskCoreException ex) {
1368  logger.log(Level.WARNING, "Unable to get current sleuthkit Case for the HTML report.");
1369  } finally {
1370  try {
1371  if (output != null) {
1372  output.flush();
1373  output.close();
1374  }
1375  } catch (IOException ex) {
1376  }
1377  }
1378  }
1379 
1380  @Messages({
1381  "ReportHTML.writeSum.case=Case:",
1382  "ReportHTML.writeSum.caseNumber=Case Number:",
1383  "ReportHTML.writeSum.caseNumImages=Number of data sources in case:",
1384  "ReportHTML.writeSum.caseNotes=Notes:",
1385  "ReportHTML.writeSum.examiner=Examiner:"
1386  })
1392  private StringBuilder writeSummaryCaseDetails() {
1393  StringBuilder summary = new StringBuilder();
1394 
1395  final boolean agencyLogoSet = reportBranding.getAgencyLogoPath() != null && !reportBranding.getAgencyLogoPath().isEmpty();
1396 
1397  // Case
1398  String caseName = currentCase.getDisplayName();
1399  String caseNumber = currentCase.getNumber();
1400  int imagecount;
1401  try {
1402  imagecount = currentCase.getDataSources().size();
1403  } catch (TskCoreException ex) {
1404  imagecount = 0;
1405  }
1406  String caseNotes = currentCase.getCaseNotes();
1407 
1408  // Examiner
1409  String examinerName = currentCase.getExaminer();
1410 
1411  // Start the layout.
1412  summary.append("<div class=\"title\">\n"); //NON-NLS
1413  if (agencyLogoSet) {
1414  summary.append("<div class=\"left\">\n"); //NON-NLS
1415  summary.append("<img src=\"");
1416  summary.append(Paths.get(reportBranding.getAgencyLogoPath()).getFileName().toString());
1417  summary.append("\" />\n"); //NON-NLS
1418  summary.append("</div>\n"); //NON-NLS
1419  }
1420  final String align = agencyLogoSet ? "right" : "left"; //NON-NLS NON-NLS
1421  summary.append("<div class=\"").append(align).append("\">\n"); //NON-NLS
1422  summary.append("<table>\n"); //NON-NLS
1423 
1424  // Case details
1425  summary.append("<tr><td>").append(Bundle.ReportHTML_writeSum_case()).append("</td><td>") //NON-NLS
1426  .append(formatHtmlString(caseName)).append("</td></tr>\n"); //NON-NLS
1427 
1428  if (!caseNumber.isEmpty()) {
1429  summary.append("<tr><td>").append(Bundle.ReportHTML_writeSum_caseNumber()).append("</td><td>") //NON-NLS
1430  .append(formatHtmlString(caseNumber)).append("</td></tr>\n"); //NON-NLS
1431  }
1432 
1433  summary.append("<tr><td>").append(Bundle.ReportHTML_writeSum_caseNumImages()).append("</td><td>") //NON-NLS
1434  .append(imagecount).append("</td></tr>\n"); //NON-NLS
1435 
1436  if (!caseNotes.isEmpty()) {
1437  summary.append("<tr><td>").append(Bundle.ReportHTML_writeSum_caseNotes()).append("</td><td>") //NON-NLS
1438  .append(formatHtmlString(caseNotes)).append("</td></tr>\n"); //NON-NLS
1439  }
1440 
1441  // Examiner details
1442  if (!examinerName.isEmpty()) {
1443  summary.append("<tr><td>").append(Bundle.ReportHTML_writeSum_examiner()).append("</td><td>") //NON-NLS
1444  .append(formatHtmlString(examinerName)).append("</td></tr>\n"); //NON-NLS
1445  }
1446 
1447  // End the layout.
1448  summary.append("</table>\n"); //NON-NLS
1449  summary.append("</div>\n"); //NON-NLS
1450  summary.append("<div class=\"clear\"></div>\n"); //NON-NLS
1451  summary.append("</div>\n"); //NON-NLS
1452  return summary;
1453  }
1454 
1460  private StringBuilder writeSummaryImageInfo() {
1461  StringBuilder summary = new StringBuilder();
1462  summary.append(NbBundle.getMessage(this.getClass(), "ReportHTML.writeSum.imageInfoHeading"));
1463  summary.append("<div class=\"info\">\n"); //NON-NLS
1464  try {
1465  for (Content c : currentCase.getDataSources()) {
1466  summary.append("<p>").append(c.getName()).append("</p>\n"); //NON-NLS
1467  if (c instanceof Image) {
1468  Image img = (Image) c;
1469 
1470  summary.append("<table>\n"); //NON-NLS
1471  summary.append("<tr><td>").append( //NON-NLS
1472  NbBundle.getMessage(this.getClass(), "ReportHTML.writeSum.timezone"))
1473  .append("</td><td>").append(img.getTimeZone()).append("</td></tr>\n"); //NON-NLS
1474  for (String imgPath : img.getPaths()) {
1475  summary.append("<tr><td>").append( //NON-NLS
1476  NbBundle.getMessage(this.getClass(), "ReportHTML.writeSum.path"))
1477  .append("</td><td>").append(imgPath).append("</td></tr>\n"); //NON-NLS
1478  }
1479  summary.append("</table>\n"); //NON-NLS
1480  }
1481  }
1482  } catch (TskCoreException ex) {
1483  logger.log(Level.WARNING, "Unable to get image information for the HTML report."); //NON-NLS
1484  }
1485  summary.append("</div>\n"); //NON-NLS
1486  return summary;
1487  }
1488 
1494  private StringBuilder writeSummarySoftwareInfo(SleuthkitCase skCase, List<IngestJobInfo> ingestJobs) {
1495  StringBuilder summary = new StringBuilder();
1496  summary.append(NbBundle.getMessage(this.getClass(), "ReportHTML.writeSum.softwareInfoHeading"));
1497  summary.append("<div class=\"info\">\n");
1498  summary.append("<table>\n");
1499  summary.append("<tr><td>").append(NbBundle.getMessage(this.getClass(), "ReportHTML.writeSum.autopsyVersion"))
1500  .append("</td><td>").append(Version.getVersion()).append("</td></tr>\n");
1501  Map<Long, IngestModuleInfo> moduleInfoHashMap = new HashMap<>();
1502  for (IngestJobInfo ingestJob : ingestJobs) {
1503  List<IngestModuleInfo> ingestModules = ingestJob.getIngestModuleInfo();
1504  for (IngestModuleInfo ingestModule : ingestModules) {
1505  if (!moduleInfoHashMap.containsKey(ingestModule.getIngestModuleId())) {
1506  moduleInfoHashMap.put(ingestModule.getIngestModuleId(), ingestModule);
1507  }
1508  }
1509  }
1510  TreeMap<String, String> modules = new TreeMap<>();
1511  for (IngestModuleInfo moduleinfo : moduleInfoHashMap.values()) {
1512  modules.put(moduleinfo.getDisplayName(), moduleinfo.getVersion());
1513  }
1514  for (Map.Entry<String, String> module : modules.entrySet()) {
1515  summary.append("<tr><td>").append(module.getKey()).append(" Module:")
1516  .append("</td><td>").append(module.getValue()).append("</td></tr>\n");
1517  }
1518  summary.append("</table>\n");
1519  summary.append("</div>\n");
1520  summary.append("<div class=\"clear\"></div>\n"); //NON-NLS
1521  return summary;
1522  }
1523 
1529  private StringBuilder writeSummaryIngestHistoryInfo(SleuthkitCase skCase, List<IngestJobInfo> ingestJobs) {
1530  StringBuilder summary = new StringBuilder();
1531  try {
1532  summary.append(NbBundle.getMessage(this.getClass(), "ReportHTML.writeSum.ingestHistoryHeading"));
1533  summary.append("<div class=\"info\">\n");
1534  int jobnumber = 1;
1535 
1536  for (IngestJobInfo ingestJob : ingestJobs) {
1537  summary.append("<h3>Job ").append(jobnumber).append(":</h3>\n");
1538  summary.append("<table>\n");
1539  summary.append("<tr><td>").append("Data Source:")
1540  .append("</td><td>").append(skCase.getContentById(ingestJob.getObjectId()).getName()).append("</td></tr>\n");
1541  summary.append("<tr><td>").append("Status:")
1542  .append("</td><td>").append(ingestJob.getStatus()).append("</td></tr>\n");
1543  summary.append("<tr><td>").append(NbBundle.getMessage(this.getClass(), "ReportHTML.writeSum.modulesEnabledHeading"))
1544  .append("</td><td>");
1545  List<IngestModuleInfo> ingestModules = ingestJob.getIngestModuleInfo();
1546  summary.append("<ul>\n");
1547  for (IngestModuleInfo ingestModule : ingestModules) {
1548  summary.append("<li>").append(ingestModule.getDisplayName()).append("</li>");
1549  }
1550  summary.append("</ul>\n");
1551  jobnumber++;
1552  summary.append("</td></tr>\n");
1553  summary.append("</table>\n");
1554  }
1555  summary.append("</div>\n");
1556  } catch (TskCoreException ex) {
1557  logger.log(Level.WARNING, "Unable to get ingest jobs for the HTML report.");
1558  }
1559  return summary;
1560  }
1561 
1570  private String prepareThumbnail(AbstractFile file) {
1571  BufferedImage bufferedThumb = ImageUtils.getThumbnail(file, ImageUtils.ICON_SIZE_MEDIUM);
1572 
1573  /*
1574  * File name is normalized to account for possible attribute name which
1575  * will be separated by a ':' character.
1576  */
1577  String fileName = org.sleuthkit.autopsy.coreutils.FileUtil.escapeFileName(file.getName());
1578 
1579  File thumbFile = Paths.get(thumbsPath, fileName + ".png").toFile();
1580  if (bufferedThumb == null) {
1581  return null;
1582  }
1583  try {
1584  ImageIO.write(bufferedThumb, "png", thumbFile);
1585  } catch (IOException ex) {
1586  logger.log(Level.WARNING, "Failed to write thumb file to report directory.", ex); //NON-NLS
1587  return null;
1588  }
1589  if (thumbFile.exists()
1590  == false) {
1591  return null;
1592  }
1593  return THUMBS_REL_PATH
1594  + thumbFile.getName();
1595  }
1596 
1605  private String formatHtmlString(String text) {
1606  String formattedString = StringEscapeUtils.escapeHtml4(text);
1607  return formattedString.replaceAll("(\r\n|\r|\n|\n\r)", "<br>");
1608  }
1609 
1610 }
List< Content > getDataSources()
Definition: Case.java:1668
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:1891
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:2978
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-2021 Basis Technology. Generated on: Thu Jul 8 2021
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.