diff --git a/core/scripts/webpanel/templates/settings.html b/core/scripts/webpanel/templates/settings.html index 63fe536..f4396cb 100644 --- a/core/scripts/webpanel/templates/settings.html +++ b/core/scripts/webpanel/templates/settings.html @@ -131,7 +131,7 @@
-
+
@@ -139,7 +139,7 @@ Please enter a valid API Token.
-
+
@@ -147,8 +147,18 @@ Please enter a valid Admin ID.
+
+ + +
+ Please enter a valid positive number for the interval. +
+
+
@@ -693,7 +703,7 @@ function validateForm(formId) { let isValid = true; - $(`#${formId} .form-control`).each(function () { + $(`#${formId} .form-control:visible`).each(function () { const input = $(this); const id = input.attr('id'); let fieldValid = true; @@ -712,8 +722,12 @@ fieldValid = input.val().trim() !== ""; } else if (id === 'extra_config_uri') { fieldValid = isValidURI(input.val()); - } else if (id === 'block_duration' || id === 'max_ips') { - fieldValid = isValidPositiveNumber(input.val()); + } else if (id === 'block_duration' || id === 'max_ips' || id === 'telegram_backup_interval') { + if (input.val().trim() === '' && id === 'telegram_backup_interval') { + fieldValid = true; + } else { + fieldValid = isValidPositiveNumber(input.val()); + } } else if (id === 'decoy_path') { fieldValid = isValidPath(input.val()); } else { @@ -944,10 +958,27 @@ }; Object.keys(servicesMap).forEach(serviceKey => { - let targetSelector = servicesMap[serviceKey]; let isRunning = data[serviceKey]; - if (serviceKey === "hysteria_normal_sub") { + if (serviceKey === "hysteria_telegram_bot") { + const $form = $("#telegram_form"); + if (isRunning) { + $form.find('[data-group="start-only"]').hide(); + $("#telegram_start").hide(); + $("#telegram_stop").show(); + $("#telegram_save_interval").show(); + if ($form.find(".alert-info").length === 0) { + $form.prepend(`
Service is running. You can stop it or change the backup interval.
`); + } + } else { + $form.find('[data-group="start-only"]').show(); + $("#telegram_start").show(); + $("#telegram_stop").hide(); + $("#telegram_save_interval").hide(); + $form.find(".alert-info").remove(); + } + + } else if (serviceKey === "hysteria_normal_sub") { const $normalForm = $("#normal_sub_service_form"); const $normalFormGroups = $normalForm.find(".form-group"); const $normalStartBtn = $("#normal_start"); @@ -1011,23 +1042,6 @@ $("#warp_config_form")[0].reset(); } } - } else { - const $formSelector = $(targetSelector); - if ($formSelector.length > 0) { - if (isRunning) { - $formSelector.find(".form-group").hide(); - $formSelector.find(".btn-success").hide(); - $formSelector.find(".btn-danger").show(); - if ($formSelector.find(".alert-info").length === 0) { - $formSelector.prepend(`
Service is running. You can stop it if needed.
`); - } - } else { - $formSelector.find(".form-group").show(); - $formSelector.find(".btn-success").show(); - $formSelector.find(".btn-danger").hide(); - $formSelector.find(".alert-info").remove(); - } - } } }); } @@ -1223,11 +1237,21 @@ if (!validateForm('telegram_form')) return; const apiToken = $("#telegram_api_token").val(); const adminId = $("#telegram_admin_id").val(); + let backupInterval = $("#telegram_backup_interval").val(); + + const data = { + token: apiToken, + admin_id: adminId + }; + if (backupInterval) { + data.backup_interval = parseInt(backupInterval); + } + confirmAction("start the Telegram bot", function () { sendRequest( "{{ url_for('telegram_start_api') }}", "POST", - { token: apiToken, admin_id: adminId }, + data, "Telegram bot started successfully!", "#telegram_start" ); @@ -1246,6 +1270,36 @@ }); } + function saveTelegramInterval() { + if (!validateForm('telegram_form')) return; + let backupInterval = $("#telegram_backup_interval").val(); + + if (!backupInterval) { + Swal.fire("Error!", "Backup interval cannot be empty.", "error"); + return; + } + + const data = { + backup_interval: parseInt(backupInterval) + }; + + confirmAction(`change the backup interval to ${backupInterval} hours`, function () { + sendRequest( + "{{ url_for('telegram_set_interval_api') }}", + "POST", + data, + "Backup interval updated successfully!", + "#telegram_save_interval", + false, + function() { + $("#telegram_backup_interval").val(""); + $("#telegram_backup_interval").removeClass("is-invalid"); + } + ); + }); + } + + function startNormal() { if (!validateForm('normal_sub_service_form')) return; const domain = $("#normal_domain").val(); @@ -1528,6 +1582,7 @@ $("#telegram_start").on("click", startTelegram); $("#telegram_stop").on("click", stopTelegram); + $("#telegram_save_interval").on("click", saveTelegramInterval); $("#normal_start").on("click", startNormal); $("#normal_stop").on("click", stopNormal); $("#normal_subpath_save_btn").on("click", editNormalSubPath); @@ -1621,13 +1676,17 @@ $(this).addClass('is-invalid'); } }); - $('#block_duration, #max_ips').on('input', function () { + $('#block_duration, #max_ips, #telegram_backup_interval').on('input', function () { + if ($(this).attr('id') === 'telegram_backup_interval' && $(this).val().trim() === '') { + $(this).removeClass('is-invalid'); + return; + } if (isValidPositiveNumber($(this).val())) { $(this).removeClass('is-invalid'); } else if ($(this).val().trim() !== "") { $(this).addClass('is-invalid'); } else { - $(this).removeClass('is-invalid'); + $(this).addClass('is-invalid'); } }); @@ -1643,4 +1702,4 @@ }); -{% endblock %} +{% endblock %} \ No newline at end of file