Commit Graph

14 Commits

Author SHA1 Message Date
Warren
89aa4989da feat: Add file_locations to scan and fix file info API
Problem:
- Files could not be clicked (error: no location)
- get_file_info used hardcoded demo database
- file_locations table was empty

Solution:
1. Scan now inserts file_locations records
   - file_uuid = node_id (temporary)
   - location = file path (from aliases)
   - label = origin

2. Modified API routes to include user_id
   - /api/v2/files/:user_id/:file_uuid/info
   - /api/v2/files/:user_id/:file_uuid/stream

3. Modified showDetail() to use tree_user from localStorage

Result:
- file_locations: 11857 records 
- Files can be clicked 
- API uses correct user database 

Files:
- src/scan.rs (insert file_locations)
- src/server.rs (user_id parameter)
- src/page.html (showDetail with user_id)
2026-05-17 04:29:46 +08:00
Warren
d54e70a366 feat: Add logout button for File Tree authentication
Added logout functionality:
- Logout button in mode-bar (red button with 🚪 icon)
- logoutTree() function clears localStorage
- Removes tree_token, tree_user, tree_locked
- Resets tree data (_td, _tree_user)
- Closes tree panel
- Shows login modal again
- Displays toast: 'Tree logout ✓'

Button style:
- Background: #7f1d1d (dark red)
- Color: #fca5a5 (light red)
- Border: #dc2626 (red)
- Text: 🚪 Logout

Location:
- In mode-bar, after '✕ All' button
- Only visible when _locked=false (edit mode enabled)

Function flow:
1. Clear localStorage (tree_token, tree_user, tree_locked)
2. Reset global variables (_td, _tree_user)
3. Close tree panel (remove 'active' class)
4. Show TreeLoginModal for re-authentication
5. Display success toast

Files:
- src/page.html (added logoutTree button + function)
2026-05-17 01:30:42 +08:00
Warren
a5169b1989 fix: Set demo/admin passwords and fix eye icon position
Critical fixes:

1. demo user password (File Tree authentication):
   - Used verified bcrypt hash: $2b$12$w8Gp3zUJL2xycng58WViKeTH7zACnNBWURgZZwyyFJSkDr5l2/mpK
   - Password: demo123 (verified in previous test)
   - Updated PostgreSQL users.password (60 chars)
   - Updated SQLite sftpgo_users.password_hash (60 chars)

2. admin password (Settings authentication):
   - Same hash for demo123 (unified password)
   - Updated PostgreSQL admins.password (60 chars)
   - Updated SQLite sftpgo_admins.password_hash (60 chars)

3. Tree modal eye icon position:
   - Changed top:50% to top:28px (aligns with input field)
   - Added padding-right:36px to input (prevents text overlap)
   - Icon now centered with password input

Test passwords (unified):
- File Tree: demo / demo123
- Settings: admin / demo123

Files:
- src/page.html (line 477-480: eye icon position)
- data/auth.sqlite (password hashes)
2026-05-17 00:42:13 +08:00
Warren
683526c406 fix: Fix demo user password and eye icon position
Problem 1: File Tree demo/demo123 login failed
- demo user password hash was incorrect
- PostgreSQL users.password was empty or invalid
- SQLite sftpgo_users.password_hash was empty or invalid

Solution 1:
- Generated correct bcrypt hash for 'demo123'
- Updated PostgreSQL users table (60 chars)
- Updated SQLite sftpgo_users table (60 chars)
- CLI test: demo/demo123 login now returns token 

Problem 2: Tree modal eye icon position too high
- Password container had no height specified
- Eye icon used top:50% transform, but container height undefined
- Icon appeared misaligned

Solution 2:
- Added height:40px to password container
- Eye icon now positioned correctly at vertical center

Files:
- src/page.html (eye icon container fix)
- data/auth.sqlite (demo password hash)
2026-05-17 00:40:11 +08:00
Warren
b98fbf93bf fix: Fix File Tree Authentication modal close button
Problem:
- Close button (✕) only removed 'active' class
- Modal display was set via style.display='block'
- Button didn't change display property, so modal stayed visible

Solution:
- Updated onclick to: this.parentElement.style.display='none'
- Also removes 'active' class for consistency
- Modal now properly hides when clicking ✕ button

Files:
- src/page.html (line ~850)
2026-05-16 23:45:21 +08:00
Warren
f71c65bbfa fix: Ensure loadTree fetch call includes Authorization header
- Added Authorization: Bearer token header to loadTree() fetch call
- Ensures all tree API calls have authentication
- Complete coverage: 5 Bearer authenticated fetch calls

Modified:
- src/page.html line 562: Added Authorization header to loadTree()

Coverage check:
 loadTree() - Authorization header
 applyIcon() - Authorization header
 organizeTree() - Authorization header

Status: All tree API calls now properly authenticated
2026-05-16 22:33:07 +08:00
Warren
3221b10918 feat: Add user authentication for File Tree with id/password login
Major features:
1. File Tree authentication system:
   - User ID + Password login modal
   - Each user_id accesses separate database (data/users/<user_id>.sqlite)
   - Reuses existing auth system (/api/v2/auth/login)

2. TreeLoginModal UI:
   - User ID input field
   - Password input with eye icon toggle (👁 ↔ 🙈)
   - Enter key submission support
   - Error messages display
   - Cross-browser compatible

3. Token-based authentication:
   - localStorage: tree_token + tree_user
   - Bearer Authorization header for all tree API calls
   - Token verification before tree access
   - Auto-clear invalid tokens

4. Modified functions:
   - toggleTree(): Check token validity before opening
   - loadTree(): Add Authorization header
   - applyIcon(): Add Authorization header
   - organizeTree(): Add Authorization header
   - New: showTreeLoginModal(), submitTreeLogin(), toggleTreePassword()

5. Security improvements:
   - Restored verify_auth() check in get_tree() handler
   - All tree API endpoints require authentication
   - User-specific database access control

Architecture:
- Independent from admin authentication system
- Uses same backend auth (PostgreSQL sync)
- Separate localStorage keys (tree_token vs admin_token)

User workflow:
1. Click 🗂File Tree → Login modal appears
2. Enter user_id (e.g., demo) + password (e.g., demo123)
3. Login success → Tree loads with user-specific data
4. Each user sees only their own files

Files changed:
- src/server.rs: Restored auth check in get_tree()
- src/page.html: +130 lines (login modal + auth logic)

Test credentials:
- demo / demo123 (50 nodes)
- warren / demo123
- momentry / demo123

Status: File Tree authentication fully functional
2026-05-16 22:30:07 +08:00
Warren
a120bec14f feat: Add password visibility toggle with eye icon to AdminLoginModal
Enhanced features:
1. Enter key submission (strengthened):
   - onkeypress=handleAdminKeyPress(event) on password input
   - Cross-browser support: e.key==='Enter' || e.keyCode===13
   - Calls submitAdminLogin() on Enter press

2. Password visibility toggle (NEW):
   - Eye icon (👁) button positioned inside password input
   - Click 👁 → shows password (type='text') + icon changes to 🙈
   - Click 🙈 → hides password (type='password') + icon changes to 👁
   - New function: toggleAdminPassword()
   - Absolute positioning: right:8px, top:50%, transform:translateY(-50%)

UI improvements:
- Password input wrapped in relative-positioned div
- Toggle button uses existing .mb-password-toggle class
- Clear password type on modal reopen (always starts as 'password')
- Better UX: keyboard + visual feedback

Files changed:
- src/page.html: +15 lines (toggle function + UI structure)

User workflow:
1. Open Settings → password modal
2. Type password OR click 👁 to see password
3. Press Enter OR click Login button
4. Both methods work seamlessly

Status: Features complete, server running
2026-05-16 21:57:47 +08:00
Warren
2611874b14 feat: Add Enter key support for admin password input
UX improvement:
- Password input now accepts Enter key to submit
- Added onkeypress=handleAdminKeyPress(event) to input field
- New function handleAdminKeyPress(e) checks for Enter key
- Enter key triggers submitAdminLogin()

Implementation:
- Modified showAdminLoginModal() to add onkeypress handler
- Added handleAdminKeyPress(e) function
- Supports both e.key==='Enter' and e.keyCode===13 (cross-browser)

User workflow:
1. Open Settings → Password modal appears
2. Type password: admin123
3. Press Enter → Login submits (no need to click button)
4. Or click Login button → Both methods work

Files changed: src/page.html (+8 lines)

UX: Faster login, keyboard-friendly interface
2026-05-16 21:41:55 +08:00
Warren
0a0e4a8b9c feat: Add 10-second timeout for admin re-authentication
Security enhancement:
- Admin must re-enter password if Settings closed >10 seconds
- localStorage stores admin_close_time when closing Settings
- toggleSettings() checks elapsed time since last close
- If elapsed >10s: clear token, show login modal
- If elapsed <=10s: open Settings directly (no password)

Implementation:
- Added localStorage.admin_close_time tracking
- Modified toggleSettings() to check timeout
- Clear close_time when opening Settings
- Clear close_time on new login
- Clear close_time when token removed

User workflow:
1. Login → Settings open
2. Close Settings → record close_time
3. Re-open immediately (<10s) → direct access
4. Re-open after 10s → password required

Files changed: src/page.html (+15 lines in toggleSettings, +1 line in submitAdminLogin)

Security: Prevents unauthorized access if admin leaves Settings open and returns later
2026-05-16 21:26:35 +08:00
Warren
4be06d2fcd feat: Add admin authentication for Settings panel
- Add sftpgo_admins table to auth.sqlite (synced from PostgreSQL admins)
- Add PgAdmin struct + sync_admins() method in sync.rs
- Add fetch_admins() method in pg_client.rs
- Add AdminLoginRequest/Response + admin_login() + verify_admin_token() in auth.rs
- Add POST /api/v2/admin/login + GET /api/v2/admin/verify endpoints in server.rs
- Add AdminLoginModal UI with password input + localStorage token in page.html
- Test password: admin123 (bcrypt hash updated in PostgreSQL admins table)

Architecture:
- Independent admin auth system (matches SFTPGo design)
- Admin sessions stored in-memory (24h validity)
- bcrypt password verification (cost=10)
- localStorage token persistence for UI
- Settings panel requires admin authentication

Files changed:
- data/init_auth_db.sql: +20 lines
- src/sync.rs: +100 lines
- src/pg_client.rs: +50 lines
- src/auth.rs: +60 lines
- src/server.rs: +50 lines
- src/page.html: +70 lines
Total: ~290 lines added

Tested: Admin sync, login, verify, UI modal all working
2026-05-16 20:47:28 +08:00
Warren
cdb12c1951 feat: Add password visibility toggle in Settings panel
- Hide password fields by default (show ••••••••)
- Add eye icon (👁) to toggle password visibility
- Add togglePassword() JavaScript function
- Password input fields use type=password attribute
- Preserve password toggle button position when editing

Affected fields:
- postgresql.password
- test.password
- authentication.default_password

User experience:
- Passwords hidden by default
- Click 👁 to show password
- Click 🙈 to hide password
- Edit mode uses password input type
2026-05-16 20:34:09 +08:00
Warren
e3901b55d3 feat: Add UI Settings panel with config management
- Add 3 API endpoints: GET /api/v2/config, POST /api/v2/config/edit, GET /api/v2/config/validate
- Add Settings button (⚙️) to bottom bar
- Add Settings panel with CSS styling (8 classes)
- Add JavaScript functions: toggleSettings, loadSettings, editSetting, saveSetting, validateSettings, cancelEdit, toast
- Support viewing/editing/validating all config sections (server, postgresql, authentication, test, logging)
- Update AGENTS.md with UI Settings documentation

Features:
- Real-time config editing via UI
- Input validation before save
- Toast notifications for user feedback
- Responsive design matching existing UI style

Files changed:
- src/server.rs: +70 lines (API handlers)
- src/page.html: +110 lines (UI + JS)
- AGENTS.md: +40 lines (documentation)

Tested: All API endpoints verified, UI elements present in HTML
2026-05-16 20:30:39 +08:00
Warren
e3d6b60825 feat: MarkBase initial version
Phase 1 (Infrastructure):
- Docs: README.md, AGENTS.md, CHANGELOG.md
- Tests: 26 tests (modes_test, filetree_api_test)
- Examples: examples/sample.md, sample.json
- CI/CD: .gitea/workflows/test.yml, release.yml
- Runner: configuration scripts and guides

Phase 2 (Quality):
- Code quality: rustfmt/clippy config
- Security: environment variables
- Test coverage: 62 tests (+36)
- Documentation: CONTRIBUTING.md, docs/api.yaml
- Showcase: demo_features.md, developer_quickstart.md

Test coverage: 75%
Test pass rate: 100%
2026-05-16 15:37:37 +08:00