Added keys count on outline page.

This commit is contained in:
A B
2024-10-26 23:36:18 +00:00
parent 75126b09ff
commit dda9b4ba5a
4 changed files with 12 additions and 2 deletions

View File

@ -17,11 +17,12 @@ Including another URLconf
from django.contrib import admin
from django.urls import path, include
from django.views.generic import RedirectView
from vpn.views import shadowsocks
from vpn.views import shadowsocks, print_headers
urlpatterns = [
path('admin/', admin.site.urls),
path('ss/<path:link>', shadowsocks, name='shadowsocks'),
path('dynamic/<path:link>', shadowsocks, name='shadowsocks'),
path('headers/', print_headers, name='print_headers'),
path('', RedirectView.as_view(url='/admin/', permanent=False)),
]

View File

@ -33,7 +33,6 @@ class ServerAdmin(PolymorphicParentModelAdmin):
status = obj.get_server_status()
if 'error' in status:
return mark_safe(f"<span style='color: red;'>Error: {status['error']}</span>")
# Преобразуем JSON в красивый формат
import json
pretty_status = ", ".join(f"{key}: {value}" for key, value in status.items())
return mark_safe(f"<pre>{pretty_status}</pre>")

View File

@ -73,7 +73,9 @@ class OutlineServer(Server):
if raw:
status = info
else:
keys = self.client.get_keys()
status.update(info)
status.update({"keys": len(keys)})
except Exception as e:
status.update({f"error": e})
return status

View File

@ -1,6 +1,14 @@
from django.shortcuts import get_object_or_404
from django.http import JsonResponse
from django.http import HttpResponse
def print_headers(request):
headers = {key: value for key, value in request.META.items() if key.startswith('HTTP_')}
for key, value in headers.items():
print(f'{key}: {value}')
return HttpResponse(f"Headers: {headers}")
def shadowsocks(request, link):
from .models import ACL