NEW API :

* /api2/wgEdit?id=<USER ID>&state=<ENABLED/DISABLED>
This commit is contained in:
infidel 2022-11-24 17:11:55 +07:00
parent 98cf19b7ab
commit 24cb941f94
22 changed files with 164 additions and 34 deletions

1
.gitignore vendored
View File

@ -1 +1,2 @@
*.swp *.swp
/inf-env/

BIN
wg_api/.views.py.swo Normal file

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.

Binary file not shown.

View File

@ -151,6 +151,7 @@ def get_profiles():
current_data["data_id"]=i current_data["data_id"]=i
final_data.append(current_data) final_data.append(current_data)
i = i + 1 i = i + 1
final_data = json.dumps(final_data) final_data = json.dumps(final_data)
# print(final_data) # print(final_data)

View 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)

View File

@ -8,6 +8,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
# Create your views here. # Create your views here.
class wgView(viewsets.ModelViewSet): class wgView(viewsets.ModelViewSet):
@ -128,19 +129,94 @@ def wgViewClients(request):
final_data = [] final_data = []
if filter : if filter :
print("x"*100)
i = 1 filter = str(filter).split(" ")
for x in data:
if str(filter).lower() in str(x["name"]).lower(): for x in filter:
print(x["data_id"]) print("-> ",x)
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 x["data_id"]=i
print(x["data_id"]) tmp_data.append(x)
final_data.append(x)
i = i+1 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
else:
final_data = data
final_data = json.dumps(final_data) final_data = json.dumps(final_data)
elif len(param)>0:
elif param == "stats": 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_logs = get_logs()
data = json.loads(data_logs) data = json.loads(data_logs)
@ -166,9 +242,31 @@ def wgViewClients(request):
data["brokentotal"]=broken_data data["brokentotal"]=broken_data
final_data = json.dumps(data) final_data = json.dumps(data)
else : else :
final_data = json.dumps(data) final_data = json.dumps(data)
# print(request.GET.get('param', '')) # print(request.GET.get('param', ''))
return HttpResponse(final_data, content_type='application') 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')

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

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"] ALLOWED_HOSTS = ["192.168.10.2", "127.0.0.1", "localhost:8000", "localhost:5000"]
# Application definition # Application definition

View File

@ -25,5 +25,6 @@ urlpatterns = [
path('admin/', admin.site.urls), path('admin/', admin.site.urls),
path('api/', include(router.urls)), path('api/', include(router.urls)),
path('api2/wgLogs', views.wgViewLogs), path('api2/wgLogs', views.wgViewLogs),
path('api2/wgClients', views.wgViewClients) path('api2/wgClients', views.wgViewClients),
path('api2/wgEdit', views.wgEditClients)
] ]