diff --git a/config/admin/app.py b/config/admin/app.py index 0f1e96e4..2f90efbd 100644 --- a/config/admin/app.py +++ b/config/admin/app.py @@ -50,6 +50,12 @@ def add_file(): session['error'] = 'Filename is required.' return redirect(url_for('index')) + new_file = new_file.strip() + + if new_file == "": + session['error'] = 'Filename is required.' + return redirect(url_for('index')) + new_file = new_file.lstrip('/') if not new_file.endswith('.yaml'): @@ -79,6 +85,25 @@ def redirect_with_error(error_message): """ return redirect(url_for('index', error=error_message)) + +@app.route('/delete-file/', methods=['POST']) +def delete_file(filepath): + # Construct the full file path + full_path = os.path.join(YAML_DIR, filepath) + + # Check if the file exists and is within the allowed directory + if os.path.exists(full_path) and os.path.abspath(full_path).startswith(os.path.abspath(YAML_DIR)): + try: + os.remove(full_path) + session['error'] = f"File '{filepath}' has been deleted successfully." + except Exception as e: + session['error'] = f"Failed to delete file: {e}" + else: + session['error'] = f"File '{filepath}' not found or invalid path." + + return redirect(url_for('index')) + + if __name__ == '__main__': os.makedirs(YAML_DIR, exist_ok=True) app.run(debug=True, port=5000) diff --git a/config/admin/templates/index.html b/config/admin/templates/index.html index b28ea609..7a5d8d51 100644 --- a/config/admin/templates/index.html +++ b/config/admin/templates/index.html @@ -9,23 +9,29 @@

Salam Admin Panel

- {% if request.args.get('error') %} + + {% if error %} {% endif %} +
- +
+