19 package org.sleuthkit.autopsy.commandlineingest;
21 import java.awt.BorderLayout;
22 import java.awt.Cursor;
24 import java.nio.file.Files;
25 import java.util.List;
26 import javax.swing.JFileChooser;
27 import javax.swing.JOptionPane;
28 import javax.swing.event.DocumentEvent;
29 import javax.swing.event.DocumentListener;
30 import org.openide.util.NbBundle;
33 import java.nio.file.Paths;
35 import org.openide.windows.WindowManager;
41 @SuppressWarnings(
"PMD.SingularField")
45 private final JFileChooser fc =
new JFileChooser();
46 private static final long serialVersionUID = 1L;
55 controller = theController;
60 jLabelInvalidResultsFolder.setText(
"");
89 final void load(
boolean inStartup) {
92 if (results != null) {
93 outputPathTextField.setText(results);
95 outputPathTextField.setText(
"");
105 String resultsFolderPath = getNormalizedFolderPath(outputPathTextField.getText().trim());
114 if (validateResultsPath()) {
127 String normalizePath(String path) {
129 while (path.length() > 0) {
130 if (path.charAt(path.length() - 1) ==
' ') {
131 path = path.substring(0, path.length() - 1);
147 boolean isFolderPathValid(String path) {
149 File file =
new File(normalizePath(path));
152 if (Files.isSymbolicLink(file.toPath())) {
157 if (file.exists() && file.isDirectory()) {
160 }
catch (Exception ex) {
178 String getNormalizedFolderPath(String path) {
182 File file =
new File(normalizePath(path));
183 return file.getPath();
189 boolean validateResultsPath() {
191 String outputPath = outputPathTextField.getText().trim();
193 if (outputPath.isEmpty()) {
194 jLabelInvalidResultsFolder.setVisible(
true);
195 jLabelInvalidResultsFolder.setText(NbBundle.getMessage(CommandLineIngestSettingsPanel.class,
"CommandLineIngestSettingsPanel.ResultsDirectoryUnspecified"));
204 if (!isFolderPathValid(outputPath)) {
205 jLabelInvalidResultsFolder.setVisible(
true);
206 jLabelInvalidResultsFolder.setText(NbBundle.getMessage(CommandLineIngestSettingsPanel.class,
"CommandLineIngestSettingsPanel.PathInvalid"));
210 if (
false == permissionsAppropriate(outputPath)) {
211 jLabelInvalidResultsFolder.setVisible(
true);
212 jLabelInvalidResultsFolder.setText(NbBundle.getMessage(CommandLineIngestSettingsPanel.class,
"CommandLineIngestSettingsPanel.CannotAccess")
213 +
" " + outputPath +
" "
214 + NbBundle.getMessage(CommandLineIngestSettingsPanel.class,
"CommandLineIngestSettingsPanel.CheckPermissions"));
218 jLabelInvalidResultsFolder.setVisible(
false);
223 this.getParent().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
226 showWarnings(ingestJobSettings);
229 add(ingestJobSettingsPanel, BorderLayout.PAGE_START);
231 if (JOptionPane.showConfirmDialog(
this, ingestJobSettingsPanel,
"Ingest Module Configuration", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE) == JOptionPane.OK_OPTION) {
233 ingestJobSettings = ingestJobSettingsPanel.
getSettings();
234 ingestJobSettings.
save();
235 showWarnings(ingestJobSettings);
238 this.getParent().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
242 List<String> warnings = ingestJobSettings.
getWarnings();
243 if (warnings.isEmpty() ==
false) {
244 StringBuilder warningMessage =
new StringBuilder();
245 for (String warning : warnings) {
246 warningMessage.append(warning).append(
"\n");
248 JOptionPane.showMessageDialog(WindowManager.getDefault().getMainWindow(), warningMessage.toString());
257 @SuppressWarnings(
"unchecked")
259 private
void initComponents() {
261 nodeScrollPane =
new javax.swing.JScrollPane();
262 nodePanel =
new javax.swing.JPanel();
263 bnEditIngestSettings =
new javax.swing.JButton();
264 browseOutputFolderButton =
new javax.swing.JButton();
265 outputPathTextField =
new javax.swing.JTextField();
266 jLabelInvalidResultsFolder =
new javax.swing.JLabel();
267 jLabelSelectOutputFolder =
new javax.swing.JLabel();
269 nodeScrollPane.setMinimumSize(
new java.awt.Dimension(0, 0));
271 nodePanel.setMinimumSize(
new java.awt.Dimension(100, 100));
273 org.openide.awt.Mnemonics.setLocalizedText(bnEditIngestSettings,
org.openide.util.NbBundle.getMessage(
CommandLineIngestSettingsPanel.class,
"CommandLineIngestSettingsPanel.bnEditIngestSettings.text"));
274 bnEditIngestSettings.setToolTipText(
org.openide.util.NbBundle.getMessage(
CommandLineIngestSettingsPanel.class,
"CommandLineIngestSettingsPanel.bnEditIngestSettings.toolTipText"));
275 bnEditIngestSettings.setActionCommand(
org.openide.util.NbBundle.getMessage(
CommandLineIngestSettingsPanel.class,
"CommandLineIngestSettingsPanel.bnEditIngestSettings.text"));
276 bnEditIngestSettings.addActionListener(
new java.awt.event.ActionListener() {
277 public void actionPerformed(java.awt.event.ActionEvent evt) {
278 bnEditIngestSettingsActionPerformed(evt);
282 org.openide.awt.Mnemonics.setLocalizedText(browseOutputFolderButton,
org.openide.util.NbBundle.getMessage(
CommandLineIngestSettingsPanel.class,
"CommandLineIngestSettingsPanel.browseOutputFolderButton.text"));
283 browseOutputFolderButton.addActionListener(
new java.awt.event.ActionListener() {
284 public void actionPerformed(java.awt.event.ActionEvent evt) {
285 browseOutputFolderButtonActionPerformed(evt);
289 outputPathTextField.setText(
org.openide.util.NbBundle.getMessage(
CommandLineIngestSettingsPanel.class,
"CommandLineIngestSettingsPanel.outputPathTextField.text"));
290 outputPathTextField.setToolTipText(
org.openide.util.NbBundle.getMessage(
CommandLineIngestSettingsPanel.class,
"CommandLineIngestSettingsPanel.outputPathTextField.toolTipText"));
292 jLabelInvalidResultsFolder.setForeground(
new java.awt.Color(255, 0, 0));
293 org.openide.awt.Mnemonics.setLocalizedText(jLabelInvalidResultsFolder,
org.openide.util.NbBundle.getMessage(
CommandLineIngestSettingsPanel.class,
"CommandLineIngestSettingsPanel.jLabelInvalidResultsFolder.text"));
295 org.openide.awt.Mnemonics.setLocalizedText(jLabelSelectOutputFolder,
org.openide.util.NbBundle.getMessage(
CommandLineIngestSettingsPanel.class,
"CommandLineIngestSettingsPanel.jLabelSelectOutputFolder.text"));
296 jLabelSelectOutputFolder.setVerticalAlignment(javax.swing.SwingConstants.BOTTOM);
298 javax.swing.GroupLayout nodePanelLayout =
new javax.swing.GroupLayout(nodePanel);
299 nodePanel.setLayout(nodePanelLayout);
300 nodePanelLayout.setHorizontalGroup(
301 nodePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
302 .addGroup(nodePanelLayout.createSequentialGroup()
304 .addGroup(nodePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
305 .addGroup(nodePanelLayout.createSequentialGroup()
306 .addComponent(outputPathTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 630, javax.swing.GroupLayout.PREFERRED_SIZE)
307 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
308 .addComponent(browseOutputFolderButton))
309 .addComponent(bnEditIngestSettings, javax.swing.GroupLayout.PREFERRED_SIZE, 155, javax.swing.GroupLayout.PREFERRED_SIZE)
310 .addGroup(nodePanelLayout.createSequentialGroup()
311 .addComponent(jLabelSelectOutputFolder)
313 .addComponent(jLabelInvalidResultsFolder, javax.swing.GroupLayout.PREFERRED_SIZE, 544, javax.swing.GroupLayout.PREFERRED_SIZE)))
314 .addContainerGap(355, Short.MAX_VALUE))
316 nodePanelLayout.setVerticalGroup(
317 nodePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
318 .addGroup(nodePanelLayout.createSequentialGroup()
320 .addGroup(nodePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
321 .addComponent(jLabelSelectOutputFolder, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE)
322 .addComponent(jLabelInvalidResultsFolder))
324 .addGroup(nodePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
325 .addComponent(browseOutputFolderButton)
326 .addComponent(outputPathTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
328 .addComponent(bnEditIngestSettings)
329 .addContainerGap(389, Short.MAX_VALUE))
332 browseOutputFolderButton.getAccessibleContext().setAccessibleName(
org.openide.util.NbBundle.getMessage(
CommandLineIngestSettingsPanel.class,
"CommandLineIngestSettingsPanel.browseOutputFolderButton.text"));
333 jLabelInvalidResultsFolder.getAccessibleContext().setAccessibleName(
org.openide.util.NbBundle.getMessage(
CommandLineIngestSettingsPanel.class,
"CommandLineIngestSettingsPanel.jLabelInvalidResultsFolder.text"));
334 jLabelSelectOutputFolder.getAccessibleContext().setAccessibleName(
org.openide.util.NbBundle.getMessage(
CommandLineIngestSettingsPanel.class,
"CommandLineIngestSettingsPanel.jLabelSelectOutputFolder.text"));
336 nodeScrollPane.setViewportView(nodePanel);
338 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(
this);
339 this.setLayout(layout);
340 layout.setHorizontalGroup(
341 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
342 .addComponent(nodeScrollPane, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 864, Short.MAX_VALUE)
344 layout.setVerticalGroup(
345 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
346 .addComponent(nodeScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 421, Short.MAX_VALUE)
351 String oldText = outputPathTextField.getText().trim();
353 File currentDir =
new File(oldText);
354 if (currentDir.exists()) {
355 fc.setCurrentDirectory(currentDir);
358 fc.setDialogTitle(
"Select case output folder:");
359 fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
361 int retval = fc.showOpenDialog(
this);
362 if (retval == JFileChooser.APPROVE_OPTION) {
363 String path = fc.getSelectedFile().getPath();
364 outputPathTextField.setText(path);
371 displayIngestJobSettingsPanel();
374 boolean permissionsAppropriate(String path) {
383 void setEnabledState(
boolean enabled) {
384 bnEditIngestSettings.setEnabled(enabled);
385 browseOutputFolderButton.setEnabled(enabled);
386 jLabelInvalidResultsFolder.setEnabled(enabled);
387 jLabelSelectOutputFolder.setEnabled(enabled);
388 outputPathTextField.setEnabled(enabled);
void displayIngestJobSettingsPanel()
javax.swing.JButton browseOutputFolderButton
javax.swing.JScrollPane nodeScrollPane
static void showWarnings(IngestJobSettings ingestJobSettings)
javax.swing.JTextField outputPathTextField
void insertUpdate(DocumentEvent e)
void removeUpdate(DocumentEvent e)
static String getCommandLineModeResultsFolder()
static boolean hasReadWriteAccess(Path dirPath)
javax.swing.JPanel nodePanel
IngestJobSettings getSettings()
void changedUpdate(DocumentEvent e)
void bnEditIngestSettingsActionPerformed(java.awt.event.ActionEvent evt)
javax.swing.JButton bnEditIngestSettings
List< String > getWarnings()
javax.swing.JLabel jLabelInvalidResultsFolder
synchronized static Logger getLogger(String name)
static void setCommandLineModeResultsFolder(String folder)
final CommandLineIngestSettingsPanelController controller
static String getCommandLineModeIngestModuleContextString()
javax.swing.JLabel jLabelSelectOutputFolder
CommandLineIngestSettingsPanel(CommandLineIngestSettingsPanelController theController)
void browseOutputFolderButtonActionPerformed(java.awt.event.ActionEvent evt)