From 7ab3cfb54ed2682df3eab861e98b350df1309692 Mon Sep 17 00:00:00 2001 From: Nathan Woodburn Date: Fri, 23 Feb 2024 14:58:21 +1100 Subject: [PATCH] fix: Use /var/www as content location --- main.py | 15 ++++++++++++--- sites.py | 6 +----- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/main.py b/main.py index 63ae53c..7cef77c 100644 --- a/main.py +++ b/main.py @@ -127,16 +127,25 @@ def upload_site(name): filename = file.filename - file.save('uploads/' + name + '/' + filename) + file.save('/var/www/{id}/{filename}'.format(id=site['id'], filename=filename)) return "File uploaded successfully." @app.route('/manage//download/') def download_site(name, file): - return send_from_directory('uploads/' + name, file, as_attachment=True) + site = sites_module.get_site(name) + if not site: + return "Error: Site not found." + + return send_from_directory('/var/www/{id}'.format(id=site['id']), file) + @app.route('/manage//delete/') def delete_site(name, file): - os.remove('uploads/' + name + '/' + file) + site = sites_module.get_site(name) + if not site: + return "Error: Site not found." + + os.remove('/var/www/{id}/{file}'.format(id=site['id'], file=file)) return redirect('/manage/' + name) diff --git a/sites.py b/sites.py index ab9003d..db37728 100644 --- a/sites.py +++ b/sites.py @@ -155,7 +155,7 @@ def write_nginx_conf(site): site = get_site(site) domain = site['domain'] id = site['id'] - location = f'/root/site-manager/uploads/{site["name"]}' + location = f'/var/www/{id}' conf = f''' server {{ @@ -228,10 +228,6 @@ def write_nginx_conf(site): with open(f'/etc/nginx/sites-enabled/{id}.conf', 'w') as file: file.write(conf) - # Give read permissions to nginx for the /root/site-manager/uploads directory - os.system(f'chown -R www-data:www-data {location}') - os.system(f'chmod -R 755 {location}') - # Restart nginx os.system('systemctl restart nginx') return True \ No newline at end of file