mirror of
https://github.com/bunkerity/bunkerweb
synced 2026-05-24 09:28:37 +00:00
chore: Ignore invalid regex checks in Configurator and Config classes + add a log
This commit is contained in:
parent
ccaef7e90a
commit
a36f9aa453
2 changed files with 21 additions and 8 deletions
|
|
@ -8,7 +8,7 @@ from logging import Logger
|
|||
from os import cpu_count, listdir, sep
|
||||
from os.path import basename, dirname, join
|
||||
from pathlib import Path
|
||||
from re import compile as re_compile, search as re_search
|
||||
from re import compile as re_compile, error as RegexError, search as re_search
|
||||
from sys import path as sys_path
|
||||
from tarfile import open as tar_open
|
||||
from threading import Lock, Semaphore, Thread
|
||||
|
|
@ -229,8 +229,13 @@ class Configurator:
|
|||
where, real_var = self.__find_var(variable)
|
||||
if not where:
|
||||
return False, f"variable name {variable} doesn't exist"
|
||||
elif not re_search(where[real_var]["regex"], value):
|
||||
return (False, f"value {value} doesn't match regex {where[real_var]['regex']}")
|
||||
|
||||
try:
|
||||
if not re_search(where[real_var]["regex"], value):
|
||||
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")
|
||||
|
||||
return True, "ok"
|
||||
# MULTISITE=yes
|
||||
prefixed, real_var = self.__var_is_prefixed(variable)
|
||||
|
|
@ -239,8 +244,13 @@ class Configurator:
|
|||
return False, f"variable name {variable} doesn't exist"
|
||||
elif prefixed and where[real_var]["context"] != "multisite":
|
||||
return False, f"context of {variable} isn't multisite"
|
||||
elif not re_search(where[real_var]["regex"], value):
|
||||
return (False, f"value {value} doesn't match regex {where[real_var]['regex']}")
|
||||
|
||||
try:
|
||||
if not re_search(where[real_var]["regex"], value):
|
||||
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")
|
||||
|
||||
return True, "ok"
|
||||
|
||||
def __find_var(self, variable: str) -> Tuple[Optional[Dict[str, Any]], str]:
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ from os import sep
|
|||
from flask import flash
|
||||
from json import loads as json_loads
|
||||
from pathlib import Path
|
||||
from re import search as re_search
|
||||
from re import error as RegexError, search as re_search
|
||||
from typing import List, Literal, Optional, Tuple
|
||||
|
||||
|
||||
|
|
@ -126,8 +126,11 @@ class Config:
|
|||
flash(f"Variable {k} is not valid.", "error")
|
||||
continue
|
||||
|
||||
if re_search(plugins_settings[setting]["regex"], v):
|
||||
check = True
|
||||
try:
|
||||
if re_search(plugins_settings[setting]["regex"], v):
|
||||
check = True
|
||||
except RegexError:
|
||||
self.__db.logger.warning(f"Invalid regex for setting {setting} : {plugins_settings[setting]['regex']}, ignoring regex check")
|
||||
|
||||
if not check:
|
||||
error = 1
|
||||
|
|
|
|||
Loading…
Reference in a new issue