Compare commits

...

19 Commits

Author SHA1 Message Date
github-actions[bot]
dd3a7a5145 chore(release): set APP_VERSION to v1.8.0 [skip ci] 2025-11-03 21:40:02 +00:00
Ryan
d00db803c3 release(v1.8.0): feat(onlyoffice): first-class ONLYOFFICE integration (view/edit), admin UI, API, CSP helpers
Refs #37 — implements ONLYOFFICE integration suggested in the discussion; video progress saving will be tracked separately.
2025-11-03 16:39:48 -05:00
github-actions[bot]
77a94ecd85 chore(release): set APP_VERSION to v1.7.5 [skip ci] 2025-11-02 04:56:35 +00:00
Ryan
699873848e release(v1.7.5): retrigger CI bump ensure up to date 2025-11-02 00:56:24 -04:00
Ryan
9cb12c11a6 release(v1.7.5): retrigger CI bump (no code changes) 2025-11-02 00:49:36 -04:00
Ryan
c08876380b release(v1.7.5): retrigger CI bump; chore(ci): update bump workflow 2025-11-02 00:44:29 -04:00
Ryan
5b824888cb release(v1.7.5): CSP hardening, API-backed previews, flicker-free theming, cache tuning & deploy script (closes #50) 2025-11-02 00:32:04 -04:00
Ryan
b7d7f7c3ce release(v1.7.5): CSP hardening, API-backed previews, flicker-free theming, cache tuning & deploy script (closes #50) 2025-11-02 00:32:03 -04:00
github-actions[bot]
e509b7ac9c chore(release): set APP_VERSION to v1.7.4 [skip ci] 2025-10-31 22:18:01 +00:00
Ryan
947255d94c release(v1.7.4): login hint replace toast + fix unauth boot 2025-10-31 18:17:52 -04:00
Ryan
55d44ef880 release(1.7.4): login hint replaced toast + fix unauth boot 2025-10-31 18:11:08 -04:00
github-actions[bot]
ad76e37ad5 chore(release): set APP_VERSION to v1.7.3 [skip ci] 2025-10-31 21:34:41 +00:00
Ryan
d664a2f5d8 release(v1.7.3): lightweight boot pipeline, dramatically faster first paint, deduped /api writes, sturdier uploads/auth 2025-10-31 17:34:25 -04:00
github-actions[bot]
a18a8df7af chore(release): set APP_VERSION to v1.7.2 [skip ci] 2025-10-29 20:54:31 +00:00
Ryan
8cf5a34ae9 release(v1.7.2): harden asset stamping & CI verification 2025-10-29 16:54:22 -04:00
github-actions[bot]
55d5656139 chore(release): set APP_VERSION to v1.7.1 [skip ci] 2025-10-29 20:19:45 +00:00
Ryan
04be05ad1e release(v1.7.1): stamp-assets.sh invoke via bash 2025-10-29 16:19:35 -04:00
github-actions[bot]
0469d183de chore(release): set APP_VERSION to v1.7.0 [skip ci] 2025-10-29 20:07:32 +00:00
Ryan
b1de8679e0 release(v1.7.0): asset cache-busting pipeline, public siteConfig cache, JS core split, and caching/security polish 2025-10-29 16:07:22 -04:00
46 changed files with 4501 additions and 1538 deletions

View File

@@ -55,17 +55,62 @@ jobs:
echo "exists=false" >> "$GITHUB_OUTPUT" echo "exists=false" >> "$GITHUB_OUTPUT"
fi fi
- name: Build zip artifact # Ensure the stamper is executable and has LF endings (helps if edited on Windows)
- name: Prep stamper script
if: steps.tagcheck.outputs.exists == 'false' if: steps.tagcheck.outputs.exists == 'false'
shell: bash shell: bash
run: | run: |
set -euo pipefail set -euo pipefail
ZIP="FileRise-${{ steps.ver.outputs.version }}.zip" sed -i 's/\r$//' scripts/stamp-assets.sh || true
zip -r "$ZIP" . \ chmod +x scripts/stamp-assets.sh
-x "./.git/*" "./.github/*" \
"./resources/*" "./resources/**" \ - name: Build zip artifact (stamped)
"./.dockerignore" "./.gitattributes" "./.gitignore" \ if: steps.tagcheck.outputs.exists == 'false'
"$ZIP" "${ZIP}.sha256" >/dev/null shell: bash
run: |
set -euo pipefail
VER="${{ steps.ver.outputs.version }}" # e.g. v1.6.12
ZIP="FileRise-${VER}.zip"
# Clean staging copy (exclude dotfiles you dont want)
rm -rf staging
rsync -a \
--exclude '.git' --exclude '.github' \
--exclude 'resources' \
--exclude '.dockerignore' --exclude '.gitattributes' --exclude '.gitignore' \
./ staging/
# Stamp IN THE STAGING COPY (invoke via bash to avoid exec-bit issues)
bash ./scripts/stamp-assets.sh "${VER}" "$(pwd)/staging"
- name: Verify placeholders are gone (staging)
if: steps.tagcheck.outputs.exists == 'false'
shell: bash
run: |
set -euo pipefail
ROOT="$(pwd)/staging"
if grep -R -n -E "{{APP_QVER}}|{{APP_VER}}" "$ROOT" \
--include='*.html' --include='*.php' --include='*.css' --include='*.js' 2>/dev/null; then
echo "---- DEBUG (show 10 hits with context) ----"
grep -R -n -E "{{APP_QVER}}|{{APP_VER}}" "$ROOT" \
--include='*.html' --include='*.php' --include='*.css' --include='*.js' \
| head -n 10 | while IFS=: read -r file line _; do
echo ">>> $file:$line"
nl -ba "$file" | sed -n "$((line-3)),$((line+3))p" || true
echo "----------------------------------------"
done
exit 1
fi
echo "OK: No unreplaced placeholders in staging."
- name: Zip stamped staging
if: steps.tagcheck.outputs.exists == 'false'
shell: bash
run: |
set -euo pipefail
VER="${{ steps.ver.outputs.version }}"
ZIP="FileRise-${VER}.zip"
(cd staging && zip -r "../$ZIP" . >/dev/null)
- name: Compute SHA-256 checksum - name: Compute SHA-256 checksum
if: steps.tagcheck.outputs.exists == 'false' if: steps.tagcheck.outputs.exists == 'false'
@@ -127,12 +172,12 @@ jobs:
SHA="${{ steps.sum.outputs.sha }}" SHA="${{ steps.sum.outputs.sha }}"
{ {
echo "## ${VER}"
echo echo
if [[ -s CHANGELOG_SNIPPET.md ]]; then if [[ -s CHANGELOG_SNIPPET.md ]]; then
cat CHANGELOG_SNIPPET.md cat CHANGELOG_SNIPPET.md
echo echo
fi fi
echo "## ${VER}"
echo "### Full Changelog" echo "### Full Changelog"
echo "[${PREV} → ${VER}](${COMPARE_URL})" echo "[${PREV} → ${VER}](${COMPARE_URL})"
echo echo

View File

@@ -5,18 +5,25 @@ on:
push: push:
paths: paths:
- "CHANGELOG.md" - "CHANGELOG.md"
workflow_dispatch: {}
permissions: permissions:
contents: write contents: write
concurrency:
group: bump-and-sync-${{ github.ref }}
cancel-in-progress: false
jobs: jobs:
bump_and_sync: bump_and_sync:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v4 - name: Checkout FileRise
uses: actions/checkout@v4
with: with:
fetch-depth: 0 fetch-depth: 0
ref: ${{ github.ref }}
- name: Extract version from commit message - name: Extract version from commit message
id: ver id: ver
@@ -32,7 +39,24 @@ jobs:
echo "No release(vX.Y.Z) tag in commit message; skipping bump." echo "No release(vX.Y.Z) tag in commit message; skipping bump."
fi fi
- name: Update public/js/version.js # Ensure we're on the branch and up to date BEFORE modifying files
- name: Ensure clean branch (no local mods), update from remote
if: steps.ver.outputs.version != ''
shell: bash
run: |
set -euo pipefail
# Be on a named branch that tracks the remote
git checkout -B "${{ github.ref_name }}" --track "origin/${{ github.ref_name }}" || git checkout -B "${{ github.ref_name }}"
# Make sure the worktree is clean
if ! git diff --quiet || ! git diff --cached --quiet; then
echo "::error::Working tree not clean before update. Aborting."
git status --porcelain
exit 1
fi
# Update branch
git pull --rebase origin "${{ github.ref_name }}"
- name: Update public/js/version.js (source of truth)
if: steps.ver.outputs.version != '' if: steps.ver.outputs.version != ''
shell: bash shell: bash
run: | run: |
@@ -42,44 +66,19 @@ jobs:
window.APP_VERSION = '${{ steps.ver.outputs.version }}'; window.APP_VERSION = '${{ steps.ver.outputs.version }}';
EOF EOF
- name: Stamp asset cache-busters (?v=...) in HTML/CSS and {{APP_VER}} everywhere - name: Commit version.js only
if: steps.ver.outputs.version != ''
shell: bash
run: |
set -euo pipefail
VER="${{ steps.ver.outputs.version }}" # e.g. v1.6.9
QVER="${VER#v}" # e.g. 1.6.9
echo "Stamping ?v=${QVER} and {{APP_VER}}=${VER}"
# 1) Only stamp ?v= in HTML/CSS (avoid JS concatenation issues)
mapfile -t html_css < <(git ls-files -- 'public/*.html' 'public/**/*.html' 'public/*.php' 'public/**/*.css')
for f in "${html_css[@]}"; do
sed -E -i "s/(\?v=)[^\"'&<>\s]*/\1${QVER}/g" "$f"
sed -E -i "s/\{\{APP_VER\}\}/${VER}/g" "$f"
done
# 2) For JS, only replace the {{APP_VER}} placeholder (do NOT touch ?v=)
mapfile -t jsfiles < <(git ls-files -- 'public/*.js' 'public/**/*.js')
for f in "${jsfiles[@]}"; do
sed -E -i "s/\{\{APP_VER\}\}/${VER}/g" "$f"
done
echo "Changed files:"
git status --porcelain | awk '{print $2}' | sed 's/^/ - /'
- name: Commit version bump + stamped assets
if: steps.ver.outputs.version != '' if: steps.ver.outputs.version != ''
shell: bash shell: bash
run: | run: |
set -euo pipefail set -euo pipefail
git config user.name "github-actions[bot]" git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com" git config user.email "github-actions[bot]@users.noreply.github.com"
git add public/js/version.js public git add public/js/version.js
if git diff --cached --quiet; then if git diff --cached --quiet; then
echo "No changes to commit" echo "No changes to commit"
else else
git commit -m "chore(release): set APP_VERSION and stamp assets to ${{ steps.ver.outputs.version }} [skip ci]" git commit -m "chore(release): set APP_VERSION to ${{ steps.ver.outputs.version }} [skip ci]"
git push git push origin "${{ github.ref_name }}"
fi fi
- name: Checkout filerise-docker - name: Checkout filerise-docker
@@ -89,6 +88,7 @@ jobs:
repository: error311/filerise-docker repository: error311/filerise-docker
token: ${{ secrets.PAT_TOKEN }} token: ${{ secrets.PAT_TOKEN }}
path: docker-repo path: docker-repo
fetch-depth: 0
- name: Copy CHANGELOG.md and write VERSION - name: Copy CHANGELOG.md and write VERSION
if: steps.ver.outputs.version != '' if: steps.ver.outputs.version != ''
@@ -110,6 +110,6 @@ jobs:
if git diff --cached --quiet; then if git diff --cached --quiet; then
echo "No changes to commit" echo "No changes to commit"
else else
git commit -m "chore: sync CHANGELOG.md and VERSION (${{ steps.ver.outputs.version }}) from FileRise" git commit -m "chore: sync CHANGELOG.md + VERSION (${{ steps.ver.outputs.version }}) from FileRise"
git push origin main git push origin main
fi fi

View File

@@ -1,5 +1,265 @@
# Changelog # Changelog
## Changes 11/3/2025 (v1.8.0)
release(v1.8.0): feat(onlyoffice): first-class ONLYOFFICE integration (view/edit), admin UI, API, CSP helpers
Refs #37 — implements ONLYOFFICE integration suggested in the discussion; video progress saving will be tracked separately.
Adds secure, ACL-aware ONLYOFFICE support throughout FileRise:
- **Backend / API**
- New OnlyOfficeController with supported extensions (doc/xls/ppt/pdf etc.), status/config endpoints, and signed download flow.
- New endpoints:
- GET /api/onlyoffice/status.php — reports availability + supported exts.
- GET /api/onlyoffice/config.php — returns DocEditor config (signed URLs, callback).
- GET /api/onlyoffice/signed-download.php — serves signed blobs to DS.
- Effective config/overrides: env/constant wins; supports docsOrigin, publicOrigin, and jwtSecret; status gated on presence of origin+secret.
- Public origin resolution (BASE_URL/proxy aware) for absolute URLs.
- **Admin config / UI**
- AdminPanel gets a new “ONLYOFFICE” section with Enable toggle, Document Server Origin, masked JWT Secret, and “Replace” control.
- Built-in connection tester (status, secret presence, callback ping, api.js load, iframe embed) + CSP helper (Apache & Nginx snippets)
- **Frontend integration**
- fileEditor detects OO capability via /api/onlyoffice/status and routes supported types to the DocEditor; loads DocsAPI dynamically.
- editFile() short-circuits to openOnlyOffice when applicable; includes live dark/light theme sync where supported.
- fileListView pulls status once on load to drive UI decisions (e.g., editing affordances).
- **AdminModel / config**
- Adds onlyoffice {enabled, docsOrigin, publicOrigin} defaults and update path, with jwtSecret persisted (kept unless explicitly replaced).
- Optional constants in config.php to override and debug.
- **Security & UX notes**
- Editor access remains ACL-checked (read/edit) and uses absolute, signed URLs surfaced via controller.
- Admin UI never echoes secrets; “Replace” toggles explicit updates only.
- CSP helper makes it straightforward to permit api.js + iframe + XHR to your DS.
- **Docs/Styling**
- Minor CSS touch-ups around hover states and modal layout.
---
## Changes 11/2/2025 (v1.7.5)
release(v1.7.5): CSP hardening, API-backed previews, flicker-free theming, cache tuning & deploy script (closes #50)
release(v1.7.5): retrigger CI bump (no code changes)
release(v1.7.5): retrigger CI bump ensure up to date
### Security/headers
- Tighten CSP: pin the inline pre-theme snippet with a script-src SHA-256 and keep everything else on 'self'.
- Improve cache policy for versioned assets: force 1y + immutable and add s-maxage for CDNs; also avoid HSTS redirects on local/dev hosts.
### Previews & editor
- Remove hardcoded `/uploads/` paths; always build preview URLs via the API (respects UPLOAD_DIR/ACL).
- Use the API URL for gallery prev/next and file-menu “Preview” to fix 404s on custom storage roots.
- Editor now probes size safely (HEAD → Range 0-0 fallback) before fetching, then fetches with credentials.
### Login, theming & UX polish
- Pre-theme inline boot sets `dark-mode` + background early; swap to `[hidden]`/`unhide()` instead of inline `display:none`.
- Add full-screen loading overlay with quick fade and proper color-scheme; prevent white/black flash on theme flips.
- Refactor app/login reveal flow in `main.js` (`revealAppAndHideOverlay`, `authed` path, setup wizard).
### HTML/CSS & perf
- Make Bootstrap/Styles/Roboto critical (plain `<link rel="stylesheet">`); keep fonts as true preloads; modulepreload app entry.
- Export a `__CSS_PROMISE__` from `defer-css.js` for sites that still promote preloads.
- Header logo marked `fetchpriority="high"` for faster first paint.
- Normalize dark-mode selectors to `.dark-mode` scope (admin panel, etc.).
### Manual Deploy script
- Add `scripts/filerise-deploy.sh`: idempotent rsync-based deploy with writable dirs preserved, optional Composer install, and PHP-FPM/Apache reloads.
### Notes
- If you change the inline pre-theme snippet, update the CSP hash accordingly.
---
## Changes 10/31/2025 (v1.7.4)
release(v1.7.4): login hint replace toast + fix unauth boot
main.js
- Added isDemoHost() and showLoginTip(message).
- In the unauth branch, call showLoginTip('Please log in to continue').
- Removed ensureToastReady() + showToast('please_log_in_to_continue') in the unauth path to avoid loading toast/DOM utils before auth.
---
## Changes 10/31/2025 (v1.7.3)
release(v1.7.3): lightweight boot pipeline, dramatically faster first paint, deduped /api writes, sturdier uploads/auth
### 🎃 Highlights (advantages) 👻 🦇
- ⚡ Faster, cleaner boot: a lightweight **main.js** decides auth/setup before painting, avoids flicker, and wires modules exactly once.
- ♻️ Fewer duplicate actions: **request coalescer** dedupes POST/PUT/PATCH/DELETE to /api/* .
- ✅ Truthy UX: global **toast bridge** queues early toasts and normalizes misleading “not found/already exists” messages after success.
- 🔐 Smoother auth: CSRF priming/rotation + **TOTP step-up detection** across JSON & redirect paths; “Welcome back, `user`” toast once per tab.
- 🌓 Polished UI: **dark-mode persistence with system fallback**, live siteConfig title application, higher-z modals, drag auto-scroll.
- 🚀 Faster first paint & interactions: defer CodeMirror/Fuse/Resumable, promote preloaded CSS, and coalesce duplicate requests → snappier UI.
- 🧭 Admin polish: live header title preview, masked OIDC fields with **Replace** flow, and a **read-only Sponsors/Donations** section.
- 🧱 Safer & cache-smarter: opinionated .htaccess (CSP/HSTS/MIME/compression) + `?v={{APP_QVER}}` for versioned immutable assets.
### Core bootstrap (main.js) overhaul
- Early **toast bridge** (queues until domUtils is ready); expose `window.__FR_TOAST_FILTER__` for centralized rewrites/suppression.
- **Result guard + request coalescer** wrapping `fetch`:
- Dedupes same-origin `/api/*` mutating requests for ~800ms using a stable key (method + path + normalized body).
- Tracks “last OK” JSON (`success|status|result=ok`) to suppress false-negative error toasts after success.
- **Boot orchestrator** with hard guards:
- `__FR_FLAGS` (`booted`, `initialized`, `wired.*`, `bootPromise`, `entryStarted`) to prevent double init/leaks.
- **No-flicker login**: resolve `checkAuth()` + `setup` before showing UI; show login only when truly unauthenticated.
- **Heavy boot** for authed users: load i18n, `appCore.loadCsrfToken/initializeApp`, first file list, then light UI wiring.
- **Auth flow**:
- `primeCsrf()` + `<meta name="csrf-token">` management; persist token in localStorage.
- **TOTP** detection via header (`X-TOTP-Required`) & JSON (`totp_required` / `TOTP_REQUIRED`); calls `openTOTPLoginModal()`.
- **Welcome toast** once per tab via `sessionStorage.__fr_welcomed`.
- **UI/UX niceties**:
- `applySiteConfig()` updates header title & login method visibility on both login & authed screens.
- Dark-mode persistence with system fallback, proper a11y labels/icons.
- Create dropdown/menu wiring with capture-phase outside-click + ESC close; modal cancel safeties.
- Lift modals above cards (z-index), **drag auto-scroll** near viewport edges.
- Dispatch legacy `DOMContentLoaded`/`load` **once** (supports older inline handlers).
- Username label refresh for existing `.user-name-label` without injecting new DOM.
### Performance & UX changes
- CSS/first paint:
- Preload Bootstrap & app CSS; promote at DOMContentLoaded; keep inline CSS minimal.
- Add `width/height/decoding/fetchpriority` to logo to reduce layout shift.
- Search/editor/uploads:
- **fileListView.js**: lazy-load Fuse with instant substring fallback; `warmUpSearch()` hook.
- **fileEditor.js**: lazy-load CodeMirror core/theme/modes; start plain then upgrade; guard very large files gracefully.
- **upload.js**: lazy-load Resumable; resilient init; background warm-up; smarter addFile/submit; clearer toasts.
- Toast/UX:
- Install early toast bridge; queue & normalize messages; neutral “Done.” when server returns misleading errors after success.
### Correctness: uploads, paths, ACLs
- **UploadController/UploadModel**: normalize folders via `ACL::normalizeFolder(rawurldecode())`; stricter segment checks; consistent base paths; safer metadata writes; proper chunk presence/merge & temp cleanup.
### Auth hardening & resilience
- **auth.js/main.js/appCore.js**: CSRF rotate/retry (JSON then x-www-form-urlencoded fallback); robust login handling; fewer misleading error toasts.
- **AuthController**: OIDC username fallback to `email` or `sub` when `preferred_username` missing.
### Admin panel
- **adminPanel.js**:
- Live header title preview (instant update without reload).
- Masked OIDC client fields with **Replace** button; saved-value hints; only send secrets when replacing.
- **New “Sponsor / Donations” section (read-only)**:
- GitHub Sponsors → `https://github.com/sponsors/error311`
- Ko-fi → `https://ko-fi.com/error311`
- Includes **Copy** and **Open** buttons; values are fixed.
- **AdminController**: boolean for `oidc.hasClientId/hasClientSecret` to drive masked inputs.
### Security & caching (.htaccess)
- Consolidated security headers (CSP, CORP, HSTS on HTTPS), MIME types, compression (Brotli/Deflate), TRACE disable.
- Caching rules:
- HTML/version.js: no-cache; unversioned JS/CSS: 1h; unversioned static: 7d; **versioned assets `?v=`: 1y `immutable`**.
- **config.php**: remove duplicate runtime headers (now via Apache) to avoid proxy/CDN conflicts.
### Upgrade notes
- No schema changes.
- Ensure Apache modules (`headers`, `rewrite`, `brotli`/`deflate`) are available for the new .htaccess rules (fallbacks included).
- Versioned assets mean users shouldnt need a hard refresh; `?v={{APP_QVER}}` busts caches automatically.
---
## Changes 10/29/2025 (v1.7.0 & v1.7.1 & v1.7.2)
release(v1.7.0): asset cache-busting pipeline, public siteConfig cache, JS core split, and caching/security polish
### ✨ Features
- Public, non-sensitive site config cache:
- Add `AdminModel::buildPublicSubset()` and `writeSiteConfig()` to write `USERS_DIR/siteConfig.json`.
- New endpoint `public/api/siteConfig.php` + `UserController::siteConfig()` to serve the public subset (regenerates if stale).
- Frontend now reads `/api/siteConfig.php` (safe subset) instead of `/api/admin/getConfig.php`.
- Frontend module versioning:
- Replace all module imports with `?v={{APP_QVER}}` query param so the release/Docker stamper can pin exact versions.
- Add `scripts/stamp-assets.sh` to stamp `?v=` and `{{APP_VER}}/{{APP_QVER}}` in **staging** for ZIP/Docker builds.
### 🧩 Refactors
- Extract shared boot/bootstrap logic into `public/js/appCore.js`:
- CSRF helpers (`setCsrfToken`, `getCsrfToken`, `loadCsrfToken`)
- `initializeApp()`, `triggerLogout()`
- Keep `main.js` lean; wrap global `fetch` once to append/rotate CSRF.
- Update imports across JS modules to use versioned module URLs.
### 🚀 Performance
- Aggressive, safe caching for versioned assets:
- `.htaccess`: `?v=…``Cache-Control: max-age=31536000, immutable`.
- Unversioned JS/CSS short cache (1h), other static (7d).
- Eliminate duplicate `main.js` loads and tighten CodeMirror mode loading.
### 🔒 Security / Hardening
- `.htaccess`:
- Conditional HSTS only when HTTPS, add CORP and X-Permitted-Cross-Domain-Policies.
- CSP kept strict for modules, workers, blobs.
- Admin config exposure reduced to a curated subset in `siteConfig.json`.
### 🧪 CI/CD / Release
- **FileRise repo**
- `sync-changelog.yml`: keep `public/js/version.js` as source-of-truth only (no repo-wide stamping).
- `release-on-version.yml`: build **stamped** ZIP from a staging copy via `scripts/stamp-assets.sh`, verify placeholders removed, attach checksum.
- **filerise-docker repo**
- Read `VERSION`, checkout app to `app/`, run stamper inside build context before `docker buildx`, tag `latest` and `:${VERSION}`.
### 🔧 Defaults
- Sample/admin config defaults now set `disableBasicAuth: true` (safer default). Existing installations keep their current setting.
### 📂 Notable file changes
- `src/models/AdminModel.php` (+public subset +atomic write)
- `src/controllers/UserController.php` (+siteConfig action)
- `public/api/siteConfig.php` (new)
- `public/js/appCore.js` (new), `public/js/main.js` (slim, uses appCore)
- Many `public/js/*.js` import paths updated to `?v={{APP_QVER}}`
- `public/.htaccess` (caching & headers)
- `scripts/stamp-assets.sh` (new)
### ⚠️ Upgrade notes
- Ensure `USERS_DIR` is writable by web server for `siteConfig.json`.
- Proxies/edge caches: the new `?v=` scheme enables long-lived immutable caching; purge is automatic on version bump.
- If you previously read admin config directly on the client, it now reads `/api/siteConfig.php`.
### Additional changes/fixes for release
- `release-on-version.yml`
- normalize line endings (strip CRLF)
- stamp-assets.sh dont rely on the exec; invoke via bash
release(v1.7.2): harden asset stamping & CI verification
### build(stamper)
- Rewrite scripts/stamp-assets.sh to be repo-agnostic and macOS/Windows friendly:
- Drop reliance on git ls-files/mapfile; use find + null-delimited loops
- Normalize CRLF to LF for all web assets before stamping
- Stamp ?v=<APP_QVER> in HTML/CSS/PHP and {{APP_VER}} everywhere
- Normalize any ".mjs|.js?v=..." occurrences inside JS (ESM imports/strings)
- Force-write public/js/version.js from VER (source of truth in stamped output)
- Print touched counts and fail fast if any {{APP_QVER}}|{{APP_VER}} remain
---
## Changes 10/28/2025 (v1.6.11) ## Changes 10/28/2025 (v1.6.11)
release(v1.6.11) fix(ui/dragAndDrop) restore floating zones toggle click action release(v1.6.11) fix(ui/dragAndDrop) restore floating zones toggle click action

View File

@@ -10,7 +10,7 @@
[![Sponsor on GitHub](https://img.shields.io/badge/Sponsor-❤-red)](https://github.com/sponsors/error311) [![Sponsor on GitHub](https://img.shields.io/badge/Sponsor-❤-red)](https://github.com/sponsors/error311)
[![Support on Ko-fi](https://img.shields.io/badge/Ko--fi-Buy%20me%20a%20coffee-orange)](https://ko-fi.com/error311) [![Support on Ko-fi](https://img.shields.io/badge/Ko--fi-Buy%20me%20a%20coffee-orange)](https://ko-fi.com/error311)
**Quick links:** [Demo](#live-demo) • [Install](#installation--setup) • [Docker](#1-running-with-docker-recommended) • [Unraid](#unraid) • [WebDAV](#quick-start-mount-via-webdav) • [FAQ](#faq--troubleshooting) **Quick links:** [Demo](#live-demo) • [Install](#installation--setup) • [Docker](#1-running-with-docker-recommended) • [Unraid](#unraid) • [WebDAV](#quick-start-mount-via-webdav) • [ONLYOFFICE](#quick-start-onlyoffice-optional) • [FAQ](#faq--troubleshooting)
**Elevate your File Management** A modern, self-hosted web file manager. **Elevate your File Management** A modern, self-hosted web file manager.
Upload, organize, and share files or folders through a sleek, responsive web interface. Upload, organize, and share files or folders through a sleek, responsive web interface.
@@ -21,6 +21,8 @@ Grant precise capabilities like *view*, *upload*, *rename*, *delete*, or *manage
With drag-and-drop uploads, in-browser editing, secure user logins (SSO & TOTP 2FA), and one-click public sharing, **FileRise** brings professional-grade file management to your own server — simple to deploy, easy to scale, and fully self-hosted. With drag-and-drop uploads, in-browser editing, secure user logins (SSO & TOTP 2FA), and one-click public sharing, **FileRise** brings professional-grade file management to your own server — simple to deploy, easy to scale, and fully self-hosted.
New: Open and edit Office documents — **Word (DOCX)**, **Excel (XLSX)**, **PowerPoint (PPTX)** — directly in **FileRise** using your self-hosted **ONLYOFFICE Document Server** (optional). Open **ODT/ODS/ODP**, and view **PDFs** inline. Where supported by your Document Server, users can add **comments/annotations** to documents (and PDFs). Everything is enforced by the same per-folder ACLs across the UI and WebDAV.
> ⚠️ **Security fix in v1.5.0** — ACL hardening. If youre on ≤1.4.x, please upgrade. > ⚠️ **Security fix in v1.5.0** — ACL hardening. If youre on ≤1.4.x, please upgrade.
**10/25/2025 Video demo:** **10/25/2025 Video demo:**
@@ -74,6 +76,8 @@ With drag-and-drop uploads, in-browser editing, secure user logins (SSO & TOTP 2
- 📝 **Built-in Editor & Preview:** Inline preview for images, video, audio, and PDFs. CodeMirror-based editor for text/code with syntax highlighting and line numbers. - 📝 **Built-in Editor & Preview:** Inline preview for images, video, audio, and PDFs. CodeMirror-based editor for text/code with syntax highlighting and line numbers.
- - 🧩 **Office Docs (ONLYOFFICE, optional):** View/edit DOCX, XLSX, PPTX (and ODT/ODS/ODP, PDF view) using your self-hosted ONLYOFFICE Document Server. Enforced by the same ACLs as the web UI & WebDAV.
- 🏷️ **Tags & Search:** Add color-coded tags and search by name, tag, uploader, or content. Advanced fuzzy search indexes metadata and file contents. - 🏷️ **Tags & Search:** Add color-coded tags and search by name, tag, uploader, or content. Advanced fuzzy search indexes metadata and file contents.
- 🔒 **Authentication & SSO:** Username/password, optional TOTP 2FA, and OIDC (Google, Authentik, Keycloak). - 🔒 **Authentication & SSO:** Username/password, optional TOTP 2FA, and OIDC (Google, Authentik, Keycloak).
@@ -342,8 +346,48 @@ https://your-host/webdav.php/
--- ---
## Quick start: ONLYOFFICE (optional)
FileRise can open & edit office docs using your **self-hosted ONLYOFFICE Document Server**.
**What you need**
- A reachable ONLYOFFICE Document Server (Community/Enterprise).
- A shared **JWT secret** used by FileRise and your Document Server.
**Setup (23 minutes)**
1. In FileRise go to **Admin → ONLYOFFICE** and:
- ✅ Enable ONLYOFFICE
- 🔗 Set **Document Server Origin** (e.g., `https://docs.example.com`)
- 🔑 Enter **JWT Secret** (click “Replace” to set)
2. (Recommended) Click **Run tests** in the ONLYOFFICE card:
- Checks FileRise status, callback reachability, `api.js` load, and iframe embed.
3. Update your **Content-Security-Policy** to allow the DS origin.
The Admin panel shows a ready-to-copy line for Apache & Nginx. Example:
**Apache**
```apache
Header always set Content-Security-Policy "default-src 'self'; frame-src 'self' https://docs.example.com; script-src 'self' https://docs.example.com https://docs.example.com/web-apps/apps/api/documents/api.js; connect-src 'self' https://docs.example.com; style-src 'self' 'unsafe-inline'; img-src 'self' data: blob:; font-src 'self'"
```
**Nginx**
```add_header Content-Security-Policy "default-src 'self'; frame-src 'self' https://docs.example.com; script-src 'self' https://docs.example.com https://docs.example.com/web-apps/apps/api/documents/api.js; connect-src 'self' https://docs.example.com; style-src 'self' 'unsafe-inline'; img-src 'self' data: blob:; font-src 'self'" always;
```
**Notes**
- If your site is https://, your Document Server must also be https:// (or the browser will block it as mixed content).
- Editor access respects FileRise ACLs (view/edit/share) exactly like the rest of the app.
---
## FAQ / Troubleshooting ## FAQ / Troubleshooting
- **ONLYOFFICE editor wont load / blank frame:** Verify CSP allows your DS origin (`script-src`, `frame-src`, `connect-src`) and that the DS is reachable over HTTPS if your site is HTTPS.
- **“Disabled — check JWT Secret / Origin” in tests:** In **Admin → ONLYOFFICE**, set the Document Server Origin and click “Replace” to save a JWT secret. Then re-run tests.
- **“Upload failed” or large files not uploading:** Ensure `TOTAL_UPLOAD_SIZE` in config and PHPs `post_max_size` / `upload_max_filesize` are set high enough. For extremely large files, you might need to increase `max_execution_time` or rely on resumable uploads in smaller chunks. - **“Upload failed” or large files not uploading:** Ensure `TOTAL_UPLOAD_SIZE` in config and PHPs `post_max_size` / `upload_max_filesize` are set high enough. For extremely large files, you might need to increase `max_execution_time` or rely on resumable uploads in smaller chunks.
- **How to enable HTTPS?** FileRise doesnt terminate TLS itself. Run it behind a reverse proxy (Nginx, Caddy, Apache with SSL) or use a companion like nginx-proxy or Caddy in Docker. Set `SECURE="true"` in Docker so FileRise generates HTTPS links. - **How to enable HTTPS?** FileRise doesnt terminate TLS itself. Run it behind a reverse proxy (Nginx, Caddy, Apache with SSL) or use a companion like nginx-proxy or Caddy in Docker. Set `SECURE="true"` in Docker so FileRise generates HTTPS links.
@@ -399,6 +443,20 @@ Every bit helps me keep FileRise fast, polished, and well-maintained. Thank you!
## Dependencies ## Dependencies
### ONLYOFFICE integration
FileRise can open office documents using a self-hosted ONLYOFFICE Document Server.
- **We do not bundle ONLYOFFICE.** Admins point FileRise to an existing ONLYOFFICE Docs server and (optionally) set a JWT secret in **Admin > ONLYOFFICE**.
- **Licensing:** ONLYOFFICE Document Server (Community Edition) is released under the GNU AGPL v3. Enterprise editions are commercially licensed. When you deploy ONLYOFFICE, you are responsible for complying with the license of the edition you use.
Project page & license: <https://github.com/ONLYOFFICE/DocumentServer> (AGPL-3.0)
- **FileRise license unaffected:** FileRise communicates with ONLYOFFICE over standard HTTP and loads `api.js` from the configured Document Server at runtime; FileRise does not redistribute ONLYOFFICE code.
- **Trademarks:** ONLYOFFICE is a trademark of Ascensio System SIA. FileRise is not affiliated with or endorsed by ONLYOFFICE.
#### Security / CSP
If you enable ONLYOFFICE, allow its origin in your CSP (`script-src`, `frame-src`, `connect-src`). The Admin panel shows a ready-to-copy line for Apache/Nginx.
### PHP Libraries ### PHP Libraries
- **[jumbojett/openid-connect-php](https://github.com/jumbojett/OpenID-Connect-PHP)** (v^1.0.0) - **[jumbojett/openid-connect-php](https://github.com/jumbojett/OpenID-Connect-PHP)** (v^1.0.0)

View File

@@ -1,22 +1,6 @@
<?php <?php
// config.php // config.php
// Prevent caching
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");
header("Expires: 0");
// Security headers
header('X-Content-Type-Options: nosniff');
header("X-Frame-Options: SAMEORIGIN");
header("Referrer-Policy: no-referrer-when-downgrade");
header("Permissions-Policy: geolocation=(), microphone=(), camera=()");
header("X-XSS-Protection: 1; mode=block");
if (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') {
header("Strict-Transport-Security: max-age=31536000; includeSubDomains; preload");
}
// Define constants // Define constants
define('PROJECT_ROOT', dirname(__DIR__)); define('PROJECT_ROOT', dirname(__DIR__));
define('UPLOAD_DIR', '/var/www/uploads/'); define('UPLOAD_DIR', '/var/www/uploads/');
@@ -41,6 +25,13 @@ if (!defined('DEFAULT_CAN_ZIP')) define('DEFAULT_CAN_ZIP', true);
if (!defined('DEFAULT_VIEW_OWN_ONLY')) define('DEFAULT_VIEW_OWN_ONLY', false); if (!defined('DEFAULT_VIEW_OWN_ONLY')) define('DEFAULT_VIEW_OWN_ONLY', false);
define('FOLDER_OWNERS_FILE', META_DIR . 'folder_owners.json'); define('FOLDER_OWNERS_FILE', META_DIR . 'folder_owners.json');
define('ACL_INHERIT_ON_CREATE', true); define('ACL_INHERIT_ON_CREATE', true);
// ONLYOFFICE integration overrides (uncomment and set as needed)
/*
define('ONLYOFFICE_ENABLED', false);
define('ONLYOFFICE_JWT_SECRET', 'test123456');
define('ONLYOFFICE_DOCS_ORIGIN', 'http://192.168.1.61'); // your Document Server
define('ONLYOFFICE_DEBUG', true);
*/
// Encryption helpers // Encryption helpers
function encryptData($data, $encryptionKey) function encryptData($data, $encryptionKey)

View File

@@ -1,76 +1,112 @@
# -------------------------------- # --------------------------------
# Base: safe in most environments # FileRise portable .htaccess
# -------------------------------- # --------------------------------
Options -Indexes Options -Indexes
DirectoryIndex index.html DirectoryIndex index.html
<IfModule mod_authz_core.c> <IfModule mod_authz_core.c>
<FilesMatch "^\."> # Block dotfiles like .env, .git, etc., but allow ACME under .well-known
<FilesMatch "^\.(?!well-known(?:/|$))">
Require all denied Require all denied
</FilesMatch> </FilesMatch>
</IfModule> </IfModule>
# ---------------- Rewrites ----------------
<IfModule mod_rewrite.c>
RewriteEngine On RewriteEngine On
#RewriteCond %{HTTPS} off
# Never redirect local/dev hosts
RewriteCond %{HTTP_HOST} ^(localhost|127\.0\.0\.1|fr\.local|192\.168\.[0-9]+\.[0-9]+)$ [NC]
RewriteRule ^ - [L]
# Let ACME http-01 pass BEFORE any redirect (needed for auto-renew)
RewriteCond %{REQUEST_URI} ^/.well-known/acme-challenge/
RewriteRule - - [L]
# HTTPS redirect (enable ONE of these, comment the other)
# A) Direct TLS on this server
#RewriteCond %{HTTPS} !=on
#RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] #RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# MIME types for fonts/SVG # B) Behind reverse proxy that sets X-Forwarded-Proto
#RewriteCond %{HTTP:X-Forwarded-Proto} =http [OR]
#RewriteCond %{HTTP:X-Forwarded-Proto} ^$
#RewriteCond %{HTTPS} !=on
#RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Mark versioned assets (?v=...) with env flag for caching rules below
RewriteCond %{QUERY_STRING} (^|&)v= [NC]
RewriteRule ^ - [E=IS_VER:1]
</IfModule>
# ---------------- MIME types ----------------
<IfModule mod_mime.c> <IfModule mod_mime.c>
AddType font/woff2 .woff2 AddType font/woff2 .woff2
AddType font/woff .woff AddType font/woff .woff
AddType image/svg+xml .svg AddType image/svg+xml .svg
AddType application/javascript .mjs
</IfModule> </IfModule>
# Security headers # ---------------- Security headers ----------------
<IfModule mod_headers.c> <IfModule mod_headers.c>
Header always set X-Frame-Options "SAMEORIGIN" Header always set X-Frame-Options "SAMEORIGIN"
Header always set X-XSS-Protection "1; mode=block" Header always set X-XSS-Protection "1; mode=block"
Header always set X-Content-Type-Options "nosniff" Header always set X-Content-Type-Options "nosniff"
Header always set Strict-Transport-Security "max-age=31536000; includeSubDomains; preload"
Header always set Referrer-Policy "strict-origin-when-cross-origin" Header always set Referrer-Policy "strict-origin-when-cross-origin"
Header always set Permissions-Policy "geolocation=(), microphone=(), camera=()" Header always set Permissions-Policy "geolocation=(), microphone=(), camera=()"
Header always set X-Download-Options "noopen" Header always set X-Download-Options "noopen"
Header always set Expect-CT "max-age=86400, enforce" Header always set Expect-CT "max-age=86400, enforce"
Header set Content-Security-Policy "default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data: blob:; font-src 'self'; connect-src 'self'; media-src 'self' blob:; worker-src 'self' blob:; frame-ancestors 'self'; object-src 'none'; base-uri 'self'; form-action 'self'" Header always set Cross-Origin-Resource-Policy "same-origin"
Header always set X-Permitted-Cross-Domain-Policies "none"
# HSTS only when HTTPS (safe for .htaccess)
Header always set Strict-Transport-Security "max-age=31536000; includeSubDomains; preload" env=HTTPS
# CSP — keep this SHA-256 in sync with your inline pre-theme script
Header always set Content-Security-Policy "default-src 'self'; base-uri 'self'; frame-ancestors 'self'; object-src 'none'; script-src 'self' 'sha256-ajmGY+5VJOY6+8JHgzCqsqI8w9dCQfAmqIkFesOKItM='; style-src 'self' 'unsafe-inline'; img-src 'self' data: blob:; font-src 'self'; connect-src 'self'; media-src 'self' blob:; worker-src 'self' blob:; form-action 'self'"
</IfModule> </IfModule>
# Caching # ---------------- Caching ----------------
SetEnvIfNoCase QUERY_STRING "(^|&)v=" has_version_param=1
<IfModule mod_headers.c> <IfModule mod_headers.c>
# HTML/PHP: no cache
<FilesMatch "\.(html?|php)$"> <FilesMatch "\.(html?|php)$">
Header set Cache-Control "no-cache, no-store, must-revalidate" Header setifempty Cache-Control "no-cache, no-store, must-revalidate"
Header set Pragma "no-cache" Header setifempty Pragma "no-cache"
Header set Expires "0" Header setifempty Expires "0"
</FilesMatch> </FilesMatch>
# version.js: never cache
<FilesMatch "^js/version\.js$"> <FilesMatch "^js/version\.js$">
Header set Cache-Control "no-cache, no-store, must-revalidate" Header set Cache-Control "no-cache, no-store, must-revalidate"
Header set Pragma "no-cache" Header set Pragma "no-cache"
Header set Expires "0" Header set Expires "0"
</FilesMatch> </FilesMatch>
<FilesMatch "\.(js|css)$"> # JS/CSS: long cache if ?v= present, else 1h
Header set Cache-Control "public, max-age=3600, must-revalidate" env=!has_version_param <FilesMatch "\.(?:m?js|css)$">
Header set Cache-Control "public, max-age=31536000, immutable" env=IS_VER
Header set Cache-Control "public, max-age=3600, must-revalidate" env=!IS_VER
</FilesMatch> </FilesMatch>
<FilesMatch "\.(png|jpe?g|gif|webp|svg|ico|woff2?|ttf|otf)$"> # Images/fonts: long cache if ?v= present, else 7d
Header set Cache-Control "public, max-age=604800" env=!has_version_param <FilesMatch "\.(?:png|jpe?g|gif|webp|svg|ico|woff2?|ttf|otf)$">
</FilesMatch> Header set Cache-Control "public, max-age=31536000, immutable" env=IS_VER
Header set Cache-Control "public, max-age=604800" env=!IS_VER
<FilesMatch "\.(js|css|png|jpe?g|gif|webp|svg|ico|woff2?|ttf|otf)$">
Header set Cache-Control "public, max-age=31536000, immutable" env=has_version_param
</FilesMatch> </FilesMatch>
</IfModule> </IfModule>
# Compression (only if module exists) # ---------------- Compression ----------------
<IfModule mod_brotli.c> <IfModule mod_brotli.c>
BrotliCompressionQuality 5 # Do NOT set BrotliCompressionQuality in .htaccess (vhost/server only)
AddOutputFilterByType BROTLI_COMPRESS text/html text/css application/javascript application/json image/svg+xml AddOutputFilterByType BROTLI_COMPRESS text/html text/css application/javascript application/json image/svg+xml
</IfModule> </IfModule>
<IfModule mod_deflate.c> <IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html text/css application/javascript application/json image/svg+xml AddOutputFilterByType DEFLATE text/html text/css application/javascript application/json image/svg+xml
</IfModule> </IfModule>
# Disable TRACE # ---------------- Disable TRACE ----------------
<IfModule mod_rewrite.c>
RewriteCond %{REQUEST_METHOD} ^TRACE RewriteCond %{REQUEST_METHOD} ^TRACE
RewriteRule .* - [F] RewriteRule .* - [F]
</IfModule>

View File

@@ -19,12 +19,8 @@ if (isset($_GET['spec'])) {
<meta charset="utf-8"/> <meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/> <meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>FileRise API Docs</title> <title>FileRise API Docs</title>
<script defer src="/vendor/redoc/redoc.standalone.js?v={{APP_QVER}}"></script>
<!-- Local ReDoc bundle --> <script defer src="/js/redoc-init.js?v={{APP_QVER}}"></script>
<script defer src="/vendor/redoc/redoc.standalone.js?v=1.6.11"></script>
<!-- Your init (also local) -->
<script defer src="/js/redoc-init.js?v=1.6.11"></script>
</head> </head>
<body> <body>
<redoc spec-url="/api.php?spec=1"></redoc> <redoc spec-url="/api.php?spec=1"></redoc>

View File

@@ -0,0 +1,13 @@
<?php
/**
* @OA\Post(
* path="/api/onlyoffice/callback.php",
* summary="ONLYOFFICE save callback",
* tags={"ONLYOFFICE"},
* @OA\Response(response=200, description="OK / error JSON")
* )
*/
declare(strict_types=1);
require_once __DIR__ . '/../../../config/config.php';
require_once PROJECT_ROOT . '/src/controllers/OnlyOfficeController.php';
(new OnlyOfficeController())->callback();

View File

@@ -0,0 +1,17 @@
<?php
/**
* @OA\Get(
* path="/api/onlyoffice/config.php",
* summary="Get editor config for a file (signed URLs, callback)",
* tags={"ONLYOFFICE"},
* @OA\Parameter(name="folder", in="query", @OA\Schema(type="string")),
* @OA\Parameter(name="file", in="query", @OA\Schema(type="string")),
* @OA\Response(response=200, description="Editor config"),
* @OA\Response(response=403, description="Forbidden"),
* @OA\Response(response=404, description="Disabled / Not found")
* )
*/
declare(strict_types=1);
require_once __DIR__ . '/../../../config/config.php';
require_once PROJECT_ROOT . '/src/controllers/OnlyOfficeController.php';
(new OnlyOfficeController())->config();

View File

@@ -0,0 +1,15 @@
<?php
/**
* @OA\Get(
* path="/api/onlyoffice/signed-download.php",
* summary="Serve a signed file blob to ONLYOFFICE",
* tags={"ONLYOFFICE"},
* @OA\Parameter(name="tok", in="query", required=true, @OA\Schema(type="string")),
* @OA\Response(response=200, description="File stream"),
* @OA\Response(response=403, description="Signature/expiry invalid")
* )
*/
declare(strict_types=1);
require_once __DIR__ . '/../../../config/config.php';
require_once PROJECT_ROOT . '/src/controllers/OnlyOfficeController.php';
(new OnlyOfficeController())->signedDownload();

View File

@@ -0,0 +1,13 @@
<?php
/**
* @OA\Get(
* path="/api/onlyoffice/status.php",
* summary="ONLYOFFICE availability & supported extensions",
* tags={"ONLYOFFICE"},
* @OA\Response(response=200, description="Status JSON")
* )
*/
declare(strict_types=1);
require_once __DIR__ . '/../../../config/config.php';
require_once PROJECT_ROOT . '/src/controllers/OnlyOfficeController.php';
(new OnlyOfficeController())->status();

View File

@@ -0,0 +1,9 @@
<?php
// public/api/siteConfig.php
require_once __DIR__ . '/../../config/config.php';
require_once PROJECT_ROOT . '/src/controllers/UserController.php';
$userController = new UserController();
$userController->siteConfig();

View File

@@ -1,6 +1,38 @@
/* =========================================================== /* ===========================================================
GENERAL STYLES & BASE LAYOUT GENERAL STYLES & BASE LAYOUT
=========================================================== */ =========================================================== */
/* Reserve stable space for header + main */
:root { --header-h: 55px; }
.header-container { min-height: var(--header-h); }
img.logo{ width:50px; height:50px; display:block; } /* belt & suspenders for logo sizing */
/* Hidden-but-reserved utility (no clicks) */
.is-visually-hidden {
visibility: hidden;
pointer-events: none;
}
/* After auth: show app, hide login */
#fr-login-tip {
min-height: 40px; /* reserve space */
max-width: 520px;
margin: 8px auto 0;
border-radius: 8px;
padding: 10px 12px;
text-align: left;
margin-bottom: 10px;
}
.main-wrapper{
display:flex; /* or grid—flex is fine here */
gap:5px;
align-items:flex-start;
}
/* GENERAL STYLES */ /* GENERAL STYLES */
body { body {
@@ -24,10 +56,12 @@ body {
padding-left: 4px !important; padding-left: 4px !important;
}@media (min-width: 1300px) { }@media (min-width: 1300px) {
.container-fluid { .container-fluid {
padding-left: 30px !important; padding-left: 20px !important;
padding-right: 30px !important; padding-right: 20px !important;
}} }}
@media (max-width: 600px) {
.zones-toggle { left: 85px !important; }
}
/* =========================================================== /* ===========================================================
HEADER & NAVIGATION HEADER & NAVIGATION
=========================================================== */ =========================================================== */
@@ -35,7 +69,6 @@ body {
/************************************************************/ /************************************************************/
/* FLEXBOX HEADER: LOGO, TITLE, BUTTONS FIXED */ /* FLEXBOX HEADER: LOGO, TITLE, BUTTONS FIXED */
/************************************************************/ /************************************************************/
.btn-login { .btn-login {
margin-top: 10px; margin-top: 10px;
}/* Color overrides */ }/* Color overrides */
@@ -59,7 +92,7 @@ body {
background-color: #2196F3; background-color: #2196F3;
transition: background-color 0.3s ease; transition: background-color 0.3s ease;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2); box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}body.dark-mode .header-container { }.dark-mode .header-container {
background-color: #1f1f1f; background-color: #1f1f1f;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.7); box-shadow: 0 2px 4px rgba(0, 0, 0, 0.7);
}#darkModeIcon { }#darkModeIcon {
@@ -71,7 +104,7 @@ body {
}.header-logo svg { }.header-logo svg {
height: 50px; height: 50px;
width: auto; width: auto;
}body.dark-mode header { }.dark-mode header {
background-color: #1f1f1f; background-color: #1f1f1f;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.7); box-shadow: 0 2px 4px rgba(0, 0, 0, 0.7);
}.header-left { }.header-left {
@@ -157,7 +190,7 @@ body {
padding: 10px; padding: 10px;
box-shadow: 2px 2px 6px rgba(0, 0, 0, 0.2); box-shadow: 2px 2px 6px rgba(0, 0, 0, 0.2);
}/* Folder Help Tooltip - Dark Mode */ }/* Folder Help Tooltip - Dark Mode */
body.dark-mode .folder-help-tooltip { .dark-mode .folder-help-tooltip {
background-color: #333 !important; background-color: #333 !important;
color: #eee !important; color: #eee !important;
border: 1px solid #555 !important; border: 1px solid #555 !important;
@@ -165,7 +198,7 @@ body {
-webkit-text-fill-color: orange !important; -webkit-text-fill-color: orange !important;
color: inherit !important; color: inherit !important;
padding-right: 10px !important; padding-right: 10px !important;
}body.dark-mode #folderHelpBtn i.material-icons.folder-help-icon { }.dark-mode #folderHelpBtn i.material-icons.folder-help-icon {
-webkit-text-fill-color: #ffa500 !important; -webkit-text-fill-color: #ffa500 !important;
padding-right: 10px !important; padding-right: 10px !important;
}/************************************************************/ }/************************************************************/
@@ -215,8 +248,8 @@ body {
.material-icons.gallery-icon { .material-icons.gallery-icon {
color: black; color: black;
margin-right: 5px; margin-right: 5px;
}body.dark-mode .material-icons.folder-icon, }.dark-mode .material-icons.folder-icon,
body.dark-mode .material-icons.gallery-icon { .dark-mode .material-icons.gallery-icon {
color: white; color: white;
margin-right: 5px; margin-right: 5px;
}.remove-file-btn { }.remove-file-btn {
@@ -247,23 +280,23 @@ body {
padding: 20px; padding: 20px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
border-radius: 4px; border-radius: 4px;
}body.dark-mode #loginForm { }.dark-mode #loginForm {
background-color: #2c2c2c; background-color: #2c2c2c;
color: #e0e0e0; color: #e0e0e0;
padding: 20px; padding: 20px;
border-radius: 8px; border-radius: 8px;
box-shadow: 0 2px 4px rgba(255, 255, 255, 0.2); box-shadow: 0 2px 4px rgba(255, 255, 255, 0.2);
}body.dark-mode #loginForm input { }.dark-mode #loginForm input {
background-color: #333; background-color: #333;
color: #fff; color: #fff;
border: 1px solid #555; border: 1px solid #555;
}body.dark-mode #loginForm label { }.dark-mode #loginForm label {
color: #ddd; color: #ddd;
}body.dark-mode #loginForm button { }.dark-mode #loginForm button {
background-color: #007bff; background-color: #007bff;
color: white; color: white;
border: none; border: none;
}body.dark-mode #loginForm button:hover { }.dark-mode #loginForm button:hover {
background-color: #0056b3; background-color: #0056b3;
}/* =========================================================== }/* ===========================================================
CARDS & MODALS CARDS & MODALS
@@ -286,7 +319,7 @@ body {
border: 1px solid #ccc; border: 1px solid #ccc;
border-radius: 4px; border-radius: 4px;
}/* Override modal content for dark mode */ }/* Override modal content for dark mode */
body.dark-mode #restoreFilesModal .modal-content { .dark-mode #restoreFilesModal .modal-content {
background: #2c2c2c !important; background: #2c2c2c !important;
border: 1px solid #555 !important; border: 1px solid #555 !important;
color: #f0f0f0; color: #f0f0f0;
@@ -370,7 +403,7 @@ body {
transform: translate(-50%, -70%); transform: translate(-50%, -70%);
}} }}
body.dark-mode .modal .modal-content { .dark-mode .modal .modal-content {
background-color: #2c2c2c; background-color: #2c2c2c;
color: #e0e0e0; color: #e0e0e0;
border-color: #444; border-color: #444;
@@ -399,10 +432,10 @@ body {
background-color: #ff4d4d; background-color: #ff4d4d;
box-shadow: 0px 0px 6px rgba(255, 77, 77, 0.8); box-shadow: 0px 0px 6px rgba(255, 77, 77, 0.8);
transform: scale(1.05); transform: scale(1.05);
}body.dark-mode .editor-close-btn { }.dark-mode .editor-close-btn {
background-color: rgba(0, 0, 0, 0.7); background-color: rgba(0, 0, 0, 0.7);
color: #ff6666; color: #ff6666;
}body.dark-mode .editor-close-btn:hover { }.dark-mode .editor-close-btn:hover {
background-color: #ff6666; background-color: #ff6666;
color: #000; color: #000;
}/* Editor Modal */ }/* Editor Modal */
@@ -428,7 +461,7 @@ body {
width: 100% !important; width: 100% !important;
resize: none !important; resize: none !important;
overflow: auto !important; overflow: auto !important;
}body.dark-mode .editor-modal { }.dark-mode .editor-modal {
background-color: #2c2c2c; background-color: #2c2c2c;
color: #e0e0e0; color: #e0e0e0;
border-color: #444; border-color: #444;
@@ -453,7 +486,7 @@ body {
}.editor-title { }.editor-title {
margin: 0; margin: 0;
line-height: 33px; line-height: 33px;
}body.dark-mode .editor-header { }.dark-mode .editor-header {
background-color: #2c2c2c; background-color: #2c2c2c;
}@media (max-width: 600px) { }@media (max-width: 600px) {
.editor-title { .editor-title {
@@ -521,9 +554,9 @@ body {
padding: 4px; padding: 4px;
border-radius: 4px; border-radius: 4px;
transition: background-color 0.2s ease, color 0.2s ease; transition: background-color 0.2s ease, color 0.2s ease;
}body.dark-mode .material-icons.pauseResumeBtn { }.dark-mode .material-icons.pauseResumeBtn {
color: white !important; color: white !important;
}body.dark-mode .material-icons.pauseResumeBtn:hover { }.dark-mode .material-icons.pauseResumeBtn:hover {
background-color: rgba(255, 215, 0, 0.3); background-color: rgba(255, 215, 0, 0.3);
color: #fff; color: #fff;
}body:not(.dark-mode) .material-icons.pauseResumeBtn:hover { }body:not(.dark-mode) .material-icons.pauseResumeBtn:hover {
@@ -626,15 +659,15 @@ body {
}#createBtn { }#createBtn {
background-color: #007bff; background-color: #007bff;
color: white; color: white;
}body.dark-mode .dropdown-menu { }.dark-mode .dropdown-menu {
background-color: #2c2c2c !important; background-color: #2c2c2c !important;
border-color: #444 !important; border-color: #444 !important;
color: #e0e0e0!important; color: #e0e0e0!important;
}body.dark-mode .dropdown-menu .dropdown-item { }.dark-mode .dropdown-menu .dropdown-item {
color: #e0e0e0 !important; color: #e0e0e0 !important;
}.dropdown-item:hover { }.dropdown-item:hover {
background-color: rgba(0,0,0,0.05); background-color: rgba(0,0,0,0.05);
}body.dark-mode .dropdown-item:hover { }.dark-mode .dropdown-item:hover {
background-color: rgba(255,255,255,0.1); background-color: rgba(255,255,255,0.1);
}#fileList button.edit-btn { }#fileList button.edit-btn {
background-color: #007bff; background-color: #007bff;
@@ -655,7 +688,7 @@ body {
background-color: transparent; background-color: transparent;
}#fileList table tr:hover { }#fileList table tr:hover {
background-color: #e0e0e0; background-color: #e0e0e0;
}body.dark-mode #fileList table tr:hover { }.dark-mode #fileList table tr:hover {
background-color: #444; background-color: #444;
}#fileListTitle { }#fileListTitle {
white-space: normal !important; white-space: normal !important;
@@ -673,7 +706,7 @@ body {
box-shadow: none; box-shadow: none;
border: none !important; border: none !important;
outline: none !important; outline: none !important;
}body.dark-mode #fileList table tr { }.dark-mode #fileList table tr {
box-shadow: none; box-shadow: none;
border: none !important; border: none !important;
outline: none !important; outline: none !important;
@@ -757,7 +790,7 @@ body {
color: inherit; color: inherit;
cursor: pointer; cursor: pointer;
padding: 0; padding: 0;
}#loginForm, }
#uploadForm { #uploadForm {
display: none; display: none;
}.folder-actions { }.folder-actions {
@@ -818,7 +851,7 @@ body {
color: #fff; color: #fff;
}.row-selected { }.row-selected {
background-color: #f2f2f2 !important; background-color: #f2f2f2 !important;
}body.dark-mode .row-selected { }.dark-mode .row-selected {
background-color: #444 !important; background-color: #444 !important;
color: #fff !important; color: #fff !important;
}.custom-prev-next-btn { }.custom-prev-next-btn {
@@ -832,11 +865,11 @@ body {
cursor: pointer; cursor: pointer;
}.custom-prev-next-btn:hover:not(:disabled) { }.custom-prev-next-btn:hover:not(:disabled) {
background-color: #d5d5d5; background-color: #d5d5d5;
}body.dark-mode .custom-prev-next-btn { }.dark-mode .custom-prev-next-btn {
background-color: #444; background-color: #444;
color: #fff; color: #fff;
border: none; border: none;
}body.dark-mode .custom-prev-next-btn:hover:not(:disabled) { }.dark-mode .custom-prev-next-btn:hover:not(:disabled) {
background-color: #555; background-color: #555;
}#customToast { }#customToast {
position: fixed; position: fixed;
@@ -873,6 +906,10 @@ body {
line-height: 1 !important; line-height: 1 !important;
vertical-align: middle !important; vertical-align: middle !important;
}#fileListContainer { }#fileListContainer {
border: 1px solid #e0e0e0;
background: white;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
border-radius: 8px;
max-width: 100%; max-width: 100%;
padding-bottom: 10px !important; padding-bottom: 10px !important;
padding-left: 5px !important; padding-left: 5px !important;
@@ -883,7 +920,7 @@ body {
width: 99%; width: 99%;
}} }}
body.dark-mode #fileListContainer { .dark-mode #fileListContainer {
background-color: #2c2c2c; background-color: #2c2c2c;
color: #e0e0e0; color: #e0e0e0;
border: 1px solid #444; border: 1px solid #444;
@@ -932,7 +969,7 @@ body {
align-items: stretch; align-items: stretch;
}.file-list-actions .action-btn { }.file-list-actions .action-btn {
width: 100%; width: 100%;
height: 10px !important;
}.modal-content { }.modal-content {
width: 95%; width: 95%;
margin: 20% auto; margin: 20% auto;
@@ -959,7 +996,7 @@ body {
#copySelectedBtn:hover, #copySelectedBtn:hover,
#moveSelectedBtn:hover, #moveSelectedBtn:hover,
#downloadZipBtn:hover, #downloadZipBtn:hover,
#extractZipBtn:hover #extractZipBtn:hover,
#customChooseBtn:hover { #customChooseBtn:hover {
transform: scale(1.08); transform: scale(1.08);
box-shadow: 0 2px 10px rgba(0,0,0,.12); box-shadow: 0 2px 10px rgba(0,0,0,.12);
@@ -1116,12 +1153,12 @@ body {
background-color: #d0d0d0; background-color: #d0d0d0;
border-radius: 4px; border-radius: 4px;
padding: 2px 4px; padding: 2px 4px;
}body.dark-mode .folder-option.selected { }.dark-mode .folder-option.selected {
background-color: #444; background-color: #444;
color: #fff; color: #fff;
border-radius: 4px; border-radius: 4px;
padding: 2px 4px; padding: 2px 4px;
}body.dark-mode .folder-option:hover { }.dark-mode .folder-option:hover {
background-color: #333; background-color: #333;
color: #fff; color: #fff;
padding: 2px 4px; padding: 2px 4px;
@@ -1161,7 +1198,7 @@ body {
display: inline-flex !important; display: inline-flex !important;
}} }}
body.dark-mode .image-preview-modal-content { .dark-mode .image-preview-modal-content {
background: #2c2c2c; background: #2c2c2c;
border-color: #444; border-color: #444;
}.image-modal-img { }.image-modal-img {
@@ -1198,13 +1235,13 @@ body {
width: 600px !important; width: 600px !important;
max-width: 90vw !important; max-width: 90vw !important;
/* ensures it doesn't exceed the viewport width */ /* ensures it doesn't exceed the viewport width */
}body.dark-mode .close-image-modal { }.dark-mode .close-image-modal {
background-color: rgba(0, 0, 0, 0.6); background-color: rgba(0, 0, 0, 0.6);
color: #ff6666; color: #ff6666;
}body.dark-mode .close-image-modal:hover { }.dark-mode .close-image-modal:hover {
background-color: #ff6666; background-color: #ff6666;
color: #000; color: #000;
}body.dark-mode .image-preview-modal-content { }.dark-mode .image-preview-modal-content {
background: #2c2c2c; background: #2c2c2c;
border-color: #444; border-color: #444;
}.page-indicator { }.page-indicator {
@@ -1217,7 +1254,7 @@ body {
margin-right: 0; margin-right: 0;
margin-left: 0; margin-left: 0;
font-size: 32px; font-size: 32px;
}body.dark-mode .file-icon { }.dark-mode .file-icon {
color: white; color: white;
}.bottom-select { }.bottom-select {
display: inline-block; display: inline-block;
@@ -1315,36 +1352,36 @@ body {
}/* =========================================================== }/* ===========================================================
DARK MODE STYLES DARK MODE STYLES
=========================================================== */ =========================================================== */
body.dark-mode { .dark-mode {
background-color: #121212; background-color: #121212;
color: #e0e0e0; color: #e0e0e0;
}body.dark-mode .container { }.dark-mode .container {
background-color: transparent !important; background-color: transparent !important;
}body.dark-mode .btn-primary { }.dark-mode .btn-primary {
background-color: #007bff; background-color: #007bff;
color: #fff; color: #fff;
border-color: #007bff; border-color: #007bff;
}body.dark-mode .btn-secondary { }.dark-mode .btn-secondary {
background-color: #6c757d; background-color: #6c757d;
color: #fff; color: #fff;
border-color: #6c757d; border-color: #6c757d;
}body.dark-mode .btn-danger { }.dark-mode .btn-danger {
background-color: #dc3545; background-color: #dc3545;
color: #fff; color: #fff;
border-color: #dc3545; border-color: #dc3545;
}body.dark-mode .modal .modal-content, }.dark-mode .modal .modal-content,
body.dark-mode .editor-modal { .dark-mode .editor-modal {
background-color: #2c2c2c; background-color: #2c2c2c;
color: #e0e0e0; color: #e0e0e0;
border: 1px solid #444; border: 1px solid #444;
}body.dark-mode table { }.dark-mode table {
background-color: #2c2c2c; background-color: #2c2c2c;
color: #e0e0e0; color: #e0e0e0;
}body.dark-mode table tr:hover { }.dark-mode table tr:hover {
background-color: #444; background-color: #444;
}body.dark-mode #uploadProgressContainer .progress { }.dark-mode #uploadProgressContainer .progress {
background-color: #333; background-color: #333;
}body.dark-mode #uploadProgressContainer .progress-bar { }.dark-mode #uploadProgressContainer .progress-bar {
background-color: #007bff; background-color: #007bff;
color: #e0e0e0; color: #e0e0e0;
}.dark-mode-toggle { }.dark-mode-toggle {
@@ -1361,10 +1398,10 @@ body {
background-color: rgba(255, 255, 255, 0.15) !important; background-color: rgba(255, 255, 255, 0.15) !important;
}.dark-mode-toggle:active { }.dark-mode-toggle:active {
background-color: rgba(255, 255, 255, 0.25) !important; background-color: rgba(255, 255, 255, 0.25) !important;
}body.dark-mode .dark-mode-toggle { }.dark-mode .dark-mode-toggle {
background-color: transparent !important; background-color: transparent !important;
color: white !important; color: white !important;
}body.dark-mode .dark-mode-toggle:hover { }.dark-mode .dark-mode-toggle:hover {
background-color: rgba(255, 255, 255, 0.15) !important; background-color: rgba(255, 255, 255, 0.15) !important;
}.dark-mode-toggle:focus { }.dark-mode-toggle:focus {
outline: none !important; outline: none !important;
@@ -1391,29 +1428,29 @@ body {
}.folder-help-list { }.folder-help-list {
margin: 0; margin: 0;
padding-left: 20px; padding-left: 20px;
}body.dark-mode .folder-help-details { }.dark-mode .folder-help-details {
color: #ddd; color: #ddd;
background-color: #2c2c2c; background-color: #2c2c2c;
border-color: #444; border-color: #444;
}body.dark-mode .folder-help-summary { }.dark-mode .folder-help-summary {
color: #ddd; color: #ddd;
background: #2c2c2c; background: #2c2c2c;
}body.dark-mode .folder-help-icon { }.dark-mode .folder-help-icon {
color: #f6a72c; color: #f6a72c;
font-size: 20px; font-size: 20px;
}body.dark-mode .CodeMirror { }.dark-mode .CodeMirror {
background: #1e1e1e !important; background: #1e1e1e !important;
color: #ffffff !important; color: #ffffff !important;
}body.dark-mode .CodeMirror-cursor { }.dark-mode .CodeMirror-cursor {
border-left: 2px solid #ffffff !important; border-left: 2px solid #ffffff !important;
}body.dark-mode .CodeMirror-gutters { }.dark-mode .CodeMirror-gutters {
background: #252526 !important; background: #252526 !important;
border-right: 1px solid #444 !important; border-right: 1px solid #444 !important;
}body.dark-mode .CodeMirror-linenumber { }.dark-mode .CodeMirror-linenumber {
color: #aaaaaa !important; color: #aaaaaa !important;
}body.dark-mode .CodeMirror-selected { }.dark-mode .CodeMirror-selected {
background: rgba(255, 255, 255, 0.2) !important; background: rgba(255, 255, 255, 0.2) !important;
}body.dark-mode .CodeMirror-matchingbracket { }.dark-mode .CodeMirror-matchingbracket {
background-color: rgba(255, 255, 255, 0.1) !important; background-color: rgba(255, 255, 255, 0.1) !important;
border-bottom: 1px solid #ffffff !important; border-bottom: 1px solid #ffffff !important;
}.zoom_in, }.zoom_in,
@@ -1448,7 +1485,7 @@ body {
}.drop-hover { }.drop-hover {
background-color: #e0e0e0; background-color: #e0e0e0;
border: 1px dashed #666; border: 1px dashed #666;
}body.dark-mode .drop-hover { }.dark-mode .drop-hover {
background-color: rgba(255, 255, 255, 0.1) !important; background-color: rgba(255, 255, 255, 0.1) !important;
border-bottom: 1px dashed #ffffff !important; border-bottom: 1px dashed #ffffff !important;
}#restoreFilesList li { }#restoreFilesList li {
@@ -1460,35 +1497,33 @@ body {
transform: translateY(-3px) !important; transform: translateY(-3px) !important;
}#restoreFilesList li label { }#restoreFilesList li label {
margin-left: 8px !important; margin-left: 8px !important;
}body.dark-mode #fileContextMenu { }.dark-mode #fileContextMenu {
background-color: #2c2c2c !important; background-color: #2c2c2c !important;
border: 1px solid #555 !important; border: 1px solid #555 !important;
color: #e0e0e0 !important; color: #e0e0e0 !important;
}body.dark-mode #fileContextMenu div { }.dark-mode #fileContextMenu div {
color: #e0e0e0 !important; color: #e0e0e0 !important;
}#folderContextMenu { }#folderContextMenu {
font-family: Arial, sans-serif; font-family: Arial, sans-serif;
font-size: 14px; font-size: 14px;
}body.dark-mode #folderContextMenu { }.dark-mode #folderContextMenu {
background-color: #2c2c2c; background-color: #2c2c2c;
border-color: #555; border-color: #555;
color: #e0e0e0; color: #e0e0e0;
}.main-wrapper {
display: flex;
flex-direction: row;
}.drop-target-sidebar { }.drop-target-sidebar {
display: none; display: none;
width: 50px;
transition: width 0.3s ease;
background-color: #f8f9fa; background-color: #f8f9fa;
border-right: 2px dashed #1565C0; border-right: 2px dashed #1565C0;
padding: 10px; margin-top: 10px;
margin-left: 10px;
}@media (min-width: 769px) { }@media (min-width: 769px) {
.drop-target-sidebar { .drop-target-sidebar {
display: block; display: block;
}} }}
.drop-target-sidebar.active { .drop-target-sidebar.active,
.drag-header.active {
width: 350px; width: 350px;
height: 750px;
}.main-column { }.main-column {
flex: 1; flex: 1;
transition: margin-left 0.3s ease; transition: margin-left 0.3s ease;
@@ -1557,13 +1592,12 @@ body {
}#sidebarDropArea, }#sidebarDropArea,
#uploadFolderRow { #uploadFolderRow {
background-color: transparent; background-color: transparent;
}#sidebarDropArea {
display: none; }.dark-mode #sidebarDropArea,
}body.dark-mode #sidebarDropArea, .dark-mode #uploadFolderRow {
body.dark-mode #uploadFolderRow {
background-color: transparent; background-color: transparent;
}body.dark-mode #sidebarDropArea.highlight, }.dark-mode #sidebarDropArea.highlight,
body.dark-mode #uploadFolderRow.highlight { .dark-mode #uploadFolderRow.highlight {
background-color: #333; background-color: #333;
border: 2px dashed #555; border: 2px dashed #555;
color: #fff; color: #fff;
@@ -1582,7 +1616,7 @@ body {
max-width: 900px; max-width: 900px;
width: 100%; width: 100%;
margin: 0 auto; margin: 0 auto;
}body.dark-mode .card { }.dark-mode .card {
background-color: #2c2c2c; background-color: #2c2c2c;
color: #e0e0e0; color: #e0e0e0;
border: 1px solid #444; border: 1px solid #444;
@@ -1596,21 +1630,21 @@ body {
#removeUserModal { #removeUserModal {
z-index: 5000 !important; z-index: 5000 !important;
}#customConfirmModal { }#customConfirmModal {
z-index: 6000 !important; z-index: 12000 !important;
}.admin-panel-content { }.admin-panel-content {
background: #fff; background: #fff;
color: #000; color: #000;
}body.dark-mode .admin-panel-content { }.dark-mode .admin-panel-content {
background: #2c2c2c; background: #2c2c2c;
color: #e0e0e0; color: #e0e0e0;
border: 1px solid #444; border: 1px solid #444;
}body.dark-mode .admin-panel-content input, }.dark-mode .admin-panel-content input,
body.dark-mode .admin-panel-content select, .dark-mode .admin-panel-content select,
body.dark-mode .admin-panel-content textarea { .dark-mode .admin-panel-content textarea {
background: #3a3a3a; background: #3a3a3a;
color: #e0e0e0; color: #e0e0e0;
border: 1px solid #555; border: 1px solid #555;
}body.dark-mode .admin-panel-content label { }.dark-mode .admin-panel-content label {
color: #e0e0e0; color: #e0e0e0;
}#openChangePasswordModalBtn { }#openChangePasswordModalBtn {
width: max-content; width: max-content;
@@ -1631,7 +1665,7 @@ body {
color: var(--download-spinner-color, #000); color: var(--download-spinner-color, #000);
}body:not(.dark-mode) { }body:not(.dark-mode) {
--download-spinner-color: #000; --download-spinner-color: #000;
}body.dark-mode { }.dark-mode {
--download-spinner-color: #fff; --download-spinner-color: #fff;
}.rise-effect { }.rise-effect {
transform: translateY(-20px); transform: translateY(-20px);
@@ -1666,7 +1700,7 @@ body {
background-color: transparent; background-color: transparent;
transition: width 0.3s ease; transition: width 0.3s ease;
box-sizing: border-box; box-sizing: border-box;
}body.dark-mode .header-drop-zone.drag-active { }.dark-mode .header-drop-zone.drag-active {
background-color: #333; background-color: #333;
border: 2px dashed #555; border: 2px dashed #555;
color: #fff; color: #fff;
@@ -1697,16 +1731,16 @@ body {
line-height: 1; line-height: 1;
margin: 0; margin: 0;
padding: 0; padding: 0;
}body.dark-mode #fileSummary { }.dark-mode #fileSummary {
color: white; color: white;
}#searchIcon { }#searchIcon {
border-radius: 4px; border-radius: 4px;
padding: 4px 8px; padding: 4px 8px;
}body.dark-mode #searchIcon { }.dark-mode #searchIcon {
background-color: #444; background-color: #444;
border: 1px solid #555; border: 1px solid #555;
color: #fff; color: #fff;
}body.dark-mode #searchInput { }.dark-mode #searchInput {
background-color: #333; background-color: #333;
color: #e0e0e0; color: #e0e0e0;
border: 1px solid #555; border: 1px solid #555;
@@ -1731,11 +1765,11 @@ body {
.btn-icon:focus { .btn-icon:focus {
background: rgba(0, 0, 0, 0.1); background: rgba(0, 0, 0, 0.1);
outline: none; outline: none;
}body.dark-mode .btn-icon .material-icons, }.dark-mode .btn-icon .material-icons,
body.dark-mode #searchIcon .material-icons { .dark-mode #searchIcon .material-icons {
color: #fff; color: #fff;
}body.dark-mode .btn-icon:hover, }.dark-mode .btn-icon:hover,
body.dark-mode .btn-icon:focus { .dark-mode .btn-icon:focus {
background: rgba(255, 255, 255, 0.1); background: rgba(255, 255, 255, 0.1);
}.user-dropdown { }.user-dropdown {
position: relative; position: relative;
@@ -1766,12 +1800,12 @@ body {
display: inline-block; display: inline-block;
vertical-align: middle; vertical-align: middle;
margin-left: 0.25rem; margin-left: 0.25rem;
}body.dark-mode .user-dropdown .user-menu { }.dark-mode .user-dropdown .user-menu {
background: #2c2c2c; background: #2c2c2c;
border-color: #444; border-color: #444;
}body.dark-mode .user-dropdown .user-menu .item { }.dark-mode .user-dropdown .user-menu .item {
color: #e0e0e0; color: #e0e0e0;
}body.dark-mode .user-dropdown .user-menu .item:hover { }.dark-mode .user-dropdown .user-menu .item:hover {
background: rgba(255,255,255,0.1); background: rgba(255,255,255,0.1);
}.user-dropdown .dropdown-username { }.user-dropdown .dropdown-username {
margin: 0 8px; margin: 0 8px;
@@ -1808,7 +1842,7 @@ body {
}:root { }:root {
--perm-caret: #444; --perm-caret: #444;
}/* light */ }/* light */
body.dark-mode { .dark-mode {
--perm-caret: #ccc; --perm-caret: #ccc;
}/* dark */ }/* dark */
@@ -1821,7 +1855,7 @@ body {
background-color 160ms cubic-bezier(.2,.0,.2,1); background-color 160ms cubic-bezier(.2,.0,.2,1);
}:root { }:root {
--toggle-icon-color: #333; --toggle-icon-color: #333;
}body.dark-mode { }.dark-mode {
--toggle-icon-color: #eee; --toggle-icon-color: #eee;
}#zonesToggleFloating .material-icons, }#zonesToggleFloating .material-icons,
#zonesToggleFloating .material-icons-outlined, #zonesToggleFloating .material-icons-outlined,
@@ -1865,4 +1899,5 @@ body {
#sidebarToggleFloating.is-collapsed { #sidebarToggleFloating.is-collapsed {
background: #fafafa; background: #fafafa;
border-color: #e2e2e2; border-color: #e2e2e2;
} }

View File

@@ -4,7 +4,7 @@
font-style: normal; font-style: normal;
font-weight: 400; font-weight: 400;
font-display: swap; font-display: swap;
src: url(/fonts/material-icons/flUhRq6tzZclQEJ-Vdg-IuiaDsNcIhQ8tQ.woff2) format('woff2'); src: url('/fonts/material-icons/flUhRq6tzZclQEJ-Vdg-IuiaDsNcIhQ8tQ.woff2?v={{APP_QVER}}') format('woff2');
} }
.material-icons { .material-icons {

View File

@@ -4,7 +4,7 @@
font-style:normal; font-style:normal;
font-weight:400; font-weight:400;
font-display:swap; font-display:swap;
src:url('/fonts/roboto/KFO7CnqEu92Fr1ME7kSn66aGLdTylUAMa3KUBHMdazTgWw.woff2') format('woff2'); src:url('/fonts/roboto/KFO7CnqEu92Fr1ME7kSn66aGLdTylUAMa3KUBHMdazTgWw.woff2?v={{APP_QVER}}') format('woff2');
unicode-range:U+0100-02BA,U+02BD-02C5,U+02C7-02CC,U+02CE-02D7,U+02DD-02FF,U+0304,U+0308,U+0329,U+1D00-1DBF,U+1E00-1E9F,U+1EF2-1EFF,U+2020,U+20A0-20AB,U+20AD-20C0,U+2113,U+2C60-2C7F,U+A720-A7FF; unicode-range:U+0100-02BA,U+02BD-02C5,U+02C7-02CC,U+02CE-02D7,U+02DD-02FF,U+0304,U+0308,U+0329,U+1D00-1DBF,U+1E00-1E9F,U+1EF2-1EFF,U+2020,U+20A0-20AB,U+20AD-20C0,U+2113,U+2C60-2C7F,U+A720-A7FF;
} }
/* Roboto Regular 400 — latin */ /* Roboto Regular 400 — latin */
@@ -13,7 +13,7 @@
font-style:normal; font-style:normal;
font-weight:400; font-weight:400;
font-display:swap; font-display:swap;
src:url('/fonts/roboto/KFO7CnqEu92Fr1ME7kSn66aGLdTylUAMa3yUBHMdazQ.woff2') format('woff2'); src:url('/fonts/roboto/KFO7CnqEu92Fr1ME7kSn66aGLdTylUAMa3yUBHMdazQ.woff2?v={{APP_QVER}}') format('woff2');
unicode-range:U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,U+2000-206F,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD; unicode-range:U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,U+2000-206F,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD;
} }
/* Roboto Medium 500 — latin-ext */ /* Roboto Medium 500 — latin-ext */
@@ -22,7 +22,7 @@
font-style:normal; font-style:normal;
font-weight:500; font-weight:500;
font-display:swap; font-display:swap;
src:url('/fonts/roboto/KFO7CnqEu92Fr1ME7kSn66aGLdTylUAMa3KUBHMdazTgWw.woff2') format('woff2'); src:url('/fonts/roboto/KFO7CnqEu92Fr1ME7kSn66aGLdTylUAMa3KUBHMdazTgWw.woff2?v={{APP_QVER}}') format('woff2');
unicode-range:U+0100-02BA,U+02BD-02C5,U+02C7-02CC,U+02CE-02D7,U+02DD-02FF,U+0304,U+0308,U+0329,U+1D00-1DBF,U+1E00-1E9F,U+1EF2-1EFF,U+2020,U+20A0-20AB,U+20AD-20C0,U+2113,U+2C60-2C7F,U+A720-A7FF; unicode-range:U+0100-02BA,U+02BD-02C5,U+02C7-02CC,U+02CE-02D7,U+02DD-02FF,U+0304,U+0308,U+0329,U+1D00-1DBF,U+1E00-1E9F,U+1EF2-1EFF,U+2020,U+20A0-20AB,U+20AD-20C0,U+2113,U+2C60-2C7F,U+A720-A7FF;
} }
/* Roboto Medium 500 — latin */ /* Roboto Medium 500 — latin */
@@ -31,7 +31,7 @@
font-style:normal; font-style:normal;
font-weight:500; font-weight:500;
font-display:swap; font-display:swap;
src:url('/fonts/roboto/KFO7CnqEu92Fr1ME7kSn66aGLdTylUAMa3yUBHMdazQ.woff2') format('woff2'); src:url('/fonts/roboto/KFO7CnqEu92Fr1ME7kSn66aGLdTylUAMa3yUBHMdazQ.woff2?v={{APP_QVER}}') format('woff2');
unicode-range:U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,U+2000-206F,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD; unicode-range:U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,U+2000-206F,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD;
} }

View File

@@ -2,116 +2,59 @@
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="UTF-8" /> <meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1"><title>FileRise</title>
<meta name="viewport" content="width=device-width, initial-scale=1" /> <script>(function(){try{var s=localStorage.getItem('darkMode');var isDark=(s===null)?(window.matchMedia&&window.matchMedia('(prefers-color-scheme: dark)').matches):(s==='1'||s==='true');var root=document.documentElement;root.setAttribute('data-theme',isDark?'dark':'light');root.classList.toggle('dark-mode',isDark);var bg=isDark?'#121212':'#ffffff';root.style.backgroundColor=bg;root.style.colorScheme=isDark?'dark':'light';root.style.setProperty('--pre-bg',bg);var m=document.querySelector('meta[name="theme-color"]');if(m)m.setAttribute('content',bg);}catch(e){}})();</script>
<title>FileRise</title> <style id="pretheme-css">
<link rel="icon" type="image/png" href="/assets/logo.png"> html,body,#loadingOverlay{background:var(--pre-bg,#ffffff) !important;}
<link rel="icon" type="image/svg+xml" href="/assets/logo.svg"> </style>
<meta name="csrf-token" content=""> <link rel="icon" type="image/png" href="/assets/logo.png"><link rel="icon" type="image/svg+xml" href="/assets/logo.svg">
<meta name="share-url" content=""> <meta name="description" content="FileRise is a fast, self-hosted file manager with granular per-folder ACLs, drag-and-drop folder moves, WebDAV, tagging, and a clean UI.">
<meta name="csrf-token" content=""><meta name="share-url" content=""><meta name="theme-color" content="#0b5ed7"><meta name="color-scheme" content="light dark">
<style>.main-wrapper{display:none}#loadingOverlay{position:fixed;inset:0;background:var(--bg-color,#fff);z-index:9999;display:flex;align-items:center;justify-content:center}</style>
<link rel="stylesheet" href="/css/vendor/roboto.css?v=1.6.11"> <!-- Critical CSS -->
<link rel="stylesheet" href="/css/vendor/material-icons.css?v=1.6.11"> <link rel="stylesheet" href="/vendor/bootstrap/4.5.2/bootstrap.min.css?v={{APP_QVER}}">
<link rel="stylesheet" href="/css/styles.css?v={{APP_QVER}}">
<!-- Bootstrap CSS (local) --> <link rel="stylesheet" href="/css/vendor/roboto.css?v={{APP_QVER}}">
<link rel="stylesheet" href="/vendor/bootstrap/4.5.2/bootstrap.min.css?v=1.6.11">
<!-- Fonts (ok to keep as real preloads) -->
<!-- CodeMirror CSS (local) --> <link rel="preload" as="font" href="/fonts/roboto/KFO7CnqEu92Fr1ME7kSn66aGLdTylUAMa3KUBHMdazTgWw.woff2?v={{APP_QVER}}" type="font/woff2" crossorigin>
<link rel="stylesheet" href="/vendor/codemirror/5.65.5/codemirror.min.css?v=1.6.11"> <link rel="preload" as="font" href="/fonts/roboto/KFO7CnqEu92Fr1ME7kSn66aGLdTylUAMa3yUBHMdazQ.woff2?v={{APP_QVER}}" type="font/woff2" crossorigin>
<link rel="stylesheet" href="/vendor/codemirror/5.65.5/theme/material-darker.min.css?v=1.6.11">
<!-- Vendor & version (deferred) -->
<!-- app CSS --> <script src="/vendor/dompurify/2.4.0/purify.min.js?v={{APP_QVER}}" defer></script>
<link rel="stylesheet" href="/css/styles.css?v=1.6.11"> <script src="/js/version.js?v={{APP_QVER}}" defer></script>
<!-- Libraries (JS) --> <!-- App entry -->
<script src="/vendor/dompurify/2.4.0/purify.min.js?v=1.6.11"></script> <link rel="modulepreload" href="/js/main.js?v={{APP_QVER}}"><script type="module" src="/js/main.js?v={{APP_QVER}}"></script>
<script src="/vendor/fuse/6.6.2/fuse.min.js?v=1.6.11"></script> </head>
<script src="/vendor/resumable/1.1.0/resumable.min.js?v=1.6.11"></script>
<!-- CodeMirror core FIRST, then modes -->
<script src="/vendor/codemirror/5.65.5/codemirror.min.js?v=1.6.11"></script>
<script src="/js/version.js?v=1.6.11"></script>
<script type="module" src="/js/main.js"></script>
</head>
<body> <body>
<div id="appRoot" style="visibility:hidden">
<header class="header-container"> <header class="header-container">
<div class="header-left"> <div class="header-left">
<a href="index.html"> <a href="index.html">
<div class="header-logo"> <div class="header-logo">
<svg version="1.1" id="filingCabinetLogo" xmlns="http://www.w3.org/2000/svg" <img
xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 64 64" xml:space="preserve"> src="/assets/logo.svg?v={{APP_QVER}}"
<defs> alt="FileRise"
<!-- Gradient for the cabinet body --> class="logo"
<linearGradient id="cabinetGradient" x1="0%" y1="0%" x2="0%" y2="100%"> width="50"
<stop offset="0%" style="stop-color:#2196F3;stop-opacity:1" /> height="50"
<stop offset="100%" style="stop-color:#1976D2;stop-opacity:1" /> decoding="async"
</linearGradient> fetchpriority="high"
<!-- Drop shadow filter with animated attributes for a lifting effect --> />
<filter id="shadowFilter" x="-20%" y="-20%" width="140%" height="140%">
<feDropShadow id="dropShadow" dx="0" dy="2" stdDeviation="2" flood-color="#000" flood-opacity="0.2">
<!-- Animate the vertical offset: from 2 to 1 (as it rises), hold, then back to 2 -->
<animate attributeName="dy" values="2;1;1;2" keyTimes="0;0.2;0.8;1" dur="5s" fill="freeze" />
<!-- Animate the blur similarly: from 2 to 1.5 then back to 2 -->
<animate attributeName="stdDeviation" values="2;1.5;1.5;2" keyTimes="0;0.2;0.8;1" dur="5s"
fill="freeze" />
</feDropShadow>
</filter>
</defs>
<style type="text/css">
/* Cabinet with gradient, white outline, and drop shadow */
.cabinet {
fill: url(#cabinetGradient);
stroke: white;
stroke-width: 2;
}
.divider {
stroke: #1565C0;
stroke-width: 1.5;
}
.drawer {
fill: #FFFFFF;
}
.handle {
fill: #1565C0;
}
</style>
<!-- Group that will animate upward and then back down once -->
<g id="cabinetGroup">
<!-- Cabinet Body with rounded corners, white outline, and drop shadow -->
<rect x="4" y="4" width="56" height="56" rx="6" ry="6" class="cabinet" filter="url(#shadowFilter)" />
<!-- Divider lines for drawers -->
<line x1="5" y1="22" x2="59" y2="22" class="divider" />
<line x1="5" y1="34" x2="59" y2="34" class="divider" />
<!-- Drawers with Handles -->
<rect x="8" y="24" width="48" height="6" rx="1" ry="1" class="drawer" />
<circle cx="54" cy="27" r="1.5" class="handle" />
<rect x="8" y="36" width="48" height="6" rx="1" ry="1" class="drawer" />
<circle cx="54" cy="39" r="1.5" class="handle" />
<rect x="8" y="48" width="48" height="6" rx="1" ry="1" class="drawer" />
<circle cx="54" cy="51" r="1.5" class="handle" />
<!-- Additional detail: a small top handle on the cabinet door -->
<rect x="28" y="10" width="8" height="4" rx="1" ry="1" fill="#1565C0" />
<!-- Animate transform: rises by 2 pixels over 1s, holds for 3s, then falls over 1s (total 5s) -->
<animateTransform attributeName="transform" type="translate" values="0 0; 0 -2; 0 -2; 0 0"
keyTimes="0;0.2;0.8;1" dur="5s" fill="freeze" />
</g>
</svg>
</div> </div>
</a> </a>
</div> </div>
<div class="header-title"> <div class="header-title">
<h1 data-i18n-key="header_title">FileRise</h1> <h1>FileRise</h1>
</div> </div>
<div class="header-right"> <div class="header-right">
<div class="header-buttons-wrapper" style="display: flex; align-items: center; gap: 10px;"> <div class="header-buttons-wrapper" style="display: flex; align-items: center; gap: 10px;">
<!-- Your header drop zone -->
<div id="headerDropArea" class="header-drop-zone"></div> <div id="headerDropArea" class="header-drop-zone"></div>
<div class="header-buttons"> <div class="header-buttons">
<button id="changePasswordBtn" data-i18n-title="change_password" style="display: none;"> <button id="changePasswordBtn" data-i18n-title="change_password" style="display: none;">
@@ -130,7 +73,7 @@
<!-- Trash items will be loaded here --> <!-- Trash items will be loaded here -->
</div> </div>
<div style="text-align: right;"> <div style="text-align: right;">
<button id="restoreSelectedBtn" class="btn btn-primary" data-i18n-key="restore_selected">Restore <button id="restoreSelectedBtn" class="btn btn-primary" data-i18n-key="restore_selected" style="display: none;">Restore
Selected</button> Selected</button>
<button id="restoreAllBtn" class="btn btn-secondary" data-i18n-key="restore_all">Restore All</button> <button id="restoreAllBtn" class="btn btn-secondary" data-i18n-key="restore_all">Restore All</button>
<button id="deleteTrashSelectedBtn" class="btn btn-warning" data-i18n-key="delete_selected_trash">Delete <button id="deleteTrashSelectedBtn" class="btn btn-warning" data-i18n-key="delete_selected_trash">Delete
@@ -146,7 +89,7 @@
<button id="removeUserBtn" data-i18n-title="remove_user" style="display: none;"> <button id="removeUserBtn" data-i18n-title="remove_user" style="display: none;">
<i class="material-icons">person_remove</i> <i class="material-icons">person_remove</i>
</button> </button>
<button id="darkModeToggle" class="btn-icon" aria-label="Toggle dark mode"> <button id="darkModeToggle" class="btn-icon" aria-label="Toggle dark mode" hidden>
<span class="material-icons" id="darkModeIcon"> <span class="material-icons" id="darkModeIcon">
dark_mode dark_mode
</span> </span>
@@ -155,15 +98,18 @@
</div> </div>
</div> </div>
</header> </header>
<div id="loadingOverlay"></div> <div id="loadingOverlay"></div>
<!-- Custom Toast Container --> <!-- Custom Toast Container -->
<div id="customToast"></div> <div id="customToast"></div>
<div id="hiddenCardsContainer" style="display:none;"></div> <div id="hiddenCardsContainer" style="display:none;"></div>
<main id="main" hidden>
<div class="row mt-4" id="loginForm"> <div class="row mt-4" id="loginForm">
<div class="col-12"> <div class="col-12">
<div id="loginBox" class="login-box">
<div id="fr-login-tip" class="alert alert-info login-hint" role="status" aria-live="polite" style="display:none;"></div>
<form id="authForm" method="post"> <form id="authForm" method="post">
<div class="form-group"> <div class="form-group">
<label for="loginUsername" data-i18n-key="user">User:</label> <label for="loginUsername" data-i18n-key="user">User:</label>
@@ -173,7 +119,7 @@
<label for="loginPassword" data-i18n-key="password">Password:</label> <label for="loginPassword" data-i18n-key="password">Password:</label>
<input type="password" class="form-control" id="loginPassword" name="password" required /> <input type="password" class="form-control" id="loginPassword" name="password" required />
</div> </div>
<button type="submit" class="btn btn-primary btn-block btn-login" data-i18n-key="login">Login</button> <button type="submit" class="btn btn-primary btn-block btn-login" data-i18n-key="login" data-default>Login</button>
<div class="form-group remember-me-container"> <div class="form-group remember-me-container">
<input type="checkbox" id="rememberMeCheckbox" name="remember_me" /> <input type="checkbox" id="rememberMeCheckbox" name="remember_me" />
<label for="rememberMeCheckbox" data-i18n-key="remember_me">Remember me</label> <label for="rememberMeCheckbox" data-i18n-key="remember_me">Remember me</label>
@@ -189,11 +135,14 @@
HTTP HTTP
Login</a> Login</a>
</div> </div>
<div>
</div> </div>
</div> </div>
</main>
<!-- Main Wrapper: Hidden by default; remove "display: none;" after login --> <!-- Main Wrapper: Hidden by default; remove "display: none;" after login -->
<div class="main-wrapper"> <div class="main-wrapper" hidden>
<!-- Sidebar Drop Zone: Hidden until you drag a card (display controlled by JS) --> <!-- Sidebar Drop Zone: Hidden until you drag a card (display controlled by JS) -->
<div id="sidebarDropArea" class="drop-target-sidebar"></div> <div id="sidebarDropArea" class="drop-target-sidebar"></div>
<!-- Main Column --> <!-- Main Column -->
@@ -273,7 +222,7 @@
<div class="modal-footer" style="margin-top:15px; text-align:right;"> <div class="modal-footer" style="margin-top:15px; text-align:right;">
<button id="cancelMoveFolder" class="btn btn-secondary" <button id="cancelMoveFolder" class="btn btn-secondary"
data-i18n-key="cancel">Cancel</button> data-i18n-key="cancel">Cancel</button>
<button id="confirmMoveFolder" class="btn btn-primary" data-i18n-key="move">Move</button> <button id="confirmMoveFolder" class="btn btn-primary" data-i18n-key="move" data-default>Move</button>
</div> </div>
</div> </div>
</div> </div>
@@ -291,7 +240,7 @@
<button id="cancelRenameFolder" class="btn btn-secondary" <button id="cancelRenameFolder" class="btn btn-secondary"
data-i18n-key="cancel">Cancel</button> data-i18n-key="cancel">Cancel</button>
<button id="submitRenameFolder" class="btn btn-primary" <button id="submitRenameFolder" class="btn btn-primary"
data-i18n-key="rename">Rename</button> data-i18n-key="rename" data-default>Rename</button>
</div> </div>
</div> </div>
</div> </div>
@@ -311,7 +260,7 @@
<button id="cancelDeleteFolder" class="btn btn-secondary" <button id="cancelDeleteFolder" class="btn btn-secondary"
data-i18n-key="cancel">Cancel</button> data-i18n-key="cancel">Cancel</button>
<button id="confirmDeleteFolder" class="btn btn-danger" <button id="confirmDeleteFolder" class="btn btn-danger"
data-i18n-key="delete">Delete</button> data-i18n-key="delete" data-default>Delete</button>
</div> </div>
</div> </div>
</div> </div>
@@ -347,7 +296,7 @@
selected files?</p> selected files?</p>
<div class="modal-footer"> <div class="modal-footer">
<button id="cancelDeleteFiles" class="btn btn-secondary" data-i18n-key="cancel">Cancel</button> <button id="cancelDeleteFiles" class="btn btn-secondary" data-i18n-key="cancel">Cancel</button>
<button id="confirmDeleteFiles" class="btn btn-danger" data-i18n-key="delete">Delete</button> <button id="confirmDeleteFiles" class="btn btn-danger" data-i18n-key="delete" data-default>Delete</button>
</div> </div>
</div> </div>
</div> </div>
@@ -361,7 +310,7 @@
<select id="copyTargetFolder" class="form-control modal-input"></select> <select id="copyTargetFolder" class="form-control modal-input"></select>
<div class="modal-footer"> <div class="modal-footer">
<button id="cancelCopyFiles" class="btn btn-secondary" data-i18n-key="cancel">Cancel</button> <button id="cancelCopyFiles" class="btn btn-secondary" data-i18n-key="cancel">Cancel</button>
<button id="confirmCopyFiles" class="btn btn-primary" data-i18n-key="copy">Copy</button> <button id="confirmCopyFiles" class="btn btn-primary" data-i18n-key="copy" data-default>Copy</button>
</div> </div>
</div> </div>
</div> </div>
@@ -375,7 +324,7 @@
<select id="moveTargetFolder" class="form-control modal-input"></select> <select id="moveTargetFolder" class="form-control modal-input"></select>
<div class="modal-footer"> <div class="modal-footer">
<button id="cancelMoveFiles" class="btn btn-secondary" data-i18n-key="cancel">Cancel</button> <button id="cancelMoveFiles" class="btn btn-secondary" data-i18n-key="cancel">Cancel</button>
<button id="confirmMoveFiles" class="btn btn-primary" data-i18n-key="move">Move</button> <button id="confirmMoveFiles" class="btn btn-primary" data-i18n-key="move" data-default>Move</button>
</div> </div>
</div> </div>
</div> </div>
@@ -383,35 +332,20 @@
data-i18n-key="download_zip">Download ZIP</button> data-i18n-key="download_zip">Download ZIP</button>
<button id="extractZipBtn" class="btn action-btn btn-sm btn-info" style="display: none;" disabled <button id="extractZipBtn" class="btn action-btn btn-sm btn-info" style="display: none;" disabled
data-i18n-key="extract_zip_button">Extract Zip</button> data-i18n-key="extract_zip_button">Extract Zip</button>
<div id="createDropdown" class="dropdown-container" style="position:relative; display:inline-block;"> <div id="createDropdown" class="dropdown-container" style="position:relative; display:inline-block;">
<button id="createBtn" class="btn action-btn" style="display: none;" data-i18n-key="create"> <button id="createBtn" class="btn action-btn" type="button" style="display:none;" aria-haspopup="true" aria-expanded="false">
${t('create')} <span class="material-icons" <span data-i18n-key="create">Create</span>
style="font-size:16px;vertical-align:middle;">arrow_drop_down</span> <span class="material-icons" style="font-size:16px;vertical-align:middle;">arrow_drop_down</span>
</button> </button>
<ul id="createMenu" class="dropdown-menu" style=" <ul id="createMenu" class="dropdown-menu" style="display:none; position:absolute; top:100%; left:0; margin:4px 0 0; padding:0; list-style:none; background:#fff; border:1px solid #ccc; box-shadow:0 2px 6px rgba(0,0,0,0.2); z-index:10010; min-width:160px;">
display: none; <li id="createFileOption" class="dropdown-item" style="padding:8px 12px; cursor:pointer;">
position: absolute; <span data-i18n-key="create_file">Create file</span>
top: 100%; </li>
left: 0; <li id="createFolderOption" class="dropdown-item" style="padding:8px 12px; cursor:pointer;">
margin: 4px 0 0; <span data-i18n-key="create_folder">Create folder</span>
padding: 0; </li>
list-style: none; </ul>
background: #fff; </div>
border: 1px solid #ccc;
box-shadow: 0 2px 6px rgba(0,0,0,0.2);
z-index: 1000;
min-width: 140px;
">
<li id="createFileOption" class="dropdown-item" data-i18n-key="create_file"
style="padding:8px 12px; cursor:pointer;">
${t('create_file')}
</li>
<li id="createFolderOption" class="dropdown-item" data-i18n-key="create_folder"
style="padding:8px 12px; cursor:pointer;">
${t('create_folder')}
</li>
</ul>
</div>
<!-- Create File Modal --> <!-- Create File Modal -->
<div id="createFileModal" class="modal" style="display:none;"> <div id="createFileModal" class="modal" style="display:none;">
<div class="modal-content"> <div class="modal-content">
@@ -420,7 +354,7 @@
data-i18n-placeholder="newfile_placeholder" /> data-i18n-placeholder="newfile_placeholder" />
<div class="modal-footer" style="margin-top:1rem; text-align:right;"> <div class="modal-footer" style="margin-top:1rem; text-align:right;">
<button id="cancelCreateFile" class="btn btn-secondary" data-i18n-key="cancel">Cancel</button> <button id="cancelCreateFile" class="btn btn-secondary" data-i18n-key="cancel">Cancel</button>
<button id="confirmCreateFile" class="btn btn-primary" data-i18n-key="create">Create</button> <button id="confirmCreateFile" class="btn btn-primary" data-i18n-key="create" data-default>Create</button>
</div> </div>
</div> </div>
</div> </div>
@@ -432,7 +366,7 @@
placeholder="files.zip" /> placeholder="files.zip" />
<div class="modal-footer" style="margin-top:15px; text-align:right;"> <div class="modal-footer" style="margin-top:15px; text-align:right;">
<button id="cancelDownloadZip" class="btn btn-secondary" data-i18n-key="cancel">Cancel</button> <button id="cancelDownloadZip" class="btn btn-secondary" data-i18n-key="cancel">Cancel</button>
<button id="confirmDownloadZip" class="btn btn-primary" data-i18n-key="download">Download</button> <button id="confirmDownloadZip" class="btn btn-primary" data-i18n-key="download" data-default>Download</button>
</div> </div>
</div> </div>
</div> </div>
@@ -470,14 +404,14 @@
placeholder="Filename" /> placeholder="Filename" />
<div style="margin-top: 15px; text-align: right;"> <div style="margin-top: 15px; text-align: right;">
<button id="cancelDownloadFile" class="btn btn-secondary" data-i18n-key="cancel">Cancel</button> <button id="cancelDownloadFile" class="btn btn-secondary" data-i18n-key="cancel">Cancel</button>
<button id="confirmSingleDownloadButton" class="btn btn-primary" data-i18n-key="download">Download</button> <button id="confirmSingleDownloadButton" class="btn btn-primary" data-i18n-key="download" data-default>Download</button>
</div> </div>
</div> </div>
</div> </div>
<!-- Change Password, Add User, Remove User, Rename File, and Custom Confirm Modals (unchanged) --> <!-- Change Password, Add User, Remove User, Rename File, and Custom Confirm Modals (unchanged) -->
<div id="changePasswordModal" class="modal" style="display:none;"> <div id="changePasswordModal" class="modal" style="display:none;">
<div class="modal-content" style="max-width:400px; margin:auto;"> <div class="modal-content" style="text-align: center; padding: 20px;">
<span id="closeChangePasswordModal" class="editor-close-btn">&times;</span> <span id="closeChangePasswordModal" class="editor-close-btn">&times;</span>
<h3 data-i18n-key="change_password_title">Change Password</h3> <h3 data-i18n-key="change_password_title">Change Password</h3>
<input type="password" id="oldPassword" class="form-control" data-i18n-placeholder="old_password" <input type="password" id="oldPassword" class="form-control" data-i18n-placeholder="old_password"
@@ -486,7 +420,7 @@
placeholder="New Password" style="width:100%; margin: 5px 0;" /> placeholder="New Password" style="width:100%; margin: 5px 0;" />
<input type="password" id="confirmPassword" class="form-control" data-i18n-placeholder="confirm_new_password" <input type="password" id="confirmPassword" class="form-control" data-i18n-placeholder="confirm_new_password"
placeholder="Confirm New Password" style="width:100%; margin: 5px 0;" /> placeholder="Confirm New Password" style="width:100%; margin: 5px 0;" />
<button id="saveNewPasswordBtn" class="btn btn-primary" data-i18n-key="save" style="width:100%;">Save</button> <button id="saveNewPasswordBtn" class="btn btn-primary" data-i18n-key="save" style="width:100%;" data-default>Save</button>
</div> </div>
</div> </div>
<div id="addUserModal" class="modal" style="display:none;"> <div id="addUserModal" class="modal" style="display:none;">
@@ -511,7 +445,7 @@
Cancel Cancel
</button> </button>
<!-- Save becomes type="submit" --> <!-- Save becomes type="submit" -->
<button type="submit" id="saveUserBtn" class="btn btn-primary" data-i18n-key="save_user"> <button type="submit" id="saveUserBtn" class="btn btn-primary" data-i18n-key="save_user" data-default>
Save User Save User
</button> </button>
</div> </div>
@@ -536,7 +470,7 @@
placeholder="Enter new file name" style="margin-top:10px;" /> placeholder="Enter new file name" style="margin-top:10px;" />
<div style="margin-top:15px; text-align:right;"> <div style="margin-top:15px; text-align:right;">
<button id="cancelRenameFile" class="btn btn-secondary" data-i18n-key="cancel">Cancel</button> <button id="cancelRenameFile" class="btn btn-secondary" data-i18n-key="cancel">Cancel</button>
<button id="submitRenameFile" class="btn btn-primary" data-i18n-key="rename">Rename</button> <button id="submitRenameFile" class="btn btn-primary" data-i18n-key="rename" data-default>Rename</button>
</div> </div>
</div> </div>
</div> </div>
@@ -544,12 +478,12 @@
<div class="modal-content"> <div class="modal-content">
<p id="confirmMessage"></p> <p id="confirmMessage"></p>
<div class="modal-actions"> <div class="modal-actions">
<button id="confirmYesBtn" class="btn btn-primary" data-i18n-key="yes">Yes</button> <button id="confirmYesBtn" class="btn btn-primary" data-i18n-key="yes" data-default>Yes</button>
<button id="confirmNoBtn" class="btn btn-secondary" data-i18n-key="no">No</button> <button id="confirmNoBtn" class="btn btn-secondary" data-i18n-key="no">No</button>
</div> </div>
</div> </div>
</div> </div>
</div>
</body> </body>
</html> </html>

File diff suppressed because it is too large Load Diff

177
public/js/appCore.js Normal file
View File

@@ -0,0 +1,177 @@
// /js/appCore.js
import { showToast } from './domUtils.js?v={{APP_QVER}}';
import { t } from './i18n.js?v={{APP_QVER}}';
import { loadFolderTree } from './folderManager.js?v={{APP_QVER}}';
import { setupTrashRestoreDelete } from './trashRestoreDelete.js?v={{APP_QVER}}';
import { initDragAndDrop, loadSidebarOrder, loadHeaderOrder } from './dragAndDrop.js?v={{APP_QVER}}';
import { initTagSearch } from './fileTags.js?v={{APP_QVER}}';
import { initFileActions } from './fileActions.js?v={{APP_QVER}}';
import { initUpload } from './upload.js?v={{APP_QVER}}';
import { loadAdminConfigFunc } from './auth.js?v={{APP_QVER}}';
// Keep a bound handle to the native fetch so wrappers elsewhere never recurse
const _nativeFetch = window.fetch.bind(window);
/* =========================
CSRF UTILITIES (shared)
========================= */
export function setCsrfToken(token) {
if (!token) return;
window.csrfToken = token;
localStorage.setItem('csrf', token);
// meta tag for easy access in other places
let meta = document.querySelector('meta[name="csrf-token"]');
if (!meta) {
meta = document.createElement('meta');
meta.name = 'csrf-token';
document.head.appendChild(meta);
}
meta.content = token;
}
export function getCsrfToken() {
return window.csrfToken || localStorage.getItem('csrf') || '';
}
/**
* Bootstrap/refresh CSRF from the server.
* Uses the native fetch to avoid wrapper loops and accepts rotated tokens via header.
*/
export async function loadCsrfToken() {
const res = await _nativeFetch('/api/auth/token.php', { method: 'GET', credentials: 'include' });
// header-based rotation
const hdr = res.headers.get('X-CSRF-Token');
if (hdr) setCsrfToken(hdr);
// body (if provided)
let body = {};
try { body = await res.json(); } catch { /* token endpoint may return empty */ }
const token = body.csrf_token || getCsrfToken();
setCsrfToken(token);
// share-url meta should reflect the actual origin
const actualShare = window.location.origin;
let shareMeta = document.querySelector('meta[name="share-url"]');
if (!shareMeta) {
shareMeta = document.createElement('meta');
shareMeta.name = 'share-url';
document.head.appendChild(shareMeta);
}
shareMeta.content = actualShare;
return { csrf_token: token, share_url: actualShare };
}
/* =========================
APP INIT (shared)
========================= */
export function initializeApp() {
const saved = parseInt(localStorage.getItem('rowHeight') || '48', 10);
document.documentElement.style.setProperty('--file-row-height', saved + 'px');
const last = localStorage.getItem('lastOpenedFolder');
window.currentFolder = last ? last : "root";
const stored = localStorage.getItem('showFoldersInList');
window.showFoldersInList = stored === null ? true : stored === 'true';
// Load public site config early (safe subset)
loadAdminConfigFunc();
// Enable tag search UI; initial file list load is controlled elsewhere
initTagSearch();
// Hook DnD relay from fileList area into upload area
const fileListArea = document.getElementById('fileListContainer');
const uploadArea = document.getElementById('uploadDropArea');
if (fileListArea && uploadArea) {
fileListArea.addEventListener('dragover', e => {
e.preventDefault();
fileListArea.classList.add('drop-hover');
});
fileListArea.addEventListener('dragleave', () => {
fileListArea.classList.remove('drop-hover');
});
fileListArea.addEventListener('drop', e => {
e.preventDefault();
fileListArea.classList.remove('drop-hover');
uploadArea.dispatchEvent(new DragEvent('drop', {
dataTransfer: e.dataTransfer,
bubbles: true,
cancelable: true
}));
});
}
// App subsystems
initDragAndDrop();
loadSidebarOrder();
loadHeaderOrder();
initFileActions();
initUpload();
loadFolderTree();
// Only run trash/restore for admins
const isAdmin =
localStorage.getItem('isAdmin') === '1' || localStorage.getItem('isAdmin') === 'true';
if (isAdmin) {
setupTrashRestoreDelete();
}
// Small help tooltip toggle
const helpBtn = document.getElementById("folderHelpBtn");
const helpTooltip = document.getElementById("folderHelpTooltip");
if (helpBtn && helpTooltip) {
helpBtn.addEventListener("click", () => {
helpTooltip.style.display =
helpTooltip.style.display === "block" ? "none" : "block";
});
}
}
/* =========================
LOGOUT (shared)
========================= */
export function triggerLogout() {
const clearWelcomeFlags = () => {
try {
// one-per-tab toast guard
sessionStorage.removeItem('__fr_welcomed');
// if you also used the per-user (all-tabs) guard, clear that too:
const u = localStorage.getItem('username') || '';
if (u) localStorage.removeItem(`__fr_welcomed_${u}`);
} catch { }
};
_nativeFetch("/api/auth/logout.php", {
method: "POST",
credentials: "include",
headers: { "X-CSRF-Token": getCsrfToken() }
})
.then(() => {
clearWelcomeFlags();
window.location.reload(true);
})
.catch(() => {
// even if the request fails, clear the flags so the next login can toast
clearWelcomeFlags();
window.location.reload(true);
});
}
/* =========================
Global UX guard (unchanged)
========================= */
window.addEventListener("unhandledrejection", (ev) => {
const msg = (ev?.reason && ev.reason.message) || "";
if (msg === "auth") {
showToast(t("please_sign_in_again") || "Please sign in again.", "error");
ev.preventDefault();
} else if (msg === "forbidden") {
showToast(t("no_access_to_resource") || "You dont have access to that.", "error");
ev.preventDefault();
}
});

View File

@@ -1,15 +1,15 @@
import { sendRequest } from './networkUtils.js'; import { sendRequest } from './networkUtils.js?v={{APP_QVER}}';
import { t, applyTranslations } from './i18n.js'; import { t, applyTranslations } from './i18n.js?v={{APP_QVER}}';
import { import {
toggleVisibility, toggleVisibility,
showToast as originalShowToast, showToast as originalShowToast,
attachEnterKeyListener, attachEnterKeyListener,
showCustomConfirmModal showCustomConfirmModal
} from './domUtils.js'; } from './domUtils.js?v={{APP_QVER}}';
import { loadFileList } from './fileListView.js'; import { loadFileList } from './fileListView.js?v={{APP_QVER}}';
import { initFileActions } from './fileActions.js'; import { initFileActions } from './fileActions.js?v={{APP_QVER}}';
import { renderFileTable } from './fileListView.js'; import { renderFileTable } from './fileListView.js?v={{APP_QVER}}';
import { loadFolderTree } from './folderManager.js'; import { loadFolderTree } from './folderManager.js?v={{APP_QVER}}';
import { import {
openTOTPLoginModal as originalOpenTOTPLoginModal, openTOTPLoginModal as originalOpenTOTPLoginModal,
openUserPanel, openUserPanel,
@@ -17,9 +17,9 @@ import {
closeTOTPModal, closeTOTPModal,
setLastLoginData, setLastLoginData,
openApiModal openApiModal
} from './authModals.js'; } from './authModals.js?v={{APP_QVER}}';
import { openAdminPanel } from './adminPanel.js'; import { openAdminPanel } from './adminPanel.js?v={{APP_QVER}}';
import { initializeApp, triggerLogout } from './main.js'; import { initializeApp, triggerLogout } from './appCore.js?v={{APP_QVER}}';
// Production OIDC configuration (override via API as needed) // Production OIDC configuration (override via API as needed)
const currentOIDCConfig = { const currentOIDCConfig = {
@@ -31,6 +31,49 @@ const currentOIDCConfig = {
}; };
window.currentOIDCConfig = currentOIDCConfig; window.currentOIDCConfig = currentOIDCConfig;
(function installToastFilter() {
const isDemoHost = location.hostname.toLowerCase() === 'demo.filerise.net';
window.__FR_TOAST_FILTER__ = function (msgKeyOrText) {
// Suppress the nag while doing TOTP step-up
if (window.pendingTOTP && (msgKeyOrText === 'please_log_in_to_continue' ||
/please log in/i.test(String(msgKeyOrText)))) {
return null; // suppress
}
// Demo host
if (isDemoHost && (msgKeyOrText === 'please_log_in_to_continue' ||
/please log in/i.test(String(msgKeyOrText)))) {
return "Demo site — use:\nUsername: demo\nPassword: demo";
}
// Try to translate keys; pass through plain text
try {
const maybe = t(msgKeyOrText);
if (typeof maybe === 'string' && maybe !== msgKeyOrText) return maybe;
} catch { }
return msgKeyOrText;
};
})();
function queueWelcomeToast(name) {
const uname = String(name || '').trim().slice(0, 80);
if (!uname) return;
// show immediately (if we dont reload instantly)
try {
window.dispatchEvent(new CustomEvent('filerise:toast', {
detail: { message: `Welcome back, ${uname}!`, duration: 2000 }
}));
} catch { }
// and persist for after-reload (flushed by main.js on boot)
try {
sessionStorage.setItem('welcomeMessage', `Welcome back, ${uname}!`);
} catch { }
}
/* ----------------- TOTP & Toast Overrides ----------------- */ /* ----------------- TOTP & Toast Overrides ----------------- */
// detect if were in a pendingTOTP state // detect if were in a pendingTOTP state
window.pendingTOTP = new URLSearchParams(window.location.search).get('totp_required') === '1'; window.pendingTOTP = new URLSearchParams(window.location.search).get('totp_required') === '1';
@@ -72,45 +115,51 @@ const originalFetch = window.fetch;
* @param {object} options * @param {object} options
* @returns {Promise<Response>} * @returns {Promise<Response>}
*/ */
export async function fetchWithCsrf(url, options = {}) { export async function fetchWithCsrf(url, options = {}) {
// 1) Merge in credentials + header const original = window.fetch.bind(window);
options = { const wantJson = (options.headers && /json/i.test(options.headers['Content-Type'] || '')) || typeof options.body === 'string' && options.body.trim().startsWith('{');
credentials: 'include',
...options, options = { credentials: 'include', ...options };
};
options.headers = { options.headers = {
...(options.headers || {}), 'Accept': 'application/json',
'X-CSRF-Token': window.csrfToken, ...(options.headers || {})
}; };
if (window.csrfToken) {
// 2) First attempt options.headers['X-CSRF-Token'] = window.csrfToken;
let res = await originalFetch(url, options);
// 3) If we got a 403, try to refresh token & retry
if (res.status === 403) {
// 3a) See if the server gave us a new token header
let newToken = res.headers.get('X-CSRF-Token');
// 3b) Otherwise fall back to the /api/auth/token endpoint
if (!newToken) {
const tokRes = await originalFetch('/api/auth/token.php', { credentials: 'include' });
if (tokRes.ok) {
const body = await tokRes.json();
newToken = body.csrf_token;
}
}
if (newToken) {
// 3c) Update global + meta
window.csrfToken = newToken;
const meta = document.querySelector('meta[name="csrf-token"]');
if (meta) meta.content = newToken;
// 3d) Retry the original request with the new token
options.headers['X-CSRF-Token'] = newToken;
res = await originalFetch(url, options);
}
} }
// 4) Return the real Response—no body peeking here! async function retryWithFreshCsrf(asFormFallback = false) {
const tokRes = await original('/api/auth/token.php', { credentials: 'include' });
if (tokRes.ok) {
const body = await tokRes.json().catch(() => ({}));
if (body?.csrf_token) {
window.csrfToken = body.csrf_token;
const meta = document.querySelector('meta[name="csrf-token"]');
if (meta) meta.content = body.csrf_token;
options.headers['X-CSRF-Token'] = body.csrf_token;
}
}
if (asFormFallback && wantJson) {
// convert JSON body into x-www-form-urlencoded
const orig = options.body && typeof options.body === 'string' ? JSON.parse(options.body) : {};
options.body = toFormBody(orig);
options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
}
return original(url, options);
}
let res = await original(url, options);
// If API doesnt like JSON or token is stale
if (res.status === 400 || res.status === 403 || res.status === 415) {
// 1) retry with fresh CSRF keeping same encoding
res = await retryWithFreshCsrf(false);
if (!res.ok && wantJson) {
// 2) retry again as form-encoded
res = await retryWithFreshCsrf(true);
}
}
return res; return res;
} }
@@ -180,7 +229,7 @@ function updateLoginOptionsUIFromStorage() {
} }
export function loadAdminConfigFunc() { export function loadAdminConfigFunc() {
return fetch("/api/admin/getConfig.php", { credentials: "include" }) return fetch("/api/siteConfig.php", { credentials: "include" })
.then(async (response) => { .then(async (response) => {
// If a proxy or some edge returns 204/empty, handle gracefully // If a proxy or some edge returns 204/empty, handle gracefully
let config = {}; let config = {};
@@ -191,13 +240,13 @@ export function loadAdminConfigFunc() {
document.title = headerTitle; document.title = headerTitle;
const lo = config.loginOptions || {}; const lo = config.loginOptions || {};
localStorage.setItem("disableFormLogin", String(!!lo.disableFormLogin)); localStorage.setItem("disableFormLogin", String(!!lo.disableFormLogin));
localStorage.setItem("disableBasicAuth", String(!!lo.disableBasicAuth)); localStorage.setItem("disableBasicAuth", String(!!lo.disableBasicAuth));
localStorage.setItem("disableOIDCLogin", String(!!lo.disableOIDCLogin)); localStorage.setItem("disableOIDCLogin", String(!!lo.disableOIDCLogin));
localStorage.setItem("globalOtpauthUrl", config.globalOtpauthUrl || "otpauth://totp/{label}?secret={secret}&issuer=FileRise"); localStorage.setItem("globalOtpauthUrl", config.globalOtpauthUrl || "otpauth://totp/{label}?secret={secret}&issuer=FileRise");
// These may be absent for non-admins; default them // These may be absent for non-admins; default them
localStorage.setItem("authBypass", String(!!lo.authBypass)); localStorage.setItem("authBypass", String(!!lo.authBypass));
localStorage.setItem("authHeaderName", lo.authHeaderName || "X-Remote-User"); localStorage.setItem("authHeaderName", lo.authHeaderName || "X-Remote-User");
updateLoginOptionsUIFromStorage(); updateLoginOptionsUIFromStorage();
@@ -253,14 +302,14 @@ export async function updateAuthenticatedUI(data) {
if (loading) loading.remove(); if (loading) loading.remove();
// 2) Show main UI // 2) Show main UI
document.querySelector('.main-wrapper').style.display = ''; document.querySelector('.main-wrapper').style.display = '';
document.getElementById('loginForm').style.display = 'none'; document.getElementById('loginForm').style.display = 'none';
toggleVisibility("loginForm", false); toggleVisibility("loginForm", false);
toggleVisibility("mainOperations", true); toggleVisibility("mainOperations", true);
toggleVisibility("uploadFileForm", true); toggleVisibility("uploadFileForm", true);
toggleVisibility("fileListContainer", true); toggleVisibility("fileListContainer", true);
attachEnterKeyListener("removeUserModal", "deleteUserBtn"); attachEnterKeyListener("removeUserModal", "deleteUserBtn");
attachEnterKeyListener("changePasswordModal","saveNewPasswordBtn"); attachEnterKeyListener("changePasswordModal", "saveNewPasswordBtn");
document.querySelector(".header-buttons").style.visibility = "visible"; document.querySelector(".header-buttons").style.visibility = "visible";
// 3) Persist auth flags (unchanged) // 3) Persist auth flags (unchanged)
@@ -271,9 +320,9 @@ export async function updateAuthenticatedUI(data) {
localStorage.setItem("username", data.username); localStorage.setItem("username", data.username);
} }
if (typeof data.folderOnly !== "undefined") { if (typeof data.folderOnly !== "undefined") {
localStorage.setItem("folderOnly", data.folderOnly ? "true" : "false"); localStorage.setItem("folderOnly", data.folderOnly ? "true" : "false");
localStorage.setItem("readOnly", data.readOnly ? "true" : "false"); localStorage.setItem("readOnly", data.readOnly ? "true" : "false");
localStorage.setItem("disableUpload",data.disableUpload? "true" : "false"); localStorage.setItem("disableUpload", data.disableUpload ? "true" : "false");
} }
// 4) Fetch up-to-date profile picture — ALWAYS overwrite localStorage // 4) Fetch up-to-date profile picture — ALWAYS overwrite localStorage
@@ -282,7 +331,7 @@ export async function updateAuthenticatedUI(data) {
// 5) Build / update header buttons // 5) Build / update header buttons
const headerButtons = document.querySelector(".header-buttons"); const headerButtons = document.querySelector(".header-buttons");
const firstButton = headerButtons.firstElementChild; const firstButton = headerButtons.firstElementChild;
// a) restore-from-trash for admins // a) restore-from-trash for admins
if (data.isAdmin) { if (data.isAdmin) {
@@ -290,8 +339,8 @@ export async function updateAuthenticatedUI(data) {
if (!r) { if (!r) {
r = document.createElement("button"); r = document.createElement("button");
r.id = "restoreFilesBtn"; r.id = "restoreFilesBtn";
r.classList.add("btn","btn-warning"); r.classList.add("btn", "btn-warning");
r.setAttribute("data-i18n-title","trash_restore_delete"); r.setAttribute("data-i18n-title", "trash_restore_delete");
r.innerHTML = '<i class="material-icons">restore_from_trash</i>'; r.innerHTML = '<i class="material-icons">restore_from_trash</i>';
if (firstButton) insertAfter(r, firstButton); if (firstButton) insertAfter(r, firstButton);
else headerButtons.appendChild(r); else headerButtons.appendChild(r);
@@ -308,8 +357,8 @@ export async function updateAuthenticatedUI(data) {
if (!a) { if (!a) {
a = document.createElement("button"); a = document.createElement("button");
a.id = "adminPanelBtn"; a.id = "adminPanelBtn";
a.classList.add("btn","btn-info"); a.classList.add("btn", "btn-info");
a.setAttribute("data-i18n-title","admin_panel"); a.setAttribute("data-i18n-title", "admin_panel");
a.innerHTML = '<i class="material-icons">admin_panel_settings</i>'; a.innerHTML = '<i class="material-icons">admin_panel_settings</i>';
insertAfter(a, document.getElementById("restoreFilesBtn")); insertAfter(a, document.getElementById("restoreFilesBtn"));
a.addEventListener("click", openAdminPanel); a.addEventListener("click", openAdminPanel);
@@ -330,19 +379,19 @@ export async function updateAuthenticatedUI(data) {
: `<i class="material-icons">account_circle</i>`; : `<i class="material-icons">account_circle</i>`;
// fallback username if missing // fallback username if missing
const usernameText = data.username const usernameText = data.username
|| localStorage.getItem("username") || localStorage.getItem("username")
|| ""; || "";
if (!dd) { if (!dd) {
dd = document.createElement("div"); dd = document.createElement("div");
dd.id = "userDropdown"; dd.id = "userDropdown";
dd.classList.add("user-dropdown"); dd.classList.add("user-dropdown");
// toggle button // toggle button
const toggle = document.createElement("button"); const toggle = document.createElement("button");
toggle.id = "userDropdownToggle"; toggle.id = "userDropdownToggle";
toggle.classList.add("btn","btn-user"); toggle.classList.add("btn", "btn-user");
toggle.setAttribute("title", t("user_settings")); toggle.setAttribute("title", t("user_settings"));
toggle.innerHTML = ` toggle.innerHTML = `
${avatarHTML} ${avatarHTML}
@@ -464,6 +513,14 @@ function checkAuthentication(showLoginToast = true) {
} }
updateAuthenticatedUI(data); updateAuthenticatedUI(data);
return data; return data;
// at the end of updateAuthenticatedUI(data)
if (!window.__FR_FLAGS?.initialized && typeof initializeApp === 'function') {
initializeApp();
window.__FR_FLAGS.initialized = true;
}
if (typeof applyTranslations === 'function') applyTranslations();
if (typeof updateLoginOptionsUIFromStorage === 'function') updateLoginOptionsUIFromStorage();
} else { } else {
const overlay = document.getElementById('loadingOverlay'); const overlay = document.getElementById('loadingOverlay');
if (overlay) overlay.remove(); if (overlay) overlay.remove();
@@ -484,53 +541,162 @@ function checkAuthentication(showLoginToast = true) {
} }
/* ----------------- Authentication Submission ----------------- */ /* ----------------- Authentication Submission ----------------- */
async function primeCsrfStrict() {
const r = await fetch('/api/auth/token.php', { credentials: 'include' });
const j = await r.json().catch(() => ({}));
if (!r.ok || !j.csrf_token) throw new Error('CSRF missing');
window.csrfToken = j.csrf_token;
const m = document.querySelector('meta[name="csrf-token"]');
if (m) m.content = j.csrf_token;
}
function toFormBody(obj) {
const p = new URLSearchParams();
for (const [k, v] of Object.entries(obj || {})) p.set(k, v == null ? '' : String(v));
return p.toString();
}
async function safeJson(res) {
const ct = res.headers.get('content-type') || '';
if (!/application\/json/i.test(ct)) return null;
try { return await res.clone().json(); } catch { return null; }
}
async function sniffTOTP(res, bodyMaybe) {
if (res.headers.get('X-TOTP-Required') === '1') return true;
if (res.redirected && /[?&]totp_required=1\b/.test(res.url)) return true;
const body = bodyMaybe ?? await safeJson(res);
if (body && (body.totp_required || body.error === 'TOTP_REQUIRED')) return true;
try {
const txt = await res.clone().text();
if (/\btotp_required\s*=\s*1\b/i.test(txt)) return true;
} catch { }
return false;
}
async function isAuthedNow() {
try {
const r = await fetch('/api/auth/checkAuth.php', { credentials: 'include' });
const j = await r.json().catch(() => ({}));
return !!j.authenticated;
} catch { return false; }
}
function rafTick(times = 2) {
return new Promise(res => {
const step = () => { if (--times <= 0) res(); else requestAnimationFrame(step); };
requestAnimationFrame(step);
});
}
async function fetchAuthSnapshot() {
try {
const r = await fetch('/api/auth/checkAuth.php', { credentials: 'include' });
return await r.json();
} catch { return {}; }
}
async function syncPermissionsToLocalStorage() {
try {
const r = await fetch('/api/getUserPermissions.php', { credentials: 'include' });
const perm = await r.json();
if (perm && typeof perm === 'object') {
localStorage.setItem('folderOnly', perm.folderOnly ? 'true' : 'false');
localStorage.setItem('readOnly', perm.readOnly ? 'true' : 'false');
localStorage.setItem('disableUpload', perm.disableUpload ? 'true' : 'false');
}
} catch { /* non-fatal */ }
}
// ——— main ———
let __loginInFlight = false;
async function submitLogin(data) { async function submitLogin(data) {
setLastLoginData(data); if (__loginInFlight) return;
window.__lastLoginData = data; __loginInFlight = true;
const payload = {
username: String(data.username || '').trim(),
password: String(data.password || '').trim(),
remember_me: data.remember_me ? 1 : 0
};
setLastLoginData(payload);
window.__lastLoginData = payload;
try { try {
// ─── 1) Get CSRF for the initial auth call ─── await primeCsrfStrict();
let res = await fetch("/api/auth/token.php", { credentials: "include" });
if (!res.ok) throw new Error("Could not fetch CSRF token");
window.csrfToken = (await res.json()).csrf_token;
// ─── 2) Send credentials ─── // Attempt #1 — JSON
const response = await sendRequest( let res = await fetchWithCsrf('/api/auth/auth.php', {
"/api/auth/auth.php", method: 'POST',
"POST", credentials: 'include',
data, headers: { 'Content-Type': 'application/json', 'Accept': 'application/json' },
{ "X-CSRF-Token": window.csrfToken } body: JSON.stringify(payload)
); });
let body = await safeJson(res);
// ─── 3a) Full login (no TOTP) ─── // TOTP requested?
if (response.success || response.status === "ok") { if (await sniffTOTP(res, body)) {
sessionStorage.setItem("welcomeMessage", "Welcome back, " + data.username + "!"); try { await primeCsrfStrict(); } catch { }
// … fetch permissions & reload … window.pendingTOTP = true;
try { try {
const perm = await sendRequest("/api/getUserPermissions.php", "GET"); const auth = await import('/js/auth.js?v={{APP_QVER}}');
if (perm && typeof perm === "object") { if (typeof auth.openTOTPLoginModal === 'function') auth.openTOTPLoginModal();
localStorage.setItem("folderOnly", perm.folderOnly ? "true" : "false");
localStorage.setItem("readOnly", perm.readOnly ? "true" : "false");
localStorage.setItem("disableUpload", perm.disableUpload ? "true" : "false");
}
} catch { } } catch { }
return window.location.reload(); return;
} }
// ─── 3b) TOTP required ─── // Full success (no TOTP)
if (response.totp_required) { if (body && (body.success || body.status === 'ok' || body.authenticated)) {
// **Refresh** CSRF before the TOTP verify call
res = await fetch("/api/auth/token.php", { credentials: "include" }); await syncPermissionsToLocalStorage();
if (res.ok) { return afterLogin();
window.csrfToken = (await res.json()).csrf_token;
}
// now open the modal—any totp_verify fetch from here on will use the new token
return openTOTPLoginModal();
} }
// ─── 3c) Too many attempts ─── // Cookie set but non-JSON body — double check session
if (response.error && response.error.includes("Too many failed login attempts")) { if (!body && await isAuthedNow()) {
showToast(response.error);
await syncPermissionsToLocalStorage();
return afterLogin();
}
// Attempt #2 — form fallback
res = await fetchWithCsrf('/api/auth/auth.php', {
method: 'POST',
credentials: 'include',
headers: { 'Content-Type': 'application/x-www-form-urlencoded', 'Accept': 'application/json' },
body: toFormBody(payload)
});
body = await safeJson(res);
if (await sniffTOTP(res, body)) {
try { await primeCsrfStrict(); } catch { }
window.pendingTOTP = true;
try {
const auth = await import('/js/auth.js?v={{APP_QVER}}');
if (typeof auth.openTOTPLoginModal === 'function') auth.openTOTPLoginModal();
} catch { }
return;
}
if (body && (body.success || body.status === 'ok' || body.authenticated)) {
await syncPermissionsToLocalStorage();
return afterLogin();
}
if (!body && await isAuthedNow()) {
await syncPermissionsToLocalStorage();
return afterLogin();
}
// Rate limit still respected
if (body?.error && /Too many failed login attempts/i.test(body.error)) {
showToast(body.error);
const btn = document.querySelector("#authForm button[type='submit']"); const btn = document.querySelector("#authForm button[type='submit']");
if (btn) { if (btn) {
btn.disabled = true; btn.disabled = true;
@@ -542,12 +708,12 @@ async function submitLogin(data) {
return; return;
} }
// ─── 3d) Other failures ─── showToast('Login failed' + (body?.error ? `: ${body.error}` : ''));
showToast("Login failed: " + (response.error || "Unknown error"));
} catch (err) { } catch (e) {
const msg = err.message || err.error || "Unknown error"; showToast('Login failed: ' + (e.message || 'Unknown error'));
showToast(`Login failed: ${msg}`); } finally {
__loginInFlight = false;
} }
} }
@@ -763,4 +929,4 @@ document.addEventListener("DOMContentLoaded", function () {
} }
}); });
export { initAuth, checkAuthentication }; export { initAuth, checkAuthentication, openTOTPLoginModal };

View File

@@ -1,7 +1,7 @@
import { showToast, toggleVisibility, attachEnterKeyListener } from './domUtils.js'; import { showToast, toggleVisibility, attachEnterKeyListener } from './domUtils.js?v={{APP_QVER}}';
import { sendRequest } from './networkUtils.js'; import { sendRequest } from './networkUtils.js?v={{APP_QVER}}';
import { t, applyTranslations, setLocale } from './i18n.js'; import { t, applyTranslations, setLocale } from './i18n.js?v={{APP_QVER}}';
import { loadAdminConfigFunc, updateAuthenticatedUI } from './auth.js'; import { loadAdminConfigFunc, updateAuthenticatedUI } from './auth.js?v={{APP_QVER}}';
let lastLoginData = null; let lastLoginData = null;
export function setLastLoginData(data) { export function setLastLoginData(data) {

31
public/js/defer-css.js Normal file
View File

@@ -0,0 +1,31 @@
// /public/js/defer-css.js
// Promote preloaded styles to real stylesheets (CSP-safe) and expose a load promise.
(function () {
if (window.__CSS_PROMISE__) return;
var loads = [];
// Promote <link rel="preload" as="style"> IN-PLACE
var preloads = document.querySelectorAll('link[rel="preload"][as="style"]');
for (var i = 0; i < preloads.length; i++) {
var l = preloads[i];
// resolve when it finishes loading as a stylesheet
loads.push(new Promise(function (res) { l.addEventListener('load', res, { once: true }); }));
l.rel = 'stylesheet';
if (!l.media || l.media === 'print') l.media = 'all'; // be explicit
l.removeAttribute('as'); // keep some engines happy about "used" preload
}
// Also wait for any existing <link rel="stylesheet"> that haven't finished yet
var styles = document.querySelectorAll('link[rel="stylesheet"]');
for (var j = 0; j < styles.length; j++) {
var s = styles[j];
if (s.sheet) continue; // already applied
loads.push(new Promise(function (res) { s.addEventListener('load', res, { once: true }); }));
}
// Safari quirk: nudge layout so promoted sheets apply immediately
void document.documentElement.offsetHeight;
window.__CSS_PROMISE__ = Promise.all(loads);
})();

View File

@@ -1,6 +1,6 @@
// domUtils.js // domUtils.js
import { t } from './i18n.js'; import { t } from './i18n.js?v={{APP_QVER}}';
import { openDownloadModal } from './fileActions.js'; import { openDownloadModal } from './fileActions.js?v={{APP_QVER}}';
// Basic DOM Helpers // Basic DOM Helpers
export function toggleVisibility(elementId, shouldShow) { export function toggleVisibility(elementId, shouldShow) {

View File

@@ -489,18 +489,12 @@ function mountHeaderToggle(btn) {
}); });
} }
function ensureZonesToggle() { function ensureZonesToggle() {
const isAuthed = document.body.classList.contains('authenticated');
let btn = document.getElementById('sidebarToggleFloating'); let btn = document.getElementById('sidebarToggleFloating');
const host = getHeaderHost(); const host = getHeaderHost();
if (!host) return; if (!host) return;
// If not authenticated, make sure the button is gone and bail.
if (!isAuthed) {
if (btn) btn.remove();
return;
}
// ensure the host is a positioning context // ensure the host is a positioning context
const hostStyle = getComputedStyle(host); const hostStyle = getComputedStyle(host);
if (hostStyle.position === 'static') { if (hostStyle.position === 'static') {
@@ -542,6 +536,7 @@ function ensureZonesToggle() {
padding: '0', padding: '0',
lineHeight: '0' lineHeight: '0'
}); });
btn.classList.add('zones-toggle');
// Dark mode polish // Dark mode polish
if (document.body.classList.contains('dark-mode')) { if (document.body.classList.contains('dark-mode')) {

View File

@@ -1,8 +1,8 @@
// fileActions.js // fileActions.js
import { showToast, attachEnterKeyListener } from './domUtils.js'; import { showToast, attachEnterKeyListener } from './domUtils.js?v={{APP_QVER}}';
import { loadFileList } from './fileListView.js'; import { loadFileList } from './fileListView.js?v={{APP_QVER}}';
import { formatFolderName } from './fileListView.js'; import { formatFolderName } from './fileListView.js?v={{APP_QVER}}';
import { t } from './i18n.js'; import { t } from './i18n.js?v={{APP_QVER}}';
export function handleDeleteSelected(e) { export function handleDeleteSelected(e) {
e.preventDefault(); e.preventDefault();
@@ -31,6 +31,7 @@ document.addEventListener("DOMContentLoaded", function () {
const confirmDelete = document.getElementById("confirmDeleteFiles"); const confirmDelete = document.getElementById("confirmDeleteFiles");
if (confirmDelete) { if (confirmDelete) {
confirmDelete.setAttribute("data-default", "");
confirmDelete.addEventListener("click", function () { confirmDelete.addEventListener("click", function () {
fetch("/api/file/deleteFiles.php", { fetch("/api/file/deleteFiles.php", {
method: "POST", method: "POST",
@@ -316,6 +317,7 @@ document.addEventListener("DOMContentLoaded", () => {
// 2) Confirm button kicks off the zip+download // 2) Confirm button kicks off the zip+download
if (confirmZipBtn) { if (confirmZipBtn) {
confirmZipBtn.setAttribute("data-default", "");
confirmZipBtn.addEventListener("click", async () => { confirmZipBtn.addEventListener("click", async () => {
// a) Validate ZIP filename // a) Validate ZIP filename
let zipName = document.getElementById("zipFileNameInput").value.trim(); let zipName = document.getElementById("zipFileNameInput").value.trim();
@@ -478,6 +480,7 @@ document.addEventListener("DOMContentLoaded", function () {
} }
const confirmCopy = document.getElementById("confirmCopyFiles"); const confirmCopy = document.getElementById("confirmCopyFiles");
if (confirmCopy) { if (confirmCopy) {
confirmCopy.setAttribute("data-default", "");
confirmCopy.addEventListener("click", function () { confirmCopy.addEventListener("click", function () {
const targetFolder = document.getElementById("copyTargetFolder").value; const targetFolder = document.getElementById("copyTargetFolder").value;
if (!targetFolder) { if (!targetFolder) {
@@ -529,6 +532,7 @@ document.addEventListener("DOMContentLoaded", function () {
} }
const confirmMove = document.getElementById("confirmMoveFiles"); const confirmMove = document.getElementById("confirmMoveFiles");
if (confirmMove) { if (confirmMove) {
confirmMove.setAttribute("data-default", "");
confirmMove.addEventListener("click", function () { confirmMove.addEventListener("click", function () {
const targetFolder = document.getElementById("moveTargetFolder").value; const targetFolder = document.getElementById("moveTargetFolder").value;
if (!targetFolder) { if (!targetFolder) {
@@ -598,6 +602,7 @@ document.addEventListener("DOMContentLoaded", () => {
const submitBtn = document.getElementById("submitRenameFile"); const submitBtn = document.getElementById("submitRenameFile");
if (submitBtn) { if (submitBtn) {
submitBtn.setAttribute("data-default", "");
submitBtn.addEventListener("click", function () { submitBtn.addEventListener("click", function () {
const newName = document.getElementById("newFileName").value.trim(); const newName = document.getElementById("newFileName").value.trim();
if (!newName || newName === window.fileToRename) { if (!newName || newName === window.fileToRename) {

View File

@@ -1,6 +1,6 @@
// fileDragDrop.js // fileDragDrop.js
import { showToast } from './domUtils.js'; import { showToast } from './domUtils.js?v={{APP_QVER}}';
import { loadFileList } from './fileListView.js'; import { loadFileList } from './fileListView.js?v={{APP_QVER}}';
export function fileDragStartHandler(event) { export function fileDragStartHandler(event) {
const row = event.currentTarget; const row = event.currentTarget;

View File

@@ -1,43 +1,59 @@
// fileEditor.js // fileEditor.js
import { escapeHTML, showToast } from './domUtils.js'; import { escapeHTML, showToast } from './domUtils.js?v={{APP_QVER}}';
import { loadFileList } from './fileListView.js'; import { loadFileList } from './fileListView.js?v={{APP_QVER}}';
import { t } from './i18n.js'; import { t } from './i18n.js?v={{APP_QVER}}';
import { buildPreviewUrl } from './filePreview.js?v={{APP_QVER}}';
// thresholds for editor behavior // thresholds for editor behavior
const EDITOR_PLAIN_THRESHOLD = 5 * 1024 * 1024; // >5 MiB => force plain text, lighter settings const EDITOR_PLAIN_THRESHOLD = 5 * 1024 * 1024; // >5 MiB => force plain text, lighter settings
const EDITOR_BLOCK_THRESHOLD = 10 * 1024 * 1024; // >10 MiB => block editing const EDITOR_BLOCK_THRESHOLD = 10 * 1024 * 1024; // >10 MiB => block editing
// Lazy-load CodeMirror modes on demand // ==== CodeMirror lazy loader ===============================================
//const CM_CDN = "https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.5/"; const CM_BASE = "/vendor/codemirror/5.65.5/";
const CM_LOCAL = "/vendor/codemirror/5.65.5/";
// Stamp-friendly helpers (the stamper will replace {{APP_QVER}})
const coreUrl = (p) => `${CM_BASE}${p}?v={{APP_QVER}}`;
const CORE = {
js: coreUrl("codemirror.min.js"),
css: coreUrl("codemirror.min.css"),
themeCss: coreUrl("theme/material-darker.min.css"),
};
// Which mode file to load for a given name/mime // Which mode file to load for a given name/mime
const MODE_URL = { const MODE_URL = {
// core/common // core/common
"xml": "mode/xml/xml.min.js", "xml": "mode/xml/xml.min.js?v={{APP_QVER}}",
"css": "mode/css/css.min.js", "css": "mode/css/css.min.js?v={{APP_QVER}}",
"javascript": "mode/javascript/javascript.min.js", "javascript": "mode/javascript/javascript.min.js?v={{APP_QVER}}",
// meta / combos // meta / combos
"htmlmixed": "mode/htmlmixed/htmlmixed.min.js", "htmlmixed": "mode/htmlmixed/htmlmixed.min.js?v={{APP_QVER}}",
"application/x-httpd-php": "mode/php/php.min.js", "application/x-httpd-php": "mode/php/php.min.js?v={{APP_QVER}}",
// docs / data // docs / data
"markdown": "mode/markdown/markdown.min.js", "markdown": "mode/markdown/markdown.min.js?v={{APP_QVER}}",
"yaml": "mode/yaml/yaml.min.js", "yaml": "mode/yaml/yaml.min.js?v={{APP_QVER}}",
"properties": "mode/properties/properties.min.js", "properties": "mode/properties/properties.min.js?v={{APP_QVER}}",
"sql": "mode/sql/sql.min.js", "sql": "mode/sql/sql.min.js?v={{APP_QVER}}",
// shells // shells
"shell": "mode/shell/shell.min.js", "shell": "mode/shell/shell.min.js?v={{APP_QVER}}",
// languages // languages
"python": "mode/python/python.min.js", "python": "mode/python/python.min.js?v={{APP_QVER}}",
"text/x-csrc": "mode/clike/clike.min.js", "text/x-csrc": "mode/clike/clike.min.js?v={{APP_QVER}}",
"text/x-c++src": "mode/clike/clike.min.js", "text/x-c++src": "mode/clike/clike.min.js?v={{APP_QVER}}",
"text/x-java": "mode/clike/clike.min.js", "text/x-java": "mode/clike/clike.min.js?v={{APP_QVER}}",
"text/x-csharp": "mode/clike/clike.min.js", "text/x-csharp": "mode/clike/clike.min.js?v={{APP_QVER}}",
"text/x-kotlin": "mode/clike/clike.min.js" "text/x-kotlin": "mode/clike/clike.min.js?v={{APP_QVER}}"
};
// Mode dependency graph
const MODE_DEPS = {
"htmlmixed": ["xml", "javascript", "css"],
"application/x-httpd-php": ["htmlmixed", "text/x-csrc"], // php overlays + clike bits
"markdown": ["xml"]
}; };
// Map any mime/alias to the key we use in MODE_URL // Map any mime/alias to the key we use in MODE_URL
@@ -49,62 +65,209 @@ function normalizeModeName(modeOption) {
return name; return name;
} }
const MODE_LOAD_TIMEOUT_MS = 2500; // allow closing immediately; don't wait forever // ---- ONLYOFFICE integration -----------------------------------------------
function getExt(name) { const i = name.lastIndexOf('.'); return i >= 0 ? name.slice(i + 1).toLowerCase() : ''; }
// Cache OO capabilities (enabled flag + ext list) from /api/onlyoffice/status.php
let __ooCaps = { enabled: false, exts: new Set(), fetched: false };
async function fetchOnlyOfficeCapsOnce() {
if (__ooCaps.fetched) return __ooCaps;
try {
const r = await fetch('/api/onlyoffice/status.php', { credentials: 'include' });
if (r.ok) {
const j = await r.json();
__ooCaps.enabled = !!j.enabled;
__ooCaps.exts = new Set(Array.isArray(j.exts) ? j.exts : []);
}
} catch { /* ignore; keep defaults */ }
__ooCaps.fetched = true;
return __ooCaps;
}
async function shouldUseOnlyOffice(fileName) {
const { enabled, exts } = await fetchOnlyOfficeCapsOnce();
return enabled && exts.has(getExt(fileName));
}
function isAbsoluteHttpUrl(u) { return /^https?:\/\//i.test(u || ''); }
async function ensureOnlyOfficeApi(srcFromConfig, originFromConfig) {
let src =
srcFromConfig ||
(originFromConfig ? originFromConfig.replace(/\/$/, '') + '/web-apps/apps/api/documents/api.js'
: (window.ONLYOFFICE_API_SRC || '/onlyoffice/web-apps/apps/api/documents/api.js'));
if (window.DocsAPI && typeof window.DocsAPI.DocEditor === 'function') return;
await loadScriptOnce(src);
}
async function openOnlyOffice(fileName, folder) {
let editor; // make visible to the whole function
try {
const url = `/api/onlyoffice/config.php?folder=${encodeURIComponent(folder)}&file=${encodeURIComponent(fileName)}`;
const resp = await fetch(url, { credentials: 'include' });
const text = await resp.text();
let cfg;
try { cfg = JSON.parse(text); } catch {
throw new Error(`ONLYOFFICE config parse failed (HTTP ${resp.status}). First 120 chars: ${text.slice(0,120)}`);
}
if (!resp.ok) throw new Error(cfg.error || `ONLYOFFICE config HTTP ${resp.status}`);
// Must be absolute
const docUrl = cfg?.document?.url;
const cbUrl = cfg?.editorConfig?.callbackUrl;
if (!/^https?:\/\//i.test(docUrl || '') || !/^https?:\/\//i.test(cbUrl || '')) {
throw new Error(`Config URLs must be absolute. document.url='${docUrl}', callbackUrl='${cbUrl}'`);
}
// Load DocsAPI if needed
await ensureOnlyOfficeApi(cfg.docs_api_js, cfg.documentServerOrigin);
// Modal
const modal = document.createElement('div');
modal.id = 'ooEditorModal';
modal.classList.add('modal', 'editor-modal');
modal.setAttribute('tabindex', '-1');
modal.innerHTML = `
<div class="editor-header">
<h3 class="editor-title">
${t("editing")}: ${escapeHTML(fileName)}
</h3>
<button id="closeEditorX" class="editor-close-btn" aria-label="${t("close") || "Close"}">&times;</button>
</div>
<div class="editor-body" style="flex:1;min-height:200px">
<div id="oo-editor" style="width:100%;height:100%"></div>
</div>
`;
document.body.appendChild(modal);
modal.style.display = 'block';
modal.focus();
// Well fill this after wiring the toggle, so destroy() can unhook it
let removeThemeListener = () => {};
const destroy = () => {
try { editor?.destroyEditor?.(); } catch {}
try { removeThemeListener(); } catch {}
try { modal.remove(); } catch {}
};
modal.addEventListener('keydown', e => { if (e.key === 'Escape') destroy(); });
document.getElementById('closeEditorX')?.addEventListener('click', destroy);
// Let DS request closing
cfg.events = Object.assign({}, cfg.events, { onRequestClose: destroy });
// Initial theme
const isDark =
document.documentElement.classList.contains('dark-mode') ||
/^(1|true)$/i.test(localStorage.getItem('darkMode') || '');
cfg.editorConfig = cfg.editorConfig || {};
cfg.editorConfig.customization = Object.assign(
{},
cfg.editorConfig.customization,
{ uiTheme: isDark ? 'theme-dark' : 'theme-light' } // <- correct key/value
);
// Launch editor
editor = new window.DocsAPI.DocEditor('oo-editor', cfg);
// Live theme switching (ONLYOFFICE v7.2+ supports setTheme)
const darkToggle = document.getElementById('darkModeToggle');
const onDarkToggle = () => {
const nowDark = document.documentElement.classList.contains('dark-mode');
if (editor && typeof editor.setTheme === 'function') {
editor.setTheme(nowDark ? 'dark' : 'light');
}
};
if (darkToggle) {
darkToggle.addEventListener('click', onDarkToggle);
removeThemeListener = () => darkToggle.removeEventListener('click', onDarkToggle);
}
} catch (e) {
console.error('[ONLYOFFICE] failed to open:', e);
showToast((e && e.message) ? e.message : 'Unable to open ONLYOFFICE editor.');
}
}
// ---- /ONLYOFFICE integration ----------------------------------------------
const _loadedScripts = new Set();
const _loadedCss = new Set();
let _corePromise = null;
function loadScriptOnce(url) { function loadScriptOnce(url) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const ver = (window.APP_VERSION ?? 'dev').replace(/^v/, ''); // "v1.6.9" -> "1.6.9" if (_loadedScripts.has(url)) return resolve();
const withQS = url + '?v=' + ver; const s = document.createElement("script");
s.src = url;
const key = `cm:${withQS}`;
let s = document.querySelector(`script[data-key="${key}"]`);
if (s) {
if (s.dataset.loaded === "1") return resolve();
s.addEventListener("load", resolve);
s.addEventListener("error", () => reject(new Error(`Load failed: ${withQS}`)));
return;
}
s = document.createElement("script");
s.src = withQS;
s.async = true; s.async = true;
s.dataset.key = key; s.onload = () => { _loadedScripts.add(url); resolve(); };
s.addEventListener("load", () => { s.dataset.loaded = "1"; resolve(); }); s.onerror = () => reject(new Error(`Load failed: ${url}`));
s.addEventListener("error", () => reject(new Error(`Load failed: ${withQS}`)));
document.head.appendChild(s); document.head.appendChild(s);
}); });
} }
function loadCssOnce(href) {
return new Promise((resolve, reject) => {
if (_loadedCss.has(href)) return resolve();
const l = document.createElement("link");
l.rel = "stylesheet";
l.href = href;
l.onload = () => { _loadedCss.add(href); resolve(); };
l.onerror = () => reject(new Error(`Load failed: ${href}`));
document.head.appendChild(l);
});
}
async function ensureCore() {
if (_corePromise) return _corePromise;
_corePromise = (async () => {
// load CSS first to avoid FOUC
await loadCssOnce(CORE.css);
await loadCssOnce(CORE.themeCss);
if (!window.CodeMirror) {
await loadScriptOnce(CORE.js);
}
})();
return _corePromise;
}
async function loadSingleMode(name) {
const rel = MODE_URL[name];
if (!rel) return;
// prepend base if needed
const url = rel.startsWith("http") ? rel : (rel.startsWith("/") ? rel : (CM_BASE + rel));
await loadScriptOnce(url);
}
function isModeRegistered(name) {
return !!(
(window.CodeMirror?.modes && window.CodeMirror.modes[name]) ||
(window.CodeMirror?.mimeModes && window.CodeMirror.mimeModes[name])
);
}
async function ensureModeLoaded(modeOption) { async function ensureModeLoaded(modeOption) {
if (!window.CodeMirror) return; await ensureCore();
const name = normalizeModeName(modeOption); const name = normalizeModeName(modeOption);
if (!name) return; if (!name) return;
if (isModeRegistered(name)) return;
const isRegistered = () => const deps = MODE_DEPS[name] || [];
(window.CodeMirror?.modes && window.CodeMirror.modes[name]) || for (const d of deps) {
(window.CodeMirror?.mimeModes && window.CodeMirror.mimeModes[name]); if (!isModeRegistered(d)) await loadSingleMode(d);
if (isRegistered()) return;
const url = MODE_URL[name];
if (!url) return; // unknown -> stay in text/plain
// Dependencies
if (name === "htmlmixed") {
await Promise.all([
ensureModeLoaded("xml"),
ensureModeLoaded("css"),
ensureModeLoaded("javascript")
]);
} }
if (name === "application/x-httpd-php") { await loadSingleMode(name);
await ensureModeLoaded("htmlmixed");
}
await loadScriptOnce(CM_LOCAL + url);
} }
// Public helper for callers (we keep your existing function name in use):
const MODE_LOAD_TIMEOUT_MS = 2500; // allow closing immediately; don't wait forever
// ==== /CodeMirror lazy loader ===============================================
function getModeForFile(fileName) { function getModeForFile(fileName) {
const dot = fileName.lastIndexOf("."); const dot = fileName.lastIndexOf(".");
const ext = dot >= 0 ? fileName.slice(dot + 1).toLowerCase() : ""; const ext = dot >= 0 ? fileName.slice(dot + 1).toLowerCase() : "";
@@ -164,29 +327,48 @@ function observeModalResize(modal) {
} }
export { observeModalResize }; export { observeModalResize };
export function editFile(fileName, folder) { export async function editFile(fileName, folder) {
// destroy any previous editor // destroy any previous editor
let existingEditor = document.getElementById("editorContainer"); let existingEditor = document.getElementById("editorContainer");
if (existingEditor) existingEditor.remove(); if (existingEditor) existingEditor.remove();
const folderUsed = folder || window.currentFolder || "root"; const folderUsed = folder || window.currentFolder || "root";
const folderPath = folderUsed === "root" const fileUrl = buildPreviewUrl(folderUsed, fileName);
? "uploads/"
: "uploads/" + folderUsed.split("/").map(encodeURIComponent).join("/") + "/";
const fileUrl = folderPath + encodeURIComponent(fileName) + "?t=" + new Date().getTime();
fetch(fileUrl, { method: "HEAD" }) if (await shouldUseOnlyOffice(fileName)) {
.then(response => { await openOnlyOffice(fileName, folderUsed);
const lenHeader = response.headers.get("content-length") ?? response.headers.get("Content-Length"); return;
const sizeBytes = lenHeader ? parseInt(lenHeader, 10) : null; }
// Probe size safely via API. Prefer HEAD; if missing Content-Length, fall back to a 1-byte Range GET.
async function probeSize(url) {
try {
const h = await fetch(url, { method: "HEAD", credentials: "include" });
const len = h.headers.get("content-length") ?? h.headers.get("Content-Length");
if (len && !Number.isNaN(parseInt(len, 10))) return parseInt(len, 10);
} catch { }
try {
const r = await fetch(url, {
method: "GET",
headers: { Range: "bytes=0-0" },
credentials: "include"
});
// Content-Range: bytes 0-0/12345
const cr = r.headers.get("content-range") ?? r.headers.get("Content-Range");
const m = cr && cr.match(/\/(\d+)\s*$/);
if (m) return parseInt(m[1], 10);
} catch { }
return null;
}
probeSize(fileUrl)
.then(sizeBytes => {
if (sizeBytes !== null && sizeBytes > EDITOR_BLOCK_THRESHOLD) { if (sizeBytes !== null && sizeBytes > EDITOR_BLOCK_THRESHOLD) {
showToast("This file is larger than 10 MB and cannot be edited in the browser."); showToast("This file is larger than 10 MB and cannot be edited in the browser.");
throw new Error("File too large."); throw new Error("File too large.");
} }
return response; return fetch(fileUrl, { credentials: "include" });
}) })
.then(() => fetch(fileUrl))
.then(response => { .then(response => {
if (!response.ok) throw new Error("HTTP error! Status: " + response.status); if (!response.ok) throw new Error("HTTP error! Status: " + response.status);
const lenHeader = response.headers.get("content-length") ?? response.headers.get("Content-Length"); const lenHeader = response.headers.get("content-length") ?? response.headers.get("Content-Length");
@@ -215,7 +397,7 @@ export function editFile(fileName, folder) {
</div> </div>
<textarea id="fileEditor" class="editor-textarea">${escapeHTML(content)}</textarea> <textarea id="fileEditor" class="editor-textarea">${escapeHTML(content)}</textarea>
<div class="editor-footer"> <div class="editor-footer">
<button id="saveBtn" class="btn btn-primary" disabled>${t("save")}</button> <button id="saveBtn" class="btn btn-primary" data-default disabled>${t("save")} </button>
<button id="closeBtn" class="btn btn-secondary">${t("close")}</button> <button id="closeBtn" class="btn btn-secondary">${t("close")}</button>
</div> </div>
`; `;
@@ -238,28 +420,28 @@ export function editFile(fileName, folder) {
// Keep buttons responsive even before editor exists // Keep buttons responsive even before editor exists
const decBtn = document.getElementById("decreaseFont"); const decBtn = document.getElementById("decreaseFont");
const incBtn = document.getElementById("increaseFont"); const incBtn = document.getElementById("increaseFont");
decBtn.addEventListener("click", () => {}); decBtn.addEventListener("click", () => { });
incBtn.addEventListener("click", () => {}); incBtn.addEventListener("click", () => { });
// Theme + mode selection // Theme + mode selection
const isDarkMode = document.body.classList.contains("dark-mode"); const isDarkMode = document.body.classList.contains("dark-mode");
const theme = isDarkMode ? "material-darker" : "default"; const theme = isDarkMode ? "material-darker" : "default";
const desiredMode = forcePlainText ? "text/plain" : getModeForFile(fileName); const desiredMode = forcePlainText ? "text/plain" : getModeForFile(fileName);
// Helper to check whether a mode is currently registered // Start core+mode loading (dont block closing)
const modeName = typeof desiredMode === "string" ? desiredMode : (desiredMode && desiredMode.name); const modePromise = (async () => {
const isModeRegistered = () => await ensureCore(); // load CM core + CSS
(window.CodeMirror?.modes && window.CodeMirror.modes[modeName]) || if (!forcePlainText) {
(window.CodeMirror?.mimeModes && window.CodeMirror.mimeModes[modeName]); await ensureModeLoaded(desiredMode); // then load the needed mode + deps
}
// Start mode loading (dont block closing) })();
const modePromise = ensureModeLoaded(desiredMode);
// Wait up to MODE_LOAD_TIMEOUT_MS; then proceed with whatever is available // Wait up to MODE_LOAD_TIMEOUT_MS; then proceed with whatever is available
const timeout = new Promise((res) => setTimeout(res, MODE_LOAD_TIMEOUT_MS)); const timeout = new Promise((res) => setTimeout(res, MODE_LOAD_TIMEOUT_MS));
Promise.race([modePromise, timeout]).then(() => { Promise.race([modePromise, timeout]).then(() => {
if (canceled) return; if (canceled) return;
if (!window.CodeMirror) { if (!window.CodeMirror) {
// Core not present: keep plain <textarea>; enable Save and bail gracefully // Core not present: keep plain <textarea>; enable Save and bail gracefully
document.getElementById("saveBtn").disabled = false; document.getElementById("saveBtn").disabled = false;
@@ -267,7 +449,9 @@ export function editFile(fileName, folder) {
return; return;
} }
const initialMode = (forcePlainText || !isModeRegistered()) ? "text/plain" : desiredMode; const normName = normalizeModeName(desiredMode) || "text/plain";
const initialMode = (forcePlainText || !isModeRegistered(normName)) ? "text/plain" : desiredMode;
const cmOptions = { const cmOptions = {
lineNumbers: !forcePlainText, lineNumbers: !forcePlainText,
mode: initialMode, mode: initialMode,
@@ -319,8 +503,11 @@ export function editFile(fileName, folder) {
// If we started in plain text due to timeout, flip to the real mode once it arrives // If we started in plain text due to timeout, flip to the real mode once it arrives
modePromise.then(() => { modePromise.then(() => {
if (!canceled && !forcePlainText && isModeRegistered()) { if (!canceled && !forcePlainText) {
editor.setOption("mode", desiredMode); const nn = normalizeModeName(desiredMode);
if (nn && isModeRegistered(nn)) {
editor.setOption("mode", desiredMode);
}
} }
}).catch(() => { }).catch(() => {
// If the mode truly fails to load, we just stay in plain text // If the mode truly fails to load, we just stay in plain text

View File

@@ -11,11 +11,11 @@ import {
updateRowHighlight, updateRowHighlight,
toggleRowSelection, toggleRowSelection,
attachEnterKeyListener attachEnterKeyListener
} from './domUtils.js'; } from './domUtils.js?v={{APP_QVER}}';
import { t } from './i18n.js'; import { t } from './i18n.js?v={{APP_QVER}}';
import { bindFileListContextMenu } from './fileMenu.js'; import { bindFileListContextMenu } from './fileMenu.js?v={{APP_QVER}}';
import { openDownloadModal } from './fileActions.js'; import { openDownloadModal } from './fileActions.js?v={{APP_QVER}}';
import { openTagModal, openMultiTagModal } from './fileTags.js'; import { openTagModal, openMultiTagModal } from './fileTags.js?v={{APP_QVER}}';
import { import {
getParentFolder, getParentFolder,
updateBreadcrumbTitle, updateBreadcrumbTitle,
@@ -24,16 +24,35 @@ import {
hideFolderManagerContextMenu, hideFolderManagerContextMenu,
openRenameFolderModal, openRenameFolderModal,
openDeleteFolderModal openDeleteFolderModal
} from './folderManager.js'; } from './folderManager.js?v={{APP_QVER}}';
import { openFolderShareModal } from './folderShareModal.js'; import { openFolderShareModal } from './folderShareModal.js?v={{APP_QVER}}';
import { import {
folderDragOverHandler, folderDragOverHandler,
folderDragLeaveHandler, folderDragLeaveHandler,
folderDropHandler folderDropHandler
} from './fileDragDrop.js'; } from './fileDragDrop.js?v={{APP_QVER}}';
export let fileData = []; export let fileData = [];
export let sortOrder = { column: "uploaded", ascending: true }; export let sortOrder = { column: "uploaded", ascending: true };
// onnlyoffice
let OO_ENABLED = false;
let OO_EXTS = new Set();
export async function initOnlyOfficeCaps() {
try {
const r = await fetch('/api/onlyoffice/status.php', { credentials: 'include' });
if (!r.ok) throw 0;
const j = await r.json();
OO_ENABLED = !!j.enabled;
OO_EXTS = new Set(Array.isArray(j.exts) ? j.exts : []);
} catch {
OO_ENABLED = false;
OO_EXTS = new Set();
}
}
// Hide "Edit" for files >10 MiB // Hide "Edit" for files >10 MiB
const MAX_EDIT_BYTES = 10 * 1024 * 1024; const MAX_EDIT_BYTES = 10 * 1024 * 1024;
@@ -205,29 +224,84 @@ function wireSelectAll(fileListContent) {
/** /**
* Fuse.js fuzzy search helper * Fuse.js fuzzy search helper
*/ */
function searchFiles(searchTerm) { // --- Lazy Fuse loader (drop-in, CSP-safe, no inline) ---
if (!searchTerm) return fileData; const FUSE_SRC = '/vendor/fuse/6.6.2/fuse.min.js?v={{APP_QVER}}';
let _fuseLoadingPromise = null;
let keys = [
{ name: 'name', weight: 0.1 }, function loadScriptOnce(src) {
{ name: 'uploader', weight: 0.1 }, // cache by src so we don't append multiple <script> tags
{ name: 'tags.name', weight: 0.1 } if (loadScriptOnce._cache?.has(src)) return loadScriptOnce._cache.get(src);
]; loadScriptOnce._cache = loadScriptOnce._cache || new Map();
if (window.advancedSearchEnabled) { const p = new Promise((resolve, reject) => {
keys.push({ name: 'content', weight: 0.7 }); const s = document.createElement('script');
} s.src = src;
s.async = true;
s.onload = resolve;
s.onerror = () => reject(new Error(`Failed to load ${src}`));
document.head.appendChild(s);
});
loadScriptOnce._cache.set(src, p);
return p;
}
function lazyLoadFuse() {
if (window.Fuse) return Promise.resolve(window.Fuse);
if (!_fuseLoadingPromise) {
_fuseLoadingPromise = loadScriptOnce(FUSE_SRC).then(() => window.Fuse);
}
return _fuseLoadingPromise;
}
// (Optional) warm-up call you can trigger from main.js after first render:
// import { warmUpSearch } from './fileListView.js?v={{APP_QVER}}';
// warmUpSearch();
// This just starts fetching Fuse in the background.
export function warmUpSearch() {
lazyLoadFuse().catch(() => {/* ignore; well fall back */});
}
// Lazy + backward-compatible search
function searchFiles(searchTerm) {
if (!searchTerm) return fileData;
// kick off Fuse load in the background, but don't await
lazyLoadFuse().catch(() => { /* ignore */ });
// keys config (matches your original)
const fuseKeys = [
{ name: 'name', weight: 0.1 },
{ name: 'uploader', weight: 0.1 },
{ name: 'tags.name', weight: 0.1 }
];
if (window.advancedSearchEnabled) {
fuseKeys.push({ name: 'content', weight: 0.7 });
}
// If Fuse is present, use it right away (synchronous API)
if (window.Fuse) {
const options = { const options = {
keys: keys, keys: fuseKeys,
threshold: 0.4, threshold: 0.4,
minMatchCharLength: 2, minMatchCharLength: 2,
ignoreLocation: true ignoreLocation: true
}; };
const fuse = new window.Fuse(fileData, options);
const fuse = new Fuse(fileData, options); const results = fuse.search(searchTerm);
let results = fuse.search(searchTerm); return results.map(r => r.item);
return results.map(result => result.item);
} }
// Fallback (first keystrokes before Fuse finishes loading):
// simple case-insensitive substring match on the same fields
const q = String(searchTerm).toLowerCase();
const hay = (v) => (v == null ? '' : String(v)).toLowerCase();
return fileData.filter(item => {
if (hay(item.name).includes(q)) return true;
if (hay(item.uploader).includes(q)) return true;
if (Array.isArray(item.tags) && item.tags.some(t => hay(t?.name).includes(q))) return true;
if (window.advancedSearchEnabled && hay(item.content).includes(q)) return true;
return false;
});
}
/** /**
* View mode toggle * View mode toggle
@@ -283,6 +357,7 @@ function wireSelectAll(fileListContent) {
window.updateRowHighlight = updateRowHighlight; window.updateRowHighlight = updateRowHighlight;
export async function loadFileList(folderParam) { export async function loadFileList(folderParam) {
await initOnlyOfficeCaps();
const reqId = ++__fileListReqSeq; // latest call wins const reqId = ++__fileListReqSeq; // latest call wins
const folder = folderParam || "root"; const folder = folderParam || "root";
const fileListContainer = document.getElementById("fileList"); const fileListContainer = document.getElementById("fileList");
@@ -750,7 +825,7 @@ function wireSelectAll(fileListContent) {
fileListContent.querySelectorAll(".edit-btn").forEach(btn => { fileListContent.querySelectorAll(".edit-btn").forEach(btn => {
btn.addEventListener("click", async e => { btn.addEventListener("click", async e => {
e.stopPropagation(); e.stopPropagation();
const m = await import('./fileEditor.js'); const m = await import('./fileEditor.js?v={{APP_QVER}}');
m.editFile(btn.dataset.editName, btn.dataset.editFolder); m.editFile(btn.dataset.editName, btn.dataset.editFolder);
}); });
}); });
@@ -759,7 +834,7 @@ function wireSelectAll(fileListContent) {
fileListContent.querySelectorAll(".rename-btn").forEach(btn => { fileListContent.querySelectorAll(".rename-btn").forEach(btn => {
btn.addEventListener("click", async e => { btn.addEventListener("click", async e => {
e.stopPropagation(); e.stopPropagation();
const m = await import('./fileActions.js'); const m = await import('./fileActions.js?v={{APP_QVER}}');
m.renameFile(btn.dataset.renameName, btn.dataset.renameFolder); m.renameFile(btn.dataset.renameName, btn.dataset.renameFolder);
}); });
}); });
@@ -768,7 +843,7 @@ function wireSelectAll(fileListContent) {
fileListContent.querySelectorAll(".preview-btn").forEach(btn => { fileListContent.querySelectorAll(".preview-btn").forEach(btn => {
btn.addEventListener("click", async e => { btn.addEventListener("click", async e => {
e.stopPropagation(); e.stopPropagation();
const m = await import('./filePreview.js'); const m = await import('./filePreview.js?v={{APP_QVER}}');
m.previewFile(btn.dataset.previewUrl, btn.dataset.previewName); m.previewFile(btn.dataset.previewUrl, btn.dataset.previewName);
}); });
}); });
@@ -822,7 +897,7 @@ function wireSelectAll(fileListContent) {
const fileName = this.getAttribute("data-file"); const fileName = this.getAttribute("data-file");
const file = fileData.find(f => f.name === fileName); const file = fileData.find(f => f.name === fileName);
if (file) { if (file) {
import('./filePreview.js').then(module => { import('./filePreview.js?v={{APP_QVER}}').then(module => {
module.openShareModal(file, folder); module.openShareModal(file, folder);
}); });
} }
@@ -831,7 +906,7 @@ function wireSelectAll(fileListContent) {
updateFileActionButtons(); updateFileActionButtons();
document.querySelectorAll("#fileList tbody tr").forEach(row => { document.querySelectorAll("#fileList tbody tr").forEach(row => {
row.setAttribute("draggable", "true"); row.setAttribute("draggable", "true");
import('./fileDragDrop.js').then(module => { import('./fileDragDrop.js?v={{APP_QVER}}').then(module => {
row.addEventListener("dragstart", module.fileDragStartHandler); row.addEventListener("dragstart", module.fileDragStartHandler);
}); });
}); });
@@ -1085,7 +1160,7 @@ function wireSelectAll(fileListContent) {
// preview clicks (dynamic import to avoid global dependency) // preview clicks (dynamic import to avoid global dependency)
fileListContent.querySelectorAll(".gallery-preview").forEach(el => { fileListContent.querySelectorAll(".gallery-preview").forEach(el => {
el.addEventListener("click", async () => { el.addEventListener("click", async () => {
const m = await import('./filePreview.js'); const m = await import('./filePreview.js?v={{APP_QVER}}');
m.previewFile(el.dataset.previewUrl, el.dataset.previewName); m.previewFile(el.dataset.previewUrl, el.dataset.previewName);
}); });
}); });
@@ -1102,7 +1177,7 @@ function wireSelectAll(fileListContent) {
fileListContent.querySelectorAll(".edit-btn").forEach(btn => { fileListContent.querySelectorAll(".edit-btn").forEach(btn => {
btn.addEventListener("click", async e => { btn.addEventListener("click", async e => {
e.stopPropagation(); e.stopPropagation();
const m = await import('./fileEditor.js'); const m = await import('./fileEditor.js?v={{APP_QVER}}');
m.editFile(btn.dataset.editName, btn.dataset.editFolder); m.editFile(btn.dataset.editName, btn.dataset.editFolder);
}); });
}); });
@@ -1111,7 +1186,7 @@ function wireSelectAll(fileListContent) {
fileListContent.querySelectorAll(".rename-btn").forEach(btn => { fileListContent.querySelectorAll(".rename-btn").forEach(btn => {
btn.addEventListener("click", async e => { btn.addEventListener("click", async e => {
e.stopPropagation(); e.stopPropagation();
const m = await import('./fileActions.js'); const m = await import('./fileActions.js?v={{APP_QVER}}');
m.renameFile(btn.dataset.renameName, btn.dataset.renameFolder); m.renameFile(btn.dataset.renameName, btn.dataset.renameFolder);
}); });
}); });
@@ -1123,7 +1198,7 @@ function wireSelectAll(fileListContent) {
const fileName = btn.dataset.file; const fileName = btn.dataset.file;
const fileObj = fileData.find(f => f.name === fileName); const fileObj = fileData.find(f => f.name === fileName);
if (fileObj) { if (fileObj) {
import('./filePreview.js').then(m => m.openShareModal(fileObj, folder)); import('./filePreview.js?v={{APP_QVER}}').then(m => m.openShareModal(fileObj, folder));
} }
}); });
}); });
@@ -1273,46 +1348,34 @@ function wireSelectAll(fileListContent) {
if (!fileName || typeof fileName !== "string") return false; if (!fileName || typeof fileName !== "string") return false;
const dot = fileName.lastIndexOf("."); const dot = fileName.lastIndexOf(".");
if (dot < 0) return false; if (dot < 0) return false;
const ext = fileName.slice(dot + 1).toLowerCase(); const ext = fileName.slice(dot + 1).toLowerCase();
const allowedExtensions = [ // Your CodeMirror text-based types
"txt", "text", "md", "markdown", "rst", const textEditExts = new Set([
"html", "htm", "xhtml", "shtml", "txt","text","md","markdown","rst",
"css", "scss", "sass", "less", "html","htm","xhtml","shtml",
"js", "mjs", "cjs", "jsx", "css","scss","sass","less",
"ts", "tsx", "js","mjs","cjs","jsx",
"json", "jsonc", "ndjson", "ts","tsx",
"yml", "yaml", "toml", "xml", "plist", "json","jsonc","ndjson",
"ini", "conf", "config", "cfg", "cnf", "properties", "props", "rc", "yml","yaml","toml","xml","plist",
"env", "dotenv", "ini","conf","config","cfg","cnf","properties","props","rc",
"csv", "tsv", "tab", "env","dotenv",
"csv","tsv","tab",
"log", "log",
"sh", "bash", "zsh", "ksh", "fish", "sh","bash","zsh","ksh","fish",
"bat", "cmd", "bat","cmd",
"ps1", "psm1", "psd1", "ps1","psm1","psd1",
"py", "pyw", "py","pyw","rb","pl","pm","go","rs","java","kt","kts",
"rb", "scala","sc","groovy","gradle",
"pl", "pm", "c","h","cpp","cxx","cc","hpp","hh","hxx",
"go", "m","mm","swift","cs","fs","fsx","dart","lua","r","rmd",
"rs", "sql","vue","svelte","twig","mustache","hbs","handlebars","ejs","pug","jade"
"java", ]);
"kt", "kts",
"scala", "sc",
"groovy", "gradle",
"c", "h", "cpp", "cxx", "cc", "hpp", "hh", "hxx",
"m", "mm",
"swift",
"cs", "fs", "fsx",
"dart",
"lua",
"r", "rmd",
"sql",
"vue", "svelte",
"twig", "mustache", "hbs", "handlebars", "ejs", "pug", "jade"
];
return allowedExtensions.includes(ext); if (textEditExts.has(ext)) return true; // CodeMirror
if (OO_ENABLED && OO_EXTS.has(ext)) return true; // ONLYOFFICE types if enabled
return false;
} }
// Expose global functions for pagination and preview. // Expose global functions for pagination and preview.

View File

@@ -1,10 +1,10 @@
// fileManager.js // fileManager.js
import './fileListView.js'; import './fileListView.js?v={{APP_QVER}}';
import './filePreview.js'; import './filePreview.js?v={{APP_QVER}}';
import './fileEditor.js'; import './fileEditor.js?v={{APP_QVER}}';
import './fileDragDrop.js'; import './fileDragDrop.js?v={{APP_QVER}}';
import './fileMenu.js'; import './fileMenu.js?v={{APP_QVER}}';
import { initFileActions } from './fileActions.js'; import { initFileActions } from './fileActions.js?v={{APP_QVER}}';
// Initialize file action buttons. // Initialize file action buttons.
document.addEventListener("DOMContentLoaded", function () { document.addEventListener("DOMContentLoaded", function () {
@@ -14,7 +14,7 @@ document.addEventListener("DOMContentLoaded", function () {
// Attach folder drag-and-drop support for folder tree nodes. // Attach folder drag-and-drop support for folder tree nodes.
document.addEventListener("DOMContentLoaded", function () { document.addEventListener("DOMContentLoaded", function () {
document.querySelectorAll(".folder-option").forEach(el => { document.querySelectorAll(".folder-option").forEach(el => {
import('./fileDragDrop.js').then(module => { import('./fileDragDrop.js?v={{APP_QVER}}').then(module => {
el.addEventListener("dragover", module.folderDragOverHandler); el.addEventListener("dragover", module.folderDragOverHandler);
el.addEventListener("dragleave", module.folderDragLeaveHandler); el.addEventListener("dragleave", module.folderDragLeaveHandler);
el.addEventListener("drop", module.folderDropHandler); el.addEventListener("drop", module.folderDropHandler);
@@ -32,7 +32,7 @@ document.addEventListener("keydown", function(e) {
const selectedCheckboxes = document.querySelectorAll("#fileList .file-checkbox:checked"); const selectedCheckboxes = document.querySelectorAll("#fileList .file-checkbox:checked");
if (selectedCheckboxes.length > 0) { if (selectedCheckboxes.length > 0) {
e.preventDefault(); e.preventDefault();
import('./fileActions.js').then(module => { import('./fileActions.js?v={{APP_QVER}}').then(module => {
module.handleDeleteSelected(new Event("click")); module.handleDeleteSelected(new Event("click"));
}); });
} }

View File

@@ -1,11 +1,11 @@
// fileMenu.js // fileMenu.js
import { updateRowHighlight, showToast } from './domUtils.js'; import { updateRowHighlight, showToast } from './domUtils.js?v={{APP_QVER}}';
import { handleDeleteSelected, handleCopySelected, handleMoveSelected, handleDownloadZipSelected, handleExtractZipSelected, renameFile, openCreateFileModal } from './fileActions.js'; import { handleDeleteSelected, handleCopySelected, handleMoveSelected, handleDownloadZipSelected, handleExtractZipSelected, renameFile, openCreateFileModal } from './fileActions.js?v={{APP_QVER}}';
import { previewFile } from './filePreview.js'; import { previewFile, buildPreviewUrl } from './filePreview.js?v={{APP_QVER}}';
import { editFile } from './fileEditor.js'; import { editFile } from './fileEditor.js?v={{APP_QVER}}';
import { canEditFile, fileData } from './fileListView.js'; import { canEditFile, fileData } from './fileListView.js?v={{APP_QVER}}';
import { openTagModal, openMultiTagModal } from './fileTags.js'; import { openTagModal, openMultiTagModal } from './fileTags.js?v={{APP_QVER}}';
import { t } from './i18n.js'; import { t } from './i18n.js?v={{APP_QVER}}';
export function showFileContextMenu(x, y, menuItems) { export function showFileContextMenu(x, y, menuItems) {
let menu = document.getElementById("fileContextMenu"); let menu = document.getElementById("fileContextMenu");
@@ -39,11 +39,11 @@ export function showFileContextMenu(x, y, menuItems) {
}); });
menu.appendChild(menuItem); menu.appendChild(menuItem);
}); });
menu.style.left = x + "px"; menu.style.left = x + "px";
menu.style.top = y + "px"; menu.style.top = y + "px";
menu.style.display = "block"; menu.style.display = "block";
const menuRect = menu.getBoundingClientRect(); const menuRect = menu.getBoundingClientRect();
const viewportHeight = window.innerHeight; const viewportHeight = window.innerHeight;
if (menuRect.bottom > viewportHeight) { if (menuRect.bottom > viewportHeight) {
@@ -62,7 +62,7 @@ export function hideFileContextMenu() {
export function fileListContextMenuHandler(e) { export function fileListContextMenuHandler(e) {
e.preventDefault(); e.preventDefault();
let row = e.target.closest("tr"); let row = e.target.closest("tr");
if (row) { if (row) {
const checkbox = row.querySelector(".file-checkbox"); const checkbox = row.querySelector(".file-checkbox");
@@ -71,9 +71,9 @@ export function fileListContextMenuHandler(e) {
updateRowHighlight(checkbox); updateRowHighlight(checkbox);
} }
} }
const selected = Array.from(document.querySelectorAll("#fileList .file-checkbox:checked")).map(chk => chk.value); const selected = Array.from(document.querySelectorAll("#fileList .file-checkbox:checked")).map(chk => chk.value);
let menuItems = [ let menuItems = [
{ label: t("create_file"), action: () => openCreateFileModal() }, { label: t("create_file"), action: () => openCreateFileModal() },
{ label: t("delete_selected"), action: () => { handleDeleteSelected(new Event("click")); } }, { label: t("delete_selected"), action: () => { handleDeleteSelected(new Event("click")); } },
@@ -81,14 +81,14 @@ export function fileListContextMenuHandler(e) {
{ label: t("move_selected"), action: () => { handleMoveSelected(new Event("click")); } }, { label: t("move_selected"), action: () => { handleMoveSelected(new Event("click")); } },
{ label: t("download_zip"), action: () => { handleDownloadZipSelected(new Event("click")); } } { label: t("download_zip"), action: () => { handleDownloadZipSelected(new Event("click")); } }
]; ];
if (selected.some(name => name.toLowerCase().endsWith(".zip"))) { if (selected.some(name => name.toLowerCase().endsWith(".zip"))) {
menuItems.push({ menuItems.push({
label: t("extract_zip"), label: t("extract_zip"),
action: () => { handleExtractZipSelected(new Event("click")); } action: () => { handleExtractZipSelected(new Event("click")); }
}); });
} }
if (selected.length > 1) { if (selected.length > 1) {
menuItems.push({ menuItems.push({
label: t("tag_selected"), label: t("tag_selected"),
@@ -100,36 +100,33 @@ export function fileListContextMenuHandler(e) {
} }
else if (selected.length === 1) { else if (selected.length === 1) {
const file = fileData.find(f => f.name === selected[0]); const file = fileData.find(f => f.name === selected[0]);
menuItems.push({ menuItems.push({
label: t("preview"), label: t("preview"),
action: () => { action: () => {
const folder = window.currentFolder || "root"; const folder = window.currentFolder || "root";
const folderPath = folder === "root" previewFile(buildPreviewUrl(folder, file.name), file.name);
? "uploads/"
: "uploads/" + folder.split("/").map(encodeURIComponent).join("/") + "/";
previewFile(folderPath + encodeURIComponent(file.name) + "?t=" + new Date().getTime(), file.name);
} }
}); });
if (canEditFile(file.name)) { if (canEditFile(file.name)) {
menuItems.push({ menuItems.push({
label: t("edit"), label: t("edit"),
action: () => { editFile(selected[0], window.currentFolder); } action: () => { editFile(selected[0], window.currentFolder); }
}); });
} }
menuItems.push({ menuItems.push({
label: t("rename"), label: t("rename"),
action: () => { renameFile(selected[0], window.currentFolder); } action: () => { renameFile(selected[0], window.currentFolder); }
}); });
menuItems.push({ menuItems.push({
label: t("tag_file"), label: t("tag_file"),
action: () => { openTagModal(file); } action: () => { openTagModal(file); }
}); });
} }
showFileContextMenu(e.clientX, e.clientY, menuItems); showFileContextMenu(e.clientX, e.clientY, menuItems);
} }
@@ -140,7 +137,7 @@ export function bindFileListContextMenu() {
} }
} }
document.addEventListener("click", function(e) { document.addEventListener("click", function (e) {
const menu = document.getElementById("fileContextMenu"); const menu = document.getElementById("fileContextMenu");
if (menu && menu.style.display === "block") { if (menu && menu.style.display === "block") {
hideFileContextMenu(); hideFileContextMenu();
@@ -148,9 +145,9 @@ document.addEventListener("click", function(e) {
}); });
// Rebind context menu after file table render. // Rebind context menu after file table render.
(function() { (function () {
const originalRenderFileTable = window.renderFileTable; const originalRenderFileTable = window.renderFileTable;
window.renderFileTable = function(folder) { window.renderFileTable = function (folder) {
originalRenderFileTable(folder); originalRenderFileTable(folder);
bindFileListContextMenu(); bindFileListContextMenu();
}; };

View File

@@ -1,7 +1,13 @@
// filePreview.js // filePreview.js
import { escapeHTML, showToast } from './domUtils.js'; import { escapeHTML, showToast } from './domUtils.js?v={{APP_QVER}}';
import { fileData } from './fileListView.js'; import { fileData } from './fileListView.js?v={{APP_QVER}}';
import { t } from './i18n.js'; import { t } from './i18n.js?v={{APP_QVER}}';
// Build a preview URL that always goes through the API layer (respects ACLs/UPLOAD_DIR)
export function buildPreviewUrl(folder, name) {
const f = (!folder || folder === '') ? 'root' : String(folder);
return `/api/file/download.php?folder=${encodeURIComponent(f)}&file=${encodeURIComponent(name)}&inline=1&t=${Date.now()}`;
}
export function openShareModal(file, folder) { export function openShareModal(file, folder) {
// Remove any existing modal // Remove any existing modal
@@ -92,10 +98,10 @@ export function openShareModal(file, folder) {
if (sel.value === "custom") { if (sel.value === "custom") {
value = parseInt(document.getElementById("customExpirationValue").value, 10); value = parseInt(document.getElementById("customExpirationValue").value, 10);
unit = document.getElementById("customExpirationUnit").value; unit = document.getElementById("customExpirationUnit").value;
} else { } else {
value = parseInt(sel.value, 10); value = parseInt(sel.value, 10);
unit = "minutes"; unit = "minutes";
} }
const password = document.getElementById("sharePassword").value; const password = document.getElementById("sharePassword").value;
@@ -115,20 +121,20 @@ export function openShareModal(file, folder) {
password password
}) })
}) })
.then(res => res.json()) .then(res => res.json())
.then(data => { .then(data => {
if (data.token) { if (data.token) {
const url = `${window.location.origin}/api/file/share.php?token=${encodeURIComponent(data.token)}`; const url = `${window.location.origin}/api/file/share.php?token=${encodeURIComponent(data.token)}`;
document.getElementById("shareLinkInput").value = url; document.getElementById("shareLinkInput").value = url;
document.getElementById("shareLinkDisplay").style.display = "block"; document.getElementById("shareLinkDisplay").style.display = "block";
} else { } else {
showToast(t("error_generating_share") + ": " + (data.error||"Unknown")); showToast(t("error_generating_share") + ": " + (data.error || "Unknown"));
} }
}) })
.catch(err => { .catch(err => {
console.error(err); console.error(err);
showToast(t("error_generating_share")); showToast(t("error_generating_share"));
}); });
}); });
// Copy to clipboard // Copy to clipboard
@@ -272,10 +278,7 @@ export function previewFile(fileUrl, fileName) {
modal.galleryCurrentIndex = (modal.galleryCurrentIndex - 1 + modal.galleryImages.length) % modal.galleryImages.length; modal.galleryCurrentIndex = (modal.galleryCurrentIndex - 1 + modal.galleryImages.length) % modal.galleryImages.length;
let newFile = modal.galleryImages[modal.galleryCurrentIndex]; let newFile = modal.galleryImages[modal.galleryCurrentIndex];
modal.querySelector("h4").textContent = newFile.name; modal.querySelector("h4").textContent = newFile.name;
img.src = ((window.currentFolder === "root") img.src = buildPreviewUrl(window.currentFolder || 'root', newFile.name);
? "uploads/"
: "uploads/" + window.currentFolder.split("/").map(encodeURIComponent).join("/") + "/")
+ encodeURIComponent(newFile.name) + "?t=" + new Date().getTime();
// Reset transforms. // Reset transforms.
img.dataset.scale = 1; img.dataset.scale = 1;
img.dataset.rotate = 0; img.dataset.rotate = 0;
@@ -355,10 +358,7 @@ export function previewFile(fileUrl, fileName) {
modal.galleryCurrentIndex = (modal.galleryCurrentIndex + 1) % modal.galleryImages.length; modal.galleryCurrentIndex = (modal.galleryCurrentIndex + 1) % modal.galleryImages.length;
let newFile = modal.galleryImages[modal.galleryCurrentIndex]; let newFile = modal.galleryImages[modal.galleryCurrentIndex];
modal.querySelector("h4").textContent = newFile.name; modal.querySelector("h4").textContent = newFile.name;
img.src = ((window.currentFolder === "root") img.src = buildPreviewUrl(window.currentFolder || 'root', newFile.name);
? "uploads/"
: "uploads/" + window.currentFolder.split("/").map(encodeURIComponent).join("/") + "/")
+ encodeURIComponent(newFile.name) + "?t=" + new Date().getTime();
// Reset transforms. // Reset transforms.
img.dataset.scale = 1; img.dataset.scale = 1;
img.dataset.rotate = 0; img.dataset.rotate = 0;
@@ -416,26 +416,26 @@ export function previewFile(fileUrl, fileName) {
} }
} else { } else {
// Handle non-image file previews. // Handle non-image file previews.
if (extension === "pdf") { if (extension === "pdf") {
// build a cachebusted URL // build a cachebusted URL
const separator = fileUrl.includes('?') ? '&' : '?'; const separator = fileUrl.includes('?') ? '&' : '?';
const urlWithTs = fileUrl + separator + 't=' + Date.now(); const urlWithTs = fileUrl + separator + 't=' + Date.now();
// open in a new tab (avoids CSP frame-ancestors) // open in a new tab (avoids CSP frame-ancestors)
window.open(urlWithTs, "_blank"); window.open(urlWithTs, "_blank");
// tear down the just-created modal // tear down the just-created modal
const modal = document.getElementById("filePreviewModal"); const modal = document.getElementById("filePreviewModal");
if (modal) modal.remove(); if (modal) modal.remove();
// stop further preview logic // stop further preview logic
return; return;
} else if (/\.(mp4|mkv|webm|mov|ogv)$/i.test(fileName)) { } else if (/\.(mp4|mkv|webm|mov|ogv)$/i.test(fileName)) {
const video = document.createElement("video"); const video = document.createElement("video");
video.src = fileUrl; video.src = fileUrl;
video.controls = true; video.controls = true;
video.className = "image-modal-img"; video.className = "image-modal-img";
const progressKey = 'videoProgress-' + fileUrl; const progressKey = 'videoProgress-' + fileUrl;
video.addEventListener("loadedmetadata", () => { video.addEventListener("loadedmetadata", () => {
const savedTime = localStorage.getItem(progressKey); const savedTime = localStorage.getItem(progressKey);

View File

@@ -3,9 +3,9 @@
// adding tags to files (with a global tag store for reuse), // adding tags to files (with a global tag store for reuse),
// updating the file row display with tag badges, // updating the file row display with tag badges,
// filtering the file list by tag, and persisting tag data. // filtering the file list by tag, and persisting tag data.
import { escapeHTML } from './domUtils.js'; import { escapeHTML } from './domUtils.js?v={{APP_QVER}}';
import { t } from './i18n.js'; import { t } from './i18n.js?v={{APP_QVER}}';
import { renderFileTable, renderGalleryView } from './fileListView.js'; import { renderFileTable, renderGalleryView } from './fileListView.js?v={{APP_QVER}}';
export function openTagModal(file) { export function openTagModal(file) {
// Create the modal element. // Create the modal element.

View File

@@ -1,11 +1,11 @@
// folderManager.js // folderManager.js
import { loadFileList } from './fileListView.js'; import { loadFileList } from './fileListView.js?v={{APP_QVER}}';
import { showToast, escapeHTML, attachEnterKeyListener } from './domUtils.js'; import { showToast, escapeHTML, attachEnterKeyListener } from './domUtils.js?v={{APP_QVER}}';
import { t } from './i18n.js'; import { t } from './i18n.js?v={{APP_QVER}}';
import { openFolderShareModal } from './folderShareModal.js'; import { openFolderShareModal } from './folderShareModal.js?v={{APP_QVER}}';
import { fetchWithCsrf } from './auth.js'; import { fetchWithCsrf } from './auth.js?v={{APP_QVER}}';
import { loadCsrfToken } from './main.js'; import { loadCsrfToken } from './appCore.js?v={{APP_QVER}}';
/* ---------------------- /* ----------------------
Helpers: safe JSON + state Helpers: safe JSON + state

View File

@@ -1,6 +1,6 @@
// js/folderShareModal.js // js/folderShareModal.js
import { escapeHTML, showToast } from './domUtils.js'; import { escapeHTML, showToast } from './domUtils.js?v={{APP_QVER}}';
import { t } from './i18n.js'; import { t } from './i18n.js?v={{APP_QVER}}';
export function openFolderShareModal(folder) { export function openFolderShareModal(folder) {
// Remove any existing modal // Remove any existing modal

View File

@@ -247,7 +247,7 @@ const translations = {
"login_options": "Login Options", "login_options": "Login Options",
"disable_login_form": "Disable Login Form", "disable_login_form": "Disable Login Form",
"disable_basic_http_auth": "Disable Basic HTTP Auth", "disable_basic_http_auth": "Disable Basic HTTP Auth",
"disable_oidc_login": "Disable OIDC Login", "disable_oidc_login": "Disable OIDC Login (OIDC Config Required to enable)",
"save_settings": "Save Settings", "save_settings": "Save Settings",
"at_least_one_login_method": "At least one login method must remain enabled.", "at_least_one_login_method": "At least one login method must remain enabled.",
"settings_updated_successfully": "Settings updated successfully.", "settings_updated_successfully": "Settings updated successfully.",

File diff suppressed because it is too large Load Diff

View File

@@ -1,9 +1,9 @@
// trashRestoreDelete.js // trashRestoreDelete.js
import { sendRequest } from './networkUtils.js'; import { sendRequest } from './networkUtils.js?v={{APP_QVER}}';
import { toggleVisibility, showToast } from './domUtils.js'; import { toggleVisibility, showToast } from './domUtils.js?v={{APP_QVER}}';
import { loadFileList } from './fileListView.js'; import { loadFileList } from './fileListView.js?v={{APP_QVER}}';
import { loadFolderTree } from './folderManager.js'; import { loadFolderTree } from './folderManager.js?v={{APP_QVER}}';
import { t } from './i18n.js'; import { t } from './i18n.js?v={{APP_QVER}}';
function showConfirm(message, onConfirm) { function showConfirm(message, onConfirm) {
const modal = document.getElementById("customConfirmModal"); const modal = document.getElementById("customConfirmModal");

View File

@@ -1,9 +1,9 @@
import { initFileActions } from './fileActions.js'; import { initFileActions } from './fileActions.js?v={{APP_QVER}}';
import { displayFilePreview } from './filePreview.js'; import { displayFilePreview } from './filePreview.js?v={{APP_QVER}}';
import { showToast, escapeHTML } from './domUtils.js'; import { showToast, escapeHTML } from './domUtils.js?v={{APP_QVER}}';
import { loadFolderTree } from './folderManager.js'; import { loadFolderTree } from './folderManager.js?v={{APP_QVER}}';
import { loadFileList } from './fileListView.js'; import { loadFileList } from './fileListView.js?v={{APP_QVER}}';
import { t } from './i18n.js'; import { t } from './i18n.js?v={{APP_QVER}}';
/* ----------------------------------------------------- /* -----------------------------------------------------
Helpers for DragandDrop Folder Uploads (Original Code) Helpers for DragandDrop Folder Uploads (Original Code)
@@ -36,6 +36,38 @@ function traverseFileTreePromise(item, path = "") {
}); });
} }
// --- Lazy loader for Resumable.js (no CSP inline, cached, safe) ---
const RESUMABLE_SRC = '/vendor/resumable/1.1.0/resumable.min.js?v={{APP_QVER}}';
let _resumableLoadPromise = null;
function loadScriptOnce(src) {
if (loadScriptOnce._cache?.has(src)) return loadScriptOnce._cache.get(src);
loadScriptOnce._cache = loadScriptOnce._cache || new Map();
const p = new Promise((resolve, reject) => {
const s = document.createElement('script');
s.src = src;
s.async = true;
s.onload = resolve;
s.onerror = () => reject(new Error(`Failed to load ${src}`));
document.head.appendChild(s);
});
loadScriptOnce._cache.set(src, p);
return p;
}
function lazyLoadResumable() {
if (window.Resumable) return Promise.resolve(window.Resumable);
if (!_resumableLoadPromise) {
_resumableLoadPromise = loadScriptOnce(RESUMABLE_SRC).then(() => window.Resumable);
}
return _resumableLoadPromise;
}
// Optional: let main.js prefetch it in the background
export function warmUpResumable() {
lazyLoadResumable().catch(() => {/* ignore warm-up failure */});
}
// Recursively retrieve files from DataTransfer items. // Recursively retrieve files from DataTransfer items.
function getFilesFromDataTransferItems(items) { function getFilesFromDataTransferItems(items) {
const promises = []; const promises = [];
@@ -401,36 +433,49 @@ function processFiles(filesInput) {
Resumable.js Integration for File Picker Uploads Resumable.js Integration for File Picker Uploads
(Only files chosen via file input use Resumable; folder uploads use original code.) (Only files chosen via file input use Resumable; folder uploads use original code.)
----------------------------------------------------- */ ----------------------------------------------------- */
const useResumable = true; // Enable resumable for file picker uploads const useResumable = true;
let resumableInstance; let resumableInstance = null;
function initResumableUpload() { let _pendingPickedFiles = []; // files picked before library/instance ready
resumableInstance = new Resumable({ let _resumableReady = false;
target: "/api/upload/upload.php",
chunkSize: 1.5 * 1024 * 1024, // Make init async-safe; it resolves when Resumable is constructed
simultaneousUploads: 3, async function initResumableUpload() {
forceChunkSize: true, if (resumableInstance) return;
testChunks: false, // Load the library if needed
withCredentials: true, const ResumableCtor = await lazyLoadResumable().catch(err => {
headers: { 'X-CSRF-Token': window.csrfToken }, console.error('Failed to load Resumable.js:', err);
query: () => ({ return null;
folder: window.currentFolder || "root",
upload_token: window.csrfToken
})
}); });
if (!ResumableCtor) return;
// Construct the instance once
if (!resumableInstance) {
resumableInstance = new ResumableCtor({
target: "/api/upload/upload.php",
chunkSize: 1.5 * 1024 * 1024,
simultaneousUploads: 3,
forceChunkSize: true,
testChunks: false,
withCredentials: true,
headers: { 'X-CSRF-Token': window.csrfToken },
query: () => ({
folder: window.currentFolder || "root",
upload_token: window.csrfToken
})
});
}
// keep query fresh when folder changes (call this from your folder nav code) // keep query fresh when folder changes (call this from your folder nav code)
function updateResumableQuery() { function updateResumableQuery() {
if (!resumableInstance) return; if (!resumableInstance) return;
resumableInstance.opts.headers['X-CSRF-Token'] = window.csrfToken; resumableInstance.opts.headers['X-CSRF-Token'] = window.csrfToken;
// if you're not using a function for query, do:
resumableInstance.opts.query.folder = window.currentFolder || 'root'; resumableInstance.opts.query.folder = window.currentFolder || 'root';
resumableInstance.opts.query.upload_token = window.csrfToken; resumableInstance.opts.query.upload_token = window.csrfToken;
} }
const fileInput = document.getElementById("file"); const fileInput = document.getElementById("file");
if (fileInput) { if (fileInput) {
// Assign Resumable to file input for file picker uploads.
resumableInstance.assignBrowse(fileInput);
fileInput.addEventListener("change", function () { fileInput.addEventListener("change", function () {
for (let i = 0; i < fileInput.files.length; i++) { for (let i = 0; i < fileInput.files.length; i++) {
resumableInstance.addFile(fileInput.files[i]); resumableInstance.addFile(fileInput.files[i]);
@@ -587,13 +632,24 @@ function initResumableUpload() {
showToast("Some files failed to upload. Please check the list."); showToast("Some files failed to upload. Please check the list.");
} }
}); });
_resumableReady = true;
if (_pendingPickedFiles.length) {
updateResumableQuery();
for (const f of _pendingPickedFiles) resumableInstance.addFile(f);
_pendingPickedFiles = [];
}
} }
/* ----------------------------------------------------- /* -----------------------------------------------------
XHR-based submitFiles for DragandDrop (Folder) Uploads XHR-based submitFiles for DragandDrop (Folder) Uploads
----------------------------------------------------- */ ----------------------------------------------------- */
function submitFiles(allFiles) { function submitFiles(allFiles) {
const folderToUse = window.currentFolder || "root"; const folderToUse = (() => {
const f = window.currentFolder || "root";
try { return decodeURIComponent(f); } catch { return f; }
})();
const progressContainer = document.getElementById("uploadProgressContainer"); const progressContainer = document.getElementById("uploadProgressContainer");
const fileInput = document.getElementById("file"); const fileInput = document.getElementById("file");
@@ -857,32 +913,48 @@ function initUpload() {
} }
if (fileInput) { if (fileInput) {
fileInput.addEventListener("change", function () { fileInput.addEventListener("change", async function () {
const files = Array.from(fileInput.files || []);
if (!files.length) return;
if (useResumable) { if (useResumable) {
// For file picker, if resumable is enabled, let it handle the files. // Ensure the lib/instance exists
for (let i = 0; i < fileInput.files.length; i++) { if (!_resumableReady) await initResumableUpload();
resumableInstance.addFile(fileInput.files[i]); if (resumableInstance) {
for (const f of files) resumableInstance.addFile(f);
} else {
// If still not ready (load error), fall back to your XHR path
processFiles(files);
} }
} else { } else {
processFiles(fileInput.files); processFiles(files);
} }
}); });
} }
if (uploadForm) { if (uploadForm) {
uploadForm.addEventListener("submit", function (e) { uploadForm.addEventListener("submit", async function (e) {
e.preventDefault(); e.preventDefault();
const files = window.selectedFiles || (fileInput ? fileInput.files : []); const files = window.selectedFiles || (fileInput ? fileInput.files : []);
if (!files || files.length === 0) { if (!files || !files.length) {
showToast("No files selected."); showToast("No files selected.");
return; return;
} }
// If files come from file picker (no relative path), use Resumable.
if (useResumable && (!files[0].customRelativePath || files[0].customRelativePath === "")) { // Resumable path (only for picked files, not folder uploads)
// Ensure current folder is updated. const first = files[0];
resumableInstance.opts.query.folder = window.currentFolder || "root"; const isFolderish = !!(first.customRelativePath || first.webkitRelativePath);
resumableInstance.upload(); if (useResumable && !isFolderish) {
showToast("Resumable upload started..."); if (!_resumableReady) await initResumableUpload();
if (resumableInstance) {
// ensure folder/token fresh
resumableInstance.opts.query.folder = window.currentFolder || "root";
resumableInstance.upload();
showToast("Resumable upload started...");
} else {
// fallback
submitFiles(files);
}
} else { } else {
submitFiles(files); submitFiles(files);
} }

View File

@@ -1,2 +1,2 @@
// generated by CI // generated by CI
window.APP_VERSION = 'v1.6.11'; window.APP_VERSION = 'v1.8.0';

54
scripts/stamp-assets.sh Normal file
View File

@@ -0,0 +1,54 @@
#!/usr/bin/env bash
# usage: scripts/stamp-assets.sh vX.Y.Z /path/to/target/dir
set -euo pipefail
VER="${1:?usage: stamp-assets.sh vX.Y.Z target_dir}"
QVER="${VER#v}"
TARGET="${2:-.}"
echo "Stamping assets in: $TARGET"
echo "VER=${VER} QVER=${QVER}"
cd "$TARGET"
# Normalize CRLF to LF (if any files were edited on Windows)
# We only touch web assets.
find public \( -name '*.html' -o -name '*.php' -o -name '*.css' -o -name '*.js' \) -type f -print0 \
| xargs -0 -r sed -i 's/\r$//'
# --- HTML/CSS/PHP: stamp ?v=... and {{APP_VER}} ---
# (?v=...) -> ?v=<QVER>
HTML_CSS_COUNT=0
while IFS= read -r -d '' f; do
sed -E -i "s/(\?v=)[^\"'&<>\s]*/\1${QVER}/g" "$f"
sed -E -i "s/\{\{APP_VER\}\}/${VER}/g" "$f"
HTML_CSS_COUNT=$((HTML_CSS_COUNT+1))
done < <(find public -type f \( -name '*.html' -o -name '*.php' -o -name '*.css' \) -print0)
# --- JS: stamp placeholders and normalize any pre-existing ?v=... ---
JS_COUNT=0
while IFS= read -r -d '' f; do
# Replace placeholders
sed -E -i "s/\{\{APP_VER\}\}/${VER}/g" "$f"
sed -E -i "s/\{\{APP_QVER\}\}/${QVER}/g" "$f"
# Normalize any "?v=..." that appear in ESM imports or strings
# This keeps any ".js" or ".mjs" then forces ?v=<QVER>
perl -0777 -i -pe "s@(\.m?js)\?v=[^\"')]+@\1?v=${QVER}@g" "$f"
JS_COUNT=$((JS_COUNT+1))
done < <(find public -type f -name '*.js' -print0)
# Force-write version.js (source of truth in stamped output)
if [[ -f public/js/version.js ]]; then
printf "window.APP_VERSION = '%s';\n" "$VER" > public/js/version.js
fi
echo "Touched files: HTML/CSS/PHP=${HTML_CSS_COUNT}, JS=${JS_COUNT}"
# Final self-check: fail if anything is left
if grep -R -n -E "{{APP_QVER}}|{{APP_VER}}" public \
--include='*.html' --include='*.php' --include='*.css' --include='*.js' 2>/dev/null; then
echo "ERROR: Placeholders remain after stamping." >&2
exit 2
fi
echo "✅ Stamped to ${VER} (${QVER})"

View File

@@ -5,57 +5,93 @@ require_once __DIR__ . '/../../config/config.php';
require_once PROJECT_ROOT . '/src/models/AdminModel.php'; require_once PROJECT_ROOT . '/src/models/AdminModel.php';
class AdminController class AdminController
{
public function getConfig(): void
{ {
header('Content-Type: application/json'); public function getConfig(): void
{
header('Content-Type: application/json; charset=utf-8');
// Load raw config (no disclosure yet) $config = AdminModel::getConfig();
$config = AdminModel::getConfig(); if (isset($config['error'])) {
if (isset($config['error'])) { http_response_code(500);
http_response_code(500); header('Cache-Control: no-store');
echo json_encode(['error' => $config['error']]); echo json_encode(['error' => $config['error']], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
exit; return;
} }
// Minimal, safe subset for all callers (unauth users and regular users) // ---- Effective ONLYOFFICE values (constants override adminConfig) ----
$public = [ $ooCfg = is_array($config['onlyoffice'] ?? null) ? $config['onlyoffice'] : [];
'header_title' => $config['header_title'] ?? 'FileRise', $effEnabled = defined('ONLYOFFICE_ENABLED')
'loginOptions' => [ ? (bool) ONLYOFFICE_ENABLED
// expose only what the login page / header needs : (bool) ($ooCfg['enabled'] ?? false);
'disableFormLogin' => (bool)($config['loginOptions']['disableFormLogin'] ?? false),
'disableBasicAuth' => (bool)($config['loginOptions']['disableBasicAuth'] ?? false),
'disableOIDCLogin' => (bool)($config['loginOptions']['disableOIDCLogin'] ?? false),
],
'globalOtpauthUrl' => $config['globalOtpauthUrl'] ?? '',
'enableWebDAV' => (bool)($config['enableWebDAV'] ?? false),
'sharedMaxUploadSize' => (int)($config['sharedMaxUploadSize'] ?? 0),
'oidc' => [ $effDocs = defined('ONLYOFFICE_DOCS_ORIGIN') && ONLYOFFICE_DOCS_ORIGIN !== ''
'providerUrl' => (string)($config['oidc']['providerUrl'] ?? ''), ? (string) ONLYOFFICE_DOCS_ORIGIN
'redirectUri' => (string)($config['oidc']['redirectUri'] ?? ''), : (string) ($ooCfg['docsOrigin'] ?? '');
// never expose clientId / clientSecret
],
];
$isAdmin = !empty($_SESSION['authenticated']) && !empty($_SESSION['isAdmin']); $hasSecret = defined('ONLYOFFICE_JWT_SECRET')
? (ONLYOFFICE_JWT_SECRET !== '')
: (!empty($ooCfg['jwtSecret']));
if ($isAdmin) { $publicOriginCfg = (string) ($ooCfg['publicOrigin'] ?? '');
// Add admin-only fields (used by Admin Panel UI)
$adminExtra = [ // Whitelisted public subset only (+ ONLYOFFICE enabled flag)
'loginOptions' => array_merge($public['loginOptions'], [ $public = [
'authBypass' => (bool)($config['loginOptions']['authBypass'] ?? false), 'header_title' => (string)($config['header_title'] ?? 'FileRise'),
'authHeaderName' => (string)($config['loginOptions']['authHeaderName'] ?? 'X-Remote-User'), 'loginOptions' => [
]), 'disableFormLogin' => (bool)($config['loginOptions']['disableFormLogin'] ?? false),
'disableBasicAuth' => (bool)($config['loginOptions']['disableBasicAuth'] ?? false),
'disableOIDCLogin' => (bool)($config['loginOptions']['disableOIDCLogin'] ?? false),
],
'globalOtpauthUrl' => (string)($config['globalOtpauthUrl'] ?? ''),
'enableWebDAV' => (bool)($config['enableWebDAV'] ?? false),
'sharedMaxUploadSize' => (int)($config['sharedMaxUploadSize'] ?? 0),
'oidc' => [
'providerUrl' => (string)($config['oidc']['providerUrl'] ?? ''),
'redirectUri' => (string)($config['oidc']['redirectUri'] ?? ''),
// never include clientId/clientSecret
],
'onlyoffice' => [
// Public only needs to know if its on; no secrets/origins here.
'enabled' => $effEnabled,
],
]; ];
echo json_encode(array_merge($public, $adminExtra));
$isAdmin = !empty($_SESSION['authenticated']) && !empty($_SESSION['isAdmin']);
if ($isAdmin) {
// admin-only extras: presence flags + proxy options + ONLYOFFICE effective view
$adminExtra = [
'loginOptions' => array_merge($public['loginOptions'], [
'authBypass' => (bool)($config['loginOptions']['authBypass'] ?? false),
'authHeaderName' => (string)($config['loginOptions']['authHeaderName'] ?? 'X-Remote-User'),
]),
'oidc' => array_merge($public['oidc'], [
'hasClientId' => !empty($config['oidc']['clientId']),
'hasClientSecret' => !empty($config['oidc']['clientSecret']),
]),
'onlyoffice' => [
'enabled' => $effEnabled,
'docsOrigin' => $effDocs, // effective (constants win)
'publicOrigin' => $publicOriginCfg, // optional override from adminConfig
'hasJwtSecret' => (bool)$hasSecret, // boolean only; never leak secret
'lockedByPhp' => (
defined('ONLYOFFICE_ENABLED')
|| defined('ONLYOFFICE_DOCS_ORIGIN')
|| defined('ONLYOFFICE_JWT_SECRET')
),
],
];
header('Cache-Control: no-store'); // dont cache admin config
echo json_encode(array_merge($public, $adminExtra), JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
return;
}
// Non-admins / unauthenticated: only the public subset
header('Cache-Control: no-store');
echo json_encode($public, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
return; return;
} }
// Non-admins / unauthenticated: only the public subset
echo json_encode($public);
}
public function updateConfig(): void public function updateConfig(): void
{ {
header('Content-Type: application/json'); header('Content-Type: application/json');
@@ -99,7 +135,7 @@ class AdminController
'header_title' => '', 'header_title' => '',
'loginOptions' => [ 'loginOptions' => [
'disableFormLogin' => false, 'disableFormLogin' => false,
'disableBasicAuth' => false, 'disableBasicAuth' => true,
'disableOIDCLogin' => true, 'disableOIDCLogin' => true,
'authBypass' => false, 'authBypass' => false,
'authHeaderName' => 'X-Remote-User' 'authHeaderName' => 'X-Remote-User'
@@ -216,6 +252,40 @@ class AdminController
} }
// —– persist merged config —– // —– persist merged config —–
// ---- ONLYOFFICE: merge from payload (unless locked by PHP defines) ----
$ooLockedByPhp = (
defined('ONLYOFFICE_ENABLED') ||
defined('ONLYOFFICE_DOCS_ORIGIN') ||
defined('ONLYOFFICE_JWT_SECRET') ||
defined('ONLYOFFICE_PUBLIC_ORIGIN')
);
if (!$ooLockedByPhp && isset($data['onlyoffice']) && is_array($data['onlyoffice'])) {
$ooExisting = (isset($existing['onlyoffice']) && is_array($existing['onlyoffice']))
? $existing['onlyoffice'] : [];
$oo = $ooExisting;
if (array_key_exists('enabled', $data['onlyoffice'])) {
$oo['enabled'] = filter_var($data['onlyoffice']['enabled'], FILTER_VALIDATE_BOOLEAN);
}
if (isset($data['onlyoffice']['docsOrigin'])) {
$oo['docsOrigin'] = (string)$data['onlyoffice']['docsOrigin'];
}
if (isset($data['onlyoffice']['publicOrigin'])) {
$oo['publicOrigin'] = (string)$data['onlyoffice']['publicOrigin'];
}
// Allow setting/changing the secret when NOT locked by PHP
if (isset($data['onlyoffice']['jwtSecret'])) {
$js = trim((string)$data['onlyoffice']['jwtSecret']);
if ($js !== '') {
$oo['jwtSecret'] = $js; // stored encrypted by AdminModel
}
// If blank, we leave existing secret unchanged (no implicit wipe).
}
$merged['onlyoffice'] = $oo;
}
$result = AdminModel::updateConfig($merged); $result = AdminModel::updateConfig($merged);
if (isset($result['error'])) { if (isset($result['error'])) {
http_response_code(500); http_response_code(500);

View File

@@ -70,7 +70,10 @@ class AuthController
if ($oidcAction === 'callback') { if ($oidcAction === 'callback') {
try { try {
$oidc->authenticate(); $oidc->authenticate();
$username = $oidc->requestUserInfo('preferred_username'); $username =
$oidc->requestUserInfo('preferred_username')
?: $oidc->requestUserInfo('email')
?: $oidc->requestUserInfo('sub');
// check if this user has a TOTP secret // check if this user has a TOTP secret
$totp_secret = null; $totp_secret = null;

View File

@@ -0,0 +1,383 @@
<?php
// src/controllers/OnlyOfficeController.php
declare(strict_types=1);
require_once PROJECT_ROOT . '/src/models/AdminModel.php';
require_once PROJECT_ROOT . '/src/lib/ACL.php';
class OnlyOfficeController
{
// What FileRise will route to ONLYOFFICE at all (edit *or* view)
private const OO_SUPPORTED_EXTS = [
'doc','docx','odt','rtf','txt',
'xls','xlsx','ods','csv',
'ppt','pptx','odp',
'pdf'
];
// Never editable via OO (well always set edit=false for these)
private const OO_NEVER_EDIT = ['pdf'];
// (Optional) More view-only types you can enable if you like
private const OO_VIEW_ONLY_EXTRAS = [
'djvu','xps','oxps','epub','fb2','pages','hwp','hwpx',
'vsdx','vsdm','vssx','vssm','vstx','vstm'
];
/** Resolve effective secret: constants override adminConfig */
private function effectiveSecret(): string
{
$cfg = AdminModel::getConfig();
$oo = is_array($cfg['onlyoffice'] ?? null) ? $cfg['onlyoffice'] : [];
if (defined('ONLYOFFICE_JWT_SECRET') && ONLYOFFICE_JWT_SECRET !== '') {
return (string)ONLYOFFICE_JWT_SECRET;
}
return (string)($oo['jwtSecret'] ?? '');
}
// --- lightweight logger ------------------------------------------------------
private const OO_LOG_PATH = '/var/www/users/onlyoffice-cb.debug';
private function ooDebug(): bool
{
// Enable verbose logging by either constant or env var
if (defined('ONLYOFFICE_DEBUG') && ONLYOFFICE_DEBUG) return true;
return getenv('ONLYOFFICE_DEBUG') === '1';
}
/**
* @param 'error'|'warn'|'info'|'debug' $level
*/
private function ooLog(string $level, string $msg): void
{
$level = strtolower($level);
$line = '[OO-CB][' . strtoupper($level) . '] ' . $msg;
// Only emit to Apache on errors (keeps logs clean)
if ($level === 'error') {
error_log($line);
}
// If debug mode is on, mirror all levels to a local file
if ($this->ooDebug()) {
@file_put_contents(self::OO_LOG_PATH, '[' . date('c') . '] ' . $line . "\n", FILE_APPEND);
}
}
/** Resolve effective docs origin (http/https root of OO Docs server) */
private function effectiveDocsOrigin(): string
{
$cfg = AdminModel::getConfig();
$oo = is_array($cfg['onlyoffice'] ?? null) ? $cfg['onlyoffice'] : [];
if (defined('ONLYOFFICE_DOCS_ORIGIN') && ONLYOFFICE_DOCS_ORIGIN !== '') {
return (string)ONLYOFFICE_DOCS_ORIGIN;
}
if (!empty($oo['docsOrigin'])) return (string)$oo['docsOrigin'];
$env = getenv('ONLYOFFICE_DOCS_ORIGIN');
return $env ? (string)$env : '';
}
/** Resolve effective enabled flag (constants override adminConfig) */
private function effectiveEnabled(): bool
{
$cfg = AdminModel::getConfig();
$oo = is_array($cfg['onlyoffice'] ?? null) ? $cfg['onlyoffice'] : [];
if (defined('ONLYOFFICE_ENABLED')) return (bool)ONLYOFFICE_ENABLED;
return !empty($oo['enabled']);
}
/** Optional explicit public origin; else infer from BASE_URL / request */
private function effectivePublicOrigin(): string
{
$cfg = AdminModel::getConfig();
$oo = is_array($cfg['onlyoffice'] ?? null) ? $cfg['onlyoffice'] : [];
if (defined('ONLYOFFICE_PUBLIC_ORIGIN') && ONLYOFFICE_PUBLIC_ORIGIN !== '') {
return (string)ONLYOFFICE_PUBLIC_ORIGIN;
}
if (!empty($oo['publicOrigin'])) return (string)$oo['publicOrigin'];
// Try BASE_URL if it isn't a placeholder
if (defined('BASE_URL') && strpos((string)BASE_URL, 'yourwebsite') === false) {
$u = parse_url((string)BASE_URL);
if (!empty($u['scheme']) && !empty($u['host'])) {
return $u['scheme'].'://'.$u['host'].(isset($u['port'])?':'.$u['port']:'');
}
}
// Fallback to request (proxy aware)
$proto = $_SERVER['HTTP_X_FORWARDED_PROTO']
?? ((!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ? 'https' : 'http');
$host = $_SERVER['HTTP_X_FORWARDED_HOST'] ?? ($_SERVER['HTTP_HOST'] ?? 'localhost');
return $proto.'://'.$host;
}
/** base64url encode/decode helpers */
private function b64uDec(string $s)
{
$s = strtr($s, '-_', '+/');
$pad = strlen($s) % 4;
if ($pad) $s .= str_repeat('=', 4 - $pad);
return base64_decode($s, true);
}
private function b64uEnc(string $s): string
{
return rtrim(strtr(base64_encode($s), '+/','-_'), '=');
}
/** GET /api/onlyoffice/status.php */
public function status(): void
{
header('Content-Type: application/json; charset=utf-8');
header('Cache-Control: no-store');
$enabled = $this->effectiveEnabled();
$docsOrig = $this->effectiveDocsOrigin();
$secret = $this->effectiveSecret();
// Must have docs origin and secret to actually function
$enabled = $enabled && ($docsOrig !== '') && ($secret !== '');
$exts = self::OO_SUPPORTED_EXTS;
// If you want the extras:
$exts = array_values(array_unique(array_merge($exts, self::OO_VIEW_ONLY_EXTRAS)));
echo json_encode(['enabled' => (bool)$enabled, 'exts' => $exts], JSON_UNESCAPED_SLASHES);
}
/** GET /api/onlyoffice/config.php?folder=...&file=... */
public function config(): void
{
header('Content-Type: application/json; charset=utf-8');
header('Cache-Control: no-store');
@session_start();
$user = $_SESSION['username'] ?? 'anonymous';
$perms = [];
$isAdmin = \ACL::isAdmin($perms);
// Effective toggles
$enabled = $this->effectiveEnabled();
$docsOrigin = rtrim($this->effectiveDocsOrigin(), '/');
$secret = $this->effectiveSecret();
if (!$enabled) { http_response_code(404); echo '{"error":"ONLYOFFICE disabled"}'; return; }
if ($secret === '') { http_response_code(500); echo '{"error":"ONLYOFFICE_JWT_SECRET not configured"}'; return; }
if ($docsOrigin === '') { http_response_code(500); echo '{"error":"ONLYOFFICE_DOCS_ORIGIN not configured"}'; return; }
if (!defined('UPLOAD_DIR')) { http_response_code(500); echo '{"error":"UPLOAD_DIR not defined"}'; return; }
// Inputs
$folder = \ACL::normalizeFolder((string)($_GET['folder'] ?? 'root'));
$file = basename((string)($_GET['file'] ?? ''));
if ($file === '') { http_response_code(400); echo '{"error":"Bad request"}'; return; }
// ACL
if (!\ACL::canRead($user, $perms, $folder)) { http_response_code(403); echo '{"error":"Forbidden"}'; return; }
$canEdit = \ACL::canEdit($user, $perms, $folder);
// Path
$base = rtrim(UPLOAD_DIR, "/\\") . DIRECTORY_SEPARATOR;
$rel = ($folder === 'root') ? '' : ($folder . '/');
$abs = realpath($base . $rel . $file);
if (!$abs || !is_file($abs)) { http_response_code(404); echo '{"error":"Not found"}'; return; }
if (strpos($abs, realpath($base)) !== 0) { http_response_code(400); echo '{"error":"Invalid path"}'; return; }
// Public origin
$publicOrigin = $this->effectivePublicOrigin();
// Signed download
$exp = time() + 10*60;
$data = json_encode(['f'=>$folder,'n'=>$file,'u'=>$user,'adm'=>$isAdmin,'exp'=>$exp], JSON_UNESCAPED_SLASHES);
$sig = hash_hmac('sha256', $data, $secret, true);
$tok = $this->b64uEnc($data) . '.' . $this->b64uEnc($sig);
$fileUrl = $publicOrigin . '/api/onlyoffice/signed-download.php?tok=' . rawurlencode($tok);
// Callback
$cbExp = time() + 10*60;
$cbSig = hash_hmac('sha256', $folder.'|'.$file.'|'.$cbExp, $secret);
$callbackUrl = $publicOrigin . '/api/onlyoffice/callback.php'
. '?folder=' . rawurlencode($folder)
. '&file=' . rawurlencode($file)
. '&exp=' . $cbExp
. '&sig=' . $cbSig;
// Doc type & key
$ext = strtolower(pathinfo($file, PATHINFO_EXTENSION) ?: 'docx');
$docType = in_array($ext, ['xls','xlsx','ods','csv'], true) ? 'cell'
: (in_array($ext, ['ppt','pptx','odp'], true) ? 'slide' : 'word');
$key = substr(sha1($abs . '|' . (string)filemtime($abs)), 0, 20);
$docsApiJs = $docsOrigin . '/web-apps/apps/api/documents/api.js';
$cfgOut = [
'document' => [
'fileType' => $ext,
'key' => $key,
'title' => $file,
'url' => $fileUrl,
'permissions' => [
'download' => true,
'print' => true,
'edit' => $canEdit && !in_array($ext, self::OO_NEVER_EDIT, true),
],
],
'documentType' => $docType,
'editorConfig' => [
'callbackUrl' => $callbackUrl,
'user' => ['id'=>$user, 'name'=>$user],
'lang' => 'en',
],
'type' => 'desktop',
];
// JWT sign cfg
$h = $this->b64uEnc(json_encode(['alg'=>'HS256','typ'=>'JWT']));
$p = $this->b64uEnc(json_encode($cfgOut, JSON_UNESCAPED_SLASHES));
$s = $this->b64uEnc(hash_hmac('sha256', "$h.$p", $secret, true));
$cfgOut['token'] = "$h.$p.$s";
$cfgOut['docs_api_js'] = $docsApiJs;
echo json_encode($cfgOut, JSON_UNESCAPED_SLASHES);
}
/** POST /api/onlyoffice/callback.php?folder=...&file=...&exp=...&sig=... */
public function callback(): void
{
header('Content-Type: application/json; charset=utf-8');
if (isset($_GET['ping'])) { echo '{"error":0}'; return; }
$secret = $this->effectiveSecret();
if ($secret === '') { http_response_code(500); $this->ooLog('error', 'missing secret'); echo '{"error":6}'; return; }
$folderRaw = (string)($_GET['folder'] ?? 'root');
$fileRaw = (string)($_GET['file'] ?? '');
$exp = (int)($_GET['exp'] ?? 0);
$sig = (string)($_GET['sig'] ?? '');
$calc = hash_hmac('sha256', "$folderRaw|$fileRaw|$exp", $secret);
// Debug-only preflight (no secrets; show short sigs)
if ($this->ooDebug()) {
$this->ooLog('debug', sprintf(
"PRE f='%s' n='%s' exp=%d sig[8]=%s calc[8]=%s",
$folderRaw, $fileRaw, $exp, substr($sig, 0, 8), substr($calc, 0, 8)
));
}
$folder = \ACL::normalizeFolder($folderRaw);
$file = basename($fileRaw);
if (!$exp || time() > $exp) { $this->ooLog('error', "expired exp for $folder/$file"); echo '{"error":6}'; return; }
if (!hash_equals($calc, $sig)) { $this->ooLog('error', "sig mismatch for $folder/$file"); echo '{"error":6}'; return; }
$raw = file_get_contents('php://input') ?: '';
if ($this->ooDebug()) {
$this->ooLog('debug', 'BODY len=' . strlen($raw));
}
$body = json_decode($raw, true) ?: [];
$status = (int)($body['status'] ?? 0);
$actor = (string)($body['actions'][0]['userid'] ?? '');
$actorIsAdmin = (defined('DEFAULT_ADMIN_USER') && $actor !== '' && strcasecmp($actor, (string)DEFAULT_ADMIN_USER) === 0)
|| (strcasecmp($actor, 'admin') === 0);
$perms = $actorIsAdmin ? ['admin'=>true] : [];
$base = rtrim(UPLOAD_DIR, "/\\") . DIRECTORY_SEPARATOR;
$rel = ($folder === 'root') ? '' : ($folder . '/');
$dir = realpath($base . $rel) ?: ($base . $rel);
if (strpos($dir, realpath($base)) !== 0) { $this->ooLog('error', 'path escape'); echo '{"error":6}'; return; }
// Save-on statuses: 2/6/7
if (in_array($status, [2,6,7], true)) {
if (!$actor || !\ACL::canEdit($actor, $perms, $folder)) {
$this->ooLog('error', "ACL deny edit: actor='$actor' folder='$folder'");
echo '{"error":6}'; return;
}
$saveUrl = (string)($body['url'] ?? '');
if ($saveUrl === '') { $this->ooLog('error', "no url for status=$status"); echo '{"error":6}'; return; }
// fetch saved file
$data = null; $curlErr=''; $httpCode=0;
if (function_exists('curl_init')) {
$ch = curl_init($saveUrl);
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_CONNECTTIMEOUT => 10,
CURLOPT_TIMEOUT => 45,
CURLOPT_HTTPHEADER => ['Accept: */*','User-Agent: FileRise-ONLYOFFICE-Callback'],
]);
$data = curl_exec($ch);
if ($data === false) $curlErr = curl_error($ch);
$httpCode = (int)curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($data === false || $httpCode >= 400) {
$this->ooLog('error', "curl get failed ($httpCode) url=$saveUrl err=" . ($curlErr ?: 'n/a'));
$data = null;
}
}
if ($data === null) {
$ctx = stream_context_create(['http'=>['method'=>'GET','timeout'=>45,'header'=>"Accept: */*\r\n"]]);
$data = @file_get_contents($saveUrl, false, $ctx);
if ($data === false) { $this->ooLog('error', "stream get failed url=$saveUrl"); echo '{"error":6}'; return; }
}
if (!is_dir($dir)) { @mkdir($dir, 0775, true); }
$dest = rtrim($dir, "/\\") . DIRECTORY_SEPARATOR . $file;
if (@file_put_contents($dest, $data) === false) { $this->ooLog('error', "write failed: $dest"); echo '{"error":6}'; return; }
@touch($dest);
// Success: debug only
if ($this->ooDebug()) {
$this->ooLog('debug', "saved OK by '$actor' → $dest (" . strlen($data) . " bytes, status=$status)");
}
echo '{"error":0}'; return;
}
// Non-saving statuses: debug only
if ($this->ooDebug()) {
$this->ooLog('debug', "status=$status ack for $folder/$file by '$actor'");
}
echo '{"error":0}';
}
/** GET /api/onlyoffice/signed-download.php?tok=... */
public function signedDownload(): void
{
header('X-Content-Type-Options: nosniff');
header('Cache-Control: no-store');
$secret = $this->effectiveSecret();
if ($secret === '') { http_response_code(403); return; }
$tok = $_GET['tok'] ?? '';
if (!$tok || strpos($tok, '.') === false) { http_response_code(400); return; }
[$b64data, $b64sig] = explode('.', $tok, 2);
$data = $this->b64uDec($b64data);
$sig = $this->b64uDec($b64sig);
if ($data === false || $sig === false) { http_response_code(400); return; }
$calc = hash_hmac('sha256', $data, $secret, true);
if (!hash_equals($calc, $sig)) { http_response_code(403); return; }
$payload = json_decode($data, true);
if (!$payload || !isset($payload['f'],$payload['n'],$payload['exp'])) { http_response_code(400); return; }
if (time() > (int)$payload['exp']) { http_response_code(403); return; }
$folder = trim(str_replace('\\','/',$payload['f']),"/ \t\r\n");
if ($folder === '' || $folder === 'root') $folder = 'root';
$file = basename((string)$payload['n']);
$base = rtrim(UPLOAD_DIR, "/\\") . DIRECTORY_SEPARATOR;
$rel = ($folder === 'root') ? '' : ($folder . '/');
$abs = realpath($base . $rel . $file);
if (!$abs || !is_file($abs)) { http_response_code(404); return; }
if (strpos($abs, realpath($base)) !== 0) { http_response_code(400); return; }
$mime = mime_content_type($abs) ?: 'application/octet-stream';
header('Content-Type: '.$mime);
header('Content-Length: '.filesize($abs));
header('Content-Disposition: inline; filename="' . rawurlencode($file) . '"');
readfile($abs);
}
}

View File

@@ -52,57 +52,69 @@ class UploadController {
} }
// ---- 3) Folder-level WRITE permission (ACL) ---- // ---- 3) Folder-level WRITE permission (ACL) ----
// Always require client to send the folder; fall back to GET if needed. // Always require client to send the folder; fall back to GET if needed.
$folderParam = isset($_POST['folder']) ? (string)$_POST['folder'] : (isset($_GET['folder']) ? (string)$_GET['folder'] : 'root'); $folderParam = isset($_POST['folder'])
$targetFolder = ACL::normalizeFolder($folderParam); ? (string)$_POST['folder']
: (isset($_GET['folder']) ? (string)$_GET['folder'] : 'root');
// Admins bypass folder canWrite checks
if (!$isAdmin && !ACL::canUpload($username, $userPerms, $targetFolder)) { // Decode %xx (e.g., "test%20folder") then normalize
http_response_code(403); $folderParam = rawurldecode($folderParam);
echo json_encode(['error' => 'Forbidden: no write access to folder "'.$targetFolder.'".']); $targetFolder = ACL::normalizeFolder($folderParam);
return;
} // Admins bypass folder canWrite checks
$username = (string)($_SESSION['username'] ?? '');
// ---- 4) Delegate to model (actual file/chunk processing) ---- $userPerms = loadUserPermissions($username) ?: [];
// (Optionally re-check in UploadModel before finalizing.) $isAdmin = ACL::isAdmin($userPerms);
$result = UploadModel::handleUpload($_POST, $_FILES);
if (!$isAdmin && !ACL::canUpload($username, $userPerms, $targetFolder)) {
// ---- 5) Response ---- http_response_code(403);
if (isset($result['error'])) { echo json_encode(['error' => 'Forbidden: no write access to folder "'.$targetFolder.'".']);
http_response_code(400); return;
echo json_encode($result);
return;
}
if (isset($result['status'])) {
// e.g., {"status":"chunk uploaded"}
echo json_encode($result);
return;
}
echo json_encode([
'success' => 'File uploaded successfully',
'newFilename' => $result['newFilename'] ?? null
]);
} }
// ---- 4) Delegate to model (force the sanitized folder) ----
$_POST['folder'] = $targetFolder; // in case model reads superglobal
$post = $_POST;
$post['folder'] = $targetFolder;
$result = UploadModel::handleUpload($post, $_FILES);
// ---- 5) Response (unchanged) ----
if (isset($result['error'])) {
http_response_code(400);
echo json_encode($result);
return;
}
if (isset($result['status'])) {
echo json_encode($result);
return;
}
echo json_encode([
'success' => 'File uploaded successfully',
'newFilename' => $result['newFilename'] ?? null
]);
}
public function removeChunks(): void { public function removeChunks(): void {
header('Content-Type: application/json'); header('Content-Type: application/json');
$receivedToken = isset($_POST['csrf_token']) ? trim($_POST['csrf_token']) : ''; $receivedToken = isset($_POST['csrf_token']) ? trim($_POST['csrf_token']) : '';
if ($receivedToken !== ($_SESSION['csrf_token'] ?? '')) { if ($receivedToken !== ($_SESSION['csrf_token'] ?? '')) {
http_response_code(403); http_response_code(403);
echo json_encode(['error' => 'Invalid CSRF token']); echo json_encode(['error' => 'Invalid CSRF token']);
return; return;
}
if (!isset($_POST['folder'])) {
http_response_code(400);
echo json_encode(['error' => 'No folder specified']);
return;
}
$folder = (string)$_POST['folder'];
$result = UploadModel::removeChunks($folder);
echo json_encode($result);
} }
if (!isset($_POST['folder'])) {
http_response_code(400);
echo json_encode(['error' => 'No folder specified']);
return;
}
$folderRaw = (string)$_POST['folder'];
$folder = ACL::normalizeFolder(rawurldecode($folderRaw));
echo json_encode(UploadModel::removeChunks($folder));
}
} }

View File

@@ -3,6 +3,7 @@
require_once __DIR__ . '/../../config/config.php'; require_once __DIR__ . '/../../config/config.php';
require_once PROJECT_ROOT . '/src/models/UserModel.php'; require_once PROJECT_ROOT . '/src/models/UserModel.php';
require_once PROJECT_ROOT . '/src/models/AdminModel.php';
/** /**
* UserController * UserController
@@ -665,4 +666,38 @@ class UserController
echo json_encode(['success' => true, 'url' => $url]); echo json_encode(['success' => true, 'url' => $url]);
exit; exit;
} }
public function siteConfig(): void
{
header('Content-Type: application/json');
$usersDir = rtrim(USERS_DIR, '/\\') . DIRECTORY_SEPARATOR;
$publicPath = $usersDir . 'siteConfig.json';
$adminEncPath = $usersDir . 'adminConfig.json';
$publicMtime = is_file($publicPath) ? (int)@filemtime($publicPath) : 0;
$adminMtime = is_file($adminEncPath) ? (int)@filemtime($adminEncPath) : 0;
// If public cache is present and fresh enough, serve it
if ($publicMtime > 0 && $publicMtime >= $adminMtime) {
$raw = @file_get_contents($publicPath);
$data = is_string($raw) ? json_decode($raw, true) : null;
if (is_array($data)) {
echo json_encode($data);
return;
}
}
// Otherwise regenerate from decrypted admin config
$cfg = AdminModel::getConfig();
if (isset($cfg['error'])) {
http_response_code(500);
echo json_encode(['error' => $cfg['error']]);
return;
}
$public = AdminModel::buildPublicSubset($cfg);
$w = AdminModel::writeSiteConfig($public); // best effort
echo json_encode($public);
}
} }

View File

@@ -62,6 +62,83 @@ class AdminModel
return (int)$val; return (int)$val;
} }
/** Allow only http(s) URLs; return '' for invalid input. */
private static function sanitizeHttpUrl($url): string
{
$url = trim((string)$url);
if ($url === '') return '';
$valid = filter_var($url, FILTER_VALIDATE_URL);
if (!$valid) return '';
$scheme = strtolower(parse_url($url, PHP_URL_SCHEME) ?: '');
return ($scheme === 'http' || $scheme === 'https') ? $url : '';
}
public static function buildPublicSubset(array $config): array
{
$public = [
'header_title' => $config['header_title'] ?? 'FileRise',
'loginOptions' => [
'disableFormLogin' => (bool)($config['loginOptions']['disableFormLogin'] ?? false),
'disableBasicAuth' => (bool)($config['loginOptions']['disableBasicAuth'] ?? false),
'disableOIDCLogin' => (bool)($config['loginOptions']['disableOIDCLogin'] ?? false),
],
'globalOtpauthUrl' => $config['globalOtpauthUrl'] ?? '',
'enableWebDAV' => (bool)($config['enableWebDAV'] ?? false),
'sharedMaxUploadSize' => (int)($config['sharedMaxUploadSize'] ?? 0),
'oidc' => [
'providerUrl' => (string)($config['oidc']['providerUrl'] ?? ''),
'redirectUri' => (string)($config['oidc']['redirectUri'] ?? ''),
],
];
// NEW: include ONLYOFFICE minimal public flag
$ooEnabled = null;
if (isset($config['onlyoffice']['enabled'])) {
$ooEnabled = (bool)$config['onlyoffice']['enabled'];
} elseif (defined('ONLYOFFICE_ENABLED')) {
$ooEnabled = (bool)ONLYOFFICE_ENABLED;
}
if ($ooEnabled !== null) {
$public['onlyoffice'] = ['enabled' => $ooEnabled];
}
$locked = defined('ONLYOFFICE_ENABLED') || defined('ONLYOFFICE_JWT_SECRET')
|| defined('ONLYOFFICE_DOCS_ORIGIN') || defined('ONLYOFFICE_PUBLIC_ORIGIN');
if ($locked) {
$ooEnabled = defined('ONLYOFFICE_ENABLED') ? (bool)ONLYOFFICE_ENABLED : false;
} else {
$ooEnabled = isset($config['onlyoffice']['enabled']) ? (bool)$config['onlyoffice']['enabled'] : false;
}
$public['onlyoffice'] = ['enabled' => $ooEnabled];
return $public;
}
/** Write USERS_DIR/siteConfig.json atomically (unencrypted). */
public static function writeSiteConfig(array $publicSubset): array
{
$dest = rtrim(USERS_DIR, '/\\') . DIRECTORY_SEPARATOR . 'siteConfig.json';
$tmp = $dest . '.tmp';
$json = json_encode($publicSubset, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
if ($json === false) {
return ["error" => "Failed to encode siteConfig.json"];
}
if (file_put_contents($tmp, $json, LOCK_EX) === false) {
return ["error" => "Failed to write temp siteConfig.json"];
}
if (!@rename($tmp, $dest)) {
@unlink($tmp);
return ["error" => "Failed to move siteConfig.json into place"];
}
@chmod($dest, 0664); // readable in bind mounts
return ["success" => true];
}
/** /**
* Updates the admin configuration file. * Updates the admin configuration file.
* *
@@ -128,6 +205,28 @@ class AdminModel
$configUpdate['loginOptions']['authHeaderName'] = trim($configUpdate['loginOptions']['authHeaderName']); $configUpdate['loginOptions']['authHeaderName'] = trim($configUpdate['loginOptions']['authHeaderName']);
} }
// ---- ONLYOFFICE (persist, sanitize; keep secret unless explicitly replaced) ----
if (isset($configUpdate['onlyoffice']) && is_array($configUpdate['onlyoffice'])) {
$oo = $configUpdate['onlyoffice'];
$norm = [
'enabled' => (bool)($oo['enabled'] ?? false),
'docsOrigin' => self::sanitizeHttpUrl($oo['docsOrigin'] ?? ''),
'publicOrigin' => self::sanitizeHttpUrl($oo['publicOrigin'] ?? ''),
];
// Only accept a new secret if provided (non-empty). We do NOT clear on empty.
if (array_key_exists('jwtSecret', $oo)) {
$js = trim((string)$oo['jwtSecret']);
if ($js !== '') {
if (strlen($js) > 1024) $js = substr($js, 0, 1024);
$norm['jwtSecret'] = $js; // will be encrypted with encryptData()
}
}
$configUpdate['onlyoffice'] = $norm;
}
// Convert configuration to JSON. // Convert configuration to JSON.
$plainTextConfig = json_encode($configUpdate, JSON_PRETTY_PRINT); $plainTextConfig = json_encode($configUpdate, JSON_PRETTY_PRINT);
if ($plainTextConfig === false) { if ($plainTextConfig === false) {
@@ -157,6 +256,14 @@ class AdminModel
// Best-effort normalize perms for host visibility (user rw, group rw) // Best-effort normalize perms for host visibility (user rw, group rw)
@chmod($configFile, 0664); @chmod($configFile, 0664);
$public = self::buildPublicSubset($configUpdate);
$w = self::writeSiteConfig($public);
// Dont fail the whole update if public cache write had a minor issue.
if (isset($w['error'])) {
// Log but keep success for admin write
error_log("AdminModel::writeSiteConfig warning: " . $w['error']);
}
return ["success" => "Configuration updated successfully."]; return ["success" => "Configuration updated successfully."];
} }
@@ -248,6 +355,19 @@ class AdminModel
$config['sharedMaxUploadSize'] = (int)min((int)$config['sharedMaxUploadSize'], $maxBytes); $config['sharedMaxUploadSize'] = (int)min((int)$config['sharedMaxUploadSize'], $maxBytes);
} }
// ---- Ensure ONLYOFFICE structure exists, sanitize values ----
if (!isset($config['onlyoffice']) || !is_array($config['onlyoffice'])) {
$config['onlyoffice'] = [
'enabled' => false,
'docsOrigin' => '',
'publicOrigin' => '',
];
} else {
$config['onlyoffice']['enabled'] = (bool)($config['onlyoffice']['enabled'] ?? false);
$config['onlyoffice']['docsOrigin'] = self::sanitizeHttpUrl($config['onlyoffice']['docsOrigin'] ?? '');
$config['onlyoffice']['publicOrigin'] = self::sanitizeHttpUrl($config['onlyoffice']['publicOrigin'] ?? '');
}
return $config; return $config;
} }
@@ -262,12 +382,17 @@ class AdminModel
], ],
'loginOptions' => [ 'loginOptions' => [
'disableFormLogin' => false, 'disableFormLogin' => false,
'disableBasicAuth' => false, 'disableBasicAuth' => true,
'disableOIDCLogin' => true 'disableOIDCLogin' => true
], ],
'globalOtpauthUrl' => "", 'globalOtpauthUrl' => "",
'enableWebDAV' => false, 'enableWebDAV' => false,
'sharedMaxUploadSize' => min(50 * 1024 * 1024, self::parseSize(TOTAL_UPLOAD_SIZE)) 'sharedMaxUploadSize' => min(50 * 1024 * 1024, self::parseSize(TOTAL_UPLOAD_SIZE)),
'onlyoffice' => [
'enabled' => false,
'docsOrigin' => '',
'publicOrigin' => '',
],
]; ];
} }
} }

View File

@@ -6,231 +6,206 @@ require_once PROJECT_ROOT . '/config/config.php';
class UploadModel { class UploadModel {
private static function sanitizeFolder(string $folder): string { private static function sanitizeFolder(string $folder): string {
$folder = trim($folder); // decode "%20", normalise slashes & trim via ACL helper
if ($folder === '' || strtolower($folder) === 'root') return ''; $f = ACL::normalizeFolder(rawurldecode($folder));
// no traversal
if (strpos($folder, '..') !== false) return ''; // model uses '' to represent root
// only safe chars + forward slashes if ($f === 'root') return '';
if (!preg_match('/^[A-Za-z0-9_\-\/]+$/', $folder)) return '';
// normalize: strip leading slashes // forbid dot segments / empty parts
return ltrim($folder, '/'); foreach (explode('/', $f) as $seg) {
if ($seg === '' || $seg === '.' || $seg === '..') {
return '';
} }
}
// allow spaces & unicode via your global regex
// (REGEX_FOLDER_NAME validates a path "seg(/seg)*")
if (!preg_match(REGEX_FOLDER_NAME, $f)) {
return '';
}
return $f; // safe, normalised, with spaces allowed
}
/**
* Handles file uploads supports both chunked uploads and full (non-chunked) uploads.
*
* @param array $post The $_POST array.
* @param array $files The $_FILES array.
* @return array Returns an associative array with "success" on success or "error" on failure.
*/
public static function handleUpload(array $post, array $files): array { public static function handleUpload(array $post, array $files): array {
// If this is a GET request for testing chunk existence. // --- GET resumable test (make folder handling consistent)
if ($_SERVER['REQUEST_METHOD'] === 'GET' && isset($post['resumableTest'])) { if ($_SERVER['REQUEST_METHOD'] === 'GET' && isset($post['resumableTest'])) {
$chunkNumber = intval($post['resumableChunkNumber']); $chunkNumber = (int)($post['resumableChunkNumber'] ?? 0);
$resumableIdentifier = $post['resumableIdentifier'] ?? ''; $resumableIdentifier = $post['resumableIdentifier'] ?? '';
$folder = isset($post['folder']) ? trim($post['folder']) : 'root'; $folderSan = self::sanitizeFolder((string)($post['folder'] ?? 'root'));
$baseUploadDir = UPLOAD_DIR; $baseUploadDir = UPLOAD_DIR;
if ($folder !== 'root') { if ($folderSan !== '') {
$baseUploadDir = rtrim(UPLOAD_DIR, '/\\') . DIRECTORY_SEPARATOR . $folder . DIRECTORY_SEPARATOR; $baseUploadDir = rtrim(UPLOAD_DIR, '/\\') . DIRECTORY_SEPARATOR
. str_replace('/', DIRECTORY_SEPARATOR, $folderSan) . DIRECTORY_SEPARATOR;
} }
$tempDir = $baseUploadDir . 'resumable_' . $resumableIdentifier . DIRECTORY_SEPARATOR;
$tempDir = $baseUploadDir . 'resumable_' . $resumableIdentifier . DIRECTORY_SEPARATOR;
$chunkFile = $tempDir . $chunkNumber; $chunkFile = $tempDir . $chunkNumber;
return ["status" => file_exists($chunkFile) ? "found" : "not found"]; return ["status" => file_exists($chunkFile) ? "found" : "not found"];
} }
// Handle chunked uploads. // --- CHUNKED ---
if (isset($post['resumableChunkNumber'])) { if (isset($post['resumableChunkNumber'])) {
$chunkNumber = intval($post['resumableChunkNumber']); $chunkNumber = (int)$post['resumableChunkNumber'];
$totalChunks = intval($post['resumableTotalChunks']); $totalChunks = (int)$post['resumableTotalChunks'];
$resumableIdentifier = $post['resumableIdentifier'] ?? ''; $resumableIdentifier = $post['resumableIdentifier'] ?? '';
$resumableFilename = urldecode(basename($post['resumableFilename'])); $resumableFilename = urldecode(basename($post['resumableFilename'] ?? ''));
// Validate file name.
if (!preg_match(REGEX_FILE_NAME, $resumableFilename)) { if (!preg_match(REGEX_FILE_NAME, $resumableFilename)) {
return ["error" => "Invalid file name: $resumableFilename"]; return ["error" => "Invalid file name: $resumableFilename"];
} }
$folderRaw = $post['folder'] ?? 'root';
$folderSan = self::sanitizeFolder((string)$folderRaw);
$folderSan = self::sanitizeFolder((string)($post['folder'] ?? 'root'));
if (empty($files['file']) || !isset($files['file']['name'])) { if (empty($files['file']) || !isset($files['file']['name'])) {
return ["error" => "No files received"]; return ["error" => "No files received"];
} }
$baseUploadDir = UPLOAD_DIR; $baseUploadDir = UPLOAD_DIR;
if ($folderSan !== '') { if ($folderSan !== '') {
$baseUploadDir = rtrim(UPLOAD_DIR, '/\\') . DIRECTORY_SEPARATOR $baseUploadDir = rtrim(UPLOAD_DIR, '/\\') . DIRECTORY_SEPARATOR
. str_replace('/', DIRECTORY_SEPARATOR, $folderSan) . DIRECTORY_SEPARATOR; . str_replace('/', DIRECTORY_SEPARATOR, $folderSan) . DIRECTORY_SEPARATOR;
} }
if (!is_dir($baseUploadDir) && !mkdir($baseUploadDir, 0775, true)) { if (!is_dir($baseUploadDir) && !mkdir($baseUploadDir, 0775, true)) {
return ["error" => "Failed to create upload directory"]; return ["error" => "Failed to create upload directory"];
} }
$tempDir = $baseUploadDir . 'resumable_' . $resumableIdentifier . DIRECTORY_SEPARATOR; $tempDir = $baseUploadDir . 'resumable_' . $resumableIdentifier . DIRECTORY_SEPARATOR;
if (!is_dir($tempDir) && !mkdir($tempDir, 0775, true)) { if (!is_dir($tempDir) && !mkdir($tempDir, 0775, true)) {
return ["error" => "Failed to create temporary chunk directory"]; return ["error" => "Failed to create temporary chunk directory"];
} }
$chunkErr = $files['file']['error'] ?? UPLOAD_ERR_NO_FILE; $chunkErr = $files['file']['error'] ?? UPLOAD_ERR_NO_FILE;
if ($chunkErr !== UPLOAD_ERR_OK) { if ($chunkErr !== UPLOAD_ERR_OK) {
return ["error" => "Upload error on chunk $chunkNumber"]; return ["error" => "Upload error on chunk $chunkNumber"];
} }
$chunkFile = $tempDir . $chunkNumber; $chunkFile = $tempDir . $chunkNumber;
$tmpName = $files['file']['tmp_name'] ?? null; $tmpName = $files['file']['tmp_name'] ?? null;
if (!$tmpName || !move_uploaded_file($tmpName, $chunkFile)) { if (!$tmpName || !move_uploaded_file($tmpName, $chunkFile)) {
return ["error" => "Failed to move uploaded chunk $chunkNumber"]; return ["error" => "Failed to move uploaded chunk $chunkNumber"];
} }
// Check if all chunks are present. // all chunks present?
$allChunksPresent = true;
for ($i = 1; $i <= $totalChunks; $i++) { for ($i = 1; $i <= $totalChunks; $i++) {
if (!file_exists($tempDir . $i)) { if (!file_exists($tempDir . $i)) {
$allChunksPresent = false; return ["status" => "chunk uploaded"];
break;
} }
} }
if (!$allChunksPresent) {
return ["status" => "chunk uploaded"]; // merge
}
// Merge chunks.
$targetPath = $baseUploadDir . $resumableFilename; $targetPath = $baseUploadDir . $resumableFilename;
if (!$out = fopen($targetPath, "wb")) { if (!$out = fopen($targetPath, "wb")) {
return ["error" => "Failed to open target file for writing"]; return ["error" => "Failed to open target file for writing"];
} }
for ($i = 1; $i <= $totalChunks; $i++) { for ($i = 1; $i <= $totalChunks; $i++) {
$chunkPath = $tempDir . $i; $chunkPath = $tempDir . $i;
if (!file_exists($chunkPath)) { if (!file_exists($chunkPath)) { fclose($out); return ["error" => "Chunk $i missing during merge"]; }
fclose($out); if (!$in = fopen($chunkPath, "rb")) { fclose($out); return ["error" => "Failed to open chunk $i"]; }
return ["error" => "Chunk $i missing during merge"]; while ($buff = fread($in, 4096)) { fwrite($out, $buff); }
}
if (!$in = fopen($chunkPath, "rb")) {
fclose($out);
return ["error" => "Failed to open chunk $i"];
}
while ($buff = fread($in, 4096)) {
fwrite($out, $buff);
}
fclose($in); fclose($in);
} }
fclose($out); fclose($out);
// Update metadata. // metadata
$metadataKey = ($folderSan === '') ? "root" : $folderSan; $metadataKey = ($folderSan === '') ? "root" : $folderSan;
$metadataFileName = str_replace(['/', '\\', ' '], '-', $metadataKey) . '_metadata.json'; $metadataFileName = str_replace(['/', '\\', ' '], '-', $metadataKey) . '_metadata.json';
$metadataFile = META_DIR . $metadataFileName; $metadataFile = META_DIR . $metadataFileName;
$uploadedDate = date(DATE_TIME_FORMAT); $uploadedDate = date(DATE_TIME_FORMAT);
$uploader = $_SESSION['username'] ?? "Unknown"; $uploader = $_SESSION['username'] ?? "Unknown";
$metadataCollection = file_exists($metadataFile) ? json_decode(file_get_contents($metadataFile), true) : []; $collection = file_exists($metadataFile) ? json_decode(file_get_contents($metadataFile), true) : [];
if (!is_array($metadataCollection)) { if (!is_array($collection)) $collection = [];
$metadataCollection = []; if (!isset($collection[$resumableFilename])) {
$collection[$resumableFilename] = ["uploaded" => $uploadedDate, "uploader" => $uploader];
file_put_contents($metadataFile, json_encode($collection, JSON_PRETTY_PRINT));
} }
if (!isset($metadataCollection[$resumableFilename])) {
$metadataCollection[$resumableFilename] = [ // cleanup temp
"uploaded" => $uploadedDate, self::rrmdir($tempDir);
"uploader" => $uploader
];
file_put_contents($metadataFile, json_encode($metadataCollection, JSON_PRETTY_PRINT));
}
// Cleanup temporary directory.
$rrmdir = function($dir) use (&$rrmdir) {
if (!is_dir($dir)) return;
$iterator = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($dir, FilesystemIterator::SKIP_DOTS),
RecursiveIteratorIterator::CHILD_FIRST
);
foreach ($iterator as $item) {
$item->isDir() ? rmdir($item->getRealPath()) : unlink($item->getRealPath());
}
rmdir($dir);
};
$rrmdir($tempDir);
return ["success" => "File uploaded successfully"]; return ["success" => "File uploaded successfully"];
} else {
// Handle full upload (non-chunked)
$folderRaw = $post['folder'] ?? 'root';
$folderSan = self::sanitizeFolder((string)$folderRaw);
}
$baseUploadDir = UPLOAD_DIR;
if ($folderSan !== '') {
$baseUploadDir = rtrim(UPLOAD_DIR, '/\\') . DIRECTORY_SEPARATOR
. str_replace('/', DIRECTORY_SEPARATOR, $folderSan) . DIRECTORY_SEPARATOR;
}
if (!is_dir($baseUploadDir) && !mkdir($baseUploadDir, 0775, true)) {
return ["error" => "Failed to create upload directory"];
}
$safeFileNamePattern = REGEX_FILE_NAME;
$metadataCollection = [];
$metadataChanged = [];
foreach ($files["file"]["name"] as $index => $fileName) {
// Basic PHP upload error check per file
if (($files['file']['error'][$index] ?? UPLOAD_ERR_OK) !== UPLOAD_ERR_OK) {
return ["error" => "Error uploading file"];
}
$safeFileName = trim(urldecode(basename($fileName)));
if (!preg_match($safeFileNamePattern, $safeFileName)) {
return ["error" => "Invalid file name: " . $fileName];
}
$relativePath = '';
if (isset($post['relativePath'])) {
$relativePath = is_array($post['relativePath']) ? $post['relativePath'][$index] ?? '' : $post['relativePath'];
}
$uploadDir = rtrim($baseUploadDir, '/\\') . DIRECTORY_SEPARATOR;
if (!empty($relativePath)) {
$subDir = dirname($relativePath);
if ($subDir !== '.' && $subDir !== '') {
// IMPORTANT: build the subfolder under the *current* base folder
$uploadDir = rtrim($baseUploadDir, '/\\') . DIRECTORY_SEPARATOR .
str_replace('/', DIRECTORY_SEPARATOR, $subDir) . DIRECTORY_SEPARATOR;
}
$safeFileName = basename($relativePath);
}
if (!is_dir($uploadDir) && !@mkdir($uploadDir, 0775, true)) {
return ["error" => "Failed to create subfolder: " . $uploadDir];
}
$targetPath = $uploadDir . $safeFileName;
if (move_uploaded_file($files["file"]["tmp_name"][$index], $targetPath)) {
$metadataKey = ($folderSan === '') ? "root" : $folderSan;
$metadataFileName = str_replace(['/', '\\', ' '], '-', $metadataKey) . '_metadata.json';
$metadataFile = META_DIR . $metadataFileName;
if (!isset($metadataCollection[$metadataKey])) {
$metadataCollection[$metadataKey] = file_exists($metadataFile) ? json_decode(file_get_contents($metadataFile), true) : [];
if (!is_array($metadataCollection[$metadataKey])) {
$metadataCollection[$metadataKey] = [];
}
$metadataChanged[$metadataKey] = false;
}
if (!isset($metadataCollection[$metadataKey][$safeFileName])) {
$uploadedDate = date(DATE_TIME_FORMAT);
$uploader = $_SESSION['username'] ?? "Unknown";
$metadataCollection[$metadataKey][$safeFileName] = [
"uploaded" => $uploadedDate,
"uploader" => $uploader
];
$metadataChanged[$metadataKey] = true;
}
} else {
return ["error" => "Error uploading file"];
}
}
foreach ($metadataCollection as $folderKey => $data) {
if ($metadataChanged[$folderKey]) {
$metadataFileName = str_replace(['/', '\\', ' '], '-', $folderKey) . '_metadata.json';
$metadataFile = META_DIR . $metadataFileName;
file_put_contents($metadataFile, json_encode($data, JSON_PRETTY_PRINT));
}
}
return ["success" => "Files uploaded successfully"];
} }
// --- NON-CHUNKED ---
$folderSan = self::sanitizeFolder((string)($post['folder'] ?? 'root'));
$baseUploadDir = UPLOAD_DIR;
if ($folderSan !== '') {
$baseUploadDir = rtrim(UPLOAD_DIR, '/\\') . DIRECTORY_SEPARATOR
. str_replace('/', DIRECTORY_SEPARATOR, $folderSan) . DIRECTORY_SEPARATOR;
}
if (!is_dir($baseUploadDir) && !mkdir($baseUploadDir, 0775, true)) {
return ["error" => "Failed to create upload directory"];
}
$safeFileNamePattern = REGEX_FILE_NAME;
$metadataCollection = [];
$metadataChanged = [];
foreach ($files["file"]["name"] as $index => $fileName) {
if (($files['file']['error'][$index] ?? UPLOAD_ERR_OK) !== UPLOAD_ERR_OK) {
return ["error" => "Error uploading file"];
}
$safeFileName = trim(urldecode(basename($fileName)));
if (!preg_match($safeFileNamePattern, $safeFileName)) {
return ["error" => "Invalid file name: " . $fileName];
}
$relativePath = '';
if (isset($post['relativePath'])) {
$relativePath = is_array($post['relativePath']) ? ($post['relativePath'][$index] ?? '') : $post['relativePath'];
}
$uploadDir = rtrim($baseUploadDir, '/\\') . DIRECTORY_SEPARATOR;
if (!empty($relativePath)) {
$subDir = dirname($relativePath);
if ($subDir !== '.' && $subDir !== '') {
$uploadDir = rtrim($baseUploadDir, '/\\') . DIRECTORY_SEPARATOR
. str_replace('/', DIRECTORY_SEPARATOR, $subDir) . DIRECTORY_SEPARATOR;
}
$safeFileName = basename($relativePath);
}
if (!is_dir($uploadDir) && !@mkdir($uploadDir, 0775, true)) {
return ["error" => "Failed to create subfolder: " . $uploadDir];
}
$targetPath = $uploadDir . $safeFileName;
if (!move_uploaded_file($files["file"]["tmp_name"][$index], $targetPath)) {
return ["error" => "Error uploading file"];
}
$metadataKey = ($folderSan === '') ? "root" : $folderSan;
$metadataFileName = str_replace(['/', '\\', ' '], '-', $metadataKey) . '_metadata.json';
$metadataFile = META_DIR . $metadataFileName;
if (!isset($metadataCollection[$metadataKey])) {
$metadataCollection[$metadataKey] = file_exists($metadataFile) ? json_decode(file_get_contents($metadataFile), true) : [];
if (!is_array($metadataCollection[$metadataKey])) $metadataCollection[$metadataKey] = [];
$metadataChanged[$metadataKey] = false;
}
if (!isset($metadataCollection[$metadataKey][$safeFileName])) {
$uploadedDate = date(DATE_TIME_FORMAT);
$uploader = $_SESSION['username'] ?? "Unknown";
$metadataCollection[$metadataKey][$safeFileName] = ["uploaded" => $uploadedDate, "uploader" => $uploader];
$metadataChanged[$metadataKey] = true;
}
}
foreach ($metadataCollection as $folderKey => $data) {
if (!empty($metadataChanged[$folderKey])) {
$metadataFileName = str_replace(['/', '\\', ' '], '-', $folderKey) . '_metadata.json';
$metadataFile = META_DIR . $metadataFileName;
file_put_contents($metadataFile, json_encode($data, JSON_PRETTY_PRINT));
}
}
return ["success" => "Files uploaded successfully"];
}
/** /**