def __init__(self): # Make the frame and set its properties self.frame = JFrame( "File Translator", defaultCloseOperation=WindowConstants.EXIT_ON_CLOSE, layout=GridBagLayout()) self.frame.setSize(1200, 800) # Make a GridBagLayout for this frame gridbag = GridBagLayout() constraints = GridBagConstraints() constraints.fill = GridBagConstraints.CENTER # Make sure to have a panel to hold everything self.loginPanel = JPanel(GridLayout(0, 2)) self.frame.add(self.loginPanel) gridbag.setConstraints(self.loginPanel, constraints) self.loginPanel.setLayout(gridbag) # Entry for the path self.usernameField = JTextField('', 30) self.loginPanel.add(JLabel("username:"******"password:")) self.loginPanel.add(self.textField) # Make a button to enter the information self.loginButton = JButton('Enter', actionPerformed=enter_button) self.loginPanel.add(self.loginButton) self.frame.add(self.loginPanel) # Make everything visible and make sure it starts at centre of screen self.frame.pack() self.frame.setLocationRelativeTo(None) self.frame.setVisible(True)
class HashImageSettingsWithUISettingsPanel(IngestModuleIngestJobSettingsPanel): # Note, we can't use a self.settings instance variable. # Rather, self.local_settings is used. # https://wiki.python.org/jython/UserGuide#javabean-properties # Jython Introspector generates a property - 'settings' on the basis # of getSettings() defined in this class. Since only getter function # is present, it creates a read-only 'settings' property. This auto- # generated read-only property overshadows the instance-variable - # 'settings' # We get passed in a previous version of the settings so that we can # prepopulate the UI def __init__(self, settings): self.local_settings = settings self.initComponents() self.customizeComponents() def FindFTKTxtFile(self, e): chooseFile = JFileChooser() filter = FileNameExtensionFilter("ALL", ["*.*"]) chooseFile.addChoosableFileFilter(filter) ret = chooseFile.showDialog(self.panel0, "Find FTK Log File") if ret == JFileChooser.APPROVE_OPTION: file = chooseFile.getSelectedFile() Canonical_file = file.getCanonicalPath() #text = self.readPath(file) self.local_settings.setSetting('FTKLogFile', Canonical_file) setSetting('FTKLogFile', Canonical_file) self.FTKLogFile_TF.setText(Canonical_file) def keyPressedMD5(self, event): self.local_settings.setSetting('MD5Hash', self.MD5HashValue_TF.getText()) def keyPressedSHA1(self, event): self.local_settings.setSetting('SHA1Hash', self.SHA1HashValue_TF.getText()) # Create the initial data fields/layout in the UI def initComponents(self): self.panel0 = JPanel() self.rbgPanel0 = ButtonGroup() self.gbPanel0 = GridBagLayout() self.gbcPanel0 = GridBagConstraints() self.panel0.setLayout( self.gbPanel0 ) self.Label_1 = JLabel("MD5 Hash Value To Verify") self.Label_1.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 1 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints( self.Label_1, self.gbcPanel0 ) self.panel0.add( self.Label_1 ) self.MD5HashValue_TF = JTextField(20, focusLost=self.keyPressedMD5) self.MD5HashValue_TF.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 3 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints( self.MD5HashValue_TF, self.gbcPanel0 ) self.panel0.add( self.MD5HashValue_TF ) self.Blank_1 = JLabel( " ") self.Blank_1.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 5 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints( self.Blank_1, self.gbcPanel0 ) self.panel0.add( self.Blank_1 ) self.Label_2 = JLabel("SHA1 Hash Value To Verify") self.Label_2.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 7 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints( self.Label_2, self.gbcPanel0 ) self.panel0.add( self.Label_2 ) self.SHA1HashValue_TF = JTextField(20, focusLost=self.keyPressedSHA1) self.SHA1HashValue_TF.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 9 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints( self.SHA1HashValue_TF, self.gbcPanel0 ) self.panel0.add( self.SHA1HashValue_TF ) self.Blank_2 = JLabel( " ") self.Blank_2.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 11 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints( self.Blank_1, self.gbcPanel0 ) self.panel0.add( self.Blank_1 ) self.Label_3 = JLabel("FTK Log File") self.Label_3.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 13 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints( self.Label_3, self.gbcPanel0 ) self.panel0.add( self.Label_3 ) self.FTKLogFile_TF = JTextField(20) self.FTKLogFile_TF.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 15 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints( self.FTKLogFile_TF, self.gbcPanel0 ) self.panel0.add( self.FTKLogFile_TF ) self.FTKLogFile_BTN = JButton( "Find File", actionPerformed=self.FindFTKTxtFile) self.FTKLogFile_BTN.setEnabled(True) self.rbgPanel0.add( self.FTKLogFile_BTN ) self.gbcPanel0.gridx = 6 self.gbcPanel0.gridy = 15 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints( self.FTKLogFile_BTN, self.gbcPanel0 ) self.panel0.add( self.FTKLogFile_BTN ) self.Label_4 = JLabel( "Message:") self.Label_4.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 29 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints( self.Label_4, self.gbcPanel0 ) self.panel0.add( self.Label_4 ) self.Error_Message = JLabel( "") self.Error_Message.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 31 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints( self.Error_Message, self.gbcPanel0 ) self.panel0.add( self.Error_Message ) self.add(self.panel0) # Custom load any data field and initialize the values def customizeComponents(self): pass # Return the settings used def getSettings(self): self.local_settings.setSetting('MD5Hash', self.MD5HashValue_TF.getText()) self.local_settings.setSetting('SHA1Hash', self.SHA1HashValue_TF.getText()) return self.local_settings
class CuckooSettingsWithUISettingsPanel(IngestModuleIngestJobSettingsPanel): # Note, we can't use a self.settings instance variable. # Rather, self.local_settings is used. # https://wiki.python.org/jython/UserGuide#javabean-properties # Jython Introspector generates a property - 'settings' on the basis # of getSettings() defined in this class. Since only getter function # is present, it creates a read-only 'settings' property. This auto- # generated read-only property overshadows the instance-variable - # 'settings' # We get passed in a previous version of the settings so that we can # prepopulate the UI # TODO: Update this for your UI def __init__(self, settings): self.local_settings = settings self.tag_list = [] self.initComponents() self.customizeComponents() self.path_to_cuckoo_exe = os.path.join(os.path.dirname(os.path.abspath(__file__)), "cuckoo_api.exe") # Check the checkboxs to see what actions need to be taken def checkBoxEvent(self, event): if self.Submit_File_CB.isSelected(): self.local_settings.setSubmit_File(True) self.local_settings.setSubmit_URL(False) else: self.local_settings.setSubmit_File(False) # if self.Submit_URL_CB.isSelected(): # self.local_settings.setSubmit_URL(True) # self.local_settings.setSubmit_File(False) # else: # self.local_settings.setSubmit_URL(False) def onchange_lb(self, event): self.local_settings.cleartag_list() list_selected = self.List_Box_LB.getSelectedValuesList() self.local_settings.settag_list(list_selected) def find_tags(self): sql_statement = "SELECT distinct(display_name) u_tag_name FROM content_tags INNER JOIN tag_names ON " + \ " content_tags.tag_name_id = tag_names.tag_name_id;" skCase = Case.getCurrentCase().getSleuthkitCase() dbquery = skCase.executeQuery(sql_statement) resultSet = dbquery.getResultSet() while resultSet.next(): self.tag_list.append(resultSet.getString("u_tag_name")) dbquery.close() # Check to see if there are any entries that need to be populated from the database. def check_Database_entries(self): head, tail = os.path.split(os.path.abspath(__file__)) settings_db = head + "\\gui_Settings.db3" try: Class.forName("org.sqlite.JDBC").newInstance() dbConn = DriverManager.getConnection("jdbc:sqlite:%s" % settings_db) except SQLException as e: self.Error_Message.setText("Error Opening Settings DB!") try: stmt = dbConn.createStatement() SQL_Statement = 'Select Protocol, cuckoo_host, cuckoo_port from cuckoo_server' resultSet = stmt.executeQuery(SQL_Statement) while resultSet.next(): self.Protocol_TF.setText(resultSet.getString("Protocol")) self.IP_Address_TF.setText(resultSet.getString("cuckoo_host")) self.Port_Number_TF.setText(resultSet.getString("cuckoo_port")) self.local_settings.setProtocol(resultSet.getString("Protocol")) self.local_settings.setIP_Address(resultSet.getString("cuckoo_host")) self.local_settings.setPort_Number(resultSet.getString("cuckoo_port")) self.Error_Message.setText("Settings Read successfully!") except SQLException as e: self.Error_Message.setText("Error Reading Settings Database") stmt.close() dbConn.close() # Save entries from the GUI to the database. def SaveSettings(self, e): head, tail = os.path.split(os.path.abspath(__file__)) settings_db = head + "\\GUI_Settings.db3" try: Class.forName("org.sqlite.JDBC").newInstance() dbConn = DriverManager.getConnection("jdbc:sqlite:%s" % settings_db) except SQLException as e: self.Error_Message.setText("Error Opening Settings") try: stmt = dbConn.createStatement() SQL_Statement = "" SQL_Statement = 'Update cuckoo_server set Protocol = "' + self.Protocol_TF.getText() + '", ' + \ ' Cuckoo_Host = "' + self.IP_Address_TF.getText() + '", ' + \ ' Cuckoo_port = "' + self.Port_Number_TF.getText() + '";' #self.Error_Message.setText(SQL_Statement) stmt.execute(SQL_Statement) self.Error_Message.setText("Cuckoo settings Saved") #self.local_settings.setCuckoo_Directory(self.Program_Executable_TF.getText()) except SQLException as e: self.Error_Message.setText(e.getMessage()) stmt.close() dbConn.close() # Check to see if the Cuckoo server is available and you can talk to it def Check_Server(self, e): pipe = Popen([self.path_to_cuckoo_exe, self.Protocol_TF.getText(),self.IP_Address_TF.getText(), self.Port_Number_TF.getText(), "cuckoo_status" ], stdout=PIPE, stderr=PIPE) out_text = pipe.communicate()[0] self.Error_Message.setText("Cuckoo Status is " + out_text) #self.log(Level.INFO, "Cuckoo Status is ==> " + out_text) # def onchange_cb(self, event): # self.local_settings.setComboBox(event.item) # Create the initial data fields/layout in the UI def initComponents(self): self.panel0 = JPanel() self.rbgPanel0 = ButtonGroup() self.gbPanel0 = GridBagLayout() self.gbcPanel0 = GridBagConstraints() self.panel0.setLayout( self.gbPanel0 ) self.Label_1 = JLabel("Protocol:") self.Label_1.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 1 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints( self.Label_1, self.gbcPanel0 ) self.panel0.add( self.Label_1 ) self.Protocol_TF = JTextField(20) self.Protocol_TF.setEnabled(True) self.gbcPanel0.gridx = 4 self.gbcPanel0.gridy = 1 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints( self.Protocol_TF, self.gbcPanel0 ) self.panel0.add( self.Protocol_TF ) self.Blank_1 = JLabel( " ") self.Blank_1.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 3 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints( self.Blank_1, self.gbcPanel0 ) self.panel0.add( self.Blank_1 ) self.Label_2 = JLabel("Cuckoo IP Address") self.Label_2.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 5 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints( self.Label_2, self.gbcPanel0 ) self.panel0.add( self.Label_2 ) self.IP_Address_TF = JTextField(20) self.IP_Address_TF.setEnabled(True) self.gbcPanel0.gridx = 4 self.gbcPanel0.gridy = 5 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints( self.IP_Address_TF, self.gbcPanel0 ) self.panel0.add( self.IP_Address_TF ) self.Blank_2 = JLabel( " ") self.Blank_2.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 7 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints( self.Blank_2, self.gbcPanel0 ) self.panel0.add( self.Blank_2 ) self.Label_3 = JLabel("Port Number") self.Label_3.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 9 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints( self.Label_3, self.gbcPanel0 ) self.panel0.add( self.Label_3 ) self.Port_Number_TF = JTextField(20) self.Port_Number_TF.setEnabled(True) self.gbcPanel0.gridx = 4 self.gbcPanel0.gridy = 9 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints( self.Port_Number_TF, self.gbcPanel0 ) self.panel0.add( self.Port_Number_TF ) self.Blank_3 = JLabel( " ") self.Blank_3.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 11 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints( self.Blank_3, self.gbcPanel0 ) self.panel0.add( self.Blank_3 ) self.Save_Settings_BTN = JButton( "Save Setup", actionPerformed=self.SaveSettings) self.Save_Settings_BTN.setEnabled(True) self.rbgPanel0.add( self.Save_Settings_BTN ) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 13 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints( self.Save_Settings_BTN, self.gbcPanel0 ) self.panel0.add( self.Save_Settings_BTN ) self.Blank_4 = JLabel( " ") self.Blank_4.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 15 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints( self.Blank_4, self.gbcPanel0 ) self.panel0.add( self.Blank_4 ) self.Blank_5 = JLabel( "Tag to Choose: ") self.Blank_5.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 17 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints( self.Blank_5, self.gbcPanel0 ) self.panel0.add( self.Blank_5 ) self.find_tags() self.List_Box_LB = JList( self.tag_list, valueChanged=self.onchange_lb) self.List_Box_LB.setVisibleRowCount( 3 ) self.scpList_Box_LB = JScrollPane( self.List_Box_LB ) self.gbcPanel0.gridx = 4 self.gbcPanel0.gridy = 17 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 1 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints( self.scpList_Box_LB, self.gbcPanel0 ) self.panel0.add( self.scpList_Box_LB ) self.Blank_6 = JLabel( " ") self.Blank_6.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 19 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints( self.Blank_6, self.gbcPanel0 ) self.panel0.add( self.Blank_6 ) self.Submit_File_CB = JCheckBox("Submit a File", actionPerformed=self.checkBoxEvent) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 21 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints( self.Submit_File_CB, self.gbcPanel0 ) self.panel0.add( self.Submit_File_CB ) # self.Submit_URL_CB = JCheckBox("Submit a URL", actionPerformed=self.checkBoxEvent) # self.gbcPanel0.gridx = 2 # self.gbcPanel0.gridy = 23 # self.gbcPanel0.gridwidth = 1 # self.gbcPanel0.gridheight = 1 # self.gbcPanel0.fill = GridBagConstraints.BOTH # self.gbcPanel0.weightx = 1 # self.gbcPanel0.weighty = 0 # self.gbcPanel0.anchor = GridBagConstraints.NORTH # self.gbPanel0.setConstraints( self.Submit_URL_CB, self.gbcPanel0 ) # self.panel0.add( self.Submit_URL_CB ) self.Check_Server_Status_BTN = JButton( "Check Server Status", actionPerformed=self.Check_Server) self.Check_Server_Status_BTN.setEnabled(True) self.rbgPanel0.add( self.Save_Settings_BTN ) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 25 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints( self.Check_Server_Status_BTN, self.gbcPanel0 ) self.panel0.add( self.Check_Server_Status_BTN ) self.Error_Message = JLabel( "") self.Error_Message.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 27 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints( self.Error_Message, self.gbcPanel0 ) self.panel0.add( self.Error_Message ) self.add(self.panel0) # Custom load any data field and initialize the values def customizeComponents(self): #self.Exclude_File_Sources_CB.setSelected(self.local_settings.getExclude_File_Sources()) #self.Run_Cuckoo_CB.setSelected(self.local_settings.getRun_Cuckoo()) #self.Import_Cuckoo_CB.setSelected(self.local_settings.getImport_Cuckoo()) self.check_Database_entries() # Return the settings used def getSettings(self): return self.local_settings
def makeRegistrationUI(original_images, original_calibration, coarse_affines, params, images, minC, maxC, cropped, cropped_imp): """ Register cropped images either all to all or all to the first one, and print out a config file with the coarse affines, the ROI for cropping, and the refined affines post-crop. original_images: the original, raw images, with original dimensions. original_calibration: the calibration of the images as they are on disk. coarse_affines: list of AffineTransform3D, one per image, that specify the translation between images as manually set using the makeTranslationUI. params: dictionary with parameters for registering the given cropped images. This includes a calibration that is likely [1.0, 1.0, 1.0] as the cropped images are expected to have been scaled to isotropy. images: the list of near-original images but scaled (by calibration) to isotropy. (These are really views of the original images, using nearest neighbor interpolation to scale them to isotropy.) minC, maxC: the minimum and maximum coordinates of a ROI with which the cropped images were made. cropped: the list of images that have been scaled to isotropy, translated and cropped by the ROI. (These are really interval views of the images, the latter using nearest neighbor interpolation.) cropped_imp: the ImagePlus holding the virtual stack of cropped image views. The computed registration will merge the scaling to isotropy + first transform (a translation) + roi cropping translation + the params["modelclass"] registration transform, to read directly from the original images using a nearest interpolation, for best performance (piling two nearest interpolations over one another would result in very slow access to pixel data). """ panel = JPanel() panel.setBorder(BorderFactory.createEmptyBorder(10,10,10,10)) gb = GridBagLayout() panel.setLayout(gb) gc = GBC() calibration = params["calibration"] params["cal X"] = calibration[0] params["cal Y"] = calibration[1] params["cal Z"] = calibration[2] # Add a label and a text field for every parameter, with titles for every block strings = [["Calibration", "cal X", "cal Y", "cal Z"], ["Difference of Gaussian", "minPeakValue", "sigmaSmaller", "sigmaLarger"], ["Feature extraction", "radius", "min_angle", "max_per_peak", "angle_epsilon", "len_epsilon_sq", "pointmatches_nearby", "pointmatches_search_radius"], ["RANSAC parameters for the model", "maxEpsilon", "minInlierRatio", "minNumInliers", "n_iterations", "maxTrust"], ["All to all registration", "maxAllowedError", "maxPlateauwidth", "maxIterations", "damp"]] # Insert all as fields, with values populated from the params dictionary # and updating dynamically the params dictionary params = dict(params) # copy, will be updated insertFloatFields(panel, gb, gc, params, strings) # Identity transforms prior to registration affines = [affine3D([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0]) for img in cropped] def run(): exe = newFixedThreadPool(min(len(cropped), numCPUs())) try: # Dummy for in-RAM reading of isotropic images img_filenames = [str(i) for i in xrange(len(cropped))] loader = InRAMLoader(dict(zip(img_filenames, cropped))) getCalibration = params.get("getCalibration", None) if not getCalibration: getCalibration = lambda img: [1.0] * cropped[0].numDimensions() csv_dir = params["csv_dir"] modelclass = params["modelclass"] # Matrices describing the registration on the basis of the cropped images matrices = computeOptimizedTransforms(img_filenames, loader, getCalibration, csv_dir, exe, modelclass, params) # Store outside, so they can be e.g. printed, and used beyond here for matrix, affine in zip(matrices, affines): affine.set(*matrix) # Combine the transforms: scaling (by calibration) # + the coarse registration (i.e. manual translations) # + the translation introduced by the ROI cropping # + the affine matrices computed above over the cropped images. coarse_matrices = [] for coarse_affine in coarse_affines: matrix = zeros(12, 'd') coarse_affine.toArray(matrix) coarse_matrices.append(matrix) # NOTE: both coarse_matrices and matrices are from the camera X to camera 0. No need to invert them. # NOTE: uses identity calibration because the coarse_matrices already include the calibration scaling to isotropy transforms = mergeTransforms([1.0, 1.0, 1.0], coarse_matrices, [minC, maxC], matrices, invert2=False) print "calibration:", [1.0, 1.0, 1.0] print "cmTransforms:\n %s\n %s\n %s\n %s" % tuple(str(m) for m in coarse_matrices) print "ROI", [minC, maxC] print "fineTransformsPostROICrop:\n %s\n %s\n %s\n %s" % tuple(str(m) for m in matrices) print "invert2:", False # Show registered images registered = [transformedView(img, transform, interval=cropped[0]) for img, transform in izip(original_images, transforms)] registered_imp = showAsStack(registered, title="Registered with %s" % params["modelclass"].getSimpleName()) registered_imp.setDisplayRange(cropped_imp.getDisplayRangeMin(), cropped_imp.getDisplayRangeMax()) """ # TEST: same as above, but without merging the transforms. WORKS, same result # Copy into ArrayImg, otherwise they are rather slow to browse def copy(img1, affine): # Copy in two steps. Otherwise the nearest neighbor interpolation on top of another # nearest neighbor interpolation takes a huge amount of time dimensions = Intervals.dimensionsAsLongArray(img1) aimg1 = ArrayImgs.unsignedShorts(dimensions) ImgUtil.copy(ImgView.wrap(img1, aimg1.factory()), aimg1) img2 = transformedView(aimg1, affine) aimg2 = ArrayImgs.unsignedShorts(dimensions) ImgUtil.copy(ImgView.wrap(img2, aimg2.factory()), aimg2) return aimg2 futures = [exe.submit(Task(copy, img, affine)) for img, affine in izip(cropped, affines)] aimgs = [f.get() for f in futures] showAsStack(aimgs, title="DEBUG Registered with %s" % params["modelclass"].getSimpleName()) """ except: print sys.exc_info() finally: exe.shutdown() SwingUtilities.invokeLater(lambda: run_button.setEnabled(True)) def launchRun(event): # Runs on the event dispatch thread run_button.setEnabled(False) # will be re-enabled at the end of run() # Fork: Thread(run).start() def printAffines(event): for i, affine in enumerate(affines): matrix = zeros(12, 'd') affine.toArray(matrix) msg = "# Refined post-crop affine matrix " + str(i) + ": \n" + \ "affine" + str(i) + ".set(*[%f, %f, %f, %f,\n %f, %f, %f, %f,\n %f, %f, %f, %f])" % tuple(matrix.tolist()) # Print everywhere print msg IJ.log(msg) System.out.println(msg) def prepareDeconvolutionScriptUI(event): """ # DEBUG generateDeconvolutionScriptUI: generate params as a loadable serialized file with open("/tmp/parameters.pickle", 'w') as f: import pickle def asArrays(affines): arrays = [] for affine in affines: matrix = zeros(12, 'd') affine.toArray(matrix) arrays.append(matrix) return arrays pickle.dump([params["srcDir"], params["tgtDir"], calibration, asArrays(coarse_affines), [minC, maxC], asArrays(affines)], f) """ generateDeconvolutionScriptUI(params["srcDir"], params["tgtDir"], calibration, coarse_affines, [minC, maxC], affines) # Buttons panel_buttons = JPanel() gc.gridx = 0 gc.gridy += 1 gc.gridwidth = 2 gb.setConstraints(panel_buttons, gc) panel.add(panel_buttons) run_button = JButton("Run") run_button.addActionListener(launchRun) gb.setConstraints(run_button, gc) panel_buttons.add(run_button) print_button = JButton("Print affines") print_button.addActionListener(printAffines) panel_buttons.add(print_button) prepare_button = JButton("Prepare deconvolution script") prepare_button.addActionListener(prepareDeconvolutionScriptUI) panel_buttons.add(prepare_button) frame = JFrame("Registration") frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE) frame.addWindowListener(CloseControl()) frame.getContentPane().add(panel) frame.pack() frame.setLocationRelativeTo(None) # center in the screen frame.setVisible(True)
def makeTranslationUI(affines, imp, show=True, print_button_text="Print transforms"): """ A GUI to control the translation components of a list of AffineTransform3D instances. When updated, the ImagePlus is refreshed. affines: a list (will be read multiple times) of one affine transform per image. imp: the ImagePlus that hosts the virtual stack with the transformed images. show: defaults to True, whether to make the GUI visible. print_button_text: whatever you want the print button to read like, defaults to "Print transforms". Returns the JFrame, the main JPanel and the lower JButton panel. """ panel = JPanel() panel.setBorder(BorderFactory.createEmptyBorder(10,10,10,10)) gb = GridBagLayout() panel.setLayout(gb) gc = GBC() gc.anchor = GBC.WEST gc.fill = GBC.NONE # Column labels gc.gridy = 0 for i, title in enumerate(["Camera", "translation X", "translation Y", "translation Z"]): gc.gridx = i gc.anchor = GBC.CENTER label = JLabel(title) gb.setConstraints(label, gc) panel.add(label) gc.anchor = GBC.WEST listeners = [] # One row per affine to control: skip the first for i, affine in enumerate(affines[1:]): gc.gridx = 0 gc.gridy += 1 label = JLabel("CM0%i: " % (i + 1)) gb.setConstraints(label, gc) panel.add(label) # One JTextField per dimension for dimension, translation in enumerate(affine.getTranslation()): tf = JTextField(str(translation), 10) listener = MatrixTextFieldListener(affine, dimension, tf, imp) listeners.append(listener) imp.addImageListener(listener) # to disable the JTextField when closed tf.addKeyListener(listener) tf.addMouseWheelListener(listener) gc.gridx += 1 gb.setConstraints(tf, gc) panel.add(tf) # Documentation for the user help_lines = ["Type a number and push enter,", "or use the scroll wheel."] gc.gridx = 0 gc.gridwidth = 4 for line in help_lines: gc.gridy += 1 help = JLabel(line) gb.setConstraints(help, gc) panel.add(help) # Buttons printButton = JButton(print_button_text) def printTransforms(event): for i, aff in enumerate(affines): # print all, including the first matrix = zeros(12, 'd') aff.toArray(matrix) msg = "# Coarse affine matrix " + str(i) + ": \n" + \ "affine" + str(i) + ".set(*[%f, %f, %f, %f,\n %f, %f, %f, %f,\n %f, %f, %f, %f])" % tuple(matrix.tolist()) # Print everywhere print msg IJ.log(msg) System.out.println(msg) printButton.addActionListener(printTransforms) gc.gridx = 0 gc.gridy += 1 gc.gridwidth = 4 button_panel = JPanel() button_panel.add(printButton) gb.setConstraints(button_panel, gc) panel.add(button_panel) frame = JFrame("Translation control") frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE) frame.addWindowListener(CloseControl(destroyables=listeners)) frame.getContentPane().add(panel) frame.pack() frame.setLocationRelativeTo(None) # center in the screen frame.setVisible(show) return frame, panel, button_panel
class VolatilitySettingsWithUISettingsPanel(IngestModuleIngestJobSettingsPanel ): # Note, we can't use a self.settings instance variable. # Rather, self.local_settings is used. # https://wiki.python.org/jython/UserGuide#javabean-properties # Jython Introspector generates a property - 'settings' on the basis # of getSettings() defined in this class. Since only getter function # is present, it creates a read-only 'settings' property. This auto- # generated read-only property overshadows the instance-variable - # 'settings' # We get passed in a previous version of the settings so that we can # prepopulate the UI # TODO: Update this for your UI def __init__(self, settings): self.local_settings = settings self.initComponents() self.customizeComponents() # Check the checkboxs to see what actions need to be taken def checkBoxEvent(self, event): if self.Exclude_File_Sources_CB.isSelected(): self.local_settings.setExclude_File_Sources(True) else: self.local_settings.setExclude_File_Sources(False) # Check to see if there are any entries that need to be populated from the database. def check_Database_entries(self): head, tail = os.path.split(os.path.abspath(__file__)) settings_db = head + "\\GUI_Settings.db3" try: Class.forName("org.sqlite.JDBC").newInstance() dbConn = DriverManager.getConnection("jdbc:sqlite:%s" % settings_db) except SQLException as e: self.Error_Message.setText("Error Opening Settings DB!") try: stmt = dbConn.createStatement() SQL_Statement = 'Select Setting_Name, Setting_Value from settings;' resultSet = stmt.executeQuery(SQL_Statement) while resultSet.next(): if resultSet.getString( "Setting_Name") == "Volatility_Executable_Directory": self.Program_Executable_TF.setText( resultSet.getString("Setting_Value")) self.local_settings.setVolatility_Directory( resultSet.getString("Setting_Value")) self.local_settings.setVolatility_Dir_Found(True) if resultSet.getString("Setting_Name") == "Volatility_Version": self.Version_CB.setSelectedItem( resultSet.getString("Setting_Value")) self.Error_Message.setText("Settings Read successfully!") except SQLException as e: self.Error_Message.setText("Error Reading Settings Database") stmt.close() dbConn.close() # Save entries from the GUI to the database. def SaveSettings(self, e): head, tail = os.path.split(os.path.abspath(__file__)) settings_db = head + "\\GUI_Settings.db3" try: Class.forName("org.sqlite.JDBC").newInstance() dbConn = DriverManager.getConnection("jdbc:sqlite:%s" % settings_db) except SQLException as e: self.Error_Message.setText("Error Opening Settings") try: stmt = dbConn.createStatement() SQL_Statement = "" if (self.local_settings.getVolatility_Dir_Found()): SQL_Statement = 'Update settings set Setting_Value = "' + self.Program_Executable_TF.getText() + '"' + \ ' where setting_name = "Volatility_Executable_Directory";' SQL_Statement2 = 'Update settings set Setting_Value = "' + self.Version_CB.getSelectedItem() + '"' + \ ' where setting_name = "Volatility_Version";' else: SQL_Statement = 'Insert into settings (Setting_Name, Setting_Value) values ("Volatility_Executable_Directory", "' + \ self.Program_Executable_TF.getText() + '");' SQL_Statement2 = 'Insert into settings (Setting_Name, Setting_Value) values ("Volatility_Version", "' + \ self.Version_CB.getSelectedItem() + '");' stmt.execute(SQL_Statement) stmt.execute(SQL_Statement2) self.Error_Message.setText("Volatility Executable Directory Saved") self.local_settings.setVolatility_Directory( self.Program_Executable_TF.getText()) except SQLException as e: self.Error_Message.setText(e.getMessage()) stmt.close() dbConn.close() def get_plugins(self): head, tail = os.path.split(os.path.abspath(__file__)) settings_db = head + "\\GUI_Settings.db3" try: Class.forName("org.sqlite.JDBC").newInstance() dbConn = DriverManager.getConnection("jdbc:sqlite:%s" % settings_db) self.Error_Message.setText("Database opened") except SQLException as e: self.Error_Message.setText("Error Opening Settings DB!") try: stmt = dbConn.createStatement() SQL_Statement = "select plugin_name from plugins where volatility_version = '" + self.Version_CB.getSelectedItem() + "' and " + \ " plugin_name in ('dumpcerts', 'dumpfiles', 'dumpregistry', 'linux_librarydump', 'linux_procdump', 'mac_dump_file', 'mac_procdump', 'moddump', 'procdump', 'vaddump');" resultSet = stmt.executeQuery(SQL_Statement) plugin_list = [] while resultSet.next(): plugin_list.append(resultSet.getString("plugin_name")) stmt.close() dbConn.close() return plugin_list except SQLException as e: self.Error_Message.setText("Error Reading plugins") stmt.close() dbConn.close() return "Error" def get_profiles(self): head, tail = os.path.split(os.path.abspath(__file__)) settings_db = head + "\\GUI_Settings.db3" try: Class.forName("org.sqlite.JDBC").newInstance() dbConn = DriverManager.getConnection("jdbc:sqlite:%s" % settings_db) self.Error_Message.setText("Database opened") except SQLException as e: self.Error_Message.setText("Error Opening Settings DB!") try: stmt = dbConn.createStatement() SQL_Statement = "select profile_name from profiles where volatility_version = '" + self.Version_CB.getSelectedItem( ) + "';" resultSet = stmt.executeQuery(SQL_Statement) profile_list = [] while resultSet.next(): profile_list.append(resultSet.getString("profile_name")) stmt.close() dbConn.close() return profile_list except SQLException as e: self.Error_Message.setText("Error Reading plugins") stmt.close() dbConn.close() return "Error" # When button to find file is clicked then open dialog to find the file and return it. def Find_Dir(self, e): chooseFile = JFileChooser() filter = FileNameExtensionFilter("All", ["*.*"]) chooseFile.addChoosableFileFilter(filter) #chooseFile.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY) ret = chooseFile.showDialog(self.panel0, "Find Volatility Directory") if ret == JFileChooser.APPROVE_OPTION: file = chooseFile.getSelectedFile() Canonical_file = file.getCanonicalPath() #text = self.readPath(file) self.local_settings.setVolatility_Directory(Canonical_file) self.Program_Executable_TF.setText(Canonical_file) def keyPressed(self, event): self.local_settings.setProcessIDs( self.Process_Ids_To_Dump_TF.getText()) #self.Error_Message.setText(self.Process_Ids_To_Dump_TF.getText()) def onchange_version(self, event): self.local_settings.setVersion(event.item) plugin_list = self.get_plugins() profile_list = self.get_profiles() self.Profile_CB.removeAllItems() self.Plugin_LB.clearSelection() self.Plugin_LB.setListData(plugin_list) for profile in profile_list: self.Profile_CB.addItem(profile) #self.Profile_CB.addItems(profile) self.panel0.repaint() def onchange_plugins_lb(self, event): self.local_settings.clearPluginListBox() list_selected = self.Plugin_LB.getSelectedValuesList() self.local_settings.setPluginListBox(list_selected) def onchange_profile_cb(self, event): self.local_settings.setProfile(event.item) # Create the initial data fields/layout in the UI def initComponents(self): self.panel0 = JPanel() self.rbgPanel0 = ButtonGroup() self.gbPanel0 = GridBagLayout() self.gbcPanel0 = GridBagConstraints() self.panel0.setLayout(self.gbPanel0) self.Error_Message = JLabel("") self.Error_Message.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 31 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.Error_Message, self.gbcPanel0) self.panel0.add(self.Error_Message) self.Label_1 = JLabel("Volatility Executable Directory") self.Label_1.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 1 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.Label_1, self.gbcPanel0) self.panel0.add(self.Label_1) self.Program_Executable_TF = JTextField(10) self.Program_Executable_TF.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 3 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.Program_Executable_TF, self.gbcPanel0) self.panel0.add(self.Program_Executable_TF) self.Find_Program_Exec_BTN = JButton("Find Dir", actionPerformed=self.Find_Dir) self.Find_Program_Exec_BTN.setEnabled(True) self.rbgPanel0.add(self.Find_Program_Exec_BTN) self.gbcPanel0.gridx = 6 self.gbcPanel0.gridy = 3 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.Find_Program_Exec_BTN, self.gbcPanel0) self.panel0.add(self.Find_Program_Exec_BTN) self.Blank_1 = JLabel(" ") self.Blank_1.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 5 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.Blank_1, self.gbcPanel0) self.panel0.add(self.Blank_1) self.Save_Settings_BTN = JButton("Save Volatility Exec Dir", actionPerformed=self.SaveSettings) self.Save_Settings_BTN.setEnabled(True) self.rbgPanel0.add(self.Save_Settings_BTN) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 7 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.Save_Settings_BTN, self.gbcPanel0) self.panel0.add(self.Save_Settings_BTN) self.Blank_2 = JLabel(" ") self.Blank_2.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 9 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.Blank_2, self.gbcPanel0) self.panel0.add(self.Blank_2) self.Version_Label_1 = JLabel("Version:") self.Blank_1.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 11 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.Version_Label_1, self.gbcPanel0) self.panel0.add(self.Version_Label_1) self.Version_List = ("2.5", "2.6") self.Version_CB = JComboBox(self.Version_List) self.Version_CB.itemStateChanged = self.onchange_version self.gbcPanel0.gridx = 6 self.gbcPanel0.gridy = 11 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.Version_CB, self.gbcPanel0) self.panel0.add(self.Version_CB) self.Blank_3 = JLabel(" ") self.Blank_3.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 13 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.Blank_3, self.gbcPanel0) self.panel0.add(self.Blank_3) self.Plugin_Label_1 = JLabel("Plugins:") self.Blank_1.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 15 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.Plugin_Label_1, self.gbcPanel0) self.panel0.add(self.Plugin_Label_1) self.Plugin_list = self.get_plugins() self.Plugin_LB = JList(self.Plugin_list, valueChanged=self.onchange_plugins_lb) self.Plugin_LB.setVisibleRowCount(3) self.scpPlugin_LB = JScrollPane(self.Plugin_LB) self.gbcPanel0.gridx = 6 self.gbcPanel0.gridy = 15 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 1 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.scpPlugin_LB, self.gbcPanel0) self.panel0.add(self.scpPlugin_LB) self.Blank_4 = JLabel(" ") self.Blank_4.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 17 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.Blank_4, self.gbcPanel0) self.panel0.add(self.Blank_4) self.Profile_Label_1 = JLabel("Profile:") self.Blank_1.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 19 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.Profile_Label_1, self.gbcPanel0) self.panel0.add(self.Profile_Label_1) self.Profile_List = self.get_profiles() self.Profile_CB = JComboBox(self.Profile_List) self.Profile_CB.itemStateChanged = self.onchange_profile_cb self.gbcPanel0.gridx = 6 self.gbcPanel0.gridy = 19 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 1 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.Profile_CB, self.gbcPanel0) self.panel0.add(self.Profile_CB) self.Blank_5 = JLabel(" ") self.Blank_5.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 21 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.Blank_5, self.gbcPanel0) self.panel0.add(self.Blank_5) self.Label_2 = JLabel("Process ids to dump (comma seperated list):") self.Label_2.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 23 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.Label_2, self.gbcPanel0) self.panel0.add(self.Label_2) self.Process_Ids_To_Dump_TF = JTextField(10, focusLost=self.keyPressed) #self.Process_Ids_To_Dump_TF.getDocument().addDocumentListener() self.Process_Ids_To_Dump_TF.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 25 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.Process_Ids_To_Dump_TF, self.gbcPanel0) self.panel0.add(self.Process_Ids_To_Dump_TF) self.Blank_6 = JLabel(" ") self.Blank_6.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 27 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.Blank_6, self.gbcPanel0) self.panel0.add(self.Blank_6) self.Label_3 = JLabel("Message:") self.Label_3.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 29 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.Label_3, self.gbcPanel0) self.panel0.add(self.Label_3) self.add(self.panel0) # Custom load any data field and initialize the values def customizeComponents(self): #self.Exclude_File_Sources_CB.setSelected(self.local_settings.getExclude_File_Sources()) #self.Run_Plaso_CB.setSelected(self.local_settings.getRun_Plaso()) #self.Import_Plaso_CB.setSelected(self.local_settings.getImport_Plaso()) self.check_Database_entries() #pass # Return the settings used def getSettings(self): return self.local_settings
class VolatilitySettingsWithUISettingsPanel(IngestModuleIngestJobSettingsPanel): # Note, we can't use a self.settings instance variable. # Rather, self.local_settings is used. # https://wiki.python.org/jython/UserGuide#javabean-properties # Jython Introspector generates a property - 'settings' on the basis # of getSettings() defined in this class. Since only getter function # is present, it creates a read-only 'settings' property. This auto- # generated read-only property overshadows the instance-variable - # 'settings' # We get passed in a previous version of the settings so that we can # prepopulate the UI # TODO: Update this for your UI _logger = Logger.getLogger(VolatilityIngestModuleFactory.moduleName) def log(self, level, msg): self._logger.logp(level, self.__class__.__name__, inspect.stack()[1][3], msg) def __init__(self, settings): self.local_settings = settings self.initComponents() self.customizeComponents() # Check the checkboxs to see what actions need to be taken def checkBoxEvent(self, event): if self.Exclude_File_Sources_CB.isSelected(): self.local_settings.setSetting('Exclude_File_Sources', 'true') else: self.local_settings.setSetting('Exclude_File_Sources', 'false') def get_plugins(self): head, tail = os.path.split(os.path.abspath(__file__)) settings_db = os.path.join(head, "GUI_Settings.db3") try: Class.forName("org.sqlite.JDBC").newInstance() dbConn = DriverManager.getConnection("jdbc:sqlite:%s" % settings_db) self.Error_Message.setText("Database opened") except SQLException as e: self.Error_Message.setText("Error Opening Settings DB!") try: stmt = dbConn.createStatement() SQL_Statement = "select plugin_name from plugins where volatility_version = '" + self.Version_CB.getSelectedItem() + "';" resultSet = stmt.executeQuery(SQL_Statement) plugin_list = [] while resultSet.next(): plugin_list.append(resultSet.getString("plugin_name")) stmt.close() dbConn.close() return plugin_list except SQLException as e: self.Error_Message.setText("Error Reading plugins") stmt.close() dbConn.close() return "Error" def get_profiles(self): head, tail = os.path.split(os.path.abspath(__file__)) settings_db = os.path.join(head, "GUI_Settings.db3") try: Class.forName("org.sqlite.JDBC").newInstance() dbConn = DriverManager.getConnection("jdbc:sqlite:%s" % settings_db) self.Error_Message.setText("Database opened") except SQLException as e: self.Error_Message.setText("Error Opening Settings DB!") try: stmt = dbConn.createStatement() SQL_Statement = "select profile_name from profiles where volatility_version = '" + self.Version_CB.getSelectedItem() + "';" resultSet = stmt.executeQuery(SQL_Statement) profile_list = [] while resultSet.next(): profile_list.append(resultSet.getString("profile_name")) stmt.close() dbConn.close() return profile_list except SQLException as e: self.Error_Message.setText("Error Reading plugins") stmt.close() dbConn.close() return "Error" # When button to find file is clicked then open dialog to find the file and return it. def Find_Dir(self, e): chooseFile = JFileChooser() filter = FileNameExtensionFilter("All", ["*.*"]) chooseFile.addChoosableFileFilter(filter) #chooseFile.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY) ret = chooseFile.showDialog(self.panel0, "Find Volatility Directory") if ret == JFileChooser.APPROVE_OPTION: file = chooseFile.getSelectedFile() Canonical_file = file.getCanonicalPath() #text = self.readPath(file) self.local_settings.setSetting('Volatility_Directory', Canonical_file) self.Program_Executable_TF.setText(Canonical_file) def keyPressed(self, event): self.local_settings.setSetting('AdditionalParms', self.Additional_Parms_TF.getText()) #self.Error_Message.setText(self.Additional_Parms_TF.getText()) def onchange_version(self, event): self.local_settings.setSetting('Version', event.item) plugin_list = self.get_plugins() profile_list = self.get_profiles() self.Profile_CB.removeAllItems() self.Plugin_LB.clearSelection() self.Plugin_LB.setListData(plugin_list) for profile in profile_list: self.Profile_CB.addItem(profile) #self.Profile_CB.addItems(profile) self.panel0.repaint() def onchange_plugins_lb(self, event): self.local_settings.setSetting('PluginListBox' , '') list_selected = self.Plugin_LB.getSelectedValuesList() self.local_settings.setSetting('PluginListBox', str(list_selected)) def onchange_profile_cb(self, event): self.local_settings.setSetting('Profile', event.item) # Create the initial data fields/layout in the UI def initComponents(self): self.panel0 = JPanel() self.rbgPanel0 = ButtonGroup() self.gbPanel0 = GridBagLayout() self.gbcPanel0 = GridBagConstraints() self.panel0.setLayout( self.gbPanel0 ) self.Error_Message = JLabel( "") self.Error_Message.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 31 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints( self.Error_Message, self.gbcPanel0 ) self.panel0.add( self.Error_Message ) self.Label_1 = JLabel("Volatility Executable Directory") self.Label_1.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 1 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints( self.Label_1, self.gbcPanel0 ) self.panel0.add( self.Label_1 ) self.Program_Executable_TF = JTextField(10) self.Program_Executable_TF.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 3 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints( self.Program_Executable_TF, self.gbcPanel0 ) self.panel0.add( self.Program_Executable_TF ) self.Find_Program_Exec_BTN = JButton( "Find Dir", actionPerformed=self.Find_Dir) self.Find_Program_Exec_BTN.setEnabled(True) self.rbgPanel0.add( self.Find_Program_Exec_BTN ) self.gbcPanel0.gridx = 6 self.gbcPanel0.gridy = 3 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints( self.Find_Program_Exec_BTN, self.gbcPanel0 ) self.panel0.add( self.Find_Program_Exec_BTN ) self.Blank_1 = JLabel( " ") self.Blank_1.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 5 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints( self.Blank_1, self.gbcPanel0 ) self.panel0.add( self.Blank_1 ) self.Version_Label_1 = JLabel( "Version:") self.Blank_1.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 11 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints( self.Version_Label_1, self.gbcPanel0 ) self.panel0.add( self.Version_Label_1 ) self.Version_List = ("2.5", "2.6") self.Version_CB = JComboBox( self.Version_List) self.Version_CB.itemStateChanged = self.onchange_version self.gbcPanel0.gridx = 6 self.gbcPanel0.gridy = 11 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints( self.Version_CB, self.gbcPanel0 ) self.panel0.add( self.Version_CB ) self.Blank_3 = JLabel( " ") self.Blank_3.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 13 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints( self.Blank_3, self.gbcPanel0 ) self.panel0.add( self.Blank_3 ) self.Plugin_Label_1 = JLabel( "Plugins:") self.Blank_1.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 15 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints( self.Plugin_Label_1, self.gbcPanel0 ) self.panel0.add( self.Plugin_Label_1 ) self.Plugin_list = self.get_plugins() self.Plugin_LB = JList( self.Plugin_list, valueChanged=self.onchange_plugins_lb) self.Plugin_LB.setVisibleRowCount( 3 ) self.scpPlugin_LB = JScrollPane( self.Plugin_LB ) self.gbcPanel0.gridx = 6 self.gbcPanel0.gridy = 15 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 1 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints( self.scpPlugin_LB, self.gbcPanel0 ) self.panel0.add( self.scpPlugin_LB ) self.Blank_4 = JLabel( " ") self.Blank_4.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 17 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints( self.Blank_4, self.gbcPanel0 ) self.panel0.add( self.Blank_4 ) self.Profile_Label_1 = JLabel( "Profile:") self.Blank_1.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 19 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints( self.Profile_Label_1, self.gbcPanel0 ) self.panel0.add( self.Profile_Label_1 ) self.Profile_List = self.get_profiles() self.Profile_CB = JComboBox( self.Profile_List) self.Profile_CB.itemStateChanged = self.onchange_profile_cb self.gbcPanel0.gridx = 6 self.gbcPanel0.gridy = 19 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 1 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints( self.Profile_CB, self.gbcPanel0 ) self.panel0.add( self.Profile_CB ) self.Blank_5 = JLabel( " ") self.Blank_5.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 21 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints( self.Blank_5, self.gbcPanel0 ) self.panel0.add( self.Blank_5 ) self.Label_2 = JLabel("Additional Parameters To Run With:") self.Label_2.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 23 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints( self.Label_2, self.gbcPanel0 ) self.panel0.add( self.Label_2 ) self.Additional_Parms_TF = JTextField(10,focusLost=self.keyPressed) #self.Additional_Parms_TF.getDocument().addDocumentListener() self.Additional_Parms_TF.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 25 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints( self.Additional_Parms_TF, self.gbcPanel0 ) self.panel0.add( self.Additional_Parms_TF ) self.Blank_6 = JLabel( " ") self.Blank_6.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 27 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints( self.Blank_6, self.gbcPanel0 ) self.panel0.add( self.Blank_6 ) self.Label_3 = JLabel( "Message:") self.Label_3.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 29 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints( self.Label_3, self.gbcPanel0 ) self.panel0.add( self.Label_3 ) self.add(self.panel0) # Custom load any data field and initialize the values def customizeComponents(self): self.Program_Executable_TF.setText(self.local_settings.getSetting('Volatility_Directory')) #pass # Return the settings used def getSettings(self): return self.local_settings
class VolatilitySettingsWithUISettingsPanel(IngestModuleIngestJobSettingsPanel): # Note, we can't use a self.settings instance variable. # Rather, self.local_settings is used. # https://wiki.python.org/jython/UserGuide#javabean-properties # Jython Introspector generates a property - 'settings' on the basis # of getSettings() defined in this class. Since only getter function # is present, it creates a read-only 'settings' property. This auto- # generated read-only property overshadows the instance-variable - # 'settings' # We get passed in a previous version of the settings so that we can # prepopulate the UI # TODO: Update this for your UI def __init__(self, settings): self.local_settings = settings self.initComponents() self.customizeComponents() # When button to find file is clicked then open dialog to find the file and return it. def Find_Dir(self, e): chooseFile = JFileChooser() filter = FileNameExtensionFilter("All", ["*.*"]) chooseFile.addChoosableFileFilter(filter) #chooseFile.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY) ret = chooseFile.showDialog(self.panel0, "Find Volatility Directory") if ret == JFileChooser.APPROVE_OPTION: file = chooseFile.getSelectedFile() Canonical_file = file.getCanonicalPath() #text = self.readPath(file) self.local_settings.setSetting('Volatility_Directory', Canonical_file) self.Program_Executable_TF.setText(Canonical_file) def keyPressed(self, event): self.local_settings.setProcessIDs(self.Process_Ids_To_Dump_TF.getText()) #self.Error_Message.setText(self.Process_Ids_To_Dump_TF.getText()) def checkBoxEvent(self, event): if self.Check_Box.isSelected(): self.local_settings.setSetting('Flag', 'true') else: self.local_settings.setSetting('Flag', 'False') # Create the initial data fields/layout in the UI def initComponents(self): self.panel0 = JPanel() self.rbgPanel0 = ButtonGroup() self.gbPanel0 = GridBagLayout() self.gbcPanel0 = GridBagConstraints() self.panel0.setLayout( self.gbPanel0 ) self.Error_Message = JLabel( "") self.Error_Message.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 15 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints( self.Error_Message, self.gbcPanel0 ) self.panel0.add( self.Error_Message ) self.Label_1 = JLabel("Volatility Executable Directory") self.Label_1.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 1 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints( self.Label_1, self.gbcPanel0 ) self.panel0.add( self.Label_1 ) self.Program_Executable_TF = JTextField(10) self.Program_Executable_TF.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 3 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints( self.Program_Executable_TF, self.gbcPanel0 ) self.panel0.add( self.Program_Executable_TF ) self.Find_Program_Exec_BTN = JButton( "Find Dir", actionPerformed=self.Find_Dir) self.Find_Program_Exec_BTN.setEnabled(True) self.rbgPanel0.add( self.Find_Program_Exec_BTN ) self.gbcPanel0.gridx = 6 self.gbcPanel0.gridy = 3 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints( self.Find_Program_Exec_BTN, self.gbcPanel0 ) self.panel0.add( self.Find_Program_Exec_BTN ) self.Blank_1 = JLabel( " ") self.Blank_1.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 5 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints( self.Blank_1, self.gbcPanel0 ) self.panel0.add( self.Blank_1 ) self.Blank_3 = JLabel( " ") self.Blank_3.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 7 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints( self.Blank_3, self.gbcPanel0 ) self.panel0.add( self.Blank_3 ) self.Check_Box = JCheckBox("Extract and Create Memory Image from Hiberfile", actionPerformed=self.checkBoxEvent) self.Blank_1.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 9 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints( self.Check_Box, self.gbcPanel0 ) self.panel0.add( self.Check_Box ) self.Blank_4 = JLabel( " ") self.Blank_4.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 11 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints( self.Blank_4, self.gbcPanel0 ) self.panel0.add( self.Blank_4 ) self.Label_3 = JLabel( "Message:") self.Label_3.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 13 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints( self.Label_3, self.gbcPanel0 ) self.panel0.add( self.Label_3 ) self.add(self.panel0) # Custom load any data field and initialize the values def customizeComponents(self): self.Check_Box.setSelected(self.local_settings.getSetting('Flag') == 'true') self.Program_Executable_TF.setText(self.local_settings.getSetting('Volatility_Directory')) #pass # Return the settings used def getSettings(self): return self.local_settings
def generateUI(file_list): # window frame = swing.JFrame("Marcksl1 prescreen tool") frame.setDefaultCloseOperation(swing.JFrame.DISPOSE_ON_CLOSE) frame.setPreferredSize(Dimension(700, 500)) frame.setSize(Dimension(700, 500)) frame.setLocationByPlatform(True) layout = GridBagLayout() frame.setLayout(layout) # image list lst_constraints = quickSetGridBagConstraints(GridBagConstraints(), 0, 0, 0.5, 0.33) lst_constraints.fill = GridBagConstraints.BOTH lst = swing.JList(file_list) lst_scrollpane = swing.JScrollPane(lst) layout.setConstraints(lst_scrollpane, lst_constraints) frame.add(lst_scrollpane) # radio buttons radio_panel_constraints = quickSetGridBagConstraints( GridBagConstraints(), 1, 0, 0.25, 0.33) radio_panel_constraints.fill = GridBagConstraints.HORIZONTAL isvButton = swing.JRadioButton("ISV", True) dlavButton = swing.JRadioButton("DLAV") radio_group = swing.ButtonGroup() radio_group.add(isvButton) radio_group.add(dlavButton) radio_panel = swing.JPanel() radio_panel_layout = GridLayout(2, 1) radio_panel.setLayout(radio_panel_layout) radio_panel.add(isvButton) radio_panel.add(dlavButton) radio_panel.setBorder( swing.BorderFactory.createTitledBorder( swing.BorderFactory.createEtchedBorder(), "Vessel type")) layout.setConstraints(radio_panel, radio_panel_constraints) frame.add(radio_panel) # checkboxes chk_constraints = quickSetGridBagConstraints(GridBagConstraints(), 2, 0, 0.25, 0.33) chk_constraints.fill = GridBagConstraints.HORIZONTAL chkbox = swing.JCheckBox("Is lumenised?", True) layout.setConstraints(chkbox, chk_constraints) frame.add(chkbox) # add ROI button roi_but_constraints = quickSetGridBagConstraints(GridBagConstraints(), 0, 1, 1, 0.16) roi_but_constraints.gridwidth = 3 roi_but_constraints.fill = GridBagConstraints.BOTH roi_but = swing.JButton("Add current ROI") layout.setConstraints(roi_but, roi_but_constraints) frame.add(roi_but) # metadata display table mdtbl_constraints = quickSetGridBagConstraints(GridBagConstraints(), 0, 2, 1, 0.33) mdtbl_constraints.gridwidth = 3 mdtbl_constraints.fill = GridBagConstraints.BOTH mdtbl_colnames = [ 'Experiment', 'Embryo', 'Imaged region index', 'ROI index', 'Vessel type', 'Lumenised?' ] mdtbl_model = swing.table.DefaultTableModel(mdtbl_colnames, 10) mdtbl = swing.JTable() mdtbl_scrollpane = swing.JScrollPane(mdtbl) layout.setConstraints(mdtbl_scrollpane, mdtbl_constraints) frame.add(mdtbl_scrollpane) # buttons del_but_constraints = quickSetGridBagConstraints(GridBagConstraints(), 1, 3, 0.25, 0.16) del_but_constraints.fill = GridBagConstraints.BOTH del_but = swing.JButton("Delete selected ROI") layout.setConstraints(del_but, del_but_constraints) frame.add(del_but) save_but_constraints = quickSetGridBagConstraints(GridBagConstraints(), 2, 3, 0.25, 0.16) save_but_constraints.fill = GridBagConstraints.BOTH save_but = swing.JButton("Save...") layout.setConstraints(save_but, save_but_constraints) frame.add(save_but) # show window frame.setVisible(True) frame.pack()
class SPAIModelReportModule(GeneralReportModuleAdapter): def __init__(self): self.tags_selected = [] self.moduleName = "SPAI's HTML Model for Autopsy Report" self._logger = Logger.getLogger(self.moduleName) def log(self, level, msg): self._logger.logp(level, self.__class__.__name__, inspect.stack()[1][3], msg) def getName(self): return self.moduleName def getDescription(self): return "SPAI's HTML Model for Autopsy Report" def getRelativeFilePath(self): return "index.html" def getConfigurationPanel(self): self.artifact_list = [] self.panel0 = JPanel() self.rbgPanel0 = ButtonGroup() self.gbPanel0 = GridBagLayout() self.gbcPanel0 = GridBagConstraints() self.panel0.setLayout(self.gbPanel0) self.Label_0 = JLabel("Number of Object to Display per page") self.gbcPanel0.gridx = 1 self.gbcPanel0.gridy = 1 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.Label_0, self.gbcPanel0) self.panel0.add(self.Label_0) self.Num_Of_Objs_Per_Page_TF = JTextField(5) self.Num_Of_Objs_Per_Page_TF.setEnabled(True) self.Num_Of_Objs_Per_Page_TF.setText("10") self.gbcPanel0.gridx = 3 self.gbcPanel0.gridy = 1 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.Num_Of_Objs_Per_Page_TF, self.gbcPanel0) self.panel0.add(self.Num_Of_Objs_Per_Page_TF) self.Blank_0 = JLabel(" ") self.Blank_0.setEnabled(True) self.gbcPanel0.gridx = 1 self.gbcPanel0.gridy = 3 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.Blank_0, self.gbcPanel0) self.panel0.add(self.Blank_0) self.Label_1 = JLabel("Title To Appear on Case Info") self.gbcPanel0.gridx = 1 self.gbcPanel0.gridy = 5 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.Label_1, self.gbcPanel0) self.panel0.add(self.Label_1) self.Title_Case_TF = JTextField(30) self.Title_Case_TF.setEnabled(True) self.Title_Case_TF.setText("Report of media analysis") self.gbcPanel0.gridx = 3 self.gbcPanel0.gridy = 5 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.Title_Case_TF, self.gbcPanel0) self.panel0.add(self.Title_Case_TF) self.Label_2 = JLabel("Report Number To Appear on Case Info") self.gbcPanel0.gridx = 1 self.gbcPanel0.gridy = 7 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.Label_2, self.gbcPanel0) self.panel0.add(self.Label_2) self.Report_Number_TF = JTextField(30) self.Report_Number_TF.setEnabled(True) self.Report_Number_TF.setText(Case.getCurrentCase().getNumber()) self.gbcPanel0.gridx = 3 self.gbcPanel0.gridy = 7 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.Report_Number_TF, self.gbcPanel0) self.panel0.add(self.Report_Number_TF) self.Label_3 = JLabel("Examiner(s) To Appear on Case Info") self.gbcPanel0.gridx = 1 self.gbcPanel0.gridy = 9 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.Label_3, self.gbcPanel0) self.panel0.add(self.Label_3) self.Examiners_TF = JTextField(30) self.Examiners_TF.setEnabled(True) self.Examiners_TF.setText(Case.getCurrentCase().getExaminer()) self.gbcPanel0.gridx = 3 self.gbcPanel0.gridy = 9 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.Examiners_TF, self.gbcPanel0) self.panel0.add(self.Examiners_TF) self.Label_4 = JLabel("Description To Appear on Case Info") self.gbcPanel0.gridx = 1 self.gbcPanel0.gridy = 11 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.Label_4, self.gbcPanel0) self.panel0.add(self.Label_4) self.Description_TF = JTextField(30) self.Description_TF.setEnabled(True) #self.Description_TF.setText(Case.getCurrentCase().getNumber()) self.gbcPanel0.gridx = 3 self.gbcPanel0.gridy = 11 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.Description_TF, self.gbcPanel0) self.panel0.add(self.Description_TF) self.Blank_4 = JLabel(" ") self.Blank_4.setEnabled(True) self.gbcPanel0.gridx = 1 self.gbcPanel0.gridy = 19 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.Blank_4, self.gbcPanel0) self.panel0.add(self.Blank_4) self.Label_5 = JLabel("Tags to Select for Report:") self.Label_5.setEnabled(True) self.gbcPanel0.gridx = 1 self.gbcPanel0.gridy = 21 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.Label_5, self.gbcPanel0) self.panel0.add(self.Label_5) self.List_Box_LB = JList(self.find_tags(), valueChanged=self.onchange_lb) self.List_Box_LB.setVisibleRowCount(3) self.scpList_Box_LB = JScrollPane(self.List_Box_LB) self.gbcPanel0.gridx = 1 self.gbcPanel0.gridy = 23 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 1 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.scpList_Box_LB, self.gbcPanel0) self.panel0.add(self.scpList_Box_LB) self.Blank_5 = JLabel(" ") self.Blank_5.setEnabled(True) self.gbcPanel0.gridx = 1 self.gbcPanel0.gridy = 25 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.Blank_5, self.gbcPanel0) self.panel0.add(self.Blank_5) #self.add(self.panel0) return self.panel0 def generateReport(self, baseReportDir, progressBar): progressBar.setIndeterminate(False) progressBar.start() # Set status bar for number of tags progressBar.setMaximumProgress(2) # Get and create the report directories head, tail = os.path.split(os.path.abspath(__file__)) copy_resources_dir = os.path.join(head, "res") try: report_dir = os.path.join(baseReportDir, "Report") os.mkdir(report_dir) except: self.log(Level.INFO, "Could not create base report dir") try: report_files_dir = os.path.join(report_dir, "report_files") os.mkdir(report_files_dir) except: self.log(Level.INFO, "Could not create report_files directory") try: report_resources_dir = os.path.join(report_dir, "res") os.mkdir(report_resources_dir) except: self.log(Level.INFO, "Could not create report_res directory") # Copy the Resource directory to the report directory try: head, tail = os.path.split(os.path.abspath(__file__)) copy_resources_dir = os.path.join(head, "res") copy_tree(copy_resources_dir, report_resources_dir) except: self.log(Level.INFO, "Could Not copy resources directory") # Copy the base files needed for the report try: copy_base_dir = os.path.join(head, "base_folder") copy_tree(copy_base_dir, report_dir) except: self.log( Level.INFO, "Could not write files from base_folder to base_report_Folder") # Create the index page self.create_index_file(report_dir) # Create The information page self.create_info_page(report_dir) # Create the Menu page. self.create_menu_file(report_dir) # Get all Content tags = Case.getCurrentCase().getServices().getTagsManager( ).getAllContentTags() tag_number = 1 for sel_tag in self.tags_selected: tags_to_process = [] for tag in tags: if tag.getName().getDisplayName() == sel_tag: tags_to_process.append(tag) self.log( Level.INFO, "this is a content tags ==> " + tag.getName().getDisplayName() + " <==") progressBar.updateStatusLabel("Process tag " + sel_tag) self.process_thru_tags(report_dir, tags_to_process, tag_number, sel_tag, report_files_dir) tag_number = tag_number + 1 # Increment since we are done with step #1 progressBar.increment() fileName = os.path.join(report_dir, "index.html") # Add the report to the Case, so it is shown in the tree Case.getCurrentCase().addReport(fileName, self.moduleName, "SPAI's HTML Model Report") progressBar.increment() # Call this with ERROR if report was not generated progressBar.complete(ReportStatus.COMPLETE) def process_thru_tags(self, report_dir, tags_to_process, book_mark_number, tag_name, report_files_dir): page_number = 1 current_page_number = 1 num_of_tags_per_page = int(str(self.Num_Of_Objs_Per_Page_TF.getText())) total_pages = int(len(tags_to_process)) // num_of_tags_per_page if (int(len(tags_to_process)) % num_of_tags_per_page) <> 0: total_pages = total_pages + 1 page_file_name = os.path.join( report_dir, "Bookmark" + str(book_mark_number) + "Pagina" + str(page_number) + ".html") page_file = open(page_file_name, 'w') self.create_page_header(page_file, len(tags_to_process), tag_name, total_pages) tag_number = 1 total_tag_number = 1 for tag in tags_to_process: if tag_number > num_of_tags_per_page: tag_number = 1 page_number = page_number + 1 page_file_name = os.path.join( report_dir, "Bookmark" + str(book_mark_number) + "Pagina" + str(page_number) + ".html") self.create_page_footer( page_file, total_pages, current_page_number, "Bookmark" + str(book_mark_number) + "Pagina") page_file.close() #page_file_name = os.path.join(report_dir, "Bookmark" + str(tag_number) + "Pagina1.html") page_file = open(page_file_name, 'w') self.create_page_header(page_file, len(tags_to_process), tag_name, current_page_number) current_page_number = current_page_number + 1 self.create_page_data(page_file, tag, total_tag_number, report_files_dir) tag_number = tag_number + 1 total_tag_number = total_tag_number + 1 self.create_page_footer(page_file, total_pages, current_page_number, "Bookmark" + str(book_mark_number) + "Pagina") page_file.close() def create_page_footer(self, page_file, total_pages, current_page, page_file_name): page_file.write('<!-- Rodape -->') page_file.write(' <table width="100%">') page_file.write(' <tr>') page_file.write(' <td><small> ' + datetime.datetime.today().strftime('%d/%m/%Y') + ' </small></td>') if current_page < total_pages: if current_page < total_pages: if current_page == 1: page_file.write(' <td>Page ' + str(current_page) + ' of ' + str(total_pages) + ' </td>') page_file.write(' <td><a href="' + page_file_name + str(current_page + 1) + ".html" + '">next page >></a></td>') else: page_file.write(' <td><a href="' + page_file_name + str(current_page - 1) + ".html" + '"><<Previous page</a></td>') page_file.write(' <td>Page ' + str(current_page) + ' of ' + str(total_pages) + ' </td>') page_file.write(' <td><a href="' + page_file_name + str(current_page + 1) + ".html" + '"> next page >></a></td>') elif current_page == total_pages: page_file.write(' <td><a href="' + page_file_name + str(current_page - 1) + ".html" + '"><<Previous page</a></td>') page_file.write(' <td>Page ' + str(current_page) + ' of ' + str(total_pages) + ' </td>') else: page_file.write(' <td>Page ' + str(current_page) + ' of ' + str(total_pages) + ' </td>') else: if current_page == 1: page_file.write(' <td>Page 1 of 1 </td>') else: page_file.write(' <td><a href="' + page_file_name + str(current_page - 1) + ".html" + '"><<Previous page</a></td>') page_file.write(' <td>Page ' + str(current_page) + ' of ' + str(total_pages) + ' </td>') page_file.write(' </tr>') page_file.write(' </table>') page_file.write(' ') page_file.write(' <p><img border="0" src="res/Footer.gif"/></p>') page_file.write('</body>') page_file.write('</html>') page_file.write('<!-- Rodape -->') def create_page_data(self, page_file, tag, tag_number, report_files_dir): try: tag_content = tag.getContent() lclDbPath = os.path.join( report_files_dir, str(tag_content.getId()) + "-" + tag_content.getName()) ContentUtils.writeToFile(tag_content, File(lclDbPath)) page_file.write(' <div class="clrBkgrnd bkmkSeparator bkmkValue">') page_file.write( ' <span style="FONT-WEIGHT:bold">Metadata: </span>') page_file.write(' </div>') page_file.write(' ') page_file.write(' <div class="row">') page_file.write( ' <span class="bkmkColLeft bkmkValue labelBorderless clrBkgrnd" width="100%" border="1">Index</span>' ) page_file.write(' <span class="bkmkColRight bkmkValue"> ' + str(tag_number) + ' </span>') page_file.write(' </div>') page_file.write(' ') page_file.write(' <div class="row">') page_file.write( ' <span class="bkmkColLeft bkmkValue labelBorderless clrBkgrnd" width="100%" border="1">Name</span>' ) page_file.write(' <span class="bkmkColRight bkmkValue"> ' + tag_content.getName() + ' </span>') page_file.write(' </div>') page_file.write(' ') page_file.write(' <div class="row">') page_file.write( ' <span class="bkmkColLeft bkmkValue labelBorderless clrBkgrnd" width="100%" border="1">Path</span>' ) page_file.write(' <span class="bkmkColRight bkmkValue"> ' + tag_content.getUniquePath() + ' </span>') page_file.write(' </div>') page_file.write(' ') page_file.write(' <div class="row">') page_file.write( ' <span class="bkmkColLeft bkmkValue labelBorderless clrBkgrnd" width="100%" border="1">Logical size</span>' ) page_file.write(' <span class="bkmkColRight bkmkValue"> ' + str(tag_content.getSize()) + ' </span>') page_file.write(' </div>') page_file.write(' ') page_file.write(' <div class="row">') page_file.write( ' <span class="bkmkColLeft bkmkValue labelBorderless clrBkgrnd" width="100%" border="1">Created</span>' ) page_file.write(' <span class="bkmkColRight bkmkValue"> ' + tag_content.getCrtimeAsDate() + ' </span>') page_file.write(' </div>') page_file.write(' ') page_file.write(' <div class="row"> ') page_file.write( ' <span class="bkmkColLeft bkmkValue labelBorderless clrBkgrnd" width="100%" border="1">Modified</span>' ) page_file.write(' <span class="bkmkColRight bkmkValue"> ' + tag_content.getMtimeAsDate() + ' </span>') page_file.write(' </div>') page_file.write(' ') page_file.write(' <div class="row">') page_file.write( ' <span class="bkmkColLeft bkmkValue labelBorderless clrBkgrnd" width="100%" border="1">Accessed</span>' ) page_file.write(' <span class="bkmkColRight bkmkValue"> ' + tag_content.getAtimeAsDate() + ' </span>') page_file.write(' </div>') page_file.write(' ') page_file.write(' <div class="row">') page_file.write( ' <span class="bkmkColLeft bkmkValue labelBorderless clrBkgrnd" width="100%" border="1">Deleted</span>' ) page_file.write(' <span class="bkmkColRight bkmkValue"> ') if tag_content.exists(): page_file.write('No' + ' </span>') else: page_file.write('Yes' + '</span>') page_file.write(' </div>') page_file.write(' ') page_file.write(' <div class="row">') page_file.write( ' <span class="bkmkColLeft bkmkValue labelBorderless clrBkgrnd" width="100%" border="1">Exported as</span>' ) page_file.write( ' <span class="bkmkColRight bkmkValue">report_files\ ' + tag_content.getName() + ' </span>') page_file.write(' </div>') page_file.write(' ') page_file.write(' <div class="row">') page_file.write( ' <span class="bkmkColLeft bkmkValue labelBorderless clrBkgrnd" width="100%" border="1">Preview</span>' ) self.log(Level.INFO, 'File Extension ==> ' + tag_content.getNameExtension()) if tag_content.getNameExtension() in ['jpg', 'png']: page_file.write('<table width="100%">') page_file.write(' <tr>') page_file.write(' <td align="center" class="">') page_file.write(' <a href="report_files\\' + str(tag_content.getId()) + '-' + tag_content.getName() + '"/>') page_file.write(' <img src="report_files\\' + str(tag_content.getId()) + '-' + tag_content.getName() + '" alt="report_files\\' + tag_content.getName() + '" width="96" height="96"/>') page_file.write(' </td>') page_file.write(' </tr>') page_file.write('</table>') else: page_file.write(' <span class="bkmkColRight bkmkValue">') page_file.write(' <a href="report_files\\' + str(tag_content.getId()) + '-' + tag_content.getName() + '">' + tag_content.getName() + '</a>') page_file.write(' </span>') page_file.write(' </div>') except: self.log( Level.INFO, "File Content Not written or created ==> " + str(tag_content.getId()) + '-' + tag_content.getName()) def create_page_header(self, page_file, number_of_tags, tag_name, page_number): page_file.write('<!-- Cabecalho -->') page_file.write('<?xml version="1.0" encoding="UTF-8"?>') page_file.write('<html xmlns="http://www.w3.org/1999/xhtml">') page_file.write(' ') page_file.write('<head>') page_file.write( ' <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>' ) page_file.write( ' <link rel="stylesheet" type="text/css" href="res/common.css"/>') page_file.write( ' <link rel="stylesheet" type="text/css" href="res/Bookmarks.css"/>' ) page_file.write(' <title>Tags</title>') page_file.write('</head>') page_file.write(' ') page_file.write(' ') page_file.write('<body>') page_file.write(' <table>') page_file.write( ' <tr><td height="20" valign="top"><img border="0" src="res/Header.gif"/></td></tr>' ) page_file.write(' </table>') page_file.write(' ') page_file.write(' <table width="100%">') page_file.write(' <tr>') # page_file.write(' <td><small> ' + datetime.datetime.today().strftime('%d/%m-%Y') + ' </small></td>') # Danilo C M Marques - 27/10/2017 page_file.write(' <td><small> ' + datetime.datetime.today().strftime('%d/%m/%Y') + ' </small></td>') # Danilo C M Marques - 27/10/2017 page_file.write(' <td>Page 1 of ' + str(page_number) + ' </td>') page_file.write(' </tr>') page_file.write(' </table>') page_file.write(' ') page_file.write(' <table width="100%">') page_file.write( ' <tr><th class="columnHead" colspan="1">Tag: <span style="font-size:1.25em">' + tag_name.encode('utf-8') + '</span></th></tr>') page_file.write( ' <tr><td class="clrBkgrnd"><span style="font-weight:bold">Number of files: </span>' + str(number_of_tags) + ' </td></tr>') page_file.write(' </table>') page_file.write(' ') page_file.write(' </br></br>') page_file.write(' ') page_file.write( ' <div class="bkmkLblFiles" width="100%" border="1">Files</div>') page_file.write(' <a name="bk_obj13550"> </a>') page_file.write('<!-- Cabecalho -->') page_file.write(' ') page_file.write(' ') page_file.write(' ') page_file.write(' ') def create_index_file(self, report_dir): index_file_name = os.path.join(report_dir, "index.html") index_file = open(index_file_name, 'w') index_file.write('<?xml version="1.0" encoding="UTF-8"?>') index_file.write('<html xmlns="http://www.w3.org/1999/xhtml">') index_file.write(" ") index_file.write("<head>") index_file.write( ' <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>' ) # index_file.write(" <title> " + 'Instituto de Criminalística Carlos Éboli - DGPTC/PCERJ' + "</title>") # Danilo C M Marques - 27/10/2017 index_file.write(" <title> " + 'My Institution' + "</title>") # Danilo C M Marques - 27/10/2017 index_file.write("</head>") index_file.write(" ") index_file.write('<frameset cols="290,10%">') index_file.write( ' <frame src="Menu.html" name="navigate" frameborder="0"/>') index_file.write( ' <frame src="Informacoes.html" name="contents" frameborder="1"/>') index_file.write(" <noframes/>") index_file.write("</frameset>") index_file.write(" ") index_file.write("</html>") index_file.close() def create_info_page(self, report_dir): # get case specific information to put in the information.html file skCase = Case.getCurrentCase() # Open and write information.html file info_file_name = os.path.join(report_dir, "Informacoes.html") info_file = open(info_file_name, 'w') info_file.write('<?xml version="1.0" encoding="UTF-8"?>') info_file.write('<html xmlns="http://www.w3.org/1999/xhtml">') info_file.write(" ") info_file.write("<head>") info_file.write( ' <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>' ) info_file.write( ' <link rel="stylesheet" type="text/css" href="res/common.css"/>') info_file.write(" <title>Case Information</title>") info_file.write("</head>") info_file.write(" ") info_file.write(" ") info_file.write(" ") info_file.write(" ") info_file.write("<body>") info_file.write(" ") info_file.write( ' <div class="bkmkColHead" width="100%" border="1">Case information</div>' ) info_file.write(' <table width="100%">') info_file.write(" <tr>") info_file.write( ' <td style="width:20%" class="bkmkValue labelBorderless clrBkgrnd">Title</td>' ) info_file.write(" <td> " + self.Title_Case_TF.getText() + " </td>") info_file.write(" </tr>") info_file.write(" ") info_file.write(" <tr>") info_file.write( ' <td style="width:20%" class="bkmkValue labelBorderless clrBkgrnd">Report number</td>' ) info_file.write(" <td> " + self.Report_Number_TF.getText() + "</td>") info_file.write(" </tr>") info_file.write(" ") info_file.write(" <tr>") info_file.write( ' <td style="width:20%" class="bkmkValue labelBorderless clrBkgrnd">Examiner(s)</td>' ) info_file.write(" <td> " + self.Examiners_TF.getText() + " </td>") info_file.write(" </tr>") info_file.write(" ") info_file.write(" <tr>") info_file.write( ' <td style="width:20%" class="bkmkValue labelBorderless clrBkgrnd">Description</td>' ) info_file.write(" <td> " + self.Description_TF.getText() + " </td>") info_file.write(" </tr>") info_file.write(" ") info_file.write(" <tr>") info_file.write( ' <td style="width:20%" class="bkmkValue labelBorderless clrBkgrnd">ATTENTION</td>' ) info_file.write( " <td>It is recommended to configure the browser to offline mode, in order to avoid that HTML temporary files be visualized in external servers</td>" ) info_file.write(" </tr>") info_file.write(" </table>") info_file.write(' <p><img border="0" src="res/Footer.gif"/></p>') info_file.write(" ") info_file.write("</body>") info_file.write("</html>") # Close Info File info_file.close() def create_menu_file(self, report_dir): # get case specific information to put in the information.html file skCase = Case.getCurrentCase() # Open and write information.html file menu_file_name = os.path.join(report_dir, "menu.html") menu_file = open(menu_file_name, 'w') menu_file.write('<?xml version="1.0" encoding="UTF-8"?>') menu_file.write('<html xmlns="http://www.w3.org/1999/xhtml">') menu_file.write(' ') menu_file.write('<head>') menu_file.write( ' <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>' ) menu_file.write( ' <link rel="stylesheet" type="text/css" href="res/navigation.css"/>' ) menu_file.write( ' <link rel="stylesheet" type="text/css" href="res/common.css"/>') menu_file.write(' <title>Summary</title>') menu_file.write('</head>') menu_file.write(' ') menu_file.write('<body background="res/Background.gif">') menu_file.write(' ') menu_file.write( '<!-- <img style="margin: 0px 70px" border="0" src="res/brasao.gif"/>-->' ) menu_file.write( ' <img style="margin: 0px 70px" border="0" src="res/icon.ico"/>') menu_file.write(' <p> </p>') menu_file.write(' <div>') menu_file.write(' <h3><font color="white">Summary of Analysis<h3>') menu_file.write( ' <a class="sectionLinks" target="contents" href="Informacoes.html">' ) menu_file.write( ' <span style="margin-left:15px"> Case Information </span>') menu_file.write(' </a>') menu_file.write(' <div> </div>') menu_file.write( ' <a class="sectionLinks" target="contents" href="Ajuda.htm">') # menu_file.write(' <span style="margin-left:15px">Ajuda</span>') # Danilo C M Marques - 27/10/2017 menu_file.write(' <span style="margin-left:15px">Help</span>') menu_file.write(' </a>') menu_file.write(' <div> </div> ') menu_file.write(' <h3>Selected Evidences<h3>') tag_number = 1 for tag in self.tags_selected: menu_file.write( ' <a class="sectionLinks" target="contents" href="Bookmark' + str(tag_number) + 'Pagina1.html">') menu_file.write(' <span style="margin-left:30px">' + tag.encode('utf-8') + '</span>') menu_file.write(' </a>') tag_number = tag_number + 1 menu_file.write(' ') menu_file.write(' </div>') menu_file.write(' ') menu_file.write('</body>') menu_file.write('</html>') menu_file.close() def onchange_lb(self, event): self.tags_selected[:] = [] self.tags_selected = self.List_Box_LB.getSelectedValuesList() def find_tags(self): tag_list = [] sql_statement = "SELECT distinct(display_name) u_tag_name FROM content_tags INNER JOIN tag_names ON " + \ " content_tags.tag_name_id = tag_names.tag_name_id;" skCase = Case.getCurrentCase().getSleuthkitCase() dbquery = skCase.executeQuery(sql_statement) resultSet = dbquery.getResultSet() while resultSet.next(): tag_list.append(resultSet.getString("u_tag_name")) dbquery.close() return tag_list
class GUI_TestWithUISettingsPanel(IngestModuleIngestJobSettingsPanel): # Note, we can't use a self.settings instance variable. # Rather, self.local_settings is used. # https://wiki.python.org/jython/UserGuide#javabean-properties # Jython Introspector generates a property - 'settings' on the basis # of getSettings() defined in this class. Since only getter function # is present, it creates a read-only 'settings' property. This auto- # generated read-only property overshadows the instance-variable - # 'settings' # We get passed in a previous version of the settings so that we can # prepopulate the UI # TODO: Update this for your UI def __init__(self, settings): self.local_settings = settings self.initComponents() self.customizeComponents() # TODO: Update this for your UI def checkBoxEvent(self, event): if self.Exec_Program_CB.isSelected(): self.local_settings.setExec_Prog_Flag(True) self.Program_Executable_TF.setEnabled(True) self.Find_Program_Exec_BTN.setEnabled(True) else: self.local_settings.setExec_Prog_Flag(False) self.Program_Executable_TF.setText("") self.Program_Executable_TF.setEnabled(False) self.Find_Program_Exec_BTN.setEnabled(False) if self.Imp_File_CB.isSelected(): self.local_settings.setImp_File_Flag(True) self.File_Imp_TF.setEnabled(True) self.Find_Imp_File_BTN.setEnabled(True) else: self.local_settings.setImp_File_Flag(False) self.File_Imp_TF.setText("") self.local_settings.setFile_Imp_TF("") self.File_Imp_TF.setEnabled(False) self.Find_Imp_File_BTN.setEnabled(False) def keyPressed(self, event): self.local_settings.setArea(self.area.getText()) def onchange_cb(self, event): self.local_settings.setComboBox(event.item) #self.Error_Message.setText(event.item) def onchange_lb(self, event): self.local_settings.clearListBox() list_selected = self.List_Box_LB.getSelectedValuesList() self.local_settings.setListBox(list_selected) # if (len(list_selected) > 0): # self.Error_Message.setText(str(list_selected)) # else: # self.Error_Message.setText("") def onClick(self, e): chooseFile = JFileChooser() filter = FileNameExtensionFilter("SQLite", ["sqlite"]) chooseFile.addChoosableFileFilter(filter) ret = chooseFile.showDialog(self.panel0, "Select SQLite") if ret == JFileChooser.APPROVE_OPTION: file = chooseFile.getSelectedFile() Canonical_file = file.getCanonicalPath() #text = self.readPath(file) if self.File_Imp_TF.isEnabled(): self.File_Imp_TF.setText(Canonical_file) self.local_settings.setFile_Imp_TF(Canonical_file) else: self.local_settings.setExecFile(Canonical_file) self.Program_Executable_TF.setText(Canonical_file) # TODO: Update this for your UI def initComponents(self): self.panel0 = JPanel() self.rbgPanel0 = ButtonGroup() self.gbPanel0 = GridBagLayout() self.gbcPanel0 = GridBagConstraints() self.panel0.setLayout(self.gbPanel0) self.Exec_Program_CB = JCheckBox("Execute Program", actionPerformed=self.checkBoxEvent) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 1 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.Exec_Program_CB, self.gbcPanel0) self.panel0.add(self.Exec_Program_CB) self.Program_Executable_TF = JTextField(20) self.Program_Executable_TF.setEnabled(False) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 3 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.Program_Executable_TF, self.gbcPanel0) self.panel0.add(self.Program_Executable_TF) self.Find_Program_Exec_BTN = JButton("Find Exec", actionPerformed=self.onClick) self.Find_Program_Exec_BTN.setEnabled(False) self.rbgPanel0.add(self.Find_Program_Exec_BTN) self.gbcPanel0.gridx = 6 self.gbcPanel0.gridy = 3 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.Find_Program_Exec_BTN, self.gbcPanel0) self.panel0.add(self.Find_Program_Exec_BTN) self.Imp_File_CB = JCheckBox("Import File", actionPerformed=self.checkBoxEvent) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 5 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.Imp_File_CB, self.gbcPanel0) self.panel0.add(self.Imp_File_CB) self.File_Imp_TF = JTextField(20) self.File_Imp_TF.setEnabled(False) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 7 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.File_Imp_TF, self.gbcPanel0) self.panel0.add(self.File_Imp_TF) self.Find_Imp_File_BTN = JButton("Find File", actionPerformed=self.onClick) self.Find_Imp_File_BTN.setEnabled(False) self.rbgPanel0.add(self.Find_Imp_File_BTN) self.gbcPanel0.gridx = 6 self.gbcPanel0.gridy = 7 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.Find_Imp_File_BTN, self.gbcPanel0) self.panel0.add(self.Find_Imp_File_BTN) self.Check_Box_CB = JCheckBox("Check Box 1", actionPerformed=self.checkBoxEvent) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 9 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.Check_Box_CB, self.gbcPanel0) self.panel0.add(self.Check_Box_CB) self.dataComboBox_CB = ("Chocolate", "Ice Cream", "Apple Pie") self.ComboBox_CB = JComboBox(self.dataComboBox_CB) self.ComboBox_CB.itemStateChanged = self.onchange_cb self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 11 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.ComboBox_CB, self.gbcPanel0) self.panel0.add(self.ComboBox_CB) self.dataList_Box_LB = ("Chocolate", "Ice Cream", "Apple Pie", "Pudding", "Candy") self.List_Box_LB = JList(self.dataList_Box_LB, valueChanged=self.onchange_lb) #self.List_Box_LB.itemStateChanged = self.onchange_lb self.List_Box_LB.setVisibleRowCount(3) self.scpList_Box_LB = JScrollPane(self.List_Box_LB) self.gbcPanel0.gridx = 6 self.gbcPanel0.gridy = 15 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 1 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.scpList_Box_LB, self.gbcPanel0) self.panel0.add(self.scpList_Box_LB) # self.Radio_Button_RB = JRadioButton( "Radio Button" ) # self.rbgPanel0.add( self.Radio_Button_RB ) # self.gbcPanel0.gridx = 7 # self.gbcPanel0.gridy = 17 # self.gbcPanel0.gridwidth = 1 # self.gbcPanel0.gridheight = 1 # self.gbcPanel0.fill = GridBagConstraints.BOTH # self.gbcPanel0.weightx = 1 # self.gbcPanel0.weighty = 0 # self.gbcPanel0.anchor = GridBagConstraints.NORTH # self.gbPanel0.setConstraints( self.Radio_Button_RB, self.gbcPanel0 ) # self.panel0.add( self.Radio_Button_RB ) # self.Label_1 = JLabel( "Error Message:") # self.Label_1.setEnabled(True) # self.gbcPanel0.gridx = 2 # self.gbcPanel0.gridy = 19 # self.gbcPanel0.gridwidth = 1 # self.gbcPanel0.gridheight = 1 # self.gbcPanel0.fill = GridBagConstraints.BOTH # self.gbcPanel0.weightx = 1 # self.gbcPanel0.weighty = 0 # self.gbcPanel0.anchor = GridBagConstraints.NORTH # self.gbPanel0.setConstraints( self.Label_1, self.gbcPanel0 ) # self.panel0.add( self.Label_1 ) # self.Error_Message = JLabel( "") # self.Error_Message.setEnabled(True) # self.gbcPanel0.gridx = 6 # self.gbcPanel0.gridy = 19 # self.gbcPanel0.gridwidth = 1 # self.gbcPanel0.gridheight = 1 # self.gbcPanel0.fill = GridBagConstraints.BOTH # self.gbcPanel0.weightx = 1 # self.gbcPanel0.weighty = 0 # self.gbcPanel0.anchor = GridBagConstraints.NORTH # self.gbPanel0.setConstraints( self.Error_Message, self.gbcPanel0 ) # self.panel0.add( self.Error_Message ) self.add(self.panel0) # TODO: Update this for your UI def customizeComponents(self): self.Exec_Program_CB.setSelected( self.local_settings.getExec_Prog_Flag()) self.Imp_File_CB.setSelected(self.local_settings.getImp_File_Flag()) self.Check_Box_CB.setSelected(self.local_settings.getCheck_Box_1()) # Return the settings used def getSettings(self): return self.local_settings
class Remove_ArtifactsWithUISettingsPanel(IngestModuleIngestJobSettingsPanel): # Note, we can't use a self.settings instance variable. # Rather, self.local_settings is used. # https://wiki.python.org/jython/UserGuide#javabean-properties # Jython Introspector generates a property - 'settings' on the basis # of getSettings() defined in this class. Since only getter function # is present, it creates a read-only 'settings' property. This auto- # generated read-only property overshadows the instance-variable - # 'settings' # We get passed in a previous version of the settings so that we can # prepopulate the UI # TODO: Update this for your UI def __init__(self, settings): self.local_settings = settings self.artifact_list = [] self.initComponents() self.customizeComponents() # Check to see if there are any entries that need to be populated from the database. def checkBoxEvent(self, event): if self.All_Artifacts_CB.isSelected(): self.local_settings.setSetting('allArtifacts', 'true') self.List_Box_LB.setEnabled(False) else: self.local_settings.setSetting('allArtifacts', 'false') self.List_Box_LB.setEnabled(True) if self.All_Attributes_CB.isSelected(): self.local_settings.setSetting('allAttributes', 'true') self.List_Box_LB.setEnabled(False) else: self.local_settings.setSetting('allAttributes', 'false') self.List_Box_LB.setEnabled(True) def onchange_lb(self, event): self.local_settings.setSetting('listSelected', '') list_selected = self.List_Box_LB.getSelectedValuesList() self.local_settings.setSetting('listSelected', list_selected) def get_artifacts(self): sql_statement = "select distinct(type_name) 'type_name' from blackboard_artifacts a, blackboard_artifact_types b " + \ " where a.artifact_type_id = b.artifact_type_id;" skCase = Case.getCurrentCase().getSleuthkitCase() dbquery = skCase.executeQuery(sql_statement) resultSet = dbquery.getResultSet() while resultSet.next(): self.artifact_list.append(resultSet.getString("type_name")) dbquery.close() # Create the initial data fields/layout in the UI def initComponents(self): self.panel0 = JPanel() self.rbgPanel0 = ButtonGroup() self.gbPanel0 = GridBagLayout() self.gbcPanel0 = GridBagConstraints() self.panel0.setLayout(self.gbPanel0) self.All_Artifacts_CB = JCheckBox("Remove All Custom Artifacts", actionPerformed=self.checkBoxEvent) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 1 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.All_Artifacts_CB, self.gbcPanel0) self.panel0.add(self.All_Artifacts_CB) self.All_Attributes_CB = JCheckBox("Remove All Custom Attributes", actionPerformed=self.checkBoxEvent) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 3 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.All_Attributes_CB, self.gbcPanel0) self.panel0.add(self.All_Attributes_CB) self.Blank_0 = JLabel(" ") self.Blank_0.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 5 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.Blank_0, self.gbcPanel0) self.panel0.add(self.Blank_0) self.Label_0 = JLabel("Remove selected Artifacts") self.Label_0.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 5 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.Label_0, self.gbcPanel0) self.panel0.add(self.Label_0) self.Blank_0 = JLabel(" ") self.Blank_0.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 5 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.Blank_0, self.gbcPanel0) self.panel0.add(self.Blank_0) self.get_artifacts() self.List_Box_LB = JList(self.artifact_list, valueChanged=self.onchange_lb) self.List_Box_LB.setVisibleRowCount(3) self.scpList_Box_LB = JScrollPane(self.List_Box_LB) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 7 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 1 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.scpList_Box_LB, self.gbcPanel0) self.panel0.add(self.scpList_Box_LB) self.Blank_1 = JLabel(" ") self.Blank_1.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 9 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.Blank_1, self.gbcPanel0) self.panel0.add(self.Blank_1) self.Label_1 = JLabel("Message:") self.Label_1.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 11 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.Label_1, self.gbcPanel0) self.panel0.add(self.Label_1) self.Blank_2 = JLabel(" ") self.Blank_2.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 13 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.Blank_2, self.gbcPanel0) self.panel0.add(self.Blank_2) self.Error_Message = JLabel( "For developer purposes only, it may fubar your case") self.Error_Message.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 15 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.Error_Message, self.gbcPanel0) self.panel0.add(self.Error_Message) self.add(self.panel0) # Custom load any data field and initialize the values def customizeComponents(self): self.All_Artifacts_CB.setSelected( self.local_settings.getSetting('allArtifacts') == 'true') self.All_Attributes_CB.setSelected( self.local_settings.getSetting('allAttributes') == 'true') # Return the settings used def getSettings(self): return self.local_settings
class CuckooSettingsWithUISettingsPanel(IngestModuleIngestJobSettingsPanel): # Note, we can't use a self.settings instance variable. # Rather, self.local_settings is used. # https://wiki.python.org/jython/UserGuide#javabean-properties # Jython Introspector generates a property - 'settings' on the basis # of getSettings() defined in this class. Since only getter function # is present, it creates a read-only 'settings' property. This auto- # generated read-only property overshadows the instance-variable - # 'settings' # We get passed in a previous version of the settings so that we can # prepopulate the UI # TODO: Update this for your UI def __init__(self, settings): self.local_settings = settings self.tag_list = [] self.initComponents() self.customizeComponents() self.path_to_cuckoo_exe = os.path.join( os.path.dirname(os.path.abspath(__file__)), "cuckoo_api.exe") # Check the checkboxs to see what actions need to be taken def checkBoxEvent(self, event): if self.Submit_File_CB.isSelected(): self.local_settings.setSetting('Submit_File', 'true') self.local_settings.setSetting('Submit_URL', 'false') else: self.local_settings.setSetting('Submit_File', 'false') def onchange_lb(self, event): self.local_settings.cleartag_list() list_selected = self.List_Box_LB.getSelectedValuesList() self.local_settings.setSetting('tag_list', str(list_selected)) def find_tags(self): sql_statement = "SELECT distinct(display_name) u_tag_name FROM content_tags INNER JOIN tag_names ON " + \ " content_tags.tag_name_id = tag_names.tag_name_id;" skCase = Case.getCurrentCase().getSleuthkitCase() dbquery = skCase.executeQuery(sql_statement) resultSet = dbquery.getResultSet() while resultSet.next(): self.tag_list.append(resultSet.getString("u_tag_name")) dbquery.close() # Check to see if the Cuckoo server is available and you can talk to it def Check_Server(self, e): pipe = Popen([ self.path_to_cuckoo_exe, self.Protocol_TF.getText(), self.IP_Address_TF.getText(), self.Port_Number_TF.getText(), "cuckoo_status" ], stdout=PIPE, stderr=PIPE) out_text = pipe.communicate()[0] self.Error_Message.setText("Cuckoo Status is " + out_text) #self.log(Level.INFO, "Cuckoo Status is ==> " + out_text) def setIPAddress(self, event): self.local_settings.setSetting('IP_Address', self.IP_Address_TF.getText()) def setProtocol(self, event): self.local_settings.setSetting('Protocol', self.Protocol_TF.getText()) def setPortNumber(self, event): self.local_settings.setSetting('Port_Number', self.Port_Number_TF.getText()) # Create the initial data fields/layout in the UI def initComponents(self): self.panel0 = JPanel() self.rbgPanel0 = ButtonGroup() self.gbPanel0 = GridBagLayout() self.gbcPanel0 = GridBagConstraints() self.panel0.setLayout(self.gbPanel0) self.Label_1 = JLabel("Protocol:") self.Label_1.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 1 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.Label_1, self.gbcPanel0) self.panel0.add(self.Label_1) self.Protocol_TF = JTextField(20, focusLost=self.setProtocol) self.Protocol_TF.setEnabled(True) self.gbcPanel0.gridx = 4 self.gbcPanel0.gridy = 1 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.Protocol_TF, self.gbcPanel0) self.panel0.add(self.Protocol_TF) self.Blank_1 = JLabel(" ") self.Blank_1.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 3 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.Blank_1, self.gbcPanel0) self.panel0.add(self.Blank_1) self.Label_2 = JLabel("Cuckoo IP Address") self.Label_2.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 5 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.Label_2, self.gbcPanel0) self.panel0.add(self.Label_2) self.IP_Address_TF = JTextField(20, focusLost=self.setIPAddress) self.IP_Address_TF.setEnabled(True) self.gbcPanel0.gridx = 4 self.gbcPanel0.gridy = 5 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.IP_Address_TF, self.gbcPanel0) self.panel0.add(self.IP_Address_TF) self.Blank_2 = JLabel(" ") self.Blank_2.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 7 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.Blank_2, self.gbcPanel0) self.panel0.add(self.Blank_2) self.Label_3 = JLabel("Port Number") self.Label_3.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 9 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.Label_3, self.gbcPanel0) self.panel0.add(self.Label_3) self.Port_Number_TF = JTextField(20, focusLost=self.setPortNumber) self.Port_Number_TF.setEnabled(True) self.gbcPanel0.gridx = 4 self.gbcPanel0.gridy = 9 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.Port_Number_TF, self.gbcPanel0) self.panel0.add(self.Port_Number_TF) self.Blank_3 = JLabel(" ") self.Blank_3.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 11 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.Blank_3, self.gbcPanel0) self.panel0.add(self.Blank_3) self.Blank_5 = JLabel("Tag to Choose: ") self.Blank_5.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 13 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.Blank_5, self.gbcPanel0) self.panel0.add(self.Blank_5) self.find_tags() self.List_Box_LB = JList(self.tag_list, valueChanged=self.onchange_lb) self.List_Box_LB.setVisibleRowCount(3) self.scpList_Box_LB = JScrollPane(self.List_Box_LB) self.gbcPanel0.gridx = 4 self.gbcPanel0.gridy = 13 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 1 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.scpList_Box_LB, self.gbcPanel0) self.panel0.add(self.scpList_Box_LB) self.Blank_6 = JLabel(" ") self.Blank_6.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 15 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.Blank_6, self.gbcPanel0) self.panel0.add(self.Blank_6) self.Submit_File_CB = JCheckBox("Submit a File", actionPerformed=self.checkBoxEvent) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 17 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.Submit_File_CB, self.gbcPanel0) self.panel0.add(self.Submit_File_CB) # self.Submit_URL_CB = JCheckBox("Submit a URL", actionPerformed=self.checkBoxEvent) # self.gbcPanel0.gridx = 2 # self.gbcPanel0.gridy = 23 # self.gbcPanel0.gridwidth = 1 # self.gbcPanel0.gridheight = 1 # self.gbcPanel0.fill = GridBagConstraints.BOTH # self.gbcPanel0.weightx = 1 # self.gbcPanel0.weighty = 0 # self.gbcPanel0.anchor = GridBagConstraints.NORTH # self.gbPanel0.setConstraints( self.Submit_URL_CB, self.gbcPanel0 ) # self.panel0.add( self.Submit_URL_CB ) self.Check_Server_Status_BTN = JButton( "Check Server Status", actionPerformed=self.Check_Server) self.Check_Server_Status_BTN.setEnabled(True) self.rbgPanel0.add(self.Check_Server_Status_BTN) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 19 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.Check_Server_Status_BTN, self.gbcPanel0) self.panel0.add(self.Check_Server_Status_BTN) self.Error_Message = JLabel("") self.Error_Message.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 21 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.Error_Message, self.gbcPanel0) self.panel0.add(self.Error_Message) self.add(self.panel0) # Custom load any data field and initialize the values def customizeComponents(self): #self.Exclude_File_Sources_CB.setSelected(self.local_settings.getExclude_File_Sources()) #self.Run_Cuckoo_CB.setSelected(self.local_settings.getSetting('Submit_File') == 'true') #self.Import_Cuckoo_CB.setSelected(self.local_settings.getImport_Cuckoo()) self.Port_Number_TF.setText( self.local_settings.getSetting('Port_Number')) self.IP_Address_TF.setText( self.local_settings.getSetting('IP_Address')) self.Protocol_TF.setText(self.local_settings.getSetting('Protocol')) # Return the settings used def getSettings(self): return self.local_settings
class CloudtopsyWithUISettingsPanel(IngestModuleIngestJobSettingsPanel): # Note, we can't use a self.settings instance variable. # Rather, self.local_settings is used. # https://wiki.python.org/jython/UserGuide#javabean-properties # Jython Introspector generates a property - 'settings' on the basis # of getSettings() defined in this class. Since only getter function # is present, it creates a read-only 'settings' property. This auto- # generated read-only property overshadows the instance-variable - # 'settings' # We get passed in a previous version of the settings so that we can # prepopulate the UI # TODO: Update this for your UI def __init__(self, settings): self.local_settings = settings self.initComponents() self.customizeComponents() # Check to see if there are any entries that need to be populated from the database. def check_Database_entries(self): head, tail = os.path.split(os.path.abspath(__file__)) settings_db = head + "\\config.db" try: Class.forName("org.sqlite.JDBC").newInstance() dbConn = DriverManager.getConnection("jdbc:sqlite:%s" % settings_db) except SQLException as e: self.Error_Message.setText("Error Opening Settings DB!") if os.path.exists(settings_db): try: stmt = dbConn.createStatement() SQL_Statement = 'Select Key_Name, Key_Value from CONFIG;' resultSet = stmt.executeQuery(SQL_Statement) while resultSet.next(): if resultSet.getString("Key_Name") == "BUCKET": self.local_settings.setBucket( resultSet.getString("Key_Value")) self.Bucket_TF.setText( resultSet.getString("Key_Value")) if resultSet.getString("Key_Name") == "ACCESS_KEY": self.local_settings.setAccessKey( resultSet.getString("Key_Value")) self.Access_Key_TF.setText( resultSet.getString("Key_Value")) if resultSet.getString("Key_Name") == "SECRET_KEY": self.local_settings.setSecretKey( resultSet.getString("Key_Value")) self.Secret_Key_TF.setText( resultSet.getString("Key_Value")) if resultSet.getString("Key_Name") == "AWS_REGION": self.local_settings.setRegion( resultSet.getString("Key_Value")) self.Region_TF.setText( resultSet.getString("Key_Value")) self.Error_Message.setText("Settings Read successfully!") except SQLException as e: self.Error_Message.setText("Error Reading Settings Database") else: try: stmt = dbConn.createStatement() SQL_Statement = 'CREATE TABLE CONFIG ( Setting_Name Text, Setting_Value Text)' resultSet = stmt.executeQuery(SQL_Statement) except SQLException as e: self.Error_Message.setText("Error Creating Settings Database") stmt.close() dbConn.close() # Save entries from the GUI to the database. def SaveSettings(self, e): error = False head, tail = os.path.split(os.path.abspath(__file__)) head, tail = os.path.split(os.path.abspath(__file__)) settings_db = head + "\\config.db" try: Class.forName("org.sqlite.JDBC").newInstance() dbConn = DriverManager.getConnection("jdbc:sqlite:%s" % settings_db) except SQLException as e: self.Error_Message.setText("Error Opening Settings") try: stmt = dbConn.createStatement() SQL_Statement = 'UPDATE CONFIG SET Key_Value = "' + self.Bucket_TF.getText( ) + '" WHERE Key_Name = "BUCKET";' resultSet = stmt.executeQuery(SQL_Statement) except: pass if re.match(r'[A-Z0-9]{20}', self.Access_Key_TF.getText()): try: stmt = dbConn.createStatement() SQL_Statement = 'UPDATE CONFIG SET Key_Value = "' + self.Access_Key_TF.getText( ) + '" WHERE Key_Name = "ACCESS_KEY";' resultSet = stmt.executeQuery(SQL_Statement) except: pass else: error = True self.Error_Message.setText("Access Key Invalid") if re.match(r'[A-Za-z0-9/+=]{40}', self.Secret_Key_TF.getText()): try: stmt = dbConn.createStatement() SQL_Statement = 'UPDATE CONFIG SET Key_Value = "' + self.Secret_Key_TF.getText( ) + '" WHERE Key_Name = "SECRET_KEY";' resultSet = stmt.executeQuery(SQL_Statement) except: pass else: error = True self.Error_Message.setText("Secret Key Invalid") if re.match( r'[a-z]{2}-(gov-)?(north|south|east|west|central)(east|west)?-\d(\w)?', self.Region_TF.getText()): try: stmt = dbConn.createStatement() SQL_Statement = 'UPDATE CONFIG SET Key_Value = "' + self.Region_TF.getText( ) + '" WHERE Key_Name = "AWS_REGION";' resultSet = stmt.executeQuery(SQL_Statement) except: pass else: error = True self.Error_Message.setText("AWS Region Invalid") if not error: self.Error_Message.setText("Settings Saved") stmt.close() dbConn.close() # Create the initial data fields/layout in the UI def initComponents(self): self.panel0 = JPanel() self.rbgPanel0 = ButtonGroup() self.gbPanel0 = GridBagLayout() self.gbcPanel0 = GridBagConstraints() self.panel0.setLayout(self.gbPanel0) self.LabelA = JLabel("S3 Bucket:") self.LabelA.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 1 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.LabelA, self.gbcPanel0) self.panel0.add(self.LabelA) self.Bucket_TF = JTextField(20) self.Bucket_TF.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 3 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.Bucket_TF, self.gbcPanel0) self.panel0.add(self.Bucket_TF) self.Blank_1 = JLabel(" ") self.Blank_1.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 4 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.Blank_1, self.gbcPanel0) self.panel0.add(self.Blank_1) self.LabelB = JLabel("AWS Access Key:") self.LabelB.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 5 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.LabelB, self.gbcPanel0) self.panel0.add(self.LabelB) self.Access_Key_TF = JTextField(20) self.Access_Key_TF.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 7 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.Access_Key_TF, self.gbcPanel0) self.panel0.add(self.Access_Key_TF) self.Blank_2 = JLabel(" ") self.Blank_2.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 8 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.Blank_2, self.gbcPanel0) self.panel0.add(self.Blank_2) self.LabelC = JLabel("AWS Secret Key:") self.LabelC.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 9 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.LabelC, self.gbcPanel0) self.panel0.add(self.LabelC) self.Secret_Key_TF = JTextField(20) self.Secret_Key_TF.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 11 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.Secret_Key_TF, self.gbcPanel0) self.panel0.add(self.Secret_Key_TF) self.Blank_3 = JLabel(" ") self.Blank_3.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 12 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.Blank_3, self.gbcPanel0) self.panel0.add(self.Blank_3) self.LabelD = JLabel("AWS Region:") self.LabelD.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 13 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.LabelD, self.gbcPanel0) self.panel0.add(self.LabelD) self.Region_TF = JTextField(20) self.Region_TF.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 15 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.Region_TF, self.gbcPanel0) self.panel0.add(self.Region_TF) self.Blank_4 = JLabel(" ") self.Blank_4.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 16 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.Blank_4, self.gbcPanel0) self.panel0.add(self.Blank_4) self.Save_Settings_BTN = JButton("Save Settings", actionPerformed=self.SaveSettings) self.Save_Settings_BTN.setEnabled(True) self.rbgPanel0.add(self.Save_Settings_BTN) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 17 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.Save_Settings_BTN, self.gbcPanel0) self.panel0.add(self.Save_Settings_BTN) self.Label_1 = JLabel("Error Message:") self.Label_1.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 18 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.Label_1, self.gbcPanel0) self.panel0.add(self.Label_1) self.Error_Message = JLabel("") self.Error_Message.setEnabled(True) self.gbcPanel0.gridx = 6 self.gbcPanel0.gridy = 19 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.Error_Message, self.gbcPanel0) self.panel0.add(self.Error_Message) self.add(self.panel0) # Custom load any data field and initialize the values def customizeComponents(self): self.check_Database_entries() # Return the settings used def getSettings(self): return self.local_settings
class CuckooSettingsWithUISettingsPanel(IngestModuleIngestJobSettingsPanel): # Note, we can't use a self.settings instance variable. # Rather, self.local_settings is used. # https://wiki.python.org/jython/UserGuide#javabean-properties # Jython Introspector generates a property - 'settings' on the basis # of getSettings() defined in this class. Since only getter function # is present, it creates a read-only 'settings' property. This auto- # generated read-only property overshadows the instance-variable - # 'settings' # We get passed in a previous version of the settings so that we can # prepopulate the UI # TODO: Update this for your UI def __init__(self, settings): self.local_settings = settings self.tag_list = [] self.initComponents() self.customizeComponents() self.path_to_cuckoo_exe = os.path.join(os.path.dirname(os.path.abspath(__file__)), "cuckoo_api.exe") # Check the checkboxs to see what actions need to be taken def checkBoxEvent(self, event): if self.Submit_File_CB.isSelected(): self.local_settings.setSetting('Submit_File', 'true') self.local_settings.setSetting('Submit_URL', 'false') else: self.local_settings.setSetting('Submit_File', 'false') def onchange_lb(self, event): self.local_settings.cleartag_list() list_selected = self.List_Box_LB.getSelectedValuesList() self.local_settings.setSetting('tag_list', str(list_selected)) def find_tags(self): sql_statement = "SELECT distinct(display_name) u_tag_name FROM content_tags INNER JOIN tag_names ON " + \ " content_tags.tag_name_id = tag_names.tag_name_id;" skCase = Case.getCurrentCase().getSleuthkitCase() dbquery = skCase.executeQuery(sql_statement) resultSet = dbquery.getResultSet() while resultSet.next(): self.tag_list.append(resultSet.getString("u_tag_name")) dbquery.close() # Check to see if the Cuckoo server is available and you can talk to it def Check_Server(self, e): pipe = Popen([self.path_to_cuckoo_exe, self.Protocol_TF.getText(),self.IP_Address_TF.getText(), self.Port_Number_TF.getText(), "cuckoo_status" ], stdout=PIPE, stderr=PIPE) out_text = pipe.communicate()[0] self.Error_Message.setText("Cuckoo Status is " + out_text) #self.log(Level.INFO, "Cuckoo Status is ==> " + out_text) def setIPAddress(self, event): self.local_settings.setSetting('IP_Address', self.IP_Address_TF.getText()) def setProtocol(self, event): self.local_settings.setSetting('Protocol', self.Protocol_TF.getText()) def setPortNumber(self, event): self.local_settings.setSetting('Port_Number', self.Port_Number_TF.getText()) # Create the initial data fields/layout in the UI def initComponents(self): self.panel0 = JPanel() self.rbgPanel0 = ButtonGroup() self.gbPanel0 = GridBagLayout() self.gbcPanel0 = GridBagConstraints() self.panel0.setLayout( self.gbPanel0 ) self.Label_1 = JLabel("Protocol:") self.Label_1.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 1 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints( self.Label_1, self.gbcPanel0 ) self.panel0.add( self.Label_1 ) self.Protocol_TF = JTextField(20, focusLost=self.setProtocol) self.Protocol_TF.setEnabled(True) self.gbcPanel0.gridx = 4 self.gbcPanel0.gridy = 1 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints( self.Protocol_TF, self.gbcPanel0 ) self.panel0.add( self.Protocol_TF ) self.Blank_1 = JLabel( " ") self.Blank_1.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 3 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints( self.Blank_1, self.gbcPanel0 ) self.panel0.add( self.Blank_1 ) self.Label_2 = JLabel("Cuckoo IP Address") self.Label_2.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 5 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints( self.Label_2, self.gbcPanel0 ) self.panel0.add( self.Label_2 ) self.IP_Address_TF = JTextField(20, focusLost=self.setIPAddress) self.IP_Address_TF.setEnabled(True) self.gbcPanel0.gridx = 4 self.gbcPanel0.gridy = 5 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints( self.IP_Address_TF, self.gbcPanel0 ) self.panel0.add( self.IP_Address_TF ) self.Blank_2 = JLabel( " ") self.Blank_2.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 7 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints( self.Blank_2, self.gbcPanel0 ) self.panel0.add( self.Blank_2 ) self.Label_3 = JLabel("Port Number") self.Label_3.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 9 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints( self.Label_3, self.gbcPanel0 ) self.panel0.add( self.Label_3 ) self.Port_Number_TF = JTextField(20, focusLost=self.setPortNumber) self.Port_Number_TF.setEnabled(True) self.gbcPanel0.gridx = 4 self.gbcPanel0.gridy = 9 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints( self.Port_Number_TF, self.gbcPanel0 ) self.panel0.add( self.Port_Number_TF ) self.Blank_3 = JLabel( " ") self.Blank_3.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 11 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints( self.Blank_3, self.gbcPanel0 ) self.panel0.add( self.Blank_3 ) self.Blank_5 = JLabel( "Tag to Choose: ") self.Blank_5.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 13 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints( self.Blank_5, self.gbcPanel0 ) self.panel0.add( self.Blank_5 ) self.find_tags() self.List_Box_LB = JList( self.tag_list, valueChanged=self.onchange_lb) self.List_Box_LB.setVisibleRowCount( 3 ) self.scpList_Box_LB = JScrollPane( self.List_Box_LB ) self.gbcPanel0.gridx = 4 self.gbcPanel0.gridy = 13 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 1 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints( self.scpList_Box_LB, self.gbcPanel0 ) self.panel0.add( self.scpList_Box_LB ) self.Blank_6 = JLabel( " ") self.Blank_6.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 15 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints( self.Blank_6, self.gbcPanel0 ) self.panel0.add( self.Blank_6 ) self.Submit_File_CB = JCheckBox("Submit a File", actionPerformed=self.checkBoxEvent) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 17 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints( self.Submit_File_CB, self.gbcPanel0 ) self.panel0.add( self.Submit_File_CB ) # self.Submit_URL_CB = JCheckBox("Submit a URL", actionPerformed=self.checkBoxEvent) # self.gbcPanel0.gridx = 2 # self.gbcPanel0.gridy = 23 # self.gbcPanel0.gridwidth = 1 # self.gbcPanel0.gridheight = 1 # self.gbcPanel0.fill = GridBagConstraints.BOTH # self.gbcPanel0.weightx = 1 # self.gbcPanel0.weighty = 0 # self.gbcPanel0.anchor = GridBagConstraints.NORTH # self.gbPanel0.setConstraints( self.Submit_URL_CB, self.gbcPanel0 ) # self.panel0.add( self.Submit_URL_CB ) self.Check_Server_Status_BTN = JButton( "Check Server Status", actionPerformed=self.Check_Server) self.Check_Server_Status_BTN.setEnabled(True) self.rbgPanel0.add( self.Check_Server_Status_BTN ) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 19 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints( self.Check_Server_Status_BTN, self.gbcPanel0 ) self.panel0.add( self.Check_Server_Status_BTN ) self.Error_Message = JLabel( "") self.Error_Message.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 21 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints( self.Error_Message, self.gbcPanel0 ) self.panel0.add( self.Error_Message ) self.add(self.panel0) # Custom load any data field and initialize the values def customizeComponents(self): #self.Exclude_File_Sources_CB.setSelected(self.local_settings.getExclude_File_Sources()) #self.Run_Cuckoo_CB.setSelected(self.local_settings.getSetting('Submit_File') == 'true') #self.Import_Cuckoo_CB.setSelected(self.local_settings.getImport_Cuckoo()) self.Port_Number_TF.setText(self.local_settings.getSetting('Port_Number')) self.IP_Address_TF.setText(self.local_settings.getSetting('IP_Address')) self.Protocol_TF.setText(self.local_settings.getSetting('Protocol')) # Return the settings used def getSettings(self): return self.local_settings
class AmcacheScanWithUISettingsPanel(IngestModuleIngestJobSettingsPanel): # Note, we can't use a self.settings instance variable. # Rather, self.local_settings is used. # https://wiki.python.org/jython/UserGuide#javabean-properties # Jython Introspector generates a property - 'settings' on the basis # of getSettings() defined in this class. Since only getter function # is present, it creates a read-only 'settings' property. This auto- # generated read-only property overshadows the instance-variable - # 'settings' # We get passed in a previous version of the settings so that we can # prepopulate the UI # TODO: Update this for your UI def __init__(self, settings): self.local_settings = settings self.initComponents() self.customizeComponents() # Check the checkboxs to see what actions need to be taken def checkBoxEvent(self, event): if self.Private_API_Key_CB.isSelected(): self.local_settings.setPrivate(True) self.local_settings.setAPI_Key(self.API_Key_TF.getText()) else: self.local_settings.setPrivate(False) self.local_settings.setAPI_Key(self.API_Key_TF.getText()) # Check to see if there are any entries that need to be populated from the database. def check_Database_entries(self): head, tail = os.path.split(os.path.abspath(__file__)) settings_db = head + "\\GUI_Settings.db3" try: Class.forName("org.sqlite.JDBC").newInstance() dbConn = DriverManager.getConnection("jdbc:sqlite:%s" % settings_db) except SQLException as e: self.Error_Message.setText("Error Opening Settings DB!") try: stmt = dbConn.createStatement() SQL_Statement = 'Select Setting_Name, Setting_Value from settings;' resultSet = stmt.executeQuery(SQL_Statement) while resultSet.next(): if resultSet.getString("Setting_Name") == "API_Key": self.local_settings.setAPI_Key(resultSet.getString("Setting_Value")) self.API_Key_TF.setText(resultSet.getString("Setting_Value")) if resultSet.getString("Setting_Name") == "Private": private = resultSet.getString("Setting_Value") if private == "1": self.local_settings.setPrivate(True) else: self.local_settings.setPrivate(False) self.Error_Message.setText("Settings Read successfully!") except SQLException as e: self.Error_Message.setText("Error Reading Settings Database") stmt.close() dbConn.close() # Save entries from the GUI to the database. def SaveSettings(self, e): head, tail = os.path.split(os.path.abspath(__file__)) settings_db = head + "\\GUI_Settings.db3" try: Class.forName("org.sqlite.JDBC").newInstance() dbConn = DriverManager.getConnection("jdbc:sqlite:%s" % settings_db) except SQLException as e: self.Error_Message.setText("Error Opening Settings") try: stmt = dbConn.createStatement() SQL_Statement = 'UPDATE settings SET Setting_Value = "' + self.API_Key_TF.getText() + '" WHERE Setting_Name = "API_Key";' resultSet = stmt.executeQuery(SQL_Statement) except: pass try: if self.local_settings.getPrivate(): SQL_Statement = 'UPDATE settings SET Setting_Value = "1" WHERE Setting_Name = "Private";' resultSet = stmt.executeQuery(SQL_Statement) else: SQL_Statement = 'UPDATE settings SET Setting_Value = "0" WHERE Setting_Name = "Private";' resultSet = stmt.executeQuery(SQL_Statement) except: pass self.Error_Message.setText("Settings Saved") stmt.close() dbConn.close() # Create the initial data fields/layout in the UI def initComponents(self): self.panel0 = JPanel() self.rbgPanel0 = ButtonGroup() self.gbPanel0 = GridBagLayout() self.gbcPanel0 = GridBagConstraints() self.panel0.setLayout( self.gbPanel0 ) self.LabelA = JLabel("VirusTotal API Key:") self.LabelA.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 1 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints( self.LabelA, self.gbcPanel0 ) self.panel0.add( self.LabelA ) self.API_Key_TF = JTextField(20) self.API_Key_TF.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 3 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints( self.API_Key_TF, self.gbcPanel0 ) self.panel0.add( self.API_Key_TF ) self.Blank_1 = JLabel( " ") self.Blank_1.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 6 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints( self.Blank_1, self.gbcPanel0 ) self.panel0.add( self.Blank_1 ) self.Private_API_Key_CB = JCheckBox("Private API Key?", actionPerformed=self.checkBoxEvent) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 5 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints( self.Private_API_Key_CB, self.gbcPanel0 ) self.panel0.add( self.Private_API_Key_CB ) self.Save_Settings_BTN = JButton( "Save Settings", actionPerformed=self.SaveSettings) self.Save_Settings_BTN.setEnabled(True) self.rbgPanel0.add( self.Save_Settings_BTN ) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 8 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints( self.Save_Settings_BTN, self.gbcPanel0 ) self.panel0.add( self.Save_Settings_BTN ) self.Label_1 = JLabel( "Error Message:") self.Label_1.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 11 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints( self.Label_1, self.gbcPanel0 ) self.panel0.add( self.Label_1 ) self.Error_Message = JLabel( "") self.Error_Message.setEnabled(True) self.gbcPanel0.gridx = 6 self.gbcPanel0.gridy = 11 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints( self.Error_Message, self.gbcPanel0 ) self.panel0.add( self.Error_Message ) self.add(self.panel0) # Custom load any data field and initialize the values def customizeComponents(self): self.check_Database_entries() self.Private_API_Key_CB.setSelected(self.local_settings.getPrivate()) # Return the settings used def getSettings(self): return self.local_settings
# Create the GUI: a 3-column table and a text area next to it # to show and write notes for any selected row, plus some buttons and a search field all = JPanel() all.setBackground(Color.white) gb = GridBagLayout() all.setLayout(gb) c = GridBagConstraints() # Top-left element: a text field for filtering rows by regular expression match c.gridx = 0 c.gridy = 0 c.anchor = GridBagConstraints.CENTER c.fill = GridBagConstraints.HORIZONTAL search_field = JTextField("") gb.setConstraints(search_field, c) all.add(search_field) # Bottom left element: the table, wrapped in a scrollable component table = JTable(TableModel()) table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION) #table.setCellSelectionEnabled(True) table.setAutoCreateRowSorter( True) # to sort the view only, not the data in the underlying TableModel c.gridx = 0 c.gridy = 1 c.anchor = GridBagConstraints.NORTHWEST c.fill = GridBagConstraints.BOTH # resize with the frame c.weightx = 1.0 c.gridheight = 2 jsp = JScrollPane(table)
class VolatilitySettingsWithUISettingsPanel(IngestModuleIngestJobSettingsPanel ): # Note, we can't use a self.settings instance variable. # Rather, self.local_settings is used. # https://wiki.python.org/jython/UserGuide#javabean-properties # Jython Introspector generates a property - 'settings' on the basis # of getSettings() defined in this class. Since only getter function # is present, it creates a read-only 'settings' property. This auto- # generated read-only property overshadows the instance-variable - # 'settings' # We get passed in a previous version of the settings so that we can # prepopulate the UI # TODO: Update this for your UI def __init__(self, settings): self.local_settings = settings self.initComponents() self.customizeComponents() # Check to see if there are any entries that need to be populated from the database. def check_Database_entries(self): head, tail = os.path.split(os.path.abspath(__file__)) settings_db = head + "\\GUI_Settings.db3" try: Class.forName("org.sqlite.JDBC").newInstance() dbConn = DriverManager.getConnection("jdbc:sqlite:%s" % settings_db) except SQLException as e: self.Error_Message.setText("Error Opening Settings DB!") try: stmt = dbConn.createStatement() SQL_Statement = 'Select Setting_Name, Setting_Value from settings;' resultSet = stmt.executeQuery(SQL_Statement) while resultSet.next(): if resultSet.getString( "Setting_Name") == "Volatility_Executable_Directory": self.Program_Executable_TF.setText( resultSet.getString("Setting_Value")) self.local_settings.setVolatility_Directory( resultSet.getString("Setting_Value")) self.local_settings.setVolatility_Dir_Found(True) # if resultSet.getString("Setting_Name") == "Volatility_Version": # self.Version_CB.setSelectedItem(resultSet.getString("Setting_Value")) self.Error_Message.setText("Settings Read successfully!") except SQLException as e: self.Error_Message.setText("Error Reading Settings Database") stmt.close() dbConn.close() # Save entries from the GUI to the database. def SaveSettings(self, e): head, tail = os.path.split(os.path.abspath(__file__)) settings_db = head + "\\GUI_Settings.db3" try: Class.forName("org.sqlite.JDBC").newInstance() dbConn = DriverManager.getConnection("jdbc:sqlite:%s" % settings_db) except SQLException as e: self.Error_Message.setText("Error Opening Settings") try: stmt = dbConn.createStatement() SQL_Statement = "" if (self.local_settings.getVolatility_Dir_Found()): SQL_Statement = 'Update settings set Setting_Value = "' + self.Program_Executable_TF.getText() + '"' + \ ' where setting_name = "Volatility_Executable_Directory";' # SQL_Statement2 = 'Update settings set Setting_Value = "' + self.Version_CB.getSelectedItem() + '"' + \ # ' where setting_name = "Volatility_Version";' else: SQL_Statement = 'Insert into settings (Setting_Name, Setting_Value) values ("Volatility_Executable_Directory", "' + \ self.Program_Executable_TF.getText() + '");' # SQL_Statement2 = 'Insert into settings (Setting_Name, Setting_Value) values ("Volatility_Version", "' + \ # self.Version_CB.getSelectedItem() + '");' stmt.execute(SQL_Statement) # stmt.execute(SQL_Statement2) self.Error_Message.setText("Volatility Executable Directory Saved") self.local_settings.setVolatility_Directory( self.Program_Executable_TF.getText()) except SQLException as e: self.Error_Message.setText(e.getMessage()) stmt.close() dbConn.close() # When button to find file is clicked then open dialog to find the file and return it. def Find_Dir(self, e): chooseFile = JFileChooser() filter = FileNameExtensionFilter("All", ["*.*"]) chooseFile.addChoosableFileFilter(filter) #chooseFile.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY) ret = chooseFile.showDialog(self.panel0, "Find Volatility Directory") if ret == JFileChooser.APPROVE_OPTION: file = chooseFile.getSelectedFile() Canonical_file = file.getCanonicalPath() #text = self.readPath(file) self.local_settings.setVolatility_Directory(Canonical_file) self.Program_Executable_TF.setText(Canonical_file) def keyPressed(self, event): self.local_settings.setProcessIDs( self.Process_Ids_To_Dump_TF.getText()) #self.Error_Message.setText(self.Process_Ids_To_Dump_TF.getText()) def checkBoxEvent(self, event): if self.Check_Box.isSelected(): self.local_settings.setFlag(True) else: self.local_settings.setFlag(False) # Create the initial data fields/layout in the UI def initComponents(self): self.panel0 = JPanel() self.rbgPanel0 = ButtonGroup() self.gbPanel0 = GridBagLayout() self.gbcPanel0 = GridBagConstraints() self.panel0.setLayout(self.gbPanel0) self.Error_Message = JLabel("") self.Error_Message.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 31 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.Error_Message, self.gbcPanel0) self.panel0.add(self.Error_Message) self.Label_1 = JLabel("Volatility Executable Directory") self.Label_1.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 1 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.Label_1, self.gbcPanel0) self.panel0.add(self.Label_1) self.Program_Executable_TF = JTextField(10) self.Program_Executable_TF.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 3 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.Program_Executable_TF, self.gbcPanel0) self.panel0.add(self.Program_Executable_TF) self.Find_Program_Exec_BTN = JButton("Find Dir", actionPerformed=self.Find_Dir) self.Find_Program_Exec_BTN.setEnabled(True) self.rbgPanel0.add(self.Find_Program_Exec_BTN) self.gbcPanel0.gridx = 6 self.gbcPanel0.gridy = 3 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.Find_Program_Exec_BTN, self.gbcPanel0) self.panel0.add(self.Find_Program_Exec_BTN) self.Blank_1 = JLabel(" ") self.Blank_1.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 5 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.Blank_1, self.gbcPanel0) self.panel0.add(self.Blank_1) self.Save_Settings_BTN = JButton("Save Volatility Exec Dir", actionPerformed=self.SaveSettings) self.Save_Settings_BTN.setEnabled(True) self.rbgPanel0.add(self.Save_Settings_BTN) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 7 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.Save_Settings_BTN, self.gbcPanel0) self.panel0.add(self.Save_Settings_BTN) self.Blank_2 = JLabel(" ") self.Blank_2.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 9 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.Blank_2, self.gbcPanel0) self.panel0.add(self.Blank_2) self.Blank_3 = JLabel(" ") self.Blank_3.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 13 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.Blank_3, self.gbcPanel0) self.panel0.add(self.Blank_3) self.Check_Box = JCheckBox( "Extract and Create Memory Image from Hiberfile", actionPerformed=self.checkBoxEvent) self.Blank_1.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 15 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.Check_Box, self.gbcPanel0) self.panel0.add(self.Check_Box) self.Blank_4 = JLabel(" ") self.Blank_4.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 17 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.Blank_4, self.gbcPanel0) self.panel0.add(self.Blank_4) self.Blank_5 = JLabel(" ") self.Blank_5.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 21 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.Blank_5, self.gbcPanel0) self.panel0.add(self.Blank_5) self.Blank_6 = JLabel(" ") self.Blank_6.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 27 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.Blank_6, self.gbcPanel0) self.panel0.add(self.Blank_6) self.Label_3 = JLabel("Message:") self.Label_3.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 29 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.Label_3, self.gbcPanel0) self.panel0.add(self.Label_3) self.add(self.panel0) # Custom load any data field and initialize the values def customizeComponents(self): self.Check_Box.setSelected(self.local_settings.getFlag()) self.check_Database_entries() #pass # Return the settings used def getSettings(self): return self.local_settings
class GUI_Test_SQLSettingsWithUISettingsPanel(IngestModuleIngestJobSettingsPanel): # Note, we can't use a self.settings instance variable. # Rather, self.local_settings is used. # https://wiki.python.org/jython/UserGuide#javabean-properties # Jython Introspector generates a property - 'settings' on the basis # of getSettings() defined in this class. Since only getter function # is present, it creates a read-only 'settings' property. This auto- # generated read-only property overshadows the instance-variable - # 'settings' # We get passed in a previous version of the settings so that we can # prepopulate the UI # TODO: Update this for your UI def __init__(self, settings): self.local_settings = settings self.initComponents() self.customizeComponents() # Check the checkboxs to see what actions need to be taken def checkBoxEvent(self, event): if self.Exec_Program_CB.isSelected(): self.local_settings.setSetting('Exec_Prog_Flag', 'true') self.Program_Executable_TF.setEnabled(True) self.Find_Program_Exec_BTN.setEnabled(True) else: self.local_settings.setSetting('Exec_Prog_Flag', 'false') self.Program_Executable_TF.setText("") self.Program_Executable_TF.setEnabled(False) self.Find_Program_Exec_BTN.setEnabled(False) # Check to see if there are any entries that need to be populated from the database. def check_Database_entries(self): head, tail = os.path.split(os.path.abspath(__file__)) settings_db = os.path.join(head, "GUI_Settings.db3") try: Class.forName("org.sqlite.JDBC").newInstance() dbConn = DriverManager.getConnection("jdbc:sqlite:%s" % settings_db) except SQLException as e: self.Error_Message.setText("Error Opening Settings DB!") try: stmt = dbConn.createStatement() SQL_Statement = 'Select Setting_Name, Setting_Value from settings;' resultSet = stmt.executeQuery(SQL_Statement) while resultSet.next(): if resultSet.getString("Setting_Name") == "Program_Exec_Name": self.Program_Executable_TF.setText(resultSet.getString("Setting_Value")) self.local_settings.setSetting('ExecFile', resultSet.getString("Setting_Value")) self.local_settings.setSetting('Exec_Prog_Flag', 'true') self.Exec_Program_CB.setSelected(True) self.Program_Executable_TF.setEnabled(True) self.Find_Program_Exec_BTN.setEnabled(True) self.Error_Message.setText("Settings Read successfully!") except SQLException as e: self.Error_Message.setText("Error Reading Settings Database") stmt.close() dbConn.close() # Save entries from the GUI to the database. def SaveSettings(self, e): head, tail = os.path.split(os.path.abspath(__file__)) settings_db = os.path.join(head, "GUI_Settings.db3") try: Class.forName("org.sqlite.JDBC").newInstance() dbConn = DriverManager.getConnection("jdbc:sqlite:%s" % settings_db) except SQLException as e: self.Error_Message.setText("Error Opening Settings") try: stmt = dbConn.createStatement() SQL_Statement = 'Insert into settings (Setting_Name, Setting_Value) values ("Program_Exec_Name", "' + \ self.Program_Executable_TF.getText() + '");' resultSet = stmt.executeQuery(SQL_Statement) self.Error_Message.setText("Settings Saved") except SQLException as e: self.Error_Message.setText("Error Inserting Settings " + str(e)) stmt.close() dbConn.close() # When button to find file is clicked then open dialog to find the file and return it. def onClick(self, e): chooseFile = JFileChooser() filter = FileNameExtensionFilter("SQLite", ["sqlite"]) chooseFile.addChoosableFileFilter(filter) ret = chooseFile.showDialog(self.panel0, "Select SQLite") if ret == JFileChooser.APPROVE_OPTION: file = chooseFile.getSelectedFile() Canonical_file = file.getCanonicalPath() #text = self.readPath(file) self.local_settings.setSetting('ExecFile', Canonical_file) self.Program_Executable_TF.setText(Canonical_file) # Create the initial data fields/layout in the UI def initComponents(self): self.panel0 = JPanel() self.rbgPanel0 = ButtonGroup() self.gbPanel0 = GridBagLayout() self.gbcPanel0 = GridBagConstraints() self.panel0.setLayout( self.gbPanel0 ) self.Exec_Program_CB = JCheckBox("Execute Program", actionPerformed=self.checkBoxEvent) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 1 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints( self.Exec_Program_CB, self.gbcPanel0 ) self.panel0.add( self.Exec_Program_CB ) self.Program_Executable_TF = JTextField(20) self.Program_Executable_TF.setEnabled(False) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 3 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints( self.Program_Executable_TF, self.gbcPanel0 ) self.panel0.add( self.Program_Executable_TF ) self.Find_Program_Exec_BTN = JButton( "Find Exec", actionPerformed=self.onClick) self.Find_Program_Exec_BTN.setEnabled(False) self.rbgPanel0.add( self.Find_Program_Exec_BTN ) self.gbcPanel0.gridx = 6 self.gbcPanel0.gridy = 3 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints( self.Find_Program_Exec_BTN, self.gbcPanel0 ) self.panel0.add( self.Find_Program_Exec_BTN ) self.Blank_1 = JLabel( " ") self.Blank_1.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 5 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints( self.Blank_1, self.gbcPanel0 ) self.panel0.add( self.Blank_1 ) self.Save_Settings_BTN = JButton( "Save Settings", actionPerformed=self.SaveSettings) self.Save_Settings_BTN.setEnabled(True) self.rbgPanel0.add( self.Save_Settings_BTN ) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 7 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints( self.Save_Settings_BTN, self.gbcPanel0 ) self.panel0.add( self.Save_Settings_BTN ) self.Blank_2 = JLabel( " ") self.Blank_2.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 9 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints( self.Blank_2, self.gbcPanel0 ) self.panel0.add( self.Blank_2 ) self.Label_1 = JLabel( "Error Message:") self.Label_1.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 11 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints( self.Label_1, self.gbcPanel0 ) self.panel0.add( self.Label_1 ) self.Error_Message = JLabel( "") self.Error_Message.setEnabled(True) self.gbcPanel0.gridx = 6 self.gbcPanel0.gridy = 11 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints( self.Error_Message, self.gbcPanel0 ) self.panel0.add( self.Error_Message ) self.add(self.panel0) # Custom load any data field and initialize the values def customizeComponents(self): self.Exec_Program_CB.setSelected(self.local_settings.getSetting('Exec_Prog_Flag') == 'true') self.check_Database_entries() # Return the settings used def getSettings(self): return self.local_settings
def createAndShowGUI(self): ''' Create and display the gui. ''' layout = GridBagLayout() c = GridBagConstraints() self.setLayout(layout) projectLabel = Label("Project: ") c.gridx = 0 c.gridy = 0 c.ipady = 5 c.ipadx = 5 c.anchor = GridBagConstraints.EAST layout.setConstraints(projectLabel, c) self.projectChoice = Choice() for name in self.projectNames: self.projectChoice.add(name) c.gridx = 1 c.gridy = 0 c.fill = GridBagConstraints.HORIZONTAL layout.setConstraints(self.projectChoice, c) storageLabel = Label("Storage: ") c.gridx = 0 c.gridy = 1 c.fill = GridBagConstraints.NONE c.anchor = GridBagConstraints.EAST layout.setConstraints(storageLabel, c) self.storageChoice = Choice() for name in self.storageNames: self.storageChoice.add(name) c.gridx = 1 c.gridy = 1 c.fill = GridBagConstraints.HORIZONTAL layout.setConstraints(self.storageChoice, c) self.convertToOMETIFCheckBox = Checkbox("convert to OME-TIF", True) c.gridx = 1 c.gridy = 2 layout.setConstraints(self.convertToOMETIFCheckBox, c) self.uploadAsGroundTruthCheckBox = Checkbox("upload as ground-truth images") c.gridx = 1 c.gridy = 3 layout.setConstraints(self.uploadAsGroundTruthCheckBox, c) self.folderTextField = TextField("", 15) self.folderTextField.setText("<Image-Folder>") c.gridx = 0 c.gridy = 4 layout.setConstraints(self.folderTextField, c) self.folderTextField.setEditable(False) browseButton = Button('Browse...') browseButton.addActionListener(self) c.gridx = 1 c.gridy = 4 layout.setConstraints(browseButton, c) statusLabel = Label("Status:") c.gridy = 5 c.gridx = 0 c.fill = GridBagConstraints.NONE c.anchor = GridBagConstraints.EAST layout.setConstraints(statusLabel, c) self.statusTextField = TextField("Select a folder!", 20) c.gridy = 5 c.gridx = 1 c.fill = GridBagConstraints.HORIZONTAL layout.setConstraints(self.statusTextField, c) self.statusTextField.setEditable(False) self.uploadButton = Button("Upload Images") self.uploadButton.addActionListener(self) c.gridwidth = 2 c.gridheight = 2 c.gridy = 6 c.gridx = 0 c.weighty = 1.0 layout.setConstraints(self.uploadButton, c) self.add(projectLabel) self.add(self.projectChoice) self.add(storageLabel) self.add(self.storageChoice) self.add(self.convertToOMETIFCheckBox) self.add(self.uploadAsGroundTruthCheckBox) self.add(self.folderTextField) self.add(browseButton) self.add(statusLabel) self.add(self.statusTextField) self.add(self.uploadButton) self.setSize(400,300) self.setVisible(True)
class GUI_TestWithUISettingsPanel(IngestModuleIngestJobSettingsPanel): # Note, we can't use a self.settings instance variable. # Rather, self.local_settings is used. # https://wiki.python.org/jython/UserGuide#javabean-properties # Jython Introspector generates a property - 'settings' on the basis # of getSettings() defined in this class. Since only getter function # is present, it creates a read-only 'settings' property. This auto- # generated read-only property overshadows the instance-variable - # 'settings' # We get passed in a previous version of the settings so that we can # prepopulate the UI # TODO: Update this for your UI def __init__(self, settings): self.local_settings = settings self.initComponents() self.customizeComponents() # TODO: Update this for your UI def checkBoxEvent(self, event): if self.Exec_Program_CB.isSelected(): self.local_settings.setSetting('Exec_Prog_Flag', 'true') self.Program_Executable_TF.setEnabled(True) self.Find_Program_Exec_BTN.setEnabled(True) else: self.local_settings.setSetting('Exec_Prog_Flag', 'false') self.Program_Executable_TF.setText("") self.Program_Executable_TF.setEnabled(False) self.Find_Program_Exec_BTN.setEnabled(False) if self.Imp_File_CB.isSelected(): self.local_settings.setSetting('Imp_File_Flag', 'true') self.File_Imp_TF.setEnabled(True) self.Find_Imp_File_BTN.setEnabled(True) else: self.local_settings.setSetting('Imp_File_Flag', 'false') self.File_Imp_TF.setText("") self.local_settings.setSetting('File_Imp_TF', "") self.File_Imp_TF.setEnabled(False) self.Find_Imp_File_BTN.setEnabled(False) def keyPressed(self, event): self.local_settings.setSetting('Area', self.area.getText()) def onchange_cb(self, event): self.local_settings.setSetting('ComboBox', event.item) #self.Error_Message.setText(event.item) def onchange_lb(self, event): self.local_settings.setSetting('ListBox', "") list_selected = self.List_Box_LB.getSelectedValuesList() self.local_settings.setSetting('ListBox', str(list_selected)) # if (len(list_selected) > 0): # self.Error_Message.setText(str(list_selected)) # else: # self.Error_Message.setText("") def onClick(self, e): chooseFile = JFileChooser() filter = FileNameExtensionFilter("SQLite", ["sqlite"]) chooseFile.addChoosableFileFilter(filter) ret = chooseFile.showDialog(self.panel0, "Select SQLite") if ret == JFileChooser.APPROVE_OPTION: file = chooseFile.getSelectedFile() Canonical_file = file.getCanonicalPath() #text = self.readPath(file) if self.File_Imp_TF.isEnabled(): self.File_Imp_TF.setText(Canonical_file) self.local_settings.setSetting('File_Imp_TF', Canonical_file) else: self.local_settings.setSetting('ExecFile', Canonical_file) self.Program_Executable_TF.setText(Canonical_file) # TODO: Update this for your UI def initComponents(self): self.panel0 = JPanel() self.rbgPanel0 = ButtonGroup() self.gbPanel0 = GridBagLayout() self.gbcPanel0 = GridBagConstraints() self.panel0.setLayout( self.gbPanel0 ) self.Exec_Program_CB = JCheckBox("Execute Program", actionPerformed=self.checkBoxEvent) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 1 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints( self.Exec_Program_CB, self.gbcPanel0 ) self.panel0.add( self.Exec_Program_CB ) self.Program_Executable_TF = JTextField(20) self.Program_Executable_TF.setEnabled(False) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 3 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints( self.Program_Executable_TF, self.gbcPanel0 ) self.panel0.add( self.Program_Executable_TF ) self.Find_Program_Exec_BTN = JButton( "Find Exec", actionPerformed=self.onClick) self.Find_Program_Exec_BTN.setEnabled(False) self.rbgPanel0.add( self.Find_Program_Exec_BTN ) self.gbcPanel0.gridx = 6 self.gbcPanel0.gridy = 3 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints( self.Find_Program_Exec_BTN, self.gbcPanel0 ) self.panel0.add( self.Find_Program_Exec_BTN ) self.Imp_File_CB = JCheckBox( "Import File", actionPerformed=self.checkBoxEvent) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 5 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints( self.Imp_File_CB, self.gbcPanel0 ) self.panel0.add( self.Imp_File_CB ) self.File_Imp_TF = JTextField(20) self.File_Imp_TF.setEnabled(False) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 7 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints( self.File_Imp_TF, self.gbcPanel0 ) self.panel0.add( self.File_Imp_TF ) self.Find_Imp_File_BTN = JButton( "Find File", actionPerformed=self.onClick) self.Find_Imp_File_BTN.setEnabled(False) self.rbgPanel0.add( self.Find_Imp_File_BTN ) self.gbcPanel0.gridx = 6 self.gbcPanel0.gridy = 7 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints( self.Find_Imp_File_BTN, self.gbcPanel0 ) self.panel0.add( self.Find_Imp_File_BTN ) self.Check_Box_CB = JCheckBox( "Check Box 1", actionPerformed=self.checkBoxEvent) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 9 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints( self.Check_Box_CB, self.gbcPanel0 ) self.panel0.add( self.Check_Box_CB ) self.dataComboBox_CB = ("Chocolate", "Ice Cream", "Apple Pie") self.ComboBox_CB = JComboBox( self.dataComboBox_CB) self.ComboBox_CB.itemStateChanged = self.onchange_cb self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 11 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints( self.ComboBox_CB, self.gbcPanel0 ) self.panel0.add( self.ComboBox_CB ) self.dataList_Box_LB = ("Chocolate", "Ice Cream", "Apple Pie", "Pudding", "Candy" ) self.List_Box_LB = JList( self.dataList_Box_LB, valueChanged=self.onchange_lb) #self.List_Box_LB.itemStateChanged = self.onchange_lb self.List_Box_LB.setVisibleRowCount( 3 ) self.scpList_Box_LB = JScrollPane( self.List_Box_LB ) self.gbcPanel0.gridx = 6 self.gbcPanel0.gridy = 15 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 1 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints( self.scpList_Box_LB, self.gbcPanel0 ) self.panel0.add( self.scpList_Box_LB ) # self.Radio_Button_RB = JRadioButton( "Radio Button" ) # self.rbgPanel0.add( self.Radio_Button_RB ) # self.gbcPanel0.gridx = 7 # self.gbcPanel0.gridy = 17 # self.gbcPanel0.gridwidth = 1 # self.gbcPanel0.gridheight = 1 # self.gbcPanel0.fill = GridBagConstraints.BOTH # self.gbcPanel0.weightx = 1 # self.gbcPanel0.weighty = 0 # self.gbcPanel0.anchor = GridBagConstraints.NORTH # self.gbPanel0.setConstraints( self.Radio_Button_RB, self.gbcPanel0 ) # self.panel0.add( self.Radio_Button_RB ) # self.Label_1 = JLabel( "Error Message:") # self.Label_1.setEnabled(True) # self.gbcPanel0.gridx = 2 # self.gbcPanel0.gridy = 19 # self.gbcPanel0.gridwidth = 1 # self.gbcPanel0.gridheight = 1 # self.gbcPanel0.fill = GridBagConstraints.BOTH # self.gbcPanel0.weightx = 1 # self.gbcPanel0.weighty = 0 # self.gbcPanel0.anchor = GridBagConstraints.NORTH # self.gbPanel0.setConstraints( self.Label_1, self.gbcPanel0 ) # self.panel0.add( self.Label_1 ) # self.Error_Message = JLabel( "") # self.Error_Message.setEnabled(True) # self.gbcPanel0.gridx = 6 # self.gbcPanel0.gridy = 19 # self.gbcPanel0.gridwidth = 1 # self.gbcPanel0.gridheight = 1 # self.gbcPanel0.fill = GridBagConstraints.BOTH # self.gbcPanel0.weightx = 1 # self.gbcPanel0.weighty = 0 # self.gbcPanel0.anchor = GridBagConstraints.NORTH # self.gbPanel0.setConstraints( self.Error_Message, self.gbcPanel0 ) # self.panel0.add( self.Error_Message ) self.add(self.panel0) # TODO: Update this for your UI def customizeComponents(self): self.Exec_Program_CB.setSelected(self.local_settings.getSetting('Exec_Prog_Flag') == 'true') self.Imp_File_CB.setSelected(self.local_settings.getSetting('Imp_File_Flag') == 'true') self.Check_Box_CB.setSelected(self.local_settings.getSetting('Check_Box_1') == 'true') # Return the settings used def getSettings(self): return self.local_settings
class TimesketchSettingsWithUISettingsPanel(IngestModuleIngestJobSettingsPanel): # Note, we can't use a self.settings instance variable. # Rather, self.local_settings is used. # https://wiki.python.org/jython/UserGuide#javabean-properties # Jython Introspector generates a property - 'settings' on the basis # of getSettings() defined in this class. Since only getter function # is present, it creates a read-only 'settings' property. This auto- # generated read-only property overshadows the instance-variable - # 'settings' # We get passed in a previous version of the settings so that we can # prepopulate the UI def __init__(self, settings): self.local_settings = settings self.tag_list = [] self.initComponents() self.customizeComponents() self.path_to_Timesketch_exe = os.path.join(os.path.dirname(os.path.abspath(__file__)), "Timesketch_api.exe") # Check to see if the Timesketch server is available and you can talk to it def Check_Server(self, e): pipe = Popen([self.path_to_Timesketch_exe, self.Protocol_TF.getText(),self.IP_Address_TF.getText(), self.Port_Number_TF.getText(), "Timesketch_status" ], stdout=PIPE, stderr=PIPE) out_text = pipe.communicate()[0] self.Error_Message.setText("Timesketch Status is " + out_text) #self.log(Level.INFO, "Timesketch Status is ==> " + out_text) def setIPAddress(self, event): self.local_settings.setSetting('ipAddress', self.IP_Address_TF.getText()) def setPortNumber(self, event): self.local_settings.setSetting('portNumber', self.Port_Number_TF.getText()) def setUserName(self, event): self.local_settings.setSetting('userName', self.userName_TF.getText()) def setPassword(self, event): self.local_settings.setSetting('password', self.password_TF.getText()) def setsketchName(self, event): self.local_settings.setSetting('sketchName', self.sketchName_TF.getText()) def setsketchDescription(self, event): self.local_settings.setSetting('sketchDescription', self.sketchDescription_TF.getText()) # Create the initial data fields/layout in the UI def initComponents(self): self.panel0 = JPanel() self.rbgPanel0 = ButtonGroup() self.gbPanel0 = GridBagLayout() self.gbcPanel0 = GridBagConstraints() self.panel0.setLayout( self.gbPanel0 ) self.Label_2 = JLabel("Timesketch IP Address") self.Label_2.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 5 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints( self.Label_2, self.gbcPanel0 ) self.panel0.add( self.Label_2 ) self.IP_Address_TF = JTextField(20, focusLost=self.setIPAddress) self.IP_Address_TF.setEnabled(True) self.gbcPanel0.gridx = 4 self.gbcPanel0.gridy = 5 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints( self.IP_Address_TF, self.gbcPanel0 ) self.panel0.add( self.IP_Address_TF ) self.Blank_2 = JLabel( " ") self.Blank_2.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 7 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints( self.Blank_2, self.gbcPanel0 ) self.panel0.add( self.Blank_2 ) self.Label_3 = JLabel("Port Number") self.Label_3.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 9 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints( self.Label_3, self.gbcPanel0 ) self.panel0.add( self.Label_3 ) self.Port_Number_TF = JTextField(20, focusLost=self.setPortNumber) self.Port_Number_TF.setEnabled(True) self.gbcPanel0.gridx = 4 self.gbcPanel0.gridy = 9 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints( self.Port_Number_TF, self.gbcPanel0 ) self.panel0.add( self.Port_Number_TF ) self.Blank_3 = JLabel( " ") self.Blank_3.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 11 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints( self.Blank_3, self.gbcPanel0 ) self.panel0.add( self.Blank_3 ) self.Label_4 = JLabel("User Name") self.Label_4.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 13 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints( self.Label_4, self.gbcPanel0 ) self.panel0.add( self.Label_4 ) self.userName_TF = JTextField(20, focusLost=self.setUserName) self.userName_TF.setEnabled(True) self.gbcPanel0.gridx = 4 self.gbcPanel0.gridy = 13 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints( self.userName_TF, self.gbcPanel0 ) self.panel0.add( self.userName_TF ) self.Blank_4 = JLabel( " ") self.Blank_4.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 15 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints( self.Blank_4, self.gbcPanel0 ) self.panel0.add( self.Blank_4 ) self.Label_5 = JLabel("Password") self.Label_5.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 17 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints( self.Label_5, self.gbcPanel0 ) self.panel0.add( self.Label_5 ) self.password_TF = JPasswordField(20, focusLost=self.setPassword) # self.password_TF = JTextField(20) self.password_TF.setEnabled(True) self.gbcPanel0.gridx = 4 self.gbcPanel0.gridy = 17 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints( self.password_TF, self.gbcPanel0 ) self.panel0.add( self.password_TF ) self.Blank_5 = JLabel( " ") self.Blank_5.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 19 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints( self.Blank_5, self.gbcPanel0 ) self.panel0.add( self.Blank_5 ) self.Label_6 = JLabel("Sketch Name") self.Label_6.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 21 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints( self.Label_6, self.gbcPanel0 ) self.panel0.add( self.Label_6 ) self.sketchName_TF = JTextField(20, focusLost=self.setsketchName) self.sketchName_TF.setEnabled(True) self.gbcPanel0.gridx = 4 self.gbcPanel0.gridy = 21 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints( self.sketchName_TF, self.gbcPanel0 ) self.panel0.add( self.sketchName_TF ) self.Blank_6 = JLabel( " ") self.Blank_6.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 23 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints( self.Blank_6, self.gbcPanel0 ) self.panel0.add( self.Blank_6 ) self.Label_7 = JLabel("Sketch Description") self.Label_7.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 25 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints( self.Label_7, self.gbcPanel0 ) self.panel0.add( self.Label_7 ) self.sketchDescription_TF = JTextField(20, focusLost=self.setsketchDescription) self.sketchDescription_TF.setEnabled(True) self.gbcPanel0.gridx = 4 self.gbcPanel0.gridy = 25 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints( self.sketchDescription_TF, self.gbcPanel0 ) self.panel0.add( self.sketchDescription_TF ) self.Blank_7 = JLabel( " ") self.Blank_7.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 27 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints( self.Blank_7, self.gbcPanel0 ) self.panel0.add( self.Blank_7 ) # self.Check_Server_Status_BTN = JButton( "Check Server Status", actionPerformed=self.Check_Server) # self.Check_Server_Status_BTN.setEnabled(True) # self.rbgPanel0.add( self.Save_Settings_BTN ) # self.gbcPanel0.gridx = 2 # self.gbcPanel0.gridy = 29 # self.gbcPanel0.gridwidth = 1 # self.gbcPanel0.gridheight = 1 # self.gbcPanel0.fill = GridBagConstraints.BOTH # self.gbcPanel0.weightx = 1 # self.gbcPanel0.weighty = 0 # self.gbcPanel0.anchor = GridBagConstraints.NORTH # self.gbPanel0.setConstraints( self.Check_Server_Status_BTN, self.gbcPanel0 ) # self.panel0.add( self.Check_Server_Status_BTN ) self.Error_Message = JLabel( "") self.Error_Message.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 31 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints( self.Error_Message, self.gbcPanel0 ) self.panel0.add( self.Error_Message ) self.add(self.panel0) # Custom load any data field and initialize the values def customizeComponents(self): #self.Exclude_File_Sources_CB.setSelected(self.local_settings.getExclude_File_Sources()) #self.Run_Timesketch_CB.setSelected(self.local_settings.getRun_Timesketch()) #self.Import_Timesketch_CB.setSelected(self.local_settings.getImport_Timesketch()) #self.check_Database_entries() self.IP_Address_TF.setText(self.local_settings.getSetting('ipAddress')) self.Port_Number_TF.setText(self.local_settings.getSetting('portNumber')) self.userName_TF.setText(self.local_settings.getSetting('userName')) self.password_TF.setText(self.local_settings.getSetting('password')) self.sketchName_TF.setText(Case.getCurrentCase().getNumber()) self.sketchDescription_TF.setText(Case.getCurrentCase().getName()) self.local_settings.setSetting('sketchName', self.sketchName_TF.getText()) self.local_settings.setSetting('sketchDescription', self.sketchDescription_TF.getText()) # Return the settings used def getSettings(self): return self.local_settings
class GUI_Test_SQLSettingsWithUISettingsPanel( IngestModuleIngestJobSettingsPanel): # Note, we can't use a self.settings instance variable. # Rather, self.local_settings is used. # https://wiki.python.org/jython/UserGuide#javabean-properties # Jython Introspector generates a property - 'settings' on the basis # of getSettings() defined in this class. Since only getter function # is present, it creates a read-only 'settings' property. This auto- # generated read-only property overshadows the instance-variable - # 'settings' # We get passed in a previous version of the settings so that we can # prepopulate the UI # TODO: Update this for your UI def __init__(self, settings): self.local_settings = settings self.initComponents() self.customizeComponents() # Check the checkboxs to see what actions need to be taken def checkBoxEvent(self, event): if self.Exec_Program_CB.isSelected(): self.local_settings.setSetting('Exec_Prog_Flag', 'true') self.Program_Executable_TF.setEnabled(True) self.Find_Program_Exec_BTN.setEnabled(True) else: self.local_settings.setSetting('Exec_Prog_Flag', 'false') self.Program_Executable_TF.setText("") self.Program_Executable_TF.setEnabled(False) self.Find_Program_Exec_BTN.setEnabled(False) # Check to see if there are any entries that need to be populated from the database. def check_Database_entries(self): head, tail = os.path.split(os.path.abspath(__file__)) settings_db = os.path.join(head, "GUI_Settings.db3") try: Class.forName("org.sqlite.JDBC").newInstance() dbConn = DriverManager.getConnection("jdbc:sqlite:%s" % settings_db) except SQLException as e: self.Error_Message.setText("Error Opening Settings DB!") try: stmt = dbConn.createStatement() SQL_Statement = 'Select Setting_Name, Setting_Value from settings;' resultSet = stmt.executeQuery(SQL_Statement) while resultSet.next(): if resultSet.getString("Setting_Name") == "Program_Exec_Name": self.Program_Executable_TF.setText( resultSet.getString("Setting_Value")) self.local_settings.setSetting( 'ExecFile', resultSet.getString("Setting_Value")) self.local_settings.setSetting('Exec_Prog_Flag', 'true') self.Exec_Program_CB.setSelected(True) self.Program_Executable_TF.setEnabled(True) self.Find_Program_Exec_BTN.setEnabled(True) self.Error_Message.setText("Settings Read successfully!") except SQLException as e: self.Error_Message.setText("Error Reading Settings Database") stmt.close() dbConn.close() # Save entries from the GUI to the database. def SaveSettings(self, e): head, tail = os.path.split(os.path.abspath(__file__)) settings_db = os.path.join(head, "GUI_Settings.db3") try: Class.forName("org.sqlite.JDBC").newInstance() dbConn = DriverManager.getConnection("jdbc:sqlite:%s" % settings_db) except SQLException as e: self.Error_Message.setText("Error Opening Settings") try: stmt = dbConn.createStatement() SQL_Statement = 'Insert into settings (Setting_Name, Setting_Value) values ("Program_Exec_Name", "' + \ self.Program_Executable_TF.getText() + '");' resultSet = stmt.executeQuery(SQL_Statement) self.Error_Message.setText("Settings Saved") except SQLException as e: self.Error_Message.setText("Error Inserting Settings " + str(e)) stmt.close() dbConn.close() # When button to find file is clicked then open dialog to find the file and return it. def onClick(self, e): chooseFile = JFileChooser() filter = FileNameExtensionFilter("SQLite", ["sqlite"]) chooseFile.addChoosableFileFilter(filter) ret = chooseFile.showDialog(self.panel0, "Select SQLite") if ret == JFileChooser.APPROVE_OPTION: file = chooseFile.getSelectedFile() Canonical_file = file.getCanonicalPath() #text = self.readPath(file) self.local_settings.setSetting('ExecFile', Canonical_file) self.Program_Executable_TF.setText(Canonical_file) # Create the initial data fields/layout in the UI def initComponents(self): self.panel0 = JPanel() self.rbgPanel0 = ButtonGroup() self.gbPanel0 = GridBagLayout() self.gbcPanel0 = GridBagConstraints() self.panel0.setLayout(self.gbPanel0) self.Exec_Program_CB = JCheckBox("Execute Program", actionPerformed=self.checkBoxEvent) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 1 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.Exec_Program_CB, self.gbcPanel0) self.panel0.add(self.Exec_Program_CB) self.Program_Executable_TF = JTextField(20) self.Program_Executable_TF.setEnabled(False) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 3 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.Program_Executable_TF, self.gbcPanel0) self.panel0.add(self.Program_Executable_TF) self.Find_Program_Exec_BTN = JButton("Find Exec", actionPerformed=self.onClick) self.Find_Program_Exec_BTN.setEnabled(False) self.rbgPanel0.add(self.Find_Program_Exec_BTN) self.gbcPanel0.gridx = 6 self.gbcPanel0.gridy = 3 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.Find_Program_Exec_BTN, self.gbcPanel0) self.panel0.add(self.Find_Program_Exec_BTN) self.Blank_1 = JLabel(" ") self.Blank_1.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 5 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.Blank_1, self.gbcPanel0) self.panel0.add(self.Blank_1) self.Save_Settings_BTN = JButton("Save Settings", actionPerformed=self.SaveSettings) self.Save_Settings_BTN.setEnabled(True) self.rbgPanel0.add(self.Save_Settings_BTN) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 7 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.Save_Settings_BTN, self.gbcPanel0) self.panel0.add(self.Save_Settings_BTN) self.Blank_2 = JLabel(" ") self.Blank_2.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 9 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.Blank_2, self.gbcPanel0) self.panel0.add(self.Blank_2) self.Label_1 = JLabel("Error Message:") self.Label_1.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 11 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.Label_1, self.gbcPanel0) self.panel0.add(self.Label_1) self.Error_Message = JLabel("") self.Error_Message.setEnabled(True) self.gbcPanel0.gridx = 6 self.gbcPanel0.gridy = 11 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.Error_Message, self.gbcPanel0) self.panel0.add(self.Error_Message) self.add(self.panel0) # Custom load any data field and initialize the values def customizeComponents(self): self.Exec_Program_CB.setSelected( self.local_settings.getSetting('Exec_Prog_Flag') == 'true') self.check_Database_entries() # Return the settings used def getSettings(self): return self.local_settings
class MassExportByExtensionSettingsWithUISettingsPanel( IngestModuleIngestJobSettingsPanel): # Note, we can't use a self.settings instance variable. # Rather, self.local_settings is used. # https://wiki.python.org/jython/UserGuide#javabean-properties # Jython Introspector generates a property - 'settings' on the basis # of getSettings() defined in this class. Since only getter function # is present, it creates a read-only 'settings' property. This auto- # generated read-only property overshadows the instance-variable - # 'settings' # We get passed in a previous version of the settings so that we can # prepopulate the UI def __init__(self, settings): self.local_settings = settings self.tag_list = [] self.initComponents() self.customizeComponents() def setFileExtension(self, event): self.local_settings.setSetting('fileExtension', self.fileExtension_TF.getText()) # Create the initial data fields/layout in the UI def initComponents(self): self.panel0 = JPanel() self.rbgPanel0 = ButtonGroup() self.gbPanel0 = GridBagLayout() self.gbcPanel0 = GridBagConstraints() self.panel0.setLayout(self.gbPanel0) self.Label_2 = JLabel( "List of File Extensions to Export, Comma Seperated no dots (.)") self.Label_2.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 5 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.Label_2, self.gbcPanel0) self.panel0.add(self.Label_2) self.fileExtension_TF = JTextField(30, focusLost=self.setFileExtension) self.fileExtension_TF.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 7 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.fileExtension_TF, self.gbcPanel0) self.panel0.add(self.fileExtension_TF) self.Blank_2 = JLabel(" ") self.Blank_2.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 9 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.Blank_2, self.gbcPanel0) self.panel0.add(self.Blank_2) self.add(self.panel0) # Custom load any data field and initialize the values def customizeComponents(self): self.fileExtension_TF.setText( self.local_settings.getSetting('fileExtension')) # Return the settings used def getSettings(self): return self.local_settings
def makeCropUI(imp, images, tgtDir, panel=None, cropContinuationFn=None): """ imp: the ImagePlus to work on. images: the list of ImgLib2 images, one per frame, not original but already isotropic. (These are views that use a nearest neighbor interpolation using the calibration to scale to isotropy.) tgtDir: the target directory where e.g. CSV files will be stored, for ROI, features, pointmatches. panel: optional, a JPanel controlled by a GridBagLayout. cropContinuationFn: optional, a function to execute after cropping, which is given as arguments the original images, minC, maxC (both define a ROI), and the cropped images. """ independent = None == panel if not panel: panel = JPanel() panel.setBorder(BorderFactory.createEmptyBorder(10,10,10,10)) gb = GridBagLayout() gc = GBC() else: gb = panel.getLayout() # Constraints of the last component gc = gb.getConstraints(panel.getComponent(panel.getComponentCount() - 1)) # Horizontal line to separate prior UI components from crop UI gc.gridx = 0 gc.gridy += 1 gc.gridwidth = 4 gc.anchor = GBC.WEST gc.fill = GBC.HORIZONTAL sep = JSeparator() sep.setMinimumSize(Dimension(200, 10)) gb.setConstraints(sep, gc) panel.add(sep) # ROI UI header title = JLabel("ROI controls:") gc.gridy +=1 gc.anchor = GBC.WEST gc.gridwidth = 4 gb.setConstraints(title, gc) panel.add(title) # Column labels for the min and max coordinates gc.gridy += 1 gc.gridwidth = 1 for i, title in enumerate(["", "X", "Y", "Z"]): gc.gridx = i gc.anchor = GBC.CENTER label = JLabel(title) gb.setConstraints(label, gc) panel.add(label) textfields = [] rms = [] # Load stored ROI if any roi_path = path = os.path.join(tgtDir, "crop-roi.csv") if os.path.exists(roi_path): with open(roi_path, 'r') as csvfile: reader = csv.reader(csvfile, delimiter=',', quotechar="\"") reader.next() # header minC = map(int, reader.next()[1:]) maxC = map(int, reader.next()[1:]) # Place the ROI over the ImagePlus imp.setRoi(Roi(minC[0], minC[1], maxC[0] + 1 - minC[0], maxC[1] + 1 - minC[1])) else: # Use whole image dimensions minC = [0, 0, 0] maxC = [v -1 for v in Intervals.dimensionsAsLongArray(images[0])] # Text fields for the min and max coordinates for rowLabel, coords in izip(["min coords: ", "max coords: "], [minC, maxC]): gc.gridx = 0 gc.gridy += 1 label = JLabel(rowLabel) gb.setConstraints(label, gc) panel.add(label) for i in xrange(3): gc.gridx += 1 tf = JTextField(str(coords[i]), 10) gb.setConstraints(tf, gc) panel.add(tf) textfields.append(tf) listener = RoiMaker(imp, textfields, len(textfields) -1) rms.append(listener) tf.addKeyListener(listener) tf.addMouseWheelListener(listener) # Listen to changes in the ROI of imp rfl = RoiFieldListener(imp, textfields) Roi.addRoiListener(rfl) # ... and enable cleanup ImagePlus.addImageListener(FieldDisabler(rfl, rms)) # Functions for cropping images cropped = None cropped_imp = None def storeRoi(minC, maxC): if os.path.exists(roi_path): # Load ROI with open(path, 'r') as csvfile: reader = csv.reader(csvfile, delimiter=',', quotechar="\"") reader.next() # header same = True for a, b in izip(minC + maxC, map(int, reader.next()[1:] + reader.next()[1:])): if a != b: same = False # Invalidate any CSV files for features and pointmatches: different cropping for filename in os.listdir(tgtDir): if filename.endswith("features.csv") or filename.endswith("pointmatches.csv"): os.remove(os.path.join(tgtDir, filename)) break if same: return # Store the ROI as crop-roi.csv with open(roi_path, 'w') as csvfile: w = csv.writer(csvfile, delimiter=',', quotechar="\"", quoting=csv.QUOTE_NONNUMERIC) w.writerow(["coords", "x", "y", "z"]) w.writerow(["min"] + map(int, minC)) w.writerow(["max"] + map(int, maxC)) def crop(event): global cropped, cropped_imp coords = [int(float(tf.getText())) for tf in textfields] minC = [max(0, c) for c in coords[0:3]] maxC = [min(d -1, c) for d, c in izip(Intervals.dimensionsAsLongArray(images[0]), coords[3:6])] storeRoi(minC, maxC) print "ROI min and max coordinates" print minC print maxC cropped = [Views.zeroMin(Views.interval(img, minC, maxC)) for img in images] cropped_imp = showAsStack(cropped, title="cropped") cropped_imp.setDisplayRange(imp.getDisplayRangeMin(), imp.getDisplayRangeMax()) if cropContinuationFn: cropContinuationFn(images, minC, maxC, cropped, cropped_imp) # Buttons to create a ROI and to crop to ROI, # which when activated enables the fine registration buttons crop_button = JButton("Crop to ROI") crop_button.addActionListener(crop) gc.gridx = 0 gc.gridy += 1 gc.gridwidth = 4 gc.anchor = GBC.WEST buttons_panel = JPanel() buttons_panel.add(crop_button) gb.setConstraints(buttons_panel, gc) panel.add(buttons_panel) if independent: frame = JFrame("Crop by ROI") frame.getContentPane().add(panel) frame.pack() frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE) frame.addWindowListener(CloseControl(destroyables=rms + [rfl])) frame.setVisible(True) else: # Re-pack the JFrame parent = panel.getParent() while not isinstance(parent, JFrame) and parent is not None: parent = parent.getParent() if parent: frame = parent frame.pack() found = False for wl in frame.getWindowListeners(): if isinstance(wl, CloseControl): wl.addDestroyables(rms + [rfl]) found = True break if not found: frame.addWindowListener(CloseControl(destroyables=rms + [rfl])) frame.setVisible(True) return panel
class Plaso_ImportSettingsWithUISettingsPanel( IngestModuleIngestJobSettingsPanel): # Note, we can't use a self.settings instance variable. # Rather, self.local_settings is used. # https://wiki.python.org/jython/UserGuide#javabean-properties # Jython Introspector generates a property - 'settings' on the basis # of getSettings() defined in this class. Since only getter function # is present, it creates a read-only 'settings' property. This auto- # generated read-only property overshadows the instance-variable - # 'settings' # We get passed in a previous version of the settings so that we can # prepopulate the UI # TODO: Update this for your UI def __init__(self, settings): self.local_settings = settings self.initComponents() self.customizeComponents() # Check the checkboxs to see what actions need to be taken def checkBoxEvent(self, event): if self.Exclude_File_Sources_CB.isSelected(): self.local_settings.setSetting('Exclude_File_Sources', 'true') else: self.local_settings.setSetting('Exclude_File_Sources', 'false') # When button to find file is clicked then open dialog to find the file and return it. def Find_Plaso_Dir(self, e): chooseFile = JFileChooser() filter = FileNameExtensionFilter("All", ["*.*"]) chooseFile.addChoosableFileFilter(filter) chooseFile.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY) ret = chooseFile.showDialog(self.panel0, "Find Plaso Directory") if ret == JFileChooser.APPROVE_OPTION: file = chooseFile.getSelectedFile() Canonical_file = file.getCanonicalPath() #text = self.readPath(file) self.local_settings.setSetting('Plaso_Directory', Canonical_file) self.Program_Executable_TF.setText(Canonical_file) def Find_Plaso_File(self, e): chooseFile = JFileChooser() filter = FileNameExtensionFilter("All", ["*.*"]) chooseFile.addChoosableFileFilter(filter) ret = chooseFile.showDialog(self.panel0, "Find Plaso Storage File") if ret == JFileChooser.APPROVE_OPTION: file = chooseFile.getSelectedFile() Canonical_file = file.getCanonicalPath() #text = self.readPath(file) self.local_settings.setSetting('Plaso_Storage_File', Canonical_file) self.Plaso_Storage_File_TF.setText(Canonical_file) def setPlasoDirectory(self, event): self.local_settings.setSetting('Plaso_Directory', self.Program_Executable_TF.getText()) def setPlasoStorageFile(self, event): self.local_settings.setSetting('Plaso_Storage_File', self.Plaso_Storage_File_TF.getText()) # Create the initial data fields/layout in the UI def initComponents(self): self.panel0 = JPanel() self.rbgPanel0 = ButtonGroup() self.gbPanel0 = GridBagLayout() self.gbcPanel0 = GridBagConstraints() self.panel0.setLayout(self.gbPanel0) self.Label_1 = JLabel("Plaso Executable Directory") self.Label_1.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 1 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.Label_1, self.gbcPanel0) self.panel0.add(self.Label_1) self.Program_Executable_TF = JTextField( 20, focusLost=self.setPlasoDirectory) self.Program_Executable_TF.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 3 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.Program_Executable_TF, self.gbcPanel0) self.panel0.add(self.Program_Executable_TF) self.Find_Program_Exec_BTN = JButton( "Find Dir", actionPerformed=self.Find_Plaso_Dir) self.Find_Program_Exec_BTN.setEnabled(True) self.rbgPanel0.add(self.Find_Program_Exec_BTN) self.gbcPanel0.gridx = 6 self.gbcPanel0.gridy = 3 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.Find_Program_Exec_BTN, self.gbcPanel0) self.panel0.add(self.Find_Program_Exec_BTN) self.Blank_1 = JLabel(" ") self.Blank_1.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 5 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.Blank_1, self.gbcPanel0) self.panel0.add(self.Blank_1) self.Label_1 = JLabel("Plaso Storage File") self.Label_1.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 7 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.Label_1, self.gbcPanel0) self.panel0.add(self.Label_1) self.Plaso_Storage_File_TF = JTextField( 20, focusLost=self.setPlasoStorageFile) self.Plaso_Storage_File_TF.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 9 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.Plaso_Storage_File_TF, self.gbcPanel0) self.panel0.add(self.Plaso_Storage_File_TF) self.Find_Storage_BTN = JButton("Find Storage File", actionPerformed=self.Find_Plaso_File) self.Find_Storage_BTN.setEnabled(True) self.rbgPanel0.add(self.Find_Storage_BTN) self.gbcPanel0.gridx = 6 self.gbcPanel0.gridy = 9 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.Find_Storage_BTN, self.gbcPanel0) self.panel0.add(self.Find_Storage_BTN) self.Blank_3 = JLabel(" ") self.Blank_3.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 13 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.Blank_3, self.gbcPanel0) self.panel0.add(self.Blank_3) self.Exclude_File_Sources_CB = JCheckBox( "Exclude File Source", actionPerformed=self.checkBoxEvent) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 15 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.Exclude_File_Sources_CB, self.gbcPanel0) self.panel0.add(self.Exclude_File_Sources_CB) self.Blank_4 = JLabel(" ") self.Blank_4.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 17 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.Blank_4, self.gbcPanel0) self.panel0.add(self.Blank_4) self.Label_3 = JLabel("Message:") self.Label_3.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 19 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.Label_3, self.gbcPanel0) self.panel0.add(self.Label_3) self.Error_Message = JLabel("") self.Error_Message.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 23 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.Error_Message, self.gbcPanel0) self.panel0.add(self.Error_Message) self.add(self.panel0) # Custom load any data field and initialize the values def customizeComponents(self): self.Exclude_File_Sources_CB.setSelected( self.local_settings.getSetting('Exclude_File_Sources') == 'true') self.Program_Executable_TF.setText( self.local_settings.getSetting('Plaso_Directory')) self.Plaso_Storage_File_TF.setText( self.local_settings.getSetting('Plaso_Storage_File')) # Return the settings used def getSettings(self): return self.local_settings
def generateDeconvolutionScriptUI(srcDir, tgtDir, calibration, preCropAffines, ROI, postCropAffines): """ Open an UI to automatically generate a script to: 1. Register the views of each time point TM folder, and deconvolve them. 2. Register deconvolved time points to each other, for a range of consecutive time points. Will ask for the file path to the kernel file, and also for the range of time points to process, and for the deconvolution iterations for CM00-CM01, and CM02-CM03. """ template = """ # AUTOMATICALLY GENERATED - %s import sys, os sys.path.append("%s") from lib.isoview import deconvolveTimePoints from mpicbg.models import RigidModel3D, TranslationModel3D from net.imglib2.img.display.imagej import ImageJFunctions as IL # The folder with the sequence of TM\d+ folders, one per time point in the 4D series. # Each folder should contain 4 KLB files, one per camera view of the IsoView microscope. srcDir = "%s" # A folder to save deconvolved images in, and CSV files describing features, point matches and transformations targetDir = "%s" # Path to the volume describing the point spread function (PSF) kernelPath = "%s" calibration = [%s] # An array with 3 floats (identity--all 1.0--because the coarse affines, that is, # the camera transformations, already include the scaling to isotropy computed using the original calibration. # The transformations of each timepoint onto the camera at index zero. def cameraTransformations(dims0, dims1, dims2, dims3, calibration): return { 0: [%s], 1: [%s], 2: [%s], 3: [%s] } # Deconvolution parameters paramsDeconvolution = { "blockSizes": None, # None means the image size + kernel size. Otherwise specify like e.g. [[128, 128, 128]] for img in images] "CM_0_1_n_iterations": %i, "CM_2_3_n_iterations": %i, } # Joint dictionary of parameters params = {} params.update(paramsDeconvolution) # A region of interest for each camera view, for cropping after registration but prior to deconvolution roi = ([%s], # array of 3 integers, top-left coordinates [%s]) # array of 3 integers, bottom-right coordinates # All 4 cameras relative to CM00 fineTransformsPostROICrop = \ [[1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0], [%s], [%s], [%s]] deconvolveTimePoints(srcDir, targetDir, kernelPath, calibration, cameraTransformations, fineTransformsPostROICrop, params, roi, fine_fwd=True, subrange=range(%i, %i)) """ od = OpenDialog("Choose kernel file", srcDir) kernel_path = od.getPath() if not kernel_path: JOptionPane.showMessageDialog(None, "Can't proceed without a filepath to the kernel", "Alert", JOptionPane.ERROR_MESSAGE) return panel = JPanel() panel.setBorder(BorderFactory.createEmptyBorder(10,10,10,10)) gb = GridBagLayout() panel.setLayout(gb) gc = GBC() msg = ["Edit parameters, then push the button", "to generate a script that, when run,", "will execute the deconvolution for each time point", "saving two 3D stacks per time point as ZIP files", "in the target directory under subfolder 'deconvolved'.", "Find the script in a new Script Editor window.", " "] gc.gridy = -1 # init for line in msg: label = JLabel(line) gc.anchor = GBC.WEST gc.gridx = 0 gc.gridy += 1 gc.gridwidth = 2 gc.gridheight = 1 gb.setConstraints(label, gc) panel.add(label) strings = [["Deconvolution iterations", "CM_0_1_n_iterations", "CM_2_3_n_iterations"], ["Range", "First time point", "Last time point"]] params = {"CM_0_1_n_iterations": 5, "CM_2_3_n_iterations": 7, "First time point": 0, "Last time point": -1} # -1 means last insertFloatFields(panel, gb, gc, params, strings) def asString(affine): matrix = zeros(12, 'd') affine.toArray(matrix) return ",".join(imap(str, matrix)) def generateScript(event): script = template % (str(datetime.now()), filter(lambda path: path.endswith("IsoView-GCaMP"), sys.path)[-1], srcDir, tgtDir, kernel_path, ", ".join(imap(str, calibration)), asString(preCropAffines[0]), asString(preCropAffines[1]), asString(preCropAffines[2]), asString(preCropAffines[3]), params["CM_0_1_n_iterations"], params["CM_2_3_n_iterations"], ", ".join(imap(str, ROI[0])), ", ".join(imap(str, ROI[1])), asString(postCropAffines[1]), asString(postCropAffines[2]), asString(postCropAffines[3]), params["First time point"], params["Last time point"]) tab = None for frame in JFrame.getFrames(): if str(frame).startswith("org.scijava.ui.swing.script.TextEditor["): try: tab = frame.newTab(script, "python") break except: print sys.exc_info() if not tab: try: now = datetime.now() with open(os.path.join(System.getProperty("java.io.tmpdir"), "script-%i-%i-%i_%i:%i.py" % (now.year, now.month, now.day, now.hour, now.minute)), 'w') as f: f.write(script) except: print sys.exc_info() print script gen = JButton("Generate script") gen.addActionListener(generateScript) gc.anchor = GBC.CENTER gc.gridx = 0 gc.gridy += 1 gc.gridwidth = 2 gb.setConstraints(gen, gc) panel.add(gen) frame = JFrame("Generate deconvolution script") frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE) frame.getContentPane().add(panel) frame.pack() frame.setLocationRelativeTo(None) # center in the screen frame.setVisible(True)
class AutopsyImageClassificationModuleWithUISettingsPanel( IngestModuleIngestJobSettingsPanel): _logger = Logger.getLogger( AutopsyImageClassificationModuleFactory.moduleName) def log(self, level, msg): self._logger.logp(level, self.__class__.__name__, inspect.stack()[1][3], msg) def __init__(self, settings): self.local_settings = settings self.config_location = os.path.join( os.path.dirname(os.path.abspath(__file__)), 'configs.json') self.init_components() self.customize_components() self.check_server_connection(None) self.classes_of_interest_changes_list = list() self.classes_of_interest_checkboxes = list() # Return the settings used def getSettings(self): if not os.path.isfile(self.config_location): self.log( Level.INFO, "Configuration file not found, loading the default configuration" ) self.local_settings.setServerHost(DEFAULT_HOST) self.local_settings.setServerPort(DEFAULT_PORT) self.local_settings.setImageFormats(DEFAULT_IMAGES_FORMAT) self.local_settings.setMinFileSize(DEFAULT_MIN_FILE_SIZE) self.local_settings.setMinProbability(DEFAULT_MIN_PROBABILITY) self.local_settings.setClassesOfInterest( json.loads(DEFAULT_CLASSES_OF_INTEREST)) # self.saveSettings(None) return self.local_settings else: if not os.access(self.config_location, os.R_OK): err_string = "Cannot access configuration file, please review the file permissions" raise IngestModuleException(err_string) with io.open(self.config_location, 'r', encoding='utf-8') as f: self.log(Level.INFO, "Configuration file read") json_configs = json.load(f) self.local_settings.setServerHost(json_configs['server']['host']) self.local_settings.setServerPort(json_configs['server']['port']) image_formats = json_configs['imageFormats'] if not isinstance(image_formats, list) or len(image_formats) == 0: err_string = "Invalid list of image formats given" raise IngestModuleException(err_string) self.local_settings.setImageFormats(image_formats) self.local_settings.setMinFileSize(json_configs['minFileSize']) self.local_settings.setMinProbability( json_configs['minProbability']) self.local_settings.setClassesOfInterest( json_configs['classesOfInterest']) return self.local_settings def check_server_connection(self, e): message_string = "Testing connection with server..." self.log(Level.INFO, message_string) self.message.setText(message_string) self.error_message.setText("") new_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) new_socket.settimeout(1) try: new_socket.connect( (self.host_TF.getText(), int(self.port_TF.getText()))) self.local_settings.setIsServerOnline(True) message_string = "Server is up!" self.log(Level.INFO, message_string) self.message.setText(message_string) except (socket.timeout, socket.error) as e: self.local_settings.setIsServerOnline(False) err_string = "Server is down" self.error_message.setText(err_string) self.message.setText("") self.log(Level.INFO, err_string) finally: new_socket.close() def save_settings(self, e): self.message.setText("") self.log(Level.INFO, "Settings save button clicked!") host = self.host_TF.getText() if not host.strip(): err_string = "Invalid host" self.error_message.setText(err_string) return # raise IngestModuleException(err_string) port = self.port_TF.getText() if not host.strip(): err_string = "Invalid port number" self.error_message.setText(err_string) return # raise IngestModuleException(err_string) image_formats_array = self.image_formats_TF.getText().strip().split( ';') if len(image_formats_array) == 0 or not image_formats_array[0]: err_string = "Invalid image formats" self.error_message.setText(err_string) return # raise IngestModuleException(err_string) min_probability_string = self.min_probability_TF.getText().strip() if not min_probability_string: err_string = "Invalid minimum confidence value" self.error_message.setText(err_string) return # raise IngestModuleException(err_string) min_probability = int(float(min_probability_string)) min_file_size_string = self.min_file_size_TF.getText().strip() if not min_file_size_string: err_string = "Invalid minimum file size" self.error_message.setText(err_string) return # raise IngestModuleException(err_string) min_file_size = int(float(min_file_size_string)) configs = { 'server': { 'host': host, 'port': port }, 'imageFormats': image_formats_array, 'minProbability': min_probability, 'minFileSize': min_file_size, 'classesOfInterest': self.local_settings.getClassesOfInterest() } with io.open(self.config_location, 'w', encoding='utf-8') as f: f.write(json.dumps(configs, ensure_ascii=False)) self.error_message.setText("") message = "Settings saved " self.message.setText(message) self.log(Level.INFO, message + " in " + self.config_location) def open_text_editor(self, e): self.log(Level.INFO, "Lauching external text editor ") if sys.platform == "win32": subprocess.call(["notepad", self.config_location]) else: opener = "open" if sys.platform == "darwin" else "xdg-open" subprocess.call([opener, self.config_location]) def on_save_classes_of_interest_click(self, e): self.detectable_obejcts_dialog.setVisible(False) for item in self.classes_of_interest_changes_list: for class_oi in self.local_settings.getClassesOfInterest(): if item.getText() == class_oi['name']: self.log( Level.INFO, "match found " + class_oi['name'] + " and is selected " + str(item.isSelected())) class_oi['enabled'] = item.isSelected() break self.classes_of_interest_checkboxes = list() def on_cancel_classes_of_interest_click(self, e): self.detectable_obejcts_dialog.setVisible(False) self.classes_of_interest_changes_list = list() self.classes_of_interest_checkboxes = list() def on_class_checkbox_clicked(self, e): self.classes_of_interest_changes_list.append(e.getSource()) def on_select_all_clicked(self, e): for checkbox in self.classes_of_interest_checkboxes: checkbox.setSelected(True) def on_deselect_all_clicked(self, e): for checkbox in self.classes_of_interest_checkboxes: checkbox.setSelected(False) def show_detectable_objects_dialog(self, e): parentComponent = SwingUtilities.windowForComponent(self.panel0) self.detectable_obejcts_dialog = JDialog( parentComponent, "List of Objects to Detect", ModalityType.APPLICATION_MODAL) panel = JPanel() self.detectable_obejcts_dialog.add(panel) gbPanel = GridBagLayout() gbcPanel = GridBagConstraints() panel.setLayout(gbPanel) y = 0 x = 0 for line in self.local_settings.getClassesOfInterest(): if y > 15: y = 0 x = x + 1 class_check_box = JCheckBox(line['name']) self.classes_of_interest_checkboxes.append(class_check_box) class_check_box.setEnabled(True) class_check_box.setSelected(line['enabled']) class_check_box.addItemListener(self.on_class_checkbox_clicked) gbcPanel.gridx = x gbcPanel.gridy = y gbcPanel.gridwidth = 1 gbcPanel.gridheight = 1 gbcPanel.fill = GridBagConstraints.BOTH gbcPanel.weightx = 1 gbcPanel.weighty = 1 gbcPanel.anchor = GridBagConstraints.NORTH gbPanel.setConstraints(class_check_box, gbcPanel) panel.add(class_check_box) y = y + 1 blank_1_L = JLabel(" ") blank_1_L.setEnabled(True) gbcPanel.gridx = 0 gbcPanel.gridy = y + 1 gbcPanel.gridwidth = 1 gbcPanel.gridheight = 1 gbcPanel.fill = GridBagConstraints.BOTH gbcPanel.weightx = 1 gbcPanel.weighty = 0 gbcPanel.anchor = GridBagConstraints.NORTH gbPanel.setConstraints(blank_1_L, gbcPanel) panel.add(blank_1_L) deselect_all_button = JButton("Deselect all") deselect_all_button.setEnabled(True) deselect_all_button.addActionListener(self.on_deselect_all_clicked) gbcPanel.gridx = 1 gbcPanel.gridy = y + 2 gbcPanel.gridwidth = 1 gbcPanel.gridheight = 1 gbcPanel.fill = GridBagConstraints.BOTH gbcPanel.weightx = 2 gbcPanel.weighty = 1 gbcPanel.anchor = GridBagConstraints.NORTH gbPanel.setConstraints(deselect_all_button, gbcPanel) panel.add(deselect_all_button) select_all_button = JButton("Select all") select_all_button.setEnabled(True) select_all_button.addActionListener(self.on_select_all_clicked) gbcPanel.gridx = 3 gbcPanel.gridy = y + 2 gbcPanel.gridwidth = 1 gbcPanel.gridheight = 1 gbcPanel.fill = GridBagConstraints.BOTH gbcPanel.weightx = 2 gbcPanel.weighty = 1 gbcPanel.anchor = GridBagConstraints.NORTH gbPanel.setConstraints(select_all_button, gbcPanel) panel.add(select_all_button) blank_2_L = JLabel(" ") blank_2_L.setEnabled(True) gbcPanel.gridx = 0 gbcPanel.gridy = y + 3 gbcPanel.gridwidth = 1 gbcPanel.gridheight = 1 gbcPanel.fill = GridBagConstraints.BOTH gbcPanel.weightx = 1 gbcPanel.weighty = 0 gbcPanel.anchor = GridBagConstraints.NORTH gbPanel.setConstraints(blank_2_L, gbcPanel) panel.add(blank_2_L) cancel_button = JButton("Cancel") cancel_button.setEnabled(True) cancel_button.addActionListener( self.on_cancel_classes_of_interest_click) gbcPanel.gridx = 1 gbcPanel.gridy = y + 4 gbcPanel.gridwidth = 1 gbcPanel.gridheight = 1 gbcPanel.fill = GridBagConstraints.BOTH gbcPanel.weightx = 2 gbcPanel.weighty = 1 gbcPanel.anchor = GridBagConstraints.NORTH gbPanel.setConstraints(cancel_button, gbcPanel) panel.add(cancel_button) save_button = JButton("Save") save_button.setEnabled(True) save_button.addActionListener(self.on_save_classes_of_interest_click) gbcPanel.gridx = 3 gbcPanel.gridy = y + 4 gbcPanel.gridwidth = 1 gbcPanel.gridheight = 1 gbcPanel.fill = GridBagConstraints.BOTH gbcPanel.weightx = 2 gbcPanel.weighty = 1 gbcPanel.anchor = GridBagConstraints.NORTH gbPanel.setConstraints(save_button, gbcPanel) panel.add(save_button) blank_3_L = JLabel(" ") blank_3_L.setEnabled(True) gbcPanel.gridx = 0 gbcPanel.gridy = y + 5 gbcPanel.gridwidth = 1 gbcPanel.gridheight = 1 gbcPanel.fill = GridBagConstraints.BOTH gbcPanel.weightx = 1 gbcPanel.weighty = 0 gbcPanel.anchor = GridBagConstraints.NORTH gbPanel.setConstraints(blank_3_L, gbcPanel) panel.add(blank_3_L) self.detectable_obejcts_dialog.pack() screenSize = Toolkit.getDefaultToolkit().getScreenSize() self.detectable_obejcts_dialog.setLocation( int((screenSize.getWidth() / 2) - (self.detectable_obejcts_dialog.getWidth() / 2)), int((screenSize.getHeight() / 2) - (self.detectable_obejcts_dialog.getHeight() / 2))) self.detectable_obejcts_dialog.setVisible(True) def customize_components(self): settings = self.getSettings() self.host_TF.setText(settings.getServerHost()) self.port_TF.setText(str(settings.getServerPort())) self.log(Level.INFO, "[customizeComponents]") self.log(Level.INFO, settings.getImageFormats()[0]) self.image_formats_TF.setText(';'.join(settings.getImageFormats())) self.min_probability_TF.setText(str(settings.getMinProbability())) self.min_file_size_TF.setText(str(settings.getMinFileSize())) def init_components(self): self.panel0 = JPanel() self.rbgPanel0 = ButtonGroup() self.gbPanel0 = GridBagLayout() self.gbcPanel0 = GridBagConstraints() self.panel0.setLayout(self.gbPanel0) self.host_L = JLabel("Host:") self.host_L.setEnabled(True) self.gbcPanel0.gridx = 0 self.gbcPanel0.gridy = 1 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.host_L, self.gbcPanel0) self.panel0.add(self.host_L) self.port_L = JLabel("Port:") self.port_L.setEnabled(True) self.gbcPanel0.gridx = 1 self.gbcPanel0.gridy = 1 self.gbcPanel0.gridwidth = 2 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.port_L, self.gbcPanel0) self.panel0.add(self.port_L) self.host_TF = JTextField(10) self.gbcPanel0.gridx = 0 self.gbcPanel0.gridy = 2 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.host_TF, self.gbcPanel0) self.panel0.add(self.host_TF) format = NumberFormat.getInstance() format.setGroupingUsed(False) port_formatter = NumberFormatter(format) port_formatter.setValueClass(Integer) port_formatter.setAllowsInvalid(False) port_formatter.setMinimum(Integer(0)) port_formatter.setMaximum(Integer(65535)) self.port_TF = JFormattedTextField(port_formatter) self.gbcPanel0.gridx = 1 self.gbcPanel0.gridy = 2 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.port_TF, self.gbcPanel0) self.panel0.add(self.port_TF) self.blank_1_L = JLabel(" ") self.blank_1_L.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 3 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.blank_1_L, self.gbcPanel0) self.panel0.add(self.blank_1_L) self.image_formats_L = JLabel("Format of images (separator \";\"):") self.port_L.setEnabled(True) self.gbcPanel0.gridx = 0 self.gbcPanel0.gridy = 4 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.image_formats_L, self.gbcPanel0) self.panel0.add(self.image_formats_L) self.image_formats_TF = JTextField(10) self.gbcPanel0.gridx = 0 self.gbcPanel0.gridy = 5 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.image_formats_TF, self.gbcPanel0) self.panel0.add(self.image_formats_TF) self.blank_2_L = JLabel(" ") self.blank_2_L.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 6 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.blank_2_L, self.gbcPanel0) self.panel0.add(self.blank_2_L) self.min_probability_L = JLabel("Confidence minimum (%):") self.port_L.setEnabled(True) self.gbcPanel0.gridx = 0 self.gbcPanel0.gridy = 7 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.min_probability_L, self.gbcPanel0) self.panel0.add(self.min_probability_L) min_probabilty_formatter = NumberFormatter(format) min_probabilty_formatter.setValueClass(Integer) min_probabilty_formatter.setAllowsInvalid(False) min_probabilty_formatter.setMinimum(Integer(0)) min_probabilty_formatter.setMaximum(Integer(100)) self.min_probability_TF = JFormattedTextField(min_probabilty_formatter) self.gbcPanel0.gridx = 0 self.gbcPanel0.gridy = 8 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.min_probability_TF, self.gbcPanel0) self.panel0.add(self.min_probability_TF) self.blank_3_L = JLabel(" ") self.blank_3_L.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 9 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.blank_3_L, self.gbcPanel0) self.panel0.add(self.blank_3_L) self.min_file_size_L = JLabel("Minimum file size (KB):") self.min_file_size_L.setEnabled(True) self.gbcPanel0.gridx = 0 self.gbcPanel0.gridy = 10 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.min_file_size_L, self.gbcPanel0) self.panel0.add(self.min_file_size_L) min_file_size_formatter = NumberFormatter(format) min_file_size_formatter.setValueClass(Integer) min_file_size_formatter.setAllowsInvalid(False) min_file_size_formatter.setMinimum(Integer(0)) self.min_file_size_TF = JFormattedTextField(min_file_size_formatter) self.gbcPanel0.gridx = 0 self.gbcPanel0.gridy = 11 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.min_file_size_TF, self.gbcPanel0) self.panel0.add(self.min_file_size_TF) self.blank_4_L = JLabel(" ") self.blank_4_L.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 12 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.blank_4_L, self.gbcPanel0) self.panel0.add(self.blank_4_L) self.detectable_obejcts_BTN = \ JButton("List of Objects to Detect", actionPerformed=self.show_detectable_objects_dialog) # self.save_Settings_BTN.setPreferredSize(Dimension(1, 20)) self.rbgPanel0.add(self.detectable_obejcts_BTN) self.gbcPanel0.gridx = 0 self.gbcPanel0.gridy = 13 self.gbPanel0.setConstraints(self.detectable_obejcts_BTN, self.gbcPanel0) self.panel0.add(self.detectable_obejcts_BTN) self.blank_5_L = JLabel(" ") self.blank_5_L.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 14 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.blank_5_L, self.gbcPanel0) self.panel0.add(self.blank_5_L) self.error_message = JLabel("", JLabel.CENTER) self.error_message.setForeground(Color.red) self.error_message.setEnabled(True) self.gbcPanel0.gridx = 0 self.gbcPanel0.gridy = 15 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.error_message, self.gbcPanel0) self.panel0.add(self.error_message) self.message = JLabel("", JLabel.CENTER) self.message.setEnabled(True) self.gbcPanel0.gridx = 0 self.gbcPanel0.gridy = 16 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.message, self.gbcPanel0) self.panel0.add(self.message) self.save_settings_BTN = JButton("Save Settings", actionPerformed=self.save_settings) # self.save_Settings_BTN.setPreferredSize(Dimension(1, 20)) self.rbgPanel0.add(self.save_settings_BTN) self.gbcPanel0.gridx = 0 self.gbcPanel0.gridy = 17 self.gbPanel0.setConstraints(self.save_settings_BTN, self.gbcPanel0) self.panel0.add(self.save_settings_BTN) self.blank_6_L = JLabel(" ") self.blank_6_L.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 18 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.blank_6_L, self.gbcPanel0) self.panel0.add(self.blank_6_L) self.blank_7_L = JLabel(" ") self.blank_7_L.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 19 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.blank_7_L, self.gbcPanel0) self.panel0.add(self.blank_7_L) self.check_server_connection_BTN = \ JButton("Check server connection", actionPerformed=self.check_server_connection) # self.save_Settings_BTN.setPreferredSize(Dimension(1, 20)) self.rbgPanel0.add(self.check_server_connection_BTN) self.gbcPanel0.gridx = 0 self.gbcPanel0.gridy = 20 self.gbPanel0.setConstraints(self.check_server_connection_BTN, self.gbcPanel0) self.panel0.add(self.check_server_connection_BTN) self.blank_8_L = JLabel(" ") self.blank_8_L.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 21 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.blank_8_L, self.gbcPanel0) self.panel0.add(self.blank_8_L) self.text_editor_BTN = \ JButton("Open config file", actionPerformed=self.open_text_editor) # self.save_Settings_BTN.setPreferredSize(Dimension(1, 20)) self.rbgPanel0.add(self.text_editor_BTN) self.gbcPanel0.gridx = 0 self.gbcPanel0.gridy = 22 self.gbPanel0.setConstraints(self.text_editor_BTN, self.gbcPanel0) self.panel0.add(self.text_editor_BTN) self.add(self.panel0)
def typingInSearchField(event): if KeyEvent.VK_ENTER == event.getKeyCode(): filterTable() elif KeyEvent.VK_ESCAPE == event.getKeyCode(): search_field.setText("") filterTable() # to restore the full list of rows # Top-left element: a text field for filtering rows by regular expression match c.gridx = 0 c.gridy = 0 c.anchor = GridBagConstraints.CENTER c.fill = GridBagConstraints.HORIZONTAL search_field = JTextField("", keyPressed=typingInSearchField) gb.setConstraints(search_field, c) all.add(search_field) # Bottom left element: the table, wrapped in a scrollable component table = JTable(TableModel()) table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION) #table.setCellSelectionEnabled(True) table.setAutoCreateRowSorter( True) # to sort the view only, not the data in the underlying TableModel c.gridx = 0 c.gridy = 1 c.anchor = GridBagConstraints.NORTHWEST c.fill = GridBagConstraints.BOTH # resize with the frame c.weightx = 1.0 c.gridheight = 2 jsp = JScrollPane(table)
def show_detectable_objects_dialog(self, e): parentComponent = SwingUtilities.windowForComponent(self.panel0) self.detectable_obejcts_dialog = JDialog( parentComponent, "List of Objects to Detect", ModalityType.APPLICATION_MODAL) panel = JPanel() self.detectable_obejcts_dialog.add(panel) gbPanel = GridBagLayout() gbcPanel = GridBagConstraints() panel.setLayout(gbPanel) y = 0 x = 0 for line in self.local_settings.getClassesOfInterest(): if y > 15: y = 0 x = x + 1 class_check_box = JCheckBox(line['name']) self.classes_of_interest_checkboxes.append(class_check_box) class_check_box.setEnabled(True) class_check_box.setSelected(line['enabled']) class_check_box.addItemListener(self.on_class_checkbox_clicked) gbcPanel.gridx = x gbcPanel.gridy = y gbcPanel.gridwidth = 1 gbcPanel.gridheight = 1 gbcPanel.fill = GridBagConstraints.BOTH gbcPanel.weightx = 1 gbcPanel.weighty = 1 gbcPanel.anchor = GridBagConstraints.NORTH gbPanel.setConstraints(class_check_box, gbcPanel) panel.add(class_check_box) y = y + 1 blank_1_L = JLabel(" ") blank_1_L.setEnabled(True) gbcPanel.gridx = 0 gbcPanel.gridy = y + 1 gbcPanel.gridwidth = 1 gbcPanel.gridheight = 1 gbcPanel.fill = GridBagConstraints.BOTH gbcPanel.weightx = 1 gbcPanel.weighty = 0 gbcPanel.anchor = GridBagConstraints.NORTH gbPanel.setConstraints(blank_1_L, gbcPanel) panel.add(blank_1_L) deselect_all_button = JButton("Deselect all") deselect_all_button.setEnabled(True) deselect_all_button.addActionListener(self.on_deselect_all_clicked) gbcPanel.gridx = 1 gbcPanel.gridy = y + 2 gbcPanel.gridwidth = 1 gbcPanel.gridheight = 1 gbcPanel.fill = GridBagConstraints.BOTH gbcPanel.weightx = 2 gbcPanel.weighty = 1 gbcPanel.anchor = GridBagConstraints.NORTH gbPanel.setConstraints(deselect_all_button, gbcPanel) panel.add(deselect_all_button) select_all_button = JButton("Select all") select_all_button.setEnabled(True) select_all_button.addActionListener(self.on_select_all_clicked) gbcPanel.gridx = 3 gbcPanel.gridy = y + 2 gbcPanel.gridwidth = 1 gbcPanel.gridheight = 1 gbcPanel.fill = GridBagConstraints.BOTH gbcPanel.weightx = 2 gbcPanel.weighty = 1 gbcPanel.anchor = GridBagConstraints.NORTH gbPanel.setConstraints(select_all_button, gbcPanel) panel.add(select_all_button) blank_2_L = JLabel(" ") blank_2_L.setEnabled(True) gbcPanel.gridx = 0 gbcPanel.gridy = y + 3 gbcPanel.gridwidth = 1 gbcPanel.gridheight = 1 gbcPanel.fill = GridBagConstraints.BOTH gbcPanel.weightx = 1 gbcPanel.weighty = 0 gbcPanel.anchor = GridBagConstraints.NORTH gbPanel.setConstraints(blank_2_L, gbcPanel) panel.add(blank_2_L) cancel_button = JButton("Cancel") cancel_button.setEnabled(True) cancel_button.addActionListener( self.on_cancel_classes_of_interest_click) gbcPanel.gridx = 1 gbcPanel.gridy = y + 4 gbcPanel.gridwidth = 1 gbcPanel.gridheight = 1 gbcPanel.fill = GridBagConstraints.BOTH gbcPanel.weightx = 2 gbcPanel.weighty = 1 gbcPanel.anchor = GridBagConstraints.NORTH gbPanel.setConstraints(cancel_button, gbcPanel) panel.add(cancel_button) save_button = JButton("Save") save_button.setEnabled(True) save_button.addActionListener(self.on_save_classes_of_interest_click) gbcPanel.gridx = 3 gbcPanel.gridy = y + 4 gbcPanel.gridwidth = 1 gbcPanel.gridheight = 1 gbcPanel.fill = GridBagConstraints.BOTH gbcPanel.weightx = 2 gbcPanel.weighty = 1 gbcPanel.anchor = GridBagConstraints.NORTH gbPanel.setConstraints(save_button, gbcPanel) panel.add(save_button) blank_3_L = JLabel(" ") blank_3_L.setEnabled(True) gbcPanel.gridx = 0 gbcPanel.gridy = y + 5 gbcPanel.gridwidth = 1 gbcPanel.gridheight = 1 gbcPanel.fill = GridBagConstraints.BOTH gbcPanel.weightx = 1 gbcPanel.weighty = 0 gbcPanel.anchor = GridBagConstraints.NORTH gbPanel.setConstraints(blank_3_L, gbcPanel) panel.add(blank_3_L) self.detectable_obejcts_dialog.pack() screenSize = Toolkit.getDefaultToolkit().getScreenSize() self.detectable_obejcts_dialog.setLocation( int((screenSize.getWidth() / 2) - (self.detectable_obejcts_dialog.getWidth() / 2)), int((screenSize.getHeight() / 2) - (self.detectable_obejcts_dialog.getHeight() / 2))) self.detectable_obejcts_dialog.setVisible(True)
class MacFSEventsSettingsWithUISettingsPanel(IngestModuleIngestJobSettingsPanel ): # Note, we can't use a self.settings instance variable. # Rather, self.local_settings is used. # https://wiki.python.org/jython/UserGuide#javabean-properties # Jython Introspector generates a property - 'settings' on the basis # of getSettings() defined in this class. Since only getter function # is present, it creates a read-only 'settings' property. This auto- # generated read-only property overshadows the instance-variable - # 'settings' # We get passed in a previous version of the settings so that we can # prepopulate the UI # TODO: Update this for your UI def __init__(self, settings): self.local_settings = settings self.initComponents() self.customizeComponents() def onchange_plugins_lb(self, event): self.local_settings.clearPluginListBox() list_selected = self.Plugin_LB.getSelectedValuesList() self.local_settings.setPluginListBox(list_selected) # Create the initial data fields/layout in the UI def initComponents(self): self.panel0 = JPanel() self.rbgPanel0 = ButtonGroup() self.gbPanel0 = GridBagLayout() self.gbcPanel0 = GridBagConstraints() self.panel0.setLayout(self.gbPanel0) self.Error_Message = JLabel("") self.Error_Message.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 31 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.Error_Message, self.gbcPanel0) self.panel0.add(self.Error_Message) # self.Label_1 = JLabel("MacFSEvents To Include:") # self.Label_1.setEnabled(True) # self.gbcPanel0.gridx = 2 # self.gbcPanel0.gridy = 1 # self.gbcPanel0.gridwidth = 1 # self.gbcPanel0.gridheight = 1 # self.gbcPanel0.fill = GridBagConstraints.BOTH # self.gbcPanel0.weightx = 1 # self.gbcPanel0.weighty = 0 # self.gbcPanel0.anchor = GridBagConstraints.NORTH # self.gbPanel0.setConstraints( self.Label_1, self.gbcPanel0 ) # self.panel0.add( self.Label_1 ) # self.Blank_1 = JLabel( " ") # self.Blank_1.setEnabled(True) # self.gbcPanel0.gridx = 2 # self.gbcPanel0.gridy = 5 # self.gbcPanel0.gridwidth = 1 # self.gbcPanel0.gridheight = 1 # self.gbcPanel0.fill = GridBagConstraints.BOTH # self.gbcPanel0.weightx = 1 # self.gbcPanel0.weighty = 0 # self.gbcPanel0.anchor = GridBagConstraints.NORTH # self.gbPanel0.setConstraints( self.Blank_1, self.gbcPanel0 ) # self.panel0.add( self.Blank_1 ) # self.Plugin_list = ('FolderEvent','Mount','Unmount','EndOfTransaction','LastHardLinkRemoved','HardLink', \ # 'SymbolicLink','FileEvent','PermissionChange','ExtendedAttrModified','ExtendedAttrRemoved', \ # 'DocumentRevisioning','Created','Removed','InodeMetaMod','Renamed','Modified', \ # 'Exchange','FinderInfoMod','FolderCreated') # self.Plugin_LB = JList( self.Plugin_list, valueChanged=self.onchange_plugins_lb) # self.Plugin_LB.setVisibleRowCount( 7 ) # self.scpPlugin_LB = JScrollPane( self.Plugin_LB ) # self.gbcPanel0.gridx = 2 # self.gbcPanel0.gridy = 7 # self.gbcPanel0.gridwidth = 1 # self.gbcPanel0.gridheight = 1 # self.gbcPanel0.fill = GridBagConstraints.BOTH # self.gbcPanel0.weightx = 1 # self.gbcPanel0.weighty = 1 # self.gbcPanel0.anchor = GridBagConstraints.NORTH # self.gbPanel0.setConstraints( self.scpPlugin_LB, self.gbcPanel0 ) # self.panel0.add( self.scpPlugin_LB ) self.Blank_4 = JLabel(" ") self.Blank_4.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 17 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints(self.Blank_4, self.gbcPanel0) self.panel0.add(self.Blank_4) # self.Label_3 = JLabel( "Message:") # self.Label_3.setEnabled(True) # self.gbcPanel0.gridx = 2 # self.gbcPanel0.gridy = 29 # self.gbcPanel0.gridwidth = 1 # self.gbcPanel0.gridheight = 1 # self.gbcPanel0.fill = GridBagConstraints.BOTH # self.gbcPanel0.weightx = 1 # self.gbcPanel0.weighty = 0 # self.gbcPanel0.anchor = GridBagConstraints.NORTH # self.gbPanel0.setConstraints( self.Label_3, self.gbcPanel0 ) # self.panel0.add( self.Label_3 ) self.add(self.panel0) # Custom load any data field and initialize the values def customizeComponents(self): #self.Exclude_File_Sources_CB.setSelected(self.local_settings.getExclude_File_Sources()) #self.Run_Plaso_CB.setSelected(self.local_settings.getRun_Plaso()) #self.Import_Plaso_CB.setSelected(self.local_settings.getImport_Plaso()) #self.check_Database_entries() pass # Return the settings used def getSettings(self): return self.local_settings
def specifyRoiUI(roi=Roi(0, 0, 0, 0)): # A panel in which to place UI elements panel = JPanel() panel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)) gb = GridBagLayout() panel.setLayout(gb) gc = GBC() bounds = roi.getBounds() if roi else Rectangle() textfields = [] roimakers = [] # Basic properties of most UI elements, will edit when needed gc.gridx = 0 # can be any natural number gc.gridy = 0 # idem. gc.gridwidth = 1 # when e.g. 2, the UI element will occupy two horizontally adjacent grid cells gc.gridheight = 1 # same but vertically gc.fill = GBC.NONE # can also be BOTH, VERTICAL and HORIZONTAL for title in ["x", "y", "width", "height"]: # label gc.gridx = 0 gc.anchor = GBC.EAST label = JLabel(title + ": ") gb.setConstraints(label, gc) # copies the given constraints 'gc', # so we can modify and reuse gc later. panel.add(label) # text field, below the title gc.gridx = 1 gc.anchor = GBC.WEST text = str(getattr(bounds, title)) # same as e.g. bounds.x, bounds.width, ... textfield = JTextField(text, 10) # 10 is the size of the field, in digits gb.setConstraints(textfield, gc) panel.add(textfield) textfields.append( textfield) # collect all 4 created textfields for the listeners # setup ROI and text field listeners listener = RoiMaker(textfields, len(textfields) - 1) # second argument is the index of textfield # in the list of textfields. roimakers.append(listener) textfield.addKeyListener(listener) textfield.addMouseWheelListener(listener) # Position next ROI property in a new row by increasing the Y coordinate of the layout grid gc.gridy += 1 # User documentation (uses HTML to define line breaks) doc = JLabel( "<html><body><br />Click on a field to activate it, then:<br />" + "Type in integer numbers<br />" + "or use arrow keys to increase by 1<br />" + "or use the scroll wheel on a field.</body></html>") gc.gridx = 0 # start at the first column gc.gridwidth = 2 # Spans both columns gb.setConstraints(doc, gc) panel.add(doc) # Listen to changes in the ROI of imp roilistener = TextFieldUpdater(textfields) Roi.addRoiListener(roilistener) # Show window frame = JFrame("Specify rectangular ROI") frame.getContentPane().add(panel) frame.pack() frame.setLocationRelativeTo(None) # center in the screen frame.setDefaultCloseOperation( JFrame.DO_NOTHING_ON_CLOSE) # prevent closing the window frame.addWindowListener( CloseControl(roilistener)) # handles closing the window frame.setVisible(True)
# Create the UI: a 3-column table and a text area next to it # to show the Motivation column of any selected row: all = JPanel() gb = GridBagLayout() all.setLayout(gb) c = GridBagConstraints() table = JTable(TableModel()) table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION) table.setAutoCreateRowSorter(True) # to sort the view only, not the data in the underlying TableModel jsp = JScrollPane(table) jsp.setPreferredSize(Dimension(200, 500)) c.anchor = GridBagConstraints.NORTHWEST c.fill = GridBagConstraints.BOTH # resize with the frame gb.setConstraints(jsp, c) all.add(jsp) c.gridx = 1 c.weightx = 1.0 # take any additionally available horizontal space c.weighty = 1.0 textarea = JTextArea() textarea.setLineWrap(True) textarea.setWrapStyleWord(True) # wrap text by cutting at whitespace textarea.setEditable(False) # avoid changing the text, as any changes wouldn't be persisted to disk font = textarea.getFont().deriveFont(20.0) textarea.setFont(font) textarea.setPreferredSize(Dimension(500, 500)) gb.setConstraints(textarea, c) all.add(textarea) frame = JFrame("CSV") frame.getContentPane().add(all)
class Remove_ArtifactsWithUISettingsPanel(IngestModuleIngestJobSettingsPanel): # Note, we can't use a self.settings instance variable. # Rather, self.local_settings is used. # https://wiki.python.org/jython/UserGuide#javabean-properties # Jython Introspector generates a property - 'settings' on the basis # of getSettings() defined in this class. Since only getter function # is present, it creates a read-only 'settings' property. This auto- # generated read-only property overshadows the instance-variable - # 'settings' # We get passed in a previous version of the settings so that we can # prepopulate the UI # TODO: Update this for your UI def __init__(self, settings): self.local_settings = settings self.artifact_list = [] self.initComponents() self.customizeComponents() # Check to see if there are any entries that need to be populated from the database. def checkBoxEvent(self, event): if self.All_Artifacts_CB.isSelected(): self.local_settings.setSetting('allArtifacts', 'true') self.List_Box_LB.setEnabled(False) else: self.local_settings.setSetting('allArtifacts', 'false') self.List_Box_LB.setEnabled(True) if self.All_Attributes_CB.isSelected(): self.local_settings.setSetting('allAttributes', 'true') self.List_Box_LB.setEnabled(False) else: self.local_settings.setSetting('allAttributes', 'false') self.List_Box_LB.setEnabled(True) def onchange_lb(self, event): self.local_settings.setSetting('listSelected', '') list_selected = self.List_Box_LB.getSelectedValuesList() self.local_settings.setSetting('listSelected', list_selected) def get_artifacts(self): sql_statement = "select distinct(type_name) 'type_name' from blackboard_artifacts a, blackboard_artifact_types b " + \ " where a.artifact_type_id = b.artifact_type_id;" skCase = Case.getCurrentCase().getSleuthkitCase() dbquery = skCase.executeQuery(sql_statement) resultSet = dbquery.getResultSet() while resultSet.next(): self.artifact_list.append(resultSet.getString("type_name")) dbquery.close() # Create the initial data fields/layout in the UI def initComponents(self): self.panel0 = JPanel() self.rbgPanel0 = ButtonGroup() self.gbPanel0 = GridBagLayout() self.gbcPanel0 = GridBagConstraints() self.panel0.setLayout( self.gbPanel0 ) self.All_Artifacts_CB = JCheckBox("Remove All Custom Artifacts", actionPerformed=self.checkBoxEvent) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 1 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints( self.All_Artifacts_CB, self.gbcPanel0 ) self.panel0.add( self.All_Artifacts_CB ) self.All_Attributes_CB = JCheckBox("Remove All Custom Attributes", actionPerformed=self.checkBoxEvent) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 3 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints( self.All_Attributes_CB, self.gbcPanel0 ) self.panel0.add( self.All_Attributes_CB ) self.Blank_0 = JLabel( " ") self.Blank_0.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 5 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints( self.Blank_0, self.gbcPanel0 ) self.panel0.add( self.Blank_0 ) self.Label_0 = JLabel( "Remove selected Artifacts") self.Label_0.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 5 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints( self.Label_0, self.gbcPanel0 ) self.panel0.add( self.Label_0 ) self.Blank_0 = JLabel( " ") self.Blank_0.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 5 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints( self.Blank_0, self.gbcPanel0 ) self.panel0.add( self.Blank_0 ) self.get_artifacts() self.List_Box_LB = JList( self.artifact_list, valueChanged=self.onchange_lb) self.List_Box_LB.setVisibleRowCount( 3 ) self.scpList_Box_LB = JScrollPane( self.List_Box_LB ) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 7 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 1 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints( self.scpList_Box_LB, self.gbcPanel0 ) self.panel0.add( self.scpList_Box_LB ) self.Blank_1 = JLabel( " ") self.Blank_1.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 9 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints( self.Blank_1, self.gbcPanel0 ) self.panel0.add( self.Blank_1 ) self.Label_1 = JLabel( "Message:") self.Label_1.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 11 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints( self.Label_1, self.gbcPanel0 ) self.panel0.add( self.Label_1 ) self.Blank_2 = JLabel( " ") self.Blank_2.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 13 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints( self.Blank_2, self.gbcPanel0 ) self.panel0.add( self.Blank_2 ) self.Error_Message = JLabel( "For developer purposes only, it may fubar your case") self.Error_Message.setEnabled(True) self.gbcPanel0.gridx = 2 self.gbcPanel0.gridy = 15 self.gbcPanel0.gridwidth = 1 self.gbcPanel0.gridheight = 1 self.gbcPanel0.fill = GridBagConstraints.BOTH self.gbcPanel0.weightx = 1 self.gbcPanel0.weighty = 0 self.gbcPanel0.anchor = GridBagConstraints.NORTH self.gbPanel0.setConstraints( self.Error_Message, self.gbcPanel0 ) self.panel0.add( self.Error_Message ) self.add(self.panel0) # Custom load any data field and initialize the values def customizeComponents(self): self.All_Artifacts_CB.setSelected(self.local_settings.getSetting('allArtifacts') == 'true') self.All_Attributes_CB.setSelected(self.local_settings.getSetting('allAttributes') == 'true') # Return the settings used def getSettings(self): return self.local_settings