예제 #1
0
 def loadData(self):
     """
     Fetch data from database
     """
     self.ports = Port.fetchObjects({})
     self.ips = Ip.fetchObjects({})
     self.tools = Tool.fetchObjects({})
예제 #2
0
    def addInDb(self):
        """
        Add this scope in database.

        Returns: a tuple with :
                * bool for success
                * mongo ObjectId : already existing object if duplicate, create object id otherwise 
        """
        base = self.getDbKey()
        # Checking unicity
        mongoInstance = MongoCalendar.getInstance()
        existing = mongoInstance.find("scopes", base, False)
        if existing is not None:
            return False, existing["_id"]
        # Inserting scope
        parent = self.getParent()
        res_insert = mongoInstance.insert("scopes", base, parent)
        ret = res_insert.inserted_id
        self._id = ret
        # adding the appropriate tools for this scope.
        wave = mongoInstance.find("waves", {"wave": self.wave}, False)
        commands = wave["wave_commands"]
        for commName in commands:
            if commName.strip() != "":
                self.addAllTool(commName)
        # Testing this scope against every ips
        ips = Ip.fetchObjects({})
        for ip in ips:
            if self._id not in ip.in_scopes:
                if ip.fitInScope(self.scope):
                    ip.addScopeFitting(self.getId())
        return True, ret
예제 #3
0
    def addDomainInDb(self, checkDomain=True):
        """
        Add this scope domain in database.

        Args:
            checkDomain: boolean. If true (Default), checks that the domain IP is in scope

        Returns: a tuple with :
                * bool for success
                * mongo ObjectId : already existing object if duplicate, create object id otherwise 
        """
        # Checking unicity
        base = self.getDbKey()
        mongoInstance = MongoCalendar.getInstance()
        existing = mongoInstance.find("scopes", base, False)
        if existing is not None:
            return 0, None
        # Check if domain's ip fit in one of the Scope of the wave
        if checkDomain:
            if not Scope.checkDomainFit(self.wave, self.scope):
                return -1, None
        # insert the domains in the scopes
        parent = self.getParent()
        res_insert = mongoInstance.insert("scopes", base, parent)
        ret = res_insert.inserted_id
        self._id = ret
        # Adding appropriate tools for this scopes
        wave = mongoInstance.find("waves", {"wave": self.wave}, False)
        commands = wave["wave_commands"]
        for commName in commands:
            comm = mongoInstance.findInDb("pollenisator", "commands", {
                "name": commName,
                "lvl": "network"
            }, False)
            if comm is not None:
                newTool = Tool()
                newTool.initialize(comm["name"], self.wave, self.scope, "", "",
                                   "", "network")
                newTool.addInDb()
            else:
                comm = mongoInstance.findInDb("pollenisator", "commands", {
                    "name": commName,
                    "lvl": "domain"
                }, False)
                if comm is not None:
                    newTool = Tool()
                    newTool.initialize(comm["name"], self.wave, self.scope, "",
                                       "", "", "domain")
                    newTool.addInDb()
        # Testing this scope against every ips
        ips = Ip.fetchObjects({})
        for ip in ips:
            if self._id not in ip.in_scopes:
                if ip.fitInScope(self.scope):
                    ip.addScopeFitting(self.getId())
        ipToInsert = Ip()
        ipToInsert.initialize(self.scope)
        ipToInsert.addInDb()
        return 1, ret
 def _load(self):
     """
     Load the treeview with database information
     """
     mongoInstance = MongoCalendar.getInstance()
     dialog = ChildDialogProgress(self.appli, "Loading "+str(
         mongoInstance.calendarName), "Opening "+str(mongoInstance.calendarName) + ". Please wait for a few seconds.", 200, "determinate")
     step = 0
     dialog.show(100)
     nbObjects = mongoInstance.find("waves").count()
     nbObjects += mongoInstance.find("scopes").count()
     nbObjects += mongoInstance.find("intervals").count()
     nbObjects += mongoInstance.find("scopes").count()
     nbObjects += mongoInstance.find("ips").count()
     nbObjects += mongoInstance.find("ports").count()
     nbObjects += mongoInstance.find("tools").count()
     onePercentNbObject = nbObjects//100 if nbObjects > 100 else 1
     nbObjectTreated = 0
     for child in self.get_children():
         self.delete(child)
     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
     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()