2019-12-10 04:57:57 -05:00
|
|
|
|
function readableBytes(bytes) {
|
|
|
|
|
var i = Math.floor(Math.log(bytes) / Math.log(1024)),
|
|
|
|
|
sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
|
2020-12-21 03:34:21 -05:00
|
|
|
|
return (bytes / Math.pow(1024, i)).toFixed(0) + ' ' + sizes[i];
|
2019-12-10 04:57:57 -05:00
|
|
|
|
}
|
|
|
|
|
|
2019-12-08 03:59:58 -05:00
|
|
|
|
const confirmBtn = $('.mini.confirm.modal .positive.button')
|
2019-12-09 05:14:31 -05:00
|
|
|
|
|
2019-12-08 03:59:58 -05:00
|
|
|
|
function showConfirm(title, content, callFn, extData) {
|
|
|
|
|
const modal = $('.mini.confirm.modal')
|
|
|
|
|
modal.children('.header').text(title)
|
|
|
|
|
modal.children('.content').text(content)
|
2019-12-09 05:14:31 -05:00
|
|
|
|
if (confirmBtn.hasClass('loading')) {
|
2019-12-08 03:59:58 -05:00
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
modal.modal({
|
|
|
|
|
closable: true,
|
|
|
|
|
onApprove: function () {
|
|
|
|
|
confirmBtn.toggleClass('loading')
|
|
|
|
|
callFn(extData)
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
}).modal('show')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function showFormModal(modelSelector, formID, URL, getData) {
|
|
|
|
|
$(modelSelector).modal({
|
|
|
|
|
closable: true,
|
|
|
|
|
onApprove: function () {
|
|
|
|
|
let success = false
|
|
|
|
|
const btn = $(modelSelector + ' .positive.button')
|
|
|
|
|
const form = $(modelSelector + ' form')
|
|
|
|
|
if (btn.hasClass('loading')) {
|
|
|
|
|
return success
|
|
|
|
|
}
|
|
|
|
|
form.children('.message').remove()
|
|
|
|
|
btn.toggleClass('loading')
|
|
|
|
|
const data = getData ? getData() : $(formID).serializeArray().reduce(function (obj, item) {
|
2021-01-08 08:04:50 -05:00
|
|
|
|
obj[item.name] = (item.name.endsWith('_id') ||
|
|
|
|
|
item.name === 'id' || item.name === 'ID' ||
|
|
|
|
|
item.name === 'RequestType' || item.name === 'RequestMethod' ||
|
2021-01-15 11:45:49 -05:00
|
|
|
|
item.name === 'DisplayIndex' || item.name === 'Type') ? parseInt(item.value) : item.value;
|
2019-12-08 03:59:58 -05:00
|
|
|
|
return obj;
|
|
|
|
|
}, {});
|
|
|
|
|
$.post(URL, JSON.stringify(data)).done(function (resp) {
|
|
|
|
|
if (resp.code == 200) {
|
|
|
|
|
if (resp.message) {
|
2019-12-11 05:03:49 -05:00
|
|
|
|
$.suiAlert({
|
|
|
|
|
title: '操作成功',
|
|
|
|
|
type: 'success',
|
|
|
|
|
description: resp.message,
|
|
|
|
|
time: '3',
|
|
|
|
|
position: 'top-center',
|
|
|
|
|
});
|
2019-12-08 03:59:58 -05:00
|
|
|
|
}
|
|
|
|
|
window.location.reload()
|
|
|
|
|
} else {
|
|
|
|
|
form.append(`<div class="ui negative message"><div class="header">操作失败</div><p>` + resp.message + `</p></div>`)
|
|
|
|
|
}
|
|
|
|
|
}).fail(function (err) {
|
|
|
|
|
form.append(`<div class="ui negative message"><div class="header">网络错误</div><p>` + err.responseText + `</p></div>`)
|
|
|
|
|
}).always(function () {
|
|
|
|
|
btn.toggleClass('loading')
|
|
|
|
|
});
|
|
|
|
|
return success
|
|
|
|
|
}
|
|
|
|
|
}).modal('show')
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-19 10:11:16 -05:00
|
|
|
|
function addOrEditAlertRule(rule) {
|
|
|
|
|
const modal = $('.rule.modal')
|
|
|
|
|
modal.children('.header').text((rule ? '修改' : '添加') + '报警规则')
|
|
|
|
|
modal.find('.positive.button').html(rule ? '修改<i class="edit icon"></i>' : '添加<i class="add icon"></i>')
|
|
|
|
|
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)
|
|
|
|
|
if (rule && rule.Enable) {
|
|
|
|
|
modal.find('.ui.rule-enable.checkbox').checkbox('set checked')
|
|
|
|
|
} else {
|
|
|
|
|
modal.find('.ui.rule-enable.checkbox').checkbox('set unchecked')
|
|
|
|
|
}
|
|
|
|
|
showFormModal('.rule.modal', '#ruleForm', '/api/alert-rule')
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-19 09:14:36 -05:00
|
|
|
|
function addOrEditNotification(notification) {
|
|
|
|
|
const modal = $('.notification.modal')
|
|
|
|
|
modal.children('.header').text((notification ? '修改' : '添加') + '通知方式')
|
|
|
|
|
modal.find('.positive.button').html(notification ? '修改<i class="edit icon"></i>' : '添加<i class="add icon"></i>')
|
|
|
|
|
modal.find('input[name=ID]').val(notification ? notification.ID : null)
|
|
|
|
|
modal.find('input[name=Name]').val(notification ? notification.Name : null)
|
|
|
|
|
modal.find('input[name=URL]').val(notification ? notification.URL : null)
|
|
|
|
|
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) {
|
2020-12-19 10:11:16 -05:00
|
|
|
|
modal.find('.ui.nf-ssl.checkbox').checkbox('set checked')
|
2020-12-19 09:14:36 -05:00
|
|
|
|
} else {
|
2020-12-19 10:11:16 -05:00
|
|
|
|
modal.find('.ui.nf-ssl.checkbox').checkbox('set unchecked')
|
2020-12-19 09:14:36 -05:00
|
|
|
|
}
|
|
|
|
|
showFormModal('.notification.modal', '#notificationForm', '/api/notification')
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-22 08:55:27 -04:00
|
|
|
|
function addOrEditServer(server) {
|
|
|
|
|
const modal = $('.server.modal')
|
|
|
|
|
modal.children('.header').text((server ? '修改' : '添加') + '服务器')
|
|
|
|
|
modal.find('.positive.button').html(server ? '修改<i class="edit icon"></i>' : '添加<i class="add icon"></i>')
|
|
|
|
|
modal.find('input[name=id]').val(server ? server.ID : null)
|
|
|
|
|
modal.find('input[name=name]').val(server ? server.Name : null)
|
2021-01-13 09:30:28 -05:00
|
|
|
|
modal.find('input[name=Tag]').val(server ? server.Tag : null)
|
|
|
|
|
modal.find('input[name=DisplayIndex]').val(server ? server.DisplayIndex : null)
|
2020-03-22 08:55:27 -04:00
|
|
|
|
if (server) {
|
|
|
|
|
modal.find('.secret.field').attr('style', '')
|
|
|
|
|
modal.find('input[name=secret]').val(server.Secret)
|
|
|
|
|
} else {
|
|
|
|
|
modal.find('.secret.field').attr('style', 'display:none')
|
|
|
|
|
modal.find('input[name=secret]').val('')
|
|
|
|
|
}
|
2019-12-08 10:18:29 -05:00
|
|
|
|
showFormModal('.server.modal', '#serverForm', '/api/server')
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-15 11:45:49 -05:00
|
|
|
|
function addOrEditMonitor(monitor) {
|
|
|
|
|
const modal = $('.monitor.modal')
|
|
|
|
|
modal.children('.header').text((monitor ? '修改' : '添加') + '监控')
|
|
|
|
|
modal.find('.positive.button').html(monitor ? '修改<i class="edit icon"></i>' : '添加<i class="add icon"></i>')
|
|
|
|
|
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)
|
|
|
|
|
modal.find('select[name=Type]').val(monitor ? monitor.Type : 1)
|
|
|
|
|
showFormModal('.monitor.modal', '#monitorForm', '/api/monitor')
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-22 08:55:27 -04:00
|
|
|
|
function deleteRequest(api) {
|
|
|
|
|
$.ajax({
|
|
|
|
|
url: api,
|
|
|
|
|
type: 'DELETE',
|
|
|
|
|
}).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 logout(id) {
|
|
|
|
|
$.post('/api/logout', JSON.stringify({ id: id })).done(function (resp) {
|
|
|
|
|
if (resp.code == 200) {
|
|
|
|
|
$.suiAlert({
|
|
|
|
|
title: '注销成功',
|
|
|
|
|
type: 'success',
|
2019-12-11 05:03:49 -05:00
|
|
|
|
description: '如需继续访问请使用 GitHub 再次登录',
|
2019-12-08 03:59:58 -05:00
|
|
|
|
time: '3',
|
|
|
|
|
position: 'top-center',
|
|
|
|
|
});
|
|
|
|
|
window.location.reload()
|
|
|
|
|
} else {
|
|
|
|
|
$.suiAlert({
|
|
|
|
|
title: '注销失败',
|
|
|
|
|
description: resp.code + ':' + resp.message,
|
|
|
|
|
type: 'error',
|
|
|
|
|
time: '3',
|
|
|
|
|
position: 'top-center',
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}).fail(function (err) {
|
2019-12-11 05:03:49 -05:00
|
|
|
|
$.suiAlert({
|
|
|
|
|
title: '网络错误',
|
|
|
|
|
description: err.responseText,
|
|
|
|
|
type: 'error',
|
|
|
|
|
time: '3',
|
|
|
|
|
position: 'top-center',
|
|
|
|
|
});
|
2019-12-08 03:59:58 -05:00
|
|
|
|
})
|
|
|
|
|
}
|