This commit is contained in:
Greg DiCristofaro 2022-05-25 09:06:15 -04:00
parent 536f4ab450
commit 6d234efe46
8 changed files with 64 additions and 16 deletions

View File

@ -28,6 +28,7 @@ import org.openide.WizardDescriptor;
import org.openide.util.HelpCtx;
import org.openide.util.NbBundle.Messages;
import org.openide.windows.WindowManager;
import org.sleuthkit.autopsy.core.configpath.SharedConfigPath;
import org.sleuthkit.autopsy.coreutils.ModuleSettings;
import org.sleuthkit.autopsy.ingest.IngestJobSettings;
import org.sleuthkit.autopsy.ingest.IngestJobSettingsPanel;
@ -191,7 +192,7 @@ class AddImageWizardIngestConfigPanel extends ShortcutWizardDescriptorPanel {
//Because this panel kicks off ingest during the wizard we need to
//swap out the ingestJobSettings for the ones of the chosen profile before
//use prefix to specify correct execution context for profiles.
IngestJobSettings ingestJobSettings = new IngestJobSettings(IngestProfiles.getIngestProfilePrefix() + lastProfileUsed);
IngestJobSettings ingestJobSettings = new IngestJobSettings(SharedConfigPath.getInstance().getIngestProfilePrefix() + lastProfileUsed);
progressPanel.setIngestJobSettings(ingestJobSettings); //prepare ingest for being started
}
}

View File

@ -52,6 +52,9 @@ public class CentralRepoSettings {
CENTRAL_REPO_BASE_PATH,
CENTRAL_REPOSITORY_SETTINGS_NAME + ".properties").toString();
private static final String DATABASE_NAME_KEY = "db.sqlite.dbName"; //NON-NLS
private static final String DATABASE_PATH_KEY = "db.sqlite.dbDirectory"; //NON-NLS
/**
* @return The base path for central repository settings.
*/
@ -87,4 +90,20 @@ public class CentralRepoSettings {
public String getDefaultDbName() {
return DEFAULT_DB_NAME;
}
/**
* @return The properties key for the sqlite database name in the settings.
*/
public String getDatabaseNameKey() {
return DATABASE_NAME_KEY;
}
/**
* @return The properties key for the sqlite database path in the settings.
*/
public String getDatabasePathKey() {
return DATABASE_PATH_KEY;
}
}

View File

@ -49,8 +49,8 @@ public final class SqliteCentralRepoSettings implements CentralRepoDbConnectivit
//property names
private static final String PROFILE_NAME = CentralRepoSettings.getInstance().getModuleSettingsKey();
private static final String DATABASE_NAME = "db.sqlite.dbName"; //NON-NLS
private static final String DATABASE_PATH = "db.sqlite.dbDirectory"; //NON-NLS
private static final String DATABASE_NAME = CentralRepoSettings.getInstance().getDatabaseNameKey(); //NON-NLS
private static final String DATABASE_PATH = CentralRepoSettings.getInstance().getDatabasePathKey(); //NON-NLS
private static final String BULK_THRESHOLD = "db.sqlite.bulkThreshold"; //NON-NLS
private final static String JDBC_DRIVER = "org.sqlite.JDBC"; // NON-NLS

View File

@ -36,6 +36,7 @@ import org.sleuthkit.autopsy.centralrepository.datamodel.SqliteCentralRepoSettin
import org.sleuthkit.autopsy.centralrepository.CentralRepoSettings;
import org.sleuthkit.autopsy.core.RuntimeProperties;
import org.sleuthkit.autopsy.core.UserPreferences;
import org.sleuthkit.autopsy.core.configpath.SharedConfigPath;
import org.sleuthkit.autopsy.coreutils.Logger;
import org.sleuthkit.autopsy.coreutils.ModuleSettings;
import org.sleuthkit.autopsy.coreutils.PlatformUtil;
@ -98,12 +99,12 @@ public class Installer extends ModuleInstall {
* Copies settings to new path location.
*/
private void upgradeSettingsPath() {
File newSettingsFile = new File(ModuleSettings.getSettingsFilePath(CentralRepoSettings.getInstance().getModuleSettingsKey()));
File legacySettingsFile = new File(ModuleSettings.getSettingsFilePath(LEGACY_MODULE_SETTINGS_KEY));
File newSettingsFile = new File(SharedConfigPath.getInstance().getSettingsFilePath(CentralRepoSettings.getInstance().getModuleSettingsKey()));
File legacySettingsFile = new File(SharedConfigPath.getInstance().getSettingsFilePath(LEGACY_MODULE_SETTINGS_KEY));
// new config has not been created, but legacy has, copy it.
if (!newSettingsFile.exists() && legacySettingsFile.exists()) {
Map<String, String> prevSettings = ModuleSettings.getConfigSettings(LEGACY_MODULE_SETTINGS_KEY);
String prevPath = prevSettings.get(SqliteCentralRepoSettings.getDatabasePathKey());
String prevPath = prevSettings.get(CentralRepoSettings.getInstance().getDatabasePathKey());
File prevDirCheck = new File(prevPath);
// if a relative directory, make sure it is relative to user config.
if (!prevDirCheck.isAbsolute()) {
@ -113,7 +114,7 @@ public class Installer extends ModuleInstall {
// if old path is default path for sqlite db, copy it over to new location and update setting.
if (prevPath != null
&& Paths.get(LEGACY_DEFAULT_DB_PARENT_PATH).toAbsolutePath().toString().equals(Paths.get(prevPath).toAbsolutePath().toString())) {
String prevDbName = prevSettings.get(SqliteCentralRepoSettings.getDatabaseNameKey());
String prevDbName = prevSettings.get(CentralRepoSettings.getInstance().getDatabaseNameKey());
File prevDir = new File(prevPath);
// copy all files starting with prevDbName in prevPath to new path location.
if (prevDir.exists() && prevDir.isDirectory()) {
@ -128,7 +129,7 @@ public class Installer extends ModuleInstall {
}
// update path settings accordingly
prevSettings.put(SqliteCentralRepoSettings.getDatabasePathKey(), CentralRepoSettings.getInstance().getDefaultDbPath());
prevSettings.put(CentralRepoSettings.getInstance().getDatabasePathKey(), CentralRepoSettings.getInstance().getDefaultDbPath());
}
// copy settings

View File

@ -30,6 +30,7 @@ public class SharedConfigPath {
private static final String SHARED_FOLDER = "SharableConfig";
private static final String SHARED_PATH = Paths.get(PlatformUtil.getUserConfigDirectory(), SHARED_FOLDER).toAbsolutePath().toString();
private static final String INGEST_PROFILE_PREFIX = "IngestProfiles.";
private SharedConfigPath() {
}
@ -55,4 +56,25 @@ public class SharedConfigPath {
public String getSharedConfigFolder() {
return SHARED_FOLDER;
}
/**
* Path to module settings path.
*
* @param moduleName The full name of the module provided to ModuleSettings.
*
* @return The path on disk for that object. NOTE: This must be in sync with
* ModuleSettings.
*/
public String getSettingsFilePath(String moduleName) {
return Paths.get(PlatformUtil.getUserConfigDirectory(), moduleName + ".properties").toString();
}
/**
* @return The prefix in front of all ingest profiles to differentiate
* between this and other ingest settings (i.e. command line, add
* image ingest wizard, etc.).
*/
public String getIngestProfilePrefix() {
return INGEST_PROFILE_PREFIX;
}
}

View File

@ -27,6 +27,7 @@ import java.util.List;
import java.util.logging.Level;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.FilenameUtils;
import org.sleuthkit.autopsy.core.configpath.SharedConfigPath;
import org.sleuthkit.autopsy.coreutils.Logger;
import org.sleuthkit.autopsy.coreutils.ModuleSettings;
@ -38,7 +39,7 @@ public final class IngestProfiles {
private static final String PROFILE_NAME_KEY = "Profile_Name";
private static final String PROFILE_DESC_KEY = "Profile_Description";
private static final String PROFILE_FILTER_KEY = "Profile_Filter";
private static final String SETTINGS_FILE_PREFIX = "IngestProfiles.";
private static final String SETTINGS_FILE_PREFIX = SharedConfigPath.getInstance().getIngestProfilePrefix();
private static final Logger logger = Logger.getLogger(IngestProfiles.class.getName());
/**
@ -82,7 +83,10 @@ public final class IngestProfiles {
* @return The file location for the root settings of that profile.
*/
private static File getRootSettingsFile(String profileName) {
return new File(ModuleSettings.getSettingsFilePath(IngestJobSettings.getModuleSettingsResource(getExecutionContext(getSanitizedProfile(profileName)))));
return new File(
SharedConfigPath.getInstance().getSettingsFilePath(
IngestJobSettings.getModuleSettingsResource(
getExecutionContext(getSanitizedProfile(profileName)))));
}
/**

View File

@ -21,6 +21,7 @@ package org.sleuthkit.autopsy.texttranslation.translators;
import java.io.File;
import java.util.Map;
import org.openide.modules.ModuleInstall;
import org.sleuthkit.autopsy.core.configpath.SharedConfigPath;
import org.sleuthkit.autopsy.coreutils.Logger;
import org.sleuthkit.autopsy.coreutils.ModuleSettings;
@ -65,8 +66,8 @@ public class Installer extends ModuleInstall {
private void copyIfExists(String oldModuleSettingsPath, String newModuleSettingsPath) {
// only copy if old path exists and new path does not
if (new File(ModuleSettings.getSettingsFilePath(oldModuleSettingsPath)).exists() &&
!(new File(ModuleSettings.getSettingsFilePath(newModuleSettingsPath)).exists())) {
if (new File(SharedConfigPath.getInstance().getSettingsFilePath(oldModuleSettingsPath)).exists() &&
!(new File(SharedConfigPath.getInstance().getSettingsFilePath(newModuleSettingsPath)).exists())) {
Map<String, String> settings = ModuleSettings.getConfigSettings(oldModuleSettingsPath);
if (!settings.isEmpty()) {

View File

@ -87,10 +87,10 @@ public class SharedConfiguration {
private static final String UPLOAD_IN_PROGRESS_FILE = "uploadInProgress"; // NON-NLS
private static final String moduleDirPath = PlatformUtil.getUserConfigDirectory();
private static final String INGEST_MODULES_PATH = IngestJobSettings.getBaseSettingsPath();
private static final String SHARED_DIR_PATH = Paths.get(moduleDirPath, "SharableConfig").toAbsolutePath().toString();
private static final String INGEST_MODULES_PATH = Paths.get(SHARED_DIR_PATH, "IngestSettings").toString();
private static final String INGEST_MODULES_REL_PATH = new File(moduleDirPath).toURI().relativize(new File(INGEST_MODULES_PATH).toURI()).getPath();
private static final Logger logger = Logger.getLogger(SharedConfiguration.class.getName());
private static final String SHARED_DIR_PATH = Paths.get(moduleDirPath, "SharableConfig").toAbsolutePath().toString();
private static final String CENTRAL_REPO_DIR_PATH = Paths.get(SHARED_DIR_PATH, "CentralRepository").toAbsolutePath().toString();
private static final String VIEW_PREFERENCE_FILE = Paths.get(SHARED_DIR_PATH, "ViewPreferences").toAbsolutePath().toString();
private static final String MACHINE_SPECIFIC_PREFERENCE_FILE = Paths.get(moduleDirPath, "MachineSpecificPreferences").toAbsolutePath().toString();