Example #1
0
def authz(environ, start_response):
    """ authorization handling """
    if environ['REQUEST_METHOD'] == 'POST' or environ['REQUEST_METHOD'] == 'GET':
        with Authorization(DEBUG, get_url(environ), LOGGER) as authorization:
            if environ['REQUEST_METHOD'] == 'POST':
                try:
                    request_body_size = int(environ.get('CONTENT_LENGTH', 0))
                except ValueError:
                    request_body_size = 0
                request_body = environ['wsgi.input'].read(request_body_size)
                response_dic = authorization.new_post(request_body)
            else:
                response_dic = authorization.new_get(get_url(environ, True))

            # generate header and nonce
            headers = [('Content-Type', 'application/json')]
            # enrich header
            if 'header' in response_dic:
                for element, value in response_dic['header'].items():
                    headers.append((element, value))
            start_response('{0} {1}'.format(response_dic['code'], HTTP_CODE_DIC[response_dic['code']]), headers)

            # logging
            logger_info(LOGGER, environ['REMOTE_ADDR'], environ['PATH_INFO'], response_dic)
            return [json.dumps(response_dic['data']).encode('utf-8')]
    else:
        start_response('405 {0}'.format(HTTP_CODE_DIC[405]), [('Content-Type', 'application/json')])
        return [json.dumps({'status':405, 'message':HTTP_CODE_DIC[405], 'detail': 'Wrong request type. Expected POST.'}).encode('utf-8')]
Example #2
0
def chall(environ, start_response):
    """ create new account """
    with Challenge(DEBUG, get_url(environ), LOGGER) as challenge:
        if environ['REQUEST_METHOD'] == 'POST':

            request_body = get_request_body(environ)
            response_dic = challenge.parse(request_body)

            # create header
            headers = create_header(response_dic)
            start_response('{0} {1}'.format(response_dic['code'], HTTP_CODE_DIC[response_dic['code']]), headers)

            # logging
            logger_info(LOGGER, environ['REMOTE_ADDR'], environ['PATH_INFO'], response_dic)
            return [json.dumps(response_dic['data']).encode('utf-8')]

        elif environ['REQUEST_METHOD'] == 'GET':

            response_dic = challenge.get(get_url(environ, True))

            # generate header
            headers = [('Content-Type', 'application/json')]
            # create the response
            start_response('{0} {1}'.format(response_dic['code'], HTTP_CODE_DIC[response_dic['code']]), headers)

            # logging
            logger_info(LOGGER, environ['REMOTE_ADDR'], environ['PATH_INFO'], response_dic)
            # send response
            return [json.dumps(response_dic['data']).encode('utf-8')]

        else:
            start_response('405 {0}'.format(HTTP_CODE_DIC[405]), [('Content-Type', 'application/json')])
            return [json.dumps({'status':405, 'message':HTTP_CODE_DIC[405], 'detail': 'Wrong request type. Expected POST.'}).encode('utf-8')]
Example #3
0
def cert(request):
    """ cert request """
    if request.method == 'POST' or request.method == 'GET':
        with Certificate(DEBUG, get_url(request.META), LOGGER) as certificate:
            if request.method == 'POST':
                response_dic = certificate.new_post(request.body)
            else:
                response_dic = certificate.new_get(request.build_absolute_uri())

            # create the response
            if response_dic['code'] == 200:
                response = HttpResponse(response_dic['data'])
                # generate additional header elements
                for element in response_dic['header']:
                    response[element] = response_dic['header'][element]
            else:
                response = HttpResponse(status=response_dic['code'])

            # logging
            logger_info(LOGGER, request.META['REMOTE_ADDR'], request.META['PATH_INFO'], response_dic)
            # send response
            return response

    else:
        return JsonResponse(status=405, data={'status': 405, 'message': 'Method Not Allowed', 'detail': 'Wrong request type. Expected POST.'})
Example #4
0
def chall(request):
    """ challenge command """
    with Challenge(DEBUG, get_url(request.META), LOGGER) as challenge:
        # pylint: disable=R1705
        if request.method == 'POST':
            response_dic = challenge.parse(request.body)
            # create the response
            response = JsonResponse(status=response_dic['code'], data=response_dic['data'])
            # generate additional header elements
            for element in response_dic['header']:
                response[element] = response_dic['header'][element]

            # logging
            logger_info(LOGGER, request.META['REMOTE_ADDR'], request.META['PATH_INFO'], response_dic)
            # send response
            return response
        elif request.method == 'GET':
            response_dic = challenge.get(request.build_absolute_uri())
            # create the response
            response = JsonResponse(status=response_dic['code'], data=response_dic['data'])

            # logging
            # logger_info(LOGGER, request.META['REMOTE_ADDR'], request.META['PATH_INFO'], response_dic)
            # send response
            return response
        else:
            return JsonResponse(status=405, data={'status': 405, 'message': 'Method Not Allowed', 'detail': 'Wrong request type. Expected POST.'})
Example #5
0
def newaccount(request):
    """ new account """
    if request.method == 'POST':
        with Account(DEBUG, get_url(request.META), LOGGER) as account:
            response_dic = account.new(request.body)
            # create the response
            response = JsonResponse(status=response_dic['code'],
                                    data=response_dic['data'])

            # generate additional header elements
            for element in response_dic['header']:
                response[element] = response_dic['header'][element]

            # logging
            logger_info(LOGGER, request.META['REMOTE_ADDR'],
                        request.META['PATH_INFO'], response_dic)
            # send response
            return response
    else:
        return JsonResponse(status=405,
                            data={
                                'status': 405,
                                'message': 'Method Not Allowed',
                                'detail': 'Wrong request type. Expected POST.'
                            })
Example #6
0
def authz(request):
    """ new-authz command """
    if request.method == 'POST' or request.method == 'GET':
        with Authorization(DEBUG, get_url(request.META),
                           LOGGER) as authorization:
            if request.method == 'POST':
                response_dic = authorization.new_post(request.body)
            else:
                response_dic = authorization.new_get(
                    request.build_absolute_uri())
            # create the response
            response = JsonResponse(status=response_dic['code'],
                                    data=response_dic['data'])

            # generate additional header elements
            for element in response_dic['header']:
                response[element] = response_dic['header'][element]

            # logging
            logger_info(LOGGER, request.META['REMOTE_ADDR'],
                        request.META['PATH_INFO'], response_dic)
            # send response
            return response
    else:
        return JsonResponse(status=405,
                            data={
                                'status': 405,
                                'message': 'Method Not Allowed',
                                'detail': 'Wrong request type. Expected POST.'
                            })
Example #7
0
def trigger(environ, start_response):
    """ ca trigger handler """
    if environ['REQUEST_METHOD'] == 'POST':
        with Trigger(DEBUG, get_url(environ), LOGGER) as trigger_:
            request_body = get_request_body(environ)
            response_dic = trigger_.parse(request_body)

            # create header
            headers = create_header(response_dic)
            start_response(
                '{0} {1}'.format(response_dic['code'],
                                 HTTP_CODE_DIC[response_dic['code']]), headers)

            # logging
            logger_info(LOGGER, environ['REMOTE_ADDR'], environ['PATH_INFO'],
                        response_dic)

            if 'data' in response_dic:
                return [json.dumps(response_dic['data']).encode('utf-8')]
            else:
                return []
            # start_response('200 {0}'.format(HTTP_CODE_DIC[200]), [('Content-Type', 'application/json')])
            # return [json.dumps({'status':200, 'message':HTTP_CODE_DIC[200], 'detail': 'OK'}).encode('utf-8')]
    else:
        start_response('405 {0}'.format(HTTP_CODE_DIC[405]),
                       [('Content-Type', 'application/json')])
        return [
            json.dumps({
                'status': 405,
                'message': HTTP_CODE_DIC[405],
                'detail': 'Wrong request type. Expected POST.'
            }).encode('utf-8')
        ]
Example #8
0
def neworders(environ, start_response):
    """ generate a new order """
    if environ['REQUEST_METHOD'] == 'POST':
        with Order(DEBUG, get_url(environ), LOGGER) as norder:
            request_body = get_request_body(environ)
            response_dic = norder.new(request_body)

            # create header
            headers = create_header(response_dic)
            start_response(
                '{0} {1}'.format(response_dic['code'],
                                 HTTP_CODE_DIC[response_dic['code']]), headers)

            # logging
            logger_info(LOGGER, environ['REMOTE_ADDR'], environ['PATH_INFO'],
                        response_dic)
            return [json.dumps(response_dic['data']).encode('utf-8')]

    else:
        start_response('405 {0}'.format(HTTP_CODE_DIC[405]),
                       [('Content-Type', 'application/json')])
        return [
            json.dumps({
                'status': 405,
                'message': HTTP_CODE_DIC[405],
                'detail': 'Wrong request type. Expected POST.'
            }).encode('utf-8')
        ]
Example #9
0
def directory(environ, start_response):
    """ directory listing """
    with Directory(DEBUG, get_url(environ), LOGGER) as direct_tory:
        start_response('200 OK', [('Content-Type', 'application/json')])
        # logging
        logger_info(LOGGER, environ['REMOTE_ADDR'], environ['PATH_INFO'], '')
        return [json.dumps(direct_tory.directory_get()).encode('utf-8')]
Example #10
0
def acmechallenge_serve(request):
    """ serving acme challenges """
    with Acmechallenge(DEBUG, get_url(request.META), LOGGER) as acmechallenge:
        key_authorization = acmechallenge.lookup(request.META['PATH_INFO'])
        if key_authorization:
            return HttpResponse(key_authorization)
        else:
            return HttpResponseNotFound('NOT FOUND')
Example #11
0
def directory(environ, start_response):
    """ directory listing """
    with Directory(DEBUG, get_url(environ), LOGGER) as direct_tory:
        headers = create_header({'code': 200})
        start_response('200 OK', headers)
        # logging
        logger_info(LOGGER, environ['REMOTE_ADDR'], environ['PATH_INFO'], '')
        return [json.dumps(direct_tory.directory_get()).encode('utf-8')]
Example #12
0
def acct(environ, start_response):
    """ account handling """
    with Account(DEBUG, get_url(environ), LOGGER) as account:
        request_body = get_request_body(environ)
        response_dic = account.parse(request_body)

        # create header
        headers = create_header(response_dic)
        start_response('{0} {1}'.format(response_dic['code'], HTTP_CODE_DIC[response_dic['code']]), headers)
        return [json.dumps(response_dic['data']).encode('utf-8')]
Example #13
0
def acct(request):
    """ xxxx command """
    with Account(DEBUG, get_url(request.META), LOGGER) as account:
        response_dic = account.parse(request.body)
        # create the response
        response = JsonResponse(status=response_dic['code'], data=response_dic['data'])

        # generate additional header elements
        for element in response_dic['header']:
            response[element] = response_dic['header'][element]

        # logging
        logger_info(LOGGER, request.META['REMOTE_ADDR'], request.META['PATH_INFO'], response_dic)
        # send response
        return response
Example #14
0
def acmechallenge_serve(environ, start_response):
    """ directory listing """
    with Acmechallenge(DEBUG, get_url(environ), LOGGER) as acmechallenge:
        request_body = get_request_body(environ)
        key_authorization = acmechallenge.lookup(environ['PATH_INFO'])
        if not key_authorization:
            key_authorization = 'NOT FOUND'
            start_response('404 {0}'.format(HTTP_CODE_DIC[404]),
                           [('Content-Type', 'text/html')])
        else:
            start_response('200 {0}'.format(HTTP_CODE_DIC[200]),
                           [('Content-Type', 'text/html')])
        # logging
        logger_info(LOGGER, environ['REMOTE_ADDR'], environ['PATH_INFO'], {})
        return [key_authorization.encode('utf-8')]
Example #15
0
def directory(request):
    """ get directory """
    with Directory(DEBUG, get_url(request.META), LOGGER) as cfg_dir:
        return JsonResponse(cfg_dir.directory_get())
Example #16
0
def servername_get(request):
    """ get server name """
    with Directory(DEBUG, get_url(request.META), LOGGER) as cfg_dir:
        return JsonResponse({'server_name': cfg_dir.servername_get()})