Added login api
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
wg_api/utils/__pycache__/reqs_handler.cpython-310.pyc
Normal file
BIN
wg_api/utils/__pycache__/reqs_handler.cpython-310.pyc
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -26,4 +26,21 @@ def req_edit_state(id, state):
|
||||
|
||||
print(req)
|
||||
|
||||
|
||||
def req_edit_user(id):
|
||||
inf_s = get_session()
|
||||
|
||||
req_val = id
|
||||
|
||||
req_url = 'http://10.30.1.138:5000/api/client/'+req_val
|
||||
|
||||
req = inf_s.get(req_url)
|
||||
|
||||
print("-->")
|
||||
print(req)
|
||||
|
||||
# req = json.loads(req)
|
||||
|
||||
return req.json()
|
||||
|
||||
#
|
||||
# http://10.30.1.138:5000/api/client/caivc1vekn84im2m6ec0?_=1669623393468
|
||||
|
||||
103
wg_api/views.py
103
wg_api/views.py
@@ -2,13 +2,30 @@ from django.shortcuts import render
|
||||
from django.http import HttpResponse
|
||||
# from django.core import serializer
|
||||
from rest_framework import viewsets
|
||||
from rest_framework.views import APIView
|
||||
from rest_framework.authentication import SessionAuthentication, BasicAuthentication
|
||||
from rest_framework.permissions import IsAuthenticated
|
||||
from rest_framework.response import Response
|
||||
from rest_framework.permissions import IsAdminUser
|
||||
from .serializers import wgSerializer
|
||||
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
|
||||
from .utils.reqs_handler import req_edit_state, req_edit_user
|
||||
from django.middleware.csrf import get_token
|
||||
from django.views.decorators.csrf import csrf_exempt
|
||||
|
||||
class wgLogin(APIView):
|
||||
authentication_classes = [SessionAuthentication, BasicAuthentication]
|
||||
permission_classes = [IsAuthenticated]
|
||||
|
||||
def get(self, request, format=None):
|
||||
content = {
|
||||
'user': str(request.user), # `django.contrib.auth.User` instance.
|
||||
'auth': str(request.auth), # None
|
||||
}
|
||||
return Response(content)
|
||||
|
||||
# Create your views here.
|
||||
class wgView(viewsets.ModelViewSet):
|
||||
@@ -129,15 +146,11 @@ def wgViewClients(request):
|
||||
final_data = []
|
||||
|
||||
if filter :
|
||||
|
||||
filter = str(filter).split(" ")
|
||||
|
||||
for x in filter:
|
||||
print("-> ",x)
|
||||
|
||||
final_data = data
|
||||
|
||||
if not (filter[0] == "" and filter[1] == "undefined" and filter[2] == "undefined"):
|
||||
if not (filter[0] == "" and filter[1] == "undefined" and filter[2] == "undefined" and filter[3] == "undefined"):
|
||||
if filter[0] != "":
|
||||
f_name = filter[0]
|
||||
i = 0
|
||||
@@ -181,6 +194,27 @@ def wgViewClients(request):
|
||||
|
||||
final_data = tmp_data
|
||||
|
||||
if filter[3] != "undefined":
|
||||
i = 0
|
||||
f_state = filter[3]
|
||||
tmp_data = []
|
||||
|
||||
if f_state == "" :
|
||||
print("Empty State...")
|
||||
for x in final_data:
|
||||
if str(x["enabled"]).lower() == "":
|
||||
x["data_id"]=i
|
||||
tmp_data.append(x)
|
||||
i = i+1
|
||||
else:
|
||||
for x in final_data:
|
||||
if str(f_state).lower() in str(x["enabled"]).lower():
|
||||
x["data_id"]=i
|
||||
tmp_data.append(x)
|
||||
i = i+1
|
||||
|
||||
final_data = tmp_data
|
||||
|
||||
else:
|
||||
final_data = data
|
||||
|
||||
@@ -196,13 +230,12 @@ def wgViewClients(request):
|
||||
tmp_val = str(tmp_val).split("@")[1]
|
||||
tmp_val = tmp_val.lower()
|
||||
if {"email": tmp_val} not in groups:
|
||||
print("-> ",tmp_val)
|
||||
# print("-> ",tmp_val)
|
||||
groups.append({"email": tmp_val})
|
||||
|
||||
final_data = json.dumps(groups)
|
||||
|
||||
if param == "orgs":
|
||||
|
||||
groups = []
|
||||
for x in data:
|
||||
if str("-").lower() in str(x["name"]).lower():
|
||||
@@ -211,7 +244,7 @@ def wgViewClients(request):
|
||||
tmp_val = tmp_val.upper()
|
||||
|
||||
if {"orgs": tmp_val} not in groups:
|
||||
print("-> ",tmp_val)
|
||||
# print("-> ",tmp_val)
|
||||
groups.append({"orgs": tmp_val})
|
||||
|
||||
final_data = json.dumps(groups)
|
||||
@@ -250,23 +283,59 @@ def wgViewClients(request):
|
||||
|
||||
return HttpResponse(final_data, content_type='application')
|
||||
|
||||
def wgEditClients(request):
|
||||
def get_EditState(request):
|
||||
|
||||
id = request.GET.get('id', '')
|
||||
state = request.GET.get('state', '')
|
||||
|
||||
print("Edit Request")
|
||||
print("Edit Request...")
|
||||
|
||||
if state and id:
|
||||
print("[ Edit ]=======")
|
||||
print(id)
|
||||
print(state)
|
||||
|
||||
req_edit_state(id, state)
|
||||
if id != "bulk":
|
||||
print("[ Edit ]=======")
|
||||
print(id)
|
||||
print(state)
|
||||
|
||||
req_edit_state(id, state)
|
||||
else:
|
||||
print(id)
|
||||
|
||||
final_data = json.dumps({"state":"Success"})
|
||||
|
||||
return HttpResponse(final_data, content_type='application')
|
||||
|
||||
# def get_Cookie(request):
|
||||
#
|
||||
# return get_token()
|
||||
|
||||
# @csrf_exempt
|
||||
def get_EditClient(request):
|
||||
|
||||
my_token = get_token()
|
||||
|
||||
print("TOKEN ...")
|
||||
print(my_token)
|
||||
|
||||
id = request.GET.get('id', '')
|
||||
|
||||
if request.method == "POST":
|
||||
print(request)
|
||||
|
||||
if id:
|
||||
print(id)
|
||||
ret_val = req_edit_user(id)
|
||||
|
||||
|
||||
else:
|
||||
ret_val = {"data": "Failed"}
|
||||
|
||||
# ret_val = json.dumps(ret_val)
|
||||
|
||||
ret_val = ret_val["Client"]
|
||||
|
||||
ret_val = json.dumps(ret_val)
|
||||
|
||||
|
||||
return HttpResponse(ret_val, content_type='application')
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user