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
@ -106,6 +106,14 @@ class Users_Controller:
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
def user_id_exists(user_id):
|
def user_id_exists(user_id):
|
||||||
return users_helper.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
|
@staticmethod
|
||||||
def get_user_id_by_api_token(token: str) -> str:
|
def get_user_id_by_api_token(token: str) -> str:
|
||||||
|
@ -37,6 +37,7 @@ class Users(Model):
|
|||||||
support_logs = CharField(default = '')
|
support_logs = CharField(default = '')
|
||||||
valid_tokens_from = DateTimeField(default=datetime.datetime.now)
|
valid_tokens_from = DateTimeField(default=datetime.datetime.now)
|
||||||
server_order = CharField(default="")
|
server_order = CharField(default="")
|
||||||
|
preparing = BooleanField(default=False)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
table_name = "users"
|
table_name = "users"
|
||||||
@ -196,6 +197,18 @@ class helper_users:
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
def set_support_path(user_id, support_path):
|
def set_support_path(user_id, support_path):
|
||||||
Users.update(support_logs = support_path).where(Users.user_id == user_id).execute()
|
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
|
@staticmethod
|
||||||
def user_id_exists(user_id):
|
def user_id_exists(user_id):
|
||||||
|
@ -6,6 +6,7 @@ import time
|
|||||||
import logging
|
import logging
|
||||||
import tempfile
|
import tempfile
|
||||||
from typing import Union
|
from typing import Union
|
||||||
|
from urllib import request
|
||||||
|
|
||||||
from app.classes.controllers.crafty_perms_controller import Crafty_Perms_Controller
|
from app.classes.controllers.crafty_perms_controller import Crafty_Perms_Controller
|
||||||
from app.classes.controllers.management_controller import Management_Controller
|
from app.classes.controllers.management_controller import Management_Controller
|
||||||
@ -28,6 +29,9 @@ from app.classes.web.websocket_helper import websocket_helper
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
from peewee import DoesNotExist
|
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:
|
except ModuleNotFoundError as err:
|
||||||
helper.auto_installer_fix(err)
|
helper.auto_installer_fix(err)
|
||||||
@ -45,6 +49,9 @@ class Controller:
|
|||||||
self.server_perms = Server_Perms_Controller()
|
self.server_perms = Server_Perms_Controller()
|
||||||
self.servers = Servers_Controller()
|
self.servers = Servers_Controller()
|
||||||
self.users = Users_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):
|
def check_server_loaded(self, server_id_to_check: int):
|
||||||
|
|
||||||
@ -128,6 +135,9 @@ class Controller:
|
|||||||
|
|
||||||
|
|
||||||
def package_support_logs(self, exec_user):
|
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
|
#pausing so on screen notifications can run for user
|
||||||
time.sleep(7)
|
time.sleep(7)
|
||||||
websocket_helper.broadcast_user(exec_user['user_id'], 'notification', 'Preparing your support logs')
|
websocket_helper.broadcast_user(exec_user['user_id'], 'notification', 'Preparing your support logs')
|
||||||
@ -161,13 +171,21 @@ class Controller:
|
|||||||
#Copy crafty logs to archive dir
|
#Copy crafty logs to archive dir
|
||||||
full_log_name = os.path.join(crafty_path, 'logs')
|
full_log_name = os.path.join(crafty_path, 'logs')
|
||||||
file_helper.copy_dir(os.path.join(self.project_root, 'logs'), full_log_name)
|
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)
|
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'
|
tempZipStorage += '.zip'
|
||||||
websocket_helper.broadcast_user(exec_user['user_id'], 'send_logs_bootbox', {
|
websocket_helper.broadcast_user(exec_user['user_id'], 'send_logs_bootbox', {
|
||||||
})
|
})
|
||||||
|
|
||||||
self.users.set_support_path(exec_user['user_id'], tempZipStorage)
|
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
|
@staticmethod
|
||||||
def add_system_user():
|
def add_system_user():
|
||||||
@ -189,6 +207,22 @@ class Controller:
|
|||||||
svr.start_crash_detection()
|
svr.start_crash_detection()
|
||||||
else:
|
else:
|
||||||
svr.stop_crash_detection()
|
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]:
|
def get_server_obj(self, server_id: Union[str, int]) -> Union[bool, Server]:
|
||||||
for s in self.servers_list:
|
for s in self.servers_list:
|
||||||
@ -603,3 +637,7 @@ class Controller:
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
def clear_unexecuted_commands():
|
def clear_unexecuted_commands():
|
||||||
helpers_management.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))
|
'backupStarted', users_helper.get_user_lang_by_id(user)).format(self.name))
|
||||||
time.sleep(3)
|
time.sleep(3)
|
||||||
conf = management_helper.get_backup_config(self.server_id)
|
conf = management_helper.get_backup_config(self.server_id)
|
||||||
|
helper.ensure_dir_exists(self.settings['backup_path'])
|
||||||
try:
|
try:
|
||||||
backup_filename = f"{self.settings['backup_path']}/{datetime.datetime.now().strftime('%Y-%m-%d_%H-%M-%S')}"
|
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']}'" +
|
logger.info(f"Creating backup of server '{self.settings['server_name']}'" +
|
||||||
|
@ -184,6 +184,7 @@ class PanelHandler(BaseHandler):
|
|||||||
# pylint: disable=unused-variable
|
# pylint: disable=unused-variable
|
||||||
api_key, token_data, exec_user = self.current_user
|
api_key, token_data, exec_user = self.current_user
|
||||||
superuser = exec_user['superuser']
|
superuser = exec_user['superuser']
|
||||||
|
preparing = exec_user['preparing']
|
||||||
if api_key is not None:
|
if api_key is not None:
|
||||||
superuser = superuser and api_key.superuser
|
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': 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"])),
|
'lang_page': helper.getLangPage(self.controller.users.get_user_lang_by_id(exec_user["user_id"])),
|
||||||
'super_user': superuser,
|
'super_user': superuser,
|
||||||
|
'preparing': preparing,
|
||||||
'api_key': {
|
'api_key': {
|
||||||
'name': api_key.name,
|
'name': api_key.name,
|
||||||
'created': api_key.created,
|
'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) {
|
if (webSocket) {
|
||||||
webSocket.on('send_logs_bootbox', function (server_id) {
|
webSocket.on('send_logs_bootbox', function (server_id) {
|
||||||
var x = document.querySelector('.bootbox');
|
var x = document.querySelector('.bootbox');
|
||||||
|
@ -32,7 +32,14 @@
|
|||||||
{% end %}
|
{% end %}
|
||||||
<p class="font-weight-light text-muted mb-0">Email: {{ data['user_data']['email'] }}</p>
|
<p class="font-weight-light text-muted mb-0">Email: {{ data['user_data']['email'] }}</p>
|
||||||
</div>
|
</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>
|
<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'] %}
|
{% 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>
|
<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 %}
|
{% 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.
|
||||||
|
"""
|
1
main.py
1
main.py
@ -148,6 +148,7 @@ if __name__ == '__main__':
|
|||||||
project_root = os.path.dirname(__file__)
|
project_root = os.path.dirname(__file__)
|
||||||
controller.set_project_root(project_root)
|
controller.set_project_root(project_root)
|
||||||
controller.clear_unexecuted_commands()
|
controller.clear_unexecuted_commands()
|
||||||
|
controller.clear_support_status()
|
||||||
|
|
||||||
def sigterm_handler(*sig):
|
def sigterm_handler(*sig):
|
||||||
print() # for newline
|
print() # for newline
|
||||||
|
Loading…
Reference in New Issue
Block a user