Autopsy  4.6.0
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-2017 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 org.apache.commons.io.FileUtils;
28 import org.apache.commons.io.FilenameUtils;
29 import org.openide.util.Exceptions;
32 
36 public final class IngestProfiles {
37 
38  private static final String PROFILE_FOLDER = "IngestProfiles";
39  private static final String PROFILE_NAME_KEY = "Profile_Name";
40  private static final String PROFILE_DESC_KEY = "Profile_Description";
41  private static final String PROFILE_FILTER_KEY = "Profile_Filter";
42  private static final String PROFILE_FILE_EXT = ".properties";
43 
49  public synchronized static List<IngestProfile> getIngestProfiles() {
50  File dir = Paths.get(PlatformUtil.getUserConfigDirectory(), PROFILE_FOLDER).toFile();
51  File[] directoryListing = dir.listFiles();
52  List<IngestProfile> profileList = new ArrayList<>();
53  if (directoryListing != null) {
54  for (File child : directoryListing) {
55  String name = FilenameUtils.removeExtension(child.getName());
56  String context = PROFILE_FOLDER + File.separator + name;
57  String desc = ModuleSettings.getConfigSetting(context, PROFILE_DESC_KEY);
58  String fileIngestFilter = ModuleSettings.getConfigSetting(context, PROFILE_FILTER_KEY);
59  profileList.add(new IngestProfile(name, desc, fileIngestFilter));
60  }
61  }
62  return profileList;
63  }
64 
68  synchronized static void setProfiles(List<IngestProfile> profiles) {
69  for (IngestProfile profile : profiles) {
70  IngestProfile.saveProfile(profile);
71  }
72  }
73 
79  public static final class IngestProfile {
80 
81  private final String name;
82  private final String description;
83  private final String fileIngestFilter;
84 
92  IngestProfile(String name, String desc, String selectedFilter) {
93  this.name = name;
94  this.description = desc;
95  this.fileIngestFilter = selectedFilter;
96  }
97 
103  @Override
104  public String toString() {
105  return getName();
106  }
107 
113  String getName() {
114  return name;
115  }
116 
122  public String getDescription() {
123  return description;
124  }
125 
131  public String getFileIngestFilter() {
132  return fileIngestFilter;
133  }
134 
140  synchronized static void deleteProfile(IngestProfile selectedProfile) {
141  try {
142  Files.deleteIfExists(Paths.get(PlatformUtil.getUserConfigDirectory(), PROFILE_FOLDER, selectedProfile.getName() + PROFILE_FILE_EXT));
143  Files.deleteIfExists(Paths.get(PlatformUtil.getUserConfigDirectory(), selectedProfile.getName() + PROFILE_FILE_EXT));
144  FileUtils.deleteDirectory(IngestJobSettings.getSavedModuleSettingsFolder(selectedProfile.getName() + File.separator).toFile());
145  } catch (IOException ex) {
146  Exceptions.printStackTrace(ex);
147  }
148  }
149 
156  synchronized static void renameProfile(String oldName, String newName) {
157  if (!oldName.equals(newName)) { //if renameProfile was called with the new name being the same as the old name, it is complete already
158  File oldFile = Paths.get(PlatformUtil.getUserConfigDirectory(), PROFILE_FOLDER, oldName + PROFILE_FILE_EXT).toFile();
159  File newFile = Paths.get(PlatformUtil.getUserConfigDirectory(), PROFILE_FOLDER, newName + PROFILE_FILE_EXT).toFile();
160  oldFile.renameTo(newFile);
161  oldFile = Paths.get(PlatformUtil.getUserConfigDirectory(), oldName + PROFILE_FILE_EXT).toFile();
162  newFile = Paths.get(PlatformUtil.getUserConfigDirectory(), newName + PROFILE_FILE_EXT).toFile();
163  oldFile.renameTo(newFile);
164  oldFile = IngestJobSettings.getSavedModuleSettingsFolder(oldName + File.separator).toFile();
165  newFile = IngestJobSettings.getSavedModuleSettingsFolder(newName + File.separator).toFile();
166  oldFile.renameTo(newFile);
167  }
168  }
169 
175  synchronized static void saveProfile(IngestProfile profile) {
176  String context = PROFILE_FOLDER + File.separator + profile.getName();
177  ModuleSettings.setConfigSetting(context, PROFILE_NAME_KEY, profile.getName());
178  ModuleSettings.setConfigSetting(context, PROFILE_DESC_KEY, profile.getDescription());
179  ModuleSettings.setConfigSetting(context, PROFILE_FILTER_KEY, profile.getFileIngestFilter());
180  }
181  }
182 }
static synchronized List< IngestProfile > getIngestProfiles()
static String getConfigSetting(String moduleName, String settingName)

Copyright © 2012-2016 Basis Technology. Generated on: Mon May 7 2018
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.