2020-09-04 02:49:20 +00:00
|
|
|
{% extends ../base.html %}
|
|
|
|
|
|
|
|
{% block meta %}
|
|
|
|
{% end %}
|
|
|
|
|
2021-09-29 02:25:47 +00:00
|
|
|
{% block title %}Crafty Controller - {{ translate('serverDetails', 'serverDetails', data['lang']) }}{% end %}
|
2020-09-04 02:49:20 +00:00
|
|
|
|
|
|
|
{% block content %}
|
|
|
|
|
|
|
|
<div class="content-wrapper">
|
|
|
|
|
2022-06-21 19:59:34 +00:00
|
|
|
<!-- Page Title Header Starts-->
|
2020-09-04 02:49:20 +00:00
|
|
|
<div class="row page-title-header">
|
|
|
|
<div class="col-12">
|
|
|
|
<div class="page-header">
|
|
|
|
<h4 class="page-title">
|
2022-06-21 19:59:34 +00:00
|
|
|
{{ translate('serverDetails', 'serverDetails', data['lang']) }} - {{
|
|
|
|
data['server_stats']['server_id']['server_name'] }}
|
|
|
|
<br />
|
|
|
|
<small>UUID: {{ data['server_stats']['server_id']['server_uuid'] }}</small>
|
2020-09-04 02:49:20 +00:00
|
|
|
</h4>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
<!-- Page Title Header Ends-->
|
|
|
|
|
2022-06-21 19:59:34 +00:00
|
|
|
{% include "parts/details_stats.html" %}
|
2020-09-04 02:49:20 +00:00
|
|
|
|
|
|
|
<div class="row">
|
|
|
|
|
|
|
|
<div class="col-sm-12 grid-margin">
|
|
|
|
<div class="card">
|
|
|
|
<div class="card-body pt-0">
|
2022-06-21 19:59:34 +00:00
|
|
|
<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="col-md-12">
|
|
|
|
<div class="input-group">
|
|
|
|
<div id="virt_console" class=""
|
2022-10-13 03:29:20 +00:00
|
|
|
style="width: 100%; font-size: .8em; padding: 5px 10px; border: 1px solid var(--outline); background-color:var(--card-banner-bg);height:500px; overflow: scroll;">
|
2020-09-04 02:49:20 +00:00
|
|
|
</div>
|
2022-06-21 19:59:34 +00:00
|
|
|
</div>
|
|
|
|
<br />
|
2022-10-13 03:29:20 +00:00
|
|
|
<label for="ignore">{{ translate('serverDetails', 'filter', data['lang']) }}</label>
|
|
|
|
<input type="text" class="form-control" name="ignore" id="searchbox" value="" required>
|
|
|
|
<br />
|
|
|
|
<br />
|
|
|
|
<h4>{{ translate('serverDetails', 'filterList', data['lang']) }}</h4>
|
|
|
|
<ul id="ignored-words" style="list-style: None;"></ul>
|
|
|
|
<br />
|
2020-09-04 02:49:20 +00:00
|
|
|
|
|
|
|
|
2022-06-21 19:59:34 +00:00
|
|
|
</div>
|
2020-09-04 02:49:20 +00:00
|
|
|
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
2022-10-13 03:29:20 +00:00
|
|
|
<span class="is-hidden">secret</span>
|
2020-09-04 02:49:20 +00:00
|
|
|
</div>
|
2022-10-13 03:29:20 +00:00
|
|
|
<style>
|
|
|
|
.is-hidden {
|
|
|
|
display: none;
|
|
|
|
position: fixed !important;
|
|
|
|
}
|
|
|
|
</style>
|
2020-09-04 02:49:20 +00:00
|
|
|
<!-- content-wrapper ends -->
|
|
|
|
|
|
|
|
{% end %}
|
|
|
|
|
|
|
|
{% block js %}
|
|
|
|
<script>
|
2022-10-22 18:04:57 +00:00
|
|
|
// ##### Log Filter Block #####
|
2023-09-05 00:05:25 +00:00
|
|
|
let lines = [];
|
|
|
|
let words = [];
|
2022-10-13 03:29:20 +00:00
|
|
|
if (localStorage.getItem("words")) {
|
|
|
|
try {
|
2022-10-18 04:22:06 +00:00
|
|
|
words = JSON.parse(localStorage.getItem("words"));
|
2022-10-13 03:29:20 +00:00
|
|
|
} catch {
|
2022-10-18 04:22:06 +00:00
|
|
|
words = [];
|
2022-10-13 03:29:20 +00:00
|
|
|
}
|
|
|
|
}
|
2020-09-04 02:49:20 +00:00
|
|
|
|
2022-10-22 18:43:59 +00:00
|
|
|
function hideFilteredWords() {
|
2022-10-20 17:04:45 +00:00
|
|
|
for (let i = 0; i < lines.length; i++) {
|
2022-10-18 04:22:06 +00:00
|
|
|
// Reinitialise line visibility
|
2022-10-20 17:04:45 +00:00
|
|
|
lines[i].classList.remove("is-hidden");
|
2022-10-18 04:22:06 +00:00
|
|
|
|
|
|
|
// If we have no words to filter, continue.
|
|
|
|
if (!words.length) continue;
|
|
|
|
|
|
|
|
// If we find our target word hide the line
|
2022-10-20 17:04:45 +00:00
|
|
|
if (words.some(ai => lines[i].textContent.toLowerCase().includes(ai))) {
|
|
|
|
lines[i].classList.add("is-hidden");
|
2022-10-13 03:29:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-22 17:11:54 +00:00
|
|
|
function sanitize(string) {
|
|
|
|
return string.replace(/[`~!@#$%^&*()_|+\-=?;:'",.<>\{\}\[\]\\\/]/gi, '');
|
|
|
|
}
|
|
|
|
|
2022-10-22 18:43:59 +00:00
|
|
|
function deleteWord(item) {
|
2022-10-22 18:04:57 +00:00
|
|
|
let safe_item = sanitize(item);
|
|
|
|
words.splice(words.indexOf(item), 1);
|
|
|
|
if (safe_item) $("#" + safe_item.replaceAll(" ", "-")).remove();
|
|
|
|
|
2022-10-22 18:43:59 +00:00
|
|
|
hideFilteredWords();
|
2022-10-22 18:04:57 +00:00
|
|
|
localStorage.setItem("words", JSON.stringify(words));
|
|
|
|
}
|
|
|
|
|
|
|
|
//A little delay
|
|
|
|
let typingTimer;
|
|
|
|
let typeInterval = 500;
|
|
|
|
let searchInput = document.getElementById('searchbox');
|
2022-10-13 03:29:20 +00:00
|
|
|
searchInput.addEventListener('keyup', (e) => {
|
|
|
|
clearTimeout(typingTimer);
|
2022-10-22 18:43:59 +00:00
|
|
|
typingTimer = setTimeout(hideFilteredWords, typeInterval);
|
2022-10-22 17:08:35 +00:00
|
|
|
|
|
|
|
// Return/Enter key press otherwise bail
|
|
|
|
if (e.keyCode !== 13) return;
|
|
|
|
|
2022-10-22 18:24:06 +00:00
|
|
|
let word = document.getElementById("searchbox").value;
|
2022-10-22 17:18:00 +00:00
|
|
|
document.getElementById("searchbox").value = "";
|
2022-10-22 17:08:35 +00:00
|
|
|
word = word.toLowerCase();
|
2022-10-22 18:24:06 +00:00
|
|
|
word = word.replace(/[`'"]/gi, " ");
|
|
|
|
|
|
|
|
let safe_word = sanitize(word).trimLeft();
|
2022-10-22 17:08:35 +00:00
|
|
|
|
|
|
|
if (word.includes("\\n")) {
|
|
|
|
window.alert("Nice try...");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!safe_word) {
|
|
|
|
window.alert("Illegal character detected");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-10-22 18:28:13 +00:00
|
|
|
if (words.includes(safe_word)) return;
|
|
|
|
|
2022-10-22 17:50:48 +00:00
|
|
|
// Display filtered word
|
2022-10-22 17:08:35 +00:00
|
|
|
words.push(word);
|
2022-10-22 17:50:48 +00:00
|
|
|
$("#ignored-words").append(
|
|
|
|
`<li id=${safe_word.replaceAll(" ", "-")}>` +
|
|
|
|
"<div class='card-header header-sm d-flex justify-content-between align-items-center'>" +
|
2022-10-22 18:43:59 +00:00
|
|
|
`${word} <button class='btn btn-danger' onclick='deleteWord("${word}")' >` +
|
2022-10-22 17:50:48 +00:00
|
|
|
"<i class='fas fa-trash'></i></button></div></li>"
|
|
|
|
);
|
2022-10-22 17:08:35 +00:00
|
|
|
|
2022-10-22 17:18:00 +00:00
|
|
|
// Set word filters in browser cache
|
2022-10-22 17:50:48 +00:00
|
|
|
localStorage.setItem("words", JSON.stringify(words));
|
2022-10-13 03:29:20 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
function populateWords() {
|
2022-10-22 18:37:16 +00:00
|
|
|
words.map(word => {
|
|
|
|
let safe_word = sanitize(word);
|
2022-10-22 17:50:48 +00:00
|
|
|
|
|
|
|
$("#ignored-words").append(
|
|
|
|
`<li id=${safe_word.replaceAll(" ", "-")}>` +
|
|
|
|
"<div class='card-header header-sm d-flex justify-content-between align-items-center'>" +
|
2022-10-22 18:43:59 +00:00
|
|
|
`${word} <button class='btn btn-danger' onclick='deleteWord("${word}")' >` +
|
2022-10-22 17:50:48 +00:00
|
|
|
"<i class='fas fa-trash'></i></button></div></li>"
|
|
|
|
);
|
2022-10-22 18:37:16 +00:00
|
|
|
});
|
2022-10-13 03:29:20 +00:00
|
|
|
}
|
2022-10-22 18:04:57 +00:00
|
|
|
// ##### End Log Filter Block #####
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Reset Scroll
|
|
|
|
function scroll() {
|
|
|
|
var logview = $('#virt_console');
|
|
|
|
if (logview.length)
|
|
|
|
logview.scrollTop(logview[0].scrollHeight - logview.height());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Populate logs and filter if present
|
|
|
|
const serverId = new URLSearchParams(document.location.search).get('id')
|
2023-09-04 17:54:24 +00:00
|
|
|
async function get_server_log() {
|
2023-09-04 23:22:11 +00:00
|
|
|
const token = getCookie("_xsrf")
|
|
|
|
let colors = true;
|
2022-10-22 18:04:57 +00:00
|
|
|
if (!$("#stop_scroll").is(':checked')) {
|
2024-01-12 23:33:21 +00:00
|
|
|
let res = await fetch(`/api/v2/servers/${serverId}/logs?colors=${colors}&file=true`, {
|
2023-09-04 17:54:24 +00:00
|
|
|
method: 'GET',
|
|
|
|
headers: {
|
|
|
|
'X-XSRFToken': token
|
2022-10-22 18:04:57 +00:00
|
|
|
},
|
|
|
|
});
|
2023-09-04 17:54:24 +00:00
|
|
|
let responseData = await res.json();
|
2023-09-05 00:05:25 +00:00
|
|
|
let html = ``
|
2023-09-04 17:54:24 +00:00
|
|
|
if (responseData.status === "ok") {
|
2023-09-05 01:14:03 +00:00
|
|
|
for (let value of responseData.data) {
|
|
|
|
html += `<span class='box'>${value}<br /></span>`
|
2023-09-04 17:54:24 +00:00
|
|
|
}
|
|
|
|
console.log('Got Log From Server')
|
|
|
|
$('#virt_console').html(html);
|
|
|
|
scroll();
|
|
|
|
lines = document.querySelectorAll('.box');
|
|
|
|
hideFilteredWords();
|
|
|
|
} else {
|
|
|
|
|
|
|
|
bootbox.alert({
|
|
|
|
title: responseData.status,
|
|
|
|
message: responseData.error
|
|
|
|
});
|
|
|
|
}
|
2023-09-04 23:22:11 +00:00
|
|
|
}
|
2022-10-22 18:04:57 +00:00
|
|
|
}
|
|
|
|
$(document).ready(function () {
|
|
|
|
console.log("ready!");
|
|
|
|
get_server_log();
|
|
|
|
populateWords();
|
|
|
|
});
|
2020-09-04 02:49:20 +00:00
|
|
|
</script>
|
2023-09-04 23:22:11 +00:00
|
|
|
{% end %}
|