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.List;
46 import java.util.TreeMap;
47 import java.util.logging.Level;
48 import javax.imageio.ImageIO;
49 import org.openide.filesystems.FileUtil;
50 import org.openide.util.NbBundle;
61 import org.
sleuthkit.datamodel.BlackboardArtifact.ARTIFACT_TYPE;
68 import org.
sleuthkit.datamodel.TskData.TSK_DB_FILES_TYPE_ENUM;
70 class ReportHTML
implements TableReportModule {
72 private static final Logger logger = Logger.getLogger(ReportHTML.class.getName());
73 private static final String THUMBS_REL_PATH =
"thumbs" + File.separator;
74 private static ReportHTML instance;
75 private static final int MAX_THUMBS_PER_PAGE = 1000;
76 private static final String HTML_SUBDIR =
"content";
77 private Case currentCase;
78 private SleuthkitCase skCase;
79 static Integer THUMBNAIL_COLUMNS = 5;
81 private Map<String, Integer> dataTypes;
83 private String thumbsPath;
84 private String subPath;
85 private String currentDataType;
86 private Integer rowCount;
89 private final ReportBranding reportBranding;
92 public static synchronized ReportHTML getDefault() {
93 if (instance == null) {
94 instance =
new ReportHTML();
100 private ReportHTML() {
101 reportBranding =
new ReportBranding();
105 private void refresh() {
106 currentCase = Case.getCurrentCase();
107 skCase = currentCase.getSleuthkitCase();
109 dataTypes =
new TreeMap<>();
114 currentDataType =
"";
120 }
catch (IOException ex) {
132 private String dataTypeToFileName(String dataType) {
136 fileName = fileName.replaceAll(
" ",
"_");
145 private String useDataTypeIcon(String dataType) {
149 OutputStream output = null;
151 logger.log(Level.INFO,
"useDataTypeIcon: dataType = {0}", dataType);
154 BlackboardArtifact.ARTIFACT_TYPE artifactType = null;
155 for (ARTIFACT_TYPE v : ARTIFACT_TYPE.values()) {
156 if (v.getDisplayName().equals(dataType)) {
161 if (null != artifactType) {
163 iconFileName = dataTypeToFileName(artifactType.getDisplayName()) +
".png";
164 iconFilePath = subPath + File.separator + iconFileName;
167 switch (artifactType) {
168 case TSK_WEB_BOOKMARK:
169 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/bookmarks.png");
172 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/cookies.png");
174 case TSK_WEB_HISTORY:
175 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/history.png");
177 case TSK_WEB_DOWNLOAD:
178 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/downloads.png");
180 case TSK_RECENT_OBJECT:
181 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/recent.png");
183 case TSK_INSTALLED_PROG:
184 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/installed.png");
186 case TSK_KEYWORD_HIT:
187 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/keywords.png");
189 case TSK_HASHSET_HIT:
190 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/hash.png");
192 case TSK_DEVICE_ATTACHED:
193 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/devices.png");
195 case TSK_WEB_SEARCH_QUERY:
196 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/search.png");
198 case TSK_METADATA_EXIF:
199 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/exif.png");
202 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/userbookmarks.png");
204 case TSK_TAG_ARTIFACT:
205 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/userbookmarks.png");
207 case TSK_SERVICE_ACCOUNT:
208 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/account-icon-16.png");
211 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/contact.png");
214 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/message.png");
217 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/calllog.png");
219 case TSK_CALENDAR_ENTRY:
220 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/calendar.png");
222 case TSK_SPEED_DIAL_ENTRY:
223 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/speeddialentry.png");
225 case TSK_BLUETOOTH_PAIRING:
226 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/bluetooth.png");
228 case TSK_GPS_BOOKMARK:
229 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/gpsfav.png");
231 case TSK_GPS_LAST_KNOWN_LOCATION:
232 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/gps-lastlocation.png");
235 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/gps-search.png");
238 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/computer.png");
240 case TSK_GPS_TRACKPOINT:
241 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/gps_trackpoint.png");
244 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/gps_trackpoint.png");
247 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/images/mail-icon-16.png");
249 case TSK_ENCRYPTION_SUSPECTED:
250 case TSK_ENCRYPTION_DETECTED:
251 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/images/encrypted-file.png");
253 case TSK_EXT_MISMATCH_DETECTED:
254 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/images/mismatch-16.png");
256 case TSK_INTERESTING_ARTIFACT_HIT:
257 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/images/interesting_item.png");
259 case TSK_INTERESTING_FILE_HIT:
260 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/images/interesting_item.png");
263 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/installed.png");
265 case TSK_REMOTE_DRIVE:
266 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/drive_network.png");
269 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/accounts.png");
272 logger.log(Level.WARNING,
"useDataTypeIcon: unhandled artifact type = " + dataType);
273 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/star.png");
274 iconFileName =
"star.png";
275 iconFilePath = subPath + File.separator + iconFileName;
278 }
else if (dataType.startsWith(ARTIFACT_TYPE.TSK_ACCOUNT.getDisplayName())) {
286 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/accounts.png");
287 iconFileName =
"accounts.png";
288 iconFilePath = subPath + File.separator + iconFileName;
290 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/star.png");
291 iconFileName =
"star.png";
292 iconFilePath = subPath + File.separator + iconFileName;
296 output =
new FileOutputStream(iconFilePath);
297 FileUtil.copy(in, output);
300 }
catch (IOException ex) {
301 logger.log(Level.SEVERE,
"Failed to extract images for HTML report.", ex);
303 if (output != null) {
307 }
catch (IOException ex) {
313 }
catch (IOException ex) {
328 public void startReport(String baseReportDir) {
332 this.path = baseReportDir;
333 this.subPath = this.path + HTML_SUBDIR + File.separator;
334 this.thumbsPath = this.subPath + THUMBS_REL_PATH;
336 FileUtil.createFolder(
new File(this.subPath));
337 FileUtil.createFolder(
new File(this.thumbsPath));
338 }
catch (IOException ex) {
339 logger.log(Level.SEVERE,
"Unable to make HTML report folder.");
352 public void endReport() {
357 }
catch (IOException ex) {
358 logger.log(Level.WARNING,
"Could not close the output writer when ending report.", ex);
372 public void startDataType(String name, String description) {
373 String title = dataTypeToFileName(name);
375 out =
new BufferedWriter(
new OutputStreamWriter(
new FileOutputStream(subPath + title +
".html"),
"UTF-8"));
376 }
catch (FileNotFoundException ex) {
377 logger.log(Level.SEVERE,
"File not found: {0}", ex);
378 }
catch (UnsupportedEncodingException ex) {
379 logger.log(Level.SEVERE,
"Unrecognized encoding");
383 StringBuilder page =
new StringBuilder();
384 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");
385 page.append(
"<div id=\"header\">").append(name).append(
"</div>\n<div id=\"content\">\n");
386 if (!description.isEmpty()) {
387 page.append(
"<p><strong>");
388 page.append(description);
389 page.append(
"</string></p>\n");
391 out.write(page.toString());
392 currentDataType = name;
394 }
catch (IOException ex) {
395 logger.log(Level.SEVERE,
"Failed to write page head: {0}", ex);
404 public void endDataType() {
405 dataTypes.put(currentDataType, rowCount);
407 out.write(
"</div>\n</body>\n</html>\n");
408 }
catch (IOException ex) {
409 logger.log(Level.SEVERE,
"Failed to write end of HTML report.", ex);
415 }
catch (IOException ex) {
416 logger.log(Level.WARNING,
"Could not close the output writer when ending data type.", ex);
429 public void startSet(String setName) {
430 StringBuilder set =
new StringBuilder();
431 set.append(
"<h1><a name=\"").append(setName).append(
"\">").append(setName).append(
"</a></h1>\n");
432 set.append(
"<div class=\"keyword_list\">\n");
435 out.write(set.toString());
436 }
catch (IOException ex) {
437 logger.log(Level.SEVERE,
"Failed to write set: {0}", ex);
445 public void endSet() {
447 out.write(
"</div>\n");
448 }
catch (IOException ex) {
449 logger.log(Level.SEVERE,
"Failed to write end of set: {0}", ex);
459 public void addSetIndex(List<String> sets) {
460 StringBuilder index =
new StringBuilder();
461 index.append(
"<ul>\n");
462 for (String set : sets) {
463 index.append(
"\t<li><a href=\"#").append(set).append(
"\">").append(set).append(
"</a></li>\n");
465 index.append(
"</ul>\n");
467 out.write(index.toString());
468 }
catch (IOException ex) {
469 logger.log(Level.SEVERE,
"Failed to add set index: {0}", ex);
479 public void addSetElement(String elementName) {
481 out.write(
"<h4>" + elementName +
"</h4>\n");
482 }
catch (IOException ex) {
483 logger.log(Level.SEVERE,
"Failed to write set element: {0}", ex);
493 public void startTable(List<String> titles) {
494 StringBuilder ele =
new StringBuilder();
495 ele.append(
"<table>\n<thead>\n\t<tr>\n");
496 for (String title : titles) {
497 ele.append(
"\t\t<th>").append(title).append(
"</th>\n");
499 ele.append(
"\t</tr>\n</thead>\n");
502 out.write(ele.toString());
503 }
catch (IOException ex) {
504 logger.log(Level.SEVERE,
"Failed to write table start: {0}", ex);
515 public void startContentTagsTable(List<String> columnHeaders) {
516 StringBuilder htmlOutput =
new StringBuilder();
517 htmlOutput.append(
"<table>\n<thead>\n\t<tr>\n");
520 for (String columnHeader : columnHeaders) {
521 htmlOutput.append(
"\t\t<th>").append(columnHeader).append(
"</th>\n");
525 htmlOutput.append(
"\t\t<th></th>\n");
527 htmlOutput.append(
"\t</tr>\n</thead>\n");
530 out.write(htmlOutput.toString());
531 }
catch (IOException ex) {
532 logger.log(Level.SEVERE,
"Failed to write table start: {0}", ex);
540 public void endTable() {
542 out.write(
"</table>\n");
543 }
catch (IOException ex) {
544 logger.log(Level.SEVERE,
"Failed to write end of table: {0}", ex);
554 public void addRow(List<String> row) {
555 StringBuilder builder =
new StringBuilder();
556 builder.append(
"\t<tr>\n");
557 for (String cell : row) {
558 String escapeHTMLCell = EscapeUtil.escapeHtml(cell);
559 builder.append(
"\t\t<td>").append(escapeHTMLCell).append(
"</td>\n");
561 builder.append(
"\t</tr>\n");
565 out.write(builder.toString());
566 }
catch (IOException ex) {
567 logger.log(Level.SEVERE,
"Failed to write row to out.", ex);
568 }
catch (NullPointerException ex) {
569 logger.log(Level.SEVERE,
"Output writer is null. Page was not initialized before writing.", ex);
583 public void addRowWithTaggedContentHyperlink(List<String> row, ContentTag contentTag) {
584 Content content = contentTag.getContent();
585 if (content instanceof AbstractFile ==
false) {
589 AbstractFile file = (AbstractFile) content;
591 StringBuilder localFileLink =
new StringBuilder();
594 || file.getType() == TSK_DB_FILES_TYPE_ENUM.UNALLOC_BLOCKS
595 || file.getType() == TSK_DB_FILES_TYPE_ENUM.UNUSED_BLOCKS)) {
596 localFileLink.append(
"<a href=\"");
598 String localFilePath = saveContent(file, contentTag.getName().getDisplayName());
599 localFileLink.append(localFilePath);
600 localFileLink.append(
"\" target=\"_top\">");
603 StringBuilder builder =
new StringBuilder();
604 builder.append(
"\t<tr>\n");
605 int positionCounter = 0;
606 for (String cell : row) {
608 if (positionCounter == 1) {
609 builder.append(
"\t\t<td class=\"left_align_cell\">").append(localFileLink.toString()).append(cell).append(
"</a></td>\n");
610 }
else if (positionCounter == 7) {
611 builder.append(
"\t\t<td class=\"right_align_cell\">").append(cell).append(
"</td>\n");
613 builder.append(
"\t\t<td>").append(cell).append(
"</td>\n");
617 builder.append(
"\t</tr>\n");
621 out.write(builder.toString());
622 }
catch (IOException ex) {
623 logger.log(Level.SEVERE,
"Failed to write row to out.", ex);
624 }
catch (NullPointerException ex) {
625 logger.log(Level.SEVERE,
"Output writer is null. Page was not initialized before writing.", ex);
634 public void addThumbnailRows(Set<Content> images) {
635 List<String> currentRow =
new ArrayList<>();
638 for (Content content : images) {
639 if (currentRow.size() == THUMBNAIL_COLUMNS) {
644 if (totalCount == MAX_THUMBS_PER_PAGE) {
648 rowCount = totalCount;
653 startDataType(NbBundle.getMessage(
this.getClass(),
"ReportHTML.addThumbRows.dataType.title", pages),
654 NbBundle.getMessage(
this.getClass(),
"ReportHTML.addThumbRows.dataType.msg"));
655 List<String> emptyHeaders =
new ArrayList<>();
656 for (
int i = 0; i < THUMBNAIL_COLUMNS; i++) {
657 emptyHeaders.add(
"");
659 startTable(emptyHeaders);
662 if (failsContentCheck(content)) {
666 AbstractFile file = (AbstractFile) content;
669 String thumbnailPath = prepareThumbnail(file);
670 if (thumbnailPath == null) {
673 String contentPath = saveContent(file,
"thumbs_fullsize");
676 nameInImage = file.getUniquePath();
677 }
catch (TskCoreException ex) {
678 nameInImage = file.getName();
681 StringBuilder linkToThumbnail =
new StringBuilder();
682 linkToThumbnail.append(
"<div id='thumbnail_link'>");
683 linkToThumbnail.append(
"<a href=\"");
684 linkToThumbnail.append(contentPath);
685 linkToThumbnail.append(
"\" target=\"_top\">");
686 linkToThumbnail.append(
"<img src=\"").append(thumbnailPath).append(
"\" title=\"").append(nameInImage).append(
"\"/>");
687 linkToThumbnail.append(
"</a><br>");
688 linkToThumbnail.append(file.getName()).append(
"<br>");
690 Services services = currentCase.getServices();
691 TagsManager tagsManager = services.getTagsManager();
693 List<ContentTag> tags = tagsManager.getContentTagsByContent(content);
694 if (tags.size() > 0) {
695 linkToThumbnail.append(NbBundle.getMessage(
this.getClass(),
"ReportHTML.thumbLink.tags"));
697 for (
int i = 0; i < tags.size(); i++) {
698 ContentTag tag = tags.get(i);
699 String notableString = tag.getName().getKnownStatus() == TskData.FileKnown.BAD ? TagsManager.getNotableTagLabel() :
"";
700 linkToThumbnail.append(tag.getName().getDisplayName() + notableString);
701 if (i != tags.size() - 1) {
702 linkToThumbnail.append(
", ");
705 }
catch (TskCoreException ex) {
706 logger.log(Level.WARNING,
"Could not find get tags for file.", ex);
708 linkToThumbnail.append(
"</div>");
709 currentRow.add(linkToThumbnail.toString());
714 if (currentRow.isEmpty() ==
false) {
715 int extraCells = THUMBNAIL_COLUMNS - currentRow.size();
716 for (
int i = 0; i < extraCells; i++) {
724 rowCount = totalCount;
727 private boolean failsContentCheck(Content c) {
728 if (c instanceof AbstractFile ==
false) {
731 AbstractFile file = (AbstractFile) c;
733 || file.getType() == TSK_DB_FILES_TYPE_ENUM.UNALLOC_BLOCKS
734 || file.getType() == TSK_DB_FILES_TYPE_ENUM.UNUSED_BLOCKS) {
749 public String saveContent(AbstractFile file, String dirName) {
754 StringBuilder localFilePath =
new StringBuilder();
756 localFilePath.append(subPath);
757 localFilePath.append(dirName2);
758 File localFileFolder =
new File(localFilePath.toString());
759 if (!localFileFolder.exists()) {
760 localFileFolder.mkdirs();
764 String fileName = file.getName();
765 String objectIdSuffix =
"_" + file.getId();
766 int lastDotIndex = fileName.lastIndexOf(
".");
767 if (lastDotIndex != -1 && lastDotIndex != 0) {
769 fileName = fileName.substring(0, lastDotIndex) + objectIdSuffix + fileName.substring(lastDotIndex, fileName.length());
773 fileName += objectIdSuffix;
775 localFilePath.append(File.separator);
776 localFilePath.append(fileName);
780 File localFile =
new File(localFilePath.toString());
781 if (!localFile.exists()) {
782 ExtractFscContentVisitor.extract(file, localFile, null, null);
786 return localFilePath.toString().substring(subPath.length());
797 public String dateToString(
long date) {
798 SimpleDateFormat sdf =
new java.text.SimpleDateFormat(
"yyyy/MM/dd HH:mm:ss");
799 return sdf.format(
new java.util.Date(date * 1000));
803 public String getRelativeFilePath() {
804 return "report.html";
808 public String getName() {
809 return NbBundle.getMessage(this.getClass(),
"ReportHTML.getName.text");
813 public String getDescription() {
814 return NbBundle.getMessage(this.getClass(),
"ReportHTML.getDesc.text");
820 private void writeCss() {
821 Writer cssOut = null;
823 cssOut =
new BufferedWriter(
new OutputStreamWriter(
new FileOutputStream(subPath +
"index.css"),
"UTF-8"));
824 String css =
"body {margin: 0px; padding: 0px; background: #FFFFFF; font: 13px/20px Arial, Helvetica, sans-serif; color: #535353;}\n"
826 "#content {padding: 30px;}\n"
828 "#header {width:100%; padding: 10px; line-height: 25px; background: #07A; color: #FFF; font-size: 20px;}\n"
830 "h1 {font-size: 20px; font-weight: normal; color: #07A; padding: 0 0 7px 0; margin-top: 25px; border-bottom: 1px solid #D6D6D6;}\n"
832 "h2 {font-size: 20px; font-weight: bolder; color: #07A;}\n"
834 "h3 {font-size: 16px; color: #07A;}\n"
836 "h4 {background: #07A; color: #FFF; font-size: 16px; margin: 0 0 0 25px; padding: 0; padding-left: 15px;}\n"
838 "ul.nav {list-style-type: none; line-height: 35px; padding: 0px; margin-left: 15px;}\n"
840 "ul li a {font-size: 14px; color: #444; text-decoration: none; padding-left: 25px;}\n"
842 "ul li a:hover {text-decoration: underline;}\n"
844 "p {margin: 0 0 20px 0;}\n"
846 "table {white-space:nowrap; min-width: 700px; padding: 2; margin: 0; border-collapse: collapse; border-bottom: 2px solid #e5e5e5;}\n"
848 ".keyword_list table {margin: 0 0 25px 25px; border-bottom: 2px solid #dedede;}\n"
850 "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"
852 "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"
854 "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"
856 "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"
858 "table tr:nth-child(even) td {background: #f3f3f3;}\n"
860 "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;}";
862 }
catch (FileNotFoundException ex) {
863 logger.log(Level.SEVERE,
"Could not find index.css file to write to.", ex);
864 }
catch (UnsupportedEncodingException ex) {
865 logger.log(Level.SEVERE,
"Did not recognize encoding when writing index.css.", ex);
866 }
catch (IOException ex) {
867 logger.log(Level.SEVERE,
"Error creating Writer for index.css.", ex);
870 if (cssOut != null) {
874 }
catch (IOException ex) {
882 private void writeIndex() {
883 Writer indexOut = null;
884 String indexFilePath = path +
"report.html";
886 indexOut =
new BufferedWriter(
new OutputStreamWriter(
new FileOutputStream(indexFilePath),
"UTF-8"));
887 StringBuilder index =
new StringBuilder();
888 final String reportTitle = reportBranding.getReportTitle();
889 String iconPath = reportBranding.getAgencyLogoPath();
890 if (iconPath == null) {
892 iconPath = HTML_SUBDIR +
"favicon.ico";
894 iconPath = Paths.get(reportBranding.getAgencyLogoPath()).getFileName().toString();
896 index.append(
"<head>\n<title>").append(reportTitle).append(
" ").append(
897 NbBundle.getMessage(
this.getClass(),
"ReportHTML.writeIndex.title", currentCase.getDisplayName())).append(
899 index.append(
"<link rel=\"icon\" type=\"image/ico\" href=\"")
900 .append(iconPath).append(
"\" />\n");
901 index.append(
"<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\n");
902 index.append(
"</head>\n");
903 index.append(
"<frameset cols=\"350px,*\">\n");
904 index.append(
"<frame src=\"" + HTML_SUBDIR).append(File.separator).append(
"nav.html\" name=\"nav\">\n");
905 index.append(
"<frame src=\"" + HTML_SUBDIR).append(File.separator).append(
"summary.html\" name=\"content\">\n");
906 index.append(
"<noframes>").append(NbBundle.getMessage(
this.getClass(),
"ReportHTML.writeIndex.noFrames.msg")).append(
"<br />\n");
907 index.append(NbBundle.getMessage(
this.getClass(),
"ReportHTML.writeIndex.noFrames.seeNav")).append(
"<br />\n");
908 index.append(NbBundle.getMessage(
this.getClass(),
"ReportHTML.writeIndex.seeSum")).append(
"</noframes>\n");
909 index.append(
"</frameset>\n");
910 index.append(
"</html>");
911 indexOut.write(index.toString());
912 Case.getCurrentCase().addReport(indexFilePath, NbBundle.getMessage(
this.getClass(),
913 "ReportHTML.writeIndex.srcModuleName.text"),
"");
914 }
catch (IOException ex) {
915 logger.log(Level.SEVERE,
"Error creating Writer for report.html: {0}", ex);
916 }
catch (TskCoreException ex) {
917 String errorMessage = String.format(
"Error adding %s to case as a report", indexFilePath);
918 logger.log(Level.SEVERE, errorMessage, ex);
921 if (indexOut != null) {
925 }
catch (IOException ex) {
933 private void writeNav() {
934 Writer navOut = null;
936 navOut =
new BufferedWriter(
new OutputStreamWriter(
new FileOutputStream(subPath +
"nav.html"),
"UTF-8"));
937 StringBuilder nav =
new StringBuilder();
938 nav.append(
"<html>\n<head>\n\t<title>").append(
939 NbBundle.getMessage(
this.getClass(),
"ReportHTML.writeNav.title"))
940 .append(
"</title>\n\t<link rel=\"stylesheet\" type=\"text/css\" href=\"index.css\" />\n");
941 nav.append(
"<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\n</head>\n<body>\n");
942 nav.append(
"<div id=\"content\">\n<h1>").append(
943 NbBundle.getMessage(
this.getClass(),
"ReportHTML.writeNav.h1")).append(
"</h1>\n");
944 nav.append(
"<ul class=\"nav\">\n");
945 nav.append(
"<li style=\"background: url(summary.png) left center no-repeat;\"><a href=\"summary.html\" target=\"content\">")
946 .append(NbBundle.getMessage(
this.getClass(),
"ReportHTML.writeNav.summary")).append(
"</a></li>\n");
948 for (String dataType : dataTypes.keySet()) {
949 String dataTypeEsc = dataTypeToFileName(dataType);
950 String iconFileName = useDataTypeIcon(dataType);
951 nav.append(
"<li style=\"background: url('").append(iconFileName)
952 .append(
"') left center no-repeat;\"><a href=\"")
953 .append(dataTypeEsc).append(
".html\" target=\"content\">")
954 .append(dataType).append(
" (").append(dataTypes.get(dataType))
955 .append(
")</a></li>\n");
957 nav.append(
"</ul>\n");
958 nav.append(
"</div>\n</body>\n</html>");
959 navOut.write(nav.toString());
960 }
catch (IOException ex) {
961 logger.log(Level.SEVERE,
"Failed to write end of report navigation menu: {0}", ex);
963 if (navOut != null) {
967 }
catch (IOException ex) {
968 logger.log(Level.WARNING,
"Could not close navigation out writer.");
973 InputStream in = null;
974 OutputStream output = null;
978 String generatorLogoPath = reportBranding.getGeneratorLogoPath();
979 if (generatorLogoPath != null && !generatorLogoPath.isEmpty()) {
980 File from =
new File(generatorLogoPath);
981 File to =
new File(subPath);
982 FileUtil.copyFile(FileUtil.toFileObject(from), FileUtil.toFileObject(to),
"generator_logo");
985 String agencyLogoPath = reportBranding.getAgencyLogoPath();
986 if (agencyLogoPath != null && !agencyLogoPath.isEmpty()) {
987 Path destinationPath = Paths.get(subPath);
988 Files.copy(Files.newInputStream(Paths.get(agencyLogoPath)), destinationPath.resolve(Paths.get(agencyLogoPath).getFileName()));
991 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/favicon.ico");
992 output =
new FileOutputStream(
new File(subPath +
"favicon.ico"));
993 FileUtil.copy(in, output);
997 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/summary.png");
998 output =
new FileOutputStream(
new File(subPath +
"summary.png"));
999 FileUtil.copy(in, output);
1003 }
catch (IOException ex) {
1004 logger.log(Level.SEVERE,
"Failed to extract images for HTML report.", ex);
1006 if (output != null) {
1010 }
catch (IOException ex) {
1016 }
catch (IOException ex) {
1025 private void writeSummary() {
1028 out =
new BufferedWriter(
new OutputStreamWriter(
new FileOutputStream(subPath +
"summary.html"),
"UTF-8"));
1029 StringBuilder head =
new StringBuilder();
1030 head.append(
"<html>\n<head>\n<title>").append(
1031 NbBundle.getMessage(
this.getClass(),
"ReportHTML.writeSum.title")).append(
"</title>\n");
1032 head.append(
"<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\n");
1033 head.append(
"<style type=\"text/css\">\n");
1034 head.append(
"body { padding: 0px; margin: 0px; font: 13px/20px Arial, Helvetica, sans-serif; color: #535353; }\n");
1035 head.append(
"#wrapper { width: 90%; margin: 0px auto; margin-top: 35px; }\n");
1036 head.append(
"h1 { color: #07A; font-size: 36px; line-height: 42px; font-weight: normal; margin: 0px; border-bottom: 1px solid #81B9DB; }\n");
1037 head.append(
"h1 span { color: #F00; display: block; font-size: 16px; font-weight: bold; line-height: 22px;}\n");
1038 head.append(
"h2 { padding: 0 0 3px 0; margin: 0px; color: #07A; font-weight: normal; border-bottom: 1px dotted #81B9DB; }\n");
1039 head.append(
"table td { padding-right: 25px; }\n");
1040 head.append(
"p.subheadding { padding: 0px; margin: 0px; font-size: 11px; color: #B5B5B5; }\n");
1041 head.append(
".title { width: 660px; margin-bottom: 50px; }\n");
1042 head.append(
".left { float: left; width: 250px; margin-top: 20px; text-align: center; }\n");
1043 head.append(
".left img { max-width: 250px; max-height: 250px; min-width: 200px; min-height: 200px; }\n");
1044 head.append(
".right { float: right; width: 385px; margin-top: 25px; font-size: 14px; }\n");
1045 head.append(
".clear { clear: both; }\n");
1046 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");
1047 head.append(
".info table { margin: 0 25px 20px 25px; }\n");
1048 head.append(
"</style>\n");
1049 head.append(
"</head>\n<body>\n");
1050 out.write(head.toString());
1052 DateFormat datetimeFormat =
new SimpleDateFormat(
"yyyy/MM/dd HH:mm:ss");
1053 Date date =
new Date();
1054 String datetime = datetimeFormat.format(date);
1056 String caseName = currentCase.getDisplayName();
1057 String caseNumber = currentCase.getNumber();
1058 String examiner = currentCase.getExaminer();
1061 imagecount = currentCase.getDataSources().size();
1062 }
catch (TskCoreException ex) {
1066 StringBuilder summary =
new StringBuilder();
1067 boolean running =
false;
1068 if (IngestManager.getInstance().isIngestRunning()) {
1072 final String reportTitle = reportBranding.getReportTitle();
1073 final String reportFooter = reportBranding.getReportFooter();
1074 final boolean agencyLogoSet = reportBranding.getAgencyLogoPath() != null && !reportBranding.getAgencyLogoPath().isEmpty();
1075 final boolean generatorLogoSet = reportBranding.getGeneratorLogoPath() != null && !reportBranding.getGeneratorLogoPath().isEmpty();
1077 summary.append(
"<div id=\"wrapper\">\n");
1078 summary.append(
"<h1>").append(reportTitle)
1079 .append(running ? NbBundle.getMessage(
this.getClass(),
"ReportHTML.writeSum.warningMsg") :
"")
1081 summary.append(
"<p class=\"subheadding\">").append(
1082 NbBundle.getMessage(
this.getClass(),
"ReportHTML.writeSum.reportGenOn.text", datetime)).append(
"</p>\n");
1083 summary.append(
"<div class=\"title\">\n");
1084 if (agencyLogoSet) {
1085 summary.append(
"<div class=\"left\">\n");
1086 summary.append(
"<img src=\"");
1087 summary.append(Paths.get(reportBranding.getAgencyLogoPath()).getFileName().toString());
1088 summary.append(
"\" />\n");
1089 summary.append(
"</div>\n");
1091 final String align = agencyLogoSet ?
"right" :
"left";
1092 summary.append(
"<div class=\"").append(align).append(
"\">\n");
1093 summary.append(
"<table>\n");
1094 summary.append(
"<tr><td>").append(NbBundle.getMessage(
this.getClass(),
"ReportHTML.writeSum.caseName"))
1095 .append(
"</td><td>").append(caseName).append(
"</td></tr>\n");
1096 summary.append(
"<tr><td>").append(NbBundle.getMessage(
this.getClass(),
"ReportHTML.writeSum.caseNum"))
1097 .append(
"</td><td>").append(!caseNumber.isEmpty() ? caseNumber : NbBundle
1098 .getMessage(this.getClass(),
"ReportHTML.writeSum.noCaseNum")).append(
"</td></tr>\n");
1099 summary.append(
"<tr><td>").append(NbBundle.getMessage(
this.getClass(),
"ReportHTML.writeSum.examiner")).append(
"</td><td>")
1100 .append(!examiner.isEmpty() ? examiner : NbBundle
1101 .getMessage(this.getClass(),
"ReportHTML.writeSum.noExaminer"))
1102 .append(
"</td></tr>\n");
1103 summary.append(
"<tr><td>").append(NbBundle.getMessage(
this.getClass(),
"ReportHTML.writeSum.numImages"))
1104 .append(
"</td><td>").append(imagecount).append(
"</td></tr>\n");
1105 summary.append(
"</table>\n");
1106 summary.append(
"</div>\n");
1107 summary.append(
"<div class=\"clear\"></div>\n");
1108 summary.append(
"</div>\n");
1109 summary.append(NbBundle.getMessage(
this.getClass(),
"ReportHTML.writeSum.imageInfoHeading"));
1110 summary.append(
"<div class=\"info\">\n");
1112 for (Content c : currentCase.getDataSources()) {
1113 summary.append(
"<p>").append(c.getName()).append(
"</p>\n");
1114 if (c instanceof Image) {
1115 Image img = (Image) c;
1117 summary.append(
"<table>\n");
1118 summary.append(
"<tr><td>").append(
1119 NbBundle.getMessage(
this.getClass(),
"ReportHTML.writeSum.timezone"))
1120 .append(
"</td><td>").append(img.getTimeZone()).append(
"</td></tr>\n");
1121 for (String imgPath : img.getPaths()) {
1122 summary.append(
"<tr><td>").append(
1123 NbBundle.getMessage(
this.getClass(),
"ReportHTML.writeSum.path"))
1124 .append(
"</td><td>").append(imgPath).append(
"</td></tr>\n");
1126 summary.append(
"</table>\n");
1129 }
catch (TskCoreException ex) {
1130 logger.log(Level.WARNING,
"Unable to get image information for the HTML report.");
1132 summary.append(
"</div>\n");
1133 if (generatorLogoSet) {
1134 summary.append(
"<div class=\"left\">\n");
1135 summary.append(
"<img src=\"generator_logo.png\" />\n");
1136 summary.append(
"</div>\n");
1138 summary.append(
"<div class=\"clear\"></div>\n");
1139 if (reportFooter != null) {
1140 summary.append(
"<p class=\"subheadding\">").append(reportFooter).append(
"</p>\n");
1142 summary.append(
"</div>\n");
1143 summary.append(
"</body></html>");
1144 out.write(summary.toString());
1145 }
catch (FileNotFoundException ex) {
1146 logger.log(Level.SEVERE,
"Could not find summary.html file to write to.");
1147 }
catch (UnsupportedEncodingException ex) {
1148 logger.log(Level.SEVERE,
"Did not recognize encoding when writing summary.hmtl.");
1149 }
catch (IOException ex) {
1150 logger.log(Level.SEVERE,
"Error creating Writer for summary.html.");
1157 }
catch (IOException ex) {
1162 private String prepareThumbnail(AbstractFile file) {
1163 BufferedImage bufferedThumb = ImageUtils.getThumbnail(file, ImageUtils.ICON_SIZE_MEDIUM);
1164 File thumbFile = Paths.get(thumbsPath, file.getName() +
".png").toFile();
1165 if (bufferedThumb == null) {
1169 ImageIO.write(bufferedThumb,
"png", thumbFile);
1170 }
catch (IOException ex) {
1171 logger.log(Level.WARNING,
"Failed to write thumb file to report directory.", ex);
1174 if (thumbFile.exists()
1178 return THUMBS_REL_PATH
1179 + thumbFile.getName();
static String escapeFileName(String fileName)