@@ -328,6 +347,12 @@
return /^[0-9]+$/.test(port) && parseInt(port) > 0 && parseInt(port) <= 65535;
}
+ function isValidSubPath(subpath) {
+ if (!subpath) return false;
+ return /^[a-zA-Z0-9]+$/.test(subpath);
+ }
+
+
function isValidIPorDomain(input) {
if (!input) return true;
@@ -365,7 +390,7 @@
});
}
- function sendRequest(url, type, data, successMessage, buttonSelector, showReload = true) {
+ function sendRequest(url, type, data, successMessage, buttonSelector, showReload = true, postSuccessCallback = null) {
$.ajax({
url: url,
type: type,
@@ -378,13 +403,15 @@
}
},
success: function (response) {
- if (showReload) {
- Swal.fire("Success!", successMessage, "success").then(() => {
+ Swal.fire("Success!", successMessage, "success").then(() => {
+ if (showReload) {
location.reload();
- });
- } else {
- Swal.fire("Success!", successMessage, "success");
- }
+ } else {
+ if (postSuccessCallback) {
+ postSuccessCallback(response);
+ }
+ }
+ });
console.log("Success Response:", response);
},
error: function (xhr, status, error) {
@@ -393,7 +420,7 @@
errorMessage = xhr.responseJSON.detail;
}
Swal.fire("Error!", errorMessage, "error");
- console.error("AJAX Error:", status, error, xhr.responseText);
+ console.error("AJAX Error:", status, error, xhr.responseText);
},
complete: function() {
if (buttonSelector) {
@@ -411,10 +438,12 @@
const id = input.attr('id');
let fieldValid = true;
- if (id.includes('domain')) {
+ if (id === 'normal_domain' || id === 'sni_domain' || id === 'decoy_domain') {
fieldValid = isValidDomain(input.val());
- } else if (id.includes('port')) {
+ } else if (id === 'normal_port' || id === 'hysteria_port') {
fieldValid = isValidPort(input.val());
+ } else if (id === 'normal_subpath_input') {
+ fieldValid = isValidSubPath(input.val());
} else if (id === 'ipv4' || id === 'ipv6') {
fieldValid = (input.val().trim() === '') ? true : isValidIPorDomain(input.val());
} else if (id === 'block_duration' || id === 'max_ips') {
@@ -427,14 +456,15 @@
if (!fieldValid) {
input.addClass('is-invalid');
- isValid = false;
+ isValid = false;
} else {
input.removeClass('is-invalid');
}
});
- return isValid;
+ return isValid;
}
+
function initUI() {
$.ajax({
url: "{{ url_for('server_services_status_api') }}",
@@ -481,50 +511,113 @@
console.error("Failed to fetch SNI domain:", error, xhr.responseText);
}
});
-
- }
+ }
function updateServiceUI(data) {
const servicesMap = {
- "hysteria_telegram_bot": "#telegram",
- "hysteria_normal_sub": "#normal",
- "hysteria_iplimit": "#ip-limit-service"
+ "hysteria_telegram_bot": "#telegram_form",
+ "hysteria_normal_sub": "#normal_sub_service_form",
+ "hysteria_iplimit": "#ip-limit-service"
};
Object.keys(servicesMap).forEach(service => {
- let selector = servicesMap[service];
- let isRunning = data[service];
+ let formSelector = servicesMap[service];
+ let isRunning = data[service];
- if (isRunning) {
- $(selector + " .form-group").hide();
- $(selector + " .btn-success").hide();
- $(selector + " .btn-danger").show();
- if ($(selector + " .alert-info").length === 0) {
- $(selector).prepend(`
Service is running. You can stop it if needed.
`);
+ if (service === "hysteria_normal_sub") {
+ const $normalFormGroups = $("#normal_sub_service_form .form-group");
+ const $normalStartBtn = $("#normal_start");
+ const $normalStopBtn = $("#normal_stop");
+ const $normalAlert = $("#normal_sub_service_form .alert-info");
+ const $normalSubConfigTabLi = $(".normal-sub-config-tab-li");
+
+ if (isRunning) {
+ $normalFormGroups.hide();
+ $normalStartBtn.hide();
+ $normalStopBtn.show();
+ if ($normalAlert.length === 0) {
+ $("#normal_sub_service_form").prepend(`
NormalSub service is running. You can stop it or configure its subpath.
`);
+ }
+ $normalSubConfigTabLi.show();
+ fetchNormalSubPath();
+ } else {
+ $normalFormGroups.show();
+ $normalStartBtn.show();
+ $normalStopBtn.hide();
+ $("#normal_sub_service_form .alert-info").remove();
+ $normalSubConfigTabLi.hide();
+ if ($('#normal-sub-config-link-tab').hasClass('active')) {
+ $('#normal-tab').tab('show');
+ }
+ $("#normal_subpath_input").val("");
+ $("#normal_subpath_input").removeClass('is-invalid');
}
-
- if(service === "hysteria_iplimit"){
+ } else if (service === "hysteria_iplimit") {
+ if (isRunning) {
$("#ip_limit_start").hide();
$("#ip_limit_stop").show();
$(".ip-limit-config-tab-li").show();
- }
-
- } else {
- $(selector + " .form-group").show();
- $(selector + " .btn-success").show();
- $(selector + " .btn-danger").hide();
- $(selector + " .alert-info").remove();
-
- if(service === "hysteria_iplimit"){
+ // TODO: Fetch IP Limit Config and populate fields
+ } else {
$("#ip_limit_start").show();
$("#ip_limit_stop").hide();
$(".ip-limit-config-tab-li").hide();
$('#ip-limit-service-tab').tab('show');
+ // TODO: Clear IP Limit Config fields
+ }
+ } else {
+ if (isRunning) {
+ $(formSelector + " .form-group").hide();
+ $(formSelector + " .btn-success").hide();
+ $(formSelector + " .btn-danger").show();
+ if ($(formSelector + " .alert-info").length === 0) {
+ $(formSelector).prepend(`
Service is running. You can stop it if needed.
`);
+ }
+ } else {
+ $(formSelector + " .form-group").show();
+ $(formSelector + " .btn-success").show();
+ $(formSelector + " .btn-danger").hide();
+ $(formSelector + " .alert-info").remove();
}
}
});
}
+ function fetchNormalSubPath() {
+ $.ajax({
+ url: "{{ url_for('normal_sub_get_subpath_api') }}",
+ type: "GET",
+ success: function (data) {
+ $("#normal_subpath_input").val(data.subpath || "");
+ if (data.subpath) {
+ $("#normal_subpath_input").removeClass('is-invalid');
+ }
+ },
+ error: function (xhr, status, error) {
+ console.error("Failed to fetch NormalSub subpath:", error, xhr.responseText);
+ $("#normal_subpath_input").val("");
+ // Swal.fire("Error!", "Could not fetch NormalSub subpath.", "error"); // Avoid too many popups during init
+ }
+ });
+ }
+
+ function editNormalSubPath() {
+ if (!validateForm('normal_sub_config_form')) return;
+ const subpath = $("#normal_subpath_input").val();
+
+ confirmAction("change the NormalSub subpath to '" + subpath + "'", function () {
+ sendRequest(
+ "{{ url_for('normal_sub_edit_subpath_api') }}",
+ "PUT",
+ { subpath: subpath },
+ "NormalSub subpath updated successfully!",
+ "#normal_subpath_save_btn",
+ false,
+ fetchNormalSubPath
+ );
+ });
+ }
+
function setupDecoy() {
if (!validateForm('decoy_form')) return;
@@ -537,9 +630,9 @@
{ domain: domain, decoy_path: path },
"Decoy site setup initiated successfully!",
"#decoy_setup",
- false
+ false,
+ function() { setTimeout(fetchDecoyStatus, 1000); }
);
- setTimeout(fetchDecoyStatus, 2000);
});
}
@@ -547,13 +640,13 @@
confirmAction("stop the decoy site", function () {
sendRequest(
"{{ url_for('stop_decoy_api') }}",
- "POST",
+ "POST",
null,
"Decoy site stop initiated successfully!",
- "#decoy_stop",
- false
+ "#decoy_stop",
+ false,
+ function() { setTimeout(fetchDecoyStatus, 1000); }
);
- setTimeout(fetchDecoyStatus, 2000);
});
}
@@ -562,7 +655,7 @@
url: "{{ url_for('get_decoy_status_api') }}",
type: "GET",
success: function (data) {
- updateDecoyStatusUI(data);
+ updateDecoyStatusUI(data);
},
error: function (xhr, status, error) {
$("#decoy_status_message").html('
Failed to fetch decoy status.
');
@@ -572,30 +665,37 @@
}
function updateDecoyStatusUI(data) {
+ const $form = $("#decoy_form");
+ const $formGroups = $form.find(".form-group");
+ const $setupBtn = $("#decoy_setup");
+ const $stopBtn = $("#decoy_stop");
+ const $alertInfo = $form.find(".alert-info");
+
if (data.active) {
- $("#decoy_form .form-group").hide();
- $("#decoy_setup").hide();
- $("#decoy_stop").show();
- $("#decoy_form .alert-info").remove();
- if ($("#decoy_form .alert-info").length === 0) {
- $("#decoy_form").prepend(`
Decoy site is running. You can stop it if needed.
`);
- }
+ $formGroups.hide();
+ $setupBtn.hide();
+ $stopBtn.show();
+ if ($alertInfo.length === 0) {
+ $form.prepend(`
Decoy site is running. You can stop it if needed.
`);
+ } else {
+ $alertInfo.text('Decoy site is running. You can stop it if needed.');
+ }
$("#decoy_status_message").html(`
Status: Active
Path: ${data.path || 'N/A'}
`);
} else {
- $("#decoy_form .form-group").show();
- $("#decoy_setup").show();
- $("#decoy_stop").hide();
- $("#decoy_form .alert-info").remove();
+ $formGroups.show();
+ $setupBtn.show();
+ $stopBtn.hide();
+ $alertInfo.remove();
$("#decoy_status_message").html('
Status: Not Active');
}
}
function startTelegram() {
- if (!validateForm('telegram')) return;
+ if (!validateForm('telegram_form')) return;
const apiToken = $("#telegram_api_token").val();
const adminId = $("#telegram_admin_id").val();
confirmAction("start the Telegram bot", function () {
@@ -622,7 +722,7 @@
}
function startNormal() {
- if (!validateForm('normal')) return;
+ if (!validateForm('normal_sub_service_form')) return;
const domain = $("#normal_domain").val();
const port = $("#normal_port").val();
confirmAction("start the normal subscription", function () {
@@ -649,7 +749,7 @@
}
function changePort() {
- if (!validateForm('port')) return;
+ if (!validateForm('port_form')) return;
const port = $("#hysteria_port").val();
const baseUrl = "{{ url_for('set_port_api', port='PORT_PLACEHOLDER') }}";
const url = baseUrl.replace("PORT_PLACEHOLDER", port);
@@ -659,7 +759,7 @@
}
function changeSNI() {
- if (!validateForm('sni')) return;
+ if (!validateForm('sni_form')) return;
const domain = $("#sni_domain").val();
const baseUrl = "{{ url_for('set_sni_api', sni='SNI_PLACEHOLDER') }}";
const url = baseUrl.replace("SNI_PLACEHOLDER", domain);
@@ -669,8 +769,8 @@
}
function saveIP() {
- if (!validateForm('change_ip')) return;
- const ipv4 = $("#ipv4").val().trim() || null;
+ if (!validateForm('change_ip_form')) return;
+ const ipv4 = $("#ipv4").val().trim() || null;
const ipv6 = $("#ipv6").val().trim() || null;
confirmAction("save the new IP settings", function () {
sendRequest(
@@ -713,7 +813,7 @@
progressBar.style.width = '0%';
progressBar.setAttribute('aria-valuenow', 0);
statusDiv.innerText = 'Uploading...';
- statusDiv.className = 'mt-2';
+ statusDiv.className = 'mt-2';
$.ajax({
url: "{{ url_for('restore_api') }}",
@@ -783,14 +883,14 @@
}
function configIPLimit() {
- if (!validateForm('ip_limit_config')) return;
+ if (!validateForm('ip_limit_config_form')) return; // Ensure correct form ID
const blockDuration = $("#block_duration").val();
const maxIps = $("#max_ips").val();
confirmAction("save the IP Limit configuration", function () {
sendRequest(
"{{ url_for('config_ip_limit_api') }}",
"POST",
- { block_duration: parseInt(blockDuration), max_ips: parseInt(maxIps) },
+ { block_duration: parseInt(blockDuration), max_ips: parseInt(maxIps) },
"IP Limit configuration saved successfully!",
"#ip_limit_change_config",
false
@@ -804,6 +904,7 @@
$("#telegram_stop").on("click", stopTelegram);
$("#normal_start").on("click", startNormal);
$("#normal_stop").on("click", stopNormal);
+ $("#normal_subpath_save_btn").on("click", editNormalSubPath);
$("#port_change").on("click", changePort);
$("#sni_change").on("click", changeSNI);
$("#ip_change").on("click", saveIP);
@@ -816,7 +917,6 @@
$("#decoy_stop").on("click", stopDecoy);
-
$('#normal_domain, #sni_domain, #decoy_domain').on('input', function () {
if (isValidDomain($(this).val())) {
$(this).removeClass('is-invalid');
@@ -837,6 +937,16 @@
}
});
+ $('#normal_subpath_input').on('input', function () {
+ if (isValidSubPath($(this).val())) {
+ $(this).removeClass('is-invalid');
+ } else if ($(this).val().trim() !== "") {
+ $(this).addClass('is-invalid');
+ } else {
+ $(this).removeClass('is-invalid');
+ }
+ });
+
$('#ipv4, #ipv6').on('input', function () {
if (isValidIPorDomain($(this).val()) || $(this).val().trim() === '') {
$(this).removeClass('is-invalid');
@@ -852,8 +962,7 @@
$(this).addClass('is-invalid');
}
});
-
- $('#block_duration, #max_ips').on('input', function () {
+ $('#block_duration, #max_ips').on('input', function () {
if (isValidPositiveNumber($(this).val())) {
$(this).removeClass('is-invalid');
} else if ($(this).val().trim() !== "") {
@@ -869,11 +978,10 @@
} else if ($(this).val().trim() !== "") {
$(this).addClass('is-invalid');
} else {
- $(this).removeClass('is-invalid');
+ $(this).removeClass('is-invalid');
}
});
-
});
{% endblock %}
\ No newline at end of file