mirror of
https://gitlab.com/crafty-controller/crafty-4.git
synced 2024-08-30 18:23:09 +00:00
add working zip import selection functionality
This commit is contained in:
parent
deeff1717b
commit
4d636cce1b
@ -753,7 +753,7 @@ class Helpers:
|
|||||||
</span>
|
</span>
|
||||||
</input></div><li>
|
</input></div><li>
|
||||||
\n"""\
|
\n"""\
|
||||||
.format(os.path.join(folder, filename), os.path.join(folder, filename), os.path.join(folder, filename), os.path.join(folder, filename), filename, os.path.join(folder, filename), os.path.join(folder, filename), filename, filename)
|
.format(os.path.join(folder, filename), os.path.join(folder, filename), os.path.join(folder, filename), filename, os.path.join(folder, filename), os.path.join(folder, filename), os.path.join(folder, filename), filename, filename)
|
||||||
return output
|
return output
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@ -777,19 +777,20 @@ class Helpers:
|
|||||||
{}
|
{}
|
||||||
</span>
|
</span>
|
||||||
</input></div><li>"""\
|
</input></div><li>"""\
|
||||||
.format(os.path.join(folder, filename), os.path.join(folder, filename), os.path.join(folder, filename), os.path.join(folder, filename), filename, os.path.join(folder, filename), os.path.join(folder, filename), filename, filename)
|
.format(os.path.join(folder, filename), os.path.join(folder, filename), os.path.join(folder, filename), filename, os.path.join(folder, filename), os.path.join(folder, filename), os.path.join(folder, filename), filename, filename)
|
||||||
return output
|
return output
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def unzipServer(zip_path, user_id):
|
def unzipServer(zip_path, user_id):
|
||||||
tempDir = tempfile.mkdtemp()
|
if helper.check_file_perms(zip_path):
|
||||||
with zipfile.ZipFile(zip_path, 'r') as zip_ref:
|
tempDir = tempfile.mkdtemp()
|
||||||
#extracts archive to temp directory
|
with zipfile.ZipFile(zip_path, 'r') as zip_ref:
|
||||||
zip_ref.extractall(tempDir)
|
#extracts archive to temp directory
|
||||||
if user_id:
|
zip_ref.extractall(tempDir)
|
||||||
websocket_helper.broadcast_user(user_id, 'send_temp_path',{
|
if user_id:
|
||||||
'path': tempDir
|
websocket_helper.broadcast_user(user_id, 'send_temp_path',{
|
||||||
})
|
'path': tempDir
|
||||||
|
})
|
||||||
return
|
return
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
@ -296,26 +296,22 @@ class Controller:
|
|||||||
new_server_dir = os.path.join(helper.servers_dir, server_id)
|
new_server_dir = os.path.join(helper.servers_dir, server_id)
|
||||||
backup_path = os.path.join(helper.backup_path, server_id)
|
backup_path = os.path.join(helper.backup_path, server_id)
|
||||||
tempDir = helper.get_os_understandable_path(zip_path)
|
tempDir = helper.get_os_understandable_path(zip_path)
|
||||||
|
helper.ensure_dir_exists(new_server_dir)
|
||||||
if helper.check_file_perms(zip_path):
|
helper.ensure_dir_exists(backup_path)
|
||||||
helper.ensure_dir_exists(new_server_dir)
|
has_properties = False
|
||||||
helper.ensure_dir_exists(backup_path)
|
#extracts archive to temp directory
|
||||||
has_properties = False
|
for item in os.listdir(tempDir):
|
||||||
#extracts archive to temp directory
|
if str(item) == 'server.properties':
|
||||||
for item in os.listdir(tempDir):
|
has_properties = True
|
||||||
if str(item) == 'server.properties':
|
try:
|
||||||
has_properties = True
|
shutil.move(os.path.join(tempDir, item), os.path.join(new_server_dir, item))
|
||||||
try:
|
except Exception as ex:
|
||||||
shutil.move(os.path.join(tempDir, item), os.path.join(new_server_dir, item))
|
logger.error('ERROR IN ZIP IMPORT: {}'.format(ex))
|
||||||
except Exception as ex:
|
if not has_properties:
|
||||||
logger.error('ERROR IN ZIP IMPORT: {}'.format(ex))
|
logger.info("No server.properties found on zip file import. Creating one with port selection of {}".format(str(port)))
|
||||||
if not has_properties:
|
with open(os.path.join(new_server_dir, "server.properties"), "w") as f:
|
||||||
logger.info("No server.properties found on zip file import. Creating one with port selection of {}".format(str(port)))
|
f.write("server-port={}".format(port))
|
||||||
with open(os.path.join(new_server_dir, "server.properties"), "w") as f:
|
f.close()
|
||||||
f.write("server-port={}".format(port))
|
|
||||||
f.close()
|
|
||||||
else:
|
|
||||||
return "false"
|
|
||||||
|
|
||||||
full_jar_path = os.path.join(new_server_dir, server_jar)
|
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),
|
server_command = 'java -Xms{}M -Xmx{}M -jar {} nogui'.format(helper.float_to_string(min_mem),
|
||||||
|
@ -192,13 +192,12 @@ class ServerHandler(BaseHandler):
|
|||||||
elif import_type == 'import_zip':
|
elif import_type == 'import_zip':
|
||||||
# here import_server_path means the zip path
|
# here import_server_path means the zip path
|
||||||
zip_path = bleach.clean(self.get_argument('root_path'))
|
zip_path = bleach.clean(self.get_argument('root_path'))
|
||||||
print(zip_path)
|
|
||||||
good_path = helper.check_path_exists(zip_path)
|
good_path = helper.check_path_exists(zip_path)
|
||||||
if not good_path:
|
if not good_path:
|
||||||
self.redirect("/panel/error?error=Temp path not found!")
|
self.redirect("/panel/error?error=Temp path not found!")
|
||||||
return
|
return
|
||||||
|
|
||||||
new_server_id = self.controller.import_zip_server(server_name, import_server_path, import_server_jar, min_mem, max_mem, port)
|
new_server_id = self.controller.import_zip_server(server_name, zip_path, import_server_jar, min_mem, max_mem, port)
|
||||||
if new_server_id == "false":
|
if new_server_id == "false":
|
||||||
self.redirect("/panel/error?error=Zip file not accessible! You can fix this permissions issue with sudo chown -R crafty:crafty {} And sudo chmod 2775 -R {}".format(import_server_path, import_server_path))
|
self.redirect("/panel/error?error=Zip file not accessible! You can fix this permissions issue with sudo chown -R crafty:crafty {} And sudo chmod 2775 -R {}".format(import_server_path, import_server_path))
|
||||||
return
|
return
|
||||||
|
@ -576,7 +576,7 @@ function hide(event) {
|
|||||||
}
|
}
|
||||||
if (webSocket) {
|
if (webSocket) {
|
||||||
webSocket.on('send_temp_path', function (data) {
|
webSocket.on('send_temp_path', function (data) {
|
||||||
document.getElementById('main-tree-input').setAttribute('data-path', data.path)
|
document.getElementById('main-tree-input').setAttribute('value', data.path)
|
||||||
getTreeView(data.path);
|
getTreeView(data.path);
|
||||||
show_file_tree();
|
show_file_tree();
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user