Esempio n. 1
0
def subscription_put():
    card = flask.request.json.get('card')
    email = flask.request.json.get('email')
    cancel = flask.request.json.get('cancel')

    try:
        if cancel:
            response = utils.request.delete(SUBSCRIPTION_SERVER,
                json_data={
                    'license': settings.app.license,
                },
            )
        else:
            response = utils.request.put(SUBSCRIPTION_SERVER,
                json_data={
                    'license': settings.app.license,
                    'card': card,
                    'email': email,
                },
            )
    except httplib.HTTPException:
        return utils.jsonify({
            'error': SUBSCRIPTION_SERVER_ERROR,
            'error_msg': SUBSCRIPTION_SERVER_ERROR_MSG,
        }, 500)

    if response.status_code != 200:
        return utils.jsonify(response.json(), response.status_code)

    subscription.update()
    return utils.jsonify(subscription.dict())
Esempio n. 2
0
def subscription_post():
    license = flask.request.json['license']
    license = license.lower().replace('begin license',
                                      '').replace('end license', '')
    license = re.sub(r'[\W_]+', '', license)

    try:
        response = utils.request.get(
            'https://app.pritunl.com/subscription',
            json_data={
                'license': license,
                'version': settings.local.version_int,
            },
        )
    except httplib.HTTPException:
        return utils.jsonify(
            {
                'error': SUBSCRIPTION_SERVER_ERROR,
                'error_msg': SUBSCRIPTION_SERVER_ERROR_MSG,
            }, 500)
    data = response.json()

    if response.status_code != 200:
        return utils.jsonify(data, response.status_code)

    subscription.update_license(license)
    return utils.jsonify(subscription.dict())
Esempio n. 3
0
def subscription_post():
    license = flask.request.json['license']
    license = license.lower().replace('begin license', '').replace(
        'end license', '')
    license = re.sub(r'[\W_]+', '', license)

    try:
        response = utils.request.get(
            'https://app.pritunl.com/subscription',
            json_data={
                'license': license,
                'version': settings.local.version_int,
            },
        )
    except httplib.HTTPException:
        return utils.jsonify({
            'error': SUBSCRIPTION_SERVER_ERROR,
            'error_msg': SUBSCRIPTION_SERVER_ERROR_MSG,
        }, 500)
    data = response.json()

    if response.status_code != 200:
        return utils.jsonify(data, response.status_code)

    subscription.update_license(license)
    return utils.jsonify(subscription.dict())
Esempio n. 4
0
def subscription_put():
    card = flask.request.json.get('card')
    email = flask.request.json.get('email')
    cancel = flask.request.json.get('cancel')

    try:
        if cancel:
            response = utils.request.delete(
                SUBSCRIPTION_SERVER,
                json_data={
                    'license': settings.app.license,
                },
            )
        else:
            response = utils.request.put(
                SUBSCRIPTION_SERVER,
                json_data={
                    'license': settings.app.license,
                    'card': card,
                    'email': email,
                },
            )
    except httplib.HTTPException:
        return utils.jsonify(
            {
                'error': SUBSCRIPTION_SERVER_ERROR,
                'error_msg': SUBSCRIPTION_SERVER_ERROR_MSG,
            }, 500)

    if response.status_code != 200:
        return utils.jsonify(response.json(), response.status_code)

    subscription.update()
    return utils.jsonify(subscription.dict())
Esempio n. 5
0
def subscription_get():
    if settings.app.demo_mode:
        resp = utils.demo_get_cache()
        if resp:
            return utils.jsonify(resp)

    subscription.update()
    resp = subscription.dict()
    if settings.app.demo_mode:
        utils.demo_set_cache(resp)
    return utils.jsonify(resp)
Esempio n. 6
0
def subscription_get():
    if settings.app.demo_mode:
        resp = utils.demo_get_cache()
        if resp:
            return utils.jsonify(resp)

    subscription.update()
    resp = subscription.dict()
    if settings.app.demo_mode:
        utils.demo_set_cache(resp)
    return utils.jsonify(resp)
Esempio n. 7
0
def subscription_post():
    # if settings.app.demo_mode:
    #     return utils.demo_blocked()

    # license = flask.request.json['license']
    # license = license.lower().replace('begin license', '').replace(
    #     'end license', '')
    # license = re.sub(r'[\W_]+', '', license)

    # try:
    #     url = 'https://app.pritunl.com/subscription'
    #     if settings.app.dedicated:
    #         url = settings.app.dedicated + '/subscription'

    #     response = requests.get(
    #         url,
    #         json={
    #             'license': license,
    #             'version': settings.local.version_int,
    #         },
    #     )
    # except httplib.HTTPException:
    #     return utils.jsonify({
    #         'error': SUBSCRIPTION_SERVER_ERROR,
    #         'error_msg': SUBSCRIPTION_SERVER_ERROR_MSG,
    #     }, 500)
    # data = response.json()

    # if response.status_code != 200:
    #     return utils.jsonify(data, response.status_code)
    license = {
        'active': True,
        'status': 'active',
        'plan': 'enterprise',
        'quantity': 1,
        'amount': 250,
        'period_end': math.floor(time.time() / 1000) + 2592000,
        'trial_end': math.floor(time.time() / 1000) + 2592000,
        'cancel_at_period_end': False,
        'balance': 250,
        'url_key': True
    }
    try:
        subscription.update_license(license)
    except LicenseInvalid:
        return utils.jsonify(
            {
                'error': LICENSE_INVALID,
                'error_msg': LICENSE_INVALID_MSG,
            }, 500)
    return utils.jsonify(subscription.dict())
Esempio n. 8
0
def subscription_put():
    if settings.app.demo_mode:
        return utils.demo_blocked()

    card = flask.request.json.get('card')
    email = flask.request.json.get('email')
    plan = flask.request.json.get('plan')
    cancel = flask.request.json.get('cancel')

    try:
        url = 'https://app.pritunl.com/subscription'
        if settings.app.dedicated:
            url = settings.app.dedicated + '/subscription'

        if cancel:
            response = requests.delete(
                url,
                json={
                    'license': settings.app.license,
                },
            )
        else:
            response = requests.put(
                url,
                json={
                    'license': settings.app.license,
                    'card': card,
                    'plan': plan,
                    'email': email,
                },
            )
    except http.client.HTTPException:
        return utils.jsonify(
            {
                'error': SUBSCRIPTION_SERVER_ERROR,
                'error_msg': SUBSCRIPTION_SERVER_ERROR_MSG,
            }, 500)

    if response.status_code != 200:
        return utils.jsonify(response.json(), response.status_code)

    subscription.update()

    return utils.jsonify(subscription.dict())
Esempio n. 9
0
def subscription_put():
    # if settings.app.demo_mode:
    #     return utils.demo_blocked()

    # card = flask.request.json.get('card')
    # email = flask.request.json.get('email')
    # plan = flask.request.json.get('plan')
    # cancel = flask.request.json.get('cancel')

    # try:
    #     url = 'https://app.pritunl.com/subscription'
    #     if settings.app.dedicated:
    #         url = settings.app.dedicated + '/subscription'

    #     if cancel:
    #         response = requests.delete(
    #             url,
    #             json={
    #                 'license': settings.app.license,
    #             },
    #         )
    #     else:
    #         response = requests.put(
    #             url,
    #             json={
    #                 'license': settings.app.license,
    #                 'card': card,
    #                 'plan': plan,
    #                 'email': email,
    #             },
    #         )
    # except httplib.HTTPException:
    #     return utils.jsonify({
    #         'error': SUBSCRIPTION_SERVER_ERROR,
    #         'error_msg': SUBSCRIPTION_SERVER_ERROR_MSG,
    #     }, 500)

    # if response.status_code != 200:
    #     return utils.jsonify(response.json(), response.status_code)

    subscription.update()

    return utils.jsonify(subscription.dict())
Esempio n. 10
0
def subscription_put():
    if settings.app.demo_mode:
        return utils.demo_blocked()

    card = flask.request.json.get('card')
    email = flask.request.json.get('email')
    plan = flask.request.json.get('plan')
    promo_code = flask.request.json.get('promo_code')
    cancel = flask.request.json.get('cancel')

    try:
        if cancel:
            response = requests.delete(
                'https://app.pritunl.com/subscription',
                json={
                    'license': settings.app.license,
                },
            )
        else:
            response = requests.put(
                'https://app.pritunl.com/subscription',
                json={
                    'license': settings.app.license,
                    'card': card,
                    'plan': plan,
                    'promo_code': promo_code,
                    'email': email,
                },
            )
    except httplib.HTTPException:
        return utils.jsonify({
            'error': SUBSCRIPTION_SERVER_ERROR,
            'error_msg': SUBSCRIPTION_SERVER_ERROR_MSG,
        }, 500)

    if response.status_code != 200:
        return utils.jsonify(response.json(), response.status_code)

    subscription.update()

    return utils.jsonify(subscription.dict())
Esempio n. 11
0
def subscription_post():
    if settings.app.demo_mode:
        return utils.demo_blocked()

    license = flask.request.json['license']
    license = license.lower().replace('begin license',
                                      '').replace('end license', '')
    license = re.sub(r'[\W_]+', '', license)

    try:
        url = 'https://app.pritunl.com/subscription'
        if settings.app.dedicated:
            url = settings.app.dedicated + '/subscription'

        response = requests.get(
            url,
            json={
                'license': license,
                'version': settings.local.version_int,
            },
        )
    except http.client.HTTPException:
        return utils.jsonify(
            {
                'error': SUBSCRIPTION_SERVER_ERROR,
                'error_msg': SUBSCRIPTION_SERVER_ERROR_MSG,
            }, 500)
    data = response.json()

    if response.status_code != 200:
        return utils.jsonify(data, response.status_code)

    try:
        subscription.update_license(license)
    except LicenseInvalid:
        return utils.jsonify(
            {
                'error': LICENSE_INVALID,
                'error_msg': LICENSE_INVALID_MSG,
            }, 500)
    return utils.jsonify(subscription.dict())
Esempio n. 12
0
def subscription_get():
    subscription.update()
    return utils.jsonify(subscription.dict())
Esempio n. 13
0
def subscription_get():
    subscription.update()
    return utils.jsonify(subscription.dict())