Fix VNC authentication: Add password prompt modal

- Add Bootstrap modal for VNC password input
- Implement credentialsrequired event handler to show password prompt
- Handle password submission and resume authentication
- Allow Enter key to submit password
- Disconnect if user cancels without providing password
parent f1c0ee8d
......@@ -189,6 +189,30 @@
<a class="nav-link" href="/logout">Logout</a>
</div></div></nav>
<div id="notification-area" class="position-fixed top-0 end-0 p-3" style="z-index: 1050;"></div>
<!-- Password Prompt Modal -->
<div class="modal fade" id="passwordModal" tabindex="-1" aria-labelledby="passwordModalLabel" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="passwordModalLabel">VNC Authentication Required</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<p>Please enter the VNC password to connect:</p>
<div class="mb-3">
<label for="vncPassword" class="form-label">Password</label>
<input type="password" class="form-control" id="vncPassword" placeholder="Enter VNC password">
</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" id="submitPasswordBtn">Connect</button>
</div>
</div>
</div>
</div>
<div class="container mt-4">
<div class="row">
<div class="col-12">
......@@ -375,7 +399,40 @@ function connect() {
});
rfb.addEventListener('credentialsrequired', (e) => {
// For now, assume no credentials needed
console.log('VNC credentials required:', e.detail.types);
if (e.detail.types.includes('password')) {
// Show password modal
const passwordModal = new bootstrap.Modal(document.getElementById('passwordModal'));
passwordModal.show();
// Handle password submission
const submitPassword = () => {
const password = document.getElementById('vncPassword').value;
if (password) {
rfb.sendCredentials({ password: password });
passwordModal.hide();
document.getElementById('vncPassword').value = ''; // Clear password field
}
};
document.getElementById('submitPasswordBtn').onclick = submitPassword;
// Allow Enter key to submit
document.getElementById('vncPassword').onkeydown = (e) => {
if (e.key === 'Enter') {
submitPassword();
}
};
// Handle modal close without password
document.getElementById('passwordModal').addEventListener('hidden.bs.modal', () => {
if (!rfb._rfbCredentials.password) {
// If no password was provided, disconnect
showNotification('VNC connection cancelled - password required', 'warning');
disconnect();
}
});
}
});
rfb.addEventListener('securityfailure', (e) => {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment