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 static Integer THUMBNAIL_COLUMNS = 5;
85 private Map<String, Integer> dataTypes;
87 private String thumbsPath;
88 private String subPath;
89 private String currentDataType;
90 private Integer rowCount;
93 private final ReportBranding reportBranding;
96 public static synchronized ReportHTML getDefault() {
97 if (instance == null) {
98 instance =
new ReportHTML();
104 private ReportHTML() {
105 reportBranding =
new ReportBranding();
109 private void refresh() throws NoCurrentCaseException {
110 currentCase = Case.getCurrentCaseThrows();
112 dataTypes =
new TreeMap<>();
117 currentDataType =
"";
123 }
catch (IOException ex) {
135 private String dataTypeToFileName(String dataType) {
139 fileName = fileName.replaceAll(
" ",
"_");
148 private String useDataTypeIcon(String dataType) {
152 OutputStream output = null;
154 logger.log(Level.INFO,
"useDataTypeIcon: dataType = {0}", dataType);
157 BlackboardArtifact.ARTIFACT_TYPE artifactType = null;
158 for (ARTIFACT_TYPE v : ARTIFACT_TYPE.values()) {
159 if (v.getDisplayName().equals(dataType)) {
164 if (null != artifactType) {
166 iconFileName = dataTypeToFileName(artifactType.getDisplayName()) +
".png";
167 iconFilePath = subPath + File.separator + iconFileName;
170 switch (artifactType) {
171 case TSK_WEB_BOOKMARK:
172 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/bookmarks.png");
175 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/cookies.png");
177 case TSK_WEB_HISTORY:
178 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/history.png");
180 case TSK_WEB_DOWNLOAD:
181 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/downloads.png");
183 case TSK_RECENT_OBJECT:
184 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/recent.png");
186 case TSK_INSTALLED_PROG:
187 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/installed.png");
189 case TSK_KEYWORD_HIT:
190 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/keywords.png");
192 case TSK_HASHSET_HIT:
193 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/hash.png");
195 case TSK_DEVICE_ATTACHED:
196 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/devices.png");
198 case TSK_WEB_SEARCH_QUERY:
199 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/search.png");
201 case TSK_METADATA_EXIF:
202 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/exif.png");
205 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/userbookmarks.png");
207 case TSK_TAG_ARTIFACT:
208 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/userbookmarks.png");
210 case TSK_SERVICE_ACCOUNT:
211 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/account-icon-16.png");
214 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/contact.png");
217 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/message.png");
220 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/calllog.png");
222 case TSK_CALENDAR_ENTRY:
223 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/calendar.png");
225 case TSK_SPEED_DIAL_ENTRY:
226 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/speeddialentry.png");
228 case TSK_BLUETOOTH_PAIRING:
229 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/bluetooth.png");
231 case TSK_GPS_BOOKMARK:
232 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/gpsfav.png");
234 case TSK_GPS_LAST_KNOWN_LOCATION:
235 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/gps-lastlocation.png");
238 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/gps-search.png");
241 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/computer.png");
243 case TSK_GPS_TRACKPOINT:
244 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/gps_trackpoint.png");
247 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/gps_trackpoint.png");
250 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/images/mail-icon-16.png");
252 case TSK_ENCRYPTION_SUSPECTED:
253 case TSK_ENCRYPTION_DETECTED:
254 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/images/encrypted-file.png");
256 case TSK_EXT_MISMATCH_DETECTED:
257 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/images/mismatch-16.png");
259 case TSK_INTERESTING_ARTIFACT_HIT:
260 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/images/interesting_item.png");
262 case TSK_INTERESTING_FILE_HIT:
263 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/images/interesting_item.png");
266 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/installed.png");
268 case TSK_REMOTE_DRIVE:
269 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/drive_network.png");
272 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/accounts.png");
275 logger.log(Level.WARNING,
"useDataTypeIcon: unhandled artifact type = {0}", dataType);
276 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/star.png");
277 iconFileName =
"star.png";
278 iconFilePath = subPath + File.separator + iconFileName;
281 }
else if (dataType.startsWith(ARTIFACT_TYPE.TSK_ACCOUNT.getDisplayName())) {
289 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/accounts.png");
290 iconFileName =
"accounts.png";
291 iconFilePath = subPath + File.separator + iconFileName;
293 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/star.png");
294 iconFileName =
"star.png";
295 iconFilePath = subPath + File.separator + iconFileName;
299 output =
new FileOutputStream(iconFilePath);
300 FileUtil.copy(in, output);
303 }
catch (IOException ex) {
304 logger.log(Level.SEVERE,
"Failed to extract images for HTML report.", ex);
306 if (output != null) {
310 }
catch (IOException ex) {
316 }
catch (IOException ex) {
331 public void startReport(String baseReportDir) {
335 }
catch (NoCurrentCaseException ex) {
336 logger.log(Level.SEVERE,
"Exception while getting open case.");
340 this.path = baseReportDir;
341 this.subPath = this.path + HTML_SUBDIR + File.separator;
342 this.thumbsPath = this.subPath + THUMBS_REL_PATH;
344 FileUtil.createFolder(
new File(this.subPath));
345 FileUtil.createFolder(
new File(this.thumbsPath));
346 }
catch (IOException ex) {
347 logger.log(Level.SEVERE,
"Unable to make HTML report folder.");
360 public void endReport() {
365 }
catch (IOException ex) {
366 logger.log(Level.WARNING,
"Could not close the output writer when ending report.", ex);
380 public void startDataType(String name, String description) {
381 String title = dataTypeToFileName(name);
383 out =
new BufferedWriter(
new OutputStreamWriter(
new FileOutputStream(subPath + title +
".html"),
"UTF-8"));
384 }
catch (FileNotFoundException ex) {
385 logger.log(Level.SEVERE,
"File not found: {0}", ex);
386 }
catch (UnsupportedEncodingException ex) {
387 logger.log(Level.SEVERE,
"Unrecognized encoding");
391 StringBuilder page =
new StringBuilder();
392 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");
393 page.append(
"<div id=\"header\">").append(name).append(
"</div>\n<div id=\"content\">\n");
394 if (!description.isEmpty()) {
395 page.append(
"<p><strong>");
396 page.append(description);
397 page.append(
"</string></p>\n");
399 out.write(page.toString());
400 currentDataType = name;
402 }
catch (IOException ex) {
403 logger.log(Level.SEVERE,
"Failed to write page head: {0}", ex);
412 public void endDataType() {
413 dataTypes.put(currentDataType, rowCount);
415 out.write(
"</div>\n</body>\n</html>\n");
416 }
catch (IOException ex) {
417 logger.log(Level.SEVERE,
"Failed to write end of HTML report.", ex);
423 }
catch (IOException ex) {
424 logger.log(Level.WARNING,
"Could not close the output writer when ending data type.", ex);
437 public void startSet(String setName) {
438 StringBuilder set =
new StringBuilder();
439 set.append(
"<h1><a name=\"").append(setName).append(
"\">").append(setName).append(
"</a></h1>\n");
440 set.append(
"<div class=\"keyword_list\">\n");
443 out.write(set.toString());
444 }
catch (IOException ex) {
445 logger.log(Level.SEVERE,
"Failed to write set: {0}", ex);
453 public void endSet() {
455 out.write(
"</div>\n");
456 }
catch (IOException ex) {
457 logger.log(Level.SEVERE,
"Failed to write end of set: {0}", ex);
467 public void addSetIndex(List<String> sets) {
468 StringBuilder index =
new StringBuilder();
469 index.append(
"<ul>\n");
470 for (String set : sets) {
471 index.append(
"\t<li><a href=\"#").append(set).append(
"\">").append(set).append(
"</a></li>\n");
473 index.append(
"</ul>\n");
475 out.write(index.toString());
476 }
catch (IOException ex) {
477 logger.log(Level.SEVERE,
"Failed to add set index: {0}", ex);
487 public void addSetElement(String elementName) {
489 out.write(
"<h4>" + elementName +
"</h4>\n");
490 }
catch (IOException ex) {
491 logger.log(Level.SEVERE,
"Failed to write set element: {0}", ex);
501 public void startTable(List<String> titles) {
502 StringBuilder ele =
new StringBuilder();
503 ele.append(
"<table>\n<thead>\n\t<tr>\n");
504 for (String title : titles) {
505 ele.append(
"\t\t<th>").append(title).append(
"</th>\n");
507 ele.append(
"\t</tr>\n</thead>\n");
510 out.write(ele.toString());
511 }
catch (IOException ex) {
512 logger.log(Level.SEVERE,
"Failed to write table start: {0}", ex);
523 public void startContentTagsTable(List<String> columnHeaders) {
524 StringBuilder htmlOutput =
new StringBuilder();
525 htmlOutput.append(
"<table>\n<thead>\n\t<tr>\n");
528 for (String columnHeader : columnHeaders) {
529 htmlOutput.append(
"\t\t<th>").append(columnHeader).append(
"</th>\n");
533 htmlOutput.append(
"\t\t<th></th>\n");
535 htmlOutput.append(
"\t</tr>\n</thead>\n");
538 out.write(htmlOutput.toString());
539 }
catch (IOException ex) {
540 logger.log(Level.SEVERE,
"Failed to write table start: {0}", ex);
548 public void endTable() {
550 out.write(
"</table>\n");
551 }
catch (IOException ex) {
552 logger.log(Level.SEVERE,
"Failed to write end of table: {0}", ex);
563 public void addRow(List<String> row) {
574 private void addRow(List<String> row,
boolean escapeText) {
575 StringBuilder builder =
new StringBuilder();
576 builder.append(
"\t<tr>\n");
577 for (String cell : row) {
578 String cellText = escapeText ? EscapeUtil.escapeHtml(cell) : cell;
579 builder.append(
"\t\t<td>").append(cellText).append(
"</td>\n");
581 builder.append(
"\t</tr>\n");
585 out.write(builder.toString());
586 }
catch (IOException ex) {
587 logger.log(Level.SEVERE,
"Failed to write row to out.", ex);
588 }
catch (NullPointerException ex) {
589 logger.log(Level.SEVERE,
"Output writer is null. Page was not initialized before writing.", ex);
603 public void addRowWithTaggedContentHyperlink(List<String> row, ContentTag contentTag) {
604 Content content = contentTag.getContent();
605 if (content instanceof AbstractFile ==
false) {
609 AbstractFile file = (AbstractFile) content;
611 StringBuilder localFileLink =
new StringBuilder();
614 || file.getType() == TSK_DB_FILES_TYPE_ENUM.UNALLOC_BLOCKS
615 || file.getType() == TSK_DB_FILES_TYPE_ENUM.UNUSED_BLOCKS)) {
616 localFileLink.append(
"<a href=\"");
618 String localFilePath = saveContent(file, contentTag.getName().getDisplayName());
619 localFileLink.append(localFilePath);
620 localFileLink.append(
"\" target=\"_top\">");
623 StringBuilder builder =
new StringBuilder();
624 builder.append(
"\t<tr>\n");
625 int positionCounter = 0;
626 for (String cell : row) {
628 switch (positionCounter) {
631 builder.append(
"\t\t<td class=\"left_align_cell\">").append(localFileLink.toString()).append(cell).append(
"</a></td>\n");
635 builder.append(
"\t\t<td class=\"right_align_cell\">").append(cell).append(
"</td>\n");
639 builder.append(
"\t\t<td>").append(cell).append(
"</td>\n");
644 builder.append(
"\t</tr>\n");
648 out.write(builder.toString());
649 }
catch (IOException ex) {
650 logger.log(Level.SEVERE,
"Failed to write row to out.", ex);
651 }
catch (NullPointerException ex) {
652 logger.log(Level.SEVERE,
"Output writer is null. Page was not initialized before writing.", ex);
661 public void addThumbnailRows(Set<Content> images) {
662 List<String> currentRow =
new ArrayList<>();
665 for (Content content : images) {
666 if (currentRow.size() == THUMBNAIL_COLUMNS) {
667 addRow(currentRow,
false);
671 if (totalCount == MAX_THUMBS_PER_PAGE) {
675 rowCount = totalCount;
680 startDataType(NbBundle.getMessage(
this.getClass(),
"ReportHTML.addThumbRows.dataType.title", pages),
681 NbBundle.getMessage(
this.getClass(),
"ReportHTML.addThumbRows.dataType.msg"));
682 List<String> emptyHeaders =
new ArrayList<>();
683 for (
int i = 0; i < THUMBNAIL_COLUMNS; i++) {
684 emptyHeaders.add(
"");
686 startTable(emptyHeaders);
689 if (failsContentCheck(content)) {
693 AbstractFile file = (AbstractFile) content;
696 String thumbnailPath = prepareThumbnail(file);
697 if (thumbnailPath == null) {
700 String contentPath = saveContent(file,
"thumbs_fullsize");
703 nameInImage = file.getUniquePath();
704 }
catch (TskCoreException ex) {
705 nameInImage = file.getName();
708 StringBuilder linkToThumbnail =
new StringBuilder();
709 linkToThumbnail.append(
"<div id='thumbnail_link'>");
710 linkToThumbnail.append(
"<a href=\"");
711 linkToThumbnail.append(contentPath);
712 linkToThumbnail.append(
"\" target=\"_top\">");
713 linkToThumbnail.append(
"<img src=\"").append(thumbnailPath).append(
"\" title=\"").append(nameInImage).append(
"\"/>");
714 linkToThumbnail.append(
"</a><br>");
715 linkToThumbnail.append(file.getName()).append(
"<br>");
717 Services services = currentCase.getServices();
718 TagsManager tagsManager = services.getTagsManager();
720 List<ContentTag> tags = tagsManager.getContentTagsByContent(content);
721 if (tags.size() > 0) {
722 linkToThumbnail.append(NbBundle.getMessage(
this.getClass(),
"ReportHTML.thumbLink.tags"));
724 for (
int i = 0; i < tags.size(); i++) {
725 ContentTag tag = tags.get(i);
726 String notableString = tag.getName().getKnownStatus() == TskData.FileKnown.BAD ? TagsManager.getNotableTagLabel() :
"";
727 linkToThumbnail.append(tag.getName().getDisplayName()).append(notableString);
728 if (i != tags.size() - 1) {
729 linkToThumbnail.append(
", ");
732 }
catch (TskCoreException ex) {
733 logger.log(Level.WARNING,
"Could not find get tags for file.", ex);
735 linkToThumbnail.append(
"</div>");
736 currentRow.add(linkToThumbnail.toString());
741 if (currentRow.isEmpty() ==
false) {
742 int extraCells = THUMBNAIL_COLUMNS - currentRow.size();
743 for (
int i = 0; i < extraCells; i++) {
747 addRow(currentRow,
false);
751 rowCount = totalCount;
754 private boolean failsContentCheck(Content c) {
755 if (c instanceof AbstractFile ==
false) {
758 AbstractFile file = (AbstractFile) c;
760 || file.getType() == TSK_DB_FILES_TYPE_ENUM.UNALLOC_BLOCKS
761 || file.getType() == TSK_DB_FILES_TYPE_ENUM.UNUSED_BLOCKS;
773 public String saveContent(AbstractFile file, String dirName) {
778 StringBuilder localFilePath =
new StringBuilder();
780 localFilePath.append(subPath);
781 localFilePath.append(dirName2);
782 File localFileFolder =
new File(localFilePath.toString());
783 if (!localFileFolder.exists()) {
784 localFileFolder.mkdirs();
795 String objectIdSuffix =
"_" + file.getId();
796 int lastDotIndex = fileName.lastIndexOf(
".");
797 if (lastDotIndex != -1 && lastDotIndex != 0) {
799 fileName = fileName.substring(0, lastDotIndex) + objectIdSuffix + fileName.substring(lastDotIndex, fileName.length());
803 fileName += objectIdSuffix;
805 localFilePath.append(File.separator);
806 localFilePath.append(fileName);
810 File localFile =
new File(localFilePath.toString());
811 if (!localFile.exists()) {
812 ExtractFscContentVisitor.extract(file, localFile, null, null);
816 return localFilePath.toString().substring(subPath.length());
827 public String dateToString(
long date) {
828 SimpleDateFormat sdf =
new java.text.SimpleDateFormat(
"yyyy/MM/dd HH:mm:ss");
829 return sdf.format(
new java.util.Date(date * 1000));
833 public String getRelativeFilePath() {
834 return "report.html";
838 public String getName() {
839 return NbBundle.getMessage(this.getClass(),
"ReportHTML.getName.text");
843 public String getDescription() {
844 return NbBundle.getMessage(this.getClass(),
"ReportHTML.getDesc.text");
850 private void writeCss() {
851 Writer cssOut = null;
853 cssOut =
new BufferedWriter(
new OutputStreamWriter(
new FileOutputStream(subPath +
"index.css"),
"UTF-8"));
854 String css =
"body {margin: 0px; padding: 0px; background: #FFFFFF; font: 13px/20px Arial, Helvetica, sans-serif; color: #535353;}\n"
856 "#content {padding: 30px;}\n"
858 "#header {width:100%; padding: 10px; line-height: 25px; background: #07A; color: #FFF; font-size: 20px;}\n"
860 "h1 {font-size: 20px; font-weight: normal; color: #07A; padding: 0 0 7px 0; margin-top: 25px; border-bottom: 1px solid #D6D6D6;}\n"
862 "h2 {font-size: 20px; font-weight: bolder; color: #07A;}\n"
864 "h3 {font-size: 16px; color: #07A;}\n"
866 "h4 {background: #07A; color: #FFF; font-size: 16px; margin: 0 0 0 25px; padding: 0; padding-left: 15px;}\n"
868 "ul.nav {list-style-type: none; line-height: 35px; padding: 0px; margin-left: 15px;}\n"
870 "ul li a {font-size: 14px; color: #444; text-decoration: none; padding-left: 25px;}\n"
872 "ul li a:hover {text-decoration: underline;}\n"
874 "p {margin: 0 0 20px 0;}\n"
876 "table {white-space:nowrap; min-width: 700px; padding: 2; margin: 0; border-collapse: collapse; border-bottom: 2px solid #e5e5e5;}\n"
878 ".keyword_list table {margin: 0 0 25px 25px; border-bottom: 2px solid #dedede;}\n"
880 "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"
882 "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"
884 "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"
886 "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"
888 "table tr:nth-child(even) td {background: #f3f3f3;}\n"
890 "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;}";
892 }
catch (FileNotFoundException ex) {
893 logger.log(Level.SEVERE,
"Could not find index.css file to write to.", ex);
894 }
catch (UnsupportedEncodingException ex) {
895 logger.log(Level.SEVERE,
"Did not recognize encoding when writing index.css.", ex);
896 }
catch (IOException ex) {
897 logger.log(Level.SEVERE,
"Error creating Writer for index.css.", ex);
900 if (cssOut != null) {
904 }
catch (IOException ex) {
912 private void writeIndex() {
913 Writer indexOut = null;
914 String indexFilePath = path +
"report.html";
917 openCase = Case.getCurrentCaseThrows();
918 }
catch (NoCurrentCaseException ex) {
919 logger.log(Level.SEVERE,
"Exception while getting open case.", ex);
923 indexOut =
new BufferedWriter(
new OutputStreamWriter(
new FileOutputStream(indexFilePath),
"UTF-8"));
924 StringBuilder index =
new StringBuilder();
925 final String reportTitle = reportBranding.getReportTitle();
926 String iconPath = reportBranding.getAgencyLogoPath();
927 if (iconPath == null) {
929 iconPath = HTML_SUBDIR +
"favicon.ico";
931 iconPath = Paths.get(reportBranding.getAgencyLogoPath()).getFileName().toString();
933 index.append(
"<head>\n<title>").append(reportTitle).append(
" ").append(
934 NbBundle.getMessage(
this.getClass(),
"ReportHTML.writeIndex.title", currentCase.getDisplayName())).append(
936 index.append(
"<link rel=\"icon\" type=\"image/ico\" href=\"")
937 .append(iconPath).append(
"\" />\n");
938 index.append(
"<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\n");
939 index.append(
"</head>\n");
940 index.append(
"<frameset cols=\"350px,*\">\n");
941 index.append(
"<frame src=\"" + HTML_SUBDIR).append(File.separator).append(
"nav.html\" name=\"nav\">\n");
942 index.append(
"<frame src=\"" + HTML_SUBDIR).append(File.separator).append(
"summary.html\" name=\"content\">\n");
943 index.append(
"<noframes>").append(NbBundle.getMessage(
this.getClass(),
"ReportHTML.writeIndex.noFrames.msg")).append(
"<br />\n");
944 index.append(NbBundle.getMessage(
this.getClass(),
"ReportHTML.writeIndex.noFrames.seeNav")).append(
"<br />\n");
945 index.append(NbBundle.getMessage(
this.getClass(),
"ReportHTML.writeIndex.seeSum")).append(
"</noframes>\n");
946 index.append(
"</frameset>\n");
947 index.append(
"</html>");
948 indexOut.write(index.toString());
949 openCase.addReport(indexFilePath, NbBundle.getMessage(
this.getClass(),
950 "ReportHTML.writeIndex.srcModuleName.text"),
"");
951 }
catch (IOException ex) {
952 logger.log(Level.SEVERE,
"Error creating Writer for report.html: {0}", ex);
953 }
catch (TskCoreException ex) {
954 String errorMessage = String.format(
"Error adding %s to case as a report", indexFilePath);
955 logger.log(Level.SEVERE, errorMessage, ex);
958 if (indexOut != null) {
962 }
catch (IOException ex) {
970 private void writeNav() {
971 Writer navOut = null;
973 navOut =
new BufferedWriter(
new OutputStreamWriter(
new FileOutputStream(subPath +
"nav.html"),
"UTF-8"));
974 StringBuilder nav =
new StringBuilder();
975 nav.append(
"<html>\n<head>\n\t<title>").append(
976 NbBundle.getMessage(
this.getClass(),
"ReportHTML.writeNav.title"))
977 .append(
"</title>\n\t<link rel=\"stylesheet\" type=\"text/css\" href=\"index.css\" />\n");
978 nav.append(
"<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\n</head>\n<body>\n");
979 nav.append(
"<div id=\"content\">\n<h1>").append(
980 NbBundle.getMessage(
this.getClass(),
"ReportHTML.writeNav.h1")).append(
"</h1>\n");
981 nav.append(
"<ul class=\"nav\">\n");
982 nav.append(
"<li style=\"background: url(summary.png) left center no-repeat;\"><a href=\"summary.html\" target=\"content\">")
983 .append(NbBundle.getMessage(
this.getClass(),
"ReportHTML.writeNav.summary")).append(
"</a></li>\n");
985 for (String dataType : dataTypes.keySet()) {
986 String dataTypeEsc = dataTypeToFileName(dataType);
987 String iconFileName = useDataTypeIcon(dataType);
988 nav.append(
"<li style=\"background: url('").append(iconFileName)
989 .append(
"') left center no-repeat;\"><a href=\"")
990 .append(dataTypeEsc).append(
".html\" target=\"content\">")
991 .append(dataType).append(
" (").append(dataTypes.get(dataType))
992 .append(
")</a></li>\n");
994 nav.append(
"</ul>\n");
995 nav.append(
"</div>\n</body>\n</html>");
996 navOut.write(nav.toString());
997 }
catch (IOException ex) {
998 logger.log(Level.SEVERE,
"Failed to write end of report navigation menu: {0}", ex);
1000 if (navOut != null) {
1004 }
catch (IOException ex) {
1005 logger.log(Level.WARNING,
"Could not close navigation out writer.");
1010 InputStream in = null;
1011 OutputStream output = null;
1015 String generatorLogoPath = reportBranding.getGeneratorLogoPath();
1016 if (generatorLogoPath != null && !generatorLogoPath.isEmpty()) {
1017 File from =
new File(generatorLogoPath);
1018 File to =
new File(subPath);
1019 FileUtil.copyFile(FileUtil.toFileObject(from), FileUtil.toFileObject(to),
"generator_logo");
1022 String agencyLogoPath = reportBranding.getAgencyLogoPath();
1023 if (agencyLogoPath != null && !agencyLogoPath.isEmpty()) {
1024 Path destinationPath = Paths.get(subPath);
1025 Files.copy(Files.newInputStream(Paths.get(agencyLogoPath)), destinationPath.resolve(Paths.get(agencyLogoPath).getFileName()));
1028 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/favicon.ico");
1029 output =
new FileOutputStream(
new File(subPath +
"favicon.ico"));
1030 FileUtil.copy(in, output);
1034 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/summary.png");
1035 output =
new FileOutputStream(
new File(subPath +
"summary.png"));
1036 FileUtil.copy(in, output);
1040 }
catch (IOException ex) {
1041 logger.log(Level.SEVERE,
"Failed to extract images for HTML report.", ex);
1043 if (output != null) {
1047 }
catch (IOException ex) {
1053 }
catch (IOException ex) {
1062 private void writeSummary() {
1063 Writer output = null;
1065 output =
new BufferedWriter(
new OutputStreamWriter(
new FileOutputStream(subPath +
"summary.html"),
"UTF-8"));
1066 StringBuilder head =
new StringBuilder();
1067 head.append(
"<html>\n<head>\n<title>").append(
1068 NbBundle.getMessage(
this.getClass(),
"ReportHTML.writeSum.title")).append(
"</title>\n");
1069 head.append(
"<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\n");
1070 head.append(
"<style type=\"text/css\">\n");
1071 head.append(
"body { padding: 0px; margin: 0px; font: 13px/20px Arial, Helvetica, sans-serif; color: #535353; }\n");
1072 head.append(
"#wrapper { width: 90%; margin: 0px auto; margin-top: 35px; }\n");
1073 head.append(
"h1 { color: #07A; font-size: 36px; line-height: 42px; font-weight: normal; margin: 0px; border-bottom: 1px solid #81B9DB; }\n");
1074 head.append(
"h1 span { color: #F00; display: block; font-size: 16px; font-weight: bold; line-height: 22px;}\n");
1075 head.append(
"h2 { padding: 0 0 3px 0; margin: 0px; color: #07A; font-weight: normal; border-bottom: 1px dotted #81B9DB; }\n");
1076 head.append(
"h3 { padding: 5 0 3px 0; margin: 0px; color: #07A; font-weight: normal; }\n");
1077 head.append(
"table td { padding: 5px 25px 5px 0px; vertical-align:top;}\n");
1078 head.append(
"p.subheadding { padding: 0px; margin: 0px; font-size: 11px; color: #B5B5B5; }\n");
1079 head.append(
".title { width: 660px; margin-bottom: 50px; }\n");
1080 head.append(
".left { float: left; width: 250px; margin-top: 20px; text-align: center; }\n");
1081 head.append(
".left img { max-width: 250px; max-height: 250px; min-width: 200px; min-height: 200px; }\n");
1082 head.append(
".right { float: right; width: 385px; margin-top: 25px; font-size: 14px; }\n");
1083 head.append(
".clear { clear: both; }\n");
1084 head.append(
".info { padding: 10px 0;}\n");
1085 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");
1086 head.append(
".info table { margin: 10px 25px 10px 25px; }\n");
1087 head.append(
"ul {padding: 0;margin: 0;list-style-type: none;}");
1088 head.append(
"li {padding-bottom: 5px;}");
1089 head.append(
"</style>\n");
1090 head.append(
"</head>\n<body>\n");
1091 output.write(head.toString());
1093 DateFormat datetimeFormat =
new SimpleDateFormat(
"yyyy/MM/dd HH:mm:ss");
1094 Date date =
new Date();
1095 String datetime = datetimeFormat.format(date);
1097 StringBuilder summary =
new StringBuilder();
1098 boolean running =
false;
1099 if (IngestManager.getInstance().isIngestRunning()) {
1102 SleuthkitCase skCase = Case.getCurrentCaseThrows().getSleuthkitCase();
1103 List<IngestJobInfo> ingestJobs = skCase.getIngestJobs();
1104 final String reportTitle = reportBranding.getReportTitle();
1105 final String reportFooter = reportBranding.getReportFooter();
1106 final boolean generatorLogoSet = reportBranding.getGeneratorLogoPath() != null && !reportBranding.getGeneratorLogoPath().isEmpty();
1108 summary.append(
"<div id=\"wrapper\">\n");
1109 summary.append(
"<h1>").append(reportTitle)
1110 .append(running ? NbBundle.getMessage(
this.getClass(),
"ReportHTML.writeSum.warningMsg") :
"")
1112 summary.append(
"<p class=\"subheadding\">").append(
1113 NbBundle.getMessage(
this.getClass(),
"ReportHTML.writeSum.reportGenOn.text", datetime)).append(
"</p>\n");
1114 summary.append(
"<div class=\"title\">\n");
1115 summary.append(writeSummaryCaseDetails());
1116 summary.append(writeSummaryImageInfo());
1117 summary.append(writeSummarySoftwareInfo(skCase, ingestJobs));
1118 summary.append(writeSummaryIngestHistoryInfo(skCase, ingestJobs));
1119 if (generatorLogoSet) {
1120 summary.append(
"<div class=\"left\">\n");
1121 summary.append(
"<img src=\"generator_logo.png\" />\n");
1122 summary.append(
"</div>\n");
1124 summary.append(
"<div class=\"clear\"></div>\n");
1125 if (reportFooter != null) {
1126 summary.append(
"<p class=\"subheadding\">").append(reportFooter).append(
"</p>\n");
1128 summary.append(
"</div>\n");
1129 summary.append(
"</body></html>");
1130 output.write(summary.toString());
1131 }
catch (FileNotFoundException ex) {
1132 logger.log(Level.SEVERE,
"Could not find summary.html file to write to.");
1133 }
catch (UnsupportedEncodingException ex) {
1134 logger.log(Level.SEVERE,
"Did not recognize encoding when writing summary.hmtl.");
1135 }
catch (IOException ex) {
1136 logger.log(Level.SEVERE,
"Error creating Writer for summary.html.");
1137 }
catch (NoCurrentCaseException | TskCoreException ex) {
1138 logger.log(Level.WARNING,
"Unable to get current sleuthkit Case for the HTML report.");
1141 if (output != null) {
1145 }
catch (IOException ex) {
1155 private StringBuilder writeSummaryCaseDetails() {
1156 StringBuilder summary =
new StringBuilder();
1157 String caseName = currentCase.getDisplayName();
1158 String caseNumber = currentCase.getNumber();
1159 String examiner = currentCase.getExaminer();
1160 final boolean agencyLogoSet = reportBranding.getAgencyLogoPath() != null && !reportBranding.getAgencyLogoPath().isEmpty();
1163 imagecount = currentCase.getDataSources().size();
1164 }
catch (TskCoreException ex) {
1167 summary.append(
"<div class=\"title\">\n");
1168 if (agencyLogoSet) {
1169 summary.append(
"<div class=\"left\">\n");
1170 summary.append(
"<img src=\"");
1171 summary.append(Paths.get(reportBranding.getAgencyLogoPath()).getFileName().toString());
1172 summary.append(
"\" />\n");
1173 summary.append(
"</div>\n");
1175 final String align = agencyLogoSet ?
"right" :
"left";
1176 summary.append(
"<div class=\"").append(align).append(
"\">\n");
1177 summary.append(
"<table>\n");
1178 summary.append(
"<tr><td>").append(NbBundle.getMessage(
this.getClass(),
"ReportHTML.writeSum.caseName"))
1179 .append(
"</td><td>").append(caseName).append(
"</td></tr>\n");
1180 summary.append(
"<tr><td>").append(NbBundle.getMessage(
this.getClass(),
"ReportHTML.writeSum.caseNum"))
1181 .append(
"</td><td>").append(!caseNumber.isEmpty() ? caseNumber : NbBundle
1182 .getMessage(this.getClass(),
"ReportHTML.writeSum.noCaseNum")).append(
"</td></tr>\n");
1183 summary.append(
"<tr><td>").append(NbBundle.getMessage(
this.getClass(),
"ReportHTML.writeSum.examiner")).append(
"</td><td>")
1184 .append(!examiner.isEmpty() ? examiner : NbBundle
1185 .getMessage(this.getClass(),
"ReportHTML.writeSum.noExaminer"))
1186 .append(
"</td></tr>\n");
1187 summary.append(
"<tr><td>").append(NbBundle.getMessage(
this.getClass(),
"ReportHTML.writeSum.numImages"))
1188 .append(
"</td><td>").append(imagecount).append(
"</td></tr>\n");
1189 summary.append(
"</table>\n");
1190 summary.append(
"</div>\n");
1191 summary.append(
"<div class=\"clear\"></div>\n");
1192 summary.append(
"</div>\n");
1201 private StringBuilder writeSummaryImageInfo() {
1202 StringBuilder summary =
new StringBuilder();
1203 summary.append(NbBundle.getMessage(
this.getClass(),
"ReportHTML.writeSum.imageInfoHeading"));
1204 summary.append(
"<div class=\"info\">\n");
1206 for (Content c : currentCase.getDataSources()) {
1207 summary.append(
"<p>").append(c.getName()).append(
"</p>\n");
1208 if (c instanceof Image) {
1209 Image img = (Image) c;
1211 summary.append(
"<table>\n");
1212 summary.append(
"<tr><td>").append(
1213 NbBundle.getMessage(
this.getClass(),
"ReportHTML.writeSum.timezone"))
1214 .append(
"</td><td>").append(img.getTimeZone()).append(
"</td></tr>\n");
1215 for (String imgPath : img.getPaths()) {
1216 summary.append(
"<tr><td>").append(
1217 NbBundle.getMessage(
this.getClass(),
"ReportHTML.writeSum.path"))
1218 .append(
"</td><td>").append(imgPath).append(
"</td></tr>\n");
1220 summary.append(
"</table>\n");
1223 }
catch (TskCoreException ex) {
1224 logger.log(Level.WARNING,
"Unable to get image information for the HTML report.");
1226 summary.append(
"</div>\n");
1235 private StringBuilder writeSummarySoftwareInfo(SleuthkitCase skCase, List<IngestJobInfo> ingestJobs) {
1236 StringBuilder summary =
new StringBuilder();
1237 summary.append(NbBundle.getMessage(
this.getClass(),
"ReportHTML.writeSum.softwareInfoHeading"));
1238 summary.append(
"<div class=\"info\">\n");
1239 summary.append(
"<table>\n");
1240 summary.append(
"<tr><td>").append(NbBundle.getMessage(
this.getClass(),
"ReportHTML.writeSum.autopsyVersion"))
1241 .append(
"</td><td>").append(Version.getVersion()).append(
"</td></tr>\n");
1242 Map<Long, IngestModuleInfo> moduleInfoHashMap =
new HashMap<>();
1243 for (IngestJobInfo ingestJob : ingestJobs) {
1244 List<IngestModuleInfo> ingestModules = ingestJob.getIngestModuleInfo();
1245 for (IngestModuleInfo ingestModule : ingestModules) {
1246 if (!moduleInfoHashMap.containsKey(ingestModule.getIngestModuleId())) {
1247 moduleInfoHashMap.put(ingestModule.getIngestModuleId(), ingestModule);
1251 TreeMap<String, String> modules =
new TreeMap<>();
1252 for (IngestModuleInfo moduleinfo : moduleInfoHashMap.values()) {
1253 modules.put(moduleinfo.getDisplayName(), moduleinfo.getVersion());
1255 for (Map.Entry<String, String> module : modules.entrySet()) {
1256 summary.append(
"<tr><td>").append(module.getKey()).append(
" Module:")
1257 .append(
"</td><td>").append(module.getValue()).append(
"</td></tr>\n");
1259 summary.append(
"</table>\n");
1260 summary.append(
"</div>\n");
1261 summary.append(
"<div class=\"clear\"></div>\n");
1270 private StringBuilder writeSummaryIngestHistoryInfo(SleuthkitCase skCase, List<IngestJobInfo> ingestJobs) {
1271 StringBuilder summary =
new StringBuilder();
1273 summary.append(NbBundle.getMessage(
this.getClass(),
"ReportHTML.writeSum.ingestHistoryHeading"));
1274 summary.append(
"<div class=\"info\">\n");
1277 for (IngestJobInfo ingestJob : ingestJobs) {
1278 summary.append(
"<h3>Job ").append(jobnumber).append(
":</h3>\n");
1279 summary.append(
"<table>\n");
1280 summary.append(
"<tr><td>").append(
"Data Source:")
1281 .append(
"</td><td>").append(skCase.getContentById(ingestJob.getObjectId()).getName()).append(
"</td></tr>\n");
1282 summary.append(
"<tr><td>").append(
"Status:")
1283 .append(
"</td><td>").append(ingestJob.getStatus()).append(
"</td></tr>\n");
1284 summary.append(
"<tr><td>").append(NbBundle.getMessage(
this.getClass(),
"ReportHTML.writeSum.modulesEnabledHeading"))
1285 .append(
"</td><td>");
1286 List<IngestModuleInfo> ingestModules = ingestJob.getIngestModuleInfo();
1287 summary.append(
"<ul>\n");
1288 for (IngestModuleInfo ingestModule : ingestModules) {
1289 summary.append(
"<li>").append(ingestModule.getDisplayName()).append(
"</li>");
1291 summary.append(
"</ul>\n");
1293 summary.append(
"</td></tr>\n");
1294 summary.append(
"</table>\n");
1296 summary.append(
"</div>\n");
1297 }
catch (TskCoreException ex) {
1298 logger.log(Level.WARNING,
"Unable to get ingest jobs for the HTML report.");
1311 private String prepareThumbnail(AbstractFile file) {
1312 BufferedImage bufferedThumb = ImageUtils.getThumbnail(file, ImageUtils.ICON_SIZE_MEDIUM);
1320 File thumbFile = Paths.get(thumbsPath, fileName +
".png").toFile();
1321 if (bufferedThumb == null) {
1325 ImageIO.write(bufferedThumb,
"png", thumbFile);
1326 }
catch (IOException ex) {
1327 logger.log(Level.WARNING,
"Failed to write thumb file to report directory.", ex);
1330 if (thumbFile.exists()
1334 return THUMBS_REL_PATH
1335 + thumbFile.getName();
static String escapeFileName(String fileName)