コード例 #1
0
    def connect_to_peer(self, peer_id):
        if self.agent_is_banned(peer_id):
            g_logger.info("Agent %s is banned." % peer_id)

        if peer_id == theApp.peer_info.ID:
            g_logger.error("Can't connect to self.")
        if peer_id not in self.sessions:
            peer_entry = None
            if peer_id in self.super_peers:
                peer_entry = self.super_peers[peer_id]
            elif peer_id in self.normal_peers:
                peer_entry = self.normal_peers[peer_id]
            elif peer_id in self.mobile_peers:
                peer_entry = self.mobile_peers[peer_id]
            else:
                g_logger.error("Peer id '%s' doesn't exist in all peer lists." %
                               peer_id)
                return

            if self.network_is_banned(peer_entry.IP):
                g_logger.info("Agent %s is banned in network grounds (%s)." % \
                                 (peer_id, peer_entry.IP))
                return

            reactor.connectTCP(peer_entry.IP, peer_entry.Port,
                               theApp.factory)
            g_logger.debug("Connecting to %s:%d..." %
                           (peer_entry.IP, peer_entry.Port))
コード例 #2
0
    def add_mobile_peer(self, peer_id, ip, port, ciphered_public_key=None,
                        status='Disconnected', network_id=0):
        if self.agent_is_banned(peer_id) or self.network_is_banned(ip):
            g_logger.info("Mobile agent %s is banned or is running from a banned "
                          "network %s" % (peer_id, ip))

            if peer_id in self.mobile_peers:
                self.remove_mobile_peer(peer_id)

            return

        if peer_id in self.mobile_peers:
            g_logger.info("Peer id %s already exists in mobile peer list." %
                          peer_id)
        else:
            peer_entry = PeerEntry()
            peer_entry.Type = 3
            peer_entry.ID = peer_id
            peer_entry.IP = ip
            peer_entry.Port = port
            peer_entry.CipheredPublicKey = ciphered_public_key
            peer_entry.status = status
            peer_entry.network_id = network_id
            self.mobile_peers[peer_entry.ID] = peer_entry
            self.mobile_peer_num = self.mobile_peer_num + 1
コード例 #3
0
    def add_normal_peer(self, peer_id, ip, port, token =None ,ciphered_public_key=None,
                        status='Disconnected', network_id=0):
        """
        """
        #if self.agent_is_banned(peer_id) or self.network_is_banned(ip):
        #    g_logger.info("Desktop agent %d is banned or is running from a banned "
        #                  "network %s" % (peer_id, ip))
        #    
        #    if peer_id in self.normal_peers:
        #        self.remove_normal_peer(peer_id)
        #
        #    return

        if peer_id in self.normal_peers:
            g_logger.info("Peer id %s already exists in normal peer list." %
                          peer_id)
        else:
            peer_entry = PeerEntry()
            peer_entry.Type = 2
            peer_entry.ID = peer_id
            peer_entry.IP = ip
            peer_entry.Port = port
            peer_entry.Token = token
            peer_entry.CipheredPublicKey = ciphered_public_key
            peer_entry.status = status
            peer_entry.network_id = network_id
            self.normal_peers[peer_entry.ID] = peer_entry
            self.normal_peer_num = self.normal_peer_num + 1       
コード例 #4
0
    def _normal_peer_connected(self, peer_id, ip, port, ciphered_public_key=None,
                              network_id=0):
        if self.agent_is_banned(peer_id) or self.network_is_banned(ip):
            g_logger.info("Desktop agent %s is banned or is running from "
                          "a banned network %s" % (peer_id, ip))
            if peer_id in self.normal_peers:
                self.remove_normal_peer(peer_id)
            return False

        if peer_id in self.normal_peers and \
           self.normal_peers[peer_id].status == 'Connected':
            g_logger.warning("Peer %s already connected." % peer_id)
            return False

        if peer_id in self.normal_peers:
            g_logger.debug("Peer id %s already exists in normal peer list." %
                           peer_id)
            self.normal_peers[peer_id].status = 'Connected'
        else:
            peer_entry = PeerEntry()
            peer_entry.Type = 2
            peer_entry.ID = peer_id
            peer_entry.IP = ip
            peer_entry.Port = port
            peer_entry.CipheredPublicKey = ciphered_public_key
            peer_entry.status = 'Connected'
            peer_entry.network_id = network_id
            self.normal_peers[peer_entry.ID] = peer_entry

        self.connected_peer_num = self.connected_peer_num + 1
        
        return True
コード例 #5
0
 def sync_bannets(self, message):
     for network in message.networks:
         ban = g_db_helper.insert_banned_network(network.start_ip,
                                                 network.end_ip,
                                                 network.nodes_count,
                                                 network.flags)
         g_logger.info("Banned %s: %s" % (network, str(ban)))
コード例 #6
0
 def get_tests(self,current_version):
     """
     """
     g_logger.info("Send P2PGetSuperPeerList message to %s" % self.remote_ip)
     request_msg = NewTests()
     request_msg.currentTestVersionNo = int(current_version)  #Get current version from DB
     self._send_message(request_msg)        
コード例 #7
0
 def sync_bannets(self, message):
     for network in message.networks:
         ban = g_db_helper.insert_banned_network(network.start_ip,
                                                 network.end_ip,
                                                 network.nodes_count,
                                                 network.flags)
         g_logger.info("Banned %s: %s" % (network, str(ban)))
コード例 #8
0
    def connect_to_peer(self, peer_id):
        if self.agent_is_banned(peer_id):
            g_logger.info("Agent %s is banned." % peer_id)

        if peer_id == theApp.peer_info.ID:
            g_logger.error("Can't connect to self.")
        if peer_id not in self.sessions:
            peer_entry = None
            if peer_id in self.super_peers:
                peer_entry = self.super_peers[peer_id]
            elif peer_id in self.normal_peers:
                peer_entry = self.normal_peers[peer_id]
            elif peer_id in self.mobile_peers:
                peer_entry = self.mobile_peers[peer_id]
            else:
                g_logger.error(
                    "Peer id '%s' doesn't exist in all peer lists." % peer_id)
                return

            if self.network_is_banned(peer_entry.IP):
                g_logger.info("Agent %s is banned in network grounds (%s)." % \
                                 (peer_id, peer_entry.IP))
                return

            reactor.connectTCP(peer_entry.IP, peer_entry.Port, theApp.factory)
            g_logger.debug("Connecting to %s:%d..." %
                           (peer_entry.IP, peer_entry.Port))
コード例 #9
0
 def irc_NICK(self,prefix,params):
     """
     called when an IRC user changes their nickname
     """
     old_nick = prefix.split('!')[0]
     new_nick = params[0]
     g_logger.info("[ServiceTest:IRC]%s is now known as %s:" % (old_nick,new_nick))  
コード例 #10
0
 def get_super_peer_list(self, count):
     g_logger.info(
         "[DesktopAgentSession] Send P2PGetSuperPeerList message to %s" %
         self.remote_ip)
     request_msg = P2PGetSuperPeerList()
     request_msg.count = int(count)
     self._send_message(request_msg)
コード例 #11
0
 def _handle_check_aggregator_website_err(self,failure):
     """
     """
     g_logger.info("Cannot connect Aggregator website: %s" % self.base_url)
     self.available = False
     
     return self.available
コード例 #12
0
    def add_mobile_peer(self,
                        peer_id,
                        ip,
                        port,
                        ciphered_public_key=None,
                        status='Disconnected',
                        network_id=0):
        if self.agent_is_banned(peer_id) or self.network_is_banned(ip):
            g_logger.info(
                "Mobile agent %s is banned or is running from a banned "
                "network %s" % (peer_id, ip))

            if peer_id in self.mobile_peers:
                self.remove_mobile_peer(peer_id)

            return

        if peer_id in self.mobile_peers:
            g_logger.info("Peer id %s already exists in mobile peer list." %
                          peer_id)
        else:
            peer_entry = PeerEntry()
            peer_entry.Type = 3
            peer_entry.ID = peer_id
            peer_entry.IP = ip
            peer_entry.Port = port
            peer_entry.CipheredPublicKey = ciphered_public_key
            peer_entry.status = status
            peer_entry.network_id = network_id
            self.mobile_peers[peer_entry.ID] = peer_entry
            self.mobile_peer_num = self.mobile_peer_num + 1
コード例 #13
0
def update_test_mod(result, *args, **kw):
    g_logger.info("Updating Test Module...")
    # args = ((version, check_code=0), {})
    version = args[0]
    if len(args) == 2:
        check_code = args[1]
    else:
        check_code = 0

    filename = 'test_' + version + '.py'
    path = os.path.join(TMP_DIR, filename)
    if not os.path.exists(path):
        g_logger.error("Test mod %s can't be found under '/tmp' folder." %
                       filename)
        return

    if check_code != 0:
        # Verify if the file is the correct one
        content = open(filename, 'rb').read()
        crc = zlib.crc32(content) & 0xffffffff
        if crc != check_code:
            g_logger.error("Test mod %s is corrupt. Try to download it again." %
                           filename)
            return

    # Rename the original test.py to test.py.bak,
    # and replace test.py with new one
    origin = os.path.join(ROOT_DIR, 'umit', 'icm', 'agent', 'test.py')
    shutil.copy(origin, origin + '.bak')
    shutil.copy(path, origin)
    if 'umit.icm.agent.test' in sys.modules:
        reload(sys.modules['umit.icm.agent.test'])
    g_logger.info("Test Module updated.")
コード例 #14
0
def update_test_mod(result, *args, **kw):
    g_logger.info("Updating Test Module...")
    # args = ((version, check_code=0), {})
    version = args[0]
    if len(args) == 2:
        check_code = args[1]
    else:
        check_code = 0

    filename = 'test_' + version + '.py'
    path = os.path.join(TMP_DIR, filename)
    if not os.path.exists(path):
        g_logger.error("Test mod %s can't be found under '/tmp' folder." %
                       filename)
        return

    if check_code != 0:
        # Verify if the file is the correct one
        content = open(filename, 'rb').read()
        crc = zlib.crc32(content) & 0xffffffff
        if crc != check_code:
            g_logger.error(
                "Test mod %s is corrupt. Try to download it again." % filename)
            return

    # Rename the original test.py to test.py.bak,
    # and replace test.py with new one
    origin = os.path.join(ROOT_DIR, 'umit', 'icm', 'agent', 'test.py')
    shutil.copy(origin, origin + '.bak')
    shutil.copy(path, origin)
    if 'umit.icm.agent.test' in sys.modules:
        reload(sys.modules['umit.icm.agent.test'])
    g_logger.info("Test Module updated.")
コード例 #15
0
    def _super_peer_connected(self,
                              peer_id,
                              ip,
                              port,
                              ciphered_public_key=None,
                              network_id=0):
        if self.agent_is_banned(peer_id) or self.network_is_banned(ip):
            g_logger.info("Super agent %s is banned or is running from "
                          "a banned network %s" % (peer_id, ip))
            if peer_id in self.super_peers:
                self.remove_super_peer(peer_id)
            return False

        if peer_id in self.super_peers and \
           self.super_peers[peer_id].status == 'Connected':
            g_logger.warning("Peer %s already connected." % peer_id)
            return False

        if peer_id in self.super_peers:
            g_logger.debug("Peer id %s already exists in super peer list." %
                           peer_id)
            self.super_peers[peer_id].status = 'Connected'
        else:
            peer_entry = PeerEntry()
            peer_entry.Type = 1
            peer_entry.ID = peer_id
            peer_entry.IP = ip
            peer_entry.Port = port
            peer_entry.CipheredPublicKey = ciphered_public_key
            peer_entry.status = 'Connected'
            peer_entry.network_id = network_id
            self.super_peers[peer_entry.ID] = peer_entry

        self.connected_speer_num = self.connected_speer_num + 1
        return True
コード例 #16
0
 def _handle_check_aggregator_website_err(self,failure):
     """
     """
     g_logger.info("Cannot connect Aggregator website: %s" % self.base_url)
     self.available = False
     
     return self.available
コード例 #17
0
 def handle_message(self, message):
     if isinstance(message, P2PGetSuperPeerList):
         self._handle_get_super_peer_list(message)
     elif isinstance(message, P2PGetSuperPeerListResponse):
         self._handle_get_super_peer_list_response(message)
     elif isinstance(message, P2PGetPeerList):
         self._handle_get_peer_list(message)
     elif isinstance(message, P2PGetPeerListResponse):
         self._handle_get_peer_list_response(message)
     elif isinstance(message, SendWebsiteReport):
         self._handle_send_website_report(message)
     elif isinstance(message, SendServiceReport):
         self._handle_send_service_report(message)
     elif isinstance(message, SendReportResponse):
         self._handle_send_report_response(message)
     elif isinstance(message,NewVersionResponse):
         self._hanlde_new_version_response(message)         
     elif isinstance(message, AgentUpdateResponse):
         g_logger.info("Peer %s update agent to version %s: %S" %
                       (self.remote_id, message.version, message.result))
     elif isinstance(message, TestModuleUpdateResponse):
         g_logger.info("Peer %s update test mod to version %s: %S" %
                       (self.remote_id, message.version, message.result))
     elif isinstance(message, NewTestsResponse):
         self._handle_get_tests_response(message)
     elif isinstance(message,NewTests):
         self._handle_get_tests(message)
コード例 #18
0
 def handle_message(self, message):
     if isinstance(message, P2PGetSuperPeerList):
         self._handle_get_super_peer_list(message)
     elif isinstance(message, P2PGetSuperPeerListResponse):
         self._handle_get_super_peer_list_response(message)
     elif isinstance(message, P2PGetPeerList):
         self._handle_get_peer_list(message)
     elif isinstance(message, P2PGetPeerListResponse):
         self._handle_get_peer_list_response(message)
     elif isinstance(message, SendWebsiteReport):
         self._handle_send_website_report(message)
     elif isinstance(message, SendServiceReport):
         self._handle_send_service_report(message)
     elif isinstance(message, SendReportResponse):
         self._handle_send_report_response(message)
     elif isinstance(message, NewVersionResponse):
         self._hanlde_new_version_response(message)
     elif isinstance(message, AgentUpdateResponse):
         g_logger.info("Peer %s update agent to version %s: %S" %
                       (self.remote_id, message.version, message.result))
     elif isinstance(message, TestModuleUpdateResponse):
         g_logger.info("Peer %s update test mod to version %s: %S" %
                       (self.remote_id, message.version, message.result))
     elif isinstance(message, NewTestsResponse):
         self._handle_get_tests_response(message)
     elif isinstance(message, NewTests):
         self._handle_get_tests(message)
コード例 #19
0
    def add_normal_peer(self,
                        peer_id,
                        ip,
                        port,
                        token=None,
                        ciphered_public_key=None,
                        status='Disconnected',
                        network_id=0):
        """
        """
        #if self.agent_is_banned(peer_id) or self.network_is_banned(ip):
        #    g_logger.info("Desktop agent %d is banned or is running from a banned "
        #                  "network %s" % (peer_id, ip))
        #
        #    if peer_id in self.normal_peers:
        #        self.remove_normal_peer(peer_id)
        #
        #    return

        if peer_id in self.normal_peers:
            g_logger.info("Peer id %s already exists in normal peer list." %
                          peer_id)
        else:
            peer_entry = PeerEntry()
            peer_entry.Type = 2
            peer_entry.ID = peer_id
            peer_entry.IP = ip
            peer_entry.Port = port
            peer_entry.Token = token
            peer_entry.CipheredPublicKey = ciphered_public_key
            peer_entry.status = status
            peer_entry.network_id = network_id
            self.normal_peers[peer_entry.ID] = peer_entry
            self.normal_peer_num = self.normal_peer_num + 1
コード例 #20
0
    def _handle_check_version_response(self, message):

        if message is None:
            return
        g_logger.info("Get check_version_response %s" % message)

        #add the record into the Database
        from umit.icm.agent.gui.SoftwareUpdate import check_update_item_in_db, insert_update_item_in_db, no_updated
        check_message = {}

        check_message["download_url"] = message.downloadURL
        check_message["version"] = str(message.versionNo)
        check_message["news_date"] = time.strftime("%Y-%m-%d",
                                                   time.localtime())
        check_message["software_name"] = "OpenMonitor Desktop V" + str(
            message.versionNo)
        check_message["is_update"] = no_updated
        check_message["description"] = "Open Monitor Desktop Agent!"
        check_message["check_code"] = ""

        if not check_update_item_in_db(check_message["version"]):
            insert_update_item_in_db(check_message)
            g_logger.info("Write a new update record into DB :%s" %
                          check_message)

        return message
コード例 #21
0
 def _send_message(self, message, transport):
     g_logger.info("Sending a %s message to %s" % (message.DESCRIPTOR.name,
                                                   transport.getPeer()))
     data = MessageFactory.encode(message)
     length = struct.pack('!I', len(data))
     transport.write(length)
     transport.write(data)
コード例 #22
0
 def get_tests(self,current_version):
     """
     """
     g_logger.info("[DesktopAgentSession]  Send Test Sets message to %s" % self.remote_ip)
     request_msg = NewTests()
     request_msg.currentTestVersionNo = int(current_version)  #Get current version from DB
     self._send_message(request_msg)        
コード例 #23
0
    def add_super_peer(self,
                       peer_id,
                       ip,
                       port,
                       token=None,
                       ciphered_public_key=None,
                       status='Disconnected',
                       network_id=0):
        """
        """
        if peer_id in self.super_peers:
            g_logger.info("Peer id %s already exists in Super Peer List" %
                          peer_id)
        else:
            peer_entry = PeerEntry()
            peer_entry.Type = 1
            peer_entry.ID = peer_id
            peer_entry.IP = ip
            peer_entry.Port = port
            peer_entry.Token = token
            peer_entry.CipheredPublicKey = ciphered_public_key
            peer_entry.status = status
            peer_entry.network_id = network_id
            self.super_peers[peer_entry.ID] = peer_entry
            self.super_peer_num += 1

            g_logger.info("Super peer(%s) is added successfully!" %
                          (peer_entry.ID))
コード例 #24
0
 def _send_message(self, message, transport):
     g_logger.info("Sending a %s message to %s" %
                   (message.DESCRIPTOR.name, transport.getPeer()))
     data = MessageFactory.encode(message)
     length = struct.pack('!I', len(data))
     transport.write(length)
     transport.write(data)
コード例 #25
0
 def set_super_peer_manual(self, ip, port, description=""):
     """
     add super peer information into super_peer_manual table
     """
     sql_str = "insert or replace into super_peers_manual values " "('%s', '%s', '%s')" % (ip, port, description)
     g_logger.info("[save_to_db]:save %s into DB" % sql_str)
     self.execute(sql_str)
コード例 #26
0
    def set_test_version(self, version):

        self.current_test_version = version
        g_logger.info("Save current test version: %s" %
                      (str(self.current_test_version)))
        g_config.set('Test', 'test_current_version',
                     str(self.current_test_version))
コード例 #27
0
    def check_username(self, username="", password=""):
        """
        check username and password in DB, the information is got from Login-Window
        """
        rs = g_db_helper.select(
            "select * from  peer_info where username='******' and \
                                password='******'" % (username, password))
        if not rs:
            g_logger.info("No matching peer info in db.\
                           icm-agent will register the username or password")
            return False
        else:
            g_logger.info("Match the username and password, \
                           we will change the default credentials")
            g_logger.debug(rs[0])

            self.peer_info.ID = rs[0][0]
            self.peer_info.Username = rs[0][1]
            self.peer_info.Password = rs[0][2]
            self.peer_info.Email = rs[0][3]
            self.peer_info.CipheredPublicKeyHash = rs[0][4]
            self.peer_info.Type = rs[0][5]
            self.peer_info.is_registered = True

            return True
コード例 #28
0
 def irc_NICK(self, prefix, params):
     """
     called when an IRC user changes their nickname
     """
     old_nick = prefix.split('!')[0]
     new_nick = params[0]
     g_logger.info("[ServiceTest:IRC]%s is now known as %s:" %
                   (old_nick, new_nick))
コード例 #29
0
 def _linux_clear(self):
     file = self.auto_sys_path + self.desktop_name
     if os.path.exists(file):
         try:
             os.remove(file)
             g_logger.info("Cancel Auto StartUP icm-agent in Linux (%s)" % (file))
         except Exception, e:
             g_logger.error("[Failed] Cancel Auto StartUP icm-agent in Linux  (%s)" % (file))
コード例 #30
0
    def _handle_register_response(self, message):
        if message is None:
            g_logger.error("Empty response while trying to register.")
            return

        g_logger.info("RegisterAgent response: (%s, %s)" %
                      (message.agentID, message.publicKeyHash))

        return {'id': message.agentID, 'hash': message.publicKeyHash}
コード例 #31
0
 def verifyHostKey(self,host_key,fingerprint=""):
     g_logger.info("host key fingerprint %s" % fingerprint)  
     #we cannot provide the key, so we should check the failure to decide the result
     if self.reportDeferred:
         task_done(self.__class__.__name__, TEST_SERVICE_TYPE, self.test)
         result = {'status_code': 0, 'time_end': default_timer()}
         self.reportDeferred.callback(result)     
     self.loseConnection()
     return defer.succeed(1)
コード例 #32
0
 def send_service_report(self, report):
     g_logger.info("Send %s message to %s" % (report.DESCRIPTOR.name,
                                              self.remote_ip))
     request_msg = SendServiceReport()
     #request_msg.header.token = theApp.peer_info.AuthToken
     #request_msg.header.agentID = str(theApp.peer_info.ID)
     request_msg.report.CopyFrom(report)
     self._send_message(request_msg)
     self.pending_report_ids.append(report.header.reportID)
コード例 #33
0
 def _handle_check_tests_response(self, message):
     if message is None:
         return
     
     #print message.tests
     #print message.testVersionNo
     
     g_logger.info("Receive Test Sets!")     
     return message
コード例 #34
0
    def show_details(self, task_type):
        """
        """
        self.task_list_dict = {}
        cnt = 0

        from umit.icm.agent.gui.dashboard.DashboardListBase import TASK_ALL, TASK_SUCCESSED, TASK_FAILED

        #########################
        # Get Task Details From DB
        rs = g_db_helper.get_task_sets(task_type=task_type)

        if rs == None:
            g_logger.info("Cannot load any Tasks from DB.")
            self.treeview.set_sensitive(True)
            self.store.clear()
            self.treeview.set_model(self.store)  # It must be after the store update
            return

        for record in rs:
            self.task_list_dict[cnt] = {}
            self.task_list_dict[cnt]["sequence"] = record[0]
            self.task_list_dict[cnt]["test_id"] = record[1]
            self.task_list_dict[cnt]["website_url"] = record[2]
            self.task_list_dict[cnt]["test_type"] = record[3]
            self.task_list_dict[cnt]["service_name"] = record[4]
            self.task_list_dict[cnt]["service_ip"] = record[5]
            self.task_list_dict[cnt]["service_port"] = record[6]
            self.task_list_dict[cnt]["done_status"] = record[7]
            self.task_list_dict[cnt]["done_result"] = record[8]
            self.task_list_dict[cnt]["execute_time"] = record[9]
            cnt += 1

        g_logger.info("Loaded %d tasks from DB." % len(rs))

        #####################
        # Output in the Window
        self.treeview.set_sensitive(True)
        self.store.clear()

        for line in self.task_list_dict.keys():
            self.store.append(
                [
                    self.task_list_dict[line]["sequence"],
                    self.task_list_dict[line]["test_id"],
                    self.task_list_dict[line]["website_url"],
                    self.task_list_dict[line]["test_type"],
                    self.task_list_dict[line]["service_name"],
                    self.task_list_dict[line]["service_ip"],
                    self.task_list_dict[line]["service_port"],
                    self.task_list_dict[line]["done_status"],
                    self.task_list_dict[line]["done_result"],
                    self.task_list_dict[line]["execute_time"],
                ]
            )

        self.treeview.set_model(self.store)  # It must be after the store update
コード例 #35
0
 def _handle_check_tests_response(self, message):
     if message is None:
         return
     
     #print message.tests
     #print message.testVersionNo
     
     g_logger.info("Receive Test Sets!")     
     return message
コード例 #36
0
    def _handle_get_bannets_response(self, message):
        g_logger.info("GET BANNETS RESPONSE: %s" % message)
        if message is None:
            return

        # TODO: Store the bannets locally
        theApp.peer_manager.sync_bannets(message)

        return message
コード例 #37
0
 def save_to_db(self):
     if self.is_registered:
         sql_str = "insert or replace into peer_info values " \
                         "('%s', '%s', '%s', '%s', '%s', %d)" % \
                         (self.ID, self.Username, self.Password, self.Email,
                          self.CipheredPublicKeyHash, self.Type)
         g_logger.info("[save_to_db]:save %s into DB"%sql_str)            
         g_db_helper.execute(sql_str)
         g_db_helper.commit()
コード例 #38
0
    def _handle_register_response(self, message):
        if message is None:
            g_logger.error("Empty response while trying to register.")
            return

        g_logger.info("RegisterAgent response: (%s, %s)" %
                      (message.agentID, message.publicKeyHash))

        return {'id': message.agentID, 'hash': message.publicKeyHash}
コード例 #39
0
    def _handle_get_bannets_response(self, message):
        g_logger.info("GET BANNETS RESPONSE: %s" % message)
        if message is None:
            return

        # TODO: Store the bannets locally
        theApp.peer_manager.sync_bannets(message)

        return message
コード例 #40
0
 def set_super_peer_manual(self, ip, port, description=""):
     """
     add super peer information into super_peer_manual table
     """
     sql_str = "insert or replace into super_peers_manual values " \
                     "('%s', '%s', '%s')" % \
                     (ip,port,description)
     g_logger.info("[save_to_db]:save %s into DB" % sql_str)
     self.execute(sql_str)
コード例 #41
0
 def verifyHostKey(self, host_key, fingerprint=""):
     g_logger.info("host key fingerprint %s" % fingerprint)
     #we cannot provide the key, so we should check the failure to decide the result
     if self.reportDeferred:
         task_done(self.__class__.__name__, TEST_SERVICE_TYPE, self.test)
         result = {'status_code': 0, 'time_end': default_timer()}
         self.reportDeferred.callback(result)
     self.loseConnection()
     return defer.succeed(1)
コード例 #42
0
 def send_service_report(self, report):
     g_logger.info("Send %s message to %s" %
                   (report.DESCRIPTOR.name, self.remote_ip))
     request_msg = SendServiceReport()
     #request_msg.header.token = theApp.peer_info.AuthToken
     #request_msg.header.agentID = str(theApp.peer_info.ID)
     request_msg.report.CopyFrom(report)
     self._send_message(request_msg)
     self.pending_report_ids.append(report.header.reportID)
コード例 #43
0
 def get_tests(self, current_version):
     """
     """
     g_logger.info("Send P2PGetSuperPeerList message to %s" %
                   self.remote_ip)
     request_msg = NewTests()
     request_msg.currentTestVersionNo = int(
         current_version)  #Get current version from DB
     self._send_message(request_msg)
コード例 #44
0
 def get_tests(self, current_version):
     """
     """
     g_logger.info("[DesktopAgentSession]  Send Test Sets message to %s" %
                   self.remote_ip)
     request_msg = NewTests()
     request_msg.currentTestVersionNo = int(
         current_version)  #Get current version from DB
     self._send_message(request_msg)
コード例 #45
0
    def execute(self):
        """Run the test"""
        g_logger.info("Testing website: %s" % self.url)

        defer_ = self._agent.request("GET", self.url, Headers({"User-Agent": ["ICM Website Test"]}), None)
        self.time_start = default_timer()
        defer_.addCallback(self._handle_response)
        defer_.addErrback(self._connectionFailed)
        return defer_
コード例 #46
0
 def _handle_get_tests_response(self,test_sets):
     """
     """
     if test_sets is None:
         g_logger.info("Receive Empty Test Sets from %s!!!"% self.remote_ip)
         return
             
     g_logger.info("Receive Test Sets from %s!"% self.remote_ip)  
     
     theApp.test_sets.execute_test(test_sets)    
コード例 #47
0
 def _handle_get_peer_list_response(self, message):
     for agent_data in message.peers:
         if str(self.remote_id) != agent_data.agentID:
             theApp.peer_manager.add_normal_peer(agent_data.agentID,
                                                 agent_data.agentIP,
                                                 agent_data.agentPort,
                                                 agent_data.token,
                                                 agent_data.publicKey)
             
     g_logger.info("[DesktopAgentSession] Got Normal Peer List : %s!"% message) 
コード例 #48
0
 def _send_request(self, method, uri, data="", mimeType=None):
     g_logger.info("Sending message to aggregator at %s" % uri)
     headers = {}
     if mimeType:
         headers['Content-Type'] = mimeType
     if data:
         headers['Content-Length'] = str(len(data))
     d = client.getPage(uri, method=method, postdata=data, headers=headers)
     d.addErrback(self._connection_errback)
     return d
コード例 #49
0
 def require_test_mod_update(self, version, download_url, check_code=0):
     """
     """
     g_logger.info("Send TestModuleUpdate message to %s" % self.remote_ip)
     request_msg = TestModuleUpdate()
     request_msg.version = version
     request_msg.downloadURL = download_url
     if check_code != 0:
         request_msg.checkCode = check_code
     self._send_message(request_msg)
コード例 #50
0
 def require_test_mod_update(self, version, download_url, check_code=0):
     """
     """
     g_logger.info("Send TestModuleUpdate message to %s" % self.remote_ip)
     request_msg = TestModuleUpdate()
     request_msg.version = version
     request_msg.downloadURL = download_url
     if check_code != 0:
         request_msg.checkCode = check_code
     self._send_message(request_msg)
コード例 #51
0
    def show_details(self, task_type):
        """
        """
        self.task_list_dict = {}
        cnt = 0

        from umit.icm.agent.gui.dashboard.DashboardListBase import TASK_ALL, TASK_SUCCESSED, TASK_FAILED
        #########################
        #Get Task Details From DB
        rs = g_db_helper.get_task_sets(task_type=task_type)

        if rs == None:
            g_logger.info("Cannot load any Tasks from DB.")
            self.treeview.set_sensitive(True)
            self.store.clear()
            self.treeview.set_model(
                self.store)  #It must be after the store update
            return

        for record in rs:
            self.task_list_dict[cnt] = {}
            self.task_list_dict[cnt]["sequence"] = record[0]
            self.task_list_dict[cnt]["test_id"] = record[1]
            self.task_list_dict[cnt]["website_url"] = record[2]
            self.task_list_dict[cnt]["test_type"] = record[3]
            self.task_list_dict[cnt]["service_name"] = record[4]
            self.task_list_dict[cnt]["service_ip"] = record[5]
            self.task_list_dict[cnt]["service_port"] = record[6]
            self.task_list_dict[cnt]["done_status"] = record[7]
            self.task_list_dict[cnt]["done_result"] = record[8]
            self.task_list_dict[cnt]["execute_time"] = record[9]
            cnt += 1

        g_logger.info("Loaded %d tasks from DB." % len(rs))

        #####################
        #Output in the Window
        self.treeview.set_sensitive(True)
        self.store.clear()

        for line in self.task_list_dict.keys():
            self.store.append([
                self.task_list_dict[line]["sequence"],
                self.task_list_dict[line]["test_id"],
                self.task_list_dict[line]["website_url"],
                self.task_list_dict[line]["test_type"],
                self.task_list_dict[line]["service_name"],
                self.task_list_dict[line]["service_ip"],
                self.task_list_dict[line]["service_port"],
                self.task_list_dict[line]["done_status"],
                self.task_list_dict[line]["done_result"],
                self.task_list_dict[line]["execute_time"]
            ])

        self.treeview.set_model(self.store)  #It must be after the store update
コード例 #52
0
    def _handle_get_peer_list_response(self, message):
        for agent_data in message.peers:
            if str(self.remote_id) != agent_data.agentID:
                theApp.peer_manager.add_normal_peer(agent_data.agentID,
                                                    agent_data.agentIP,
                                                    agent_data.agentPort,
                                                    agent_data.token,
                                                    agent_data.publicKey)

        g_logger.info("[DesktopAgentSession] Got Normal Peer List : %s!" %
                      message)
コード例 #53
0
ファイル: db.py プロジェクト: gkso/openmonitor-desktop-agent
 def task_service(self,task_service_info):
     """
     """
     self.execute("INSERT INTO tasks VALUES "
                  "(NULL,'%s', NULL ,'%s', '%s', '%s', '%s', '%s','%s','%s','%s')" % \
                     (task_service_info['test_id'], task_service_info['test_type'], 
                      task_service_info['service_name'], task_service_info['service_port'], task_service_info['service_ip'], 
                      task_service_info['done_status'],task_service_info['done_result'],str(task_service_info['execute_time']),
                      task_service_info['unique_id']))
     
     g_logger.info("Store %s Service Test Task into Database"%(task_service_info['test_id']))
コード例 #54
0
 def fetch_task(self):
     """
     fetch task from Aggregator by using Aggregator AssignTask API
     """
     if theApp.aggregator.available:
         g_logger.info("Fetching assigned task from aggregator")
        # defer_ = theApp.aggregator.get_task()
        # defer_.addCallback(self.task_append)
        # defer_.addErrback(self._handler_error(failure))
     else:
         g_logger.error("Cannot connect to Aggregator")
コード例 #55
0
 def fetch_task(self):
     """
     fetch task from Aggregator by using Aggregator AssignTask API
     """
     if theApp.aggregator.available:
         g_logger.info("Fetching assigned task from aggregator")
     # defer_ = theApp.aggregator.get_task()
     # defer_.addCallback(self.task_append)
     # defer_.addErrback(self._handler_error(failure))
     else:
         g_logger.error("Cannot connect to Aggregator")
コード例 #56
0
ファイル: db.py プロジェクト: gkso/openmonitor-desktop-agent
 def task_web(self,task_web_info):
     """
     """
     
     self.execute("INSERT INTO tasks VALUES "
                  "(NULL,'%s', '%s', '%s',NULL,NULL,NULL ,'%s', '%s', '%s','%s')" % \
                     (task_web_info['test_id'], task_web_info['website_url'], task_web_info['test_type'], 
                      task_web_info['done_status'],task_web_info['done_result'],str(task_web_info['execute_time']),
                      task_web_info['unique_id']))        
     
     g_logger.info("Store %s WebSite Test Task into Database"%(task_web_info['test_id']))
コード例 #57
0
 def _send_request(self, method, uri, data="", mimeType=None):
     g_logger.info("Sending message to aggregator at %s" % uri)
     headers = {}
     if mimeType:
         headers['Content-Type'] = mimeType
     if data:
         headers['Content-Length'] = str(len(data))
     d = client.getPage(uri, method=method, postdata=data,
                        headers=headers)
     d.addErrback(self._connection_errback)
     return d
コード例 #58
0
    def _handle_get_tests_response(self, test_sets):
        """
        """
        if test_sets is None:
            g_logger.info("Receive Empty Test Sets from %s!!!" %
                          self.remote_ip)
            return

        g_logger.info("Receive Test Sets from %s!" % self.remote_ip)

        theApp.test_sets.execute_test(test_sets)
コード例 #59
0
    def _handle_login_response(self, message):
        if message is None:
            return

        g_logger.info("Login successfully.")

        # Being available, we need to retrieve the bannets and banlist
        d = theApp.aggregator.get_banlist()
        d = theApp.aggregator.get_bannets()

        return True