From 38568a474b349d357649be407e0cab565e69f901 Mon Sep 17 00:00:00 2001 From: Niranjan Date: Tue, 7 Apr 2026 02:26:06 +0530 Subject: [PATCH] Initial YakPanel commit --- YakPanel-server/README.md | 4 +- YakPanel-server/backend/.env.example | 1 + YakPanel-server/backend/app/core/config.py | 2 +- YakPanel-server/backend/app/core/database.py | 49 +++++++++++++++----- YakPanel-server/install.sh | 5 +- 5 files changed, 44 insertions(+), 17 deletions(-) diff --git a/YakPanel-server/README.md b/YakPanel-server/README.md index fd08e625..ae2a8698 100644 --- a/YakPanel-server/README.md +++ b/YakPanel-server/README.md @@ -49,7 +49,7 @@ All native installs require **root**. Use `sudo -E ...` when you set environment | Variable | Meaning | Default | | --- | --- | --- | -| `REPO_URL` | Git URL to clone | `https://github.com/YakPanel/YakPanel.git` (optional: `https://source.yakpanel.com/yakpanel.git` when your mirror is live) | +| `REPO_URL` | Git URL to clone | `https://source.yakpanel.com/admin/yakpanel-core` (fallback: `https://github.com/YakPanel/YakPanel.git`) | | `YAKPANEL_BRANCH` | Branch/tag for shallow clone | default branch | | `GIT_REF` | Alias for `YAKPANEL_BRANCH` | — | | `INSTALL_PATH` | Install directory | `/www/server/YakPanel-server` | @@ -103,7 +103,7 @@ sudo bash scripts/install.sh Uses `docker-compose.yml` in this directory — **not** the same layout as native (no host Nginx unit from `install.sh`). ```bash -git clone --depth 1 https://github.com/YakPanel/YakPanel.git +git clone --depth 1 https://source.yakpanel.com/admin/yakpanel-core # Then cd to this folder (in the full monorepo it is under YakPanel-master/YakPanel-server). cd YakPanel-master/YakPanel-server docker compose up -d diff --git a/YakPanel-server/backend/.env.example b/YakPanel-server/backend/.env.example index e623e465..66a68fbe 100644 --- a/YakPanel-server/backend/.env.example +++ b/YakPanel-server/backend/.env.example @@ -1,5 +1,6 @@ # YakPanel - Environment SECRET_KEY=change-this-in-production +# Resolved against backend directory (see app/core/database.py), safe when CWD is not backend/ DATABASE_URL=sqlite+aiosqlite:///./data/default.db REDIS_URL=redis://localhost:6379/0 DEBUG=false diff --git a/YakPanel-server/backend/app/core/config.py b/YakPanel-server/backend/app/core/config.py index 10db5599..2b6c45fa 100644 --- a/YakPanel-server/backend/app/core/config.py +++ b/YakPanel-server/backend/app/core/config.py @@ -21,7 +21,7 @@ class Settings(BaseSettings): www_logs: str = "/www/wwwlogs" vhost_path: str = "/www/server/panel/vhost" - # Database (use absolute path for SQLite) + # Database (relative SQLite paths are resolved to backend/data/, not process CWD) database_url: str = "sqlite+aiosqlite:///./data/default.db" # Redis diff --git a/YakPanel-server/backend/app/core/database.py b/YakPanel-server/backend/app/core/database.py index f2546fa0..cb42b400 100644 --- a/YakPanel-server/backend/app/core/database.py +++ b/YakPanel-server/backend/app/core/database.py @@ -1,20 +1,36 @@ """YakPanel - Database configuration""" -import os -from sqlalchemy.ext.asyncio import create_async_engine, AsyncSession, async_sessionmaker +from pathlib import Path + +from sqlalchemy.engine.url import URL, make_url +from sqlalchemy.ext.asyncio import AsyncSession, async_sessionmaker, create_async_engine from sqlalchemy.orm import DeclarativeBase + from app.core.config import get_settings -settings = get_settings() +def _resolve_database_url(raw_url: str) -> str: + """Anchor relative SQLite paths to the backend directory (not process CWD).""" + url = make_url(raw_url) + if not url.drivername.startswith("sqlite"): + return raw_url + db_path = url.database + if db_path is None or db_path.startswith(":"): + return raw_url + path = Path(db_path) + backend_dir = Path(__file__).resolve().parent.parent + if not path.is_absolute(): + path = (backend_dir / path).resolve() + else: + path = path.resolve() + path.parent.mkdir(parents=True, exist_ok=True) + return str(URL.create(drivername=url.drivername, database=str(path))) -# Ensure data directory exists for SQLite -if "sqlite" in settings.database_url: - backend_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) - data_dir = os.path.join(backend_dir, "data") - os.makedirs(data_dir, exist_ok=True) + +settings = get_settings() +DATABASE_URL = _resolve_database_url(settings.database_url) engine = create_async_engine( - settings.database_url, + DATABASE_URL, echo=settings.debug, ) @@ -29,6 +45,7 @@ AsyncSessionLocal = async_sessionmaker( class Base(DeclarativeBase): """SQLAlchemy declarative base""" + pass @@ -48,13 +65,22 @@ async def get_db(): def _run_migrations(conn): """Add new columns to existing tables (SQLite).""" import sqlalchemy + try: r = conn.execute(sqlalchemy.text("PRAGMA table_info(sites)")) cols = [row[1] for row in r.fetchall()] if "php_version" not in cols: - conn.execute(sqlalchemy.text("ALTER TABLE sites ADD COLUMN php_version VARCHAR(16) DEFAULT '74'")) + conn.execute( + sqlalchemy.text( + "ALTER TABLE sites ADD COLUMN php_version VARCHAR(16) DEFAULT '74'" + ) + ) if "force_https" not in cols: - conn.execute(sqlalchemy.text("ALTER TABLE sites ADD COLUMN force_https INTEGER DEFAULT 0")) + conn.execute( + sqlalchemy.text( + "ALTER TABLE sites ADD COLUMN force_https INTEGER DEFAULT 0" + ) + ) except Exception: pass # Create backup_plans if not exists (create_all handles new installs) @@ -91,6 +117,7 @@ def _run_migrations(conn): async def init_db(): """Initialize database tables""" import app.models # noqa: F401 - register all models with Base.metadata + async with engine.begin() as conn: await conn.run_sync(Base.metadata.create_all) if "sqlite" in str(engine.url): diff --git a/YakPanel-server/install.sh b/YakPanel-server/install.sh index e1b2a345..6c3e3beb 100644 --- a/YakPanel-server/install.sh +++ b/YakPanel-server/install.sh @@ -9,7 +9,7 @@ # sudo -E bash install.sh # # Environment (optional): -# REPO_URL Git URL (default: public GitHub; use source.yakpanel.com when mirror is live) +# REPO_URL Git URL (default: https://source.yakpanel.com/admin/yakpanel-core) # YAKPANEL_BRANCH Branch/tag for shallow clone (default: default branch) # GIT_REF Alias for YAKPANEL_BRANCH # INSTALL_PATH Install dir (default: /www/server/YakPanel-server) @@ -209,8 +209,7 @@ else CLONE_ARGS+=("$REPO_URL" "$TMP_DIR/repo") if ! "${CLONE_ARGS[@]}"; then echo "Git clone failed. Check REPO_URL=$REPO_URL, DNS, and outbound HTTPS." - echo "Try: sudo -E env REPO_URL=https://github.com/YakPanel/YakPanel.git bash install.sh" - echo "Own mirror: REPO_URL=https://source.yakpanel.com/yakpanel.git (requires bare repo published; see HOSTING.txt)." + echo "Try public fallback: sudo -E env REPO_URL=https://github.com/YakPanel/YakPanel.git bash install.sh" exit 1 fi SRC_DIR="$(find_yakpanel_root_in_tree "$TMP_DIR/repo")"