$id_agente, 'id_module_inventory' => $id_module_inventory, ] ); if (!$if_exists) { $values = [ 'id_agente' => $id_agente, 'id_module_inventory' => $id_module_inventory, 'target' => $target, 'interval' => $interval, 'username' => $username, 'password' => $password, 'custom_fields' => $custom_fields_enabled && !empty($custom_fields) ? base64_encode(json_encode(io_safe_output($custom_fields), JSON_UNESCAPED_UNICODE)) : '', ]; $result = db_process_sql_insert('tagent_module_inventory', $values); if ($result) { ui_print_success_message(__('Successfully added inventory module')); } else { ui_print_error_message(__('Error adding inventory module')); } } else { ui_print_error_message(__('The inventory of the module already exists')); } // Remove inventory module from agent } else if ($delete_inventory_module) { $result = db_process_sql_delete( 'tagent_module_inventory', ['id_agent_module_inventory' => $delete_inventory_module] ); if ($result) { ui_print_success_message(__('Successfully deleted inventory module')); } else { ui_print_error_message(__('Error deleting inventory module')); } // Update inventory module } else if ($force_inventory_module) { $result = db_process_sql_update('tagent_module_inventory', ['flag' => 1], ['id_agent_module_inventory' => $force_inventory_module]); if ($result) { ui_print_success_message(__('Successfully forced inventory module')); } else { ui_print_error_message(__('Error forcing inventory module')); } // Update inventory module } else if ($update_inventory_module) { $values = [ 'target' => $target, 'interval' => $interval, 'username' => $username, 'password' => $password, 'custom_fields' => $custom_fields_enabled && !empty($custom_fields) ? base64_encode(json_encode(io_safe_output($custom_fields, true), JSON_UNESCAPED_UNICODE)) : '', ]; $result = db_process_sql_update('tagent_module_inventory', $values, ['id_agent_module_inventory' => $id_agent_module_inventory, 'id_agente' => $id_agente]); if ($result) { ui_print_success_message(__('Successfully updated inventory module')); } else { ui_print_error_message(__('Error updating inventory module')); } } // Load inventory module data for updating if ($load_inventory_module) { $sql = 'SELECT * FROM tagent_module_inventory WHERE id_module_inventory = '.$load_inventory_module; $row = db_get_row_sql($sql); if (!empty($row)) { $id_agent_module_inventory = $row['id_agent_module_inventory']; $id_module_inventory = $row['id_module_inventory']; $target = $row['target']; $interval = $row['interval']; $username = $row['username']; $password = io_output_password($row['password']); $custom_fields = []; if (!empty($row['custom_fields'])) { try { $custom_fields = array_map( function ($field) { if ($field['secure']) { $field['value'] = io_output_password($field['value']); } return $field; }, json_decode(base64_decode($row['custom_fields']), true) ); $custom_fields_enabled = true; } catch (Exception $e) { } } } else { ui_print_error_message(__('Inventory module error')); include 'general/footer.php'; return; } } else { $target = $direccion_agente; $interval = (string) SECONDS_1HOUR; $username = ''; $password = ''; $custom_fields_enabled = false; $custom_fields = []; } // Inventory module configuration $form_buttons = ''; if ($load_inventory_module) { $form_buttons .= html_print_input_hidden('id_agent_module_inventory', $id_agent_module_inventory, true); $form_buttons .= html_print_submit_button( __('Update'), 'update_inventory_module', false, ['icon' => 'wand'], true ); } else { $form_buttons .= html_print_submit_button( __('Add'), 'add_inventory_module', false, ['icon' => 'wand'], true ); } echo ui_get_inventory_module_add_form( 'index.php?sec=estado&sec2=godmode/agentes/configurar_agente&tab=inventory&id_agente='.$id_agente, html_print_action_buttons($form_buttons, [], true), $load_inventory_module, $id_os, $target, $interval, $username, $password, $custom_fields_enabled, $custom_fields ); // Inventory module list $sql = sprintf( 'SELECT * FROM tmodule_inventory, tagent_module_inventory WHERE tagent_module_inventory.id_agente = %d AND tmodule_inventory.id_module_inventory = tagent_module_inventory.id_module_inventory ORDER BY name', $id_agente ); $result = db_process_sql($sql); if (db_get_num_rows($sql) == 0) { echo '