Autopsy 4.22.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
ConfigVisualPanel3.java
Go to the documentation of this file.
1/*
2 * Autopsy
3 *
4 * Copyright 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 */
19package org.sleuthkit.autopsy.logicalimager.configuration;
20
21import com.google.gson.Gson;
22import com.google.gson.GsonBuilder;
23import com.google.gson.JsonIOException;
24import java.awt.Color;
25import java.awt.Cursor;
26import java.io.File;
27import java.io.IOException;
28import java.nio.file.Path;
29import java.nio.file.Paths;
30import java.util.Arrays;
31import java.util.List;
32import java.util.logging.Level;
33import javax.swing.JOptionPane;
34import org.apache.commons.io.FileUtils;
35import org.apache.commons.io.FilenameUtils;
36import org.openide.util.NbBundle;
37import org.sleuthkit.autopsy.coreutils.Logger;
38import static org.sleuthkit.autopsy.logicalimager.configuration.CreateLogicalImagerAction.getLogicalImagerExe;
39
43class ConfigVisualPanel3 extends javax.swing.JPanel {
44
45 private static final Logger logger = Logger.getLogger(ConfigVisualPanel3.class.getName());
46 private static final String SAVED_LOGICAL_IMAGER = "SAVED_LOGICAL_IMAGER";
47 private static final long serialVersionUID = 1L;
48 private boolean hasBeenSaved = false;
49 private String configFilename;
50 private LogicalImagerConfig config;
51
55 @NbBundle.Messages({"ConfigVisualPanel3.copyStatus.notSaved=File has not been saved",
56 "ConfigVisualPanel3.copyStatus.savingInProgress=Saving file, please wait",
57 "ConfigVisualPanel3.copyStatus.saved=Saved",
58 "ConfigVisualPanel3.copyStatus.error=Unable to save file"})
59 ConfigVisualPanel3() {
60 initComponents();
61 }
62
63 final void resetPanel() {
64 hasBeenSaved = false;
65 configStatusLabel.setText(Bundle.ConfigVisualPanel3_copyStatus_notSaved());
66 executableStatusLabel.setText(Bundle.ConfigVisualPanel3_copyStatus_notSaved());
67 }
68
69 @NbBundle.Messages({
70 "ConfigVisualPanel3.saveConfigurationFile=Save imager"
71 })
72 @Override
73 public String getName() {
74 return Bundle.ConfigVisualPanel3_saveConfigurationFile();
75 }
76
82 boolean isSaved() {
83 return hasBeenSaved;
84 }
85
90 @NbBundle.Messages({
91 "# {0} - configFilename",
92 "ConfigVisualPanel3.failedToSaveConfigMsg=Failed to save configuration file: {0}",
93 "# {0} - reason",
94 "ConfigVisualPanel3.reason=\nReason: {0}",
95 "ConfigVisualPanel3.failedToSaveExeMsg=Failed to save tsk_logical_imager.exe file"
96 })
97 void saveConfigFile() {
98 boolean saveSuccess = true;
99 executableStatusLabel.setForeground(Color.BLACK);
100 configStatusLabel.setText(Bundle.ConfigVisualPanel3_copyStatus_savingInProgress());
101 executableStatusLabel.setText(Bundle.ConfigVisualPanel3_copyStatus_savingInProgress());
102 setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
103 GsonBuilder gsonBuilder = new GsonBuilder()
104 .setPrettyPrinting()
105 .excludeFieldsWithoutExposeAnnotation()
106 .disableHtmlEscaping();
107 Gson gson = gsonBuilder.create();
108 String toJson = gson.toJson(config);
109 try {
110 List<String> lines = Arrays.asList(toJson.split("\\n"));
111 FileUtils.writeLines(new File(configFilename), "UTF-8", lines, System.getProperty("line.separator")); // NON-NLS
112 configStatusLabel.setText(Bundle.ConfigVisualPanel3_copyStatus_saved());
113 } catch (IOException ex) {
114 saveSuccess = false;
115 configStatusLabel.setText(Bundle.ConfigVisualPanel3_copyStatus_error());
116 configStatusLabel.setForeground(Color.RED);
117 JOptionPane.showMessageDialog(this, Bundle.ConfigVisualPanel3_failedToSaveConfigMsg(configFilename)
118 + Bundle.ConfigVisualPanel3_reason(ex.getMessage()));
119 } catch (JsonIOException jioe) {
120 saveSuccess = false;
121 executableStatusLabel.setText(Bundle.ConfigVisualPanel3_copyStatus_error());
122 executableStatusLabel.setForeground(Color.RED);
123 logger.log(Level.SEVERE, "Failed to save configuration file: " + configFilename, jioe); // NON-NLS
124 JOptionPane.showMessageDialog(this, Bundle.ConfigVisualPanel3_failedToSaveConfigMsg(configFilename)
125 + Bundle.ConfigVisualPanel3_reason(jioe.getMessage()));
126 }
127 try {
128 writeTskLogicalImagerExe(Paths.get(configFilename).getParent());
129 executableStatusLabel.setText(Bundle.ConfigVisualPanel3_copyStatus_saved());
130 } catch (IOException ex) {
131 saveSuccess = false;
132 executableStatusLabel.setText(Bundle.ConfigVisualPanel3_copyStatus_error());
133 executableStatusLabel.setForeground(Color.RED);
134 logger.log(Level.SEVERE, "Failed to save tsk_logical_imager.exe file", ex); // NON-NLS
135 JOptionPane.showMessageDialog(this, Bundle.ConfigVisualPanel3_failedToSaveExeMsg()
136 + Bundle.ConfigVisualPanel3_reason(ex.getMessage()));
137 }
138 if (saveSuccess) {
139 hasBeenSaved = true;
140 firePropertyChange(SAVED_LOGICAL_IMAGER, false, true); // NON-NLS
141 }
142 setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
143 }
144
152 @NbBundle.Messages({
153 "ConfigVisualPanel3.errorMsg.cannotFindLogicalImager=Cannot locate logical imager, cannot copy to destination"
154 })
155 private void writeTskLogicalImagerExe(Path destDir) throws IOException {
156 File logicalImagerExe = getLogicalImagerExe();
157 if (logicalImagerExe != null && logicalImagerExe.exists()) {
158 FileUtils.copyFileToDirectory(getLogicalImagerExe(), destDir.toFile());
159 } else {
160 throw new IOException(Bundle.ConfigVisualPanel3_errorMsg_cannotFindLogicalImager());
161 }
162 }
163
170 static String getSavedEventName() {
171 return SAVED_LOGICAL_IMAGER;
172 }
173
179 @SuppressWarnings("unchecked")
180 // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
181 private void initComponents() {
182
183 javax.swing.JButton saveButton = new javax.swing.JButton();
184 descriptionScrollPane = new javax.swing.JScrollPane();
185 descriptionTextArea = new javax.swing.JTextArea();
186 javax.swing.JLabel configLabel = new javax.swing.JLabel();
187 configStatusLabel = new javax.swing.JLabel();
188 javax.swing.JLabel executableLabel = new javax.swing.JLabel();
189 executableStatusLabel = new javax.swing.JLabel();
190
191 org.openide.awt.Mnemonics.setLocalizedText(saveButton, org.openide.util.NbBundle.getMessage(ConfigVisualPanel3.class, "ConfigVisualPanel3.saveButton.text")); // NOI18N
192 saveButton.addActionListener(new java.awt.event.ActionListener() {
193 public void actionPerformed(java.awt.event.ActionEvent evt) {
194 saveButtonActionPerformed(evt);
195 }
196 });
197
198 descriptionTextArea.setEditable(false);
199 descriptionTextArea.setBackground(new java.awt.Color(240, 240, 240));
200 descriptionTextArea.setColumns(20);
201 descriptionTextArea.setLineWrap(true);
202 descriptionTextArea.setRows(5);
203 descriptionTextArea.setWrapStyleWord(true);
204 descriptionTextArea.setEnabled(false);
205 descriptionScrollPane.setViewportView(descriptionTextArea);
206
207 org.openide.awt.Mnemonics.setLocalizedText(configLabel, org.openide.util.NbBundle.getMessage(ConfigVisualPanel3.class, "ConfigVisualPanel3.configLabel.text")); // NOI18N
208
209 org.openide.awt.Mnemonics.setLocalizedText(executableLabel, org.openide.util.NbBundle.getMessage(ConfigVisualPanel3.class, "ConfigVisualPanel3.executableLabel.text")); // NOI18N
210
211 org.openide.awt.Mnemonics.setLocalizedText(executableStatusLabel, org.openide.util.NbBundle.getMessage(ConfigVisualPanel3.class, "ConfigVisualPanel3.executableStatusLabel.text")); // NOI18N
212
213 javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
214 this.setLayout(layout);
215 layout.setHorizontalGroup(
216 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
217 .addGroup(layout.createSequentialGroup()
218 .addContainerGap()
219 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
220 .addGroup(layout.createSequentialGroup()
221 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
222 .addComponent(configLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
223 .addComponent(executableLabel))
224 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
225 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
226 .addComponent(configStatusLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 237, javax.swing.GroupLayout.PREFERRED_SIZE)
227 .addComponent(executableStatusLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 238, javax.swing.GroupLayout.PREFERRED_SIZE))
228 .addGap(0, 10, Short.MAX_VALUE))
229 .addGroup(layout.createSequentialGroup()
230 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
231 .addComponent(descriptionScrollPane)
232 .addGroup(layout.createSequentialGroup()
233 .addComponent(saveButton, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE)
234 .addGap(0, 0, Short.MAX_VALUE)))
235 .addContainerGap())))
236 );
237 layout.setVerticalGroup(
238 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
239 .addGroup(layout.createSequentialGroup()
240 .addContainerGap()
241 .addComponent(descriptionScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
242 .addGap(18, 18, 18)
243 .addComponent(saveButton)
244 .addGap(18, 18, 18)
245 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
246 .addComponent(configLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
247 .addComponent(configStatusLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE))
248 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
249 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
250 .addComponent(executableLabel)
251 .addComponent(executableStatusLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE))
252 .addContainerGap(100, Short.MAX_VALUE))
253 );
254 }// </editor-fold>//GEN-END:initComponents
255
256 private void saveButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveButtonActionPerformed
257 saveConfigFile();
258 }//GEN-LAST:event_saveButtonActionPerformed
259
260
261 // Variables declaration - do not modify//GEN-BEGIN:variables
262 private javax.swing.JLabel configStatusLabel;
263 private javax.swing.JScrollPane descriptionScrollPane;
264 private javax.swing.JTextArea descriptionTextArea;
265 private javax.swing.JLabel executableStatusLabel;
266 // End of variables declaration//GEN-END:variables
267
274 @NbBundle.Messages({
275 "# {0} - configurationLocation",
276 "ConfigVisualPanel3.description.text=Press Save to write the imaging tool and configuration file to the destination.\nDestination: {0}"
277 })
278 void setConfigInfoForSaving(String configFile, LogicalImagerConfig config) {
279 this.configFilename = configFile;
280 this.config = config;
281 descriptionTextArea.setText(Bundle.ConfigVisualPanel3_description_text(FilenameUtils.getFullPath(configFilename)));
282 }
283}

Copyright © 2012-2024 Sleuth Kit Labs. Generated on:
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.