Phase 5: secure credentials, first-login setup, user rename, admin settings

Security:
- PBKDF2-HMAC-SHA256 password hashing (260k iterations, random salt per password)
- Legacy MICRONAS_PASS plaintext still works for existing installs
- MICRONAS_PASS_HASH replaces plaintext in env file after first setup/change
- Timing-safe comparison via hmac.compare_digest

First-login setup:
- /setup route: shown when no credentials configured (fresh install)
- Replaces editing /etc/micronas.env manually
- setup.html dark-themed form matching login.html

Admin credential change:
- POST /api/admin/credentials (requires current password to confirm)
- Settings button in topbar opens modal for username + password change
- Session cleared after change → redirected to login

User management:
- PATCH /api/users/<name>: rename Linux user (usermod -l)
  SMB + WebDAV entries removed, password reset required after rename
- Rename button in users table, modal with yellow warning

WebDAV:
- Options Indexes: directories now browsable in a regular web browser

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
marcandClaude Sonnet 4.6 committed 2026-06-20 16:45:16 +02:00
1 parent 559954b222
commit a29862860d
4 files changed
+282 -16

No files matched your search

+60 -1
View File
@@ -67,11 +67,70 @@
</div>
</div>
<!-- Admin settings modal -->
<div class="modal fade" id="adminModal" tabindex="-1">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Admin Credentials</h5>
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal"></button>
</div>
<div class="modal-body">
<div class="mb-3">
<label class="form-label" style="color:var(--muted); font-size:.85rem">Current Password</label>
<input type="password" id="adminCurrentPw" class="form-control" placeholder="Required to confirm changes">
</div>
<hr style="border-color:var(--border)">
<div class="mb-3">
<label class="form-label" style="color:var(--muted); font-size:.85rem">New Username <span style="font-weight:400">(leave blank to keep current)</span></label>
<input type="text" id="adminNewUser" class="form-control" placeholder="admin">
</div>
<div class="mb-3">
<label class="form-label" style="color:var(--muted); font-size:.85rem">New Password <span style="font-weight:400">(leave blank to keep current)</span></label>
<input type="password" id="adminNewPw" class="form-control" placeholder="min 8 characters">
</div>
<div class="mb-1">
<label class="form-label" style="color:var(--muted); font-size:.85rem">Confirm New Password</label>
<input type="password" id="adminNewPwConfirm" class="form-control">
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button>
<button type="button" class="btn btn-primary" onclick="submitAdminSettings()">Save</button>
</div>
</div>
</div>
</div>
<!-- Rename user modal -->
<div class="modal fade" id="renameModal" tabindex="-1">
<div class="modal-dialog modal-sm">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Rename User</h5>
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal"></button>
</div>
<div class="modal-body">
<input type="hidden" id="renameOldName">
<label class="form-label" style="color:var(--muted); font-size:.85rem">New Username</label>
<input type="text" id="renameNewName" class="form-control mb-2">
<div class="small" style="color:var(--yellow)">SMB and WebDAV password must be reset after rename.</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary btn-sm" data-bs-dismiss="modal">Cancel</button>
<button type="button" class="btn btn-primary btn-sm" onclick="submitRename()">Rename</button>
</div>
</div>
</div>
</div>
<!-- Header -->
<div class="topbar d-flex justify-content-between align-items-center">
<span class="fw-semibold fs-5">MicroNAS</span>
<div class="d-flex align-items-center gap-3">
<span id="lastRefresh" class="small" style="color:var(--muted)"></span>
<button type="button" class="btn btn-sm" style="border:1px solid var(--border); color:var(--muted)"
onclick="openAdminSettings()">&#9881; Settings</button>
<a href="/logout" class="btn btn-sm" style="border:1px solid var(--border); color:var(--muted)">Sign out</a>
</div>
</div>
@@ -261,7 +320,7 @@
<div class="fw-semibold mb-2">Users</div>
<div class="table-responsive mb-5">
<table class="table table-striped mb-0">
<thead><tr><th>Username</th><th>UID</th><th>SMB Account</th><th>Actions</th></tr></thead>
<thead><tr><th>Username</th><th>UID</th><th>SMB</th><th>Actions</th></tr></thead>
<tbody id="usersTableBody">
<tr><td colspan="4" style="color:var(--muted)">Loading…</td></tr>
</tbody>