diff --git a/apps/api/views.py b/apps/api/views.py index 493593d6e7..5db3ccd371 100644 --- a/apps/api/views.py +++ b/apps/api/views.py @@ -83,6 +83,10 @@ def get_user_and_nodes(self, request): native_ip = request.GET.get("native_ip") if native_ip: node_list = node_list.filter(native_ip=True) + location = request.GET.get("location") + if location: + node_list = node_list.filter(country=location) + if node_list.count() == 0: return None, HttpResponseBadRequest("no active nodes for you") diff --git a/apps/proxy/admin.py b/apps/proxy/admin.py index 3744773a64..abb6b1cae9 100644 --- a/apps/proxy/admin.py +++ b/apps/proxy/admin.py @@ -75,6 +75,56 @@ class ProxyNodeAdmin(admin.ModelAdmin): list_editable = ["sequence"] search_fields = ["name", "provider_remark"] + fieldsets = ( + ( + None, + { + "fields": ( + "name", + "server", + "node_type", + "info", + "country", + "provider_remark", + "level", + "enable", + "enable_direct", + "enable_udp", + "native_ip", + ) + }, + ), + ( + "Traffic and Bandwidth", + { + "fields": ( + "used_traffic", + "total_traffic", + "upload_bandwidth_bytes", + "download_bandwidth_bytes", + "current_used_upload_bandwidth_bytes", + "current_used_download_bandwidth_bytes", + ) + }, + ), + ( + "Xray and Ehco Configuration", + { + "fields": ( + "xray_grpc_port", + "ehco_listen_host", + "ehco_listen_port", + "ehco_listen_type", + "ehco_transport_type", + "ehco_web_port", + "ehco_web_token", + "ehco_log_level", + "ehco_reload_interval", + ) + }, + ), + ) + def get_form(self, request, obj=None, **kwargs): if obj: help_texts = { diff --git a/apps/sub.py b/apps/sub.py index 25d58292d5..ebf39dcb3c 100644 --- a/apps/sub.py +++ b/apps/sub.py @@ -39,6 +39,10 @@ def _get_clash_sub_yaml(self): direct_ip_rule_set_url = user.direct_ip_rule_set_endpoint direct_domain_rule_set_url = user.direct_domain_rule_set_endpoint + node_location_set = set() + for node in self.node_list: + node_location_set.add(node.country) + return render_to_string( "clash/main.yaml", { @@ -48,6 +52,7 @@ def _get_clash_sub_yaml(self): "native_ip_proxy_provider_url": native_ip_proxy_provider_url, "direct_ip_rule_set_url": direct_ip_rule_set_url, "direct_domain_rule_set_url": direct_domain_rule_set_url, + "node_location_set": node_location_set, }, ) diff --git a/poetry.lock b/poetry.lock index 218a354aee..d8f8ec5701 100644 --- a/poetry.lock +++ b/poetry.lock @@ -733,12 +733,12 @@ prometheus-client = ">=0.7" [[package]] name = "django-simpleui" -version = "2023.12.12" +version = "2024.4.1" description = "django admin theme 后台模板" optional = false python-versions = "*" files = [ - {file = "django-simpleui-2023.12.12.tar.gz", hash = "sha256:517f0cd6cf657aac89de4b6b48b929c817a7bcb428779bbd80fd5213766e2518"}, + {file = "django-simpleui-2024.4.1.tar.gz", hash = "sha256:d2d5556b1b6dcb6a06df6e70c2f0840bd8267e9712064c82151e1280d57f893d"}, ] [package.dependencies] @@ -2253,4 +2253,4 @@ multidict = ">=4.0" [metadata] lock-version = "2.0" python-versions = "^3.11" -content-hash = "76c4803c606dfb2347b4f2f04254b40806dbaf4ad5de93d16f9ca4a49c4a0c99" +content-hash = "cb80bd755b436dcb543b56d557b5f2676fccae477e77c42fb6b77b0d3b557805" diff --git a/pyproject.toml b/pyproject.toml index 6476c25eaa..194a270e38 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -39,7 +39,7 @@ django-cors-headers = "^4.2.0" django-countries = "^7.1" django-debug-toolbar = "^4.2.0" django-prometheus = "^2.1.0" -django-simpleui = "^2023.8.28" +django-simpleui = "^2024.4.1" django-telegram-login = "^0.2.3" ipicn = "^2021.5.5" ipython = "^8.19.0" diff --git a/templates/clash/main.yaml b/templates/clash/main.yaml index 9a7028f83b..b0c38d3bbe 100644 --- a/templates/clash/main.yaml +++ b/templates/clash/main.yaml @@ -1,17 +1,17 @@ # see https://github.com/Loyalsoldier/clash-rules - mode: rule port: 7890 socks-port: 7891 allow-lan: true log-level: info external-controller: 0.0.0.0:9090 - proxy-groups: - name: PROXY type: select proxies: - auto + {% for loc in node_location_set %}- {{ loc }} + {% endfor %} use: - {{ provider_name }}-all @@ -20,15 +20,22 @@ proxy-groups: use: - {{ provider_name }}-native-ip + {% for loc in node_location_set %} + - name: {{ loc }} + type: select + use: + - {{ provider_name }}-{{ loc }} + {% endfor %} + - name: auto type: url-test use: - {{ provider_name }}-all - - {{ provider_name }}-native-ip url: "http://www.gstatic.com/generate_204" interval: 300 tolerance: 150 lazy: true + - name: Final type: select proxies: @@ -59,6 +66,19 @@ proxy-providers: tolerance: 150 lazy: true url: http://www.gstatic.com/generate_204 +{% for loc in node_location_set %} + {{ provider_name }}-{{ loc }}: + type: http + url: {{ all_proxy_provider_url|safe }}&location={{ loc }} + interval: 3600 + path: ./providers/{{ provider_name }}-native-ip.yaml + health-check: + enable: true + interval: 300 + tolerance: 150 + lazy: true + url: http://www.gstatic.com/generate_204 + {% endfor %} rule-providers: reject: @@ -189,3 +209,4 @@ rules: - GEOIP,LAN,DIRECT - GEOIP,CN,DIRECT - MATCH,Final + diff --git a/templates/web/user_info.html b/templates/web/user_info.html index a4e7fb12b8..8467282025 100644 --- a/templates/web/user_info.html +++ b/templates/web/user_info.html @@ -140,7 +140,7 @@