2023-06-03 16:21:23 +00:00
|
|
|
{% extends ../base.html %}
|
|
|
|
|
|
|
|
{% block meta %}
|
|
|
|
{% end %}
|
|
|
|
|
|
|
|
{% block title %}Crafty Controller - {{ translate('serverDetails', 'serverDetails', data['lang']) }}{% end %}
|
|
|
|
|
|
|
|
{% block content %}
|
|
|
|
|
|
|
|
<div class="content-wrapper">
|
|
|
|
|
|
|
|
<!-- Page Title Header Starts-->
|
|
|
|
<div class="row page-title-header">
|
|
|
|
<div class="col-12">
|
|
|
|
<div class="page-header">
|
|
|
|
<h4 class="page-title">
|
|
|
|
{{ translate('serverDetails', 'serverDetails', data['lang']) }} - {{
|
|
|
|
data['server_stats']['server_id']['server_name'] }}
|
|
|
|
<br />
|
2023-11-01 17:44:56 +00:00
|
|
|
<small>UUID: {{ data['server_stats']['server_id']['server_id'] }}</small>
|
2023-06-03 16:21:23 +00:00
|
|
|
</h4>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
<!-- Page Title Header Ends-->
|
|
|
|
|
|
|
|
{% include "parts/details_stats.html" %}
|
|
|
|
|
|
|
|
<div class="row">
|
|
|
|
|
|
|
|
<div class="col-sm-12 grid-margin">
|
|
|
|
<div class="card">
|
|
|
|
<div class="card-body pt-0">
|
|
|
|
|
|
|
|
<span class="d-none d-sm-block">
|
|
|
|
{% include "parts/server_controls_list.html" %}
|
|
|
|
</span>
|
|
|
|
<span class="d-block d-sm-none">
|
|
|
|
{% include "parts/m_server_controls_list.html" %}
|
|
|
|
</span>
|
|
|
|
|
|
|
|
<div class="row">
|
|
|
|
<div class="col-md-12 col-sm-12" style="overflow-x:auto;">
|
|
|
|
<div class="card">
|
|
|
|
<div class="card-header header-sm d-flex justify-content-between align-items-center">
|
2023-06-03 22:44:18 +00:00
|
|
|
<h4 class="card-title"><i class="fa-regular fa-bell"></i> {{ translate('webhooks', 'webhooks', data['lang']) }} </h4>
|
2023-06-03 16:21:23 +00:00
|
|
|
{% if data['user_data']['hints'] %}
|
2023-10-21 15:32:48 +00:00
|
|
|
<span class="too_small" title="{{ translate('serverSchedules', 'cannotSee', data['lang']) }}" , data-content="{{ translate('serverSchedules', 'cannotSeeOnMobile', data['lang']) }}" , data-placement="bottom"></span>
|
2023-06-03 16:21:23 +00:00
|
|
|
{% end %}
|
2023-10-21 15:32:48 +00:00
|
|
|
<div><a class="btn btn-info" href="/panel/add_webhook?id={{ data['server_stats']['server_id']['server_id'] }}"><i class="fas fa-plus-circle"></i> {{ translate('webhooks', 'new', data['lang']) }}</a></div>
|
2023-06-03 16:21:23 +00:00
|
|
|
</div>
|
|
|
|
<div class="card-body">
|
2023-10-21 15:32:48 +00:00
|
|
|
{% if len(data['webhooks']) == 0 %}
|
|
|
|
<div style="text-align: center; color: grey;">
|
|
|
|
<h7>{{ translate('webhooks', 'no-webhook', data['lang']) }} <strong>{{ translate('webhooks', 'newWebhook',data['lang']) }}</strong>.</h7>
|
|
|
|
</div>
|
|
|
|
{% end %}
|
|
|
|
{% if len(data['webhooks']) > 0 %}
|
|
|
|
<div class="d-none d-lg-block">
|
|
|
|
<table class="table table-hover responsive-table" aria-label="webhooks list" id="webhook_table" width="100%" style="table-layout:fixed;">
|
|
|
|
<thead>
|
|
|
|
<tr class="rounded">
|
|
|
|
<th scope="col" style="width: 5%; min-width: 64px;">{{ translate('webhooks', 'enabled', data['lang']) }}</th>
|
|
|
|
<th scope="col" style="width: 15%; min-width: 10px;">{{ translate('webhooks', 'name', data['lang']) }} </th>
|
|
|
|
<th scope="col" style="width: 20%; min-width: 50px;">{{ translate('webhooks', 'type', data['lang']) }}</th>
|
|
|
|
<th scope="col" style="width: 50%; min-width: 50px;">{{ translate('webhooks', 'trigger', data['lang']) }}</th>
|
|
|
|
<th scope="col" style="width: 10%; min-width: 50px;">{{ translate('webhooks', 'edit', data['lang']) }}</th>
|
|
|
|
</tr>
|
|
|
|
</thead>
|
|
|
|
<tbody>
|
|
|
|
{% for webhook in data['webhooks'] %}
|
|
|
|
<tr>
|
|
|
|
<td id="{{webhook.enabled}}" class="enabled">
|
|
|
|
<button type="button" class="btn btn-sm btn-info btn-toggle webhook-custom-toggle" id="webhook_{{webhook.id}}" name="webhook_{{webhook.id}}" data-webhook-id="{{webhook.id}}" data-webhook-enabled="{{ 'true' if webhook.enabled else 'false' }}" data-toggle="button" aria-pressed="true" autocomplete="off">
|
|
|
|
<div class="handle"></div>
|
|
|
|
</button>
|
|
|
|
</td>
|
|
|
|
<td id="{{webhook.name}}" class="id">
|
|
|
|
<p>{{webhook.name}}</p>
|
|
|
|
</td>
|
|
|
|
<td id="{{webhook.webhook_type}}" class="type">
|
|
|
|
<p>{{webhook.webhook_type}}</p>
|
|
|
|
</td>
|
|
|
|
<td id="{{webhook.trigger}}" class="trigger" style="overflow: scroll; max-width: 30px;">
|
|
|
|
<ul>
|
|
|
|
{% for trigger in webhook.trigger.split(",") %}
|
|
|
|
{% if trigger in data["triggers"] %}
|
|
|
|
<li>{{translate('webhooks', trigger , data['lang'])}}</li>
|
|
|
|
{%end%}
|
|
|
|
{%end%}
|
|
|
|
</ul>
|
|
|
|
</td>
|
|
|
|
<td id="webhook_edit" class="action">
|
|
|
|
<button onclick="window.location.href=`/panel/webhook_edit?id={{ data['server_stats']['server_id']['server_id'] }}&webhook_id={{webhook.id}}`" class="btn btn-info">
|
|
|
|
<i class="fas fa-pencil-alt"></i>
|
|
|
|
</button>
|
|
|
|
<button data-webhook={{ webhook.id }} class="btn btn-danger del_button">
|
|
|
|
<i class="fas fa-trash" aria-hidden="true"></i>
|
|
|
|
</button>
|
|
|
|
<button data-webhook={{ webhook.id }} data-toggle="tooltip" title="{{ translate('webhooks', 'run', data['lang']) }}" class="btn btn-outline-warning test-socket">
|
|
|
|
<i class="fa-solid fa-vial"></i>
|
|
|
|
</button>
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
{% end %}
|
|
|
|
</tbody>
|
|
|
|
</table>
|
|
|
|
</div>
|
|
|
|
<div class="d-block d-lg-none">
|
|
|
|
<table aria-label="webhooks list" class="table table-hover responsive-table" id="webhook_table_mini" width="100%" style="table-layout:fixed;">
|
|
|
|
<thead>
|
|
|
|
<tr class="rounded">
|
|
|
|
<th style="width: 20%; min-width: 64px;">{{ translate('webhooks', 'enabled',
|
|
|
|
data['lang']) }}</th>
|
|
|
|
<th style="width: 40%; min-width: 10px;">Name
|
|
|
|
</th>
|
|
|
|
<th style="width: 40%; min-width: 50px;">{{ translate('webhooks', 'edit', data['lang'])
|
|
|
|
}}</th>
|
|
|
|
</tr>
|
|
|
|
</thead>
|
|
|
|
<tbody>
|
|
|
|
{% for webhook in data['webhooks'] %}
|
|
|
|
<tr>
|
|
|
|
<td id="{{webhook.enabled}}" class="enabled">
|
|
|
|
<button type="button" class="btn btn-sm btn-info btn-toggle webhook-custom-toggle" id="webhook_{{webhook.id}}" name="webhook_{{webhook.id}}" data-webhook-id="{{webhook.id}}" data-webhook-enabled="{{ 'true' if webhook.enabled else 'false' }}" data-toggle="button" aria-pressed="true" autocomplete="off">
|
|
|
|
<div class="handle"></div>
|
|
|
|
</button>
|
|
|
|
</td>
|
|
|
|
<td id="{{webhook.name}}" class="id">
|
|
|
|
<p>{{webhook.name}}</p>
|
|
|
|
</td>
|
|
|
|
<td id="webhook_edit" class="action">
|
|
|
|
<button onclick="window.location.href=`/panel/webhook_edit?id={{ data['server_stats']['server_id']['server_id'] }}&webhook_id={{webhook.id}}`" class="btn btn-info">
|
|
|
|
<i class="fas fa-pencil-alt"></i>
|
|
|
|
</button>
|
|
|
|
<button data-webhook={{ webhook.id }} class="btn btn-danger del_button">
|
|
|
|
<i class="fas fa-trash" aria-hidden="true"></i>
|
|
|
|
</button>
|
|
|
|
<button data-webhook={{ webhook.id }} data-toggle="tooltip" title="{{ translate('webhooks', 'run', data['lang']) }}" class="btn btn-outline-warning test-socket">
|
|
|
|
<i class="fa-solid fa-vial"></i>
|
|
|
|
</button>
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
{% end %}
|
|
|
|
</tbody>
|
|
|
|
</table>
|
|
|
|
</div>
|
|
|
|
{% end %}
|
2023-06-03 16:21:23 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<style>
|
|
|
|
.popover-body {
|
|
|
|
color: white !important;
|
|
|
|
;
|
|
|
|
}
|
|
|
|
|
|
|
|
.toggle-handle {
|
|
|
|
background-color: white !important;
|
|
|
|
}
|
|
|
|
|
|
|
|
.toggle-on {
|
|
|
|
color: black !important;
|
|
|
|
}
|
|
|
|
|
|
|
|
.toggle {
|
|
|
|
height: 0px !important;
|
|
|
|
}
|
2023-10-21 15:32:48 +00:00
|
|
|
|
|
|
|
td.enabled {
|
|
|
|
vertical-align: middle;
|
|
|
|
border-collapse: collapse !important;
|
|
|
|
}
|
|
|
|
|
|
|
|
.enabled .toggle-group .btn {
|
|
|
|
vertical-align: middle;
|
|
|
|
cursor: pointer;
|
|
|
|
}
|
2023-06-03 16:21:23 +00:00
|
|
|
</style>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
</div>
|
|
|
|
<style>
|
|
|
|
/* Hide scrollbar for Chrome, Safari and Opera */
|
|
|
|
td::-webkit-scrollbar {
|
|
|
|
display: none;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Hide scrollbar for IE, Edge and Firefox */
|
|
|
|
td {
|
|
|
|
-ms-overflow-style: none;
|
|
|
|
/* IE and Edge */
|
|
|
|
scrollbar-width: none;
|
|
|
|
/* Firefox */
|
|
|
|
}
|
|
|
|
</style>
|
|
|
|
<!-- content-wrapper ends -->
|
|
|
|
|
|
|
|
{% end %}
|
|
|
|
|
|
|
|
{% block js %}
|
|
|
|
<script>
|
2023-10-21 15:32:48 +00:00
|
|
|
$(document).ready(function () {
|
2023-06-03 22:38:44 +00:00
|
|
|
console.log('ready for JS!')
|
|
|
|
$('#webhook_table').DataTable({
|
|
|
|
'order': [4, 'asc'],
|
|
|
|
}
|
|
|
|
);
|
|
|
|
$('#webhook_table_mini').DataTable({
|
|
|
|
'order': [2, 'asc']
|
|
|
|
}
|
|
|
|
);
|
|
|
|
document.getElementById('webhook_table_mini_wrapper').hidden = true;
|
|
|
|
});
|
|
|
|
$(document).ready(function () {
|
|
|
|
$('[data-toggle="popover"]').popover();
|
|
|
|
if ($(window).width() < 1000) {
|
|
|
|
$('.too_small').popover("show");
|
|
|
|
document.getElementById('webhook_table_wrapper').hidden = true;
|
|
|
|
document.getElementById('webhook_table_mini_wrapper').hidden = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
$(window).ready(function () {
|
|
|
|
$('body').click(function () {
|
|
|
|
$('.too_small').popover("hide");
|
|
|
|
});
|
|
|
|
});
|
|
|
|
$(window).resize(function () {
|
|
|
|
// This will execute whenever the window is resized
|
|
|
|
if ($(window).width() < 1000) {
|
|
|
|
$('.too_small').popover("show");
|
|
|
|
document.getElementById('webhook_table_wrapper').hidden = true;
|
|
|
|
document.getElementById('webhook_table_mini_wrapper').hidden = false;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$('.too_small').popover("hide");
|
|
|
|
document.getElementById('webhook_table_wrapper').hidden = false;
|
|
|
|
document.getElementById('webhook_table_mini_wrapper').hidden = true;
|
|
|
|
} // New width
|
|
|
|
});
|
2023-06-03 16:21:23 +00:00
|
|
|
|
|
|
|
function debounce(func, timeout = 300) {
|
|
|
|
let timer;
|
|
|
|
return (...args) => {
|
|
|
|
clearTimeout(timer);
|
|
|
|
timer = setTimeout(() => { func.apply(this, args); }, timeout);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-10-21 15:32:48 +00:00
|
|
|
$(document).ready(function () {
|
|
|
|
$('.webhook-custom-toggle').each(function () {
|
2023-06-03 22:10:39 +00:00
|
|
|
const enabled = JSON.parse(this.getAttribute('data-webhook-enabled'));
|
2023-10-21 15:32:48 +00:00
|
|
|
if (enabled) {
|
|
|
|
this.classList.add("active");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
this.classList.remove("active");
|
|
|
|
}
|
2023-06-03 16:21:23 +00:00
|
|
|
})
|
2023-10-21 15:32:48 +00:00
|
|
|
});
|
|
|
|
$(() => {
|
|
|
|
$('.webhook-custom-toggle').click(function () {
|
2023-06-03 22:10:39 +00:00
|
|
|
const id = this.getAttribute('data-webhook-id');
|
2023-10-21 15:32:48 +00:00
|
|
|
const enabled = !JSON.parse(this.getAttribute('data-webhook-enabled'));
|
2023-06-03 16:21:23 +00:00
|
|
|
|
2023-06-03 22:10:39 +00:00
|
|
|
fetch(`/api/v2/servers/{{data['server_id']}}/webhook/${id}`, {
|
2023-06-03 16:21:23 +00:00
|
|
|
method: 'PATCH',
|
|
|
|
body: JSON.stringify({ enabled }),
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
},
|
|
|
|
})
|
|
|
|
});
|
|
|
|
})
|
|
|
|
|
|
|
|
const serverId = new URLSearchParams(document.location.search).get('id')
|
|
|
|
</script>
|
|
|
|
<script>
|
|
|
|
|
|
|
|
|
|
|
|
//used to get cookies from browser - this is part of tornados xsrf protection - it's for extra security
|
|
|
|
function getCookie(name) {
|
|
|
|
var r = document.cookie.match("\\b" + name + "=([^;]*)\\b");
|
|
|
|
return r ? r[1] : undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
$(document).ready(function () {
|
|
|
|
console.log("ready!");
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
$(".del_button").click(function () {
|
2023-06-03 22:10:39 +00:00
|
|
|
var webhook_id = $(this).data('webhook');
|
|
|
|
|
|
|
|
bootbox.confirm({
|
2023-06-03 22:38:44 +00:00
|
|
|
message: "{{ translate('webhooks', 'areYouSureDel', data['lang']) }}",
|
2023-06-03 22:10:39 +00:00
|
|
|
buttons: {
|
|
|
|
cancel: {
|
2023-10-21 15:32:48 +00:00
|
|
|
label: '<i class="fas fa-times"></i> {{ translate("serverSchedules", "cancel", data["lang"]) }}'
|
|
|
|
},
|
2023-06-03 22:10:39 +00:00
|
|
|
confirm: {
|
|
|
|
className: 'btn-outline-danger',
|
2023-10-21 15:32:48 +00:00
|
|
|
label: '<i class="fas fa-check"></i> {{ translate("serverSchedules", "confirm", data["lang"]) }}'
|
|
|
|
}
|
2023-06-03 22:10:39 +00:00
|
|
|
},
|
|
|
|
callback: function (result) {
|
|
|
|
console.log(result);
|
|
|
|
if (result == true) {
|
|
|
|
del_hook(webhook_id, serverId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2023-06-03 16:21:23 +00:00
|
|
|
|
2023-06-03 22:10:39 +00:00
|
|
|
$(".test-socket").click(function () {
|
|
|
|
var webhook_id = $(this).data('webhook');
|
2023-06-03 16:21:23 +00:00
|
|
|
|
|
|
|
bootbox.confirm({
|
2023-06-03 22:38:44 +00:00
|
|
|
message: "{{ translate('webhooks', 'areYouSureRun', data['lang']) }}",
|
2023-06-03 16:21:23 +00:00
|
|
|
buttons: {
|
|
|
|
cancel: {
|
2023-10-21 15:32:48 +00:00
|
|
|
label: '<i class="fas fa-times"></i> {{ translate("serverSchedules", "cancel", data["lang"]) }}'
|
|
|
|
},
|
2023-06-03 16:21:23 +00:00
|
|
|
confirm: {
|
|
|
|
className: 'btn-outline-danger',
|
2023-10-21 15:32:48 +00:00
|
|
|
label: '<i class="fas fa-check"></i> {{ translate("serverSchedules", "confirm", data["lang"]) }}'
|
|
|
|
}
|
2023-06-03 16:21:23 +00:00
|
|
|
},
|
|
|
|
callback: function (result) {
|
|
|
|
console.log(result);
|
|
|
|
if (result == true) {
|
2023-06-03 22:10:39 +00:00
|
|
|
test_hook(webhook_id, serverId);
|
2023-06-03 16:21:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2023-06-03 22:10:39 +00:00
|
|
|
async function test_hook(webhook_id, id) {
|
|
|
|
var token = getCookie("_xsrf")
|
|
|
|
|
|
|
|
let res = await fetch(`/api/v2/servers/${id}/webhook/${webhook_id}/`, {
|
|
|
|
method: 'POST',
|
|
|
|
headers: {
|
|
|
|
'token': token,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
let responseData = await res.json();
|
|
|
|
if (responseData.status === "ok") {
|
|
|
|
bootbox.alert("Webhook Sent!")
|
2023-10-21 15:32:48 +00:00
|
|
|
} else {
|
2023-06-03 22:10:39 +00:00
|
|
|
console.log(responseData);
|
2023-10-21 15:32:48 +00:00
|
|
|
bootbox.alert({
|
|
|
|
title: responseData.status,
|
|
|
|
message: responseData.error
|
|
|
|
});
|
2023-06-03 22:10:39 +00:00
|
|
|
}
|
|
|
|
}
|
2023-06-03 16:21:23 +00:00
|
|
|
|
2023-06-03 22:10:39 +00:00
|
|
|
async function del_hook(webhook_id, id) {
|
2023-06-03 16:21:23 +00:00
|
|
|
var token = getCookie("_xsrf")
|
|
|
|
|
2023-06-03 22:10:39 +00:00
|
|
|
let res = await fetch(`/api/v2/servers/${id}/webhook/${webhook_id}`, {
|
2023-06-03 16:21:23 +00:00
|
|
|
method: 'DELETE',
|
|
|
|
headers: {
|
|
|
|
'token': token,
|
|
|
|
},
|
|
|
|
});
|
2023-06-03 22:10:39 +00:00
|
|
|
let responseData = await res.json();
|
2023-06-03 22:44:18 +00:00
|
|
|
if (responseData.status === "ok") {
|
2023-06-03 16:21:23 +00:00
|
|
|
window.location.reload();
|
2023-10-21 15:32:48 +00:00
|
|
|
} else {
|
2023-06-03 22:10:39 +00:00
|
|
|
bootbox.alert({
|
2023-10-21 15:32:48 +00:00
|
|
|
title: responseData.status,
|
|
|
|
message: responseData.error
|
|
|
|
});
|
2023-06-03 16:21:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
{% end %}
|