Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new config endpoints #91

Merged
merged 6 commits into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions hiddifypanel/panel/commercial/restapi/v2/user/configs_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,30 +46,35 @@ def create_item(name, domain, type, protocol, transport, security, link):
items.append(
create_item(
"Auto", "ALL", "ALL", "", "", "",
f"{base_url}sub/?asn={c['asn']}")
# f"{base_url}sub/?asn={c['asn']}"
f"{base_url}auto/?asn={c['asn']}"
)
)

# Add Full Singbox
items.append(
create_item(
"Full Singbox", "ALL", "ALL", "", "", "",
f"{base_url}full-singbox.json?asn={c['asn']}"
# f"{base_url}full-singbox.json?asn={c['asn']}"
f"{base_url}singbox/?asn={c['asn']}"
)
)

# Add Clash Meta
items.append(
create_item(
"Clash Meta", "ALL", "ALL", "", "", "",
f"clashmeta://install-config?url={base_url}clash/meta/all.yml&name=mnormal_{c['db_domain'].alias or c['db_domain'].domain}-{c['asn']}-{c['mode']}&asn={c['asn']}&mode={c['mode']}"
# f"clashmeta://install-config?url={base_url}clash/meta/all.yml&name=mnormal_{c['db_domain'].alias or c['db_domain'].domain}-{c['asn']}-{c['mode']}&asn={c['asn']}&mode={c['mode']}"
f"clash://install-config?url={base_url}clashmeta/?asn={c['asn']}"
)
)

# Add Clash
items.append(
create_item(
"Clash", "ALL", "Except VLess", "", "", "",
f"clash://install-config?url={base_url}clash/all.yml&name=new_normal_{c['db_domain'].alias or c['db_domain'].domain}-{c['asn']}-{c['mode']}&asn={c['asn']}&mode={c['mode']}"
# f"clash://install-config?url={base_url}clash/all.yml&name=new_normal_{c['db_domain'].alias or c['db_domain'].domain}-{c['asn']}-{c['mode']}&asn={c['asn']}&mode={c['mode']}"
f"clash://install-config?url={base_url}clash/?asn={c['asn']}"
)
)

Expand All @@ -78,23 +83,26 @@ def create_item(name, domain, type, protocol, transport, security, link):
items.append(
create_item(
"Singbox: SSH", "SSH", "SHH", "", "", "",
f"{base_url}singbox.json?name={c['db_domain'].alias or c['db_domain'].domain}-{c['asn']}&asn={c['asn']}&mode={c['mode']}"
# f"{base_url}singbox.json?name={c['db_domain'].alias or c['db_domain'].domain}-{c['asn']}&asn={c['asn']}&mode={c['mode']}"
f"{base_url}singbox-ssh/?asn={c['asn']}"
)
)

# Add Subscription link
items.append(
create_item(
"Subscription link", "ALL", "ALL", "", "", "",
f"{base_url}all.txt?name={c['db_domain'].alias or c['db_domain'].domain}-{c['asn']}&asn={c['asn']}&mode={c['mode']}"
# f"{base_url}all.txt?name={c['db_domain'].alias or c['db_domain'].domain}-{c['asn']}&asn={c['asn']}&mode={c['mode']}"
f"{base_url}sub/?asn={c['asn']}"
)
)

# Add Subscription link base64
items.append(
create_item(
"Subscription link b64", "ALL", "ALL", "", "", "",
f"{base_url}all.txt?name=new_link_{c['db_domain'].alias or c['db_domain'].domain}-{c['asn']}-{c['mode']}&asn={c['asn']}&mode={c['mode']}&base64=True"
# f"{base_url}all.txt?name=new_link_{c['db_domain'].alias or c['db_domain'].domain}-{c['asn']}-{c['mode']}&asn={c['asn']}&mode={c['mode']}&base64=True"
f"{base_url}sub64/?asn={c['asn']}"
)
)

Expand Down
73 changes: 56 additions & 17 deletions hiddifypanel/panel/user/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,65 @@ def auto_sub(self):
return self.new()
return self.get_proper_config() or self.all_configs(base64=True)

@route('/sub')
@route('/sub/')
# former /sub/ or /sub (it was auto actually but we named it as /sub/)
# TODO: @hiddify: check this out
@route('/auto/')
@route('/auto')
@login_required(roles={Role.user})
def force_sub(self):
return self.get_proper_config() or self.all_configs(base64=False)

# region new endpoints
@route("/sub/")
@route("/sub")
@login_required(roles={Role.user})
def sub(self):
return self.all_configs(base64=False)

@route("/sub64/")
@route("/sub64")
@login_required(roles={Role.user})
def sub64(self):
return self.all_configs(base64=True)

@route("/singbox/")
@route("/singbox")
@login_required(roles={Role.user})
def singbox_full(self):
return self.full_singbox()

@route("/singbox-ssh/")
@route("/singbox-ssh")
@login_required(roles={Role.user})
def singbox_ssh(self):
return self.singbox()

@route("/clash/")
@route("/clash")
@login_required(roles={Role.user})
def clash(self):
return self.clash_config(meta_or_normal="normal")

@route("/clashmeta/")
@route("/clashmeta")
@login_required(roles={Role.user})
def clashmeta(self):
return self.clash_config(meta_or_normal="meta")
# endregion

@ route('/new/')
@ route('/new')
@login_required(roles={Role.user})
def new(self):
conf = self.get_proper_config()
if conf:
return conf

c = get_common_data(g.account.uuid, mode="new")
user_agent = user_agents.parse(request.user_agent.string)
# return render_template('home/multi.html', **c, ua=user_agent)
return render_template('new.html', **c, ua=user_agent)

def get_proper_config(self):
if g.user_agent['is_browser']:
return None
Expand All @@ -59,20 +112,6 @@ def get_proper_config(self):
if re.match('^(Hiddify|FoXray|Fair|v2rayNG|SagerNet|Shadowrocket|V2Box|Loon|Liberty)', ua, re.IGNORECASE):
return self.all_configs(base64=True)

@ route('/new/')
@ route('/new')
@login_required(roles={Role.user})
# @ route('/')
def new(self):
conf = self.get_proper_config()
if conf:
return conf

c = get_common_data(g.account.uuid, mode="new")
user_agent = user_agents.parse(request.user_agent.string)
# return render_template('home/multi.html', **c, ua=user_agent)
return render_template('new.html', **c, ua=user_agent)

@ route('/clash/<meta_or_normal>/proxies.yml')
@ route('/clash/proxies.yml')
@login_required(roles={Role.user})
Expand Down Expand Up @@ -185,8 +224,8 @@ def all_configs(self, base64=False):
resp = do_base_64(resp)
return add_headers(resp, c)

@login_required(roles={Role.user})
@ route("/offline.html")
@login_required(roles={Role.user})
def offline():
return f"Not Connected <a href='{hiddify.get_account_panel_link(g.account, request.host)}'>click for reload</a>"

Expand Down