From ace5e8a6e83f2b4cae6cdd1e98c6d9cc59f6bd28 Mon Sep 17 00:00:00 2001 From: Sarina Date: Thu, 18 Jan 2024 00:21:29 +0330 Subject: [PATCH 1/6] add: new config links --- hiddifypanel/panel/user/user.py | 71 +++++++++++++++++++++++++-------- 1 file changed, 54 insertions(+), 17 deletions(-) diff --git a/hiddifypanel/panel/user/user.py b/hiddifypanel/panel/user/user.py index e4e93e6c2..eff11fef2 100644 --- a/hiddifypanel/panel/user/user.py +++ b/hiddifypanel/panel/user/user.py @@ -34,12 +34,63 @@ 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("/full-singbox/") + @route("/full-singbox") + @login_required(roles={Role.user}) + def singbox_full(self): + return self.full_singbox() + + @route("/singbox/") + @route("/singbox") + @login_required(roles={Role.user}) + def singbox_ssh(self): + return self.singbox() + + @route("/clash/") + @route("/clash") + @login_required(roles={Role.user}) + def clash(self): + ua = request.user_agent.string + if re.match('^(Clash-verge|Clash-?Meta|Stash|NekoBox|NekoRay|Pharos|hiddify-desktop)', ua, re.IGNORECASE): + return self.clash_config(meta_or_normal="meta") + else: # if re.match('^(Clash|Stash)', ua, re.IGNORECASE): + return self.clash_config(meta_or_normal="normal") + # 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 @@ -59,20 +110,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//proxies.yml') @ route('/clash/proxies.yml') @login_required(roles={Role.user}) @@ -185,8 +222,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 click for reload" From 687738e076b4d1c455e37eb8a0e1697d752c41cf Mon Sep 17 00:00:00 2001 From: Sarina Date: Fri, 19 Jan 2024 14:23:01 +0330 Subject: [PATCH 2/6] chg: update configs link --- hiddifypanel/panel/user/user.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/hiddifypanel/panel/user/user.py b/hiddifypanel/panel/user/user.py index eff11fef2..b4bf1f3d2 100644 --- a/hiddifypanel/panel/user/user.py +++ b/hiddifypanel/panel/user/user.py @@ -61,8 +61,8 @@ def sub64(self): def singbox_full(self): return self.full_singbox() - @route("/singbox/") - @route("/singbox") + @route("/singbox-ssh/") + @route("/singbox-ssh") @login_required(roles={Role.user}) def singbox_ssh(self): return self.singbox() @@ -71,6 +71,11 @@ def singbox_ssh(self): @route("/clash") @login_required(roles={Role.user}) def clash(self): + if mode := request.args.get("mode"): + if re.match(r'^(meta|normal)$', mode, re.IGNORECASE): + return self.clash_config(meta_or_normal=mode) + else: + return abort(400, 'Unsupported mode for clash config') ua = request.user_agent.string if re.match('^(Clash-verge|Clash-?Meta|Stash|NekoBox|NekoRay|Pharos|hiddify-desktop)', ua, re.IGNORECASE): return self.clash_config(meta_or_normal="meta") From c17fc026f68490c72f43526bcaa609ab5fd1d86c Mon Sep 17 00:00:00 2001 From: Sarina Date: Fri, 19 Jan 2024 14:23:34 +0330 Subject: [PATCH 3/6] chg: all-configs api links --- .../commercial/restapi/v2/user/configs_api.py | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/hiddifypanel/panel/commercial/restapi/v2/user/configs_api.py b/hiddifypanel/panel/commercial/restapi/v2/user/configs_api.py index 1dcc3fa6f..fd80ffb96 100644 --- a/hiddifypanel/panel/commercial/restapi/v2/user/configs_api.py +++ b/hiddifypanel/panel/commercial/restapi/v2/user/configs_api.py @@ -46,14 +46,17 @@ 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/" + ) ) # 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}full-singbox/" ) ) @@ -61,7 +64,8 @@ def create_item(name, domain, type, protocol, transport, security, link): 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}clash/?mode=meta" ) ) @@ -69,7 +73,8 @@ def create_item(name, domain, type, protocol, transport, security, link): 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/?mode=normal" ) ) @@ -78,7 +83,8 @@ 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/" ) ) @@ -86,7 +92,8 @@ def create_item(name, domain, type, protocol, transport, security, 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/" ) ) @@ -94,7 +101,8 @@ def create_item(name, domain, type, protocol, transport, security, link): 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/" ) ) From ad435afef89b68dba69791034df9be5f63023394 Mon Sep 17 00:00:00 2001 From: Sarina Date: Fri, 19 Jan 2024 14:50:20 +0330 Subject: [PATCH 4/6] chg: seperate clash and clashmeta endpoints --- .../commercial/restapi/v2/user/configs_api.py | 4 ++-- hiddifypanel/panel/user/user.py | 17 +++++++---------- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/hiddifypanel/panel/commercial/restapi/v2/user/configs_api.py b/hiddifypanel/panel/commercial/restapi/v2/user/configs_api.py index fd80ffb96..5f6bd43d5 100644 --- a/hiddifypanel/panel/commercial/restapi/v2/user/configs_api.py +++ b/hiddifypanel/panel/commercial/restapi/v2/user/configs_api.py @@ -65,7 +65,7 @@ def create_item(name, domain, type, protocol, transport, security, link): 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"clash://install-config?url={base_url}clash/?mode=meta" + f"clash://install-config?url={base_url}clashmeta/" ) ) @@ -74,7 +74,7 @@ def create_item(name, domain, type, protocol, transport, security, link): 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/?mode=normal" + f"clash://install-config?url={base_url}clash/" ) ) diff --git a/hiddifypanel/panel/user/user.py b/hiddifypanel/panel/user/user.py index b4bf1f3d2..406a14817 100644 --- a/hiddifypanel/panel/user/user.py +++ b/hiddifypanel/panel/user/user.py @@ -71,16 +71,13 @@ def singbox_ssh(self): @route("/clash") @login_required(roles={Role.user}) def clash(self): - if mode := request.args.get("mode"): - if re.match(r'^(meta|normal)$', mode, re.IGNORECASE): - return self.clash_config(meta_or_normal=mode) - else: - return abort(400, 'Unsupported mode for clash config') - ua = request.user_agent.string - if re.match('^(Clash-verge|Clash-?Meta|Stash|NekoBox|NekoRay|Pharos|hiddify-desktop)', ua, re.IGNORECASE): - return self.clash_config(meta_or_normal="meta") - else: # if re.match('^(Clash|Stash)', ua, re.IGNORECASE): - return self.clash_config(meta_or_normal="normal") + 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/') From c856c0866e3991c6c7c6249efb6cf69838d269d2 Mon Sep 17 00:00:00 2001 From: Sarina Date: Fri, 19 Jan 2024 15:25:46 +0330 Subject: [PATCH 5/6] chg: send args in link (asn,mode...) --- .../commercial/restapi/v2/user/configs_api.py | 14 +++++++------- hiddifypanel/panel/user/user.py | 4 ++-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/hiddifypanel/panel/commercial/restapi/v2/user/configs_api.py b/hiddifypanel/panel/commercial/restapi/v2/user/configs_api.py index 5f6bd43d5..b2f17edd1 100644 --- a/hiddifypanel/panel/commercial/restapi/v2/user/configs_api.py +++ b/hiddifypanel/panel/commercial/restapi/v2/user/configs_api.py @@ -47,7 +47,7 @@ def create_item(name, domain, type, protocol, transport, security, link): create_item( "Auto", "ALL", "ALL", "", "", "", # f"{base_url}sub/?asn={c['asn']}" - f"{base_url}auto/" + f"{base_url}auto/?asn={c['asn']}" ) ) @@ -56,7 +56,7 @@ def create_item(name, domain, type, protocol, transport, security, link): create_item( "Full Singbox", "ALL", "ALL", "", "", "", # f"{base_url}full-singbox.json?asn={c['asn']}" - f"{base_url}full-singbox/" + f"{base_url}singbox/?asn={c['asn']}" ) ) @@ -65,7 +65,7 @@ def create_item(name, domain, type, protocol, transport, security, link): 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"clash://install-config?url={base_url}clashmeta/" + f"clash://install-config?url={base_url}clashmeta/?asn={c['asn']}&mode={c['mode']}" ) ) @@ -74,7 +74,7 @@ def create_item(name, domain, type, protocol, transport, security, link): 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/" + f"clash://install-config?url={base_url}clash/?asn={c['asn']}&mode={c['mode']}" ) ) @@ -84,7 +84,7 @@ def create_item(name, domain, type, protocol, transport, security, link): 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-ssh/" + f"{base_url}singbox-ssh/?asn={c['asn']}&mode={c['mode']}" ) ) @@ -93,7 +93,7 @@ def create_item(name, domain, type, protocol, transport, security, link): 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}sub/" + f"{base_url}sub/?asn={c['asn']}&mode={c['mode']}" ) ) @@ -102,7 +102,7 @@ def create_item(name, domain, type, protocol, transport, security, link): 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}sub64/" + f"{base_url}sub64/?asn={c['asn']}&mode={c['mode']}" ) ) diff --git a/hiddifypanel/panel/user/user.py b/hiddifypanel/panel/user/user.py index 406a14817..453e9d7e5 100644 --- a/hiddifypanel/panel/user/user.py +++ b/hiddifypanel/panel/user/user.py @@ -55,8 +55,8 @@ def sub(self): def sub64(self): return self.all_configs(base64=True) - @route("/full-singbox/") - @route("/full-singbox") + @route("/singbox/") + @route("/singbox") @login_required(roles={Role.user}) def singbox_full(self): return self.full_singbox() From 421275f2ad55bfd2cc255cbac157aaeedc1b050b Mon Sep 17 00:00:00 2001 From: Sarina Date: Fri, 19 Jan 2024 15:33:05 +0330 Subject: [PATCH 6/6] chg: remove unused argument/parameter --- .../panel/commercial/restapi/v2/user/configs_api.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/hiddifypanel/panel/commercial/restapi/v2/user/configs_api.py b/hiddifypanel/panel/commercial/restapi/v2/user/configs_api.py index b2f17edd1..438af452f 100644 --- a/hiddifypanel/panel/commercial/restapi/v2/user/configs_api.py +++ b/hiddifypanel/panel/commercial/restapi/v2/user/configs_api.py @@ -65,7 +65,7 @@ def create_item(name, domain, type, protocol, transport, security, link): 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"clash://install-config?url={base_url}clashmeta/?asn={c['asn']}&mode={c['mode']}" + f"clash://install-config?url={base_url}clashmeta/?asn={c['asn']}" ) ) @@ -74,7 +74,7 @@ def create_item(name, domain, type, protocol, transport, security, link): 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/?asn={c['asn']}&mode={c['mode']}" + f"clash://install-config?url={base_url}clash/?asn={c['asn']}" ) ) @@ -84,7 +84,7 @@ def create_item(name, domain, type, protocol, transport, security, link): 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-ssh/?asn={c['asn']}&mode={c['mode']}" + f"{base_url}singbox-ssh/?asn={c['asn']}" ) ) @@ -93,7 +93,7 @@ def create_item(name, domain, type, protocol, transport, security, link): 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}sub/?asn={c['asn']}&mode={c['mode']}" + f"{base_url}sub/?asn={c['asn']}" ) ) @@ -102,7 +102,7 @@ def create_item(name, domain, type, protocol, transport, security, link): 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}sub64/?asn={c['asn']}&mode={c['mode']}" + f"{base_url}sub64/?asn={c['asn']}" ) )