Merge branch 'pretzel-patches' into 'dev'

# Conflicts:
#   app/classes/shared/server.py
This commit is contained in:
Andrew 2021-11-23 22:12:06 +00:00
commit 97ddc1b964
11 changed files with 138 additions and 23 deletions

View File

@ -15,6 +15,7 @@ import zipfile
import pathlib
import shutil
from requests import get
from contextlib import suppress
from datetime import datetime
from socket import gethostname
@ -373,9 +374,10 @@ class Helpers:
logger.critical("Unable to write to {} directory!".format(self.root_dir))
sys.exit(1)
# ensure the log directory is there
# ensure the log directory is there
try:
os.makedirs(os.path.join(self.root_dir, 'logs'))
with suppress(FileExistsError):
os.makedirs(os.path.join(self.root_dir, 'logs'))
except Exception as e:
console.error("Failed to make logs directory with error: {} ".format(e))

View File

@ -223,7 +223,7 @@ class Controller:
# download the jar
server_jar_obj.download_jar(server, version, full_jar_path, name)
new_id = self.register_server(name, server_id, server_dir, backup_path, server_command, server_file, server_log_file, server_stop)
new_id = self.register_server(name, server_id, server_dir, backup_path, server_command, server_file, server_log_file, server_stop, port)
return new_id
@staticmethod
@ -253,6 +253,16 @@ class Controller:
server_path = helper.get_os_understandable_path(server_path)
dir_util.copy_tree(server_path, new_server_dir)
has_properties = False
for item in os.listdir(new_server_dir):
if str(item) == 'server.properties':
has_properties = True
if not has_properties:
logger.info("No server.properties found on zip file import. Creating one with port selection of {}".format(str(port)))
with open(os.path.join(new_server_dir, "server.properties"), "w") as f:
f.write("server-port={}".format(port))
f.close()
full_jar_path = os.path.join(new_server_dir, server_jar)
server_command = 'java -Xms{}M -Xmx{}M -jar {} nogui'.format(helper.float_to_string(min_mem),
helper.float_to_string(max_mem),
@ -317,7 +327,7 @@ class Controller:
server_log_file, server_stop, port)
return new_id
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):
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: int):
# put data in the db
new_id = self.servers.create_server(name, server_uuid, server_dir, backup_path, server_command, server_file, server_log_file, server_stop, server_port)

View File

@ -193,7 +193,36 @@ class Server:
logger.info("Launching Server {} with command {}".format(self.name, self.server_command))
console.info("Launching Server {} with command {}".format(self.name, self.server_command))
<<<<<<< app/classes/shared/server.py
if helper.check_file_exists(os.path.join(self.settings['path'], 'eula.txt')):
f = open(os.path.join(self.settings['path'], 'eula.txt'), 'r')
line = f.readline().lower()
if line == 'eula=true':
e_flag = True
elif line == 'eula = true':
e_flag = True
elif line == 'eula= true':
e_flag = True
elif line == 'eula =true':
e_flag = True
else:
e_flag = False
else:
e_flag = False
if e_flag == False:
websocket_helper.broadcast('send_eula_bootbox', {
'id': self.server_id
})
return False
f.close()
if helper.is_os_windows():
>>>>>>> app/classes/shared/server.py
logger.info("Windows Detected")
creationflags=subprocess.CREATE_NEW_CONSOLE
else:
@ -346,7 +375,7 @@ class Server:
if self.settings['crash_detection']:
logger.warning("The server {} has crashed and will be restarted. Restarting server".format(name))
console.warning("The server {} has crashed and will be restarted. Restarting server".format(name))
self.run_threaded_server()
self.run_threaded_server('en_EN')
return True
else:
logger.critical(
@ -420,6 +449,13 @@ class Server:
console.info("Removing old crash detection watcher thread")
schedule.clear(self.name)
def agree_eula(self, user_lang):
file = os.path.join(self.server_path, 'eula.txt')
f = open(file, 'w')
f.write('eula=true')
f.close
self.run_threaded_server(user_lang)
def is_backup_running(self):
if self.is_backingup:
return True

View File

@ -207,6 +207,10 @@ class AjaxHandler(BaseHandler):
except Exception as e:
logger.error("Could not find PID for requested termsig. Full error: {}".format(e))
return
elif page == "eula":
server_id = self.get_argument('id', None)
svr = self.controller.get_server_obj(server_id)
svr.agree_eula(self.controller.users.get_user_lang_by_id(user_data['user_id']))
@tornado.web.authenticated
def delete(self, page):

View File

@ -40,6 +40,7 @@ class PublicHandler(BaseHandler):
def get(self, page=None):
error = bleach.clean(self.get_argument('error', "Invalid Login!"))
error_msg = bleach.clean(self.get_argument('error_msg', ''))
page_data = {
'version': helper.get_version_string(),
@ -75,6 +76,7 @@ class PublicHandler(BaseHandler):
template,
data=page_data,
translate=self.translator.translate,
error_msg = error_msg
)
def post(self, page=None):
@ -89,18 +91,18 @@ class PublicHandler(BaseHandler):
# if we don't have a user
if not user_data:
next_page = "/public/error?error=Login Failed"
error_msg = "Inncorrect username or password. Please try again."
self.clear_cookie("user")
self.clear_cookie("user_data")
self.redirect(next_page)
self.redirect('/public/login?error_msg={}'.format(error_msg))
return
# if they are disabled
if not user_data.enabled:
next_page = "/public/error?error=Login Failed"
error_msg = "User account disabled. Please contact your system administrator for more info."
self.clear_cookie("user")
self.clear_cookie("user_data")
self.redirect(next_page)
self.redirect('/public/login?error_msg={}'.format(error_msg))
return
login_result = helper.verify_pass(entered_password, user_data.password)
@ -132,9 +134,10 @@ class PublicHandler(BaseHandler):
else:
self.clear_cookie("user")
self.clear_cookie("user_data")
error_msg = "Inncorrect username or password. Please try again."
# log this failed login attempt
self.controller.management.add_to_audit_log(user_data.user_id, "Tried to log in", 0, self.get_remote_ip())
self.redirect('/public/error?error=Login Failed')
self.redirect('/public/login?error_msg={}'.format(error_msg))
else:
self.redirect("/public/login")

View File

@ -237,6 +237,57 @@ if (webSocket) {
});
}
if (webSocket) {
webSocket.on('send_eula_bootbox', function (server_id) {
var x = document.querySelector('.bootbox');
if(x){
x.remove()}
var x = document.querySelector('.modal-backdrop');
if(x){
x.remove()}
bootbox.confirm({
title: '{% raw translate("error", "eulaTitle", data['lang']) %}',
message: '{% raw translate("error", "eulaMsg", data['lang']) %} <br><br><a href="https://account.mojang.com/documents/minecraft_eula" target="_blank">EULA</a><br><br>{% raw translate("error", "eulaAgree", data['lang']) %}',
buttons: {
confirm: {
label: 'Yes',
className: 'btn-info'
},
cancel: {
label: 'No',
className: 'btn-secondary'
}
},
callback: function (result) {
if(result == true){
eulaAgree(server_id.id)
}
else {
location.reload()
}
}
})
});
}
function eulaAgree (server_id, command){
<!-- this getCookie function is in base.html-->
var token = getCookie("_xsrf");
$.ajax({
type: "POST",
headers: {'X-XSRFToken': token},
url: '/ajax/eula?id='+ server_id,
success: function(data){
console.log("got response:");
console.log(data);
location.reload();
}
});
}
function warn(message) {
var closeEl = document.createElement('span');

View File

@ -94,7 +94,7 @@
<br>
<h7>{{ translate('dashboard', 'no-servers', data['lang']) }} {{ translate('dashboard', 'newServer', data['lang']) }}.</h7>
</div>
{% end %}
{% if len(data['servers']) > 0 %}
<table class="table table-hover">
@ -180,7 +180,7 @@
{{ server['stats']['online'] }} / {{ server['stats']['max'] }} {{ translate('dashboard', 'max', data['lang']) }}<br />
{% if server['stats']['desc'] != 'False' %}
<span id="input_motd_{{ server['stats']['server_id']['server_id'] }}" class="input_motd">{{ server['stats']['desc'] }}</span> <br />
{{ server['stats']['desc'] }} <br />
{% end %}
{% if server['stats']['version'] != 'False' %}
@ -221,18 +221,13 @@
{% end %}
{% block js %}
<script src="/static/assets/js/motd.js"></script>
<script>
$(document).ready(function(){
$(document).ready(function(){
$('[data-toggle="popover"]').popover();
if($(window).width() < 1000){
$('.too_small').popover("show");
}
var all_motds = Array.from(document.getElementsByClassName('input_motd'));
for (element of all_motds) {
initParser(element.id, element.id);
};
});
$(window).ready(function(){
$('body').click(function(){
@ -345,7 +340,7 @@ $( document ).ready(function() {
title: '{% raw translate("dashboard", "killing", data['lang']) %}',
message: '<p><i class="fa fa-spin fa-spinner"></i> Loading...</p>'
});
dialog.init(function(){
setTimeout(function(){
location.reload();

View File

@ -71,6 +71,11 @@
<div class="form-group">
<button class="login-input btn btn-primary submit-btn btn-block">{{ translate('login', 'login', data['lang']) }}</button>
</div>
{% if error_msg is not None %}
<fieldset style="color: red; text-align: center;">
<span>{{error_msg}}</span>
</fieldset>
{% end %}
<div class="form-group d-flex justify-content-between">
<div class="form-check form-check-flat mt-0">
&nbsp;

View File

@ -13,7 +13,10 @@
"error": "Error!",
"start-error": "Server {} failed to start with error code: {}",
"closedPort": "We have detected port {} may not be open on the host network or a firewall is blocking it. Remote client connections to the server may be limited.",
"internet": "We have detected the machine running Crafty has no connection to the internet. Client connections to the server may be limited."
"internet": "We have detected the machine running Crafty has no connection to the internet. Client connections to the server may be limited.",
"eulaTitle": "Agree To EULA",
"eulaMsg": "You must agree to the EULA. A copy of the Mojang EULA is linked under this message.",
"eulaAgree": "Do you agree?"
},
"404": {
"contact": "Contact Crafty Control Support via Discord",

View File

@ -13,7 +13,10 @@
"error": "Virhe!",
"start-error": "Palvelin {} ei käynnistynyt virhekoodilla: {}",
"closedPort": "Olemme havainneet, että portti {} ei ehkä ole auki isäntäverkossa tai palomuuri estää sen. Etäasiakkaan yhteydet palvelimeen voivat olla rajallisia.",
"internet": "Olemme havainneet, että Crafty -koneella ei ole Internet -yhteyttä. Asiakasyhteydet palvelimelle voivat olla rajalliset."
"internet": "Olemme havainneet, että Crafty -koneella ei ole Internet -yhteyttä. Asiakasyhteydet palvelimelle voivat olla rajalliset.",
"eulaTitle": "Hyväksy EULA",
"eulaMsg": "Sinun on hyväksyttävä EULA. Kopio Mojang EULA:sta on linkitetty tämän viestin alla.",
"eulaAgree": "Oletko samaa mieltä?"
},
"404": {
"contact": "Ota yhteyttä Crafty Control -tukeen Discordin kautta",

View File

@ -13,7 +13,10 @@
"error": "Erreur !",
"start-error": "Le serveur {} n'a pas pu démarrer avec le code d'erreur : {}",
"closedPort": "Nous avons détecté que le port {} n'est peut-être pas ouvert sur le réseau hôte ou qu'un pare-feu le bloque. Les connexions des clients distants au serveur peuvent être limitées.",
"internet": "Nous avons détecté que la machine exécutant Crafty n'a pas de connexion à Internet. Les connexions client au serveur peuvent être limitées."
"internet": "Nous avons détecté que la machine exécutant Crafty n'a pas de connexion à Internet. Les connexions client au serveur peuvent être limitées.",
"eulaTitle": "Accepter le EULA",
"eulaMsg": "Vous devez accepter le EULA. Une copie du CLUF de Mojang est liée sous ce message.",
"eulaAgree": "Êtes-vous d'accord?"
},
"404": {
"contact": "Contacter le Support de Crafty Control via Discord",