2022-04-29 21:32:57 -04:00
|
|
|
|
let LANG = {
|
|
|
|
|
Add: "添加",
|
|
|
|
|
Edit: "修改",
|
|
|
|
|
AlarmRule: "报警规则",
|
|
|
|
|
Notification: "通知方式",
|
|
|
|
|
Server: "服务器",
|
|
|
|
|
Monitor: "监控",
|
|
|
|
|
Cron: "计划任务",
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function updateLang(newLang) {
|
|
|
|
|
if (newLang) {
|
|
|
|
|
LANG = newLang;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-10 04:57:57 -05:00
|
|
|
|
function readableBytes(bytes) {
|
2021-06-30 06:15:53 -04:00
|
|
|
|
if (!bytes) {
|
|
|
|
|
return '0B'
|
|
|
|
|
}
|
2021-04-22 09:53:31 -04:00
|
|
|
|
var i = Math.floor(Math.log(bytes) / Math.log(1024)),
|
|
|
|
|
sizes = ["B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
|
2021-06-30 06:15:53 -04:00
|
|
|
|
return parseFloat((bytes / Math.pow(1024, i)).toFixed(2)) + sizes[i];
|
2019-12-10 04:57:57 -05:00
|
|
|
|
}
|
|
|
|
|
|
2021-08-05 23:48:34 -04:00
|
|
|
|
const confirmBtn = $(".mini.confirm.modal .nezha-primary-btn.button");
|
2019-12-09 05:14:31 -05:00
|
|
|
|
|
2019-12-08 03:59:58 -05:00
|
|
|
|
function showConfirm(title, content, callFn, extData) {
|
2021-04-22 09:53:31 -04:00
|
|
|
|
const modal = $(".mini.confirm.modal");
|
|
|
|
|
modal.children(".header").text(title);
|
|
|
|
|
modal.children(".content").text(content);
|
|
|
|
|
if (confirmBtn.hasClass("loading")) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
modal
|
|
|
|
|
.modal({
|
|
|
|
|
closable: true,
|
|
|
|
|
onApprove: function () {
|
|
|
|
|
confirmBtn.toggleClass("loading");
|
|
|
|
|
callFn(extData);
|
|
|
|
|
return false;
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
.modal("show");
|
2019-12-08 03:59:58 -05:00
|
|
|
|
}
|
|
|
|
|
|
2023-06-13 12:23:47 -04:00
|
|
|
|
function postJson(url, data) {
|
|
|
|
|
return $.ajax({
|
|
|
|
|
url: url,
|
|
|
|
|
type: "POST",
|
|
|
|
|
contentType: "application/json",
|
|
|
|
|
data: JSON.stringify(data),
|
|
|
|
|
}).done((resp) => {
|
|
|
|
|
if (resp.code == 200) {
|
|
|
|
|
if (resp.message) {
|
|
|
|
|
alert(resp.message);
|
|
|
|
|
} else {
|
|
|
|
|
alert("删除成功");
|
|
|
|
|
}
|
|
|
|
|
window.location.reload();
|
|
|
|
|
} else {
|
|
|
|
|
alert("删除失败 " + resp.code + ":" + resp.message);
|
|
|
|
|
confirmBtn.toggleClass("loading");
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.fail((err) => {
|
|
|
|
|
alert("网络错误:" + err.responseText);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-08 03:59:58 -05:00
|
|
|
|
function showFormModal(modelSelector, formID, URL, getData) {
|
2021-04-22 09:53:31 -04:00
|
|
|
|
$(modelSelector)
|
|
|
|
|
.modal({
|
|
|
|
|
closable: true,
|
|
|
|
|
onApprove: function () {
|
|
|
|
|
let success = false;
|
2021-08-05 23:48:34 -04:00
|
|
|
|
const btn = $(modelSelector + " .nezha-primary-btn.button");
|
2021-04-22 09:53:31 -04:00
|
|
|
|
const form = $(modelSelector + " form");
|
|
|
|
|
if (btn.hasClass("loading")) {
|
|
|
|
|
return success;
|
|
|
|
|
}
|
|
|
|
|
form.children(".message").remove();
|
|
|
|
|
btn.toggleClass("loading");
|
|
|
|
|
const data = getData
|
|
|
|
|
? getData()
|
|
|
|
|
: $(formID)
|
2021-06-21 09:30:42 -04:00
|
|
|
|
.serializeArray()
|
|
|
|
|
.reduce(function (obj, item) {
|
|
|
|
|
// ID 类的数据
|
|
|
|
|
if (
|
|
|
|
|
item.name.endsWith("_id") ||
|
|
|
|
|
item.name === "id" ||
|
|
|
|
|
item.name === "ID" ||
|
|
|
|
|
item.name === "RequestType" ||
|
|
|
|
|
item.name === "RequestMethod" ||
|
2022-09-12 16:02:34 -04:00
|
|
|
|
item.name === "TriggerMode" ||
|
2022-09-13 23:32:15 -04:00
|
|
|
|
item.name === "TaskType" ||
|
2021-06-21 09:30:42 -04:00
|
|
|
|
item.name === "DisplayIndex" ||
|
|
|
|
|
item.name === "Type" ||
|
2021-09-02 11:45:21 -04:00
|
|
|
|
item.name === "Cover" ||
|
|
|
|
|
item.name === "Duration"
|
2021-06-21 09:30:42 -04:00
|
|
|
|
) {
|
|
|
|
|
obj[item.name] = parseInt(item.value);
|
2022-09-16 22:30:32 -04:00
|
|
|
|
} else if (item.name.endsWith("Latency")) {
|
|
|
|
|
obj[item.name] = parseFloat(item.value);
|
2021-06-21 09:30:42 -04:00
|
|
|
|
} else {
|
|
|
|
|
obj[item.name] = item.value;
|
|
|
|
|
}
|
2021-01-20 09:15:47 -05:00
|
|
|
|
|
2021-06-21 09:30:42 -04:00
|
|
|
|
if (item.name.endsWith("ServersRaw")) {
|
|
|
|
|
if (item.value.length > 2) {
|
|
|
|
|
obj[item.name] = JSON.stringify(
|
|
|
|
|
[...item.value.matchAll(/\d+/gm)].map((k) =>
|
|
|
|
|
parseInt(k[0])
|
|
|
|
|
)
|
|
|
|
|
);
|
2021-01-20 09:15:47 -05:00
|
|
|
|
}
|
2021-06-21 09:30:42 -04:00
|
|
|
|
}
|
2021-01-20 09:15:47 -05:00
|
|
|
|
|
2022-09-13 23:32:15 -04:00
|
|
|
|
if (item.name.endsWith("TasksRaw")) {
|
|
|
|
|
if (item.value.length > 2) {
|
|
|
|
|
obj[item.name] = JSON.stringify(
|
2022-09-16 22:30:32 -04:00
|
|
|
|
[...item.value.matchAll(/\d+/gm)].map((k) =>
|
|
|
|
|
parseInt(k[0])
|
|
|
|
|
)
|
2022-09-13 23:32:15 -04:00
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-21 09:30:42 -04:00
|
|
|
|
return obj;
|
|
|
|
|
}, {});
|
2021-04-22 09:53:31 -04:00
|
|
|
|
$.post(URL, JSON.stringify(data))
|
|
|
|
|
.done(function (resp) {
|
|
|
|
|
if (resp.code == 200) {
|
2021-06-21 09:30:42 -04:00
|
|
|
|
window.location.reload()
|
2021-04-22 09:53:31 -04:00
|
|
|
|
} else {
|
|
|
|
|
form.append(
|
|
|
|
|
`<div class="ui negative message"><div class="header">操作失败</div><p>` +
|
2021-06-21 09:30:42 -04:00
|
|
|
|
resp.message +
|
|
|
|
|
`</p></div>`
|
2021-04-22 09:53:31 -04:00
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.fail(function (err) {
|
|
|
|
|
form.append(
|
|
|
|
|
`<div class="ui negative message"><div class="header">网络错误</div><p>` +
|
2021-06-21 09:30:42 -04:00
|
|
|
|
err.responseText +
|
|
|
|
|
`</p></div>`
|
2021-04-22 09:53:31 -04:00
|
|
|
|
);
|
|
|
|
|
})
|
|
|
|
|
.always(function () {
|
|
|
|
|
btn.toggleClass("loading");
|
|
|
|
|
});
|
|
|
|
|
return success;
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
.modal("show");
|
2019-12-08 03:59:58 -05:00
|
|
|
|
}
|
|
|
|
|
|
2020-12-19 10:11:16 -05:00
|
|
|
|
function addOrEditAlertRule(rule) {
|
2021-04-22 09:53:31 -04:00
|
|
|
|
const modal = $(".rule.modal");
|
2022-04-29 21:32:57 -04:00
|
|
|
|
modal.children(".header").text((rule ? LANG.Edit : LANG.Add) + ' ' + LANG.AlarmRule);
|
2021-04-22 09:53:31 -04:00
|
|
|
|
modal
|
2021-08-05 23:48:34 -04:00
|
|
|
|
.find(".nezha-primary-btn.button")
|
2021-04-22 09:53:31 -04:00
|
|
|
|
.html(
|
2022-04-29 21:32:57 -04:00
|
|
|
|
rule ? LANG.Edit + '<i class="edit icon"></i>' : LANG.Add + '<i class="add icon"></i>'
|
2021-04-22 09:53:31 -04:00
|
|
|
|
);
|
|
|
|
|
modal.find("input[name=ID]").val(rule ? rule.ID : null);
|
|
|
|
|
modal.find("input[name=Name]").val(rule ? rule.Name : null);
|
|
|
|
|
modal.find("textarea[name=RulesRaw]").val(rule ? rule.RulesRaw : null);
|
2022-09-12 16:02:34 -04:00
|
|
|
|
modal.find("select[name=TriggerMode]").val(rule ? rule.TriggerMode : 0);
|
2022-04-14 22:56:04 -04:00
|
|
|
|
modal.find("input[name=NotificationTag]").val(rule ? rule.NotificationTag : null);
|
2021-04-22 09:53:31 -04:00
|
|
|
|
if (rule && rule.Enable) {
|
|
|
|
|
modal.find(".ui.rule-enable.checkbox").checkbox("set checked");
|
|
|
|
|
} else {
|
|
|
|
|
modal.find(".ui.rule-enable.checkbox").checkbox("set unchecked");
|
|
|
|
|
}
|
2022-09-13 23:32:15 -04:00
|
|
|
|
modal.find("a.ui.label.visible").each((i, el) => {
|
|
|
|
|
el.remove();
|
|
|
|
|
});
|
|
|
|
|
var failTriggerTasks;
|
|
|
|
|
var recoverTriggerTasks;
|
|
|
|
|
if (rule) {
|
|
|
|
|
failTriggerTasks = rule.FailTriggerTasksRaw;
|
|
|
|
|
recoverTriggerTasks = rule.RecoverTriggerTasksRaw;
|
|
|
|
|
const failTriggerTasksList = JSON.parse(failTriggerTasks || "[]");
|
|
|
|
|
const recoverTriggerTasksList = JSON.parse(recoverTriggerTasks || "[]");
|
|
|
|
|
const node1 = modal.find("i.dropdown.icon.1");
|
|
|
|
|
const node2 = modal.find("i.dropdown.icon.2");
|
|
|
|
|
for (let i = 0; i < failTriggerTasksList.length; i++) {
|
|
|
|
|
node1.after(
|
2022-09-16 22:30:32 -04:00
|
|
|
|
'<a class="ui label transition visible" data-value="' +
|
|
|
|
|
failTriggerTasksList[i] +
|
|
|
|
|
'" style="display: inline-block !important;">ID:' +
|
|
|
|
|
failTriggerTasksList[i] +
|
|
|
|
|
'<i class="delete icon"></i></a>'
|
2022-09-13 23:32:15 -04:00
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
for (let i = 0; i < recoverTriggerTasksList.length; i++) {
|
|
|
|
|
node2.after(
|
2022-09-16 22:30:32 -04:00
|
|
|
|
'<a class="ui label transition visible" data-value="' +
|
|
|
|
|
recoverTriggerTasksList[i] +
|
|
|
|
|
'" style="display: inline-block !important;">ID:' +
|
|
|
|
|
recoverTriggerTasksList[i] +
|
|
|
|
|
'<i class="delete icon"></i></a>'
|
2022-09-13 23:32:15 -04:00
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
modal
|
2022-09-16 22:30:32 -04:00
|
|
|
|
.find("input[name=FailTriggerTasksRaw]")
|
|
|
|
|
.val(rule ? "[]," + failTriggerTasks.substr(1, failTriggerTasks.length - 2) : "[]");
|
2022-09-13 23:32:15 -04:00
|
|
|
|
modal
|
2022-09-16 22:30:32 -04:00
|
|
|
|
.find("input[name=RecoverTriggerTasksRaw]")
|
|
|
|
|
.val(rule ? "[]," + recoverTriggerTasks.substr(1, recoverTriggerTasks.length - 2) : "[]");
|
2022-09-13 23:32:15 -04:00
|
|
|
|
|
2021-04-22 09:53:31 -04:00
|
|
|
|
showFormModal(".rule.modal", "#ruleForm", "/api/alert-rule");
|
2020-12-19 10:11:16 -05:00
|
|
|
|
}
|
|
|
|
|
|
2020-12-19 09:14:36 -05:00
|
|
|
|
function addOrEditNotification(notification) {
|
2021-04-22 09:53:31 -04:00
|
|
|
|
const modal = $(".notification.modal");
|
2022-04-29 21:32:57 -04:00
|
|
|
|
modal.children(".header").text((notification ? LANG.Edit : LANG.Add) + ' ' + LANG.Notification);
|
2021-04-22 09:53:31 -04:00
|
|
|
|
modal
|
2021-08-05 23:48:34 -04:00
|
|
|
|
.find(".nezha-primary-btn.button")
|
2021-04-22 09:53:31 -04:00
|
|
|
|
.html(
|
|
|
|
|
notification
|
2022-04-29 21:32:57 -04:00
|
|
|
|
? LANG.Edit + '<i class="edit icon"></i>'
|
|
|
|
|
: LANG.Add + '<i class="add icon"></i>'
|
2021-04-22 09:53:31 -04:00
|
|
|
|
);
|
|
|
|
|
modal.find("input[name=ID]").val(notification ? notification.ID : null);
|
|
|
|
|
modal.find("input[name=Name]").val(notification ? notification.Name : null);
|
2022-04-14 22:56:04 -04:00
|
|
|
|
modal.find("input[name=Tag]").val(notification ? notification.Tag : null);
|
2021-04-22 09:53:31 -04:00
|
|
|
|
modal.find("input[name=URL]").val(notification ? notification.URL : null);
|
2021-11-05 00:04:39 -04:00
|
|
|
|
modal
|
|
|
|
|
.find("textarea[name=RequestHeader]")
|
|
|
|
|
.val(notification ? notification.RequestHeader : null);
|
2021-04-22 09:53:31 -04:00
|
|
|
|
modal
|
|
|
|
|
.find("textarea[name=RequestBody]")
|
|
|
|
|
.val(notification ? notification.RequestBody : null);
|
|
|
|
|
modal
|
|
|
|
|
.find("select[name=RequestMethod]")
|
|
|
|
|
.val(notification ? notification.RequestMethod : 1);
|
|
|
|
|
modal
|
|
|
|
|
.find("select[name=RequestType]")
|
|
|
|
|
.val(notification ? notification.RequestType : 1);
|
|
|
|
|
if (notification && notification.VerifySSL) {
|
|
|
|
|
modal.find(".ui.nf-ssl.checkbox").checkbox("set checked");
|
|
|
|
|
} else {
|
|
|
|
|
modal.find(".ui.nf-ssl.checkbox").checkbox("set unchecked");
|
|
|
|
|
}
|
2022-04-23 02:51:10 -04:00
|
|
|
|
modal.find(".ui.nf-skip-check.checkbox").checkbox("set unchecked");
|
2021-04-22 09:53:31 -04:00
|
|
|
|
showFormModal(
|
|
|
|
|
".notification.modal",
|
|
|
|
|
"#notificationForm",
|
|
|
|
|
"/api/notification"
|
|
|
|
|
);
|
2020-12-19 09:14:36 -05:00
|
|
|
|
}
|
|
|
|
|
|
2021-08-17 23:56:54 -04:00
|
|
|
|
function connectToServer(id) {
|
|
|
|
|
post('/terminal', { Host: window.location.host, Protocol: window.location.protocol, ID: id })
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function post(path, params, method = 'post') {
|
|
|
|
|
const form = document.createElement('form');
|
|
|
|
|
form.method = method;
|
|
|
|
|
form.action = path;
|
2021-08-18 12:04:09 -04:00
|
|
|
|
form.target = "_blank";
|
2021-08-17 23:56:54 -04:00
|
|
|
|
|
|
|
|
|
for (const key in params) {
|
|
|
|
|
if (params.hasOwnProperty(key)) {
|
|
|
|
|
const hiddenField = document.createElement('input');
|
|
|
|
|
hiddenField.type = 'hidden';
|
|
|
|
|
hiddenField.name = key;
|
|
|
|
|
hiddenField.value = params[key];
|
|
|
|
|
form.appendChild(hiddenField);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
document.body.appendChild(form);
|
|
|
|
|
form.submit();
|
2021-08-18 22:42:47 -04:00
|
|
|
|
document.body.removeChild(form);
|
2021-08-17 23:56:54 -04:00
|
|
|
|
}
|
|
|
|
|
|
2022-05-18 08:52:18 -04:00
|
|
|
|
function issueNewApiToken(apiToken) {
|
|
|
|
|
const modal = $(".api.modal");
|
|
|
|
|
modal.children(".header").text((apiToken ? LANG.Edit : LANG.Add) + ' ' + "API Token");
|
|
|
|
|
modal
|
2022-09-16 22:30:32 -04:00
|
|
|
|
.find(".nezha-primary-btn.button")
|
|
|
|
|
.html(
|
|
|
|
|
apiToken ? LANG.Edit + '<i class="edit icon"></i>' : LANG.Add + '<i class="add icon"></i>'
|
|
|
|
|
);
|
2022-05-18 08:52:18 -04:00
|
|
|
|
modal.find("textarea[name=Note]").val(apiToken ? apiToken.Note : null);
|
|
|
|
|
showFormModal(".api.modal", "#apiForm", "/api/token");
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-10 02:04:21 -04:00
|
|
|
|
function addOrEditServer(server, conf) {
|
2021-04-22 09:53:31 -04:00
|
|
|
|
const modal = $(".server.modal");
|
2022-04-29 21:32:57 -04:00
|
|
|
|
modal.children(".header").text((server ? LANG.Edit : LANG.Add) + ' ' + LANG.Server);
|
2021-04-22 09:53:31 -04:00
|
|
|
|
modal
|
2021-08-05 23:48:34 -04:00
|
|
|
|
.find(".nezha-primary-btn.button")
|
2021-04-22 09:53:31 -04:00
|
|
|
|
.html(
|
2022-04-29 21:32:57 -04:00
|
|
|
|
server ? LANG.Edit + '<i class="edit icon"></i>' : LANG.Add + '<i class="add icon"></i>'
|
2021-04-22 09:53:31 -04:00
|
|
|
|
);
|
|
|
|
|
modal.find("input[name=id]").val(server ? server.ID : null);
|
|
|
|
|
modal.find("input[name=name]").val(server ? server.Name : null);
|
|
|
|
|
modal.find("input[name=Tag]").val(server ? server.Tag : null);
|
|
|
|
|
modal
|
|
|
|
|
.find("input[name=DisplayIndex]")
|
|
|
|
|
.val(server ? server.DisplayIndex : null);
|
|
|
|
|
modal.find("textarea[name=Note]").val(server ? server.Note : null);
|
|
|
|
|
if (server) {
|
|
|
|
|
modal.find(".secret.field").attr("style", "");
|
2021-08-10 02:04:21 -04:00
|
|
|
|
modal.find(".command.field").attr("style", "");
|
|
|
|
|
modal.find(".command.hostSecret").text(server.Secret);
|
2021-04-22 09:53:31 -04:00
|
|
|
|
modal.find("input[name=secret]").val(server.Secret);
|
|
|
|
|
} else {
|
|
|
|
|
modal.find(".secret.field").attr("style", "display:none");
|
2021-08-10 02:04:21 -04:00
|
|
|
|
modal.find(".command.field").attr("style", "display:none");
|
2021-04-22 09:53:31 -04:00
|
|
|
|
modal.find("input[name=secret]").val("");
|
|
|
|
|
}
|
2022-09-30 10:40:56 -04:00
|
|
|
|
if (server && server.HideForGuest) {
|
|
|
|
|
modal.find(".ui.hideforguest.checkbox").checkbox("set checked");
|
|
|
|
|
} else {
|
|
|
|
|
modal.find(".ui.hideforguest.checkbox").checkbox("set unchecked");
|
|
|
|
|
}
|
2021-04-22 09:53:31 -04:00
|
|
|
|
showFormModal(".server.modal", "#serverForm", "/api/server");
|
2019-12-08 10:18:29 -05:00
|
|
|
|
}
|
|
|
|
|
|
2021-01-15 11:45:49 -05:00
|
|
|
|
function addOrEditMonitor(monitor) {
|
2021-04-22 09:53:31 -04:00
|
|
|
|
const modal = $(".monitor.modal");
|
2022-04-29 21:32:57 -04:00
|
|
|
|
modal.children(".header").text((monitor ? LANG.Edit : LANG.Add) + ' ' + LANG.Monitor);
|
2021-04-22 09:53:31 -04:00
|
|
|
|
modal
|
2021-08-05 23:48:34 -04:00
|
|
|
|
.find(".nezha-primary-btn.button")
|
2021-04-22 09:53:31 -04:00
|
|
|
|
.html(
|
2022-04-29 21:32:57 -04:00
|
|
|
|
monitor ? LANG.Edit + '<i class="edit icon"></i>' : LANG.Add + '<i class="add icon"></i>'
|
2021-04-22 09:53:31 -04:00
|
|
|
|
);
|
|
|
|
|
modal.find("input[name=ID]").val(monitor ? monitor.ID : null);
|
|
|
|
|
modal.find("input[name=Name]").val(monitor ? monitor.Name : null);
|
|
|
|
|
modal.find("input[name=Target]").val(monitor ? monitor.Target : null);
|
2021-09-02 11:45:21 -04:00
|
|
|
|
modal.find("input[name=Duration]").val(monitor && monitor.Duration ? monitor.Duration : 30);
|
2021-04-22 09:53:31 -04:00
|
|
|
|
modal.find("select[name=Type]").val(monitor ? monitor.Type : 1);
|
2021-06-21 09:30:42 -04:00
|
|
|
|
modal.find("select[name=Cover]").val(monitor ? monitor.Cover : 0);
|
2022-04-14 22:56:04 -04:00
|
|
|
|
modal.find("input[name=NotificationTag]").val(monitor ? monitor.NotificationTag : null);
|
2021-04-22 09:53:31 -04:00
|
|
|
|
if (monitor && monitor.Notify) {
|
|
|
|
|
modal.find(".ui.nb-notify.checkbox").checkbox("set checked");
|
|
|
|
|
} else {
|
|
|
|
|
modal.find(".ui.nb-notify.checkbox").checkbox("set unchecked");
|
|
|
|
|
}
|
2022-09-16 22:30:32 -04:00
|
|
|
|
modal.find("input[name=MaxLatency]").val(monitor ? monitor.MaxLatency : null);
|
|
|
|
|
modal.find("input[name=MinLatency]").val(monitor ? monitor.MinLatency : null);
|
|
|
|
|
if (monitor && monitor.LatencyNotify) {
|
|
|
|
|
modal.find(".ui.nb-lt-notify.checkbox").checkbox("set checked");
|
|
|
|
|
} else {
|
|
|
|
|
modal.find(".ui.nb-lt-notify.checkbox").checkbox("set unchecked");
|
|
|
|
|
}
|
2022-09-13 23:06:59 -04:00
|
|
|
|
modal.find("a.ui.label.visible").each((i, el) => {
|
|
|
|
|
el.remove();
|
|
|
|
|
});
|
2023-04-15 07:04:38 -04:00
|
|
|
|
if (monitor && monitor.EnableTriggerTask) {
|
|
|
|
|
modal.find(".ui.nb-EnableTriggerTask.checkbox").checkbox("set checked");
|
|
|
|
|
} else {
|
|
|
|
|
modal.find(".ui.nb-EnableTriggerTask.checkbox").checkbox("set unchecked");
|
|
|
|
|
}
|
2021-04-22 09:53:31 -04:00
|
|
|
|
var servers;
|
2023-04-15 07:04:38 -04:00
|
|
|
|
var failTriggerTasks;
|
|
|
|
|
var recoverTriggerTasks;
|
2021-04-22 09:53:31 -04:00
|
|
|
|
if (monitor) {
|
2021-04-22 10:18:55 -04:00
|
|
|
|
servers = monitor.SkipServersRaw;
|
|
|
|
|
const serverList = JSON.parse(servers || "[]");
|
2023-04-15 07:04:38 -04:00
|
|
|
|
const node = modal.find("i.dropdown.icon.specificServer");
|
2021-04-22 09:53:31 -04:00
|
|
|
|
for (let i = 0; i < serverList.length; i++) {
|
|
|
|
|
node.after(
|
2023-06-13 12:23:47 -04:00
|
|
|
|
'<a class="ui label transition visible" data-value="' +
|
|
|
|
|
serverList[i] +
|
|
|
|
|
'" style="display: inline-block !important;">ID:' +
|
|
|
|
|
serverList[i] +
|
|
|
|
|
'<i class="delete icon"></i></a>'
|
2023-04-15 07:04:38 -04:00
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
failTriggerTasks = monitor.FailTriggerTasksRaw;
|
|
|
|
|
recoverTriggerTasks = monitor.RecoverTriggerTasksRaw;
|
|
|
|
|
const failTriggerTasksList = JSON.parse(failTriggerTasks || "[]");
|
|
|
|
|
const recoverTriggerTasksList = JSON.parse(recoverTriggerTasks || "[]");
|
|
|
|
|
const node1 = modal.find("i.dropdown.icon.failTask");
|
|
|
|
|
const node2 = modal.find("i.dropdown.icon.recoverTask");
|
|
|
|
|
for (let i = 0; i < failTriggerTasksList.length; i++) {
|
|
|
|
|
node1.after(
|
2023-06-13 12:23:47 -04:00
|
|
|
|
'<a class="ui label transition visible" data-value="' +
|
|
|
|
|
failTriggerTasksList[i] +
|
|
|
|
|
'" style="display: inline-block !important;">ID:' +
|
|
|
|
|
failTriggerTasksList[i] +
|
|
|
|
|
'<i class="delete icon"></i></a>'
|
2023-04-15 07:04:38 -04:00
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
for (let i = 0; i < recoverTriggerTasksList.length; i++) {
|
|
|
|
|
node2.after(
|
2023-06-13 12:23:47 -04:00
|
|
|
|
'<a class="ui label transition visible" data-value="' +
|
|
|
|
|
recoverTriggerTasksList[i] +
|
|
|
|
|
'" style="display: inline-block !important;">ID:' +
|
|
|
|
|
recoverTriggerTasksList[i] +
|
|
|
|
|
'<i class="delete icon"></i></a>'
|
2021-04-22 09:53:31 -04:00
|
|
|
|
);
|
2021-04-17 11:36:37 -04:00
|
|
|
|
}
|
2021-04-22 09:53:31 -04:00
|
|
|
|
}
|
2023-06-13 12:23:47 -04:00
|
|
|
|
modal
|
2023-04-15 07:04:38 -04:00
|
|
|
|
.find("input[name=FailTriggerTasksRaw]")
|
|
|
|
|
.val(monitor ? "[]," + failTriggerTasks.substr(1, failTriggerTasks.length - 2) : "[]");
|
2023-06-13 12:23:47 -04:00
|
|
|
|
modal
|
2023-04-15 07:04:38 -04:00
|
|
|
|
.find("input[name=RecoverTriggerTasksRaw]")
|
|
|
|
|
.val(monitor ? "[]," + recoverTriggerTasks.substr(1, recoverTriggerTasks.length - 2) : "[]");
|
|
|
|
|
|
2023-06-13 12:23:47 -04:00
|
|
|
|
modal
|
2021-04-22 09:53:31 -04:00
|
|
|
|
.find("input[name=SkipServersRaw]")
|
|
|
|
|
.val(monitor ? "[]," + servers.substr(1, servers.length - 2) : "[]");
|
|
|
|
|
showFormModal(".monitor.modal", "#monitorForm", "/api/monitor");
|
2021-01-15 11:45:49 -05:00
|
|
|
|
}
|
|
|
|
|
|
2021-01-18 20:59:04 -05:00
|
|
|
|
function addOrEditCron(cron) {
|
2021-04-22 09:53:31 -04:00
|
|
|
|
const modal = $(".cron.modal");
|
2022-04-29 21:32:57 -04:00
|
|
|
|
modal.children(".header").text((cron ? LANG.Edit : LANG.Add) + ' ' + LANG.Cron);
|
2021-04-22 09:53:31 -04:00
|
|
|
|
modal
|
2021-08-05 23:48:34 -04:00
|
|
|
|
.find(".nezha-primary-btn.button")
|
2021-04-22 09:53:31 -04:00
|
|
|
|
.html(
|
2022-04-29 21:32:57 -04:00
|
|
|
|
cron ? LANG.Edit + '<i class="edit icon"></i>' : LANG.Add + '<i class="add icon"></i>'
|
2021-04-22 09:53:31 -04:00
|
|
|
|
);
|
|
|
|
|
modal.find("input[name=ID]").val(cron ? cron.ID : null);
|
|
|
|
|
modal.find("input[name=Name]").val(cron ? cron.Name : null);
|
2022-09-13 23:32:15 -04:00
|
|
|
|
modal.find("select[name=TaskType]").val(cron ? cron.TaskType : 0);
|
|
|
|
|
modal.find("select[name=Cover]").val(cron ? cron.Cover : 0);
|
2022-04-14 22:56:04 -04:00
|
|
|
|
modal.find("input[name=NotificationTag]").val(cron ? cron.NotificationTag : null);
|
2021-04-22 09:53:31 -04:00
|
|
|
|
modal.find("input[name=Scheduler]").val(cron ? cron.Scheduler : null);
|
|
|
|
|
modal.find("a.ui.label.visible").each((i, el) => {
|
|
|
|
|
el.remove();
|
|
|
|
|
});
|
|
|
|
|
var servers;
|
|
|
|
|
if (cron) {
|
|
|
|
|
servers = cron.ServersRaw;
|
2021-04-22 10:18:55 -04:00
|
|
|
|
const serverList = JSON.parse(servers || "[]");
|
2021-04-22 09:53:31 -04:00
|
|
|
|
const node = modal.find("i.dropdown.icon");
|
|
|
|
|
for (let i = 0; i < serverList.length; i++) {
|
|
|
|
|
node.after(
|
|
|
|
|
'<a class="ui label transition visible" data-value="' +
|
2021-06-21 09:30:42 -04:00
|
|
|
|
serverList[i] +
|
|
|
|
|
'" style="display: inline-block !important;">ID:' +
|
|
|
|
|
serverList[i] +
|
|
|
|
|
'<i class="delete icon"></i></a>'
|
2021-04-22 09:53:31 -04:00
|
|
|
|
);
|
2021-01-20 09:15:47 -05:00
|
|
|
|
}
|
2021-04-22 09:53:31 -04:00
|
|
|
|
}
|
|
|
|
|
modal
|
|
|
|
|
.find("input[name=ServersRaw]")
|
|
|
|
|
.val(cron ? "[]," + servers.substr(1, servers.length - 2) : "[]");
|
|
|
|
|
modal.find("textarea[name=Command]").val(cron ? cron.Command : null);
|
|
|
|
|
if (cron && cron.PushSuccessful) {
|
|
|
|
|
modal.find(".ui.push-successful.checkbox").checkbox("set checked");
|
|
|
|
|
} else {
|
|
|
|
|
modal.find(".ui.push-successful.checkbox").checkbox("set unchecked");
|
|
|
|
|
}
|
|
|
|
|
showFormModal(".cron.modal", "#cronForm", "/api/cron");
|
2021-01-18 20:59:04 -05:00
|
|
|
|
}
|
|
|
|
|
|
2020-03-22 08:55:27 -04:00
|
|
|
|
function deleteRequest(api) {
|
2021-04-22 09:53:31 -04:00
|
|
|
|
$.ajax({
|
|
|
|
|
url: api,
|
|
|
|
|
type: "DELETE",
|
|
|
|
|
})
|
|
|
|
|
.done((resp) => {
|
|
|
|
|
if (resp.code == 200) {
|
|
|
|
|
if (resp.message) {
|
|
|
|
|
alert(resp.message);
|
2020-03-22 08:55:27 -04:00
|
|
|
|
} else {
|
2021-04-22 09:53:31 -04:00
|
|
|
|
alert("删除成功");
|
2020-03-22 08:55:27 -04:00
|
|
|
|
}
|
2021-04-22 09:53:31 -04:00
|
|
|
|
window.location.reload();
|
|
|
|
|
} else {
|
|
|
|
|
alert("删除失败 " + resp.code + ":" + resp.message);
|
|
|
|
|
confirmBtn.toggleClass("loading");
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.fail((err) => {
|
|
|
|
|
alert("网络错误:" + err.responseText);
|
2020-03-22 08:55:27 -04:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-23 20:41:35 -05:00
|
|
|
|
function manualTrigger(btn, cronId) {
|
2021-04-22 09:53:31 -04:00
|
|
|
|
$(btn).toggleClass("loading");
|
|
|
|
|
$.ajax({
|
|
|
|
|
url: "/api/cron/" + cronId + "/manual",
|
|
|
|
|
type: "GET",
|
|
|
|
|
})
|
|
|
|
|
.done((resp) => {
|
|
|
|
|
$(btn).toggleClass("loading");
|
|
|
|
|
if (resp.code == 200) {
|
|
|
|
|
$.suiAlert({
|
|
|
|
|
title: "触发成功,等待执行结果",
|
|
|
|
|
type: "success",
|
|
|
|
|
description: resp.message,
|
|
|
|
|
time: "3",
|
|
|
|
|
position: "top-center",
|
|
|
|
|
});
|
|
|
|
|
} else {
|
2021-01-23 20:41:35 -05:00
|
|
|
|
$.suiAlert({
|
2021-04-22 09:53:31 -04:00
|
|
|
|
title: "触发失败 ",
|
|
|
|
|
type: "error",
|
|
|
|
|
description: resp.code + ":" + resp.message,
|
|
|
|
|
time: "3",
|
|
|
|
|
position: "top-center",
|
2021-01-23 20:41:35 -05:00
|
|
|
|
});
|
2021-04-22 09:53:31 -04:00
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.fail((err) => {
|
|
|
|
|
$(btn).toggleClass("loading");
|
|
|
|
|
$.suiAlert({
|
|
|
|
|
title: "触发失败 ",
|
|
|
|
|
type: "error",
|
|
|
|
|
description: "网络错误:" + err.responseText,
|
|
|
|
|
time: "3",
|
|
|
|
|
position: "top-center",
|
|
|
|
|
});
|
2021-01-23 20:41:35 -05:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-08 03:59:58 -05:00
|
|
|
|
function logout(id) {
|
2021-04-22 09:53:31 -04:00
|
|
|
|
$.post("/api/logout", JSON.stringify({ id: id }))
|
|
|
|
|
.done(function (resp) {
|
|
|
|
|
if (resp.code == 200) {
|
|
|
|
|
$.suiAlert({
|
|
|
|
|
title: "注销成功",
|
|
|
|
|
type: "success",
|
|
|
|
|
description: "如需继续访问请使用 GitHub 再次登录",
|
|
|
|
|
time: "3",
|
|
|
|
|
position: "top-center",
|
|
|
|
|
});
|
|
|
|
|
window.location.reload();
|
|
|
|
|
} else {
|
2019-12-11 05:03:49 -05:00
|
|
|
|
$.suiAlert({
|
2021-04-22 09:53:31 -04:00
|
|
|
|
title: "注销失败",
|
|
|
|
|
description: resp.code + ":" + resp.message,
|
|
|
|
|
type: "error",
|
|
|
|
|
time: "3",
|
|
|
|
|
position: "top-center",
|
2019-12-11 05:03:49 -05:00
|
|
|
|
});
|
2021-04-22 09:53:31 -04:00
|
|
|
|
}
|
2019-12-08 03:59:58 -05:00
|
|
|
|
})
|
2021-04-22 09:53:31 -04:00
|
|
|
|
.fail(function (err) {
|
|
|
|
|
$.suiAlert({
|
|
|
|
|
title: "网络错误",
|
|
|
|
|
description: err.responseText,
|
|
|
|
|
type: "error",
|
|
|
|
|
time: "3",
|
|
|
|
|
position: "top-center",
|
|
|
|
|
});
|
|
|
|
|
});
|
2019-12-08 03:59:58 -05:00
|
|
|
|
}
|
2021-01-20 09:15:47 -05:00
|
|
|
|
|
|
|
|
|
$(document).ready(() => {
|
2021-04-22 09:53:31 -04:00
|
|
|
|
try {
|
|
|
|
|
$(".ui.servers.search.dropdown").dropdown({
|
|
|
|
|
clearable: true,
|
|
|
|
|
apiSettings: {
|
|
|
|
|
url: "/api/search-server?word={query}",
|
|
|
|
|
cache: false,
|
|
|
|
|
},
|
|
|
|
|
});
|
2021-06-21 09:30:42 -04:00
|
|
|
|
} catch (error) { }
|
2021-04-22 09:53:31 -04:00
|
|
|
|
});
|
2022-09-13 23:32:15 -04:00
|
|
|
|
|
|
|
|
|
$(document).ready(() => {
|
|
|
|
|
try {
|
|
|
|
|
$(".ui.tasks.search.dropdown").dropdown({
|
|
|
|
|
clearable: true,
|
|
|
|
|
apiSettings: {
|
|
|
|
|
url: "/api/search-tasks?word={query}",
|
|
|
|
|
cache: false,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
} catch (error) { }
|
|
|
|
|
});
|