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