pyproxytools 0.4.5__tar.gz → 0.4.6__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. {pyproxytools-0.4.5/pyproxytools.egg-info → pyproxytools-0.4.6}/PKG-INFO +1 -1
  2. {pyproxytools-0.4.5 → pyproxytools-0.4.6}/pyproxy/__init__.py +1 -1
  3. {pyproxytools-0.4.5 → pyproxytools-0.4.6}/pyproxy/handlers/https.py +0 -1
  4. pyproxytools-0.4.6/pyproxy/monitoring/routes.py +211 -0
  5. {pyproxytools-0.4.5 → pyproxytools-0.4.6/pyproxytools.egg-info}/PKG-INFO +1 -1
  6. pyproxytools-0.4.5/pyproxy/monitoring/routes.py +0 -78
  7. {pyproxytools-0.4.5 → pyproxytools-0.4.6}/LICENSE +0 -0
  8. {pyproxytools-0.4.5 → pyproxytools-0.4.6}/README.md +0 -0
  9. {pyproxytools-0.4.5 → pyproxytools-0.4.6}/benchmark/benchmark.py +0 -0
  10. {pyproxytools-0.4.5 → pyproxytools-0.4.6}/benchmark/utils/__init__.py +0 -0
  11. {pyproxytools-0.4.5 → pyproxytools-0.4.6}/benchmark/utils/html.py +0 -0
  12. {pyproxytools-0.4.5 → pyproxytools-0.4.6}/benchmark/utils/req.py +0 -0
  13. {pyproxytools-0.4.5 → pyproxytools-0.4.6}/pyproject.toml +0 -0
  14. {pyproxytools-0.4.5 → pyproxytools-0.4.6}/pyproxy/__main__.py +0 -0
  15. {pyproxytools-0.4.5 → pyproxytools-0.4.6}/pyproxy/handlers/__init__.py +0 -0
  16. {pyproxytools-0.4.5 → pyproxytools-0.4.6}/pyproxy/handlers/client.py +0 -0
  17. {pyproxytools-0.4.5 → pyproxytools-0.4.6}/pyproxy/handlers/http.py +0 -0
  18. {pyproxytools-0.4.5 → pyproxytools-0.4.6}/pyproxy/modules/__init__.py +0 -0
  19. {pyproxytools-0.4.5 → pyproxytools-0.4.6}/pyproxy/modules/cancel_inspect.py +0 -0
  20. {pyproxytools-0.4.5 → pyproxytools-0.4.6}/pyproxy/modules/custom_header.py +0 -0
  21. {pyproxytools-0.4.5 → pyproxytools-0.4.6}/pyproxy/modules/filter.py +0 -0
  22. {pyproxytools-0.4.5 → pyproxytools-0.4.6}/pyproxy/modules/shortcuts.py +0 -0
  23. {pyproxytools-0.4.5 → pyproxytools-0.4.6}/pyproxy/monitoring/__init__.py +0 -0
  24. {pyproxytools-0.4.5 → pyproxytools-0.4.6}/pyproxy/monitoring/auth.py +0 -0
  25. {pyproxytools-0.4.5 → pyproxytools-0.4.6}/pyproxy/monitoring/monitor.py +0 -0
  26. {pyproxytools-0.4.5 → pyproxytools-0.4.6}/pyproxy/pyproxy.py +0 -0
  27. {pyproxytools-0.4.5 → pyproxytools-0.4.6}/pyproxy/server.py +0 -0
  28. {pyproxytools-0.4.5 → pyproxytools-0.4.6}/pyproxy/utils/__init__.py +0 -0
  29. {pyproxytools-0.4.5 → pyproxytools-0.4.6}/pyproxy/utils/args.py +0 -0
  30. {pyproxytools-0.4.5 → pyproxytools-0.4.6}/pyproxy/utils/config.py +0 -0
  31. {pyproxytools-0.4.5 → pyproxytools-0.4.6}/pyproxy/utils/crypto.py +0 -0
  32. {pyproxytools-0.4.5 → pyproxytools-0.4.6}/pyproxy/utils/http_req.py +0 -0
  33. {pyproxytools-0.4.5 → pyproxytools-0.4.6}/pyproxy/utils/logger.py +0 -0
  34. {pyproxytools-0.4.5 → pyproxytools-0.4.6}/pyproxytools.egg-info/SOURCES.txt +0 -0
  35. {pyproxytools-0.4.5 → pyproxytools-0.4.6}/pyproxytools.egg-info/dependency_links.txt +0 -0
  36. {pyproxytools-0.4.5 → pyproxytools-0.4.6}/pyproxytools.egg-info/entry_points.txt +0 -0
  37. {pyproxytools-0.4.5 → pyproxytools-0.4.6}/pyproxytools.egg-info/requires.txt +0 -0
  38. {pyproxytools-0.4.5 → pyproxytools-0.4.6}/pyproxytools.egg-info/top_level.txt +0 -0
  39. {pyproxytools-0.4.5 → pyproxytools-0.4.6}/requirements.txt +0 -0
  40. {pyproxytools-0.4.5 → pyproxytools-0.4.6}/setup.cfg +0 -0
  41. {pyproxytools-0.4.5 → pyproxytools-0.4.6}/setup.py +0 -0
  42. {pyproxytools-0.4.5 → pyproxytools-0.4.6}/tests/modules/__init__.py +0 -0
  43. {pyproxytools-0.4.5 → pyproxytools-0.4.6}/tests/modules/test_cancel_inspect.py +0 -0
  44. {pyproxytools-0.4.5 → pyproxytools-0.4.6}/tests/modules/test_custom_header.py +0 -0
  45. {pyproxytools-0.4.5 → pyproxytools-0.4.6}/tests/modules/test_filter.py +0 -0
  46. {pyproxytools-0.4.5 → pyproxytools-0.4.6}/tests/modules/test_shortcuts.py +0 -0
  47. {pyproxytools-0.4.5 → pyproxytools-0.4.6}/tests/utils/__init__.py +0 -0
  48. {pyproxytools-0.4.5 → pyproxytools-0.4.6}/tests/utils/test_crypto.py +0 -0
  49. {pyproxytools-0.4.5 → pyproxytools-0.4.6}/tests/utils/test_http_req.py +0 -0
  50. {pyproxytools-0.4.5 → pyproxytools-0.4.6}/tests/utils/test_logger.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pyproxytools
3
- Version: 0.4.5
3
+ Version: 0.4.6
4
4
  Summary: Lightweight and fast python web proxy
5
5
  Author: pyproxytools
6
6
  License-Expression: MIT
@@ -5,7 +5,7 @@ that holds the current version number of the application.
5
5
 
6
6
  import os
7
7
 
8
- __version__ = "0.4.5"
8
+ __version__ = "0.4.6"
9
9
 
10
10
  if os.path.isdir("pyproxy/monitoring"):
11
11
  __slim__ = False
@@ -415,7 +415,6 @@ class HttpsHandler:
415
415
  data
416
416
  )
417
417
  except (socket.error, OSError):
418
- self.logger_config.console_logger("error")
419
418
  client_socket.close()
420
419
  server_socket.close()
421
420
  self.active_connections.pop(threading.get_ident(), None)
@@ -0,0 +1,211 @@
1
+ """
2
+ pyproxy.monitoring.routes.py
3
+
4
+ Defines and registers monitoring-related routes for the Flask application,
5
+ including endpoints for system information, configuration, and a secured
6
+ HTML-based index page.
7
+ """
8
+
9
+ from flask import jsonify, render_template, request
10
+
11
+
12
+ def register_routes(app, auth, proxy_server, ProxyMonitor):
13
+ """
14
+ Registers the monitoring routes to the Flask app, secured with HTTP Basic Auth.
15
+
16
+ Args:
17
+ app (Flask): The Flask application instance.
18
+ auth (HTTPBasicAuth): The HTTP Basic Auth instance used to secure routes.
19
+ proxy_server (ProxyServer): The running ProxyServer instance to monitor.
20
+ ProxyMonitor (class): The monitoring class used to gather runtime information.
21
+ """
22
+
23
+ @app.route("/")
24
+ @auth.login_required
25
+ def index():
26
+ """
27
+ Serves the main index HTML page for the monitoring dashboard.
28
+
29
+ Returns:
30
+ Response: Rendered HTML page.
31
+ """
32
+ return render_template("index.html")
33
+
34
+ @app.route("/api/status", methods=["GET"])
35
+ @auth.login_required
36
+ def monitoring():
37
+ """
38
+ Provides real-time monitoring information about the ProxyServer,
39
+ including process, thread, and connection status.
40
+
41
+ Returns:
42
+ Response: JSON object containing monitoring data.
43
+ """
44
+ monitor = ProxyMonitor(proxy_server)
45
+ return jsonify(monitor.get_process_info())
46
+
47
+ @app.route("/api/settings", methods=["GET"])
48
+ @auth.login_required
49
+ def config():
50
+ """
51
+ Returns the current configuration of the ProxyServer.
52
+
53
+ The configuration includes:
54
+ - Host and port
55
+ - Debug mode
56
+ - 403 HTML page usage
57
+ - Logger configuration (if present)
58
+ - Filter configuration (if present)
59
+ - SSL configuration (if present)
60
+ - Flask monitoring port
61
+
62
+ Returns:
63
+ Response: JSON object containing configuration data.
64
+ """
65
+ config_data = {
66
+ "host": proxy_server.host_port[0],
67
+ "port": proxy_server.host_port[1],
68
+ "debug": proxy_server.debug,
69
+ "html_403": proxy_server.html_403,
70
+ "logger_config": (
71
+ proxy_server.logger_config.to_dict()
72
+ if proxy_server.logger_config
73
+ else None
74
+ ),
75
+ "filter_config": (
76
+ proxy_server.filter_config.to_dict()
77
+ if proxy_server.filter_config
78
+ else None
79
+ ),
80
+ "ssl_config": (
81
+ proxy_server.ssl_config.to_dict() if proxy_server.ssl_config else None
82
+ ),
83
+ "flask_port": proxy_server.monitoring_config.flask_port,
84
+ }
85
+ return jsonify(config_data)
86
+
87
+ @app.route("/api/filtering", methods=["GET", "POST", "DELETE"])
88
+ @auth.login_required
89
+ def blocked():
90
+ """
91
+ Manages the blocked sites and URLs list.
92
+
93
+ GET:
94
+ Reads and returns the current blocked domains and URLs from the corresponding files.
95
+ Returns:
96
+ Response: JSON object with 'blocked_sites' and 'blocked_url' lists.
97
+
98
+ POST:
99
+ Adds a new domain or URL to the blocked lists based on
100
+ 'type' and 'value' from JSON input.
101
+ Request JSON:
102
+ {
103
+ "type": "domain" | "url",
104
+ "value": "<value_to_block>"
105
+ }
106
+ Returns:
107
+ 201: Successfully added.
108
+ 400: Invalid input.
109
+ 409: Value already blocked.
110
+
111
+ DELETE:
112
+ Removes a domain or URL from the blocked lists based on
113
+ 'type' and 'value' from JSON input.
114
+ Request JSON:
115
+ {
116
+ "type": "domain" | "url",
117
+ "value": "<value_to_unblock>"
118
+ }
119
+ Returns:
120
+ 200: Successfully removed.
121
+ 400: Invalid input.
122
+ 404: Value not found.
123
+ 500: Server error.
124
+ """
125
+ if request.method == "GET":
126
+ blocked_sites_content = ""
127
+ blocked_url_content = ""
128
+
129
+ with open(
130
+ proxy_server.filter_config.blocked_sites, "r", encoding="utf-8"
131
+ ) as f:
132
+ blocked_sites_content = [line.strip() for line in f if line.strip()]
133
+ with open(
134
+ proxy_server.filter_config.blocked_url, "r", encoding="utf-8"
135
+ ) as f:
136
+ blocked_url_content = [line.strip() for line in f if line.strip()]
137
+
138
+ blocked_data = {
139
+ "blocked_sites": blocked_sites_content,
140
+ "blocked_url": blocked_url_content,
141
+ }
142
+ return jsonify(blocked_data)
143
+
144
+ elif request.method == "POST":
145
+ data = request.get_json()
146
+ typ = data.get("type")
147
+ val = data.get("value", "").strip()
148
+ if not val or typ not in ["domain", "url"]:
149
+ return jsonify({"error": "Invalid input"}), 400
150
+
151
+ filename = (
152
+ proxy_server.filter_config.blocked_sites
153
+ if typ == "domain"
154
+ else proxy_server.filter_config.blocked_url
155
+ )
156
+
157
+ with open(filename, "r+", encoding="utf-8") as f:
158
+ lines = [line.strip() for line in f if line.strip()]
159
+ if val in lines:
160
+ return jsonify({"message": "Already blocked"}), 409
161
+ lines.append(val)
162
+ f.seek(0)
163
+ f.truncate()
164
+ f.write("\n".join(lines) + "\n")
165
+ return jsonify({"message": "Added successfully"}), 201
166
+
167
+ elif request.method == "DELETE":
168
+ data = request.get_json()
169
+ if not data or "type" not in data or "value" not in data:
170
+ return (
171
+ jsonify({"error": "Missing 'type' or 'value' in request body"}),
172
+ 400,
173
+ )
174
+
175
+ block_type = data["type"]
176
+ value = data["value"].strip()
177
+
178
+ if block_type == "domain":
179
+ filepath = proxy_server.filter_config.blocked_sites
180
+ elif block_type == "url":
181
+ filepath = proxy_server.filter_config.blocked_url
182
+ else:
183
+ return (
184
+ jsonify({"error": "Invalid type, must be 'domain' or 'url'"}),
185
+ 400,
186
+ )
187
+
188
+ try:
189
+ with open(filepath, "r", encoding="utf-8") as f:
190
+ lines = [line.strip() for line in f if line.strip()]
191
+
192
+ if value not in lines:
193
+ return (
194
+ jsonify({"error": f"{value} not found in {block_type} list"}),
195
+ 404,
196
+ )
197
+
198
+ lines = [line for line in lines if line != value]
199
+
200
+ with open(filepath, "w", encoding="utf-8") as f:
201
+ for line in lines:
202
+ f.write(line + "\n")
203
+
204
+ return (
205
+ jsonify(
206
+ {"message": f"{block_type} '{value}' removed successfully"}
207
+ ),
208
+ 200,
209
+ )
210
+ except Exception as e:
211
+ return jsonify({"error": f"Server error: {str(e)}"}), 500
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pyproxytools
3
- Version: 0.4.5
3
+ Version: 0.4.6
4
4
  Summary: Lightweight and fast python web proxy
5
5
  Author: pyproxytools
6
6
  License-Expression: MIT
@@ -1,78 +0,0 @@
1
- """
2
- pyproxy.monitoring.routes.py
3
-
4
- Defines and registers monitoring-related routes for the Flask application,
5
- including endpoints for system information, configuration, and a secured
6
- HTML-based index page.
7
- """
8
-
9
- from flask import jsonify, render_template
10
-
11
-
12
- def register_routes(app, auth, proxy_server, ProxyMonitor):
13
- """
14
- Registers the monitoring routes to the Flask app, secured with HTTP Basic Auth.
15
-
16
- Args:
17
- app (Flask): The Flask application instance.
18
- auth (HTTPBasicAuth): The HTTP Basic Auth instance used to secure routes.
19
- proxy_server (ProxyServer): The running ProxyServer instance to monitor.
20
- ProxyMonitor (class): The monitoring class used to gather runtime information.
21
- """
22
-
23
- @app.route("/")
24
- @auth.login_required
25
- def index():
26
- """
27
- Serves the main index HTML page for the monitoring dashboard.
28
-
29
- Returns:
30
- Response: Rendered HTML page.
31
- """
32
- return render_template("index.html")
33
-
34
- @app.route("/monitoring", methods=["GET"])
35
- @auth.login_required
36
- def monitoring():
37
- """
38
- Provides real-time monitoring information about the ProxyServer,
39
- including process, thread, and connection status.
40
-
41
- Returns:
42
- Response: JSON object containing monitoring data.
43
- """
44
- monitor = ProxyMonitor(proxy_server)
45
- return jsonify(monitor.get_process_info())
46
-
47
- @app.route("/config", methods=["GET"])
48
- @auth.login_required
49
- def config():
50
- """
51
- Returns the current configuration of the ProxyServer, including
52
- host, port, debug mode, and optional components like logger, filter,
53
- and SSL configuration.
54
-
55
- Returns:
56
- Response: JSON object containing configuration data.
57
- """
58
- config_data = {
59
- "host": proxy_server.host_port[0],
60
- "port": proxy_server.host_port[1],
61
- "debug": proxy_server.debug,
62
- "html_403": proxy_server.html_403,
63
- "logger_config": (
64
- proxy_server.logger_config.to_dict()
65
- if proxy_server.logger_config
66
- else None
67
- ),
68
- "filter_config": (
69
- proxy_server.filter_config.to_dict()
70
- if proxy_server.filter_config
71
- else None
72
- ),
73
- "ssl_config": (
74
- proxy_server.ssl_config.to_dict() if proxy_server.ssl_config else None
75
- ),
76
- "flask_port": proxy_server.monitoring_config.flask_port,
77
- }
78
- return jsonify(config_data)
File without changes
File without changes
File without changes
File without changes