31 lines
910 B
PHP
31 lines
910 B
PHP
namespace PluginNetconfig\Agent\Task;
|
|
|
|
use PluginNetconfig\Config;
|
|
use Glpi\Toolbox\Encryption;
|
|
use Session;
|
|
|
|
class Backup
|
|
{
|
|
public static function handleReceived(array $input): bool
|
|
{
|
|
if (!Config::canCreate()) return false;
|
|
|
|
$hash = hash('sha256', $input['config']);
|
|
$latest = Config::getLastByDevice($input['device_id']);
|
|
|
|
if ($latest && $latest->fields['config_hash'] === $hash) {
|
|
return true; // Nessuna modifica
|
|
}
|
|
|
|
$config = new Config();
|
|
$data = [
|
|
'networkdevices_id' => $input['device_id'],
|
|
'config_content' => Encryption::encrypt($input['config']),
|
|
'config_hash' => $hash,
|
|
'users_id' => Session::getLoginUserID() ?: 0, // 0 = agent/system
|
|
'created_at' => $_SESSION['glpi_currenttime']
|
|
];
|
|
return $config->add($data) !== false;
|
|
}
|
|
}
|