connessione con hardware in assets

This commit is contained in:
test
2026-08-07 14:27:33 +02:00
parent 7c6e244155
commit f575d8cb05
33 changed files with 3489 additions and 1608 deletions
+1 -19
View File
@@ -84,7 +84,7 @@ if (isset($_POST['connect'])) {
}
if (isset($_POST['disconnect'])) {
if (!Profile::canCurrentUser(UPDATE) && !Profile::canCurrentUser(DELETE)) {
if (!Profile::canCurrentUser(UPDATE)) {
Html::displayRightError();
}
@@ -103,24 +103,6 @@ if (isset($_POST['disconnect'])) {
}
}
if (isset($_POST['start_file_backup'])) {
if (!Profile::canCurrentUser(UPDATE)) {
Html::displayRightError();
}
AssetTab::startBackup($item, 'file');
Html::redirect($item->getFormURL());
}
if (isset($_POST['start_image_backup'])) {
if (!Profile::canCurrentUser(UPDATE)) {
Html::displayRightError();
}
AssetTab::startBackup($item, 'image');
Html::redirect($item->getFormURL());
}
if (isset($_POST['execute'])) {
$action = $_POST['urbackup_action'] ?? '';
+42 -6
View File
@@ -4,17 +4,53 @@ declare(strict_types=1);
use GlpiPlugin\Urbackup\Config;
global $CFG_GLPI;
if (!defined('GLPI_ROOT')) {
define('GLPI_ROOT', dirname(__DIR__, 4));
}
include_once GLPI_ROOT . '/inc/includes.php';
// Check user has right to manage plugin configuration
if (!Session::haveRight('config', UPDATE)) {
Html::displayRightError();
}
// Handle form submission
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['update'])) {
Config::saveConfiguration($_POST);
Html::redirect($_SERVER['REQUEST_URI']);
if (($_SERVER['REQUEST_METHOD'] ?? 'GET') === 'POST') {
// CSRF token is validated by the global CheckCsrfListener on every POST.
if (isset($_POST['update'])) {
global $DB;
$enable_computer = (string) ($_POST['enable_computer'] ?? '0') === '1' ? '1' : '0';
$table = Config::getTable();
$iterator = $DB->request([
'FROM' => $table,
'WHERE' => ['name' => 'enable_computer'],
'LIMIT' => 1,
]);
$row = $iterator->current();
$values = [
'value' => $enable_computer,
'date_mod' => $_SESSION['glpi_currenttime'] ?? date('Y-m-d H:i:s'),
];
if ($row === false) {
$values['name'] = 'enable_computer';
$values['date_creation'] = $_SESSION['glpi_currenttime'] ?? date('Y-m-d H:i:s');
$DB->insert($table, $values);
} else {
$DB->update($table, $values, ['name' => 'enable_computer']);
}
Session::addMessageAfterRedirect(
__('Configuration saved.', 'urbackup'),
false,
INFO
);
Html::redirect(Config::getFormURL());
}
}
// Display GLPI header
@@ -30,4 +66,4 @@ $config = new Config();
$config->showForm(1);
// Display GLPI footer
Html::footer();
Html::footer();
+43
View File
@@ -0,0 +1,43 @@
<?php
declare(strict_types=1);
/**
* AJAX endpoint providing the asset dropdown for the "Hardware host"
* field of the UrBackup server form.
*
* Called through Ajax::updateItemOnSelectEvent when the host itemtype
* selection changes. GET only, no state changes are performed.
*/
use GlpiPlugin\Urbackup\Config;
if (!defined('GLPI_ROOT')) {
define('GLPI_ROOT', dirname(__DIR__, 4));
}
include_once GLPI_ROOT . '/inc/includes.php';
Html::header_nocache();
Session::checkLoginUser();
if (($_SERVER['REQUEST_METHOD'] ?? '') !== 'GET') {
http_response_code(405);
exit;
}
$itemtype = (string) ($_GET['itemtype'] ?? '');
if ($itemtype === '' || !class_exists($itemtype) || !Config::isItemtypeEnabled($itemtype)) {
exit;
}
$value = (int) ($_GET['value'] ?? 0);
Dropdown::show($itemtype, [
'name' => 'host_items_id',
'value' => $value,
'entity' => Session::getActiveEntities(),
'display_emptychoice' => true,
]);
+1 -1
View File
@@ -44,7 +44,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
Html::redirect(PLUGIN_URBACKUP_WEB_DIR . "/front/server.php");
}
$ID = $_GET['id'] ?? null;
$ID = (int) ($_GET['id'] ?? 0);
Html::header(
$ID ? __('Edit UrBackup server', 'urbackup') : __('Add UrBackup server', 'urbackup'),
+26 -7
View File
@@ -3,29 +3,48 @@
declare(strict_types=1);
/**
* AJAX endpoint for testing UrBackup API
* AJAX endpoint for testing UrBackup API.
*
* This endpoint updates the server monitoring fields (last_api_status,
* last_api_message, last_api_check), so it requires UPDATE right and
* only accepts POST requests (GET requests must not trigger state changes).
*/
$AJAX_INCLUDE = 1;
use GlpiPlugin\Urbackup\Profile;
use GlpiPlugin\Urbackup\Server;
use GlpiPlugin\Urbackup\UrbackupApiClient;
if (!defined('GLPI_ROOT')) {
define('GLPI_ROOT', dirname(__DIR__, 4));
}
include_once GLPI_ROOT . '/inc/includes.php';
header("Content-Type: application/json; charset=UTF-8");
Html::header_nocache();
Session::checkLoginUser();
if (!Session::haveRight('plugin_urbackup', READ)) {
if (($_SERVER['REQUEST_METHOD'] ?? '') !== 'POST') {
http_response_code(405);
echo json_encode(['success' => false, 'message' => __('Method not allowed', 'urbackup')]);
exit;
}
if (!Profile::canCurrentUser(UPDATE)) {
http_response_code(403);
echo json_encode(['success' => false, 'message' => __('No permission', 'urbackup')]);
exit;
}
$server_id = (int) ($_POST['id'] ?? $_GET['id'] ?? 0);
$server_id = (int) ($_POST['id'] ?? 0);
if ($server_id <= 0) {
echo json_encode(['success' => false, 'message' => __('Invalid server ID', 'urbackup')]);
exit;
}
$server = new GlpiPlugin\Urbackup\Server();
$server = new Server();
if (!$server->getFromDB($server_id)) {
echo json_encode(['success' => false, 'message' => __('Server not found', 'urbackup')]);
@@ -33,7 +52,7 @@ if (!$server->getFromDB($server_id)) {
}
try {
$client = new GlpiPlugin\Urbackup\UrbackupApiClient($server);
$client = new UrbackupApiClient($server);
$result = $client->testConnection();
$server->update([
@@ -46,4 +65,4 @@ try {
echo json_encode($result);
} catch (Throwable $e) {
echo json_encode(['success' => false, 'message' => $e->getMessage()]);
}
}