diff --git a/auth.php b/auth.php index 141e80c..45aa167 100644 --- a/auth.php +++ b/auth.php @@ -167,11 +167,11 @@ function sanitizeUsername($username) { } function getUserConfigPath($username) { - return USER_CONFIG_DIR . '/' . sanitizeUsername($username) . '-config.php'; + return USER_CONFIG_DIR . '/' . sanitizeUsername($username) . '-config.json'; } function getUserChatPath($username) { - return USER_CONFIG_DIR . '/' . sanitizeUsername($username) . '-chat.php'; + return USER_CONFIG_DIR . '/' . sanitizeUsername($username) . '-chat.json'; } function getConfiguredDefaultModel() { @@ -188,11 +188,30 @@ function getDefaultModelForUser($username) { function readUserConfig($username) { $path = getUserConfigPath($username); if (!file_exists($path)) { + // Try migrating from legacy PHP file if present + $legacy = USER_CONFIG_DIR . '/' . sanitizeUsername($username) . '-config.php'; + if (file_exists($legacy)) { + $raw = @file_get_contents($legacy); + if ($raw !== false) { + // attempt to include safely + $data = @include $legacy; + if (is_array($data)) { + // write JSON migration + writeUserConfig($username, $data); + return $data; + } + } + } + return []; + } + + $raw = @file_get_contents($path); + if ($raw === false) { return []; } - $data = include $path; - return is_array($data) ? $data : []; + $decoded = json_decode($raw, true); + return is_array($decoded) ? $decoded : []; } function writeUserConfig($username, $config) { @@ -202,7 +221,6 @@ function writeUserConfig($username, $config) { if ($username === '') { return false; } - $data = is_array($config) ? $config : []; $data['username'] = $username; $data['role'] = (string) ($data['role'] ?? 'user'); @@ -211,18 +229,41 @@ function writeUserConfig($username, $config) { $storedDefaultModel = trim((string) ($data['defaultModel'] ?? '')); $data['defaultModel'] = $storedDefaultModel !== '' ? $storedDefaultModel : getConfiguredDefaultModel(); - $php = "