예제 #1
0
def attachments(attachment_id=None):
    if request.method == 'GET':
        if not attachment_id:
            return jsonify(list(event_handler.attachments.values()))
        else:
            attachment = event_handler.attachments.get(attachment_id)
            if attachment:
                return send_file(attachment['path'])
            else:
                return make_fail_response('Not found attachment')

    elif request.method == 'PUT':
        path = Path(event_handler.attachments[attachment_id].get('path'))
        name = event_handler.attachments[attachment_id].get('name')
        image_data = request.json.get('imageData')

        image_data = image_data.replace('data:image/png;base64,', '', 1)

        with codecs.open(str(path), 'wb') as f:
            image_data = base64.decodebytes(image_data.encode())
            f.write(image_data)
        return make_ok_response(
            message=f'Edited picture {name} has been saved')

    elif request.method == 'DELETE':
        event_handler.attachments.pop(attachment_id)
        return make_ok_response()
예제 #2
0
def template_options_controller(action):
    if request.method == 'GET':
        if action == 'install':
            install_options = template_loader.install_options()
            return make_ok_response(install_options=install_options)
        elif action == 'start':
            start_options = template_loader.start_options()
            return make_ok_response(start_options=start_options)
        else:
            return make_fail_response(f'Unknown template action: {action}')
예제 #3
0
 def put(self, plugin_name):
     try:
         if plugin_name == 'lyrebird':
             context.application.conf = request.get_json()
             context.application.save()
             return context.make_ok_response()
         else:
             plugin_manager.set_conf(plugin_name, request.get_json())
             return context.make_ok_response()
     except Exception as e:
         return context.make_fail_response(str(e))
예제 #4
0
def search_app():
    if request.method == 'POST':
        search_str = request.json.get('searchStr')
        template = request.json.get('template')
        template_path = template.get('path')

        template = template_loader.get_template(template_path)
        origin_app_list = template.get_apps()

        if not search_str:
            return make_ok_response(applist=origin_app_list)

        matched_apps = [app for app in origin_app_list if search_str in app['name']]
        return make_ok_response(applist=matched_apps)
예제 #5
0
 def delete(self, group):
     if group in context.application.data_manager.data_groups:
         _group = context.application.data_manager.data_groups.pop(group)
         _group.delete()
         return context.make_ok_response()
     else:
         return context.make_fail_response('Not found group')
예제 #6
0
def execute_command():
    if request.method == 'POST':
        _command = request.json.get('command')
        if not _command:
            return make_fail_response('Empty command!')

        _device_id = request.json.get('device_id', '')
        device = device_service.devices.get(_device_id)
        if not device:
            return make_fail_response('Device not found!')

        res = device.adb_command_executor(_command)
        output = res.stdout.decode()
        err_str = res.stderr.decode()

        publish_channel = 'android.command'
        publish_message = {
            'command': res.args,
            'returncode': res.returncode,
            'result': err_str if err_str else output
        }
        publish(publish_channel, publish_message)

        if err_str:
            return make_fail_response(err_str)
        else:
            return make_ok_response(data=output)
예제 #7
0
파일: menu.py 프로젝트: zhzb/lyrebird
 def get(self):
     menu = [
         {
             'name': 'inspector',
             'title': 'Inspector',
             'type': 'router',
             'path': '/'
         },
         {
             'name': 'datamanager',
             'title': 'DataManager',
             'type': 'router',
             'path': '/datamanager'
         }]
     for plugin_key in plugin_manager.plugins:
         plugin = plugin_manager.plugins[plugin_key]
         if 'beta_web' not in plugin:
             continue
         web = plugin['beta_web']
         name = plugin['name']
         if hasattr(web, 'get_title'):
             title = web.get_title()
         else:
             title = name[0].upper() + name[1:]
         menu.append({
             'name': 'plugin-view',
             'title': title,
             'type': 'router',
             'path': '/plugin',
             'params': {
                 'src': f'/plugin/{plugin["project_name"]}',
                 'name': name
             }
         })
     return context.make_ok_response(menu=menu)
예제 #8
0
def stop_app(device_id, bundle_id):
    device = device_service.devices.get(device_id)
    res = device.stop_app()
    if 'NoneType' in res:
        return make_fail_response(
            f'Cannot stop app {bundle_id} before start it')
    return make_ok_response()
예제 #9
0
def start_app(device_id, bundle_id):
    device = device_service.devices.get(device_id)
    port = application.config.get('mock.port')
    res = device.start_app(bundle_id, _get_ip(), port)
    if res:
        return make_fail_response(res)
    return make_ok_response()
예제 #10
0
def app_list(device_id):
    device = device_service.devices.get(device_id)
    if device:
        app_list = device.get_apps_list(device_id)
        return make_ok_response(app_list=app_list)
    else:
        return make_fail_response(f'Device id {device_id} not found!')
예제 #11
0
def device_controller(device_id, action):
    controller_actions = {'install': _install_package}

    if request.method == 'PUT':
        device = device_service.devices.get(device_id)
        if not device:
            return make_fail_response(f'Device {device_id} not found!')
        if not controller_actions.get(action):
            return make_fail_response(f'Unknown device action: {action}')

        action_func = controller_actions.get(action)
        res = action_func(device, request)

        publish_channel = 'android.' + action
        publish_message = {
            'command':
            res.args,
            'returncode':
            res.returncode,
            'result':
            res.stderr.decode()
            if res.stderr.decode() else res.stdout.decode()
        }
        publish(publish_channel, publish_message)

        if res.returncode != 0:
            return make_fail_response(res.stderr.decode())
        else:
            return make_ok_response()
예제 #12
0
 def put(self):
     data_id = request.json.get('id')
     data = request.json
     save_data = {}
     encoders_decoders.encoder_handler(data, res=save_data)
     context.application.data_manager.update_data(data_id, save_data)
     return context.make_ok_response()
예제 #13
0
 def put(self):
     try:
         context.application.conf = request.get_json()
         context.application.save()
         return context.make_ok_response()
     except Exception as e:
         return context.make_fail_response(str(e))
예제 #14
0
파일: mock.py 프로젝트: zzzyw-work/lyrebird
 def put(self):
     data_id = request.json.get('id')
     data = request.json
     # Import encoder for encoding the requested content
     application.encoders_decoders.encoder_handler(data)
     context.application.data_manager.update_data(data_id, data)
     return context.make_ok_response()
예제 #15
0
파일: mock.py 프로젝트: zhzb/lyrebird
    def put(self, group_id=None, data_id=None):
        if not group_id or not data_id:
            return abort(400, '请设置参数 group_id & data_id')
        _group = context.application.data_manager.groups.get(group_id)
        if not _group:
            return context.make_fail_response('Group not found')
        _data = _group.all_data.get(data_id)
        if not _data:
            return context.make_fail_response('Data not found')

        _data.name = request.json.get('name')
        _data.rule = request.json.get('rule')
        req = request.json.get('request')
        if req:
            _data.request.content = req['content']
            _data.request.filetype = req['filetype']
        req_data = request.json.get('request_data')
        if req_data:
            _data.request_data.content = req_data['content']
            _data.request_data.filetype = req_data['filetype']
        resp = request.json.get('response')
        if resp:
            _data.response.content = resp['content']
            _data.response.filetype = resp['filetype']
        resp_data = request.json.get('response_data')
        if resp_data:
            _data.response_data.content = resp_data['content']
            _data.response_data.filetype = resp_data['filetype']
        _data.save()
        return context.make_ok_response()
예제 #16
0
 def post(self):
     link = request.json.get('link')
     qrcode_img = qrcode.get_qrcode_img(link)
     if qrcode_img:
         return context.make_ok_response(img=qrcode_img)
     else:
         return context.make_fail_response(
             f'make qrcode fail! Link is {link}')
예제 #17
0
파일: mock.py 프로젝트: zhzb/lyrebird
 def post(self):
     name = request.json.get('name')
     parent = request.json.get('parent')
     group = context.application.data_manager.create_group()
     group.name = name
     group.parent_id = parent
     group.save()
     return context.make_ok_response(group_id=group.id)
예제 #18
0
파일: mock.py 프로젝트: zhzb/lyrebird
 def delete(self, group_id=None, data_id=None):
     _group = context.application.data_manager.groups.get(group_id)
     if not _group:
         return context.make_fail_response('Group not found')
     ids = request.json.get('ids')
     for data_id in ids:
         _group.delete_data(data_id)        
     return context.make_ok_response()
예제 #19
0
파일: api.py 프로젝트: samesky2016/lyrebird
 def get(self):
     conf = context.application.conf
     return context.make_ok_response(
         **{
             'ip': conf.get('ip', 'unknown ip'),
             'mock.port': conf['mock.port'],
             'proxy.port': conf['proxy.port']
         })
예제 #20
0
def take_screen_shot(device_id):
    device = device_service.devices.get(device_id)
    img_info = device.take_screen_shot()
    if img_info['returncode'] != 0:
        return make_fail_response(img_info['result'].stdout.decode())
    timestamp = img_info.get('timestamp')
    return make_ok_response(
        imgUrl=f'/plugins/ios/api/src/screenshot/{device_id}?time={timestamp}')
예제 #21
0
 def delete(self):
     _ids = request.json.get('ids')
     if _ids:
         context.application.cache.delete_by_ids(*_ids)
     else:
         context.application.cache.clear()
     context.application.socket_io.emit('action', 'delete flow log')
     return context.make_ok_response()
예제 #22
0
파일: mock.py 프로젝트: zzzyw-work/lyrebird
 def put(self, group_id=None, action=None):
     if action == 'activate':
         # Only one group could be activated
         context.application.data_manager.deactivate()
         context.application.data_manager.activate(group_id)
     else:
         context.application.data_manager.deactivate()
     return context.make_ok_response()
예제 #23
0
파일: mock.py 프로젝트: duyanguang/lyrebird
 def put(self):
     name = request.json.get('name')
     group_id = request.json.get('group_id')
     group = context.application.data_manager.groups.get(group_id)
     if not group:
         return context.make_fail_response('Group not found')
     group.name = name
     group.save()
     return context.make_ok_response()
예제 #24
0
def take_screen_shot(device_id):
    device = device_service.devices.get(device_id)
    img_info = device.take_screen_shot()
    timestamp = img_info.get('timestamp')
    if img_info.get('screen_shot_file'):
        return make_ok_response(
            imgUrl=
            f'/plugins/android/api/src/screenshot/{device_id}?time={timestamp}'
        )
예제 #25
0
 def put(self, group=None, action=None):
     if action == 'activate':
         result = context.application.data_manager.set_current_data_group(group)
     else:
         result = context.application.data_manager.set_current_data_group(None)
     if result:
         return context.make_ok_response()
     else:
         return context.make_fail_response("Activate group fail. Not found! group=%s action=%s" % (group, action))
예제 #26
0
 def put(self, plugin_name):
     try:
         if plugin_name == 'lyrebird':
             return context.make_fail_response('暂未开放')
         else:
             plugin_manager.set_default_conf(plugin_name)
             return context.make_ok_response()
     except Exception as e:
         return context.make_fail_response(str(e))
예제 #27
0
 def post(self):
     data = request.json.get('data')
     if not data:
         data = {
             'name': request.json.get('name'),
             'parent_id': request.json.get('parent_id')
         }
     group_id = context.application.data_manager.add_group(data)
     return context.make_ok_response(data={'group_id': group_id})
예제 #28
0
파일: mock.py 프로젝트: zzzyw-work/lyrebird
    def delete(self):
        label_id = request.json.get('id')
        if not label_id:
            return application.make_fail_response('Label id is required!')
        if not label_id in application.labels.label_map:
            return application.make_fail_response(f'Label {label_id} not found!')

        application.labels.delete_label(label_id)
        return context.make_ok_response()
예제 #29
0
 def delete(self, group=None, data=None):
     if not group or not data:
         return abort(400, '请设置参数 group name')
     _group = context.application.data_manager.data_groups.get(group)
     if _group and data in _group.data_dict:
         data = _group.data_dict[data]
         data.delete()
         _group.scan()
         return context.make_ok_response()
     return context.make_fail_response('Data not found')
예제 #30
0
파일: mock.py 프로젝트: zzzyw-work/lyrebird
    def put(self):
        label = request.json.get('label')
        label_id = label.get('id')
        if not label_id:
            return application.make_fail_response('Label id is required!')
        if not label_id in application.labels.label_map:
            return application.make_fail_response(f'Label {label.get("name")} not found!')

        application.labels.update_label(label)
        return context.make_ok_response()