2025-02-23 19:18:23 +00:00
|
|
|
import yaml
|
2025-02-23 19:33:54 +00:00
|
|
|
import json
|
2024-10-20 21:57:12 +00:00
|
|
|
from django.shortcuts import get_object_or_404
|
2024-10-28 17:15:49 +00:00
|
|
|
from django.http import JsonResponse, HttpResponse, Http404
|
2024-10-20 21:57:12 +00:00
|
|
|
|
|
|
|
def shadowsocks(request, link):
|
2024-10-28 17:15:49 +00:00
|
|
|
from .models import ACLLink, AccessLog
|
|
|
|
try:
|
|
|
|
acl_link = get_object_or_404(ACLLink, link=link)
|
|
|
|
acl = acl_link.acl
|
|
|
|
except Http404:
|
2025-02-23 21:22:12 +00:00
|
|
|
AccessLog.objects.create(user=None, server="Unknown", action="Failed",
|
|
|
|
data=f"ACL not found for link: {link}")
|
2024-10-28 17:15:49 +00:00
|
|
|
return JsonResponse({"error": "Not allowed"}, status=403)
|
2025-02-23 21:22:12 +00:00
|
|
|
|
2024-10-21 13:22:03 +00:00
|
|
|
try:
|
|
|
|
server_user = acl.server.get_user(acl.user, raw=True)
|
2024-10-26 12:22:19 +00:00
|
|
|
except Exception as e:
|
2025-02-23 21:22:12 +00:00
|
|
|
AccessLog.objects.create(user=acl.user, server=acl.server.name, action="Failed",
|
|
|
|
data=f"{e}")
|
2024-10-26 12:22:19 +00:00
|
|
|
return JsonResponse({"error": f"Couldn't get credentials from server. {e}"})
|
2024-10-21 13:22:03 +00:00
|
|
|
|
2025-02-23 21:22:12 +00:00
|
|
|
if request.GET.get('mode') == 'json':
|
|
|
|
config = {
|
|
|
|
"info": "Managed by OutFleet_v2 [github.com/house-of-vanity/OutFleet/]",
|
|
|
|
"password": server_user.password,
|
|
|
|
"method": server_user.method,
|
|
|
|
"prefix": "\u0005\u00dc_\u00e0\u0001",
|
|
|
|
"server": acl.server.client_hostname,
|
|
|
|
"server_port": server_user.port,
|
|
|
|
"access_url": server_user.access_url,
|
|
|
|
"outfleet": {
|
|
|
|
"acl_link": link,
|
|
|
|
"server_name": acl.server.name,
|
|
|
|
"server_type": acl.server.server_type,
|
|
|
|
}
|
|
|
|
}
|
2025-02-23 21:29:03 +00:00
|
|
|
response = json.dumps(config, indent=2)
|
2025-02-23 21:22:12 +00:00
|
|
|
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"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2025-02-23 21:29:03 +00:00
|
|
|
response = yaml.dump(config, allow_unicode=True)
|
2025-02-23 21:22:12 +00:00
|
|
|
|
|
|
|
AccessLog.objects.create(user=acl.user, server=acl.server.name, action="Success", data=response)
|
2025-02-23 19:18:23 +00:00
|
|
|
|
2025-02-23 21:22:12 +00:00
|
|
|
return HttpResponse(response, content_type=f"{ 'application/json; charset=utf-8' if request.GET.get('mode') == 'json' else 'text/html' }")
|
2025-02-23 19:18:23 +00:00
|
|
|
|