23 package org.sleuthkit.autopsy.report;
25 import java.awt.image.BufferedImage;
26 import java.io.BufferedWriter;
28 import java.io.FileNotFoundException;
29 import java.io.FileOutputStream;
30 import java.io.IOException;
31 import java.io.InputStream;
32 import java.io.OutputStream;
33 import java.io.OutputStreamWriter;
34 import java.io.UnsupportedEncodingException;
35 import java.io.Writer;
36 import java.nio.file.Files;
37 import java.nio.file.Path;
38 import java.nio.file.Paths;
39 import java.text.DateFormat;
40 import java.text.SimpleDateFormat;
41 import java.util.ArrayList;
42 import java.util.Date;
43 import java.util.HashMap;
44 import java.util.List;
47 import java.util.TreeMap;
48 import java.util.logging.Level;
49 import javax.imageio.ImageIO;
50 import org.openide.filesystems.FileUtil;
51 import org.openide.util.NbBundle;
64 import org.
sleuthkit.datamodel.BlackboardArtifact.ARTIFACT_TYPE;
73 import org.
sleuthkit.datamodel.TskData.TSK_DB_FILES_TYPE_ENUM;
75 class ReportHTML
implements TableReportModule {
77 private static final Logger logger = Logger.getLogger(ReportHTML.class.getName());
78 private static final String THUMBS_REL_PATH =
"thumbs" + File.separator;
79 private static ReportHTML instance;
80 private static final int MAX_THUMBS_PER_PAGE = 1000;
81 private static final String HTML_SUBDIR =
"content";
82 private Case currentCase;
83 private SleuthkitCase skCase;
84 static Integer THUMBNAIL_COLUMNS = 5;
86 private Map<String, Integer> dataTypes;
88 private String thumbsPath;
89 private String subPath;
90 private String currentDataType;
91 private Integer rowCount;
94 private final ReportBranding reportBranding;
97 public static synchronized ReportHTML getDefault() {
98 if (instance == null) {
99 instance =
new ReportHTML();
105 private ReportHTML() {
106 reportBranding =
new ReportBranding();
110 private void refresh() throws NoCurrentCaseException {
111 currentCase = Case.getCurrentCaseThrows();
112 skCase = currentCase.getSleuthkitCase();
114 dataTypes =
new TreeMap<>();
119 currentDataType =
"";
125 }
catch (IOException ex) {
137 private String dataTypeToFileName(String dataType) {
141 fileName = fileName.replaceAll(
" ",
"_");
150 private String useDataTypeIcon(String dataType) {
154 OutputStream output = null;
156 logger.log(Level.INFO,
"useDataTypeIcon: dataType = {0}", dataType);
159 BlackboardArtifact.ARTIFACT_TYPE artifactType = null;
160 for (ARTIFACT_TYPE v : ARTIFACT_TYPE.values()) {
161 if (v.getDisplayName().equals(dataType)) {
166 if (null != artifactType) {
168 iconFileName = dataTypeToFileName(artifactType.getDisplayName()) +
".png";
169 iconFilePath = subPath + File.separator + iconFileName;
172 switch (artifactType) {
173 case TSK_WEB_BOOKMARK:
174 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/bookmarks.png");
177 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/cookies.png");
179 case TSK_WEB_HISTORY:
180 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/history.png");
182 case TSK_WEB_DOWNLOAD:
183 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/downloads.png");
185 case TSK_RECENT_OBJECT:
186 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/recent.png");
188 case TSK_INSTALLED_PROG:
189 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/installed.png");
191 case TSK_KEYWORD_HIT:
192 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/keywords.png");
194 case TSK_HASHSET_HIT:
195 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/hash.png");
197 case TSK_DEVICE_ATTACHED:
198 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/devices.png");
200 case TSK_WEB_SEARCH_QUERY:
201 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/search.png");
203 case TSK_METADATA_EXIF:
204 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/exif.png");
207 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/userbookmarks.png");
209 case TSK_TAG_ARTIFACT:
210 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/userbookmarks.png");
212 case TSK_SERVICE_ACCOUNT:
213 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/account-icon-16.png");
216 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/contact.png");
219 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/message.png");
222 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/calllog.png");
224 case TSK_CALENDAR_ENTRY:
225 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/calendar.png");
227 case TSK_SPEED_DIAL_ENTRY:
228 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/speeddialentry.png");
230 case TSK_BLUETOOTH_PAIRING:
231 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/bluetooth.png");
233 case TSK_GPS_BOOKMARK:
234 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/gpsfav.png");
236 case TSK_GPS_LAST_KNOWN_LOCATION:
237 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/gps-lastlocation.png");
240 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/gps-search.png");
243 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/computer.png");
245 case TSK_GPS_TRACKPOINT:
246 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/gps_trackpoint.png");
249 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/gps_trackpoint.png");
252 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/images/mail-icon-16.png");
254 case TSK_ENCRYPTION_SUSPECTED:
255 case TSK_ENCRYPTION_DETECTED:
256 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/images/encrypted-file.png");
258 case TSK_EXT_MISMATCH_DETECTED:
259 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/images/mismatch-16.png");
261 case TSK_INTERESTING_ARTIFACT_HIT:
262 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/images/interesting_item.png");
264 case TSK_INTERESTING_FILE_HIT:
265 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/images/interesting_item.png");
268 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/installed.png");
270 case TSK_REMOTE_DRIVE:
271 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/drive_network.png");
274 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/accounts.png");
277 logger.log(Level.WARNING,
"useDataTypeIcon: unhandled artifact type = " + dataType);
278 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/star.png");
279 iconFileName =
"star.png";
280 iconFilePath = subPath + File.separator + iconFileName;
283 }
else if (dataType.startsWith(ARTIFACT_TYPE.TSK_ACCOUNT.getDisplayName())) {
291 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/accounts.png");
292 iconFileName =
"accounts.png";
293 iconFilePath = subPath + File.separator + iconFileName;
295 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/star.png");
296 iconFileName =
"star.png";
297 iconFilePath = subPath + File.separator + iconFileName;
301 output =
new FileOutputStream(iconFilePath);
302 FileUtil.copy(in, output);
305 }
catch (IOException ex) {
306 logger.log(Level.SEVERE,
"Failed to extract images for HTML report.", ex);
308 if (output != null) {
312 }
catch (IOException ex) {
318 }
catch (IOException ex) {
333 public void startReport(String baseReportDir) {
337 }
catch (NoCurrentCaseException ex) {
338 logger.log(Level.SEVERE,
"Exception while getting open case.");
342 this.path = baseReportDir;
343 this.subPath = this.path + HTML_SUBDIR + File.separator;
344 this.thumbsPath = this.subPath + THUMBS_REL_PATH;
346 FileUtil.createFolder(
new File(this.subPath));
347 FileUtil.createFolder(
new File(this.thumbsPath));
348 }
catch (IOException ex) {
349 logger.log(Level.SEVERE,
"Unable to make HTML report folder.");
362 public void endReport() {
367 }
catch (IOException ex) {
368 logger.log(Level.WARNING,
"Could not close the output writer when ending report.", ex);
382 public void startDataType(String name, String description) {
383 String title = dataTypeToFileName(name);
385 out =
new BufferedWriter(
new OutputStreamWriter(
new FileOutputStream(subPath + title +
".html"),
"UTF-8"));
386 }
catch (FileNotFoundException ex) {
387 logger.log(Level.SEVERE,
"File not found: {0}", ex);
388 }
catch (UnsupportedEncodingException ex) {
389 logger.log(Level.SEVERE,
"Unrecognized encoding");
393 StringBuilder page =
new StringBuilder();
394 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");
395 page.append(
"<div id=\"header\">").append(name).append(
"</div>\n<div id=\"content\">\n");
396 if (!description.isEmpty()) {
397 page.append(
"<p><strong>");
398 page.append(description);
399 page.append(
"</string></p>\n");
401 out.write(page.toString());
402 currentDataType = name;
404 }
catch (IOException ex) {
405 logger.log(Level.SEVERE,
"Failed to write page head: {0}", ex);
414 public void endDataType() {
415 dataTypes.put(currentDataType, rowCount);
417 out.write(
"</div>\n</body>\n</html>\n");
418 }
catch (IOException ex) {
419 logger.log(Level.SEVERE,
"Failed to write end of HTML report.", ex);
425 }
catch (IOException ex) {
426 logger.log(Level.WARNING,
"Could not close the output writer when ending data type.", ex);
439 public void startSet(String setName) {
440 StringBuilder set =
new StringBuilder();
441 set.append(
"<h1><a name=\"").append(setName).append(
"\">").append(setName).append(
"</a></h1>\n");
442 set.append(
"<div class=\"keyword_list\">\n");
445 out.write(set.toString());
446 }
catch (IOException ex) {
447 logger.log(Level.SEVERE,
"Failed to write set: {0}", ex);
455 public void endSet() {
457 out.write(
"</div>\n");
458 }
catch (IOException ex) {
459 logger.log(Level.SEVERE,
"Failed to write end of set: {0}", ex);
469 public void addSetIndex(List<String> sets) {
470 StringBuilder index =
new StringBuilder();
471 index.append(
"<ul>\n");
472 for (String set : sets) {
473 index.append(
"\t<li><a href=\"#").append(set).append(
"\">").append(set).append(
"</a></li>\n");
475 index.append(
"</ul>\n");
477 out.write(index.toString());
478 }
catch (IOException ex) {
479 logger.log(Level.SEVERE,
"Failed to add set index: {0}", ex);
489 public void addSetElement(String elementName) {
491 out.write(
"<h4>" + elementName +
"</h4>\n");
492 }
catch (IOException ex) {
493 logger.log(Level.SEVERE,
"Failed to write set element: {0}", ex);
503 public void startTable(List<String> titles) {
504 StringBuilder ele =
new StringBuilder();
505 ele.append(
"<table>\n<thead>\n\t<tr>\n");
506 for (String title : titles) {
507 ele.append(
"\t\t<th>").append(title).append(
"</th>\n");
509 ele.append(
"\t</tr>\n</thead>\n");
512 out.write(ele.toString());
513 }
catch (IOException ex) {
514 logger.log(Level.SEVERE,
"Failed to write table start: {0}", ex);
525 public void startContentTagsTable(List<String> columnHeaders) {
526 StringBuilder htmlOutput =
new StringBuilder();
527 htmlOutput.append(
"<table>\n<thead>\n\t<tr>\n");
530 for (String columnHeader : columnHeaders) {
531 htmlOutput.append(
"\t\t<th>").append(columnHeader).append(
"</th>\n");
535 htmlOutput.append(
"\t\t<th></th>\n");
537 htmlOutput.append(
"\t</tr>\n</thead>\n");
540 out.write(htmlOutput.toString());
541 }
catch (IOException ex) {
542 logger.log(Level.SEVERE,
"Failed to write table start: {0}", ex);
550 public void endTable() {
552 out.write(
"</table>\n");
553 }
catch (IOException ex) {
554 logger.log(Level.SEVERE,
"Failed to write end of table: {0}", ex);
564 public void addRow(List<String> row) {
565 StringBuilder builder =
new StringBuilder();
566 builder.append(
"\t<tr>\n");
567 for (String cell : row) {
568 String escapeHTMLCell = EscapeUtil.escapeHtml(cell);
569 builder.append(
"\t\t<td>").append(escapeHTMLCell).append(
"</td>\n");
571 builder.append(
"\t</tr>\n");
575 out.write(builder.toString());
576 }
catch (IOException ex) {
577 logger.log(Level.SEVERE,
"Failed to write row to out.", ex);
578 }
catch (NullPointerException ex) {
579 logger.log(Level.SEVERE,
"Output writer is null. Page was not initialized before writing.", ex);
593 public void addRowWithTaggedContentHyperlink(List<String> row, ContentTag contentTag) {
594 Content content = contentTag.getContent();
595 if (content instanceof AbstractFile ==
false) {
599 AbstractFile file = (AbstractFile) content;
601 StringBuilder localFileLink =
new StringBuilder();
604 || file.getType() == TSK_DB_FILES_TYPE_ENUM.UNALLOC_BLOCKS
605 || file.getType() == TSK_DB_FILES_TYPE_ENUM.UNUSED_BLOCKS)) {
606 localFileLink.append(
"<a href=\"");
608 String localFilePath = saveContent(file, contentTag.getName().getDisplayName());
609 localFileLink.append(localFilePath);
610 localFileLink.append(
"\" target=\"_top\">");
613 StringBuilder builder =
new StringBuilder();
614 builder.append(
"\t<tr>\n");
615 int positionCounter = 0;
616 for (String cell : row) {
618 if (positionCounter == 1) {
619 builder.append(
"\t\t<td class=\"left_align_cell\">").append(localFileLink.toString()).append(cell).append(
"</a></td>\n");
620 }
else if (positionCounter == 7) {
621 builder.append(
"\t\t<td class=\"right_align_cell\">").append(cell).append(
"</td>\n");
623 builder.append(
"\t\t<td>").append(cell).append(
"</td>\n");
627 builder.append(
"\t</tr>\n");
631 out.write(builder.toString());
632 }
catch (IOException ex) {
633 logger.log(Level.SEVERE,
"Failed to write row to out.", ex);
634 }
catch (NullPointerException ex) {
635 logger.log(Level.SEVERE,
"Output writer is null. Page was not initialized before writing.", ex);
644 public void addThumbnailRows(Set<Content> images) {
645 List<String> currentRow =
new ArrayList<>();
648 for (Content content : images) {
649 if (currentRow.size() == THUMBNAIL_COLUMNS) {
654 if (totalCount == MAX_THUMBS_PER_PAGE) {
658 rowCount = totalCount;
663 startDataType(NbBundle.getMessage(
this.getClass(),
"ReportHTML.addThumbRows.dataType.title", pages),
664 NbBundle.getMessage(
this.getClass(),
"ReportHTML.addThumbRows.dataType.msg"));
665 List<String> emptyHeaders =
new ArrayList<>();
666 for (
int i = 0; i < THUMBNAIL_COLUMNS; i++) {
667 emptyHeaders.add(
"");
669 startTable(emptyHeaders);
672 if (failsContentCheck(content)) {
676 AbstractFile file = (AbstractFile) content;
679 String thumbnailPath = prepareThumbnail(file);
680 if (thumbnailPath == null) {
683 String contentPath = saveContent(file,
"thumbs_fullsize");
686 nameInImage = file.getUniquePath();
687 }
catch (TskCoreException ex) {
688 nameInImage = file.getName();
691 StringBuilder linkToThumbnail =
new StringBuilder();
692 linkToThumbnail.append(
"<div id='thumbnail_link'>");
693 linkToThumbnail.append(
"<a href=\"");
694 linkToThumbnail.append(contentPath);
695 linkToThumbnail.append(
"\" target=\"_top\">");
696 linkToThumbnail.append(
"<img src=\"").append(thumbnailPath).append(
"\" title=\"").append(nameInImage).append(
"\"/>");
697 linkToThumbnail.append(
"</a><br>");
698 linkToThumbnail.append(file.getName()).append(
"<br>");
700 Services services = currentCase.getServices();
701 TagsManager tagsManager = services.getTagsManager();
703 List<ContentTag> tags = tagsManager.getContentTagsByContent(content);
704 if (tags.size() > 0) {
705 linkToThumbnail.append(NbBundle.getMessage(
this.getClass(),
"ReportHTML.thumbLink.tags"));
707 for (
int i = 0; i < tags.size(); i++) {
708 ContentTag tag = tags.get(i);
709 String notableString = tag.getName().getKnownStatus() == TskData.FileKnown.BAD ? TagsManager.getNotableTagLabel() :
"";
710 linkToThumbnail.append(tag.getName().getDisplayName() + notableString);
711 if (i != tags.size() - 1) {
712 linkToThumbnail.append(
", ");
715 }
catch (TskCoreException ex) {
716 logger.log(Level.WARNING,
"Could not find get tags for file.", ex);
718 linkToThumbnail.append(
"</div>");
719 currentRow.add(linkToThumbnail.toString());
724 if (currentRow.isEmpty() ==
false) {
725 int extraCells = THUMBNAIL_COLUMNS - currentRow.size();
726 for (
int i = 0; i < extraCells; i++) {
734 rowCount = totalCount;
737 private boolean failsContentCheck(Content c) {
738 if (c instanceof AbstractFile ==
false) {
741 AbstractFile file = (AbstractFile) c;
743 || file.getType() == TSK_DB_FILES_TYPE_ENUM.UNALLOC_BLOCKS
744 || file.getType() == TSK_DB_FILES_TYPE_ENUM.UNUSED_BLOCKS) {
759 public String saveContent(AbstractFile file, String dirName) {
764 StringBuilder localFilePath =
new StringBuilder();
766 localFilePath.append(subPath);
767 localFilePath.append(dirName2);
768 File localFileFolder =
new File(localFilePath.toString());
769 if (!localFileFolder.exists()) {
770 localFileFolder.mkdirs();
774 String fileName = file.getName();
775 String objectIdSuffix =
"_" + file.getId();
776 int lastDotIndex = fileName.lastIndexOf(
".");
777 if (lastDotIndex != -1 && lastDotIndex != 0) {
779 fileName = fileName.substring(0, lastDotIndex) + objectIdSuffix + fileName.substring(lastDotIndex, fileName.length());
783 fileName += objectIdSuffix;
785 localFilePath.append(File.separator);
786 localFilePath.append(fileName);
790 File localFile =
new File(localFilePath.toString());
791 if (!localFile.exists()) {
792 ExtractFscContentVisitor.extract(file, localFile, null, null);
796 return localFilePath.toString().substring(subPath.length());
807 public String dateToString(
long date) {
808 SimpleDateFormat sdf =
new java.text.SimpleDateFormat(
"yyyy/MM/dd HH:mm:ss");
809 return sdf.format(
new java.util.Date(date * 1000));
813 public String getRelativeFilePath() {
814 return "report.html";
818 public String getName() {
819 return NbBundle.getMessage(this.getClass(),
"ReportHTML.getName.text");
823 public String getDescription() {
824 return NbBundle.getMessage(this.getClass(),
"ReportHTML.getDesc.text");
830 private void writeCss() {
831 Writer cssOut = null;
833 cssOut =
new BufferedWriter(
new OutputStreamWriter(
new FileOutputStream(subPath +
"index.css"),
"UTF-8"));
834 String css =
"body {margin: 0px; padding: 0px; background: #FFFFFF; font: 13px/20px Arial, Helvetica, sans-serif; color: #535353;}\n"
836 "#content {padding: 30px;}\n"
838 "#header {width:100%; padding: 10px; line-height: 25px; background: #07A; color: #FFF; font-size: 20px;}\n"
840 "h1 {font-size: 20px; font-weight: normal; color: #07A; padding: 0 0 7px 0; margin-top: 25px; border-bottom: 1px solid #D6D6D6;}\n"
842 "h2 {font-size: 20px; font-weight: bolder; color: #07A;}\n"
844 "h3 {font-size: 16px; color: #07A;}\n"
846 "h4 {background: #07A; color: #FFF; font-size: 16px; margin: 0 0 0 25px; padding: 0; padding-left: 15px;}\n"
848 "ul.nav {list-style-type: none; line-height: 35px; padding: 0px; margin-left: 15px;}\n"
850 "ul li a {font-size: 14px; color: #444; text-decoration: none; padding-left: 25px;}\n"
852 "ul li a:hover {text-decoration: underline;}\n"
854 "p {margin: 0 0 20px 0;}\n"
856 "table {white-space:nowrap; min-width: 700px; padding: 2; margin: 0; border-collapse: collapse; border-bottom: 2px solid #e5e5e5;}\n"
858 ".keyword_list table {margin: 0 0 25px 25px; border-bottom: 2px solid #dedede;}\n"
860 "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"
862 "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"
864 "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"
866 "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"
868 "table tr:nth-child(even) td {background: #f3f3f3;}\n"
870 "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;}";
872 }
catch (FileNotFoundException ex) {
873 logger.log(Level.SEVERE,
"Could not find index.css file to write to.", ex);
874 }
catch (UnsupportedEncodingException ex) {
875 logger.log(Level.SEVERE,
"Did not recognize encoding when writing index.css.", ex);
876 }
catch (IOException ex) {
877 logger.log(Level.SEVERE,
"Error creating Writer for index.css.", ex);
880 if (cssOut != null) {
884 }
catch (IOException ex) {
892 private void writeIndex() {
893 Writer indexOut = null;
894 String indexFilePath = path +
"report.html";
897 openCase = Case.getCurrentCaseThrows();
898 }
catch (NoCurrentCaseException ex) {
899 logger.log(Level.SEVERE,
"Exception while getting open case.", ex);
903 indexOut =
new BufferedWriter(
new OutputStreamWriter(
new FileOutputStream(indexFilePath),
"UTF-8"));
904 StringBuilder index =
new StringBuilder();
905 final String reportTitle = reportBranding.getReportTitle();
906 String iconPath = reportBranding.getAgencyLogoPath();
907 if (iconPath == null) {
909 iconPath = HTML_SUBDIR +
"favicon.ico";
911 iconPath = Paths.get(reportBranding.getAgencyLogoPath()).getFileName().toString();
913 index.append(
"<head>\n<title>").append(reportTitle).append(
" ").append(
914 NbBundle.getMessage(
this.getClass(),
"ReportHTML.writeIndex.title", currentCase.getDisplayName())).append(
916 index.append(
"<link rel=\"icon\" type=\"image/ico\" href=\"")
917 .append(iconPath).append(
"\" />\n");
918 index.append(
"<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\n");
919 index.append(
"</head>\n");
920 index.append(
"<frameset cols=\"350px,*\">\n");
921 index.append(
"<frame src=\"" + HTML_SUBDIR).append(File.separator).append(
"nav.html\" name=\"nav\">\n");
922 index.append(
"<frame src=\"" + HTML_SUBDIR).append(File.separator).append(
"summary.html\" name=\"content\">\n");
923 index.append(
"<noframes>").append(NbBundle.getMessage(
this.getClass(),
"ReportHTML.writeIndex.noFrames.msg")).append(
"<br />\n");
924 index.append(NbBundle.getMessage(
this.getClass(),
"ReportHTML.writeIndex.noFrames.seeNav")).append(
"<br />\n");
925 index.append(NbBundle.getMessage(
this.getClass(),
"ReportHTML.writeIndex.seeSum")).append(
"</noframes>\n");
926 index.append(
"</frameset>\n");
927 index.append(
"</html>");
928 indexOut.write(index.toString());
929 openCase.addReport(indexFilePath, NbBundle.getMessage(
this.getClass(),
930 "ReportHTML.writeIndex.srcModuleName.text"),
"");
931 }
catch (IOException ex) {
932 logger.log(Level.SEVERE,
"Error creating Writer for report.html: {0}", ex);
933 }
catch (TskCoreException ex) {
934 String errorMessage = String.format(
"Error adding %s to case as a report", indexFilePath);
935 logger.log(Level.SEVERE, errorMessage, ex);
938 if (indexOut != null) {
942 }
catch (IOException ex) {
950 private void writeNav() {
951 Writer navOut = null;
953 navOut =
new BufferedWriter(
new OutputStreamWriter(
new FileOutputStream(subPath +
"nav.html"),
"UTF-8"));
954 StringBuilder nav =
new StringBuilder();
955 nav.append(
"<html>\n<head>\n\t<title>").append(
956 NbBundle.getMessage(
this.getClass(),
"ReportHTML.writeNav.title"))
957 .append(
"</title>\n\t<link rel=\"stylesheet\" type=\"text/css\" href=\"index.css\" />\n");
958 nav.append(
"<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\n</head>\n<body>\n");
959 nav.append(
"<div id=\"content\">\n<h1>").append(
960 NbBundle.getMessage(
this.getClass(),
"ReportHTML.writeNav.h1")).append(
"</h1>\n");
961 nav.append(
"<ul class=\"nav\">\n");
962 nav.append(
"<li style=\"background: url(summary.png) left center no-repeat;\"><a href=\"summary.html\" target=\"content\">")
963 .append(NbBundle.getMessage(
this.getClass(),
"ReportHTML.writeNav.summary")).append(
"</a></li>\n");
965 for (String dataType : dataTypes.keySet()) {
966 String dataTypeEsc = dataTypeToFileName(dataType);
967 String iconFileName = useDataTypeIcon(dataType);
968 nav.append(
"<li style=\"background: url('").append(iconFileName)
969 .append(
"') left center no-repeat;\"><a href=\"")
970 .append(dataTypeEsc).append(
".html\" target=\"content\">")
971 .append(dataType).append(
" (").append(dataTypes.get(dataType))
972 .append(
")</a></li>\n");
974 nav.append(
"</ul>\n");
975 nav.append(
"</div>\n</body>\n</html>");
976 navOut.write(nav.toString());
977 }
catch (IOException ex) {
978 logger.log(Level.SEVERE,
"Failed to write end of report navigation menu: {0}", ex);
980 if (navOut != null) {
984 }
catch (IOException ex) {
985 logger.log(Level.WARNING,
"Could not close navigation out writer.");
990 InputStream in = null;
991 OutputStream output = null;
995 String generatorLogoPath = reportBranding.getGeneratorLogoPath();
996 if (generatorLogoPath != null && !generatorLogoPath.isEmpty()) {
997 File from =
new File(generatorLogoPath);
998 File to =
new File(subPath);
999 FileUtil.copyFile(FileUtil.toFileObject(from), FileUtil.toFileObject(to),
"generator_logo");
1002 String agencyLogoPath = reportBranding.getAgencyLogoPath();
1003 if (agencyLogoPath != null && !agencyLogoPath.isEmpty()) {
1004 Path destinationPath = Paths.get(subPath);
1005 Files.copy(Files.newInputStream(Paths.get(agencyLogoPath)), destinationPath.resolve(Paths.get(agencyLogoPath).getFileName()));
1008 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/favicon.ico");
1009 output =
new FileOutputStream(
new File(subPath +
"favicon.ico"));
1010 FileUtil.copy(in, output);
1014 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/summary.png");
1015 output =
new FileOutputStream(
new File(subPath +
"summary.png"));
1016 FileUtil.copy(in, output);
1020 }
catch (IOException ex) {
1021 logger.log(Level.SEVERE,
"Failed to extract images for HTML report.", ex);
1023 if (output != null) {
1027 }
catch (IOException ex) {
1033 }
catch (IOException ex) {
1042 private void writeSummary() {
1045 out =
new BufferedWriter(
new OutputStreamWriter(
new FileOutputStream(subPath +
"summary.html"),
"UTF-8"));
1046 StringBuilder head =
new StringBuilder();
1047 head.append(
"<html>\n<head>\n<title>").append(
1048 NbBundle.getMessage(
this.getClass(),
"ReportHTML.writeSum.title")).append(
"</title>\n");
1049 head.append(
"<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\n");
1050 head.append(
"<style type=\"text/css\">\n");
1051 head.append(
"body { padding: 0px; margin: 0px; font: 13px/20px Arial, Helvetica, sans-serif; color: #535353; }\n");
1052 head.append(
"#wrapper { width: 90%; margin: 0px auto; margin-top: 35px; }\n");
1053 head.append(
"h1 { color: #07A; font-size: 36px; line-height: 42px; font-weight: normal; margin: 0px; border-bottom: 1px solid #81B9DB; }\n");
1054 head.append(
"h1 span { color: #F00; display: block; font-size: 16px; font-weight: bold; line-height: 22px;}\n");
1055 head.append(
"h2 { padding: 0 0 3px 0; margin: 0px; color: #07A; font-weight: normal; border-bottom: 1px dotted #81B9DB; }\n");
1056 head.append(
"h3 { padding: 5 0 3px 0; margin: 0px; color: #07A; font-weight: normal; }\n");
1057 head.append(
"table td { padding: 5px 25px 5px 0px; vertical-align:top;}\n");
1058 head.append(
"p.subheadding { padding: 0px; margin: 0px; font-size: 11px; color: #B5B5B5; }\n");
1059 head.append(
".title { width: 660px; margin-bottom: 50px; }\n");
1060 head.append(
".left { float: left; width: 250px; margin-top: 20px; text-align: center; }\n");
1061 head.append(
".left img { max-width: 250px; max-height: 250px; min-width: 200px; min-height: 200px; }\n");
1062 head.append(
".right { float: right; width: 385px; margin-top: 25px; font-size: 14px; }\n");
1063 head.append(
".clear { clear: both; }\n");
1064 head.append(
".info { padding: 10px 0;}\n");
1065 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");
1066 head.append(
".info table { margin: 10px 25px 10px 25px; }\n");
1067 head.append(
"ul {padding: 0;margin: 0;list-style-type: none;}");
1068 head.append(
"li {padding-bottom: 5px;}");
1069 head.append(
"</style>\n");
1070 head.append(
"</head>\n<body>\n");
1071 out.write(head.toString());
1073 DateFormat datetimeFormat =
new SimpleDateFormat(
"yyyy/MM/dd HH:mm:ss");
1074 Date date =
new Date();
1075 String datetime = datetimeFormat.format(date);
1077 StringBuilder summary =
new StringBuilder();
1078 boolean running =
false;
1079 if (IngestManager.getInstance().isIngestRunning()) {
1082 SleuthkitCase skCase = Case.getCurrentCaseThrows().getSleuthkitCase();
1083 List<IngestJobInfo> ingestJobs = skCase.getIngestJobs();
1084 final String reportTitle = reportBranding.getReportTitle();
1085 final String reportFooter = reportBranding.getReportFooter();
1086 final boolean generatorLogoSet = reportBranding.getGeneratorLogoPath() != null && !reportBranding.getGeneratorLogoPath().isEmpty();
1088 summary.append(
"<div id=\"wrapper\">\n");
1089 summary.append(
"<h1>").append(reportTitle)
1090 .append(running ? NbBundle.getMessage(
this.getClass(),
"ReportHTML.writeSum.warningMsg") :
"")
1092 summary.append(
"<p class=\"subheadding\">").append(
1093 NbBundle.getMessage(
this.getClass(),
"ReportHTML.writeSum.reportGenOn.text", datetime)).append(
"</p>\n");
1094 summary.append(
"<div class=\"title\">\n");
1095 summary.append(writeSummaryCaseDetails());
1096 summary.append(writeSummaryImageInfo());
1097 summary.append(writeSummarySoftwareInfo(skCase,ingestJobs));
1098 summary.append(writeSummaryIngestHistoryInfo(skCase,ingestJobs));
1099 if (generatorLogoSet) {
1100 summary.append(
"<div class=\"left\">\n");
1101 summary.append(
"<img src=\"generator_logo.png\" />\n");
1102 summary.append(
"</div>\n");
1104 summary.append(
"<div class=\"clear\"></div>\n");
1105 if (reportFooter != null) {
1106 summary.append(
"<p class=\"subheadding\">").append(reportFooter).append(
"</p>\n");
1108 summary.append(
"</div>\n");
1109 summary.append(
"</body></html>");
1110 out.write(summary.toString());
1111 }
catch (FileNotFoundException ex) {
1112 logger.log(Level.SEVERE,
"Could not find summary.html file to write to.");
1113 }
catch (UnsupportedEncodingException ex) {
1114 logger.log(Level.SEVERE,
"Did not recognize encoding when writing summary.hmtl.");
1115 }
catch (IOException ex) {
1116 logger.log(Level.SEVERE,
"Error creating Writer for summary.html.");
1117 }
catch (NoCurrentCaseException | TskCoreException ex) {
1118 logger.log(Level.WARNING,
"Unable to get current sleuthkit Case for the HTML report.");
1125 }
catch (IOException ex) {
1136 private StringBuilder writeSummaryCaseDetails(){
1137 StringBuilder summary =
new StringBuilder();
1138 String caseName = currentCase.getDisplayName();
1139 String caseNumber = currentCase.getNumber();
1140 String examiner = currentCase.getExaminer();
1141 final boolean agencyLogoSet = reportBranding.getAgencyLogoPath() != null && !reportBranding.getAgencyLogoPath().isEmpty();
1144 imagecount = currentCase.getDataSources().size();
1145 }
catch (TskCoreException ex) {
1148 summary.append(
"<div class=\"title\">\n");
1149 if (agencyLogoSet) {
1150 summary.append(
"<div class=\"left\">\n");
1151 summary.append(
"<img src=\"");
1152 summary.append(Paths.get(reportBranding.getAgencyLogoPath()).getFileName().toString());
1153 summary.append(
"\" />\n");
1154 summary.append(
"</div>\n");
1156 final String align = agencyLogoSet ?
"right" :
"left";
1157 summary.append(
"<div class=\"").append(align).append(
"\">\n");
1158 summary.append(
"<table>\n");
1159 summary.append(
"<tr><td>").append(NbBundle.getMessage(
this.getClass(),
"ReportHTML.writeSum.caseName"))
1160 .append(
"</td><td>").append(caseName).append(
"</td></tr>\n");
1161 summary.append(
"<tr><td>").append(NbBundle.getMessage(
this.getClass(),
"ReportHTML.writeSum.caseNum"))
1162 .append(
"</td><td>").append(!caseNumber.isEmpty() ? caseNumber : NbBundle
1163 .getMessage(this.getClass(),
"ReportHTML.writeSum.noCaseNum")).append(
"</td></tr>\n");
1164 summary.append(
"<tr><td>").append(NbBundle.getMessage(
this.getClass(),
"ReportHTML.writeSum.examiner")).append(
"</td><td>")
1165 .append(!examiner.isEmpty() ? examiner : NbBundle
1166 .getMessage(this.getClass(),
"ReportHTML.writeSum.noExaminer"))
1167 .append(
"</td></tr>\n");
1168 summary.append(
"<tr><td>").append(NbBundle.getMessage(
this.getClass(),
"ReportHTML.writeSum.numImages"))
1169 .append(
"</td><td>").append(imagecount).append(
"</td></tr>\n");
1170 summary.append(
"</table>\n");
1171 summary.append(
"</div>\n");
1172 summary.append(
"<div class=\"clear\"></div>\n");
1173 summary.append(
"</div>\n");
1183 private StringBuilder writeSummaryImageInfo() {
1184 StringBuilder summary =
new StringBuilder();
1185 summary.append(NbBundle.getMessage(
this.getClass(),
"ReportHTML.writeSum.imageInfoHeading"));
1186 summary.append(
"<div class=\"info\">\n");
1188 for (Content c : currentCase.getDataSources()) {
1189 summary.append(
"<p>").append(c.getName()).append(
"</p>\n");
1190 if (c instanceof Image) {
1191 Image img = (Image) c;
1193 summary.append(
"<table>\n");
1194 summary.append(
"<tr><td>").append(
1195 NbBundle.getMessage(
this.getClass(),
"ReportHTML.writeSum.timezone"))
1196 .append(
"</td><td>").append(img.getTimeZone()).append(
"</td></tr>\n");
1197 for (String imgPath : img.getPaths()) {
1198 summary.append(
"<tr><td>").append(
1199 NbBundle.getMessage(
this.getClass(),
"ReportHTML.writeSum.path"))
1200 .append(
"</td><td>").append(imgPath).append(
"</td></tr>\n");
1202 summary.append(
"</table>\n");
1205 }
catch (TskCoreException ex) {
1206 logger.log(Level.WARNING,
"Unable to get image information for the HTML report.");
1208 summary.append(
"</div>\n");
1218 private StringBuilder writeSummarySoftwareInfo(SleuthkitCase skCase, List<IngestJobInfo> ingestJobs) {
1219 StringBuilder summary =
new StringBuilder();
1220 summary.append(NbBundle.getMessage(
this.getClass(),
"ReportHTML.writeSum.softwareInfoHeading"));
1221 summary.append(
"<div class=\"info\">\n");
1222 summary.append(
"<table>\n");
1223 summary.append(
"<tr><td>").append(NbBundle.getMessage(
this.getClass(),
"ReportHTML.writeSum.autopsyVersion"))
1224 .append(
"</td><td>").append(Version.getVersion()).append(
"</td></tr>\n");
1225 Map<Long, IngestModuleInfo> moduleInfoHashMap =
new HashMap<>();
1226 for (IngestJobInfo ingestJob : ingestJobs) {
1227 List<IngestModuleInfo> ingestModules = ingestJob.getIngestModuleInfo();
1228 for (IngestModuleInfo ingestModule : ingestModules) {
1229 if (!moduleInfoHashMap.containsKey(ingestModule.getIngestModuleId())) {
1230 moduleInfoHashMap.put(ingestModule.getIngestModuleId(), ingestModule);
1234 TreeMap<String, String> modules =
new TreeMap<>();
1235 for (IngestModuleInfo moduleinfo : moduleInfoHashMap.values()) {
1236 modules.put(moduleinfo.getDisplayName(), moduleinfo.getVersion());
1238 for (Map.Entry<String, String> module : modules.entrySet()) {
1239 summary.append(
"<tr><td>").append(module.getKey()).append(
" Module:")
1240 .append(
"</td><td>").append(module.getValue()).append(
"</td></tr>\n");
1242 summary.append(
"</table>\n");
1243 summary.append(
"</div>\n");
1244 summary.append(
"<div class=\"clear\"></div>\n");
1254 private StringBuilder writeSummaryIngestHistoryInfo(SleuthkitCase skCase, List<IngestJobInfo> ingestJobs) {
1255 StringBuilder summary =
new StringBuilder();
1257 summary.append(NbBundle.getMessage(
this.getClass(),
"ReportHTML.writeSum.ingestHistoryHeading"));
1258 summary.append(
"<div class=\"info\">\n");
1261 for (IngestJobInfo ingestJob : ingestJobs) {
1262 summary.append(
"<h3>Job ").append(jobnumber).append(
":</h3>\n");
1263 summary.append(
"<table>\n");
1264 summary.append(
"<tr><td>").append(
"Data Source:")
1265 .append(
"</td><td>").append(skCase.getContentById(ingestJob.getObjectId()).getName()).append(
"</td></tr>\n");
1266 summary.append(
"<tr><td>").append(
"Status:")
1267 .append(
"</td><td>").append(ingestJob.getStatus()).append(
"</td></tr>\n");
1268 summary.append(
"<tr><td>").append(NbBundle.getMessage(
this.getClass(),
"ReportHTML.writeSum.modulesEnabledHeading"))
1269 .append(
"</td><td>");
1270 List<IngestModuleInfo> ingestModules = ingestJob.getIngestModuleInfo();
1271 summary.append(
"<ul>\n");
1272 for (IngestModuleInfo ingestModule : ingestModules) {
1273 summary.append(
"<li>").append(ingestModule.getDisplayName()).append(
"</li>");
1275 summary.append(
"</ul>\n");
1277 summary.append(
"</td></tr>\n");
1278 summary.append(
"</table>\n");
1280 summary.append(
"</div>\n");
1281 }
catch (TskCoreException ex) {
1282 logger.log(Level.WARNING,
"Unable to get ingest jobs for the HTML report.");
1287 private String prepareThumbnail(AbstractFile file) {
1288 BufferedImage bufferedThumb = ImageUtils.getThumbnail(file, ImageUtils.ICON_SIZE_MEDIUM);
1289 File thumbFile = Paths.get(thumbsPath, file.getName() +
".png").toFile();
1290 if (bufferedThumb == null) {
1294 ImageIO.write(bufferedThumb,
"png", thumbFile);
1295 }
catch (IOException ex) {
1296 logger.log(Level.WARNING,
"Failed to write thumb file to report directory.", ex);
1299 if (thumbFile.exists()
1303 return THUMBS_REL_PATH
1304 + thumbFile.getName();
static String escapeFileName(String fileName)