mirror of
https://gitlab.com/crafty-controller/crafty-4.git
synced 2024-08-30 18:23:09 +00:00
Fix error with scheduled tasks by system
Create a system user
This commit is contained in:
parent
e53da60b4f
commit
58d1ffea54
@ -70,7 +70,7 @@ class helper_users:
|
||||
|
||||
@staticmethod
|
||||
def get_all_users():
|
||||
query = Users.select()
|
||||
query = Users.select().where(Users.username != "system")
|
||||
return query
|
||||
|
||||
@staticmethod
|
||||
@ -79,8 +79,6 @@ class helper_users:
|
||||
|
||||
@staticmethod
|
||||
def get_user_id_by_name(username):
|
||||
if username == "SYSTEM":
|
||||
return 0
|
||||
try:
|
||||
return (Users.get(Users.username == username)).user_id
|
||||
except DoesNotExist:
|
||||
@ -108,14 +106,14 @@ class helper_users:
|
||||
if user_id == 0:
|
||||
return {
|
||||
'user_id': 0,
|
||||
'created': None,
|
||||
'last_login': None,
|
||||
'last_update': None,
|
||||
'created': '10/24/2019, 11:34:00',
|
||||
'last_login': '10/24/2019, 11:34:00',
|
||||
'last_update': '10/24/2019, 11:34:00',
|
||||
'last_ip': "127.27.23.89",
|
||||
'username': "SYSTEM",
|
||||
'password': None,
|
||||
'enabled': True,
|
||||
'superuser': False,
|
||||
'superuser': True,
|
||||
'api_token': None,
|
||||
'roles': [],
|
||||
'servers': [],
|
||||
@ -130,6 +128,13 @@ class helper_users:
|
||||
#logger.debug("user: ({}) {}".format(user_id, {}))
|
||||
return {}
|
||||
|
||||
def check_system_user(user_id):
|
||||
try:
|
||||
Users.get(Users.user_id == user_id).user_id == user_id
|
||||
return True
|
||||
except:
|
||||
return False
|
||||
|
||||
@staticmethod
|
||||
def add_user(username, password=None, api_token=None, enabled=True, superuser=False):
|
||||
if password is not None:
|
||||
|
@ -3,6 +3,7 @@ import pathlib
|
||||
import time
|
||||
import logging
|
||||
import sys
|
||||
from app.classes.models.users import helper_users
|
||||
from peewee import DoesNotExist
|
||||
import schedule
|
||||
import yaml
|
||||
@ -120,6 +121,17 @@ class Controller:
|
||||
server_obj = self.get_server_obj(server_id)
|
||||
server_obj.reload_server_settings()
|
||||
|
||||
@staticmethod
|
||||
def check_system_user():
|
||||
if helper_users.get_user_id_by_name("system") is not None:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
@staticmethod
|
||||
def add_system_user():
|
||||
helper_users.add_user("system", helper.random_string_generator(64), helper_users.new_api_token(), False, True)
|
||||
|
||||
def get_server_settings(self, server_id):
|
||||
for s in self.servers_list:
|
||||
if int(s['server_id']) == int(server_id):
|
||||
|
@ -74,8 +74,11 @@ class db_shortcuts:
|
||||
try:
|
||||
if query.count() > 0:
|
||||
for s in query:
|
||||
if s.user_id == 0:
|
||||
print(s.user_id)
|
||||
rows.append(model_to_dict(s))
|
||||
except Exception as e:
|
||||
print('QUERY: ', query)
|
||||
logger.warning("Database Error: {}".format(e))
|
||||
pass
|
||||
|
||||
|
4
main.py
4
main.py
@ -6,6 +6,7 @@ import time
|
||||
import argparse
|
||||
import logging.config
|
||||
import signal
|
||||
from app.classes.controllers.management_controller import Management_Controller
|
||||
|
||||
""" Our custom classes / pip packages """
|
||||
from app.classes.shared.console import console
|
||||
@ -146,6 +147,9 @@ if __name__ == '__main__':
|
||||
console.warning("We have detected Crafty's port, {} may not be open on the host network or a firewall is blocking it. Remote client connections to Crafty may be limited.".format(helper.get_setting('https_port')))
|
||||
console.help("If you are not forwarding ports from your public IP or your router does not support hairpin NAT you can safely disregard the previous message.")
|
||||
|
||||
if not controller.check_system_user():
|
||||
controller.add_system_user()
|
||||
|
||||
Crafty = MainPrompt(tasks_manager, migration_manager)
|
||||
|
||||
def sigterm_handler(signum, current_stack_frame):
|
||||
|
Loading…
Reference in New Issue
Block a user