diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index 4e4cdd8df1..a378d61632 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,13 @@ +2012-10-25 Vanessa Gil + + * include/functions_reporting.php + include/functions_report.php + operation/reporting/reporting_xml.php + operation/reporting/reporting_viewer.php + godmode/reporting/reporting_builder.item_editor.php + godmode/reporting/reporting_builder.php: Changed XML reports + and added two new types of report. + 2012-10-25 Miguel de Dios * pandoradb_data.sql: fixed the lost fields in the table "tgrupo" diff --git a/pandora_console/godmode/reporting/reporting_builder.item_editor.php b/pandora_console/godmode/reporting/reporting_builder.item_editor.php index ce64fb80cb..6667dbf9b5 100644 --- a/pandora_console/godmode/reporting/reporting_builder.item_editor.php +++ b/pandora_console/godmode/reporting/reporting_builder.item_editor.php @@ -339,6 +339,12 @@ switch ($action) { $inventory_modules = $es['inventory_modules']; $id_agents = $es['id_agents']; break; + case 'agent_configuration': + $idAgent = $item['id_agent']; + break; + case 'group_configuration': + $group = $item['id_group']; + break; } //Restore db connection @@ -1797,6 +1803,12 @@ function chooseType() { break; case 'inventory_changes': break; + case 'agent_configuration': + $("#row_agent").show(); + break; + case 'group_configuration': + $("#row_group").show(); + break; } } - \ No newline at end of file + diff --git a/pandora_console/godmode/reporting/reporting_builder.php b/pandora_console/godmode/reporting/reporting_builder.php index 2aa0f92cae..49d137c500 100644 --- a/pandora_console/godmode/reporting/reporting_builder.php +++ b/pandora_console/godmode/reporting/reporting_builder.php @@ -663,7 +663,7 @@ switch ($action) { $values['id_agent_module'] = ''; if (isset($values['type'])) { - if (($values['type'] == 'alert_report_agent') or ($values['type'] == 'event_report_agent')) + if (($values['type'] == 'alert_report_agent') or ($values['type'] == 'event_report_agent') or ($values['type'] == 'agent_configuration') or ($values['type'] == 'group_configuration')) $values['id_agent_module'] = ''; else $values['id_agent_module'] = get_parameter('id_agent_module'); @@ -807,6 +807,14 @@ switch ($action) { $values['external_source'] = json_encode($es); $good_format = true; break; + case 'agent_configuration': + $values['id_agent'] = get_parameter('id_agent'); + $good_format = true; + break; + case 'group_configuration': + $values['id_group'] = get_parameter('id_group'); + $good_format = true; + break; default: $values['period'] = get_parameter('period'); $values['top_n'] = get_parameter('radiobutton_max_min_avg',0); @@ -817,7 +825,7 @@ switch ($action) { $values['id_agent'] = get_parameter('id_agent'); $values['id_gs'] = get_parameter('id_custom_graph'); - if (($values['type'] == 'alert_report_agent') or ($values['type'] == 'event_report_agent')) + if (($values['type'] == 'alert_report_agent') or ($values['type'] == 'event_report_agent') or ($values['type'] == 'agent_configuration') or ($values['type'] == 'group_configuration')) $values['id_agent_module'] = ''; else $values['id_agent_module'] = get_parameter('id_agent_module'); @@ -1329,4 +1337,4 @@ switch ($activeTab) { reporting_enterprise_select_tab($activeTab); break; } -?> \ No newline at end of file +?> diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index c2fb5f8149..ac3db3722d 100644 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -4474,6 +4474,274 @@ function reporting_render_report_html_item ($content, $table, $report, $mini = f array_push ($table->data, $data); break; + case 'agent_configuration': + + reporting_header_content($mini, $content, $report, $table, __('Agent configuration: ').$agent_name); + + $agent_name = agents_get_name ($content['id_agent']); + $modules = agents_get_modules ($content['id_agent']); + + $data= array (); + $table->colspan[0][1] = 9; + + //Agent's data + $data[0] = ''.__('Agent name').''; + $data[1] = ''.__('Group').''; + $data[2] = ''.__('SO').''; + $data[3] = ''.__('IP').''; + $data[4] = ''.__('Description').''; + $data[5] = ''.__('Status').''; + + $table->colspan[1][1] = 2; + $table->colspan[1][2] = 2; + $table->colspan[1][4] = 3; + + array_push ($table->data, $data); + unset($data); + + $sql = "SELECT * FROM tagente WHERE id_agente=".$content['id_agent']; + $agent_data = db_get_row_sql($sql); + + $data[0] = $agent_data['nombre']; + $data[1] = ui_print_group_icon ($agent_data['id_grupo'], true, '', '', false); + $data[2] = ui_print_os_icon ($agent_data["id_os"], true, true); + $data[3] = $agent_data['direccion']; + $data[4] = $agent_data['comentarios']; + + if ($agent_data['disabled'] == 0) + $data[5] = __('Enabled'); + else + $data[5] = __('Disabled'); + + $table->colspan[2][1] = 2; + $table->colspan[2][2] = 2; + $table->colspan[2][4] = 3; + array_push ($table->data, $data); + unset($data); + + //Agent's modules + $data[0] = ''.agents_get_name ($content['id_agent'], 'upper').__(' MODULES').''; + $data[1] = ''; + $table->colspan[3][1] = 9; + + array_push ($table->data, $data); + unset($data); + + if ($modules == null) { + $modules = array(); + } else { + $data[0] = ''.__('Name').''; + $data[1] = ''.__('Type').''; + $data[2] = ''.__('Warning/Critical').''; + $data[3] = ''.__('Threshold').''; + $data[4] = ''.__('Group').''; + $data[5] = ''.__('Description').''; + $data[6] = ''.__('Interval').''; + $data[7] = ''.__('Unit').''; + $data[8] = ''.__('Status').''; + $data[9] = ''.__('Tags').''; + + $table->style[0] = 'text-align: left'; + $table->style[1] = 'text-align: center'; + $table->style[2] = 'text-align: center'; + $table->style[3] = 'text-align: center'; + $table->style[4] = 'text-align: center'; + $table->style[5] = 'text-align: left'; + $table->style[6] = 'text-align: center'; + $table->style[7] = 'text-align: center'; + $table->style[8] = 'text-align: left'; + $table->style[9] = 'text-align: left'; + + array_push ($table->data, $data); + } + + foreach ($modules as $id_agent_module=>$module) { + $sql = "SELECT * FROM tagente_modulo WHERE id_agente_modulo=$id_agent_module"; + $data_module = db_get_row_sql($sql); + + $data = array(); + + if ($data_module['disabled'] == 0) + $disabled = ''; + else + $disabled = ' (Disabled)'; + $data[0] = $data_module['nombre'].$disabled; + $data[1] = ui_print_moduletype_icon ($data_module['id_tipo_modulo'], true); + $data[2] = $data_module['max_warning'].'/'.$data_module['min_warning'].' - '.$data_module['max_critical'].'/'.$data_module['min_critical']; + $data[3] = $data_module['module_ff_interval']; + $data[4] = groups_get_name ($content['id_group'], true); + $data[5] = $data_module['descripcion']; + + if (($data_module['module_interval'] == 0) || ($data_module['module_interval'] == '')) + $data[6] = db_get_value('intervalo', 'tagente', 'id_agente', $content['id_agent']); + else + $data[6] = $data_module['module_interval']; + + + $data[7] = $data_module['unit']; + + $module_status = db_get_row('tagente_estado', 'id_agente_modulo', $id_agent_module); + modules_get_status($id_agent_module, $module_status['estado'], $module_status['datos'], $status, $title); + $data[8] = ui_print_status_image($status, $title, true); + + $sql_tag = "SELECT name FROM ttag WHERE id_tag IN ( + SELECT id_tag FROM ttag_module + WHERE id_agente_modulo=$id_agent_module)"; + $tags = db_get_all_rows_sql($sql_tag); + if ($tags === false) + $tags = ''; + else + $tags = implode (",", $tags); + + $data[9] = $tags; + array_push ($table->data, $data); + } + + break; + case 'group_configuration': + $group_name = groups_get_name($content['id_group']); + reporting_header_content($mini, $content, $report, $table, __('Group configuration: ').$group_name); + + $sql = "SELECT * FROM tagente WHERE id_grupo=".$content['id_group']; + $agents_list = db_get_all_rows_sql($sql); + if ($agents_list === false) + $agents_list = array(); + + $table->colspan[0][1] = 9; + + $i = 1; + foreach ($agents_list as $agent) { + $data= array (); + + $table->colspan[$i][1] = 2; + $table->colspan[$i][2] = 2; + $table->colspan[$i][4] = 3; + $i++; + + //Agent's data + $data[0] = ''.__('Agent name').''; + $data[1] = ''.__('Group').''; + $data[2] = ''.__('SO').''; + $data[3] = ''.__('IP').''; + $data[4] = ''.__('Description').''; + $data[5] = ''.__('Status').''; + + array_push ($table->data, $data); + unset($data); + + $sql = "SELECT * FROM tagente WHERE id_agente=".$agent['id_agente']; + $agent_data = db_get_row_sql($sql); + + $data[0] = $agent_data['nombre']; + $data[1] = ui_print_group_icon ($agent_data['id_grupo'], true, '', '', false); + $data[2] = ui_print_os_icon ($agent_data["id_os"], true, true); + $data[3] = $agent_data['direccion']; + $data[4] = $agent_data['comentarios']; + + if ($agent_data['disabled'] == 0) + $data[5] = __('Enabled'); + else + $data[5] = __('Disabled'); + + $table->colspan[$i][1] = 2; + $table->colspan[$i][2] = 2; + $table->colspan[$i][4] = 3; + $i++; + + array_push ($table->data, $data); + unset($data); + + + + $modules = agents_get_modules ($agent['id_agente']); + + if ($modules == null) { + $modules = array(); + } else { + + //Agent's modules + $data[0] = ''.agents_get_name ($agent['id_agente'], 'upper').__(' MODULES').''; + $data[1] = ''; + $table->colspan[$i][1] = 9; + + $i++; + + array_push ($table->data, $data); + unset($data); + + $data[0] = ''.__('Name').''; + $data[1] = ''.__('Type').''; + $data[2] = ''.__('Warning/Critical').''; + $data[3] = ''.__('Threshold').''; + $data[4] = ''.__('Group').''; + $data[5] = ''.__('Description').''; + $data[6] = ''.__('Interval').''; + $data[7] = ''.__('Unit').''; + $data[8] = ''.__('Status').''; + $data[9] = ''.__('Tags').''; + + $table->style[0] = 'text-align: left'; + $table->style[1] = 'text-align: center'; + $table->style[2] = 'text-align: center'; + $table->style[3] = 'text-align: center'; + $table->style[4] = 'text-align: center'; + $table->style[5] = 'text-align: left'; + $table->style[6] = 'text-align: center'; + $table->style[7] = 'text-align: center'; + $table->style[8] = 'text-align: left'; + $table->style[9] = 'text-align: left'; + + array_push ($table->data, $data); + + $i++; + } + + foreach ($modules as $id_agent_module=>$module) { + $sql = "SELECT * FROM tagente_modulo WHERE id_agente_modulo=$id_agent_module"; + $data_module = db_get_row_sql($sql); + + $data = array(); + + if ($data_module['disabled'] == 0) + $disabled = ''; + else + $disabled = ' (Disabled)'; + $data[0] = $data_module['nombre'].$disabled; + $data[1] = ui_print_moduletype_icon ($data_module['id_tipo_modulo'], true); + $data[2] = $data_module['max_warning'].'/'.$data_module['min_warning'].' - '.$data_module['max_critical'].'/'.$data_module['min_critical']; + $data[3] = $data_module['module_ff_interval']; + $data[4] = groups_get_name ($content['id_group'], true); + $data[5] = $data_module['descripcion']; + + if (($data_module['module_interval'] == 0) || ($data_module['module_interval'] == '')) + $data[6] = db_get_value('intervalo', 'tagente', 'id_agente', $content['id_agent']); + else + $data[6] = $data_module['module_interval']; + + + $data[7] = $data_module['unit']; + + $module_status = db_get_row('tagente_estado', 'id_agente_modulo', $id_agent_module); + modules_get_status($id_agent_module, $module_status['estado'], $module_status['datos'], $status, $title); + $data[8] = ui_print_status_image($status, $title, true); + + $sql_tag = "SELECT name FROM ttag WHERE id_tag IN ( + SELECT id_tag FROM ttag_module + WHERE id_agente_modulo=$id_agent_module)"; + $tags = db_get_all_rows_sql($sql_tag); + if ($tags === false) + $tags = ''; + else + $tags = implode (",", $tags); + + $data[9] = $tags; + array_push ($table->data, $data); + + $i++; + } + + } + break; } //Restore dbconnection if (($config ['metaconsole'] == 1) && $server_name != '' && defined('METACONSOLE')) { diff --git a/pandora_console/include/functions_reports.php b/pandora_console/include/functions_reports.php index 3a0beea6b7..06c9056ca5 100644 --- a/pandora_console/include/functions_reports.php +++ b/pandora_console/include/functions_reports.php @@ -592,6 +592,11 @@ function reports_get_report_types ($template = false) { 'name' => __('Inventory changes')); } + $types['agent_configuration'] = array('optgroup' => __('Configuration'), + 'name' => __('Agent configuration')); + $types['group_configuration'] = array('optgroup' => __('Configuration'), + 'name' => __('Group configuration')); + return $types; } -?> \ No newline at end of file +?> diff --git a/pandora_console/operation/reporting/reporting_viewer.php b/pandora_console/operation/reporting/reporting_viewer.php index 4d10c5da4f..5108987d01 100644 --- a/pandora_console/operation/reporting/reporting_viewer.php +++ b/pandora_console/operation/reporting/reporting_viewer.php @@ -285,4 +285,4 @@ $(document).ready (function () { } }); }); - \ No newline at end of file + diff --git a/pandora_console/operation/reporting/reporting_xml.php b/pandora_console/operation/reporting/reporting_xml.php index 479286d5c2..861ea90d60 100644 --- a/pandora_console/operation/reporting/reporting_xml.php +++ b/pandora_console/operation/reporting/reporting_xml.php @@ -18,8 +18,15 @@ include_once("include/functions_events.php"); include_once ('include/functions_groups.php'); enterprise_include_once ('include/functions_metaconsole.php'); -function xml_array ($array) { - foreach ($array as $name => $value) { +function xml_array ($array, $buffer_file = array()) { + + foreach ($array as $name => $value) { + //si coincide con el nivel de anidaciĆ³n y existe el fichero + $file_to_print = false; + if(isset($buffer_file[$name]) && file_exists($buffer_file[$name])) { + $file_to_print = $buffer_file[$name]; + } + if (is_int ($name)) { echo ""; $name = "object"; @@ -27,9 +34,18 @@ function xml_array ($array) { else { echo "<".$name.">"; } - + if (is_array ($value)) { - xml_array ($value); + //si es la ruta al fichero que contiene el xml + if(is_string($file_to_print)) { + $file = fopen($file_to_print, 'r'); + while (!feof($file)) { + $buffer = fgets($file); + echo "$buffer"; + } + $file_to_print = false; + } + xml_array ($value, $file_to_print); } else { echo $value; @@ -39,6 +55,136 @@ function xml_array ($array) { } } +function write_xml_file_agent_data ($agent_data = array(), $file_temp) { + + $file = fopen($file_temp, 'a+'); + + $content_report = " ". $agent_data['nombre']."\n"; + $content_report .= " ". $agent_data['comentarios']."\n"; + $content_report .= " ".$agent_data['direccion']."\n"; + $content_report .= " ".$agent_data['id_grupo']."\n"; + $content_report .= " ". $agent_data['intervalo']."\n"; + $content_report .= " ".$agent_data['id_os']."\n"; + $content_report .= " ". agents_get_name ($agent_data['id_parent'])."\n"; + $content_report .= " ".$agent_data['id_extra']."\n"; + $content_report .= " ".$agent_data['disabled']."\n"; + + $result = fwrite($file, $content_report); + $position++; + + fclose($file); + return $position; +} + +function write_xml_file_agent_conf ($modules = array(), $file_temp, $position = 0, $id_agent) { + + $file = fopen($file_temp, 'a+'); + + foreach ($modules as $module) { + + $content_report = " \n"; + + $content_report .= " ".$module['nombre']."\n"; + $content_report .= " ".$module['id_agente_modulo']."\n"; + $content_report .= " ".$module['id_tipo_modulo']."\n"; + $content_report .= " ".$module['descripcion']."\n"; + $content_report .= " ". $module['extended_info']."\n"; + $content_report .= " ". $module['unit']."\n"; + $content_report .= " ". $module['max']."\n"; + $content_report .= " ".$module['min']."\n"; + $content_report .= " ". $module['module_interval']."\n"; + $content_report .= " ". $module['module_ff_interval']."\n"; + $content_report .= " ". $module['tcp_port']."\n"; + $content_report .= " ". $module['tcp_send']."\n"; + $content_report .= " ". $module['tcp_rcv']."\n"; + $content_report .= " ". $module['snmp_community']."\n"; + $content_report .= " ".$module['snmp_oid']."\n"; + $content_report .= " ". $module['ip_target']."\n"; + $content_report .= " ".$module['id_module_group']."\n"; + $content_report .= " ". $module['disabled']."\n"; + $content_report .= " ".$module['id_plugin']."\n"; + $content_report .= " ". $module['post_process']."\n"; + $content_report .= " ". $module['min_warning']."\n"; + $content_report .= " ". $module['max_warning']."\n"; + $content_report .= " ". $module['str_warning']."\n"; + $content_report .= " ". $module['min_critical']."\n"; + $content_report .= " ".$module['max_critical']."\n"; + $content_report .= " ". $module['str_critical']."\n"; + $content_report .= " ". $module['id_policy_module']."\n"; + $content_report .= " ".$module['wizard_level']."\n"; + $content_report .= " ". $module['critical_instructions']."\n"; + $content_report .= " ". $module['warning_instructions']."\n"; + $content_report .= " ".$module['unknown_instructions']."\n"; + + $content_report .= " \n"; + + $result = fwrite($file, $content_report); + $position++; + } + fclose($file); + return $position; +} + +function write_xml_file_event ($events = array(), $file_temp, $position = 0, $id_agent) { + + $file = fopen($file_temp, 'a+'); + + foreach ($events as $event) { + + $content_report = " \n"; + $content_report .= " ".$event['evento']."\n"; + $content_report .= " ".$event['event_type']."\n"; + $content_report .= " ".get_priority_name($event['criticity'])."\n"; + $content_report .= " ".$event['count_rep']."\n"; + $content_report .= " ".$event['time2']."\n"; + $content_report .= " ".modules_get_agentmodule_name ($event['id_agentmodule'])."\n"; + $content_report .= " ".agents_get_name ($id_agent)."\n"; + + if ($event['estado'] == 0) + $status = __('New'); + else if ($event['estado'] == 1) + $status = __('Validated'); + else if ($event['estado'] == 2) + $status = __('In process'); + else + $status = ""; + + $content_report .= " ".$status."\n"; + $content_report .= " ".$event['user_comment']."\n"; + $content_report .= " ".$event['tags']."\n"; + $content_report .= " ".$event['source']."\n"; + $content_report .= " ".$event['id_extra']."\n"; + $content_report .= " ".$event['owner_user']."\n"; + $content_report .= " \n"; + + $result = fwrite($file, $content_report); + $position++; + + } + fclose($file); + return $position; +} + +function write_xml_file_graph ($data_module = array(), $file_temp, $position = 0) { + + $file = fopen($file_temp, 'a+'); + + foreach ($data_module as $data_m) { + + $content_report = " \n"; + $content_report .= " ".date ('Y-m-d H:i:s', $data_m['utimestamp'])."\n"; + $content_report .= " ".$data_m['utimestamp']."\n"; + $content_report .= " ".$data_m['datos']."\n"; + $content_report .= " \n"; + + $result = fwrite($file, $content_report); + $position++; + } + + fclose($file); + return $position; +} + // Login check if (isset ($_GET["direct"])) { /* @@ -190,7 +336,7 @@ foreach ($contents as $content) { $data["period"] = human_time_description_raw ($content['period']); $data["uperiod"] = $content['period']; $data["type"] = $content["type"]; - + // Support for metaconsole $server_name = $content ['server_name']; @@ -206,54 +352,136 @@ foreach ($contents as $content) { case 1: case 'simple_graph': - + $data["module"] = io_safe_output_xml (db_get_value ('nombre', 'tagente_modulo', 'id_agente_modulo', $content['id_agent_module'])); $data["agent"] = io_safe_output_xml (modules_get_agentmodule_agent_name ($content['id_agent_module'])); $data["title"] = __('Simple graph'); - + $data["objdata"] = array(); + $date_end = time(); $date_init = $date_end - $content['period']; + /// + $temp_file = $config['attachment_store'] . '/simple_graph_' . $time.'_'.$content['id_rc'] . '.tmp'; - $sql = "SELECT * FROM tagente_datos WHERE id_agente_modulo=".$content['id_agent_module']." + $file = fopen ($temp_file, 'a+'); + + $buffer_file["objdata"] = $config['attachment_store'] . '/simple_graph_' . $time.'_'.$content['id_rc'] . '.tmp'; + + $limit = 1000; + $offset = 0; + + $sql_count = "SELECT COUNT(id_agente_modulo) FROM tagente_datos WHERE id_agente_modulo=".$content['id_agent_module']." AND (utimestamp>=$date_init AND utimestamp<=$date_end)"; + $data_count = db_get_value_sql($sql_count); - $data_module = db_get_all_rows_sql($sql); - if ($data_module === false) { - $data_module = array(); + if ($data_count == false) { + $content_report = " \n"; + $result = fwrite($file, $content_report); + fclose($file); + } else if ($data_count <= $limit) { + $content_report = " \n"; + $result = fwrite($file, $content_report); + fclose($file); + + $sql = "SELECT * FROM tagente_datos WHERE id_agente_modulo=".$content['id_agent_module']." + AND (utimestamp>=$date_init AND utimestamp<=$date_end)"; + + $data_module = db_get_all_rows_sql($sql); + write_xml_file_graph ($data_module, $temp_file); + + $file = fopen ($temp_file, 'a+'); + $content_report = " \n"; + $result = fwrite($file, $content_report); + + + } else { + $content_report = " \n"; + $result = fwrite($file, $content_report); + fclose($file); + + $position = 0; + while ($offset < $data_count) { + + $sql = "SELECT * FROM tagente_datos WHERE id_agente_modulo=".$content['id_agent_module']." + AND (utimestamp>=$date_init AND utimestamp<=$date_end) LIMIT $offset,$limit"; + $data_module = db_get_all_rows_sql($sql); + + $position = write_xml_file_graph ($data_module, $temp_file, $position); + $offset += $limit; + } + + $file = fopen ($temp_file, 'a+'); + $content_report = " \n"; + $result = fwrite($file, $content_report); + fclose($file); } - $i = 0; - foreach ($data_module as $data_m) { - $data["objdata"][$content['type']][$i]["timestamp"] = date ('Y-m-d H:i:s', $data_m['utimestamp']); - $data["objdata"][$content['type']][$i]["utimestamp"] = $data_m['utimestamp']; - $data["objdata"][$content['type']][$i]["data"] = $data_m['datos']; - $i++; - } + /// break; case 'simple_baseline_graph': $data["module"] = io_safe_output_xml (db_get_value ('nombre', 'tagente_modulo', 'id_agente_modulo', $content['id_agent_module'])); - $data["agent"] = io_safe_output_xml (modules_get_agentmodule_agent_name ($content['id_agent_module'])); - + $data["agent"] = io_safe_output_xml (modules_get_agentmodule_agent_name ($content['id_agent_module'])); $data["title"] = __('Simple baseline graph'); + $data["objdata"] = array(); $date_end = time(); $date_init = $date_end - $content['period']; + /// + $temp_file = $config['attachment_store'] . '/simple_baseline_graph_' . $time.'_'.$content['id_rc'] . '.tmp'; - $sql = "SELECT * FROM tagente_datos WHERE id_agente_modulo=".$content['id_agent_module']." + $file = fopen ($temp_file, 'a+'); + + $buffer_file["objdata"] = $config['attachment_store'] . '/simple_baseline_graph_' . $time.'_'.$content['id_rc'] . '.tmp'; + + $limit = 1000; + $offset = 0; + + $sql_count = "SELECT COUNT(id_agente_modulo) FROM tagente_datos WHERE id_agente_modulo=".$content['id_agent_module']." AND (utimestamp>=$date_init AND utimestamp<=$date_end)"; + $data_count = db_get_value_sql($sql_count); - $data_module = db_get_all_rows_sql($sql); - if ($data_module === false) { - $data_module = array(); + if ($data_count == false) { + $content_report = " \n"; + $result = fwrite($file, $content_report); + } else if ($data_count <= $limit) { + $content_report = " \n"; + $result = fwrite($file, $content_report); + fclose($file); + + $sql = "SELECT * FROM tagente_datos WHERE id_agente_modulo=".$content['id_agent_module']." + AND (utimestamp>=$date_init AND utimestamp<=$date_end)"; + + $data_module = db_get_all_rows_sql($sql); + write_xml_file_graph ($data_module, $temp_file); + + $file = fopen ($temp_file, 'a+'); + $content_report = " \n"; + $result = fwrite($file, $content_report); + fclose($file); + + } else { + $content_report = " \n"; + $result = fwrite($file, $content_report); + fclose($file); + + $position = 0; + while ($offset < $data_count) { + + $sql = "SELECT * FROM tagente_datos WHERE id_agente_modulo=".$content['id_agent_module']." + AND (utimestamp>=$date_init AND utimestamp<=$date_end) LIMIT $offset,$limit"; + $data_module = db_get_all_rows_sql($sql); + + $position = write_xml_file_graph ($data_module, $temp_file, $position); + $offset += $limit; + } + + $file = fopen ($temp_file, 'a+'); + $content_report = " \n"; + $result = fwrite($file, $content_report); + fclose($file); } - $i = 0; - foreach ($data_module as $data_m) { - $data["objdata"][$content['type']][$i]["timestamp"] = date ('Y-m-d H:i:s', $data_m['utimestamp']); - $data["objdata"][$content['type']][$i]["utimestamp"] = $data_m['utimestamp']; - $data["objdata"][$content['type']][$i]["data"] = $data_m['datos']; - $i++; - } + /// break; case 2: case 'custom_graph': @@ -263,7 +491,7 @@ foreach ($contents as $content) { $graph = db_get_row ("tgraph", "id_graph", $content['id_gs']); $data["title"] = __('Custom graph'); - $data["objdata"]["img_name"] = $graph["name"]; + $data["objdata"] = array(); $result = db_get_all_rows_field_filter ("tgraph_source","id_graph",$content['id_gs']); $modules = array (); @@ -280,21 +508,61 @@ foreach ($contents as $content) { $date_end = time(); $date_init = $date_end - $content['period']; + /// + $temp_file = $config['attachment_store'] . '/custom_graph_' . $time.'_'.$content['id_rc'] . '.tmp'; - $sql = "SELECT * FROM tagente_datos WHERE id_agente_modulo=".$content['id_agent_module']." + $file = fopen ($temp_file, 'a+'); + + $buffer_file["objdata"] = $config['attachment_store'] . '/custom_graph_' . $time.'_'.$content['id_rc'] . '.tmp'; + + $limit = 1000; + $offset = 0; + + $sql_count = "SELECT COUNT(id_agente_modulo) FROM tagente_datos WHERE id_agente_modulo=".$content2['id_agent_module']." AND (utimestamp>=$date_init AND utimestamp<=$date_end)"; + $data_count = db_get_value_sql($sql_count); - $data_module = db_get_all_rows_sql($sql); - if ($data_module === false) { - $data_module = array(); + if ($data_count == false) { + $content_report = " \n"; + $result = fwrite($file, $content_report); + fclose($file); + } else if ($data_count <= $limit) { + $content_report = " \n"; + $result = fwrite($file, $content_report); + fclose($file); + + $sql = "SELECT * FROM tagente_datos WHERE id_agente_modulo=".$content2['id_agent_module']." + AND (utimestamp>=$date_init AND utimestamp<=$date_end)"; + + $data_module = db_get_all_rows_sql($sql); + write_xml_file_graph ($data_module, $temp_file); + + $file = fopen ($temp_file, 'a+'); + $content_report = " \n"; + $result = fwrite($file, $content_report); + + } else { + $content_report = " \n"; + $result = fwrite($file, $content_report); + fclose($file); + + $position = 0; + while ($offset < $data_count) { + + $sql = "SELECT * FROM tagente_datos WHERE id_agente_modulo=".$content['id_agent_module']." + AND (utimestamp>=$date_init AND utimestamp<=$date_end) LIMIT $offset,$limit"; + $data_module = db_get_all_rows_sql($sql); + + $position = write_xml_file_graph ($data_module, $temp_file, $position); + $offset += $limit; + } + + $file = fopen ($temp_file, 'a+'); + $content_report = " \n"; + $result = fwrite($file, $content_report); + fclose($file); } - $i = 0; - foreach ($data_module as $data_m) { - $data["objdata"][$content['type']][$i]["timestamp"] = date ('Y-m-d H:i:s', $data_m['utimestamp']); - $data["objdata"][$content['type']][$i]["utimestamp"] = $data_m['utimestamp']; - $data["objdata"][$content['type']][$i]["data"] = $data_m['datos']; - $i++; - } + /// break; case 3: case 'SLA': @@ -419,43 +687,76 @@ foreach ($contents as $content) { case 'agent_detailed_event': case 'event_report_agent': $data["title"] = __('Agent detailed event'); - - $data["objdata"]["event_report_agent"] = array (); + $data["objdata"] = array (); $date = get_system_time (); - - $events = events_get_agent ($content['id_agent'], $content['period'], $date ); - if (empty ($events)) { - $events = array (); - } - - foreach ($events as $event) { - $objdata = array (); - $objdata['event'] = $event['evento']; - $objdata['event_type'] = $event['event_type']; - $objdata['criticity'] = get_priority_name($event['criticity']); - $objdata['count'] = $event['count_rep']; - $objdata['timestamp'] = $event['time2']; - $objdata['module_name'] = modules_get_agentmodule_name ($event['id_agentmodule']); - $objdata['agent_name'] = agents_get_name ($content['id_agent']); + /// + $temp_file = $config['attachment_store'] . '/event_report_agent_' . $time.'_'.$content['id_rc'] . '.tmp'; + $file = fopen ($temp_file, 'a+'); + $buffer_file["objdata"] = $config['attachment_store'] . '/event_report_agent_' . $time.'_'.$content['id_rc'] . '.tmp'; + + $limit = 1000; + $offset = 0; + + $datelimit = $date - $content['period']; + + $sql_count = "SELECT count(*) FROM (SELECT count(*) + FROM tevento + WHERE id_agente =".$content['id_agent']." AND utimestamp > $datelimit AND utimestamp <= $date + GROUP BY id_agentmodule, evento) t1"; + $data_count = db_get_value_sql($sql_count); + + if ($data_count == false) { + $content_report = " \n"; + $result = fwrite($file, $content_report); + fclose($file); + } else if ($data_count <= $limit) { + $content_report = " \n"; + $result = fwrite($file, $content_report); + fclose($file); - if ($event['estado'] == 0) - $status = __('New'); - else if ($event['estado'] == 1) - $status = __('Validated'); - else if ($event['estado'] == 2) - $status = __('In process'); - else - $status = ""; + $sql = sprintf ('SELECT evento, event_type, criticity, count(*) as count_rep, + max(timestamp) AS time2, id_agentmodule, estado, user_comment, tags, source, id_extra, owner_user + FROM tevento + WHERE id_agente = %d AND utimestamp > %d AND utimestamp <= %d + GROUP BY id_agentmodule, evento + ORDER BY time2 DESC', $content['id_agent'], $datelimit, $date); + + $events = db_get_all_rows_sql ($sql); + write_xml_file_event ($events, $temp_file,0, $content['id_agent']); + + $file = fopen ($temp_file, 'a+'); + $content_report = " \n"; + $result = fwrite($file, $content_report); + + + } else { + $content_report = " \n"; + $result = fwrite($file, $content_report); + fclose($file); + + $position = 0; + while ($offset < $data_count) { - $objdata['event_status'] = $status; - $objdata['user_comment'] = $event['user_comment']; - $objdata['tags'] = $event['tags']; - $objdata['event_source'] = $event['source']; - $objdata['extra_id'] = $event['id_extra']; - $objdata['user_validation'] = $event['owner_user']; - array_push ($data["objdata"]["event_report_agent"], $objdata); + $sql = sprintf ('SELECT evento, event_type, criticity, count(*) as count_rep, + max(timestamp) AS time2, id_agentmodule, estado, user_comment, tags, source, id_extra, owner_user + FROM tevento + WHERE id_agente = %d AND utimestamp > %d AND utimestamp <= %d + GROUP BY id_agentmodule, evento + ORDER BY time2 DESC LIMIT %d,%d', $content['id_agent'], $datelimit, $date, $offset,$limit); + + $events = db_get_all_rows_sql ($sql); + + $position = write_xml_file_event ($events, $temp_file, $position, $content['id_agent']); + $offset += $limit; + } + + $file = fopen ($temp_file, 'a+'); + $content_report = " \n"; + $result = fwrite($file, $content_report); + fclose($file); } + /// break; case 'text': $data["title"] = __('Text'); @@ -516,101 +817,146 @@ foreach ($contents as $content) { case 'event_report_group': $data["title"] = __('Group detailed event'); $data['group'] = groups_get_name($content['id_group'], true); - $data["objdata"]["event_report_group"] = array(); + $data["objdata"] = array(); $id_group = groups_safe_acl ($config["id_user"], $content['id_group'], "AR"); - + /// if (!empty ($id_group)) { + //An empty array means the user doesn't have access $datelimit = $report["datetime"] - $content['period']; - $sql = sprintf ('SELECT * FROM tevento + $sql_count = sprintf ('SELECT count(*) FROM tevento WHERE utimestamp > %d AND utimestamp <= %d AND id_grupo IN (%s) ORDER BY utimestamp ASC', $datelimit, $report["datetime"], implode (",", $id_group)); - - $events = db_get_all_rows_sql($sql); - if ($events === false) { - $events = array(); - } - } else { - $events = array(); - } - - foreach ($events as $event) { - $objdata = array(); - - $objdata['event'] = $event['evento']; - $objdata['event_type'] = $event['event_type']; - $objdata['criticity'] = get_priority_name($event['criticity']); - $objdata['timestamp'] = $event['timestamp']; - $objdata['module_name'] = modules_get_agentmodule_name ($event['id_agentmodule']); - $objdata['agent_name'] = agents_get_name ($content['id_agent']); - - if ($event['estado'] == 0) - $status = __('New'); - else if ($event['estado'] == 1) - $status = __('Validated'); - else if ($event['estado'] == 2) - $status = __('In process'); - else - $status = ""; - $objdata['event_status'] = $status; - $objdata['user_comment'] = $event['user_comment']; - $objdata['tags'] = $event['tags']; - $objdata['event_source'] = $event['source']; - $objdata['extra_id'] = $event['id_extra']; - $objdata['user_validation'] = $event['owner_user']; + $data_count = db_get_value_sql($sql_count); + + $temp_file = $config['attachment_store'] . '/event_report_group_' . $time.'_'.$content['id_rc'] . '.tmp'; + $file = fopen ($temp_file, 'a+'); + $buffer_file["objdata"] = $config['attachment_store'] . '/event_report_group_' . $time.'_'.$content['id_rc'] . '.tmp'; - array_push($data["objdata"]["event_report_group"], $objdata); + $limit = 1000; + $offset = 0; + + if ($data_count == false) { + $content_report = " \n"; + $result = fwrite($file, $content_report); + fclose($file); + } else if ($data_count <= $limit) { + $content_report = " \n"; + $result = fwrite($file, $content_report); + fclose($file); + + $sql = sprintf ('SELECT * FROM tevento + WHERE utimestamp > %d AND utimestamp <= %d + AND id_grupo IN (%s) + ORDER BY utimestamp ASC', + $datelimit, $report["datetime"], implode (",", $id_group)); + $events = db_get_all_rows_sql($sql); + write_xml_file_event ($events, $temp_file, 0, $content['id_agent']); + + $file = fopen ($temp_file, 'a+'); + $content_report = " \n"; + $result = fwrite($file, $content_report); + + } else { + $content_report = " \n"; + $result = fwrite($file, $content_report); + fclose($file); + + $position = 0; + while ($offset < $data_count) { + + $sql = sprintf ('SELECT * FROM tevento + WHERE utimestamp > %d AND utimestamp <= %d + AND id_grupo IN (%s) + ORDER BY utimestamp ASC LIMIT %d,%d', + $datelimit, $report["datetime"], implode (",", $id_group), $offset,$limit); + + $events = db_get_all_rows_sql($sql); + + $position = write_xml_file_event ($events, $temp_file, $position, $content['id_agent']); + $offset += $limit; + } + + $file = fopen ($temp_file, 'a+'); + $content_report = " \n"; + $result = fwrite($file, $content_report); + fclose($file); + } } + /// break; case 'event_report_module': + $data["title"] = __('Agents detailed event'); - $data["objdata"]["event_report_module"] = array(); + $data["objdata"] = array(); - $datelimit = $report["datetime"] - $content['period']; + $date = get_system_time (); + $datelimit = $date - $content['period']; + /// + $sql_count = "SELECT count(*) FROM (SELECT count(*) + FROM tevento + WHERE id_agente =".$content['id_agent']." AND utimestamp > $datelimit AND utimestamp <=". $date. + " GROUP BY id_agentmodule, evento) t1"; + + $data_count = db_get_value_sql($sql_count); - $sql = sprintf ('SELECT evento, event_type, criticity, count(*) as count_rep, max(timestamp) AS time2, id_agentmodule, estado, user_comment, tags, source, id_extra, owner_user + $temp_file = $config['attachment_store'] . '/event_report_module_' . $time.'_'.$content['id_rc'] . '.tmp'; + $file = fopen ($temp_file, 'a+'); + $buffer_file["objdata"] = $config['attachment_store'] . '/event_report_module_' . $time.'_'.$content['id_rc'] . '.tmp'; + + $limit = 1000; + $offset = 0; + + if ($data_count == false) { + $content_report = " \n"; + $result = fwrite($file, $content_report); + fclose($file); + } else if ($data_count <= $limit) { + $content_report = " \n"; + $result = fwrite($file, $content_report); + fclose($file); + + $sql = "SELECT evento, event_type, criticity, count(*) as count_rep, max(timestamp) AS time2, id_agentmodule, estado, user_comment, tags, source, id_extra, owner_user + FROM tevento + WHERE id_agente =".$content['id_agent']." AND utimestamp > $datelimit AND utimestamp <=". $date. + " GROUP BY id_agentmodule, evento"; + + $events = db_get_all_rows_sql($sql); + + write_xml_file_event ($events, $temp_file, 0, $content['id_agent']); + + $file = fopen ($temp_file, 'a+'); + $content_report = " \n"; + $result = fwrite($file, $content_report); + + } else { + $content_report = " \n"; + $result = fwrite($file, $content_report); + fclose($file); + + $position = 0; + while ($offset < $data_count) { + + $sql = sprintf ('SELECT evento, event_type, criticity, count(*) as count_rep, max(timestamp) AS time2, id_agentmodule, estado, user_comment, tags, source, id_extra, owner_user FROM tevento WHERE id_agentmodule = %d AND utimestamp > %d AND utimestamp <= %d - GROUP BY id_agentmodule, evento ORDER BY time2 DESC', $content['id_agent_module'], $datelimit, $report["datetime"]); + GROUP BY id_agentmodule, evento ORDER BY time2 DESC LIMIT %d,%d', $content['id_agent_module'], $datelimit, $date, $offset,$limit); - $events = db_get_all_rows_sql($sql); - if ($events === false) { - $events = array(); - } - - foreach ($events as $event) { - $objdata = array(); - - $objdata['event'] = $event['evento']; - $objdata['event_type'] = $event['event_type']; - $objdata['criticity'] = get_priority_name($event['criticity']); - $objdata['count'] = $event['count_rep']; - $objdata['timestamp'] = $event['time2']; - $objdata['module_name'] = modules_get_agentmodule_name ($event['id_agentmodule']); - $objdata['agent_name'] = agents_get_name ($content['id_agent']); - - if ($event['estado'] == 0) - $status = __('New'); - else if ($event['estado'] == 1) - $status = __('Validated'); - else if ($event['estado'] == 2) - $status = __('In process'); - else - $status = ""; + $events = db_get_all_rows_sql($sql); - $objdata['event_status'] = $status; - $objdata['user_comment'] = $event['user_comment']; - $objdata['tags'] = $event['tags']; - $objdata['event_source'] = $event['source']; - $objdata['extra_id'] = $event['id_extra']; - $objdata['user_validation'] = $event['owner_user']; + $position = write_xml_file_event ($events, $temp_file, $position, $content['id_agent']); + $offset += $limit; + } - array_push($data["objdata"]["event_report_module"], $objdata); + $file = fopen ($temp_file, 'a+'); + $content_report = " \n"; + $result = fwrite($file, $content_report); + fclose($file); } break; case 'alert_report_module': @@ -811,10 +1157,349 @@ foreach ($contents as $content) { $data["objdata"]["inventory_changes"] = inventory_get_changes($id_agent, $module_name, $report["datetime"] - $content['period'], $report["datetime"], 'array'); + break; + case 'agent_configuration': + + $agent_name = agents_get_name ($content['id_agent']); + + $sql = "SELECT * FROM tagente WHERE id_agente=".$content['id_agent']; + $agent_data = db_get_row_sql($sql); + + $data["title"] = __('Configuration report for agent ').$agent_name; + $data["agent"] = $agent_name; + $data["objdata"] = array(); + + ///// + $temp_file = $config['attachment_store'] . '/agent_configuration_' . $time.'_'.$content['id_rc'] . '.tmp'; + $file = fopen ($temp_file, 'a+'); + $buffer_file["objdata"] = $config['attachment_store'] . '/agent_configuration_' . $time.'_'.$content['id_rc'] . '.tmp'; + + $content_report = " \n"; + $result = fwrite($file, $content_report); + fclose($file); + + write_xml_file_agent_data($agent_data, $temp_file, $agent_name); + + $userGroups = users_get_groups($config['id_user'], 'AR', false); + if (empty($userGroups)) { + return array(); + } + $id_groups = array_keys($userGroups); + if (!empty($id_groups)) { + + $sql_count = "SELECT count(*) FROM (SELECT * + FROM tagente_modulo WHERE + ( + 1 = ( + SELECT is_admin + FROM tusuario + WHERE id_user = '".$config['id_user']."' + ) + OR tagente_modulo.id_agente IN ( + SELECT id_agente + FROM tagente + WHERE id_grupo IN (" . implode(',', $id_groups) . ") + ) + OR 0 IN ( + SELECT id_grupo + FROM tusuario_perfil + WHERE id_usuario ='".$config['id_user']."' + AND id_perfil IN ( + SELECT id_perfil + FROM tperfil WHERE agent_view = 1 + ) + ) + ) AND id_agente=".$content['id_agent']." AND delete_pending = 0 + ORDER BY nombre) t1"; + $data_count = db_get_value_sql($sql_count); + + $limit = 1000; + $offset = 0; + + if ($data_count == false) { + + $content_report = " \n"; + $content_report .= " \n"; + + $file = fopen ($temp_file, 'a+'); + $result = fwrite($file, $content_report); + fclose($file); + } else if ($data_count <= $limit) { + $content_report = " \n"; + + $file = fopen ($temp_file, 'a+'); + $result = fwrite($file, $content_report); + fclose($file); + + $sql = "SELECT * + FROM tagente_modulo WHERE + ( + 1 = ( + SELECT is_admin + FROM tusuario + WHERE id_user = '".$config['id_user']."' + ) + OR tagente_modulo.id_agente IN ( + SELECT id_agente + FROM tagente + WHERE id_grupo IN (" . implode(',', $id_groups) . ") + ) + OR 0 IN ( + SELECT id_grupo + FROM tusuario_perfil + WHERE id_usuario ='".$config['id_user']."' + AND id_perfil IN ( + SELECT id_perfil + FROM tperfil WHERE agent_view = 1 + ) + ) + ) AND id_agente=".$content['id_agent']." AND delete_pending = 0 + ORDER BY nombre"; + + $modules = db_get_all_rows_sql ($sql); + write_xml_file_agent_conf ($modules, $temp_file,0, $content['id_agent']); + + $file = fopen ($temp_file, 'a+'); + $content_report = " \n"; + $content_report .= " \n"; + $result = fwrite($file, $content_report); + + } else { + $content_report = " \n"; + + $file = fopen ($temp_file, 'a+'); + $result = fwrite($file, $content_report); + fclose($file); + + $position = 0; + while ($offset < $data_count) { + + $sql = "SELECT * + FROM tagente_modulo WHERE + ( + 1 = ( + SELECT is_admin + FROM tusuario + WHERE id_user = '".$config['id_user']."' + ) + OR tagente_modulo.id_agente IN ( + SELECT id_agente + FROM tagente + WHERE id_grupo IN (" . implode(',', $id_groups) . ") + ) + OR 0 IN ( + SELECT id_grupo + FROM tusuario_perfil + WHERE id_usuario ='".$config['id_user']."' + AND id_perfil IN ( + SELECT id_perfil + FROM tperfil WHERE agent_view = 1 + ) + ) + ) AND id_agente=".$content['id_agent']." AND delete_pending = 0 + ORDER BY nombre + LIMIT $offset,$limit"; + + $modules = db_get_all_rows_sql ($sql); + + $position = write_xml_file_agent_conf ($modules, $temp_file, $position, $content['id_agent']); + $offset += $limit; + } + + $file = fopen ($temp_file, 'a+'); + $content_report = " \n"; + $content_report .= " \n"; + $result = fwrite($file, $content_report); + fclose($file); + } + + } + + break; + case 'group_configuration': + + $group_name = groups_get_name ($content['id_group'], true); + + $data["title"] = __('Configuration report for group ').$group_name; + $data["group"] = $group_name; + + /// + $data["objdata"] = array(); + $temp_file = $config['attachment_store'] . '/group_configuration_' . $time.'_'.$content['id_rc'] . '.tmp'; + $file = fopen ($temp_file, 'a+'); + $buffer_file["objdata"] = $config['attachment_store'] . '/group_configuration_' . $time.'_'.$content['id_rc'] . '.tmp'; + + $content_report = " \n"; + $content_report .= " ".$group_name."\n"; + $content_report .= " ".$content['id_group']."\n"; + $result = fwrite($file, $content_report); + fclose($file); + + $sql = "SELECT * FROM tagente WHERE id_grupo=".$content['id_group']; + $agents_list = db_get_all_rows_sql($sql); + if ($agents_list === false) + $agents_list = array(); + $i = 0; + foreach ($agents_list as $key=>$agent) { + $file = fopen ($temp_file, 'a+'); + $content_report = " \n"; + $content_report .= " \n"; + $result = fwrite($file, $content_report); + write_xml_file_agent_data($agent, $temp_file); + + $userGroups = users_get_groups($config['id_user'], 'AR', false); + if (empty($userGroups)) { + return array(); + } + $id_groups = array_keys($userGroups); + if (!empty($id_groups)) { + + $sql_count = "SELECT count(*) FROM (SELECT * + FROM tagente_modulo WHERE + ( + 1 = ( + SELECT is_admin + FROM tusuario + WHERE id_user = '".$config['id_user']."' + ) + OR tagente_modulo.id_agente IN ( + SELECT id_agente + FROM tagente + WHERE id_grupo IN (" . implode(',', $id_groups) . ") + ) + OR 0 IN ( + SELECT id_grupo + FROM tusuario_perfil + WHERE id_usuario ='".$config['id_user']."' + AND id_perfil IN ( + SELECT id_perfil + FROM tperfil WHERE agent_view = 1 + ) + ) + ) AND id_agente=".$agent['id_agente']." AND delete_pending = 0 + ORDER BY nombre) t1"; + + $data_count = db_get_value_sql($sql_count); + + $limit = 1000; + $offset = 0; + + if ($data_count == false) { + $content_report = " \n"; + $content_report .= " \n"; + + $file = fopen ($temp_file, 'a+'); + $result = fwrite($file, $content_report); + fclose($file); + + } else if ($data_count <= $limit) { + $content_report = " \n"; + + $file = fopen ($temp_file, 'a+'); + $result = fwrite($file, $content_report); + fclose($file); + + $sql = "SELECT * + FROM tagente_modulo WHERE + ( + 1 = ( + SELECT is_admin + FROM tusuario + WHERE id_user = '".$config['id_user']."' + ) + OR tagente_modulo.id_agente IN ( + SELECT id_agente + FROM tagente + WHERE id_grupo IN (" . implode(',', $id_groups) . ") + ) + OR 0 IN ( + SELECT id_grupo + FROM tusuario_perfil + WHERE id_usuario ='".$config['id_user']."' + AND id_perfil IN ( + SELECT id_perfil + FROM tperfil WHERE agent_view = 1 + ) + ) + ) AND id_agente=".$agent['id_agente']." AND delete_pending = 0 + ORDER BY nombre"; + + $modules = db_get_all_rows_sql ($sql); + write_xml_file_agent_conf ($modules, $temp_file, 0, $content['id_agent']); + + $file = fopen ($temp_file, 'a+'); + $content_report = " \n"; + $content_report .= " \n"; + $result = fwrite($file, $content_report); + + + } else { + $content_report = " \n"; + + $file = fopen ($temp_file, 'a+'); + $result = fwrite($file, $content_report); + fclose($file); + + $position = 0; + while ($offset < $data_count) { + + $sql = "SELECT * + FROM tagente_modulo WHERE + ( + 1 = ( + SELECT is_admin + FROM tusuario + WHERE id_user = '".$config['id_user']."' + ) + OR tagente_modulo.id_agente IN ( + SELECT id_agente + FROM tagente + WHERE id_grupo IN (" . implode(',', $id_groups) . ") + ) + OR 0 IN ( + SELECT id_grupo + FROM tusuario_perfil + WHERE id_usuario ='".$config['id_user']."' + AND id_perfil IN ( + SELECT id_perfil + FROM tperfil WHERE agent_view = 1 + ) + ) + ) AND id_agente=".$agent['id_agente']." AND delete_pending = 0 + ORDER BY nombre + LIMIT $offset,$limit"; + + $modules = db_get_all_rows_sql ($sql); + + $position = write_xml_file_agent_conf ($modules, $temp_file, $position, $content['id_agent']); + $offset += $limit; + } + + $file = fopen ($temp_file, 'a+'); + $content_report = " \n"; + $content_report .= " \n"; + $result = fwrite($file, $content_report); + fclose($file); + } + + } + $i++; + + $file = fopen ($temp_file, 'a+'); + $content_report = " \n"; + $result = fwrite($file, $content_report); + fclose($file); + } + $file = fopen ($temp_file, 'a+'); + $content_report = " \n"; + $result = fwrite($file, $content_report); + fclose($file); + /// + break; } - xml_array ($data); + xml_array ($data, $buffer_file); echo ''; $counter++;