413 lines
22 KiB
HTML
413 lines
22 KiB
HTML
<!-- <!DOCTYPE html> -->
|
|
<!-- <html lang="en"> -->
|
|
<!-- <head> -->
|
|
<!-- <meta charset="UTF-8"> -->
|
|
<!-- <meta http-equiv="X-UA-Compatible" content="IE=edge"> -->
|
|
<!-- <meta name="viewport" content="width=device-width, initial-scale=1.0"> -->
|
|
<!-- <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous"> -->
|
|
<!-- <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script> -->
|
|
<!-- <script src="https://unpkg.com/htmx.org@1.9.12"></script> -->
|
|
<!-- <title>g2: gommand & gontrol</title> -->
|
|
<!-- <script> -->
|
|
<!-- document.addEventListener('DOMContentLoaded', () => { -->
|
|
<!-- // Fetch agent names to populate the dropdown -->
|
|
<!-- fetch('/agentNames') -->
|
|
<!-- .then(response => response.json()) -->
|
|
<!-- .then(agentNames => { -->
|
|
<!-- const dropdown = document.getElementById('agentName'); -->
|
|
<!-- agentNames.forEach(name => { -->
|
|
<!-- const option = document.createElement('option'); -->
|
|
<!-- option.value = name; -->
|
|
<!-- option.textContent = name; -->
|
|
<!-- dropdown.appendChild(option); -->
|
|
<!-- }); -->
|
|
<!-- }) -->
|
|
<!-- .catch(error => console.error('Error fetching agent names:', error)); -->
|
|
|
|
<!-- // WebSocket setup -->
|
|
<!-- const socket = new WebSocket("ws://localhost:5555/data"); -->
|
|
|
|
<!-- // Handle WebSocket messages -->
|
|
<!-- socket.onmessage = (event) => { -->
|
|
<!-- const message = JSON.parse(event.data); -->
|
|
<!-- if (message.type === 'response') { -->
|
|
<!-- const output = document.getElementById('commandOutput'); -->
|
|
<!-- output.textContent = message.payload; // Display the agent's response -->
|
|
<!-- } -->
|
|
<!-- }; -->
|
|
|
|
<!-- // Handle WebSocket errors -->
|
|
<!-- socket.onerror = (error) => { -->
|
|
<!-- console.error("WebSocket error:", error); -->
|
|
<!-- }; -->
|
|
|
|
<!-- // Handle WebSocket closure -->
|
|
<!-- socket.onclose = () => { -->
|
|
<!-- console.warn('WebSocket connection closed.'); -->
|
|
<!-- }; -->
|
|
|
|
<!-- // Intercept HTMX requests for /executeCommand -->
|
|
<!-- document.body.addEventListener('htmx:beforeRequest', (evt) => { -->
|
|
<!-- const url = evt.detail.pathInfo.requestPath; -->
|
|
<!-- if (url === '/executeCommand') { -->
|
|
<!-- evt.preventDefault(); // Stop HTMX from processing the request -->
|
|
|
|
<!-- // Collect form data -->
|
|
<!-- const formData = new FormData(evt.detail.elt); -->
|
|
<!-- const payload = new URLSearchParams(formData); // Convert form data to query string -->
|
|
|
|
<!-- // Send form data using fetch -->
|
|
<!-- fetch('http://localhost:5555/executeCommand', { -->
|
|
<!-- method: 'POST', -->
|
|
<!-- headers: { -->
|
|
<!-- 'Content-Type': 'application/x-www-form-urlencoded', -->
|
|
<!-- }, -->
|
|
<!-- body: payload, -->
|
|
<!-- }).then((response) => { -->
|
|
<!-- if (!response.ok) { -->
|
|
<!-- console.error('Failed to execute command:', response.statusText); -->
|
|
<!-- } -->
|
|
<!-- console.log(response) -->
|
|
<!-- }); -->
|
|
<!-- } -->
|
|
<!-- }); -->
|
|
<!-- }); -->
|
|
<!-- </script> -->
|
|
<!-- </head> -->
|
|
<!-- <body> -->
|
|
<!-- <div class="container"> -->
|
|
<!-- <div class="row"> -->
|
|
<!-- <div class="col"> -->
|
|
<!-- <h2>Agents</h2> -->
|
|
|
|
<!-- <!-1- Agent List -1-> -->
|
|
<!-- <div id="agentList" hx-get="/agents" hx-trigger="load" hx-swap="innerHTML"></div> -->
|
|
|
|
<!-- <!-1- Command Execution -1-> -->
|
|
<!-- <div id="agentCommands"> -->
|
|
<!-- <h3>Command Execution</h3> -->
|
|
<!-- <form hx-post="/executeCommand" hx-target="#commandOutput" hx-encoding="application/x-www-form-urlencoded" hx-swap="innerHTML"> -->
|
|
<!-- <div class="mb-3"> -->
|
|
<!-- <label for="agentName" class="form-label">Agent Name</label> -->
|
|
<!-- <select class="form-select" id="agentName" name="agentName" required> -->
|
|
<!-- <!-1- Dynamically populated with agent names -1-> -->
|
|
<!-- </select> -->
|
|
<!-- </div> -->
|
|
<!-- <div class="mb-3"> -->
|
|
<!-- <label for="command" class="form-label">Command</label> -->
|
|
<!-- <input type="text" class="form-control" id="command" name="command" placeholder="Enter command" required> -->
|
|
<!-- </div> -->
|
|
<!-- <button type="submit" class="btn btn-primary">Execute</button> -->
|
|
<!-- </form> -->
|
|
<!-- <div id="commandOutput" class="mt-3 p-2 border">Here goes the output...</div> -->
|
|
<!-- </div> -->
|
|
|
|
<!-- <!-1- Add Agent Form -1-> -->
|
|
<!-- <button class="btn btn-primary mt-3" data-bs-toggle="collapse" data-bs-target="#addAgentForm">Add Agent</button> -->
|
|
<!-- <div id="addAgentForm" class="collapse mt-2"> -->
|
|
<!-- <form hx-post="/agents" hx-target="#agentList" hx-swap="innerHTML"> -->
|
|
<!-- <div class="mb-3"> -->
|
|
<!-- <label for="agentId" class="form-label">Agent Id</label> -->
|
|
<!-- <input type="text" class="form-control" id="agentId" name="agentId" required> -->
|
|
<!-- </div> -->
|
|
<!-- <div class="mb-3"> -->
|
|
<!-- <label for="agentName" class="form-label">Agent Name</label> -->
|
|
<!-- <input type="text" class="form-control" id="agentNameInput" name="agentName" required> -->
|
|
<!-- </div> -->
|
|
<!-- <div class="mb-3"> -->
|
|
<!-- <label for="IPv4Address" class="form-label">IPv4 Address</label> -->
|
|
<!-- <input type="text" class="form-control" id="IPv4Address" name="IPv4Address" required> -->
|
|
<!-- </div> -->
|
|
<!-- <div class="mb-3"> -->
|
|
<!-- <label for="initialContact" class="form-label">Initial Contact</label> -->
|
|
<!-- <input type="datetime-local" class="form-control" id="initialContact" name="initialContact" required> -->
|
|
<!-- </div> -->
|
|
<!-- <div class="mb-3"> -->
|
|
<!-- <label for="lastContact" class="form-label">Last Contact</label> -->
|
|
<!-- <input type="datetime-local" class="form-control" id="lastContact" name="lastContact" required> -->
|
|
<!-- </div> -->
|
|
<!-- <button type="submit" class="btn btn-success">Add Agent</button> -->
|
|
<!-- </form> -->
|
|
<!-- </div> -->
|
|
<!-- </div> -->
|
|
|
|
<!-- <!-1- Agent Details -1-> -->
|
|
<!-- <div class="col" id="agentDetails"> -->
|
|
<!-- <h3>Details</h3> -->
|
|
<!-- <p>Select an agent to view details.</p> -->
|
|
<!-- </div> -->
|
|
<!-- </div> -->
|
|
<!-- </div> -->
|
|
<!-- </body> -->
|
|
<!-- </html> -->
|
|
|
|
<!-- <!DOCTYPE html> -->
|
|
<!-- <html lang="en"> -->
|
|
<!-- <head> -->
|
|
<!-- <meta charset="UTF-8"> -->
|
|
<!-- <meta http-equiv="X-UA-Compatible" content="IE=edge"> -->
|
|
<!-- <meta name="viewport" content="width=device-width, initial-scale=1.0"> -->
|
|
<!-- <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous"> -->
|
|
<!-- <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script> -->
|
|
<!-- <script src="https://unpkg.com/htmx.org@1.9.12"></script> -->
|
|
<!-- <title>g2: gommand & gontrol</title> -->
|
|
<!-- <script> -->
|
|
<!-- document.addEventListener('DOMContentLoaded', () => { -->
|
|
<!-- // Fetch agent names to populate the dropdown -->
|
|
<!-- fetch('/agentNames') -->
|
|
<!-- .then(response => response.json()) -->
|
|
<!-- .then(agentNames => { -->
|
|
<!-- const dropdown = document.getElementById('agentName'); -->
|
|
<!-- agentNames.forEach(name => { -->
|
|
<!-- const option = document.createElement('option'); -->
|
|
<!-- option.value = name; -->
|
|
<!-- option.textContent = name; -->
|
|
<!-- dropdown.appendChild(option); -->
|
|
<!-- }); -->
|
|
<!-- }) -->
|
|
<!-- .catch(error => console.error('Error fetching agent names:', error)); -->
|
|
|
|
<!-- // WebSocket setup for listening to agent responses -->
|
|
<!-- const socket = new WebSocket("ws://localhost:5555/executeCommand"); -->
|
|
|
|
<!-- // Handle WebSocket messages -->
|
|
<!-- socket.onmessage = (event) => { -->
|
|
<!-- const message = JSON.parse(event.data); -->
|
|
<!-- if (message.type === 'response') { -->
|
|
<!-- const output = document.getElementById('commandOutput'); -->
|
|
<!-- output.textContent = message.payload; // Display the agent's response -->
|
|
<!-- } -->
|
|
<!-- }; -->
|
|
|
|
<!-- // Handle WebSocket errors -->
|
|
<!-- socket.onerror = (error) => { -->
|
|
<!-- console.error("WebSocket error:", error); -->
|
|
<!-- }; -->
|
|
|
|
<!-- // Handle WebSocket closure -->
|
|
<!-- socket.onclose = () => { -->
|
|
<!-- console.warn('WebSocket connection closed.'); -->
|
|
<!-- }; -->
|
|
|
|
<!-- // Intercept HTMX requests for /executeCommand to send via WebSocket -->
|
|
<!-- document.body.addEventListener('htmx:beforeRequest', (evt) => { -->
|
|
<!-- const url = evt.detail.pathInfo.requestPath; -->
|
|
<!-- if (url === '/executeCommand') { -->
|
|
<!-- evt.preventDefault(); // Stop HTMX from processing the request -->
|
|
|
|
<!-- // Collect form data -->
|
|
<!-- const formData = new FormData(evt.detail.elt); -->
|
|
<!-- const payload = new URLSearchParams(formData); // Convert form data to query string -->
|
|
|
|
<!-- // Send form data using fetch -->
|
|
<!-- fetch('http://localhost:5555/executeCommand', { -->
|
|
<!-- method: 'POST', -->
|
|
<!-- headers: { -->
|
|
<!-- 'Content-Type': 'application/x-www-form-urlencoded', -->
|
|
<!-- }, -->
|
|
<!-- body: payload, -->
|
|
<!-- }).then((response) => { -->
|
|
<!-- if (!response.ok) { -->
|
|
<!-- console.error('Failed to execute command:', response.statusText); -->
|
|
<!-- } -->
|
|
<!-- }); -->
|
|
<!-- } -->
|
|
<!-- }); -->
|
|
<!-- }); -->
|
|
<!-- </script> -->
|
|
<!-- </head> -->
|
|
<!-- <body> -->
|
|
<!-- <div class="container"> -->
|
|
<!-- <div class="row"> -->
|
|
<!-- <div class="col"> -->
|
|
<!-- <h2>Agents</h2> -->
|
|
|
|
<!-- <!-1- Agent List -1-> -->
|
|
<!-- <div id="agentList" hx-get="/agents" hx-trigger="load" hx-swap="innerHTML"></div> -->
|
|
|
|
<!-- <!-1- Command Execution -1-> -->
|
|
<!-- <div id="agentCommands"> -->
|
|
<!-- <h3>Command Execution</h3> -->
|
|
<!-- <form hx-post="/executeCommand" hx-target="#commandOutput" hx-encoding="application/x-www-form-urlencoded" hx-swap="innerHTML"> -->
|
|
<!-- <div class="mb-3"> -->
|
|
<!-- <label for="agentName" class="form-label">Agent Name</label> -->
|
|
<!-- <select class="form-select" id="agentName" name="agentName" required> -->
|
|
<!-- <!-1- Dynamically populated with agent names -1-> -->
|
|
<!-- </select> -->
|
|
<!-- </div> -->
|
|
<!-- <div class="mb-3"> -->
|
|
<!-- <label for="command" class="form-label">Command</label> -->
|
|
<!-- <input type="text" class="form-control" id="command" name="command" placeholder="Enter command" required> -->
|
|
<!-- </div> -->
|
|
<!-- <button type="submit" class="btn btn-primary">Execute</button> -->
|
|
<!-- </form> -->
|
|
<!-- <div id="commandOutput" class="mt-3 p-2 border">Here goes the output...</div> -->
|
|
<!-- </div> -->
|
|
|
|
<!-- <!-1- Add Agent Form -1-> -->
|
|
<!-- <button class="btn btn-primary mt-3" data-bs-toggle="collapse" data-bs-target="#addAgentForm">Add Agent</button> -->
|
|
<!-- <div id="addAgentForm" class="collapse mt-2"> -->
|
|
<!-- <form hx-post="/agents" hx-target="#agentList" hx-swap="innerHTML"> -->
|
|
<!-- <div class="mb-3"> -->
|
|
<!-- <label for="agentId" class="form-label">Agent Id</label> -->
|
|
<!-- <input type="text" class="form-control" id="agentId" name="agentId" required> -->
|
|
<!-- </div> -->
|
|
<!-- <div class="mb-3"> -->
|
|
<!-- <label for="agentName" class="form-label">Agent Name</label> -->
|
|
<!-- <input type="text" class="form-control" id="agentNameInput" name="agentName" required> -->
|
|
<!-- </div> -->
|
|
<!-- <div class="mb-3"> -->
|
|
<!-- <label for="IPv4Address" class="form-label">IPv4 Address</label> -->
|
|
<!-- <input type="text" class="form-control" id="IPv4Address" name="IPv4Address" required> -->
|
|
<!-- </div> -->
|
|
<!-- <div class="mb-3"> -->
|
|
<!-- <label for="initialContact" class="form-label">Initial Contact</label> -->
|
|
<!-- <input type="datetime-local" class="form-control" id="initialContact" name="initialContact" required> -->
|
|
<!-- </div> -->
|
|
<!-- <div class="mb-3"> -->
|
|
<!-- <label for="lastContact" class="form-label">Last Contact</label> -->
|
|
<!-- <input type="datetime-local" class="form-control" id="lastContact" name="lastContact" required> -->
|
|
<!-- </div> -->
|
|
<!-- <button type="submit" class="btn btn-success">Add Agent</button> -->
|
|
<!-- </form> -->
|
|
<!-- </div> -->
|
|
<!-- </div> -->
|
|
|
|
<!-- <!-1- Agent Details -1-> -->
|
|
<!-- <div class="col" id="agentDetails"> -->
|
|
<!-- <h3>Details</h3> -->
|
|
<!-- <p>Select an agent to view details.</p> -->
|
|
<!-- </div> -->
|
|
<!-- </div> -->
|
|
<!-- </div> -->
|
|
<!-- </body> -->
|
|
<!-- </html> -->
|
|
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">
|
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
|
|
<script src="https://unpkg.com/htmx.org@1.9.12"></script>
|
|
<!-- <script src="https://code.jquery.com/jquery-3.7.1.min.js"></script> -->
|
|
<title>g2: gommand & gontrol</title>
|
|
<script>
|
|
document.body.addEventListener('htmx:afterRequest', (evt) => {
|
|
console.log(evt.detail.xhr.responseText);
|
|
});
|
|
document.body.addEventListener('htmx:responseError', (evt) => {
|
|
console.error(evt.detail.xhr.responseText);
|
|
});
|
|
</script>
|
|
<script>
|
|
document.addEventListener('DOMContentLoaded', () => {
|
|
fetch('/agentNames')
|
|
.then(response => response.json())
|
|
.then(agentNames => {
|
|
const dropdown = document.getElementById('agentName');
|
|
agentNames.forEach(name => {
|
|
const option = document.createElement('option');
|
|
option.value = name;
|
|
option.textContent = name;
|
|
dropdown.appendChild(option);
|
|
});
|
|
})
|
|
.catch(error => console.error('Error fetching agent names:', error));
|
|
|
|
const socket = new WebSocket("ws://localhost:5555/data");
|
|
socket.onmessage = (event) => {
|
|
const message = JSON.parse(event.data);
|
|
if (message.type === 'response') {
|
|
const output = document.getElementById('commandOutput');
|
|
output.textContent = "";
|
|
output.innerText = message.payload.trim();
|
|
console.log("Raw websocket Data:", event.data);
|
|
}
|
|
};
|
|
|
|
socket.onerror = (error) => {
|
|
console.error("Websocket error:", error);
|
|
};
|
|
|
|
socket.onclose = () => {
|
|
console.warn('Websocket connection closed.');
|
|
};
|
|
});
|
|
</script>
|
|
</head>
|
|
<body>
|
|
<div class="container">
|
|
<div class="row">
|
|
<div class="col">
|
|
<h2>Agents</h2>
|
|
|
|
<!-- Agent List -->
|
|
<div id="agentList" hx-get="/agents" hx-trigger="load" hx-swap="innerHTML"></div>
|
|
<!-- Agent Commands -->
|
|
<div id="agentCommands">
|
|
<h3>Command Execution</h3>
|
|
<form hx-post="http://localhost:5555/executeCommand" hx-target="#commandOutput" hx-encoding="application/x-www-form-urlencoded" hx-swap="innerHTML">
|
|
<div class="mb-3">
|
|
<label for="agentName" class="form-label">Agent Name</label>
|
|
<select class="form-select" id="agentName" name="agentName" required>
|
|
<!-- Dynamically populated with agent names -->
|
|
</select>
|
|
</div>
|
|
<div class="mb-3">
|
|
<label for="command" class="form-label">Command</label>
|
|
<input type="text" class="form-control" id="command" name="command" placeholder="Enter command" required>
|
|
</div>
|
|
<button type="submit" class="btn btn-primary">Execute</button>
|
|
</form>
|
|
<pre id="commandOutput"></pre>
|
|
</div>
|
|
|
|
<!-- <form hx-post="/agents/{agentId}/commands" hx-target="#commandOutput" hx-swap="innerHTML"> -->
|
|
<!-- <input type="text" name="command" placeholder="Enter command" required> -->
|
|
<!-- <button type="submit" class="btn btn-primary">Execute</button> -->
|
|
<!-- </form> -->
|
|
<!-- <pre id="commandOutput"></pre> -->
|
|
<!-- </div> -->
|
|
|
|
<!-- Add Agent Form -->
|
|
<button class="btn btn-primary mt-3" data-bs-toggle="collapse" data-bs-target="#addAgentForm">Add Agent</button>
|
|
<div id="addAgentForm" class="collapse mt-2">
|
|
<form hx-post="/agents" hx-target="#agentList" hx-swap="innerHTML">
|
|
<div class="mb-3">
|
|
<label for="agentId" class="form-label">Agent Id</label>
|
|
<input type="text" class="form-control" id="agentId" name="agentId" required>
|
|
</div>
|
|
<div class="mb-3">
|
|
<label for="agentName" class="form-label">Agent Name</label>
|
|
<input type="text" class="form-control" id="agentName" name="agentName" required>
|
|
</div>
|
|
<div class="mb-3">
|
|
<label for="IPv4Address" class="form-label">IPv4 Address</label>
|
|
<input type="text" class="form-control" id="IPv4Address" name="IPv4Address" required>
|
|
</div>
|
|
<div class="mb-3">
|
|
<label for="initialContact" class="form-label">Initial Contact</label>
|
|
<input type="datetime-local" class="form-control" id="initialContact" name="initialContact" required>
|
|
</div>
|
|
<div class="mb-3">
|
|
<label for="lastContact" class="form-label">Last Contact</label>
|
|
<input type="datetime-local" class="form-control" id="lastContact" name="lastContact" required>
|
|
</div>
|
|
<button type="submit" class="btn btn-success">Add Agent</button>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Agent Details -->
|
|
<div class="col" id="agentDetails">
|
|
<h3>Details</h3>
|
|
<p>Select an agent to view details.</p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</body>
|
|
</html>
|