Example #1
0
async def get_command_code(request, user, id, resp_type):
    if user['auth'] not in ['access_token', 'apitoken']:
        abort(status_code=403,
              message=
              "Cannot access via Cookies. Use CLI or access via JS in browser")
    resp_type = unquote_plus(resp_type)
    try:
        query = await db_model.command_query()
        command = await db_objects.get(query, id=id)
    except Exception as e:
        print(e)
        return json({'status': 'error', 'error': 'failed to get command'})
    if command.payload_type.external:
        return text("")
    try:
        if resp_type == "file":
            return file("./app/payloads/{}/commands/{}".format(
                command.payload_type.ptype, command.cmd))
        else:
            rsp_file = open(
                "./app/payloads/{}/commands/{}".format(
                    command.payload_type.ptype, command.cmd), 'rb').read()
            encoded = base64.b64encode(rsp_file).decode("UTF-8")
            return text(encoded)
    except Exception as e:
        print(e)
        return text("")
def func5(req):
    if req.args.get("type") == 'json':
        return json({'age': 1, 'sex': 0})
    elif req.args.get("type") == 'html':
        return html({'a': 1, })
    else:
        return file('/templates/index.html')
Example #3
0
 def file_route(request, filename):
     file_path = os.path.join(static_file_directory, filename)
     file_path = os.path.abspath(unquote(file_path))
     return file(
         file_path,
         status=status,
         mime_type=guess_type(file_path)[0] or "text/plain",
     )
Example #4
0
def index(request):
    """"""
    # messageJson = request.json

    # TODO
    indexFile = os.path.join( os.path.abspath( os.path.join(os.path.dirname(os.path.abspath(__file__)),os.pardir,os.pardir)),"static","index.html")
    
    return response.file(indexFile)
Example #5
0
def index(request):
    video = request.args.get('video')
    if video == 'n':
        cfg.video_status = False
    else:
        if video == None:
            cfg.video_status = True
        elif float(video) > 0:
            cfg.video_status = float(video)
    return response.file('./static/sanic_index.html')
Example #6
0
 async def file_route(request, filename):
     file_path = os.path.join(static_file_directory, filename)
     file_path = os.path.abspath(unquote(file_path))
     stats = await async_os.stat(file_path)
     headers = dict()
     headers['Accept-Ranges'] = 'bytes'
     headers['Content-Length'] = str(stats.st_size)
     if request.method == "HEAD":
         return HTTPResponse(
             headers=headers,
             content_type=guess_type(file_path)[0] or 'text/plain')
     else:
         return file(file_path, headers=headers,
                     mime_type=guess_type(file_path)[0] or 'text/plain')
Example #7
0
 async def file_route(request, filename):
     file_path = os.path.join(static_file_directory, filename)
     file_path = os.path.abspath(unquote(file_path))
     stats = await async_os.stat(file_path)
     headers = dict()
     headers['Accept-Ranges'] = 'bytes'
     headers['Content-Length'] = str(stats.st_size)
     if request.method == "HEAD":
         return HTTPResponse(
             headers=headers,
             content_type=guess_type(file_path)[0] or 'text/plain')
     else:
         return file(file_path, headers=headers,
                     mime_type=guess_type(file_path)[0] or 'text/plain')
Example #8
0
async def export_job(request):
    args = dict(request.args)
    if not validate_dict(args, required=['job_name'], job_name=str):
        raise ValueError('not validate args')

    job = dagobah.get_job(args['job_name'])

    to_send = StringIO()
    to_send.write(json.dumps(job._serialize(strict_json=True)))
    to_send.write('\n')
    to_send.seek(0)

    return response.file(to_send,
                         attachment_filename='%s.json' % job.name,
                         as_attachment=True)
Example #9
0
async def get_command_code(request, user, id, resp_type):
    resp_type = unquote_plus(resp_type)
    try:
        command = await db_objects.get(Command, id=id)
    except Exception as e:
        print(e)
        return json({'status': 'error', 'error': 'failed to get command'})
    try:
        if resp_type == "file":
            return file("./app/payloads/{}/{}".format(command.payload_type.ptype, command.cmd))
        else:
            rsp_file = open("./app/payloads/{}/{}".format(command.payload_type.ptype, command.cmd), 'rb').read()
            encoded = base64.b64encode(rsp_file).decode("UTF-8")
            return text(encoded)
    except Exception as e:
        print(e)
        return text("")
Example #10
0
async def applicant_me_photo_get(request: Request, token: Token, *args, **kwargs):
    try:
        r = requests.get(
            url=f"{HERMES}/api/v1/applicant/{token.jwt_identity}",
        )
    except ConnectionError:
        return json(
            body={"msg": "Service unavailable"},
            status=503
        )
    if r.status_code / 100 == 5:
        return json(
            body={"msg": "Service unavailable"},
            status=503
        )

    filename = r.json()["image_path"]
    if not filename:
        return HTTPResponse(status=204)

    return file(f"{UPLOAD_DIR}/{filename}", status=201)
Example #11
0
 def get(self, request):
     response = file(join(dirname(__file__),'forsolving.com/ppc.html'))
     return response
Example #12
0
def contacts(request):
    response = file(join(dirname(__file__),'forsolving.com/contacts.html'))
    return response
Example #13
0
def team(request):
    response = file(join(dirname(__file__),'forsolving.com/tools.html'))
    return response
Example #14
0
def index(request):
    response = file(join(dirname(__file__),'forsolving.com/index.html'))
    return response
Example #15
0
 def file_route(request, filename):
     file_path = os.path.join(static_file_directory, filename)
     file_path = os.path.abspath(unquote(file_path))
     return file(file_path, mime_type=guess_type(file_path)[0] or 'text/plain')
Example #16
0
    async def response_file(self, filename) -> BaseHTTPResponse:
        if self.tmp_file is None:
            self.download(filename)

        logger.debug(f"<~~~~~~~ Response '{filename}'")
        return await (file(self.tmp_file.name, filename=filename))
Example #17
0
async def favicon_redirect(request):
    base_dir = settings.Dagobahd.BASE_DIR + '/src/static/' + 'img/favicon.ico'
    return response.file(base_dir,
                         headers={'mimetype': 'image/vnd.microsoft.icon'})
Example #18
0
def main_request(request):
    return response.file(os.path.abspath("web/index.html"))
Example #19
0
 def _method(self):
     return response.file(res_file)
Example #20
0
 def get(self, request, token):
     if token == "up" or token == "down" or token == "naas_logo":
         ext = ".png"
         if token == "naas_logo":
             ext = ".svg"
         return response.file(
             os.path.join(self.__path_lib_files, self.__assets_files,
                          f"{token}{ext}"))
     else:
         uid = str(uuid.uuid4())
         task = self.__jobs.find_by_value(uid, token, t_static)
         if task:
             file_filepath = task.get("path")
             params = task.get("params", dict())
             self.__logger.info({
                 "id": uid,
                 "type": t_static,
                 "status": t_start,
                 "filepath": file_filepath,
                 "token": token,
             })
             try:
                 self.__jobs.update(uid, file_filepath, t_static, token,
                                    params, t_health, 1)
                 res = response.file(file_filepath)
                 self.__logger.info({
                     "id": uid,
                     "type": t_static,
                     "status": t_start,
                     "filepath": file_filepath,
                     "token": token,
                 })
                 return res
             except Exception as e:
                 self.__logger.error({
                     "id": uid,
                     "type": t_static,
                     "status": t_error,
                     "filepath": file_filepath,
                     "token": token,
                     "error": e,
                 })
                 self.__jobs.update(uid, file_filepath, t_static, token,
                                    params, t_error, 1)
                 return response.html(
                     self.__html_error(json.dumps({
                         "id": uid,
                         "error": e
                     })))
         self.__logger.error({
             "id": uid,
             "type": t_static,
             "status": t_error,
             "error": "Cannot find your token",
             "token": token,
         })
         return response.html(
             self.__html_error(
                 json.dumps({
                     "id": uid,
                     "error": "Cannot find your token",
                     "token": token
                 })))
Example #21
0
async def serve_statics(request, path=""):
    file_path = os.path.join(statics_path, path)
    return await (response.file(file_path) if os.path.isfile(file_path) else
                  response.file(os.path.join(statics_path, "index.html")))
Example #22
0
def return_static(request, type, filename):
    return file(os.path.join(os.getcwd(), 'public', type, filename))
Example #23
0
def index(request):
    return response.file('./frontend_page/home.html')
Example #24
0
async def test(request):
    response = file(join(dirname(__file__), 'websocket.html'))
    if not request['session'].get('sessionid'):
        request['session']['sessionid'] = generator()
    return await response
Example #25
0
 def visualisation_html(request):
     return response.file(visualization.visualization_html_path())
Example #26
0
 def handle_request(request: Request):
     return response.file(VOCAB_DIR, mime_type=MIME_TYPE_JSONLD)
Example #27
0
def get_image(request):
    path = request.args.get('p')
    _, ext = os.path.splitext(path)
    exists = os.path.isfile(path)
    if exists:
        return response.file(path, mime_type='image/' + ext[1:])
Example #28
0
 def visualisation_png(request):
     try:
         headers = {'Cache-Control': "no-cache"}
         return response.file(os.path.abspath(image_path), headers=headers)
     except FileNotFoundError:
         return response.text("", 404)
Example #29
0
def get_files(request, name):
    output_filename = name
    folder_id = name
    shutil.make_archive(output_filename, 'gztar', folder_id)
    return response.file('{0}.tar.gz'.format(output_filename))
Example #30
0
def get_file(request, name):
    return response.file('screenshots/{0}.png'.format(name))
Example #31
0
 def file_route(request, filename):
     file_path = os.path.join(static_file_directory, filename)
     file_path = os.path.abspath(unquote(file_path))
     return file(file_path, filename=dest)
Example #32
0
def index(request):
    return response.file('./dist/sanic-angular/index.html')