feat: Added basic git
This commit is contained in:
parent
a4d79ef773
commit
2c97d4c169
17
README.md
17
README.md
@ -18,3 +18,20 @@ cd /root/site-manager
|
||||
python3 account.py
|
||||
exit
|
||||
```
|
||||
|
||||
|
||||
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)
|
BIN
assets/dash.png
Normal file
BIN
assets/dash.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 75 KiB |
BIN
assets/git.png
Normal file
BIN
assets/git.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 80 KiB |
BIN
assets/mg1.png
Normal file
BIN
assets/mg1.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 101 KiB |
BIN
assets/plain.png
Normal file
BIN
assets/plain.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 35 KiB |
25
main.py
25
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'<form action="/manage/{site["name"]}/clone" method="post"><input class="form-control form-control-user" type="text" name="url" placeholder="https://github.com/..." /><input class="btn btn-primary" type="submit" value="Clone Git via HTTPS" /></form>'
|
||||
if "git" in site:
|
||||
if site["git"]:
|
||||
git = f'<p>Git repository <a href="{site["git"]}" target="_blank">{site["git"]}</a> added</p><a href="/manage/{site["name"]}/pull" class="btn btn-primary">Pull</a>'
|
||||
|
||||
|
||||
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/<name>/alt', methods=['POST'])
|
||||
@ -166,9 +173,25 @@ def delete_site(name, file):
|
||||
return redirect('/manage/' + name)
|
||||
|
||||
|
||||
@app.route('/manage/<name>/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/<name>/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)
|
||||
|
||||
|
||||
|
||||
|
42
sites.py
42
sites.py
@ -285,3 +285,45 @@ def is_icann(domain):
|
||||
if domain.split('.')[-1].upper() in tlds:
|
||||
return True
|
||||
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
|
@ -116,7 +116,7 @@
|
||||
<p>Click or drop files here. Drop a zip to include folders</p><input type="file" id="fileInput" multiple="">
|
||||
</div><ul class="list-group">
|
||||
{{files|safe}}
|
||||
</ul>
|
||||
</ul>{{git|safe}}
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
|
Loading…
Reference in New Issue
Block a user