mirror of
https://github.com/myronblair/novacpx
synced 2026-06-30 17:50:41 -05:00
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:
@@ -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 = [];
|
||||
|
||||
Reference in New Issue
Block a user