-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathweb.py
More file actions
78 lines (65 loc) · 2.58 KB
/
web.py
File metadata and controls
78 lines (65 loc) · 2.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
from flask import Flask, render_template, request, jsonify, redirect
import subprocess
import re
from functions import *
from config import rclone_bin, location_list, ip_nas
app = Flask(__name__)
rclone_web_acess_options = "serve http --addr :8080"
@app.route("/")
def index():
subprocess.run("killall rclone", shell=True, check=False)
location_list_index = list(enumerate(location_list))
return render_template("index.html", location_list_index=location_list_index)
@app.route("/web-files-access", methods=["POST", "GET"])
def web_files_access():
if request.method == "GET":
return redirect("/")
else:
if request.form["index_pa"] == "" or request.form["snapshot"] == "":
return redirect("/")
else:
index_pa = int(request.form["index_pa"])
snapshot = request.form["snapshot"]
value = location_list[index_pa]
destino = value["destin"].localpath
recover_function = value["destin"].cmd_recover
if destino[-1] == "/":
destino = destino[:-1]
list_command = [
rclone_bin,
rclone_web_acess_options,
recover_function(f"{destino}/.zfs/snapshot/{snapshot}/"),
]
cmd = " ".join(list_command)
rclone_process_pid = subprocess.Popen(cmd, shell=True).pid
return render_template(
"index.html",
message=(
f"Permissão concedida para acessar o diretório.<br>"
f"Acesse <a href='http://{ip_nas}:8080' target='_blank'>aqui</a> para explorar.<br>"
f"O processo está em execução com o PID {rclone_process_pid}."
f"<br><br><a href='/'>Reniciar app</a>"
),
)
@app.route("/get-snapshots/<int:index_pa>")
def get_snapshots(index_pa):
value = location_list[index_pa]
destino = value["destin"].localpath
if destino[-1] == "/":
destino = destino[:-1]
list_snapshots = (
subprocess.check_output(f"ls {destino}/.zfs/snapshot/", shell=True)
.decode()
.split("\n")
)
list_snapshots = [i for i in list_snapshots[::-1] if i != ""]
return jsonify({"snapshots": list_snapshots})
@app.route("/get-log")
def get_log():
log_dir = "/var/log/"
subprocess.call(
f'rclone serve http --addr :8080 {log_dir} --include "backup*" ', shell=True
)
return render_template("index.html", message="Acesso aos logs concedido.")
if __name__ == "__main__":
app.run(host="0.0.0.0", port=5000, debug=True)