Agile deployment method with docker

This commit is contained in:
infidel 2022-12-17 01:45:33 +07:00
parent 59671130cb
commit 5d5357c57f
11 changed files with 53 additions and 7 deletions

21
Readme.md Normal file
View File

@ -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.
- [ ]

View File

@ -82,3 +82,29 @@ def req_ip_recommendation():
print(req_dump) print(req_dump)
return json.dumps(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}' )

View File

@ -15,7 +15,7 @@ from .models import user_model
from .utils.html_parser import get_logs, get_profiles from .utils.html_parser import get_logs, get_profiles
import json import json
from .utils.statistics import count_clients, count_traffic, count_connection, count_percentage, count_broken 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.middleware.csrf import get_token
from django.views.decorators.csrf import csrf_exempt from django.views.decorators.csrf import csrf_exempt
@ -26,8 +26,7 @@ class wgLogin(APIView):
def get(self, request, format=None): def get(self, request, format=None):
# serializer = self.get_serializer(data=request.data) # serializer = self.get_serializer(data=request.data)
# serializer.is_valid(raise_exception=True) # serializer.is_valid(raise_exception=True) user = serializer.validated_data['user']
# user = serializer.validated_data['user']
user = request.GET.get('username') user = request.GET.get('username')
password = request.GET.get('password') password = request.GET.get('password')
@ -514,7 +513,7 @@ def wgBulkReg(request):
print("-> Bulk Registration") print("-> Bulk Registration")
RegData = json.loads(request.body) RegData = json.loads(request.body)
for x in RegData: req_ip = req_ip_recommendation()
print(x) req_commit = reg_bulk(RegData)
return HttpResponse({"success"}, content_type='application') return HttpResponse(json.dumps({"Reg":"Success"}), content_type='application')

View File

@ -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! # SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True 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 # Application definition