Adds agents management pages
parent
3c9cce2c8b
commit
9c3964da20
|
@ -209,30 +209,39 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST') {
|
|||
}
|
||||
break;
|
||||
|
||||
case 'endpoint':
|
||||
// TODO ad here endpoints options
|
||||
echo 'under construction';
|
||||
// switch ($action) {
|
||||
// case 'add-agent':
|
||||
// $jilo_agent_types = $agentObject->getAgentTypes();
|
||||
// $jilo_agents_in_platform = $agentObject->getPlatformAgentTypes($platform_id);
|
||||
// $jilo_agent_types_in_platform = array_column($jilo_agents_in_platform, 'agent_type_id');
|
||||
// include '../app/templates/config-add-agent.php';
|
||||
// break;
|
||||
// case 'edit':
|
||||
// if (isset($_GET['agent'])) {
|
||||
// $agentDetails = $agentObject->getAgentDetails($platform_id, $agent);
|
||||
// $jilo_agent_types = $agentObject->getAgentTypes();
|
||||
// include '../app/templates/config-edit-agent.php';
|
||||
// }
|
||||
// break;
|
||||
// case 'delete':
|
||||
// if (isset($_GET['agent'])) {
|
||||
// $agentDetails = $agentObject->getAgentDetails($platform_id, $agent);
|
||||
// include '../app/templates/config-delete-agent.php';
|
||||
// }
|
||||
// break;
|
||||
// }
|
||||
case 'agent':
|
||||
if (isset($action) && $action === 'add') {
|
||||
$jilo_agent_types = $agentObject->getAgentTypes();
|
||||
$platform_id = $_REQUEST['platform'] ?? '';
|
||||
if (!empty($platform_id)) {
|
||||
$jilo_agents_in_platform = $agentObject->getPlatformAgentTypes($platform_id);
|
||||
$jilo_agent_types_in_platform = array_column($jilo_agents_in_platform, 'agent_type_id');
|
||||
include '../app/templates/config-agent-add.php';
|
||||
} else {
|
||||
$_SESSION['error'] = "Platform ID is required to add an agent.";
|
||||
header("Location: $app_root?page=config");
|
||||
exit();
|
||||
}
|
||||
} elseif (isset($action) && $action === 'edit') {
|
||||
if (isset($_REQUEST['agent'])) {
|
||||
$platform_id = $_REQUEST['platform'] ?? '';
|
||||
$agentDetails = $agentObject->getAgentDetails($platform_id, $agent)['0'];
|
||||
$jilo_agent_types = $agentObject->getAgentTypes();
|
||||
include '../app/templates/config-agent-edit.php';
|
||||
}
|
||||
} elseif (isset($action) && $action === 'delete') {
|
||||
if (isset($_REQUEST['agent'])) {
|
||||
$platform_id = $_REQUEST['platform'] ?? '';
|
||||
$agentDetails = $agentObject->getAgentDetails($platform_id, $agent)['0'];
|
||||
include '../app/templates/config-agent-delete.php';
|
||||
}
|
||||
} else {
|
||||
if ($userObject->hasRight($user_id, 'view config file')) {
|
||||
include '../app/templates/config-agent.php';
|
||||
} else {
|
||||
include '../app/templates/error-unauthorized.php';
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 'config_file':
|
||||
|
|
|
@ -0,0 +1,59 @@
|
|||
<?php
|
||||
// Get available agent types that are not yet in the platform
|
||||
$available_agent_types = array_filter($jilo_agent_types, function($type) use ($jilo_agent_types_in_platform) {
|
||||
return !in_array($type['id'], $jilo_agent_types_in_platform);
|
||||
});
|
||||
?>
|
||||
|
||||
<div class="card text-center w-75 mx-lef">
|
||||
<p class="h4 card-header">Add new Jilo agent</p>
|
||||
<div class="card-body">
|
||||
<form method="post" action="<?= htmlspecialchars($app_root) ?>">
|
||||
<input type="hidden" name="platform" value="<?= htmlspecialchars($platform_id) ?>">
|
||||
<input type="hidden" name="item" value="agent">
|
||||
<input type="hidden" name="new" value="true">
|
||||
|
||||
<div class="mb-3 row">
|
||||
<label for="type" class="col-sm-2 col-form-label">Agent Type:</label>
|
||||
<div class="col-sm-10">
|
||||
<select class="form-select" id="type" name="type" required>
|
||||
<option value="">Select agent type</option>
|
||||
<?php foreach ($available_agent_types as $type): ?>
|
||||
<option value="<?= htmlspecialchars($type['id']) ?>">
|
||||
<?= htmlspecialchars($type['description']) ?>
|
||||
</option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mb-3 row">
|
||||
<label for="url" class="col-sm-2 col-form-label">URL:</label>
|
||||
<div class="col-sm-10">
|
||||
<input type="text" class="form-control" id="url" name="url" required>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mb-3 row">
|
||||
<label for="secret_key" class="col-sm-2 col-form-label">Secret Key:</label>
|
||||
<div class="col-sm-10">
|
||||
<input type="text" class="form-control" id="secret_key" name="secret_key" required>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mb-3 row">
|
||||
<label for="check_period" class="col-sm-2 col-form-label">Check Period (minutes):</label>
|
||||
<div class="col-sm-10">
|
||||
<input type="number" class="form-control" id="check_period" name="check_period" min="1" required>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mb-3 row">
|
||||
<div class="col-sm-10 offset-sm-2">
|
||||
<button type="submit" class="btn btn-primary">Add Agent</button>
|
||||
<a href="<?= htmlspecialchars($app_root) ?>?page=config&item=agent" class="btn btn-secondary">Cancel</a>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
|
@ -0,0 +1,31 @@
|
|||
<?php if (!empty($agentDetails)): ?>
|
||||
<div class="card text-center w-75 mx-lef">
|
||||
<p class="h4 card-header">Delete Jilo agent</p>
|
||||
<div class="card-body">
|
||||
<p class="card-text">Are you sure you want to delete this agent?</p>
|
||||
|
||||
<div class="mb-3">
|
||||
<strong>Agent ID:</strong> <?= htmlspecialchars($agentDetails['id']) ?><br>
|
||||
<strong>Type:</strong> <?= htmlspecialchars($agentDetails['agent_description']) ?><br>
|
||||
<strong>URL:</strong> <?= htmlspecialchars($agentDetails['url']) ?><br>
|
||||
<strong>Check Period:</strong> <?= htmlspecialchars($agentDetails['check_period']) ?> <?= ($agentDetails['check_period'] == 1 ? 'minute' : 'minutes') ?>
|
||||
</div>
|
||||
|
||||
<form method="post" action="<?= htmlspecialchars($app_root) ?>">
|
||||
<input type="hidden" name="platform" value="<?= htmlspecialchars($platform_id) ?>">
|
||||
<input type="hidden" name="agent" value="<?= htmlspecialchars($agentDetails['id']) ?>">
|
||||
<input type="hidden" name="item" value="agent">
|
||||
<input type="hidden" name="delete" value="true">
|
||||
|
||||
<div class="mb-3">
|
||||
<button type="submit" class="btn btn-danger">Delete Agent</button>
|
||||
<a href="<?= htmlspecialchars($app_root) ?>?page=config" class="btn btn-secondary">Cancel</a>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<?php else: ?>
|
||||
<div class="alert alert-danger">
|
||||
Agent not found.
|
||||
</div>
|
||||
<?php endif; ?>
|
|
@ -0,0 +1,57 @@
|
|||
<?php if (!empty($agentDetails)): ?>
|
||||
<div class="card text-center w-75 mx-lef">
|
||||
<p class="h4 card-header">Edit Jilo agent</p>
|
||||
<div class="card-body">
|
||||
<form method="post" action="<?= htmlspecialchars($app_root . '?page=' . $page) ?>">
|
||||
<input type="hidden" name="platform" value="<?= htmlspecialchars($platform_id) ?>">
|
||||
<input type="hidden" name="agent" value="<?= htmlspecialchars($agentDetails['id']) ?>">
|
||||
<input type="hidden" name="item" value="agent">
|
||||
|
||||
<div class="mb-3 row">
|
||||
<label for="type" class="col-sm-2 col-form-label">Agent Type:</label>
|
||||
<div class="col-sm-10">
|
||||
<select class="form-select" id="type" name="type" required>
|
||||
<?php foreach ($jilo_agent_types as $type): ?>
|
||||
<option value="<?= htmlspecialchars($type['id']) ?>" <?= $type['id'] == $agentDetails['agent_type_id'] ? 'selected' : '' ?>>
|
||||
<?= htmlspecialchars($type['description']) ?>
|
||||
</option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mb-3 row">
|
||||
<label for="url" class="col-sm-2 col-form-label">URL:</label>
|
||||
<div class="col-sm-10">
|
||||
<input type="text" class="form-control" id="url" name="url" value="<?= htmlspecialchars($agentDetails['url']) ?>" required>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mb-3 row">
|
||||
<label for="secret_key" class="col-sm-2 col-form-label">Secret Key:</label>
|
||||
<div class="col-sm-10">
|
||||
<input type="text" class="form-control" id="secret_key" name="secret_key" value="<?= htmlspecialchars($agentDetails['secret_key']) ?>" required>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mb-3 row">
|
||||
<label for="check_period" class="col-sm-2 col-form-label">Check Period (minutes):</label>
|
||||
<div class="col-sm-10">
|
||||
<input type="number" class="form-control" id="check_period" name="check_period" value="<?= htmlspecialchars($agentDetails['check_period']) ?>" min="1" required>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mb-3 row">
|
||||
<div class="col-sm-10 offset-sm-2">
|
||||
<button type="submit" class="btn btn-primary">Save Changes</button>
|
||||
<a href="<?= htmlspecialchars($app_root) ?>?page=config&item=agent" class="btn btn-secondary">Cancel</a>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<?php else: ?>
|
||||
<div class="alert alert-danger">
|
||||
Agent not found.
|
||||
</div>
|
||||
<?php endif; ?>
|
|
@ -0,0 +1,84 @@
|
|||
|
||||
<div class="card text-center w-75 mx-lef">
|
||||
<p class="h4 card-header">Jilo agents configuration</p>
|
||||
<div class="card-body">
|
||||
<?php if (!empty($platformsAll)): ?>
|
||||
<?php foreach ($platformsAll as $platform): ?>
|
||||
<?php
|
||||
$agents = $agentObject->getAgentDetails($platform['id']);
|
||||
?>
|
||||
<div class="row mb-3">
|
||||
<div class="border bg-light" style="padding-left: 50px; padding-bottom: 0px; padding-top: 0px;">
|
||||
<a style="text-decoration: none;" data-toggle="collapse" href="#collapsePlatform<?= htmlspecialchars($platform['id']) ?>" role="button" aria-expanded="true" aria-controls="collapsePlatform<?= htmlspecialchars($platform['id']) ?>">
|
||||
<div class="border bg-white text-start mb-3 rounded mt-3" data-toggle="tooltip" data-placement="bottom" title="agents for platform <?= htmlspecialchars($platform['id']) ?>">
|
||||
<i class="fas fa-server"></i>
|
||||
<small>platform <?= htmlspecialchars($platform['id']) ?> (<?= htmlspecialchars($platform['name']) ?>)</small>
|
||||
</div>
|
||||
</a>
|
||||
<div class="collapse show" id="collapsePlatform<?= htmlspecialchars($platform['id']) ?>">
|
||||
<p class="card-text text-start">
|
||||
total <?= htmlspecialchars(count($agents)) ?> <?= count($agents) === 1 ? 'agent' : 'agents' ?>
|
||||
<a class="btn btn-secondary" style="padding: 0px;" href="<?= htmlspecialchars($app_root) ?>?page=config&item=agent&action=add&platform=<?= htmlspecialchars($platform['id']) ?>">add new</a>
|
||||
</p>
|
||||
|
||||
<?php if (!empty($agents)): ?>
|
||||
<?php foreach ($agents as $agent): ?>
|
||||
<div class="row mb-3" style="padding-left: 0px;">
|
||||
<div class="border rounded bg-light" style="padding-left: 50px; padding-bottom: 20px; padding-top: 20px;">
|
||||
<div class="row mb-1" style="padding-left: 0px;">
|
||||
<div class="col-md-4 text-end">
|
||||
agent id <?= htmlspecialchars($agent['id']) ?>:
|
||||
</div>
|
||||
<div class="col-md-8 text-start">
|
||||
<a class="btn btn-secondary" style="padding: 2px;" href="<?= htmlspecialchars($app_root) ?>?page=config&item=agent&action=edit&platform=<?= htmlspecialchars($platform['id']) ?>&agent=<?= htmlspecialchars($agent['id']) ?>">edit agent</a>
|
||||
<a class="btn btn-danger" style="padding: 2px;" href="<?= htmlspecialchars($app_root) ?>?page=config&item=agent&action=delete&platform=<?= htmlspecialchars($platform['id']) ?>&agent=<?= htmlspecialchars($agent['id']) ?>">delete agent</a>
|
||||
</div>
|
||||
</div>
|
||||
<div style="padding-left: 100px;">
|
||||
<div class="row mb-1" style="padding-left: 100px;">
|
||||
<div class="col-md-4 text-end">
|
||||
agent type:
|
||||
</div>
|
||||
<div class="border col-md-8 text-start">
|
||||
<?= htmlspecialchars($agent['agent_description']) ?>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row mb-1" style="padding-left: 100px;">
|
||||
<div class="col-md-4 text-end">
|
||||
endpoint:
|
||||
</div>
|
||||
<div class="border col-md-8 text-start">
|
||||
<?= htmlspecialchars($agent['url'].$agent['agent_endpoint']) ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php if (isset($agent['check_period']) && $agent['check_period'] !== 0): ?>
|
||||
<div class="row mb-1" style="padding-left: 100px;">
|
||||
<div class="col-md-4 text-end">
|
||||
check period:
|
||||
</div>
|
||||
<div class="border col-md-8 text-start">
|
||||
<?= htmlspecialchars($agent['check_period']) ?> <?= ($agent['check_period'] == 1 ? 'minute' : 'minutes') ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
<?php else: ?>
|
||||
<div class="alert alert-info text-start">
|
||||
No agents configured for this platform.
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<hr />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
<?php else: ?>
|
||||
<div class="alert alert-warning">
|
||||
No platforms available. Please create a platform first.
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
Loading…
Reference in New Issue