From d4ae2de0816b0974e9a9d6fa80a224a8315ff970 Mon Sep 17 00:00:00 2001 From: Iam54r1n4 Date: Sun, 9 Feb 2025 10:48:59 +0000 Subject: [PATCH] Add: Change port & Fill sni domain field on loading DOM & Adopt previous commit changes --- core/scripts/webpanel/templates/settings.html | 94 ++++++++++++++----- 1 file changed, 73 insertions(+), 21 deletions(-) diff --git a/core/scripts/webpanel/templates/settings.html b/core/scripts/webpanel/templates/settings.html index c384a28..ee22fc3 100644 --- a/core/scripts/webpanel/templates/settings.html +++ b/core/scripts/webpanel/templates/settings.html @@ -27,6 +27,9 @@ Telegram Bot + @@ -90,7 +93,7 @@ -
+
@@ -106,6 +109,18 @@
+ +
+ +
+
+ + +
+ +
+
+
@@ -186,6 +201,51 @@ } }); } + + + // Fetch IP addresses + $.ajax({ + url: "{{ url_for('get_ip_api') }}", + type: "GET", + success: function (data) { + $("#ipv4").val(data.ipv4 || ""); + $("#ipv6").val(data.ipv6 || ""); + + $("#ipv4").attr("placeholder", "Enter IPv4"); + $("#ipv6").attr("placeholder", "Enter IPv6"); + + + }, + error: function () { + console.error("Failed to fetch IP addresses."); + $("#ipv4").attr("placeholder", "Enter IPv4"); + $("#ipv6").attr("placeholder", "Enter IPv6"); + } + }); + + // Fetch Port + $.ajax({ + url: "{{ url_for('get_port_api') }}", + type: "GET", + success: function (data) { + $("#hysteria_port").val(data.port || ""); + }, + error: function () { + console.error("Failed to fetch port."); + } + }); + + // Fetch SNI domain + $.ajax({ + url: "{{ url_for('get_sni_api') }}", + type: "GET", + success: function (data) { + $("#sni_domain").val(data.sni || ""); + }, + error: function () { + console.error("Failed to fetch SNI domain."); + } + }); } $(document).ready(function () { // Init UI @@ -307,10 +367,19 @@ }); } + function changePort() { + const port = $("#hysteria_port").val(); + const baseUrl = "{{ url_for('set_port_api', port='PORT_PLACEHOLDER') }}"; + const url = baseUrl.replace("PORT_PLACEHOLDER", port); + confirmAction("change the port", function () { + sendRequest(url, "GET", null, "Port changed successfully!"); + }); + } + // Change SNI function changeSNI() { const domain = $("#sni_domain").val(); - const baseUrl = "{{ url_for('set_sni', sni='SNI_PLACEHOLDER') }}"; + const baseUrl = "{{ url_for('set_sni_api', sni='SNI_PLACEHOLDER') }}"; const url = baseUrl.replace("SNI_PLACEHOLDER", domain); confirmAction("change the SNI", function () { sendRequest(url, "GET", null, "SNI changed successfully!"); @@ -336,31 +405,14 @@ $("#singbox_stop").on("click", stopSingbox); $("#normal_start").on("click", startNormal); $("#normal_stop").on("click", stopNormal); + $("#port_change").on("click", changePort); $("#sni_change").on("click", changeSNI); $("#ip_change").on("click", saveIP); - $.ajax({ - url: "{{ url_for('get_ip_api') }}", - type: "GET", - success: function (data) { - $("#ipv4").val(data.ipv4 || ""); - $("#ipv6").val(data.ipv6 || ""); - - $("#ipv4").attr("placeholder", "Enter IPv4"); - $("#ipv6").attr("placeholder", "Enter IPv6"); - - - }, - error: function () { - console.error("Failed to fetch IP addresses."); - $("#ipv4").attr("placeholder", "Enter IPv4"); - $("#ipv6").attr("placeholder", "Enter IPv6"); - } - }); }); -{% endblock %} +{% endblock %} \ No newline at end of file