// ═══════════════════════════════════════════════════════════════ // Encryption Tools (SECURE - No shell injection) // ═══════════════════════════════════════════════════════════════ async function encryptPassword() { const password = document.getElementById('encryptInput').value.trim(); if (!password) { log('Please enter a password', 'warning'); return; } // SECURITY FIX: Use Python script with proper argument handling // Instead of: `python3 script.py encrypt "${password}"` (VULNERABLE) // We use a wrapper script that handles arguments safely try { // Create a temporary file with the password const tempFile = `/tmp/ssh_encrypt_${Date.now()}.txt`; await window.openclawExec?.(`echo '${password.replace(/'/g, "'\\''")}' > ${tempFile}`); await window.openclawExec?.(`chmod 600 ${tempFile}`); // Use Python script to read from file (safe) const response = await window.openclawExec?.( `python3 -c "import sys; from pathlib import Path; exec(open('/home/subline/.openclaw/workspace/skills/ssh-batch-manager/ssh-batch-manager.py').read().split('if __name__')[0]); print(encrypt_data(open('${tempFile}').read().strip(), load_key()))"` ); // Clean up temp file await window.openclawExec?.(`rm -f ${tempFile}`); const encryptedMatch = response?.match(/AES256:[A-Za-z0-9+/=]+/); if (encryptedMatch) { const resultDiv = document.getElementById('encryptResult'); resultDiv.style.display = 'block'; resultDiv.textContent = encryptedMatch[0]; log('Password encrypted successfully', 'success'); } else { log('Encryption failed', 'error'); } } catch (error) { log(`Encryption failed: ${error.message}`, 'error'); } } async function encryptConfig() { log('Encrypting configuration file...', 'info'); try { await window.openclawExec?.( 'python3 /home/subline/.openclaw/workspace/skills/ssh-batch-manager/ssh-batch-manager.py encrypt-file ~/.openclaw/credentials/ssh-batch.json' ); log('Configuration file encrypted', 'success'); } catch (error) { log(`Encryption failed: ${error.message}`, 'error'); } } // ═══════════════════════════════════════════════════════════════ // Initialize // ═══════════════════════════════════════════════════════════════ window.addEventListener('DOMContentLoaded', () => { log('SSH Batch Manager loaded', 'success'); loadServers(); });