-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathview_tasks.py
60 lines (53 loc) · 2.3 KB
/
view_tasks.py
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
from flask import Blueprint, render_template, redirect, url_for, flash, session
import os
import subprocess # For running system commands
from shAndCrontab import SHAndCRONTABHandler
# Blueprint for viewing the shell script and crontab entries
view_tasks_blueprint = Blueprint("view_tasks", __name__)
# Route to execute the shell script
@view_tasks_blueprint.route("/execute_shell_script")
def execute_shell_script():
# Execute the shell script
shAndCrontab = SHAndCRONTABHandler(use_remote=True)
shAndCrontab.execute_shell_script()
flash("Shell script executed successfully", 'success')
script_content = shAndCrontab.view_script()
return render_template(
"view_shell_script.html",
script_content=script_content,
script_name=shAndCrontab.sh_script_path,
script_full_path=shAndCrontab.sh_script_path
)
# Route to view the content of the shell script
@view_tasks_blueprint.route("/view_shell_script")
def view_shell_script():
if 'logged_in' not in session:
return redirect(url_for('login'))
shAndCrontab = SHAndCRONTABHandler(use_remote=True)
script_content = shAndCrontab.view_script()
return render_template(
"view_shell_script.html",
script_content=script_content,
script_name=shAndCrontab.sh_script_path,
script_full_path=shAndCrontab.sh_script_path
)
# Route to view the `rsync` entries in the crontab
@view_tasks_blueprint.route("/view_crontab")
def view_crontab():
if 'logged_in' not in session:
return redirect(url_for('login'))
shAndCrontab = SHAndCRONTABHandler(use_remote=True)
rsync_entries = shAndCrontab.view_crontab()
return render_template("view_crontab.html", rsync_entries=rsync_entries)
@view_tasks_blueprint.route("/purge_script")
def purge_script():
shAndCrontab = SHAndCRONTABHandler(use_remote=True)
shAndCrontab.purge_script()
flash("Shell script purged successfully", 'success')
script_content = shAndCrontab.view_script()
return render_template(
"view_shell_script.html",
script_content=script_content,
script_name=shAndCrontab.sh_script_path,
script_full_path=shAndCrontab.sh_script_path
)