Migrate panel DB from MySQL to SQLite

Panel no longer depends on the user-managed MariaDB service.
SQLite at /var/lib/novacpx/panel.db runs independently so the
control panel stays up even when MariaDB is stopped.

- DB.php: switch to sqlite: DSN, add SQL translator (ON DUPLICATE KEY,
  DATE_ADD/DATE_SUB INTERVAL, NOW(), UNIX_TIMESTAMP(), IFNULL)
- Core.php: replace DB_HOST/NAME/USER/PASS with DB_PATH constant
- schema.sql: full SQLite syntax, add TOTP columns to users table
- _branding.php: use sqlite: PDO, datetime('now') for session check
- install.sh: apt install sqlite3, create SQLite DB instead of MySQL DB
- tools/migrate-to-sqlite.sh: one-shot migration script for existing installs
This commit is contained in:
2026-06-09 14:52:02 +00:00
parent 9bd78a81ea
commit fbc445dad2
5 changed files with 713 additions and 335 deletions
+3 -3
View File
@@ -9,15 +9,15 @@ function novacpx_get_branding(): array {
$cfg = @parse_ini_file('/etc/novacpx/config.ini', true);
if (!$cfg) return $cache = [];
try {
$dbPath = $cfg['database']['path'] ?? '/var/lib/novacpx/panel.db';
$pdo = new PDO(
"mysql:host={$cfg['database']['host']};dbname={$cfg['database']['name']};charset=utf8mb4",
$cfg['database']['user'], $cfg['database']['pass'],
"sqlite:{$dbPath}", null, null,
[PDO::ATTR_ERRMODE => PDO::ERRMODE_SILENT, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC]
);
$token = $_COOKIE['ncpx_session'] ?? '';
if (!$token || strlen($token) < 32) return $cache = [];
$stmt = $pdo->prepare("SELECT user_id FROM sessions WHERE token = ? AND expires_at > NOW() LIMIT 1");
$stmt = $pdo->prepare("SELECT user_id FROM sessions WHERE token = ? AND expires_at > datetime('now') LIMIT 1");
$stmt->execute([substr($token, 0, 128)]);
$uid = (int)($stmt->fetchColumn() ?: 0);
if (!$uid) return $cache = [];