From 461921b7bc03a2718335cdb45eed7ff87d8c1d28 Mon Sep 17 00:00:00 2001 From: Ryan Date: Fri, 18 Apr 2025 00:40:17 -0400 Subject: [PATCH] Remember me adjustment --- .github/workflows/sync-changelog.yml | 39 ++++++ README.md | 4 +- config/config.php | 180 ++++++++++++--------------- src/controllers/authController.php | 3 +- 4 files changed, 122 insertions(+), 104 deletions(-) create mode 100644 .github/workflows/sync-changelog.yml diff --git a/.github/workflows/sync-changelog.yml b/.github/workflows/sync-changelog.yml new file mode 100644 index 0000000..e4fc40b --- /dev/null +++ b/.github/workflows/sync-changelog.yml @@ -0,0 +1,39 @@ +name: Sync CHANGELOG to Docker Repo + +on: + push: + paths: + - 'CHANGELOG.md' + +jobs: + sync: + runs-on: ubuntu-latest + steps: + - name: Checkout FileRise + uses: actions/checkout@v4 + with: + path: file-rise + + - name: Checkout filerise-docker + uses: actions/checkout@v4 + with: + repository: error311/filerise-docker + token: ${{ secrets.PAT_TOKEN }} + path: docker-repo + + - name: Copy CHANGELOG.md + run: | + cp file-rise/CHANGELOG.md docker-repo/CHANGELOG.md + + - name: Commit & push + working-directory: docker-repo + run: | + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + if git diff --quiet; then + echo "No changes to commit" + else + git add CHANGELOG.md + git commit -m "chore: sync CHANGELOG from FileRise" + git push origin main + fi \ No newline at end of file diff --git a/README.md b/README.md index c2c9090..57e26dc 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ Upload, organize, and share files through a sleek web interface. **FileRise** is - 🎨 **Responsive UI (Dark/Light Mode):** FileRise is mobile-friendly out of the box – manage files from your phone or tablet with a responsive layout. Choose between Dark mode or Light theme, or let it follow your system preference. The interface remembers your preferences (layout, items per page, last visited folder, etc.) for a personalized experience each time. -- 🌐 **Internationalization & Localization:** FileRise supports multiple languages via an integrated i18n system. Users can switch languages through a user panel dropdown, and their choice is saved in local storage for a consistent experience across sessions. Currently available in English, Spanish, and French—please report any translation issues you encounter. +- 🌐 **Internationalization & Localization:** FileRise supports multiple languages via an integrated i18n system. Users can switch languages through a user panel dropdown, and their choice is saved in local storage for a consistent experience across sessions. Currently available in English, Spanish, French & German—please report any translation issues you encounter. - 🗑️ **Trash & File Recovery:** Mistakenly deleted files? No worries – deleted items go to the Trash instead of immediate removal. Admins can restore files from Trash or empty it to free space. FileRise auto-purges old trash entries (default 3 days) to keep your storage tidy. @@ -60,8 +60,6 @@ If you have Docker installed, you can get FileRise up and running in minutes: docker pull error311/filerise-docker:latest ``` -*(For Apple Silicon (M1/M2) users, use --platform linux/amd64 tag until multi-arch support is added.)* - - **Run a container:** ``` bash diff --git a/config/config.php b/config/config.php index 060b585..7dfd828 100644 --- a/config/config.php +++ b/config/config.php @@ -1,73 +1,61 @@ 7200, +// Choose session lifetime based on "remember me" cookie +$defaultSession = 7200; // 2 hours +$persistentDays = 30 * 24 * 60 * 60; // 30 days +$sessionLifetime = isset($_COOKIE['remember_me_token']) + ? $persistentDays + : $defaultSession; + +// Configure PHP session cookie and GC +session_set_cookie_params([ + 'lifetime' => $sessionLifetime, 'path' => '/', - 'domain' => '', // Set your domain as needed. + 'domain' => '', // adjust if you need a specific domain 'secure' => $secure, 'httponly' => true, 'samesite' => 'Lax' -]; -// At the very beginning of config.php -/*ini_set('session.save_path', __DIR__ . '/../sessions'); -if (!is_dir(__DIR__ . '/../sessions')) { - mkdir(__DIR__ . '/../sessions', 0777, true); -}*/ +]); +ini_set('session.gc_maxlifetime', (string)$sessionLifetime); + if (session_status() === PHP_SESSION_NONE) { - session_set_cookie_params($cookieParams); - ini_set('session.gc_maxlifetime', 7200); session_start(); } +// CSRF token if (empty($_SESSION['csrf_token'])) { $_SESSION['csrf_token'] = bin2hex(random_bytes(32)); } -// Auto-login via persistent token. -if (!isset($_SESSION["authenticated"]) && isset($_COOKIE['remember_me_token'])) { - $persistentTokensFile = USERS_DIR . 'persistent_tokens.json'; - $persistentTokens = []; - if (file_exists($persistentTokensFile)) { - $encryptedContent = file_get_contents($persistentTokensFile); - $decryptedContent = decryptData($encryptedContent, $encryptionKey); - $persistentTokens = json_decode($decryptedContent, true); - if (!is_array($persistentTokens)) { - $persistentTokens = []; - } +// Auto‑login via persistent token +if (empty($_SESSION["authenticated"]) && !empty($_COOKIE['remember_me_token'])) { + $tokFile = USERS_DIR . 'persistent_tokens.json'; + $tokens = []; + if (file_exists($tokFile)) { + $enc = file_get_contents($tokFile); + $dec = decryptData($enc, $encryptionKey); + $tokens = json_decode($dec, true) ?: []; } - if (isset($persistentTokens[$_COOKIE['remember_me_token']])) { - $tokenData = $persistentTokens[$_COOKIE['remember_me_token']]; - if ($tokenData['expiry'] >= time()) { + $token = $_COOKIE['remember_me_token']; + if (!empty($tokens[$token])) { + $data = $tokens[$token]; + if ($data['expiry'] >= time()) { $_SESSION["authenticated"] = true; - $_SESSION["username"] = $tokenData["username"]; - // IMPORTANT: Set the folderOnly flag here for auto-login. - $_SESSION["folderOnly"] = loadUserPermissions($tokenData["username"]); + $_SESSION["username"] = $data["username"]; + $_SESSION["folderOnly"] = loadUserPermissions($data["username"]); + $_SESSION["isAdmin"] = !empty($data["isAdmin"]); } else { - unset($persistentTokens[$_COOKIE['remember_me_token']]); - $newEncryptedContent = encryptData(json_encode($persistentTokens, JSON_PRETTY_PRINT), $encryptionKey); - file_put_contents($persistentTokensFile, $newEncryptedContent, LOCK_EX); + // expired — clean up + unset($tokens[$token]); + file_put_contents($tokFile, encryptData(json_encode($tokens, JSON_PRETTY_PRINT), $encryptionKey), LOCK_EX); setcookie('remember_me_token', '', time() - 3600, '/', '', $secure, true); } } } +// Share URL fallback define('BASE_URL', 'http://yourwebsite/uploads/'); - if (strpos(BASE_URL, 'yourwebsite') !== false) { - $defaultShareUrl = isset($_SERVER['HTTP_HOST']) - ? "http://" . $_SERVER['HTTP_HOST'] . "/api/file/share.php" + $defaultShare = isset($_SERVER['HTTP_HOST']) + ? "http://{$_SERVER['HTTP_HOST']}/api/file/share.php" : "http://localhost/api/file/share.php"; } else { - $defaultShareUrl = rtrim(BASE_URL, '/') . "/api/file/share.php"; + $defaultShare = rtrim(BASE_URL, '/') . "/api/file/share.php"; } -define('SHARE_URL', getenv('SHARE_URL') ? getenv('SHARE_URL') : $defaultShareUrl); +define('SHARE_URL', getenv('SHARE_URL') ?: $defaultShare); \ No newline at end of file diff --git a/src/controllers/authController.php b/src/controllers/authController.php index 4c56686..f9bd58a 100644 --- a/src/controllers/authController.php +++ b/src/controllers/authController.php @@ -84,7 +84,7 @@ class AuthController if ($totpCode && isset($_SESSION['pending_login_user'], $_SESSION['pending_login_secret'])) { $username = $_SESSION['pending_login_user']; $secret = $_SESSION['pending_login_secret']; - + $rememberMe = $_SESSION['pending_login_remember_me'] ?? false; $tfa = new TwoFactorAuth(new GoogleChartsQrCodeProvider(), 'FileRise', 6, 30, Algorithm::Sha1); if (! $tfa->verifyCode($secret, $totpCode)) { echo json_encode(['error' => 'Invalid TOTP code']); @@ -203,6 +203,7 @@ class AuthController if (! empty($user['totp_secret'])) { $_SESSION['pending_login_user'] = $username; $_SESSION['pending_login_secret'] = $user['totp_secret']; + $_SESSION['pending_login_remember_me'] = $rememberMe; echo json_encode(['totp_required' => true]); exit(); }