modifica visualizzazione pagina server
This commit is contained in:
+47
-20
@@ -3,7 +3,6 @@
|
|||||||
use GlpiPlugin\Urbackup\Profile;
|
use GlpiPlugin\Urbackup\Profile;
|
||||||
use GlpiPlugin\Urbackup\Server;
|
use GlpiPlugin\Urbackup\Server;
|
||||||
use GlpiPlugin\Urbackup\ServerAsset;
|
use GlpiPlugin\Urbackup\ServerAsset;
|
||||||
use Html;
|
|
||||||
|
|
||||||
if (!defined('GLPI_ROOT')) {
|
if (!defined('GLPI_ROOT')) {
|
||||||
define('GLPI_ROOT', dirname(__DIR__, 4));
|
define('GLPI_ROOT', dirname(__DIR__, 4));
|
||||||
@@ -52,26 +51,54 @@ Html::header(
|
|||||||
'GlpiPlugin\Urbackup\Server'
|
'GlpiPlugin\Urbackup\Server'
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if ($ID > 0) {
|
||||||
|
$server->getFromDB($ID);
|
||||||
|
?>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-2">
|
||||||
|
<ul class="nav nav-pills flex-column">
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link active" data-bs-toggle="tab" href="#tab-server">
|
||||||
|
<?php echo htmlspecialchars(__('Server')); ?>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link" data-bs-toggle="tab" href="#tab-linked">
|
||||||
|
<?php echo htmlspecialchars(__('Linked clients', 'urbackup')); ?>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link" data-bs-toggle="tab" href="#tab-unlinked">
|
||||||
|
<?php echo htmlspecialchars(__('Unlinked clients', 'urbackup')); ?>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link" data-bs-toggle="tab" href="#tab-missing">
|
||||||
|
<?php echo htmlspecialchars(__('Missing clients', 'urbackup')); ?>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
<div class="col-10">
|
||||||
|
<div class="tab-content">
|
||||||
|
<div class="tab-pane active" id="tab-server">
|
||||||
|
<?php $server->showForm($ID); ?>
|
||||||
|
</div>
|
||||||
|
<div class="tab-pane" id="tab-linked">
|
||||||
|
<?php Server::showLinkedClientsTab($server); ?>
|
||||||
|
</div>
|
||||||
|
<div class="tab-pane" id="tab-unlinked">
|
||||||
|
<?php Server::showUnlinkedClientsTab($server); ?>
|
||||||
|
</div>
|
||||||
|
<div class="tab-pane" id="tab-missing">
|
||||||
|
<?php Server::showMissingClientsTab($server); ?>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<?php
|
||||||
|
} else {
|
||||||
$server->showForm($ID);
|
$server->showForm($ID);
|
||||||
|
|
||||||
if ($ID > 0 && $server->getFromDB($ID)) {
|
|
||||||
echo '<div class="card mt-4">';
|
|
||||||
echo '<div class="card-header">';
|
|
||||||
echo '<h5 class="mb-0">' . htmlspecialchars(__('Linked clients', 'urbackup')) . '</h5>';
|
|
||||||
echo '</div>';
|
|
||||||
echo '<div class="card-body">';
|
|
||||||
Server::showLinkedClientsTab($server);
|
|
||||||
echo '</div>';
|
|
||||||
echo '</div>';
|
|
||||||
|
|
||||||
echo '<div class="card mt-4">';
|
|
||||||
echo '<div class="card-header">';
|
|
||||||
echo '<h5 class="mb-0">' . htmlspecialchars(__('Unlinked clients', 'urbackup')) . '</h5>';
|
|
||||||
echo '</div>';
|
|
||||||
echo '<div class="card-body">';
|
|
||||||
Server::showUnlinkedClientsTab($server);
|
|
||||||
echo '</div>';
|
|
||||||
echo '</div>';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Html::footer();
|
Html::footer();
|
||||||
+156
-7
@@ -324,7 +324,14 @@ class Server extends CommonDBTM
|
|||||||
|
|
||||||
$this->initForm($ID, $options);
|
$this->initForm($ID, $options);
|
||||||
$this->showFormHeader($options);
|
$this->showFormHeader($options);
|
||||||
|
$this->showFormFields($ID);
|
||||||
|
$this->showFormButtons($options);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function showFormFields(int $ID): void
|
||||||
|
{
|
||||||
echo "<tr class='tab_bg_1'>";
|
echo "<tr class='tab_bg_1'>";
|
||||||
echo "<td>" . htmlspecialchars(__('Name')) . "</td>";
|
echo "<td>" . htmlspecialchars(__('Name')) . "</td>";
|
||||||
echo "<td>";
|
echo "<td>";
|
||||||
@@ -479,10 +486,6 @@ $apiStatus = (int) ($this->fields['last_api_status'] ?? 0);
|
|||||||
echo "</td>";
|
echo "</td>";
|
||||||
echo "</tr>";
|
echo "</tr>";
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->showFormButtons($options);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -789,7 +792,6 @@ $apiStatus = (int) ($this->fields['last_api_status'] ?? 0);
|
|||||||
echo '<thead>';
|
echo '<thead>';
|
||||||
echo '<tr>';
|
echo '<tr>';
|
||||||
echo '<th>' . htmlspecialchars(__('Asset', 'urbackup')) . '</th>';
|
echo '<th>' . htmlspecialchars(__('Asset', 'urbackup')) . '</th>';
|
||||||
echo '<th>' . htmlspecialchars(__('Name', 'urbackup')) . '</th>';
|
|
||||||
echo '<th>' . htmlspecialchars(__('Client name', 'urbackup')) . '</th>';
|
echo '<th>' . htmlspecialchars(__('Client name', 'urbackup')) . '</th>';
|
||||||
echo '<th>' . htmlspecialchars(__('Version', 'urbackup')) . '</th>';
|
echo '<th>' . htmlspecialchars(__('Version', 'urbackup')) . '</th>';
|
||||||
echo '<th>' . htmlspecialchars(__('Status', 'urbackup')) . '</th>';
|
echo '<th>' . htmlspecialchars(__('Status', 'urbackup')) . '</th>';
|
||||||
@@ -840,8 +842,14 @@ $apiStatus = (int) ($this->fields['last_api_status'] ?? 0);
|
|||||||
$itemUrl = $glpiItem ? $glpiItem->getLinkURL() : '';
|
$itemUrl = $glpiItem ? $glpiItem->getLinkURL() : '';
|
||||||
|
|
||||||
echo '<tr>';
|
echo '<tr>';
|
||||||
echo '<td>' . htmlspecialchars($itemTypeLabel . ' #' . $link['items_id']) . '</td>';
|
echo '<td>';
|
||||||
echo '<td>' . ($itemUrl ? '<a href="' . htmlspecialchars($itemUrl) . '">' . htmlspecialchars($clientName) . '</a>' : htmlspecialchars($clientName)) . '</td>';
|
if ($itemUrl) {
|
||||||
|
echo '<a href="' . htmlspecialchars($itemUrl) . '">' . htmlspecialchars($clientName) . '</a>';
|
||||||
|
} else {
|
||||||
|
echo htmlspecialchars($clientName);
|
||||||
|
}
|
||||||
|
echo ' <small class="text-muted">(' . htmlspecialchars($itemTypeLabel) . ')</small>';
|
||||||
|
echo '</td>';
|
||||||
echo '<td>' . htmlspecialchars($urbackupClientName) . '</td>';
|
echo '<td>' . htmlspecialchars($urbackupClientName) . '</td>';
|
||||||
echo '<td>' . htmlspecialchars($clientVersion) . '</td>';
|
echo '<td>' . htmlspecialchars($clientVersion) . '</td>';
|
||||||
echo '<td>' . $statusHtml . '</td>';
|
echo '<td>' . $statusHtml . '</td>';
|
||||||
@@ -1005,4 +1013,145 @@ $apiStatus = (int) ($this->fields['last_api_status'] ?? 0);
|
|||||||
echo '</tbody>';
|
echo '</tbody>';
|
||||||
echo '</table>';
|
echo '</table>';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function showMissingClientsTab(Server $server): void
|
||||||
|
{
|
||||||
|
global $DB;
|
||||||
|
|
||||||
|
$apiStatus = (int) ($server->fields['last_api_status'] ?? 0);
|
||||||
|
if ($apiStatus !== 1) {
|
||||||
|
echo '<div class="alert alert-warning">';
|
||||||
|
echo htmlspecialchars(__('API connection not working. Save server to test connection.', 'urbackup'));
|
||||||
|
echo '</div>';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$serverLocationId = (int) ($server->fields['locations_id'] ?? 0);
|
||||||
|
if ($serverLocationId <= 0) {
|
||||||
|
echo '<div class="alert alert-info">';
|
||||||
|
echo htmlspecialchars(__('No location configured for this server.', 'urbackup'));
|
||||||
|
echo '</div>';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$rootLocationId = LocationHelper::getRootLocationId($serverLocationId);
|
||||||
|
|
||||||
|
$linkedIterator = $DB->request([
|
||||||
|
'FROM' => ServerAsset::getTable(),
|
||||||
|
]);
|
||||||
|
$linkedAssetKeys = [];
|
||||||
|
foreach ($linkedIterator as $row) {
|
||||||
|
$linkedAssetKeys[$row['itemtype'] . ':' . $row['items_id']] = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
$client = new UrbackupApiClient($server);
|
||||||
|
$urbackupClients = $client->getStatus();
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
echo '<div class="alert alert-danger">';
|
||||||
|
echo htmlspecialchars($e->getMessage());
|
||||||
|
echo '</div>';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$urbackupClientNames = [];
|
||||||
|
foreach ($urbackupClients as $uc) {
|
||||||
|
$name = strtolower((string) ($uc['name'] ?? $uc['clientname'] ?? $uc['hostname'] ?? ''));
|
||||||
|
if ($name !== '') {
|
||||||
|
$urbackupClientNames[$name] = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$itemtypes = Config::getEnabledItemtypes();
|
||||||
|
$missingAssets = [];
|
||||||
|
|
||||||
|
foreach ($itemtypes as $itemtype) {
|
||||||
|
if (!class_exists($itemtype)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$assetItem = new $itemtype();
|
||||||
|
if (!$assetItem instanceof CommonDBTM) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$table = $assetItem->getTable();
|
||||||
|
if (!$DB->tableExists($table)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$iterator = $DB->request([
|
||||||
|
'FROM' => $table,
|
||||||
|
'WHERE' => [
|
||||||
|
'is_deleted' => 0,
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
|
||||||
|
foreach ($iterator as $assetRow) {
|
||||||
|
$name = (string) ($assetRow['name'] ?? '');
|
||||||
|
if ($name === '') {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$nameLower = strtolower($name);
|
||||||
|
|
||||||
|
$assetLocationId = (int) ($assetRow['locations_id'] ?? 0);
|
||||||
|
$assetRootLocationId = LocationHelper::getRootLocationId($assetLocationId);
|
||||||
|
|
||||||
|
if ($assetRootLocationId !== $rootLocationId) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$key = $itemtype . ':' . $assetRow['id'];
|
||||||
|
if (isset($linkedAssetKeys[$key])) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (isset($urbackupClientNames[$nameLower])) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$missingAssets[] = [
|
||||||
|
'itemtype' => $itemtype,
|
||||||
|
'items_id' => (int) $assetRow['id'],
|
||||||
|
'name' => $name,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (count($missingAssets) === 0) {
|
||||||
|
echo '<div class="alert alert-success">';
|
||||||
|
echo htmlspecialchars(__('All assets in this location are linked or already on the UrBackup server.', 'urbackup'));
|
||||||
|
echo '</div>';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$formAction = PLUGIN_URBACKUP_WEB_DIR . '/front/server.form.php';
|
||||||
|
|
||||||
|
echo '<table class="table table-striped table-hover">';
|
||||||
|
echo '<thead><tr>';
|
||||||
|
echo '<th>' . htmlspecialchars(__('Asset type')) . '</th>';
|
||||||
|
echo '<th>' . htmlspecialchars(__('Name')) . '</th>';
|
||||||
|
echo '<th>' . htmlspecialchars(__('Actions', 'urbackup')) . '</th>';
|
||||||
|
echo '</tr></thead>';
|
||||||
|
echo '<tbody>';
|
||||||
|
|
||||||
|
foreach ($missingAssets as $asset) {
|
||||||
|
$itemtypeLabel = class_exists($asset['itemtype']) ? $asset['itemtype']::getTypeName(1) : $asset['itemtype'];
|
||||||
|
echo '<tr>';
|
||||||
|
echo '<td>' . htmlspecialchars($itemtypeLabel) . '</td>';
|
||||||
|
echo '<td>' . htmlspecialchars($asset['name']) . '</td>';
|
||||||
|
echo '<td>';
|
||||||
|
echo '<form method="post" action="' . htmlspecialchars($formAction) . '" class="d-inline">';
|
||||||
|
echo Html::hidden('_glpi_csrf_token', ['value' => Session::getNewCSRFToken()]);
|
||||||
|
echo Html::hidden('itemtype', ['value' => $asset['itemtype']]);
|
||||||
|
echo Html::hidden('items_id', ['value' => $asset['items_id']]);
|
||||||
|
echo Html::hidden('id', ['value' => (int) $server->fields['id']]);
|
||||||
|
echo '<button type="submit" name="link_asset" value="1" class="btn btn-primary btn-sm">';
|
||||||
|
echo htmlspecialchars(__('Connect'));
|
||||||
|
echo '</button>';
|
||||||
|
Html::closeForm();
|
||||||
|
echo '</td>';
|
||||||
|
echo '</tr>';
|
||||||
|
}
|
||||||
|
|
||||||
|
echo '</tbody>';
|
||||||
|
echo '</table>';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user