Skip to content
This repository was archived by the owner on Apr 18, 2022. It is now read-only.

Commit f6f2adc

Browse files
committed
improve documentation + fix default ban ip
1 parent 7fade8f commit f6f2adc

File tree

2 files changed

+25
-15
lines changed

2 files changed

+25
-15
lines changed

README.md

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,20 @@
11
![GitHub stars](https://img.shields.io/github/stars/unixfox/antibot-proxy.svg?style=social) [![Docker Cloud Build Status](https://img.shields.io/docker/cloud/build/unixfox/antibot-proxy.svg)](https://hub.docker.com/r/unixfox/antibot-proxy) [![Docker Cloud Automated build](https://img.shields.io/docker/cloud/automated/unixfox/antibot-proxy.svg)](https://hub.docker.com/r/unixfox/antibot-proxy) ![GitHub package.json version](https://img.shields.io/github/package-json/v/unixfox/antibot-proxy.svg)
22

33
# Description
4+
45
:warning: This program is still experimental and (badly written) so there are probably some bugs and vulnerabilities in the bot detection system. :warning:
56

67
The algorithm is based on the fact that every browser will accept cookie and load the external CSS that you included in your HTML page so in case of a stupid/basic bot it won't simply process the cookie or/and load that external CSS file because it does not process the HTML code.
78

8-
# How to make it work?
9+
# How to make it work? (minimalistic configuration)
910

10-
1. Copy the `example.toml` to `config.toml` and the `views/bot.template.pug` to `views/bot.pug`.
11+
1. Copy the `example.toml` to `config.toml`.
1112

12-
2. Modify the settings inside the `config.toml`. You don't need to modify every setting, just change the one that you want to be changed. Here is the reference for each setting:
13-
- `COOKIE_NAME`: The name of the cookie that will be used for checking if the client can handle the cookie.
14-
- `ENDPOINT_NAME`: The name of the CSS file that will be used for checking if the client can process the HTML code.
15-
- `JAIL_PATH`: The path to the directory where the banned IP will be stored. Optionally to be used with the [ipfilter](https://caddyserver.com/docs/http.ipfilter) plugin of Caddy.
16-
- `MAX_RETRY`: The number of retries allowed for the client before getting banned.
17-
- `PORT`: The port of which the proxy application will listen to.
18-
- `TARGET`: The URL of the application to proxy/protect.
19-
- `TIMEOUT_LOAD`: The time before the program consider that the client failed to reach the CSS file.
20-
- `WHITELIST`: The IP that you want to be whitelisted. Separate each IP with a `,`.
21-
- `WHITELIST_PAGES`: Pages to whitelist from the blocked page for bots.
13+
2. Modify the setting `TARGET` in the `config.toml` to the URL where your application is listening to. For example if your application reachable on `http://127.0.0.1:8080` just set `127.0.0.1:8080` in the setting.
2214

23-
3. On your main webserver (nginx, apache, caddy,...) you need to pass the IP address of the client to the application (with the `X-Real-IP` header). Here is how to do it on:
15+
3. Modify the setting `JAIL_PATH` in the `config.toml` to an empty directory that you created for the application.
16+
17+
3. On your main webserver (nginx, apache, caddy,...) when you will proxy the `antibot-proxy` application you will also need to pass the IP address of the client to the application (with the `X-Real-IP` header). Here is how to do it on:
2418
- Apache:
2519

2620
```apache
@@ -38,8 +32,22 @@ proxy_set_header X-Real-IP $remote_addr;
3832
```caddy
3933
transparent
4034
```
35+
> Note: You may consult the documentation of your webserver for further details about proxying an application.
36+
37+
# Reference of each setting in `config.toml` for advanced configuration
38+
39+
- `COOKIE_NAME`: The name of the cookie that will be used for checking if the client can handle the cookie.
40+
- `ENDPOINT_NAME`: The name of the CSS file that will be used for checking if the client can process the HTML code.
41+
- `JAIL_PATH`: The path to the directory where the banned IP will be stored. Optionally to be used with the [ipfilter](https://caddyserver.com/docs/http.ipfilter) plugin of Caddy.
42+
- `MAX_RETRY`: The number of retries allowed for the client before getting banned.
43+
- `PORT`: The port of which the proxy application will listen to.
44+
- `TARGET`: The URL of the application to proxy/protect.
45+
- `TIMEOUT_LOAD`: The time before the program consider that the client failed to reach the CSS file.
46+
- `WHITELIST`: The IP that you want to be whitelisted.
47+
- `WHITELIST_PAGES`: Pages to whitelist from the blocked page for bots.
48+
4149

42-
# How to configure the ipfilter plugin to handle the banned IPs?
50+
# How to configure the ipfilter Caddy plugin to handle the banned IPs?
4351

4452
You just need to add this block to your `Caddyfile`:
4553
````JSON

index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,10 @@ app.get("/" + configFile.ENDPOINT_NAME, function (userReq, userRes) {
6565
app.all("*", function (userReq, userRes, next) {
6666
const IP = (userReq.headers["x-real-ip"] || userReq.connection.remoteAddress);
6767
const secretCookie = crypto.createHash('md5').update(IP).digest('hex');
68-
if (userReq.method != "GET" && userReq.method != "POST")
68+
if ((userReq.method != "GET" && userReq.method != "POST") || checkFileExist(configFile.JAIL_PATH + "/" + IP, false)) {
69+
userRes.status(403);
6970
userRes.end();
71+
}
7072
else if ((userReq.cookies && userReq.cookies[configFile.COOKIE_NAME] === secretCookie)
7173
|| configFile.WHITELIST.indexOf(IP) > -1 || whitelistPageChecker(userReq.url, userReq.method))
7274
next();

0 commit comments

Comments
 (0)