diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index d5562077f2..b9ee77e1cf 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,15 @@ +2011-03-03 Miguel de Dios + * godmode/setup/news.php, godmode/setup/links.php, include/fgraph.php, + operation/agentes/status_monitor.php, operation/reporting/graph_viewer.php: + changed the calls to mysql functions to own functions. + + * godmode/agentes/module_manager.php: marked with a comment the source code + the SQL postgreSQL and mySQL standar querys. + + * include/functions_html.php, include/db/postgresql.php, + include/functions_reporting.php, include/pchart_graph.php, + include/functions_db.php: cleaned source code style. + 2011-03-03 Miguel de Dios * include/functions_reporting.php: refixed the status when the agent have diff --git a/pandora_console/godmode/agentes/module_manager.php b/pandora_console/godmode/agentes/module_manager.php index 02b148937e..bbc1eb217d 100644 --- a/pandora_console/godmode/agentes/module_manager.php +++ b/pandora_console/godmode/agentes/module_manager.php @@ -30,10 +30,10 @@ echo ""; // Check if there is at least one server of each type available to assign that // kind of modules. If not, do not show server type in combo -$network_available = get_db_sql ("SELECT count(*) from tserver where server_type = 1"); -$wmi_available = get_db_sql ("SELECT count(*) from tserver where server_type = 6"); -$plugin_available = get_db_sql ("SELECT count(*) from tserver where server_type = 4"); -$prediction_available = get_db_sql ("SELECT count(*) from tserver where server_type = 5"); +$network_available = get_db_sql ("SELECT count(*) from tserver where server_type = 1"); //POSTGRESQL COMPATIBLE +$wmi_available = get_db_sql ("SELECT count(*) from tserver where server_type = 6"); //POSTGRESQL COMPATIBLE +$plugin_available = get_db_sql ("SELECT count(*) from tserver where server_type = 4"); //POSTGRESQL COMPATIBLE +$prediction_available = get_db_sql ("SELECT count(*) from tserver where server_type = 5"); //POSTGRESQL COMPATIBLE // Development mode to use all servers if ($develop_bypass) { diff --git a/pandora_console/godmode/setup/links.php b/pandora_console/godmode/setup/links.php index 75d0245022..e220e09551 100644 --- a/pandora_console/godmode/setup/links.php +++ b/pandora_console/godmode/setup/links.php @@ -30,13 +30,14 @@ print_page_header (__('Link management'), "images/extensions.png", false, "", fa if (isset($_POST["create"])){ // If create $name = get_parameter_post ("name"); $link = get_parameter_post ("link"); - $sql_insert = "INSERT INTO tlink (name,link) VALUES ('$name','$link')"; - $result=mysql_query($sql_insert); + + $result = process_sql_insert("tlink", array('name' => $name, 'link' => $link)); + if (! $result) echo "

".__('There was a problem creating link')."

"; else { echo "

".__('Successfully created')."

"; - $id_link = mysql_insert_id(); + $id_link = $result; } } @@ -44,8 +45,9 @@ if (isset($_POST["update"])){ // if update $id_link = safe_input($_POST["id_link"]); $name = safe_input($_POST["name"]); $link = safe_input($_POST["link"]); -$sql_update ="UPDATE tlink SET name = '".$name."', link ='".$link."' WHERE id_link = '".$id_link."'"; - $result=mysql_query($sql_update); + + $result = process_sql_update("tlink", array('name' => $name, 'link' => $link), array('id_link' => $id_link)); + if (! $result) echo "

".__('There was a problem modifying link')."

"; else @@ -54,8 +56,9 @@ $sql_update ="UPDATE tlink SET name = '".$name."', link ='".$link."' WHERE id_li if (isset($_GET["borrar"])){ // if delete $id_link = safe_input($_GET["borrar"]); - $sql_delete= "DELETE FROM tlink WHERE id_link = ".$id_link; - $result=mysql_query($sql_delete); + + $result = process_sql_delete("tlink", array("id_link" => $id_link)); + if (! $result) echo "

".__('There was a problem deleting link')."

"; else @@ -68,14 +71,16 @@ if ((isset($_GET["form_add"])) or (isset($_GET["form_edit"]))){ if (isset($_GET["form_edit"])){ $creation_mode = 0; $id_link = safe_input($_GET["id_link"]); - $sql1='SELECT * FROM tlink WHERE id_link = '.$id_link; - $result=mysql_query($sql1); - if ($row=mysql_fetch_array($result)){ - $nombre = $row["name"]; - $link = $row["link"]; + + $row = get_db_row("tlink", "id_link", $id_link); + + if ($row !== false) { + $nombre = $row["name"]; + $link = $row["link"]; } else echo "

".__('Name error')."

"; - } else { // form_add + } + else { // form_add $creation_mode =1; $nombre = ""; $link = ""; @@ -87,7 +92,9 @@ if ((isset($_GET["form_add"])) or (isset($_GET["form_edit"]))){ else echo ""; echo ""; echo ' '.__('Link name').' @@ -112,10 +119,14 @@ else { // Main list view for Links editor echo ""; echo ""; echo ""; - $sql1='SELECT * FROM tlink ORDER BY name'; - $result=mysql_query($sql1); + + $rows = get_db_all_rows_in_table('tlink', 'name'); + if ($rows === false) { + $rows = array(); + } + $color=1; - while ($row=mysql_fetch_array($result)){ + foreach ($rows as $row) { if ($color == 1){ $tdcolor = "datos"; $color = 0; diff --git a/pandora_console/godmode/setup/news.php b/pandora_console/godmode/setup/news.php index 8c8872379c..90a66099fd 100644 --- a/pandora_console/godmode/setup/news.php +++ b/pandora_console/godmode/setup/news.php @@ -130,10 +130,14 @@ else { echo ""; echo ""; echo ""; - $sql = 'SELECT * FROM tnews ORDER BY timestamp'; - $result = mysql_query ($sql); + + $rows = get_db_all_rows_in_table("tnews", "timestamp"); + if ($rows === false) { + $rows = array(); + } + $color = 1; - while ($row=mysql_fetch_array($result)){ + foreach ($rows as $row) { if ($color == 1) { $tdcolor = "datos"; $color = 0; diff --git a/pandora_console/include/db/postgresql.php b/pandora_console/include/db/postgresql.php index f3b83a8710..912dbf2d19 100644 --- a/pandora_console/include/db/postgresql.php +++ b/pandora_console/include/db/postgresql.php @@ -334,7 +334,6 @@ function postgresql_process_sql_insert($table, $values) { } /** - * * Escape string to set it properly to use in sql queries * * @param string String to be cleaned. diff --git a/pandora_console/include/fgraph.php b/pandora_console/include/fgraph.php index 239e1ae215..b63a2ef5d5 100644 --- a/pandora_console/include/fgraph.php +++ b/pandora_console/include/fgraph.php @@ -1938,8 +1938,11 @@ function grafico_modulo_log4x ($id_agente_modulo, $periodo, $show_event, grafico_modulo_log4x_trace("$sql1"); $rows = 0; - $result=mysql_query($sql1); - while ($row=mysql_fetch_array($result)){ + + $first = true; + while ($row = get_db_all_row_by_steps_sql($first, $result, $sql1)){ + $first = false; + $rows++; $utimestamp = $row[0]; $severity = $row[1]; diff --git a/pandora_console/include/functions_db.php b/pandora_console/include/functions_db.php index de5eb84e73..dbcb2cebd5 100644 --- a/pandora_console/include/functions_db.php +++ b/pandora_console/include/functions_db.php @@ -3220,15 +3220,15 @@ function get_modulegroup_name ($modulegroup_id) { * * @return mixed False in case of error or invalid values passed. Affected rows otherwise */ -function process_sql_insert ($table, $values) { +function process_sql_insert($table, $values) { global $config; switch ($config["dbtype"]) { case "mysql": - return mysql_process_sql_insert ($table, $values); + return mysql_process_sql_insert($table, $values); break; case "postgresql": - return postgresql_process_sql_insert ($table, $values); + return postgresql_process_sql_insert($table, $values); break; } } diff --git a/pandora_console/include/functions_html.php b/pandora_console/include/functions_html.php index 7d6d336c2d..a3ca4eb44d 100644 --- a/pandora_console/include/functions_html.php +++ b/pandora_console/include/functions_html.php @@ -1270,12 +1270,14 @@ function html2rgb($htmlcolor) $g = hexdec($htmlcolor[2].$htmlcolor[3]); $b = hexdec($htmlcolor[4].$htmlcolor[5]); return array($r, $g, $b); - } elseif (strlen($htmlcolor) == 3) { + } + elseif (strlen($htmlcolor) == 3) { $r = hexdec($htmlcolor[0].$htmlcolor[0]); $g = hexdec($htmlcolor[1].$htmlcolor[1]); $b = hexdec($htmlcolor[2].$htmlcolor[2]); return array($r, $g, $b); - } else { + } + else { return false; } } diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index cc5c9df170..dd366e94be 100644 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -2078,7 +2078,7 @@ function render_report_html_item ($content, $table, $report, $mini = false) { if ($content['header_definition'] != '') { $table2->head = explode('|', $content['header_definition']); } - + $data = array (); $data[0] = ''; diff --git a/pandora_console/include/pchart_graph.php b/pandora_console/include/pchart_graph.php index 4d68b62257..c771c2824d 100644 --- a/pandora_console/include/pchart_graph.php +++ b/pandora_console/include/pchart_graph.php @@ -379,42 +379,44 @@ class PchartGraph extends PandoraGraphAbstract { $this->xaxis_interval = ($this->xaxis_interval / 7 >= 1) ? ($this->xaxis_interval / 7) : 10; $this->graph->drawScale ($this->dataset->GetData (), $this->dataset->GetDataDescription (), SCALE_START0, - 80, 80, 80, $this->show_axis, 0, 50, false, - $this->xaxis_interval); + 80, 80, 80, $this->show_axis, 0, 50, false, + $this->xaxis_interval); $this->graph->drawGrid (1, true, 225, 225, 225, 100, false); // Draw the graph if ($stacked == 1) { // Stacked solid $this->graph->drawScale ($this->dataset->GetData (), - $this->dataset->GetDataDescription (), - SCALE_START0, 80, 80, 80, $this->show_axis, 0, 0, false, - $this->xaxis_interval); + $this->dataset->GetDataDescription (), + SCALE_START0, 80, 80, 80, $this->show_axis, 0, 0, false, + $this->xaxis_interval); $this->graph->drawFilledCubicCurve ($this->dataset->GetData(), - $this->dataset->GetDataDescription(), 1, 30, true); + $this->dataset->GetDataDescription(), 1, 30, true); } elseif ($stacked == 3) { // Stacked wired $this->graph->drawScale ($this->dataset->GetData (), - $this->dataset->GetDataDescription (), - SCALE_START0, 80, 80, 80, $this->show_axis, 0, 0, false, - $this->xaxis_interval); + $this->dataset->GetDataDescription (), + SCALE_START0, 80, 80, 80, $this->show_axis, 0, 0, false, + $this->xaxis_interval); $this->graph->drawFilledCubicCurve ($this->dataset->GetData(), - $this->dataset->GetDataDescription(), 1, 0, true); + $this->dataset->GetDataDescription(), 1, 0, true); - } else if ($stacked == 2) { // Wired mode + } + else if ($stacked == 2) { // Wired mode $this->graph->drawScale ($this->dataset->GetData (), - $this->dataset->GetDataDescription (), - SCALE_START0, 80, 80, 80, $this->show_axis, 0, 0, false, - $this->xaxis_interval); + $this->dataset->GetDataDescription (), + SCALE_START0, 80, 80, 80, $this->show_axis, 0, 0, false, + $this->xaxis_interval); $this->graph->drawLineGraph ($this->dataset->GetData (), - $this->dataset->GetDataDescription ()); - } else { // Non-stacked, area overlapped + $this->dataset->GetDataDescription ()); + } + else { // Non-stacked, area overlapped $this->graph->drawScale ($this->dataset->GetData (), - $this->dataset->GetDataDescription (), - SCALE_START0, 80, 80, 80, $this->show_axis, 0, 0, false, - $this->xaxis_interval); + $this->dataset->GetDataDescription (), + SCALE_START0, 80, 80, 80, $this->show_axis, 0, 0, false, + $this->xaxis_interval); $this->graph->drawFilledCubicCurve ($this->dataset->GetData(), - $this->dataset->GetDataDescription(), 1, 30, true); + $this->dataset->GetDataDescription(), 1, 30, true); } $this->graph->setFontProperties($this->fontpath,7); @@ -608,13 +610,14 @@ class PchartGraph extends PandoraGraphAbstract { if ($this->show_title){ $this->graph->setFontProperties ($this->fontpath, 7); $this->graph->drawTextBox ($this->width - 8, 40, - $this->width - 240, 90, 'PANDORA FMS', 90, - 174, 214, 174, ALIGN_BOTTOM_LEFT, false); - } else { + $this->width - 240, 90, 'PANDORA FMS', 90, + 174, 214, 174, ALIGN_BOTTOM_LEFT, false); + } + else { $this->graph->setFontProperties ($this->fontpath, 7); $this->graph->drawTextBox ($this->width - 8, 50, - $this->width - 240, 60, 'PANDORA FMS', 90, - 174, 214, 174, ALIGN_BOTTOM_LEFT, false); + $this->width - 240, 60, 'PANDORA FMS', 90, + 174, 214, 174, ALIGN_BOTTOM_LEFT, false); } } } diff --git a/pandora_console/operation/agentes/status_monitor.php b/pandora_console/operation/agentes/status_monitor.php index 99bdd5025b..d333ce9ffd 100644 --- a/pandora_console/operation/agentes/status_monitor.php +++ b/pandora_console/operation/agentes/status_monitor.php @@ -76,36 +76,72 @@ $user_groups = implode (",", array_keys (get_user_groups ())); //$modules = get_db_all_rows_filter ('tagente_modulo', array('id_agente' => $user_agents, 'nombre' => '<>delete_pending'), 'DISTINCT(nombre)'); -$sql = ' -select distinct(nombre) -from tagente_modulo -where nombre <> "delete_pending" and id_agente in -( - select id_agente - from tagente where id_grupo 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 - ) - ) - OR - (1 = ( - SELECT is_admin FROM tusuario WHERE id_user = "' . $config['id_user'] . '" - ) - ) - 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 - ) - ) -)'; +switch ($config["dbtype"]) { + case "mysql": + $sql = ' + select distinct(nombre) + from tagente_modulo + where nombre <> "delete_pending" and id_agente in + ( + select id_agente + from tagente where id_grupo 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 + ) + ) + OR + (1 = ( + SELECT is_admin FROM tusuario WHERE id_user = "' . $config['id_user'] . '" + ) + ) + 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 + ) + ) + )'; + break; + case "postgresql": + $sql = ' + select distinct(nombre) + from tagente_modulo + where nombre <> \'delete_pending\' and id_agente in + ( + select id_agente + from tagente where id_grupo 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 + ) + ) + OR + (1 = ( + SELECT is_admin FROM tusuario WHERE id_user = \'' . $config['id_user'] . '\' + ) + ) + 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 + ) + ) + )'; + break; +} $modules = get_db_all_rows_sql($sql); diff --git a/pandora_console/operation/reporting/graph_viewer.php b/pandora_console/operation/reporting/graph_viewer.php index 04cea716cb..4b331bbc36 100644 --- a/pandora_console/operation/reporting/graph_viewer.php +++ b/pandora_console/operation/reporting/graph_viewer.php @@ -28,13 +28,17 @@ $id_graph = (int) get_parameter ('id'); // Delete module SQL code if ($delete_graph) { if (check_acl ($config['id_user'], 0, "AW")) { - $sql = "DELETE FROM tgraph_source WHERE id_graph = $id_graph"; - if ($res=mysql_query($sql)) + $res = process_sql_delete('tgraph_source', array('id_graph' => $id_graph)); + + if ($res) $result = "

".__('Successfully deleted')."

"; else $result = "

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

"; + + $res = process_sql_delete('tgraph', array('id_graph' => $id_graph)); + $sql = "DELETE FROM tgraph WHERE id_graph = $id_graph"; - if ($res=mysql_query($sql)) + if ($res) $result = "

".__('Successfully deleted')."

"; else $result = "

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

";
".__('Link name')."".__('Delete')."".__('Author')."".__('Timestamp')."".__('Delete')."