Add specific order for core plugins and check them
This commit is contained in:
parent
7860aeab94
commit
bd4c94e834
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"id": "antibot",
|
||||
"order": 4,
|
||||
"order": 8,
|
||||
"name": "Antibot",
|
||||
"description": "Bot detection by using a challenge.",
|
||||
"version": "0.1",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"id": "badbehavior",
|
||||
"order": 2,
|
||||
"order": 999,
|
||||
"name": "Bad behavior",
|
||||
"description": "Ban IP generating too much 'bad' HTTP status code in a period of time.",
|
||||
"version": "0.1",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"id": "bunkernet",
|
||||
"order": 2,
|
||||
"order": 6,
|
||||
"name": "BunkerNet",
|
||||
"description": "Share threat data with other BunkerWeb instances via BunkerNet.",
|
||||
"version": "0.1",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"id": "country",
|
||||
"order": 2,
|
||||
"order": 4,
|
||||
"name": "Country",
|
||||
"description": "Deny access based on the country of the client IP.",
|
||||
"version": "0.1",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"id": "dnsbl",
|
||||
"order": 2,
|
||||
"order": 5,
|
||||
"name": "DNSBL",
|
||||
"description": "Deny access based on external DNSBL servers.",
|
||||
"version": "0.1",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"id": "greylist",
|
||||
"order": 2,
|
||||
"order": 3,
|
||||
"name": "Greylist",
|
||||
"description": "Allow access while keeping security features based on internal and external IP/network/rDNS/ASN greylists.",
|
||||
"version": "0.1",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"id": "letsencrypt",
|
||||
"order": 1,
|
||||
"order": 999,
|
||||
"name": "Let's Encrypt",
|
||||
"description": "Automatic creation, renewal and configuration of Let's Encrypt certificates.",
|
||||
"version": "0.1",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"id": "limit",
|
||||
"order": 3,
|
||||
"order": 7,
|
||||
"name": "Limit",
|
||||
"description": "Limit maximum number of requests and connections.",
|
||||
"version": "0.1",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"id": "whitelist",
|
||||
"order": 2,
|
||||
"order": 1,
|
||||
"name": "Whitelist",
|
||||
"description": "Allow access based on internal and external IP/network/rDNS/ASN whitelists.",
|
||||
"version": "0.1",
|
||||
|
|
|
@ -8,7 +8,7 @@ class Configurator :
|
|||
|
||||
def __init__(self, settings, core, plugins, variables) :
|
||||
self.__settings = self.__load_settings(settings)
|
||||
self.__core = self.__load_plugins(core)
|
||||
self.__core = core
|
||||
self.__plugins = self.__load_plugins(plugins)
|
||||
self.__variables = self.__load_variables(variables)
|
||||
self.__multisite = False
|
||||
|
|
30
gen/main.py
30
gen/main.py
|
@ -1,8 +1,7 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import argparse, os, sys, shutil, glob, traceback
|
||||
import argparse, os, sys, shutil, glob, traceback, json
|
||||
|
||||
import sys
|
||||
sys.path.append("/opt/bunkerweb/deps/python")
|
||||
sys.path.append("/opt/bunkerweb/gen")
|
||||
sys.path.append("/opt/bunkerweb/utils")
|
||||
|
@ -60,9 +59,34 @@ if __name__ == "__main__" :
|
|||
log("GENERATOR", "❌", "Missing W rights on directory : " + path)
|
||||
sys.exit(1)
|
||||
|
||||
# Check core plugins orders
|
||||
log("GENERATOR", "ℹ️", "Checking core plugins orders ...")
|
||||
core_plugins = {}
|
||||
files = glob.glob(args.core + "/*/plugin.json")
|
||||
for file in files :
|
||||
try :
|
||||
with open(file) as f :
|
||||
core_plugin = json.loads(f.read())
|
||||
|
||||
if core_plugin["order"] not in core_plugins :
|
||||
core_plugins[core_plugin["order"]] = []
|
||||
|
||||
core_plugins[core_plugin["order"]].append({"id": core_plugin["id"], "settings": core_plugin["settings"]})
|
||||
except :
|
||||
log("GENERATOR", "❌", "Exception while loading JSON from " + file + " :")
|
||||
print(traceback.format_exc())
|
||||
|
||||
core_settings = {}
|
||||
for order in core_plugins :
|
||||
if len(core_plugins[order]) > 1 and order != 999 :
|
||||
log("GENERATOR", "⚠️", "Multiple plugins have the same order (" + str(order) + ") : " + ", ".join(plugin["id"] for plugin in core_plugins[order]) + ". Therefor, the execution order will be random.")
|
||||
|
||||
for plugin in core_plugins[order] :
|
||||
core_settings.update(plugin["settings"])
|
||||
|
||||
# Compute the config
|
||||
log("GENERATOR", "ℹ️", "Computing config ...")
|
||||
configurator = Configurator(args.settings, args.core, args.plugins, args.variables)
|
||||
configurator = Configurator(args.settings, core_settings, args.plugins, args.variables)
|
||||
config = configurator.get_config()
|
||||
|
||||
# Remove old files
|
||||
|
|
Loading…
Reference in New Issue