diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index 5dacaf7293..d0bea76c7e 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,11 @@ +2011-03-08 Miguel de Dios + + * include/functions_api.php, include/functions_db.php, + operation/incidents/incident_detail.php, godmode/agentes/agent_template.php, + godmode/servers/manage_recontask.php, godmode/snmpconsole/snmp_alert.php, + godmode/users/configure_profile.php: change the source code + for to use process_sql_insert instead of the SQL (SQL write in multiple lines). + 2011-03-08 Miguel de Dios * include/functions_events.php, include/functions_messages.php, diff --git a/pandora_console/godmode/agentes/agent_template.php b/pandora_console/godmode/agentes/agent_template.php index 83f025d057..362e35801f 100644 --- a/pandora_console/godmode/agentes/agent_template.php +++ b/pandora_console/godmode/agentes/agent_template.php @@ -52,27 +52,51 @@ if (isset ($_POST["template_id"])) { } foreach ($nc as $row2) { // Insert each module from tnetwork_component into agent - $sql = sprintf ("INSERT INTO tagente_modulo - (id_agente, id_tipo_modulo, descripcion, nombre, max, min, module_interval, - tcp_port, tcp_send, tcp_rcv, snmp_community, snmp_oid, ip_target, id_module_group, id_modulo, - plugin_user, plugin_pass, plugin_parameter, max_timeout, id_plugin) - VALUES (%d, %d, '%s', '%s', %d, %d, %d, %d, '%s', '%s', '%s', '%s', '%s', %d, %d, '%s', '%s', '%s', %d, %d)", - $id_agente, $row2["type"], $row2["description"], $row2["name"], $row2["max"], $row2["min"], $row2["module_interval"], - $row2["tcp_port"], $row2["tcp_send"], $row2["tcp_rcv"], $row2["snmp_community"], $row2["snmp_oid"], $direccion_agente, $row2["id_module_group"], $row2["id_modulo"], - $row2["plugin_user"], $row2["plugin_pass"], $row2["plugin_parameter"], $row2["max_timeout"], $row2['id_plugin']); - - $id_agente_modulo = process_sql ($sql, "insert_id"); + $values = array( + 'id_agente' => $id_agente, + 'id_tipo_modulo' => $row2["type"], + 'descripcion' => $row2["description"], + 'nombre' => $row2["name"], + 'max' => $row2["max"], + 'min' => $row2["min"], + 'module_interval' => $row2["module_interval"], + 'tcp_port' => $row2["tcp_port"], + 'tcp_send' => $row2["tcp_send"], + 'tcp_rcv' => $row2["tcp_rcv"], + 'snmp_community' => $row2["snmp_community"], + 'snmp_oid' => $row2["snmp_oid"], + 'ip_target' => $direccion_agente, + 'id_module_group' => $row2["id_module_group"], + 'id_modulo' => $row2["id_modulo"], + 'plugin_user' => $row2["plugin_user"], + 'plugin_pass' => $row2["plugin_pass"], + 'plugin_parameter' => $row2["plugin_parameter"], + 'max_timeout' => $row2["max_timeout"], + 'id_plugin' => $row2['id_plugin']); + $id_agente_modulo = process_sql_insert('tagente_modulo', $values); // Create with different estado if proc type or data type if ($id_agente_modulo !== false && ($row2["type"] == 2) || ($row2["type"] == 6) || ($row2["type"] == 9) || ($row2["type"] == 12) || ($row2["type"] == 18)) { - $sql = sprintf ("INSERT INTO tagente_estado (id_agente_modulo,datos,timestamp,estado,id_agente, utimestamp) - VALUES (%d, 0,'0000-00-00 00:00:00',0, %d, 0)", $id_agente_modulo, $id_agente); - process_sql ($sql); - } elseif ($id_agente_modulo !== false) { - $sql = sprintf ("INSERT INTO tagente_estado (id_agente_modulo,datos,timestamp,estado,id_agente, utimestamp) - VALUES (%d, 0,'0000-00-00 00:00:00',100, %d, 0)", $id_agente_modulo, $id_agente); - process_sql ($sql); - } else { + $values = array( + 'id_agente_modulo' => $id_agente_modulo, + 'datos' => 0, + 'timestamp' => '0000-00-00 00:00:00', + 'estado' => 0, + 'id_agente' => $id_agente, + 'utimestamp' => 0); + process_sql_insert('tagente_estado', $values); + } + elseif ($id_agente_modulo !== false) { + $values = array( + 'id_agente_modulo' =>$id_agente_modulo, + 'datos' => 0, + 'timestamp' => '0000-00-00 00:00:00', + 'estado' => 100, + 'id_agente' => $id_agente, + 'utimestamp' => 0); + process_sql_insert('tagente_estado', $values); + } + else { echo '

'.__('Error adding module').'

'; } } diff --git a/pandora_console/godmode/servers/manage_recontask.php b/pandora_console/godmode/servers/manage_recontask.php index f040412820..6a2b3baee1 100644 --- a/pandora_console/godmode/servers/manage_recontask.php +++ b/pandora_console/godmode/servers/manage_recontask.php @@ -123,24 +123,43 @@ if (isset($_GET["update"])) { // CREATE A RECON TASK // -------------------------------- if (isset($_GET["create"])) { - $sql = sprintf ("INSERT INTO trecon_task - (name, subnet, description, id_recon_server, create_incident, id_group, id_network_profile, interval_sweep, id_os, recon_ports, snmp_community, id_recon_script, field1, field2, field3, field4) - VALUES ( '%s', '%s', '%s', %u, %b, %d, %d, %u, %d, '%s', '%s', %s, '%s', '%s', '%s', '%s')",$name,$network,$description,$id_recon_server,$create_incident,$id_group,$id_network_profile,$interval,$id_os, $recon_ports, $snmp_community,$id_recon_script, $field1, $field2, $field3, $field4); + $values = array( + 'name' => $name, + 'subnet' => $network, + 'description' => $description, + 'id_recon_server' => $id_recon_server, + 'create_incident' => $create_incident, + 'id_group' => $id_group, + 'id_network_profile' => $id_network_profile, + 'interval_sweep' => $interval, + 'id_os' => $id_os, + 'recon_ports' => $recon_ports, + 'snmp_community' => $snmp_community, + 'id_recon_script' => $id_recon_script, + 'field1' => $field1, + 'field2' => $field2, + 'field3' => $field3, + 'field4' => $field4); if ($name != "") { if (($id_recon_script == 0) && preg_match("/[0-9]+.+[0-9]+.+[0-9]+.+[0-9]+\/+[0-9]/", $network)) - $result = process_sql ($sql); - elseif ($id_recon_script != 0) - $result = process_sql ($sql); + { + $result = process_sql_insert('trecon_task', $values); + } + elseif ($id_recon_script != 0) { + $result = process_sql_insert('trecon_task', $values); + } else $result = false; - } else + } + else $result = false; if ($result !== false) { echo '

'.__('Successfully created recon task').'

'; - } else { + } + else { echo '

'.__('Error creating recon task').'

'; } } diff --git a/pandora_console/godmode/snmpconsole/snmp_alert.php b/pandora_console/godmode/snmpconsole/snmp_alert.php index b98f380a98..99ecc5057e 100644 --- a/pandora_console/godmode/snmpconsole/snmp_alert.php +++ b/pandora_console/godmode/snmpconsole/snmp_alert.php @@ -52,18 +52,25 @@ if (isset ($_GET["update_alert"]) && $_GET["update_alert"] == "-1") { } if ($id_as < 1) { - $sql = sprintf ("INSERT INTO talert_snmp - (id_alert, al_field1, al_field2, al_field3, description, - agent, custom_oid, oid, time_threshold, max_alerts, min_alerts, priority) - VALUES - (%d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, %d, %d) ", - $alert_type, $al_field1, $al_field2, $al_field3, $description, $source_ip, $custom_value, $oid, $time_threshold, $max_alerts, $min_alerts, $priority); + $values = array( + 'id_alert' => $alert_type, + 'al_field1' => $al_field1, + 'al_field2' => $al_field2, + 'al_field3' => $al_field3, + 'description' => $description, + 'agent' => $source_ip, + 'custom_oid' => $custom_value, + 'oid' => $oid, + 'time_threshold' => $time_threshold, + 'max_alerts' => $max_alerts, + 'min_alerts' => $min_alerts, + 'priority' => $priority); + $result = process_sql_insert('talert_snmp', $values); - $result = process_sql ($sql); - if ($result === false) { echo '

'.__('There was a problem creating the alert').'

'; - } else { + } + else { echo '

'.__('Successfully created').'

'; } diff --git a/pandora_console/godmode/users/configure_profile.php b/pandora_console/godmode/users/configure_profile.php index 4124d510dd..b09b895116 100644 --- a/pandora_console/godmode/users/configure_profile.php +++ b/pandora_console/godmode/users/configure_profile.php @@ -115,16 +115,20 @@ if ($create_profile) { $alert_management = (bool) get_parameter ("alert_management"); $pandora_management = (bool) get_parameter ("pandora_management"); - $sql = sprintf ('INSERT INTO tperfil - (name, incident_view, incident_edit, incident_management, agent_view, - agent_edit, alert_edit, user_management, db_management, - alert_management, pandora_management) - VALUES ("%s", %d, %d, %d, %d, %d, %d, %d, %d, %d, %d)', - $name, $incident_view, $incident_edit, $incident_management, - $agent_view, $agent_edit, $alert_edit, $user_management, - $db_management, $alert_management, $pandora_management); + $values = array( + 'name' => $name, + 'incident_view' => $incident_view, + 'incident_edit' => $incident_edit, + 'incident_management' => $incident_management, + 'agent_view' => $agent_view, + 'agent_edit' => $agent_edit, + 'alert_edit' => $alert_edit, + 'user_management' => $user_management, + 'db_management' => $db_management, + 'alert_management' => $alert_management, + 'pandora_management' => $pandora_management); + $ret = process_sql_insert('tperfil', $values); - $ret = process_sql ($sql, 'insert_id'); if ($ret !== false) { echo '

'.__('Successfully created').'

'; echo '« Back'; diff --git a/pandora_console/include/functions_api.php b/pandora_console/include/functions_api.php index 554f3bebc7..fc2b41d20a 100644 --- a/pandora_console/include/functions_api.php +++ b/pandora_console/include/functions_api.php @@ -1542,12 +1542,19 @@ function set_new_incident($thrash1, $thrash2, $other, $thrash3) { $id_creator = 'API'; $state = $other['data'][4]; $group = $other['data'][5]; - $sql = sprintf("INSERT INTO tincidencia - (inicio, actualizacion, titulo, descripcion, id_usuario, origen, - estado, prioridad, id_grupo, id_creator) VALUES - (NOW(), NOW(), '%s', '%s', '%s', '%s', %d, %d, '%s', '%s')", - $title, $description, 'API', $origin, $state, $priority, $group, $id_creator); - $idIncident = process_sql ($sql, "insert_id"); + + $values = array( + 'inicio' => 'NOW()', + 'actualizacion' => 'NOW()', + 'titulo' => $title, + 'descripcion' => $description, + 'id_usuario' => 'API', + 'origen' => $origin, + 'estado' => $state, + 'prioridad' => $priority, + 'id_grupo' => $group, + 'id_creator' => $id_creator); + $idIncident = process_sql_insert('tincidencia', $values); if ($return === false) returnError('error_new_incident', 'Error create new incident.'); diff --git a/pandora_console/include/functions_db.php b/pandora_console/include/functions_db.php index 7d68b8a18b..c14badbabb 100644 --- a/pandora_console/include/functions_db.php +++ b/pandora_console/include/functions_db.php @@ -2028,10 +2028,8 @@ function agent_add_address ($id_agent, $ip_address) { } // Add address to agent - $sql = sprintf("INSERT INTO taddress_agent - (id_a, id_agent) VALUES - (%d, %d)",$id_address, $id_agent); - process_sql ($sql); + $values = array('id_a' => $id_address, 'id_agent' => $id_agent); + process_sql_insert('taddress_agent', $values); } /** diff --git a/pandora_console/operation/incidents/incident_detail.php b/pandora_console/operation/incidents/incident_detail.php index 0398016657..b32abd3972 100644 --- a/pandora_console/operation/incidents/incident_detail.php +++ b/pandora_console/operation/incidents/incident_detail.php @@ -125,10 +125,13 @@ if (isset ($_GET["id"])) { } } - $sql = sprintf ("INSERT INTO tattachment (id_incidencia, id_usuario, filename, description, size) - VALUES (%d, '%s', '%s', '%s', %d)", $id_inc, $config["id_user"],$filename,$description,$filesize); - - $id_attachment = process_sql ($sql,"insert_id"); + $values = array( + 'id_incidencia' => $id_inc, + 'id_usuario' => $config["id_user"], + 'filename' => $filename, + 'description' => $description, + 'size' => $filesize); + $id_attachment = process_sql_insert('tattachment', $values); // Copy file to directory and change name if ($id_attachment !== false) {