diff --git a/Readme.md b/Readme.md new file mode 100644 index 00000000..a41eeb09 --- /dev/null +++ b/Readme.md @@ -0,0 +1,21 @@ +# Wireguard Backend + +## Code Structure +``` + ocp-wg-backend + -> wgweb # Your global configs + -> wg_api # Your shitty APIs + -> utils # Custom tools for custom tasks +``` +### Docker based deployment + +1. Create docker container with `docker build . -t wg-backend` +2. Run the docker with volume binding to apply realtime code changes. + ``` + docker run --rm -it -v $(pwd):/usr/src/app wg-backend + ``` + +## Future works + +- [ ] Implement `docker-compose` deployment method. +- [ ] diff --git a/wg_api/__pycache__/views.cpython-310.pyc b/wg_api/__pycache__/views.cpython-310.pyc index 284844ba..623e733a 100644 Binary files a/wg_api/__pycache__/views.cpython-310.pyc and b/wg_api/__pycache__/views.cpython-310.pyc differ diff --git a/wg_api/__pycache__/views.cpython-311.pyc b/wg_api/__pycache__/views.cpython-311.pyc index e05b6ad9..f83f5035 100644 Binary files a/wg_api/__pycache__/views.cpython-311.pyc and b/wg_api/__pycache__/views.cpython-311.pyc differ diff --git a/wg_api/utils/__pycache__/reqs_handler.cpython-310.pyc b/wg_api/utils/__pycache__/reqs_handler.cpython-310.pyc index 87b6de4b..e9ea12ce 100644 Binary files a/wg_api/utils/__pycache__/reqs_handler.cpython-310.pyc and b/wg_api/utils/__pycache__/reqs_handler.cpython-310.pyc differ diff --git a/wg_api/utils/__pycache__/reqs_handler.cpython-311.pyc b/wg_api/utils/__pycache__/reqs_handler.cpython-311.pyc index 34175a5e..52c8d424 100644 Binary files a/wg_api/utils/__pycache__/reqs_handler.cpython-311.pyc and b/wg_api/utils/__pycache__/reqs_handler.cpython-311.pyc differ diff --git a/wg_api/utils/reqs_handler.py b/wg_api/utils/reqs_handler.py index f66403d9..d316f323 100644 --- a/wg_api/utils/reqs_handler.py +++ b/wg_api/utils/reqs_handler.py @@ -82,3 +82,29 @@ def req_ip_recommendation(): print(req_dump) return json.dumps(req_dump) + +def reg_bulk(data): + + inf_s = get_session() + req_url = 'http://10.30.1.138:5000/api/new-client' + + # req = inf_s.post(req_url, req_val) + + + for x in data: + + uname = x[0] + email = x[1] + code = x[2] + org = x[3] + + data = {"name":uname,"email":email,"code":code,"org":org} + # data = {"name":uname,"email":email,"allocated_ips":suggest_ips,"allowed_ips":allowed_ips,"extra_allowed_ips":[],"use_server_dns":true,"enabled":true,"preshared_key":true} + + print(data) + + + # ret_reg=$(curl -s --location --request POST 'http://10.30.1.138:5000/new-client' \ + # --header 'Content-Type: application/json' \ + # --cookie .tmp-cookie \ + # --data-raw '{"name":"'$uname'","email":"'$email'","allocated_ips":'$suggest_ips',"allowed_ips":["10.0.0.0/8", "192.168.100.0/24"],"extra_allowed_ips":[],"use_server_dns":true,"enabled":true,"preshared_key":true}' ) diff --git a/wg_api/views.py b/wg_api/views.py index 5e123559..06815db0 100644 --- a/wg_api/views.py +++ b/wg_api/views.py @@ -15,7 +15,7 @@ from .models import user_model from .utils.html_parser import get_logs, get_profiles import json from .utils.statistics import count_clients, count_traffic, count_connection, count_percentage, count_broken -from .utils.reqs_handler import req_edit_state, req_edit_user, req_apply_sys, req_ip_recommendation +from .utils.reqs_handler import req_edit_state, req_edit_user, req_apply_sys, req_ip_recommendation, reg_bulk from django.middleware.csrf import get_token from django.views.decorators.csrf import csrf_exempt @@ -26,8 +26,7 @@ class wgLogin(APIView): def get(self, request, format=None): # serializer = self.get_serializer(data=request.data) - # serializer.is_valid(raise_exception=True) - # user = serializer.validated_data['user'] + # serializer.is_valid(raise_exception=True) user = serializer.validated_data['user'] user = request.GET.get('username') password = request.GET.get('password') @@ -514,7 +513,7 @@ def wgBulkReg(request): print("-> Bulk Registration") RegData = json.loads(request.body) - for x in RegData: - print(x) + req_ip = req_ip_recommendation() + req_commit = reg_bulk(RegData) - return HttpResponse({"success"}, content_type='application') + return HttpResponse(json.dumps({"Reg":"Success"}), content_type='application') diff --git a/wgweb/__pycache__/settings.cpython-310.pyc b/wgweb/__pycache__/settings.cpython-310.pyc index 6d50c353..fc6c888b 100644 Binary files a/wgweb/__pycache__/settings.cpython-310.pyc and b/wgweb/__pycache__/settings.cpython-310.pyc differ diff --git a/wgweb/__pycache__/settings.cpython-311.pyc b/wgweb/__pycache__/settings.cpython-311.pyc index dd1c287d..5c9e0723 100644 Binary files a/wgweb/__pycache__/settings.cpython-311.pyc and b/wgweb/__pycache__/settings.cpython-311.pyc differ diff --git a/wgweb/__pycache__/urls.cpython-311.pyc b/wgweb/__pycache__/urls.cpython-311.pyc index 446fe80d..a7485d07 100644 Binary files a/wgweb/__pycache__/urls.cpython-311.pyc and b/wgweb/__pycache__/urls.cpython-311.pyc differ diff --git a/wgweb/settings.py b/wgweb/settings.py index 12bb1506..02bca18c 100644 --- a/wgweb/settings.py +++ b/wgweb/settings.py @@ -25,7 +25,7 @@ SECRET_KEY = 'django-insecure-n(+d-xz5933rr363)v31jcdl^+#ab23&s317uxek+d*-_d6q99 # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True -ALLOWED_HOSTS = ["192.168.10.2", "127.0.0.1", "localhost:8000", "localhost:5000", "wg-django-backend-ma-wg.apps-crc.testing", "wg.nnag.me"] +ALLOWED_HOSTS = ["192.168.10.2", "127.0.0.1", "localhost:8000", "localhost:5000", "wg-django-backend-ma-wg.apps-crc.testing", "wg.nnag.me", "172.17.0.2"] # Application definition