示例#1
0
文件: newgui.py 项目: tsondt/Canvas
    def pull_down_targeting(self, obj, ip):
        """ handles pull down targeting """

        # we dont need to draw shizit for this, but we do need to set the target_line for unsets
        p_key = None
        host = None
        for key in self.graph.hosts.keys():
            p_host = self.graph.hosts[key]
            if len(p_host['children']):
                if ip in p_host['children'].keys():
                    print "[!] found parent host for child ip: %s" % ip
                    p_key = key
                    host = p_host['children'][ip]

        # operate on found child host
        if host['target'] == False:
            host['target_line'] = hostKnowledge(ip, None)
            host['target'] = True
        else:
            if host['target_line']:
                if self.engine.unset_target_host(host['target_line']) != False:
                    host['target'] = False
                    host['target_line'] = None
                else:
                    print "[X] could not unset target .. likely set as primary target ? reverting to initial values .. "
                    # back up to target_hosts backup
                    host['target'] = False
                    host['target_line'] = None
                    self.engine.set_target_host(self.target_hosts_init[0])

        # update the object in the list
        self.graph.hosts[p_key]['children'][ip] = host
        # update the targeting in the engine list
        self.update_targets()
        return
示例#2
0
    def add_host(self, newhost):
        if type(newhost) == type(""):
            #newhost is a string
            #duplicate check
            a = self.get_known_host(newhost)
            if a:
                return a
            newhost = hostKnowledge(newhost, self)  #not anymore

        self.add_hostKnowledge(newhost)
        return newhost
示例#3
0
    def new_host(self, ip, add=1, resolved_from=None):
        """We know something about a new host!"""

        ##Stop 0.0.0.0 being added as that's just plain stupid
        if ip == "0.0.0.0":
            self.log(
                "0.0.0.0 is not a valid target address, changing to 127.0.0.1")
            ip = "127.0.0.1"

        # XXX: check for ipv6 compliance
        devlog('CANVASNode::new_host', "(%s)" % ip)
        for c in self.hostsknowledge.children:
            if c.interface == ip:
                #we already know about that host
                return c

        if resolved_from:
            newhost = hostKnowledge(ip,
                                    self,
                                    doDNS=False,
                                    resolved_from=resolved_from)
        else:
            newhost = hostKnowledge(ip, self)

        newhost.engine = self.engine

        if add:
            self.add_hostKnowledge(newhost)

            if self.engine:
                self.engine.new_event(
                    "new host", {
                        "ip": ip,
                        "resolved_from": newhost.resolved_from,
                        "node": self.getname(),
                    })

        return newhost
示例#4
0
    def new_host(self, ip, add=1):
        """We know something about a new host!"""

        # XXX: check for ipv6 compliance
        devlog('CANVASNode::new_host', "(%s)" % ip)
        for c in self.hostsknowledge.children:
            if c.interface == ip:
                #we already know about that host
                return c

        newhost = hostKnowledge(ip, self)
        newhost.engine = self.engine
        if not add:
            return newhost
        return self.add_host(newhost)
示例#5
0
    def add_host(self, newhost, lookup=True):

        if type(newhost) == type(""):
            #newhost is a string
            #duplicate check
            a = self.get_known_host(newhost)
            if a:
                return a
            newhost = hostKnowledge(newhost, self, doDNS=lookup)  #not anymore
        else:
            ##dupe check
            a = self.get_known_host(newhost.interface)
            if a:
                return a

        self.add_hostKnowledge(newhost)

        return newhost
示例#6
0
文件: newgui.py 项目: tsondt/Canvas
    def on_graph_line_press(self, obj, event):
        """ Similar to our line_press for traditional menu stuff, but for graphs """

        x = event.x
        y = event.y
        self.eventbutton = event.button

        #print "XXX: TARGET FRAME -> button press (x: %d, y: %d)"% (event.x, event.y)
        # check if we have a callback handler for this map click in any known hosts
        for host_key in self.graph.hosts.keys():
            host = self.graph.hosts[host_key]

            host_x = host['x']
            host_y = host['y']
            if x in range(host_x, host_x + 5) and y in range(
                    host_y, host_y + 5):
                handler = host['click_handler']
                ip = host['ip']

                # if we want button specific actions .. do it here
                if event.button == 1:
                    # XXX: engine call from gui code .. but will do

                    if host['target'] == False:
                        host['target_line'] = hostKnowledge(ip, None)
                        host['target'] = True
                    else:
                        if host['target_line']:
                            if self.engine.unset_target_host(
                                    host['target_line']) != False:
                                host['target'] = False
                                host['target_line'] = None
                            else:
                                print "[X] could not unset target .. likely set as primary target ? reverting to initial values .. "
                                # back up to target_hosts backup
                                host['target'] = False
                                host['target_line'] = None
                                self.engine.set_target_host(
                                    self.target_hosts_init[0])

                    # update the object in the list
                    self.graph.hosts[host_key] = host
                    # update the targeting in the gui
                    self.update_targets()
                    self.graph.redraw()
                    continue

                if event.button == 2:
                    # you can set click handler to be anything .. good for glueing in your own non-canvas modules ;)
                    if handler:
                        handler()
                    continue

                if event.button == 3:
                    # handle any available additional hosts for that city location
                    item_handlers = {}
                    if len(host['children']):
                        for ip in host['children']:
                            # this is where the actual activate handler function is set
                            item_handlers[ip] = self.pull_down_targeting
                        # show the menu
                        self.graph.pop_up_menu(item_handlers, event.button,
                                               event.time)
                    else:
                        print "[X] No additional hosts available for this location .."
                    continue

        return