mirror of
https://gitlab.com/crafty-controller/crafty-4.git
synced 2024-08-30 18:23:09 +00:00
Merge branch 'admin-controls' into 'dev'
Player controls See merge request crafty-controller/crafty-commander!26
This commit is contained in:
commit
653a4d6bc7
@ -9,6 +9,7 @@ import datetime
|
|||||||
from app.classes.shared.helpers import helper
|
from app.classes.shared.helpers import helper
|
||||||
from app.classes.minecraft.mc_ping import ping
|
from app.classes.minecraft.mc_ping import ping
|
||||||
from app.classes.shared.controller import controller
|
from app.classes.shared.controller import controller
|
||||||
|
from app.classes.shared.models import db_helper
|
||||||
from app.classes.shared.models import Host_Stats, Server_Stats
|
from app.classes.shared.models import Host_Stats, Server_Stats
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
@ -151,6 +152,32 @@ class Stats:
|
|||||||
}
|
}
|
||||||
|
|
||||||
return ping_data
|
return ping_data
|
||||||
|
|
||||||
|
def get_server_players(self, server_id):
|
||||||
|
|
||||||
|
server = db_helper.get_server_data_by_id(server_id)
|
||||||
|
|
||||||
|
logger.info("Getting players for server {}".format(server))
|
||||||
|
|
||||||
|
# get our settings and data dictionaries
|
||||||
|
server_settings = server.get('server_settings', {})
|
||||||
|
server_data = server.get('server_data_obj', {})
|
||||||
|
|
||||||
|
|
||||||
|
# TODO: search server properties file for possible override of 127.0.0.1
|
||||||
|
internal_ip = server_data.get('server_ip', "127.0.0.1")
|
||||||
|
server_port = server_settings.get('server_port', "25565")
|
||||||
|
|
||||||
|
logger.debug("Pinging {} on port {}".format(internal_ip, server_port))
|
||||||
|
int_mc_ping = ping(internal_ip, int(server_port))
|
||||||
|
|
||||||
|
ping_data = {}
|
||||||
|
|
||||||
|
# if we got a good ping return, let's parse it
|
||||||
|
if int_mc_ping:
|
||||||
|
ping_data = self.parse_server_ping(int_mc_ping)
|
||||||
|
return ping_data['players']
|
||||||
|
return []
|
||||||
|
|
||||||
def get_servers_stats(self):
|
def get_servers_stats(self):
|
||||||
|
|
||||||
|
@ -516,6 +516,22 @@ class Helpers:
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
def in_path(x, y):
|
def in_path(x, y):
|
||||||
return os.path.abspath(y).__contains__(os.path.abspath(x))
|
return os.path.abspath(y).__contains__(os.path.abspath(x))
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def get_banned_players(server_id, db_helper):
|
||||||
|
stats = db_helper.get_server_stats_by_id(server_id)
|
||||||
|
server_path = stats[0]['server_id']['path']
|
||||||
|
path = os.path.join(server_path, 'banned-players.json')
|
||||||
|
|
||||||
|
try:
|
||||||
|
with open(path) as file:
|
||||||
|
content = file.read()
|
||||||
|
file.close()
|
||||||
|
except Exception as ex:
|
||||||
|
print (ex)
|
||||||
|
return None
|
||||||
|
|
||||||
|
return json.loads(content)
|
||||||
|
|
||||||
|
|
||||||
helper = Helpers()
|
helper = Helpers()
|
||||||
|
@ -12,6 +12,7 @@ from app.classes.web.base_handler import BaseHandler
|
|||||||
from app.classes.shared.controller import controller
|
from app.classes.shared.controller import controller
|
||||||
from app.classes.shared.models import db_helper, Servers
|
from app.classes.shared.models import db_helper, Servers
|
||||||
from app.classes.shared.helpers import helper
|
from app.classes.shared.helpers import helper
|
||||||
|
from app.classes.minecraft.stats import stats
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -106,7 +107,7 @@ class PanelHandler(BaseHandler):
|
|||||||
self.redirect("/panel/error?error=Invalid Server ID")
|
self.redirect("/panel/error?error=Invalid Server ID")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
valid_subpages = ['term', 'logs', 'config', 'files']
|
valid_subpages = ['term', 'logs', 'config', 'files', 'admin_controls']
|
||||||
|
|
||||||
if subpage not in valid_subpages:
|
if subpage not in valid_subpages:
|
||||||
logger.debug('not a valid subpage')
|
logger.debug('not a valid subpage')
|
||||||
@ -116,6 +117,29 @@ class PanelHandler(BaseHandler):
|
|||||||
# server_data isn't needed since the server_stats also pulls server data
|
# server_data isn't needed since the server_stats also pulls server data
|
||||||
# page_data['server_data'] = db_helper.get_server_data_by_id(server_id)
|
# page_data['server_data'] = db_helper.get_server_data_by_id(server_id)
|
||||||
page_data['server_stats'] = db_helper.get_server_stats_by_id(server_id)
|
page_data['server_stats'] = db_helper.get_server_stats_by_id(server_id)
|
||||||
|
page_data['get_players'] = lambda: stats.get_server_players(server_id)
|
||||||
|
|
||||||
|
def get_banned_players_html():
|
||||||
|
banned_players = helper.get_banned_players(server_id, db_helper)
|
||||||
|
if banned_players is None:
|
||||||
|
return """
|
||||||
|
<li class="playerItem banned">
|
||||||
|
<h3>Error while reading banned-players.json</h3>
|
||||||
|
</li>
|
||||||
|
"""
|
||||||
|
html = ""
|
||||||
|
for player in banned_players:
|
||||||
|
html += """
|
||||||
|
<li class="playerItem banned">
|
||||||
|
<h3>{}</h3>
|
||||||
|
<span>Banned by {} for reason: {}</span>
|
||||||
|
<button onclick="send_command_to_server('pardon {}')" type="button" class="btn btn-danger">Unban</button>
|
||||||
|
</li>
|
||||||
|
""".format(player['name'], player['source'], player['reason'], player['name'])
|
||||||
|
|
||||||
|
return html
|
||||||
|
if subpage == "admin_controls":
|
||||||
|
page_data['banned_players'] = get_banned_players_html()
|
||||||
|
|
||||||
# template = "panel/server_details.html"
|
# template = "panel/server_details.html"
|
||||||
template = "panel/server_{subpage}.html".format(subpage=subpage)
|
template = "panel/server_{subpage}.html".format(subpage=subpage)
|
||||||
|
184
app/frontend/templates/panel/server_admin_controls.html
Normal file
184
app/frontend/templates/panel/server_admin_controls.html
Normal file
@ -0,0 +1,184 @@
|
|||||||
|
{% extends ../base.html %}
|
||||||
|
|
||||||
|
{% block meta %}
|
||||||
|
<!-- <meta http-equiv="refresh" content="60">-->
|
||||||
|
{% end %}
|
||||||
|
|
||||||
|
{% block title %}Crafty Controller - Server Details{% 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">
|
||||||
|
Server Details - {{ data['server_stats'][0]['server_id']['server_name'] }}
|
||||||
|
<br />
|
||||||
|
<small>UUID: {{ data['server_stats'][0]['server_id']['server_uuid'] }}</small>
|
||||||
|
</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">
|
||||||
|
<ul class="nav nav-tabs col-md-12 tab-simple-styled " role="tablist">
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link" href="/panel/server_detail?id={{ data['server_stats'][0]['server_id']['server_id'] }}&subpage=term" role="tab" aria-selected="false">
|
||||||
|
<i class="fas fa-file-signature"></i>Terminal</a>
|
||||||
|
</li>
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link" href="/panel/server_detail?id={{ data['server_stats'][0]['server_id']['server_id'] }}&subpage=logs" role="tab" aria-selected="false">
|
||||||
|
<i class="fas fa-file-signature"></i>Logs</a>
|
||||||
|
</li>
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link" href="/panel/server_detail?id={{ data['server_stats'][0]['server_id']['server_id'] }}&subpage=tasks" role="tab" aria-selected="false">
|
||||||
|
<i class="fas fa-clock"></i>Schedule</a>
|
||||||
|
</li>
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link" href="/panel/server_detail?id={{ data['server_stats'][0]['server_id']['server_id'] }}&subpage=backup" role="tab" aria-selected="false">
|
||||||
|
<i class="fas fa-save"></i>Backup</a>
|
||||||
|
</li>
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link" href="/panel/server_detail?id={{ data['server_stats'][0]['server_id']['server_id'] }}&subpage=files" role="tab" aria-selected="false">
|
||||||
|
<i class="fas fa-folder-tree"></i>Files</a>
|
||||||
|
</li>
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link" href="/panel/server_detail?id={{ data['server_stats'][0]['server_id']['server_id'] }}&subpage=config" role="tab" aria-selected="true">
|
||||||
|
<i class="fas fa-cogs"></i>Config</a>
|
||||||
|
</li>
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link active" href="/panel/server_detail?id={{ data['server_stats'][0]['server_id']['server_id'] }}&subpage=admin_controls" role="tab" aria-selected="true">
|
||||||
|
<i class="fas fa-users"></i>Player Controls</a>
|
||||||
|
</li>
|
||||||
|
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-6 col-sm-12">
|
||||||
|
<style>
|
||||||
|
.playerItem {
|
||||||
|
background: #1c1e2f;
|
||||||
|
padding: 1rem;
|
||||||
|
display: flex;
|
||||||
|
flex-flow: row wrap;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
margin: 1rem 0px 1rem 0px;
|
||||||
|
}
|
||||||
|
.playerItem h3 {
|
||||||
|
vertical-align: middle;
|
||||||
|
padding: 0px;
|
||||||
|
margin: 0px;
|
||||||
|
margin-right: 1.5rem;
|
||||||
|
}
|
||||||
|
.playerItem button {
|
||||||
|
vertical-align: middle;
|
||||||
|
margin: 0.25rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.playerUnban {
|
||||||
|
margin-bottom: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.banned span {
|
||||||
|
font-size: 1.1rem;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
<h2>Players:</h2>
|
||||||
|
<ul style="list-style: none;padding: 0px;margin: 0px; margin-bottom: 1rem;gap: 1rem;">
|
||||||
|
{% for player in data['get_players']() %}
|
||||||
|
<li class="playerItem">
|
||||||
|
<h3>{{ player }}</h3>
|
||||||
|
<div class="buttons">
|
||||||
|
<button onclick="send_command_to_server('ban {{ player }}')" type="button" class="btn btn-danger">Ban</button>
|
||||||
|
<button onclick="send_command_to_server('kick {{ player }}')" type="button" class="btn btn-outline-danger">Kick</button>
|
||||||
|
<button onclick="send_command_to_server('op {{ player }}')" type="button" class="btn btn-warning">OP</button>
|
||||||
|
<button onclick="send_command_to_server('deop {{ player }}')" type="button" class="btn btn-outline-warning">De-OP</button>
|
||||||
|
</div>
|
||||||
|
</li>
|
||||||
|
{% end %}
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-6 col-sm-12">
|
||||||
|
<h2>Banned Players:</h2>
|
||||||
|
<ul id="bannedPlayers" style="list-style: none;padding: 0px;margin: 0px; margin-bottom: 1rem;gap: 1rem;">
|
||||||
|
<li class="playerItem banned">
|
||||||
|
<h3>Loading Banned Players</h3>
|
||||||
|
</li>
|
||||||
|
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</div>
|
||||||
|
<!-- content-wrapper ends -->
|
||||||
|
|
||||||
|
{% end %}
|
||||||
|
|
||||||
|
{% block js %}
|
||||||
|
<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;
|
||||||
|
}
|
||||||
|
|
||||||
|
function htmlDecode(input){
|
||||||
|
var e = document.createElement('textarea');
|
||||||
|
e.innerHTML = input;
|
||||||
|
// handle case of empty input
|
||||||
|
return e.childNodes.length === 0 ? "" : e.childNodes[0].nodeValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$( document ).ready(function() {
|
||||||
|
console.log( "ready!" );
|
||||||
|
|
||||||
|
var bannedPlayers = `{{ data['banned_players'] }}`;
|
||||||
|
|
||||||
|
var bannedPlayersDecoded = htmlDecode(bannedPlayers);
|
||||||
|
|
||||||
|
$("#bannedPlayers").html(bannedPlayersDecoded)
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
function send_command_to_server (command) {
|
||||||
|
console.log(command)
|
||||||
|
var token = getCookie("_xsrf")
|
||||||
|
console.log('sending command: ' + command)
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
type: "POST",
|
||||||
|
headers: {'X-XSRFToken': token},
|
||||||
|
url: '/ajax/send_command?id=1',
|
||||||
|
data: { command },
|
||||||
|
success: function(data){
|
||||||
|
console.log("got response:");
|
||||||
|
console.log(data);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
</script>
|
||||||
|
|
||||||
|
{% end %}
|
@ -57,6 +57,10 @@
|
|||||||
<a class="nav-link active" href="/panel/server_detail?id={{ data['server_stats'][0]['server_id']['server_id'] }}&subpage=config" role="tab" aria-selected="true">
|
<a class="nav-link active" href="/panel/server_detail?id={{ data['server_stats'][0]['server_id']['server_id'] }}&subpage=config" role="tab" aria-selected="true">
|
||||||
<i class="fas fa-cogs"></i>Config</a>
|
<i class="fas fa-cogs"></i>Config</a>
|
||||||
</li>
|
</li>
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link" href="/panel/server_detail?id={{ data['server_stats'][0]['server_id']['server_id'] }}&subpage=admin_controls" role="tab" aria-selected="true">
|
||||||
|
<i class="fas fa-users"></i>Player Controls</a>
|
||||||
|
</li>
|
||||||
|
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
|
@ -57,6 +57,10 @@
|
|||||||
<a class="nav-link" href="/panel/server_detail?id={{ data['server_stats'][0]['server_id']['server_id'] }}&subpage=config" role="tab" aria-selected="true">
|
<a class="nav-link" href="/panel/server_detail?id={{ data['server_stats'][0]['server_id']['server_id'] }}&subpage=config" role="tab" aria-selected="true">
|
||||||
<i class="fas fa-cogs"></i>Config</a>
|
<i class="fas fa-cogs"></i>Config</a>
|
||||||
</li>
|
</li>
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link" href="/panel/server_detail?id={{ data['server_stats'][0]['server_id']['server_id'] }}&subpage=admin_controls" role="tab" aria-selected="true">
|
||||||
|
<i class="fas fa-users"></i>Player Controls</a>
|
||||||
|
</li>
|
||||||
|
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
|
@ -58,6 +58,10 @@
|
|||||||
<a class="nav-link" href="/panel/server_detail?id={{ data['server_stats'][0]['server_id']['server_id'] }}&subpage=config" role="tab" aria-selected="false">
|
<a class="nav-link" href="/panel/server_detail?id={{ data['server_stats'][0]['server_id']['server_id'] }}&subpage=config" role="tab" aria-selected="false">
|
||||||
<i class="fas fa-cogs"></i>Config</a>
|
<i class="fas fa-cogs"></i>Config</a>
|
||||||
</li>
|
</li>
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link" href="/panel/server_detail?id={{ data['server_stats'][0]['server_id']['server_id'] }}&subpage=admin_controls" role="tab" aria-selected="true">
|
||||||
|
<i class="fas fa-users"></i>Player Controls</a>
|
||||||
|
</li>
|
||||||
|
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
|
@ -58,6 +58,10 @@
|
|||||||
<a class="nav-link" href="/panel/server_detail?id={{ data['server_stats'][0]['server_id']['server_id'] }}&subpage=config" role="tab" aria-selected="false">
|
<a class="nav-link" href="/panel/server_detail?id={{ data['server_stats'][0]['server_id']['server_id'] }}&subpage=config" role="tab" aria-selected="false">
|
||||||
<i class="fas fa-cogs"></i>Config</a>
|
<i class="fas fa-cogs"></i>Config</a>
|
||||||
</li>
|
</li>
|
||||||
|
<li class="nav-item term-nav-item">
|
||||||
|
<a class="nav-link" href="/panel/server_detail?id={{ data['server_stats'][0]['server_id']['server_id'] }}&subpage=admin_controls" role="tab" aria-selected="true">
|
||||||
|
<i class="fas fa-users"></i>Player Controls</a>
|
||||||
|
</li>
|
||||||
<li class="nav-item term-nav-item">
|
<li class="nav-item term-nav-item">
|
||||||
<label class="p-0 m-0">
|
<label class="p-0 m-0">
|
||||||
<input type="checkbox" name="stop_scroll" id="stop_scroll" />
|
<input type="checkbox" name="stop_scroll" id="stop_scroll" />
|
||||||
|
Loading…
Reference in New Issue
Block a user