Merge branch 'dev' into tweak/user-edit

This commit is contained in:
amcmanu3 2023-10-08 16:40:30 -04:00
commit 700194df9f
11 changed files with 98 additions and 79 deletions

1
.gitignore vendored
View File

@ -18,6 +18,7 @@ env.bak/
venv.bak/
.idea/
/import/
/imports/
/servers/
/app/frontend/static/assets/images/auth/custom/

View File

@ -15,6 +15,8 @@
- Fix Backup Restore/Schedules, Backup button function on `remote-comms2` ([Merge Request](https://gitlab.com/crafty-controller/crafty-4/-/merge_requests/634))
- Add a wait to the call for the directory so we can make sure the wait dialogue has time to show up first ([Merge Request](https://gitlab.com/crafty-controller/crafty-4/-/merge_requests/637))
- Fix bug where a reaction loop could be created, but would be cut short by an error when the loop occurred ([Merge Request](https://gitlab.com/crafty-controller/crafty-4/-/merge_requests/636))
- Use controller on update user call ([Merge Request](https://gitlab.com/crafty-controller/crafty-4/-/merge_requests/640))
- Move `imports` to `import/upload` in bind mount to better serve users on unraid with limited vdisk storage ([Merge Request](https://gitlab.com/crafty-controller/crafty-4/-/merge_requests/642))
### Refactor
- Consolidate remaining frontend functions into API V2, and remove ajax internal API ([Merge Request](https://gitlab.com/crafty-controller/crafty-4/-/merge_requests/585))
- Replace bleach with nh3 ([Merge Request](https://gitlab.com/crafty-controller/crafty-4/-/merge_requests/628))
@ -28,6 +30,8 @@
- Improve ui visibility of Build Wizard selection tabs ([Merge Request](https://gitlab.com/crafty-controller/crafty-4/-/merge_requests/633))
- Add additional logging for server bootstrap & moves unnecessary logging to `debug` for improved log clarity ([Merge Request](https://gitlab.com/crafty-controller/crafty-4/-/merge_requests/635))
- Bump orjson to 3.9.7 for python 3.12 support ([Merge Request](https://gitlab.com/crafty-controller/crafty-4/-/merge_requests/638))
- Bump all Crafty required python dependancies, maintaining minimum 3.9 support ([Merge Request](https://gitlab.com/crafty-controller/crafty-4/-/merge_requests/639))
- Better optimize and refactor docker launcher sh ([Merge Request](https://gitlab.com/crafty-controller/crafty-4/-/merge_requests/642))
### Lang
TBD
<br><br>

View File

@ -8,11 +8,11 @@ import time
import json
import logging
import threading
from zoneinfo import ZoneInfoNotFoundError
from peewee import DoesNotExist
# TZLocal is set as a hidden import on win pipeline
from tzlocal import get_localzone
from tzlocal.utils import ZoneInfoNotFoundError
from apscheduler.schedulers.background import BackgroundScheduler
from app.classes.models.server_permissions import EnumPermissionsServer

View File

@ -16,8 +16,8 @@ import json
from zoneinfo import ZoneInfo
# TZLocal is set as a hidden import on win pipeline
from zoneinfo import ZoneInfoNotFoundError
from tzlocal import get_localzone
from tzlocal.utils import ZoneInfoNotFoundError
from apscheduler.schedulers.background import BackgroundScheduler
from apscheduler.jobstores.base import JobLookupError, ConflictingIdError
@ -42,6 +42,45 @@ with redirect_stderr(NullWriter()):
logger = logging.getLogger(__name__)
def callback(called_func):
# Usage of @callback on method
# definition to run a webhook check
# on method completion
def wrapper(*args, **kwargs):
res = None
logger.debug("Checking for callbacks")
try:
res = called_func(*args, **kwargs)
finally:
events = WebhookFactory.get_monitored_events()
if called_func.__name__ in events:
server_webhooks = HelpersWebhooks.get_webhooks_by_server(
args[0].server_id, True
)
for swebhook in server_webhooks:
if called_func.__name__ in str(swebhook.trigger).split(","):
logger.info(
f"Found callback for event {called_func.__name__}"
f" for server {args[0].server_id}"
)
webhook = HelpersWebhooks.get_webhook_by_id(swebhook.id)
webhook_provider = WebhookFactory.create_provider(
webhook["webhook_type"]
)
if res is not False and swebhook.enabled:
webhook_provider.send(
bot_name=webhook["bot_name"],
server_name=args[0].name,
title=webhook["name"],
url=webhook["url"],
message=webhook["body"],
color=webhook["color"],
)
return res
return wrapper
class ServerOutBuf:
lines = {}
@ -166,45 +205,6 @@ class ServerInstance:
self.stats_helper.server_crash_reset()
self.stats_helper.set_update(False)
@staticmethod
def callback(called_func):
# Usage of @callback on method
# definition to run a webhook check
# on method completion
def wrapper(*args, **kwargs):
res = None
logger.debug("Checking for callbacks")
try:
res = called_func(*args, **kwargs)
finally:
events = WebhookFactory.get_monitored_events()
if called_func.__name__ in events:
server_webhooks = HelpersWebhooks.get_webhooks_by_server(
args[0].server_id, True
)
for swebhook in server_webhooks:
if called_func.__name__ in str(swebhook.trigger).split(","):
logger.info(
f"Found callback for event {called_func.__name__}"
f" for server {args[0].server_id}"
)
webhook = HelpersWebhooks.get_webhook_by_id(swebhook.id)
webhook_provider = WebhookFactory.create_provider(
webhook["webhook_type"]
)
if res is not False and swebhook.enabled:
webhook_provider.send(
bot_name=webhook["bot_name"],
server_name=args[0].name,
title=webhook["name"],
url=webhook["url"],
message=webhook["body"],
color=webhook["color"],
)
return res
return wrapper
# **********************************************************************************
# Minecraft Server Management
# **********************************************************************************

View File

@ -5,9 +5,8 @@ import threading
import asyncio
import datetime
import json
from zoneinfo import ZoneInfoNotFoundError
from tzlocal import get_localzone
from tzlocal.utils import ZoneInfoNotFoundError
from apscheduler.events import EVENT_JOB_EXECUTED
from apscheduler.schedulers.background import BackgroundScheduler
from apscheduler.triggers.cron import CronTrigger
@ -758,11 +757,13 @@ class TasksManager:
)
# Search for old files in imports
self.helper.ensure_dir_exists(
os.path.join(self.controller.project_root, "imports")
os.path.join(self.controller.project_root, "import", "upload")
)
for file in os.listdir(os.path.join(self.controller.project_root, "imports")):
for file in os.listdir(
os.path.join(self.controller.project_root, "import", "upload")
):
if self.helper.is_file_older_than_x_days(
os.path.join(self.controller.project_root, "imports", file)
os.path.join(self.controller.project_root, "import", "upload", file)
):
try:
os.remove(os.path.join(file))

View File

@ -7,6 +7,7 @@ import json
import logging
import threading
import urllib.parse
from zoneinfo import ZoneInfoNotFoundError
import nh3
import requests
import tornado.web
@ -15,7 +16,6 @@ from tornado import iostream
# TZLocal is set as a hidden import on win pipeline
from tzlocal import get_localzone
from tzlocal.utils import ZoneInfoNotFoundError
from app.classes.models.servers import Servers
from app.classes.models.server_permissions import EnumPermissionsServer

View File

@ -64,7 +64,9 @@ class ApiImportFilesIndexHandler(BaseApiHandler):
# JSON we need to remove this and just send
# the path.
if data["upload"]:
folder = os.path.join(self.controller.project_root, "imports", folder)
folder = os.path.join(
self.controller.project_root, "import", "upload", folder
)
if Helpers.check_file_exists(folder):
folder = self.file_helper.unzip_server(folder, user_id)
root_path = True

View File

@ -280,7 +280,7 @@ class ApiUsersUserIndexHandler(BaseApiHandler):
if key == "password":
value = self.helper.encode_pass(value)
setattr(user_obj, key, value)
user_obj.save()
self.controller.users.update_user(auth_data[4]["user_id"], data)
self.controller.management.add_to_audit_log(
user["user_id"],

View File

@ -102,7 +102,8 @@ class UploadHandler(BaseHandler):
)
self.do_upload = False
path = os.path.join(self.controller.project_root, "imports")
path = os.path.join(self.controller.project_root, "import", "upload")
self.helper.ensure_dir_exists(path)
# Delete existing files
if len(os.listdir(path)) > 0:
for item in os.listdir():

View File

@ -1,19 +1,30 @@
#!/bin/sh
repair_permissions () {
printf "\033[36mWrapper | \033[35m📋 (1/3) Ensuring root group ownership...\033[0m\n"
find . ! -group root -print0 | xargs -0 -r chgrp root
printf "\033[36mWrapper | \033[35m📋 (2/3) Ensuring group read-write is present on files...\033[0m\n"
find . ! -perm g+rw -print0 | xargs -0 -r chmod g+rw
printf "\033[36mWrapper | \033[35m📋 (3/3) Ensuring sticky bit is present on directories...\033[0m\n"
find . -type d ! -perm g+s -print0 | xargs -0 -r chmod g+s
}
# Check if config exists taking one from image if needed.
if [ ! "$(ls -A --ignore=.gitkeep ./app/config)" ]; then
echo "\033[36mWrapper | \033[33m🏗 Config not found, pulling defaults..."
printf "\033[36mWrapper | \033[33m🏗 Config not found, pulling defaults...\033[0m\n"
mkdir ./app/config/ 2> /dev/null
cp -r ./app/config_original/* ./app/config/
if [ $(id -u) -eq 0 ]; then
# We're running as root;
# Look for files & dirs that require group permissions to be fixed
# This will do the full /crafty dir, so will take a miniute.
echo "\033[36mWrapper | \033[35m📋 Looking for problem bind mount permissions globally..."
find . ! -group root -exec chgrp root {} \;
find . ! -perm g+rw -exec chmod g+rw {} \;
find . -type d ! -perm g+s -exec chmod g+s {} \;
printf "\033[36mWrapper | \033[35m📋 Looking for problem bind mount permissions globally...\033[0m\n"
repair_permissions
printf "\033[36mWrapper | \033[32m✅ Initialization complete!\033[0m\n"
fi
else
# Keep version file up to date with image
@ -26,24 +37,24 @@ if [ $(id -u) -eq 0 ]; then
# If we find files in import directory, we need to ensure all dirs are owned by the root group,
# This fixes bind mounts that may have incorrect perms.
if [ "$(ls -A --ignore=.gitkeep ./import)" ]; then
echo "\033[36mWrapper | \033[35m📋 Files present in import directory, checking/fixing permissions..."
echo "\033[36mWrapper | \033[33m⏳ Please be paitent for larger servers..."
find . ! -group root -exec chgrp root {} \;
find . ! -perm g+rw -exec chmod g+rw {} \;
find . -type d ! -perm g+s -exec chmod g+s {} \;
echo "\033[36mWrapper | \033[32m✅ Permissions Fixed! (This will happen every boot until /import is empty!)"
if [ "$(find ./import -type f ! -name '.gitkeep')" ]; then
printf "\033[36mWrapper | \033[35m📋 Files present in import directory, checking/fixing permissions...\033[0m\n"
printf "\033[36mWrapper | \033[33m⏳ Please be patient for larger servers...\033[0m\n"
repair_permissions
printf "\033[36mWrapper | \033[32m✅ Permissions Fixed! (This will happen every boot until /import is empty!)\033[0m\n"
fi
# Switch user, activate our prepared venv and lauch crafty
# Switch user, activate our prepared venv and launch crafty
args="$@"
echo "\033[36mWrapper | \033[32m🚀 Launching crafty with [\033[34m$args\033[32m]"
printf "\033[36mWrapper | \033[32m🚀 Launching crafty with [\033[34m%s\033[32m]\033[0m\n" "$args"
exec sudo -u crafty bash -c "source ./.venv/bin/activate && exec python3 main.py $args"
else
# Activate our prepared venv
echo "\033[36mWrapper | \033[32m🚀 Non-root host detected, using normal exec"
printf "\033[36mWrapper | \033[32m🚀 Non-root host detected, using normal exec\033[0m\n"
. ./.venv/bin/activate
# Use exec as our perms are already correct
# This is likely if using Kubernetes/OpenShift etc
exec python3 main.py $@
exec python3 main.py "$@"
fi

View File

@ -1,22 +1,21 @@
apscheduler==3.8.1
argon2-cffi==21.3
apscheduler==3.10.4
argon2-cffi==23.1.0
cached_property==1.5.2
colorama==0.4
croniter==1.3.5
cryptography==41.0.3
libgravatar==1.0.0
colorama==0.4.6
croniter==1.4.1
cryptography==41.0.4
libgravatar==1.0.4
nh3==0.2.14
packaging==23.1
peewee==3.13
pexpect==4.8
packaging==23.2
peewee==3.16.3
psutil==5.9.5
pyOpenSSL==23.2.0
pyjwt==2.4.0
pyjwt==2.8.0
PyYAML==6.0.1
requests==2.31
requests==2.31.0
termcolor==1.1
tornado==6.3.3
tzlocal==4.0
jsonschema==4.5.1
tzlocal==5.1
jsonschema==4.19.1
orjson==3.9.7