mirror of
https://github.com/house-of-vanity/OutFleet.git
synced 2025-07-06 17:14:07 +00:00
Fixed content type
This commit is contained in:
71
vpn/views.py
71
vpn/views.py
@ -3,43 +3,62 @@ import json
|
|||||||
from django.shortcuts import get_object_or_404
|
from django.shortcuts import get_object_or_404
|
||||||
from django.http import JsonResponse, HttpResponse, Http404
|
from django.http import JsonResponse, HttpResponse, Http404
|
||||||
|
|
||||||
|
|
||||||
def shadowsocks(request, link):
|
def shadowsocks(request, link):
|
||||||
from .models import ACLLink, AccessLog
|
from .models import ACLLink, AccessLog
|
||||||
try:
|
try:
|
||||||
acl_link = get_object_or_404(ACLLink, link=link)
|
acl_link = get_object_or_404(ACLLink, link=link)
|
||||||
acl = acl_link.acl
|
acl = acl_link.acl
|
||||||
except Http404:
|
except Http404:
|
||||||
AccessLog.objects.create(user=None, server="Unknown", action="Failed", data=f"ACL not found for link: {link}")
|
AccessLog.objects.create(user=None, server="Unknown", action="Failed",
|
||||||
|
data=f"ACL not found for link: {link}")
|
||||||
return JsonResponse({"error": "Not allowed"}, status=403)
|
return JsonResponse({"error": "Not allowed"}, status=403)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
server_user = acl.server.get_user(acl.user, raw=True)
|
server_user = acl.server.get_user(acl.user, raw=True)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
AccessLog.objects.create(user=acl.user, server=acl.server.name, action="Failed", data=f"{e}")
|
AccessLog.objects.create(user=acl.user, server=acl.server.name, action="Failed",
|
||||||
|
data=f"{e}")
|
||||||
return JsonResponse({"error": f"Couldn't get credentials from server. {e}"})
|
return JsonResponse({"error": f"Couldn't get credentials from server. {e}"})
|
||||||
|
|
||||||
config = {
|
if request.GET.get('mode') == 'json':
|
||||||
"transport": {
|
config = {
|
||||||
"$type": "tcpudp",
|
"info": "Managed by OutFleet_v2 [github.com/house-of-vanity/OutFleet/]",
|
||||||
"tcp": {
|
"password": server_user.password,
|
||||||
"$type": "shadowsocks",
|
"method": server_user.method,
|
||||||
"endpoint": f"{acl.server.client_hostname}:{server_user.port}",
|
"prefix": "\u0005\u00dc_\u00e0\u0001",
|
||||||
"cipher": f"{server_user.method}",
|
"server": acl.server.client_hostname,
|
||||||
"secret": f"{server_user.password}",
|
"server_port": server_user.port,
|
||||||
"prefix": "\u0005\u00dc_\u00e0\u0001"
|
"access_url": server_user.access_url,
|
||||||
},
|
"outfleet": {
|
||||||
"udp": {
|
"acl_link": link,
|
||||||
"$type": "shadowsocks",
|
"server_name": acl.server.name,
|
||||||
"endpoint": f"{acl.server.client_hostname}:{server_user.port}",
|
"server_type": acl.server.server_type,
|
||||||
"cipher": f"{server_user.method}",
|
}
|
||||||
"secret": f"{server_user.password}",
|
}
|
||||||
"prefix": "\u0005\u00dc_\u00e0\u0001"
|
response = yaml.dump(config, allow_unicode=True)
|
||||||
}
|
else:
|
||||||
}
|
config = {
|
||||||
}
|
"transport": {
|
||||||
|
"$type": "tcpudp",
|
||||||
|
"tcp": {
|
||||||
|
"$type": "shadowsocks",
|
||||||
|
"endpoint": f"{acl.server.client_hostname}:{server_user.port}",
|
||||||
|
"cipher": f"{server_user.method}",
|
||||||
|
"secret": f"{server_user.password}",
|
||||||
|
"prefix": "\u0005\u00dc_\u00e0\u0001"
|
||||||
|
},
|
||||||
|
"udp": {
|
||||||
|
"$type": "shadowsocks",
|
||||||
|
"endpoint": f"{acl.server.client_hostname}:{server_user.port}",
|
||||||
|
"cipher": f"{server_user.method}",
|
||||||
|
"secret": f"{server_user.password}",
|
||||||
|
"prefix": "\u0005\u00dc_\u00e0\u0001"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
response = json.dumps(config, indent=2)
|
||||||
|
|
||||||
AccessLog.objects.create(user=acl.user, server=acl.server.name, action="Success", data=json.dumps(config, indent=2))
|
AccessLog.objects.create(user=acl.user, server=acl.server.name, action="Success", data=response)
|
||||||
|
|
||||||
|
return HttpResponse(response, content_type=f"{ 'application/json; charset=utf-8' if request.GET.get('mode') == 'json' else 'text/html' }")
|
||||||
|
|
||||||
yaml_data = yaml.dump(config, allow_unicode=True)
|
|
||||||
return HttpResponse(yaml_data, content_type="text/html")
|
|
||||||
|
Reference in New Issue
Block a user