diff --git a/app/classes/shared/controller.py b/app/classes/shared/controller.py
index 805abe5d..54c858eb 100644
--- a/app/classes/shared/controller.py
+++ b/app/classes/shared/controller.py
@@ -49,7 +49,7 @@ class Controller:
continue
# if this server path no longer exists - let's warn and bomb out
- if not helper.check_path_exits(s['path']):
+ if not helper.check_path_exists(s['path']):
logger.warning("Unable to find server {} at path {}. Skipping this server".format(s['server_name'],
s['path']))
diff --git a/app/classes/shared/helpers.py b/app/classes/shared/helpers.py
index 46e2e4e4..3cba2eea 100644
--- a/app/classes/shared/helpers.py
+++ b/app/classes/shared/helpers.py
@@ -272,7 +272,7 @@ class Helpers:
return "%.1f%s%s" % (num, 'Y', suffix)
@staticmethod
- def check_path_exits(path: str):
+ def check_path_exists(path: str):
logger.debug('Looking for path: {}'.format(path))
if os.path.exists(path):
@@ -463,13 +463,21 @@ class Helpers:
print(filename)
rel = os.path.join(folder, raw_filename)
if os.path.isdir(rel):
- output += '
""".format(os.path.join(folder, filename), filename, filename)
return output
@staticmethod
diff --git a/app/classes/shared/server.py b/app/classes/shared/server.py
index a52cb73a..54d3b618 100644
--- a/app/classes/shared/server.py
+++ b/app/classes/shared/server.py
@@ -96,7 +96,7 @@ class Server:
console.critical("Server executable path: {} does not seem to exist".format(full_path))
helper.do_exit()
- if not helper.check_path_exits(self.server_path):
+ if not helper.check_path_exists(self.server_path):
logger.critical("Server path: {} does not seem to exits".format(self.server_path))
console.critical("Server path: {} does not seem to exits".format(self.server_path))
helper.do_exit()
diff --git a/app/classes/web/ajax_handler.py b/app/classes/web/ajax_handler.py
index f7f75190..13331e71 100644
--- a/app/classes/web/ajax_handler.py
+++ b/app/classes/web/ajax_handler.py
@@ -4,6 +4,7 @@ import tornado.web
import tornado.escape
import bleach
import os
+import shutil
from app.classes.shared.console import console
from app.classes.shared.models import Users, installer
@@ -101,12 +102,6 @@ class AjaxHandler(BaseHandler):
or not helper.check_file_exists(os.path.abspath(file_path)):
logger.warning("Invalid path in get_file ajax call")
console.warning("Invalid path in get_file ajax call")
- if not helper.in_path(db_helper.get_server_data_by_id(server_id)['path'], file_path):
- console.warning('1')
- elif not helper.check_file_exists(os.path.abspath(file_path)):
- console.warning('2')
- else:
- console.warning('3')
return False
file = open(file_path)
@@ -117,6 +112,26 @@ class AjaxHandler(BaseHandler):
self.write(file_contents)
self.finish()
+ elif page == "get_tree":
+ server_id = self.get_argument('id', None)
+
+ if server_id is None:
+ logger.warning("Server ID not found in get_file ajax call")
+ console.warning("Server ID not found in get_file ajax call")
+ return False
+ else:
+ server_id = bleach.clean(server_id)
+
+ # does this server id exist?
+ if not db_helper.server_id_exists(server_id):
+ logger.warning("Server ID not found in get_file ajax call")
+ console.warning("Server ID not found in get_file ajax call")
+ return False
+
+ self.write(db_helper.get_server_data_by_id(server_id)['path'] + '\n' +
+ helper.generate_tree(db_helper.get_server_data_by_id(server_id)['path']))
+ self.finish()
+
def post(self, page):
user_data = json.loads(self.get_secure_cookie("user_data"))
error = bleach.clean(self.get_argument('error', "WTF Error!"))
@@ -127,8 +142,8 @@ class AjaxHandler(BaseHandler):
}
if page == "send_command":
- command = bleach.clean(self.get_body_argument('command', default=None, strip=True))
- server_id = bleach.clean(self.get_argument('id'))
+ command = self.get_body_argument('command', default=None, strip=True)
+ server_id = self.get_argument('id')
if server_id is None:
logger.warning("Server ID not found in send_command ajax call")
@@ -140,9 +155,125 @@ class AjaxHandler(BaseHandler):
if srv_obj.check_running():
srv_obj.send_command(command)
- elif page == "save_file":
- file_contents = bleach.clean(self.get_body_argument('file_contents', default=None, strip=True))
- file_path = bleach.clean(self.get_body_argument('file_path', default=None, strip=True))
+ elif page == "create_file":
+ file_parent = self.get_body_argument('file_parent', default=None, strip=True)
+ file_name = self.get_body_argument('file_name', default=None, strip=True)
+ file_path = os.path.join(file_parent, file_name)
+ server_id = self.get_argument('id', None)
+ print(server_id)
+
+ if server_id is None:
+ logger.warning("Server ID not found in create_file ajax call")
+ console.warning("Server ID not found in create_file ajax call")
+ return False
+ else:
+ server_id = bleach.clean(server_id)
+
+ # does this server id exist?
+ if not db_helper.server_id_exists(server_id):
+ logger.warning("Server ID not found in create_file ajax call")
+ console.warning("Server ID not found in create_file ajax call")
+ return False
+
+ if not helper.in_path(db_helper.get_server_data_by_id(server_id)['path'], file_path) \
+ or helper.check_file_exists(os.path.abspath(file_path)):
+ logger.warning("Invalid path in create_file ajax call")
+ console.warning("Invalid path in create_file ajax call")
+ return False
+
+ # Create the file by opening it
+ with open(file_path, 'w') as file_object:
+ file_object.close()
+
+ elif page == "create_dir":
+ dir_parent = self.get_body_argument('dir_parent', default=None, strip=True)
+ dir_name = self.get_body_argument('dir_name', default=None, strip=True)
+ dir_path = os.path.join(dir_parent, dir_name)
+ server_id = self.get_argument('id', None)
+ print(server_id)
+
+ if server_id is None:
+ logger.warning("Server ID not found in create_dir ajax call")
+ console.warning("Server ID not found in create_dir ajax call")
+ return False
+ else:
+ server_id = bleach.clean(server_id)
+
+ # does this server id exist?
+ if not db_helper.server_id_exists(server_id):
+ logger.warning("Server ID not found in create_dir ajax call")
+ console.warning("Server ID not found in create_dir ajax call")
+ return False
+
+ if not helper.in_path(db_helper.get_server_data_by_id(server_id)['path'], dir_path) \
+ or helper.check_path_exists(os.path.abspath(dir_path)):
+ logger.warning("Invalid path in create_dir ajax call")
+ console.warning("Invalid path in create_dir ajax call")
+ return False
+
+ # Create the directory
+ os.mkdir(dir_path)
+
+ def delete(self, page):
+ if page == "del_file":
+ file_path = self.get_body_argument('file_path', default=None, strip=True)
+ server_id = self.get_argument('id', None)
+ print(server_id)
+
+ if server_id is None:
+ logger.warning("Server ID not found in del_file ajax call")
+ console.warning("Server ID not found in del_file ajax call")
+ return False
+ else:
+ server_id = bleach.clean(server_id)
+
+ # does this server id exist?
+ if not db_helper.server_id_exists(server_id):
+ logger.warning("Server ID not found in del_file ajax call")
+ console.warning("Server ID not found in del_file ajax call")
+ return False
+
+ if not helper.in_path(db_helper.get_server_data_by_id(server_id)['path'], file_path) \
+ or not helper.check_file_exists(os.path.abspath(file_path)):
+ logger.warning("Invalid path in del_file ajax call")
+ console.warning("Invalid path in del_file ajax call")
+ return False
+
+ # Delete the file
+ os.remove(file_path)
+
+ elif page == "del_dir":
+ dir_path = self.get_body_argument('dir_path', default=None, strip=True)
+ server_id = self.get_argument('id', None)
+ print(server_id)
+
+ if server_id is None:
+ logger.warning("Server ID not found in del_file ajax call")
+ console.warning("Server ID not found in del_file ajax call")
+ return False
+ else:
+ server_id = bleach.clean(server_id)
+
+ # does this server id exist?
+ if not db_helper.server_id_exists(server_id):
+ logger.warning("Server ID not found in del_file ajax call")
+ console.warning("Server ID not found in del_file ajax call")
+ return False
+
+ if not helper.in_path(db_helper.get_server_data_by_id(server_id)['path'], dir_path) \
+ or not helper.check_path_exists(os.path.abspath(dir_path)):
+ logger.warning("Invalid path in del_file ajax call")
+ console.warning("Invalid path in del_file ajax call")
+ return False
+
+ # Delete the file
+ # os.rmdir(dir_path)
+ shutil.rmtree(dir_path) # Removes also when there are contents
+
+ def put(self, page):
+ if page == "save_file":
+ file_contents = self.get_body_argument('file_contents', default=None, strip=True)
+ file_path = self.get_body_argument('file_path', default=None, strip=True)
server_id = self.get_argument('id', None)
print(file_contents)
print(file_path)
@@ -169,4 +300,45 @@ class AjaxHandler(BaseHandler):
# Open the file in write mode and store the content in file_object
with open(file_path, 'w') as file_object:
- file_object.write(file_contents)
\ No newline at end of file
+ file_object.write(file_contents)
+
+ elif page == "rename_item":
+ item_path = self.get_body_argument('item_path', default=None, strip=True)
+ new_item_name = self.get_body_argument('new_item_name', default=None, strip=True)
+ server_id = self.get_argument('id', None)
+ print(server_id)
+
+ if server_id is None:
+ logger.warning("Server ID not found in rename_item ajax call")
+ console.warning("Server ID not found in rename_item ajax call")
+ return False
+ else:
+ server_id = bleach.clean(server_id)
+
+ # does this server id exist?
+ if not db_helper.server_id_exists(server_id):
+ logger.warning("Server ID not found in rename_item ajax call (1)")
+ console.warning("Server ID not found in rename_item ajax call (1)")
+ return False
+
+ if item_path is None or new_item_name is None:
+ logger.warning("Invalid path in rename_item ajax call (2)")
+ console.warning("Invalid path in rename_item ajax call (2)")
+ return False
+
+ if not helper.in_path(db_helper.get_server_data_by_id(server_id)['path'], item_path) \
+ or not helper.check_path_exists(os.path.abspath(item_path)):
+ logger.warning("Invalid path in rename_item ajax call (3)")
+ console.warning("Invalid path in rename_item ajax call (3)")
+ return False
+
+ new_item_path = os.path.join(os.path.split(item_path)[0], new_item_name)
+
+ if not helper.in_path(db_helper.get_server_data_by_id(server_id)['path'], new_item_path) \
+ or helper.check_path_exists(os.path.abspath(new_item_path)):
+ logger.warning("Invalid path 2 in rename_item ajax call")
+ console.warning("Invalid path 2 in rename_item ajax call")
+ return False
+
+ # RENAME
+ os.rename(item_path, new_item_path)
diff --git a/app/classes/web/panel_handler.py b/app/classes/web/panel_handler.py
index d284facc..8ebd1b19 100644
--- a/app/classes/web/panel_handler.py
+++ b/app/classes/web/panel_handler.py
@@ -109,9 +109,6 @@ class PanelHandler(BaseHandler):
console.debug('not a valid subpage')
subpage = 'term'
console.debug('Subpage: "{}"'.format(subpage))
- if subpage == 'files':
- console.debug('Subpage is "files"')
- page_data['tree_html'] = helper.generate_tree(db_helper.get_server_data_by_id(server_id)['path'])
# server_data isn't needed since the server_stats also pulls server data
# page_data['server_data'] = db_helper.get_server_data_by_id(server_id)
diff --git a/app/frontend/templates/panel/server_files.html b/app/frontend/templates/panel/server_files.html
index e3267cb6..d08e11ac 100644
--- a/app/frontend/templates/panel/server_files.html
+++ b/app/frontend/templates/panel/server_files.html
@@ -65,9 +65,82 @@
+