2022-11-22 02:07:36 -05:00
|
|
|
from django.shortcuts import render
|
|
|
|
from django.http import HttpResponse
|
|
|
|
# from django.core import serializer
|
|
|
|
from rest_framework import viewsets
|
|
|
|
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
|
2022-11-24 05:11:55 -05:00
|
|
|
from .utils.reqs_handler import req_edit_state
|
2022-11-22 02:07:36 -05:00
|
|
|
|
|
|
|
# Create your views here.
|
|
|
|
class wgView(viewsets.ModelViewSet):
|
|
|
|
|
|
|
|
# queryset = user_model.objects.all()
|
|
|
|
queryset = user_model.objects.all()
|
|
|
|
serializer_class = wgSerializer
|
|
|
|
|
|
|
|
# print(">"*100," ",inf_data)
|
|
|
|
|
|
|
|
def get(self, request):
|
|
|
|
return self.inf_connector()
|
|
|
|
# iserializer = wgSerializer
|
|
|
|
# queryset = user_model.objects.all()
|
|
|
|
# serializers_class = wgSerializer
|
|
|
|
# serializer = wgSerializer
|
|
|
|
# permission_classes = [IsAdminUser]
|
|
|
|
|
|
|
|
def wgViewLogs(request):
|
|
|
|
|
|
|
|
param = request.GET.get('param', '')
|
|
|
|
|
|
|
|
data = get_logs()
|
|
|
|
data = json.loads(data)
|
|
|
|
|
|
|
|
final_data = []
|
|
|
|
|
|
|
|
|
|
|
|
if param == "d2201":
|
|
|
|
print("x"*100)
|
|
|
|
i = 1
|
|
|
|
for x in data:
|
|
|
|
if "DTS22_PNUP_01" in str(x["wgName"]):
|
|
|
|
print(x)
|
|
|
|
x["data_id"]=i
|
|
|
|
final_data.append(x)
|
|
|
|
i = i+1
|
|
|
|
elif param == "d2202":
|
|
|
|
print("x"*100)
|
|
|
|
i = 1
|
|
|
|
for x in data:
|
|
|
|
if "DTS22_PNUP_02" in str(x["wgName"]):
|
|
|
|
print(x)
|
|
|
|
x["data_id"]=i
|
|
|
|
final_data.append(x)
|
|
|
|
i = i+1
|
|
|
|
elif param == "d2203":
|
|
|
|
print("x"*100)
|
|
|
|
i = 1
|
|
|
|
for x in data:
|
|
|
|
if "DTS22_PNUP_03" in str(x["wgName"]):
|
|
|
|
print(x)
|
|
|
|
x["data_id"]=i
|
|
|
|
final_data.append(x)
|
|
|
|
i = i+1
|
|
|
|
elif param == "d2204":
|
|
|
|
print("x"*100)
|
|
|
|
i = 1
|
|
|
|
for x in data:
|
|
|
|
if "DTS22_PNUP_04" in str(x["wgName"]):
|
|
|
|
print(x)
|
|
|
|
x["data_id"]=i
|
|
|
|
final_data.append(x)
|
|
|
|
i = i+1
|
|
|
|
elif param == "d2205":
|
|
|
|
print("x"*100)
|
|
|
|
i = 1
|
|
|
|
for x in data:
|
|
|
|
if "DTS22_PNUP_05" in str(x["wgName"]):
|
|
|
|
print(x)
|
|
|
|
x["data_id"]=i
|
|
|
|
final_data.append(x)
|
|
|
|
i = i+1
|
|
|
|
elif param == "d2206":
|
|
|
|
print("x"*100)
|
|
|
|
i = 1
|
|
|
|
for x in data:
|
|
|
|
if "DTS22_TELU" in str(x["wgName"]):
|
|
|
|
print(x)
|
|
|
|
x["data_id"]=i
|
|
|
|
final_data.append(x)
|
|
|
|
i = i+1
|
|
|
|
elif param == "GCI":
|
|
|
|
print("x"*100)
|
|
|
|
i = 1
|
|
|
|
for x in data:
|
|
|
|
if "GCI" in str(x["wgName"]):
|
|
|
|
x["data_id"]=i
|
|
|
|
print(x)
|
|
|
|
final_data.append(x)
|
|
|
|
i = i+1
|
|
|
|
elif param == "META":
|
|
|
|
print("x"*100)
|
|
|
|
i = 1
|
|
|
|
for x in data:
|
|
|
|
if "NIS" in str(x["wgName"]):
|
|
|
|
print(x["data_id"])
|
|
|
|
x["data_id"]=i
|
|
|
|
print(x["data_id"])
|
|
|
|
final_data.append(x)
|
|
|
|
i = i+1
|
|
|
|
else:
|
|
|
|
final_data = data
|
|
|
|
|
|
|
|
final_data = json.dumps(final_data)
|
|
|
|
|
|
|
|
return HttpResponse(final_data, content_type='application')
|
|
|
|
|
|
|
|
def wgViewClients(request):
|
|
|
|
|
|
|
|
param = request.GET.get('param', '')
|
|
|
|
filter = request.GET.get('filter', '')
|
|
|
|
|
|
|
|
data = get_profiles()
|
|
|
|
data = json.loads(data)
|
|
|
|
|
|
|
|
|
|
|
|
final_data = []
|
|
|
|
|
2022-11-24 05:11:55 -05:00
|
|
|
if filter :
|
2022-11-22 02:07:36 -05:00
|
|
|
|
2022-11-24 05:11:55 -05:00
|
|
|
filter = str(filter).split(" ")
|
2022-11-22 02:07:36 -05:00
|
|
|
|
2022-11-24 05:11:55 -05:00
|
|
|
for x in filter:
|
|
|
|
print("-> ",x)
|
|
|
|
|
|
|
|
final_data = data
|
2022-11-22 02:07:36 -05:00
|
|
|
|
2022-11-24 05:11:55 -05:00
|
|
|
if not (filter[0] == "" and filter[1] == "undefined" and filter[2] == "undefined"):
|
|
|
|
if filter[0] != "":
|
|
|
|
f_name = filter[0]
|
|
|
|
i = 0
|
|
|
|
tmp_data = []
|
|
|
|
for x in final_data:
|
|
|
|
if str(f_name).lower() in str(x["name"]).lower():
|
|
|
|
x["data_id"]=i
|
|
|
|
tmp_data.append(x)
|
|
|
|
i = i+1
|
|
|
|
final_data = tmp_data
|
|
|
|
|
|
|
|
if filter[1] != "undefined":
|
|
|
|
f_orgs = filter[1]
|
|
|
|
i = 0
|
|
|
|
tmp_data = []
|
|
|
|
for x in final_data:
|
|
|
|
if str(f_orgs).lower() in str(x["name"]).lower():
|
|
|
|
x["data_id"]=i
|
|
|
|
tmp_data.append(x)
|
|
|
|
i = i+1
|
|
|
|
final_data = tmp_data
|
|
|
|
|
|
|
|
if filter[2] != "undefined":
|
|
|
|
i = 0
|
|
|
|
f_email = filter[2]
|
|
|
|
tmp_data = []
|
|
|
|
|
|
|
|
if f_email == "" :
|
|
|
|
print("Empty mails...")
|
|
|
|
for x in final_data:
|
|
|
|
if str(x["email"]).lower() == "":
|
|
|
|
x["data_id"]=i
|
|
|
|
tmp_data.append(x)
|
|
|
|
i = i+1
|
|
|
|
else:
|
|
|
|
for x in final_data:
|
|
|
|
if str(f_email).lower() in str(x["email"]).lower():
|
|
|
|
x["data_id"]=i
|
|
|
|
tmp_data.append(x)
|
|
|
|
i = i+1
|
|
|
|
|
|
|
|
final_data = tmp_data
|
2022-11-22 02:07:36 -05:00
|
|
|
|
|
|
|
else:
|
2022-11-24 05:11:55 -05:00
|
|
|
final_data = data
|
2022-11-22 02:07:36 -05:00
|
|
|
|
2022-11-24 05:11:55 -05:00
|
|
|
final_data = json.dumps(final_data)
|
|
|
|
|
|
|
|
elif len(param)>0:
|
|
|
|
|
|
|
|
if param == "email":
|
|
|
|
groups = []
|
|
|
|
for x in data:
|
|
|
|
if str("@").lower() in str(x["email"]).lower():
|
|
|
|
tmp_val = x["email"]
|
|
|
|
tmp_val = str(tmp_val).split("@")[1]
|
|
|
|
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 param == "orgs":
|
|
|
|
|
|
|
|
groups = []
|
|
|
|
for x in data:
|
|
|
|
if str("-").lower() in str(x["name"]).lower():
|
|
|
|
tmp_val = x["name"]
|
|
|
|
tmp_val = str(tmp_val).split("-")[0]
|
|
|
|
tmp_val = tmp_val.upper()
|
|
|
|
|
|
|
|
if {"orgs": tmp_val} not in groups:
|
|
|
|
print("-> ",tmp_val)
|
|
|
|
groups.append({"orgs": tmp_val})
|
|
|
|
|
|
|
|
final_data = json.dumps(groups)
|
|
|
|
|
|
|
|
if param == "stats":
|
|
|
|
data_logs = get_logs()
|
|
|
|
data = json.loads(data_logs)
|
|
|
|
|
|
|
|
sum_data = count_clients(data)
|
|
|
|
connected_data = count_connection(data)
|
|
|
|
traffic_data = len(data)
|
|
|
|
|
|
|
|
percentage_data = count_percentage(data)
|
|
|
|
broken_data = count_broken(data)
|
|
|
|
|
|
|
|
traffic_data = count_traffic(data)
|
|
|
|
if traffic_data > 1000000000:
|
|
|
|
traffic_data="{:.2f}".format(traffic_data/1000000000)+" GB"
|
|
|
|
else:
|
|
|
|
traffic_data="{:.2f}".format(traffic_data/1000000)+" MB"
|
|
|
|
|
|
|
|
data = {}
|
|
|
|
|
|
|
|
data["clienttotal"]=sum_data
|
|
|
|
data["traffictotal"]=traffic_data
|
|
|
|
data["connectedtotal"]=connected_data
|
|
|
|
data["percentagetotal"]=percentage_data
|
|
|
|
data["brokentotal"]=broken_data
|
|
|
|
|
|
|
|
final_data = json.dumps(data)
|
2022-11-22 02:07:36 -05:00
|
|
|
|
|
|
|
else :
|
|
|
|
final_data = json.dumps(data)
|
|
|
|
|
|
|
|
# print(request.GET.get('param', ''))
|
|
|
|
|
|
|
|
return HttpResponse(final_data, content_type='application')
|
2022-11-24 05:11:55 -05:00
|
|
|
|
|
|
|
def wgEditClients(request):
|
|
|
|
|
|
|
|
id = request.GET.get('id', '')
|
|
|
|
state = request.GET.get('state', '')
|
|
|
|
|
|
|
|
print("Edit Request")
|
|
|
|
|
|
|
|
if state and id:
|
|
|
|
print("[ Edit ]=======")
|
|
|
|
print(id)
|
|
|
|
print(state)
|
|
|
|
|
|
|
|
req_edit_state(id, state)
|
|
|
|
|
|
|
|
|
|
|
|
final_data = json.dumps({"state":"Success"})
|
|
|
|
|
|
|
|
return HttpResponse(final_data, content_type='application')
|
|
|
|
|
|
|
|
|