mirror of
https://github.com/Sebclem/hassio-nextcloud-backup.git
synced 2024-11-22 09:12:58 +01:00
✏️ Add error detail on config save
This commit is contained in:
parent
c419ab24ea
commit
c9b4b71e85
@ -7,51 +7,48 @@ const default_toast_timeout = 10000;
|
||||
let loadingModal;
|
||||
let nextcloud_setting_modal;
|
||||
let backup_setting_modal;
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
document.addEventListener("DOMContentLoaded", function () {
|
||||
$.ajaxSetup({ traditional: true });
|
||||
updateLocalSnaps();
|
||||
update_status();
|
||||
loadingModal = new bootstrap.Modal(document.getElementById('loading-modal'), {
|
||||
loadingModal = new bootstrap.Modal(document.getElementById("loading-modal"), {
|
||||
keyboard: false,
|
||||
backdrop: 'static'
|
||||
backdrop: "static",
|
||||
});
|
||||
nextcloud_setting_modal = new bootstrap.Modal(document.getElementById('modal-settings-nextcloud'));
|
||||
backup_setting_modal = new bootstrap.Modal(document.getElementById('modal-settings-backup'));
|
||||
nextcloud_setting_modal = new bootstrap.Modal(document.getElementById("modal-settings-nextcloud"));
|
||||
backup_setting_modal = new bootstrap.Modal(document.getElementById("modal-settings-backup"));
|
||||
|
||||
setInterval(update_status, 500);
|
||||
setInterval(updateLocalSnaps, 5000);
|
||||
listeners();
|
||||
|
||||
});
|
||||
|
||||
function updateDynamicListeners() {
|
||||
$('.local-snap-listener').on('click', function () {
|
||||
let id = this.getAttribute('data-id');
|
||||
$(".local-snap-listener").on("click", function () {
|
||||
let id = this.getAttribute("data-id");
|
||||
console.log(id);
|
||||
});
|
||||
let manual_back_list = $('.manual-back-list');
|
||||
let manual_back_list = $(".manual-back-list");
|
||||
manual_back_list.off();
|
||||
manual_back_list.on("click", function () {
|
||||
let id = this.getAttribute('data-id');
|
||||
let name = this.getAttribute('data-name');
|
||||
let id = this.getAttribute("data-id");
|
||||
let name = this.getAttribute("data-name");
|
||||
manualBackup(id, name);
|
||||
})
|
||||
$('.restore').click(function () {
|
||||
let to_restore = this.getAttribute('data-id');
|
||||
console.log(to_restore)
|
||||
restore(to_restore)
|
||||
|
||||
})
|
||||
});
|
||||
$(".restore").click(function () {
|
||||
let to_restore = this.getAttribute("data-id");
|
||||
console.log(to_restore);
|
||||
restore(to_restore);
|
||||
});
|
||||
}
|
||||
|
||||
function updateLocalSnaps() {
|
||||
let needUpdate = false;
|
||||
$.get('./api/formated-local-snap', (data) => {
|
||||
if (JSON.stringify(data) === last_local_snap)
|
||||
return;
|
||||
$.get("./api/formated-local-snap", (data) => {
|
||||
if (JSON.stringify(data) === last_local_snap) return;
|
||||
last_local_snap = JSON.stringify(data);
|
||||
needUpdate = true;
|
||||
let local_snaps = $('#local_snaps');
|
||||
let local_snaps = $("#local_snaps");
|
||||
local_snaps.empty();
|
||||
local_snaps.html(data);
|
||||
}).always(() => {
|
||||
@ -61,15 +58,13 @@ function updateLocalSnaps() {
|
||||
|
||||
function updateManuBackup(prevUpdate) {
|
||||
let needUpdate = false;
|
||||
$.get('./api/formated-backup-manual', (data) => {
|
||||
if (JSON.stringify(data) === last_manu_back)
|
||||
return;
|
||||
$.get("./api/formated-backup-manual", (data) => {
|
||||
if (JSON.stringify(data) === last_manu_back) return;
|
||||
last_manu_back = JSON.stringify(data);
|
||||
needUpdate = true;
|
||||
let manual_backups = $('#manual_backups')
|
||||
let manual_backups = $("#manual_backups");
|
||||
manual_backups.empty();
|
||||
manual_backups.html(data);
|
||||
|
||||
}).always(() => {
|
||||
updateAutoBackup(prevUpdate || needUpdate);
|
||||
});
|
||||
@ -77,157 +72,145 @@ function updateManuBackup(prevUpdate) {
|
||||
|
||||
function updateAutoBackup(prevUpdate) {
|
||||
let needUpdate = false;
|
||||
$.get('./api/formated-backup-auto', (data) => {
|
||||
if (JSON.stringify(data) === last_auto_back)
|
||||
return;
|
||||
$.get("./api/formated-backup-auto", (data) => {
|
||||
if (JSON.stringify(data) === last_auto_back) return;
|
||||
needUpdate = true;
|
||||
last_auto_back = JSON.stringify(data);
|
||||
let auto_backups = $('#auto_backups')
|
||||
let auto_backups = $("#auto_backups");
|
||||
auto_backups.empty();
|
||||
auto_backups.html(data);
|
||||
|
||||
}).always(() => {
|
||||
if (prevUpdate || needUpdate)
|
||||
updateDynamicListeners();
|
||||
if (prevUpdate || needUpdate) updateDynamicListeners();
|
||||
});
|
||||
}
|
||||
|
||||
function update_status() {
|
||||
$.get('./api/status', (data) => {
|
||||
$.get("./api/status", (data) => {
|
||||
if (JSON.stringify(data) !== last_status) {
|
||||
last_status = JSON.stringify(data);
|
||||
let buttons = $('#btn-backup-now, #btn-clean-now');
|
||||
let buttons = $("#btn-backup-now, #btn-clean-now");
|
||||
switch (data.status) {
|
||||
case "error":
|
||||
printStatus('Error', data.message);
|
||||
printStatus("Error", data.message);
|
||||
buttons.removeClass("disabled");
|
||||
break;
|
||||
case "idle":
|
||||
printStatus('Idle', "Waiting for next backup.");
|
||||
printStatus("Idle", "Waiting for next backup.");
|
||||
buttons.removeClass("disabled");
|
||||
break;
|
||||
case "download":
|
||||
printStatusWithBar('Downloading Snapshot', data.progress);
|
||||
printStatusWithBar("Downloading Snapshot", data.progress);
|
||||
buttons.addClass("disabled");
|
||||
break;
|
||||
case "download-b":
|
||||
printStatusWithBar('Downloading Backup', data.progress);
|
||||
printStatusWithBar("Downloading Backup", data.progress);
|
||||
buttons.addClass("disabled");
|
||||
break;
|
||||
case "upload":
|
||||
printStatusWithBar('Uploading Snapshot', data.progress);
|
||||
printStatusWithBar("Uploading Snapshot", data.progress);
|
||||
buttons.addClass("disabled");
|
||||
break;
|
||||
case "upload-b":
|
||||
printStatusWithBar('Uploading Snapshot', data.progress);
|
||||
printStatusWithBar("Uploading Snapshot", data.progress);
|
||||
buttons.addClass("disabled");
|
||||
break;
|
||||
case "creating":
|
||||
printStatusWithBar('Creating Snapshot', data.progress);
|
||||
printStatusWithBar("Creating Snapshot", data.progress);
|
||||
buttons.addClass("disabled");
|
||||
break;
|
||||
case "stopping":
|
||||
printStatusWithBar('Stopping addons', data.progress);
|
||||
printStatusWithBar("Stopping addons", data.progress);
|
||||
buttons.addClass("disabled");
|
||||
break;
|
||||
case "starting":
|
||||
printStatusWithBar('Starting addons', data.progress);
|
||||
printStatusWithBar("Starting addons", data.progress);
|
||||
buttons.addClass("disabled");
|
||||
break;
|
||||
}
|
||||
if (data.last_backup != null) {
|
||||
let last_back_status = $('#last_back_status');
|
||||
if (last_back_status.html() !== data.last_backup)
|
||||
last_back_status.html(data.last_backup);
|
||||
let last_back_status = $("#last_back_status");
|
||||
if (last_back_status.html() !== data.last_backup) last_back_status.html(data.last_backup);
|
||||
}
|
||||
if (data.next_backup != null) {
|
||||
let next_back_status = $('#next_back_status');
|
||||
if (next_back_status.html() !== data.next_backup)
|
||||
next_back_status.html(data.next_backup);
|
||||
let next_back_status = $("#next_back_status");
|
||||
if (next_back_status.html() !== data.next_backup) next_back_status.html(data.next_backup);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
function printStatus(status, secondLine) {
|
||||
let status_jq = $('#status');
|
||||
let status_jq = $("#status");
|
||||
status_jq.empty();
|
||||
status_jq.html(status);
|
||||
let status_s_l_jq = $('#status-second-line');
|
||||
let status_s_l_jq = $("#status-second-line");
|
||||
status_s_l_jq.empty();
|
||||
status_s_l_jq.removeClass('text-center');
|
||||
status_s_l_jq.removeClass("text-center");
|
||||
status_s_l_jq.html(secondLine);
|
||||
$('#progress').addClass("invisible");
|
||||
$("#progress").addClass("invisible");
|
||||
}
|
||||
|
||||
function printStatusWithBar(status, progress) {
|
||||
let status_jq = $('#status')
|
||||
let status_jq = $("#status");
|
||||
status_jq.empty();
|
||||
status_jq.html(status);
|
||||
let secondLine = $('#status-second-line')
|
||||
let secondLine = $("#status-second-line");
|
||||
secondLine.empty();
|
||||
secondLine.html(progress === -1 ? "Waiting..." : (Math.round(progress * 100) + "%"));
|
||||
secondLine.html(progress === -1 ? "Waiting..." : Math.round(progress * 100) + "%");
|
||||
secondLine.addClass("text-center");
|
||||
|
||||
let progressDiv = $('#progress');
|
||||
let progressDiv = $("#progress");
|
||||
progressDiv.removeClass("invisible");
|
||||
if (progress === -1) {
|
||||
progressDiv.children().css('width', "100%");
|
||||
progressDiv.children().addClass('progress-bar-striped progress-bar-animated');
|
||||
progressDiv.children().css("width", "100%");
|
||||
progressDiv.children().addClass("progress-bar-striped progress-bar-animated");
|
||||
} else {
|
||||
progressDiv.children().removeClass('progress-bar-striped progress-bar-animated');
|
||||
progressDiv.children().css('width', (progress * 100) + "%");
|
||||
progressDiv.children().removeClass("progress-bar-striped progress-bar-animated");
|
||||
progressDiv.children().css("width", progress * 100 + "%");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function listeners() {
|
||||
$('#btn-backup-now').on('click', backupNow);
|
||||
$('#btn-clean-now').on('click',cleanNow);
|
||||
$("#btn-backup-now").on("click", backupNow);
|
||||
$("#btn-clean-now").on("click", cleanNow);
|
||||
|
||||
$('#trigger-backup-settings').on('click', getBackupSettings);
|
||||
$('#password_protected').on('change', function () {
|
||||
if (!$(this).is(':checked')) {
|
||||
$('#password_protect_value').parent().parent().addClass('d-none');
|
||||
$("#trigger-backup-settings").on("click", getBackupSettings);
|
||||
$("#password_protected").on("change", function () {
|
||||
if (!$(this).is(":checked")) {
|
||||
$("#password_protect_value").parent().parent().addClass("d-none");
|
||||
} else {
|
||||
$('#password_protect_value').parent().parent().removeClass('d-none');
|
||||
}
|
||||
})
|
||||
$('#cron-drop-settings').on('change', updateDropVisibility);
|
||||
$('#save-backup-settings').click(sendBackupSettings);
|
||||
$('#auto_clean_local').on('change', function () {
|
||||
if (!$(this).is(':checked')) {
|
||||
$('#local-snap-keep').parent().parent().addClass("d-none");
|
||||
} else {
|
||||
$('#local-snap-keep').parent().parent().removeClass("d-none");
|
||||
$("#password_protect_value").parent().parent().removeClass("d-none");
|
||||
}
|
||||
});
|
||||
$('#auto_clean_backup').on('change', function () {
|
||||
if (!$(this).is(':checked')) {
|
||||
$('#backup-snap-keep').parent().parent().addClass("d-none");
|
||||
$("#cron-drop-settings").on("change", updateDropVisibility);
|
||||
$("#save-backup-settings").click(sendBackupSettings);
|
||||
$("#auto_clean_local").on("change", function () {
|
||||
if (!$(this).is(":checked")) {
|
||||
$("#local-snap-keep").parent().parent().addClass("d-none");
|
||||
} else {
|
||||
$('#backup-snap-keep').parent().parent().removeClass("d-none");
|
||||
$("#local-snap-keep").parent().parent().removeClass("d-none");
|
||||
}
|
||||
});
|
||||
$("#auto_clean_backup").on("change", function () {
|
||||
if (!$(this).is(":checked")) {
|
||||
$("#backup-snap-keep").parent().parent().addClass("d-none");
|
||||
} else {
|
||||
$("#backup-snap-keep").parent().parent().removeClass("d-none");
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
$('#trigger-nextcloud-settings').click(getNextcloudSettings);
|
||||
$('#save-nextcloud-settings').click(sendNextcloudSettings);
|
||||
$('#ssl').on('change', function () {
|
||||
let div = $('#self_signed').parent().parent();
|
||||
if ($('#ssl').is(':checked'))
|
||||
div.removeClass("invisible")
|
||||
else
|
||||
div.addClass("invisible");
|
||||
$("#trigger-nextcloud-settings").click(getNextcloudSettings);
|
||||
$("#save-nextcloud-settings").click(sendNextcloudSettings);
|
||||
$("#ssl").on("change", function () {
|
||||
let div = $("#self_signed").parent().parent();
|
||||
if ($("#ssl").is(":checked")) div.removeClass("invisible");
|
||||
else div.addClass("invisible");
|
||||
});
|
||||
}
|
||||
|
||||
function restore(id) {
|
||||
loadingModal.show();
|
||||
$.post('./api/restore', { path: id })
|
||||
$.post("./api/restore", { path: id })
|
||||
.done(() => {
|
||||
console.log("Restore cmd send !");
|
||||
create_toast("success", "Command sent !", default_toast_timeout);
|
||||
@ -236,49 +219,48 @@ function restore(id) {
|
||||
console.log(error);
|
||||
create_toast("error", "Can't send command !", default_toast_timeout);
|
||||
})
|
||||
.always(() => loadingModal.hide())
|
||||
.always(() => loadingModal.hide());
|
||||
}
|
||||
|
||||
function sendNextcloudSettings() {
|
||||
loadingModal.show();
|
||||
nextcloud_setting_modal.hide();
|
||||
let ssl = $('#ssl').is(':checked')
|
||||
let self_signed = $('#self_signed').is(':checked')
|
||||
let hostname = $('#hostname').val();
|
||||
let username = $('#username').val();
|
||||
let password = $('#password').val();
|
||||
let back_dir = $('#back-dir').val();
|
||||
$.post('./api/nextcloud-settings', {
|
||||
let ssl = $("#ssl").is(":checked");
|
||||
let self_signed = $("#self_signed").is(":checked");
|
||||
let hostname = $("#hostname").val();
|
||||
let username = $("#username").val();
|
||||
let password = $("#password").val();
|
||||
let back_dir = $("#back-dir").val();
|
||||
$.post("./api/nextcloud-settings", {
|
||||
ssl: ssl,
|
||||
host: hostname,
|
||||
username: username,
|
||||
password: password,
|
||||
back_dir: back_dir,
|
||||
self_signed: self_signed
|
||||
self_signed: self_signed,
|
||||
})
|
||||
.done(() => {
|
||||
console.log('Saved');
|
||||
$('#nextcloud_settings_message').parent().addClass("d-none");
|
||||
console.log("Saved");
|
||||
$("#nextcloud_settings_message").parent().addClass("d-none");
|
||||
create_toast("success", "Nextcloud settings saved !", default_toast_timeout);
|
||||
0
|
||||
0;
|
||||
})
|
||||
.fail((data) => {
|
||||
let nextcloud_settings_message = $('#nextcloud_settings_message')
|
||||
let nextcloud_settings_message = $("#nextcloud_settings_message");
|
||||
if (data.status === 406) {
|
||||
console.log(data.responseJSON.message);
|
||||
nextcloud_settings_message.html(data.responseJSON.message);
|
||||
|
||||
} else {
|
||||
nextcloud_settings_message.html("Invalid Settings.");
|
||||
|
||||
}
|
||||
nextcloud_settings_message.parent().removeClass("d-none");
|
||||
nextcloud_setting_modal.show();
|
||||
create_toast("error", "Invalid Nextcloud settings !", default_toast_timeout);
|
||||
console.log('Fail');
|
||||
}).always(() => {
|
||||
loadingModal.hide();
|
||||
})
|
||||
console.log("Fail");
|
||||
})
|
||||
.always(() => {
|
||||
loadingModal.hide();
|
||||
});
|
||||
}
|
||||
|
||||
function manualBackup(id, name) {
|
||||
@ -290,40 +272,40 @@ function manualBackup(id, name) {
|
||||
.fail((error) => {
|
||||
console.log(error);
|
||||
create_toast("error", "Can't send command !", default_toast_timeout);
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
function getNextcloudSettings() {
|
||||
loadingModal.show();
|
||||
$.get('./api/nextcloud-settings', (data) => {
|
||||
$('#ssl').prop("checked", data.ssl === "true");
|
||||
let sef_signed_jq = $('#self_signed')
|
||||
$.get("./api/nextcloud-settings", (data) => {
|
||||
$("#ssl").prop("checked", data.ssl === "true");
|
||||
let sef_signed_jq = $("#self_signed");
|
||||
if (data.ssl === "true") {
|
||||
let div = sef_signed_jq.parent().parent();
|
||||
div.removeClass("invisible");
|
||||
}
|
||||
sef_signed_jq.prop('checked', data.self_signed === "true")
|
||||
$('#hostname').val(data.host);
|
||||
$('#username').val(data.username);
|
||||
$('#password').val(data.password);
|
||||
$('#back-dir').val(data.back_dir);
|
||||
sef_signed_jq.prop("checked", data.self_signed === "true");
|
||||
$("#hostname").val(data.host);
|
||||
$("#username").val(data.username);
|
||||
$("#password").val(data.password);
|
||||
$("#back-dir").val(data.back_dir);
|
||||
nextcloud_setting_modal.show();
|
||||
}).fail((error) => {
|
||||
if (error.status === 404)
|
||||
nextcloud_setting_modal.show();
|
||||
else {
|
||||
console.log(error);
|
||||
create_toast("error", "Failed to fetch Nextcloud config !", default_toast_timeout);
|
||||
}
|
||||
}).always(() => {
|
||||
loadingModal.hide();
|
||||
});
|
||||
})
|
||||
.fail((error) => {
|
||||
if (error.status === 404) nextcloud_setting_modal.show();
|
||||
else {
|
||||
console.log(error);
|
||||
create_toast("error", "Failed to fetch Nextcloud config !", default_toast_timeout);
|
||||
}
|
||||
})
|
||||
.always(() => {
|
||||
loadingModal.hide();
|
||||
});
|
||||
}
|
||||
|
||||
function backupNow() {
|
||||
loadingModal.show();
|
||||
$.post('./api/new-backup')
|
||||
$.post("./api/new-backup")
|
||||
.done(() => {
|
||||
create_toast("success", "Command sent !", default_toast_timeout);
|
||||
})
|
||||
@ -333,12 +315,12 @@ function backupNow() {
|
||||
})
|
||||
.always(() => {
|
||||
loadingModal.hide();
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
function cleanNow() {
|
||||
loadingModal.show();
|
||||
$.post('./api/clean-now')
|
||||
$.post("./api/clean-now")
|
||||
.done(() => {
|
||||
create_toast("success", "Command sent !", default_toast_timeout);
|
||||
})
|
||||
@ -348,141 +330,158 @@ function cleanNow() {
|
||||
})
|
||||
.always(() => {
|
||||
loadingModal.hide();
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
function getBackupSettings() {
|
||||
loadingModal.show();
|
||||
$.get('./api/backup-settings', (data) => {
|
||||
$.get("./api/backup-settings", (data) => {
|
||||
if (JSON.stringify(data) === "{}") {
|
||||
data = {
|
||||
cron_base: "0",
|
||||
cron_hour: "00:00",
|
||||
cron_weekday: "0",
|
||||
cron_month_day: "1",
|
||||
auto_clean_local: false,
|
||||
auto_clean_local_keep: 5,
|
||||
auto_clean_backup: false,
|
||||
auto_clean_backup_keep: 5,
|
||||
}
|
||||
settings: {
|
||||
cron_base: "0",
|
||||
cron_hour: "00:00",
|
||||
cron_weekday: "0",
|
||||
cron_month_day: "1",
|
||||
cron_custom: "5 4 * * *",
|
||||
auto_clean_local: false,
|
||||
auto_clean_local_keep: 5,
|
||||
auto_clean_backup: false,
|
||||
auto_clean_backup_keep: 5,
|
||||
}
|
||||
};
|
||||
}
|
||||
if (data.settings.cron_custom == null || data.settings.cron_custom == "") {
|
||||
data.settings.cron_custom = "5 4 * * *";
|
||||
}
|
||||
|
||||
$('#cron-drop-settings').val(data.settings.cron_base);
|
||||
$('#name-template').val(data.settings.name_template);
|
||||
$("#cron-drop-settings").val(data.settings.cron_base);
|
||||
$("#name-template").val(data.settings.name_template);
|
||||
|
||||
$("#timepicker").val(data.settings.cron_hour);
|
||||
$("#cron-drop-day-month-read").val(data.settings.cron_month_day);
|
||||
$("#cron-drop-day-month").val(data.settings.cron_month_day);
|
||||
$("#cron-drop-custom").val(data.settings.cron_custom);
|
||||
|
||||
$('#timepicker').val(data.settings.cron_hour);
|
||||
$('#cron-drop-day-month-read').val(data.settings.cron_month_day);
|
||||
$('#cron-drop-day-month').val(data.settings.cron_month_day);
|
||||
|
||||
|
||||
$('#auto_clean_local').prop('checked', data.settings.auto_clean_local === "true");
|
||||
let local_snap_keep = $('#local-snap-keep');
|
||||
if (data.settings.auto_clean_local === "true")
|
||||
local_snap_keep.parent().parent().removeClass("d-none");
|
||||
else
|
||||
local_snap_keep.parent().parent().addClass("d-none");
|
||||
$("#auto_clean_local").prop("checked", data.settings.auto_clean_local === "true");
|
||||
let local_snap_keep = $("#local-snap-keep");
|
||||
if (data.settings.auto_clean_local === "true") local_snap_keep.parent().parent().removeClass("d-none");
|
||||
else local_snap_keep.parent().parent().addClass("d-none");
|
||||
local_snap_keep.val(data.settings.auto_clean_local_keep);
|
||||
$('#auto_clean_backup').prop('checked', data.settings.auto_clean_backup === "true");
|
||||
let backup_snap_keep = $('#backup-snap-keep');
|
||||
if (data.settings.auto_clean_backup === "true")
|
||||
backup_snap_keep.parent().parent().removeClass("d-none");
|
||||
else
|
||||
backup_snap_keep.parent().parent().addClass("d-none");
|
||||
$("#auto_clean_backup").prop("checked", data.settings.auto_clean_backup === "true");
|
||||
let backup_snap_keep = $("#backup-snap-keep");
|
||||
if (data.settings.auto_clean_backup === "true") backup_snap_keep.parent().parent().removeClass("d-none");
|
||||
else backup_snap_keep.parent().parent().addClass("d-none");
|
||||
backup_snap_keep.val(data.settings.auto_clean_backup_keep);
|
||||
|
||||
$('#cron-drop-day').val(data.settings.cron_weekday);
|
||||
let folder_html = ""
|
||||
$("#cron-drop-day").val(data.settings.cron_weekday);
|
||||
let folder_html = "";
|
||||
for (let thisFolder of data.folders) {
|
||||
let exclude = data.settings.exclude_folder.includes(thisFolder.slug);
|
||||
folder_html += `<li class="list-group-item"><div class="form-check"><input class="form-check-input folders-box" type="checkbox" id="${thisFolder.slug}" ${exclude ? "" : "checked"}><label class="form-label mb-0" for="${thisFolder.slug}">${thisFolder.name}</label></div></li>`
|
||||
folder_html += `<li class="list-group-item"><div class="form-check"><input class="form-check-input folders-box" type="checkbox" id="${
|
||||
thisFolder.slug
|
||||
}" ${exclude ? "" : "checked"}><label class="form-label mb-0" for="${thisFolder.slug}">${thisFolder.name}</label></div></li>`;
|
||||
}
|
||||
$("#folders-div").html(folder_html);
|
||||
|
||||
let addons_html = ""
|
||||
let addons_html = "";
|
||||
for (let thisAddon of data.addonList) {
|
||||
let exclude = data.settings.exclude_addon.includes(thisAddon.slug);
|
||||
addons_html += `<li class="list-group-item"><div class="form-check"><input class="form-check-input addons-box" type="checkbox" id="${thisAddon.slug}" ${exclude ? "" : "checked"}><label class="form-label mb-0" for="${thisAddon.slug}">${thisAddon.name}</label></div></li>`
|
||||
addons_html += `<li class="list-group-item"><div class="form-check"><input class="form-check-input addons-box" type="checkbox" id="${
|
||||
thisAddon.slug
|
||||
}" ${exclude ? "" : "checked"}><label class="form-label mb-0" for="${thisAddon.slug}">${thisAddon.name}</label></div></li>`;
|
||||
}
|
||||
$("#addons-div").html(addons_html);
|
||||
|
||||
let addons_stop_html = ""
|
||||
let addons_stop_html = "";
|
||||
for (let thisAddon of data.addonList) {
|
||||
if (thisAddon.slug !== "229cc4d7_nextcloud_backup"){
|
||||
if (thisAddon.slug !== "229cc4d7_nextcloud_backup") {
|
||||
let on = data.settings.auto_stop_addon.includes(thisAddon.slug);
|
||||
addons_stop_html += `<li class="list-group-item"><div class="form-check"><input class="form-check-input stop-addons-box" type="checkbox" id="${thisAddon.slug}" ${on ? "checked" : ""}><label class="form-label mb-0" for="${thisAddon.slug}">${thisAddon.name}</label></div></li>`
|
||||
addons_stop_html += `<li class="list-group-item"><div class="form-check"><input class="form-check-input stop-addons-box" type="checkbox" id="${
|
||||
thisAddon.slug
|
||||
}" ${on ? "checked" : ""}><label class="form-label mb-0" for="${thisAddon.slug}">${thisAddon.name}</label></div></li>`;
|
||||
}
|
||||
}
|
||||
$("#auto-stop-addons-div").html(addons_stop_html);
|
||||
|
||||
updateDropVisibility();
|
||||
backup_setting_modal.show();
|
||||
|
||||
|
||||
}).fail((error) => {
|
||||
console.log(error);
|
||||
create_toast("error", "Failed to fetch Nextcloud config !", default_toast_timeout);
|
||||
}).always(() => {
|
||||
loadingModal.hide();
|
||||
});
|
||||
|
||||
})
|
||||
.fail((error) => {
|
||||
console.log(error);
|
||||
create_toast("error", "Failed to fetch Nextcloud config !", default_toast_timeout);
|
||||
})
|
||||
.always(() => {
|
||||
loadingModal.hide();
|
||||
});
|
||||
}
|
||||
|
||||
function updateDropVisibility() {
|
||||
let cronBase = $("#cron-drop-settings").val();
|
||||
let timepicker = $('#timepicker');
|
||||
let cron_drop_day = $('#cron-drop-day');
|
||||
let cron_drop_day_mount = $('#cron-drop-day-month');
|
||||
let timepicker = $("#timepicker");
|
||||
let cron_drop_day = $("#cron-drop-day");
|
||||
let cron_drop_day_mount = $("#cron-drop-day-month");
|
||||
let cron_drop_custom = $("#cron-drop-custom");
|
||||
switch (cronBase) {
|
||||
case "4":
|
||||
timepicker.parent().parent().addClass("d-none");
|
||||
cron_drop_day.parent().parent().addClass("d-none");
|
||||
cron_drop_day_mount.parent().parent().addClass("d-none");
|
||||
cron_drop_custom.parent().parent().removeClass("d-none");
|
||||
break;
|
||||
case "3":
|
||||
timepicker.parent().parent().removeClass("d-none");
|
||||
cron_drop_day.parent().parent().addClass("d-none");
|
||||
cron_drop_day_mount.parent().parent().removeClass("d-none");
|
||||
|
||||
cron_drop_custom.parent().parent().addClass("d-none");
|
||||
break;
|
||||
case "2":
|
||||
timepicker.parent().parent().removeClass("d-none");
|
||||
cron_drop_day.parent().parent().removeClass("d-none");
|
||||
cron_drop_day_mount.parent().parent().addClass("d-none");
|
||||
cron_drop_custom.parent().parent().addClass("d-none");
|
||||
break;
|
||||
case "1":
|
||||
timepicker.parent().parent().removeClass("d-none");
|
||||
cron_drop_day.parent().parent().addClass("d-none");
|
||||
cron_drop_day_mount.parent().parent().addClass("d-none");
|
||||
cron_drop_custom.parent().parent().addClass("d-none");
|
||||
break;
|
||||
case "0":
|
||||
timepicker.parent().parent().addClass("d-none");
|
||||
cron_drop_day.parent().parent().addClass("d-none");
|
||||
cron_drop_day_mount.parent().parent().addClass("d-none");
|
||||
cron_drop_custom.parent().parent().addClass("d-none");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
function sendBackupSettings() {
|
||||
let cron_month_day = $('#cron-drop-day-month').val();
|
||||
let cron_weekday = $('#cron-drop-day').val();
|
||||
let cron_hour = $('#timepicker').val();
|
||||
let cron_base = $('#cron-drop-settings').val();
|
||||
let auto_clean_local = $("#auto_clean_local").is(':checked');
|
||||
let auto_clean_backup = $("#auto_clean_backup").is(':checked');
|
||||
let cron_month_day = $("#cron-drop-day-month").val();
|
||||
let cron_weekday = $("#cron-drop-day").val();
|
||||
let cron_hour = $("#timepicker").val();
|
||||
let cron_custom = $("#cron-drop-custom").val();
|
||||
let cron_base = $("#cron-drop-settings").val();
|
||||
let auto_clean_local = $("#auto_clean_local").is(":checked");
|
||||
let auto_clean_backup = $("#auto_clean_backup").is(":checked");
|
||||
let auto_clean_local_keep = $("#local-snap-keep").val();
|
||||
let auto_clean_backup_keep = $("#backup-snap-keep").val();
|
||||
let name_template = $('#name-template').val();
|
||||
let excluded_folders_nodes = document.querySelectorAll('.folders-box:not(:checked)');
|
||||
let name_template = $("#name-template").val();
|
||||
let excluded_folders_nodes = document.querySelectorAll(".folders-box:not(:checked)");
|
||||
let exclude_folder = [""];
|
||||
let password_protected = $('#password_protected').is(':checked');
|
||||
let password_protect_value = $('#password_protect_value').val();
|
||||
let password_protected = $("#password_protected").is(":checked");
|
||||
let password_protect_value = $("#password_protect_value").val();
|
||||
for (let i of excluded_folders_nodes) {
|
||||
exclude_folder.push(i.id);
|
||||
}
|
||||
|
||||
let excluded_addons_nodes = document.querySelectorAll('.addons-box:not(:checked)');
|
||||
let excluded_addons_nodes = document.querySelectorAll(".addons-box:not(:checked)");
|
||||
let exclude_addon = [""];
|
||||
for (let i of excluded_addons_nodes) {
|
||||
exclude_addon.push(i.id);
|
||||
}
|
||||
|
||||
let stop_addons_nodes = document.querySelectorAll('.stop-addons-box:checked');
|
||||
let stop_addons_nodes = document.querySelectorAll(".stop-addons-box:checked");
|
||||
let stop_addon = [""];
|
||||
for (let i of stop_addons_nodes) {
|
||||
stop_addon.push(i.id);
|
||||
@ -490,29 +489,29 @@ function sendBackupSettings() {
|
||||
|
||||
loadingModal.show();
|
||||
backup_setting_modal.hide();
|
||||
$.post('./api/backup-settings',
|
||||
{
|
||||
name_template: name_template,
|
||||
cron_base: cron_base,
|
||||
cron_hour: cron_hour,
|
||||
cron_weekday: cron_weekday,
|
||||
cron_month_day: cron_month_day,
|
||||
auto_clean_local: auto_clean_local,
|
||||
auto_clean_local_keep: auto_clean_local_keep,
|
||||
auto_clean_backup: auto_clean_backup,
|
||||
auto_clean_backup_keep: auto_clean_backup_keep,
|
||||
exclude_addon: exclude_addon,
|
||||
exclude_folder: exclude_folder,
|
||||
auto_stop_addon: stop_addon,
|
||||
password_protected: password_protected,
|
||||
password_protect_value: password_protect_value
|
||||
})
|
||||
$.post("./api/backup-settings", {
|
||||
name_template: name_template,
|
||||
cron_base: cron_base,
|
||||
cron_hour: cron_hour,
|
||||
cron_weekday: cron_weekday,
|
||||
cron_month_day: cron_month_day,
|
||||
cron_custom: cron_custom,
|
||||
auto_clean_local: auto_clean_local,
|
||||
auto_clean_local_keep: auto_clean_local_keep,
|
||||
auto_clean_backup: auto_clean_backup,
|
||||
auto_clean_backup_keep: auto_clean_backup_keep,
|
||||
exclude_addon: exclude_addon,
|
||||
exclude_folder: exclude_folder,
|
||||
auto_stop_addon: stop_addon,
|
||||
password_protected: password_protected,
|
||||
password_protect_value: password_protect_value,
|
||||
})
|
||||
.done(() => {
|
||||
create_toast("success", "Backup settings saved !", default_toast_timeout);
|
||||
|
||||
})
|
||||
.fail(() => {
|
||||
create_toast("error", "Can't save backup settings !", default_toast_timeout);
|
||||
.fail((data) => {
|
||||
debugger
|
||||
create_toast("error", `Can't save backup settings ! <br> Error: ${data.responseText}`, default_toast_timeout);
|
||||
backup_setting_modal.show();
|
||||
})
|
||||
.always(() => {
|
||||
|
@ -188,13 +188,14 @@ router.get("/backup-settings", function (req, res, next) {
|
||||
});
|
||||
|
||||
router.post("/backup-settings", function (req, res, next) {
|
||||
if (settingsTools.check(req.body)) {
|
||||
let [result, message] = settingsTools.check(req.body)
|
||||
if (result) {
|
||||
settingsTools.setSettings(req.body);
|
||||
cronTools.startCron();
|
||||
res.send();
|
||||
} else {
|
||||
res.status(400);
|
||||
res.send();
|
||||
res.send(message);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
const fs = require("fs");
|
||||
const logger = require("../config/winston");
|
||||
const moment = require('moment')
|
||||
const moment = require("moment");
|
||||
|
||||
const settingsPath = "/data/backup_conf.json";
|
||||
|
||||
@ -26,143 +26,140 @@ function check_cron(conf) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
function check(conf, fallback = false) {
|
||||
let needSave = false;
|
||||
if (!check_cron(conf)) {
|
||||
if (fallback) {
|
||||
logger.warn("Bad value for cron settings, fallback to default ")
|
||||
logger.warn("Bad value for cron settings, fallback to default ");
|
||||
conf.cron_base = "0";
|
||||
conf.cron_hour = "00:00",
|
||||
conf.cron_weekday = "0",
|
||||
conf.cron_month_day = "1"
|
||||
conf.cron_hour = "00:00";
|
||||
conf.cron_weekday = "0";
|
||||
conf.cron_month_day = "1";
|
||||
} else {
|
||||
logger.error("Bad value for cron settings")
|
||||
return false;
|
||||
logger.error("Bad value for cron settings");
|
||||
return [false, "Bad cron settings"];
|
||||
}
|
||||
}
|
||||
if (conf.name_template == null) {
|
||||
if (fallback) {
|
||||
logger.warn("Bad value for 'name_template', fallback to default ")
|
||||
conf.name_template = "{type}-{ha_version}-{date}_{hour}"
|
||||
logger.warn("Bad value for 'name_template', fallback to default ");
|
||||
conf.name_template = "{type}-{ha_version}-{date}_{hour}";
|
||||
} else {
|
||||
logger.error("Bad value for 'name_template'")
|
||||
return false;
|
||||
logger.error("Bad value for 'name_template'");
|
||||
return [false, "Bad value for 'name_template'"];
|
||||
}
|
||||
}
|
||||
if (conf.auto_clean_local_keep == null || !/^\d+$/.test(conf.auto_clean_local_keep)) {
|
||||
|
||||
if (fallback) {
|
||||
logger.warn("Bad value for 'auto_clean_local_keep', fallback to 5 ")
|
||||
conf.auto_clean_local_keep = "5"
|
||||
logger.warn("Bad value for 'auto_clean_local_keep', fallback to 5 ");
|
||||
conf.auto_clean_local_keep = "5";
|
||||
} else {
|
||||
logger.error("Bad value for 'auto_clean_local_keep'")
|
||||
return false;
|
||||
logger.error("Bad value for 'auto_clean_local_keep'");
|
||||
return [false, "Bad value for 'auto_clean_local_keep'"];
|
||||
}
|
||||
}
|
||||
if (conf.auto_clean_backup_keep == null || !/^\d+$/.test(conf.auto_clean_backup_keep)) {
|
||||
if (fallback) {
|
||||
logger.warn("Bad value for 'auto_clean_backup_keep', fallback to 5 ")
|
||||
conf.auto_clean_backup_keep = "5"
|
||||
logger.warn("Bad value for 'auto_clean_backup_keep', fallback to 5 ");
|
||||
conf.auto_clean_backup_keep = "5";
|
||||
} else {
|
||||
logger.error("Bad value for 'auto_clean_backup_keep'")
|
||||
return false;
|
||||
logger.error("Bad value for 'auto_clean_backup_keep'");
|
||||
return [false, "Bad value for 'auto_clean_backup_keep'"];
|
||||
}
|
||||
}
|
||||
if (conf.auto_clean_local == null) {
|
||||
if (fallback) {
|
||||
logger.warn("Bad value for 'auto_clean_local', fallback to false ")
|
||||
conf.auto_clean_local = "false"
|
||||
logger.warn("Bad value for 'auto_clean_local', fallback to false ");
|
||||
conf.auto_clean_local = "false";
|
||||
} else {
|
||||
logger.error("Bad value for 'auto_clean_local'")
|
||||
return false;
|
||||
logger.error("Bad value for 'auto_clean_local'");
|
||||
return [false, "Bad value for 'auto_clean_local'"];
|
||||
}
|
||||
}
|
||||
if (conf.auto_clean_backup == null) {
|
||||
if (fallback) {
|
||||
logger.warn("Bad value for 'auto_clean_backup', fallback to false ")
|
||||
conf.auto_clean_backup = "false"
|
||||
logger.warn("Bad value for 'auto_clean_backup', fallback to false ");
|
||||
conf.auto_clean_backup = "false";
|
||||
} else {
|
||||
logger.error("Bad value for 'auto_clean_backup'")
|
||||
return false;
|
||||
logger.error("Bad value for 'auto_clean_backup'");
|
||||
return [false, "Bad value for 'auto_clean_backup'"];
|
||||
}
|
||||
}
|
||||
if (conf.exclude_addon == null) {
|
||||
if (fallback) {
|
||||
logger.warn("Bad value for 'exclude_addon', fallback to [] ")
|
||||
conf.exclude_addon = []
|
||||
logger.warn("Bad value for 'exclude_addon', fallback to [] ");
|
||||
conf.exclude_addon = [];
|
||||
} else {
|
||||
logger.error("Bad value for 'exclude_addon'")
|
||||
return false;
|
||||
logger.error("Bad value for 'exclude_addon'");
|
||||
return [false, "Bad value for 'exclude_addon'"];
|
||||
}
|
||||
}
|
||||
if (conf.exclude_folder == null) {
|
||||
if (fallback) {
|
||||
logger.warn("Bad value for 'exclude_folder', fallback to [] ")
|
||||
conf.exclude_folder = []
|
||||
logger.warn("Bad value for 'exclude_folder', fallback to [] ");
|
||||
conf.exclude_folder = [];
|
||||
} else {
|
||||
logger.error("Bad value for 'exclude_folder'")
|
||||
return false;
|
||||
logger.error("Bad value for 'exclude_folder'");
|
||||
return [false, "Bad value for 'exclude_folder'"];
|
||||
}
|
||||
}
|
||||
if (conf.auto_stop_addon == null) {
|
||||
if (fallback) {
|
||||
logger.warn("Bad value for 'auto_stop_addon', fallback to [] ")
|
||||
conf.auto_stop_addon = []
|
||||
logger.warn("Bad value for 'auto_stop_addon', fallback to [] ");
|
||||
conf.auto_stop_addon = [];
|
||||
} else {
|
||||
logger.error("Bad value for 'auto_stop_addon'")
|
||||
return false;
|
||||
logger.error("Bad value for 'auto_stop_addon'");
|
||||
return [false, "Bad value for 'auto_stop_addon'"];
|
||||
}
|
||||
}
|
||||
|
||||
if (!Array.isArray(conf.exclude_folder)) {
|
||||
logger.debug("exclude_folder is not array (Empty value), reset...");
|
||||
conf.exclude_folder = []
|
||||
conf.exclude_folder = [];
|
||||
needSave = true;
|
||||
}
|
||||
if (!Array.isArray(conf.exclude_addon)) {
|
||||
logger.debug("exclude_addon is not array (Empty value), reset...");
|
||||
conf.exclude_addon = []
|
||||
conf.exclude_addon = [];
|
||||
needSave = true;
|
||||
}
|
||||
if(conf.password_protected == null){
|
||||
if (conf.password_protected == null) {
|
||||
if (fallback) {
|
||||
logger.warn("Bad value for 'password_protected', fallback to false ");
|
||||
conf.password_protected = 'false';
|
||||
conf.password_protected = "false";
|
||||
} else {
|
||||
logger.error("Bad value for 'password_protect_value'");
|
||||
return false;
|
||||
return [false, "Bad value for 'password_protect_value'"];
|
||||
}
|
||||
}
|
||||
|
||||
if(conf.password_protect_value == null){
|
||||
if (conf.password_protect_value == null) {
|
||||
if (fallback) {
|
||||
logger.warn("Bad value for 'password_protect_value', fallback to '' ");
|
||||
conf.password_protect_value = '';
|
||||
conf.password_protect_value = "";
|
||||
} else {
|
||||
logger.error("Bad value for 'password_protect_value'");
|
||||
return false;
|
||||
return [false, "Bad value for 'password_protect_value'"];
|
||||
}
|
||||
}
|
||||
|
||||
if (fallback || needSave) {
|
||||
setSettings(conf);
|
||||
}
|
||||
return true
|
||||
|
||||
return [true, null];
|
||||
}
|
||||
|
||||
function getFormatedName(is_manual, ha_version) {
|
||||
let setting = getSettings();
|
||||
let template = setting.name_template;
|
||||
template = template.replace('{type_low}', is_manual ? 'manual' : 'auto');
|
||||
template = template.replace('{type}', is_manual ? 'Manual' : 'Auto');
|
||||
template = template.replace('{ha_version}', ha_version);
|
||||
let mmt = moment()
|
||||
template = template.replace('{hour_12}', mmt.format('hhmmA'));
|
||||
template = template.replace('{hour}', mmt.format('HHmm'));
|
||||
template = template.replace('{date}', mmt.format('YYYY-MM-DD'));
|
||||
return template
|
||||
template = template.replace("{type_low}", is_manual ? "manual" : "auto");
|
||||
template = template.replace("{type}", is_manual ? "Manual" : "Auto");
|
||||
template = template.replace("{ha_version}", ha_version);
|
||||
let mmt = moment();
|
||||
template = template.replace("{hour_12}", mmt.format("hhmmA"));
|
||||
template = template.replace("{hour}", mmt.format("HHmm"));
|
||||
template = template.replace("{date}", mmt.format("YYYY-MM-DD"));
|
||||
return template;
|
||||
}
|
||||
|
||||
function getSettings() {
|
||||
|
Loading…
Reference in New Issue
Block a user