fix: Use /var/www as content location

This commit is contained in:
Nathan Woodburn 2024-02-23 14:58:21 +11:00
parent 5b9a114085
commit 7ab3cfb54e
Signed by: nathanwoodburn
GPG Key ID: 203B000478AD0EF1
2 changed files with 13 additions and 8 deletions

15
main.py
View File

@ -127,16 +127,25 @@ def upload_site(name):
filename = file.filename filename = file.filename
file.save('uploads/' + name + '/' + filename) file.save('/var/www/{id}/{filename}'.format(id=site['id'], filename=filename))
return "File uploaded successfully." return "File uploaded successfully."
@app.route('/manage/<name>/download/<file>') @app.route('/manage/<name>/download/<file>')
def download_site(name, file): 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/<name>/delete/<file>') @app.route('/manage/<name>/delete/<file>')
def delete_site(name, file): 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) return redirect('/manage/' + name)

View File

@ -155,7 +155,7 @@ def write_nginx_conf(site):
site = get_site(site) site = get_site(site)
domain = site['domain'] domain = site['domain']
id = site['id'] id = site['id']
location = f'/root/site-manager/uploads/{site["name"]}' location = f'/var/www/{id}'
conf = f''' conf = f'''
server {{ server {{
@ -228,10 +228,6 @@ def write_nginx_conf(site):
with open(f'/etc/nginx/sites-enabled/{id}.conf', 'w') as file: with open(f'/etc/nginx/sites-enabled/{id}.conf', 'w') as file:
file.write(conf) 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 # Restart nginx
os.system('systemctl restart nginx') os.system('systemctl restart nginx')
return True return True