Exemple #1
0
    def run_spider_target(self, toAgent):
        self.total_links = 0
        self.links = []
        self.zera_links()

        print("Target is: " + self.baseUrlTarget)
        sp = spider.Spider()
        if len(self.urlTarget) != 0:
            sp.set_baseUrl(self.urlTarget)
        else:
            sp.set_baseUrl(self.baseUrlTarget)

        self.links = sp.run()

        body = ''
        total = 0
        for line in self.links:
            body += line + "\n"
            total += 1

        self.total_links = total

        performative = "inform"
        reply_with = utl.id_generator()
        conversation_id = utl.id_gen()
        content = ("Response From spider (= (run-spider) (" + body + "))\n")
        msg = self.mAgent.set_data_to_agent(performative, AGENT_NAME, toAgent,
                                            content, reply_with,
                                            conversation_id)
        ret = self.mAgent.send_data_to_agent(msg)
        self.is_running = False
Exemple #2
0
 def responseInfo(self,performative, toAgent, reply_to, reqfunction,values):
     content = ("Response (= (" + reqfunction + ") (" + values + "))\n")           
     conversation_id = utl.id_gen()   
     
     msg = self.mAgent.set_response_to_agent(performative,AGENT_NAME, toAgent, content, reply_to, conversation_id)
     ret = self.mAgent.send_data_to_agent(msg)
     return ret
Exemple #3
0
 def informAgent(self,performative, toAgent,  reqfunction,values):
     content = ("Inform Agent (= (" + reqfunction + ") (" + values + "))\n")
     reply_with = utl.id_generator()           
     conversation_id = utl.id_gen()   
     
     msg = self.mAgent.set_data_to_agent(performative,AGENT_NAME, toAgent, content, reply_with, conversation_id)
     ret = self.mAgent.send_data_to_agent(msg)
     return ret
Exemple #4
0
 def register(self):
     sender = AGENT_NAME
     toAgent = "All Agents"
     content = ("Register Agent (= (agent-name) (" + AGENT_NAME + "))\n")              
     reply_with = utl.id_generator()
     conversation_id = utl.id_gen()   
     msg = self.mAgent.set_data_to_agent("subscribe", sender, toAgent, content, reply_with, conversation_id)
     ret = self.mAgent.send_data_to_agent(msg)
Exemple #5
0
 def cfp(self,reqfunction,values):
     performative = "cfp"
     toAgent = ALL_AGENTS
     content = ("Call For Propose (= (" + reqfunction + ") (" + values + "))\n")           
     reply_with = utl.id_generator()
     conversation_id = utl.id_gen()   
 
     msg = self.mAgent.set_data_to_agent(performative,AGENT_NAME, toAgent, content, reply_with, conversation_id)
     ret = self.mAgent.send_data_to_agent(msg)
Exemple #6
0
 def showAgents(self):
     sender = AGENT_NAME
     performative = "request"
     toAgent = "MasterAgent"
     content = ("Request AvaiableAgents (= (avaiable-agents) (*))\n")           
     reply_with = utl.id_generator()
     conversation_id = utl.id_gen()   
     msg = self.mAgent.set_data_to_agent(performative, sender, toAgent, content, reply_with, conversation_id)
     ret = self.mAgent.send_data_to_agent(msg)
Exemple #7
0
 def deregister(self):
     performative = "subscribe"
     toAgent = ALL_AGENTS
     content = ("Deregister Agent (= (agent-name) (" + AGENT_NAME + "))\n")           
     reply_with = utl.id_generator()
     conversation_id = utl.id_gen()   
 
     msg = self.mAgent.set_data_to_agent(performative,AGENT_NAME, toAgent, content, reply_with, conversation_id)
     ret = self.mAgent.send_data_to_agent(msg)
Exemple #8
0
 def deregister(self):
     sender = AGENT_NAME
     performative = "inform"
     toAgent = "All Agents"
     content = ("Deregister Agent (= (agent-name) (" + AGENT_NAME + "))\n")           
     reply_with = utl.id_generator()
     conversation_id = utl.id_gen()   
     msg = self.mAgent.set_data_to_agent(performative, sender, toAgent, content, reply_with, conversation_id)
     ret = self.mAgent.send_data_to_agent(msg)
Exemple #9
0
    def registerUrl(self, url, toAgent):
        performative = "inform"
        reply_with = utl.id_generator()
        conversation_id = utl.id_gen()
        content = ("Register urlTarget (= (url-target) (" + url + "))\n")

        msg = self.mAgent.set_data_to_agent(performative, AGENT_NAME, toAgent,
                                            content, reply_with,
                                            conversation_id)
        ret = self.mAgent.send_data_to_agent(msg)
Exemple #10
0
 def sendQuestion(self, toAgent, Question):
     sender = AGENT_NAME
     performative = "request"
     content = ("Request Information (= (" + Question + ") (*))\n")
     reply_with = utl.id_generator()
     conversation_id = utl.id_gen()
     msg = self.mAgent.set_data_to_agent(performative, sender, toAgent,
                                         content, reply_with,
                                         conversation_id)
     ret = self.mAgent.send_data_to_agent(msg)
Exemple #11
0
 def sendInform(self, toAgent):
     sender = AGENT_NAME
     performative = "inform"
     content = ("Sending Information (= (" + self.directive + ") (" +
                self.values + "))\n")
     reply_with = utl.id_generator()
     conversation_id = utl.id_gen()
     msg = self.mAgent.set_data_to_agent(performative, sender, toAgent,
                                         content, reply_with,
                                         conversation_id)
     ret = self.mAgent.send_data_to_agent(msg)
Exemple #12
0
    def requestUrlBase(self, toAgent):
        performative = 'request'
        content = ("Request Target Url Base (= (base-url-target) (*))\n")
        reply_with = utl.id_generator()
        conversation_id = utl.id_gen()

        msg = self.mAgent.set_data_to_agent(performative, AGENT_NAME, toAgent,
                                            content, reply_with,
                                            conversation_id)
        ret = self.mAgent.send_data_to_agent(msg)
        return ret
Exemple #13
0
 def run_pomdp(self, toAgent, reply_with_orig):
     if self.is_running_pomdp is True:
         performative = "inform"
         reply_with = utl.id_generator()
         conversation_id = utl.id_gen()    
         body = "POMDP in execution..."
         content = ("Response from MasterAgent (= (run-pomdp) (" + body + "))\n")              
 
         msg = self.mAgent.set_data_to_agent(performative,AGENT_NAME, toAgent, content, reply_with, conversation_id)
         ret = self.mAgent.send_data_to_agent(msg)
         return ret
     else:
         self.is_running_pomdp = True
         p = Process(target=self.run_pomdp_bf(toAgent, reply_with_orig))
         p.start()
Exemple #14
0
def runAgent():
    signal.signal(signal.SIGINT, handler)
    signal.signal(signal.SIGTERM, handler)

    print("Loading %s...\n" % AGENT_NAME)

    toAgent = "All Agents"
    content = ("Register Agent (= (agent-name) (" + AGENT_NAME + "))\n")
    reply_with = utl.id_generator()
    conversation_id = utl.id_gen()
    mAction = WebInfraAction()
    mAgent = Transport()
    mAction.set_mAgent(mAgent)
    mAction.registerAgent()
    fm = FIPAMessage()
    agent_id = []
    while True:
        time.sleep(1)
        rcv = mAgent.receive_data_from_agents()
        if not len(rcv) == 0:
            fm.parse_pkg(rcv)
            match = re.search("(agent-name(.)+)(\(\w+\))", rcv)
            if match:
                field = match.group(3).lstrip()
                match2 = re.search("\w+", field)
                if match2:
                    agt_id = match2.group(0)

                if agt_id in agent_id:
                    continue
                else:
                    print("agentID: ", agt_id)
                    agent_id.append(agt_id)
                    print(rcv)
                    mAction.add_avaiable_agent(agt_id)
                    break
            else:
                print(rcv)

    mAction = WebInfraAction()
    mAgent = Transport()
    mAction.set_mAgent(mAgent)
    #request url base to check
    toAgent = "AgentTarget"
    ret = mAction.requestUrlBase(toAgent)
    mAction.receive_pkg(mAgent)
Exemple #15
0
    def agentStatus(self, toAgent):
        status = "UP"
        performative = "inform"
        reply_with = utl.id_generator()
        conversation_id = utl.id_gen()

        uptime = time.time() - startTime
        content = ("Response agent-status (= (agent-status) ("
                   "AgentName: " + AGENT_NAME + "\n"
                   "Agend_id: " + AGENT_ID + "\n"
                   "Uptime: %0.2f " % uptime + "\n"
                   "))\n")

        msg = self.mAgent.set_data_to_agent(performative, AGENT_NAME, toAgent,
                                            content, reply_with,
                                            conversation_id)
        ret = self.mAgent.send_data_to_agent(msg)
        return ret
Exemple #16
0
    def sendHTTPHeaders(self, toAgent):
        performative = "inform"
        reply_with = utl.id_generator()
        conversation_id = utl.id_gen()

        content = ("Register HttpHeaders (= (http-headers) ("
                   "User-Agent: Kurgan 0.1\n"
                   "Host: localhost\n"
                   "Cache: nocache\n"
                   "Cookie: abcdef\n"
                   "Content-type: text-html\n"
                   "))\n")

        msg = self.mAgent.set_data_to_agent(performative, AGENT_NAME, toAgent,
                                            content, reply_with,
                                            conversation_id)
        ret = self.mAgent.send_data_to_agent(msg)
        return ret
Exemple #17
0
    def run_pageClassifierHeadless(self, toAgent):
        if self.is_running_pc is True:
            performative = "inform"
            reply_with = utl.id_generator()
            conversation_id = utl.id_gen()
            body = "Page Classifier Headless in execution..."
            content = (
                "Response from PageClassifierHeadless (= (run-page-classifier-headless) ("
                + body + "))\n")

            msg = self.mAgent.set_data_to_agent(performative, AGENT_NAME,
                                                toAgent, content, reply_with,
                                                conversation_id)
            ret = self.mAgent.send_data_to_agent(msg)
            return ret
        else:
            self.is_running_pc = True
            p = Process(target=self.run_pc_headless(toAgent))
            p.start()
Exemple #18
0
    def run_pc(self, toAgent):
        pc = PageClassifier()

        if len(self.urlTarget) != 0:
            pc.set_url(self.urlTarget)
        else:
            pc.set_url(self.baseUrlTarget)

        body = 'Checking url: ' + pc.get_url() + '\n'
        retauth = pc.checkIfAuthForm()
        body = body + 'Page is Authentication Form Page: {0:.0f}%'.format(
            retauth) + '\n'
        retstatic = pc.checkIfStatic()

        body = body + 'Page is Static HTML Page: {0:.0f}%'.format(
            retstatic) + "\n"
        retforgotten_password = pc.checkIfForgottenPassword()
        body = body + 'Page is Forgotten Password Page: {0:.0f}%'.format(
            retforgotten_password) + "\n"

        if (retauth > retstatic) and (retauth > retforgotten_password):
            self.pageDetected = "FormLogin"
        if (retauth < retstatic) and (retstatic > retforgotten_password):
            self.pageDetected = "Static"
        if (retauth < retforgotten_password) and (retstatic <
                                                  retforgotten_password):
            self.pageDetected = "FormReset"

        performative = "inform"
        reply_with = utl.id_generator()
        conversation_id = utl.id_gen()

        uptime = time.time() - startTime
        content = ("Response page-classifier (= (run-page-classifier) (" +
                   body + "))\n")

        msg = self.mAgent.set_data_to_agent(performative, AGENT_NAME, toAgent,
                                            content, reply_with,
                                            conversation_id)
        ret = self.mAgent.send_data_to_agent(msg)
        self.is_running_pc = False
        return ret
Exemple #19
0
    def runSpider(self, toAgent):
        if self.is_running is True:
            performative = "inform"
            reply_with = utl.id_generator()
            conversation_id = utl.id_gen()
            body = "Spider in execution..."
            content = ("Response from Spider (= (run-spider) (" + body +
                       "))\n")

            msg = self.mAgent.set_data_to_agent(performative, AGENT_NAME,
                                                toAgent, content, reply_with,
                                                conversation_id)
            ret = self.mAgent.send_data_to_agent(msg)
            return ret
        else:
            self.zera_links()
            self.is_running = True
            p = Process(target=self.run_spider_target(toAgent))
            p.start()
        '''
Exemple #20
0
    def run_pc_headless(self, toAgent):
        pc = PageFormClassifier()

        if len(self.urlTarget) != 0:
            pc.set_url(self.urlTarget)
        else:
            pc.set_url(self.baseUrlTarget)

        body = 'Checking url: ' + pc.get_url() + '\n'
        pc.get_page()
        pc.run()
        is_authform = pc.get_isAuthform()
        if is_authform is True:
            self.pageDetected = "FormLogin"
            body = body + 'Page is Authentication Form Page:' + '{:.0%}'.format(
                float(pc.get_Accuracy())) + '\n'
            print("It is Authentication Form Page: " +
                  '{:.0%}'.format(float(pc.get_Accuracy())))
        else:
            body = body + 'Page is not Authentication Form Page:' + '{:.0%}'.format(
                float(pc.get_Accuracy())) + '\n'
            self.pageDetected = "NotFormLogin"
            print("It is not Authentication Form Page: " +
                  '{:.0%}'.format(float(pc.get_Accuracy())))

        performative = "inform"
        reply_with = utl.id_generator()
        conversation_id = utl.id_gen()

        uptime = time.time() - startTime
        content = (
            "Response page-classifier-headless (= (run-page-classifier-headless) ("
            + body + "))\n")

        msg = self.mAgent.set_data_to_agent(performative, AGENT_NAME, toAgent,
                                            content, reply_with,
                                            conversation_id)
        ret = self.mAgent.send_data_to_agent(msg)
        self.is_running_pc = False
        return ret