Merge branch 'dev-staging' into 'dev'

Fix notify.html to properly check for superuser

See merge request crafty-controller/crafty-commander!73
This commit is contained in:
Andrew 2021-09-20 22:40:06 +00:00
commit 0cac7fcd1e
11 changed files with 85 additions and 13 deletions

View File

@ -86,6 +86,14 @@ class Controller:
# add this temp object to the list of init servers
self.servers_list.append(temp_server_dict)
if s['auto_start']:
db_helper.set_waiting_start(s['server_id'], True)
db_helper.get_waiting_start(s['server_id'])
server_stats = db_helper.get_all_servers_stats()
self.refresh_server_settings(s['server_id'])
console.info("Loaded Server: ID {} | Name: {} | Autostart: {} | Delay: {} ".format(
s['server_id'],
s['server_name'],

View File

@ -162,6 +162,7 @@ class Server_Stats(Model):
desc = CharField(default="Unable to Connect")
version = CharField(default="")
updating = BooleanField(default=False)
waiting_start = BooleanField(default=False)
class Meta:
@ -459,6 +460,20 @@ class db_shortcuts:
with database.atomic():
Server_Stats.update(updating=value).where(Server_Stats.server_id == server_id).execute()
@staticmethod
def set_waiting_start(server_id, value):
try:
row = Server_Stats.select().where(Server_Stats.server_id == server_id)
except Exception as ex:
logger.error("Database entry not found. ".format(ex))
with database.atomic():
Server_Stats.update(waiting_start=value).where(Server_Stats.server_id == server_id).execute()
@staticmethod
def get_waiting_start(server_id):
waiting_start = Server_Stats.select().where(Server_Stats.server_id == server_id).get()
return waiting_start.waiting_start
@staticmethod
def get_TTL_without_player(server_id):
last_stat = Server_Stats.select().where(Server_Stats.server_id == server_id).order_by(Server_Stats.created.desc()).first()

View File

@ -206,7 +206,7 @@ class Server:
'error': translation.translate('error', 'internet')
})
db_helper.set_waiting_start(self.server_id, False)
self.process = pexpect.spawn(self.server_command, cwd=self.server_path, timeout=None, encoding='utf-8')
out_buf = ServerOutBuf(self.process, self.server_id)

View File

@ -123,6 +123,8 @@ class PanelHandler(BaseHandler):
elif page == 'dashboard':
if exec_user['superuser'] == 1:
page_data['servers'] = db_helper.get_all_servers_stats()
for data in page_data['servers']:
data['stats']['waiting_start'] = db_helper.get_waiting_start(int(data['stats']['server_id']['server_id']))
else:
user_auth = db_helper.get_authorized_servers_stats(exec_user_id)
logger.debug("ASFR: {}".format(user_auth))
@ -172,6 +174,7 @@ class PanelHandler(BaseHandler):
# 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_stats'] = db_helper.get_server_stats_by_id(server_id)
page_data['waiting_start'] = db_helper.get_waiting_start(server_id)
page_data['get_players'] = lambda: self.controller.stats.get_server_players(server_id)
page_data['active_link'] = subpage
page_data['permissions'] = {
@ -638,7 +641,10 @@ class PanelHandler(BaseHandler):
server_id = self.get_argument('id', None)
backup_path = bleach.clean(self.get_argument('backup_path', None))
max_backups = bleach.clean(self.get_argument('max_backups', None))
enabled = int(float(bleach.clean(self.get_argument('auto_enabled'), '0')))
try:
enabled = int(float(bleach.clean(self.get_argument('auto_enabled'), '0')))
except Exception as e:
enabled = '0'
if not exec_user['superuser']:
self.redirect("/panel/error?error=Unauthorized access: not superuser")
@ -653,10 +659,16 @@ class PanelHandler(BaseHandler):
return
if backup_path is not None:
Servers.update({
Servers.backup_path: backup_path
}).where(Servers.server_id == server_id).execute()
db_helper.set_backup_config(server_id, max_backups=max_backups)
if enabled == '0':
Servers.update({
Servers.backup_path: backup_path
}).where(Servers.server_id == server_id).execute()
db_helper.set_backup_config(server_id, max_backups=max_backups, auto_enabled=False)
else:
Servers.update({
Servers.backup_path: backup_path
}).where(Servers.server_id == server_id).execute()
db_helper.set_backup_config(server_id, max_backups=max_backups, auto_enabled=True)
db_helper.add_to_audit_log(exec_user['user_id'],
"Edited server {}: updated backups".format(server_id),

View File

@ -28,7 +28,7 @@
<p class="font-weight-light text-muted mb-0">{{ r }}</p>
{% end %}
</div>
{% if data['super_user'] %}
{% if "Super User" in data['user_role'] %}
<a class="dropdown-item" href="/panel/activity_logs"><i class="dropdown-item-icon mdi mdi-calendar-check-outline text-primary"></i> Activity</a>
{% end %}
<a class="dropdown-item" href="/public/logout"><i class="dropdown-item-icon mdi mdi-power text-primary"></i>Sign Out</a>

View File

@ -131,6 +131,8 @@
<a class="kill_button" data-id="{{server['server_data']['server_id']}}" class="kill_button" data-toggle="tooltip" title={{ translate('dashboard', 'kill') }}> <i class="fas fa-skull"></i></a> &nbsp;
{% elif server['stats']['updating']%}
<a data-id="{{server['server_data']['server_id']}}" class="">{{ translate('serverTerm', 'updating') }}</i></a>
{% elif server['stats']['waiting_start']%}
<a data-id="{{server['server_data']['server_id']}}" class="" title={{ translate('dashboard', 'delay-explained')}}>{{ translate('dashboard', 'starting') }}</i></a>
{% else %}
<a data-id="{{server['server_data']['server_id']}}" class="play_button"><i class="fas fa-play" data-toggle="tooltip" title={{ translate('dashboard', 'start') }}></i></a> &nbsp;
<a data-id="{{server['server_data']['server_id']}}" class="clone_button"> <i class="fas fa-clone" data-toggle="tooltip" title={{ translate('dashboard', 'clone') }}></i></a>&nbsp;

View File

@ -54,6 +54,12 @@
<button onclick="" id="restart-btn" style="max-width: 7rem;" class="btn btn-outline-primary m-1 flex-grow-1 disabled">{% raw translate('serverTerm', 'restart') %}</button>
<button onclick="" id="stop-btn" style="max-width: 7rem;" class="btn btn-danger m-1 flex-grow-1 disabled">{{ translate('serverTerm', 'stop') }}</button>
</div>
{% elif data['waiting_start'] %}
<div id="control_buttons" class="mt-4 flex-wrap d-flex justify-content-between justify-content-md-center align-items-center px-5 px-md-0" style="visibility: visible">
<button onclick="" id="start-btn" style="max-width: 7rem; white-space: nowrap;" class="btn btn-secondary m-1 flex-grow-1 disabled" data-toggle="tooltip" title="{{ translate('serverTerm', 'delay-explained')}}">{{ translate('serverTerm', 'starting') }}</button>
<button onclick="" id="restart-btn" style="max-width: 7rem;" class="btn btn-outline-primary m-1 flex-grow-1 disabled">{% raw translate('serverTerm', 'restart') %}</button>
<button onclick="" id="stop-btn" style="max-width: 7rem;" class="btn btn-danger m-1 flex-grow-1 disabled">{{ translate('serverTerm', 'stop') }}</button>
</div>
{% else %}
<div id="control_buttons" class="mt-4 flex-wrap d-flex justify-content-between justify-content-md-center align-items-center px-5 px-md-0" style="visibility: visible">
<button onclick="send_command(server_id, 'start_server');" id="start-btn" style="max-width: 7rem;" class="btn btn-primary m-1 flex-grow-1">{{ translate('serverTerm', 'start') }}</button>

View File

@ -0,0 +1,16 @@
# Generated by database migrator
import peewee
def migrate(migrator, database, **kwargs):
migrator.add_columns('server_stats', waiting_start=peewee.BooleanField(default=False))
"""
Write your migrations here.
"""
def rollback(migrator, database, **kwargs):
migrator.drop_columns('server_stats', ['waiting_start'])
"""
Write your rollback migrations here.
"""

View File

@ -98,7 +98,9 @@
"clone": "Clone",
"kill": "Kill Process",
"restart": "Restart",
"killing": "Killing process..."
"killing": "Killing process...",
"starting": "Delayed-Start",
"delay-explained": "The service/agent has recently started and is delaying the start of the minecraft server instance"
},
"accessDenied": {
"accessDenied": "Access Denied",
@ -138,7 +140,9 @@
"start": "Start",
"restart": "Restart",
"stop": "Stop",
"updating": "Updating..."
"updating": "Updating...",
"starting": "Delayed-Start",
"delay-explained": "The service/agent has recently started and is delaying the start of the minecraft server instance"
},
"serverPlayerManagement": {
"players": "Players",

View File

@ -98,7 +98,9 @@
"clone": "Klooni",
"kill": "Tapa prosessi",
"restart": "Uudelleenkäynnistää",
"killing": "Tappamisprosessi ..."
"killing": "Tappamisprosessi ...",
"starting": "Myöhästynyt lähtö",
"delay-explained": "Palvelu/agentti on äskettäin aloittanut ja viivästyttää minecraft -palvelimen ilmentymän alkua"
},
"accessDenied": {
"accessDenied": "Käyttö estetty",
@ -137,7 +139,10 @@
"sendCommand": "Lähetä komento",
"start": "Käynnistä",
"restart": "Uudelleen&shy;käynnistä",
"stop": "Sammuta"
"stop": "Sammuta",
"updating": "Updating",
"starting": "Myöhästynyt lähtö",
"delay-explained": "Palvelu/agentti on äskettäin aloittanut ja viivästyttää minecraft -palvelimen ilmentymän alkua"
},
"serverPlayerManagement": {
"players": "Pelaajat",

View File

@ -98,7 +98,9 @@
"clone": "Cloner",
"kill": "Tuer le processus",
"restart": "Redémarrage",
"killing": "Processus de mise à mort..."
"killing": "Processus de mise à mort...",
"starting": "Démarrage retardé",
"delay-explained": "Le service/agent a récemment démarré et retarde le démarrage de l'instance du serveur minecraft"
},
"accessDenied": {
"accessDenied": "Accès Interdit",
@ -138,7 +140,9 @@
"start": "Démarrer",
"restart": "Redémarrer",
"stop": "Arrêter",
"updating": "Mise à Jour ..."
"updating": "Mise à Jour ...",
"starting": "Démarrage retardé",
"delay-explained": "Le service/agent a récemment démarré et retarde le démarrage de l'instance du serveur minecraft"
},
"serverPlayerManagement": {
"players": "Joueurs",