Fix file manager always use the database now + create log file for UI if not exists
This commit is contained in:
parent
47ccd9f047
commit
34d12cd552
|
@ -66,6 +66,10 @@ from utils import (
|
|||
from logger import setup_logger
|
||||
from Database import Database
|
||||
|
||||
if not exists("/var/log/nginx/ui.log"):
|
||||
Path("/var/log/nginx").mkdir(parents=True, exist_ok=True)
|
||||
Path("/var/log/nginx/ui.log").touch()
|
||||
|
||||
logger = setup_logger("UI", getenv("LOG_LEVEL", "INFO"))
|
||||
|
||||
|
||||
|
@ -682,7 +686,6 @@ def configs():
|
|||
path_to_dict(
|
||||
"/etc/bunkerweb/configs",
|
||||
db_data=db.get_custom_configs(),
|
||||
integration=integration,
|
||||
services=app.config["CONFIG"]
|
||||
.get_config(methods=False)["SERVER_NAME"]
|
||||
.split(" "),
|
||||
|
@ -1325,8 +1328,8 @@ def cache():
|
|||
folders=[
|
||||
path_to_dict(
|
||||
"/var/cache/bunkerweb",
|
||||
is_cache=True,
|
||||
db_data=db.get_jobs_cache_files(),
|
||||
integration=integration,
|
||||
services=app.config["CONFIG"]
|
||||
.get_config(methods=False)["SERVER_NAME"]
|
||||
.split(" "),
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
Flask==2.2.2
|
||||
Flask_Cors==3.0.10
|
||||
Flask_Login==0.6.2
|
||||
Flask_WTF==1.1.1
|
||||
beautifulsoup4==4.11.2
|
||||
python_dateutil==2.8.2
|
||||
python-magic==0.4.27
|
||||
bcrypt==4.0.1
|
||||
gunicorn==20.1.0
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
from datetime import datetime
|
||||
from typing import List
|
||||
import magic
|
||||
import os
|
||||
|
||||
|
||||
|
@ -20,80 +18,14 @@ def get_variables():
|
|||
return vars
|
||||
|
||||
|
||||
def log(event):
|
||||
with open("/var/log/nginx/ui.log", "a") as f:
|
||||
f.write("[" + str(datetime.now().replace(microsecond=0)) + "] " + event + "\n")
|
||||
|
||||
|
||||
def path_to_dict(
|
||||
path,
|
||||
*,
|
||||
level: int = 0,
|
||||
is_cache: bool = False,
|
||||
db_data: List[dict] = [],
|
||||
integration: str = "Linux",
|
||||
services: List[str] = [],
|
||||
) -> dict:
|
||||
if integration == "Linux":
|
||||
d = {"name": os.path.basename(path)}
|
||||
|
||||
if os.path.isdir(path):
|
||||
d.update(
|
||||
{
|
||||
"type": "folder",
|
||||
"path": path,
|
||||
"can_create_files": level > 0 and not is_cache,
|
||||
"can_create_folders": level > 0 and not is_cache,
|
||||
"can_edit": level > 1 and not is_cache,
|
||||
"can_delete": False,
|
||||
"children": [
|
||||
path_to_dict(
|
||||
os.path.join(path, x),
|
||||
level=level + 1,
|
||||
is_cache=is_cache,
|
||||
db_data=db_data,
|
||||
)
|
||||
for x in sorted(os.listdir(path))
|
||||
],
|
||||
}
|
||||
)
|
||||
|
||||
if level > 1 and not is_cache and not d["children"]:
|
||||
d["can_delete"] = True
|
||||
else:
|
||||
d.update(
|
||||
{
|
||||
"type": "file",
|
||||
"path": path,
|
||||
"can_download": True,
|
||||
}
|
||||
)
|
||||
|
||||
can_edit = False
|
||||
if level > 1 and not is_cache:
|
||||
exploded_path = path.split("/")
|
||||
for conf in db_data:
|
||||
if exploded_path[-1].replace(".conf", "") == conf["name"]:
|
||||
if level > 2 and exploded_path[-2] != conf["service_id"]:
|
||||
continue
|
||||
|
||||
can_edit = True
|
||||
break
|
||||
|
||||
d["can_edit"] = can_edit
|
||||
|
||||
magic_file = magic.from_file(path, mime=True)
|
||||
|
||||
if (
|
||||
not is_cache
|
||||
or magic_file.startswith("text/")
|
||||
or magic_file.startswith("application/json")
|
||||
):
|
||||
with open(path, "rb") as f:
|
||||
d["content"] = f.read().decode("utf-8")
|
||||
else:
|
||||
d["content"] = "Download file to view content"
|
||||
elif path.startswith("/etc/bunkerweb/configs"):
|
||||
if not is_cache:
|
||||
config_types = [
|
||||
"http",
|
||||
"stream",
|
||||
|
|
Loading…
Reference in New Issue