Esempio n. 1
0
 def run(self):
     """
     compile thread method
     get the mission from compile queue and compile it
     if successful, then push it into running queue
     else, save the compile data into database
     """
     while True:
         while not self.queue.is_empty():
             compile_mission = self.queue.get_front()
             self.queue.pop()
             #change the state of the mission
             self.db.update_collection('mission', {'id' : int(compile_mission.mission_id)}, {'type' : COMPILING})
             print 'get a mission: ', compile_mission.mission_id
             compile_ok, compile_infor = self.compile(compile_mission)
             print compile_infor
             is_success = False
             if compile_ok == COMPILE_SUCCESS:
                 is_success = True
                 temp_str = compile_mission.mission_file_path.split('.')
                 out = '.'.join(temp_str[i] for i in range(0, len(temp_str) - 1))
                 running_mission = Mission(compile_mission.mission_id, out, compile_mission.mission_file_name, compile_mission.mission_file_style, compile_mission.mission_owner_id)
                 self.run_queue.push(running_mission)
             else:
                 subject = "任务编译失败,请登录查看信息"
                 content = "任务查看:http://127.0.0.1:8080/mission_detail?ID=" + str(compile_mission.mission_id)
                 send_email_thread = SendEmailThread(compile_mission.mission_owner_id, content, subject)
                 send_email_thread.start()
                 pass
             #save compile failed information
             self.save_compile_infor(is_success, compile_infor, compile_mission.mission_id)
Esempio n. 2
0
def register_end():
    """ get register data and register 
        need to keep the structure of the database the same as defied in mon_config.py

        Args:None
        Returns: a template object indicating the hint for identifying
        Raises: InsertException defined in monkey.py
    """
    # get the data from forms and save into database
    user_email = request.forms.get("email")
    user_passwd = request.forms.get("password")

    ids = db.find_collection("ids", {"name": "user"})
    user_id = ids[0]["ids"] + 1 if ids else 1
    insert_dict = {
        "id": user_id,
        "name": "",
        "email": user_email,
        "profile": [],
        "password": md5.new(user_passwd).hexdigest(),
        "type": 0,
        "interest": [],
        "mission": [],
    }
    if db.insert_collection("user", insert_dict):
        if user_id == 1:
            db.insert_collection("ids", {"name": "user", "ids": 1})
        else:
            db.update_collection("ids", {"name": "user"}, {"ids": user_id})
        # send email to user
        send_content = (
            "127.0.0.1:8080/authenticate?token=" + md5.new(user_passwd).hexdigest() + "&" + "ID=" + user_email
        )
        send_thread = SendEmailThread(user_email, send_content, "click the following link to authenticate")
        send_thread.start()

        return template("register_ok", email=user_email)
    else:
        return "sorry ,register failed"
Esempio n. 3
0
    def run(self):
        """
        running thread method
        get a mission from mission queue and run it
        and of course the outcome will be save into running_infor collection
        """
        while True:
            while not self.queue.is_empty():
                running_mission = self.queue.get_front()
                #update the mission type
                self.db.update_collection('mission', {'id' : int(running_mission.mission_id)}, {'type' : RUNNING})
                print 'get a mission from compile', running_mission.mission_id
                self.queue.pop()
                self.running(running_mission)

                self.db.update_collection('mission', {'id' : int(running_mission.mission_id)}, {'type' : COMPLETED})
                
                subject = "任务运行成功,请登录查看信息"
                content = "任务查看:http://127.0.0.1:8080/mission_detail?ID=" + str(running_mission.mission_id)
                send_email_thread = SendEmailThread(running_mission.mission_owner_id, content, subject)
                send_email_thread.start()
                """