Exemplo n.º 1
0
class ProjectIngestSettingsPanel(IngestModuleIngestJobSettingsPanel):
    def __init__(self, settings):
        self.local_settings = settings
        self.initComponents()
        self.customizeComponents()

    def initComponents(self):
        self.apps_checkboxes_list = []

        self.setLayout(BoxLayout(self, BoxLayout.PAGE_AXIS))
        self.setPreferredSize(Dimension(300, 0))

        # title
        self.p_title = SettingsUtils.createPanel()

        self.lb_title = JLabel("Forensic Analysis for Mobile Apps")
        self.lb_title.setFont(self.lb_title.getFont().deriveFont(
            Font.BOLD, 15))
        self.p_title.add(self.lb_title)
        self.add(self.p_title)

        # end of title

        # info menu
        self.p_info = SettingsUtils.createPanel()
        self.p_info.setPreferredSize(Dimension(300, 20))

        self.lb_info = SettingsUtils.createInfoLabel("")
        self.lb_info2 = SettingsUtils.createInfoLabel("")
        self.sp2 = SettingsUtils.createSeparators(1)

        self.p_method = SettingsUtils.createPanel()
        self.bg_method = ButtonGroup()

        autopsy_version = PsyUtils.get_autopsy_version()

        if ((autopsy_version["major"] == 4 and autopsy_version["minor"] <= 17)
                or autopsy_version["major"] < 4):
            self.p_info.add(self.lb_info)
            self.p_info.add(self.lb_info2, BorderLayout.SOUTH)

            self.rb_selectedDatasource = SettingsUtils.createRadioButton(
                "Analyze selected datasource", "method_datasource",
                self.onMethodChange)
            self.bg_method.add(self.rb_selectedDatasource)

            # self.rb_importReportFile = SettingsUtils.createRadioButton("Import previous generated report file","method_importfile" ,self.onMethodChange)
            self.rb_liveExtraction = SettingsUtils.createRadioButton(
                "Live extraction with ADB", "method_adb", self.onMethodChange)
            self.rb_selectedDatasource.setSelected(True)

            #self.bg_method.add(self.rb_importReportFile)
            self.bg_method.add(self.rb_liveExtraction)

            self.p_method.add(JLabel("Analysis method"))
            self.p_method.add(self.rb_selectedDatasource)
            self.p_method.add(self.rb_liveExtraction)

        else:
            self.p_info.add(
                SettingsUtils.createInfoLabel(
                    "It will analyze the data source with previously selected method and index the forensic artifacts."
                ))

        self.add(self.p_method)

        self.p_apps = SettingsUtils.createPanel(True)

        sorted_items = OrderedDict(sorted(Utils.get_all_packages().items()))

        for app, app_id in sorted_items.iteritems():
            #(app, app_id)
            checkbox = SettingsUtils.addApplicationCheckbox(
                app, app_id, self.getSelectedApps)
            self.add(checkbox)
            self.apps_checkboxes_list.append(checkbox)
            self.p_apps.add(checkbox)

        self.add(self.p_apps)
        self.add(self.p_info)
        # end of checkboxes menu

    def customizeComponents(self):
        self.onMethodChange("")  #initialize method option
        self.getSelectedApps("")  #initialize selected apps

    def onMethodChange(self, event):
        self.method = self.getMethod()
        self.local_settings.setSetting("method", self.method)

        if self.method == "method_adb":
            self.lb_info.setText(
                "This method is used when there is no data source but you have the device."
            )
            self.lb_info2.setText(
                "It will extract the content of the selected applications from the device, analyze and index the forensic artifacts."
            )
            self.toggleCheckboxes(True)
        else:
            self.lb_info.setText(
                "This method is used when the application data has already been collected."
            )
            self.lb_info2.setText(
                "It will analyze the data source previously added to the data source and index the forensic artifacts."
            )
            self.toggleCheckboxes(False)

    def getSettings(self):
        return self.local_settings

    def getMethod(self):
        selection = self.bg_method.getSelection()
        if not selection:
            return None

        return selection.getActionCommand()

    def getSelectedApps(self, event):
        selected_apps = []

        for cb_app in self.apps_checkboxes_list:
            if cb_app.isSelected():
                selected_apps.append(cb_app.getActionCommand())

        self.local_settings.setSetting("apps", json.dumps(selected_apps))

    def toggleCheckboxes(self, visible):
        for cb_app in self.apps_checkboxes_list:
            cb_app.setVisible(visible)
Exemplo n.º 2
0
class Gui(JFrame):
    '''
    classdocs
    '''


    def __init__(self, pP):
        '''
        Constructor
        '''
        self.pP = pP
        self.annotationType = self.pP.getAnnotationType()
        
        self.setTitle("Random Picture Picker")

        #annotation Panel
        annoPanel = JPanel()
        annoPanel.setBorder(BorderFactory.createTitledBorder("Annotations"))
        annoPLayout = GroupLayout(annoPanel)
        annoPanel.setLayout(annoPLayout)
        annoPLayout.setAutoCreateContainerGaps(True)
        annoPLayout.setAutoCreateGaps(True)        

        # dynamic creation of annotation panel
        # yesNoIgnore, int, number, list
        if len(self.pP.getAnnotationType()) == 1:
            self.annoField = JTextField("", 16)
            annoPLayout.setHorizontalGroup(annoPLayout.createParallelGroup().addComponent(self.annoField))
            annoPLayout.setVerticalGroup(annoPLayout.createSequentialGroup().addComponent(self.annoField))
        elif len(self.pP.getAnnotationType()) > 1:
            choices = pP.getAnnotationType()
            print "choices", choices
            choiceBtns = []
            self.annoField = ButtonGroup()
            for c in choices:
                Btn = JRadioButton(c, actionCommand=c)
                self.annoField.add(Btn)
                choiceBtns.append(Btn)
          
            h = annoPLayout.createParallelGroup()
            for b in choiceBtns:
                h.addComponent(b)
            annoPLayout.setHorizontalGroup(h)
            
            v = annoPLayout.createSequentialGroup()
            for b in choiceBtns:
                v.addComponent(b)
            annoPLayout.setVerticalGroup(v)


        # Control Panel
        ctrlPanel = JPanel()
        ctrlPLayout = GroupLayout(ctrlPanel, autoCreateContainerGaps=True, autoCreateGaps=True)
        ctrlPanel.setLayout(ctrlPLayout)
        
        nextImgButton = JButton("Next >", actionPerformed=self.nextPicture)
        prevImgButton = JButton("< Prev", actionPerformed=self.pP.prevPicture)
        quitButton = JButton("Quit", actionPerformed=self.exit)

        ctrlPLayout.setHorizontalGroup(ctrlPLayout.createParallelGroup(GroupLayout.Alignment.CENTER)
                                       .addGroup(ctrlPLayout.createSequentialGroup()
                                                 .addComponent(prevImgButton)
                                                 .addComponent(nextImgButton))
                                       .addComponent(quitButton))
        ctrlPLayout.setVerticalGroup(ctrlPLayout.createSequentialGroup()
                                     .addGroup(ctrlPLayout.createParallelGroup()
                                               .addComponent(prevImgButton)
                                               .addComponent(nextImgButton))
                                     .addComponent(quitButton))
        ctrlPLayout.linkSize(SwingConstants.HORIZONTAL, quitButton)

        
        statusPanel = JPanel()   # contains status information: progress bar
        self.progressBar = JProgressBar()
        self.progressBar.setStringPainted(True)
        self.progressBar.setValue(0)
        statusPanel.add(self.progressBar)
        
        #MainLayout
        mainLayout = GroupLayout(self.getContentPane())
        self.getContentPane().setLayout(mainLayout)
        
        mainLayout.setHorizontalGroup(mainLayout.createParallelGroup(GroupLayout.Alignment.CENTER)
                                    .addComponent(annoPanel)
                                    .addComponent(ctrlPanel)
                                    .addComponent(statusPanel)
                                    )
        mainLayout.setVerticalGroup(mainLayout.createSequentialGroup()
                                    .addComponent(annoPanel)
                                    .addComponent(ctrlPanel)
                                    .addComponent(statusPanel)
                                    )
        mainLayout.linkSize(SwingConstants.HORIZONTAL, annoPanel, ctrlPanel, statusPanel)
         
      
        self.pack()
        self.setVisible(True)
        
        self.pP.nextPicture()
        
    def nextPicture(self, event):
        percent = (float(len(self.pP.usedList))/len(self.pP.pictureList))*100
        self.progressBar.setValue(int(percent))

        self.setAnnotation()
        self.pP.nextPicture()

        #try:
        #    self.setAnnotation()
        #    self.pP.nextPicture()
        #except AttributeError:
        #    print "Please choose something!"
     
    def setAnnotationField(self, a):
        if len(self.pP.getAnnotationType()) > 1:
            [Rbutton.setSelected(True) for Rbutton in self.annoField.getElements() if Rbutton.getActionCommand()==a]
        if len(self.pP.getAnnotationType()) == 1:
            self.annoField.setText(a)
        
    #rename this method to something clearer!    
    def setAnnotation(self):
        if len(self.pP.getAnnotationType()) > 1:
            annotation = self.annoField.getSelection().getActionCommand()
        if len(self.pP.getAnnotationType()) == 1:
            annotation = self.annoField.getText()
            self.annoField.setText(None)
        self.pP.getCurrentPicture().annotate(annotation)
        
    def getAnnotation(self):
        return self.annotation
    
    def exit(self, event):
        self.pP.exit()
        self.dispose()
class MenueFrame(JFrame, ActionListener, WindowFocusListener): # should extend JFrame
    def __init__(self):
        self.mainDir = ""

        self.setTitle("Dots Quality Check")
        self.setSize(250, 300)
        self.setLocation(20,120)
        self.addWindowFocusListener(self)
        
        self.Panel = JPanel(GridLayout(0,1))
        self.add(self.Panel)
        self.openNextButton = JButton("Open Next Random", actionPerformed=self.openRandom)
        self.Panel.add(self.openNextButton)
        self.saveButton = JButton("Save", actionPerformed=self.save, enabled=False)
        self.Panel.add(self.saveButton)
        self.cropButton = JButton("Crop values from here", actionPerformed=self.cropVals)
        self.Panel.add(self.cropButton)
        self.DiscardButton = JButton("Discard cell", actionPerformed=self.discardCell)
        self.Panel.add(self.DiscardButton)
        self.quitButton = JButton("Quit script",actionPerformed=self.quit)
        self.Panel.add(self.quitButton)

        annoPanel = JPanel()
        #add gridlayout
        self.wtRButton = JRadioButton("wt", actionCommand="wt")
        self.wtRButton.addActionListener(self)
        self.defectRButton = JRadioButton("Defect", actionCommand="defect")
        self.defectRButton.addActionListener(self)
        annoPanel.add(self.wtRButton)
        annoPanel.add(self.defectRButton)
        self.aButtonGroup = ButtonGroup()
        self.aButtonGroup.add(self.wtRButton)
        self.aButtonGroup.add(self.defectRButton)
      
        self.Panel.add(annoPanel)

        self.ProgBar = JProgressBar()
        self.ProgBar.setStringPainted(True)
        self.ProgBar.setValue(0)
        self.Panel.add(self.ProgBar)

        self.pathLabel = JLabel("-- No main directory chosen --")
        self.pathLabel.setHorizontalAlignment( SwingConstants.CENTER )
        self.Panel.add(self.pathLabel)
      
        WindowManager.addWindow(self)
        self.show()

    # - - - -   B U T T O N   M E T H O D S  - - - -
    # - - - - - -  - - - - - - - - - - - - - - - - -
    def openRandom(self, event):      # when click here: get random cell and meas.measure(csv, tif, savePath)
        if self.mainDir == "":
            self.mainDir = DirectoryChooser("Random QC - Please choose main directory containing ctrl and test folders").getDirectory()
            self.pathLabel.setText("MainDir: " + os.path.basename(os.path.split(self.mainDir)[0]))
        try:
            # should be complete disposal!
            self.cT.closeWindows()
        finally:
            inFiles = glob.glob(os.path.join(self.mainDir, "*", G_OPENSUBDIR, "val_*.csv"))  # glob.glob returns list of paths
            uncheckedCells = [cell(csvPath) for csvPath in inFiles if cell(csvPath).processed == False]
            if len(uncheckedCells) > 0:
                self.cell = random.choice(uncheckedCells)
                #update progressbar
                self.ProgBar.setMaximum(len(inFiles)-1)
                self.ProgBar.setValue(len(inFiles)-len(uncheckedCells))
                # open imp and resultstable
                self.cT = correctionTable(self.cell, self) #self, openPath_csv, mF
                self.RBActionListener.setCell(self.cell)
                # delete previous Radiobutton annotation
                self.wtRButton.setSelected(False)
                self.defectRButton.setSelected(True)
            else:
                print "All cells measured!"

    def save(self, event):
        savepath = self.cell.getQcCsvPath()
        anaphase = self.cell.getAnOn()
        timeInterval = self.cT.getImp().getCalibration().frameInterval
        annotation = self.getAnnotation()
        position = str(self.cell.position)
        cellIndex = str(self.cell.cellNo)
        if not os.path.exists(os.path.split(savepath)[0]): # check if save folder present.
            os.makedirs(os.path.split(savepath)[0]) # create save folder, if not present
        f = open(savepath, "w")
        # Position Cell Phenotype Frame Time AnOn Distance ch0x ch0y ch0z ch0vol ch1x ch1y ch1z ch1vol
        f.write("Position,Cell,Phenotype,Frame,Time,Anaphase,Distance,ch0x,ch0y,ch0z,ch0vol,ch1x,ch1y,ch1z,ch1vol\n")
        for i in range(self.cT.getLineCount()):
            frame, distance, a = self.cT.getLine(i).split("\t")
            corrFrame = str(int(frame)-int(anaphase))
            time = "%.f" % (round(timeInterval) * int(corrFrame))
            if distance == "NA":
                ch0x, ch0y, ch0z, ch0vol, ch1x, ch1y, ch1z, ch1vol = ("NA," * 7 + "NA\n").split(",")
            else:
                ch0x, ch0y, ch0z, ch0vol, ch1x, ch1y, ch1z, ch1vol = self.cT.getXYZtable()[i]
            f.write(position+","+cellIndex+","+annotation+","+corrFrame+","+time+","+anaphase+","+distance+","+ch0x+","+ch0y+","+ch0z+","+ch0vol+","+ch1x+","+ch1y+","+ch1z+","+ch1vol)
        f.close()
        print "Successfully saved!"

    def cropVals(self, event): #"this function deletes all values with frame > current cursor"   
        for line in range(self.cT.getSelectionEnd(), self.cT.getLineCount(), 1):
            frame, distance, AOCol = self.cT.getLine(line).split("\t")
            self.cT.setLine(line, frame + "\tNA" + "\t" + AOCol)

    def discardCell(self, event):
        if not os.path.exists(os.path.split(self.cell.getQcCsvPath() )[0]): # check if save folder present.
            os.makedirs(os.path.split(self.cell.getQcCsvPath() )[0]) # create save folder, if not present.
        f = open(self.cell.getQcCsvPath() ,"w")
        # Write dummy header. Position Cell Phenotype Frame Time AnOn Distance ch0x ch0y ch0z ch0vol ch1x ch1y ch1z ch1vol
        f.write("Position,Cell,Phenotype,Frame,Time,AnOn,Distance,ch0x,ch0y,ch0z,ch0vol,ch1x,ch1y,ch1z,ch1vol\n")
        f.close()
        print "Discarded cell - saved dummy" 

    def quit(self, event):
        try:
            self.cT.closeWindows()
        finally:
            WindowManager.removeWindow(self)
            self.dispose()

    # Methods implementing ActionListener interfaces:
    def actionPerformed(self, e):
        # this function is called when RadioButtons are changed
        self.cell.annotate( e.getSource().getActionCommand() )
        self.setSaveActive()

    def windowGainedFocus(self, e):
        pass

    def windowLostFocus(self, e):
        pass
        

    # - - - - - - - - - - - - -
    # - get and set methods - -
    # - - - - - - - - - - - - -
    def getAnnotation(self):
        return self.aButtonGroup.getSelection().getActionCommand()

    def getMainDir(self):
        return self.mainDir

    def setSaveActive(self):
        if (self.cell.getAnnotation() != None and self.cell.getAnOn() != None):
            self.saveButton.setEnabled(True)
            self.show()

    def setSaveInactive(self):
        self.saveButton.setEnabled(False)
        self.show()

    def setMainDir(self, path):
        self.mainDir = path
        self.pathLabel.setText("MainDir: " + os.path.basename(os.path.split(self.mainDir)[0]))
Exemplo n.º 4
0
class initDialog(JDialog): # JFrame
    
    def __init__(self, pP):
        # fields
        self.tPath = ""
        self.cPath = ""
        self.exPath = ""
        self.picPicker = pP
        self.annotationType = self.picPicker.getAnnotationType()
    
        super(initDialog, self).__init__()
        
        self.initUI()


    def initUI(self):
        
        inputPanel = JPanel()
        inputPanel.setBorder(BorderFactory.createTitledBorder("Where are your control and treament images?"))
        inputLayout = GroupLayout(inputPanel, autoCreateContainerGaps=True, autoCreateGaps=True)
        inputPanel.setLayout(inputLayout)
        
        annotatePanel = JPanel()
        annotatePanel.setBorder(BorderFactory.createTitledBorder("How do you want to annotate your data?"))
        anLayout = GroupLayout(annotatePanel, autoCreateContainerGaps=True, autoCreateGaps=True)
        annotatePanel.setLayout(anLayout)
        
        exportPanel = JPanel()
        exportPanel.setBorder(BorderFactory.createTitledBorder("Where do you want to export your data"))
        exportLayout = GroupLayout(exportPanel, autoCreateContainerGaps=True, autoCreateGaps=True)
        exportPanel.setLayout(exportLayout)
        
        btnPanel = JPanel()
        btnLayout = GroupLayout(btnPanel, autoCreateContainerGaps=True, autoCreateGaps=True)
        btnPanel.setLayout(btnLayout)
        
        layout = GroupLayout(self.getContentPane(), autoCreateContainerGaps=True, autoCreateGaps=True)
        self.getContentPane().setLayout(layout)

        self.setModalityType(ModalityType.APPLICATION_MODAL)
        self.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE)# JFrame.EXIT_ON_CLOSE)
        # definition of elements
        # labels
        cPathLabel = JLabel("Control Path:")
        tPathLabel = JLabel("Treatment Path:")
        exPathLabel = JLabel("Save Results in:")
        
        #textfields
        self.cPathField = JTextField("/Users/schiklen/DotData/131118_dummy/131118_2926/cutout/", 16)
        self.tPathField = JTextField("/Users/schiklen/DotData/131118_dummy/131118_2926/cutout/", 16)
        self.exPathField = JTextField("/Users/schiklen/DotData/131118_dummy/131118_2926/cutout/", 16)
        
        #Radiobuttons
        yesNoRButton = JRadioButton("Yes / No / Ignore", selected=True, actionCommand="yesNoIgnore", actionPerformed=self.setAnnotationTypeDialog)
        intRButton = JRadioButton("Integer", actionCommand="int", actionPerformed=self.setAnnotationTypeDialog)
        nRButton = JRadioButton("Number", actionCommand="float", actionPerformed=self.setAnnotationTypeDialog)
        listRButton = JRadioButton("From List...", actionCommand="list", actionPerformed=self.openListDialog)

        self.rBGroup = ButtonGroup()
        self.rBGroup.add(yesNoRButton)
        self.rBGroup.add(intRButton)
        self.rBGroup.add(nRButton)
        self.rBGroup.add(listRButton)
        
        #self.customListButton = JButton("Custom List...", actionPerformed=self.makeCustomList, enabled=0)
        
        #buttons
        cPathButton = JButton("Browse...", actionPerformed=self.browseC) # lambda on fieldvalue
        tPathButton = JButton("Browse...", actionPerformed=self.browseT) # lambda on fieldvalue
        exPathButton = JButton("Browse...", actionPerformed=self.browseE)
        OKButton = JButton("OK", actionPerformed=self.okayEvent)
        CancelButton = JButton("Cancel", actionPerformed=self.cancel)
        
        '''General ContentPane Layout'''
        layout.setHorizontalGroup(layout.createParallelGroup()
                                  .addComponent(inputPanel)
                                  .addComponent(annotatePanel)
                                  .addComponent(exportPanel)
                                  .addComponent(btnPanel)
                                  )
        layout.linkSize(SwingConstants.HORIZONTAL, inputPanel, annotatePanel, exportPanel, btnPanel)
        layout.setVerticalGroup(layout.createSequentialGroup()
                                .addComponent(inputPanel)
                                .addComponent(annotatePanel)
                                .addComponent(exportPanel)
                                .addComponent(btnPanel)
                                )
        
        ''' Input panel Layout '''
        inputLayout.setHorizontalGroup(inputLayout.createSequentialGroup()
                                       .addGroup(inputLayout.createParallelGroup(GroupLayout.Alignment.TRAILING)
                                                 .addComponent(cPathLabel)
                                                 .addComponent(tPathLabel))
                                       .addGroup(inputLayout.createParallelGroup(GroupLayout.Alignment.TRAILING)
                                                 .addComponent(self.cPathField)
                                                 .addComponent(self.tPathField))
                                       .addGroup(inputLayout.createParallelGroup()
                                                 .addComponent(cPathButton)
                                                 .addComponent(tPathButton))
                                       )
        
        inputLayout.setVerticalGroup(inputLayout.createSequentialGroup()
                                       .addGroup(inputLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                                                 .addComponent(cPathLabel)
                                                 .addComponent(self.cPathField)
                                                 .addComponent(cPathButton))
                                       .addGroup(inputLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                                                 .addComponent(tPathLabel)
                                                 .addComponent(self.tPathField)
                                                 .addComponent(tPathButton))
                                     )
        
        '''Annotate panel layout'''
        anLayout.setHorizontalGroup(anLayout.createParallelGroup()
                                    .addComponent(yesNoRButton)
                                    .addComponent(intRButton)
                                    .addComponent(nRButton)
                                    .addComponent(listRButton)
                                    #.addComponent(self.customListButton)
                                    )
        anLayout.setVerticalGroup(anLayout.createSequentialGroup()
                                    .addComponent(yesNoRButton)
                                    .addComponent(intRButton)
                                    .addComponent(nRButton)
                                    .addComponent(listRButton)
                                    #.addComponent(self.customListButton)
                                    )
        
        
        '''Export panel layout'''
        exportLayout.setHorizontalGroup(exportLayout.createSequentialGroup()
                                        .addComponent(exPathLabel)
                                        .addComponent(self.exPathField)
                                        .addComponent(exPathButton))
        exportLayout.setVerticalGroup(exportLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                                        .addComponent(exPathLabel)
                                        .addComponent(self.exPathField)
                                        .addComponent(exPathButton))
        
        
        '''Buttons Panel Layout'''
        btnLayout.setHorizontalGroup(btnLayout.createSequentialGroup()
                                     .addComponent(CancelButton)
                                     .addComponent(OKButton)
                                     )
        btnLayout.setVerticalGroup(btnLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                                   .addComponent(CancelButton)
                                   .addComponent(OKButton)
                                   )

        self.setTitle("Random Picture Picker")

        self.pack()
        self.setLocationRelativeTo(None)
        self.setVisible(True)

    def addDirToList(self, p):
        self.dirPathList.append(p)

    def browseT(self, event):
        self.tPathField.text = DirectoryChooser("Select Treatment Folder").getDirectory()
        
    def browseC(self, event):
        self.cPathField.text = DirectoryChooser("Select Control Folder").getDirectory()

    def browseE(self, event):
        self.exPathField.text = DirectoryChooser("Select Export Folder").getDirectory()
        self.picPicker.setOutputPath(self.exPathField.text)

    def makeCustomList(self):
        ld = listDialog(self)
        ld.startUI()
        
    def cancel(self, event):
        exit(0)

    def okayEvent(self, event):
        inputDict = {self.tPathField.getText():"treatment", self.cPathField.getText():"control"} # this is for later extension
        self.picPicker.setInputPathDict(inputDict)
        self.picPicker.setOutputPath(self.exPathField.getText())
        
        self.dispose()
        
    def getPicPicker(self):
        return self.picPicker

    def setAnnotationTypeDialog(self, event):
        annotype = self.rBGroup.getSelection().getActionCommand()
        if annotype == "int" or "float":
            self.picPicker.setAnnotationType(["text"])
        if annotype == "yesNoIgnore":
            self.picPicker.setAnnotationType(["Yes", "No", "Ignore"])
    
    def openListDialog(self,event):
        self.makeCustomList()
        #self.customListButton.setEnabled(True)
Exemplo n.º 5
0
class ProjectIngestSettingsPanel(IngestModuleIngestJobSettingsPanel):
    def __init__(self, settings):
        self.local_settings = settings
        self.initComponents()
        self.customizeComponents()

    # def event(self, event):
    #     self.local_settings.setSetting('adb', 'true' if self.adb.isSelected() else 'false')
    #     #self.local_settings.setSetting('clean_temp', 'true' if self.clean_temp.isSelected() else 'false')
    #     self.local_settings.setSetting('old_report', 'true' if self.json_reports.isSelected() else 'false')
    #     # self.local_settings.setSetting('app', self.app.getSelectedItem().split(' (')[0].lower())

    def initComponents(self):
        self.apps_checkboxes_list = []

        self.setLayout(BoxLayout(self, BoxLayout.PAGE_AXIS))
        
        # title 
        self.p_title = SettingsUtils.createPanel()
        self.lb_title = JLabel("Android Forensics")
        self.lb_title.setFont(self.lb_title.getFont().deriveFont(Font.BOLD, 11))
        self.p_title.add(self.lb_title)
        self.add(self.p_title)
        # end of title
        
        
        # info menu
        self.p_info = SettingsUtils.createPanel()
        self.lb_info = JLabel("")
        self.lb_info2 = JLabel("")
        self.p_info.add(self.lb_info)
        self.p_info.add(self.lb_info2)
        
       
        self.add(self.p_info)

        # end of info menu

        # method menu

        self.p_method = SettingsUtils.createPanel()
        self.bg_method = ButtonGroup()
        self.rb_selectedDatasource = SettingsUtils.createRadioButton("Analyse selected datasource", "method_datasource", self.onMethodChange)
        self.rb_importReportFile = SettingsUtils.createRadioButton("Import previous generated report file","method_importfile" ,self.onMethodChange)
        self.rb_liveExtraction = SettingsUtils.createRadioButton("Live extraction with ADB","method_adb", self.onMethodChange)
        self.rb_selectedDatasource.setSelected(True)

        self.bg_method.add(self.rb_selectedDatasource)
        self.bg_method.add(self.rb_importReportFile)
        self.bg_method.add(self.rb_liveExtraction)

        self.p_method.add(JLabel("Analysis method"))
        self.p_method.add(self.rb_selectedDatasource)
        self.p_method.add(self.rb_importReportFile)
        self.p_method.add(self.rb_liveExtraction)
        self.add(self.p_method)

        # end of method menu

        #app checkboxes menu
        self.p_apps = SettingsUtils.createPanel()
        
        sorted_items = OrderedDict(sorted(Utils.get_all_packages().items()))

        for app, app_id in sorted_items.iteritems():
            #(app, app_id)
            checkbox = SettingsUtils.addApplicationCheckbox(app, app_id, self.getSelectedApps)
            self.add(checkbox)
            self.apps_checkboxes_list.append(checkbox)
            self.p_apps.add(checkbox)

        self.add(self.p_apps)
        # end of checkboxes menu

    def customizeComponents(self):
        self.onMethodChange("") #initialize method option
        self.getSelectedApps("") #initialize selected apps
    
    def onMethodChange(self, event):
        self.method = self.bg_method.getSelection().getActionCommand()
        self.local_settings.setSetting("method", self.method)

        if self.method == "method_datasource":
            self.lb_info.setText("This method is used when there is no data source but you have the device.")
            self.lb_info2.setText("It will extract the content of the selected applications from the device, analyze and index the forensic artifacts.")
            self.toggleCheckboxes(False)
            
        elif self.method == "method_importfile":
            self.lb_info.setText("This method is used when you already have a report in json format previously generated by the application.")
            self.lb_info2.setText("It will analyze the report previously added to the data source and index the forensic artifacts.")
            self.toggleCheckboxes(False)
    
        elif self.method == "method_adb":
            self.lb_info.setText("This method is used when the application data has already been collected.")
            self.lb_info2.setText("It will analyze the data source previously added to the data source and index the forensic artifacts.")
            self.toggleCheckboxes(True)

        # self.local_settings.setSetting("apps", self.getSelectedApps())
        
    def getSettings(self):
        return self.local_settings
    
    def getMethod(self):
        return self.bg_method.getSelection().getActionCommand()
    
    def getSelectedApps(self, event):
        selected_apps = []
        
        for cb_app in self.apps_checkboxes_list:
            if cb_app.isSelected():
                selected_apps.append(cb_app.getActionCommand())
        
        self.local_settings.setSetting("apps", json.dumps(selected_apps))
    
    def toggleCheckboxes(self, visible):
        for cb_app in self.apps_checkboxes_list:
            cb_app.setVisible(visible)