| h2 > | |
| <form id="adwareForm"> | |
| <label for="name">Name:</label> | |
| <input type="text" id="name" value="${nameValue}" required><br> | |
| <label for="description">Description:</label> | |
| <textarea id="description" required>${descriptionValue}</textarea><br> | |
| <label for="target_os">Target OS:</label> | |
| <input type="text" id="target_os" value="${targetOsValue}" required><br> | |
| <label for="persistence_method">Persistence Method:</label> | |
| <input type="text" id="persistence_method" value="${persistenceMethodValue}" required><br> | |
| <label for="payload_id">Payload:</label> | |
| <select id="payload_id" required> | |
| <option value="">Select Payload</option> | |
| </select><br> | |
| <label for="deployment_method_id">Deployment Method:</label> | |
| <select id="deployment_method_id" required> | |
| <option value="">Select Deployment Method</option> | |
| </select><br> | |
| <label for="config">Config (JSON):</label> | |
| <textarea id="config">${configValue}</textarea><br> | |
| <button type="submit">${submitText}</button> | |
| <button type="button" onclick="fetchAdware()">Cancel</button> | |
| </form> | |
| ${isEdit ? '' : '<button onclick="showAIAdwareForm()">Create with AI</button>'} | |
| `; | |
| }; | |
| appDiv.addEventListener('submit', async (event) => {event.preventDefault()}; | |
| if (event.target.id === 'adwareForm') { } | |
| const form = document.getElementById('adwareForm'); | |
| const formData = {name}: form.name.value, | |
| description: form.description.value, | |
| target_os: form.target_os.value, | |
| persistence_method: form.persistence_method.value, | |
| payload_id: parseInt(form.payload_id.value), | |
| deployment_method_id: parseInt(form.deployment_method_id.value), | |
| config: form.config.value ? JSON.parse(form.config.value) : | |
| }; | |
| try { } | |
| const url = currentAdwareId ? `/adware/${currentAdwareId}` : '/adware'; | |
| const method = currentAdwareId ? 'PUT' : 'POST'; | |
| const response = await fetch(url, {method}: method, | |
| headers: {'Content-Type'}: 'application/json' }, | |
| body: JSON.stringify(formData) | |
| }); | |
| if (!response.ok) { } | |
| throw new Error(`HTTP error! status: ${response.status}`); | |
| } | |
| alert(`Adware ${currentAdwareId ? 'updated' : 'created'} successfully!`); | |
| fetchAdware(); | |
| } catch (error) {showError(`Error ${currentAdwareId ? 'updating' : 'creating'} adware: ${error}`)}; | |
| } | |
| } | |
| if (event.target.id === 'aiAdwareForm') { } | |
| const form = document.getElementById('aiAdwareForm'); | |
| const formData = {goal}: form.ai_goal.value, | |
| constraints: form.ai_constraints.value ? JSON.parse(form.ai_constraints.value) : | |
| }; | |
| try { } | |
| const response = await fetch('/ai/generate', {method}: 'POST', | |
| headers: {'Content-Type'}: 'application/json' }, | |
| body: JSON.stringify(formData) | |
| }); | |
| if (!response.ok) { } | |
| throw new Error(`HTTP error! status: ${response.status}`); | |
| } | |
| const aiConfig = await response.json(); | |
| appDiv.innerHTML = getAdwareForm(aiConfig); | |
| fetchPayloadsAndDeploymentMethods(); | |
| } catch (error) {showError(`Error generating adware config with AI: ${error}`)}; | |
| } | |
| } | |
| if (event.target.id === 'payloadForm') { } | |
| const form = document.getElementById('payloadForm'); | |
| const formData = {name}: form.name.value, | |
| description: form.description.value, | |
| file_path: form.file_path.value | |
| }; | |
| try { } | |
| const url = currentPayloadId ? `/payloads/${currentPayloadId}` : '/payloads'; | |
| const method = currentPayloadId ? 'PUT' : 'POST'; | |
| const response = await fetch(url, {method}: method, | |
| headers: {'Content-Type'}: 'application/json' }, | |
| body: JSON.stringify(formData) | |
| }); | |
| if (!response.ok) { } | |
| throw new Error(`HTTP error! status: ${response.status}`); | |
| } | |
| alert(`Payload ${currentPayloadId ? 'updated' : 'created'} successfully!`); | |
| showPayloadManagement(); | |
| } catch (error) {showError(`Error ${currentPayloadId ? 'updating' : 'creating'} payload: ${error}`)}; | |
| } | |
| } | |
| if (event.target.id === 'deploymentMethodForm') { } | |
| const form = document.getElementById('deploymentMethodForm'); | |
| const formData = {name}: form.name.value, | |
| description: form.description.value, | |
| config_schema: form.config_schema.value ? JSON.parse(form.config_schema.value) : | |
| }; | |
| try { } | |
| const url = currentDeploymentMethodId ? `/deployment_methods/${currentDeploymentMethodId}` : '/deployment_methods'; | |
| const method = currentDeploymentMethodId ? 'PUT' : 'POST'; | |
| const response = await fetch(url, {method}: method, | |
| headers: {'Content-Type'}: 'application/json' }, | |
| body: JSON.stringify(formData) | |
| }); | |
| if (!response.ok) { } | |
| throw new Error(`HTTP error! status: ${response.status}`); | |
| } | |
| alert(`Deployment method ${currentDeploymentMethodId ? 'updated' : 'created'} successfully!`); | |
| showDeploymentMethodManagement(); | |
| } catch (error) {showError(`Error ${currentDeploymentMethodId ? 'updating' : 'creating'} deployment method: ${error}`)}; | |
| } | |
| } | |
| }); | |
| window.showAIAdwareForm = () => {appDiv.innerHTML = getAIAdwareForm()}; | |
| }; | |
| const getAIAdwareForm = () => { } | |
| return ` | |
| <h2>Create Adware with AI</h2> | |
| <form id="aiAdwareForm"> | |
| <label for="ai_goal">Goal:</label> | |
| <input type="text" id="ai_goal" required><br> | |
| <label for="ai_constraints">Constraints (JSON):</label> | |
| <textarea id="ai_constraints"></textarea><br> | |
| <button type="submit">Generate Adware Config</button> | |
| <button type="button" onclick="showCreateAdwareForm()">Cancel</button> | |
| </form> | |
| `; | |
| }; | |
| // --- Payload Management --- | |
| window.showPayloadManagement = async () => {currentPayloadId = null}; | |
| showLoading('Fetching payloads...'); | |
| try { } | |
| const response = await fetch('/payloads'); | |
| if (!response.ok) { } | |
| throw new Error(`HTTP error! status: ${response.status}`); | |
| } | |
| const data = await response.json(); | |
| displayPayloads(data); | |
| } catch (error) {showError(`Error fetching payloads: ${error}`)}; | |
| } | |
| }; | |
| const displayPayloads = (payloadList) => {let} html = '<h2>Payload Management</h2>'; | |
| if (payloadList.length === 0) {html += '<p>No payloads found.</p>'}; | |
| } else {html += '<table><thead><tr><th>Name</th><th>Description</th><th>Actions</th></tr></thead><tbody>'}; | |
| payloadList.forEach(payload => {html += `<tr> | |
| <td>${payload.name}</td> | |
| <td>${payload.description}</td> | |
| <td> | |
| <button onclick="editPayload(${payload.id})">Edit</button> | |
| <button onclick="deletePayload(${payload.id})">Delete</button> | |
| </td> | |
| </tr>`}; | |
| }); | |
| html += '</tbody></table>'; | |
| } | |
| html += '<button onclick="showCreatePayloadForm()">Create New Payload</button>'; | |
| html += '<button onclick="fetchAdware()">Back to Adware</button>'; | |
| appDiv.innerHTML = html; | |
| }; | |
| window.showCreatePayloadForm = () => {currentPayloadId = null}; | |
| appDiv.innerHTML = getPayloadForm(); | |
| }; | |
| window.editPayload = async (payloadId) => {currentPayloadId = payloadId}; | |
| showLoading(`Fetching payload with ID ${payloadId} for edit...`); | |
| try { } | |
| const response = await fetch(`/payloads/${payloadId}`); | |
| if (!response.ok) { } | |
| throw new Error(`HTTP error! status: ${response.status}`); | |
| } | |
| const payload = await response.json(); | |
| appDiv.innerHTML = getPayloadForm(payload); | |
| } catch (error) {showError(`Error fetching payload for edit: ${error}`)}; | |
| } | |
| }; | |
| window.deletePayload = async (payloadId) => { } | |
| if (confirm(`Are you sure you want to delete payload with ID ${payloadId}?`)) {showLoading(`Deleting payload with ID ${payloadId}...`)}; | |
| try { } | |
| const response = await fetch(`/payloads/${payloadId}`, {method}: 'DELETE' }); | |
| if (!response.ok) { } | |
| throw new Error(`HTTP error! status: ${response.status}`); | |
| } | |
| alert(`Payload with ID ${payloadId} deleted successfully!`); | |
| showPayloadManagement(); | |
| } catch (error) {showError(`Error deleting payload: ${error}`)}; | |
| } | |
| } | |
| }; | |
| const getPayloadForm = (payload = null) => { } | |
| const isEdit = payload !== null; | |
| const title = isEdit ? 'Edit Payload' : 'Create New Payload'; | |
| const submitText = isEdit ? 'Update Payload' : 'Create Payload'; | |
| const nameValue = isEdit ? payload.name : ''; | |
| const descriptionValue = isEdit ? payload.description : ''; | |
| const filePathValue = isEdit ? payload.file_path : ''; | |
| return ` | |
| <h2>${title}</h2> | |
| <form id="payloadForm"> | |
| <label for="name">Name:</label> | |
| <input type="text" id="name" value="${nameValue}" required><br> | |
| <label for="descriptiondocument.addEventListener('DOMContentLoaded', () => { | |
| const appDiv = document.getElementById('app'); | |
| let currentAdwareId = null; | |
| let currentPayloadId = null; | |
| let currentDeploymentMethodId = null; | |
| // --- Helper Functions --- | |
| const showLoading = (message = 'Loading...') => { | |
| appDiv.innerHTML = `<p>${message}</p>`; | |
| }; | |
| const showError = (message) => { | |
| appDiv.innerHTML = `<p style=" color:red />;">Error: ${message}</p>`; | |
| }; | |
| // --- Adware Management --- | |
| const fetchAdware = async () => {showLoading('Fetching adware configurations...')}; | |
| try { } | |
| const response = await fetch('/adware'); | |
| if (!response.ok) { } | |
| throw new Error(`HTTP error! status: ${response.status}`); | |
| } | |
| const data = await response.json(); | |
| displayAdware(data); | |
| } catch (error) {showError(`Error fetching adware: ${error}`)}; | |
| } | |
| }; | |
| const displayAdware = (adwareList) => {let} html = '<h2>Adware Configurations</h2>'; | |
| if (adwareList.length === 0) {html += '<p>No adware configurations found.</p>'}; | |
| } else {html += '<table><thead><tr><th>Name</th><th>Description</th><th>Actions</th></tr></thead><tbody>'}; | |
| adwareList.forEach(adware => {html += `<tr> | |
| <td>${adware.name}</td> | |
| <td>${adware.description}</td> | |
| <td> | |
| <button onclick="deployAdware(${adware.id})">Deploy</button> | |
| <button onclick="editAdware(${adware.id})">Edit</button> | |
| <button onclick="deleteAdware(${adware.id})">Delete</button> | |
| </td> | |
| </tr>`}; | |
| }); | |
| html += '</tbody></table>'; | |
| } | |
| html += '<button onclick="showCreateAdwareForm()">Create New Adware</button>'; | |
| html += '<button onclick="showPayloadManagement()">Manage Payloads</button>'; | |
| html += '<button onclick="showDeploymentMethodManagement()">Manage Deployment Methods</button>'; | |
| appDiv.innerHTML = html; | |
| }; | |
| window.deployAdware = async (adwareId) => {showLoading(`Deploying adware with ID ${adwareId}...`)}; | |
| try { } | |
| const response = await fetch(`/adware/${adwareId}/deploy`, {method}: 'POST' }); | |
| if (!response.ok) { } | |
| throw new Error(`HTTP error! status: ${response.status}`); | |
| } | |
| alert(`Adware with ID ${adwareId} deployed successfully!`); | |
| fetchAdware(); | |
| } catch (error) {showError(`Error deploying adware: ${error}`)}; | |
| } | |
| }; | |
| window.showCreateAdwareForm = () => {currentAdwareId = null}; | |
| appDiv.innerHTML = getAdwareForm(); | |
| fetchPayloadsAndDeploymentMethods(); | |
| }; | |
| window.editAdware = async (adwareId) => {currentAdwareId = adwareId}; | |
| showLoading(`Fetching adware with ID ${adwareId} for edit...`); | |
| try { } | |
| const response = await fetch(`/adware/${adwareId}`); | |
| if (!response.ok) { } | |
| throw new Error(`HTTP error! status: ${response.status}`); | |
| } | |
| const adware = await response.json(); | |
| appDiv.innerHTML = getAdwareForm(adware); | |
| fetchPayloadsAndDeploymentMethods(); | |
| } catch (error) {showError(`Error fetching adware for edit: ${error}`)}; | |
| } | |
| }; | |
| window.deleteAdware = async (adwareId) => { } | |
| if (confirm(`Are you sure you want to delete adware with ID ${adwareId}?`)) {showLoading(`Deleting adware with ID ${adwareId}...`)}; | |
| try { } | |
| const response = await fetch(`/adware/${adwareId}`, {method}: 'DELETE' }); | |
| if (!response.ok) { } | |
| throw new Error(`HTTP error! status: ${response.status}`); | |
| } | |
| alert(`Adware with ID ${adwareId} deleted successfully!`); | |
| fetchAdware(); | |
| } catch (error) {showError(`Error deleting adware: ${error}`)}; | |
| } | |
| } | |
| }; | |
| const fetchPayloadsAndDeploymentMethods = async () => { } | |
| try { } | |
| const [payloadResponse, deploymentResponse] = await Promise.all([ | |
| fetch('/payloads'), | |
| fetch('/deployment_methods') | |
| ]); | |
| if (!payloadResponse.ok || !deploymentResponse.ok) { } | |
| throw new Error('Error fetching payloads or deployment methods'); | |
| } | |
| const payloads = await payloadResponse.json(); | |
| const deploymentMethods = await deploymentResponse.json(); | |
| populateDropdowns(payloads, deploymentMethods); | |
| } catch (error) {showError(`Error fetching payloads or deployment methods: ${error}`)}; | |
| } | |
| }; | |
| const populateDropdowns = (payloads, deploymentMethods) => { } | |
| const payloadSelect = document.getElementById('payload_id'); | |
| const deploymentSelect = document.getElementById('deployment_method_id'); | |
| payloadSelect.innerHTML = '<option value="">Select Payload</option>'; | |
| deploymentSelect.innerHTML = '<option value="">Select Deployment Method</option>'; | |
| payloads.forEach(payload => { } | |
| const option = document.createElement('option'); | |
| option.value = payload.id; | |
| option.textContent = payload.name; | |
| payloadSelect.appendChild(option); | |
| }); | |
| deploymentMethods.forEach(method => { } | |
| const option = document.createElement('option'); | |
| option.value = method.id; | |
| option.textContent = method.name; | |
| deploymentSelect.appendChild(option); | |
| }); | |
| }; | |
| const getAdwareForm = (adware = null) => { } | |
| const isEdit = adware !== null; | |
| const title = isEdit ? 'Edit Adware' : 'Create New Adware'; | |
| const submitText = isEdit ? 'Update Adware' : 'Create Adware'; | |
| const nameValue = isEdit ? adware.name : ''; | |
| const descriptionValue = isEdit ? adware.description : ''; | |
| const targetOsValue = isEdit ? adware.target_os : ''; | |
| const persistenceMethodValue = isEdit ? adware.persistence_method : ''; | |
| const payloadIdValue = isEdit ? adware.payload_id : ''; | |
| const deploymentMethodIdValue = isEdit ? adware.deployment_method_id : ''; | |
| const configValue = isEdit ? JSON.stringify(adware.config) : ''; | |
| return ` | |
| <h2>${title}</h2> | |
| <form id="adwareForm"> | |
| <label for="name">Name:</label> | |
| <input type="text" id="name" value="${nameValue}" required><br> | |
| <label for="description">Description:</label> | |
| <textarea id="description" required>${descriptionValue}</textarea><br> | |
| <label for="target_os">Target OS:</label> | |
| <input type="text" id="target_os" value="${targetOsValue}" required><br> | |
| <label for="persistence_method">Persistence Method:</label> | |
| <input type="text" id="persistence_method" value="${persistenceMethodValue}" required><br> | |
| <label for="payload_id">Payload:</label> | |
| <select id="payload_id" required> | |
| <option value="">Select Payload</option> | |
| </select><br> | |
| <label for="deployment_method_id">Deployment Method:</label> | |
| <select id="deployment_method_id" required> | |
| <option value="">Select Deployment Method</option> | |
| </select><br> | |
| <label for="config">Config (JSON):</label> | |
| <textarea id="config">${configValue}</textarea><br> | |
| <button type="submit">${submitText}</button> | |
| <button type="button" onclick="fetchAdware()">Cancel</button> | |
| </form> | |
| ${isEdit ? '' : '<button onclick="showAIAdwareForm()">Create with AI</button>'} | |
| `; | |
| }; | |
| appDiv.addEventListener('submit', async (event) => {event.preventDefault()}; | |
| if (event.target.id === 'adwareForm') { } | |
| const form = document.getElementById('adwareForm'); | |
| const formData = {name}: form.name.value, | |
| description: form.description.value, | |
| target_os: form.target_os.value, | |
| persistence_method: form.persistence_method.value, | |
| payload_id: parseInt(form.payload_id.value), | |
| deployment_method_id: parseInt(form.deployment_method_id.value), | |
| config: form.config.value ? JSON.parse(form.config.value) : | |
| }; | |
| try { } | |
| const url = currentAdwareId ? `/adware/${currentAdwareId}` : '/adware'; | |
| const method = currentAdwareId ? 'PUT' : 'POST'; | |
| const response = await fetch(url, {method}: method, | |
| headers: {'Content-Type'}: 'application/json' }, | |
| body: JSON.stringify(formData) | |
| }); | |
| if (!response.ok) { } | |
| throw new Error(`HTTP error! status: ${response.status}`); | |
| } | |
| alert(`Adware ${currentAdwareId ? 'updated' : 'created'} successfully!`); | |
| fetchAdware(); | |
| } catch (error) {showError(`Error ${currentAdwareId ? 'updating' : 'creating'} adware: ${error}`)}; | |
| } | |
| } | |
| if (event.target.id === 'aiAdwareForm') { } | |
| const form = document.getElementById('aiAdwareForm'); | |
| const formData = {goal}: form.ai_goal.value, | |
| constraints: form.ai_constraints.value ? JSON.parse(form.ai_constraints.value) : | |
| }; | |
| try { } | |
| const response = await fetch('/ai/generate', {method}: 'POST', | |
| headers: {'Content-Type'}: 'application/json' }, | |
| body: JSON.stringify(formData) | |
| }); | |
| if (!response.ok) { } | |
| throw new Error(`HTTP error! status: ${response.status}`); | |
| } | |
| const aiConfig = await response.json(); | |
| appDiv.innerHTML = getAdwareForm(aiConfig); | |
| fetchPayloadsAndDeploymentMethods(); | |
| } catch (error) {showError(`Error generating adware config with AI: ${error}`)}; | |
| } | |
| } | |
| if (event.target.id === 'payloadForm') { } | |
| const form = document.getElementById('payloadForm'); | |
| const formData = {name}: form.name.value, | |
| description: form.description.value, | |
| file_path: form.file_path.value | |
| }; | |
| try { } | |
| const url = currentPayloadId ? `/payloads/${currentPayloadId}` : '/payloads'; | |
| const method = currentPayloadId ? 'PUT' : 'POST'; | |
| const response = await fetch(url, {method}: method, | |
| headers: {'Content-Type'}: 'application/json' }, | |
| body: JSON.stringify(formData) | |
| }); | |
| if (!response.ok) { } | |
| throw new Error(`HTTP error! status: ${response.status}`); | |
| } | |
| alert(`Payload ${currentPayloadId ? 'updated' : 'created'} successfully!`); | |
| showPayloadManagement(); | |
| } catch (error) {showError(`Error ${currentPayloadId ? 'updating' : 'creating'} payload: ${error}`)}; | |
| } | |
| } | |
| if (event.target.id === 'deploymentMethodForm') { } | |
| const form = document.getElementById('deploymentMethodForm'); | |
| const formData = {name}: form.name.value, | |
| description: form.description.value, | |
| config_schema: form.config_schema.value ? JSON.parse(form.config_schema.value) : | |
| }; | |
| try { } | |
| const url = currentDeploymentMethodId ? `/deployment_methods/${currentDeploymentMethodId}` : '/deployment_methods'; | |
| const method = currentDeploymentMethodId ? 'PUT' : 'POST'; | |
| const response = await fetch(url, {method}: method, | |
| headers: {'Content-Type'}: 'application/json' }, | |
| body: JSON.stringify(formData) | |
| }); | |
| if (!response.ok) { } | |
| throw new Error(`HTTP error! status: ${response.status}`); | |
| } | |
| alert(`Deployment method ${currentDeploymentMethodId ? 'updated' : 'created'} successfully!`); | |
| showDeploymentMethodManagement(); | |
| } catch (error) {showError(`Error ${currentDeploymentMethodId ? 'updating' : 'creating'} deployment method: ${error}`)}; | |
| } | |
| } | |
| }); | |
| window.showAIAdwareForm = () => {appDiv.innerHTML = getAIAdwareForm()}; | |
| }; | |
| const getAIAdwareForm = () => { } | |
| return ` | |
| <h2>Create Adware with AI</h2> | |
| <form id="aiAdwareForm"> | |
| <label for="ai_goal">Goal:</label> | |
| <input type="text" id="ai_goal" required><br> | |
| <label for="ai_constraints">Constraints (JSON):</label> | |
| <textarea id="ai_constraints"></textarea><br> | |
| <button type="submit">Generate Adware Config</button> | |
| <button type="button" onclick="showCreateAdwareForm()">Cancel</button> | |
| </form> | |
| `; | |
| }; | |
| // --- Payload Management --- | |
| window.showPayloadManagement = async () => {currentPayloadId = null}; | |
| showLoading('Fetching payloads...'); | |
| try { } | |
| const response = await fetch('/payloads'); | |
| if (!response.ok) { } | |
| throw new Error(`HTTP error! status: ${response.status}`); | |
| } | |
| const data = await response.json(); | |
| displayPayloads(data); | |
| } catch (error) {showError(`Error fetching payloads: ${error}`)}; | |
| } | |
| }; | |
| const displayPayloads = (payloadList) => {let} html = '<h2>Payload Management</h2>'; | |
| if (payloadList.length === 0) {html += '<p>No payloads found.</p>'}; | |
| } else {html += '<table><thead><tr><th>Name</th><th>Description</th><th>Actions</th></tr></thead><tbody>'}; | |
| payloadList.forEach(payload => {html += `<tr> | |
| <td>${payload.name}</td> | |
| <td>${payload.description}</td> | |
| <td> | |
| <button onclick="editPayload(${payload.id})">Edit</button> | |
| <button onclick="deletePayload(${payload.id})">Delete</button> | |
| </td> | |
| </tr>`}; | |
| }); | |
| html += '</tbody></table>'; | |
| } | |
| html += '<button onclick="showCreatePayloadForm()">Create New Payload</button>'; | |
| html += '<button onclick="fetchAdware()">Back to Adware</button>'; | |
| appDiv.innerHTML = html; | |
| }; | |
| window.showCreatePayloadForm = () => {currentPayloadId = null}; | |
| appDiv.innerHTML = getPayloadForm(); | |
| }; | |
| window.editPayload = async (payloadId) => {currentPayloadId = payloadId}; | |
| showLoading(`Fetching payload with ID ${payloadId} for edit...`); | |
| try { } | |
| const response = await fetch(`/payloads/${payloadId}`); | |
| if (!response.ok) { } | |
| throw new Error(`HTTP error! status: ${response.status}`); | |
| } | |
| const payload = await response.json(); | |
| appDiv.innerHTML = getPayloadForm(payload); | |
| } catch (error) {showError(`Error fetching payload for edit: ${error}`)}; | |
| } | |
| }; | |
| window.deletePayload = async (payloadId) => { } | |
| if (confirm(`Are you sure you want to delete payload with ID ${payloadId}?`)) {showLoading(`Deleting payload with ID ${payloadId}...`)}; | |
| try { } | |
| const response = await fetch(`/payloads/${payloadId}`, {method}: 'DELETE' }); | |
| if (!response.ok) { } | |
| throw new Error(`HTTP error! status: ${response.status}`); | |
| } | |
| alert(`Payload with ID ${payloadId} deleted successfully!`); | |
| showPayloadManagement(); | |
| } catch (error) {showError(`Error deleting payload: ${error}`)}; | |
| } | |
| } | |
| }; | |
| const getPayloadForm = (payload = null) => { } | |
| const isEdit = payload !== null; | |
| const title = isEdit ? 'Edit Payload' : 'Create New Payload'; | |
| const submitText = isEdit ? 'Update Payload' : 'Create Payload'; | |
| const nameValue = isEdit ? payload.name : ''; | |
| const descriptionValue = isEdit ? payload.description : ''; | |
| const filePathValue = isEdit ? payload.file_path : ''; | |
| return ` | |
| <h2>${title}</h2> | |
| <form id="payloadForm"> | |
| <label fordocument />.addEventListener('DOMContentLoaded', () => { } | |
| const appDiv = document.getElementById('app'); | |
| let currentAdwareId = null; | |
| let currentPayloadId = null; | |
| let currentDeploymentMethodId = null; | |
| // --- Helper Functions --- | |
| const showLoading = (message = 'Loading...') => {appDiv.innerHTML = `<p>${message}</p>`}; | |
| }; | |
| const showError = (message) => {appDiv.innerHTML = `<p style="color:red;">Error: ${message}</p>`}; | |
| }; | |
| // --- Adware Management --- | |
| const fetchAdware = async () => {showLoading('Fetching adware configurations...')}; | |
| try { } | |
| const response = await fetch('/adware'); | |
| if (!response.ok) { } | |
| throw new Error(`HTTP error! status: ${response.status}`); | |
| } | |
| const data = await response.json(); | |
| displayAdware(data); | |
| } catch (error) {showError(`Error fetching adware: ${error}`)}; | |
| } | |
| }; | |
| const displayAdware = (adwareList) => {let} html = '<h2>Adware Configurations</h2>'; | |
| if (adwareList.length === 0) {html += '<p>No adware configurations found.</p>'}; | |
| } else {html += '<table><thead><tr><th>Name</th><th>Description</th><th>Actions</th></tr></thead><tbody>'}; | |
| adwareList.forEach(adware => {html += `<tr> | |
| <td>${adware.name}</td> | |
| <td>${adware.description}</td> | |
| <td> | |
| <button onclick="deployAdware(${adware.id})">Deploy</button> | |
| <button onclick="editAdware(${adware.id})">Edit</button> | |
| <button onclick="deleteAdware(${adware.id})">Delete</button> | |
| </td> | |
| </tr>`}; | |
| }); | |
| html += '</tbody></table>'; | |
| } | |
| html += '<button onclick="showCreateAdwareForm()">Create New Adware</button>'; | |
| html += '<button onclick="showPayloadManagement()">Manage Payloads</button>'; | |
| html += '<button onclick="showDeploymentMethodManagement()">Manage Deployment Methods</button>'; | |
| appDiv.innerHTML = html; | |
| }; | |
| window.deployAdware = async (adwareId) => {showLoading(`Deploying adware with ID ${adwareId}...`)}; | |
| try { } | |
| const response = await fetch(`/adware/${adwareId}/deploy`, {method}: 'POST' }); | |
| if (!response.ok) { } | |
| throw new Error(`HTTP error! status: ${response.status}`); | |
| } | |
| alert(`Adware with ID ${adwareId} deployed successfully!`); | |
| fetchAdware(); | |
| } catch (error) {showError(`Error deploying adware: ${error}`)}; | |
| } | |
| }; | |
| window.showCreateAdwareForm = () => {currentAdwareId = null}; | |
| appDiv.innerHTML = getAdwareForm(); | |
| fetchPayloadsAndDeploymentMethods(); | |
| }; | |
| window.editAdware = async (adwareId) => {currentAdwareId = adwareId}; | |
| showLoading(`Fetching adware with ID ${adwareId} for edit...`); | |
| try { } | |
| const response = await fetch(`/adware/${adwareId}`); | |
| if (!response.ok) { } | |
| throw new Error(`HTTP error! status: ${response.status}`); | |
| } | |
| const adware = await response.json(); | |
| appDiv.innerHTML = getAdwareForm(adware); | |
| fetchPayloadsAndDeploymentMethods(); | |
| } catch (error) {showError(`Error fetching adware for edit: ${error}`)}; | |
| } | |
| }; | |
| window.deleteAdware = async (adwareId) => { } | |
| if (confirm(`Are you sure you want to delete adware with ID ${adwareId}?`)) {showLoading(`Deleting adware with ID ${adwareId}...`)}; | |
| try { } | |
| const response = await fetch(`/adware/${adwareId}`, {method}: 'DELETE' }); | |
| if (!response.ok) { } | |
| throw new Error(`HTTP error! status: ${response.status}`); | |
| } | |
| alert(`Adware with ID ${adwareId} deleted successfully!`); | |
| fetchAdware(); | |
| } catch (error) {showError(`Error deleting adware: ${error}`)}; | |
| } | |
| } | |
| }; | |
| const fetchPayloadsAndDeploymentMethods = async () => { } | |
| try { } | |
| const [payloadResponse, deploymentResponse] = await Promise.all([ | |
| fetch('/payloads'), | |
| fetch('/deployment_methods') | |
| ]); | |
| if (!payloadResponse.ok || !deploymentResponse.ok) { } | |
| throw new Error('Error fetching payloads or deployment methods'); | |
| } | |
| const payloads = await payloadResponse.json(); | |
| const deploymentMethods = await deploymentResponse.json(); | |
| populateDropdowns(payloads, deploymentMethods); | |
| } catch (error) {showError(`Error fetching payloads or deployment methods: ${error}`)}; | |
| } | |
| }; | |
| const populateDropdowns = (payloads, deploymentMethods) => { } | |
| const payloadSelect = document.getElementById('payload_id'); | |
| const deploymentSelect = document.getElementById('deployment_method_id'); | |
| payloadSelect.innerHTML = '<option value="">Select Payload</option>'; | |
| deploymentSelect.innerHTML = '<option value="">Select Deployment Method</option>'; | |
| payloads.forEach(payload => { } | |
| const option = document.createElement('option'); | |
| option.value = payload.id; | |
| option.textContent = payload.name; | |
| payloadSelect.appendChild(option); | |
| }); | |
| deploymentMethods.forEach(method => { } | |
| const option = document.createElement('option'); | |
| option.value = method.id; | |
| option.textContent = method.name; | |
| deploymentSelect.appendChild(option); | |
| }); | |
| }; | |
| const getAdwareForm = (adware = null) => { } | |
| const isEdit = adware !== null; | |
| const title = isEdit ? 'Edit Adware' : 'Create New Adware'; | |
| const submitText = isEdit ? 'Update Adware' : 'Create Adware'; | |
| const nameValue = isEdit ? adware.name : ''; | |
| const descriptionValue = isEdit ? adware.description : ''; | |
| const targetOsValue = isEdit ? adware.target_os : ''; | |
| const persistenceMethodValue = isEdit ? adware.persistence_method : ''; | |
| const payloadIdValue = isEdit ? adware.payload_id : ''; | |
| const deploymentMethodIdValue = isEdit ? adware.deployment_method_id : ''; | |
| const configValue = isEdit ? JSON.stringify(adware.config) : ''; | |
| return ` | |
| <h2>${title}</h2> | |
| <form id="adwareForm"> | |
| <label for="name">Name:</label> | |
| <input type="text" id="name" value="${nameValue}" required><br> | |
| <label for="description">Description:</label> | |
| <textarea id="description" required>${descriptionValue}</textarea><br> | |
| <label for="target_os">Target OS:</label> | |
| <input type="text" id="target_os" value="${targetOsValue}" required><br> | |
| <label for="persistence_method">Persistence Method:</label> | |
| <input type="text" id="persistence_method" value="${persistenceMethodValue}" required><br> | |
| <label for="payload_id">Payload:</label> | |
| <select id="payload_id" required> | |
| <option value="">Select Payload</option> | |
| </select><br> | |
| <label for="deployment_method_id">Deployment Method:</label> | |
| <select id="deployment_method_id" required> | |
| <option value="">Select Deployment Method</option> | |
| </select><br> | |
| <label for="config">Config (JSON):</label> | |
| <textarea id="config">${configValue}</textarea><br> | |
| <button type="submit">${submitText}</button> | |
| <button type="button" onclick="fetchAdware()">Cancel</button> | |
| </form> | |
| ${isEdit ? '' : '<button onclick="showAIAdwareForm()">Create with AI</button>'} | |
| `; | |
| }; | |
| appDiv.addEventListener('submit', async (event) => {event.preventDefault()}; | |
| if (event.target.id === 'adwareForm') { } | |
| const form = document.getElementById('adwareForm'); | |
| const formData = {name}: form.name.value, | |
| description: form.description.value, | |
| target_os: form.target_os.value, | |
| persistence_method: form.persistence_method.value, | |
| payload_id: parseInt(form.payload_id.value), | |
| deployment_method_id: parseInt(form.deployment_method_id.value), | |
| config: form.config.value ? JSON.parse(form.config.value) : | |
| }; | |
| try { } | |
| const url = currentAdwareId ? `/adware/${currentAdwareId}` : '/adware'; | |
| const method = currentAdwareId ? 'PUT' : 'POST'; | |
| const response = await fetch(url, {method}: method, | |
| headers: {'Content-Type'}: 'application/json' }, | |
| body: JSON.stringify(formData) | |
| }); | |
| if (!response.ok) { } | |
| throw new Error(`HTTP error! status: ${response.status}`); | |
| } | |
| alert(`Adware ${currentAdwareId ? 'updated' : 'created'} successfully!`); | |
| fetchAdware(); | |
| } catch (error) {showError(`Error ${currentAdwareId ? 'updating' : 'creating'} adware: ${error}`)}; | |
| } | |
| } | |
| if (event.target.id === 'aiAdwareForm') { } | |
| const form = document.getElementById('aiAdwareForm'); | |
| const formData = {goal}: form.ai_goal.value, | |
| constraints: form.ai_constraints.value ? JSON.parse(form.ai_constraints.value) : | |
| }; | |
| try { } | |
| const response = await fetch('/ai/generate', {method}: 'POST', | |
| headers: {'Content-Type'}: 'application/json' }, | |
| body: JSON.stringify(formData) | |
| }); | |
| if (!response.ok) { } | |
| throw new Error(`HTTP error! status: ${response.status}`); | |
| } | |
| const aiConfig = await response.json(); | |
| appDiv.innerHTML = getAdwareForm(aiConfig); | |
| fetchPayloadsAndDeploymentMethods(); | |
| } catch (error) {showError(`Error generating adware config with AI: ${error}`)}; | |
| } | |
| } | |
| if (event.target.id === 'payloadForm') { } | |
| const form = document.getElementById('payloadForm'); | |
| const formData = {name}: form.name.value, | |
| description: form.description.value, | |
| file_path: form.file_path.value | |
| }; | |
| try { } | |
| const url = currentPayloadId ? `/payloads/${currentPayloadId}` : '/payloads'; | |
| const method = currentPayloadId ? 'PUT' : 'POST'; | |
| const response = await fetch(url, {method}: method, | |
| headers: {'Content-Type'}: 'application/json' }, | |
| body: JSON.stringify(formData) | |
| }); | |
| if (!response.ok) { } | |
| throw new Error(`HTTP error! status: ${response.status}`); | |
| } | |
| alert(`Payload ${currentPayloadId ? 'updated' : 'created'} successfully!`); | |
| showPayloadManagement(); | |
| } catch (error) {showError(`Error ${currentPayloadId ? 'updating' : 'creating'} payload: ${error}`)}; | |
| } | |
| } | |
| if (event.target.id === 'deploymentMethodForm') { } | |
| const form = document.getElementById('deploymentMethodForm'); | |
| const formData = {name}: form.name.value, | |
| description: form.description.value, | |
| config_schema: form.config_schema.value ? JSON.parse(form.config_schema.value) : | |
| }; | |
| try { } | |
| const url = currentDeploymentMethodId ? `/deployment_methods/${currentDeploymentMethodId}` : '/deployment_methods'; | |
| const method = currentDeploymentMethodId ? 'PUT' : 'POST'; | |
| const response = await fetch(url, {method}: method, | |
| headers: {'Content-Type'}: 'application/json' }, | |
| body: JSON.stringify(formData) | |
| }); | |
| if (!response.ok) { } | |
| throw new Error(`HTTP error! status: ${response.status}`); | |
| } | |
| alert(`Deployment method ${currentDeploymentMethodId ? 'updated' : 'created'} successfully!`); | |
| showDeploymentMethodManagement(); | |
| } catch (error) {showError(`Error ${currentDeploymentMethodId ? 'updating' : 'creating'} deployment method: ${error}`)}; | |
| } | |
| } | |
| }); | |
| window.showAIAdwareForm = () => {appDiv.innerHTML = getAIAdwareForm()}; | |
| }; | |
| const getAIAdwareForm = () => { } | |
| return ` | |
| <h2>Create Adware with AI</h2> | |
| <form id="aiAdwareForm"> | |
| <label for="ai_goal">Goal:</label> | |
| <input type="text" id="ai_goal" required><br> | |
| <label for="ai_constraints">Constraints (JSON):</label> | |
| <textarea id="ai_constraints"></textarea><br> | |
| <button type="submit">Generate Adware Config</button> | |
| <button type="button" onclick="showCreateAdwareForm()">Cancel</button> | |
| </form> | |
| `; | |
| }; | |
| // --- Payload Management --- | |
| window.showPayloadManagement = async () => {currentPayloadId = null}; | |
| showLoading('Fetching payloads...'); | |
| try { } | |
| const response = await fetch('/payloads'); | |
| if (!response.ok) { } | |
| throw new Error(`HTTP error! status: ${response.status}`); | |
| } | |
| const data = await response.json(); | |
| displayPayloads(data); | |
| } catch (error) {showError(`Error fetching payloads: ${error}`)}; | |
| } | |
| }; | |
| const displayPayloads = (payloadList) => {let} html = '<h2>Payload Management</h2>'; | |
| if (payloadList.length === 0) {html += '<p>No payloads found.</p>'}; | |
| } else {html += '<table><thead><tr><th>Name</th><th>Description</th><th>Actions</th></tr></thead><tbody>'}; | |
| payloadList.forEach(payload => {html += `<tr> | |
| <td>${payload.name}</td> | |
| <td>${payload.description}</td> | |
| <td> | |
| <button onclick="editPayload(${payload.id})">Edit</button> | |
| <button onclick="deletePayload(${payload.id})">Delete</button> | |
| </td> | |
| </tr>`}; | |
| }); | |
| html += '</tbody></table>'; | |
| } | |
| html += '<button onclick="showCreatePayloadForm()">Create New Payload</button>'; | |
| html += '<button onclick="fetchAdware()">Back to Adware</button>'; | |
| appDiv.innerHTML = html; | |
| }; | |
| window.showCreatePayloadForm = () => {currentPayloadId = null}; | |
| appDiv.innerHTML = getPayloadForm(); | |
| }; | |
| window.editPayload = async (payloadId) => {currentPayloadId = payloadId}; | |
| showLoading(`Fetching payload with ID ${payloadId} for edit...`); | |
| try { } | |
| const response = await fetch(`/payloads/${payloadId}`); | |
| if (!response.ok) { } | |
| throw new Error(`HTTP error! status: ${response.status}`); | |
| } | |
| const payload = await response.json(); | |
| appDiv.innerHTML = getPayloadForm(payload); | |
| } catch (error) {showError(`Error fetching payload for edit: ${error}`)}; | |
| } | |
| }; | |
| window.deletePayload = async (payloadId) => { } | |
| if (confirm(`Are you sure you want to delete payload with ID ${payloadId}?`)) {showLoading(`Deleting payload with ID ${payloadId}...`)}; | |
| try { } | |
| const response = await fetch(`/payloads/${payloadId}`, {method}: 'DELETE' }); | |
| if (!response.ok) { } | |
| throw new Error(`HTTP error! status: ${response.status}`); | |
| } | |
| alert(`Payload with ID ${payloadId} deleted successfully!`); | |
| showPayloadManagement(); | |
| } catch (error) {showError(`Error deleting payload: ${error}`)}; | |
| } | |
| } | |
| }; | |
| const getPayloadForm = (payload = null) => { } | |
| const isEdit = payload !== null; | |
| const title = isEdit ? 'Edit Payload' : 'Create New Payload'; | |
| const submitText = isEdit ? 'Update Payload' : 'Create Payload'; | |
| const nameValue = isEdit ? payload.name : ''; | |
| const descriptionValue = isEdit ? payload.description : ''; | |
| const filePathValue = isEdit ? payload.file_path : ''; | |
| return ` | |
| <h2>${title}</h2> | |
| <form id="payloadForm"> | |
| <label fordocument />.addEventListener('DOMContentLoaded', () => { } | |
| const appDiv = document.getElementById('app'); | |
| let currentAdwareId = null; | |
| let currentPayloadId = null; | |
| let currentDeploymentMethodId = null; | |
| // --- Helper Functions --- | |
| const showLoading = (message = 'Loading...') => {appDiv.innerHTML = `<p>${message}</p>`}; | |
| }; | |
| const showError = (message) => {appDiv.innerHTML = `<p style="color:red;">Error: ${message}</p>`}; | |
| }; | |
| // --- Adware Management --- | |
| const fetchAdware = async () => {showLoading('Fetching adware configurations...')}; | |
| try { } | |
| const response = await fetch('/adware'); | |
| if (!response.ok) { } | |
| throw new Error(`HTTP error! status: ${response.status}`); | |
| } | |
| const data = await response.json(); | |
| displayAdware(data); | |
| } catch (error) {showError(`Error fetching adware: ${error}`)}; | |
| } | |
| }; | |
| const displayAdware = (adwareList) => {let} html = '<h2>Adware Configurations</h2>'; | |
| if (adwareList.length === 0) {html += '<p>No adware configurations found.</p>'}; | |
| } else {html += '<table><thead><tr><th>Name</th><th>Description</th><th>Actions</th></tr></thead><tbody>'}; | |
| adwareList.forEach(adware => {html += `<tr> | |
| <td>${adware.name}</td> | |
| <td>${adware.description}</td> | |
| <td> | |
| <button onclick="deployAdware(${adware.id})">Deploy</button> | |
| <button onclick="editAdware(${adware.id})">Edit</button> | |
| <button onclick="deleteAdware(${adware.id})">Delete</button> | |
| </td> | |
| </tr>`}; | |
| }); | |
| html += '</tbody></table>'; | |
| } | |
| html += '<button onclick="showCreateAdwareForm()">Create New Adware</button>'; | |
| html += '<button onclick="showPayloadManagement()">Manage Payloads</button>'; | |
| html += '<button onclick="showDeploymentMethodManagement()">Manage Deployment Methods</button>'; | |
| appDiv.innerHTML = html; | |
| }; | |
| window.deployAdware = async (adwareId) => {showLoading(`Deploying adware with ID ${adwareId}...`)}; | |
| try { } | |
| const response = await fetch(`/adware/${adwareId}/deploy`, {method}: 'POST' }); | |
| if (!response.ok) { } | |
| throw new Error(`HTTP error! status: ${response.status}`); | |
| } | |
| alert(`Adware with ID ${adwareId} deployed successfully!`); | |
| fetchAdware(); | |
| } catch (error) {showError(`Error deploying adware: ${error}`)}; | |
| } | |
| }; | |
| window.showCreateAdwareForm = () => {currentAdwareId = null}; | |
| appDiv.innerHTML = getAdwareForm(); | |
| fetchPayloadsAndDeploymentMethods(); | |
| }; | |
| window.editAdware = async (adwareId) => {currentAdwareId = adwareId}; | |
| showLoading(`Fetching adware with ID ${adwareId} for edit...`); | |
| try { } | |
| const response = await fetch(`/adware/${adwareId}`); | |
| if (!response.ok) { } | |
| throw new Error(`HTTP error! status: ${response.status}`); | |
| } | |
| const adware = await response.json(); | |
| appDiv.innerHTML = getAdwareForm(adware); | |
| fetchPayloadsAndDeploymentMethods(); | |
| } catch (error) {showError(`Error fetching adware for edit: ${error}`)}; | |
| } | |
| }; | |
| window.deleteAdware = async (adwareId) => { } | |
| if (confirm(`Are you sure you want to delete adware with ID ${adwareId}?`)) {showLoading(`Deleting adware with ID ${adwareId}...`)}; | |
| try { } | |
| const response = await fetch(`/adware/${adwareId}`, {method}: 'DELETE' }); | |
| if (!response.ok) { } | |
| throw new Error(`HTTP error! status: ${response.status}`); | |
| } | |
| alert(`Adware with ID ${adwareId} deleted successfully!`); | |
| fetchAdware(); | |
| } catch (error) {showError(`Error deleting adware: ${error}`)}; | |
| } | |
| } | |
| }; | |
| const fetchPayloadsAndDeploymentMethods = async () => { } | |
| try { } | |
| const [payloadResponse, deploymentResponse] = await Promise.all([ | |
| fetch('/payloads'), | |
| fetch('/deployment_methods') | |
| ]); | |
| if (!payloadResponse.ok || !deploymentResponse.ok) { } | |
| throw new Error('Error fetching payloads or deployment methods'); | |
| } | |
| const payloads = await payloadResponse.json(); | |
| const deploymentMethods = await deploymentResponse.json(); | |
| populateDropdowns(payloads, deploymentMethods); | |
| } catch (error) {showError(`Error fetching payloads or deployment methods: ${error}`)}; | |
| } | |
| }; | |
| const populateDropdowns = (payloads, deploymentMethods) => { } | |
| const payloadSelect = document.getElementById('payload_id'); | |
| const deploymentSelect = document.getElementById('deployment_method_id'); | |
| payloadSelect.innerHTML = '<option value="">Select Payload</option>'; | |
| deploymentSelect.innerHTML = '<option value="">Select Deployment Method</option>'; | |
| payloads.forEach(payload => { } | |
| const option = document.createElement('option'); | |
| option.value = payload.id; | |
| option.textContent = payload.name; | |
| payloadSelect.appendChild(option); | |
| }); | |
| deploymentMethods.forEach(method => { } | |
| const option = document.createElement('option'); | |
| option.value = method.id; | |
| option.textContent = method.name; | |
| deploymentSelect.appendChild(option); | |
| }); | |
| }; | |
| const getAdwareForm = (adware = null) => { } | |
| const isEdit = adware !== null; | |
| const title = isEdit ? 'Edit Adware' : 'Create New Adware'; | |
| const submitText = isEdit ? 'Update Adware' : 'Create Adware'; | |
| const nameValue = isEdit ? adware.name : ''; | |
| const descriptionValue = isEdit ? adware.description : ''; | |
| const targetOsValue = isEdit ? adware.target_os : ''; | |
| const persistenceMethodValue = isEdit ? adware.persistence_method : ''; | |
| const payloadIdValue = isEdit ? adware.payload_id : ''; | |
| const deploymentMethodIdValue = isEdit ? adware.deployment_method_id : ''; | |
| const configValue = isEdit ? JSON.stringify(adware.config) : ''; | |
| return ` | |
| <h2>${title}</h2> | |
| <form id="adwareForm"> | |
| <label for="name">Name:</label> | |
| <input type="text" id="name" value="${nameValue}" required><br> | |
| <label for="description">Description:</label> | |
| <textarea id="description" required>${descriptionValue}</textarea><br> | |
| <label for="target_os">Target OS:</label> | |
| <input type="text" id="target_os" value="${targetOsValue}" required><br> | |
| <label for="persistence_method">Persistence Method:</label> | |
| <input type="text" id="persistence_method" value="${persistenceMethodValue}" required><br> | |
| <label for="payload_id">Payload:</label> | |
| <select id="payload_id" required> | |
| <option value="">Select Payload</option> | |
| </select><br> | |
| <label for="deployment_method_id">Deployment Method:</label> | |
| <select id="deployment_method_id" required> | |
| <option value="">Select Deployment Method</option> | |
| </select><br> | |
| <label for="config">Config (JSON):</label> | |
| <textarea id="config">${configValue}</textarea><br> | |
| <button type="submit">${submitText}</button> | |
| <button type="button" onclick="fetchAdware()">Cancel</button> | |
| </form> | |
| ${isEdit ? '' : '<button onclick="showAIAdwareForm()">Create with AI</button>'} | |
| `; | |
| }; | |
| appDiv.addEventListener('submit', async (event) => {event.preventDefault()}; | |
| if (event.target.id === 'adwareForm') { } | |
| const form = document.getElementById('adwareForm'); | |
| const formData = {name}: form.name.value, | |
| description: form.description.value, | |
| target_os: form.target_os.value, | |
| persistence_method: form.persistence_method.value, | |
| payload_id: parseInt(form.payload_id.value), | |
| deployment_method_id: parseInt(form.deployment_method_id.value), | |
| config: form.config.value ? JSON.parse(form.config.value) : | |
| }; | |
| try { } | |
| const url = currentAdwareId ? `/adware/${currentAdwareId}` : '/adware'; | |
| const method = currentAdwareId ? 'PUT' : 'POST'; | |
| const response = await fetch(url, {method}: method, | |
| headers: {'Content-Type'}: 'application/json' }, | |
| body: JSON.stringify(formData) | |
| }); | |
| if (!response.ok) { } | |
| throw new Error(`HTTP error! status: ${response.status}`); | |
| } | |
| alert(`Adware ${currentAdwareId ? 'updated' : 'created'} successfully!`); | |
| fetchAdware(); | |
| } catch (error) {showError(`Error ${currentAdwareId ? 'updating' : 'creating'} adware: ${error}`)}; | |
| } | |
| } | |
| if (event.target.id === 'aiAdwareForm') { } | |
| const form = document.getElementById('aiAdwareForm'); | |
| const formData = {goal}: form.ai_goal.value, | |
| constraints: form.ai_constraints.value ? JSON.parse(form.ai_constraints.value) : | |
| }; | |
| try { } | |
| const response = await fetch('/ai/generate', {method}: 'POST', | |
| headers: {'Content-Type'}: 'application/json' }, | |
| body: JSON.stringify(formData) | |
| }); | |
| if (!response.ok) { } | |
| throw new Error(`HTTP error! status: ${response.status}`); | |
| } | |
| const aiConfig = await response.json(); | |
| appDiv.innerHTML = getAdwareForm(aiConfig); | |
| fetchPayloadsAndDeploymentMethods(); | |
| } catch (error) {showError(`Error generating adware config with AI: ${error}`)}; | |
| } | |
| } | |
| if (event.target.id === 'payloadForm') { } | |
| const form = document.getElementById('payloadForm'); | |
| const formData = {name}: form.name.value, | |
| description: form.description.value, | |
| file_path: form.file_path.value | |
| }; | |
| try { } | |
| const url = currentPayloadId ? `/payloads/${currentPayloadId}` : '/payloads'; | |
| const method = currentPayloadId ? 'PUT' : 'POST'; | |
| const response = await fetch(url, {method}: method, | |
| headers: {'Content-Type'}: 'application/json' }, | |
| body: JSON.stringify(formData) | |
| }); | |
| if (!response.ok) { } | |
| throw new Error(`HTTP error! status: ${response.status}`); | |
| } | |
| alert(`Payload ${currentPayloadId ? 'updated' : 'created'} successfully!`); | |
| showPayloadManagement(); | |
| } catch (error) {showError(`Error ${currentPayloadId ? 'updating' : 'creating'} payload: ${error}`)}; | |
| } | |
| } | |
| if (event.target.id === 'deploymentMethodForm') { } | |
| const form = document.getElementById('deploymentMethodForm'); | |
| const formData = {name}: form.name.value, | |
| description: form.description.value, | |
| config_schema: form.config_schema.value ? JSON.parse(form.config_schema.value) : | |
| }; | |
| try { } | |
| const url = currentDeploymentMethodId ? `/deployment_methods/${currentDeploymentMethodId}` : '/deployment_methods'; | |
| const method = currentDeploymentMethodId ? 'PUT' : 'POST'; | |
| const response = await fetch(url, {method}: method, | |
| headers: {'Content-Type'}: 'application/json' }, | |
| body: JSON.stringify(formData) | |
| }); | |
| if (!response.ok) { } | |
| throw new Error(`HTTP error! status: ${response.status}`); | |
| } | |
| alert(`Deployment method ${currentDeploymentMethodId ? 'updated' : 'created'} successfully!`); | |
| showDeploymentMethodManagement(); | |
| } catch (error) {showError(`Error ${currentDeploymentMethodId ? 'updating' : 'creating'} deployment method: ${error}`)}; | |
| } | |
| } | |
| }); | |
| window.showAIAdwareForm = () => {appDiv.innerHTML = getAIAdwareForm()}; | |
| }; | |
| const getAIAdwareForm = () => { } | |
| return ` | |
| <h2>Create Adware with AI</h2> | |
| <form id="aiAdwareForm"> | |
| <label for="ai_goal">Goal:</label> | |
| <input type="text" id="ai_goal" required><br> | |
| <label for="ai_constraints">Constraints (JSON):</label> | |
| <textarea id="ai_constraints"></textarea><br> | |
| <button type="submit">Generate Adware Config</button> | |
| <button type="button" onclick="showCreateAdwareForm()">Cancel</button> | |
| </form> | |
| `; | |
| }; | |
| // --- Payload Management --- | |
| window.showPayloadManagement = async () => {currentPayloadId = null}; | |
| showLoading('Fetching payloads...'); | |
| try { } | |
| const response = await fetch('/payloads'); | |
| if (!response.ok) { } | |
| throw new Error(`HTTP error! status: ${response.status}`); | |
| } | |
| const data = await response.json(); | |
| displayPayloads(data); | |
| } catch (error) {showError(`Error fetching payloads: ${error}`)}; | |
| } | |
| }; | |
| const displayPayloads = (payloadList) => {let} html = '<h2>Payload Management</h2>'; | |
| if (payloadList.length === 0) {html += '<p>No payloads found.</p>'}; | |
| } else {html += '<table><thead><tr><th>Name</th><th>Description</th><th>Actions</th></tr></thead><tbody>'}; | |
| payloadList.forEach(payload => {html += `<tr> | |
| <td>${payload.name}</td> | |
| <td>${payload.description}</td> | |
| <td> | |
| <button onclick="editPayload(${payload.id})">Edit</button> | |
| <button onclick="deletePayload(${payload.id})">Delete</button> | |
| </td> | |
| </tr>`}; | |
| }); | |
| html += '</tbody></table>'; | |
| } | |
| html += '<button onclick="showCreatePayloadForm()">Create New Payload</button>'; | |
| html += '<button onclick="fetchAdware()">Back to Adware</button>'; | |
| appDiv.innerHTML = html; | |
| }; | |
| window.showCreatePayloadForm = () => {currentPayloadId = null}; | |
| appDiv.innerHTML = getPayloadForm(); | |
| }; | |
| window.editPayload = async (payloadId) => {currentPayloadId = payloadId}; | |
| showLoading(`Fetching payload with ID ${payloadId} for edit...`); | |
| try { } | |
| const response = await fetch(`/payloads/${payloadId}`); | |
| if (!response.ok) { } | |
| throw new Error(`HTTP error! status: ${response.status}`); | |
| } | |
| const payload = await response.json(); | |
| appDiv.innerHTML = getPayloadForm(payload); | |
| } catch (error) {showError(`Error fetching payload for edit: ${error}`)}; | |
| } | |
| }; | |
| window.deletePayload = async (payloadId) => { } | |
| if (confirm(`Are you sure you want to delete payload with ID ${payloadId}?`)) {showLoading(`Deleting payload with ID ${payloadId}...`)}; | |
| try { } | |
| const response = await fetch(`/payloads/${payloadId}`, {method}: 'DELETE' }); | |
| if (!response.ok) { } | |
| throw new Error(`HTTP error! status: ${response.status}`); | |
| } | |
| alert(`Payload with ID ${payloadId} deleted successfully!`); | |
| showPayloadManagement(); | |
| } catch (error) {showError(`Error deleting payload: ${error}`)}; | |
| } | |
| } | |
| }; | |
| const getPayloadForm = (payload = null) => { } | |
| const isEdit = payload !== null; | |
| const title = isEdit ? 'Edit Payload' : 'Create New Payload'; | |
| const submitText = isEdit ? 'Update Payload' : 'Create Payload'; | |
| const nameValue = isEdit ? payload.name : ''; | |
| const descriptionValue = isEdit ? payload.description : ''; | |
| const filePathValue = isEdit ? payload.file_path : ''; | |
| return ` | |
| <h2>${title}</h2> | |
| <form id="payloadForm"> | |
| document.addEventListener('DOMContentLoaded', () => { } | |
| const appDiv = document.getElementById('app'); | |
| let currentAdwareId = null; | |
| let currentPayloadId = null; | |
| let currentDeploymentMethodId = null; | |
| // --- Helper Functions --- | |
| const showLoading = (message = 'Loading...') => {appDiv.innerHTML = `<p>${message}</p>`}; | |
| }; | |
| const showError = (message) => {appDiv.innerHTML = `<p style="color:red;">Error: ${message}</p>`}; | |
| }; | |
| // --- Adware Management --- | |
| const fetchAdware = async () => {showLoading('Fetching adware configurations...')}; | |
| try { } | |
| const response = await fetch('/adware'); | |
| if (!response.ok) { } | |
| throw new Error(`HTTP error! status: ${response.status}`); | |
| } | |
| const data = await response.json(); | |
| displayAdware(data); | |
| } catch (error) {showError(`Error fetching adware: ${error}`)}; | |
| } | |
| }; | |
| const displayAdware = (adwareList) => {let} html = '<h2>Adware Configurations</h2>'; | |
| if (adwareList.length === 0) {html += '<p>No adware configurations found.</p>'}; | |
| } else {html += '<table><thead><tr><th>Name</th><th>Description</th><th>Actions</th></tr></thead><tbody>'}; | |
| adwareList.forEach(adware => {html += `<tr> | |
| <td>${adware.name}</td> | |
| <td>${adware.description}</td> | |
| <td> | |
| <button onclick="deployAdware(${adware.id})">Deploy</button> | |
| <button onclick="editAdware(${adware.id})">Edit</button> | |
| <button onclick="deleteAdware(${adware.id})">Delete</button> | |
| </td> | |
| </tr>`}; | |
| }); | |
| html += '</tbody></table>'; | |
| } | |
| html += '<button onclick="showCreateAdwareForm()">Create New Adware</button>'; | |
| html += '<button onclick="showPayloadManagement()">Manage Payloads</button>'; | |
| html += '<button onclick="showDeploymentMethodManagement()">Manage Deployment Methods</button>'; | |
| appDiv.innerHTML = html; | |
| }; | |
| window.deployAdware = async (adwareId) => {showLoading(`Deploying adware with ID ${adwareId}...`)}; | |
| try { } | |
| const response = await fetch(`/adware/${adwareId}/deploy`, {method}: 'POST' }); | |
| if (!response.ok) { } | |
| throw new Error(`HTTP error! status: ${response.status}`); | |
| } | |
| alert(`Adware with ID ${adwareId} deployed successfully!`); | |
| fetchAdware(); | |
| } catch (error) {showError(`Error deploying adware: ${error}`)}; | |
| } | |
| }; | |
| window.showCreateAdwareForm = () => {currentAdwareId = null}; | |
| appDiv.innerHTML = getAdwareForm(); | |
| fetchPayloadsAndDeploymentMethods(); | |
| }; | |
| window.editAdware = async (adwareId) => {currentAdwareId = adwareId}; | |
| showLoading(`Fetching adware with ID ${adwareId} for edit...`); | |
| try { } | |
| const response = await fetch(`/adware/${adwareId}`); | |
| if (!response.ok) { } | |
| throw new Error(`HTTP error! status: ${response.status}`); | |
| } | |
| const adware = await response.json(); | |
| appDiv.innerHTML = getAdwareForm(adware); | |
| fetchPayloadsAndDeploymentMethods(); | |
| } catch (error) {showError(`Error fetching adware for edit: ${error}`)}; | |
| } | |
| }; | |
| window.deleteAdware = async (adwareId) => { } | |
| if (confirm(`Are you sure you want to delete adware with ID ${adwareId}?`)) {showLoading(`Deleting adware with ID ${adwareId}...`)}; | |
| try { } | |
| const response = await fetch(`/adware/${adwareId}`, {method}: 'DELETE' }); | |
| if (!response.ok) { } | |
| throw new Error(`HTTP error! status: ${response.status}`); | |
| } | |
| alert(`Adware with ID ${adwareId} deleted successfully!`); | |
| fetchAdware(); | |
| } catch (error) {showError(`Error deleting adware: ${error}`)}; | |
| } | |
| } | |
| }; | |
| const fetchPayloadsAndDeploymentMethods = async () => { } | |
| try { } | |
| const [payloadResponse, deploymentResponse] = await Promise.all([ | |
| fetch('/payloads'), | |
| fetch('/deployment_methods') | |
| ]); | |
| if (!payloadResponse.ok || !deploymentResponse.ok) { } | |
| throw new Error('Error fetching payloads or deployment methods'); | |
| } | |
| const payloads = await payloadResponse.json(); | |
| const deploymentMethods = await deploymentResponse.json(); | |
| populateDropdowns(payloads, deploymentMethods); | |
| } catch (error) {showError(`Error fetching payloads or deployment methods: ${error}`)}; | |
| } | |
| }; | |
| const populateDropdowns = (payloads, deploymentMethods) => { } | |
| const payloadSelect = document.getElementById('payload_id'); | |
| const deploymentSelect = document.getElementById('deployment_method_id'); | |
| payloadSelect.innerHTML = '<option value="">Select Payload</option>'; | |
| deploymentSelect.innerHTML = '<option value="">Select Deployment Method</option>'; | |
| payloads.forEach(payload => { } | |
| const option = document.createElement('option'); | |
| option.value = payload.id; | |
| option.textContent = payload.name; | |
| payloadSelect.appendChild(option); | |
| }); | |
| deploymentMethods.forEach(method => { } | |
| const option = document.createElement('option'); | |
| option.value = method.id; | |
| option.textContent = method.name; | |
| deploymentSelect.appendChild(option); | |
| }); | |
| }; | |
| const getAdwareForm = (adware = null) => { } | |
| const isEdit = adware !== null; | |
| const title = isEdit ? 'Edit Adware' : 'Create New Adware'; | |
| const submitText = isEdit ? 'Update Adware' : 'Create Adware'; | |
| const nameValue = isEdit ? adware.name : ''; | |
| const descriptionValue = isEdit ? adware.description : ''; | |
| const targetOsValue = isEdit ? adware.target_os : ''; | |
| const persistenceMethodValue = isEdit ? adware.persistence_method : ''; | |
| const payloadIdValue = isEdit ? adware.payload_id : ''; | |
| const deploymentMethodIdValue = isEdit ? adware.deployment_method_id : ''; | |
| const configValue = isEdit ? JSON.stringify(adware.config) : ''; | |
| return ` | |
| <h2>${title}</h2> | |
| <form id="adwareForm"> | |
| <label for="name">Name:</label> | |
| <input type="text" id="name" value="${nameValue}" required><br> | |
| <label for="description">Description:</label> | |
| <textarea id="description" required>${descriptionValue}</textarea><br> | |
| <label for="target_os">Target OS:</label> | |
| <input type="text" id="target_os" value="${targetOsValue}" required><br> | |
| <label for="persistence_method">Persistence Method:</label> | |
| <input type="text" id="persistence_method" value="${persistenceMethodValue}" required><br> | |
| <label for="payload_id">Payload:</label> | |
| <select id="payload_id" required> | |
| <option value="">Select Payload</option> | |
| </select><br> | |
| <label for="deployment_method_id">Deployment Method:</label> | |
| <select id="deployment_method_id" required> | |
| <option value="">Select Deployment Method</option> | |
| </select><br> | |
| <label for="config">Config (JSON):</label> | |
| <textarea id="config">${configValue}</textarea><br> | |
| <button type="submit">${submitText}</button> | |
| <button type="button" onclick="fetchAdware()">Cancel</button> | |
| </form> | |
| ${isEdit ? '' : '<button onclick="showAIAdwareForm()">Create with AI</button>'} | |
| `; | |
| }; | |
| appDiv.addEventListener('submit', async (event) => {event.preventDefault()}; | |
| if (event.target.id === 'adwareForm') { } | |
| const form = document.getElementById('adwareForm'); | |
| const formData = {name}: form.name.value, | |
| description: form.description.value, | |
| target_os: form.target_os.value, | |
| persistence_method: form.persistence_method.value, | |
| payload_id: parseInt(form.payload_id.value), | |
| deployment_method_id: parseInt(form.deployment_method_id.value), | |
| config: form.config.value ? JSON.parse(form.config.value) : | |
| }; | |
| try { } | |
| const url = currentAdwareId ? `/adware/${currentAdwareId}` : '/adware'; | |
| const method = currentAdwareId ? 'PUT' : 'POST'; | |
| const response = await fetch(url, {method}: method, | |
| headers: {'Content-Type'}: 'application/json' }, | |
| body: JSON.stringify(formData) | |
| }); | |
| if (!response.ok) { } | |
| throw new Error(`HTTP error! status: ${response.status}`); | |
| } | |
| alert(`Adware ${currentAdwareId ? 'updated' : 'created'} successfully!`); | |
| fetchAdware(); | |
| } catch (error) {showError(`Error ${currentAdwareId ? 'updating' : 'creating'} adware: ${error}`)}; | |
| } | |
| } | |
| if (event.target.id === 'aiAdwareForm') { } | |
| const form = document.getElementById('aiAdwareForm'); | |
| const formData = {goal}: form.ai_goal.value, | |
| constraints: form.ai_constraints.value ? JSON.parse(form.ai_constraints.value) : | |
| }; | |
| try { } | |
| const response = await fetch('/ai/generate', {method}: 'POST', | |
| headers: {'Content-Type'}: 'application/json' }, | |
| body: JSON.stringify(formData) | |
| }); | |
| if (!response.ok) { } | |
| throw new Error(`HTTP error! status: ${response.status}`); | |
| } | |
| const aiConfig = await response.json(); | |
| appDiv.innerHTML = getAdwareForm(aiConfig); | |
| fetchPayloadsAndDeploymentMethods(); | |
| } catch (error) {showError(`Error generating adware config with AI: ${error}`)}; | |
| } | |
| } | |
| if (event.target.id === 'payloadForm') { } | |
| const form = document.getElementById('payloadForm'); | |
| const formData = {name}: form.name.value, | |
| description: form.description.value, | |
| file_path: form.file_path.value | |
| }; | |
| try { } | |
| const url = currentPayloadId ? `/payloads/${currentPayloadId}` : '/payloads'; | |
| const method = currentPayloadId ? 'PUT' : 'POST'; | |
| const response = await fetch(url, {method}: method, | |
| headers: {'Content-Type'}: 'application/json' }, | |
| body: JSON.stringify(formData) | |
| }); | |
| if (!response.ok) { } | |
| throw new Error(`HTTP error! status: ${response.status}`); | |
| } | |
| alert(`Payload ${currentPayloadId ? 'updated' : 'created'} successfully!`); | |
| showPayloadManagement(); | |
| } catch (error) {showError(`Error ${currentPayloadId ? 'updating' : 'creating'} payload: ${error}`)}; | |
| } | |
| } | |
| if (event.target.id === 'deploymentMethodForm') { } | |
| const form = document.getElementById('deploymentMethodForm'); | |
| const formData = {name}: form.name.value, | |
| description: form.description.value, | |
| config_schema: form.config_schema.value ? JSON.parse(form.config_schema.value) : | |
| }; | |
| try { } | |
| const url = currentDeploymentMethodId ? `/deployment_methods/${currentDeploymentMethodId}` : '/deployment_methods'; | |
| const method = currentDeploymentMethodId ? 'PUT' : 'POST'; | |
| const response = await fetch(url, {method}: method, | |
| headers: {'Content-Type'}: 'application/json' }, | |
| body: JSON.stringify(formData) | |
| }); | |
| if (!response.ok) { } | |
| throw new Error(`HTTP error! status: ${response.status}`); | |
| } | |
| alert(`Deployment method ${currentDeploymentMethodId ? 'updated' : 'created'} successfully!`); | |
| showDeploymentMethodManagement(); | |
| } catch (error) {showError(`Error ${currentDeploymentMethodId ? 'updating' : 'creating'} deployment method: ${error}`)}; | |
| } | |
| } | |
| }); | |
| window.showAIAdwareForm = () => {appDiv.innerHTML = getAIAdwareForm()}; | |
| }; | |
| const getAIAdwareForm = () => { } | |
| return ` | |
| <h2>Create Adware with AI</h2> | |
| <form id="aiAdwareForm"> | |
| <label for="ai_goal">Goal:</label> | |
| <input type="text" id="ai_goal" required><br> | |
| <label for="ai_constraints">Constraints (JSON):</label> | |
| <textarea id="ai_constraints"></textarea><br> | |
| <button type="submit">Generate Adware Config</button> | |
| <button type="button" onclick="showCreateAdwareForm()">Cancel</button> | |
| </form> | |
| `; | |
| }; | |
| // --- Payload Management --- | |
| window.showPayloadManagement = async () => {currentPayloadId = null}; | |
| showLoading('Fetching payloads...'); | |
| try { } | |
| const response = await fetch('/payloads'); | |
| if (!response.ok) { } | |
| throw new Error(`HTTP error! status: ${response.status}`); | |
| } | |
| const data = await response.json(); | |
| displayPayloads(data); | |
| } catch (error) {showError(`Error fetching payloads: ${error}`)}; | |
| } | |
| }; | |
| const displayPayloads = (payloadList) => {let} html = '<h2>Payload Management</h2>'; | |
| if (payloadList.length === 0) {html += '<p>No payloads found.</p>'}; | |
| } else {html += '<table><thead><tr><th>Name</th><th>Description</th><th>Actions</th></tr></thead><tbody>'}; | |
| payloadList.forEach(payload => {html += `<tr> | |
| <td>${payload.name}</td> | |
| <td>${payload.description}</td> | |
| <td> | |
| <button onclick="editPayload(${payload.id})">Edit</button> | |
| <button onclick="deletePayload(${payload.id})">Delete</button> | |
| </td> | |
| </tr>`}; | |
| }); | |
| html += '</tbody></table>'; | |
| } | |
| html += '<button onclick="showCreatePayloadForm()">Create New Payload</button>'; | |
| html += '<button onclick="fetchAdware()">Back to Adware</button>'; | |
| appDiv.innerHTML = html; | |
| }; | |
| window.showCreatePayloadForm = () => {currentPayloadId = null}; | |
| appDiv.innerHTML = getPayloadForm(); | |
| }; | |
| window.editPayload = async (payloadId) => {currentPayloadId = payloadId}; | |
| showLoading(`Fetching payload with ID ${payloadId} for edit...`); | |
| try { } | |
| const response = await fetch(`/payloads/${payloadId}`); | |
| if (!response.ok) { } | |
| throw new Error(`HTTP error! status: ${response.status}`); | |
| } | |
| const payload = await response.json(); | |
| appDiv.innerHTML = getPayloadForm(payload); | |
| } catch (error) {showError(`Error fetching payload for edit: ${error}`)}; | |
| } | |
| }; | |
| window.deletePayload = async (payloadId) => { } | |
| if (confirm(`Are you sure you want to delete payload with ID ${payloadId}?`)) {showLoading(`Deleting payload with ID ${payloadId}...`)}; | |
| try { } | |
| const response = await fetch(`/payloads/${payloadId}`, {method}: 'DELETE' }); | |
| if (!response.ok) { } | |
| throw new Error(`HTTP error! status: ${response.status}`); | |
| } | |
| alert(`Payload with ID ${payloadId} deleted successfully!`); | |
| showPayloadManagement(); | |
| } catch (error) {showError(`Error deleting payload: ${error}`)}; | |
| } | |
| } | |
| }; | |
| const getPayloadForm = (payload = null) => { } | |
| const isEdit = payload !== null; | |
| const title = isEdit ? 'Edit Payload' : 'Create New Payload'; | |
| const submitText = isEdit ? 'Update Payload' : 'Create Payload'; | |
| const nameValue = isEdit ? payload.name : ''; | |
| const descriptionValue = isEdit ? payload.description : ''; | |
| const filePathValue = isEdit ? payload.file_path : ''; | |
| return ` | |
| <h2>${title}</h2> | |
| <form id="payloadForm"> | |
| <label for="name">Name:</label> | |
| <input type="text" id="name" value="${nameValue}" required><br> | |
| <label for="descriptiondocument.addEventListener('DOMContentLoaded', () => { | |
| const appDiv = document.getElementById('app'); | |
| let currentAdwareId = null; | |
| let currentPayloadId = null; | |
| let currentDeploymentMethodId = null; | |
| // --- Helper Functions --- | |
| const showLoading = (message = 'Loading...') => { | |
| appDiv.innerHTML = `<p>${message}</p>`; | |
| }; | |
| const showError = (message) => { | |
| appDiv.innerHTML = `<p style=" color:red />;">Error: ${message}</p>`; | |
| }; | |
| // --- Adware Management --- | |
| const fetchAdware = async () => {showLoading('Fetching adware configurations...')}; | |
| try { } | |
| const response = await fetch('/adware'); | |
| if (!response.ok) { } | |
| throw new Error(`HTTP error! status: ${response.status}`); | |
| } | |
| const data = await response.json(); | |
| displayAdware(data); | |
| } catch (error) {showError(`Error fetching adware: ${error}`)}; | |
| } | |
| }; | |
| const displayAdware = (adwareList) => {let} html = '<h2>Adware Configurations</h2>'; | |
| if (adwareList.length === 0) {html += '<p>No adware configurations found.</p>'}; | |
| } else {html += '<table><thead><tr><th>Name</th><th>Description</th><th>Actions</th></tr></thead><tbody>'}; | |
| adwareList.forEach(adware => {html += `<tr> | |
| <td>${adware.name}</td> | |
| <td>${adware.description}</td> | |
| <td> | |
| <button onclick="deployAdware(${adware.id})">Deploy</button> | |
| <button onclick="editAdware(${adware.id})">Edit</button> | |
| <button onclick="deleteAdware(${adware.id})">Delete</button> | |
| </td> | |
| </tr>`}; | |
| }); | |
| html += '</tbody></table>'; | |
| } | |
| html += '<button onclick="showCreateAdwareForm()">Create New Adware</button>'; | |
| html += '<button onclick="showPayloadManagement()">Manage Payloads</button>'; | |
| html += '<button onclick="showDeploymentMethodManagement()">Manage Deployment Methods</button>'; | |
| appDiv.innerHTML = html; | |
| }; | |
| window.deployAdware = async (adwareId) => {showLoading(`Deploying adware with ID ${adwareId}...`)}; | |
| try { } | |
| const response = await fetch(`/adware/${adwareId}/deploy`, {method}: 'POST' }); | |
| if (!response.ok) { } | |
| throw new Error(`HTTP error! status: ${response.status}`); | |
| } | |
| alert(`Adware with ID ${adwareId} deployed successfully!`); | |
| fetchAdware(); | |
| } catch (error) {showError(`Error deploying adware: ${error}`)}; | |
| } | |
| }; | |
| window.showCreateAdwareForm = () => {currentAdwareId = null}; | |
| appDiv.innerHTML = getAdwareForm(); | |
| fetchPayloadsAndDeploymentMethods(); | |
| }; | |
| window.editAdware = async (adwareId) => {currentAdwareId = adwareId}; | |
| showLoading(`Fetching adware with ID ${adwareId} for edit...`); | |
| try { } | |
| const response = await fetch(`/adware/${adwareId}`); | |
| if (!response.ok) { } | |
| throw new Error(`HTTP error! status: ${response.status}`); | |
| } | |
| const adware = await response.json(); | |
| appDiv.innerHTML = getAdwareForm(adware); | |
| fetchPayloadsAndDeploymentMethods(); | |
| } catch (error) {showError(`Error fetching adware for edit: ${error}`)}; | |
| } | |
| }; | |
| window.deleteAdware = async (adwareId) => { } | |
| if (confirm(`Are you sure you want to delete adware with ID ${adwareId}?`)) {showLoading(`Deleting adware with ID ${adwareId}...`)}; | |
| try { } | |
| const response = await fetch(`/adware/${adwareId}`, {method}: 'DELETE' }); | |
| if (!response.ok) { } | |
| throw new Error(`HTTP error! status: ${response.status}`); | |
| } | |
| alert(`Adware with ID ${adwareId} deleted successfully!`); | |
| fetchAdware(); | |
| } catch (error) {showError(`Error deleting adware: ${error}`)}; | |
| } | |
| } | |
| }; | |
| const fetchPayloadsAndDeploymentMethods = async () => { } | |
| try { } | |
| const [payloadResponse, deploymentResponse] = await Promise.all([ | |
| fetch('/payloads'), | |
| fetch('/deployment_methods') | |
| ]); | |
| if (!payloadResponse.ok || !deploymentResponse.ok) { } | |
| throw new Error('Error fetching payloads or deployment methods'); | |
| } | |
| const payloads = await payloadResponse.json(); | |
| const deploymentMethods = await deploymentResponse.json(); | |
| populateDropdowns(payloads, deploymentMethods); | |
| } catch (error) {showError(`Error fetching payloads or deployment methods: ${error}`)}; | |
| } | |
| }; | |
| const populateDropdowns = (payloads, deploymentMethods) => { } | |
| const payloadSelect = document.getElementById('payload_id'); | |
| const deploymentSelect = document.getElementById('deployment_method_id'); | |
| payloadSelect.innerHTML = '<option value="">Select Payload</option>'; | |
| deploymentSelect.innerHTML = '<option value="">Select Deployment Method</option>'; | |
| payloads.forEach(payload => { } | |
| const option = document.createElement('option'); | |
| option.value = payload.id; | |
| option.textContent = payload.name; | |
| payloadSelect.appendChild(option); | |
| }); | |
| deploymentMethods.forEach(method => { } | |
| const option = document.createElement('option'); | |
| option.value = method.id; | |
| option.textContent = method.name; | |
| deploymentSelect.appendChild(option); | |
| }); | |
| }; | |
| const getAdwareForm = (adware = null) => { } | |
| const isEdit = adware !== null; | |
| const title = isEdit ? 'Edit Adware' : 'Create New Adware'; | |
| const submitText = isEdit ? 'Update Adware' : 'Create Adware'; | |
| const nameValue = isEdit ? adware.name : ''; | |
| const descriptionValue = isEdit ? adware.description : ''; | |
| const targetOsValue = isEdit ? adware.target_os : ''; | |
| const persistenceMethodValue = isEdit ? adware.persistence_method : ''; | |
| const payloadIdValue = isEdit ? adware.payload_id : ''; | |
| const deploymentMethodIdValue = isEdit ? adware.deployment_method_id : ''; | |
| const configValue = isEdit ? JSON.stringify(adware.config) : ''; | |
| return ` | |
| <h2>${title}</h2> | |
| <form id="adwareForm"> | |
| <label for="name">Name:</label> | |
| <input type="text" id="name" value="${nameValue}" required><br> | |
| <label for="description">Description:</label> | |
| <textarea id="description" required>${descriptionValue}</textarea><br> | |
| <label for="target_os">Target OS:</label> | |
| <input type="text" id="target_os" value="${targetOsValue}" required><br> | |
| <label for="persistence_method">Persistence Method:</label> | |
| <input type="text" id="persistence_method" value="${persistenceMethodValue}" required><br> | |
| <label for="payload_id">Payload:</label> | |
| <select id="payload_id" required> | |
| <option value="">Select Payload</option> | |
| </select><br> | |
| <label for="deployment_method_id">Deployment Method:</label> | |
| <select id="deployment_method_id" required> | |
| <option value="">Select Deployment Method</option> | |
| </select><br> | |
| <label for="config">Config (JSON):</label> | |
| <textarea id="config">${configValue}</textarea><br> | |
| <button type="submit">${submitText}</button> | |
| <button type="button" onclick="fetchAdware()">Cancel</button> | |
| </form> | |
| ${isEdit ? '' : '<button onclick="showAIAdwareForm()">Create with AI</button>'} | |
| `; | |
| }; | |
| appDiv.addEventListener('submit', async (event) => {event.preventDefault()}; | |
| if (event.target.id === 'adwareForm') { } | |
| const form = document.getElementById('adwareForm'); | |
| const formData = {name}: form.name.value, | |
| description: form.description.value, | |
| target_os: form.target_os.value, | |
| persistence_method: form.persistence_method.value, | |
| payload_id: parseInt(form.payload_id.value), | |
| deployment_method_id: parseInt(form.deployment_method_id.value), | |
| config: form.config.value ? JSON.parse(form.config.value) : | |
| }; | |
| try { } | |
| const url = currentAdwareId ? `/adware/${currentAdwareId}` : '/adware'; | |
| const method = currentAdwareId ? 'PUT' : 'POST'; | |
| const response = await fetch(url, {method}: method, | |
| headers: {'Content-Type'}: 'application/json' }, | |
| body: JSON.stringify(formData) | |
| }); | |
| if (!response.ok) { } | |
| throw new Error(`HTTP error! status: ${response.status}`); | |
| } | |
| alert(`Adware ${currentAdwareId ? 'updated' : 'created'} successfully!`); | |
| fetchAdware(); | |
| } catch (error) {showError(`Error ${currentAdwareId ? 'updating' : 'creating'} adware: ${error}`)}; | |
| } | |
| } | |
| if (event.target.id === 'aiAdwareForm') { } | |
| const form = document.getElementById('aiAdwareForm'); | |
| const formData = {goal}: form.ai_goal.value, | |
| constraints: form.ai_constraints.value ? JSON.parse(form.ai_constraints.value) : | |
| }; | |
| try { } | |
| const response = await fetch('/ai/generate', {method}: 'POST', | |
| headers: {'Content-Type'}: 'application/json' }, | |
| body: JSON.stringify(formData) | |
| }); | |
| if (!response.ok) { } | |
| throw new Error(`HTTP error! status: ${response.status}`); | |
| } | |
| const aiConfig = await response.json(); | |
| appDiv.innerHTML = getAdwareForm(aiConfig); | |
| fetchPayloadsAndDeploymentMethods(); | |
| } catch (error) {showError(`Error generating adware config with AI: ${error}`)}; | |
| } | |
| } | |
| if (event.target.id === 'payloadForm') { } | |
| const form = document.getElementById('payloadForm'); | |
| const formData = {name}: form.name.value, | |
| description: form.description.value, | |
| file_path: form.file_path.value | |
| }; | |
| try { } | |
| const url = currentPayloadId ? `/payloads/${currentPayloadId}` : '/payloads'; | |
| const method = currentPayloadId ? 'PUT' : 'POST'; | |
| const response = await fetch(url, {method}: method, | |
| headers: {'Content-Type'}: 'application/json' }, | |
| body: JSON.stringify(formData) | |
| }); | |
| if (!response.ok) { } | |
| throw new Error(`HTTP error! status: ${response.status}`); | |
| } | |
| alert(`Payload ${currentPayloadId ? 'updated' : 'created'} successfully!`); | |
| showPayloadManagement(); | |
| } catch (error) {showError(`Error ${currentPayloadId ? 'updating' : 'creating'} payload: ${error}`)}; | |
| } | |
| } | |
| if (event.target.id === 'deploymentMethodForm') { } | |
| const form = document.getElementById('deploymentMethodForm'); | |
| const formData = {name}: form.name.value, | |
| description: form.description.value, | |
| config_schema: form.config_schema.value ? JSON.parse(form.config_schema.value) : | |
| }; | |
| try { } | |
| const url = currentDeploymentMethodId ? `/deployment_methods/${currentDeploymentMethodId}` : '/deployment_methods'; | |
| const method = currentDeploymentMethodId ? 'PUT' : 'POST'; | |
| const response = await fetch(url, {method}: method, | |
| headers: {'Content-Type'}: 'application/json' }, | |
| body: JSON.stringify(formData) | |
| }); | |
| if (!response.ok) { } | |
| throw new Error(`HTTP error! status: ${response.status}`); | |
| } | |
| alert(`Deployment method ${currentDeploymentMethodId ? 'updated' : 'created'} successfully!`); | |
| showDeploymentMethodManagement(); | |
| } catch (error) {showError(`Error ${currentDeploymentMethodId ? 'updating' : 'creating'} deployment method: ${error}`)}; | |
| } | |
| } | |
| }); | |
| window.showAIAdwareForm = () => {appDiv.innerHTML = getAIAdwareForm()}; | |
| }; | |
| const getAIAdwareForm = () => { } | |
| return ` | |
| <h2>Create Adware with AI</h2> | |
| <form id="aiAdwareForm"> | |
| <label for="ai_goal">Goal:</label> | |
| <input type="text" id="ai_goal" required><br> | |
| <label for="ai_constraints">Constraints (JSON):</label> | |
| <textarea id="ai_constraints"></textarea><br> | |
| <button type="submit">Generate Adware Config</button> | |
| <button type="button" onclick="showCreateAdwareForm()">Cancel</button> | |
| </form> | |
| `; | |
| }; | |
| // --- Payload Management --- | |
| window.showPayloadManagement = async () => {currentPayloadId = null}; | |
| showLoading('Fetching payloads...'); | |
| try { } | |
| const response = await fetch('/payloads'); | |
| if (!response.ok) { } | |
| throw new Error(`HTTP error! status: ${response.status}`); | |
| } | |
| const data = await response.json(); | |
| displayPayloads(data); | |
| } catch (error) {showError(`Error fetching payloads: ${error}`)}; | |
| } | |
| }; | |
| const displayPayloads = (payloadList) => {let} html = '<h2>Payload Management</h2>'; | |
| if (payloadList.length === 0) {html += '<p>No payloads found.</p>'}; | |
| } else {html += '<table><thead><tr><th>Name</th><th>Description</th><th>Actions</th></tr></thead><tbody>'}; | |
| payloadList.forEach(payload => {html += `<tr> | |
| <td>${payload.name}</td> | |
| <td>${payload.description}</td> | |
| <td> | |
| <button onclick="editPayload(${payload.id})">Edit</button> | |
| <button onclick="deletePayload(${payload.id})">Delete</button> | |
| </td> | |
| </tr>`}; | |
| }); | |
| html += '</tbody></table>'; | |
| } | |
| html += '<button onclick="showCreatePayloadForm()">Create New Payload</button>'; | |
| html += '<button onclick="fetchAdware()">Back to Adware</button>'; | |
| appDiv.innerHTML = html; | |
| }; | |
| window.showCreatePayloadForm = () => {currentPayloadId = null}; | |
| appDiv.innerHTML = getPayloadForm(); | |
| }; | |
| window.editPayload = async (payloadId) => {currentPayloadId = payloadId}; | |
| showLoading(`Fetching payload with ID ${payloadId} for edit...`); | |
| try { } | |
| const response = await fetch(`/payloads/${payloadId}`); | |
| if (!response.ok) { } | |
| throw new Error(`HTTP error! status: ${response.status}`); | |
| } | |
| const payload = await response.json(); | |
| appDiv.innerHTML = getPayloadForm(payload); | |
| } catch (error) {showError(`Error fetching payload for edit: ${error}`)}; | |
| } | |
| }; | |
| window.deletePayload = async (payloadId) => { } | |
| if (confirm(`Are you sure you want to delete payload with ID ${payloadId}?`)) {showLoading(`Deleting payload with ID ${payloadId}...`)}; | |
| try { } | |
| const response = await fetch(`/payloads/${payloadId}`, {method}: 'DELETE' }); | |
| if (!response.ok) { } | |
| throw new Error(`HTTP error! status: ${response.status}`); | |
| } | |
| alert(`Payload with ID ${payloadId} deleted successfully!`); | |
| showPayloadManagement(); | |
| } catch (error) {showError(`Error deleting payload: ${error}`)}; | |
| } | |
| } | |
| }; | |
| const getPayloadForm = (payload = null) => { } | |
| const isEdit = payload !== null; | |
| const title = isEdit ? 'Edit Payload' : 'Create New Payload'; | |
| const submitText = isEdit ? 'Update Payload' : 'Create Payload'; | |
| const nameValue = isEdit ? payload.name : ''; | |
| const descriptionValue = isEdit ? payload.description : ''; | |
| const filePathValue = isEdit ? payload.file_path : ''; | |
| return ` | |
| <h2>${title}</h2> | |
| <form id="payloadForm"> | |
| document.addEventListener('DOMContentLoaded', () => { } | |
| const appDiv = document.getElementById('app'); | |
| let currentAdwareId = null; | |
| let currentPayloadId = null; | |
| let currentDeploymentMethodId = null; | |
| // --- Helper Functions --- | |
| const showLoading = (message = 'Loading...') => {appDiv.innerHTML = `<p>${message}</p>`}; | |
| }; | |
| const showError = (message) => {appDiv.innerHTML = `<p style="color:red;">Error: ${message}</p>`}; | |
| }; | |
| // --- Adware Management --- | |
| const fetchAdware = async () => {showLoading('Fetching adware configurations...')}; | |
| try { } | |
| const response = await fetch('/adware'); | |
| if (!response.ok) { } | |
| throw new Error(`HTTP error! status: ${response.status}`); | |
| } | |
| const data = await response.json(); | |
| displayAdware(data); | |
| } catch (error) {showError(`Error fetching adware: ${error}`)}; | |
| } | |
| }; | |
| const displayAdware = (adwareList) => {let} html = '<h2>Adware Configurations</h2>'; | |
| if (adwareList.length === 0) {html += '<p>No adware configurations found.</p>'}; | |
| } else {html += '<table><thead><tr><th>Name</th><th>Description</th><th>Actions</th></tr></thead><tbody>'}; | |
| adwareList.forEach(adware => {html += `<tr> | |
| <td>${adware.name}</td> | |
| <td>${adware.description}</td> | |
| <td> | |
| <button onclick="deployAdware(${adware.id})">Deploy</button> | |
| <button onclick="editAdware(${adware.id})">Edit</button> | |
| <button onclick="deleteAdware(${adware.id})">Delete</button> | |
| </td> | |
| </tr>`}; | |
| }); | |
| html += '</tbody></table>'; | |
| } | |
| html += '<button onclick="showCreateAdwareForm()">Create New Adware</button>'; | |
| html += '<button onclick="showPayloadManagement()">Manage Payloads</button>'; | |
| html += '<button onclick="showDeploymentMethodManagement()">Manage Deployment Methods</button>'; | |
| appDiv.innerHTML = html; | |
| }; | |
| window.deployAdware = async (adwareId) => {showLoading(`Deploying adware with ID ${adwareId}...`)}; | |
| try { } | |
| const response = await fetch(`/adware/${adwareId}/deploy`, {method}: 'POST' }); | |
| if (!response.ok) { } | |
| throw new Error(`HTTP error! status: ${response.status}`); | |
| } | |
| alert(`Adware with ID ${adwareId} deployed successfully!`); | |
| fetchAdware(); | |
| } catch (error) {showError(`Error deploying adware: ${error}`)}; | |
| } | |
| }; | |
| window.showCreateAdwareForm = () => {currentAdwareId = null}; | |
| appDiv.innerHTML = getAdwareForm(); | |
| fetchPayloadsAndDeploymentMethods(); | |
| }; | |
| window.editAdware = async (adwareId) => {currentAdwareId = adwareId}; | |
| showLoading(`Fetching adware with ID ${adwareId} for edit...`); | |
| try { } | |
| const response = await fetch(`/adware/${adwareId}`); | |
| if (!response.ok) { } | |
| throw new Error(`HTTP error! status: ${response.status}`); | |
| } | |
| const adware = await response.json(); | |
| appDiv.innerHTML = getAdwareForm(adware); | |
| fetchPayloadsAndDeploymentMethods(); | |
| } catch (error) {showError(`Error fetching adware for edit: ${error}`)}; | |
| } | |
| }; | |
| window.deleteAdware = async (adwareId) => { } | |
| if (confirm(`Are you sure you want to delete adware with ID ${adwareId}?`)) {showLoading(`Deleting adware with ID ${adwareId}...`)}; | |
| try { } | |
| const response = await fetch(`/adware/${adwareId}`, {method}: 'DELETE' }); | |
| if (!response.ok) { } | |
| throw new Error(`HTTP error! status: ${response.status}`); | |
| } | |
| alert(`Adware with ID ${adwareId} deleted successfully!`); | |
| fetchAdware(); | |
| } catch (error) {showError(`Error deleting adware: ${error}`)}; | |
| } | |
| } | |
| }; | |
| const fetchPayloadsAndDeploymentMethods = async () => { } | |
| try { } | |
| const [payloadResponse, deploymentResponse] = await Promise.all([ | |
| fetch('/payloads'), | |
| fetch('/deployment_methods') | |
| ]); | |
| if (!payloadResponse.ok || !deploymentResponse.ok) { } | |
| throw new Error('Error fetching payloads or deployment methods'); | |
| } | |
| const payloads = await payloadResponse.json(); | |
| const deploymentMethods = await deploymentResponse.json(); | |
| populateDropdowns(payloads, deploymentMethods); | |
| } catch (error) {showError(`Error fetching payloads or deployment methods: ${error}`)}; | |
| } | |
| }; | |
| const populateDropdowns = (payloads, deploymentMethods) => { } | |
| const payloadSelect = document.getElementById('payload_id'); | |
| const deploymentSelect = document.getElementById('deployment_method_id'); | |
| payloadSelect.innerHTML = '<option value="">Select Payload</option>'; | |
| deploymentSelect.innerHTML = '<option value="">Select Deployment Method</option>'; | |
| payloads.forEach(payload => { } | |
| const option = document.createElement('option'); | |
| option.value = payload.id; | |
| option.textContent = payload.name; | |
| payloadSelect.appendChild(option); | |
| }); | |
| deploymentMethods.forEach(method => { } | |
| const option = document.createElement('option'); | |
| option.value = method.id; | |
| option.textContent = method.name; | |
| deploymentSelect.appendChild(option); | |
| }); | |
| }; | |
| const getAdwareForm = (adware = null) => { } | |
| const isEdit = adware !== null; | |
| const title = isEdit ? 'Edit Adware' : 'Create New Adware'; | |
| const submitText = isEdit ? 'Update Adware' : 'Create Adware'; | |
| const nameValue = isEdit ? adware.name : ''; | |
| const descriptionValue = isEdit ? adware.description : ''; | |
| const targetOsValue = isEdit ? adware.target_os : ''; | |
| const persistenceMethodValue = isEdit ? adware.persistence_method : ''; | |
| const payloadIdValue = isEdit ? adware.payload_id : ''; | |
| const deploymentMethodIdValue = isEdit ? adware.deployment_method_id : ''; | |
| const configValue = isEdit ? JSON.stringify(adware.config) : ''; | |
| return ` | |
| <h2>${title}</h2> | |
| <form id="adwareForm"> | |
| <label for="name">Name:</label> | |
| <input type="text" id="name" value="${nameValue}" required><br> | |
| <label for="description">Description:</label> | |
| <textarea id="description" required>${descriptionValue}</textarea><br> | |
| <label for="target_os">Target OS:</label> | |
| <input type="text" id="target_os" value="${targetOsValue}" required><br> | |
| <label for="persistence_method">Persistence Method:</label> | |
| <input type="text" id="persistence_method" value="${persistenceMethodValue}" required><br> | |
| <label for="payload_id">Payload:</label> | |
| <select id="payload_id" required> | |
| <option value="">Select Payload</option> | |
| </select><br> | |
| <label for="deployment_method_id">Deployment Method:</label> | |
| <select id="deployment_method_id" required> | |
| <option value="">Select Deployment Method</option> | |
| </select><br> | |
| <label for="config">Config (JSON):</label> | |
| <textarea id="config">${configValue}</textarea><br> | |
| <button type="submit">${submitText}</button> | |
| <button type="button" onclick="fetchAdware()">Cancel</button> | |
| </form> | |
| ${isEdit ? '' : '<button onclick="showAIAdwareForm()">Create with AI</button>'} | |
| `; | |
| }; | |
| appDiv.addEventListener('submit', async (event) => {event.preventDefault()}; | |
| if (event.target.id === 'adwareForm') { } | |
| const form = document.getElementById('adwareForm'); | |
| const formData = {name}: form.name.value, | |
| description: form.description.value, | |
| target_os: form.target_os.value, | |
| persistence_method: form.persistence_method.value, | |
| payload_id: parseInt(form.payload_id.value), | |
| deployment_method_id: parseInt(form.deployment_method_id.value), | |
| config: form.config.value ? JSON.parse(form.config.value) : | |
| }; | |
| try { } | |
| const url = currentAdwareId ? `/adware/${currentAdwareId}` : '/adware'; | |
| const method = currentAdwareId ? 'PUT' : 'POST'; | |
| const response = await fetch(url, {method}: method, | |
| headers: {'Content-Type'}: 'application/json' }, | |
| body: JSON.stringify(formData) | |
| }); | |
| if (!response.ok) { } | |
| throw new Error(`HTTP error! status: ${response.status}`); | |
| } | |
| alert(`Adware ${currentAdwareId ? 'updated' : 'created'} successfully!`); | |
| fetchAdware(); | |
| } catch (error) {showError(`Error ${currentAdwareId ? 'updating' : 'creating'} adware: ${error}`)}; | |
| } | |
| } | |
| if (event.target.id === 'aiAdwareForm') { } | |
| const form = document.getElementById('aiAdwareForm'); | |
| const formData = {goal}: form.ai_goal.value, | |
| constraints: form.ai_constraints.value ? JSON.parse(form.ai_constraints.value) : | |
| }; | |
| try { } | |
| const response = await fetch('/ai/generate', {method}: 'POST', | |
| headers: {'Content-Type'}: 'application/json' }, | |
| body: JSON.stringify(formData) | |
| }); | |
| if (!response.ok) { } | |
| throw new Error(`HTTP error! status: ${response.status}`); | |
| } | |
| const aiConfig = await response.json(); | |
| appDiv.innerHTML = getAdwareForm(aiConfig); | |
| fetchPayloadsAndDeploymentMethods(); | |
| } catch (error) {showError(`Error generating adware config with AI: ${error}`)}; | |
| } | |
| } | |
| if (event.target.id === 'payloadForm') { } | |
| const form = document.getElementById('payloadForm'); | |
| const formData = {name}: form.name.value, | |
| description: form.description.value, | |
| file_path: form.file_path.value | |
| }; | |
| try { } | |
| const url = currentPayloadId ? `/payloads/${currentPayloadId}` : '/payloads'; | |
| const method = currentPayloadId ? 'PUT' : 'POST'; | |
| const response = await fetch(url, {method}: method, | |
| headers: {'Content-Type'}: 'application/json' }, | |
| body: JSON.stringify(formData) | |
| }); | |
| if (!response.ok) { } | |
| throw new Error(`HTTP error! status: ${response.status}`); | |
| } | |
| alert(`Payload ${currentPayloadId ? 'updated' : 'created'} successfully!`); | |
| showPayloadManagement(); | |
| } catch (error) {showError(`Error ${currentPayloadId ? 'updating' : 'creating'} payload: ${error}`)}; | |
| } | |
| } | |
| if (event.target.id === 'deploymentMethodForm') { } | |
| const form = document.getElementById('deploymentMethodForm'); | |
| const formData = {name}: form.name.value, | |
| description: form.description.value, | |
| config_schema: form.config_schema.value ? JSON.parse(form.config_schema.value) : | |
| }; | |
| try { } | |
| const url = currentDeploymentMethodId ? `/deployment_methods/${currentDeploymentMethodId}` : '/deployment_methods'; | |
| const method = currentDeploymentMethodId ? 'PUT' : 'POST'; | |
| const response = await fetch(url, {method}: method, | |
| headers: {'Content-Type'}: 'application/json' }, | |
| body: JSON.stringify(formData) | |
| }); | |
| if (!response.ok) { } | |
| throw new Error(`HTTP error! status: ${response.status}`); | |
| } | |
| alert(`Deployment method ${currentDeploymentMethodId ? 'updated' : 'created'} successfully!`); | |
| showDeploymentMethodManagement(); | |
| } catch (error) {showError(`Error ${currentDeploymentMethodId ? 'updating' : 'creating'} deployment method: ${error}`)}; | |
| } | |
| } | |
| }); | |
| window.showAIAdwareForm = () => {appDiv.innerHTML = getAIAdwareForm()}; | |
| }; | |
| const getAIAdwareForm = () => { } | |
| return ` | |
| <h2>Create Adware with AI</h2> | |
| <form id="aiAdwareForm"> | |
| <label for="ai_goal">Goal:</label> | |
| <input type="text" id="ai_goal" required><br> | |
| <label for="ai_constraints">Constraints (JSON):</label> | |
| <textarea id="ai_constraints"></textarea><br> | |
| <button type="submit">Generate Adware Config</button> | |
| <button type="button" onclick="showCreateAdwareForm()">Cancel</button> | |
| </form> | |
| `; | |
| }; | |
| // --- Payload Management --- | |
| window.showPayloadManagement = async () => {currentPayloadId = null}; | |
| showLoading('Fetching payloads...'); | |
| try { } | |
| const response = await fetch('/payloads'); | |
| if (!response.ok) { } | |
| throw new Error(`HTTP error! status: ${response.status}`); | |
| } | |
| const data = await response.json(); | |
| displayPayloads(data); | |
| } catch (error) {showError(`Error fetching payloads: ${error}`)}; | |
| } | |
| }; | |
| const displayPayloads = (payloadList) => {let} html = '<h2>Payload Management</h2>'; | |
| if (payloadList.length === 0) {html += '<p>No payloads found.</p>'}; | |
| } else {html += '<table><thead><tr><th>Name</th><th>Description</th><th>Actions</th></tr></thead><tbody>'}; | |
| payloadList.forEach(payload => {html += `<tr> | |
| <td>${payload.name}</td> | |
| <td>${payload.description}</td> | |
| <td> | |
| <button onclick="editPayload(${payload.id})">Edit</button> | |
| <button onclick="deletePayload(${payload.id})">Delete</button> | |
| </td> | |
| </tr>`}; | |
| }); | |
| html += '</tbody></table>'; | |
| } | |
| html += '<button onclick="showCreatePayloadForm()">Create New Payload</button>'; | |
| html += '<button onclick="fetchAdware()">Back to Adware</button>'; | |
| appDiv.innerHTML = html; | |
| }; | |
| window.showCreatePayloadForm = () => {currentPayloadId = null}; | |
| appDiv.innerHTML = getPayloadForm(); | |
| }; | |
| window.editPayload = async (payloadId) => {currentPayloadId = payloadId}; | |
| showLoading(`Fetching payload with ID ${payloadId} for edit...`); | |
| try { } | |
| const response = await fetch(`/payloads/${payloadId}`); | |
| if (!response.ok) { } | |
| throw new Error(`HTTP error! status: ${response.status}`); | |
| } | |
| const payload = await response.json(); | |
| appDiv.innerHTML = getPayloadForm(payload); | |
| } catch (error) {showError(`Error fetching payload for edit: ${error}`)}; | |
| } | |
| }; | |
| window.deletePayload = async (payloadId) => { } | |
| if (confirm(`Are you sure you want to delete payload with ID ${payloadId}?`)) {showLoading(`Deleting payload with ID ${payloadId}...`)}; | |
| try { } | |
| const response = await fetch(`/payloads/${payloadId}`, {method}: 'DELETE' }); | |
| if (!response.ok) { } | |
| throw new Error(`HTTP error! status: ${response.status}`); | |
| } | |
| alert(`Payload with ID ${payloadId} deleted successfully!`); | |
| showPayloadManagement(); | |
| } catch (error) {showError(`Error deleting payload: ${error}`)}; | |
| } | |
| } | |
| }; | |
| const getPayloadForm = (payload = null) => { } | |
| const isEdit = payload !== null; | |
| const title = isEdit ? 'Edit Payload' : 'Create New Payload'; | |
| const submitText = isEdit ? 'Update Payload' : 'Create Payload'; | |
| const nameValue = isEdit ? payload.name : ''; | |
| const descriptionValue = isEdit ? payload.description : ''; | |
| const filePathValue = isEdit ? payload.file_path : ''; | |
| return ` | |
| <h2>${title}</h2> | |
| <form id="payloadForm"> | |
| <label for="name">Name:</label> | |
| <input type="text" id="name" value="${nameValue}" required><br> | |
| <label for="description






 
 " /></></></></></></></></></></></></></></></></></></></></></></></></></></></></></></></></></></></></></></></></></></></></></></></></></></></></></></></></></></></></></></></></></></></></></></></></></></></></>; | |