crafty-4/app/frontend/templates/panel/server_logs.html

227 lines
6.4 KiB
HTML
Raw Normal View History

{% extends ../base.html %}
{% block meta %}
{% end %}
{% block title %}Crafty Controller - {{ translate('serverDetails', 'serverDetails', data['lang']) }}{% end %}
{% block content %}
<div class="content-wrapper">
2022-06-21 19:59:34 +00:00
<!-- Page Title Header Starts-->
<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 />
2023-11-01 17:44:56 +00:00
<small>UUID: {{ data['server_stats']['server_id']['server_id'] }}</small>
</h4>
</div>
</div>
</div>
<!-- Page Title Header Ends-->
2022-06-21 19:59:34 +00:00
{% include "parts/details_stats.html" %}
<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=""
style="width: 100%; font-size: .8em; padding: 5px 10px; border: 1px solid var(--outline); background-color:var(--card-banner-bg);height:500px; overflow: scroll;">
</div>
2022-06-21 19:59:34 +00:00
</div>
<br />
<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 />
2022-06-21 19:59:34 +00:00
</div>
</div>
</div>
</div>
</div>
<span class="is-hidden">secret</span>
</div>
<style>
.is-hidden {
display: none;
position: fixed !important;
}
</style>
<!-- content-wrapper ends -->
{% end %}
{% block js %}
<script>
// ##### Log Filter Block #####
2023-09-05 00:05:25 +00:00
let lines = [];
let words = [];
if (localStorage.getItem("words")) {
try {
2022-10-18 04:22:06 +00:00
words = JSON.parse(localStorage.getItem("words"));
} catch {
2022-10-18 04:22:06 +00:00
words = [];
}
}
2022-10-22 18:43:59 +00:00
function hideFilteredWords() {
for (let i = 0; i < lines.length; i++) {
2022-10-18 04:22:06 +00:00
// Reinitialise line visibility
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
if (words.some(ai => lines[i].textContent.toLowerCase().includes(ai))) {
lines[i].classList.add("is-hidden");
}
}
}
function sanitize(string) {
return string.replace(/[`~!@#$%^&*()_|+\-=?;:'",.<>\{\}\[\]\\\/]/gi, '');
}
2022-10-22 18:43:59 +00:00
function deleteWord(item) {
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();
localStorage.setItem("words", JSON.stringify(words));
}
//A little delay
let typingTimer;
let typeInterval = 500;
let searchInput = document.getElementById('searchbox');
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;
let word = document.getElementById("searchbox").value;
document.getElementById("searchbox").value = "";
2022-10-22 17:08:35 +00:00
word = word.toLowerCase();
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;
}
if (words.includes(safe_word)) return;
// Display filtered word
2022-10-22 17:08:35 +00:00
words.push(word);
$("#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}&nbsp;<button class='btn btn-danger' onclick='deleteWord("${word}")' >` +
"<i class='fas fa-trash'></i></button></div></li>"
);
2022-10-22 17:08:35 +00:00
// Set word filters in browser cache
localStorage.setItem("words", JSON.stringify(words));
});
function populateWords() {
words.map(word => {
let safe_word = sanitize(word);
$("#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}&nbsp;<button class='btn btn-danger' onclick='deleteWord("${word}")' >` +
"<i class='fas fa-trash'></i></button></div></li>"
);
});
}
// ##### 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;
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
},
});
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
}
}
$(document).ready(function () {
console.log("ready!");
get_server_log();
populateWords();
});
</script>
2023-09-04 23:22:11 +00:00
{% end %}