23 package org.sleuthkit.autopsy.report;
25 import java.io.BufferedWriter;
27 import java.io.FileNotFoundException;
28 import java.io.FileOutputStream;
29 import java.io.IOException;
30 import java.io.InputStream;
31 import java.io.OutputStream;
32 import java.io.OutputStreamWriter;
33 import java.io.UnsupportedEncodingException;
34 import java.io.Writer;
35 import java.text.DateFormat;
36 import java.text.SimpleDateFormat;
37 import java.util.ArrayList;
38 import java.util.Date;
39 import java.util.List;
41 import java.util.TreeMap;
42 import java.util.logging.Level;
43 import org.openide.filesystems.FileObject;
44 import org.openide.filesystems.FileUtil;
45 import org.openide.util.NbBundle;
55 import org.
sleuthkit.datamodel.BlackboardArtifact.ARTIFACT_TYPE;
61 import org.
sleuthkit.datamodel.TskData.TSK_DB_FILES_TYPE_ENUM;
63 class ReportHTML
implements TableReportModule {
65 private static final Logger logger = Logger.getLogger(ReportHTML.class.getName());
66 private static final String THUMBS_REL_PATH =
"thumbs" + File.separator;
67 private static ReportHTML instance;
68 private static final int MAX_THUMBS_PER_PAGE = 1000;
69 private Case currentCase;
70 private SleuthkitCase skCase;
71 static Integer THUMBNAIL_COLUMNS = 5;
73 private Map<String, Integer> dataTypes;
75 private String thumbsPath;
76 private String currentDataType;
77 private Integer rowCount;
80 private final ReportBranding reportBranding;
83 public static synchronized ReportHTML getDefault() {
84 if (instance == null) {
85 instance =
new ReportHTML();
91 private ReportHTML() {
92 reportBranding =
new ReportBranding();
96 private void refresh() {
97 currentCase = Case.getCurrentCase();
98 skCase = currentCase.getSleuthkitCase();
100 dataTypes =
new TreeMap<>();
104 currentDataType =
"";
110 }
catch (IOException ex) {
122 private String dataTypeToFileName(String dataType) {
126 fileName = fileName.replaceAll(
" ",
"_");
135 private String useDataTypeIcon(String dataType) {
139 OutputStream output = null;
141 logger.log(Level.INFO,
"useDataTypeIcon: dataType = {0}", dataType);
144 BlackboardArtifact.ARTIFACT_TYPE artifactType = null;
145 for (ARTIFACT_TYPE v : ARTIFACT_TYPE.values()) {
146 if (v.getDisplayName().equals(dataType)) {
151 if (null != artifactType) {
153 iconFileName = dataTypeToFileName(artifactType.getDisplayName()) +
".png";
154 iconFilePath = path + File.separator + iconFileName;
157 switch (artifactType) {
158 case TSK_WEB_BOOKMARK:
159 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/bookmarks.png");
162 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/cookies.png");
164 case TSK_WEB_HISTORY:
165 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/history.png");
167 case TSK_WEB_DOWNLOAD:
168 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/downloads.png");
170 case TSK_RECENT_OBJECT:
171 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/recent.png");
173 case TSK_INSTALLED_PROG:
174 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/installed.png");
176 case TSK_KEYWORD_HIT:
177 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/keywords.png");
179 case TSK_HASHSET_HIT:
180 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/hash.png");
182 case TSK_DEVICE_ATTACHED:
183 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/devices.png");
185 case TSK_WEB_SEARCH_QUERY:
186 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/search.png");
188 case TSK_METADATA_EXIF:
189 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/exif.png");
192 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/userbookmarks.png");
194 case TSK_TAG_ARTIFACT:
195 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/userbookmarks.png");
197 case TSK_SERVICE_ACCOUNT:
198 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/account-icon-16.png");
201 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/contact.png");
204 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/message.png");
207 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/calllog.png");
209 case TSK_CALENDAR_ENTRY:
210 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/calendar.png");
212 case TSK_SPEED_DIAL_ENTRY:
213 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/speeddialentry.png");
215 case TSK_BLUETOOTH_PAIRING:
216 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/bluetooth.png");
218 case TSK_GPS_BOOKMARK:
219 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/gpsfav.png");
221 case TSK_GPS_LAST_KNOWN_LOCATION:
222 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/gps-lastlocation.png");
225 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/gps-search.png");
228 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/computer.png");
230 case TSK_GPS_TRACKPOINT:
231 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/gps_trackpoint.png");
234 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/gps_trackpoint.png");
237 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/images/mail-icon-16.png");
239 case TSK_ENCRYPTION_DETECTED:
240 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/images/encrypted-file.png");
242 case TSK_EXT_MISMATCH_DETECTED:
243 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/images/mismatch-16.png");
245 case TSK_INTERESTING_ARTIFACT_HIT:
246 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/images/interesting_item.png");
248 case TSK_INTERESTING_FILE_HIT:
249 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/images/interesting_item.png");
252 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/installed.png");
254 case TSK_REMOTE_DRIVE:
255 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/drive_network.png");
258 logger.log(Level.WARNING,
"useDataTypeIcon: unhandled artifact type = " + dataType);
259 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/star.png");
260 iconFileName =
"star.png";
261 iconFilePath = path + File.separator + iconFileName;
265 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/star.png");
266 iconFileName =
"star.png";
267 iconFilePath = path + File.separator + iconFileName;
271 output =
new FileOutputStream(iconFilePath);
272 FileUtil.copy(in, output);
275 }
catch (IOException ex) {
276 logger.log(Level.SEVERE,
"Failed to extract images for HTML report.", ex);
278 if (output != null) {
282 }
catch (IOException ex) {
288 }
catch (IOException ex) {
303 public void startReport(String baseReportDir) {
307 this.path = baseReportDir +
"HTML Report" + File.separator;
308 this.thumbsPath = this.path +
"thumbs" + File.separator;
310 FileUtil.createFolder(
new File(this.path));
311 FileUtil.createFolder(
new File(this.thumbsPath));
312 }
catch (IOException ex) {
313 logger.log(Level.SEVERE,
"Unable to make HTML report folder.");
326 public void endReport() {
331 }
catch (IOException ex) {
332 logger.log(Level.WARNING,
"Could not close the output writer when ending report.", ex);
346 public void startDataType(String name, String description) {
347 String title = dataTypeToFileName(name);
349 out =
new BufferedWriter(
new OutputStreamWriter(
new FileOutputStream(path + title +
".html"),
"UTF-8"));
350 }
catch (FileNotFoundException ex) {
351 logger.log(Level.SEVERE,
"File not found: {0}", ex);
352 }
catch (UnsupportedEncodingException ex) {
353 logger.log(Level.SEVERE,
"Unrecognized encoding");
357 StringBuilder page =
new StringBuilder();
358 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");
359 page.append(
"<div id=\"header\">").append(name).append(
"</div>\n<div id=\"content\">\n");
360 if (!description.isEmpty()) {
361 page.append(
"<p><strong>");
362 page.append(description);
363 page.append(
"</string></p>\n");
365 out.write(page.toString());
366 currentDataType = name;
368 }
catch (IOException ex) {
369 logger.log(Level.SEVERE,
"Failed to write page head: {0}", ex);
378 public void endDataType() {
379 dataTypes.put(currentDataType, rowCount);
381 out.write(
"</div>\n</body>\n</html>\n");
382 }
catch (IOException ex) {
383 logger.log(Level.SEVERE,
"Failed to write end of HTML report.", ex);
389 }
catch (IOException ex) {
390 logger.log(Level.WARNING,
"Could not close the output writer when ending data type.", ex);
403 public void startSet(String setName) {
404 StringBuilder set =
new StringBuilder();
405 set.append(
"<h1><a name=\"").append(setName).append(
"\">").append(setName).append(
"</a></h1>\n");
406 set.append(
"<div class=\"keyword_list\">\n");
409 out.write(set.toString());
410 }
catch (IOException ex) {
411 logger.log(Level.SEVERE,
"Failed to write set: {0}", ex);
419 public void endSet() {
421 out.write(
"</div>\n");
422 }
catch (IOException ex) {
423 logger.log(Level.SEVERE,
"Failed to write end of set: {0}", ex);
433 public void addSetIndex(List<String> sets) {
434 StringBuilder index =
new StringBuilder();
435 index.append(
"<ul>\n");
436 for (String set : sets) {
437 index.append(
"\t<li><a href=\"#").append(set).append(
"\">").append(set).append(
"</a></li>\n");
439 index.append(
"</ul>\n");
441 out.write(index.toString());
442 }
catch (IOException ex) {
443 logger.log(Level.SEVERE,
"Failed to add set index: {0}", ex);
453 public void addSetElement(String elementName) {
455 out.write(
"<h4>" + elementName +
"</h4>\n");
456 }
catch (IOException ex) {
457 logger.log(Level.SEVERE,
"Failed to write set element: {0}", ex);
467 public void startTable(List<String> titles) {
468 StringBuilder ele =
new StringBuilder();
469 ele.append(
"<table>\n<thead>\n\t<tr>\n");
470 for (String title : titles) {
471 ele.append(
"\t\t<th>").append(title).append(
"</th>\n");
473 ele.append(
"\t</tr>\n</thead>\n");
476 out.write(ele.toString());
477 }
catch (IOException ex) {
478 logger.log(Level.SEVERE,
"Failed to write table start: {0}", ex);
489 public void startContentTagsTable(List<String> columnHeaders) {
490 StringBuilder htmlOutput =
new StringBuilder();
491 htmlOutput.append(
"<table>\n<thead>\n\t<tr>\n");
494 for (String columnHeader : columnHeaders) {
495 htmlOutput.append(
"\t\t<th>").append(columnHeader).append(
"</th>\n");
499 htmlOutput.append(
"\t\t<th></th>\n");
501 htmlOutput.append(
"\t</tr>\n</thead>\n");
504 out.write(htmlOutput.toString());
505 }
catch (IOException ex) {
506 logger.log(Level.SEVERE,
"Failed to write table start: {0}", ex);
514 public void endTable() {
516 out.write(
"</table>\n");
517 }
catch (IOException ex) {
518 logger.log(Level.SEVERE,
"Failed to write end of table: {0}", ex);
528 public void addRow(List<String> row) {
529 StringBuilder builder =
new StringBuilder();
530 builder.append(
"\t<tr>\n");
531 for (String cell : row) {
532 builder.append(
"\t\t<td>").append(cell).append(
"</td>\n");
534 builder.append(
"\t</tr>\n");
538 out.write(builder.toString());
539 }
catch (IOException ex) {
540 logger.log(Level.SEVERE,
"Failed to write row to out.", ex);
541 }
catch (NullPointerException ex) {
542 logger.log(Level.SEVERE,
"Output writer is null. Page was not initialized before writing.", ex);
556 public void addRowWithTaggedContentHyperlink(List<String> row, ContentTag contentTag) {
557 Content content = contentTag.getContent();
558 if (content instanceof AbstractFile ==
false) {
562 AbstractFile file = (AbstractFile) content;
564 StringBuilder localFileLink =
new StringBuilder();
567 || file.getType() == TSK_DB_FILES_TYPE_ENUM.UNALLOC_BLOCKS
568 || file.getType() == TSK_DB_FILES_TYPE_ENUM.UNUSED_BLOCKS)) {
569 localFileLink.append(
"<a href=\"");
571 String localFilePath = saveContent(file, contentTag.getName().getDisplayName());
572 localFileLink.append(localFilePath);
573 localFileLink.append(
"\">");
576 StringBuilder builder =
new StringBuilder();
577 builder.append(
"\t<tr>\n");
578 int positionCounter = 0;
579 for (String cell : row) {
581 if (positionCounter == 1) {
582 builder.append(
"\t\t<td class=\"left_align_cell\">").append(localFileLink.toString()).append(cell).append(
"</a></td>\n");
583 }
else if (positionCounter == 7) {
584 builder.append(
"\t\t<td class=\"right_align_cell\">").append(cell).append(
"</td>\n");
586 builder.append(
"\t\t<td>").append(cell).append(
"</td>\n");
590 builder.append(
"\t</tr>\n");
594 out.write(builder.toString());
595 }
catch (IOException ex) {
596 logger.log(Level.SEVERE,
"Failed to write row to out.", ex);
597 }
catch (NullPointerException ex) {
598 logger.log(Level.SEVERE,
"Output writer is null. Page was not initialized before writing.", ex);
607 public void addThumbnailRows(List<Content> images) {
608 List<String> currentRow =
new ArrayList<>();
611 for (Content content : images) {
612 if (currentRow.size() == THUMBNAIL_COLUMNS) {
617 if (totalCount == MAX_THUMBS_PER_PAGE) {
621 rowCount = totalCount;
626 startDataType(NbBundle.getMessage(
this.getClass(),
"ReportHTML.addThumbRows.dataType.title", pages),
627 NbBundle.getMessage(
this.getClass(),
"ReportHTML.addThumbRows.dataType.msg"));
628 List<String> emptyHeaders =
new ArrayList<>();
629 for (
int i = 0; i < THUMBNAIL_COLUMNS; i++) {
630 emptyHeaders.add(
"");
632 startTable(emptyHeaders);
635 if (failsContentCheck(content)) {
639 AbstractFile file = (AbstractFile) content;
642 String thumbnailPath = prepareThumbnail(file);
643 if (thumbnailPath == null) {
646 String contentPath = saveContent(file,
"thumbs_fullsize");
649 nameInImage = file.getUniquePath();
650 }
catch (TskCoreException ex) {
651 nameInImage = file.getName();
654 StringBuilder linkToThumbnail =
new StringBuilder();
655 linkToThumbnail.append(
"<a href=\"");
656 linkToThumbnail.append(contentPath);
657 linkToThumbnail.append(
"\">");
658 linkToThumbnail.append(
"<img src=\"").append(thumbnailPath).append(
"\" title=\"").append(nameInImage).append(
"\"/>");
659 linkToThumbnail.append(
"</a><br>");
660 linkToThumbnail.append(file.getName()).append(
"<br>");
662 Services services = currentCase.getServices();
663 TagsManager tagsManager = services.getTagsManager();
665 List<ContentTag> tags = tagsManager.getContentTagsByContent(content);
666 if (tags.size() > 0) {
667 linkToThumbnail.append(NbBundle.getMessage(
this.getClass(),
"ReportHTML.thumbLink.tags"));
669 for (
int i = 0; i < tags.size(); i++) {
670 ContentTag tag = tags.get(i);
671 linkToThumbnail.append(tag.getName().getDisplayName());
672 if (i != tags.size() - 1) {
673 linkToThumbnail.append(
", ");
676 }
catch (TskCoreException ex) {
677 logger.log(Level.WARNING,
"Could not find get tags for file.", ex);
680 currentRow.add(linkToThumbnail.toString());
685 if (currentRow.isEmpty() ==
false) {
686 int extraCells = THUMBNAIL_COLUMNS - currentRow.size();
687 for (
int i = 0; i < extraCells; i++) {
695 rowCount = totalCount;
698 private boolean failsContentCheck(Content c) {
699 if (c instanceof AbstractFile ==
false) {
702 AbstractFile file = (AbstractFile) c;
704 || file.getType() == TSK_DB_FILES_TYPE_ENUM.UNALLOC_BLOCKS
705 || file.getType() == TSK_DB_FILES_TYPE_ENUM.UNUSED_BLOCKS) {
720 public String saveContent(AbstractFile file, String dirName) {
722 String dirName2 = dirName.replace(
"/",
"_");
723 dirName2 = dirName2.replace(
"\\",
"_");
726 StringBuilder localFilePath =
new StringBuilder();
728 localFilePath.append(path);
729 localFilePath.append(dirName2);
730 File localFileFolder =
new File(localFilePath.toString());
731 if (!localFileFolder.exists()) {
732 localFileFolder.mkdirs();
736 String fileName = file.getName();
737 String objectIdSuffix =
"_" + file.getId();
738 int lastDotIndex = fileName.lastIndexOf(
".");
739 if (lastDotIndex != -1 && lastDotIndex != 0) {
741 fileName = fileName.substring(0, lastDotIndex) + objectIdSuffix + fileName.substring(lastDotIndex, fileName.length());
745 fileName += objectIdSuffix;
747 localFilePath.append(File.separator);
748 localFilePath.append(fileName);
752 File localFile =
new File(localFilePath.toString());
753 if (!localFile.exists()) {
754 ExtractFscContentVisitor.extract(file, localFile, null, null);
758 return localFilePath.toString().substring(path.length());
769 public String dateToString(
long date) {
770 SimpleDateFormat sdf =
new java.text.SimpleDateFormat(
"yyyy/MM/dd HH:mm:ss");
771 return sdf.format(
new java.util.Date(date * 1000));
775 public String getRelativeFilePath() {
776 return "HTML Report" + File.separator +
"index.html";
780 public String getName() {
781 return NbBundle.getMessage(this.getClass(),
"ReportHTML.getName.text");
785 public String getDescription() {
786 return NbBundle.getMessage(this.getClass(),
"ReportHTML.getDesc.text");
792 private void writeCss() {
793 Writer cssOut = null;
795 cssOut =
new BufferedWriter(
new OutputStreamWriter(
new FileOutputStream(path +
"index.css"),
"UTF-8"));
796 String css =
"body {margin: 0px; padding: 0px; background: #FFFFFF; font: 13px/20px Arial, Helvetica, sans-serif; color: #535353;}\n" +
797 "#content {padding: 30px;}\n" +
798 "#header {width:100%; padding: 10px; line-height: 25px; background: #07A; color: #FFF; font-size: 20px;}\n" +
799 "h1 {font-size: 20px; font-weight: normal; color: #07A; padding: 0 0 7px 0; margin-top: 25px; border-bottom: 1px solid #D6D6D6;}\n" +
800 "h2 {font-size: 20px; font-weight: bolder; color: #07A;}\n" +
801 "h3 {font-size: 16px; color: #07A;}\n" +
802 "h4 {background: #07A; color: #FFF; font-size: 16px; margin: 0 0 0 25px; padding: 0; padding-left: 15px;}\n" +
803 "ul.nav {list-style-type: none; line-height: 35px; padding: 0px; margin-left: 15px;}\n" +
804 "ul li a {font-size: 14px; color: #444; text-decoration: none; padding-left: 25px;}\n" +
805 "ul li a:hover {text-decoration: underline;}\n" +
806 "p {margin: 0 0 20px 0;}\n" +
807 "table {white-space:nowrap; min-width: 700px; padding: 2; margin: 0; border-collapse: collapse; border-bottom: 2px solid #e5e5e5;}\n" +
808 ".keyword_list table {margin: 0 0 25px 25px; border-bottom: 2px solid #dedede;}\n" +
809 "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" +
810 "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" +
811 "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" +
812 "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; }\n" +
813 "table tr:nth-child(even) td {background: #f3f3f3;}";
815 }
catch (FileNotFoundException ex) {
816 logger.log(Level.SEVERE,
"Could not find index.css file to write to.", ex);
817 }
catch (UnsupportedEncodingException ex) {
818 logger.log(Level.SEVERE,
"Did not recognize encoding when writing index.css.", ex);
819 }
catch (IOException ex) {
820 logger.log(Level.SEVERE,
"Error creating Writer for index.css.", ex);
823 if (cssOut != null) {
827 }
catch (IOException ex) {
835 private void writeIndex() {
836 Writer indexOut = null;
837 String indexFilePath = path +
"index.html";
839 indexOut =
new BufferedWriter(
new OutputStreamWriter(
new FileOutputStream(indexFilePath),
"UTF-8"));
840 StringBuilder index =
new StringBuilder();
841 index.append(
"<head>\n<title>").append(
842 NbBundle.getMessage(
this.getClass(),
"ReportHTML.writeIndex.title", currentCase.getName())).append(
844 index.append(
"<link rel=\"icon\" type=\"image/ico\" href=\"favicon.ico\" />\n");
845 index.append(
"<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\n");
846 index.append(
"</head>\n");
847 index.append(
"<frameset cols=\"350px,*\">\n");
848 index.append(
"<frame src=\"nav.html\" name=\"nav\">\n");
849 index.append(
"<frame src=\"summary.html\" name=\"content\">\n");
850 index.append(
"<noframes>").append(NbBundle.getMessage(
this.getClass(),
"ReportHTML.writeIndex.noFrames.msg")).append(
"<br />\n");
851 index.append(NbBundle.getMessage(
this.getClass(),
"ReportHTML.writeIndex.noFrames.seeNav")).append(
"<br />\n");
852 index.append(NbBundle.getMessage(
this.getClass(),
"ReportHTML.writeIndex.seeSum")).append(
"</noframes>\n");
853 index.append(
"</frameset>\n");
854 index.append(
"</html>");
855 indexOut.write(index.toString());
856 Case.getCurrentCase().addReport(indexFilePath, NbBundle.getMessage(
this.getClass(),
857 "ReportHTML.writeIndex.srcModuleName.text"),
"");
858 }
catch (IOException ex) {
859 logger.log(Level.SEVERE,
"Error creating Writer for index.html: {0}", ex);
860 }
catch (TskCoreException ex) {
861 String errorMessage = String.format(
"Error adding %s to case as a report", indexFilePath);
862 logger.log(Level.SEVERE, errorMessage, ex);
865 if (indexOut != null) {
869 }
catch (IOException ex) {
877 private void writeNav() {
878 Writer navOut = null;
880 navOut =
new BufferedWriter(
new OutputStreamWriter(
new FileOutputStream(path +
"nav.html"),
"UTF-8"));
881 StringBuilder nav =
new StringBuilder();
882 nav.append(
"<html>\n<head>\n\t<title>").append(
883 NbBundle.getMessage(
this.getClass(),
"ReportHTML.writeNav.title"))
884 .append(
"</title>\n\t<link rel=\"stylesheet\" type=\"text/css\" href=\"index.css\" />\n");
885 nav.append(
"<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\n</head>\n<body>\n");
886 nav.append(
"<div id=\"content\">\n<h1>").append(
887 NbBundle.getMessage(
this.getClass(),
"ReportHTML.writeNav.h1")).append(
"</h1>\n");
888 nav.append(
"<ul class=\"nav\">\n");
889 nav.append(
"<li style=\"background: url(summary.png) left center no-repeat;\"><a href=\"summary.html\" target=\"content\">")
890 .append(NbBundle.getMessage(
this.getClass(),
"ReportHTML.writeNav.summary")).append(
"</a></li>\n");
892 for (String dataType : dataTypes.keySet()) {
893 String dataTypeEsc = dataTypeToFileName(dataType);
894 String iconFileName = useDataTypeIcon(dataType);
895 nav.append(
"<li style=\"background: url('").append(iconFileName)
896 .append(
"') left center no-repeat;\"><a href=\"")
897 .append(dataTypeEsc).append(
".html\" target=\"content\">")
898 .append(dataType).append(
" (").append(dataTypes.get(dataType))
899 .append(
")</a></li>\n");
901 nav.append(
"</ul>\n");
902 nav.append(
"</div>\n</body>\n</html>");
903 navOut.write(nav.toString());
904 }
catch (IOException ex) {
905 logger.log(Level.SEVERE,
"Failed to write end of report navigation menu: {0}", ex);
907 if (navOut != null) {
911 }
catch (IOException ex) {
912 logger.log(Level.WARNING,
"Could not close navigation out writer.");
917 InputStream in = null;
918 OutputStream output = null;
922 String generatorLogoPath = reportBranding.getGeneratorLogoPath();
923 if (generatorLogoPath != null && !generatorLogoPath.isEmpty()) {
924 File from =
new File(generatorLogoPath);
925 File to =
new File(path);
926 FileUtil.copyFile(FileUtil.toFileObject(from), FileUtil.toFileObject(to),
"generator_logo");
929 String agencyLogoPath = reportBranding.getAgencyLogoPath();
930 if (agencyLogoPath != null && !agencyLogoPath.isEmpty()) {
931 File from =
new File(agencyLogoPath);
932 File to =
new File(path);
933 FileUtil.copyFile(FileUtil.toFileObject(from), FileUtil.toFileObject(to),
"agency_logo");
936 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/favicon.ico");
937 output =
new FileOutputStream(
new File(path + File.separator +
"favicon.ico"));
938 FileUtil.copy(in, output);
942 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/summary.png");
943 output =
new FileOutputStream(
new File(path + File.separator +
"summary.png"));
944 FileUtil.copy(in, output);
948 }
catch (IOException ex) {
949 logger.log(Level.SEVERE,
"Failed to extract images for HTML report.", ex);
951 if (output != null) {
955 }
catch (IOException ex) {
961 }
catch (IOException ex) {
970 private void writeSummary() {
973 out =
new BufferedWriter(
new OutputStreamWriter(
new FileOutputStream(path +
"summary.html"),
"UTF-8"));
974 StringBuilder head =
new StringBuilder();
975 head.append(
"<html>\n<head>\n<title>").append(
976 NbBundle.getMessage(
this.getClass(),
"ReportHTML.writeSum.title")).append(
"</title>\n");
977 head.append(
"<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\n");
978 head.append(
"<style type=\"text/css\">\n");
979 head.append(
"body { padding: 0px; margin: 0px; font: 13px/20px Arial, Helvetica, sans-serif; color: #535353; }\n");
980 head.append(
"#wrapper { width: 90%; margin: 0px auto; margin-top: 35px; }\n");
981 head.append(
"h1 { color: #07A; font-size: 36px; line-height: 42px; font-weight: normal; margin: 0px; border-bottom: 1px solid #81B9DB; }\n");
982 head.append(
"h1 span { color: #F00; display: block; font-size: 16px; font-weight: bold; line-height: 22px;}\n");
983 head.append(
"h2 { padding: 0 0 3px 0; margin: 0px; color: #07A; font-weight: normal; border-bottom: 1px dotted #81B9DB; }\n");
984 head.append(
"table td { padding-right: 25px; }\n");
985 head.append(
"p.subheadding { padding: 0px; margin: 0px; font-size: 11px; color: #B5B5B5; }\n");
986 head.append(
".title { width: 660px; margin-bottom: 50px; }\n");
987 head.append(
".left { float: left; width: 250px; margin-top: 20px; text-align: center; }\n");
988 head.append(
".left img { max-width: 250px; max-height: 250px; min-width: 200px; min-height: 200px; }\n");
989 head.append(
".right { float: right; width: 385px; margin-top: 25px; font-size: 14px; }\n");
990 head.append(
".clear { clear: both; }\n");
991 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");
992 head.append(
".info table { margin: 0 25px 20px 25px; }\n");
993 head.append(
"</style>\n");
994 head.append(
"</head>\n<body>\n");
995 out.write(head.toString());
997 DateFormat datetimeFormat =
new SimpleDateFormat(
"yyyy/MM/dd HH:mm:ss");
998 Date date =
new Date();
999 String datetime = datetimeFormat.format(date);
1001 String caseName = currentCase.getName();
1002 String caseNumber = currentCase.getNumber();
1003 String examiner = currentCase.getExaminer();
1006 imagecount = currentCase.getDataSources().size();
1007 }
catch (TskCoreException ex) {
1011 StringBuilder summary =
new StringBuilder();
1012 boolean running =
false;
1013 if (IngestManager.getInstance().isIngestRunning()) {
1017 final String reportTitle = reportBranding.getReportTitle();
1018 final String reportFooter = reportBranding.getReportFooter();
1019 final boolean agencyLogoSet = reportBranding.getAgencyLogoPath() != null && !reportBranding.getAgencyLogoPath().isEmpty();
1020 final boolean generatorLogoSet = reportBranding.getGeneratorLogoPath() != null && !reportBranding.getGeneratorLogoPath().isEmpty();
1022 summary.append(
"<div id=\"wrapper\">\n");
1023 summary.append(
"<h1>").append(reportTitle)
1024 .append(running ? NbBundle.getMessage(
this.getClass(),
"ReportHTML.writeSum.warningMsg") :
"")
1026 summary.append(
"<p class=\"subheadding\">").append(
1027 NbBundle.getMessage(
this.getClass(),
"ReportHTML.writeSum.reportGenOn.text", datetime)).append(
"</p>\n");
1028 summary.append(
"<div class=\"title\">\n");
1029 if (agencyLogoSet) {
1030 summary.append(
"<div class=\"left\">\n");
1031 summary.append(
"<img src=\"agency_logo.png\" />\n");
1032 summary.append(
"</div>\n");
1034 final String align = agencyLogoSet ?
"right" :
"left";
1035 summary.append(
"<div class=\"").append(align).append(
"\">\n");
1036 summary.append(
"<table>\n");
1037 summary.append(
"<tr><td>").append(NbBundle.getMessage(
this.getClass(),
"ReportHTML.writeSum.caseName"))
1038 .append(
"</td><td>").append(caseName).append(
"</td></tr>\n");
1039 summary.append(
"<tr><td>").append(NbBundle.getMessage(
this.getClass(),
"ReportHTML.writeSum.caseNum"))
1040 .append(
"</td><td>").append(!caseNumber.isEmpty() ? caseNumber : NbBundle
1041 .getMessage(this.getClass(),
"ReportHTML.writeSum.noCaseNum")).append(
"</td></tr>\n");
1042 summary.append(
"<tr><td>").append(NbBundle.getMessage(
this.getClass(),
"ReportHTML.writeSum.examiner")).append(
"</td><td>")
1043 .append(!examiner.isEmpty() ? examiner : NbBundle
1044 .getMessage(this.getClass(),
"ReportHTML.writeSum.noExaminer"))
1045 .append(
"</td></tr>\n");
1046 summary.append(
"<tr><td>").append(NbBundle.getMessage(
this.getClass(),
"ReportHTML.writeSum.numImages"))
1047 .append(
"</td><td>").append(imagecount).append(
"</td></tr>\n");
1048 summary.append(
"</table>\n");
1049 summary.append(
"</div>\n");
1050 summary.append(
"<div class=\"clear\"></div>\n");
1051 summary.append(
"</div>\n");
1052 summary.append(NbBundle.getMessage(
this.getClass(),
"ReportHTML.writeSum.imageInfoHeading"));
1053 summary.append(
"<div class=\"info\">\n");
1055 for (Content c : currentCase.getDataSources()) {
1056 summary.append(
"<p>").append(c.getName()).append(
"</p>\n");
1057 if (c instanceof Image) {
1058 Image img = (Image) c;
1060 summary.append(
"<table>\n");
1061 summary.append(
"<tr><td>").append(
1062 NbBundle.getMessage(
this.getClass(),
"ReportHTML.writeSum.timezone"))
1063 .append(
"</td><td>").append(img.getTimeZone()).append(
"</td></tr>\n");
1064 for (String imgPath : img.getPaths()) {
1065 summary.append(
"<tr><td>").append(
1066 NbBundle.getMessage(
this.getClass(),
"ReportHTML.writeSum.path"))
1067 .append(
"</td><td>").append(imgPath).append(
"</td></tr>\n");
1069 summary.append(
"</table>\n");
1072 }
catch (TskCoreException ex) {
1073 logger.log(Level.WARNING,
"Unable to get image information for the HTML report.");
1075 summary.append(
"</div>\n");
1076 if (generatorLogoSet) {
1077 summary.append(
"<div class=\"left\">\n");
1078 summary.append(
"<img src=\"generator_logo.png\" />\n");
1079 summary.append(
"</div>\n");
1081 summary.append(
"<div class=\"clear\"></div>\n");
1082 if (reportFooter != null) {
1083 summary.append(
"<p class=\"subheadding\">").append(reportFooter).append(
"</p>\n");
1085 summary.append(
"</div>\n");
1086 summary.append(
"</body></html>");
1087 out.write(summary.toString());
1088 }
catch (FileNotFoundException ex) {
1089 logger.log(Level.SEVERE,
"Could not find summary.html file to write to.");
1090 }
catch (UnsupportedEncodingException ex) {
1091 logger.log(Level.SEVERE,
"Did not recognize encoding when writing summary.hmtl.");
1092 }
catch (IOException ex) {
1093 logger.log(Level.SEVERE,
"Error creating Writer for summary.html.");
1100 }
catch (IOException ex) {
1105 private String prepareThumbnail(AbstractFile file) {
1106 File thumbFile = ImageUtils.getCachedThumbnailFile(file, ImageUtils.ICON_SIZE_MEDIUM);
1107 if (thumbFile.exists() ==
false) {
1111 File to =
new File(thumbsPath);
1112 FileObject from = FileUtil.toFileObject(thumbFile);
1113 FileObject dest = FileUtil.toFileObject(to);
1114 FileUtil.copyFile(from, dest, thumbFile.getName(),
"");
1115 }
catch (IOException ex) {
1116 logger.log(Level.SEVERE,
"Failed to write thumb file to report directory.", ex);
1119 return THUMBS_REL_PATH + thumbFile.getName();
static String escapeFileName(String fileName)