def on_falsePositiveBtn_clicked(self, event): """Tell the tool server that selected error is a false positive """ check = self.selectedError.check tool = check.tool if tool.falseFeedbackMode == "url": #the tool supports automatic reporting if self.properties.getProperty("false_positive_warning.%s" % tool.name) == "on": messageArguments = array([tool.title], String) formatter = MessageFormat("") formatter.applyPattern(self.strings.getString("false_positive_confirmation")) msg = formatter.format(messageArguments) options = [self.strings.getString("yes_do_not_ask_the_next_time"), self.strings.getString("Yes"), self.strings.getString("No")] answer = JOptionPane.showOptionDialog(Main.parent, msg, self.strings.getString("flagging_a_false_positive"), JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE, None, options, options[2]) if answer == 0: #don't ask again self.properties.setProperty("false_positive_warning.%s" % tool.name, "off") self.save_config(self) elif answer == 2: #don't flag as false positive return tool.sayFalseBug(self.selectedError, check) elif tool.falseFeedbackMode == "msg": #the tool supports manual reporting of false positives if self.properties.getProperty("false_positive_warning.%s" % tool.name) == "on": messageArguments = array([tool.title], String) formatter = MessageFormat("") formatter.applyPattern(self.strings.getString("manual_false_positive_confirmation")) msg = formatter.format(messageArguments) options = [self.strings.getString("yes_do_not_ask_the_next_time"), self.strings.getString("Yes"), self.strings.getString("No")] answer = JOptionPane.showOptionDialog(Main.parent, msg, self.strings.getString("flagging_a_false_positive"), JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE, None, options, options[2]) errorInfo = [tool.title, check.name, self.selectedError.errorId, self.selectedError.osmId] self.falsePositiveDlg.tableModel.addRow(errorInfo) else: #the tool does not support feedback return self.editDone()
def move_script_warning(): """Warn the user to move qat_script directory into Scripting Plugin directory """ scriptingPluginDir = PluginHandler.getPlugin("scripting").getPluginDir() pane = JPanel(GridLayout(3, 1, 5, 5)) warningTitle = "Warning: qat_script directory not found" pane.add(JLabel("Please, move qat_script directory to the following location and start the script again:\n")) defaultPathTextField = JTextField(scriptingPluginDir, editable=0, border=None, background=None) pane.add(defaultPathTextField) if not Desktop.isDesktopSupported(): JOptionPane.showMessageDialog( Main.parent, pane, warningTitle, JOptionPane.WARNING_MESSAGE) else: #add a button to open default path with the files manager pane.add(JLabel("Do you want to open this folder?")) options = ["No", "Yes"] answer = JOptionPane.showOptionDialog( Main.parent, pane, warningTitle, JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, None, options, options[1]) if answer == 1: Desktop.getDesktop().open(File(scriptingPluginDir))
def vulnNameChanged(self): if os.path.exists(self.getCurrentVulnPath()) and self.vulnName.getText() != "": self.addButton.setText("Update") elif self.addButton.getText() != "Add": options = ["Create a new vulnerability", "Change current vulnerability name"] n = JOptionPane.showOptionDialog(None, "Would you like to?", "Vulnerability Name", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, None, options, options[0]); if n == 0: self.clearVulnerabilityTab(False) self.addButton.setText("Add") else: newName = JOptionPane.showInputDialog( None, "Enter new name:", "Vulnerability Name", JOptionPane.PLAIN_MESSAGE, None, None, self.vulnName.getText()) row = self.logTable.getSelectedRow() old = self.logTable.getValueAt(row,1) self.changeVulnName(newName,old)
def loadClick(self, e): returnVal = self._fc.showOpenDialog(self._splitpane) if returnVal == JFileChooser.APPROVE_OPTION: warning = """ CAUTION: Loading a saved configuration deserializes data. This action may pose a security threat to the application. Only proceed when the source and contents of this file is trusted. Load Selected File? """ result = JOptionPane.showOptionDialog(self._splitpane, warning, "Caution", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE, None, ["OK", "Cancel"], "OK") if result != JOptionPane.YES_OPTION: return f = self._fc.getSelectedFile() fileName = f.getPath() ins = io.ObjectInputStream(io.FileInputStream(fileName)) dbData = ins.readObject() ins.close() self._db.load(dbData, self._callbacks, self._helpers) self._userTable.redrawTable() self._messageTable.redrawTable()
def _onExport(control, event): component = control.getElement().getRootElement().getComponent() openDialog = JFileChooser() openDialog.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY) response = openDialog.showDialog(component, 'Export') if response == JFileChooser.APPROVE_OPTION: sf = openDialog.getSelectedFile() if sf is not None: filename = sf.getPath() if filename is not None and os.path.isdir(filename): response = JOptionPane.showOptionDialog( component, 'Existing content will be overwritten. Proceed?', 'Overwrite existing content', JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE, None, ['Overwrite', 'Cancel'], 'Cancel') if response == JFileChooser.APPROVE_OPTION: exc = None try: project.export(filename) except: exc = JythonException.getCurrentException() if exc is not None: BubblePopup.popupInBubbleAdjacentTo( DefaultPerspective.instance(exc), control.getElement(), Anchor.BOTTOM, True, True)
def confirm(message, title="Confirm", allowCancel=False): """Displays a confirmation dialog box to the user with "Yes", "No" and "Cancel" options, and a custom message. Args: message (str): The message to show in the confirmation dialog. title (str): The title for the confirmation dialog. Optional. allowCancel (bool): Show a cancel button in the dialog. Optional. Returns: bool: True (1) if the user selected "Yes", False (0) if the user selected "No", None if the user selected "Cancel". """ options = ["Yes", "No"] if allowCancel: options.append("Cancel") choice = JOptionPane.showOptionDialog( None, message, title, JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, None, options, options[0], ) return ( not bool(choice) if choice in [JOptionPane.YES_OPTION, JOptionPane.NO_OPTION] else None )
def loadClick(self,e): returnVal = self._fc.showOpenDialog(self._splitpane) if returnVal == JFileChooser.APPROVE_OPTION: warning = """ CAUTION: Loading a saved configuration deserializes data. This action may pose a security threat to the application. Only proceed when the source and contents of this file is trusted. Load Selected File? """ result = JOptionPane.showOptionDialog(self._splitpane, warning, "Caution", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE, None, ["OK", "Cancel"],"OK") if result != JOptionPane.YES_OPTION: return f = self._fc.getSelectedFile() fileName = f.getPath() ins = ObjectInputStream(FileInputStream(fileName)) dbData=ins.readObject() ins.close() self._db.load(dbData,self) self._userTable.redrawTable() self._messageTable.redrawTable()
def _buildProjectJar(element, document): component = element.getRootElement().getComponent() larchJarURL = app_in_jar.getLarchJarURL() chosenJarURL = None if larchJarURL is None: openDialog = JFileChooser() openDialog.setFileFilter( FileNameExtensionFilter('Larch executable JAR (*.jar)', ['jar'])) response = openDialog.showDialog(component, 'Choose Larch JAR') if response == JFileChooser.APPROVE_OPTION: sf = openDialog.getSelectedFile() if sf is not None: chosenJarURL = sf.toURI().toURL() else: return jarFile = None bFinished = False while not bFinished: saveDialog = JFileChooser() saveDialog.setFileFilter( FileNameExtensionFilter('JAR file (*.jar)', ['jar'])) response = saveDialog.showSaveDialog(component) if response == JFileChooser.APPROVE_OPTION: sf = saveDialog.getSelectedFile() if sf is not None: if sf.exists(): response = JOptionPane.showOptionDialog( component, 'File already exists. Overwrite?', 'File already exists', JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE, None, ['Overwrite', 'Cancel'], 'Cancel') if response == JFileChooser.APPROVE_OPTION: jarFile = sf bFinished = True else: bFinished = False else: jarFile = sf bFinished = True else: bFinished = True else: bFinished = True if jarFile is not None: outStream = FileOutputStream(jarFile) documentBytes = document.writeAsBytes() nameBytesPairs = [('app.larch', documentBytes)] app_in_jar.buildLarchJar(outStream, nameBytesPairs, larchJarURL=chosenJarURL) outStream.close()
def getOption(title, message, options, optDefault=None): if optDefault is None: optDefault = options[0] val = optPane.showOptionDialog(None, message, title, optPane.DEFAULT_OPTION, optPane.INFORMATION_MESSAGE, None, options, optDefault) return val
def managePlugins(self): try: self.installer.checkPluginDirectory() plugins = self.installer.getAllPluginInfo() if not plugins: JOptionPane.showMessageDialog(self.parentWindow, "No plugins are installed.\n" "If you have a plugin that you wish to install, " "select \"Install Plugin...\" from the \"File\" menu.", TITLE, JOptionPane.ERROR_MESSAGE ) return pluginsByDisplay = dict((info['display'] + ' - ' + info['status'], info) for info in plugins.values()) pluginNames = pluginsByDisplay.keys() pluginNames.sort() while True: name = JOptionPane.showInputDialog(self.parentWindow, "Here are the installed plugins.\n" "Select a plugin to see its description or uninstall it.", TITLE, JOptionPane.QUESTION_MESSAGE, None, pluginNames, pluginNames[0] ) if name is None or name not in pluginsByDisplay: return info = pluginsByDisplay[name] message = info['longDescription'] + '\n' + info['note'] if info['isInstalled']: choice = JOptionPane.showOptionDialog(self.parentWindow, message, TITLE, JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE, None, ["OK", "Uninstall"], "OK" ) if choice == JOptionPane.NO_OPTION: if not self.confirm("Are you sure you want to uninstall\n%s?" % info['display']): return self.installer.uninstall(info) self.notifyDone("%s was removed." % info['title']) return else: JOptionPane.showMessageDialog(self.parentWindow, message, TITLE, JOptionPane.INFORMATION_MESSAGE ) except (EnvironmentError, InvalidPluginError), exc: self.showErrorMessage(exc)
def input(message, title="Input"): """Open up a popup input dialog box. This dialog box will show a prompt message, and allow the user to type in a string. When the user is done, they can press "OK" or "Cancel". If OK is pressed, this function will return with the value that they typed in. If Cancel is pressed, this function will return the value None. Args: message (str): The message to display. This will be translated to the selected Locale. Will accept html formatting. title (str): A title for the input box. This will be translated to the selected Locale. Optional. Returns: str: The string value that was entered in the input box. """ options = [ system.util.translate(constants.OK_TEXT), system.util.translate(constants.CANCEL_TEXT), ] panel = JPanel() label = JLabel("{}: ".format(system.util.translate(message))) panel.add(label) text_field = JTextField(25) panel.add(text_field) choice = JOptionPane.showOptionDialog( None, panel, system.util.translate(title), JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, None, options, options[0], ) return text_field.getText() if choice == JOptionPane.OK_OPTION else None
def dialog(self, message, options=None, default=0, title="GeoGebra", message_type='question'): message_type = message_types[message_type] if options is None: return JOptionPane.showMessageDialog( self.api.appFrame, message, title, message_type ) if isinstance(options, basestring): if options in option_types: option_type = option_types[options] return JOptionPane.showConfirmDialog( self.api.appFrame, message, title, option_type, message_type ) options = options.split("/") default = options[default] return JOptionPane.showOptionDialog( self.api.appFrame, message, title, 0, message_type, None, options, default )
def confirm(message, title="Confirm", show_cancel=False): """Display a confirmation dialog box to the user. This will present the user with "Yes", "No" and "Cancel" options, and a custom message. Args: message (str): The message to display. This will be translated to the selected Locale. title (str): A title for the message box. This will be translated to the selected Locale. Optional. show_cancel (bool): Show a cancel button in the dialog. Optional. Returns: bool: True if the user selected "Yes", False if the user selected "No", None if the user selected "Cancel" or closes the dialog. """ options = [ system.util.translate(constants.YES_TEXT), system.util.translate(constants.NO_TEXT), ] if show_cancel: options.append(system.util.translate(constants.CANCEL_TEXT)) choice = JOptionPane.showOptionDialog( None, system.util.translate(message), system.util.translate(title), JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, None, options, options[0], ) return (not bool(choice) if choice in [JOptionPane.YES_OPTION, JOptionPane.NO_OPTION] else None)
def inputBox(message, defaultText=None): """Opens up a popup input dialog box. This dialog box will show a prompt message, and allow the user to type in a string. When the user is done, they can press "OK" or "Cancel". If OK is pressed, this function will return with the value that they typed in. If Cancel is pressed, this function will return the value None. Args: message (str): The message to display for the input box. Will accept html formatting. defaultText (str): The default text to initialize the input box with. Optional. Returns: str: The string value that was entered in the input box. """ options = ["OK", "Cancel"] panel = JPanel() label = JLabel("{}: ".format(message)) panel.add(label) text_field = JTextField(25) text_field.setText(defaultText) panel.add(text_field) choice = JOptionPane.showOptionDialog( None, panel, "Input", JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, None, options, options[0], ) return text_field.getText() if choice == JOptionPane.OK_OPTION else None
def _onClose(link, event): element = link.getElement() world = fragment.subject.world document = node.getDocument() def _performClose(): document.close() node.appState.unregisterDocument(document) if document.hasUnsavedData(): response = JOptionPane.showOptionDialog( element.rootElement.component, 'You have not saved your work. Close document anyway?', 'Unsaved data', JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE, None, ['Close document', 'Cancel'], 'Cancel') if response == JOptionPane.YES_OPTION: _performClose() else: return else: _performClose()
def actionTarget(self, event): print("*" * 80) self.fileId = [] requestResponses = self.invocation.getSelectedMessages() chosts, ihosts = self.countHostIssues(requestResponses) if self.project <= 1: panelinput = JPanel() panelinput.add(JLabel("Projeto ID: ")) projectq = JTextField(20) panelinput.add(projectq) result = JOptionPane.showOptionDialog( None, panelinput, "Qual projeto enviar Issues?", JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, None, ["OK", "Sem projeto"], "OK") if result == -1: print("[-] Cancelado envio!") return if result == JOptionPane.OK_OPTION: self.project_id.setText(projectq.getText()) self.projectId = str(projectq.getText()) if not re.match('([0-9a-f]{24})', self.projectId): self.projectId = None mess = "Projeto Id formato inválido".decode("utf8") JOptionPane.showMessageDialog(None, mess, "Error", JOptionPane.ERROR_MESSAGE) return mess = "Sessão atual".decode("utf8") ever = JOptionPane.showOptionDialog( None, "Solicitar Id de Projeto novamente?", mess, JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, None, ["Nunca", "Sim"], "Sim") # let user select parameters for new session if ever == JOptionPane.OK_OPTION: self.project = 2 else: self.project = 1 for reqResp in requestResponses: url = reqResp.getHttpService() requestIssues = self._callbacks.getScanIssues(str(url)) listIssues = [] if requestIssues: if len(requestIssues) > 0: for i in requestIssues: scanissue = i if scanissue.getIssueName() not in ['']: sep = "<br><hr><br>" issue = {} issue['Tool_Type'] = "BURP" IssueType = scanissue.getIssueType() IssueName = scanissue.getIssueName() IssueCrit = scanissue.getSeverity() IssueConf = scanissue.getConfidence() protocol = scanissue.getHttpService().getProtocol() host = scanissue.getHttpService().getHost() IssuePath = i.getUrl().getPath() IssueDesc = scanissue.getIssueDetail() IssueDescBk = scanissue.getIssueBackground() IssueRecom = scanissue.getRemediationDetail() IssueRecomBk = scanissue.getRemediationBackground() if IssueType: issue['IssueType'] = scanissue.getIssueType() else: issue['IssueType'] = 0000 if IssueName: issue['DetailsFinding_Title'] = IssueName issue['Recomenation_Title'] = IssueName else: issue['DetailsFinding_Title'] = "No Issue name" issue['Recomenation_Title'] = "No Issue name" if "False positive" in IssueCrit: sTag = "False positive" IssueCrit = "" elif "Information" in IssueCrit: IssueCrit = "Informative" sTag = "" else: sTag = "" if IssueCrit: issue['Severity'] = IssueCrit else: issue['Severity'] = "Informative" issue['Web_Application_URI'] = "{}://{}".format( protocol, host) if IssuePath: issue['Web_Application_Path'] = IssuePath else: issue['Web_Application_Path'] = "/" if IssueConf: issue['fTag'] = IssueConf else: issue['fTag'] = " " issue['sTag'] = sTag if IssueDescBk is not None: issue['Description'] = IssueDescBk.replace( "\n", "") else: issue['Description'] = "" if IssueDesc is not None: issue['Description'] += "{}{}".format( sep, IssueDesc.replace("\n", "")) if IssueRecomBk is not None: issue['Recommendation'] = IssueRecomBk.replace( "\n", "") else: issue['Recommendation'] = IssueName if IssueRecom is not None: issue['Recommendation'] += "{}{}".format( sep, IssueRecom.replace("\n", "")) listIssues.append(issue) self.generateReportGat(listIssues) # iniciar threads print("[+] Thread(s) Iniciada(s)...") if self.project: print("[+] Enviando Issues para o Project Id: {}".format( self.projectId)) print("[+] Enviando {} host(s), total de {} Issue(s),\n".format( chosts, ihosts)) self.launchThread(self.sendIssues)
if not acct: raise Exception("ERROR") get_a_date = JLabel("enter a date (enter as yyyy/mm/dd):") user_selectDateStart = JDateField(CustomDateFormat("ymd"),15) # Use MD API function (not std Python) user_selectDateStart.setDateInt(DateUtil.getStrippedDateInt()) datePanel = JPanel(GridLayout(0, 1)) datePanel.add(get_a_date) datePanel.add(user_selectDateStart) options = ["Cancel", "OK"] userAction = JOptionPane.showOptionDialog(None, datePanel, "Select a Date for balance:", JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, None, options, options[0]) # type: int if userAction != 1: raise Exception("No date entered") theDate = user_selectDateStart.getDateInt() allCurrs=[] currencies = moneydance_data.getCurrencies().getAllCurrencies() for curr in currencies: if curr.getCurrencyType() != CurrencyType.Type.CURRENCY: continue # noqa allCurrs.append(curr) selectedCurr = JOptionPane.showInputDialog(None, "Select Currency", "CURRENCY LIST",
from javax.swing import JFileChooser, JOptionPane, chooser = JFileChooser() option = chooser.showOpenDialog(getMainFrame()) if option == JFileChooser.APPROVE_OPTION: file = chooser.getSelectedFile() if not file.isDirectory(): file = file.getParentFile() folderName = file.getName() #need to sort out get movie name by its folder name #movieName = folderName.replace('.', '') if movieName != None: movieNames = searchMovieByName(movieName) if movieNames == 0: return movieName = movieNames[0] if movieNames.length() > 1: comboBox = JComboBox(movieNames) option = JOptionPane.showOptionDialog(frame, comboBox, "Title", JOptionPane.OK_CANCEL_OPTION, JOptionPane.INFORMATION_MESSAGE, null, null, null); if option == JOptionPane.OK_OPTION: movieName = comboBox.getSelectedItem() addMovie(movieName);
def doInBackground(self): #print "\n- Checking for the latest version..." try: url = URL(self.app.scriptVersionUrl) uc = url.openConnection() ins = uc.getInputStream() p = Properties() p.load(ins) latestScriptVersion = p.getProperty("script") self.app.latestToolsVersion = p.getProperty("tools") except (UnknownHostException, SocketException): print "I can't connect to:\n%s" % url ins.close() return if latestScriptVersion == self.app.SCRIPTVERSION: #using latest script print " already using the latest script version:", self.app.SCRIPTVERSION if self.app.latestToolsVersion == self.app.TOOLSVERSION: #using latest tools print " already using the latest tools version:", self.app.TOOLSVERSION if self.mode != "auto": JOptionPane.showMessageDialog(self.app.preferencesFrame, self.app.strings.getString("using_latest")) return else: #not using latest tools print " tools can be updated: %s -> %s" % (self.app.TOOLSVERSION, self.app.latestToolsVersion) answer = JOptionPane.showConfirmDialog(Main.parent, self.app.strings.getString("update_tools_question"), self.app.strings.getString("updates_available"), JOptionPane.YES_NO_OPTION) if answer == 0: #Download the updated tools data print "\n- Update tools data" try: self.app.toolsProgressDialog except AttributeError: from java.awt import Dialog self.app.toolsProgressDialog = ToolsProgressDialog(Main.parent, self.app.strings.getString("download_tools_updates"), Dialog.ModalityType.APPLICATION_MODAL, self.app) self.app.toolsProgressDialog.show() else: #not using latest script print "a new script version is available:\n%s -> %s" % (self.app.SCRIPTVERSION, latestScriptVersion) messageArguments = array([self.app.SCRIPTVERSION, latestScriptVersion], String) formatter = MessageFormat("") formatter.applyPattern(self.app.strings.getString("updates_warning")) msg = formatter.format(messageArguments) options = [ self.app.strings.getString("Do_not_check_for_updates"), self.app.strings.getString("Visit_Wiki"), self.app.strings.getString("cancel")] answer = JOptionPane.showOptionDialog(Main.parent, msg, self.app.strings.getString("updates_available"), JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, None, options, options[1]) if answer == 0: self.app.properties.setProperty("check_for_update", "off") self.app.save_config(self) elif answer == 1: OpenBrowser.displayUrl(self.app.SCRIPTWEBSITE)
def getOption(title,message,options): return JOptionPane.showOptionDialog(None,message,title,JOptionPane.DEFAULT_OPTION,JOptionPane.QUESTION_MESSAGE,None,options,options[0])