From 315aaded4148a08f9bf33069f5f7156aaee852fd Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Thu, 20 Feb 2020 16:05:58 +0100 Subject: [PATCH] Focus on creating a VPN as a first test case --- README.md | 7 +++- hack.py => hack-a-vpn.py | 81 +++++++++++++++++++++++++++++++++++++++- ldaptest.py | 25 +++++++++++-- 3 files changed, 106 insertions(+), 7 deletions(-) rename hack.py => hack-a-vpn.py (53%) diff --git a/README.md b/README.md index 1b50cf3..72199ca 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,10 @@ The pay module for the uncloud - uses [Stripe](https://stripe.com/docs/api) as the payment gateway. - uses [ldap3](https://github.com/cannatag/ldap3) for ldap authentication. -## Getting started + +## Getting started as a user + + **TODO** @@ -40,4 +43,4 @@ http --json GET http://[::]:5000/order/list email=your_email_here password=your_ ```shell script http --json http://[::]:5000/user/register_payment card_number=4111111111111111 cvc=123 expiry_year=2020 expiry_month=8 card_holder_name="The test user" email=your_email_here password=your_password_here -``` \ No newline at end of file +``` diff --git a/hack.py b/hack-a-vpn.py similarity index 53% rename from hack.py rename to hack-a-vpn.py index cbb9a07..0956cd5 100644 --- a/hack.py +++ b/hack-a-vpn.py @@ -82,8 +82,84 @@ class Order(Resource): @staticmethod def post(): - print("{} {}".format(data, config)) data = request.get_json(silent=True) or {} + print("{} {}".format(data, config)) + + +class Product(Resource): + def __init__(self, config): + self.config = config + + self.products = [] + self.products.append( + { "name": "membership-free", + "description": """ +This membership gives you access to the API and includes a VPN +with 1 IPv6 address. +See https://redmine.ungleich.ch/issues/7747? +""", + "uuid": "a3883466-0012-4d01-80ff-cbf7469957af", + "recurring": True, + "recurring_time_frame": "per_year", + "features": [ + { "name": "membership", + "price_one_time": 0, + "price_recurring": 0 + } + ] + } + ) + self.products.append( + { "name": "membership-standard", + "description": """ +This membership gives you access to the API and includes an IPv6-VPN with +one IPv6 address ("Road warrior") +See https://redmine.ungleich.ch/issues/7747? +""", + "uuid": "1d85296b-0863-4dd6-a543-a6d5a4fbe4a6", + "recurring": True, + "recurring_time_frame": "per_month", + "features": [ + { "name": "membership", + "price_one_time": 0, + "price_recurring": 5 + } + + ] + } + ) + self.products.append( + { "name": "membership-premium", + "description": """ +This membership gives you access to the API and includes an +IPv6-VPN with a /48 IPv6 network. +See https://redmine.ungleich.ch/issues/7747? +""", + "uuid": "bfd63fd2-d227-436f-a8b8-600de74dd6ce", + "recurring": True, + "recurring_time_frame": "per_month", + "features": [ + { "name": "membership", + "price_one_time": 0, + "price_recurring": 5 + } + + ] + } + ) + + + @staticmethod + def post(): + data = request.get_json(silent=True) or {} + print("{} {}".format(data, config)) + + def get(self): + data = request.get_json(silent=True) or {} + print("{} {}".format(data, config)) + + return self.products + @@ -97,7 +173,8 @@ if __name__ == '__main__': config['ldap_url']="ldaps://ldap1.ungleich.ch" api = Api(app) - api.add_resource(Order, '/order', resource_class_args=( config, )) + api.add_resource(Order, '/orders', resource_class_args=( config, )) + api.add_resource(Product, '/products', resource_class_args=( config, )) api.add_resource(Membership, '/membership', resource_class_args=( config, )) app.run(host='::', port=5000, debug=True) diff --git a/ldaptest.py b/ldaptest.py index f28fcf6..eb5a5be 100644 --- a/ldaptest.py +++ b/ldaptest.py @@ -1,8 +1,27 @@ import ldap3 from ldap3 import Server, Connection, ObjectDef, Reader, ALL import os +import sys -server = Server("ldaps://ldap1.ungleich.ch") -conn = Connection(server, 'cn=Nico Schottelius,ou=users,dc=ungleich,dc=ch', os.environ['PW'], auto_bind=True) +def is_valid_ldap_user(username, password): + server = Server("ldaps://ldap1.ungleich.ch") + is_valid = False -print(conn) + try: + conn = Connection(server, 'cn={},ou=users,dc=ungleich,dc=ch'.format(username), password, auto_bind=True) + is_valid = True + except Exception as e: + print("user: {}".format(e)) + + try: + conn = Connection(server, 'uid={},ou=customer,dc=ungleich,dc=ch'.format(username), password, auto_bind=True) + is_valid = True + except Exception as e: + print("customer: {}".format(e)) + + + return is_valid + + +if __name__ == '__main__': + print(is_valid_ldap_user(sys.argv[1], sys.argv[2]))