9 Commits

Author SHA1 Message Date
mariano 6441a8636d elimina pippo.txt 2026-05-20 13:16:07 +02:00
mariano 6a49489b73 merge all 2026-05-20 13:11:03 +02:00
mariano a5c20dc834 pippo.txt 2026-05-20 12:25:45 +02:00
mariano 6056a29865 remove debug raw data 2026-05-20 12:04:21 +02:00
mariano a20e429456 modifica redirect 2026-05-20 12:00:39 +02:00
mariano a1c3a5a07e pulsanti e create client 2026-05-20 11:46:28 +02:00
mariano f4bd50c1b1 pulsanti e sistemazione create client 2026-05-20 11:16:14 +02:00
mariano 7143d721fb fix true/false toggle switch 2026-05-20 10:26:50 +02:00
mariano fe9223a617 fix internet_enabled 2026-05-20 10:13:30 +02:00
7 changed files with 124 additions and 51 deletions
+32
View File
@@ -152,6 +152,38 @@ if (isset($_POST['execute'])) {
} }
} }
break; 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': case 'set_internet_mode':
if (Profile::canCurrentUser(UPDATE)) { if (Profile::canCurrentUser(UPDATE)) {
$enabled = (int) ($_POST['internet_mode'] ?? 0) === 1; $enabled = (int) ($_POST['internet_mode'] ?? 0) === 1;
+17
View File
@@ -2,6 +2,7 @@
use GlpiPlugin\Urbackup\Profile; use GlpiPlugin\Urbackup\Profile;
use GlpiPlugin\Urbackup\Server; use GlpiPlugin\Urbackup\Server;
use GlpiPlugin\Urbackup\ServerAsset;
use Html; use Html;
if (!defined('GLPI_ROOT')) { if (!defined('GLPI_ROOT')) {
@@ -17,6 +18,22 @@ if (!Profile::canCurrentUser(UPDATE)) {
$server = new Server(); $server = new Server();
if ($_SERVER['REQUEST_METHOD'] === 'POST') { 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);
}
<<<<<<< HEAD
Html::redirect(PLUGIN_URBACKUP_WEB_DIR . '/front/server.form.php?id=' . $server_id);
=======
Html::redirect(PLUGIN_URBACKUP_WEB_DIR . '/front/server.php?id=' . $server_id);
>>>>>>> collegamento_e_verifica_host
}
$id = $_POST['id'] ?? 0; $id = $_POST['id'] ?? 0;
if ($id > 0) { if ($id > 0) {
-27
View File
@@ -116,8 +116,6 @@ class AssetTab extends CommonDBTM
*/ */
private static function showNoServerLinkedBlock(CommonDBTM $item): void 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); $is_sub_location = LocationHelper::assetIsInSubLocation($item);
$servers = LocationHelper::getAvailableServersForAsset($item); $servers = LocationHelper::getAvailableServersForAsset($item);
@@ -128,16 +126,6 @@ class AssetTab extends CommonDBTM
echo "<table class='tab_cadre_fixe'>"; echo "<table class='tab_cadre_fixe'>";
echo "<tr><th colspan='2'>" . htmlspecialchars(__('UrBackup server selection', 'urbackup')) . "</th></tr>"; 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) { if ($is_sub_location) {
echo "<tr class='tab_bg_1'>"; echo "<tr class='tab_bg_1'>";
echo "<td colspan='2'><em>"; echo "<td colspan='2'><em>";
@@ -418,17 +406,6 @@ class AssetTab extends CommonDBTM
echo "</table>"; echo "</table>";
echo '<details class="mt-2" style="cursor:pointer;color:#666;font-size:0.85em">';
echo '<summary>' . htmlspecialchars(__('API raw data (debug)', 'urbackup')) . '</summary>';
echo '<pre style="max-height:300px;overflow:auto;background:#f5f5f5;padding:8px;border:1px solid #ddd;font-size:0.8em">';
echo "--- client_settings ---\n\n";
echo htmlspecialchars(json_encode($settings, JSON_PRETTY_PRINT));
echo "\n\n--- client_status ---\n\n";
echo htmlspecialchars(json_encode($status, JSON_PRETTY_PRINT));
echo "\n\n--- recent_backups ---\n\n";
echo htmlspecialchars(json_encode($api_data['recent_backups'] ?? [], JSON_PRETTY_PRINT));
echo '</pre>';
echo '</details>';
} }
/** /**
@@ -707,10 +684,6 @@ class AssetTab extends CommonDBTM
echo "<textarea name='default_dirs' rows='4' cols='80'>" . htmlspecialchars($display) . "</textarea><br>"; echo "<textarea name='default_dirs' rows='4' cols='80'>" . htmlspecialchars($display) . "</textarea><br>";
echo '<div style="color:#999;font-size:0.8em">';
echo 'raw: ' . htmlspecialchars(json_encode($raw));
echo '</div>';
echo Html::submit(__('Save'), [ echo Html::submit(__('Save'), [
'name' => 'execute', 'name' => 'execute',
'class' => 'btn btn-primary', 'class' => 'btn btn-primary',
+2 -4
View File
@@ -88,16 +88,14 @@ class AssetController
case 'set_internet_mode': case 'set_internet_mode':
if (Profile::canCurrentUser(UPDATE)) { if (Profile::canCurrentUser(UPDATE)) {
$internet_mode = (int) $request->request->get('internet_mode', 0); $enabled = (int) $request->request->get('internet_mode', 0) === 1;
$serverAsset = new ServerAsset();
$link = ServerAsset::getLinkForAsset($itemtype, $items_id, true); $link = ServerAsset::getLinkForAsset($itemtype, $items_id, true);
if ($link) { if ($link) {
$server = new Server(); $server = new Server();
if ($server->getFromDB((int) $link['plugin_urbackup_servers_id'])) { if ($server->getFromDB((int) $link['plugin_urbackup_servers_id'])) {
$api = new UrbackupApiClient($server); $api = new UrbackupApiClient($server);
$client_name = (string) ($item->fields['name'] ?? ''); $client_name = (string) ($item->fields['name'] ?? '');
$setting_key = $api->getInternetModeSettingKey(); $api->saveInternetMode($client_name, $enabled);
$api->changeClientSetting($client_name, $setting_key, $internet_mode);
} }
} }
} }
+67 -1
View File
@@ -904,6 +904,51 @@ $apiStatus = (int) ($this->fields['last_api_status'] ?? 0);
return; 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 '<table class="table table-striped table-hover">';
echo '<thead>'; echo '<thead>';
echo '<tr>'; echo '<tr>';
@@ -912,11 +957,15 @@ $apiStatus = (int) ($this->fields['last_api_status'] ?? 0);
echo '<th>' . htmlspecialchars(__('Status', 'urbackup')) . '</th>'; echo '<th>' . htmlspecialchars(__('Status', 'urbackup')) . '</th>';
echo '<th>' . htmlspecialchars(__('Last backup', 'urbackup')) . '</th>'; echo '<th>' . htmlspecialchars(__('Last backup', 'urbackup')) . '</th>';
echo '<th>' . htmlspecialchars(__('IP address', 'urbackup')) . '</th>'; echo '<th>' . htmlspecialchars(__('IP address', 'urbackup')) . '</th>';
echo '<th>' . htmlspecialchars(__('Actions', 'urbackup')) . '</th>';
echo '</tr>'; echo '</tr>';
echo '</thead>'; echo '</thead>';
echo '<tbody>'; echo '<tbody>';
foreach ($unlinkedClients as $uc) { foreach ($unlinkedClients as $uc) {
$clientName = (string) ($uc['name'] ?? 'Unknown');
$clientNameLower = strtolower($clientName);
$online = $uc['online'] ?? null; $online = $uc['online'] ?? null;
$apiStatusString = $uc['status'] ?? ''; $apiStatusString = $uc['status'] ?? '';
$statusHtml = self::renderOnlineBadge($online, $apiStatusString); $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'] ?? '-'; $clientVersion = $uc['client_version_string'] ?? $uc['client_version'] ?? '-';
echo '<tr>'; echo '<tr>';
echo '<td>' . htmlspecialchars((string) ($uc['name'] ?? 'Unknown')) . '</td>'; echo '<td>' . htmlspecialchars($clientName) . '</td>';
echo '<td>' . htmlspecialchars($clientVersion) . '</td>'; echo '<td>' . htmlspecialchars($clientVersion) . '</td>';
echo '<td>' . $statusHtml . '</td>'; echo '<td>' . $statusHtml . '</td>';
echo '<td>' . htmlspecialchars($lastBackup ?: '-') . '</td>'; echo '<td>' . htmlspecialchars($lastBackup ?: '-') . '</td>';
echo '<td>' . htmlspecialchars($clientIp ?: '-') . '</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>'; echo '</tr>';
} }
+6 -11
View File
@@ -37,7 +37,7 @@ class UrbackupApiClient
private string $server_version = ''; private string $server_version = '';
private bool $is_version_2_5_or_higher = false; private bool $is_version_2_4_or_higher = false;
/** /**
* Constructor. * Constructor.
@@ -52,15 +52,10 @@ class UrbackupApiClient
$this->password = (string) ($server->fields['api_password'] ?? ''); $this->password = (string) ($server->fields['api_password'] ?? '');
$this->ignore_ssl = ((int) ($server->fields['ignore_ssl'] ?? 0)) === 1; $this->ignore_ssl = ((int) ($server->fields['ignore_ssl'] ?? 0)) === 1;
$this->server_version = (string) ($server->fields['server_version'] ?? ''); $this->server_version = (string) ($server->fields['server_version'] ?? '');
$this->is_version_2_5_or_higher = $this->detectVersion2_5OrHigher(); $this->is_version_2_4_or_higher = $this->detectVersion2_4OrHigher();
} }
/** private function detectVersion2_4OrHigher(): bool
* Detect if server version is 2.5 or higher.
*
* @return bool
*/
private function detectVersion2_5OrHigher(): bool
{ {
if ($this->server_version === '') { if ($this->server_version === '') {
return false; return false;
@@ -77,7 +72,7 @@ class UrbackupApiClient
if ($major > 2) { if ($major > 2) {
return true; return true;
} }
if ($major === 2 && $minor >= 5) { if ($major === 2 && $minor >= 4) {
return true; return true;
} }
@@ -91,7 +86,7 @@ class UrbackupApiClient
*/ */
public function getInternetModeSettingKey(): string public function getInternetModeSettingKey(): string
{ {
return $this->is_version_2_5_or_higher ? 'internet_mode_enabled' : 'internet_mode'; return $this->is_version_2_4_or_higher ? 'internet_mode_enabled' : 'internet_mode';
} }
/** /**
@@ -391,7 +386,7 @@ class UrbackupApiClient
'sa' => 'clientsettings_save', 'sa' => 'clientsettings_save',
't_clientid' => $client_id, 't_clientid' => $client_id,
'overwrite' => 'true', 'overwrite' => 'true',
$key => $enabled ? '1' : '0', $key => $enabled ? 'true' : 'false',
]; ];
$data = $this->apiAction('settings', $params); $data = $this->apiAction('settings', $params);
-8
View File
@@ -7,14 +7,6 @@
<tr> <tr>
<th colspan="2">{{ __('UrBackup server selection', 'urbackup') }}</th> <th colspan="2">{{ __('UrBackup server selection', 'urbackup') }}</th>
</tr> </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 %} {% if is_sub_location %}
<tr class="tab_bg_1"> <tr class="tab_bg_1">
<td colspan="2"><em> <td colspan="2"><em>