mirror of
https://github.com/bunkerity/bunkerweb
synced 2026-05-24 09:28:37 +00:00
Apply pre-commit-config and update pyproject.toml
This commit is contained in:
parent
c683466f36
commit
985c764bcb
10 changed files with 34 additions and 23 deletions
|
|
@ -283,7 +283,7 @@ This script is running on flask context, you have access to lib and utils like `
|
|||
|
||||
- **template.html** : custom plugin page you can access from ui.
|
||||
|
||||
- **plugin.lua** : code to execute on NGINX using [NGING LUA modile.](https://github.com/openresty/lua-nginx-module)
|
||||
- **plugin.lua** : code to execute on NGINX using [NGING LUA module.](https://github.com/openresty/lua-nginx-module)
|
||||
|
||||
- **plugin.json** : metadata, settings and jobs for your settings.
|
||||
|
||||
|
|
@ -619,5 +619,5 @@ I need to add this on my **template.html** :
|
|||
| `el` | element| Select element you want the value to be updated. |
|
||||
| `value` | any | Default value on template load or in case retrieving JSON failed. |
|
||||
| `type` | string | Define the script behavior with the incoming value. Available : `text`, `list` and `status`. |
|
||||
| `textEl` | element| Optional additionnal text content when type is `status`. |
|
||||
| `textEl` | element| Optional additional text content when type is `status`. |
|
||||
| `listNames`| string | List of data keys when type is `list`. |
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ authors = [
|
|||
]
|
||||
|
||||
[tool.black]
|
||||
py39 = true
|
||||
line-length = 250
|
||||
include = '\.pyi?$'
|
||||
exclude = '''
|
||||
|
|
|
|||
|
|
@ -786,7 +786,7 @@ utils.get_phases = function()
|
|||
"preread",
|
||||
"log_stream",
|
||||
"log_default",
|
||||
"timer"
|
||||
"timer",
|
||||
}
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
from datetime import datetime
|
||||
from json import dumps, loads
|
||||
from operator import itemgetter
|
||||
from time import time
|
||||
from dotenv import dotenv_values
|
||||
from os import getenv, sep
|
||||
|
|
@ -249,7 +250,7 @@ class CLI(ApiCaller):
|
|||
exp = self.__redis.ttl(key)
|
||||
servers["redis"].append({"ip": ip, "exp": exp} | loads(data))
|
||||
|
||||
servers = {k: sorted(v, key=lambda x: x["date"]) for k, v in servers.items()}
|
||||
servers = {k: sorted(v, key=itemgetter("date")) for k, v in servers.items()}
|
||||
|
||||
cli_str = ""
|
||||
for server, bans in servers.items():
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ init_worker_by_lua_block {
|
|||
-- Recurrent timer
|
||||
local recurrent_timer
|
||||
recurrent_timer = function(premature)
|
||||
|
||||
|
||||
local worker_id = tostring(worker.id())
|
||||
local logger = require "bunkerweb.logger":new("TIMER-" .. worker_id)
|
||||
|
||||
|
|
@ -52,7 +52,7 @@ init_worker_by_lua_block {
|
|||
logger:log(ERR, "can't get plugins order from datastore : " .. err)
|
||||
return
|
||||
end
|
||||
|
||||
|
||||
-- Call timer() methods
|
||||
logger:log(INFO, "calling timer() methods of plugins ...")
|
||||
for i, plugin_id in ipairs(order.timer) do
|
||||
|
|
|
|||
|
|
@ -1,21 +1,21 @@
|
|||
local cjson = require "cjson"
|
||||
local class = require "middleclass"
|
||||
local datastore = require "bunkerweb.datastore"
|
||||
local lrucache = require "resty.lrucache"
|
||||
local plugin = require "bunkerweb.plugin"
|
||||
local utils = require "bunkerweb.utils"
|
||||
local lrucache = require "resty.lrucache"
|
||||
|
||||
local metrics = class("metrics", plugin)
|
||||
local ngx = ngx
|
||||
local ERR = ngx.ERR
|
||||
|
||||
local lru, err_lru = lrucache.new(100000)
|
||||
if not lru then
|
||||
require "bunkerweb.logger":new("METRICS"):log(ERR, "failed to instantiate LRU cache : " .. err_lru)
|
||||
end
|
||||
|
||||
local ngx = ngx
|
||||
local shared = ngx.shared
|
||||
local subsystem = ngx.config.subsystem
|
||||
local ERR = ngx.ERR
|
||||
local HTTP_INTERNAL_SERVER_ERROR = ngx.HTTP_INTERNAL_SERVER_ERROR
|
||||
local HTTP_OK = ngx.HTTP_OK
|
||||
local worker = ngx.worker
|
||||
|
|
@ -94,13 +94,13 @@ function metrics:log(bypass_checks)
|
|||
local all_metrics = self.ctx.bw.metrics
|
||||
if all_metrics then
|
||||
-- Loop on plugins
|
||||
for plugin, plugin_metrics in pairs(all_metrics) do
|
||||
for plugin_id, plugin_metrics in pairs(all_metrics) do
|
||||
-- Loop on kinds
|
||||
for kind, kind_metrics in pairs(plugin_metrics) do
|
||||
-- Increment counters
|
||||
if kind == "counters" then
|
||||
for metric_key, metric_value in pairs(kind_metrics) do
|
||||
local lru_key = plugin .. "_counter_" .. metric_key
|
||||
local lru_key = plugin_id .. "_counter_" .. metric_key
|
||||
local metric_counter = lru:get(lru_key)
|
||||
if not metric_counter then
|
||||
metric_counter = metric_value
|
||||
|
|
@ -148,7 +148,8 @@ function metrics:timer()
|
|||
if not setup then
|
||||
for _, key in ipairs(self.metrics_datastore:keys()) do
|
||||
if key:match("_" .. wid .. "$") then
|
||||
local value, err = self.metrics_datastore:get(key)
|
||||
local value
|
||||
value, err = self.metrics_datastore:get(key)
|
||||
if not value and err ~= "not found" then
|
||||
ret = false
|
||||
ret_err = err
|
||||
|
|
@ -173,7 +174,8 @@ function metrics:timer()
|
|||
value = encode(value)
|
||||
end
|
||||
-- Push to dict
|
||||
local ok, err = self.metrics_datastore:set(key .. "_" .. wid, value)
|
||||
local ok
|
||||
ok, err = self.metrics_datastore:set(key .. "_" .. wid, value)
|
||||
if not ok then
|
||||
ret = false
|
||||
ret_err = err
|
||||
|
|
@ -217,8 +219,8 @@ function metrics:api()
|
|||
for _, metric_value in ipairs(data) do
|
||||
table_insert(metrics_data[metric_key], metric_value)
|
||||
end
|
||||
-- Counter case
|
||||
else
|
||||
-- Counter case
|
||||
if not metrics_data[metric_key] then
|
||||
metrics_data[metric_key] = 0
|
||||
end
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ local ngx = ngx
|
|||
local NOTICE = ngx.NOTICE
|
||||
local HTTP_INTERNAL_SERVER_ERROR = ngx.HTTP_INTERNAL_SERVER_ERROR
|
||||
local HTTP_OK = ngx.HTTP_OK
|
||||
local match = string.match
|
||||
|
||||
function redis:initialize(ctx)
|
||||
-- Call parent initialize
|
||||
|
|
@ -48,7 +47,11 @@ function redis:api()
|
|||
local ok, err = self.clusterstore:call("ping")
|
||||
self.clusterstore:close()
|
||||
if err then
|
||||
return self:ret(true, "error while sending ping command to redis server : " .. err, HTTP_INTERNAL_SERVER_ERROR)
|
||||
return self:ret(
|
||||
true,
|
||||
"error while sending ping command to redis server : " .. err,
|
||||
HTTP_INTERNAL_SERVER_ERROR
|
||||
)
|
||||
end
|
||||
if not ok then
|
||||
return self:ret(true, "redis ping command failed", HTTP_INTERNAL_SERVER_ERROR)
|
||||
|
|
@ -65,14 +68,18 @@ function redis:api()
|
|||
local nb_keys, err = self.clusterstore:call("dbsize")
|
||||
self.clusterstore:close()
|
||||
if err then
|
||||
return self:ret(true, "error while sending dbsize command to redis server : " .. err, HTTP_INTERNAL_SERVER_ERROR)
|
||||
return self:ret(
|
||||
true,
|
||||
"error while sending dbsize command to redis server : " .. err,
|
||||
HTTP_INTERNAL_SERVER_ERROR
|
||||
)
|
||||
end
|
||||
if not ok then
|
||||
return self:ret(true, "redis dbsize command failed", HTTP_INTERNAL_SERVER_ERROR)
|
||||
end
|
||||
-- Return data
|
||||
local data = {
|
||||
redis_nb_keys = nb_keys
|
||||
redis_nb_keys = nb_keys,
|
||||
}
|
||||
return self:ret(true, data, HTTP_OK)
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1486,7 +1486,7 @@ def logs_linux():
|
|||
error_type = (
|
||||
"error"
|
||||
if "[error]" in log_lower or "[crit]" in log_lower or "[alert]" in log_lower or "❌" in log_lower
|
||||
else ("warn" if "[warn]" in log_lower or "⚠️" in log_lower else ("info" if "[info]" in log_lower or "ℹ️" in log_lower else "message"))
|
||||
else (("warn" if "[warn]" in log_lower or "⚠️" in log_lower else ("info" if "[info]" in log_lower or "ℹ️" in log_lower else "message")))
|
||||
)
|
||||
|
||||
logs.append(
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
from copy import deepcopy
|
||||
from operator import itemgetter
|
||||
from os import sep
|
||||
from os.path import join
|
||||
from flask import flash
|
||||
|
|
@ -84,7 +85,7 @@ class Config:
|
|||
|
||||
def get_plugins(self, *, external: bool = False, with_data: bool = False) -> List[dict]:
|
||||
plugins = self.__db.get_plugins(external=external, with_data=with_data)
|
||||
plugins.sort(key=lambda x: x["name"])
|
||||
plugins.sort(key=itemgetter("name"))
|
||||
|
||||
general_plugin = None
|
||||
for plugin in plugins.copy():
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
#!/usr/bin/env python3
|
||||
from operator import itemgetter
|
||||
from os import sep
|
||||
from os.path import join
|
||||
from pathlib import Path
|
||||
|
|
@ -330,7 +331,7 @@ class Instances:
|
|||
continue
|
||||
bans.extend(instance_bans[instance.name if instance.name != "local" else "127.0.0.1"].get("data", []))
|
||||
|
||||
bans.sort(key=lambda x: x["exp"])
|
||||
bans.sort(key=itemgetter("exp"))
|
||||
|
||||
unique_bans = {}
|
||||
|
||||
|
|
@ -373,7 +374,7 @@ class Instances:
|
|||
continue
|
||||
reports.extend((instance_reports[instance.name if instance.name != "local" else "127.0.0.1"].get("msg") or {"requests": []})["requests"])
|
||||
|
||||
reports.sort(key=lambda x: x["date"], reverse=True)
|
||||
reports.sort(key=itemgetter("date"), reverse=True)
|
||||
|
||||
return reports
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue