diff --git a/.gitignore b/.gitignore index 1377554e..ca3ce43f 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ *.swp +/inf-env/ diff --git a/wg_api/.views.py.swo b/wg_api/.views.py.swo new file mode 100644 index 00000000..215bde65 Binary files /dev/null and b/wg_api/.views.py.swo differ diff --git a/wg_api/__pycache__/__init__.cpython-311.pyc b/wg_api/__pycache__/__init__.cpython-311.pyc new file mode 100644 index 00000000..b8666011 Binary files /dev/null and b/wg_api/__pycache__/__init__.cpython-311.pyc differ diff --git a/wg_api/__pycache__/admin.cpython-311.pyc b/wg_api/__pycache__/admin.cpython-311.pyc new file mode 100644 index 00000000..acd215b8 Binary files /dev/null and b/wg_api/__pycache__/admin.cpython-311.pyc differ diff --git a/wg_api/__pycache__/apps.cpython-311.pyc b/wg_api/__pycache__/apps.cpython-311.pyc new file mode 100644 index 00000000..d791aa90 Binary files /dev/null and b/wg_api/__pycache__/apps.cpython-311.pyc differ diff --git a/wg_api/__pycache__/models.cpython-311.pyc b/wg_api/__pycache__/models.cpython-311.pyc new file mode 100644 index 00000000..d1334259 Binary files /dev/null and b/wg_api/__pycache__/models.cpython-311.pyc differ diff --git a/wg_api/__pycache__/serializers.cpython-311.pyc b/wg_api/__pycache__/serializers.cpython-311.pyc new file mode 100644 index 00000000..36a98b31 Binary files /dev/null and b/wg_api/__pycache__/serializers.cpython-311.pyc differ diff --git a/wg_api/__pycache__/views.cpython-311.pyc b/wg_api/__pycache__/views.cpython-311.pyc new file mode 100644 index 00000000..6261f8c5 Binary files /dev/null and b/wg_api/__pycache__/views.cpython-311.pyc differ diff --git a/wg_api/migrations/__pycache__/0001_initial.cpython-311.pyc b/wg_api/migrations/__pycache__/0001_initial.cpython-311.pyc new file mode 100644 index 00000000..5c298dcd Binary files /dev/null and b/wg_api/migrations/__pycache__/0001_initial.cpython-311.pyc differ diff --git a/wg_api/migrations/__pycache__/__init__.cpython-311.pyc b/wg_api/migrations/__pycache__/__init__.cpython-311.pyc new file mode 100644 index 00000000..b9799ec0 Binary files /dev/null and b/wg_api/migrations/__pycache__/__init__.cpython-311.pyc differ diff --git a/wg_api/utils/__pycache__/html_parser.cpython-311.pyc b/wg_api/utils/__pycache__/html_parser.cpython-311.pyc new file mode 100644 index 00000000..99993a74 Binary files /dev/null and b/wg_api/utils/__pycache__/html_parser.cpython-311.pyc differ diff --git a/wg_api/utils/__pycache__/reqs_handler.cpython-311.pyc b/wg_api/utils/__pycache__/reqs_handler.cpython-311.pyc new file mode 100644 index 00000000..3c4bc1e6 Binary files /dev/null and b/wg_api/utils/__pycache__/reqs_handler.cpython-311.pyc differ diff --git a/wg_api/utils/__pycache__/statistics.cpython-311.pyc b/wg_api/utils/__pycache__/statistics.cpython-311.pyc new file mode 100644 index 00000000..8f229fe9 Binary files /dev/null and b/wg_api/utils/__pycache__/statistics.cpython-311.pyc differ diff --git a/wg_api/utils/html_parser.py b/wg_api/utils/html_parser.py index 6736cbf6..c8689a2e 100644 --- a/wg_api/utils/html_parser.py +++ b/wg_api/utils/html_parser.py @@ -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) diff --git a/wg_api/utils/reqs_handler.py b/wg_api/utils/reqs_handler.py new file mode 100644 index 00000000..88c84d4c --- /dev/null +++ b/wg_api/utils/reqs_handler.py @@ -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) + + diff --git a/wg_api/views.py b/wg_api/views.py index 99416f6a..66c60ca2 100644 --- a/wg_api/views.py +++ b/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') + + diff --git a/wgweb/__pycache__/__init__.cpython-311.pyc b/wgweb/__pycache__/__init__.cpython-311.pyc new file mode 100644 index 00000000..ceff05a3 Binary files /dev/null and b/wgweb/__pycache__/__init__.cpython-311.pyc differ diff --git a/wgweb/__pycache__/settings.cpython-311.pyc b/wgweb/__pycache__/settings.cpython-311.pyc new file mode 100644 index 00000000..0a21b9d8 Binary files /dev/null and b/wgweb/__pycache__/settings.cpython-311.pyc differ diff --git a/wgweb/__pycache__/urls.cpython-311.pyc b/wgweb/__pycache__/urls.cpython-311.pyc new file mode 100644 index 00000000..91a2e759 Binary files /dev/null and b/wgweb/__pycache__/urls.cpython-311.pyc differ diff --git a/wgweb/__pycache__/wsgi.cpython-311.pyc b/wgweb/__pycache__/wsgi.cpython-311.pyc new file mode 100644 index 00000000..f8815381 Binary files /dev/null and b/wgweb/__pycache__/wsgi.cpython-311.pyc differ diff --git a/wgweb/settings.py b/wgweb/settings.py index fdd8063d..35844f56 100644 --- a/wgweb/settings.py +++ b/wgweb/settings.py @@ -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 diff --git a/wgweb/urls.py b/wgweb/urls.py index fb0f4e5b..b455d57f 100644 --- a/wgweb/urls.py +++ b/wgweb/urls.py @@ -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) ]