Skip to content

Commit

Permalink
added three environment variables
Browse files Browse the repository at this point in the history
API_TIMEOUT: determines the timeout for BunkerWeb API calls. useful if the API is accessed through bad or unstable links.
API_READ_TIMEOUT: determines the read timeout for BunkerWeb API calls. since the nginx configuration must be tested before the server responds to the API call, a configuration large enough simply prevents BunkerWeb from ever working without this value changed.
DISABLE_CONFIGURATION_TESTING: disables all regex testing for all configuration variables. sometimes the regexes are simply too strict and sanity checks fail for some valid configurations, especially involving permission policies and feature policies. this way, we can at least give a way for people to ignore the checks.
  • Loading branch information
JohnTheNerd committed Oct 27, 2024
1 parent b454f2c commit b84b8db
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
6 changes: 5 additions & 1 deletion docs/settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ STREAM support :warning:
|`AUTOCONF_MODE` |`no` |global |no |Enable Autoconf Docker integration. |
|`SWARM_MODE` |`no` |global |no |Enable Docker Swarm integration. |
|`KUBERNETES_MODE` |`no` |global |no |Enable Kubernetes integration. |

|`API_TIMEOUT` |`10` |global |no |Manually set the timeout for BunkerWeb API requests. | |
|`API_READ_TIMEOUT` |`30` |global |no |Manually set the read timeout for BunkerWeb API requests. |

|`SERVER_TYPE` |`http` |multisite|no |Server type : http or stream. |
|`LISTEN_STREAM` |`yes` |multisite|no |Enable listening for non-ssl (passthrough). |
|`LISTEN_STREAM_PORT` |`1337` |multisite|no |Listening port for non-ssl (passthrough). |
Expand All @@ -51,7 +55,7 @@ STREAM support :warning:
|`IS_DRAFT` |`no` |multisite|no |Internal use : set to yes when the service is in draft mode. |
|`TIMERS_LOG_LEVEL` |`debug` |global |no |Log level for timers. |
|`OVERRIDE_INSTANCES` | |global |no |List of BunkerWeb instances separated with spaces (format : fqdn-or-ip:5000 fqdn-or-ip:5000)|

|`DISABLE_CONFIGURATION_TESTING` |`no` |global |no |Disable sanity checks for all other environment variables. |

## Antibot

Expand Down
4 changes: 3 additions & 1 deletion src/common/api/API.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env python3

from os import environ
from typing import Literal, Optional, Union
from requests import request

Expand All @@ -25,7 +26,8 @@ def request(
url: str,
data: Optional[Union[dict, bytes]] = None,
files=None,
timeout=(10, 30),
timeout=(int(environ.get('API_TIMEOUT', 10)),
int(environ.get('API_READ_TIMEOUT', 30))),
) -> tuple[bool, str, Optional[int], Optional[dict]]:
try:
kwargs = {}
Expand Down
11 changes: 6 additions & 5 deletions src/common/gen/Configurator.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from io import BytesIO
from json import loads
from logging import Logger
from os import cpu_count, listdir, sep
from os import cpu_count, listdir, sep, environ
from os.path import basename, dirname, join
from pathlib import Path
from re import compile as re_compile, error as RegexError, search as re_search
Expand Down Expand Up @@ -40,6 +40,7 @@ def __init__(
self.__settings = self.__load_settings(settings)
self.__core_plugins = []
self.__load_plugins(core)
self.__disable_test = environ.get('DISABLE_CONFIGURATION_TESTING', 'no') == 'yes'

if isinstance(external_plugins, str):
self.__external_plugins = []
Expand Down Expand Up @@ -89,15 +90,15 @@ def __map_servers(self) -> Dict[str, List[str]]:
if not server_name:
continue

if not re_search(self.__settings["SERVER_NAME"]["regex"], server_name):
if not re_search(self.__settings["SERVER_NAME"]["regex"], server_name) and not self.__disable_test:
self.__logger.warning(f"Ignoring server name {server_name} because regex is not valid")
continue
names = [server_name]
if f"{server_name}_SERVER_NAME" in self.__variables:
if not re_search(
self.__settings["SERVER_NAME"]["regex"],
self.__variables[f"{server_name}_SERVER_NAME"],
):
) and not self.__disable_test:
self.__logger.warning(f"Ignoring {server_name}_SERVER_NAME because regex is not valid")
else:
names = self.__variables[f"{server_name}_SERVER_NAME"].strip().split(" ")
Expand Down Expand Up @@ -235,7 +236,7 @@ def __check_var(self, variable: str) -> Tuple[bool, str]:
return False, f"variable name {variable} doesn't exist"

try:
if not re_search(where[real_var]["regex"], value):
if not re_search(where[real_var]["regex"], value) and not self.__disable_test:
return (False, f"value {value} doesn't match regex {where[real_var]['regex']}")
except RegexError:
self.__logger.warning(f"Invalid regex for {variable} : {where[real_var]['regex']}, ignoring regex check")
Expand All @@ -250,7 +251,7 @@ def __check_var(self, variable: str) -> Tuple[bool, str]:
return False, f"context of {variable} isn't multisite"

try:
if not re_search(where[real_var]["regex"], value):
if not re_search(where[real_var]["regex"], value) and not self.__disable_test:
return (False, f"value {value} doesn't match regex {where[real_var]['regex']}")
except RegexError:
self.__logger.warning(f"Invalid regex for {variable} : {where[real_var]['regex']}, ignoring regex check")
Expand Down

0 comments on commit b84b8db

Please sign in to comment.