2011-03-03 Miguel de Dios <miguel.dedios@artica.es>

* include/db/postgresql.php, include/db/mysql.php, include/functions_db.php:
	fixed the function "get_db_all_rows_filter" for PostgreSQL engine, added
	new function "get_db_last_error" and derivate functions in DB engines. And
	added new parameter $status in function "process_sql".
	
	* extensions/dbmanager.php, general/error_authconfig.php,
	general/error_dbconfig.php, godmode/groups/modu_group_list.php,
	godmode/groups/group_list.php, godmode/db/db_sanity.php,
	godmode/agentes/fields_manager.php,
	godmode/agentes/manage_config_remote.php, godmode/servers/recon_script.php,
	godmode/servers/plugin.php, godmode/modules/module_list.php,
	godmode/modules/manage_network_components_form_wmi.php,
	godmode/reporting/graphs.php: changed the calls to mysql functions to own
	functions, and rewrote some parts of source code for this action.



git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@4057 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
mdtrooper 2011-03-03 18:35:37 +00:00
parent fbc02682cc
commit e3cf87c00f
17 changed files with 312 additions and 153 deletions

View File

@ -1,3 +1,19 @@
2011-03-03 Miguel de Dios <miguel.dedios@artica.es>
* include/db/postgresql.php, include/db/mysql.php, include/functions_db.php:
fixed the function "get_db_all_rows_filter" for PostgreSQL engine, added
new function "get_db_last_error" and derivate functions in DB engines. And
added new parameter $status in function "process_sql".
* extensions/dbmanager.php, general/error_authconfig.php,
general/error_dbconfig.php, godmode/groups/modu_group_list.php,
godmode/groups/group_list.php, godmode/db/db_sanity.php,
godmode/agentes/fields_manager.php,
godmode/agentes/manage_config_remote.php, godmode/servers/recon_script.php,
godmode/servers/plugin.php, godmode/modules/module_list.php,
godmode/modules/manage_network_components_form_wmi.php,
godmode/reporting/graphs.php: changed the calls to mysql functions to own
functions, and rewrote some parts of source code for this action.
2011-03-03 Miguel de Dios <miguel.dedios@artica.es> 2011-03-03 Miguel de Dios <miguel.dedios@artica.es>
* godmode/setup/news.php, godmode/setup/links.php, include/fgraph.php, * godmode/setup/news.php, godmode/setup/links.php, include/fgraph.php,
operation/agentes/status_monitor.php, operation/reporting/graph_viewer.php: operation/agentes/status_monitor.php, operation/reporting/graph_viewer.php:

View File

@ -15,6 +15,8 @@
function dbmanager_query ($sql, &$error) { function dbmanager_query ($sql, &$error) {
global $config; global $config;
switch ($config["dbtype"]) {
case "mysql":
$retval = array(); $retval = array();
if ($sql == '') if ($sql == '')
@ -43,6 +45,33 @@ function dbmanager_query ($sql, &$error) {
//Return false, check with === or !== //Return false, check with === or !==
return "Empty"; return "Empty";
break;
case "postgresql":
$retval = array();
if ($sql == '')
return false;
$sql = html_entity_decode($sql, ENT_QUOTES);
$result = process_sql($sql, "affected_rows", '', false, $status);
//$result = mysql_query ($sql);
if ($result === false) {
$backtrace = debug_backtrace();
$error = get_db_last_error();
return false;
}
if ($status == 2) {
return $result;
}
else {
return $result;
}
break;
}
} }
@ -50,6 +79,7 @@ function dbmgr_extension_main () {
require_css_file ('dbmanager', 'extensions/dbmanager/'); require_css_file ('dbmanager', 'extensions/dbmanager/');
global $config; global $config;
if (! check_acl ($config['id_user'], 0, "PM") && ! is_user_admin ($config['id_user'])) { if (! check_acl ($config['id_user'], 0, "PM") && ! is_user_admin ($config['id_user'])) {
pandora_audit("ACL Violation", "Trying to access Setup Management"); pandora_audit("ACL Violation", "Trying to access Setup Management");
require ("general/noaccess.php"); require ("general/noaccess.php");

View File

@ -42,7 +42,10 @@
Cannot connect to the database, please check your database setup in the <b>include/config.php</b> file or read the documentation on how to setup Pandora FMS.<i><br /><br /> Cannot connect to the database, please check your database setup in the <b>include/config.php</b> file or read the documentation on how to setup Pandora FMS.<i><br /><br />
Probably one or more of your user, database or hostname values are incorrect or Probably one or more of your user, database or hostname values are incorrect or
the database server is not running.</i><br /><br /><span class="error"> the database server is not running.</i><br /><br /><span class="error">
<b>MySQL ERROR:</b> <?php echo mysql_error() ?></span> <b>DB ERROR:</b>
<?php
echo get_db_last_error();
?></span>
</div> </div>
<div class="msg"> <div class="msg">
If you have modified auth system, problem could be because Pandora cannot override authorization variables from the config database. Remove them from your database by executing:<br><br><pre>DELETE FROM tconfig WHERE token = "auth";</pre> If you have modified auth system, problem could be because Pandora cannot override authorization variables from the config database. Remove them from your database by executing:<br><br><pre>DELETE FROM tconfig WHERE token = "auth";</pre>

View File

@ -42,7 +42,7 @@
Cannot connect to the database, please check your database setup in the <b>include/config.php</b> file or read the documentation on how to setup Pandora FMS.<i><br /><br /> Cannot connect to the database, please check your database setup in the <b>include/config.php</b> file or read the documentation on how to setup Pandora FMS.<i><br /><br />
Probably one or more of your user, database or hostname values are incorrect or Probably one or more of your user, database or hostname values are incorrect or
the database server is not running.</i><br /><br /><span class="error"> the database server is not running.</i><br /><br /><span class="error">
<b>MySQL ERROR:</b> '. mysql_error().'</span> <b>DB ERROR:</b><?php echo get_db_last_error(); ?></span>
<br />&nbsp; <br />&nbsp;
</div> </div>
</div> </div>

View File

@ -23,6 +23,7 @@ if (! check_acl($config['id_user'], 0, "PM")) {
pandora_audit("ACL Violation", pandora_audit("ACL Violation",
"Trying to access Group Management"); "Trying to access Group Management");
require ("general/noaccess.php"); require ("general/noaccess.php");
return; return;
} }
@ -40,44 +41,43 @@ $display_on_front = (int) get_parameter ('display_on_front', 0);
if ($create_field) { if ($create_field) {
/*Check if name field is empty*/ /*Check if name field is empty*/
if ($name != "") { if ($name != "") {
$sql = sprintf ('INSERT INTO tagent_custom_fields (name, display_on_front) $result = process_sql_insert('tagent_custom_fields', array('name' => $name, 'display_on_front' => $display_on_front));
VALUES ("%s", "%d")', }
$name, $display_on_front); else {
$result = mysql_query ($sql);
} else {
$result = false; $result = false;
} }
if ($result) { if ($result) {
echo "<h3 class='suc'>".__('Field successfully created')."</h3>"; echo "<h3 class='suc'>".__('Field successfully created')."</h3>";
} else { }
echo "<h3 class='error'>".__('There was a problem creating field')."</h3>"; } else {
echo "<h3 class='error'>".__('There was a problem creating field')."</h3>";
}
} }
/* Update field */ /* Update field */
if ($update_field) { if ($update_field) {
/*Check if name field is empty*/ /*Check if name field is empty*/
if( $name != "") { if( $name != "") {
$sql = sprintf ('UPDATE tagent_custom_fields SET name = "%s", $values = array('name' => $name, 'display_on_front' => $display_on_front);
display_on_front = %d
WHERE id_field = %d', $result = process_sql_update('tagent_custom_fields', $values, array('id_field' => $id_field));
$name, $display_on_front, $id_field); }
$result = process_sql ($sql); else {
} else {
$result = false; $result = false;
} }
if ($result !== false) { if ($result !== false) {
echo "<h3 class='suc'>".__('Field successfully updated')."</h3>"; echo "<h3 class='suc'>".__('Field successfully updated')."</h3>";
} else { }
else {
echo "<h3 class='error'>".__('There was a problem modifying field')."</h3>"; echo "<h3 class='error'>".__('There was a problem modifying field')."</h3>";
} }
} }
/* Delete field */ /* Delete field */
if ($delete_field) { if ($delete_field) {
$sql = sprintf ('DELETE FROM tagent_custom_fields WHERE id_field = %d', $id_field); $result = process_sql_delete('tagent_custom_fields', array('id_field' => $id_field));
$result = process_sql ($sql);
if (!$result) if (!$result)
echo "<h3 class='error'>".__('There was a problem deleting field')."</h3>"; echo "<h3 class='error'>".__('There was a problem deleting field')."</h3>";
@ -97,7 +97,8 @@ if ($fields) {
$table->align[1] = 'center'; $table->align[1] = 'center';
$table->align[2] = 'center'; $table->align[2] = 'center';
$table->data = array (); $table->data = array ();
} else { }
else {
echo '<div class="nf">'. __('No fields defined') .'</div>'; echo '<div class="nf">'. __('No fields defined') .'</div>';
} }
@ -109,7 +110,8 @@ foreach ($fields as $field) {
if($field['display_on_front']) { if($field['display_on_front']) {
$data[1] = print_image('images/tick.png', true); $data[1] = print_image('images/tick.png', true);
}else { }
else {
$data[1] = print_image('images/delete.png', true); $data[1] = print_image('images/delete.png', true);
} }

View File

@ -121,8 +121,13 @@ if ((isset($_GET["operacion"])) AND ($update_group == -1) ) {
$sql1 = "SELECT * FROM tagente WHERE id_grupo IN ($grouplist) ORDER BY nombre"; $sql1 = "SELECT * FROM tagente WHERE id_grupo IN ($grouplist) ORDER BY nombre";
echo '<select name="origen" style="width:200px">'; echo '<select name="origen" style="width:200px">';
$result=mysql_query($sql1); $rows = get_db_all_rows_sql($sql1);
while ($row=mysql_fetch_array($result)){
if ($rows === false) {
$rows = array();
}
foreach ($rows as $row) {
if (check_acl ($config["id_user"], $row["id_grupo"], "AR")){ if (check_acl ($config["id_user"], $row["id_grupo"], "AR")){
$source = $config["remote_config"]."/conf/". md5($row["nombre"]).".conf"; $source = $config["remote_config"]."/conf/". md5($row["nombre"]).".conf";
if (file_exists($source)){ if (file_exists($source)){
@ -142,8 +147,13 @@ if ((isset($_GET["operacion"])) AND ($update_group == -1) ) {
else else
$sql1 = "SELECT * FROM tagente WHERE id_grupo IN ($grouplist) ORDER BY nombre"; $sql1 = "SELECT * FROM tagente WHERE id_grupo IN ($grouplist) ORDER BY nombre";
$result=mysql_query($sql1); $rows = get_db_all_rows_sql($sql1);
while ($row=mysql_fetch_array($result)){
if ($rows === false) {
$rows = array();
}
foreach ($rows as $row) {
if (check_acl ($config["id_user"], $row["id_grupo"], "AW")) if (check_acl ($config["id_user"], $row["id_grupo"], "AW"))
echo "<option value=".$row["id_agente"].">".$row["nombre"]."</option>"; echo "<option value=".$row["id_agente"].">".$row["nombre"]."</option>";
} }

View File

@ -33,9 +33,13 @@ $sanity = get_parameter ("sanity", 0);
if ($sanity == 1) { if ($sanity == 1) {
// Create tagente estado when missing // Create tagente estado when missing
echo "<h2>".__('Checking tagente_estado table')."</h2>"; echo "<h2>".__('Checking tagente_estado table')."</h2>";
$sql = "SELECT * FROM tagente_modulo";
$result = mysql_query ($sql); $rows = get_db_all_rows_in_table('tagente_modulo');
while ($row = mysql_fetch_array ($result)) { if ($rows === false) {
$rows = array();
}
foreach ($rows as $row) {
$id_agente_modulo = $row[0]; $id_agente_modulo = $row[0];
$id_agente = $row["id_agente"]; $id_agente = $row["id_agente"];
// check if exist in tagente_estado and create if not // check if exist in tagente_estado and create if not
@ -50,35 +54,46 @@ if ($sanity == 1) {
} }
echo "<h3>".__('Checking database consistency')."</h2>"; echo "<h3>".__('Checking database consistency')."</h2>";
$query1 = "SELECT * FROM tagente_estado";
$result = mysql_query($query1); $rows = get_db_all_rows_in_table('tagente_estado');
while ($row = mysql_fetch_array ($result)) { if ($rows === false) {
$id_agente_modulo = $row[1]; $rows = array();
}
foreach ($rows as $row) {
$id_agente_modulo = $row['id_agente_modulo'];
# check if exist in tagente_estado and create if not # check if exist in tagente_estado and create if not
$query2 = "SELECT COUNT(*) FROM tagente_modulo WHERE id_agente_modulo = $id_agente_modulo";
$result2 = mysql_query ($query2); $rows = get_db_all_rows_sql("SELECT COUNT(*) AS count FROM tagente_modulo WHERE id_agente_modulo = $id_agente_modulo");
$row2 = mysql_fetch_array ($result2);
if ($row2[0] == 0) { if ($rows !== false) {
$query3 = "DELETE FROM tagente_estado WHERE id_agente_modulo = $id_agente_modulo"; $row = reset($rows);
$count = $rows['count'];
if ($count == 0) {
echo "Deleting non-existing module $id_agente_modulo in state table <br>"; echo "Deleting non-existing module $id_agente_modulo in state table <br>";
mysql_query($query3);
process_sql_delete('tagente_estado', array('id_agente_modulo' => $id_agente_modulo));
} }
} }
} elseif ($sanity == 2) { }
}
elseif ($sanity == 2) {
echo "<h3>".__('Deleting non-init data')."</h2>"; echo "<h3>".__('Deleting non-init data')."</h2>";
$query1 = "SELECT * FROM tagente_estado WHERE utimestamp = 0";
$result = mysql_query ($query1); $rows = get_db_all_rows_filter("tagente_estado", array("utimestamp" => 0));
while ($row = mysql_fetch_array ($result)) { if ($rows === false) {
$id_agente_modulo = $row[1]; $rows = array();
}
foreach ($rows as $row) {
echo "Deleting non init module $id_agente_modulo <br>"; echo "Deleting non init module $id_agente_modulo <br>";
$sql = "DELETE FROM tagente_modulo WHERE id_agente_modulo = $id_agente_modulo";
mysql_query ($sql); process_sql_delete('tagente_estado', array('id_agente_modulo' => $row['id_agente_modulo']));
$sql = "DELETE FROM tagente_estado WHERE id_agente_modulo = $id_agente_modulo";
mysql_query ($sql);
} }
echo "Deleting bad module (id 0)<br>"; echo "Deleting bad module (id 0)<br>";
$sql = "DELETE FROM tagente_modulo WHERE id_modulo = 0";
mysql_query ($sql); process_sql_delete('tagente_modulo', array('id_modulo' => 0));
} }
echo "<br>"; echo "<br>";
@ -99,7 +114,4 @@ echo __('Delete non-initialized modules now');
echo "</a></b>"; echo "</a></b>";
echo "</div>"; echo "</div>";
?> ?>

View File

@ -102,11 +102,18 @@ if ($create_group) {
/*Check if name field is empty*/ /*Check if name field is empty*/
if ($name != "") { if ($name != "") {
$sql = sprintf ('INSERT INTO tgrupo (nombre, icon, parent, disabled, custom_id, id_skin) $values = array(
VALUES ("%s", "%s", %d, %d, "%s", %d)', 'nombre' => $name,
$name, substr ($icon, 0, -4), $id_parent, $alerts_disabled, $custom_id, $skin); 'icon' => substr ($icon, 0, -4),
$result = mysql_query ($sql); 'parent' => $id_parent,
} else { 'disabled' => $alerts_disabled,
'custom_id' => $custom_id,
'id_skin' => $skin
);
$result = process_sql_insert('tgrupo', $values);
}
else {
$result = false; $result = false;
} }

View File

@ -65,14 +65,14 @@ if ($create_group) {
$alerts_disabled = (bool) get_parameter ('alerts_disabled'); $alerts_disabled = (bool) get_parameter ('alerts_disabled');
$custom_id = (string) get_parameter ('custom_id'); $custom_id = (string) get_parameter ('custom_id');
$sql = sprintf ('INSERT INTO tmodule_group (name) $result = process_sql_insert('tmodule_group', array('name' => $name));
VALUES ("%s")',
$name);
$result = mysql_query ($sql);
if ($result) { if ($result) {
echo "<h3 class='suc'>".__('Group successfully created')."</h3>"; echo "<h3 class='suc'>".__('Group successfully created')."</h3>";
} else { }
echo "<h3 class='error'>".__('There was a problem creating group')."</h3>"; } else {
echo "<h3 class='error'>".__('There was a problem creating group')."</h3>";
}
} }
/* Update group */ /* Update group */
@ -97,10 +97,8 @@ if ($update_group) {
if ($delete_group) { if ($delete_group) {
$id_group = (int) get_parameter ('id_group'); $id_group = (int) get_parameter ('id_group');
// $sql = sprintf ('UPDATE tmodule_group set id_mg = 1 WHERE id_mg = %d', $id_group); $result = process_sql_delete('tmodule_group', array('id_mg' => $id_group));
// $result = mysql_query ($sql);
$sql = sprintf ('DELETE FROM tmodule_group WHERE id_mg = %d', $id_group);
$result = mysql_query ($sql);
if (! $result) if (! $result)
echo "<h3 class='error'>".__('There was a problem deleting group')."</h3>"; echo "<h3 class='error'>".__('There was a problem deleting group')."</h3>";
else else

View File

@ -89,8 +89,13 @@ echo '<td class="datos2">' . __('Module type') . '</td>';
echo '<td class="datos2">'; echo '<td class="datos2">';
echo '<select name="tipo">'; echo '<select name="tipo">';
echo '<option value="' . $type . '">' . get_moduletype_name ($type); echo '<option value="' . $type . '">' . get_moduletype_name ($type);
$result = mysql_query('SELECT id_tipo, nombre FROM ttipo_modulo WHERE categoria IN (0,1,2) ORDER BY nombre;');
while ($component = mysql_fetch_array($result)){ $rows = get_db_all_rows_sql('SELECT id_tipo, nombre FROM ttipo_modulo WHERE categoria IN (0,1,2) ORDER BY nombre;');
if ($rows === false) {
$rows = array();
}
foreach ($rows as $row) {
echo '<option value="' . $component['id_tipo'] . '">' . $component['nombre'] . '</option>'; echo '<option value="' . $component['id_tipo'] . '">' . $component['nombre'] . '</option>';
} }
echo '</select>'; echo '</select>';
@ -110,9 +115,15 @@ echo '<select name="id_module_group">';
if ($id) { if ($id) {
echo '<option value="' . $id_module_group . '">' . get_modulegroup_name($id_module_group); echo '<option value="' . $id_module_group . '">' . get_modulegroup_name($id_module_group);
} }
$result = mysql_query('SELECT * FROM tmodule_group');
while ($component = mysql_fetch_array($result)) $rows = get_db_all_rows_in_table('tmodule_group');
if ($rows === false) {
$rows = array();
}
foreach ($rows as $row) {
echo '<option value="' . $component['id_mg'] . '">' . $component['name'] . '</option>'; echo '<option value="' . $component['id_mg'] . '">' . $component['name'] . '</option>';
}
echo '</select>'; echo '</select>';
echo '<tr>'; echo '<tr>';

View File

@ -37,11 +37,15 @@ if ($update_module) {
$icon = get_parameter_post ("icon"); $icon = get_parameter_post ("icon");
$category = get_parameter_post ("category"); $category = get_parameter_post ("category");
$sql_update ="UPDATE ttipo_modulo $values = array(
SET descripcion = '".$description."', categoria = '".$category."', 'descripcion' => $description,
nombre = '".$name."', icon = '".$icon."' 'categoria' => $category,
WHERE id_tipo = '".$id_type."'"; 'nombre' => $name,
$result = mysql_query($sql_update); 'icon' => $icon
);
$result = process_sql_update('ttipo_modulo', $values, array('id_tipo' => $id_type));
if (! $result) if (! $result)
echo "<h3 class='error'>".__('Problem modifying module')."</h3>"; echo "<h3 class='error'>".__('Problem modifying module')."</h3>";
else else
@ -54,14 +58,19 @@ echo "<th>".__('Icon')."</th>";
echo "<th>".__('ID')."</th>"; echo "<th>".__('ID')."</th>";
echo "<th>".__('Name')."</th>"; echo "<th>".__('Name')."</th>";
echo "<th>".__('Description')."</th>"; echo "<th>".__('Description')."</th>";
$sql = 'SELECT * FROM ttipo_modulo ORDER BY nombre';
$result = mysql_query ($sql); $rows = get_db_all_rows_sql('SELECT * FROM ttipo_modulo ORDER BY nombre');
if ($rows === false) {
$rows = array();
}
$color = 0; $color = 0;
while ($row = mysql_fetch_array ($result)){ foreach ($rows as $row) {
if ($color == 1) { if ($color == 1) {
$tdcolor = "datos"; $tdcolor = "datos";
$color = 0; $color = 0;
} else { }
else {
$tdcolor = "datos2"; $tdcolor = "datos2";
$color = 1; $color = 1;
} }

View File

@ -37,16 +37,20 @@ print_page_header (__('Graphs management'), "", false, "", true);
// Delete module SQL code // Delete module SQL code
if ($delete_graph) { if ($delete_graph) {
if (check_acl ($config['id_user'], 0, "AW")) { if (check_acl ($config['id_user'], 0, "AW")) {
$sql = "DELETE FROM tgraph_source WHERE id_graph = $id"; $result = process_sql_delete("tgraph_source", array('id_graph' =>$id));
if ($res=mysql_query($sql))
if ($result)
$result = "<h3 class=suc>".__('Successfully deleted')."</h3>"; $result = "<h3 class=suc>".__('Successfully deleted')."</h3>";
else else
$result = "<h3 class=error>".__('Not deleted. Error deleting data')."</h3>"; $result = "<h3 class=error>".__('Not deleted. Error deleting data')."</h3>";
$sql = "DELETE FROM tgraph WHERE id_graph = $id";
if ($res=mysql_query($sql)) $result = process_sql_delete("tgraph", array('id_graph' =>$id));
if ($result)
$result = "<h3 class=suc>".__('Successfully deleted')."</h3>"; $result = "<h3 class=suc>".__('Successfully deleted')."</h3>";
else else
$result = "<h3 class=error>".__('Not deleted. Error deleting data')."</h3>"; $result = "<h3 class=error>".__('Not deleted. Error deleting data')."</h3>";
echo $result; echo $result;
} }
else { else {

View File

@ -152,21 +152,23 @@ else {
$plugin_pass_opt = get_parameter ("form_pass_opt", ""); $plugin_pass_opt = get_parameter ("form_pass_opt", "");
$plugin_plugin_type = get_parameter ("form_plugin_type", "0"); $plugin_plugin_type = get_parameter ("form_plugin_type", "0");
$sql_update ="UPDATE tplugin SET $values = array(
name = '$plugin_name', 'name' => $plugin_name,
description = '$plugin_description', 'description' => $plugin_description,
max_timeout = '$plugin_max_timeout', 'max_timeout' => $plugin_max_timeout,
execute = '$plugin_execute', 'execute' => $plugin_execute,
net_dst_opt = '$plugin_net_dst_opt', 'net_dst_opt' => $plugin_net_dst_opt,
net_port_opt = '$plugin_net_port_opt', 'net_port_opt' => $plugin_net_port_opt,
user_opt = '$plugin_user_opt', 'user_opt' => $plugin_user_opt,
plugin_type = '$plugin_plugin_type', 'plugin_type' => $plugin_plugin_type,
pass_opt = '$plugin_pass_opt' 'pass_opt' => $plugin_pass_opt);
WHERE id = $plugin_id";
$result=mysql_query($sql_update); $result =process_sql_update('tplugin', $values, array('id' => $plugin_id));
if (! $result) { if (! $result) {
echo "<h3 class='error'>".__('Problem updating plugin')."</h3>"; echo "<h3 class='error'>".__('Problem updating plugin')."</h3>";
} else { }
else {
echo "<h3 class='suc'>".__('Plugin updated successfully')."</h3>"; echo "<h3 class='suc'>".__('Plugin updated successfully')."</h3>";
} }
} }
@ -183,42 +185,56 @@ else {
$plugin_pass_opt = get_parameter ("form_pass_opt", ""); $plugin_pass_opt = get_parameter ("form_pass_opt", "");
$plugin_plugin_type = get_parameter ("form_plugin_type", "0"); $plugin_plugin_type = get_parameter ("form_plugin_type", "0");
$sql_insert ="INSERT tplugin (name, description, max_timeout, execute, net_dst_opt, net_port_opt, user_opt, pass_opt, plugin_type) VALUES ('$plugin_name', '$plugin_description', '$plugin_max_timeout', '$plugin_execute', '$plugin_net_dst_opt', '$plugin_net_port_opt', '$plugin_user_opt', '$plugin_pass_opt', $plugin_plugin_type)"; $values = array(
$result=mysql_query($sql_insert); 'name' => $plugin_name,
'description' => $plugin_description,
'max_timeout' => $plugin_max_timeout,
'execute' => $plugin_execute,
'net_dst_opt' => $plugin_net_dst_opt,
'net_port_opt' => $plugin_net_port_opt,
'user_opt' => $plugin_user_opt,
'pass_opt' => $plugin_pass_opt,
'plugin_type' => $plugin_plugin_type);
$result = process_sql_insert('tplugin', $values);
if (! $result) { if (! $result) {
echo "<h3 class='error'>".__('Problem creating plugin')."</h3>"; echo "<h3 class='error'>".__('Problem creating plugin')."</h3>";
echo $sql_insert; echo $sql_insert;
} else { }
else {
echo "<h3 class='suc'>".__('Plugin created successfully')."</h3>"; echo "<h3 class='suc'>".__('Plugin created successfully')."</h3>";
} }
} }
if (isset($_GET["kill_plugin"])){ // if delete alert if (isset($_GET["kill_plugin"])){ // if delete alert
$plugin_id = get_parameter ("kill_plugin", 0); $plugin_id = get_parameter ("kill_plugin", 0);
$sql_delete= "DELETE FROM tplugin WHERE id= ".$plugin_id;
$result=mysql_query($sql_delete); $result = process_sql_delete('tplugin', array('id' => $plugin_id));
if (! $result){ if (! $result){
echo "<h3 class='error'>".__('Problem deleting plugin')."</h3>"; echo "<h3 class='error'>".__('Problem deleting plugin')."</h3>";
} else { }
else {
echo "<h3 class='suc'>".__('Plugin deleted successfully')."</h3>"; echo "<h3 class='suc'>".__('Plugin deleted successfully')."</h3>";
} }
if ($plugin_id != 0){ if ($plugin_id != 0){
$sql_delete2 ="DELETE FROM tagente_modulo WHERE id_plugin = ".$plugin_id; $result = process_sql_delete('tagente_modulo', array('id_plugin' => $plugin_id));
$result=mysql_query($sql_delete2);
} }
} }
// If not edition or insert, then list available plugins // If not edition or insert, then list available plugins
$sql1='SELECT * FROM tplugin ORDER BY name'; $rows = get_db_sql('SELECT * FROM tplugin ORDER BY name');
$result=mysql_query($sql1);
if (mysql_num_rows($result) > 0){ if ($rows !== false) {
echo '<table width="730" cellspacing="4" cellpadding="4" class="databox">'; echo '<table width="730" cellspacing="4" cellpadding="4" class="databox">';
echo "<th>".__('Name')."</th>"; echo "<th>".__('Name')."</th>";
echo "<th>".__('Type')."</th>"; echo "<th>".__('Type')."</th>";
echo "<th>".__('Command')."</th>"; echo "<th>".__('Command')."</th>";
echo "<th>".__('Delete')."</th>"; echo "<th>".__('Delete')."</th>";
$color = 0; $color = 0;
while ($row=mysql_fetch_array($result)){
foreach ($rows as $row) {
if ($color == 1){ if ($color == 1){
$tdcolor = "datos"; $tdcolor = "datos";
$color = 0; $color = 0;

View File

@ -157,16 +157,16 @@ else {
// If not edition or insert, then list available reconscripts // If not edition or insert, then list available reconscripts
$sql1='SELECT * FROM trecon_script ORDER BY name'; $rows = get_db_all_rows_in_table('trecon_script');
$result=mysql_query($sql1);
if (mysql_num_rows($result) > 0) { if ($rows !== false) {
echo '<table width="730" cellspacing="4" cellpadding="4" class="databox">'; echo '<table width="730" cellspacing="4" cellpadding="4" class="databox">';
echo "<th>".__('Name')."</th>"; echo "<th>".__('Name')."</th>";
echo "<th>".__('Command')."</th>"; echo "<th>".__('Command')."</th>";
echo "<th>".__('Description')."</th>"; echo "<th>".__('Description')."</th>";
echo "<th>".__('Delete')."</th>"; echo "<th>".__('Delete')."</th>";
$color = 0; $color = 0;
while ($row=mysql_fetch_array($result)){ foreach ($rows as $row) {
if ($color == 1){ if ($color == 1){
$tdcolor = "datos"; $tdcolor = "datos";
$color = 0; $color = 0;

View File

@ -950,4 +950,13 @@ function mysql_safe_sql_string($string) {
return mysql_real_escape_string($string, $config['dbconnection']); return mysql_real_escape_string($string, $config['dbconnection']);
} }
/**
* Get last error.
*
* @return string Return the string error.
*/
function mysql_get_db_last_error() {
return mysql_error();
}
?> ?>

View File

@ -180,7 +180,7 @@ function postgresql_insert_id($dbconnection = '') {
return $result; return $result;
} }
function postgresql_process_sql($sql, $rettype = "affected_rows", $dbconnection = '', $cache = true) { function postgresql_process_sql($sql, $rettype = "affected_rows", $dbconnection = '', $cache = true, &$status = null) {
global $config; global $config;
global $sql_cache; global $sql_cache;
@ -205,7 +205,10 @@ function postgresql_process_sql($sql, $rettype = "affected_rows", $dbconnection
$result = pg_get_result($config['dbconnection']); $result = pg_get_result($config['dbconnection']);
} }
$time = microtime (true) - $start; $time = microtime (true) - $start;
if ($result === false) {
$resultError = pg_result_error($result);
if (($result === false) || (!empty($resultError))) {
$backtrace = debug_backtrace (); $backtrace = debug_backtrace ();
$error = sprintf ('%s (\'%s\') in <strong>%s</strong> on line %d', $error = sprintf ('%s (\'%s\') in <strong>%s</strong> on line %d',
pg_result_error($result), $sql, $backtrace[0]['file'], $backtrace[0]['line']); pg_result_error($result), $sql, $backtrace[0]['file'], $backtrace[0]['line']);
@ -964,4 +967,13 @@ function postgresql_safe_sql_string($string) {
return pg_escape_string($config['dbconnection'], $string); return pg_escape_string($config['dbconnection'], $string);
} }
/**
* Get last error.
*
* @return string Return the string error.
*/
function postgresql_get_db_last_error() {
return pg_last_error();
}
?> ?>

View File

@ -2267,7 +2267,7 @@ function get_db_all_rows_filter($table, $filter = array(), $fields = false, $whe
return mysql_get_db_all_rows_filter($table, $filter, $fields, $where_join, $search_history_db, $returnSQL); return mysql_get_db_all_rows_filter($table, $filter, $fields, $where_join, $search_history_db, $returnSQL);
break; break;
case "postgresql": case "postgresql":
return postgresql_get_db_all_rows_sql($table, $filter, $fields, $where_join, $search_history_db, $returnSQL); return postgresql_get_db_all_rows_filter($table, $filter, $fields, $where_join, $search_history_db, $returnSQL);
break; break;
} }
} }
@ -2397,17 +2397,19 @@ function clean_cache() {
* 'insert_id' will return the ID of an autoincrement value * 'insert_id' will return the ID of an autoincrement value
* 'info' will return the full (debug) information of a query * 'info' will return the full (debug) information of a query
* *
* @param string $status The status and type of query (support only postgreSQL).
*
* @return mixed An array with the rows, columns and values in a multidimensional array or false in error * @return mixed An array with the rows, columns and values in a multidimensional array or false in error
*/ */
function process_sql($sql, $rettype = "affected_rows", $dbconnection = '', $cache = true) { function process_sql($sql, $rettype = "affected_rows", $dbconnection = '', $cache = true, &$status = null) {
global $config; global $config;
switch ($config["dbtype"]) { switch ($config["dbtype"]) {
case "mysql": case "mysql":
return mysql_process_sql($sql, $rettype, $dbconnection, $cache); return @mysql_process_sql($sql, $rettype, $dbconnection, $cache);
break; break;
case "postgresql": case "postgresql":
return postgresql_process_sql($sql, $rettype, $dbconnection, $cache); return @postgresql_process_sql($sql, $rettype, $dbconnection, $cache, $status);
break; break;
} }
} }
@ -3486,4 +3488,22 @@ function user_access_to_agent ($id_agent, $mode = "AR", $id_user = false) {
$id_group = (int) get_db_value ('id_grupo', 'tagente', 'id_agente', (int) $id_agent); $id_group = (int) get_db_value ('id_grupo', 'tagente', 'id_agente', (int) $id_agent);
return (bool) check_acl ($id_user, $id_group, $mode); return (bool) check_acl ($id_user, $id_group, $mode);
} }
/**
* Get last error.
*
* @return string Return the string error.
*/
function get_db_last_error() {
global $config;
switch ($config["dbtype"]) {
case "mysql":
return mysql_get_db_last_error();
break;
case "postgresql":
return postgresql_get_db_last_error();
break;
}
}
?> ?>