mirror of
https://gitlab.com/crafty-controller/crafty-4.git
synced 2024-08-30 18:23:09 +00:00
Completed file uploading. Need to fix listing when right clicking. Unzip is shown at all times. Added unzip function to helpers and is called through ajax for unzipping files to current directory.
This commit is contained in:
@ -286,7 +286,10 @@ class Controller:
|
|||||||
tempDir = tempfile.mkdtemp()
|
tempDir = tempfile.mkdtemp()
|
||||||
with zipfile.ZipFile(zip_path, 'r') as zip_ref:
|
with zipfile.ZipFile(zip_path, 'r') as zip_ref:
|
||||||
zip_ref.extractall(tempDir)
|
zip_ref.extractall(tempDir)
|
||||||
test = zip_ref.filelist[1].filename
|
for i in range(len(zip_ref.filelist)):
|
||||||
|
if len(zip_ref.filelist) > 1 or not zip_ref.filelist[i].filename.endswith('/'):
|
||||||
|
test = zip_ref.filelist[i].filename
|
||||||
|
break
|
||||||
path_list = test.split('/')
|
path_list = test.split('/')
|
||||||
root_path = path_list[0]
|
root_path = path_list[0]
|
||||||
if len(path_list) > 1:
|
if len(path_list) > 1:
|
||||||
|
@ -268,15 +268,16 @@ class Helpers:
|
|||||||
else:
|
else:
|
||||||
new_dir += '/'+new_dir_list[i]
|
new_dir += '/'+new_dir_list[i]
|
||||||
|
|
||||||
if helper.check_file_perms(zip_path):
|
if helper.check_file_perms(zip_path) and os.path.isfile(zip_path):
|
||||||
helper.ensure_dir_exists(new_dir)
|
helper.ensure_dir_exists(new_dir)
|
||||||
tempDir = tempfile.mkdtemp()
|
tempDir = tempfile.mkdtemp()
|
||||||
with zipfile.ZipFile(zip_path, 'r') as zip_ref:
|
try:
|
||||||
zip_ref.extractall(tempDir)
|
with zipfile.ZipFile(zip_path, 'r') as zip_ref:
|
||||||
for item in os.listdir(tempDir):
|
zip_ref.extractall(tempDir)
|
||||||
print(item)
|
for i in range(len(zip_ref.filelist)):
|
||||||
test = zip_ref.filelist[1].filename
|
if len(zip_ref.filelist) > 1 or not zip_ref.filelist[i].filename.endswith('/'):
|
||||||
print(test)
|
test = zip_ref.filelist[i].filename
|
||||||
|
break
|
||||||
path_list = test.split('/')
|
path_list = test.split('/')
|
||||||
root_path = path_list[0]
|
root_path = path_list[0]
|
||||||
if len(path_list) > 1:
|
if len(path_list) > 1:
|
||||||
@ -290,8 +291,11 @@ class Helpers:
|
|||||||
shutil.move(os.path.join(full_root_path, item), os.path.join(new_dir, item))
|
shutil.move(os.path.join(full_root_path, item), os.path.join(new_dir, item))
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
logger.error('ERROR IN ZIP IMPORT: {}'.format(ex))
|
logger.error('ERROR IN ZIP IMPORT: {}'.format(ex))
|
||||||
|
except Exception as ex:
|
||||||
|
print(ex)
|
||||||
else:
|
else:
|
||||||
return "false"
|
return "false"
|
||||||
|
return
|
||||||
|
|
||||||
def ensure_logging_setup(self):
|
def ensure_logging_setup(self):
|
||||||
log_file = os.path.join(os.path.curdir, 'logs', 'commander.log')
|
log_file = os.path.join(os.path.curdir, 'logs', 'commander.log')
|
||||||
|
@ -189,32 +189,34 @@ class AjaxHandler(BaseHandler):
|
|||||||
# Create the directory
|
# Create the directory
|
||||||
os.mkdir(dir_path)
|
os.mkdir(dir_path)
|
||||||
|
|
||||||
|
elif page == "unzip_file":
|
||||||
|
server_id = self.get_argument('id', None)
|
||||||
|
path = self.get_argument('path', None)
|
||||||
|
helper.unzipFile(path)
|
||||||
|
self.render_page("/panel/server_detail?id={}&subpage=files".format(server_id))
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
elif page == "upload_files":
|
elif page == "upload_files":
|
||||||
server_id = self.get_argument('id', None)
|
server_id = self.get_argument('id', None)
|
||||||
path = self.get_argument('path', None)
|
path = self.get_argument('path', None)
|
||||||
unzip = self.get_argument('unzip', None)
|
|
||||||
|
|
||||||
if helper.in_path(db_helper.get_server_data_by_id(server_id)['path'], path):
|
if helper.in_path(db_helper.get_server_data_by_id(server_id)['path'], path):
|
||||||
try:
|
try:
|
||||||
files = self.request.files['files']
|
files = self.request.files['files']
|
||||||
for file in files:
|
for file in files:
|
||||||
if file['filename'].split('.') is not None:
|
if file['filename'].split('.') is not None:
|
||||||
self._upload_file(file['body'], path, file['filename'], unzip)
|
self._upload_file(file['body'], path, file['filename'])
|
||||||
else:
|
else:
|
||||||
logger.error("Directory Detected. Skipping")
|
logger.error("Directory Detected. Skipping")
|
||||||
self.redirect("/panel/server_detail?id={}&subpage=files".format(server_id))
|
self.redirect("/panel/server_detail?id={}&subpage=files".format(server_id))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
|
||||||
self.redirect("/panel/server_detail?id={}&subpage=files".format(server_id))
|
self.redirect("/panel/server_detail?id={}&subpage=files".format(server_id))
|
||||||
else:
|
else:
|
||||||
logger.error("Invalid directory requested. Canceling upload")
|
logger.error("Invalid directory requested. Canceling upload")
|
||||||
|
return
|
||||||
|
|
||||||
elif page == 'unzip_file':
|
def _upload_file(self, file_data, file_path, file_name):
|
||||||
print("in unzip file")
|
|
||||||
path = self.get_argument('path', None)
|
|
||||||
helper.unzipFile(path)
|
|
||||||
|
|
||||||
def _upload_file(self, file_data, file_path, file_name, unzip):
|
|
||||||
error = ""
|
error = ""
|
||||||
|
|
||||||
file_full_path = os.path.join(file_path, file_name)
|
file_full_path = os.path.join(file_path, file_name)
|
||||||
@ -231,17 +233,6 @@ class AjaxHandler(BaseHandler):
|
|||||||
output_file = open(file_full_path, 'wb')
|
output_file = open(file_full_path, 'wb')
|
||||||
output_file.write(file_data)
|
output_file.write(file_data)
|
||||||
logger.info('Saving File: {}'.format(file_full_path))
|
logger.info('Saving File: {}'.format(file_full_path))
|
||||||
uploading = True
|
|
||||||
while uploading:
|
|
||||||
try:
|
|
||||||
new_output = open(file_full_path, 'wb')
|
|
||||||
new_output.close()
|
|
||||||
uploading = False
|
|
||||||
except:
|
|
||||||
print("file is still uploading")
|
|
||||||
if unzip == "True":
|
|
||||||
helper.unzipFile(file_full_path)
|
|
||||||
print("DONE")
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@tornado.web.authenticated
|
@tornado.web.authenticated
|
||||||
|
@ -531,27 +531,59 @@
|
|||||||
path: path
|
path: path
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
location.href="/
|
||||||
|
}
|
||||||
|
function uploadFilesE(event){
|
||||||
|
path = event.target.parentElement.getAttribute('data-path');
|
||||||
|
console.log("PATH: " + path);
|
||||||
|
$(function () {
|
||||||
|
server_id = {{ data['server_stats']['server_id']['server_id'] }};
|
||||||
|
var uploadHtml = "<div>" +
|
||||||
|
'<form id="upload_file" enctype="multipart/form-data" action="/ajax/upload_files?id=' + server_id +'&path='+ path +'"method="post">{% raw xsrf_form_html() %}'+"<label class='upload-area' style='width:100%;text-align:center;' for='files'>" +
|
||||||
|
"<input id='files' name='files' type='file' style='display:none;' multiple='true'>" +
|
||||||
|
"<i class='fa fa-cloud-upload fa-3x'></i>" +
|
||||||
|
"<br />" +
|
||||||
|
"Click Here To Upload" +
|
||||||
|
"</label></form>" +
|
||||||
|
"<br />" +
|
||||||
|
"<ul style='margin-left:5px !important;' id='fileList'></ul>" +
|
||||||
|
"</div><div class='clearfix'></div>";
|
||||||
|
|
||||||
|
bootbox.dialog({
|
||||||
|
message: uploadHtml,
|
||||||
|
title: "File Upload",
|
||||||
|
buttons: {
|
||||||
|
success: {
|
||||||
|
label: "Upload",
|
||||||
|
className: "btn-default",
|
||||||
|
callback: function () {
|
||||||
|
$('#upload_file').submit(); //.trigger('submit');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
var fileList = document.getElementById("files");
|
||||||
|
fileList.addEventListener("change", function (e) {
|
||||||
|
var list = "";
|
||||||
|
for (var i = 0; i < this.files.length; i++) {
|
||||||
|
list += "<li class='col-xs-12 file-list'>" + this.files[i].name + "</li>"
|
||||||
|
}
|
||||||
|
|
||||||
|
document.getElementById("fileList").innerHTML = list;
|
||||||
|
}, false);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function uploadFilesE(e){
|
|
||||||
|
function uploadFiles(e){
|
||||||
path = event.target.parentElement.getAttribute('data-path');
|
path = event.target.parentElement.getAttribute('data-path');
|
||||||
server_id = {{ data['server_stats']['server_id']['server_id'] }};
|
server_id = {{ data['server_stats']['server_id']['server_id'] }};
|
||||||
var uploadHtml = '<form enctype="multipart/form-data" action="/ajax/upload_files?id=' + server_id +'&path='+ path +'"method="post">{% raw xsrf_form_html() %}<div class="form-group"><label for="files">Upload A File Here</label><input id="files" type="file" name="files" class="form-control-file" multiple></div><input id="unzip" type = checkbox value="1" checked> Would you like us Unzip directories? </input><br><br><input id="upload_file" type="submit"value="Upload File" class="btn btn-success hidden"/></form>';
|
var uploadHtml = '<form enctype="multipart/form-data" action="/ajax/upload_files?id=' + server_id +'&path='+ path +'"method="post">{% raw xsrf_form_html() %}<div class="form-group">'+"<label class='upload-area' style='width:100%;text-align:center;' for='fupload'>" +'<input id="files" type="file" name="files" multiple>' +"<i class='fa fa-cloud-upload fa-3x'></i>" +"<br />" +"Upload Files Here" +"</label>" +"<br />" +"<span style='margin-left:5px !important;' id='fileList'></span>"+'</div><br><br><input id="upload_file" type="submit"value="Upload File" class="btn btn-success hidden"/></form>';
|
||||||
|
|
||||||
bootbox.dialog({
|
bootbox.dialog({
|
||||||
message: uploadHtml,
|
message: uploadHtml,
|
||||||
title: "Upload Files To "+path,
|
title: "Upload Files To "+path,
|
||||||
});
|
});
|
||||||
|
|
||||||
var fileList = document.getElementById("upload");
|
|
||||||
fileList.addEventListener("change", function (e) {
|
|
||||||
var list = "";
|
|
||||||
for (var i = 0; i < this.files.length; i++) {
|
|
||||||
list += "<div class='col-xs-12 file-list'>"+this.files[i].name+"</div>";
|
|
||||||
}
|
|
||||||
|
|
||||||
$("#fileList").text(list);
|
|
||||||
}, false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function getTreeView() {
|
function getTreeView() {
|
||||||
|
Reference in New Issue
Block a user