Exemplo n.º 1
0
 def _insertChildrenDefects(self):
     """Insert every children defect in database as DefectView under this node"""
     defects = self.controller.getDefects()
     for defect in defects:
         defect_o = DefectController(Defect(defect))
         defect_vw = DefectView(self.appliTw, self.appliViewFrame,
                                self.mainApp, defect_o)
         defect_vw.addInTreeview(str(self.controller.getDbId()))
Exemplo n.º 2
0
    def addInTreeview(self, parentNode=None, addChildren=True):
        """Add this view in treeview. Also stores infos in application treeview.
        Args:
            parentNode: if None, will calculate the parent. If setted, forces the node to be inserted inside given parentNode.
            addChildren: If False, skip the tool and defects insert. Useful when displaying search results
        """
        if parentNode is None:
            parentNode = self.getParentNode()
            nodeText = str(self.controller.getModelRepr())
        elif parentNode == '':
            nodeText = self.controller.getDetailedString()
        else:
            nodeText = str(self.controller.getModelRepr())
        self.appliTw.views[str(self.controller.getDbId())] = {"view": self}
        try:
            self.appliTw.insert(parentNode,
                                "end",
                                str(self.controller.getDbId()),
                                text=nodeText,
                                tags=self.controller.getTags(),
                                image=self.getClassIcon())
        except TclError:
            pass
        if addChildren:
            defects = self.controller.getDefects()
            for defect in defects:
                defect_o = DefectController(Defect(defect))
                defect_vw = DefectView(self.appliTw, self.appliViewFrame,
                                       self.mainApp, defect_o)
                defect_vw.addInTreeview(str(self.controller.getDbId()))

            tools = self.controller.getTools()
            for tool in tools:
                tool_o = ToolController(Tool(tool))
                tool_vw = ToolView(self.appliTw, self.appliViewFrame,
                                   self.mainApp, tool_o)
                tool_vw.addInTreeview(str(self.controller.getDbId()))

        self.appliTw.sort(parentNode)
        if "hidden" in self.controller.getTags():
            self.hide()
Exemplo n.º 3
0
    def _load(self):
        """
        Load the treeview with database information
        """
        apiclient = APIClient.getInstance()
        dialog = ChildDialogProgress(
            self.appli, "Loading " + str(apiclient.getCurrentPentest()),
            "Opening " + str(apiclient.getCurrentPentest()) +
            ". Please wait for a few seconds.", 200, "determinate")
        step = 0
        dialog.show(100)
        nbObjects = apiclient.count("waves", )
        nbObjects += apiclient.count("scopes")
        nbObjects += apiclient.count("intervals")
        nbObjects += apiclient.count("scopes")
        nbObjects += apiclient.count("ips")
        nbObjects += apiclient.count("ports")
        nbObjects += apiclient.count("tools")
        nbObjects += apiclient.count("commands")
        onePercentNbObject = nbObjects // 100 if nbObjects > 100 else 1
        nbObjectTreated = 0
        self.delete(*self.get_children())
        self._hidden = []
        self._detached = []
        self.waves_node = self.insert("",
                                      "end",
                                      str("waves"),
                                      text="Waves",
                                      image=WaveView.getClassIcon())
        # Loading every category separatly is faster than recursivly.
        # This is due to cursor.next function calls in pymongo
        # Adding wave objects

        self.commands_node = self.insert("",
                                         "end",
                                         "commands",
                                         text="Commands",
                                         image=CommandView.getClassIcon())
        self.group_command_node = self.insert(
            "",
            "end",
            "groupcommands",
            text="Command Groups",
            image=CommandGroupView.getClassIcon())
        self.my_group_command_node = self.insert(
            self.group_command_node,
            "end",
            "mygroupcommands",
            text="My Command Groups",
            image=CommandGroupView.getClassIcon())
        self.worker_group_command_node = self.insert(
            self.group_command_node,
            "end",
            "workergroupcommands",
            text="Worker Command Groups",
            image=CommandGroupView.getClassIcon())
        self.my_commands_node = self.insert(self.commands_node,
                                            "end",
                                            "mycommands",
                                            text="My commands",
                                            image=CommandView.getClassIcon())
        self.worker_commands_node = self.insert(
            self.commands_node,
            "end",
            "workercommands",
            text="Worker commands",
            image=CommandView.getClassIcon())
        self.others_commands_node = self.insert(
            self.commands_node,
            "end",
            "otherscommands",
            text="Others commands",
            image=CommandView.getClassIcon())
        commands = Command.fetchObjects({}, apiclient.getCurrentPentest())
        for command in commands:
            command_vw = CommandView(self, self.appli.viewframe, self.appli,
                                     CommandController(command))
            command_vw.addInTreeview()
        group_commands = CommandGroup.fetchObjects(
            {}, apiclient.getCurrentPentest())
        for command_groupe_vw in group_commands:
            command_groupe_vw = CommandGroupView(
                self, self.appli.viewframe, self.appli,
                CommandGroupController(command_groupe_vw))
            command_groupe_vw.addInTreeview()
        waves = Wave.fetchObjects({})
        for wave in waves:
            wave_o = WaveController(wave)
            wave_vw = WaveView(self, self.appli.viewframe, self.appli, wave_o)
            wave_vw.addInTreeview(self.waves_node, False)
            nbObjectTreated += 1
            if nbObjectTreated % onePercentNbObject == 0:
                step += 1
                dialog.update(step)
        scopes = Scope.fetchObjects({})
        for scope in scopes:
            scope_o = ScopeController(scope)
            scope_vw = ScopeView(self, self.appli.viewframe, self.appli,
                                 scope_o)
            scope_vw.addInTreeview(None, False)
            nbObjectTreated += 1
            if nbObjectTreated % onePercentNbObject == 0:
                step += 1
                dialog.update(step)
        intervals = Interval.fetchObjects({})
        for interval in intervals:
            interval_o = IntervalController(interval)
            interval_vw = IntervalView(self, self.appli.viewframe, self.appli,
                                       interval_o)
            interval_vw.addInTreeview(None, False)
            nbObjectTreated += 1
            if nbObjectTreated % onePercentNbObject == 0:
                step += 1
                dialog.update(step)
        #Adding ip objects
        self.ips_node = self.insert("",
                                    "end",
                                    str("ips"),
                                    text="IPs",
                                    image=IpView.getClassIcon())
        ips = Ip.fetchObjects({})
        for ip in ips:
            ip_o = IpController(ip)
            ip_vw = IpView(self, self.appli.viewframe, self.appli, ip_o)
            ip_vw.addInTreeview(None, False)
            self.appli.statusbar.notify(ip_vw.controller.getTags())
            nbObjectTreated += 1
            if nbObjectTreated % onePercentNbObject == 0:
                step += 1
                dialog.update(step)
        # Adding port objects
        ports = Port.fetchObjects({})
        for port in ports:
            port_o = PortController(port)
            port_vw = PortView(self, self.appli.viewframe, self.appli, port_o)
            port_vw.addInTreeview(None, False)
            self.appli.statusbar.notify(port_vw.controller.getTags())
            nbObjectTreated += 1
            if nbObjectTreated % onePercentNbObject == 0:
                step += 1
                dialog.update(step)
        # Adding defect objects
        defects = Defect.fetchObjects({"ip": {"$ne": ""}})
        for defect in defects:
            defect_o = DefectController(defect)
            defect_vw = DefectView(self, self.appli.viewframe, self.appli,
                                   defect_o)
            defect_vw.addInTreeview(None)
            nbObjectTreated += 1
            if nbObjectTreated % onePercentNbObject == 0:
                step += 1
                dialog.update(step)
        # Adding tool objects
        tools = Tool.fetchObjects({})
        for tool in tools:
            tool_o = ToolController(tool)
            tool_vw = ToolView(self, self.appli.viewframe, self.appli, tool_o)
            tool_vw.addInTreeview(None, False)
            self.appli.statusbar.notify(tool_vw.controller.getTags())
            nbObjectTreated += 1
            if nbObjectTreated % onePercentNbObject == 0:
                step += 1
                dialog.update(step)
        self.sort(self.ips_node)
        self.appli.statusbar.update()
        dialog.destroy()