Compare commits

...
1 Commits
3 changed files with 94 additions and 10 deletions

No files matched your search

+3 -1
View File
@@ -2146,7 +2146,9 @@ def register_api_routes(app, services, settings):
@app.route('/api/backup/schedule', methods=['GET'])
@auth_req
def api_backup_schedule_get():
return jsonify({'success': True, 'schedule': backup_svc.get_schedule()})
sched = backup_svc.get_schedule()
sched.pop('password', None) # never send password to client
return jsonify({'success': True, 'schedule': sched})
@app.route('/api/backup/schedule', methods=['POST'])
@auth_req
+7 -3
View File
@@ -12,7 +12,7 @@ import threading
import time
from datetime import datetime, timedelta
from cryptography.fernet import Fernet
from cryptography.fernet import Fernet, InvalidToken
from cryptography.hazmat.primitives import hashes
from cryptography.hazmat.primitives.kdf.pbkdf2 import PBKDF2HMAC
@@ -311,7 +311,9 @@ class BackupService:
cfg['schedule_times'] = data['schedule_times']
cfg['keep'] = int(data.get('keep', cfg['keep']))
if 'password' in data:
cfg['password'] = data['password']
if data['password']:
cfg['password'] = data['password']
# empty string = keep existing password (don't overwrite)
if cfg.get('mode') == 'schedule':
cfg['next_run'] = self._next_run_from_schedule(cfg)
else:
@@ -434,8 +436,10 @@ class BackupService:
'size': os.path.getsize(path),
'components': meta.get('components', []),
}
except InvalidToken:
return {'success': False, 'valid': False, 'error': 'Wrong password'}
except Exception as e:
return {'success': False, 'valid': False, 'error': str(e)}
return {'success': False, 'valid': False, 'error': f'Backup corrupted: {e}'}
# ── Restore Orchestration ─────────────────────────────────────────
+84 -6
View File
@@ -119,7 +119,7 @@
</div>
<div style="margin-bottom:8px;">
<label style="display:block;font-size:12px;color:var(--text-muted);margin-bottom:2px;">Encryption password (leave blank for no encryption)</label>
<input type="password" id="sched-password" placeholder="All scheduled backups use this password"
<input type="password" id="sched-password" placeholder="Leave blank to keep existing password"
style="width:100%;padding:6px 8px;background:var(--bg-input);border:1px solid var(--border);border-radius:4px;color:var(--text);font-size:13px;">
</div>
</div>
@@ -264,8 +264,51 @@
}
</style>
<!-- Create Backup Password Modal -->
<div id="create-pw-modal" class="modal-overlay" style="display:none;" onclick="if(event.target===this)closeModal('create-pw-modal')">
<div class="modal" style="max-width:400px;">
<div class="modal-header"><h3>Encrypt Backup (optional)</h3></div>
<div class="modal-body" style="padding:20px;">
<label style="display:block;margin-bottom:12px;font-size:13px;color:var(--text-light);">
Password
<input type="password" id="create-pw" placeholder="Leave blank for no encryption"
style="display:block;width:100%;margin-top:4px;padding:8px 10px;border:1px solid var(--border);border-radius:4px;font-size:14px;background:var(--card-bg);color:var(--text);">
</label>
<label style="display:block;font-size:13px;color:var(--text-light);">
Confirm password
<input type="password" id="create-pw-confirm" placeholder="Repeat password"
style="display:block;width:100%;margin-top:4px;padding:8px 10px;border:1px solid var(--border);border-radius:4px;font-size:14px;background:var(--card-bg);color:var(--text);">
</label>
<div id="create-pw-error" style="color:#c0392b;font-size:12px;margin-top:8px;display:none;"></div>
</div>
<div class="modal-actions" style="padding:12px 16px;border-top:1px solid var(--border);">
<button onclick="closeModal('create-pw-modal')" class="btn-cancel">Cancel</button>
<button id="create-pw-confirm-btn" onclick="confirmCreateBackup()" class="btn-save" style="margin-left:8px;">Create Backup</button>
</div>
</div>
</div>
<!-- Verify Backup Password Modal -->
<div id="verify-pw-modal" class="modal-overlay" style="display:none;" onclick="if(event.target===this)closeModal('verify-pw-modal')">
<div class="modal" style="max-width:380px;">
<div class="modal-header"><h3>Verify Backup — <span id="verify-pw-label"></span></h3></div>
<div class="modal-body" style="padding:20px;">
<label style="display:block;font-size:13px;color:var(--text-light);">
Password
<input type="password" id="verify-pw" placeholder="Leave blank if not encrypted"
style="display:block;width:100%;margin-top:4px;padding:8px 10px;border:1px solid var(--border);border-radius:4px;font-size:14px;background:var(--card-bg);color:var(--text);">
</label>
</div>
<div class="modal-actions" style="padding:12px 16px;border-top:1px solid var(--border);">
<button onclick="closeModal('verify-pw-modal')" class="btn-cancel">Cancel</button>
<button id="verify-pw-confirm-btn" onclick="confirmVerifyBackup()" class="btn-save" style="margin-left:8px;">Verify</button>
</div>
</div>
</div>
<script>
let restorePollInterval = null;
let _pendingVerifyBackup = null;
function showStatus(msg, type) {
const el = document.getElementById('backup-status');
@@ -333,8 +376,32 @@ function populateRestoreSelect(backups) {
}
}
function openModal(id) {
document.getElementById(id).style.display = '';
}
function closeModal(id) {
document.getElementById(id).style.display = 'none';
}
async function createBackup() {
const pw = prompt('Optional: Enter a password to encrypt this backup (leave blank for no encryption):', '');
document.getElementById('create-pw').value = '';
document.getElementById('create-pw-confirm').value = '';
document.getElementById('create-pw-error').style.display = 'none';
openModal('create-pw-modal');
document.getElementById('create-pw').focus();
}
async function confirmCreateBackup() {
const pw = document.getElementById('create-pw').value;
const confirm = document.getElementById('create-pw-confirm').value;
const errEl = document.getElementById('create-pw-error');
if (pw !== confirm) {
errEl.textContent = 'Passwords do not match.';
errEl.style.display = '';
return;
}
errEl.style.display = 'none';
closeModal('create-pw-modal');
const btn = document.getElementById('create-btn');
btn.disabled = true;
btn.textContent = 'Creating...';
@@ -360,7 +427,17 @@ async function createBackup() {
}
async function verifyBackup(name) {
const pw = prompt('Enter backup password (leave blank if not encrypted):', '');
_pendingVerifyBackup = name;
document.getElementById('verify-pw-label').textContent = name;
document.getElementById('verify-pw').value = '';
openModal('verify-pw-modal');
document.getElementById('verify-pw').focus();
}
async function confirmVerifyBackup() {
const name = _pendingVerifyBackup;
const pw = document.getElementById('verify-pw').value;
closeModal('verify-pw-modal');
showStatus('Verifying ' + name + '...', 'info');
try {
const r = await csrfFetch('/api/backup/verify', {
@@ -375,11 +452,12 @@ async function verifyBackup(name) {
showStatus(name + ' verified: ' + d.files + ' files, ' + bytesStr(d.size), 'success');
}
} else {
showStatus('Verification failed: ' + esc(d.error || 'Corrupt backup'), 'error');
showStatus('Verification failed: ' + esc(d.error || 'Unknown error'), 'error');
}
} catch (e) {
showStatus('Error: ' + esc(e.message), 'error');
}
_pendingVerifyBackup = null;
}
async function deleteBackup(name) {
@@ -469,7 +547,7 @@ async function loadSchedule() {
list.appendChild(div);
});
document.getElementById('sched-keep').value = s.keep;
document.getElementById('sched-password').value = s.password || '';
document.getElementById('sched-password').value = '';
const status = document.getElementById('schedule-status');
status.innerHTML = s.enabled
? '<span style="color:#27ae60;">&#9679; Active</span>'
@@ -648,7 +726,7 @@ async function startRestore() {
try {
const r = await csrfFetch('/api/backup/restore/start', {
method:'POST', headers:{'Content-Type':'application/json'},
body: JSON.stringify({name, vm_ip: vmIp, options})
body: JSON.stringify({name, options})
});
const d = await r.json();
if (!d.success) {