$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 ' '; } else { $table = new stdClass(); $table->width = '100%'; $table->class = 'databox info_table max_floating_element_size'; $table->data = []; $table->head = []; $table->styleTable = ''; $table->head[0] = "".__('P.').''; $table->head[1] = __('Name'); $table->head[2] = __('Description'); $table->head[3] = __('Target'); $table->head[4] = __('Interval'); $table->head[5] = __('Actions'); $table->align = []; $table->align[5] = 'left'; $i = 0; foreach ($result as $row) { $table->cellclass[$i++][5] = 'table_action_buttons'; $data = []; $sql = sprintf('SELECT id_policy FROM tpolicy_modules_inventory WHERE id = %d', $row['id_policy_module_inventory']); $id_policy = db_get_value_sql($sql); if ($id_policy) { $policy = policies_get_policy($id_policy); $data[0] = ''; $data[0] .= html_print_image('images/policy@svg.svg', true, ['border' => '0', 'title' => $policy['name'], 'class' => 'main_menu_icon invert_filter']); $data[0] .= ''; } else { $data[0] = ''; } $data[1] = ''.$row['name'].''; $data[2] = $row['description']; $data[3] = $row['target']; $data[4] = human_time_description_raw($row['interval']); // Delete module $data[5] = ''; $data[5] .= html_print_image('images/delete.svg', true, ['border' => '0', 'title' => __('Delete'), 'class' => 'main_menu_icon invert_filter']); $data[5] .= '  '; // Update module $data[5] .= ''; $data[5] .= html_print_image('images/edit.svg', true, ['border' => '0', 'title' => __('Update'), 'class' => 'main_menu_icon invert_filter']); $data[5] .= '  '; // Force refresh module $data[5] .= ''; $data[5] .= html_print_image('images/force@svg.svg', true, ['border' => '0', 'title' => __('Force'), 'class' => 'main_menu_icon invert_filter']).''; array_push($table->data, $data); } html_print_table($table); }