-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmanagement_console.py
More file actions
87 lines (78 loc) · 2.33 KB
/
management_console.py
File metadata and controls
87 lines (78 loc) · 2.33 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
79
80
81
82
83
84
85
86
87
from flask import Flask, request, render_template_string
app = Flask(__name__)
# Global block list stored in Python
BLOCK_LIST = []
# File name to store blocked URLs (must match what the C code reads)
BLOCK_LIST_FILE = "block_list.txt"
def save_block_list():
with open(BLOCK_LIST_FILE, "w") as f:
for url in BLOCK_LIST:
f.write(url + "\n")
# HTML template for the management console.
HTML_TEMPLATE = """
<html>
<head>
<title>Proxy Management Console</title>
</head>
<body>
<h1>Proxy Management Console</h1>
{% if message %}
<p><strong>{{ message }}</strong></p>
{% endif %}
<ul>
<li>
<form action="{{ url_for('block') }}" method="post">
Block URL: <input type="text" name="url">
<input type="submit" value="Block">
</form>
</li>
<li>
<form action="{{ url_for('unblock') }}" method="post">
Unblock URL: <input type="text" name="url">
<input type="submit" value="Unblock">
</form>
</li>
</ul>
{% if block_list %}
<h2>Blocked URLs</h2>
<ul>
{% for url in block_list %}
<li>{{ url }}</li>
{% endfor %}
</ul>
{% endif %}
</body>
</html>
"""
@app.route("/")
def index():
return render_template_string(HTML_TEMPLATE, message="", block_list=BLOCK_LIST)
@app.route("/block", methods=["POST"])
def block():
url = request.form.get("url", "").strip()
if url:
if url not in BLOCK_LIST:
BLOCK_LIST.append(url)
message = f"Blocked URL: {url}"
else:
message = f"URL already blocked: {url}"
save_block_list()
else:
message = "No URL provided."
return render_template_string(HTML_TEMPLATE, message=message, block_list=BLOCK_LIST)
@app.route("/unblock", methods=["POST"])
def unblock():
url = request.form.get("url", "").strip()
if url:
if url in BLOCK_LIST:
BLOCK_LIST.remove(url)
message = f"Unblocked URL: {url}"
else:
message = f"URL not in block list: {url}"
save_block_list()
else:
message = "No URL provided."
return render_template_string(HTML_TEMPLATE, message=message, block_list=BLOCK_LIST)
if __name__ == "__main__":
# Run the management console on port 3000.
app.run(host="0.0.0.0", port=3000)