Autopsy  4.11.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
CommandLineOptionProcessor.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2019-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.commandlineingest;
20 
21 import java.io.File;
22 import java.util.HashSet;
23 import java.util.Map;
24 import java.util.Set;
25 import java.util.logging.Level;
26 import java.util.logging.Logger;
27 import org.netbeans.api.sendopts.CommandException;
28 import org.netbeans.spi.sendopts.Env;
29 import org.netbeans.spi.sendopts.Option;
30 import org.netbeans.spi.sendopts.OptionProcessor;
31 import org.openide.util.lookup.ServiceProvider;
32 
36 @ServiceProvider(service = OptionProcessor.class)
37 public class CommandLineOptionProcessor extends OptionProcessor {
38 
39  private static final Logger logger = Logger.getLogger(CommandLineOptionProcessor.class.getName());
40  private final Option pathToDataSourceOption = Option.optionalArgument('l', "inputPath");
41  private final Option caseNameOption = Option.optionalArgument('2', "caseName");
42  private final Option runFromCommandLineOption = Option.optionalArgument('3', "runFromCommandLine");
43  private String pathToDataSource;
44  private String baseCaseName;
45  private boolean runFromCommandLine = false;
46 
47  @Override
48  protected Set<Option> getOptions() {
49  Set<Option> set = new HashSet<>();
50  set.add(pathToDataSourceOption);
51  set.add(caseNameOption);
52  set.add(runFromCommandLineOption);
53  return set;
54  }
55 
56  @Override
57  protected void process(Env env, Map<Option, String[]> values) throws CommandException {
58  logger.log(Level.INFO, "Processing Autopsy command line options"); //NON-NLS
59  System.out.println("Processing Autopsy command line options");
60  if (values.containsKey(pathToDataSourceOption) && values.containsKey(caseNameOption) && values.containsKey(runFromCommandLineOption)) {
61  // parse input parameters
62  String inputPath;
63  String inputCaseName;
64  String modeString;
65  if (values.size() < 3) {
66  logger.log(Level.SEVERE, "Insufficient number of input arguments to run command line ingest");
67  System.out.println("Insufficient number of input arguments to run command line ingest");
68  this.runFromCommandLine = false;
69  return;
70  } else {
71  String[] argDirs = values.get(pathToDataSourceOption);
72  if (argDirs.length < 1) {
73  logger.log(Level.SEVERE, "Missing argument 'inputPath'");
74  System.out.println("Missing argument 'inputPath'");
75  this.runFromCommandLine = false;
76  return;
77  }
78  inputPath = argDirs[0];
79 
80  argDirs = values.get(caseNameOption);
81  if (argDirs.length < 1) {
82  logger.log(Level.SEVERE, "Missing argument 'caseName'");
83  System.out.println("Missing argument 'caseName'");
84  this.runFromCommandLine = false;
85  return;
86  }
87  inputCaseName = argDirs[0];
88 
89  argDirs = values.get(runFromCommandLineOption);
90  if (argDirs.length < 1) {
91  logger.log(Level.SEVERE, "Missing argument 'runFromCommandLine'");
92  System.out.println("Missing argument 'runFromCommandLine'");
93  this.runFromCommandLine = false;
94  return;
95  }
96  modeString = argDirs[0];
97 
98  // verify inputs
99  if (modeString == null || modeString.isEmpty()) {
100  this.runFromCommandLine = false;
101  System.out.println("runFromCommandLine argument is empty");
102  return;
103  }
104 
105  if (modeString.equalsIgnoreCase("true")) {
106  this.runFromCommandLine = true;
107  }
108 
109  System.out.println("runFromCommandLine = " + this.runFromCommandLine);
110  }
111 
112  // verify inputs
113  if (inputPath == null || inputPath.isEmpty() || !(new File(inputPath).exists())) {
114  logger.log(Level.SEVERE, "Input file {0} doesn''t exist", inputPath);
115  System.out.println("Input file " + inputPath + " doesn't exist");
116  this.runFromCommandLine = false;
117  return;
118  }
119 
120  if (inputCaseName == null || inputCaseName.isEmpty()) {
121  logger.log(Level.SEVERE, "Case name argument is empty");
122  System.out.println("Case name argument is empty");
123  this.runFromCommandLine = false;
124  return;
125  }
126 
127  // save the inputs
128  this.pathToDataSource = inputPath;
129  this.baseCaseName = inputCaseName;
130  logger.log(Level.INFO, "Input file = {0}", this.pathToDataSource); //NON-NLS
131  logger.log(Level.INFO, "Case name = {0}", this.baseCaseName); //NON-NLS
132  logger.log(Level.INFO, "runFromCommandLine = {0}", this.runFromCommandLine); //NON-NLS
133  System.out.println("Input file = " + this.pathToDataSource);
134  System.out.println("Case name = " + this.baseCaseName);
135  System.out.println("runFromCommandLine = " + this.runFromCommandLine);
136  } else {
137  System.out.println("Missing input arguments to run command line ingest");
138  logger.log(Level.SEVERE, "Missing input arguments to run command line ingest");
139  }
140  }
141 
147  String getPathToDataSource() {
148  return pathToDataSource;
149  }
150 
156  String getBaseCaseName() {
157  return baseCaseName;
158  }
159 
165  public boolean isRunFromCommandLine() {
166  return runFromCommandLine;
167  }
168 }
synchronized static Logger getLogger(String name)
Definition: Logger.java:124

Copyright © 2012-2018 Basis Technology. Generated on: Fri Jun 21 2019
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.