CSV Parser added, interactive table with bind utilization
This commit is contained in:
parent
caaedfa003
commit
59671130cb
BIN
db.sqlite3
BIN
db.sqlite3
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -54,3 +54,31 @@ def req_apply_sys():
|
|||||||
|
|
||||||
#
|
#
|
||||||
# http://10.30.1.138:5000/api/client/caivc1vekn84im2m6ec0?_=1669623393468
|
# http://10.30.1.138:5000/api/client/caivc1vekn84im2m6ec0?_=1669623393468
|
||||||
|
|
||||||
|
def req_ip_recommendation():
|
||||||
|
# Write your own ip recommendation next time
|
||||||
|
# http://10.30.1.138:5000/api/suggest-client-ips
|
||||||
|
|
||||||
|
inf_s = get_session()
|
||||||
|
req_url = 'http://10.30.1.138:5000/api/suggest-client-ips'
|
||||||
|
|
||||||
|
req = inf_s.get(req_url)
|
||||||
|
req = req.json()
|
||||||
|
|
||||||
|
req_dump = {}
|
||||||
|
req_dump["allocated_ips"] = {}
|
||||||
|
req_dump["allowed_ips"] = {"OAM":"10.30.1.0/24", "NEW_OAM":"192.168.200.0/24", "WG Nodes":"192.168.100.0/24"}
|
||||||
|
|
||||||
|
i = 0
|
||||||
|
|
||||||
|
tmp_array = []
|
||||||
|
for x in req:
|
||||||
|
print(x)
|
||||||
|
tmp_array.append(x)
|
||||||
|
i = i+1
|
||||||
|
|
||||||
|
req_dump["allocated_ips"] = tmp_array
|
||||||
|
print(req)
|
||||||
|
print(req_dump)
|
||||||
|
|
||||||
|
return json.dumps(req_dump)
|
||||||
|
182
wg_api/views.py
182
wg_api/views.py
@ -1,18 +1,21 @@
|
|||||||
from django.shortcuts import render
|
from django.shortcuts import render
|
||||||
from django.http import HttpResponse
|
from django.http import HttpResponse
|
||||||
|
from django.contrib.auth import authenticate
|
||||||
# from django.core import serializer
|
# from django.core import serializer
|
||||||
from rest_framework import viewsets
|
from rest_framework import viewsets
|
||||||
|
from rest_framework.decorators import api_view, permission_classes
|
||||||
from rest_framework.views import APIView
|
from rest_framework.views import APIView
|
||||||
from rest_framework.authentication import SessionAuthentication, BasicAuthentication
|
from rest_framework.authentication import SessionAuthentication, BasicAuthentication
|
||||||
from rest_framework.permissions import IsAuthenticated
|
from rest_framework.permissions import IsAuthenticated
|
||||||
from rest_framework.response import Response
|
from rest_framework.response import Response
|
||||||
|
from rest_framework.authtoken.models import Token
|
||||||
from rest_framework.permissions import IsAdminUser
|
from rest_framework.permissions import IsAdminUser
|
||||||
from .serializers import wgSerializer
|
from .serializers import wgSerializer
|
||||||
from .models import user_model
|
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
|
from .utils.reqs_handler import req_edit_state, req_edit_user, req_apply_sys, req_ip_recommendation
|
||||||
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
|
||||||
|
|
||||||
@ -21,11 +24,40 @@ class wgLogin(APIView):
|
|||||||
permission_classes = [IsAuthenticated]
|
permission_classes = [IsAuthenticated]
|
||||||
|
|
||||||
def get(self, request, format=None):
|
def get(self, request, format=None):
|
||||||
|
|
||||||
|
# serializer = self.get_serializer(data=request.data)
|
||||||
|
# serializer.is_valid(raise_exception=True)
|
||||||
|
# user = serializer.validated_data['user']
|
||||||
|
user = request.GET.get('username')
|
||||||
|
password = request.GET.get('password')
|
||||||
|
|
||||||
content = {
|
content = {
|
||||||
'user': str(request.user), # `django.contrib.auth.User` instance.
|
'user': str(request.user), # `django.contrib.auth.User` instance.
|
||||||
'auth': str(request.auth), # None
|
'auth': str(request.auth), # None
|
||||||
}
|
}
|
||||||
return Response(content)
|
|
||||||
|
# user = content['user']
|
||||||
|
print(request.META['HTTP_AUTHORIZATION'])
|
||||||
|
|
||||||
|
print(user)
|
||||||
|
print(password)
|
||||||
|
|
||||||
|
user = authenticate(username=user, password=password)
|
||||||
|
|
||||||
|
print("****-> ",user.id)
|
||||||
|
|
||||||
|
token, _ = Token.objects.get_or_create(user=user)
|
||||||
|
|
||||||
|
response = Response(content)
|
||||||
|
|
||||||
|
response.set_cookie('Token', token.key)
|
||||||
|
|
||||||
|
# print(response)
|
||||||
|
|
||||||
|
return response
|
||||||
|
# return response
|
||||||
|
|
||||||
|
# return Response(content)
|
||||||
|
|
||||||
# Create your views here.
|
# Create your views here.
|
||||||
class wgView(viewsets.ModelViewSet):
|
class wgView(viewsets.ModelViewSet):
|
||||||
@ -44,6 +76,16 @@ class wgView(viewsets.ModelViewSet):
|
|||||||
# serializer = wgSerializer
|
# serializer = wgSerializer
|
||||||
# permission_classes = [IsAdminUser]
|
# permission_classes = [IsAdminUser]
|
||||||
|
|
||||||
|
@csrf_exempt
|
||||||
|
@api_view(["GET"])
|
||||||
|
@permission_classes([IsAuthenticated])
|
||||||
|
def wgCheckAuth(request):
|
||||||
|
|
||||||
|
return HttpResponse(json.dumps({"Auth":True}))
|
||||||
|
|
||||||
|
@csrf_exempt
|
||||||
|
@api_view(["GET"])
|
||||||
|
@permission_classes([IsAuthenticated])
|
||||||
def wgViewLogs(request):
|
def wgViewLogs(request):
|
||||||
|
|
||||||
param = request.GET.get('param', '')
|
param = request.GET.get('param', '')
|
||||||
@ -134,6 +176,9 @@ def wgViewLogs(request):
|
|||||||
|
|
||||||
return HttpResponse(final_data, content_type='application')
|
return HttpResponse(final_data, content_type='application')
|
||||||
|
|
||||||
|
@csrf_exempt
|
||||||
|
@api_view(["GET"])
|
||||||
|
@permission_classes([IsAuthenticated])
|
||||||
def wgViewClients(request):
|
def wgViewClients(request):
|
||||||
|
|
||||||
param = request.GET.get('param', '')
|
param = request.GET.get('param', '')
|
||||||
@ -145,6 +190,7 @@ def wgViewClients(request):
|
|||||||
|
|
||||||
final_data = []
|
final_data = []
|
||||||
|
|
||||||
|
# if request.user.is_authenticated:
|
||||||
if filter :
|
if filter :
|
||||||
filter = str(filter).split(" ")
|
filter = str(filter).split(" ")
|
||||||
for x in filter:
|
for x in filter:
|
||||||
@ -229,11 +275,15 @@ def wgViewClients(request):
|
|||||||
tmp_val = x["email"]
|
tmp_val = x["email"]
|
||||||
tmp_val = str(tmp_val).split("@")[1]
|
tmp_val = str(tmp_val).split("@")[1]
|
||||||
tmp_val = tmp_val.lower()
|
tmp_val = tmp_val.lower()
|
||||||
if {"email": tmp_val} not in groups:
|
|
||||||
# print("-> ",tmp_val)
|
|
||||||
groups.append({"email": tmp_val})
|
|
||||||
|
|
||||||
final_data = json.dumps(groups)
|
if tmp_val not in groups:
|
||||||
|
groups.append(tmp_val)
|
||||||
|
|
||||||
|
# if {"email": tmp_val} not in groups:
|
||||||
|
# # print("-> ",tmp_val)
|
||||||
|
# groups.append({"email": tmp_val})
|
||||||
|
|
||||||
|
final_data = json.dumps({"email":groups})
|
||||||
|
|
||||||
if param == "orgs":
|
if param == "orgs":
|
||||||
groups = []
|
groups = []
|
||||||
@ -243,11 +293,14 @@ def wgViewClients(request):
|
|||||||
tmp_val = str(tmp_val).split("-")[0]
|
tmp_val = str(tmp_val).split("-")[0]
|
||||||
tmp_val = tmp_val.upper()
|
tmp_val = tmp_val.upper()
|
||||||
|
|
||||||
if {"orgs": tmp_val} not in groups:
|
if tmp_val not in groups:
|
||||||
# print("-> ",tmp_val)
|
groups.append(tmp_val)
|
||||||
groups.append({"orgs": tmp_val})
|
|
||||||
|
|
||||||
final_data = json.dumps(groups)
|
# if {"orgs": tmp_val} not in groups:
|
||||||
|
# # print("-> ",tmp_val)
|
||||||
|
# groups.append({"orgs": tmp_val})
|
||||||
|
|
||||||
|
final_data = json.dumps({"orgs": groups})
|
||||||
|
|
||||||
if param == "stats":
|
if param == "stats":
|
||||||
data_logs = get_logs()
|
data_logs = get_logs()
|
||||||
@ -278,11 +331,16 @@ def wgViewClients(request):
|
|||||||
|
|
||||||
else :
|
else :
|
||||||
final_data = json.dumps(data)
|
final_data = json.dumps(data)
|
||||||
|
# else:
|
||||||
|
# final_data = {"Not Logged In"}
|
||||||
|
|
||||||
# print(request.GET.get('param', ''))
|
# print(request.GET.get('param', ''))
|
||||||
|
|
||||||
return HttpResponse(final_data, content_type='application')
|
return HttpResponse(final_data, content_type='application')
|
||||||
|
|
||||||
|
@csrf_exempt
|
||||||
|
@api_view(["GET"])
|
||||||
|
@permission_classes([IsAuthenticated])
|
||||||
def get_ApplyConfig(request):
|
def get_ApplyConfig(request):
|
||||||
|
|
||||||
# id = request.GET.get('id', '')
|
# id = request.GET.get('id', '')
|
||||||
@ -293,6 +351,9 @@ def get_ApplyConfig(request):
|
|||||||
|
|
||||||
return HttpResponse(req_response)
|
return HttpResponse(req_response)
|
||||||
|
|
||||||
|
@csrf_exempt
|
||||||
|
@api_view(["GET", "POST"])
|
||||||
|
@permission_classes([IsAuthenticated])
|
||||||
def get_EditState(request):
|
def get_EditState(request):
|
||||||
|
|
||||||
id = request.GET.get('id', '')
|
id = request.GET.get('id', '')
|
||||||
@ -325,6 +386,9 @@ def get_EditState(request):
|
|||||||
# return get_token()
|
# return get_token()
|
||||||
|
|
||||||
# @csrf_exempt
|
# @csrf_exempt
|
||||||
|
@csrf_exempt
|
||||||
|
@api_view(["GET"])
|
||||||
|
@permission_classes([IsAuthenticated])
|
||||||
def get_EditClient(request):
|
def get_EditClient(request):
|
||||||
|
|
||||||
my_token = get_token()
|
my_token = get_token()
|
||||||
@ -354,5 +418,103 @@ def get_EditClient(request):
|
|||||||
|
|
||||||
return HttpResponse(ret_val, content_type='application')
|
return HttpResponse(ret_val, content_type='application')
|
||||||
|
|
||||||
|
@csrf_exempt
|
||||||
|
@api_view(["GET"])
|
||||||
|
@permission_classes([IsAuthenticated])
|
||||||
|
def get_user_param_recommendation(request):
|
||||||
|
|
||||||
|
ret_val = req_ip_recommendation()
|
||||||
|
|
||||||
|
return HttpResponse(ret_val, content_type='application')
|
||||||
|
|
||||||
|
@csrf_exempt
|
||||||
|
@api_view(["GET"])
|
||||||
|
@permission_classes([IsAuthenticated])
|
||||||
|
|
||||||
|
def wgFilterClients(request):
|
||||||
|
|
||||||
|
param = request.GET.get('param', '')
|
||||||
|
filter = request.GET.get('filter', '')
|
||||||
|
name = request.GET.get('names', '')
|
||||||
|
orgs = request.GET.get('orgs', '')
|
||||||
|
emails = request.GET.get('emails', '')
|
||||||
|
state = request.GET.get('state', '')
|
||||||
|
|
||||||
|
print("param ",param)
|
||||||
|
print("filter ",filter)
|
||||||
|
print("name ",name)
|
||||||
|
print("orgs ",orgs)
|
||||||
|
print("emails ",emails)
|
||||||
|
print("state ",state)
|
||||||
|
|
||||||
|
data = get_profiles()
|
||||||
|
data = json.loads(data)
|
||||||
|
|
||||||
|
final_data = []
|
||||||
|
|
||||||
|
if orgs:
|
||||||
|
orgs = str(orgs).split(", ")
|
||||||
|
tmp_data = []
|
||||||
|
for x in orgs:
|
||||||
|
print(x)
|
||||||
|
f_orgs = x
|
||||||
|
i = 0
|
||||||
|
for x in data:
|
||||||
|
if str(f_orgs).lower() in str(x["name"]).lower():
|
||||||
|
x["data_id"]=i
|
||||||
|
tmp_data.append(x)
|
||||||
|
i = i+1
|
||||||
|
|
||||||
|
print(tmp_data)
|
||||||
|
|
||||||
|
if len(final_data) < 1:
|
||||||
|
final_data = tmp_data
|
||||||
|
else:
|
||||||
|
for x in tmp_data:
|
||||||
|
final_data.append(x)
|
||||||
|
|
||||||
|
if emails:
|
||||||
|
emails = str(emails).split(", ")
|
||||||
|
tmp_data = []
|
||||||
|
for x in emails:
|
||||||
|
print(x)
|
||||||
|
f_emails = x
|
||||||
|
i = 0
|
||||||
|
for x in data:
|
||||||
|
if str(f_emails).lower() in str(x["email"]).lower():
|
||||||
|
x["data_id"]=i
|
||||||
|
tmp_data.append(x)
|
||||||
|
i = i+1
|
||||||
|
|
||||||
|
if len(final_data) < 1:
|
||||||
|
final_data = tmp_data
|
||||||
|
else:
|
||||||
|
for x in tmp_data:
|
||||||
|
final_data.append(x)
|
||||||
|
|
||||||
|
if not (orgs or filter or name or emails):
|
||||||
|
final_data = data
|
||||||
|
|
||||||
|
# SANITY Starts here -------------------------------
|
||||||
|
|
||||||
|
no_duplicate = []
|
||||||
|
for x in final_data:
|
||||||
|
if x not in no_duplicate:
|
||||||
|
no_duplicate.append(x)
|
||||||
|
|
||||||
|
ret_val = json.dumps(no_duplicate)
|
||||||
|
|
||||||
|
return HttpResponse(ret_val, content_type='application')
|
||||||
|
|
||||||
|
@csrf_exempt
|
||||||
|
@api_view(["POST"])
|
||||||
|
@permission_classes([IsAuthenticated])
|
||||||
|
def wgBulkReg(request):
|
||||||
|
|
||||||
|
print("-> Bulk Registration")
|
||||||
|
RegData = json.loads(request.body)
|
||||||
|
|
||||||
|
for x in RegData:
|
||||||
|
print(x)
|
||||||
|
|
||||||
|
return HttpResponse({"success"}, content_type='application')
|
||||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -39,6 +39,7 @@ INSTALLED_APPS = [
|
|||||||
'django.contrib.staticfiles',
|
'django.contrib.staticfiles',
|
||||||
'corsheaders',
|
'corsheaders',
|
||||||
'rest_framework',
|
'rest_framework',
|
||||||
|
'rest_framework.authtoken',
|
||||||
'wg_api'
|
'wg_api'
|
||||||
|
|
||||||
]
|
]
|
||||||
@ -65,6 +66,13 @@ CORS_ORIGIN_WHITELIST = [
|
|||||||
CSRF_TRUSTED_ORIGINS = ['https://wg.nnag.me']
|
CSRF_TRUSTED_ORIGINS = ['https://wg.nnag.me']
|
||||||
CSRF_COOKIE_SECURE = True
|
CSRF_COOKIE_SECURE = True
|
||||||
|
|
||||||
|
|
||||||
|
REST_FRAMEWORK = {
|
||||||
|
'DEFAULT_AUTHENTICATION_CLASSES': [
|
||||||
|
'rest_framework.authentication.TokenAuthentication', # <-- And here
|
||||||
|
],
|
||||||
|
}
|
||||||
|
|
||||||
ROOT_URLCONF = 'wgweb.urls'
|
ROOT_URLCONF = 'wgweb.urls'
|
||||||
|
|
||||||
TEMPLATES = [
|
TEMPLATES = [
|
||||||
@ -133,6 +141,8 @@ USE_TZ = True
|
|||||||
|
|
||||||
STATIC_URL = 'static/'
|
STATIC_URL = 'static/'
|
||||||
|
|
||||||
|
# LOGIN_REDIRECT_URL = '/admin/dashboard'
|
||||||
|
|
||||||
# Default primary key field type
|
# Default primary key field type
|
||||||
# https://docs.djangoproject.com/en/4.1/ref/settings/#default-auto-field
|
# https://docs.djangoproject.com/en/4.1/ref/settings/#default-auto-field
|
||||||
|
|
||||||
|
@ -26,7 +26,11 @@ urlpatterns = [
|
|||||||
path('api2/wgLogin', views.wgLogin.as_view()),
|
path('api2/wgLogin', views.wgLogin.as_view()),
|
||||||
path('api2/wgLogs', views.wgViewLogs),
|
path('api2/wgLogs', views.wgViewLogs),
|
||||||
path('api2/wgClients', views.wgViewClients),
|
path('api2/wgClients', views.wgViewClients),
|
||||||
|
path('api2/wgFilterClients', views.wgFilterClients),
|
||||||
path('api2/wgEditState', views.get_EditState),
|
path('api2/wgEditState', views.get_EditState),
|
||||||
path('api2/wgSysApply', views.get_ApplyConfig),
|
path('api2/wgSysApply', views.get_ApplyConfig),
|
||||||
|
path('api2/wgBulkReg', views.wgBulkReg),
|
||||||
|
path('api2/wgUserRecommendations', views.get_user_param_recommendation),
|
||||||
|
path('api2/wgCheckAuth', views.wgCheckAuth),
|
||||||
path('api2/wgEditClient', views.get_EditClient)
|
path('api2/wgEditClient', views.get_EditClient)
|
||||||
]
|
]
|
||||||
|
Loading…
Reference in New Issue
Block a user