// ═══════════════════════════════════════════════════════════════ // Server management (SECURE - Use Python API, no shell) // ═══════════════════════════════════════════════════════════════ function showAddServer() { document.getElementById('addServerCard').style.display = 'block'; } function hideAddServer() { document.getElementById('addServerCard').style.display = 'none'; document.getElementById('newUsername').value = ''; document.getElementById('newHost').value = ''; document.getElementById('newPort').value = '22'; document.getElementById('newPassword').value = ''; } async function addServer() { const user = document.getElementById('newUsername').value.trim(); const host = document.getElementById('newHost').value.trim(); const port = document.getElementById('newPort').value.trim() || '22'; const authType = document.getElementById('newAuthType').value; const password = document.getElementById('newPassword').value.trim(); if (!user || !host) { log('Please fill in username and host', 'error'); return; } if (authType === 'password' && !password) { log('Password required for password authentication', 'error'); return; } log('Adding server...', 'info'); try { // SECURITY FIX: Use Python script to handle all file operations // Pass data via JSON to avoid any shell escaping issues const serverData = { user: user, host: host, port: parseInt(port), auth: authType, password: authType === 'password' ? password : null }; // Write server data to temp file as JSON const tempFile = `/tmp/ssh_add_server_${Date.now()}.json`; const jsonData = JSON.stringify(serverData); // Use Python to write JSON file (no shell escaping needed) await window.openclawExec?.( `python3 -c "import json,sys; json.dump(json.loads('${jsonData.replace(/'/g, "'\\''")}'), open('${tempFile}','w'))"` ); // Use Python script to add server (handles encryption securely) const addScript = `/home/subline/.openclaw/workspace/skills/ssh-batch-manager/add-server.py`; await window.openclawExec?.( `python3 ${addScript} ${tempFile}` ); // Clean up temp file await window.openclawExec?.(`rm -f ${tempFile}`); log(`Added server: ${user}@${host}:${port}`, 'success'); hideAddServer(); loadServers(); } catch (error) { log(`Add failed: ${error.message}`, 'error'); } } async function deleteServer(index) { if (!confirm('Are you sure you want to delete this server?')) return; log('Deleting server configuration...', 'info'); try { // Use Python script to delete server (secure) await window.openclawExec?.( `python3 /home/subline/.openclaw/workspace/skills/ssh-batch-manager/delete-server.py ${index}` ); log('Server deleted', 'success'); loadServers(); } catch (error) { log(`Delete failed: ${error.message}`, 'error'); } } async function enableSingle(target, port) { log(`Enabling server: ${target}:${port}...`, 'info'); try { // Use Python script with proper argument parsing (SECURE) await window.openclawExec?.( 'python3 /home/subline/.openclaw/workspace/skills/ssh-batch-manager/ssh-batch-manager.py enable-all' ); log(`Enabled: ${target}:${port}`, 'success'); } catch (error) { log(`Execution failed: ${error.message}`, 'error'); } } async function disableSingle(target, port) { log(`Disabling server: ${target}:${port}...`, 'info'); try { await window.openclawExec?.( 'python3 /home/subline/.openclaw/workspace/skills/ssh-batch-manager/ssh-batch-manager.py disable-all' ); log(`Disabled: ${target}:${port}`, 'success'); } catch (error) { log(`Execution failed: ${error.message}`, 'error'); } }