flask-Humanify 0.1.2__tar.gz → 0.1.3.1__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.
- {flask_humanify-0.1.2/flask_Humanify.egg-info → flask_humanify-0.1.3.1}/PKG-INFO +16 -3
- {flask_humanify-0.1.2 → flask_humanify-0.1.3.1}/README.md +15 -2
- {flask_humanify-0.1.2 → flask_humanify-0.1.3.1/flask_Humanify.egg-info}/PKG-INFO +16 -3
- {flask_humanify-0.1.2 → flask_humanify-0.1.3.1}/flask_humanify/__init__.py +1 -1
- {flask_humanify-0.1.2 → flask_humanify-0.1.3.1}/flask_humanify/features/rate_limiter.py +1 -1
- {flask_humanify-0.1.2 → flask_humanify-0.1.3.1}/flask_humanify/humanify.py +22 -2
- {flask_humanify-0.1.2 → flask_humanify-0.1.3.1}/pyproject.toml +1 -1
- {flask_humanify-0.1.2 → flask_humanify-0.1.3.1}/LICENSE +0 -0
- {flask_humanify-0.1.2 → flask_humanify-0.1.3.1}/MANIFEST.in +0 -0
- {flask_humanify-0.1.2 → flask_humanify-0.1.3.1}/flask_Humanify.egg-info/SOURCES.txt +0 -0
- {flask_humanify-0.1.2 → flask_humanify-0.1.3.1}/flask_Humanify.egg-info/dependency_links.txt +0 -0
- {flask_humanify-0.1.2 → flask_humanify-0.1.3.1}/flask_Humanify.egg-info/requires.txt +0 -0
- {flask_humanify-0.1.2 → flask_humanify-0.1.3.1}/flask_Humanify.egg-info/top_level.txt +0 -0
- {flask_humanify-0.1.2 → flask_humanify-0.1.3.1}/flask_humanify/datasets/ipset.json +0 -0
- {flask_humanify-0.1.2 → flask_humanify-0.1.3.1}/flask_humanify/ipset.py +0 -0
- {flask_humanify-0.1.2 → flask_humanify-0.1.3.1}/flask_humanify/templates/access_denied.html +0 -0
- {flask_humanify-0.1.2 → flask_humanify-0.1.3.1}/flask_humanify/templates/oneclick_captcha.html +0 -0
- {flask_humanify-0.1.2 → flask_humanify-0.1.3.1}/flask_humanify/templates/rate_limited.html +0 -0
- {flask_humanify-0.1.2 → flask_humanify-0.1.3.1}/flask_humanify/utils.py +0 -0
- {flask_humanify-0.1.2 → flask_humanify-0.1.3.1}/setup.cfg +0 -0
- {flask_humanify-0.1.2 → flask_humanify-0.1.3.1}/setup.py +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: flask-Humanify
|
3
|
-
Version: 0.1.
|
3
|
+
Version: 0.1.3.1
|
4
4
|
Summary: Protect against bots and DDoS attacks
|
5
5
|
Author-email: TN3W <tn3w@protonmail.com>
|
6
6
|
License-Expression: Apache-2.0
|
@@ -42,19 +42,32 @@ from flask_Humanify import Humanify
|
|
42
42
|
app = Flask(__name__)
|
43
43
|
humanify = Humanify(app)
|
44
44
|
|
45
|
+
# Register the middleware to deny access to bots
|
46
|
+
humanify.register_middleware(action="deny_access")
|
47
|
+
|
45
48
|
@app.route("/")
|
46
49
|
def index():
|
47
50
|
"""
|
48
51
|
A route that is protected against bots and DDoS attacks.
|
49
52
|
"""
|
50
|
-
if humanify.is_bot:
|
51
|
-
return humanify.redirect_to_access_denied()
|
52
53
|
return "Hello, Human!"
|
53
54
|
|
54
55
|
if __name__ == "__main__":
|
55
56
|
app.run()
|
56
57
|
```
|
57
58
|
|
59
|
+
Not using the middleware:
|
60
|
+
```python
|
61
|
+
@app.route("/")
|
62
|
+
def index():
|
63
|
+
"""
|
64
|
+
A route that is protected against bots and DDoS attacks.
|
65
|
+
"""
|
66
|
+
if humanify.is_bot:
|
67
|
+
return humanify.deny_access()
|
68
|
+
return "Hello, Human!"
|
69
|
+
```
|
70
|
+
|
58
71
|
## Usage
|
59
72
|
|
60
73
|
### Installation
|
@@ -11,19 +11,32 @@ from flask_Humanify import Humanify
|
|
11
11
|
app = Flask(__name__)
|
12
12
|
humanify = Humanify(app)
|
13
13
|
|
14
|
+
# Register the middleware to deny access to bots
|
15
|
+
humanify.register_middleware(action="deny_access")
|
16
|
+
|
14
17
|
@app.route("/")
|
15
18
|
def index():
|
16
19
|
"""
|
17
20
|
A route that is protected against bots and DDoS attacks.
|
18
21
|
"""
|
19
|
-
if humanify.is_bot:
|
20
|
-
return humanify.redirect_to_access_denied()
|
21
22
|
return "Hello, Human!"
|
22
23
|
|
23
24
|
if __name__ == "__main__":
|
24
25
|
app.run()
|
25
26
|
```
|
26
27
|
|
28
|
+
Not using the middleware:
|
29
|
+
```python
|
30
|
+
@app.route("/")
|
31
|
+
def index():
|
32
|
+
"""
|
33
|
+
A route that is protected against bots and DDoS attacks.
|
34
|
+
"""
|
35
|
+
if humanify.is_bot:
|
36
|
+
return humanify.deny_access()
|
37
|
+
return "Hello, Human!"
|
38
|
+
```
|
39
|
+
|
27
40
|
## Usage
|
28
41
|
|
29
42
|
### Installation
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: flask-Humanify
|
3
|
-
Version: 0.1.
|
3
|
+
Version: 0.1.3.1
|
4
4
|
Summary: Protect against bots and DDoS attacks
|
5
5
|
Author-email: TN3W <tn3w@protonmail.com>
|
6
6
|
License-Expression: Apache-2.0
|
@@ -42,19 +42,32 @@ from flask_Humanify import Humanify
|
|
42
42
|
app = Flask(__name__)
|
43
43
|
humanify = Humanify(app)
|
44
44
|
|
45
|
+
# Register the middleware to deny access to bots
|
46
|
+
humanify.register_middleware(action="deny_access")
|
47
|
+
|
45
48
|
@app.route("/")
|
46
49
|
def index():
|
47
50
|
"""
|
48
51
|
A route that is protected against bots and DDoS attacks.
|
49
52
|
"""
|
50
|
-
if humanify.is_bot:
|
51
|
-
return humanify.redirect_to_access_denied()
|
52
53
|
return "Hello, Human!"
|
53
54
|
|
54
55
|
if __name__ == "__main__":
|
55
56
|
app.run()
|
56
57
|
```
|
57
58
|
|
59
|
+
Not using the middleware:
|
60
|
+
```python
|
61
|
+
@app.route("/")
|
62
|
+
def index():
|
63
|
+
"""
|
64
|
+
A route that is protected against bots and DDoS attacks.
|
65
|
+
"""
|
66
|
+
if humanify.is_bot:
|
67
|
+
return humanify.deny_access()
|
68
|
+
return "Hello, Human!"
|
69
|
+
```
|
70
|
+
|
58
71
|
## Usage
|
59
72
|
|
60
73
|
### Installation
|
@@ -51,7 +51,7 @@ class RateLimiter:
|
|
51
51
|
Before request hook.
|
52
52
|
"""
|
53
53
|
ip = get_client_ip(request)
|
54
|
-
if request.endpoint
|
54
|
+
if request.endpoint in ["humanify.rate_limited", "humanify.access_denied"]:
|
55
55
|
return
|
56
56
|
if self.is_rate_limited(ip or "127.0.0.1"):
|
57
57
|
return redirect(
|
@@ -2,7 +2,8 @@ from dataclasses import dataclass
|
|
2
2
|
import logging
|
3
3
|
from typing import List, Optional
|
4
4
|
|
5
|
-
from
|
5
|
+
from werkzeug.wrappers import Response
|
6
|
+
from flask import Blueprint, request, render_template, redirect, url_for, current_app
|
6
7
|
from .ipset import IPSetClient, ensure_server_running
|
7
8
|
from .utils import get_client_ip, get_return_url
|
8
9
|
|
@@ -120,6 +121,25 @@ class Humanify:
|
|
120
121
|
{"Cache-Control": "public, max-age=15552000"},
|
121
122
|
)
|
122
123
|
|
124
|
+
def register_middleware(self, action: str = "deny_access"):
|
125
|
+
"""
|
126
|
+
Register the middleware.
|
127
|
+
"""
|
128
|
+
|
129
|
+
self.app = self.app or current_app
|
130
|
+
|
131
|
+
@self.app.before_request
|
132
|
+
def before_request():
|
133
|
+
"""
|
134
|
+
Before request hook.
|
135
|
+
"""
|
136
|
+
if request.endpoint in ["humanify.rate_limited", "humanify.access_denied"]:
|
137
|
+
return
|
138
|
+
|
139
|
+
if self.is_bot:
|
140
|
+
if action == "deny_access":
|
141
|
+
return self.deny_access()
|
142
|
+
|
123
143
|
@property
|
124
144
|
def is_bot(self) -> HumanifyResult:
|
125
145
|
"""
|
@@ -131,7 +151,7 @@ class Humanify:
|
|
131
151
|
ip_groups = self.ipset_client.lookup_ip(ip)
|
132
152
|
return HumanifyResult.from_ip_groups(ip, ip_groups)
|
133
153
|
|
134
|
-
def
|
154
|
+
def deny_access(self) -> Response:
|
135
155
|
"""
|
136
156
|
Redirect to the access denied page.
|
137
157
|
"""
|
File without changes
|
File without changes
|
File without changes
|
{flask_humanify-0.1.2 → flask_humanify-0.1.3.1}/flask_Humanify.egg-info/dependency_links.txt
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{flask_humanify-0.1.2 → flask_humanify-0.1.3.1}/flask_humanify/templates/oneclick_captcha.html
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|