209 lines
10 KiB
HTML
209 lines
10 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>
|
|
<!-- <script src="https://code.jquery.com/jquery-3.7.1.min.js"></script> -->
|
|
<title>g2: gommand & gontrol</title>
|
|
<script>
|
|
// Query Agents for the Dropdown Menu
|
|
<!-- 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)); -->
|
|
<!-- }); -->
|
|
<!-- // Query agents currently connected to the websocket and put status into the table -->
|
|
<!-- const updateAgentStatuses = () => { -->
|
|
<!-- fetch('http://localhost:5555/agentNames') -->
|
|
<!-- .then(response => response.json()) -->
|
|
<!-- .then(agentNames => { -->
|
|
<!-- console.log("Agent names fetched:", agentNames); -->
|
|
<!-- const tableRows = document.querySelectorAll('#agentList table tbody tr'); -->
|
|
<!-- tableRows.forEach(row => { -->
|
|
<!-- const nameCell = row.querySelector('td:nth-child(2)'); -->
|
|
<!-- const statusCell = row.querySelector('td:nth-child(5)'); -->
|
|
<!-- if (nameCell && statusCell) { -->
|
|
<!-- const agentName = nameCell.textContent.trim(); -->
|
|
<!-- if (agentNames.includes(agentName)) { -->
|
|
<!-- statusCell.innerHTML = '<span class="badge bg-success">Connected</span>'; -->
|
|
<!-- } else { -->
|
|
<!-- statusCell.innerHTML = '<span class="badge bg-danger">Disconnected</span>'; -->
|
|
<!-- } -->
|
|
<!-- } -->
|
|
<!-- }); -->
|
|
<!-- }) -->
|
|
<!-- .catch(error => console.error('Error fetching agent names:', error)); -->
|
|
<!-- }; -->
|
|
<!-- updateAgentStatuses(); -->
|
|
<!-- setInterval(updateAgentStatuses, 5000); -->
|
|
|
|
<!-- document.body.addEventListener('htmx:afterSwap', function(evt) { -->
|
|
<!-- if (evt.detail.xhr.status === 200) { -->
|
|
<!-- const tableRows = document.querySelectorAll('#agentList table tbody tr'); -->
|
|
<!-- tableRows.forEach(row => { -->
|
|
<!-- const nameCell = row.querySelector('td:nth-child(2)'); -->
|
|
<!-- const statusCell = row.querySelector('td:nth-child(5)'); -->
|
|
<!-- if (nameCell && statusCell) { -->
|
|
<!-- const agentName = nameCell.textContent.trim(); -->
|
|
<!-- if ("Connected" === statusCell.innerHTML) { -->
|
|
<!-- statusCell.innerHTML = '<span class="badge bg-success">Connected</span>'; -->
|
|
<!-- } else { -->
|
|
<!-- statusCell.innerHTML = '<span class="badge bg-danger">Disconnected</span>'; -->
|
|
<!-- } -->
|
|
<!-- } -->
|
|
<!-- } -->
|
|
<!-- } -->
|
|
<!-- }); -->
|
|
|
|
document.addEventListener('DOMContentLoaded', () => {
|
|
document.body.addEventListener('htmx:afterSwap', function(event) {
|
|
if (event.target.id === "agentList") {
|
|
updateAgentDropdown();
|
|
}
|
|
});
|
|
|
|
function updateAgentDropdown() {
|
|
const select = document.getElementById("agentName");
|
|
const optionValues = Array.from(select.options).map(opt => opt.value);
|
|
const rows = document.querySelectorAll("#agentList tbody tr");
|
|
|
|
rows.forEach(row => {
|
|
const status = row.cells[4].textContent.trim();
|
|
const name = row.cells[1].textContent.trim();
|
|
|
|
if (status === "Connected") {
|
|
row.cells[4].innerHTML = '<span class="badge bg-success">Connected</span>';
|
|
const option = document.createElement("option");
|
|
if (!(optionValues.includes(name))) {
|
|
option.value = name;
|
|
option.textContent = name;
|
|
select.appendChild(option);
|
|
}
|
|
}
|
|
|
|
if (status === "Disconnected") {
|
|
row.cells[4].innerHTML = '<span class="badge bg-danger">Disconnected</span>';
|
|
const option = Array.from(select.options).find(opt => opt.value === name);
|
|
if(option) {
|
|
select.removeChild(option);
|
|
}
|
|
}
|
|
});
|
|
}
|
|
});
|
|
|
|
</script>
|
|
<style>
|
|
.log-info {
|
|
color: green;
|
|
}
|
|
.log-warning {
|
|
color: orange;
|
|
}
|
|
.log-error {
|
|
color: red;
|
|
}
|
|
.log-fatal {
|
|
color: blue;
|
|
}
|
|
.log-debug {
|
|
color: violet;
|
|
}
|
|
</style>
|
|
|
|
</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, every 2s" hx-swap="innerHTML"></div>
|
|
<!-- <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> -->
|
|
<select id="agentName" class="form-select" name="agentName" hx-on="htmx:afterSwap:updateAgentDropdown" required>
|
|
<option value="" disabled selected>Select an Agent</option>
|
|
<!-- 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>
|
|
|
|
<!-- 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> -->
|
|
|
|
<!-- Logs Section -->
|
|
<h3>Logs</h3>
|
|
<div id="logs-container" hx-get="/logs" hx-target="#logs-container" hx-swap="innerHTML" hx-trigger="every 3s">
|
|
<!-- Logs will be injected here -->
|
|
<!-- </div> -->
|
|
<!-- <button hx-get="/logs" hx-target="#logs-container" hx-swap="innerHTML"> -->
|
|
<!-- Load Logs -->
|
|
<!-- </button> -->
|
|
<!-- <button hx-get="/logs" hx-target="#logs-container" hx-swap="innerHTML" hx-trigger="every 8s"> -->
|
|
<!-- Auto-Refresh Logs -->
|
|
<!-- </button> -->
|
|
<!-- </div> -->
|
|
|
|
<!-- Agent Details -->
|
|
<div class="col" id="agentDetails">
|
|
<h3>Details</h3>
|
|
<p>Select an agent to view details.</p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</body>
|
|
</html>
|