NEW API :
* /api2/wgEdit?id=<USER ID>&state=<ENABLED/DISABLED>
This commit is contained in:
parent
98cf19b7ab
commit
24cb941f94
1
.gitignore
vendored
1
.gitignore
vendored
@ -1 +1,2 @@
|
||||
*.swp
|
||||
/inf-env/
|
||||
|
BIN
wg_api/.views.py.swo
Normal file
BIN
wg_api/.views.py.swo
Normal file
Binary file not shown.
BIN
wg_api/__pycache__/__init__.cpython-311.pyc
Normal file
BIN
wg_api/__pycache__/__init__.cpython-311.pyc
Normal file
Binary file not shown.
BIN
wg_api/__pycache__/admin.cpython-311.pyc
Normal file
BIN
wg_api/__pycache__/admin.cpython-311.pyc
Normal file
Binary file not shown.
BIN
wg_api/__pycache__/apps.cpython-311.pyc
Normal file
BIN
wg_api/__pycache__/apps.cpython-311.pyc
Normal file
Binary file not shown.
BIN
wg_api/__pycache__/models.cpython-311.pyc
Normal file
BIN
wg_api/__pycache__/models.cpython-311.pyc
Normal file
Binary file not shown.
BIN
wg_api/__pycache__/serializers.cpython-311.pyc
Normal file
BIN
wg_api/__pycache__/serializers.cpython-311.pyc
Normal file
Binary file not shown.
BIN
wg_api/__pycache__/views.cpython-311.pyc
Normal file
BIN
wg_api/__pycache__/views.cpython-311.pyc
Normal file
Binary file not shown.
BIN
wg_api/migrations/__pycache__/0001_initial.cpython-311.pyc
Normal file
BIN
wg_api/migrations/__pycache__/0001_initial.cpython-311.pyc
Normal file
Binary file not shown.
BIN
wg_api/migrations/__pycache__/__init__.cpython-311.pyc
Normal file
BIN
wg_api/migrations/__pycache__/__init__.cpython-311.pyc
Normal file
Binary file not shown.
BIN
wg_api/utils/__pycache__/html_parser.cpython-311.pyc
Normal file
BIN
wg_api/utils/__pycache__/html_parser.cpython-311.pyc
Normal file
Binary file not shown.
BIN
wg_api/utils/__pycache__/reqs_handler.cpython-311.pyc
Normal file
BIN
wg_api/utils/__pycache__/reqs_handler.cpython-311.pyc
Normal file
Binary file not shown.
BIN
wg_api/utils/__pycache__/statistics.cpython-311.pyc
Normal file
BIN
wg_api/utils/__pycache__/statistics.cpython-311.pyc
Normal file
Binary file not shown.
@ -151,6 +151,7 @@ def get_profiles():
|
||||
current_data["data_id"]=i
|
||||
final_data.append(current_data)
|
||||
i = i + 1
|
||||
|
||||
final_data = json.dumps(final_data)
|
||||
# print(final_data)
|
||||
|
||||
|
29
wg_api/utils/reqs_handler.py
Normal file
29
wg_api/utils/reqs_handler.py
Normal file
@ -0,0 +1,29 @@
|
||||
import json
|
||||
import requests
|
||||
|
||||
def get_session():
|
||||
login_data = {'username':"admin","password":"admin"}
|
||||
inf_s = requests.Session()
|
||||
inf_s.post('http://10.30.1.138:5000/login', login_data)
|
||||
|
||||
return inf_s
|
||||
|
||||
def req_edit_state(id, state):
|
||||
inf_s = get_session()
|
||||
|
||||
if state == "false":
|
||||
state = False
|
||||
|
||||
if state == "true":
|
||||
state = True
|
||||
|
||||
req_val = {"id":id,"status":state}
|
||||
req_val = json.dumps(req_val)
|
||||
|
||||
print("Req Val --> ", req_val)
|
||||
|
||||
req = inf_s.post('http://10.30.1.138:5000/client/set-status', req_val)
|
||||
|
||||
print(req)
|
||||
|
||||
|
162
wg_api/views.py
162
wg_api/views.py
@ -8,6 +8,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
|
||||
|
||||
# Create your views here.
|
||||
class wgView(viewsets.ModelViewSet):
|
||||
@ -127,48 +128,145 @@ def wgViewClients(request):
|
||||
|
||||
final_data = []
|
||||
|
||||
if filter :
|
||||
print("x"*100)
|
||||
i = 1
|
||||
for x in data:
|
||||
if str(filter).lower() in str(x["name"]).lower():
|
||||
print(x["data_id"])
|
||||
x["data_id"]=i
|
||||
print(x["data_id"])
|
||||
final_data.append(x)
|
||||
i = i+1
|
||||
final_data = json.dumps(final_data)
|
||||
|
||||
if filter :
|
||||
|
||||
elif param == "stats":
|
||||
data_logs = get_logs()
|
||||
data = json.loads(data_logs)
|
||||
filter = str(filter).split(" ")
|
||||
|
||||
sum_data = count_clients(data)
|
||||
connected_data = count_connection(data)
|
||||
traffic_data = len(data)
|
||||
for x in filter:
|
||||
print("-> ",x)
|
||||
|
||||
percentage_data = count_percentage(data)
|
||||
broken_data = count_broken(data)
|
||||
final_data = data
|
||||
|
||||
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
|
||||
|
||||
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"
|
||||
final_data = data
|
||||
|
||||
data = {}
|
||||
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)
|
||||
|
||||
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)
|
||||
else :
|
||||
final_data = json.dumps(data)
|
||||
|
||||
# print(request.GET.get('param', ''))
|
||||
|
||||
return HttpResponse(final_data, content_type='application')
|
||||
|
||||
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')
|
||||
|
||||
|
||||
|
BIN
wgweb/__pycache__/__init__.cpython-311.pyc
Normal file
BIN
wgweb/__pycache__/__init__.cpython-311.pyc
Normal file
Binary file not shown.
BIN
wgweb/__pycache__/settings.cpython-311.pyc
Normal file
BIN
wgweb/__pycache__/settings.cpython-311.pyc
Normal file
Binary file not shown.
BIN
wgweb/__pycache__/urls.cpython-311.pyc
Normal file
BIN
wgweb/__pycache__/urls.cpython-311.pyc
Normal file
Binary file not shown.
BIN
wgweb/__pycache__/wsgi.cpython-311.pyc
Normal file
BIN
wgweb/__pycache__/wsgi.cpython-311.pyc
Normal file
Binary file not shown.
@ -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"]
|
||||
ALLOWED_HOSTS = ["192.168.10.2", "127.0.0.1", "localhost:8000", "localhost:5000"]
|
||||
|
||||
|
||||
# Application definition
|
||||
|
@ -25,5 +25,6 @@ urlpatterns = [
|
||||
path('admin/', admin.site.urls),
|
||||
path('api/', include(router.urls)),
|
||||
path('api2/wgLogs', views.wgViewLogs),
|
||||
path('api2/wgClients', views.wgViewClients)
|
||||
path('api2/wgClients', views.wgViewClients),
|
||||
path('api2/wgEdit', views.wgEditClients)
|
||||
]
|
||||
|
Loading…
Reference in New Issue
Block a user