pulsanti e create client
This commit is contained in:
@@ -152,6 +152,38 @@ if (isset($_POST['execute'])) {
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'create_client':
|
||||
if (Profile::canCurrentUser(CREATE)) {
|
||||
$link = ServerAsset::getLinkForAsset($itemtype, $items_id, false);
|
||||
if ($link !== null) {
|
||||
$server = new \GlpiPlugin\Urbackup\Server();
|
||||
$server->getFromDB((int) $link['plugin_urbackup_servers_id']);
|
||||
$client_name = ServerAsset::getAssetName($itemtype, $items_id);
|
||||
try {
|
||||
$api = new \GlpiPlugin\Urbackup\UrbackupApiClient($server);
|
||||
$api->addClient($client_name);
|
||||
} catch (\Throwable $e) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'delete_client':
|
||||
if (Profile::canCurrentUser(PURGE)) {
|
||||
$link = ServerAsset::getLinkForAsset($itemtype, $items_id, false);
|
||||
if ($link !== null) {
|
||||
$server = new \GlpiPlugin\Urbackup\Server();
|
||||
$server->getFromDB((int) $link['plugin_urbackup_servers_id']);
|
||||
$client_name = ServerAsset::getAssetName($itemtype, $items_id);
|
||||
try {
|
||||
$api = new \GlpiPlugin\Urbackup\UrbackupApiClient($server);
|
||||
$api->removeClient($client_name);
|
||||
} catch (\Throwable $e) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'set_internet_mode':
|
||||
if (Profile::canCurrentUser(UPDATE)) {
|
||||
$enabled = (int) ($_POST['internet_mode'] ?? 0) === 1;
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
use GlpiPlugin\Urbackup\Profile;
|
||||
use GlpiPlugin\Urbackup\Server;
|
||||
use GlpiPlugin\Urbackup\ServerAsset;
|
||||
use Html;
|
||||
|
||||
if (!defined('GLPI_ROOT')) {
|
||||
@@ -17,6 +18,18 @@ if (!Profile::canCurrentUser(UPDATE)) {
|
||||
$server = new Server();
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
if (isset($_POST['link_asset'])) {
|
||||
$itemtype = (string) ($_POST['itemtype'] ?? '');
|
||||
$items_id = (int) ($_POST['items_id'] ?? 0);
|
||||
$server_id = (int) ($_POST['id'] ?? 0);
|
||||
|
||||
if ($itemtype !== '' && $items_id > 0 && $server_id > 0) {
|
||||
ServerAsset::connectAssetToServer($itemtype, $items_id, $server_id);
|
||||
}
|
||||
|
||||
Html::redirect(PLUGIN_URBACKUP_WEB_DIR . '/front/server.php?id=' . $server_id);
|
||||
}
|
||||
|
||||
$id = $_POST['id'] ?? 0;
|
||||
|
||||
if ($id > 0) {
|
||||
|
||||
@@ -116,8 +116,6 @@ class AssetTab extends CommonDBTM
|
||||
*/
|
||||
private static function showNoServerLinkedBlock(CommonDBTM $item): void
|
||||
{
|
||||
$asset_location_id = LocationHelper::getAssetLocationId($item);
|
||||
$root_location_id = LocationHelper::getRootLocationIdForAsset($item);
|
||||
$is_sub_location = LocationHelper::assetIsInSubLocation($item);
|
||||
$servers = LocationHelper::getAvailableServersForAsset($item);
|
||||
|
||||
@@ -128,16 +126,6 @@ class AssetTab extends CommonDBTM
|
||||
echo "<table class='tab_cadre_fixe'>";
|
||||
echo "<tr><th colspan='2'>" . htmlspecialchars(__('UrBackup server selection', 'urbackup')) . "</th></tr>";
|
||||
|
||||
echo "<tr class='tab_bg_1'>";
|
||||
echo "<td>" . htmlspecialchars(__('Asset location ID', 'urbackup')) . "</td>";
|
||||
echo "<td>" . htmlspecialchars((string) $asset_location_id) . "</td>";
|
||||
echo "</tr>";
|
||||
|
||||
echo "<tr class='tab_bg_1'>";
|
||||
echo "<td>" . htmlspecialchars(__('Root location ID', 'urbackup')) . "</td>";
|
||||
echo "<td>" . htmlspecialchars((string) $root_location_id) . "</td>";
|
||||
echo "</tr>";
|
||||
|
||||
if ($is_sub_location) {
|
||||
echo "<tr class='tab_bg_1'>";
|
||||
echo "<td colspan='2'><em>";
|
||||
|
||||
+67
-1
@@ -904,6 +904,51 @@ $apiStatus = (int) ($this->fields['last_api_status'] ?? 0);
|
||||
return;
|
||||
}
|
||||
|
||||
$serverLocationId = (int) ($server->fields['locations_id'] ?? 0);
|
||||
$linkableAssets = [];
|
||||
if ($serverLocationId > 0) {
|
||||
$itemtypes = Config::getEnabledItemtypes();
|
||||
foreach ($unlinkedClients as $uc) {
|
||||
$clientName = (string) ($uc['name'] ?? '');
|
||||
if ($clientName === '') {
|
||||
continue;
|
||||
}
|
||||
$clientNameLower = strtolower($clientName);
|
||||
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;
|
||||
}
|
||||
$assetIterator = $DB->request([
|
||||
'FROM' => $table,
|
||||
'WHERE' => [
|
||||
'name' => $clientName,
|
||||
'is_deleted' => 0,
|
||||
],
|
||||
'LIMIT' => 1,
|
||||
]);
|
||||
foreach ($assetIterator as $assetRow) {
|
||||
$assetLocationId = (int) ($assetRow['locations_id'] ?? 0);
|
||||
$rootLocationId = LocationHelper::getRootLocationId($assetLocationId);
|
||||
if ($rootLocationId > 0 && $rootLocationId === $serverLocationId) {
|
||||
$linkableAssets[$clientNameLower] = [
|
||||
'itemtype' => $itemtype,
|
||||
'items_id' => (int) $assetRow['id'],
|
||||
];
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
echo '<table class="table table-striped table-hover">';
|
||||
echo '<thead>';
|
||||
echo '<tr>';
|
||||
@@ -912,11 +957,15 @@ $apiStatus = (int) ($this->fields['last_api_status'] ?? 0);
|
||||
echo '<th>' . htmlspecialchars(__('Status', 'urbackup')) . '</th>';
|
||||
echo '<th>' . htmlspecialchars(__('Last backup', 'urbackup')) . '</th>';
|
||||
echo '<th>' . htmlspecialchars(__('IP address', 'urbackup')) . '</th>';
|
||||
echo '<th>' . htmlspecialchars(__('Actions', 'urbackup')) . '</th>';
|
||||
echo '</tr>';
|
||||
echo '</thead>';
|
||||
echo '<tbody>';
|
||||
|
||||
foreach ($unlinkedClients as $uc) {
|
||||
$clientName = (string) ($uc['name'] ?? 'Unknown');
|
||||
$clientNameLower = strtolower($clientName);
|
||||
|
||||
$online = $uc['online'] ?? null;
|
||||
$apiStatusString = $uc['status'] ?? '';
|
||||
$statusHtml = self::renderOnlineBadge($online, $apiStatusString);
|
||||
@@ -928,11 +977,28 @@ $apiStatus = (int) ($this->fields['last_api_status'] ?? 0);
|
||||
$clientVersion = $uc['client_version_string'] ?? $uc['client_version'] ?? '-';
|
||||
|
||||
echo '<tr>';
|
||||
echo '<td>' . htmlspecialchars((string) ($uc['name'] ?? 'Unknown')) . '</td>';
|
||||
echo '<td>' . htmlspecialchars($clientName) . '</td>';
|
||||
echo '<td>' . htmlspecialchars($clientVersion) . '</td>';
|
||||
echo '<td>' . $statusHtml . '</td>';
|
||||
echo '<td>' . htmlspecialchars($lastBackup ?: '-') . '</td>';
|
||||
echo '<td>' . htmlspecialchars($clientIp ?: '-') . '</td>';
|
||||
echo '<td>';
|
||||
if (isset($linkableAssets[$clientNameLower])) {
|
||||
$match = $linkableAssets[$clientNameLower];
|
||||
$formAction = PLUGIN_URBACKUP_WEB_DIR . '/front/server.form.php';
|
||||
echo '<form method="post" action="' . htmlspecialchars($formAction) . '" class="d-inline">';
|
||||
echo Html::hidden('_glpi_csrf_token', ['value' => Session::getNewCSRFToken()]);
|
||||
echo Html::hidden('itemtype', ['value' => $match['itemtype']]);
|
||||
echo Html::hidden('items_id', ['value' => $match['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();
|
||||
} else {
|
||||
echo '<span class="text-muted">—</span>';
|
||||
}
|
||||
echo '</td>';
|
||||
echo '</tr>';
|
||||
}
|
||||
|
||||
|
||||
@@ -7,14 +7,6 @@
|
||||
<tr>
|
||||
<th colspan="2">{{ __('UrBackup server selection', 'urbackup') }}</th>
|
||||
</tr>
|
||||
<tr class="tab_bg_1">
|
||||
<td>{{ __('Asset location ID', 'urbackup') }}</td>
|
||||
<td>{{ asset_location_id }}</td>
|
||||
</tr>
|
||||
<tr class="tab_bg_1">
|
||||
<td>{{ __('Root location ID', 'urbackup') }}</td>
|
||||
<td>{{ root_location_id }}</td>
|
||||
</tr>
|
||||
{% if is_sub_location %}
|
||||
<tr class="tab_bg_1">
|
||||
<td colspan="2"><em>
|
||||
|
||||
Reference in New Issue
Block a user