mirror of
https://github.com/bunkerity/bunkerweb
synced 2026-05-24 09:28:37 +00:00
Merge branch 'dev' of github.com:bunkerity/bunkerweb into dev
This commit is contained in:
commit
7d0c638bc9
8 changed files with 91 additions and 107 deletions
|
|
@ -134,6 +134,8 @@ try:
|
|||
for first_server in skipped_servers:
|
||||
JOB.del_cache("cert.pem", service_id=first_server)
|
||||
JOB.del_cache("key.pem", service_id=first_server)
|
||||
except SystemExit as e:
|
||||
status = e.code
|
||||
except:
|
||||
status = 2
|
||||
LOGGER.error(f"Exception while running custom-cert.py :\n{format_exc()}")
|
||||
|
|
|
|||
|
|
@ -132,6 +132,8 @@ try:
|
|||
for first_server in skipped_servers:
|
||||
JOB.del_cache("cert.pem", service_id=first_server)
|
||||
JOB.del_cache("key.pem", service_id=first_server)
|
||||
except SystemExit as e:
|
||||
status = e.code
|
||||
except:
|
||||
status = 2
|
||||
LOGGER.error(f"Exception while running self-signed.py :\n{format_exc()}")
|
||||
|
|
|
|||
|
|
@ -1697,7 +1697,7 @@ class Database:
|
|||
}
|
||||
|
||||
def get_job_cache_file(
|
||||
self, job_name: str, file_name: str, *, service_id: str = "", with_info: bool = False, with_data: bool = True
|
||||
self, job_name: str, file_name: str, *, service_id: str = "", plugin_id: str = "", with_info: bool = False, with_data: bool = True
|
||||
) -> Optional[Union[Dict[str, Any], bytes]]:
|
||||
"""Get job cache file."""
|
||||
entities = []
|
||||
|
|
@ -1711,12 +1711,15 @@ class Database:
|
|||
filters["service_id"] = service_id
|
||||
|
||||
with self.__db_session() as session:
|
||||
if plugin_id:
|
||||
job = session.query(Jobs).filter_by(name=job_name, plugin_id=plugin_id).first()
|
||||
if not job:
|
||||
return None
|
||||
data = session.query(Jobs_cache).with_entities(*entities).filter_by(**filters).first()
|
||||
|
||||
if not data:
|
||||
return None
|
||||
|
||||
if with_data and not with_info:
|
||||
elif with_data and not with_info:
|
||||
return data.data
|
||||
|
||||
ret_data = {}
|
||||
|
|
@ -1727,7 +1730,7 @@ class Database:
|
|||
ret_data["data"] = data.data
|
||||
return ret_data
|
||||
|
||||
def get_jobs_cache_files(self, *, job_name: str = "", with_data: bool = False) -> List[Dict[str, Any]]:
|
||||
def get_jobs_cache_files(self, *, job_name: str = "", plugin_id: str = "", with_data: bool = False) -> List[Dict[str, Any]]:
|
||||
"""Get jobs cache files."""
|
||||
with self.__db_session() as session:
|
||||
entities = [Jobs_cache.job_name, Jobs_cache.service_id, Jobs_cache.file_name]
|
||||
|
|
@ -1739,15 +1742,33 @@ class Database:
|
|||
if job_name:
|
||||
query = query.filter_by(job_name=job_name)
|
||||
|
||||
return [
|
||||
{
|
||||
"job_name": cache.job_name,
|
||||
"service_id": cache.service_id,
|
||||
"file_name": cache.file_name,
|
||||
"data": "Download file to view content" if not with_data else cache.data,
|
||||
}
|
||||
for cache in query
|
||||
]
|
||||
db_cache = query.all()
|
||||
|
||||
if not db_cache:
|
||||
return []
|
||||
|
||||
job_names = []
|
||||
if plugin_id:
|
||||
filters = {"plugin_id": plugin_id}
|
||||
if job_name:
|
||||
filters["name"] = job_name
|
||||
job_names = [name for name in session.query(Jobs).with_entities(Jobs.name).filter_by(**filters)]
|
||||
if not job_names:
|
||||
return []
|
||||
|
||||
cache_files = []
|
||||
for cache in db_cache:
|
||||
if cache.job_name not in job_names:
|
||||
continue
|
||||
cache_files.append(
|
||||
{
|
||||
"job_name": cache.job_name,
|
||||
"service_id": cache.service_id,
|
||||
"file_name": cache.file_name,
|
||||
"data": "Download file to view content" if not with_data else cache.data,
|
||||
}
|
||||
)
|
||||
return cache_files
|
||||
|
||||
def add_instance(self, hostname: str, port: int, server_name: str, changed: Optional[bool] = True) -> str:
|
||||
"""Add instance."""
|
||||
|
|
|
|||
|
|
@ -72,11 +72,7 @@ class Settings(Base):
|
|||
|
||||
id = Column(String(256), primary_key=True)
|
||||
name = Column(String(256), primary_key=True)
|
||||
plugin_id = Column(
|
||||
String(64),
|
||||
ForeignKey("bw_plugins.id", onupdate="cascade", ondelete="cascade"),
|
||||
nullable=False,
|
||||
)
|
||||
plugin_id = Column(String(64), ForeignKey("bw_plugins.id", onupdate="cascade", ondelete="cascade"), nullable=False)
|
||||
context = Column(CONTEXTS_ENUM, nullable=False)
|
||||
default = Column(String(4096), nullable=True, default="")
|
||||
help = Column(String(512), nullable=False)
|
||||
|
|
@ -94,11 +90,7 @@ class Settings(Base):
|
|||
class Global_values(Base):
|
||||
__tablename__ = "bw_global_values"
|
||||
|
||||
setting_id = Column(
|
||||
String(256),
|
||||
ForeignKey("bw_settings.id", onupdate="cascade", ondelete="cascade"),
|
||||
primary_key=True,
|
||||
)
|
||||
setting_id = Column(String(256), ForeignKey("bw_settings.id", onupdate="cascade", ondelete="cascade"), primary_key=True)
|
||||
value = Column(String(8192), nullable=False)
|
||||
suffix = Column(Integer, primary_key=True, nullable=True, default=0)
|
||||
method = Column(METHODS_ENUM, nullable=False)
|
||||
|
|
@ -121,16 +113,8 @@ class Services(Base):
|
|||
class Services_settings(Base):
|
||||
__tablename__ = "bw_services_settings"
|
||||
|
||||
service_id = Column(
|
||||
String(64),
|
||||
ForeignKey("bw_services.id", onupdate="cascade", ondelete="cascade"),
|
||||
primary_key=True,
|
||||
)
|
||||
setting_id = Column(
|
||||
String(256),
|
||||
ForeignKey("bw_settings.id", onupdate="cascade", ondelete="cascade"),
|
||||
primary_key=True,
|
||||
)
|
||||
service_id = Column(String(64), ForeignKey("bw_services.id", onupdate="cascade", ondelete="cascade"), primary_key=True)
|
||||
setting_id = Column(String(256), ForeignKey("bw_settings.id", onupdate="cascade", ondelete="cascade"), primary_key=True)
|
||||
value = Column(String(8192), nullable=False)
|
||||
suffix = Column(Integer, primary_key=True, nullable=True, default=0)
|
||||
method = Column(METHODS_ENUM, nullable=False)
|
||||
|
|
@ -144,10 +128,7 @@ class Jobs(Base):
|
|||
__table_args__ = (UniqueConstraint("name", "plugin_id"),)
|
||||
|
||||
name = Column(String(128), primary_key=True)
|
||||
plugin_id = Column(
|
||||
String(64),
|
||||
ForeignKey("bw_plugins.id", onupdate="cascade", ondelete="cascade"),
|
||||
)
|
||||
plugin_id = Column(String(64), ForeignKey("bw_plugins.id", onupdate="cascade", ondelete="cascade"))
|
||||
file_name = Column(String(256), nullable=False)
|
||||
every = Column(SCHEDULES_ENUM, nullable=False)
|
||||
reload = Column(Boolean, default=False, nullable=False)
|
||||
|
|
@ -161,16 +142,8 @@ class Jobs(Base):
|
|||
class Plugin_pages(Base):
|
||||
__tablename__ = "bw_plugin_pages"
|
||||
|
||||
id = Column(
|
||||
Integer,
|
||||
Identity(start=1, increment=1),
|
||||
primary_key=True,
|
||||
)
|
||||
plugin_id = Column(
|
||||
String(64),
|
||||
ForeignKey("bw_plugins.id", onupdate="cascade", ondelete="cascade"),
|
||||
nullable=False,
|
||||
)
|
||||
id = Column(Integer, Identity(start=1, increment=1), primary_key=True)
|
||||
plugin_id = Column(String(64), ForeignKey("bw_plugins.id", onupdate="cascade", ondelete="cascade"), nullable=False)
|
||||
template_file = Column(LargeBinary(length=(2**32) - 1), nullable=False)
|
||||
template_checksum = Column(String(128), nullable=False)
|
||||
actions_file = Column(LargeBinary(length=(2**32) - 1), nullable=False)
|
||||
|
|
@ -181,27 +154,11 @@ class Plugin_pages(Base):
|
|||
|
||||
class Jobs_cache(Base):
|
||||
__tablename__ = "bw_jobs_cache"
|
||||
__table_args__ = (UniqueConstraint("job_name", "service_id", "file_name"),)
|
||||
|
||||
id = Column(
|
||||
Integer,
|
||||
Identity(start=1, increment=1),
|
||||
primary_key=True,
|
||||
)
|
||||
job_name = Column(
|
||||
String(128),
|
||||
ForeignKey("bw_jobs.name", onupdate="cascade", ondelete="cascade"),
|
||||
nullable=False,
|
||||
)
|
||||
service_id = Column(
|
||||
String(64),
|
||||
ForeignKey("bw_services.id", onupdate="cascade", ondelete="cascade"),
|
||||
nullable=True,
|
||||
)
|
||||
file_name = Column(
|
||||
String(256),
|
||||
nullable=False,
|
||||
)
|
||||
id = Column(Integer, Identity(start=1, increment=1), primary_key=True)
|
||||
job_name = Column(String(128), ForeignKey("bw_jobs.name", onupdate="cascade", ondelete="cascade"), nullable=False)
|
||||
service_id = Column(String(64), ForeignKey("bw_services.id", onupdate="cascade", ondelete="cascade"), nullable=True)
|
||||
file_name = Column(String(256), nullable=False)
|
||||
data = Column(LargeBinary(length=(2**32) - 1), nullable=True)
|
||||
last_update = Column(DateTime, nullable=True)
|
||||
checksum = Column(String(128), nullable=True)
|
||||
|
|
@ -214,16 +171,8 @@ class Custom_configs(Base):
|
|||
__tablename__ = "bw_custom_configs"
|
||||
__table_args__ = (UniqueConstraint("service_id", "type", "name"),)
|
||||
|
||||
id = Column(
|
||||
Integer,
|
||||
Identity(start=1, increment=1),
|
||||
primary_key=True,
|
||||
)
|
||||
service_id = Column(
|
||||
String(64),
|
||||
ForeignKey("bw_services.id", onupdate="cascade", ondelete="cascade"),
|
||||
nullable=True,
|
||||
)
|
||||
id = Column(Integer, Identity(start=1, increment=1), primary_key=True)
|
||||
service_id = Column(String(64), ForeignKey("bw_services.id", onupdate="cascade", ondelete="cascade"), nullable=True)
|
||||
type = Column(CUSTOM_CONFIGS_TYPES_ENUM, nullable=False)
|
||||
name = Column(String(256), nullable=False)
|
||||
data = Column(LargeBinary(length=(2**32) - 1), nullable=False)
|
||||
|
|
@ -236,11 +185,7 @@ class Custom_configs(Base):
|
|||
class Selects(Base):
|
||||
__tablename__ = "bw_selects"
|
||||
|
||||
setting_id = Column(
|
||||
String(256),
|
||||
ForeignKey("bw_settings.id", onupdate="cascade", ondelete="cascade"),
|
||||
primary_key=True,
|
||||
)
|
||||
setting_id = Column(String(256), ForeignKey("bw_settings.id", onupdate="cascade", ondelete="cascade"), primary_key=True)
|
||||
value = Column(String(256), primary_key=True)
|
||||
|
||||
setting = relationship("Settings", back_populates="selects")
|
||||
|
|
|
|||
|
|
@ -47,11 +47,11 @@ class Job:
|
|||
if not deprecated:
|
||||
self.restore_cache()
|
||||
|
||||
def restore_cache(self, *, job_name: str = "") -> bool:
|
||||
def restore_cache(self, *, job_name: str = "", plugin_id: str = "") -> bool:
|
||||
"""Restore job cache files from database."""
|
||||
ret = True
|
||||
with LOCK:
|
||||
job_cache_files = self.db.get_jobs_cache_files(job_name=job_name or self.job_name, with_data=True) # type: ignore
|
||||
job_cache_files = self.db.get_jobs_cache_files(job_name=job_name or self.job_name, plugin_id=plugin_id or self.job_path.name, with_data=True) # type: ignore
|
||||
|
||||
for job_cache_file in job_cache_files:
|
||||
try:
|
||||
|
|
@ -71,7 +71,7 @@ class Job:
|
|||
return ret
|
||||
|
||||
def get_cache(
|
||||
self, name: str, *, job_name: str = "", service_id: str = "", with_info: bool = False, with_data: bool = True
|
||||
self, name: str, *, job_name: str = "", service_id: str = "", plugin_id: str = "", with_info: bool = False, with_data: bool = True
|
||||
) -> Optional[Union[Dict[str, Any], bytes]]:
|
||||
"""Get cache file from database or from local cache file."""
|
||||
cache_path = self.job_path.joinpath(service_id, name)
|
||||
|
|
@ -84,15 +84,17 @@ class Job:
|
|||
|
||||
with LOCK:
|
||||
if not ret_data:
|
||||
return self.db.get_job_cache_file(job_name or self.job_name, name, service_id=service_id, with_info=with_info, with_data=with_data) # type: ignore
|
||||
ret_data.update(self.db.get_job_cache_file(job_name or self.job_name, name, service_id=service_id, with_info=True, with_data=False)) # type: ignore
|
||||
return self.db.get_job_cache_file(job_name or self.job_name, name, service_id=service_id, plugin_id=plugin_id or self.job_path.name, with_info=with_info, with_data=with_data) # type: ignore
|
||||
ret_data.update(self.db.get_job_cache_file(job_name or self.job_name, name, service_id=service_id, plugin_id=plugin_id or self.job_path.name, with_info=True, with_data=False)) # type: ignore
|
||||
return ret_data
|
||||
|
||||
def is_cached_file(self, name: str, expire: Literal["hour", "day", "week", "month"], *, job_name: str = "", service_id: str = "") -> bool:
|
||||
def is_cached_file(
|
||||
self, name: str, expire: Literal["hour", "day", "week", "month"], *, job_name: str = "", service_id: str = "", plugin_id: str = ""
|
||||
) -> bool:
|
||||
"""Check if cache file is cached and if it's still fresh."""
|
||||
is_cached = False
|
||||
try:
|
||||
cache_info = self.get_cache(name, job_name=job_name, service_id=service_id, with_info=True, with_data=False)
|
||||
cache_info = self.get_cache(name, job_name=job_name, service_id=service_id, plugin_id=plugin_id, with_info=True, with_data=False)
|
||||
if isinstance(cache_info, dict):
|
||||
current_time = datetime.now().timestamp()
|
||||
if current_time < cache_info["last_update"]:
|
||||
|
|
@ -178,13 +180,13 @@ class Job:
|
|||
return False, f"exception :\n{format_exc()}"
|
||||
return ret, err
|
||||
|
||||
def cache_hash(self, name: str, *, job_name: str = "", service_id: str = "") -> Optional[str]:
|
||||
def cache_hash(self, name: str, *, job_name: str = "", service_id: str = "", plugin_id: str = "") -> Optional[str]:
|
||||
"""Get cache file hash from database or from local cache file."""
|
||||
cache_path = self.job_path.joinpath(service_id, name)
|
||||
if cache_path.is_file():
|
||||
return file_hash(cache_path)
|
||||
|
||||
cache_info = self.get_cache(name, with_info=True, with_data=False, job_name=job_name, service_id=service_id)
|
||||
cache_info = self.get_cache(name, with_info=True, with_data=False, job_name=job_name, service_id=service_id, plugin_id=plugin_id)
|
||||
|
||||
if isinstance(cache_info, dict):
|
||||
return cache_info.get("checksum")
|
||||
|
|
|
|||
|
|
@ -446,7 +446,7 @@ def check():
|
|||
if "Origin" not in request.headers:
|
||||
return Response(status=403)
|
||||
|
||||
return Response(status=200, headers={"Access-Control-Allow-Origin": "*"})
|
||||
return Response(status=200, headers={"Access-Control-Allow-Origin": "*"}, response=dumps({"message": "ok"}), content_type="application/json")
|
||||
|
||||
|
||||
@app.route("/setup", methods=["GET", "POST"])
|
||||
|
|
|
|||
40
src/ui/templates/setup.html
vendored
40
src/ui/templates/setup.html
vendored
|
|
@ -185,16 +185,9 @@
|
|||
value="" />
|
||||
</div>
|
||||
<!-- auto privacy policy-->
|
||||
<div class="flex flex-col relative col-span-12 my-3 mx-2 max-w-[400px] w-full">
|
||||
<h5 class="text-base my-1 transition duration-300 ease-in-out text-md font-bold m-0">
|
||||
I've read and agree to the
|
||||
<a class="privacy-link"
|
||||
href="https://www.bunkerity.com/privacy-policy/?utm_campaign=self&utm_source=ui"
|
||||
target="_blank"
|
||||
rel="noopener">privacy policy</a>
|
||||
</h5>
|
||||
<label class="sr-only" for="newsletter-check">privacy policy</label>
|
||||
<div data-checkbox-handler="newsletter-check"
|
||||
<div class="flex relative col-span-12 my-3 mx-2 max-w-[400px] w-full">
|
||||
<label class="sr-only" for="newsletter-check">privacy policy</label>
|
||||
<div data-checkbox-handler="newsletter-check"
|
||||
class="relative mb-7 md:mb-0 z-10">
|
||||
<input data-check
|
||||
type="checkbox"
|
||||
|
|
@ -207,10 +200,17 @@
|
|||
class="pointer-events-none absolute fill-white left-0 top-0 translate-x-1 translate-y-2 h-3 w-3"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
viewBox="0 0 512 512">
|
||||
<path class="pointer-events-none" d="M470.6 105.4c12.5 12.5 12.5 32.8 0 45.3l-256 256c-12.5 12.5-32.8 12.5-45.3 0l-128-128c-12.5-12.5-12.5-32.8 0-45.3s32.8-12.5 45.3 0L192 338.7 425.4 105.4c12.5-12.5 32.8-12.5 45.3 0z">
|
||||
<path class="pointer-events-none" d="M470.6 105.4c12.5 12.5 12.5 32.8 0 45.3l-256 256c-12.5 12.5-32.8 12.5-45.3 0l-128-128c-12.5-12.5-12.5-32.8 0-45.3s32.8-12.5 45.3 0L192 338.7 425.4 105.4c12.5-12.5 32.8-12.5 45.3 0z">
|
||||
</path>
|
||||
</svg>
|
||||
</div>
|
||||
</svg>
|
||||
</div>
|
||||
<h5 class="text-base mt-1 transition duration-300 ease-in-out text-md font-bold m-0 ml-2">
|
||||
I've read and agree to the
|
||||
<a class="privacy-link"
|
||||
href="https://www.bunkerity.com/privacy-policy/?utm_campaign=self&utm_source=ui"
|
||||
target="_blank"
|
||||
rel="noopener">privacy policy</a>
|
||||
</h5>
|
||||
</div>
|
||||
<!-- end auto privacy policy-->
|
||||
<!-- end email inpt-->
|
||||
|
|
@ -348,7 +348,19 @@
|
|||
}://${this.servInp.value}/setup/check`;
|
||||
fetch(api)
|
||||
.then((res) => {
|
||||
this.updateCheck("success");
|
||||
// check if status 200 and body = {"message" : "ok"}
|
||||
if (res.status === 200) {
|
||||
return res.json();
|
||||
} else {
|
||||
this.updateCheck("error");
|
||||
}
|
||||
}).then(res => {
|
||||
// check message
|
||||
if (res.message === "ok") {
|
||||
this.updateCheck("success");
|
||||
} else {
|
||||
this.updateCheck("error");
|
||||
}
|
||||
})
|
||||
.catch((err) => {
|
||||
this.updateCheck("error");
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ try:
|
|||
|
||||
assert_button_click(DRIVER, "//div[@data-cache-element='mmdb-asn/asn.mmdb']")
|
||||
|
||||
file_content_elem = safe_get_element(DRIVER, By.XPATH, "//div[@data-cache-modal-editor='']/div[@class='ace_scroller']//div[@class='ace_line']")
|
||||
file_content_elem = safe_get_element(DRIVER, By.XPATH, "//div[@data-cache-modal-editor='']/div[@class='ace_scroller']//div[@class='ace_content']")
|
||||
assert isinstance(file_content_elem, WebElement), "The file content element is not an instance of WebElement"
|
||||
if file_content_elem.text.strip() != "Download file to view content":
|
||||
log_exception("The cache file content is not correct, exiting ...")
|
||||
|
|
|
|||
Loading…
Reference in a new issue