mirror of
https://gitlab.com/crafty-controller/crafty-4.git
synced 2024-08-30 18:23:09 +00:00
Add status bar for support log archive
This commit is contained in:
parent
6e4435c86f
commit
3a8174cc22
@ -107,6 +107,14 @@ class Users_Controller:
|
||||
def user_id_exists(user_id):
|
||||
return users_helper.user_id_exists(user_id)
|
||||
|
||||
@staticmethod
|
||||
def set_prepare(user_id):
|
||||
return users_helper.set_prepare(user_id)
|
||||
|
||||
@staticmethod
|
||||
def stop_prepare(user_id):
|
||||
return users_helper.stop_prepare(user_id)
|
||||
|
||||
@staticmethod
|
||||
def get_user_id_by_api_token(token: str) -> str:
|
||||
token_data = authentication.check_no_iat(token)
|
||||
|
@ -37,6 +37,7 @@ class Users(Model):
|
||||
support_logs = CharField(default = '')
|
||||
valid_tokens_from = DateTimeField(default=datetime.datetime.now)
|
||||
server_order = CharField(default="")
|
||||
preparing = BooleanField(default=False)
|
||||
|
||||
class Meta:
|
||||
table_name = "users"
|
||||
@ -197,6 +198,18 @@ class helper_users:
|
||||
def set_support_path(user_id, support_path):
|
||||
Users.update(support_logs = support_path).where(Users.user_id == user_id).execute()
|
||||
|
||||
@staticmethod
|
||||
def set_prepare(user_id):
|
||||
Users.update(preparing = True).where(Users.user_id == user_id).execute()
|
||||
|
||||
@staticmethod
|
||||
def stop_prepare(user_id):
|
||||
Users.update(preparing = False).where(Users.user_id == user_id).execute()
|
||||
|
||||
@staticmethod
|
||||
def clear_support_status():
|
||||
Users.update(preparing = False).where(Users.preparing == True).execute()
|
||||
|
||||
@staticmethod
|
||||
def user_id_exists(user_id):
|
||||
if not users_helper.get_user(user_id):
|
||||
|
@ -6,6 +6,7 @@ import time
|
||||
import logging
|
||||
import tempfile
|
||||
from typing import Union
|
||||
from urllib import request
|
||||
|
||||
from app.classes.controllers.crafty_perms_controller import Crafty_Perms_Controller
|
||||
from app.classes.controllers.management_controller import Management_Controller
|
||||
@ -28,6 +29,9 @@ from app.classes.web.websocket_helper import websocket_helper
|
||||
|
||||
try:
|
||||
from peewee import DoesNotExist
|
||||
#TZLocal is set as a hidden import on win pipeline
|
||||
from tzlocal import get_localzone
|
||||
from apscheduler.schedulers.background import BackgroundScheduler
|
||||
|
||||
except ModuleNotFoundError as err:
|
||||
helper.auto_installer_fix(err)
|
||||
@ -45,6 +49,9 @@ class Controller:
|
||||
self.server_perms = Server_Perms_Controller()
|
||||
self.servers = Servers_Controller()
|
||||
self.users = Users_Controller()
|
||||
tz = get_localzone()
|
||||
self.support_scheduler = BackgroundScheduler(timezone=str(tz))
|
||||
self.support_scheduler.start()
|
||||
|
||||
def check_server_loaded(self, server_id_to_check: int):
|
||||
|
||||
@ -128,6 +135,9 @@ class Controller:
|
||||
|
||||
|
||||
def package_support_logs(self, exec_user):
|
||||
if exec_user['preparing']:
|
||||
return
|
||||
self.users.set_prepare(exec_user['user_id'])
|
||||
#pausing so on screen notifications can run for user
|
||||
time.sleep(7)
|
||||
websocket_helper.broadcast_user(exec_user['user_id'], 'notification', 'Preparing your support logs')
|
||||
@ -161,14 +171,22 @@ class Controller:
|
||||
#Copy crafty logs to archive dir
|
||||
full_log_name = os.path.join(crafty_path, 'logs')
|
||||
file_helper.copy_dir(os.path.join(self.project_root, 'logs'), full_log_name)
|
||||
self.support_scheduler.add_job(self.log_status, 'interval', seconds=1, id="logs_"+str(exec_user['user_id']), args = [full_temp,
|
||||
tempZipStorage +'.zip', exec_user])
|
||||
file_helper.make_archive(tempZipStorage, tempDir)
|
||||
|
||||
if len(websocket_helper.clients) > 0:
|
||||
websocket_helper.broadcast_user(exec_user['user_id'], 'support_status_update', helper.calc_percent(full_temp, tempZipStorage +'.zip'))
|
||||
|
||||
tempZipStorage += '.zip'
|
||||
websocket_helper.broadcast_user(exec_user['user_id'], 'send_logs_bootbox', {
|
||||
})
|
||||
|
||||
self.users.set_support_path(exec_user['user_id'], tempZipStorage)
|
||||
|
||||
self.users.stop_prepare(exec_user['user_id'])
|
||||
self.support_scheduler.remove_job('logs_'+str(exec_user["user_id"]))
|
||||
|
||||
@staticmethod
|
||||
def add_system_user():
|
||||
helper_users.add_user("system", helper.random_string_generator(64), "default@example.com", False, False)
|
||||
@ -190,6 +208,22 @@ class Controller:
|
||||
else:
|
||||
svr.stop_crash_detection()
|
||||
|
||||
def log_status(self, source_path, dest_path, exec_user):
|
||||
results = helper.calc_percent(source_path, dest_path)
|
||||
self.log_stats = results
|
||||
|
||||
if len(websocket_helper.clients) > 0:
|
||||
websocket_helper.broadcast_user(exec_user['user_id'], 'support_status_update', results)
|
||||
|
||||
def send_log_status(self):
|
||||
try:
|
||||
return self.log_stats
|
||||
except:
|
||||
return {
|
||||
'percent': 0,
|
||||
'total_files': 0
|
||||
}
|
||||
|
||||
def get_server_obj(self, server_id: Union[str, int]) -> Union[bool, Server]:
|
||||
for s in self.servers_list:
|
||||
if str(s['server_id']) == str(server_id):
|
||||
@ -603,3 +637,7 @@ class Controller:
|
||||
@staticmethod
|
||||
def clear_unexecuted_commands():
|
||||
helpers_management.clear_unexecuted_commands()
|
||||
|
||||
@staticmethod
|
||||
def clear_support_status():
|
||||
helper_users.clear_support_status()
|
||||
|
@ -623,6 +623,7 @@ class Server:
|
||||
'backupStarted', users_helper.get_user_lang_by_id(user)).format(self.name))
|
||||
time.sleep(3)
|
||||
conf = management_helper.get_backup_config(self.server_id)
|
||||
helper.ensure_dir_exists(self.settings['backup_path'])
|
||||
try:
|
||||
backup_filename = f"{self.settings['backup_path']}/{datetime.datetime.now().strftime('%Y-%m-%d_%H-%M-%S')}"
|
||||
logger.info(f"Creating backup of server '{self.settings['server_name']}'" +
|
||||
|
@ -184,6 +184,7 @@ class PanelHandler(BaseHandler):
|
||||
# pylint: disable=unused-variable
|
||||
api_key, token_data, exec_user = self.current_user
|
||||
superuser = exec_user['superuser']
|
||||
preparing = exec_user['preparing']
|
||||
if api_key is not None:
|
||||
superuser = superuser and api_key.superuser
|
||||
|
||||
@ -254,6 +255,7 @@ class PanelHandler(BaseHandler):
|
||||
'lang': self.controller.users.get_user_lang_by_id(exec_user["user_id"]),
|
||||
'lang_page': helper.getLangPage(self.controller.users.get_user_lang_by_id(exec_user["user_id"])),
|
||||
'super_user': superuser,
|
||||
'preparing': preparing,
|
||||
'api_key': {
|
||||
'name': api_key.name,
|
||||
'created': api_key.created,
|
||||
|
@ -262,6 +262,17 @@
|
||||
})
|
||||
});
|
||||
}
|
||||
if (webSocket) {
|
||||
webSocket.on('support_status_update', function (logs) {
|
||||
if(logs.percent >= 100){
|
||||
document.getElementById('logs_progress_bar').innerHTML = '100%';
|
||||
document.getElementById('logs_progress_bar').style.width = '100%';
|
||||
}else{
|
||||
document.getElementById('logs_progress_bar').innerHTML = logs.percent +'%';
|
||||
document.getElementById('logs_progress_bar').style.width = logs.percent + '%';
|
||||
}
|
||||
});
|
||||
}
|
||||
if (webSocket) {
|
||||
webSocket.on('send_logs_bootbox', function (server_id) {
|
||||
var x = document.querySelector('.bootbox');
|
||||
|
@ -32,7 +32,14 @@
|
||||
{% end %}
|
||||
<p class="font-weight-light text-muted mb-0">Email: {{ data['user_data']['email'] }}</p>
|
||||
</div>
|
||||
{% if data['preparing'] %}
|
||||
<span class="dropdown-item" id="support_progress"><i class="dropdown-item-icon mdi mdi-download-outline text-primary"></i>{{ translate('notify', 'supportLogs', data['lang']) }}<br><br></span>
|
||||
<span class="dropdown-item" id="support_progress"><div class="support_progress" style="height: 15px; width: 100%;">
|
||||
<div class="progress-bar progress-bar-striped progress-bar-animated" id="logs_progress_bar" role="progressbar" style="width:0%;" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100">0%</div>
|
||||
</div></span>
|
||||
{% else %}
|
||||
<a class="dropdown-item" id="support_logs" ><i class="dropdown-item-icon mdi mdi-download-outline text-primary"></i>{{ translate('notify', 'supportLogs', data['lang']) }}</i></a>
|
||||
{% end %}
|
||||
{% if data['superuser'] %}
|
||||
<a class="dropdown-item" href="/panel/activity_logs"><i class="dropdown-item-icon mdi mdi-calendar-check-outline text-primary"></i>{{ translate('notify', 'activityLog', data['lang']) }}</a>
|
||||
{% end %}
|
||||
|
16
app/migrations/20220312_support_log_status.py
Normal file
16
app/migrations/20220312_support_log_status.py
Normal file
@ -0,0 +1,16 @@
|
||||
# Generated by database migrator
|
||||
import peewee
|
||||
|
||||
def migrate(migrator, database, **kwargs):
|
||||
migrator.add_columns('users', preparing=peewee.BooleanField(default=False))
|
||||
"""
|
||||
Write your migrations here.
|
||||
"""
|
||||
|
||||
|
||||
|
||||
def rollback(migrator, database, **kwargs):
|
||||
migrator.drop_columns('users', ['preparing'])
|
||||
"""
|
||||
Write your rollback migrations here.
|
||||
"""
|
Loading…
Reference in New Issue
Block a user