19 package org.sleuthkit.autopsy.report.modules.datasourcesummaryexport;
21 import java.text.DateFormat;
22 import java.text.SimpleDateFormat;
23 import java.util.Arrays;
24 import java.util.Date;
25 import java.util.List;
26 import java.util.Locale;
27 import java.util.function.Function;
28 import java.util.stream.Collectors;
29 import java.util.stream.Stream;
30 import org.apache.commons.lang.StringUtils;
31 import org.openide.util.NbBundle.Messages;
47 "ExportUserActivity_tab_title=User Activity",
48 "ExportUserActivity_TopProgramsTableModel_tabName=Recent Programs",
49 "ExportUserActivity_TopDomainsTableModel_tabName=Recent Domains",
50 "ExportUserActivity_TopWebSearchTableModel_tabName=Recent Web Searches",
51 "ExportUserActivity_TopDeviceAttachedTableModel_tabName=Recent Devices Attached",
52 "ExportUserActivity_TopAccountTableModel_tabName=Recent Account Types Used",
53 "ExportUserActivity_TopProgramsTableModel_name_header=Program",
54 "ExportUserActivity_TopProgramsTableModel_folder_header=Folder",
55 "ExportUserActivity_TopProgramsTableModel_count_header=Run Times",
56 "ExportUserActivity_TopProgramsTableModel_lastrun_header=Last Run",
57 "ExportUserActivity_TopDomainsTableModel_domain_header=Domain",
58 "ExportUserActivity_TopDomainsTableModel_count_header=Visits",
59 "ExportUserActivity_TopDomainsTableModel_lastAccess_header=Last Accessed",
60 "ExportUserActivity_TopWebSearchTableModel_searchString_header=Search String",
61 "ExportUserActivity_TopWebSearchTableModel_dateAccessed_header=Date Accessed",
62 "ExportUserActivity_TopWebSearchTableModel_translatedResult_header=Translated",
63 "ExportUserActivity_TopDeviceAttachedTableModel_deviceId_header=Device Id",
64 "ExportUserActivity_TopDeviceAttachedTableModel_makeModel_header=Make and Model",
65 "ExportUserActivity_TopDeviceAttachedTableModel_dateAccessed_header=Last Accessed",
66 "ExportUserActivity_TopAccountTableModel_accountType_header=Account Type",
67 "ExportUserActivity_TopAccountTableModel_lastAccess_header=Last Accessed",
68 "ExportUserActivity_noDataExists=No communication data exists"})
69 class ExportUserActivity {
71 private final UserActivitySummary userSummary;
73 private static final String DATETIME_FORMAT_STR =
"yyyy/MM/dd HH:mm:ss";
74 private static final DateFormat DATETIME_FORMAT =
new SimpleDateFormat(DATETIME_FORMAT_STR, Locale.getDefault());
75 private static final int TOP_PROGS_COUNT = 10;
76 private static final int TOP_DOMAINS_COUNT = 10;
77 private static final int TOP_SEARCHES_COUNT = 10;
78 private static final int TOP_ACCOUNTS_COUNT = 5;
79 private static final int TOP_DEVICES_COUNT = 10;
82 private static final List<ColumnModel<TopProgramsResult, DefaultCellModel<?>>> topProgramsTemplate = Arrays.asList(
85 Bundle.ExportUserActivity_TopProgramsTableModel_name_header(),
87 return new DefaultCellModel<>(prog.getProgramName());
92 Bundle.ExportUserActivity_TopProgramsTableModel_folder_header(),
94 return new DefaultCellModel<>(
95 UserActivitySummary.getShortFolderName(
96 prog.getProgramPath(),
97 prog.getProgramName()));
102 Bundle.ExportUserActivity_TopProgramsTableModel_count_header(),
104 return new DefaultCellModel<>(prog.getRunTimes(), (num) -> num == null ?
"" : num.toString());
109 Bundle.ExportUserActivity_TopProgramsTableModel_lastrun_header(),
115 private static final List<ColumnModel<TopDomainsResult, DefaultCellModel<?>>> topDomainsTemplate = Arrays.asList(
118 Bundle.ExportUserActivity_TopDomainsTableModel_domain_header(),
120 return new DefaultCellModel<>(recentDomain.getDomain());
125 Bundle.ExportUserActivity_TopDomainsTableModel_count_header(),
127 return new DefaultCellModel<>(recentDomain.getVisitTimes(), (num) -> num == null ?
"" : num.toString());
132 Bundle.ExportUserActivity_TopDomainsTableModel_lastAccess_header(),
138 private static final List<ColumnModel<TopWebSearchResult, DefaultCellModel<?>>> topWebSearchesTemplate = Arrays.asList(
141 Bundle.ExportUserActivity_TopWebSearchTableModel_searchString_header(),
143 return new DefaultCellModel<>(webSearch.getSearchString());
149 Bundle.ExportUserActivity_TopWebSearchTableModel_dateAccessed_header(),
155 Bundle.ExportUserActivity_TopWebSearchTableModel_translatedResult_header(),
157 return new DefaultCellModel<>(webSearch.getTranslatedResult());
164 private static final List<ColumnModel<TopDeviceAttachedResult, DefaultCellModel<?>>> topDevicesTemplate = Arrays.asList(
167 Bundle.ExportUserActivity_TopDeviceAttachedTableModel_deviceId_header(),
169 return new DefaultCellModel<>(device.getDeviceId());
175 Bundle.ExportUserActivity_TopDeviceAttachedTableModel_dateAccessed_header(),
181 Bundle.ExportUserActivity_TopDeviceAttachedTableModel_makeModel_header(),
183 String make = StringUtils.isBlank(device.getDeviceMake()) ?
"" : device.getDeviceMake().trim();
184 String model = StringUtils.isBlank(device.getDeviceModel()) ?
"" : device.getDeviceModel().trim();
185 String makeModelString = (make.isEmpty() || model.isEmpty())
187 : String.format(
"%s - %s", make, model);
188 return new DefaultCellModel<>(makeModelString);
195 private static final List<ColumnModel<TopAccountResult, DefaultCellModel<?>>> topAccountsTemplate = Arrays.asList(
198 Bundle.ExportUserActivity_TopAccountTableModel_accountType_header(),
200 return new DefaultCellModel<>(account.getAccountType());
206 Bundle.ExportUserActivity_TopAccountTableModel_lastAccess_header(),
212 ExportUserActivity() {
213 userSummary =
new UserActivitySummary();
216 private static <T extends LastAccessedArtifact> Function<T, DefaultCellModel<?>> getDateFunct() {
217 return (T lastAccessed) -> {
218 Function<Date, String> dateParser = (dt) -> dt == null ?
"" : DATETIME_FORMAT.format(dt);
219 return new DefaultCellModel<>(lastAccessed.getLastAccessed(), dateParser, DATETIME_FORMAT_STR);
223 List<ExcelExport.ExcelSheetExport> getExports(DataSource dataSource) {
225 DataFetcher<DataSource, List<TopProgramsResult>> topProgramsFetcher = (ds) -> userSummary.getTopPrograms(ds, TOP_PROGS_COUNT);
226 DataFetcher<DataSource, List<TopDomainsResult>> topDomainsFetcher = (ds) -> userSummary.getRecentDomains(ds, TOP_DOMAINS_COUNT);
227 DataFetcher<DataSource, List<TopWebSearchResult>> topWebSearchesFetcher = (ds) -> userSummary.getMostRecentWebSearches(ds, TOP_SEARCHES_COUNT);
228 DataFetcher<DataSource, List<TopDeviceAttachedResult>> topDevicesAttachedFetcher = (ds) -> userSummary.getRecentDevices(ds, TOP_DEVICES_COUNT);
229 DataFetcher<DataSource, List<TopAccountResult>> topAccountsFetcher = (ds) -> userSummary.getRecentAccounts(ds, TOP_ACCOUNTS_COUNT);
232 getTableExport(topProgramsFetcher, topProgramsTemplate, Bundle.ExportUserActivity_TopProgramsTableModel_tabName(), dataSource),
233 getTableExport(topDomainsFetcher, topDomainsTemplate, Bundle.ExportUserActivity_TopDomainsTableModel_tabName(), dataSource),
234 getTableExport(topWebSearchesFetcher, topWebSearchesTemplate, Bundle.ExportUserActivity_TopWebSearchTableModel_tabName(), dataSource),
235 getTableExport(topDevicesAttachedFetcher, topDevicesTemplate, Bundle.ExportUserActivity_TopDeviceAttachedTableModel_tabName(), dataSource),
236 getTableExport(topAccountsFetcher, topAccountsTemplate, Bundle.ExportUserActivity_TopAccountTableModel_tabName(), dataSource))
237 .filter(sheet -> sheet != null)
238 .collect(Collectors.toList());