Autopsy  4.19.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
IngestProfiles.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2011-2019 Basis Technology Corp.
5  * Contact: carrier <at> sleuthkit <dot> org
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 package org.sleuthkit.autopsy.ingest;
20 
21 import java.io.File;
22 import java.io.IOException;
23 import java.nio.file.Files;
24 import java.nio.file.Paths;
25 import java.util.ArrayList;
26 import java.util.List;
27 import java.util.logging.Level;
28 import org.apache.commons.io.FileUtils;
29 import org.apache.commons.io.FilenameUtils;
33 
37 public final class IngestProfiles {
38 
39  private static final String PROFILE_FOLDER = "IngestProfiles";
40  private static final String PROFILE_NAME_KEY = "Profile_Name";
41  private static final String PROFILE_DESC_KEY = "Profile_Description";
42  private static final String PROFILE_FILTER_KEY = "Profile_Filter";
43  private static final String PROFILE_FILE_EXT = ".properties";
44  private static final Logger logger = Logger.getLogger(IngestProfiles.class.getName());
50  public synchronized static List<IngestProfile> getIngestProfiles() {
51  File dir = Paths.get(PlatformUtil.getUserConfigDirectory(), PROFILE_FOLDER).toFile();
52  File[] directoryListing = dir.listFiles();
53  List<IngestProfile> profileList = new ArrayList<>();
54  if (directoryListing != null) {
55  for (File child : directoryListing) {
56  String name = FilenameUtils.removeExtension(child.getName());
57  String context = PROFILE_FOLDER + File.separator + name;
58  String desc = ModuleSettings.getConfigSetting(context, PROFILE_DESC_KEY);
59  String fileIngestFilter = ModuleSettings.getConfigSetting(context, PROFILE_FILTER_KEY);
60  profileList.add(new IngestProfile(name, desc, fileIngestFilter));
61  }
62  }
63  return profileList;
64  }
65 
69  synchronized static void setProfiles(List<IngestProfile> profiles) {
70  for (IngestProfile profile : profiles) {
71  IngestProfile.saveProfile(profile);
72  }
73  }
74 
80  public static final class IngestProfile {
81 
82  private final String name;
83  private final String description;
84  private final String fileIngestFilter;
85 
93  IngestProfile(String name, String desc, String selectedFilter) {
94  this.name = name;
95  this.description = desc;
96  this.fileIngestFilter = selectedFilter;
97  }
98 
104  @Override
105  public String toString() {
106  return getName();
107  }
108 
114  String getName() {
115  return name;
116  }
117 
123  public String getDescription() {
124  return description;
125  }
126 
132  public String getFileIngestFilter() {
133  return fileIngestFilter;
134  }
135 
141  synchronized static void deleteProfile(IngestProfile selectedProfile) {
142  try {
143  Files.deleteIfExists(Paths.get(PlatformUtil.getUserConfigDirectory(), PROFILE_FOLDER, selectedProfile.getName() + PROFILE_FILE_EXT));
144  Files.deleteIfExists(Paths.get(PlatformUtil.getUserConfigDirectory(), selectedProfile.getName() + PROFILE_FILE_EXT));
145  FileUtils.deleteDirectory(IngestJobSettings.getSavedModuleSettingsFolder(selectedProfile.getName() + File.separator).toFile());
146  } catch (IOException ex) {
147  logger.log(Level.WARNING, "Error deleting directory for profile " + selectedProfile.getName(), ex);
148  }
149  }
150 
157  synchronized static void renameProfile(String oldName, String newName) {
158  if (!oldName.equals(newName)) { //if renameProfile was called with the new name being the same as the old name, it is complete already
159  File oldFile = Paths.get(PlatformUtil.getUserConfigDirectory(), PROFILE_FOLDER, oldName + PROFILE_FILE_EXT).toFile();
160  File newFile = Paths.get(PlatformUtil.getUserConfigDirectory(), PROFILE_FOLDER, newName + PROFILE_FILE_EXT).toFile();
161  oldFile.renameTo(newFile);
162  oldFile = Paths.get(PlatformUtil.getUserConfigDirectory(), oldName + PROFILE_FILE_EXT).toFile();
163  newFile = Paths.get(PlatformUtil.getUserConfigDirectory(), newName + PROFILE_FILE_EXT).toFile();
164  oldFile.renameTo(newFile);
165  oldFile = IngestJobSettings.getSavedModuleSettingsFolder(oldName + File.separator).toFile();
166  newFile = IngestJobSettings.getSavedModuleSettingsFolder(newName + File.separator).toFile();
167  oldFile.renameTo(newFile);
168  }
169  }
170 
176  synchronized static void saveProfile(IngestProfile profile) {
177  String context = PROFILE_FOLDER + File.separator + profile.getName();
178  ModuleSettings.setConfigSetting(context, PROFILE_NAME_KEY, profile.getName());
179  ModuleSettings.setConfigSetting(context, PROFILE_DESC_KEY, profile.getDescription());
180  ModuleSettings.setConfigSetting(context, PROFILE_FILTER_KEY, profile.getFileIngestFilter());
181  }
182  }
183 }
static synchronized String getConfigSetting(String moduleName, String settingName)
static synchronized List< IngestProfile > getIngestProfiles()
synchronized static Logger getLogger(String name)
Definition: Logger.java:124

Copyright © 2012-2021 Basis Technology. Generated on: Thu Sep 30 2021
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.