Skip to content

Commit

Permalink
Merge pull request #608 from vex-so/dev
Browse files Browse the repository at this point in the history
Postgres, Email, true shadowsocks encryption, OUTLINE ssconf subscription.
  • Loading branch information
SaintShit authored Nov 2, 2023
2 parents 215bfb3 + 0dbb063 commit 8881a58
Show file tree
Hide file tree
Showing 9 changed files with 2,548 additions and 13 deletions.
15 changes: 15 additions & 0 deletions app/dashboard/build/assets/index.e40384a1.js

Large diffs are not rendered by default.

2,465 changes: 2,465 additions & 0 deletions app/dashboard/build/assets/vendor.4e8f7a1b.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion app/dashboard/src/components/UserDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ const getDefaultValues = (): FormType => {
vless: { id: "", flow: "" },
vmess: { id: "" },
trojan: { password: "" },
shadowsocks: { password: "", method: "chacha20-poly1305" },
shadowsocks: { password: "", method: "chacha20-ietf-poly1305" },
},
};
};
Expand Down
2 changes: 1 addition & 1 deletion app/dashboard/src/constants/Proxies.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,5 @@ export const XTLSFlows = [
export const shadowsocksMethods = [
"aes-128-gcm",
"aes-256-gcm",
"chacha20-poly1305",
"chacha20-ietf-poly1305",
];
2 changes: 1 addition & 1 deletion app/models/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from config import XRAY_SUBSCRIPTION_URL_PREFIX
from xray_api.types.account import Account

USERNAME_REGEXP = re.compile(r"^(?=\w{3,32}\b)[a-zA-Z0-9]+(?:_[a-zA-Z0-9]+)*$")
USERNAME_REGEXP = re.compile(r"^(?=\w{3,32}\b)[a-zA-Z0-9-_@.]+(?:_[a-zA-Z0-9-_@.]+)*$")


class ReminderType(str, Enum):
Expand Down
58 changes: 52 additions & 6 deletions app/utils/share.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,9 @@ def shadowsocks(cls,
address: str,
port: int,
password: str,
security='chacha20-ietf-poly1305'):
method: str):
return "ss://" + \
base64.b64encode(f'{security}:{password}'.encode()).decode() + \
base64.b64encode(f'{method}:{password}'.encode()).decode() + \
f"@{address}:{port}#{urlparse.quote(remark)}"


Expand Down Expand Up @@ -487,7 +487,43 @@ def get_v2ray_link(remark: str, address: str, inbound: dict, settings: dict):
return V2rayShareLink.shadowsocks(remark=remark,
address=address,
port=inbound['port'],
password=settings['password'])
password=settings['password'],
method=settings['method'])

class OutlineConfiguration:
def __init__(self):
self.config = {}

def add_directly(self, data: dict):
self.config.update(data)

def render(self):
return json.dumps(self.config, indent=0)

def make_outbound(self, remark: str, address: str, port: int, password: str, method: str):
config = {
"method": method,
"password": password,
"server": address,
"server_port": port,
"tag": remark,
}
return config

def add(self, remark: str, address: str, inbound: dict, settings: dict):
if inbound['protocol'] != 'shadowsocks':
return

outbound = self.make_outbound(
remark=remark,
address=address,
port=inbound['port'],
password=settings['password'],
method=settings['method']
)
self.add_directly(outbound)




class SingBoxConfiguration(str):
Expand Down Expand Up @@ -709,9 +745,17 @@ def generate_v2ray_subscription(links: list) -> str:
return base64.b64encode('\n'.join(links).encode()).decode()



def generate_outline_subscription(proxies: dict, inbounds: dict, extra_data: dict) -> str:
conf = OutlineConfiguration()

format_variables = setup_format_variables(extra_data)
return process_inbounds_and_tags(inbounds, proxies, format_variables, mode="outline", conf=conf)


def generate_subscription(
user: "UserResponse",
config_format: Literal["v2ray", "clash-meta", "clash", "sing-box"],
config_format: Literal["v2ray", "clash-meta", "clash", "sing-box", "outline"],
as_base64: bool
) -> str:
kwargs = {"proxies": user.proxies, "inbounds": user.inbounds, "extra_data": user.__dict__}
Expand All @@ -724,6 +768,8 @@ def generate_subscription(
config = generate_clash_subscription(**kwargs)
elif config_format == 'sing-box':
config = generate_singbox_subscription(**kwargs)
elif config_format == 'outline':
config = generate_outline_subscription(**kwargs)
else:
raise ValueError(f'Unsupported format "{config_format}"')

Expand Down Expand Up @@ -841,15 +887,15 @@ def process_inbounds_and_tags(inbounds: dict, proxies: dict, format_variables: d
address=host['address'].format_map(format_variables),
inbound=host_inbound,
settings=settings.dict(no_obj=True)))
elif mode in ["clash", "sing-box"]:
elif mode in ["clash", "sing-box", "outline"]:
conf.add(
remark=host['remark'].format_map(format_variables),
address=host['address'].format_map(format_variables),
inbound=host_inbound,
settings=settings.dict(no_obj=True),
)

if mode in ["clash", "sing-box"]:
if mode in ["clash", "sing-box", "outline"]:
return conf.render()

return results
Expand Down
14 changes: 11 additions & 3 deletions app/views/subscription.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ def get_subscription_user_info(user: UserResponse) -> dict:
conf = generate_subscription(user=user, config_format="sing-box", as_base64=False)
return Response(content=conf, media_type="application/json", headers=response_headers)

elif re.match('^(SS|SSR|SSD|SSS|Outline|Shadowsocks|SSconf)', user_agent):
conf = generate_subscription(user=user, config_format="outline", as_base64=False)
return Response(content=conf, media_type="application/json", headers=response_headers)

else:
conf = generate_subscription(user=user, config_format="v2ray", as_base64=True)
return Response(content=conf, media_type="text/plain", headers=response_headers)
Expand All @@ -106,11 +110,11 @@ def user_subscription_info(token: str,
def user_subscription_with_client_type(
token: str,
request: Request,
client_type: str = Path(..., regex="sing-box|clash-meta|clash|v2ray"),
client_type: str = Path(..., regex="sing-box|clash-meta|clash|outline|v2ray"),
db: Session = Depends(get_db),
):
"""
Subscription link, v2ray, clash, sing-box, and clash-meta supported
Subscription link, v2ray, clash, sing-box, outline and clash-meta supported
"""

def get_subscription_user_info(user: UserResponse) -> dict:
Expand Down Expand Up @@ -163,5 +167,9 @@ def get_subscription_user_info(user: UserResponse) -> dict:
conf = generate_subscription(user=user, config_format="v2ray", as_base64=True)
return Response(content=conf, media_type="text/plain", headers=response_headers)

elif client_type == "outline":
conf = generate_subscription(user=user, config_format="outline", as_base64=False)
return Response(content=conf, media_type="application/json", headers=response_headers)

else:
raise HTTPException(status_code=400, detail="Invalid subscription type")
raise HTTPException(status_code=400, detail="Invalid subscription type")
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ Pillow==9.4.0
plumbum==1.8.1
protobuf==3.20.3
psutil==5.9.4
psycopg2-binary==2.9.7
pyasn1==0.4.8
pycparser==2.21
pydantic==1.10.2
Expand Down
2 changes: 1 addition & 1 deletion xray_api/types/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def message(self):
class ShadowsocksMethods(Enum):
AES_128_GCM = 'aes-128-gcm'
AES_256_GCM = 'aes-256-gcm'
CHACHA20_POLY1305 = 'chacha20-poly1305'
CHACHA20_POLY1305 = 'chacha20-ietf-poly1305'


class ShadowsocksAccount(Account):
Expand Down

0 comments on commit 8881a58

Please sign in to comment.