Merge branch 'pretzel-fixes' into 'dev'

Pretzel fixes

See merge request crafty-controller/crafty-commander!159
This commit is contained in:
Andrew 2022-01-30 20:36:36 +00:00
commit 9164a89eed
4 changed files with 29 additions and 8 deletions

View File

@ -191,6 +191,14 @@ class helpers_management:
Audit_Log.log_msg: audit_msg,
Audit_Log.source_ip: source_ip
}).execute()
#todo make this user configurable
#deletes records when they're more than 100
ordered = Audit_Log.select().order_by(+Audit_Log.created)
for item in ordered:
if Audit_Log.select().count() > 300:
Audit_Log.delete().where(Audit_Log.audit_id == item.audit_id).execute()
else:
return
@staticmethod
def add_to_audit_log_raw(user_name, user_id, server_id, log_msg, source_ip):
@ -201,7 +209,13 @@ class helpers_management:
Audit_Log.log_msg: log_msg,
Audit_Log.source_ip: source_ip
}).execute()
#deletes records when they're more than 100
ordered = Audit_Log.select().order_by(+Audit_Log.created)
for item in ordered:
if Audit_Log.select().count() > 300:
Audit_Log.delete().where(Audit_Log.audit_id == item.audit_id).execute()
else:
return
#************************************************************************************************
# Schedules Methods
#************************************************************************************************
@ -291,10 +305,10 @@ class helpers_management:
@staticmethod
def set_backup_config(server_id: int, backup_path: str = None, max_backups: int = None):
logger.debug(f"Updating server {server_id} backup config with {locals()}")
try:
if Backups.select().where(Backups.server_id == server_id).count() != 0:
new_row = False
conf = {}
except IndexError:
else:
conf = {
"directories": None,
"max_backups": 0,

View File

@ -322,9 +322,10 @@ class Server:
def stop_server(self):
if self.settings['stop_command']:
self.send_command(self.settings['stop_command'])
#remove crash detection watcher
logger.info(f"Removing crash watcher for server {self.name}")
self.server_scheduler.remove_job('c_' + str(self.server_id))
if self.settings['crash_detection']:
#remove crash detection watcher
logger.info(f"Removing crash watcher for server {self.name}")
self.server_scheduler.remove_job('c_' + str(self.server_id))
else:
#windows will need to be handled separately for Ctrl+C
self.process.terminate()
@ -408,7 +409,7 @@ class Server:
print("crash detected")
# clear the old scheduled watcher task
self.server_scheduler.remove_job("c_"+str(self.server_id))
self.server_scheduler.remove_job(f"c_{self.server_id}")
# the server crashed, or isn't found - so let's reset things.
logger.warning(f"The server {name} seems to have vanished unexpectedly, did it crash?")

View File

@ -17,6 +17,7 @@ from app.classes.models.management import management_helper
from app.classes.controllers.users_controller import Users_Controller
from app.classes.controllers.servers_controller import Servers_Controller
from app.classes.models.servers import servers_helper
from app.classes.models.users import users_helper
logger = logging.getLogger('apscheduler')
@ -373,6 +374,8 @@ class TasksManager:
if not event.exception:
if str(event.job_id).isnumeric():
task = management_helper.get_scheduled_task_model(int(event.job_id))
management_helper.add_to_audit_log_raw('system', users_helper.get_user_id_by_name('system'), task.server_id,
f"Task with id {task.schedule_id} completed successfully", '127.0.0.1')
if task.one_time:
self.remove_job(task.schedule_id)
logger.info("one time task detected. Deleting...")

View File

@ -17,7 +17,6 @@ from tornado.ioloop import IOLoop
#TZLocal is set as a hidden import on win pipeline
from tzlocal import get_localzone
from cron_validator import CronValidator
from app.classes.controllers.servers_controller import Servers_Controller
from app.classes.models.server_permissions import Enum_Permissions_Server
from app.classes.models.crafty_permissions import Enum_Permissions_Crafty
@ -452,6 +451,10 @@ class PanelHandler(BaseHandler):
return
server = self.controller.get_server_obj(server_id)
management_helper.add_to_audit_log_raw(
self.controller.users.get_user_by_id(exec_user['user_id'])['username'], exec_user['user_id'], server_id,
f"Backup now executed for server {server_id} ",
source_ip=self.get_remote_ip())
server.backup_server()
self.redirect(f"/panel/server_detail?id={server_id}&subpage=backup")