mirror of
https://gitlab.com/crafty-controller/crafty-4.git
synced 2024-08-30 18:23:09 +00:00
Moved server DB code to models, fix autobleach logging, fix redirect bug
This commit is contained in:
parent
33e1f07fa6
commit
1e2abff40a
@ -10,7 +10,7 @@ from distutils import dir_util
|
||||
from app.classes.shared.helpers import helper
|
||||
from app.classes.shared.console import console
|
||||
|
||||
from app.classes.shared.models import db_helper, Servers
|
||||
from app.classes.shared.models import db_helper
|
||||
|
||||
from app.classes.shared.server import Server
|
||||
from app.classes.minecraft.server_props import ServerProps
|
||||
@ -293,22 +293,9 @@ class Controller:
|
||||
server_log_file, server_stop, port)
|
||||
return new_id
|
||||
|
||||
def register_server(self, name: str, server_id: str, server_dir: str, backup_path: str, server_command: str, server_file: str, server_log_file: str, server_stop: str, server_port=25565):
|
||||
def register_server(self, name: str, server_uuid: str, server_dir: str, backup_path: str, server_command: str, server_file: str, server_log_file: str, server_stop: str, server_port=25565):
|
||||
# put data in the db
|
||||
new_id = Servers.insert({
|
||||
Servers.server_name: name,
|
||||
Servers.server_uuid: server_id,
|
||||
Servers.path: server_dir,
|
||||
Servers.executable: server_file,
|
||||
Servers.execution_command: server_command,
|
||||
Servers.auto_start: False,
|
||||
Servers.auto_start_delay: 10,
|
||||
Servers.crash_detection: False,
|
||||
Servers.log_path: server_log_file,
|
||||
Servers.server_port: server_port,
|
||||
Servers.stop_command: server_stop,
|
||||
Servers.backup_path: backup_path
|
||||
}).execute()
|
||||
new_id = db_helper.create_server(name, server_uuid, server_dir, backup_path, server_command, server_file, server_log_file, server_stop, server_port)
|
||||
|
||||
try:
|
||||
# place a file in the dir saying it's owned by crafty
|
||||
@ -345,9 +332,7 @@ class Controller:
|
||||
self.stop_server(server_id)
|
||||
|
||||
# remove the server from the DB
|
||||
with database.atomic():
|
||||
Role_Servers.delete().where(Role_Servers.server_id == server_id).execute()
|
||||
Servers.delete().where(Servers.server_id == server_id).execute()
|
||||
db_helper.remove_server(server_id)
|
||||
|
||||
# remove the server from servers list
|
||||
self.servers_list.pop(counter)
|
||||
|
@ -313,6 +313,29 @@ class db_shortcuts:
|
||||
|
||||
return rows
|
||||
|
||||
@staticmethod
|
||||
def create_server(name: str, server_uuid: str, server_dir: str, backup_path: str, server_command: str, server_file: str, server_log_file: str, server_stop: str, server_port=25565):
|
||||
return Servers.insert({
|
||||
Servers.server_name: name,
|
||||
Servers.server_uuid: server_uuid,
|
||||
Servers.path: server_dir,
|
||||
Servers.executable: server_file,
|
||||
Servers.execution_command: server_command,
|
||||
Servers.auto_start: False,
|
||||
Servers.auto_start_delay: 10,
|
||||
Servers.crash_detection: False,
|
||||
Servers.log_path: server_log_file,
|
||||
Servers.server_port: server_port,
|
||||
Servers.stop_command: server_stop,
|
||||
Servers.backup_path: backup_path
|
||||
}).execute()
|
||||
|
||||
@staticmethod
|
||||
def remove_server(server_id):
|
||||
with database.atomic():
|
||||
Role_Servers.delete().where(Role_Servers.server_id == server_id).execute()
|
||||
Servers.delete().where(Servers.server_id == server_id).execute()
|
||||
|
||||
@staticmethod
|
||||
def get_server_data_by_id(server_id):
|
||||
query = Servers.select().where(Servers.server_id == server_id).limit(1)
|
||||
|
@ -13,6 +13,7 @@ logger = logging.getLogger(__name__)
|
||||
class BaseHandler(tornado.web.RequestHandler):
|
||||
|
||||
nobleach = {bool, type(None)}
|
||||
redactables = ("pass", "api")
|
||||
|
||||
def initialize(self, controller=None, tasks_manager=None, translator=None):
|
||||
self.controller = controller
|
||||
@ -28,8 +29,14 @@ class BaseHandler(tornado.web.RequestHandler):
|
||||
def get_current_user(self):
|
||||
return self.get_secure_cookie("user", max_age_days=1)
|
||||
|
||||
def autobleach(self, text):
|
||||
def autobleach(self, name, text):
|
||||
for r in self.redactables:
|
||||
if r in name:
|
||||
logger.debug("Auto-bleaching {}: {}".format(name, "[**REDACTED* c,mmvkkkkkkkkkkkkkkkkkkkkkkkkn*]"))
|
||||
else:
|
||||
logger.debug("Auto-bleaching {}: {}".format(name, text))
|
||||
if type(text) in self.nobleach:
|
||||
logger.debug("Auto-bleaching - bypass type")
|
||||
return text
|
||||
else:
|
||||
return bleach.clean(text)
|
||||
@ -41,14 +48,12 @@ class BaseHandler(tornado.web.RequestHandler):
|
||||
strip: bool = True,
|
||||
) -> Optional[str]:
|
||||
arg = self._get_argument(name, default, self.request.arguments, strip)
|
||||
logger.debug("Bleaching {}: {}".format(name, arg))
|
||||
return self.autobleach(arg)
|
||||
return self.autobleach(name, arg)
|
||||
|
||||
def get_arguments(self, name: str, strip: bool = True) -> List[str]:
|
||||
assert isinstance(strip, bool)
|
||||
args = self._get_arguments(name, self.request.arguments, strip)
|
||||
args_ret = []
|
||||
for arg in args:
|
||||
logger.debug("Bleaching {}: {}".format(name, arg))
|
||||
args_ret += self.autobleach(arg)
|
||||
args_ret += self.autobleach(name, arg)
|
||||
return args_ret
|
||||
|
@ -117,6 +117,6 @@ class PublicHandler(BaseHandler):
|
||||
|
||||
next_page = "/panel/dashboard"
|
||||
self.redirect(next_page)
|
||||
|
||||
else:
|
||||
self.redirect("/public/login")
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user