new changes
This commit is contained in:
Binary file not shown.
@@ -7,7 +7,7 @@ from sqlalchemy import select
|
||||
|
||||
from app.models.site import Site, Domain
|
||||
from app.models.redirect import SiteRedirect
|
||||
from app.core.config import get_runtime_config
|
||||
from app.core.config import get_runtime_config, get_settings
|
||||
from app.core.utils import path_safe_check, write_file, read_file, exec_shell_sync
|
||||
|
||||
|
||||
@@ -17,6 +17,37 @@ LETSENCRYPT_LIVE = "/etc/letsencrypt/live"
|
||||
SSL_EXPIRING_DAYS = 14
|
||||
|
||||
|
||||
def _nginx_site_template_path() -> str | None:
|
||||
"""
|
||||
Resolve webserver/templates/nginx_site.conf.
|
||||
Order: YAKPANEL_NGINX_TEMPLATE env, repo root (parent of backend/), Settings.panel_path.
|
||||
"""
|
||||
candidates: list[str] = []
|
||||
env_override = (os.environ.get("YAKPANEL_NGINX_TEMPLATE") or "").strip()
|
||||
if env_override:
|
||||
candidates.append(env_override)
|
||||
# site_service.py -> services -> app -> backend -> YakPanel-server (repo root)
|
||||
here = os.path.abspath(__file__)
|
||||
repo_root = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(here))))
|
||||
candidates.append(os.path.join(repo_root, "webserver", "templates", "nginx_site.conf"))
|
||||
try:
|
||||
s = get_settings()
|
||||
pp = (s.panel_path or "").strip()
|
||||
if pp:
|
||||
candidates.append(os.path.join(os.path.abspath(pp), "webserver", "templates", "nginx_site.conf"))
|
||||
sp = (s.setup_path or "").strip()
|
||||
if sp:
|
||||
candidates.append(
|
||||
os.path.join(os.path.abspath(sp), "YakPanel-server", "webserver", "templates", "nginx_site.conf")
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
for path in candidates:
|
||||
if path and os.path.isfile(path):
|
||||
return path
|
||||
return None
|
||||
|
||||
|
||||
def _backup_count(site_name: str, backup_dir: str) -> int:
|
||||
if not backup_dir or not os.path.isdir(backup_dir):
|
||||
return 0
|
||||
@@ -415,9 +446,8 @@ async def update_site(
|
||||
cfg = get_runtime_config()
|
||||
vhost_path = os.path.join(cfg["setup_path"], "panel", "vhost", "nginx")
|
||||
conf_path = os.path.join(vhost_path, f"{site.name}.conf")
|
||||
panel_root = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
template_path = os.path.join(panel_root, "webserver", "templates", "nginx_site.conf")
|
||||
if os.path.exists(template_path):
|
||||
template_path = _nginx_site_template_path()
|
||||
if template_path:
|
||||
template = read_file(template_path) or ""
|
||||
domain_result = await db.execute(select(Domain).where(Domain.pid == site.id))
|
||||
domain_rows = domain_result.scalars().all()
|
||||
@@ -492,10 +522,13 @@ async def regenerate_site_vhost(db: AsyncSession, site_id: int) -> dict:
|
||||
write_path = conf_path
|
||||
else:
|
||||
write_path = disabled_path if os.path.isfile(disabled_path) else conf_path
|
||||
panel_root = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
template_path = os.path.join(panel_root, "webserver", "templates", "nginx_site.conf")
|
||||
if not os.path.exists(template_path):
|
||||
return {"status": False, "msg": "Template not found"}
|
||||
template_path = _nginx_site_template_path()
|
||||
if not template_path:
|
||||
return {
|
||||
"status": False,
|
||||
"msg": "Template not found (nginx_site.conf). Expected under panel webserver/templates/ "
|
||||
"or set env YAKPANEL_NGINX_TEMPLATE to the full path. Check Settings.panel_path matches the install directory.",
|
||||
}
|
||||
template = read_file(template_path) or ""
|
||||
domain_result = await db.execute(select(Domain).where(Domain.pid == site.id))
|
||||
domain_rows = domain_result.scalars().all()
|
||||
|
||||
Reference in New Issue
Block a user