diff --git a/README.md b/README.md index b3c3ce9..e47cf37 100644 --- a/README.md +++ b/README.md @@ -17,4 +17,21 @@ sudo -i cd /root/site-manager python3 account.py exit -``` \ No newline at end of file +``` + + +Updating +-------- +```bash +sudo -i +cd /root/site-manager +git pull +exit +``` + + +## Screenshots +![Dashboard](assets/dash.png) +![Management page](assets/mg1.png) +![Plain Content](assets/plain.png) +![Git Content](assets/git.png) \ No newline at end of file diff --git a/assets/dash.png b/assets/dash.png new file mode 100644 index 0000000..28812ee Binary files /dev/null and b/assets/dash.png differ diff --git a/assets/git.png b/assets/git.png new file mode 100644 index 0000000..b7d17f1 Binary files /dev/null and b/assets/git.png differ diff --git a/assets/mg1.png b/assets/mg1.png new file mode 100644 index 0000000..5f369b8 Binary files /dev/null and b/assets/mg1.png differ diff --git a/assets/plain.png b/assets/plain.png new file mode 100644 index 0000000..601e220 Binary files /dev/null and b/assets/plain.png differ diff --git a/main.py b/main.py index 9d2c5d4..6e658cf 100644 --- a/main.py +++ b/main.py @@ -85,9 +85,16 @@ def manage_site(name): dns_info = sites_module.get_dns_info(name) dns_info = render.dns_info(dns_info) + git = f'
' + if "git" in site: + if site["git"]: + git = f'

Git repository {site["git"]} added

Pull' + + return render_template('manage.html', user=user, year=datetime.datetime.now().year, site=site['name'], domain=site['domain'], enabled=site['active'], - alt_domains=alt_domains, checked=checked, files=files, dns_info=dns_info) + alt_domains=alt_domains, checked=checked, + files=files, dns_info=dns_info, git=git) @app.route('/manage//alt', methods=['POST']) @@ -166,9 +173,25 @@ def delete_site(name, file): return redirect('/manage/' + name) +@app.route('/manage//clone', methods=['POST']) +def clone_git(name): + site = sites_module.get_site(name) + if not site: + return "Error: Site not found." + data = request.form + url = data['url'] + sites_module.clone_git(name, url) + return redirect('/manage/' + name) +@app.route('/manage//pull') +def pull_git(name): + site = sites_module.get_site(name) + if not site: + return "Error: Site not found." + sites_module.pull_git(name) + return redirect('/manage/' + name) diff --git a/sites.py b/sites.py index 09b44cc..e1ad27e 100644 --- a/sites.py +++ b/sites.py @@ -284,4 +284,46 @@ def is_icann(domain): tlds = [tld for tld in tlds if not tld.startswith('#')] if domain.split('.')[-1].upper() in tlds: return True - return False \ No newline at end of file + return False + +def clone_git(name, url): + site = get_site(name) + id = site['id'] + path = f'/var/www/{id}' + if not os.path.isdir(path): + os.mkdir(path) + os.system(f'git clone {url} {path}') + + with open('sites.json', 'r') as file: + sites = json.loads(file.read()) + for site in sites: + if site['name'] == name: + site['git'] = url + with open('sites.json', 'w') as file: + file.write(json.dumps(sites)) + return True + + return True + +def pull_git(name): + site = get_site(name) + id = site['id'] + path = f'/var/www/{id}' + if not os.path.isdir(path): + return False + + # Check if it's a git repo + if not os.path.isdir(f'{path}/.git'): + # Remove git from sites.json + with open('sites.json', 'r') as file: + sites = json.loads(file.read()) + for site in sites: + if site['name'] == name: + del site['git'] + with open('sites.json', 'w') as file: + file.write(json.dumps(sites)) + return False + + + os.system(f'cd {path} && git pull') + return True \ No newline at end of file diff --git a/templates/manage.html b/templates/manage.html index db18c21..5763a57 100644 --- a/templates/manage.html +++ b/templates/manage.html @@ -116,7 +116,7 @@

Click or drop files here. Drop a zip to include folders

    {{files|safe}} -
+{{git|safe}}