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.nio.file.Files;
36 import java.nio.file.Path;
37 import java.nio.file.Paths;
38 import java.text.DateFormat;
39 import java.text.SimpleDateFormat;
40 import java.util.ArrayList;
41 import java.util.Date;
42 import java.util.List;
44 import java.util.TreeMap;
45 import java.util.logging.Level;
46 import org.openide.filesystems.FileObject;
47 import org.openide.filesystems.FileUtil;
48 import org.openide.util.NbBundle;
58 import org.
sleuthkit.datamodel.BlackboardArtifact.ARTIFACT_TYPE;
64 import org.
sleuthkit.datamodel.TskData.TSK_DB_FILES_TYPE_ENUM;
66 class ReportHTML
implements TableReportModule {
68 private static final Logger logger = Logger.getLogger(ReportHTML.class.getName());
69 private static final String THUMBS_REL_PATH =
"thumbs" + File.separator;
70 private static ReportHTML instance;
71 private static final int MAX_THUMBS_PER_PAGE = 1000;
72 private Case currentCase;
73 private SleuthkitCase skCase;
74 static Integer THUMBNAIL_COLUMNS = 5;
76 private Map<String, Integer> dataTypes;
78 private String thumbsPath;
79 private String currentDataType;
80 private Integer rowCount;
83 private final ReportBranding reportBranding;
86 public static synchronized ReportHTML getDefault() {
87 if (instance == null) {
88 instance =
new ReportHTML();
94 private ReportHTML() {
95 reportBranding =
new ReportBranding();
99 private void refresh() {
100 currentCase = Case.getCurrentCase();
101 skCase = currentCase.getSleuthkitCase();
103 dataTypes =
new TreeMap<>();
107 currentDataType =
"";
113 }
catch (IOException ex) {
125 private String dataTypeToFileName(String dataType) {
129 fileName = fileName.replaceAll(
" ",
"_");
138 private String useDataTypeIcon(String dataType) {
142 OutputStream output = null;
144 logger.log(Level.INFO,
"useDataTypeIcon: dataType = {0}", dataType);
147 BlackboardArtifact.ARTIFACT_TYPE artifactType = null;
148 for (ARTIFACT_TYPE v : ARTIFACT_TYPE.values()) {
149 if (v.getDisplayName().equals(dataType)) {
154 if (null != artifactType) {
156 iconFileName = dataTypeToFileName(artifactType.getDisplayName()) +
".png";
157 iconFilePath = path + File.separator + iconFileName;
160 switch (artifactType) {
161 case TSK_WEB_BOOKMARK:
162 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/bookmarks.png");
165 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/cookies.png");
167 case TSK_WEB_HISTORY:
168 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/history.png");
170 case TSK_WEB_DOWNLOAD:
171 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/downloads.png");
173 case TSK_RECENT_OBJECT:
174 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/recent.png");
176 case TSK_INSTALLED_PROG:
177 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/installed.png");
179 case TSK_KEYWORD_HIT:
180 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/keywords.png");
182 case TSK_HASHSET_HIT:
183 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/hash.png");
185 case TSK_DEVICE_ATTACHED:
186 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/devices.png");
188 case TSK_WEB_SEARCH_QUERY:
189 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/search.png");
191 case TSK_METADATA_EXIF:
192 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/exif.png");
195 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/userbookmarks.png");
197 case TSK_TAG_ARTIFACT:
198 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/userbookmarks.png");
200 case TSK_SERVICE_ACCOUNT:
201 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/account-icon-16.png");
204 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/contact.png");
207 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/message.png");
210 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/calllog.png");
212 case TSK_CALENDAR_ENTRY:
213 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/calendar.png");
215 case TSK_SPEED_DIAL_ENTRY:
216 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/speeddialentry.png");
218 case TSK_BLUETOOTH_PAIRING:
219 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/bluetooth.png");
221 case TSK_GPS_BOOKMARK:
222 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/gpsfav.png");
224 case TSK_GPS_LAST_KNOWN_LOCATION:
225 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/gps-lastlocation.png");
228 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/gps-search.png");
231 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/computer.png");
233 case TSK_GPS_TRACKPOINT:
234 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/gps_trackpoint.png");
237 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/gps_trackpoint.png");
240 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/images/mail-icon-16.png");
242 case TSK_ENCRYPTION_DETECTED:
243 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/images/encrypted-file.png");
245 case TSK_EXT_MISMATCH_DETECTED:
246 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/images/mismatch-16.png");
248 case TSK_INTERESTING_ARTIFACT_HIT:
249 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/images/interesting_item.png");
251 case TSK_INTERESTING_FILE_HIT:
252 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/images/interesting_item.png");
255 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/installed.png");
257 case TSK_REMOTE_DRIVE:
258 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/drive_network.png");
261 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/accounts.png");
264 logger.log(Level.WARNING,
"useDataTypeIcon: unhandled artifact type = " + dataType);
265 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/star.png");
266 iconFileName =
"star.png";
267 iconFilePath = path + File.separator + iconFileName;
270 }
else if (dataType.startsWith(ARTIFACT_TYPE.TSK_ACCOUNT.getDisplayName())) {
277 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/accounts.png");
278 iconFileName =
"accounts.png";
279 iconFilePath = path + File.separator + iconFileName;
281 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/star.png");
282 iconFileName =
"star.png";
283 iconFilePath = path + File.separator + iconFileName;
287 output =
new FileOutputStream(iconFilePath);
288 FileUtil.copy(in, output);
291 }
catch (IOException ex) {
292 logger.log(Level.SEVERE,
"Failed to extract images for HTML report.", ex);
294 if (output != null) {
298 }
catch (IOException ex) {
304 }
catch (IOException ex) {
319 public void startReport(String baseReportDir) {
323 this.path = baseReportDir +
"HTML Report" + File.separator;
324 this.thumbsPath = this.path +
"thumbs" + File.separator;
326 FileUtil.createFolder(
new File(this.path));
327 FileUtil.createFolder(
new File(this.thumbsPath));
328 }
catch (IOException ex) {
329 logger.log(Level.SEVERE,
"Unable to make HTML report folder.");
342 public void endReport() {
347 }
catch (IOException ex) {
348 logger.log(Level.WARNING,
"Could not close the output writer when ending report.", ex);
362 public void startDataType(String name, String description) {
363 String title = dataTypeToFileName(name);
365 out =
new BufferedWriter(
new OutputStreamWriter(
new FileOutputStream(path + title +
".html"),
"UTF-8"));
366 }
catch (FileNotFoundException ex) {
367 logger.log(Level.SEVERE,
"File not found: {0}", ex);
368 }
catch (UnsupportedEncodingException ex) {
369 logger.log(Level.SEVERE,
"Unrecognized encoding");
373 StringBuilder page =
new StringBuilder();
374 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");
375 page.append(
"<div id=\"header\">").append(name).append(
"</div>\n<div id=\"content\">\n");
376 if (!description.isEmpty()) {
377 page.append(
"<p><strong>");
378 page.append(description);
379 page.append(
"</string></p>\n");
381 out.write(page.toString());
382 currentDataType = name;
384 }
catch (IOException ex) {
385 logger.log(Level.SEVERE,
"Failed to write page head: {0}", ex);
394 public void endDataType() {
395 dataTypes.put(currentDataType, rowCount);
397 out.write(
"</div>\n</body>\n</html>\n");
398 }
catch (IOException ex) {
399 logger.log(Level.SEVERE,
"Failed to write end of HTML report.", ex);
405 }
catch (IOException ex) {
406 logger.log(Level.WARNING,
"Could not close the output writer when ending data type.", ex);
419 public void startSet(String setName) {
420 StringBuilder set =
new StringBuilder();
421 set.append(
"<h1><a name=\"").append(setName).append(
"\">").append(setName).append(
"</a></h1>\n");
422 set.append(
"<div class=\"keyword_list\">\n");
425 out.write(set.toString());
426 }
catch (IOException ex) {
427 logger.log(Level.SEVERE,
"Failed to write set: {0}", ex);
435 public void endSet() {
437 out.write(
"</div>\n");
438 }
catch (IOException ex) {
439 logger.log(Level.SEVERE,
"Failed to write end of set: {0}", ex);
449 public void addSetIndex(List<String> sets) {
450 StringBuilder index =
new StringBuilder();
451 index.append(
"<ul>\n");
452 for (String set : sets) {
453 index.append(
"\t<li><a href=\"#").append(set).append(
"\">").append(set).append(
"</a></li>\n");
455 index.append(
"</ul>\n");
457 out.write(index.toString());
458 }
catch (IOException ex) {
459 logger.log(Level.SEVERE,
"Failed to add set index: {0}", ex);
469 public void addSetElement(String elementName) {
471 out.write(
"<h4>" + elementName +
"</h4>\n");
472 }
catch (IOException ex) {
473 logger.log(Level.SEVERE,
"Failed to write set element: {0}", ex);
483 public void startTable(List<String> titles) {
484 StringBuilder ele =
new StringBuilder();
485 ele.append(
"<table>\n<thead>\n\t<tr>\n");
486 for (String title : titles) {
487 ele.append(
"\t\t<th>").append(title).append(
"</th>\n");
489 ele.append(
"\t</tr>\n</thead>\n");
492 out.write(ele.toString());
493 }
catch (IOException ex) {
494 logger.log(Level.SEVERE,
"Failed to write table start: {0}", ex);
505 public void startContentTagsTable(List<String> columnHeaders) {
506 StringBuilder htmlOutput =
new StringBuilder();
507 htmlOutput.append(
"<table>\n<thead>\n\t<tr>\n");
510 for (String columnHeader : columnHeaders) {
511 htmlOutput.append(
"\t\t<th>").append(columnHeader).append(
"</th>\n");
515 htmlOutput.append(
"\t\t<th></th>\n");
517 htmlOutput.append(
"\t</tr>\n</thead>\n");
520 out.write(htmlOutput.toString());
521 }
catch (IOException ex) {
522 logger.log(Level.SEVERE,
"Failed to write table start: {0}", ex);
530 public void endTable() {
532 out.write(
"</table>\n");
533 }
catch (IOException ex) {
534 logger.log(Level.SEVERE,
"Failed to write end of table: {0}", ex);
544 public void addRow(List<String> row) {
545 StringBuilder builder =
new StringBuilder();
546 builder.append(
"\t<tr>\n");
547 for (String cell : row) {
548 builder.append(
"\t\t<td>").append(cell).append(
"</td>\n");
550 builder.append(
"\t</tr>\n");
554 out.write(builder.toString());
555 }
catch (IOException ex) {
556 logger.log(Level.SEVERE,
"Failed to write row to out.", ex);
557 }
catch (NullPointerException ex) {
558 logger.log(Level.SEVERE,
"Output writer is null. Page was not initialized before writing.", ex);
572 public void addRowWithTaggedContentHyperlink(List<String> row, ContentTag contentTag) {
573 Content content = contentTag.getContent();
574 if (content instanceof AbstractFile ==
false) {
578 AbstractFile file = (AbstractFile) content;
580 StringBuilder localFileLink =
new StringBuilder();
583 || file.getType() == TSK_DB_FILES_TYPE_ENUM.UNALLOC_BLOCKS
584 || file.getType() == TSK_DB_FILES_TYPE_ENUM.UNUSED_BLOCKS)) {
585 localFileLink.append(
"<a href=\"");
587 String localFilePath = saveContent(file, contentTag.getName().getDisplayName());
588 localFileLink.append(localFilePath);
589 localFileLink.append(
"\" target=\"_top\">");
592 StringBuilder builder =
new StringBuilder();
593 builder.append(
"\t<tr>\n");
594 int positionCounter = 0;
595 for (String cell : row) {
597 if (positionCounter == 1) {
598 builder.append(
"\t\t<td class=\"left_align_cell\">").append(localFileLink.toString()).append(cell).append(
"</a></td>\n");
599 }
else if (positionCounter == 7) {
600 builder.append(
"\t\t<td class=\"right_align_cell\">").append(cell).append(
"</td>\n");
602 builder.append(
"\t\t<td>").append(cell).append(
"</td>\n");
606 builder.append(
"\t</tr>\n");
610 out.write(builder.toString());
611 }
catch (IOException ex) {
612 logger.log(Level.SEVERE,
"Failed to write row to out.", ex);
613 }
catch (NullPointerException ex) {
614 logger.log(Level.SEVERE,
"Output writer is null. Page was not initialized before writing.", ex);
623 public void addThumbnailRows(List<Content> images) {
624 List<String> currentRow =
new ArrayList<>();
627 for (Content content : images) {
628 if (currentRow.size() == THUMBNAIL_COLUMNS) {
633 if (totalCount == MAX_THUMBS_PER_PAGE) {
637 rowCount = totalCount;
642 startDataType(NbBundle.getMessage(
this.getClass(),
"ReportHTML.addThumbRows.dataType.title", pages),
643 NbBundle.getMessage(
this.getClass(),
"ReportHTML.addThumbRows.dataType.msg"));
644 List<String> emptyHeaders =
new ArrayList<>();
645 for (
int i = 0; i < THUMBNAIL_COLUMNS; i++) {
646 emptyHeaders.add(
"");
648 startTable(emptyHeaders);
651 if (failsContentCheck(content)) {
655 AbstractFile file = (AbstractFile) content;
658 String thumbnailPath = prepareThumbnail(file);
659 if (thumbnailPath == null) {
662 String contentPath = saveContent(file,
"thumbs_fullsize");
665 nameInImage = file.getUniquePath();
666 }
catch (TskCoreException ex) {
667 nameInImage = file.getName();
670 StringBuilder linkToThumbnail =
new StringBuilder();
671 linkToThumbnail.append(
"<a href=\"");
672 linkToThumbnail.append(contentPath);
673 linkToThumbnail.append(
"\">");
674 linkToThumbnail.append(
"<img src=\"").append(thumbnailPath).append(
"\" title=\"").append(nameInImage).append(
"\"/>");
675 linkToThumbnail.append(
"</a><br>");
676 linkToThumbnail.append(file.getName()).append(
"<br>");
678 Services services = currentCase.getServices();
679 TagsManager tagsManager = services.getTagsManager();
681 List<ContentTag> tags = tagsManager.getContentTagsByContent(content);
682 if (tags.size() > 0) {
683 linkToThumbnail.append(NbBundle.getMessage(
this.getClass(),
"ReportHTML.thumbLink.tags"));
685 for (
int i = 0; i < tags.size(); i++) {
686 ContentTag tag = tags.get(i);
687 linkToThumbnail.append(tag.getName().getDisplayName());
688 if (i != tags.size() - 1) {
689 linkToThumbnail.append(
", ");
692 }
catch (TskCoreException ex) {
693 logger.log(Level.WARNING,
"Could not find get tags for file.", ex);
696 currentRow.add(linkToThumbnail.toString());
701 if (currentRow.isEmpty() ==
false) {
702 int extraCells = THUMBNAIL_COLUMNS - currentRow.size();
703 for (
int i = 0; i < extraCells; i++) {
711 rowCount = totalCount;
714 private boolean failsContentCheck(Content c) {
715 if (c instanceof AbstractFile ==
false) {
718 AbstractFile file = (AbstractFile) c;
720 || file.getType() == TSK_DB_FILES_TYPE_ENUM.UNALLOC_BLOCKS
721 || file.getType() == TSK_DB_FILES_TYPE_ENUM.UNUSED_BLOCKS) {
736 public String saveContent(AbstractFile file, String dirName) {
741 StringBuilder localFilePath =
new StringBuilder();
743 localFilePath.append(path);
744 localFilePath.append(dirName2);
745 File localFileFolder =
new File(localFilePath.toString());
746 if (!localFileFolder.exists()) {
747 localFileFolder.mkdirs();
751 String fileName = file.getName();
752 String objectIdSuffix =
"_" + file.getId();
753 int lastDotIndex = fileName.lastIndexOf(
".");
754 if (lastDotIndex != -1 && lastDotIndex != 0) {
756 fileName = fileName.substring(0, lastDotIndex) + objectIdSuffix + fileName.substring(lastDotIndex, fileName.length());
760 fileName += objectIdSuffix;
762 localFilePath.append(File.separator);
763 localFilePath.append(fileName);
767 File localFile =
new File(localFilePath.toString());
768 if (!localFile.exists()) {
769 ExtractFscContentVisitor.extract(file, localFile, null, null);
773 return localFilePath.toString().substring(path.length());
784 public String dateToString(
long date) {
785 SimpleDateFormat sdf =
new java.text.SimpleDateFormat(
"yyyy/MM/dd HH:mm:ss");
786 return sdf.format(
new java.util.Date(date * 1000));
790 public String getRelativeFilePath() {
791 return "HTML Report" + File.separator +
"index.html";
795 public String getName() {
796 return NbBundle.getMessage(this.getClass(),
"ReportHTML.getName.text");
800 public String getDescription() {
801 return NbBundle.getMessage(this.getClass(),
"ReportHTML.getDesc.text");
807 private void writeCss() {
808 Writer cssOut = null;
810 cssOut =
new BufferedWriter(
new OutputStreamWriter(
new FileOutputStream(path +
"index.css"),
"UTF-8"));
811 String css =
"body {margin: 0px; padding: 0px; background: #FFFFFF; font: 13px/20px Arial, Helvetica, sans-serif; color: #535353;}\n" +
812 "#content {padding: 30px;}\n" +
813 "#header {width:100%; padding: 10px; line-height: 25px; background: #07A; color: #FFF; font-size: 20px;}\n" +
814 "h1 {font-size: 20px; font-weight: normal; color: #07A; padding: 0 0 7px 0; margin-top: 25px; border-bottom: 1px solid #D6D6D6;}\n" +
815 "h2 {font-size: 20px; font-weight: bolder; color: #07A;}\n" +
816 "h3 {font-size: 16px; color: #07A;}\n" +
817 "h4 {background: #07A; color: #FFF; font-size: 16px; margin: 0 0 0 25px; padding: 0; padding-left: 15px;}\n" +
818 "ul.nav {list-style-type: none; line-height: 35px; padding: 0px; margin-left: 15px;}\n" +
819 "ul li a {font-size: 14px; color: #444; text-decoration: none; padding-left: 25px;}\n" +
820 "ul li a:hover {text-decoration: underline;}\n" +
821 "p {margin: 0 0 20px 0;}\n" +
822 "table {white-space:nowrap; min-width: 700px; padding: 2; margin: 0; border-collapse: collapse; border-bottom: 2px solid #e5e5e5;}\n" +
823 ".keyword_list table {margin: 0 0 25px 25px; border-bottom: 2px solid #dedede;}\n" +
824 "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" +
825 "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" +
826 "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" +
827 "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" +
828 "table tr:nth-child(even) td {background: #f3f3f3;}";
830 }
catch (FileNotFoundException ex) {
831 logger.log(Level.SEVERE,
"Could not find index.css file to write to.", ex);
832 }
catch (UnsupportedEncodingException ex) {
833 logger.log(Level.SEVERE,
"Did not recognize encoding when writing index.css.", ex);
834 }
catch (IOException ex) {
835 logger.log(Level.SEVERE,
"Error creating Writer for index.css.", ex);
838 if (cssOut != null) {
842 }
catch (IOException ex) {
850 private void writeIndex() {
851 Writer indexOut = null;
852 String indexFilePath = path +
"index.html";
854 indexOut =
new BufferedWriter(
new OutputStreamWriter(
new FileOutputStream(indexFilePath),
"UTF-8"));
855 StringBuilder index =
new StringBuilder();
856 final String reportTitle = reportBranding.getReportTitle();
857 String iconPath = reportBranding.getAgencyLogoPath();
858 if (iconPath == null) {
860 iconPath =
"favicon.ico";
862 iconPath = Paths.get(reportBranding.getAgencyLogoPath()).getFileName().toString();
864 index.append(
"<head>\n<title>").append(reportTitle).append(
" ").append(
865 NbBundle.getMessage(
this.getClass(),
"ReportHTML.writeIndex.title", currentCase.getDisplayName())).append(
867 index.append(
"<link rel=\"icon\" type=\"image/ico\" href=\"")
868 .append(iconPath).append(
"\" />\n");
869 index.append(
"<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\n");
870 index.append(
"</head>\n");
871 index.append(
"<frameset cols=\"350px,*\">\n");
872 index.append(
"<frame src=\"nav.html\" name=\"nav\">\n");
873 index.append(
"<frame src=\"summary.html\" name=\"content\">\n");
874 index.append(
"<noframes>").append(NbBundle.getMessage(
this.getClass(),
"ReportHTML.writeIndex.noFrames.msg")).append(
"<br />\n");
875 index.append(NbBundle.getMessage(
this.getClass(),
"ReportHTML.writeIndex.noFrames.seeNav")).append(
"<br />\n");
876 index.append(NbBundle.getMessage(
this.getClass(),
"ReportHTML.writeIndex.seeSum")).append(
"</noframes>\n");
877 index.append(
"</frameset>\n");
878 index.append(
"</html>");
879 indexOut.write(index.toString());
880 Case.getCurrentCase().addReport(indexFilePath, NbBundle.getMessage(
this.getClass(),
881 "ReportHTML.writeIndex.srcModuleName.text"),
"");
882 }
catch (IOException ex) {
883 logger.log(Level.SEVERE,
"Error creating Writer for index.html: {0}", ex);
884 }
catch (TskCoreException ex) {
885 String errorMessage = String.format(
"Error adding %s to case as a report", indexFilePath);
886 logger.log(Level.SEVERE, errorMessage, ex);
889 if (indexOut != null) {
893 }
catch (IOException ex) {
901 private void writeNav() {
902 Writer navOut = null;
904 navOut =
new BufferedWriter(
new OutputStreamWriter(
new FileOutputStream(path +
"nav.html"),
"UTF-8"));
905 StringBuilder nav =
new StringBuilder();
906 nav.append(
"<html>\n<head>\n\t<title>").append(
907 NbBundle.getMessage(
this.getClass(),
"ReportHTML.writeNav.title"))
908 .append(
"</title>\n\t<link rel=\"stylesheet\" type=\"text/css\" href=\"index.css\" />\n");
909 nav.append(
"<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\n</head>\n<body>\n");
910 nav.append(
"<div id=\"content\">\n<h1>").append(
911 NbBundle.getMessage(
this.getClass(),
"ReportHTML.writeNav.h1")).append(
"</h1>\n");
912 nav.append(
"<ul class=\"nav\">\n");
913 nav.append(
"<li style=\"background: url(summary.png) left center no-repeat;\"><a href=\"summary.html\" target=\"content\">")
914 .append(NbBundle.getMessage(
this.getClass(),
"ReportHTML.writeNav.summary")).append(
"</a></li>\n");
916 for (String dataType : dataTypes.keySet()) {
917 String dataTypeEsc = dataTypeToFileName(dataType);
918 String iconFileName = useDataTypeIcon(dataType);
919 nav.append(
"<li style=\"background: url('").append(iconFileName)
920 .append(
"') left center no-repeat;\"><a href=\"")
921 .append(dataTypeEsc).append(
".html\" target=\"content\">")
922 .append(dataType).append(
" (").append(dataTypes.get(dataType))
923 .append(
")</a></li>\n");
925 nav.append(
"</ul>\n");
926 nav.append(
"</div>\n</body>\n</html>");
927 navOut.write(nav.toString());
928 }
catch (IOException ex) {
929 logger.log(Level.SEVERE,
"Failed to write end of report navigation menu: {0}", ex);
931 if (navOut != null) {
935 }
catch (IOException ex) {
936 logger.log(Level.WARNING,
"Could not close navigation out writer.");
941 InputStream in = null;
942 OutputStream output = null;
946 String generatorLogoPath = reportBranding.getGeneratorLogoPath();
947 if (generatorLogoPath != null && !generatorLogoPath.isEmpty()) {
948 File from =
new File(generatorLogoPath);
949 File to =
new File(path);
950 FileUtil.copyFile(FileUtil.toFileObject(from), FileUtil.toFileObject(to),
"generator_logo");
953 String agencyLogoPath = reportBranding.getAgencyLogoPath();
954 if (agencyLogoPath != null && !agencyLogoPath.isEmpty()) {
955 Path destinationPath = Paths.get(path);
956 Files.copy(Files.newInputStream(Paths.get(agencyLogoPath)), destinationPath.resolve(Paths.get(agencyLogoPath).getFileName()));
959 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/favicon.ico");
960 output =
new FileOutputStream(
new File(path + File.separator +
"favicon.ico"));
961 FileUtil.copy(in, output);
965 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/summary.png");
966 output =
new FileOutputStream(
new File(path + File.separator +
"summary.png"));
967 FileUtil.copy(in, output);
971 }
catch (IOException ex) {
972 logger.log(Level.SEVERE,
"Failed to extract images for HTML report.", ex);
974 if (output != null) {
978 }
catch (IOException ex) {
984 }
catch (IOException ex) {
993 private void writeSummary() {
996 out =
new BufferedWriter(
new OutputStreamWriter(
new FileOutputStream(path +
"summary.html"),
"UTF-8"));
997 StringBuilder head =
new StringBuilder();
998 head.append(
"<html>\n<head>\n<title>").append(
999 NbBundle.getMessage(
this.getClass(),
"ReportHTML.writeSum.title")).append(
"</title>\n");
1000 head.append(
"<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\n");
1001 head.append(
"<style type=\"text/css\">\n");
1002 head.append(
"body { padding: 0px; margin: 0px; font: 13px/20px Arial, Helvetica, sans-serif; color: #535353; }\n");
1003 head.append(
"#wrapper { width: 90%; margin: 0px auto; margin-top: 35px; }\n");
1004 head.append(
"h1 { color: #07A; font-size: 36px; line-height: 42px; font-weight: normal; margin: 0px; border-bottom: 1px solid #81B9DB; }\n");
1005 head.append(
"h1 span { color: #F00; display: block; font-size: 16px; font-weight: bold; line-height: 22px;}\n");
1006 head.append(
"h2 { padding: 0 0 3px 0; margin: 0px; color: #07A; font-weight: normal; border-bottom: 1px dotted #81B9DB; }\n");
1007 head.append(
"table td { padding-right: 25px; }\n");
1008 head.append(
"p.subheadding { padding: 0px; margin: 0px; font-size: 11px; color: #B5B5B5; }\n");
1009 head.append(
".title { width: 660px; margin-bottom: 50px; }\n");
1010 head.append(
".left { float: left; width: 250px; margin-top: 20px; text-align: center; }\n");
1011 head.append(
".left img { max-width: 250px; max-height: 250px; min-width: 200px; min-height: 200px; }\n");
1012 head.append(
".right { float: right; width: 385px; margin-top: 25px; font-size: 14px; }\n");
1013 head.append(
".clear { clear: both; }\n");
1014 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");
1015 head.append(
".info table { margin: 0 25px 20px 25px; }\n");
1016 head.append(
"</style>\n");
1017 head.append(
"</head>\n<body>\n");
1018 out.write(head.toString());
1020 DateFormat datetimeFormat =
new SimpleDateFormat(
"yyyy/MM/dd HH:mm:ss");
1021 Date date =
new Date();
1022 String datetime = datetimeFormat.format(date);
1024 String caseName = currentCase.getDisplayName();
1025 String caseNumber = currentCase.getNumber();
1026 String examiner = currentCase.getExaminer();
1029 imagecount = currentCase.getDataSources().size();
1030 }
catch (TskCoreException ex) {
1034 StringBuilder summary =
new StringBuilder();
1035 boolean running =
false;
1036 if (IngestManager.getInstance().isIngestRunning()) {
1040 final String reportTitle = reportBranding.getReportTitle();
1041 final String reportFooter = reportBranding.getReportFooter();
1042 final boolean agencyLogoSet = reportBranding.getAgencyLogoPath() != null && !reportBranding.getAgencyLogoPath().isEmpty();
1043 final boolean generatorLogoSet = reportBranding.getGeneratorLogoPath() != null && !reportBranding.getGeneratorLogoPath().isEmpty();
1045 summary.append(
"<div id=\"wrapper\">\n");
1046 summary.append(
"<h1>").append(reportTitle)
1047 .append(running ? NbBundle.getMessage(
this.getClass(),
"ReportHTML.writeSum.warningMsg") :
"")
1049 summary.append(
"<p class=\"subheadding\">").append(
1050 NbBundle.getMessage(
this.getClass(),
"ReportHTML.writeSum.reportGenOn.text", datetime)).append(
"</p>\n");
1051 summary.append(
"<div class=\"title\">\n");
1052 if (agencyLogoSet) {
1053 summary.append(
"<div class=\"left\">\n");
1054 summary.append(
"<img src=\"");
1055 summary.append(Paths.get(reportBranding.getAgencyLogoPath()).getFileName().toString());
1056 summary.append(
"\" />\n");
1057 summary.append(
"</div>\n");
1059 final String align = agencyLogoSet ?
"right" :
"left";
1060 summary.append(
"<div class=\"").append(align).append(
"\">\n");
1061 summary.append(
"<table>\n");
1062 summary.append(
"<tr><td>").append(NbBundle.getMessage(
this.getClass(),
"ReportHTML.writeSum.caseName"))
1063 .append(
"</td><td>").append(caseName).append(
"</td></tr>\n");
1064 summary.append(
"<tr><td>").append(NbBundle.getMessage(
this.getClass(),
"ReportHTML.writeSum.caseNum"))
1065 .append(
"</td><td>").append(!caseNumber.isEmpty() ? caseNumber : NbBundle
1066 .getMessage(this.getClass(),
"ReportHTML.writeSum.noCaseNum")).append(
"</td></tr>\n");
1067 summary.append(
"<tr><td>").append(NbBundle.getMessage(
this.getClass(),
"ReportHTML.writeSum.examiner")).append(
"</td><td>")
1068 .append(!examiner.isEmpty() ? examiner : NbBundle
1069 .getMessage(this.getClass(),
"ReportHTML.writeSum.noExaminer"))
1070 .append(
"</td></tr>\n");
1071 summary.append(
"<tr><td>").append(NbBundle.getMessage(
this.getClass(),
"ReportHTML.writeSum.numImages"))
1072 .append(
"</td><td>").append(imagecount).append(
"</td></tr>\n");
1073 summary.append(
"</table>\n");
1074 summary.append(
"</div>\n");
1075 summary.append(
"<div class=\"clear\"></div>\n");
1076 summary.append(
"</div>\n");
1077 summary.append(NbBundle.getMessage(
this.getClass(),
"ReportHTML.writeSum.imageInfoHeading"));
1078 summary.append(
"<div class=\"info\">\n");
1080 for (Content c : currentCase.getDataSources()) {
1081 summary.append(
"<p>").append(c.getName()).append(
"</p>\n");
1082 if (c instanceof Image) {
1083 Image img = (Image) c;
1085 summary.append(
"<table>\n");
1086 summary.append(
"<tr><td>").append(
1087 NbBundle.getMessage(
this.getClass(),
"ReportHTML.writeSum.timezone"))
1088 .append(
"</td><td>").append(img.getTimeZone()).append(
"</td></tr>\n");
1089 for (String imgPath : img.getPaths()) {
1090 summary.append(
"<tr><td>").append(
1091 NbBundle.getMessage(
this.getClass(),
"ReportHTML.writeSum.path"))
1092 .append(
"</td><td>").append(imgPath).append(
"</td></tr>\n");
1094 summary.append(
"</table>\n");
1097 }
catch (TskCoreException ex) {
1098 logger.log(Level.WARNING,
"Unable to get image information for the HTML report.");
1100 summary.append(
"</div>\n");
1101 if (generatorLogoSet) {
1102 summary.append(
"<div class=\"left\">\n");
1103 summary.append(
"<img src=\"generator_logo.png\" />\n");
1104 summary.append(
"</div>\n");
1106 summary.append(
"<div class=\"clear\"></div>\n");
1107 if (reportFooter != null) {
1108 summary.append(
"<p class=\"subheadding\">").append(reportFooter).append(
"</p>\n");
1110 summary.append(
"</div>\n");
1111 summary.append(
"</body></html>");
1112 out.write(summary.toString());
1113 }
catch (FileNotFoundException ex) {
1114 logger.log(Level.SEVERE,
"Could not find summary.html file to write to.");
1115 }
catch (UnsupportedEncodingException ex) {
1116 logger.log(Level.SEVERE,
"Did not recognize encoding when writing summary.hmtl.");
1117 }
catch (IOException ex) {
1118 logger.log(Level.SEVERE,
"Error creating Writer for summary.html.");
1125 }
catch (IOException ex) {
1130 private String prepareThumbnail(AbstractFile file) {
1131 File thumbFile = ImageUtils.getCachedThumbnailFile(file, ImageUtils.ICON_SIZE_MEDIUM);
1132 if (thumbFile.exists() ==
false) {
1135 File to =
new File(thumbsPath);
1136 FileObject from = FileUtil.toFileObject(thumbFile);
1137 FileObject dest = FileUtil.toFileObject(to);
1139 FileUtil.copyFile(from, dest, thumbFile.getName(),
"");
1140 }
catch (IOException ex) {
1141 logger.log(Level.SEVERE,
"Failed to write thumb file to report directory.", ex);
1142 }
catch (NullPointerException ex) {
1143 logger.log(Level.SEVERE,
"NPE generated from FileUtil.copyFile, probably because FileUtil.toFileObject returned null. \n" +
1144 "The File argument for toFileObject was " + thumbFile +
" with toString: " + thumbFile.toString() +
"\n" +
1145 "The FileObject returned by toFileObject, passed into FileUtil.copyFile, was " + from, ex);
1148 return THUMBS_REL_PATH + thumbFile.getName();
static String escapeFileName(String fileName)