Skip to content

Commit

Permalink
Merge pull request #1225 from fodhelper/respect-xray-policy
Browse files Browse the repository at this point in the history
Respect User Xray Policies
  • Loading branch information
ImMohammad20000 authored Oct 11, 2024
2 parents 4767837 + 84c29fb commit a556c49
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion app/xray/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@
from app.utils.crypto import get_cert_SANs
from config import DEBUG, XRAY_EXCLUDE_INBOUND_TAGS, XRAY_FALLBACKS_INBOUND_TAG

def merge_dicts(a, b): # B will override A dictionary key and values
for key, value in b.items():
if isinstance(value, dict) and key in a and isinstance(a[key], dict):
merge_dicts(a[key], value) # Recursively merge nested dictionaries
else:
a[key] = value
return a

class XRayConfig(dict):
def __init__(self,
Expand Down Expand Up @@ -69,7 +76,7 @@ def _apply_api(self):
"tag": "API"
}
self["stats"] = {}
self["policy"] = {
forced_policies = {
"levels": {
"0": {
"statsUserUplink": True,
Expand All @@ -83,6 +90,10 @@ def _apply_api(self):
"statsOutboundUplink": True
}
}
if self.get("policy"):
self["policy"] = merge_dicts(self.get("policy"), forced_policies)
else:
self["policy"] = forced_policies
inbound = {
"listen": self.api_host,
"port": self.api_port,
Expand Down

0 comments on commit a556c49

Please sign in to comment.