コード例 #1
0
def test_task(uuid, box):
    ret = False
    try:
        folder = path.join(box["temp"], uuid)
        virtual_machine = VirtualBox().find_machine(box["vm"])
        with virtual_machine.create_session() as session:
            session.unlock_machine()
            proc = virtual_machine.launch_vm_process(session, "gui", "")
            proc.wait_for_completion(timeout=-1)
            with session.console.guest.create_session(box["user"],
                                                      box["pass"]) as gs:
                if box["os"] == "Linux":
                    gs.environment_schedule_set("DISPLAY", ":0")
                    process, stdout, stderr = gs.execute("bin/ls")
                    if len(stdout) > 0:
                        ret = True
                elif box["os"] == "Windows":
                    process, stdout, stderr = gs.execute(
                        "%WINDIR%\\system32\\cmd.exe", ["/C", "dir"])
                    if len(stdout) > 0:
                        ret = True
            session.console.power_down()
    except Exception as e:
        log_string(uuid, "custom_task Failed {}".format(e), "Red")
    return ret
コード例 #2
0
def custom_task(uuid, box, actions_list):
    ret = False
    try:
        folder = path.join(box["temp"], uuid)
        file_recording(uuid, box["vm"],
                       path.join(folder, box["screen_recorder"]))
        virtual_machine = VirtualBox().find_machine(box["vm"])
        with virtual_machine.create_session() as session:
            session.unlock_machine()
            file_recording(uuid, box["vm"],
                           path.join(folder, box["screen_recorder"]))
            proc = virtual_machine.launch_vm_process(session, "headless", "")
            proc.wait_for_completion(timeout=-1)
            #do not timeout the session.console.guest.create_session timeout_ms=5*1000 (some vms)
            with session.console.guest.create_session(box["user"],
                                                      box["pass"]) as gs:
                #fix issues with display
                if box["os"] == "Linux":
                    gs.environment_schedule_set("DISPLAY", ":0")
                sleep(1)
                session.machine.recording_settings.enabled = True
                sleep(1)
                parse_actions(uuid, box, folder, session, gs, actions_list)
                sleep(1)
                session.machine.recording_settings.enabled = False
                take_screenshot(uuid, box["vm"],
                                path.join(folder, box["screenshot"]))
                sleep(1)
                ret = True
            session.console.power_down()
    except Exception as e:
        log_string(uuid, "custom_task Failed {}".format(e), "Red")
    return ret
コード例 #3
0
def vbox_remote_control(uuid, box):
    ret = False
    try:
        queue = Redis.from_url(redis_settings_docker)
        virtual_machine = VirtualBox().find_machine(box["vm"])
        vm_name_lock = "{}_lock".format(box["vm"])
        vm_name_frame = "{}_frame".format(box["vm"])
        vm_name_action = "{}_action".format(box["vm"])
        with virtual_machine.create_session() as session:
            session.unlock_machine()
            proc = virtual_machine.launch_vm_process(session, "headless", "")
            proc.wait_for_completion(timeout=-1)
            with session.console.guest.create_session(box["user"],
                                                      box["pass"]) as gs:
                h, w, _, _, _, _ = session.console.display.get_screen_resolution(
                    0)
                update_item(mongo_settings_docker["worker_db"],
                            mongo_settings_docker["worker_col_logs"], uuid, {
                                "status": "live",
                                "started_time": datetime.now()
                            })
                queue.set(vm_name_lock, "False")
                while queue.get(vm_name_lock) == b"False":
                    x, y, dz, dw, button_state, key = "false", "false", "false", "false", "false", "false"
                    try:
                        t = queue.get(vm_name_action)
                        if t and t != "None":
                            x, y, dz, dw, button_state, key = loads(t)
                            #log_string(uuid,">>>>>>>>>> {} {} {} {} {} {}".format(x,y,dz,dw,button_state,key),"Red")
                    except e:
                        pass
                    try:
                        if key != "false":
                            session.console.keyboard.put_scancodes(
                                list(scan_code_table[key]))
                        if "false" not in (x, y, dz, dw, button_state):
                            session.console.mouse.put_mouse_event_absolute(
                                x, y, dz, dw, 0)
                            if button_state == "leftclick":
                                session.console.mouse.put_mouse_event_absolute(
                                    x, y, dz, dw, 1)
                                session.console.mouse.put_mouse_event_absolute(
                                    x, y, dz, dw, 0)
                            elif button_state == "leftdoubleclick":
                                session.console.mouse.put_mouse_event_absolute(
                                    x, y, dz, dw, 1)
                                session.console.mouse.put_mouse_event_absolute(
                                    x, y, dz, dw, 0)
                            elif button_state == "rightclick":
                                session.console.mouse.put_mouse_event_absolute(
                                    x, y, dz, dw, 2)
                                session.console.mouse.put_mouse_event_absolute(
                                    x, y, dz, dw, 0)
                        queue.set(vm_name_action, "None")
                        png = session.console.display.take_screen_shot_to_array(
                            0, h, w, BitmapFormat.png)
                        queue.set(vm_name_frame, png)
                    except:
                        pass
                    sleep(.2)
                ret = True
            session.console.power_down()
    except Exception as e:
        log_string(uuid, "custom_task Failed {}".format(e), "Red")
    return ret