From 6632bf3a8a2fb10f76e5a4e3d6fb74087fdbd7cb Mon Sep 17 00:00:00 2001 From: mdtrooper Date: Sat, 17 Oct 2009 15:19:16 +0000 Subject: [PATCH] 2009-10-17 Miguel de Dios * include/functions_custom_graphs.php, operation/reporting/graph_viewer.php, godmode/reporting/graphs.php, godmode/reporting/graph_builder.php, godmode/menu.php: change the process to create graphs, now you can edit all parts of any grahps (edit, delete, add..) and has a list of graphs. Start to add ACL in graphs...only pending test. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@2033 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f --- pandora_console/ChangeLog | 8 + pandora_console/godmode/menu.php | 2 +- .../godmode/reporting/graph_builder.php | 314 ++++++++++++------ pandora_console/godmode/reporting/graphs.php | 114 +++++++ .../include/functions_custom_graphs.php | 6 +- .../operation/reporting/graph_viewer.php | 11 +- 6 files changed, 347 insertions(+), 108 deletions(-) create mode 100644 pandora_console/godmode/reporting/graphs.php diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index c8582ff90d..65277defe9 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,11 @@ +2009-10-17 Miguel de Dios + + * include/functions_custom_graphs.php, operation/reporting/graph_viewer.php, + godmode/reporting/graphs.php, godmode/reporting/graph_builder.php, + godmode/menu.php: change the process to create graphs, now you can edit + all parts of any grahps (edit, delete, add..) and has a list of graphs. + Start to add ACL in graphs...only pending test. + 2009-10-17 Miguel de Dios * godmode/alerts/alert_list.php: set default action in alert combo box when diff --git a/pandora_console/godmode/menu.php b/pandora_console/godmode/menu.php index b1a1b57ac1..8e73ccd3a7 100644 --- a/pandora_console/godmode/menu.php +++ b/pandora_console/godmode/menu.php @@ -119,7 +119,7 @@ if (give_acl ($config['id_user'], 0, "AW")) { $sub["godmode/reporting/reporting_builder"]["text"] = __('Report builder'); // Custom graph builder - $sub["godmode/reporting/graph_builder"]["text"] = __('Graph builder'); + $sub["godmode/reporting/graphs"]["text"] = __('Graph builder'); // Custom map builder $sub["godmode/reporting/map_builder"]["text"] = __('Map builder'); diff --git a/pandora_console/godmode/reporting/graph_builder.php b/pandora_console/godmode/reporting/graph_builder.php index 52ee947f7b..f2412ba0e2 100644 --- a/pandora_console/godmode/reporting/graph_builder.php +++ b/pandora_console/godmode/reporting/graph_builder.php @@ -13,7 +13,6 @@ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. - if (is_ajax ()) { $search_agents = (bool) get_parameter ('search_agents'); @@ -71,12 +70,14 @@ $render=1; // by default $stacked = 0; $add_module = (bool) get_parameter ('add_module'); +$editGraph = (bool) get_parameter('edit_graph'); if (isset ($_GET["store_graph"])) { $name = get_parameter_post ("name"); $description = get_parameter_post ("description"); $module_number = get_parameter_post ("module_number"); - $private = get_parameter_post ("private"); + //$private = get_parameter_post ("private"); + $idGroup = get_parameter_post ('graph_id_group'); $width = get_parameter_post ("width"); $height = get_parameter_post ("height"); $events = get_parameter_post ("events"); @@ -86,14 +87,15 @@ if (isset ($_GET["store_graph"])) { $period = get_parameter_post ("period"); // Create graph $sql = "INSERT INTO tgraph - (id_user, name, description, period, width, height, private, events, stacked) VALUES + (id_user, name, description, period, width, height, private, id_group, events, stacked) VALUES ('".$config['id_user']."', '$name', '$description', $period, $width, $height, - $private, + 0, + $idGroup, $events, $stacked)"; //echo "DEBUG $sql
"; @@ -116,6 +118,19 @@ if (isset ($_GET["store_graph"])) { echo "

".__('There was a problem storing Graph')."

"; } +if (isset($_GET['change_graph'])) { + $id = get_parameter('id'); + $name = get_parameter('name'); + $id_group = get_parameter('graph_id_group'); + $description = get_parameter('description'); + + $success = process_sql_update('tgraph', + array('name' => $name, 'id_group' => $id_group, 'description' => $description), + array('id_graph' => $id)); + + print_result_message($success, __("Update the graph"), __("Bad update the graph")); +} + if (isset ($_GET["get_agent"])) { $id_agent = $_POST["id_agent"]; if (isset($_POST["chunk"])) @@ -123,76 +138,104 @@ if (isset ($_GET["get_agent"])) { } if (isset ($_GET["delete_module"] )) { - $chunkdata = $_POST["chunk"]; - if (isset($chunkdata)) { - $chunk1 = array(); - $chunk1 = split ("\|", $chunkdata); - $modules="";$weights=""; - for ($a = 0; $a < count ($chunk1); $a++) { - if (isset ($_POST["delete_$a"])) { - $id_module = $_POST["delete_$a"]; - $deleted_id[]=$id_module; - } + if ($editGraph) { + $deleteGraphs = get_parameter('delete'); + foreach ($deleteGraphs as $deleteGraph) { + process_sql_delete('tgraph_source', array('id_gs' => $deleteGraph)); } - $chunkdata2 = ""; - $module_array = array (); - $weight_array = array (); - $agent_array = array (); - for ($a = 0; $a < count ($chunk1); $a++) { - $chunk2[$a] = array(); - $chunk2[$a] = split (",", $chunk1[$a]); - $skip_module =0; - for ($b = 0; $b < count ($deleted_id); $b++) { - if ($deleted_id[$b] == $chunk2[$a][1]) { - $skip_module = 1; + } + else + { + $chunkdata = $_POST["chunk"]; + if (isset($chunkdata)) { + $chunk1 = array(); + $chunk1 = split ("\|", $chunkdata); + $modules="";$weights=""; + for ($a = 0; $a < count ($chunk1); $a++) { + if (isset ($_POST["delete_$a"])) { + $id_module = $_POST["delete_$a"]; + $deleted_id[]=$id_module; + } + } + $chunkdata2 = ""; + $module_array = array (); + $weight_array = array (); + $agent_array = array (); + for ($a = 0; $a < count ($chunk1); $a++) { + $chunk2[$a] = array(); + $chunk2[$a] = split (",", $chunk1[$a]); + $skip_module =0; + for ($b = 0; $b < count ($deleted_id); $b++) { + if ($deleted_id[$b] == $chunk2[$a][1]) { + $skip_module = 1; + } + } + if (($skip_module == 0) && (strpos ($modules, $chunk2[$a][1]) == 0)) { // Skip + $module_array[] = $chunk2[$a][1]; + $agent_array[] = $chunk2[$a][0]; + $weight_array[] = $chunk2[$a][2]; + if ($chunkdata2 == "") + $chunkdata2 .= $chunk2[$a][0].",".$chunk2[$a][1].",".$chunk2[$a][2]; + else + $chunkdata2 .= "|".$chunk2[$a][0].",".$chunk2[$a][1].",".$chunk2[$a][2]; + if ($modules !="") + $modules = $modules.",".$chunk2[$a][1]; + else + $modules = $chunk2[$a][1]; + if ($weights !="") + $weights = $weights.",".$chunk2[$a][2]; + else + $weights = $chunk2[$a][2]; } } - if (($skip_module == 0) && (strpos ($modules, $chunk2[$a][1]) == 0)) { // Skip - $module_array[] = $chunk2[$a][1]; - $agent_array[] = $chunk2[$a][0]; - $weight_array[] = $chunk2[$a][2]; - if ($chunkdata2 == "") - $chunkdata2 .= $chunk2[$a][0].",".$chunk2[$a][1].",".$chunk2[$a][2]; - else - $chunkdata2 .= "|".$chunk2[$a][0].",".$chunk2[$a][1].",".$chunk2[$a][2]; - if ($modules !="") - $modules = $modules.",".$chunk2[$a][1]; - else - $modules = $chunk2[$a][1]; - if ($weights !="") - $weights = $weights.",".$chunk2[$a][2]; - else - $weights = $chunk2[$a][2]; - } + $chunkdata = $chunkdata2; } - $chunkdata = $chunkdata2; } } if ($add_module) { - $id_agent = $_POST["id_agent"]; - $id_module = $_POST["id_module"]; - if (isset($_POST["factor"])) - $factor = $_POST["factor"]; - else - $factor = 1; - $period = $_POST["period"]; - $render = $_POST["render"]; - $stacked = get_parameter ("stacked",0); -// $alerts = $_POST["alerts"]; - if (isset($_POST["chunk"])) - $chunkdata = $_POST["chunk"]; - $events = $_POST["events"]; - $factor = $_POST["factor"]; - if ($_POST["width"]!= "") - $width = $_POST["width"]; - if ($_POST["height"]!= "") - $height = $_POST["height"]; - if ($id_module > 0){ - if (!isset($chunkdata) OR ($chunkdata == "")) - $chunkdata = "$id_agent,$id_module,$factor"; + if ($editGraph) { + + $id = get_parameter('id'); + $id_module = get_parameter('id_module'); + $factor = get_parameter('factor'); + process_sql_insert('tgraph_source', array('id_graph' => $id, 'id_agent_module' => $id_module, 'weight' => $factor)); + + $period = get_parameter('period'); + $width = get_parameter('width'); + $height = get_parameter('height'); + $events = get_parameter('events'); + $stacked = get_parameter('stacked'); + + process_sql_update('tgraph', array('period' => $period, + 'width' => $width, 'height' => $height, 'events' => $events, + 'stacked' => $stacked), array('id_graph' => $id)); + } + else { + $id_agent = $_POST["id_agent"]; + $id_module = $_POST["id_module"]; + if (isset($_POST["factor"])) + $factor = $_POST["factor"]; else - $chunkdata = $chunkdata."|$id_agent,$id_module,$factor"; + $factor = 1; + $period = $_POST["period"]; + $render = $_POST["render"]; + $stacked = get_parameter ("stacked",0); + // $alerts = $_POST["alerts"]; + if (isset($_POST["chunk"])) + $chunkdata = $_POST["chunk"]; + $events = $_POST["events"]; + $factor = $_POST["factor"]; + if ($_POST["width"]!= "") + $width = $_POST["width"]; + if ($_POST["height"]!= "") + $height = $_POST["height"]; + if ($id_module > 0){ + if (!isset($chunkdata) OR ($chunkdata == "")) + $chunkdata = "$id_agent,$id_module,$factor"; + else + $chunkdata = $chunkdata."|$id_agent,$id_module,$factor"; + } } } @@ -228,10 +271,55 @@ if (! isset($_GET["delete_module"])) { } } +if ($editGraph) { + $id = (integer) get_parameter('id'); + $graphRows = get_db_all_rows_sql("SELECT t1.*, + (SELECT t3.nombre + FROM tagente AS t3 + WHERE t3.id_agente = + (SELECT t2.id_agente + FROM tagente_modulo AS t2 + WHERE t2.id_agente_modulo = t1.id_agent_module)) + AS agent_name + FROM tgraph_source AS t1 + WHERE t1.id_graph = " . $id); + $chunk1 = true; + $module_array = array(); + $weight_array = array(); + $agent_array = array(); + $chunk1 = array(); + $tempChunkdata = array(); + $chunkdata = ""; + + foreach ($graphRows as $graphRow) { + $idsTable[] = $graphRow['id_gs']; + $module_array[] = $graphRow['id_agent_module']; + $weight_array[] = $graphRow['weight']; + $agent_array[] = $graphRow['agent_name']; + + $tempChunkdata[] = $graphRow['agent_name'] . "," . + $graphRow['id_agent_module'] . "," . + $graphRow['weight']; + } + + $graphInTgraph = get_db_row_sql("SELECT * FROM tgraph WHERE id_graph = " . $id); + $stacked = $graphInTgraph['stacked']; + $events = $graphInTgraph['events']; + + $modules = implode(',', $module_array); + $weights = implode(',', $weight_array); + $chunkdata = implode('|', $tempChunkdata); +} + echo "

".__('Reporting')." » "; if (isset ($chunk1)) { echo __('Graph builder module list')."

"; - echo "
"; + if ($editGraph) { + echo ""; + } + else { + echo ""; + } if (isset($chunkdata)) echo ""; if ($id_agent) @@ -245,8 +333,8 @@ if (isset ($chunk1)) { ".__('Module')." ".__('Weight')." ".__('Delete').""; - $color=0; - for ($a=0; $a < count($module_array); $a++){ + $color = 0; + for ($a = 0; $a < count($module_array); $a++){ // Calculate table line color if ($color == 1){ $tdcolor = "datos"; @@ -264,7 +352,12 @@ if (isset ($chunk1)) { echo ""; echo $weight_array[$a].""; echo ""; - echo ""; + if ($editGraph) { + echo ""; + } else + { + echo ""; + } } echo ""; echo ""; @@ -297,8 +390,13 @@ if (($render == 1) && (isset($modules))) { echo __('Graph builder').""; echo "
"; -echo ""; -print_input_hidden ('add_module', 1); +if ($editGraph) { + echo ""; +} +else { + echo ""; + print_input_hidden ('add_module', 1); +} if (isset($period)) echo ""; @@ -494,44 +592,66 @@ echo "
"; if (isset($module_array)){ echo "

".__('Custom graph store')."

"; echo ""; - echo ""; - - // hidden fields with data begin - echo ""; - echo ""; - echo ""; - echo ""; - echo ""; - echo ""; - - for ($a=0; $a < count($module_array); $a++){ - $id_agentemodulo = $module_array[$a]; - $id_agentemodulo_w = $weight_array[$a]; - echo ""; - echo ""; + + if ($editGraph) { + echo ""; + } + else + { + echo ""; + + // hidden fields with data begin + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + + debugPrint($module_array); + debugPrint($width); + debugPrint($height); + debugPrint($period); + debugPrint($events); + debugPrint($stacked); + + for ($a=0; $a < count($module_array); $a++){ + $id_agentemodulo = $module_array[$a]; + $id_agentemodulo_w = $weight_array[$a]; + echo ""; + echo ""; + } } // hidden fields end - echo ""; echo ""; echo ""; - echo ""; - echo ""; - echo ""; + echo ""; echo ""; echo ""; echo ""; echo "
".__('Name').""; - - echo "".__('Private').""; - echo "
"; + + $group_select = get_user_groups ($config['id_user']); + echo "".__('Group')."" . + print_select ($group_select, 'graph_id_group', $graphInTgraph['id_group'], '', '', '', true) . + "
".__('Description').""; echo "
"; echo ""; - echo "
"; + if ($editGraph) { + echo "
"; + } + else { + echo "
"; + } echo ""; diff --git a/pandora_console/godmode/reporting/graphs.php b/pandora_console/godmode/reporting/graphs.php new file mode 100644 index 0000000000..c7f1b26d6f --- /dev/null +++ b/pandora_console/godmode/reporting/graphs.php @@ -0,0 +1,114 @@ +".__('Successfully deleted').""; + else + $result = "

".__('Not deleted. Error deleting data')."

"; + $sql = "DELETE FROM tgraph WHERE id_graph = $id"; + if ($res=mysql_query($sql)) + $result = "

".__('Successfully deleted')."

"; + else + $result = "

".__('Not deleted. Error deleting data')."

"; + echo $result; + } + else { + audit_db ($config['id_user'],$REMOTE_ADDR, "ACL Violation","Trying to delete a graph from access graph builder"); + include ("general/noaccess.php"); + exit; + } +} + +echo "

".__('Reporting')." » " . __('Graphs management').'

'; + +$graphs = get_user_custom_graphs (); +//debugPrint($graphs); +if (! empty ($graphs)) { + $table->width = '650px'; + $tale->class = 'databox_frame'; + $table->align = array (); + $table->align[0] = 'center'; + $table->align[3] = 'right'; + $table->align[4] = 'center'; + $table->head = array (); + $table->head[0] = ''; + $table->head[1] = __('Graph name'); + $table->head[2] = __('Description'); + $table->head[3] = __('Num Graphs'); + $table->head[4] = __('Group'); + $table->size[0] = '20px'; + $table->size[3] = '80px'; + $table->size[4] = '50px'; + if (give_acl ($config['id_user'], 0, "AW")) { + $table->align[5] = 'center'; + $table->head[5] = __('Delete'); + $table->size[5] = '50px'; + } + $table->data = array (); + + foreach ($graphs as $graph) { + $data = array (); + + $data[0] = '' . "" . ''; + $data[1] = ''.$graph['name'].''; + $data[2] = $graph["description"]; + + $data[3] = $graph["graphs_count"]; + $data[4] = print_group_icon($graph['id_group'],true); + + if (give_acl ($config['id_user'], 0, "AW")) { + $data[5] = ''; + } + + array_push ($table->data, $data); + } + print_table ($table); +} +else { + echo "
".__('There are no defined reportings')."
"; +} + +echo '
'; +echo '
'; +print_submit_button (__('Create graph'), 'create', false, 'class="sub next"'); +echo "
"; +echo "
"; +?> \ No newline at end of file diff --git a/pandora_console/include/functions_custom_graphs.php b/pandora_console/include/functions_custom_graphs.php index a566cbbb14..33b9bafd40 100644 --- a/pandora_console/include/functions_custom_graphs.php +++ b/pandora_console/include/functions_custom_graphs.php @@ -55,9 +55,13 @@ function get_user_custom_graphs ($id_user = 0, $only_names = false) { if ($only_names) { $graphs[$graph['id_graph']] = $graph['name']; - } else { + } + else { $graphs[$graph['id_graph']] = $graph; } + + $graphsCount = get_db_value_sql("SELECT COUNT(id_gs) FROM tgraph_source WHERE id_graph = " . $graph['id_graph']); + $graphs[$graph['id_graph']]['graphs_count'] = $graphsCount; } return $graphs; diff --git a/pandora_console/operation/reporting/graph_viewer.php b/pandora_console/operation/reporting/graph_viewer.php index 646dd233fb..c2b47ff90e 100644 --- a/pandora_console/operation/reporting/graph_viewer.php +++ b/pandora_console/operation/reporting/graph_viewer.php @@ -39,7 +39,8 @@ if ($delete_graph) { else $result = "

".__('Not deleted. Error deleting data')."

"; echo $result; - } else { + } + else { audit_db ($config['id_user'],$REMOTE_ADDR, "ACL Violation","Trying to delete a graph from access graph builder"); include ("general/noaccess.php"); exit; @@ -140,8 +141,6 @@ if (! empty ($graphs)) { $table->head = array (); $table->head[0] = __('Graph name'); $table->head[1] = __('Description'); - if (give_acl ($config['id_user'], 0, "AW")) - $table->head[2] = __('Delete'); $table->data = array (); foreach ($graphs as $graph) { @@ -151,12 +150,6 @@ if (! empty ($graphs)) { $graph['id_graph'].'">'.$graph['name'].''; $data[1] = $graph["description"]; - if (give_acl ($config['id_user'], 0, "AW")) { - $data[2] = ''; - } - array_push ($table->data, $data); } print_table ($table);