Example #1
0
 def downloadResultFile(self, _event=None):
     """Callback for tool click #TODO move to ToolController
     Download the tool result file and asks the user if he or she wants to open it. 
     If OK, tries to open it
     Args:
         _event: not used 
     """
     apiclient = APIClient.getInstance()
     dialog = ChildDialogInfo(self.appliViewFrame, "Download Started",
                              "Downloading...")
     dialog.show()
     abs_path = os.path.dirname(os.path.abspath(__file__))
     outputDir = os.path.join(abs_path, "../../results")
     path = self.controller.getOutputDir(apiclient.getCurrentPentest())
     path = apiclient.getResult(self.controller.getDbId(),
                                os.path.join(outputDir, path))
     dialog.destroy()
     if path is not None:
         if os.path.isfile(path):
             dialog = ChildDialogQuestion(
                 self.appliViewFrame,
                 "Download completed",
                 "The file has been downloaded.\n Would you like to open it?",
                 answers=["Open", "Cancel"])
             self.appliViewFrame.wait_window(dialog.app)
             if dialog.rvalue == "Open":
                 Utils.openPathForUser(path)
                 return
             else:
                 return
         path = None
     if path is None:
         tkinter.messagebox.showerror(
             "Download failed", "the file does not exist on sftp server")
Example #2
0
 def removeItem(self, toDeleteIid):
     """
     Remove defect from given iid in defect treeview
     Args:
         toDeleteIid: database ID of defect to delete
     """
     try:
         item = self.treevw.item(toDeleteIid)
     except tk.TclError:
         return
     dialog = ChildDialogQuestion(
         self.parent, "DELETE WARNING",
         "Are you sure you want to delete defect " + str(item["text"]) +
         " ?", ["Delete", "Cancel"])
     self.parent.wait_window(dialog.app)
     if dialog.rvalue != "Delete":
         return
     self.treevw.delete(toDeleteIid)
     defectToDelete = Defect.fetchObject({
         "title": item["text"],
         "ip": "",
         "port": "",
         "proto": ""
     })
     if defectToDelete is not None:
         defectToDelete.delete()
         self.resizeDefectTreeview()
 def deleteSelected(self, _event):
     """
     Interface to delete a database object from an event.
     Prompt the user a confirmation window.
     Args:
         _event: not used, a ttk Treeview event autofilled. Contains information on what treeview node was clicked.
     """
     n = len(self.selection())
     dialog = ChildDialogQuestion(
         self.parentFrame, "DELETE WARNING",
         "Becareful for you are about to delete " + str(n) +
         " entries and there is no turning back.", ["Delete", "Cancel"])
     self.wait_window(dialog.app)
     if dialog.rvalue != "Delete":
         return
     if n == 1:
         view = self.getViewFromId(self.selection()[0])
         if view is None:
             return
         view.delete(None, False)
     else:
         toDelete = {}
         for selected in self.selection():
             view = self.getViewFromId(selected)
             if view is not None:
                 viewtype = view.controller.model.coll_name
                 if viewtype not in toDelete:
                     toDelete[viewtype] = []
                 toDelete[viewtype].append(view.controller.getDbId())
         apiclient = APIClient.getInstance()
         apiclient.bulkDelete(toDelete)
Example #4
0
 def _download_and_open_template(self, templateName):
     apiclient = APIClient.getInstance()
     path = apiclient.downloadTemplate(self.curr_lang, templateName)
     dialog = ChildDialogQuestion(
         self.parent, "Template downloaded",
         "Template was downloaded here : " + str(path) +
         ". Do you you want to open it ?", ["Open", "Cancel"])
     self.parent.wait_window(dialog.app)
     if dialog.rvalue != "Open":
         return
     openPathForUser(path, folder_only=True)
Example #5
0
 def exportSelection(self, _event=None):
     """
     Popup a window to help a user to export some data from treeview.
     Args:
         _event: not used but mandatory
     """
     values = set()
     for selected in self.selection():
         view_o = self.getViewFromId(selected)
         if view_o is not None:
             data = view_o.controller.getData()
             for key in data.keys():
                 if key == "infos":
                     for info_keys in data["infos"]:
                         values.add("infos." + info_keys)
                 else:
                     values.add(key)
     dialog = ChildDialogExportSelection(self, values)
     self.wait_window(dialog.app)
     if isinstance(dialog.rvalue, list):
         fields_to_export = dialog.rvalue
         f = tk.filedialog.asksaveasfilename(defaultextension=".csv")
         if f is None or len(
                 f
         ) == 0:  # asksaveasfile return `None` if dialog closed with "cancel".
             return
         csv_filename = str(f)
         with open(csv_filename, 'w') as f:
             f.write(", ".join(fields_to_export) + "\n")
             for selected in self.selection():
                 view_o = self.getViewFromId(selected)
                 if view_o is not None:
                     line = []
                     modelData = view_o.controller.getData()
                     for field in fields_to_export:
                         if field.startswith("infos."):
                             line.append(
                                 str(
                                     modelData.get("infos",
                                                   {}).get(field[6:], "")))
                         else:
                             line.append(str(modelData.get(field, "")))
                     f.write(", ".join(line) + "\n")
         dialog = ChildDialogQuestion(
             self, "Export completed", "Your export just finished : " +
             csv_filename + ".\n Do you want to open this folder ?")
         self.wait_window(dialog.app)
         if dialog.rvalue == "Yes":
             openPathForUser(csv_filename, folder_only=True)
Example #6
0
 def removeRemarkItem(self, toDeleteIid):
     """	
     Remove remark from given iid in defect treeview	
     Args:	
         toDeleteIid: database ID of defect to delete	
     """
     item = self.remarks_treevw.item(toDeleteIid)
     dialog = ChildDialogQuestion(
         self.parent, "DELETE WARNING",
         "Are you sure you want to delete remark " + str(item["text"]) +
         " ?", ["Delete", "Cancel"])
     self.parent.wait_window(dialog.app)
     if dialog.rvalue != "Delete":
         return
     self.remarks_treevw.delete(toDeleteIid)
     remarkToDelete = Remark.fetchObject({"title": item["text"]})
     if remarkToDelete is not None:
         remarkToDelete.delete()
         self.resizeRemarkTreeview()
Example #7
0
    def launchCallback(self, _event=None):
        """
        Callback for the launch tool button. Will queue this tool to a worker. #TODO move to ToolController
        Will try to launch respecting limits first. If it does not work, it will asks the user to force launch.

        Args:
            _event: Automatically generated with a button Callback, not used.
        """
        res = self.safeLaunchCallback()
        if not res:
            dialog = ChildDialogQuestion(
                self.appliViewFrame, "Safe queue failed",
                "This tool cannot be launched because no worker add space for its thread.\nDo you want to launch it anyway?"
            )
            self.appliViewFrame.wait_window(dialog.app)
            answer = dialog.rvalue
            if answer == "Yes":
                apiclient = APIClient.getInstance()
                apiclient.sendLaunchTask(self.controller.model.getId(), False)
        if res:
            self.form.clear()
            for widget in self.appliViewFrame.winfo_children():
                widget.destroy()
            self.openModifyWindow()
 def ask_confirmation(self, title, question):
     dialog = ChildDialogQuestion(self.parent, title, question)
     self.parent.wait_window(dialog.app)
     return dialog.rvalue == "Yes"