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

* include/functions_modules.php, include/functions_reporting.php,
	include/functions_gis.php, include/functions_servers.php,
	include/ajax/reporting.ajax.php, include/fgraph.php,
	include/functions_db.php, include/functions_alerts.php,
	include/functions_reports.php, extensions/system_info.php,
	extensions/agents_modules.php, operation/agentes/group_view.php,
	operation/events/events_rss.php, operation/reporting/reporting_xml.php,
	operation/reporting/reporting_viewer.php, extras/pandora_diag.php,
	general/logon_ok.php, godmode/db/db_audit.php, godmode/db/db_event.php,
	godmode/db/db_purge.php, godmode/agentes/planned_downtime.php,
	godmode/setup/setup.php,
	godmode/massive/massive_enable_disable_alerts.php,
	godmode/massive/massive_delete_modules.php,
	godmode/massive/massive_standby_alerts.php,
	godmode/modules/manage_network_templates.php,
	godmode/modules/manage_network_templates_form.php,
	godmode/reporting/reporting_builder.list_items.php,
	godmode/reporting/reporting_builder.preview.php,
	godmode/reporting/reporting_builder.php: changes for to use character " in
	the SQL queries for PostgreSQL, in some cases. In other case there are more
	changes for to create SQL query PostgreSQL.



git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@4062 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
mdtrooper 2011-03-07 16:59:14 +00:00
parent 57d7372c4c
commit f619a76404
31 changed files with 627 additions and 200 deletions

View File

@ -1,3 +1,27 @@
2011-03-07 Miguel de Dios <miguel.dedios@artica.es>
* include/functions_modules.php, include/functions_reporting.php,
include/functions_gis.php, include/functions_servers.php,
include/ajax/reporting.ajax.php, include/fgraph.php,
include/functions_db.php, include/functions_alerts.php,
include/functions_reports.php, extensions/system_info.php,
extensions/agents_modules.php, operation/agentes/group_view.php,
operation/events/events_rss.php, operation/reporting/reporting_xml.php,
operation/reporting/reporting_viewer.php, extras/pandora_diag.php,
general/logon_ok.php, godmode/db/db_audit.php, godmode/db/db_event.php,
godmode/db/db_purge.php, godmode/agentes/planned_downtime.php,
godmode/setup/setup.php,
godmode/massive/massive_enable_disable_alerts.php,
godmode/massive/massive_delete_modules.php,
godmode/massive/massive_standby_alerts.php,
godmode/modules/manage_network_templates.php,
godmode/modules/manage_network_templates_form.php,
godmode/reporting/reporting_builder.list_items.php,
godmode/reporting/reporting_builder.preview.php,
godmode/reporting/reporting_builder.php: changes for to use character " in
the SQL queries for PostgreSQL, in some cases. In other case there are more
changes for to create SQL query PostgreSQL.
2011-03-07 Miguel de Dios <miguel.dedios@artica.es>
* general/logon_ok.php: change the SQL in postgreSQL and some parts of

View File

@ -14,6 +14,7 @@
function mainAgentsModules() {
global $config;
// Load global vars
require_once ("include/config.php");
require_once ("include/functions_reporting.php");
@ -33,8 +34,9 @@ function mainAgentsModules() {
if (isset ($_GET["update_netgroup"])) {
$group = get_parameter_get ("update_netgroup", 0);
if (check_acl ($config['id_user'], $group, "AW")) {
$sql = sprintf ("UPDATE tagente_modulo SET `flag` = 1 WHERE `id_agente` = ANY(SELECT id_agente FROM tagente WHERE `id_grupo` = %d)",$group);
process_sql ($sql);
$where = array("id_agente" => "ANY(SELECT id_agente FROM tagente WHERE id_grupo = " . $group);
process_sql_update('tagente_modulo', array("flag" => 1), $where);
}
else {
pandora_audit("ACL Violation", "Trying to set flag for groups");

View File

@ -42,14 +42,28 @@ function getPandoraDiagnostic(&$systemInfo) {
$systemInfo['tusuario'] = get_db_sql("SELECT COUNT(*) FROM tusuario");
$systemInfo['tsesion'] = get_db_sql("SELECT COUNT(*) FROM tsesion");
$systemInfo['db_scheme_version'] = get_db_sql("SELECT `value` FROM tconfig WHERE `token` = 'db_scheme_version'");
$systemInfo['db_scheme_build'] = get_db_sql("SELECT `value` FROM tconfig WHERE `token` = 'db_scheme_build'");
$systemInfo['enterprise_installed'] = get_db_sql("SELECT `value` FROM tconfig WHERE `token` = 'enterprise_installed'");
$systemInfo['db_maintance'] = date ("Y/m/d H:i:s", get_db_sql ("SELECT `value` FROM tconfig WHERE `token` = 'db_maintance'"));
$systemInfo['customer_key'] = get_db_sql("SELECT value FROM tupdate_settings WHERE `key` = 'customer_key';");
$systemInfo['updating_code_path'] = get_db_sql("SELECT value FROM tupdate_settings WHERE `key` = 'updating_code_path'");
$systemInfo['keygen_path'] = get_db_sql("SELECT value FROM tupdate_settings WHERE `key` = 'keygen_path'");
$systemInfo['current_update'] = get_db_sql("SELECT value FROM tupdate_settings WHERE `key` = 'current_update'");
switch ($config["dbtype"]) {
case "mysql":
$systemInfo['db_scheme_version'] = get_db_sql("SELECT `value` FROM tconfig WHERE `token` = 'db_scheme_version'");
$systemInfo['db_scheme_build'] = get_db_sql("SELECT `value` FROM tconfig WHERE `token` = 'db_scheme_build'");
$systemInfo['enterprise_installed'] = get_db_sql("SELECT `value` FROM tconfig WHERE `token` = 'enterprise_installed'");
$systemInfo['db_maintance'] = date ("Y/m/d H:i:s", get_db_sql ("SELECT `value` FROM tconfig WHERE `token` = 'db_maintance'"));
$systemInfo['customer_key'] = get_db_sql("SELECT value FROM tupdate_settings WHERE `key` = 'customer_key';");
$systemInfo['updating_code_path'] = get_db_sql("SELECT value FROM tupdate_settings WHERE `key` = 'updating_code_path'");
$systemInfo['keygen_path'] = get_db_sql("SELECT value FROM tupdate_settings WHERE `key` = 'keygen_path'");
$systemInfo['current_update'] = get_db_sql("SELECT value FROM tupdate_settings WHERE `key` = 'current_update'");
break;
case "postgresql":
$systemInfo['db_scheme_version'] = get_db_sql("SELECT \"value\" FROM tconfig WHERE \"token\" = 'db_scheme_version'");
$systemInfo['db_scheme_build'] = get_db_sql("SELECT \"value\" FROM tconfig WHERE \"token\" = 'db_scheme_build'");
$systemInfo['enterprise_installed'] = get_db_sql("SELECT \"value\" FROM tconfig WHERE \"token\" = 'enterprise_installed'");
$systemInfo['db_maintance'] = date ("Y/m/d H:i:s", get_db_sql ("SELECT \"value\" FROM tconfig WHERE \"token\" = 'db_maintance'"));
$systemInfo['customer_key'] = get_db_sql("SELECT value FROM tupdate_settings WHERE \"key\" = 'customer_key';");
$systemInfo['updating_code_path'] = get_db_sql("SELECT value FROM tupdate_settings WHERE \"key\" = 'updating_code_path'");
$systemInfo['keygen_path'] = get_db_sql("SELECT value FROM tupdate_settings WHERE \"key\" = 'keygen_path'");
$systemInfo['current_update'] = get_db_sql("SELECT value FROM tupdate_settings WHERE \"key\" = 'current_update'");
break;
}
}
function getSystemInfo(&$systemInfo, $script = false) {

View File

@ -15,18 +15,21 @@
function render_info ($table) {
global $console_mode;
$info = get_db_sql ("SELECT COUNT(*) FROM $table");
render_row ($info,"DB Table $table");
}
function render_info_data ($query, $label) {
global $console_mode;
$info = get_db_sql ($query);
render_row ($info, $label);
}
function render_row ($data, $label){
global $console_mode;
if ($console_mode == 1){
echo $label;
echo "|";
@ -116,16 +119,30 @@ render_info ("ttrap");
render_info ("tusuario");
render_info ("tsesion");
render_info_data ("SELECT `value` FROM tconfig WHERE `token` = 'db_scheme_version'", "DB Schema Version");
render_info_data ("SELECT `value` FROM tconfig WHERE `token` = 'db_scheme_build'", "DB Schema Build");
render_info_data ("SELECT `value` FROM tconfig WHERE `token` = 'enterprise_installed'", "Enterprise installed");
render_row ( date ("Y/m/d H:i:s",get_db_sql ("SELECT `value` FROM tconfig WHERE `token` = 'db_maintance'")), "PandoraDB Last run");
render_info_data ("SELECT value FROM tupdate_settings WHERE `key` = 'customer_key';", "Update Key");
render_info_data ("SELECT value FROM tupdate_settings WHERE `key` = 'updating_code_path'", "Updating code path");
render_info_data ("SELECT value FROM tupdate_settings WHERE `key` = 'keygen_path'", "Keygen path");
render_info_data ("SELECT value FROM tupdate_settings WHERE `key` = 'current_update'", "Current Update #");
switch ($config["dbtype"]) {
case "mysql":
render_info_data ("SELECT `value` FROM tconfig WHERE `token` = 'db_scheme_version'", "DB Schema Version");
render_info_data ("SELECT `value` FROM tconfig WHERE `token` = 'db_scheme_build'", "DB Schema Build");
render_info_data ("SELECT `value` FROM tconfig WHERE `token` = 'enterprise_installed'", "Enterprise installed");
render_row ( date ("Y/m/d H:i:s",get_db_sql ("SELECT `value` FROM tconfig WHERE `token` = 'db_maintance'")), "PandoraDB Last run");
render_info_data ("SELECT value FROM tupdate_settings WHERE `key` = 'customer_key';", "Update Key");
render_info_data ("SELECT value FROM tupdate_settings WHERE `key` = 'updating_code_path'", "Updating code path");
render_info_data ("SELECT value FROM tupdate_settings WHERE `key` = 'keygen_path'", "Keygen path");
render_info_data ("SELECT value FROM tupdate_settings WHERE `key` = 'current_update'", "Current Update #");
break;
case "postgresql":
render_info_data ("SELECT \"value\" FROM tconfig WHERE \"token\" = 'db_scheme_version'", "DB Schema Version");
render_info_data ("SELECT \"value\" FROM tconfig WHERE \"token\" = 'db_scheme_build'", "DB Schema Build");
render_info_data ("SELECT \"value\" FROM tconfig WHERE \"token\" = 'enterprise_installed'", "Enterprise installed");
render_row ( date ("Y/m/d H:i:s",get_db_sql ("SELECT \"value\" FROM tconfig WHERE \"token\" = 'db_maintance'")), "PandoraDB Last run");
render_info_data ("SELECT value FROM tupdate_settings WHERE \"key\" = 'customer_key';", "Update Key");
render_info_data ("SELECT value FROM tupdate_settings WHERE \"key\" = 'updating_code_path'", "Updating code path");
render_info_data ("SELECT value FROM tupdate_settings WHERE \"key\" = 'keygen_path'", "Keygen path");
render_info_data ("SELECT value FROM tupdate_settings WHERE \"key\" = 'current_update'", "Current Update #");
break;
}
if ($console_mode == 0) {
echo "</table>";

View File

@ -157,13 +157,13 @@ switch ($config["dbtype"]) {
$sql = sprintf ("SELECT id_usuario,accion,fecha,ip_origen,descripcion
FROM tsesion
WHERE (`utimestamp` > UNIX_TIMESTAMP(NOW()) - 604800)
AND `id_usuario` = '%s' ORDER BY `utimestamp` DESC LIMIT 10", $config["id_user"]);
AND `id_usuario` = '%s' ORDER BY `utimestamp` DESC LIMIT 10", $config["id_user"]);
break;
case "postgresql":
$sql = sprintf ("SELECT \"ID_usuario\", accion, fecha, \"IP_origen\", descripcion
FROM tsesion
WHERE (\"utimestamp\" > ceil(date_part('epoch', CURRENT_TIMESTAMP)) - 604800)
AND \"ID_usuario\" = '%s' ORDER BY \"utimestamp\" DESC LIMIT 10", $config["id_user"]);
AND \"ID_usuario\" = '%s' ORDER BY \"utimestamp\" DESC LIMIT 10", $config["id_user"]);
break;
}

View File

@ -95,27 +95,32 @@ if ($create_downtime || $update_downtime) {
if ($datetime_from > $datetime_to) {
echo '<h3 class="error">'.__('Not created. Error inserting data').': START &gt; END</h3>';
} else {
}
else {
$sql = '';
if ($create_downtime) {
$sql = sprintf ("INSERT INTO tplanned_downtime (`name`,
`description`, `date_from`, `date_to`, `id_group`)
VALUES ('%s','%s',%d,%d, %d)",
$name, $description, $datetime_from,
$datetime_to, $id_group);
} else if ($update_downtime) {
$sql = sprintf ("UPDATE tplanned_downtime
SET `name`='%s', `description`='%s', `date_from`=%d,
`date_to`=%d, `id_group`=%d
WHERE `id` = '%d'",
$name, $description, $datetime_from,
$datetime_to, $id_group, $id_downtime);
$values = array(
'name' => $name,
'description' => $description,
'date_from' => $datetime_from,
'date_to' => $datetime_to,
'id_group' => $id_group);
$result = process_sql_insert('tplanned_downtime', $values);
}
else if ($update_downtime) {
$values = array(
'name' => $name,
'description' => $description,
'date_from' => $datetime_from,
'date_to' => $datetime_to,
'id_group' => $id_group);
$result = process_sql_update('tplanned_downtime', $values, array('id' => $id_downtime));
}
$result = process_sql ($sql);
if ($result === false) {
echo '<h3 class="error">'.__('Could not be created').'</h3>';
} else {
}
else {
echo '<h3 class="suc">'.__('Successfully created').'</h3>';
}
}
@ -126,9 +131,18 @@ if ($create_downtime || $update_downtime) {
if (($first_create != 0) OR ($first_update != 0)){
// Have any data to show ?
if ($id_downtime > 0) {
$sql = sprintf ("SELECT `id`, `name`, `description`, `date_from`, `date_to`, `id_group`
FROM `tplanned_downtime` WHERE `id` = %d",
$id_downtime);
switch ($config["dbtype"]) {
case "mysql":
$sql = sprintf ("SELECT `id`, `name`, `description`, `date_from`, `date_to`, `id_group`
FROM `tplanned_downtime` WHERE `id` = %d",
$id_downtime);
break;
case "postgresql":
$sql = sprintf ("SELECT \"id\", \"name\", \"description\", \"date_from\", \"date_to\", \"id_group\"
FROM \"tplanned_downtime\" WHERE \"id\" = %d",
$id_downtime);
break;
}
$result = get_db_row_sql ($sql);
$name = $result["name"];

View File

@ -63,8 +63,8 @@ $time["3month"] = $time["all"]-(86400*90);
# Purge data using dates
if (isset($_POST["purgedb"])){ # Fixed 2005-1-13, nil
$from_date = get_parameter_post("date_purge");
$query = sprintf("DELETE FROM `tsesion` WHERE `utimestamp` < '%s';",$from_date);
(int) $deleted = process_sql($query);
$deleted = process_sql_delete('tsesion', array('utimestamp' => '< ' . $from_date));
}
# End of get parameters block

View File

@ -31,11 +31,13 @@ if (! check_acl ($config['id_user'], 0, "DM")) {
# Purge data using dates
if (isset ($_POST["date_purge"])){
$from_date = (int) get_parameter_post ("date_purge");
$query = sprintf ("DELETE FROM `tevento` WHERE `utimestamp` < %d",$from_date);
$deleted = process_sql ($query);
$deleted = process_sql_delete('tevento', array('utimestamp' => '< ' . $from_date));
if ($deleted !== false) {
echo '<h3 class="suc">'.__('Successfully deleted old events').'</h3>';
} else {
}
else {
echo '<h3 class="error">'.__('Error deleting old events').'</h3>';
}
}

View File

@ -98,32 +98,33 @@ if (isset($_POST["purgedb"])) {
echo "<br />";
flush (); //Flush here in case there are errors and the script dies, at least we know where we ended
set_time_limit (); //Reset the time limit just in case
$sql = sprintf ("DELETE FROM `tagente_datos` WHERE `id_agente_modulo` = %d AND `utimestamp` < %d",$row["id_agente_modulo"],$from_date);
$result = process_sql ($sql);
$result = process_sql_delete('tagente_datos', array('id_agente_modulo' => $row["id_agente_modulo"], 'utimestamp' => '< ' . $from_date));
if ($result === false)
$errors++;
else
$affected += $result;
if ($errors == 0) {
$sql = sprintf ("DELETE FROM `tagente_datos_inc` WHERE `id_agente_modulo` = %d AND `utimestamp` < %d",$row["id_agente_modulo"],$from_date);
$result = process_sql ($sql);
$result = process_sql_delete('tagente_datos_inc', array('id_agente_modulo' => $row["id_agente_modulo"], 'utimestamp' => '< ' . $from_date));
if ($result === false)
$errors++;
else
$affected += $result;
}
if ($errors == 0) {
$sql = sprintf ("DELETE FROM `tagente_datos_string` WHERE `id_agente_modulo` = %d AND `utimestamp` < %d",$row["id_agente_modulo"],$from_date);
$result = process_sql ($sql);
$result = process_sql_delete('tagente_datos_string', array('id_agente_modulo' => $row["id_agente_modulo"], 'utimestamp' => '< ' . $from_date));
if ($result === false)
$errors++;
else
$affected += $result;
}
if ($errors == 0) {
$sql = sprintf ("DELETE FROM `tagente_datos_log4x` WHERE `id_agente_modulo` = %d AND `utimestamp` < %d",$row["id_agente_modulo"],$from_date);
$result = process_sql ($sql);
$result = process_sql_delete('tagente_datos_log4x', array('id_agente_modulo' => $row["id_agente_modulo"], 'utimestamp' => '< ' . $from_date));
if ($result === false)
$errors++;
else
@ -133,7 +134,8 @@ if (isset($_POST["purgedb"])) {
if ($errors > 0) {
process_sql_rollback ();
} else {
}
else {
process_sql_commit ();
echo __('Total records deleted: ') . $affected;
@ -142,14 +144,11 @@ if (isset($_POST["purgedb"])) {
//All agents
echo __('Deleting records for all agents');
flush ();
$query = sprintf ("DELETE FROM `tagente_datos` WHERE `utimestamp` < %d",$from_date);
process_sql ($query);
$query = sprintf ("DELETE FROM `tagente_datos_inc` WHERE `utimestamp` < %d",$from_date);
process_sql ($query);
$query = sprintf ("DELETE FROM `tagente_datos_string` WHERE `utimestamp` < %d",$from_date);
process_sql ($query);
$query = sprintf ("DELETE FROM `tagente_datos_log4x` WHERE `utimestamp` < %d",$from_date);
process_sql ($query);
process_sql_delete('tagente_datos', array('utimestamp' => '< ' . $from_date));
process_sql_delete('tagente_datos_inc', array('utimestamp' => '< ' . $from_date));
process_sql_delete('tagente_datos_string', array('utimestamp' => '< ' . $from_date));
process_sql_delete('tagente_datos_log4x', array('utimestamp' => '< ' . $from_date));
}
echo "<br /><br />";
}

View File

@ -36,7 +36,7 @@ if (is_ajax ()) {
$agents_modules = get_agents_with_module_name ($module_name, $id_group,
array ('delete_pending' => 0,
'`tagente_modulo`.disabled' => 0),
'tagente_modulo.disabled' => 0),
array ('tagente.id_agente', 'tagente.nombre'));
echo json_encode (index_array ($agents_modules, 'id_agente', 'nombre'));
@ -127,7 +127,7 @@ $table->data[2][0] .= print_image('images/spinner.png', true);
$table->data[2][0] .= '</span>';
$agents = get_agents_with_module_name ($module_name, $id_group,
array ('delete_pending' => 0,
'`tagente_modulo`.disabled' => 0),
'tagente_modulo.disabled' => 0),
array ('tagente.id_agente', 'tagente.nombre'));
$table->data[2][1] = print_select (index_array ($agents, 'id_agente', 'nombre'),
'id_agents[]', 0, false, __('None'), 0, true, true, true, '', empty ($module_name));

View File

@ -47,7 +47,7 @@ if (is_ajax ()) {
$disabled = (int) get_parameter ('disabled');
$agents_alerts = get_agents_with_alert_template ($id_alert_templates, false,
array('order' => 'tagente.nombre, talert_template_modules.disabled', '`talert_template_modules`.disabled' => $disabled),
array('order' => 'tagente.nombre, talert_template_modules.disabled', 'talert_template_modules.disabled' => $disabled),
array ('LEFT(CONCAT(LEFT(tagente.nombre,40), " - ", tagente_modulo.nombre), 85) as agent_agentmodule_name',
'talert_template_modules.id as template_module_id'), $id_agents);

View File

@ -48,7 +48,7 @@ if (is_ajax ()) {
$standby = (int) get_parameter ('standby');
$agents_alerts = get_agents_with_alert_template ($id_alert_templates, false,
array('order' => 'tagente.nombre, talert_template_modules.standby', '`talert_template_modules`.standby' => $standby),
array('order' => 'tagente.nombre, talert_template_modules.standby', 'talert_template_modules.standby' => $standby),
array ('LEFT(CONCAT(LEFT(tagente.nombre,40), " - ", tagente_modulo.nombre), 85) as agent_agentmodule_name',
'talert_template_modules.id as template_module_id'), $id_agents);

View File

@ -54,15 +54,32 @@ if ($export_profile) {
}
//It's important to keep the structure and order in the same way for backwards compatibility.
$sql = sprintf ("SELECT components.name, components.description, components.type, components.max, components.min, components.module_interval,
components.tcp_port, components.tcp_send, components.tcp_rcv, components.snmp_community, components.snmp_oid,
components.id_module_group, components.id_modulo, components.plugin_user, components.plugin_pass, components.plugin_parameter,
components.max_timeout, components.history_data, components.min_warning, components.max_warning, components.min_critical,
components.max_critical, components.min_ff_event, comp_group.name AS group_name
FROM `tnetwork_component` AS components, tnetwork_profile_component AS tpc, tnetwork_component_group AS comp_group
WHERE tpc.id_nc = components.id_nc
AND components.id_group = comp_group.id_sg
AND tpc.id_np = %d", $id);
switch ($config["dbtype"]) {
case "mysql":
$sql = sprintf ("
SELECT components.name, components.description, components.type, components.max, components.min, components.module_interval,
components.tcp_port, components.tcp_send, components.tcp_rcv, components.snmp_community, components.snmp_oid,
components.id_module_group, components.id_modulo, components.plugin_user, components.plugin_pass, components.plugin_parameter,
components.max_timeout, components.history_data, components.min_warning, components.max_warning, components.min_critical,
components.max_critical, components.min_ff_event, comp_group.name AS group_name
FROM `tnetwork_component` AS components, tnetwork_profile_component AS tpc, tnetwork_component_group AS comp_group
WHERE tpc.id_nc = components.id_nc
AND components.id_group = comp_group.id_sg
AND tpc.id_np = %d", $id);
break;
case "postgresql":
$sql = sprintf ("
SELECT components.name, components.description, components.type, components.max, components.min, components.module_interval,
components.tcp_port, components.tcp_send, components.tcp_rcv, components.snmp_community, components.snmp_oid,
components.id_module_group, components.id_modulo, components.plugin_user, components.plugin_pass, components.plugin_parameter,
components.max_timeout, components.history_data, components.min_warning, components.max_warning, components.min_critical,
components.max_critical, components.min_ff_event, comp_group.name AS group_name
FROM \"tnetwork_component\" AS components, tnetwork_profile_component AS tpc, tnetwork_component_group AS comp_group
WHERE tpc.id_nc = components.id_nc
AND components.id_group = comp_group.id_sg
AND tpc.id_np = %d", $id);
break;
}
$components = get_db_all_rows_sql ($sql);

View File

@ -132,14 +132,23 @@ echo "</td></tr></table></form>";
if ($id_np > 0) {
// Show associated modules, allow to delete, and to add
$sql = sprintf ("SELECT npc.id_nc AS component_id, nc.name, nc.type, nc.description, nc.id_group AS `group`
FROM tnetwork_profile_component AS npc, tnetwork_component AS nc
WHERE npc.id_nc = nc.id_nc AND npc.id_np = %d", $id_np);
switch ($config["dbtype"]) {
case "mysql":
$sql = sprintf ("SELECT npc.id_nc AS component_id, nc.name, nc.type, nc.description, nc.id_group AS `group`
FROM tnetwork_profile_component AS npc, tnetwork_component AS nc
WHERE npc.id_nc = nc.id_nc AND npc.id_np = %d", $id_np);
break;
case "postgresql":
$sql = sprintf ("SELECT npc.id_nc AS component_id, nc.name, nc.type, nc.description, nc.id_group AS \"group\"
FROM tnetwork_profile_component AS npc, tnetwork_component AS nc
WHERE npc.id_nc = nc.id_nc AND npc.id_np = %d", $id_np);
break;
}
$result = get_db_all_rows_sql ($sql);
if (empty ($result)) {
echo '<div style="width:550px;" class="error">'.__("No modules for this profile").'</div>';
echo '<div style="width:550px;" class="error">' . __("No modules for this profile") . '</div>';
$result = array ();
}

View File

@ -120,7 +120,22 @@ if($moduleFilter != 0) {
$where .= ' AND id_agent_module = ' . $moduleFilter;
}
$items = get_db_all_rows_sql('SELECT * FROM treport_content WHERE ' . $where . ' AND id_report = ' . $idReport . ' ORDER BY `order` LIMIT ' . $offset . ', ' . $config["block_size"]);
switch ($config["dbtype"]) {
case "mysql":
$items = get_db_all_rows_sql('SELECT *
FROM treport_content
WHERE ' . $where . ' AND id_report = ' . $idReport . '
ORDER BY `order`
LIMIT ' . $offset . ', ' . $config["block_size"]);
break;
case "postgresql":
$items = get_db_all_rows_sql('SELECT *
FROM treport_content
WHERE ' . $where . ' AND id_report = ' . $idReport . '
ORDER BY "order"
LIMIT ' . $offset . ', ' . $config["block_size"]);
break;
}
$countItems = get_db_sql('SELECT COUNT(id_rc) FROM treport_content WHERE ' . $where . ' AND id_report = ' . $idReport);
$table = null;

View File

@ -254,15 +254,30 @@ switch ($action) {
else {
$idItem = $result;
$max = get_db_all_rows_sql('SELECT max(`order`) AS max
FROM treport_content WHERE id_report = ' . $idReport . ';');
switch ($config["dbtype"]) {
case "mysql":
$max = get_db_all_rows_sql('SELECT max(`order`) AS max
FROM treport_content WHERE id_report = ' . $idReport . ';');
break;
case "postgresql":
$max = get_db_all_rows_sql('SELECT max("order") AS max
FROM treport_content WHERE id_report = ' . $idReport . ';');
break;
}
if ($max === false) {
$max = 0;
}
else {
$max = $max[0]['max'];
}
process_sql_update('treport_content', array('`order`' => $max + 1), array('id_rc' => $idItem));
switch ($config["dbtype"]) {
case "mysql":
process_sql_update('treport_content', array('`order`' => $max + 1), array('id_rc' => $idItem));
break;
case "postgresql":
process_sql_update('treport_content', array('"order"' => $max + 1), array('id_rc' => $idItem));
break;
}
$resultOperationDB = true;
}
@ -370,7 +385,14 @@ switch ($action) {
}
break;
default:
$oldOrder = get_db_value_sql('SELECT `order` FROM treport_content WHERE id_rc = ' . $idItem);
switch ($config["dbtype"]) {
case "mysql":
$oldOrder = get_db_value_sql('SELECT `order` FROM treport_content WHERE id_rc = ' . $idItem);
break;
case "postgresql":
$oldOrder = get_db_value_sql('SELECT "order" FROM treport_content WHERE id_rc = ' . $idItem);
break;
}
//get_db_value_filter('order', 'treport_content', array('id_rc' => $idItem));
switch ($dir) {
@ -383,10 +405,26 @@ switch ($action) {
}
process_sql_begin();
$resultOperationDB = process_sql_update('treport_content',
array('`order`' => $oldOrder), array('`order`' => $newOrder, 'id_report' => $idReport));
switch ($config["dbtype"]) {
case "mysql":
$resultOperationDB = process_sql_update('treport_content',
array('`order`' => $oldOrder), array('`order`' => $newOrder, 'id_report' => $idReport));
break;
case "postgresql":
$resultOperationDB = process_sql_update('treport_content',
array('"order"' => $oldOrder), array('"order"' => $newOrder, 'id_report' => $idReport));
break;
}
if ($resultOperationDB !== false) {
$resultOperationDB = process_sql_update('treport_content', array('`order`' => $newOrder), array('id_rc' => $idItem));
switch ($config["dbtype"]) {
case "mysql":
$resultOperationDB = process_sql_update('treport_content', array('`order`' => $newOrder), array('id_rc' => $idItem));
break;
case "postgresql":
$resultOperationDB = process_sql_update('treport_content', array('"order"' => $newOrder), array('id_rc' => $idItem));
break;
}
if ($resultOperationDB !== false) {
process_sql_commit();
}

View File

@ -123,7 +123,15 @@ $table->rowclass[0] = 'datos3';
$report["group_name"] = get_group_name ($report['id_group']);
$contents = get_db_all_rows_field_filter ("treport_content", "id_report", $id_report, "`order`");
switch ($config["dbtype"]) {
case "mysql":
$contents = get_db_all_rows_field_filter ("treport_content", "id_report", $id_report, "`order`");
break;
case "postgresql":
$contents = get_db_all_rows_field_filter ("treport_content", "id_report", $id_report, '"order"'');
break;
}
if ($contents === false) {
return;
}

View File

@ -57,7 +57,14 @@ $table->data = array ();
// Current config["language"] could be set by user, not taken from global setup !
$current_system_lang = get_db_sql ('SELECT `value` FROM tconfig WHERE `token` = "language"');
switch ($config["dbtype"]) {
case "mysql":
$current_system_lang = get_db_sql ('SELECT `value` FROM tconfig WHERE `token` = "language"');
break;
case "postgresql":
$current_system_lang = get_db_sql ('SELECT "value" FROM tconfig WHERE "token" = \'language\'');
break;
}
if ($current_system_lang == ""){
$current_system_lang = "en";

View File

@ -69,7 +69,14 @@ if ($add_sla) {
}
if ($get_custom_sql) {
$sql = get_db_value_filter('`sql`', 'treport_custom_sql', array('id' => $id));
switch ($config["dbtype"]) {
case "mysql":
$sql = get_db_value_filter('`sql`', 'treport_custom_sql', array('id' => $id));
break;
case "postgresql":
$sql = get_db_value_filter('"sql"', 'treport_custom_sql', array('id' => $id));
break;
}
if ($sql === false) {
$data['correct'] = 0;

View File

@ -680,9 +680,19 @@ function graphic_incident_source ($width = 320, $height = 200) {
$data = array ();
$max_items = 5;
$sql = sprintf ('SELECT COUNT(id_incidencia) n_incident, origen
FROM tincidencia GROUP BY `origen`
ORDER BY 1 DESC LIMIT %d', $max_items);
switch ($config["dbtype"]) {
case "mysql":
$sql = sprintf ('SELECT COUNT(id_incidencia) n_incident, origen
FROM tincidencia GROUP BY `origen`
ORDER BY 1 DESC LIMIT %d', $max_items);
break;
case "postgresql":
$sql = sprintf ('SELECT COUNT(id_incidencia) n_incident, origen
FROM tincidencia GROUP BY "origen"
ORDER BY 1 DESC LIMIT %d', $max_items);
break;
}
$origins = get_db_all_rows_sql ($sql);
if($origins == false) {

View File

@ -959,6 +959,8 @@ function delete_alert_compound ($id_alert_compound) {
}
function get_agents_with_alert_template ($id_alert_template, $id_group, $filter = false, $fields = false, $id_agents = false) {
global $config;
if (empty ($id_alert_template))
return false;
if (! is_array ($filter))
@ -966,10 +968,26 @@ function get_agents_with_alert_template ($id_alert_template, $id_group, $filter
$filter[] = 'tagente_modulo.id_agente_modulo = talert_template_modules.id_agent_module';
$filter[] = 'tagente_modulo.id_agente = tagente.id_agente';
$filter['id_alert_template'] = $id_alert_template;
if (empty ($id_agents))
$filter['`tagente`.id_agente'] = array_keys (get_group_agents ($id_group, false, "none"));
else
$filter['`tagente`.id_agente'] = $id_agents;
if (empty ($id_agents)) {
switch ($config["dbtype"]) {
case "mysql":
$filter['`tagente`.id_agente'] = array_keys (get_group_agents ($id_group, false, "none"));
break;
case "postgresql":
$filter['tagente.id_agente'] = array_keys (get_group_agents ($id_group, false, "none"));
break;
}
}
else {
switch ($config["dbtype"]) {
case "mysql":
$filter['`tagente`.id_agente'] = $id_agents;
break;
case "postgresql":
$filter['tagente.id_agente'] = $id_agents;
break;
}
}
return get_db_all_rows_filter ('tagente, tagente_modulo, talert_template_modules',
$filter, $fields);

View File

@ -1018,16 +1018,31 @@ function get_agentmodule_type ($id_agentmodule) {
* @return int The number of times a monitor went down.
*/
function get_monitor_downs_in_period ($id_agent_module, $period, $date = 0) {
global $config;
if ($date == 0) {
$date = get_system_time ();
}
$datelimit = $date - $period;
$sql = sprintf ("SELECT COUNT(`id_agentmodule`) FROM `tevento` WHERE
`event_type` = 'monitor_down'
AND `id_agentmodule` = %d
AND `utimestamp` > %d
AND `utimestamp` <= %d",
$id_agent_module, $datelimit, $date);
switch ($config["dbtype"]) {
case "mysql":
$sql = sprintf ("SELECT COUNT(`id_agentmodule`) FROM `tevento` WHERE
`event_type` = 'monitor_down'
AND `id_agentmodule` = %d
AND `utimestamp` > %d
AND `utimestamp` <= %d",
$id_agent_module, $datelimit, $date);
break;
case "postgresql":
$sql = sprintf ("SELECT COUNT(\"id_agentmodule\") FROM \"tevento\" WHERE
\"event_type\" = 'monitor_down'
AND \"id_agentmodule\" = %d
AND \"utimestamp\" > %d
AND \"utimestamp\" <= %d",
$id_agent_module, $datelimit, $date);
break;
}
return get_db_sql ($sql);
}
@ -1042,16 +1057,31 @@ function get_monitor_downs_in_period ($id_agent_module, $period, $date = 0) {
* @return int The last time a monitor went down.
*/
function get_monitor_last_down_timestamp_in_period ($id_agent_module, $period, $date = 0) {
global $config;
if ($date == 0) {
$date = get_system_time ();
}
$datelimit = $date - $period;
$sql = sprintf ("SELECT MAX(`timestamp`) FROM `tevento` WHERE
event_type = 'monitor_down'
AND `id_agentmodule` = %d
AND `utimestamp` > %d
AND `utimestamp` <= %d",
$id_agent_module, $datelimit, $date);
switch ($config["dbtype"]) {
case "mysql":
$sql = sprintf ("SELECT MAX(`timestamp`) FROM `tevento` WHERE
event_type = 'monitor_down'
AND `id_agentmodule` = %d
AND `utimestamp` > %d
AND `utimestamp` <= %d",
$id_agent_module, $datelimit, $date);
break;
case "postgresql":
$sql = sprintf ("SELECT MAX(\"timestamp\") FROM \"tevento\" WHERE
event_type = 'monitor_down'
AND \"id_agentmodule\" = %d
AND \"utimestamp\" > %d
AND \"utimestamp\" <= %d",
$id_agent_module, $datelimit, $date);
break;
}
return get_db_sql ($sql);
}
@ -1064,6 +1094,8 @@ function get_monitor_last_down_timestamp_in_period ($id_agent_module, $period, $
* @return array An array with all the monitors defined in the group (tagente_modulo).
*/
function get_monitors_in_group ($id_group) {
global $config;
if ($id_group <= 0) {
//We select all groups the user has access to if it's 0 or -1
global $config;
@ -1074,11 +1106,23 @@ function get_monitors_in_group ($id_group) {
$id_group = implode (",",$id_group);
}
$sql = sprintf ("SELECT `tagente_modulo`.* FROM `tagente_modulo`, `ttipo_modulo`, `tagente` WHERE
`id_tipo_modulo` = `id_tipo`
AND `tagente`.`id_agente` = `tagente_modulo`.`id_agente`
AND `ttipo_modulo`.`nombre` LIKE '%%_proc'
AND `tagente`.`id_grupo` IN (%s) ORDER BY `tagente`.`nombre`", $id_group);
switch ($config["dbtype"]) {
case "mysql":
$sql = sprintf ("SELECT `tagente_modulo`.* FROM `tagente_modulo`, `ttipo_modulo`, `tagente` WHERE
`id_tipo_modulo` = `id_tipo`
AND `tagente`.`id_agente` = `tagente_modulo`.`id_agente`
AND `ttipo_modulo`.`nombre` LIKE '%%_proc'
AND `tagente`.`id_grupo` IN (%s) ORDER BY `tagente`.`nombre`", $id_group);
break;
case "postgresql":
$sql = sprintf ("SELECT tagente_modulo.* FROM tagente_modulo, ttipo_modulo, tagente WHERE
id_tipo_modulo = id_tipo
AND tagente.id_agente = tagente_modulo.id_agente
AND ttipo_modulo.nombre LIKE '%%_proc'
AND tagente.id_grupo IN (%s) ORDER BY tagente.nombre", $id_group);
break;
}
return get_db_all_rows_sql ($sql);
}
@ -1238,12 +1282,27 @@ function get_module_alert_fired ($id_agent_module, $id_alert, $period, $date = 0
* @return array An array with all the monitors defined (tagente_modulo).
*/
function get_monitors_in_agent ($id_agent) {
$sql = sprintf ("SELECT `tagente_modulo`.*
FROM `tagente_modulo`, `ttipo_modulo`, `tagente`
WHERE `id_tipo_modulo` = `id_tipo`
AND `tagente`.`id_agente` = `tagente_modulo`.`id_agente`
AND `ttipo_modulo`.`nombre` LIKE '%%_proc'
AND `tagente`.`id_agente` = %d", $id_agent);
global $config;
switch ($config["dbtype"]) {
case "mysql":
$sql = sprintf ("SELECT `tagente_modulo`.*
FROM `tagente_modulo`, `ttipo_modulo`, `tagente`
WHERE `id_tipo_modulo` = `id_tipo`
AND `tagente`.`id_agente` = `tagente_modulo`.`id_agente`
AND `ttipo_modulo`.`nombre` LIKE '%%_proc'
AND `tagente`.`id_agente` = %d", $id_agent);
break;
case "postgresql":
$sql = sprintf ("SELECT tagente_modulo.*
FROM tagente_modulo, ttipo_modulo, tagente
WHERE id_tipo_modulo = id_tipo
AND tagente.id_agente = tagente_modulo.id_agente
AND ttipo_modulo.nombre LIKE '%%_proc'
AND tagente.id_agente = %d", $id_agent);
break;
}
return get_db_all_rows_sql ($sql);
}
@ -1281,15 +1340,34 @@ function get_monitors_down ($monitors, $period = 0, $date = 0) {
* @return int The number of times an alert fired.
*/
function get_alert_fires_in_period ($id_alert_module, $period, $date = 0) {
global $config;
if (!$date)
$date = get_system_time ();
$date = get_system_time ();
$datelimit = $date - $period;
$sql = sprintf ("SELECT COUNT(`id_agentmodule`) FROM `tevento` WHERE
`event_type` = 'alert_fired'
AND `id_alert_am` = %d
AND `utimestamp` > %d
AND `utimestamp` <= %d",
$id_alert_module, $datelimit, $date);
switch ($config["dbtype"]) {
case "mysql":
$sql = sprintf ("SELECT COUNT(`id_agentmodule`)
FROM `tevento`
WHERE `event_type` = 'alert_fired'
AND `id_alert_am` = %d
AND `utimestamp` > %d
AND `utimestamp` <= %d",
$id_alert_module, $datelimit, $date);
break;
case "postgresql":
$sql = sprintf ("SELECT COUNT(id_agentmodule)
FROM tevento
WHERE event_type = 'alert_fired'
AND id_alert_am = %d
AND utimestamp > %d
AND utimestamp <= %d",
$id_alert_module, $datelimit, $date);
break;
}
return (int) get_db_sql ($sql);
}
@ -1358,16 +1436,34 @@ function get_alerts_fired ($alerts, $period = 0, $date = 0) {
* @return int The last time an alert fired. It's an UNIX timestamp.
*/
function get_alert_last_fire_timestamp_in_period ($id_alert_module, $period, $date = 0) {
global $config;
if ($date == 0) {
$date = get_system_time ();
}
$datelimit = $date - $period;
$sql = sprintf ("SELECT MAX(`utimestamp`) FROM `tevento` WHERE
`event_type` = 'alert_fired'
AND `id_alert_am` = %d
AND `utimestamp` > %d
AND `utimestamp` <= %d",
$id_alert_module, $datelimit, $date);
switch ($config["dbtype"]) {
case "mysql":
$sql = sprintf ("SELECT MAX(`utimestamp`)
FROM `tevento`
WHERE `event_type` = 'alert_fired'
AND `id_alert_am` = %d
AND `utimestamp` > %d
AND `utimestamp` <= %d",
$id_alert_module, $datelimit, $date);
break;
case "postgresql":
$sql = sprintf ("SELECT MAX(utimestamp)
FROM tevento
WHERE event_type = 'alert_fired'
AND id_alert_am = %d
AND utimestamp > %d
AND utimestamp <= %d",
$id_alert_module, $datelimit, $date);
break;
}
return get_db_sql ($sql);
}
@ -1903,10 +1999,21 @@ function get_networkprofile_name ($id_network_profile) {
* @param string IP address to assign
*/
function agent_add_address ($id_agent, $ip_address) {
global $config;
// Check if already is attached to agent
$sql = sprintf ("SELECT COUNT(`ip`) FROM taddress_agent, taddress
WHERE taddress_agent.id_a = taddress.id_a
AND ip = '%s' AND id_agent = %d",$ip_address,$id_agent);
switch ($config["dbtype"]) {
case "mysql":
$sql = sprintf ("SELECT COUNT(`ip`) FROM taddress_agent, taddress
WHERE taddress_agent.id_a = taddress.id_a
AND ip = '%s' AND id_agent = %d",$ip_address,$id_agent);
break;
case "postgresql":
$sql = sprintf ("SELECT COUNT(ip) FROM taddress_agent, taddress
WHERE taddress_agent.id_a = taddress.id_a
AND ip = '%s' AND id_agent = %d", $ip_address, $id_agent);
break;
}
$current_address = get_db_sql ($sql);
if ($current_address > 0)
return;
@ -1952,7 +2059,15 @@ function agent_delete_address ($id_agent, $ip_address) {
if (get_agent_address ($id_agent) == $ip_address) {
$new_ips = get_agent_addresses ($id_agent);
// Change main address in agent to first one in the list
$query = sprintf ("UPDATE tagente SET `direccion` = '%s' WHERE id_agente = %d", current ($new_ips), $id_agent);
switch ($config["dbtype"]) {
case "mysql":
$query = sprintf ("UPDATE tagente SET `direccion` = '%s' WHERE id_agente = %d", current ($new_ips), $id_agent);
break;
case "postgresql":
$query = sprintf ("UPDATE tagente SET direccion = '%s' WHERE id_agente = %d", current ($new_ips), $id_agent);
break;
}
process_sql ($query);
}
}

View File

@ -1028,14 +1028,28 @@ function validateMapData($map_name, $map_zoom_level,
* @return Array Return a asociative array whith the items 'map', 'connections' and 'layers'. And in 'layers' has data and item 'agents'.
*/
function getMapData($idMap) {
global $config;
$returnVar = array();
$map = get_db_row('tgis_map', 'id_tgis_map', $idMap);
$connections = get_db_all_rows_sql('SELECT t1.tgis_map_connection_id_tmap_connection AS id_conection,
t1.default_map_connection AS `default`,
(SELECT t2.num_zoom_levels
FROM tgis_map_connection AS t2 WHERE t2.id_tmap_connection = t1.tgis_map_connection_id_tmap_connection) AS num_zoom_levels
FROM tgis_map_has_tgis_map_connection AS t1 WHERE t1.tgis_map_id_tgis_map = '. $map['id_tgis_map']);
switch ($config["dbtype"]) {
case "mysql":
$connections = get_db_all_rows_sql('SELECT t1.tgis_map_connection_id_tmap_connection AS id_conection,
t1.default_map_connection AS `default`,
(SELECT t2.num_zoom_levels
FROM tgis_map_connection AS t2 WHERE t2.id_tmap_connection = t1.tgis_map_connection_id_tmap_connection) AS num_zoom_levels
FROM tgis_map_has_tgis_map_connection AS t1 WHERE t1.tgis_map_id_tgis_map = '. $map['id_tgis_map']);
break;
case "postgresql":
$connections = get_db_all_rows_sql('SELECT t1.tgis_map_connection_id_tmap_connection AS id_conection,
t1.default_map_connection AS "default",
(SELECT t2.num_zoom_levels
FROM tgis_map_connection AS t2 WHERE t2.id_tmap_connection = t1.tgis_map_connection_id_tmap_connection) AS num_zoom_levels
FROM tgis_map_has_tgis_map_connection AS t1 WHERE t1.tgis_map_id_tgis_map = '. $map['id_tgis_map']);
break;
}
$layers = get_db_all_rows_sql('SELECT id_tmap_layer, layer_name, tgrupo_id_grupo AS layer_group, view_layer AS layer_visible FROM tgis_map_layer WHERE tgis_map_id_tgis_map = ' . $map['id_tgis_map']);
if ($layers === false) $layers = array();

View File

@ -230,11 +230,12 @@ function create_agent_module ($id_agent, $name, $values = false, $disableACL = f
function get_agents_with_module_name ($module_name, $id_group, $filter = false, $fields = 'tagente.*') {
if (empty ($module_name))
return false;
if (! is_array ($filter))
$filter = array ();
$filter[] = 'tagente_modulo.id_agente = tagente.id_agente';
$filter['`tagente_modulo`.nombre'] = $module_name;
$filter['`tagente`.id_agente'] = array_keys (get_group_agents ($id_group, false, "none"));
$filter['tagente_modulo.nombre'] = $module_name;
$filter['tagente.id_agente'] = array_keys (get_group_agents ($id_group, false, "none"));
return get_db_all_rows_filter ('tagente, tagente_modulo',
$filter, $fields);

View File

@ -1836,8 +1836,8 @@ function render_report_html_item ($content, $table, $report, $mini = false) {
//RUNNING
$table->style[1] = 'text-align: right';
$data = array ();
$data[0] = $sizh.__('S.L.A.').$sizhfin;
$data[1] = $sizh.human_time_description ($content['period']).$sizhfin;;
$data[0] = $sizh . __('S.L.A.').$sizhfin;
$data[1] = $sizh . human_time_description_raw($content['period']) . $sizhfin;;
$n = array_push ($table->data, $data);
// Put description at the end of the module (if exists)
@ -2116,7 +2116,14 @@ function render_report_html_item ($content, $table, $report, $mini = false) {
}
if ($content['treport_custom_sql_id'] != 0) {
$sql = safe_output_html (get_db_value_filter('`sql`', 'treport_custom_sql', array('id' => $content['treport_custom_sql_id'])));
switch ($config["dbtype"]) {
case "mysql":
$sql = safe_output_html (get_db_value_filter('`sql`', 'treport_custom_sql', array('id' => $content['treport_custom_sql_id'])));
break;
case "postgresql":
$sql = safe_output_html (get_db_value_filter('"sql"', 'treport_custom_sql', array('id' => $content['treport_custom_sql_id'])));
break;
}
}
else {
$sql = safe_output_html ($content['external_source']);

View File

@ -184,6 +184,8 @@ function get_report_content ($id_report_content, $filter = false, $fields = fals
* @return array All the contents of a report.
*/
function create_report_content ($id_report, $values) {
global $config;
$id_report = safe_int ($id_report);
if (empty ($id_report))
return false;
@ -193,9 +195,21 @@ function create_report_content ($id_report, $values) {
if (! is_array ($values))
return false;
$values['id_report'] = $id_report;
unset ($values['`order`']);
$order = (int) get_db_value ('MAX(`order`)', 'treport_content', 'id_report', $id_report);
$values['`order`'] = $order + 1;
switch ($config["dbtype"]) {
case "mysql":
unset ($values['`order`']);
$order = (int) get_db_value ('MAX(`order`)', 'treport_content', 'id_report', $id_report);
$values['`order`'] = $order + 1;
break;
case "postgresql":
unset ($values['"order"']);
$order = (int) get_db_value ('MAX("order")', 'treport_content', 'id_report', $id_report);
$values['"order"'] = $order + 1;
break;
}
return @process_sql_insert ('treport_content', $values);
}
@ -236,21 +250,41 @@ function get_report_contents ($id_report, $filter = false, $fields = false) {
* @return bool True if moved, false otherwise.
*/
function move_report_content_up ($id_report_content) {
global $config;
if (empty ($id_report_content))
return false;
$content = get_report_content ($id_report_content);
if ($content === false)
return false;
$order = get_db_value ('`order`', 'treport_content', 'id_rc', $id_report_content);
/* Set the previous element order to the current of the content we want to change */
process_sql_update ('treport_content',
array ('`order` = `order` + 1'),
array ('id_report' => $content['id_report'],
'`order` = '.($order - 1)));
return (@process_sql_update ('treport_content',
array ('`order` = `order` - 1'),
array ('id_rc' => $id_report_content))) !== false;
switch ($config["dbtype"]) {
case "mysql":
$order = get_db_value ('`order`', 'treport_content', 'id_rc', $id_report_content);
/* Set the previous element order to the current of the content we want to change */
process_sql_update ('treport_content',
array ('`order` = `order` + 1'),
array ('id_report' => $content['id_report'],
'`order` = '.($order - 1)));
return (@process_sql_update ('treport_content',
array ('`order` = `order` - 1'),
array ('id_rc' => $id_report_content))) !== false;
break;
case "postgresql":
$order = get_db_value ('"order"', 'treport_content', 'id_rc', $id_report_content);
/* Set the previous element order to the current of the content we want to change */
process_sql_update ('treport_content',
array ('"order" = "order" + 1'),
array ('id_report' => $content['id_report'],
'"order" = '.($order - 1)));
return (@process_sql_update ('treport_content',
array ('"order" = "order" - 1'),
array ('id_rc' => $id_report_content))) !== false;
break;
}
}
/**
@ -261,21 +295,39 @@ function move_report_content_up ($id_report_content) {
* @return bool True if moved, false otherwise.
*/
function move_report_content_down ($id_report_content) {
global $config;
if (empty ($id_report_content))
return false;
$content = get_report_content ($id_report_content);
if ($content === false)
return false;
$order = get_db_value ('`order`', 'treport_content', 'id_rc', $id_report_content);
/* Set the previous element order to the current of the content we want to change */
process_sql_update ('treport_content',
array ('`order` = `order` - 1'),
array ('id_report' => (int) $content['id_report'],
'`order` = '.($order + 1)));
return (@process_sql_update ('treport_content',
array ('`order` = `order` + 1'),
array ('id_rc' => $id_report_content))) !== false;
switch ($config["dbtype"]) {
case "mysql":
$order = get_db_value ('`order`', 'treport_content', 'id_rc', $id_report_content);
/* Set the previous element order to the current of the content we want to change */
process_sql_update ('treport_content',
array ('`order` = `order` - 1'),
array ('id_report' => (int) $content['id_report'],
'`order` = '.($order + 1)));
return (@process_sql_update ('treport_content',
array ('`order` = `order` + 1'),
array ('id_rc' => $id_report_content))) !== false;
break;
case "postgresql":
$order = get_db_value ('"order"', 'treport_content', 'id_rc', $id_report_content);
/* Set the previous element order to the current of the content we want to change */
process_sql_update ('treport_content',
array ('"order" = "order" - 1'),
array ('id_report' => (int) $content['id_report'],
'"order" = '.($order + 1)));
return (@process_sql_update ('treport_content',
array ('"order" = "order" + 1'),
array ('id_rc' => $id_report_content))) !== false;
break;
}
}
/**
@ -292,11 +344,24 @@ function delete_report_content ($id_report_content) {
$content = get_report_content ($id_report_content);
if ($content === false)
return false;
$order = get_db_value ('`order`', 'treport_content', 'id_rc', $id_report_content);
process_sql_update ('treport_content',
array ('`order` = `order` - 1'),
array ('id_report' => (int) $content['id_report'],
'`order` > '.$order));
switch ($config["dbtype"]) {
case "mysql":
$order = get_db_value ('`order`', 'treport_content', 'id_rc', $id_report_content);
process_sql_update ('treport_content',
array ('`order` = `order` - 1'),
array ('id_report' => (int) $content['id_report'],
'`order` > '.$order));
break;
case "postgresql":
$order = get_db_value ('"order"', 'treport_content', 'id_rc', $id_report_content);
process_sql_update ('treport_content',
array ('"order" = "order" - 1'),
array ('id_report' => (int) $content['id_report'],
'"order" > '.$order));
break;
}
return (@process_sql_delete ('treport_content',
array ('id_rc' => $id_report_content))) !== false;
}

View File

@ -44,7 +44,7 @@ function get_server ($id_server, $filter = false, $fields = false) {
* @return All the servers available.
*/
function get_server_names () {
$all_servers = @get_db_all_rows_filter ('tserver', false, array ('DISTINCT(`name`) as name'));
$all_servers = @get_db_all_rows_filter ('tserver', false, array ('DISTINCT(name) as name'));
if ($all_servers === false)
return array ();

View File

@ -31,9 +31,11 @@ if (! check_acl ($config['id_user'], 0, "AR")) {
if (isset ($_GET["update_netgroup"])) {
$group = get_parameter_get ("update_netgroup", 0);
if (check_acl ($config['id_user'], $group, "AW")) {
$sql = sprintf ("UPDATE tagente_modulo SET `flag` = 1 WHERE `id_agente` = ANY(SELECT id_agente FROM tagente WHERE `id_grupo` = %d)",$group);
process_sql ($sql);
} else {
$where = array('id_agente' => 'ANY(SELECT id_agente FROM tagente WHERE id_grupo = ' . $group . ')');
process_sql_update('tagente_modulo', array('flag' => 1), $where);
}
else {
pandora_audit("ACL Violation", "Trying to set flag for groups");
require ("general/noaccess.php");
exit;

View File

@ -78,40 +78,40 @@ $sql_post = "";
if ($event_view_hr > 0) {
$unixtime = (int) (get_system_time () - ($event_view_hr * 3600)); //Put hours in seconds
$sql_post .= " AND `tevento`.`utimestamp` > ".$unixtime;
$sql_post .= " AND tevento.utimestamp > ".$unixtime;
}
if ($ev_group > 1)
$sql_post .= " AND `tevento`.`id_grupo` = $ev_group";
$sql_post .= " AND tevento.id_grupo = $ev_group";
switch($status) {
case 0:
case 1:
case 2:
$sql_post .= " AND `tevento`.`estado` = ".$status;
$sql_post .= " AND tevento.estado = ".$status;
break;
case 3:
$sql_post .= " AND (`tevento`.`estado` = 0 OR `tevento`.`estado` = 2)";
$sql_post .= " AND (tevento.estado = 0 OR tevento.estado = 2)";
break;
}
if ($search != "")
$sql_post .= " AND `tevento`.`evento` LIKE '%$search%'";
$sql_post .= " AND tevento.evento LIKE '%$search%'";
if ($event_type != "") {
// If normal, warning, could be several (going_up_warning, going_down_warning... too complex
// for the user so for him is presented only "warning, critical and normal"
if ($event_type == "warning" || $event_type == "critical" || $event_type == "normal") {
$sql_post .= " AND `tevento`.`event_type` LIKE '%$event_type%' ";
$sql_post .= " AND tevento.event_type LIKE '%$event_type%' ";
}
elseif ($event_type == "not_normal") {
$sql_post .= " AND `tevento`.`event_type` LIKE '%warning%' OR `tevento`.`event_type` LIKE '%critical%' OR `tevento`.`event_type` LIKE '%unknown%' ";
$sql_post .= " AND tevento.event_type LIKE '%warning%' OR tevento.event_type LIKE '%critical%' OR tevento.event_type LIKE '%unknown%' ";
}
else
$sql_post .= " AND `tevento`.`event_type` = '".$event_type."'";
$sql_post .= " AND tevento.event_type = '".$event_type."'";
}
if ($severity != -1)
$sql_post .= " AND `tevento`.`criticity` >= ".$severity;
$sql_post .= " AND tevento.criticity >= ".$severity;
@ -149,22 +149,22 @@ else {
if ($id_agent != -1)
$sql_post .= " AND `tevento`.`id_agente` = ".$id_agent;
$sql_post .= " AND tevento.id_agente = ".$id_agent;
if ($id_event != -1)
$sql_post .= " AND id_evento = ".$id_event;
// Avoid to show system events to not administrators
if(!check_acl($user, 0, "PM"))
$sql_post .= " AND `tevento`.`event_type` <> 'system'";
$sql_post .= " AND tevento.event_type <> 'system'";
$sql="SELECT `tevento`.`id_evento` AS event_id,
`tevento`.`id_agente` AS id_agent,
`tevento`.`id_usuario` AS validated_by,
`tevento`.`id_grupo` AS id_group,
`tevento`.`estado` AS validated,
`tevento`.`evento` AS event_descr,
`tevento`.`utimestamp` AS unix_timestamp,
`tevento`.`event_type` AS event_type
$sql="SELECT tevento.id_evento AS event_id,
tevento.id_agente AS id_agent,
tevento.id_usuario AS validated_by,
tevento.id_grupo AS id_group,
tevento.estado AS validated,
tevento.evento AS event_descr,
tevento.utimestamp AS unix_timestamp,
tevento.event_type AS event_type
FROM tevento
WHERE 1 = 1".$sql_post."
ORDER BY utimestamp DESC LIMIT 0 , 30";

View File

@ -133,7 +133,14 @@ $table->rowclass[0] = 'datos3';
$report["group_name"] = get_group_name ($report['id_group']);
$contents = get_db_all_rows_field_filter ("treport_content", "id_report", $id_report, "`order`");
switch ($config["dbtype"]) {
case "mysql":
$contents = get_db_all_rows_field_filter ("treport_content", "id_report", $id_report, "`order`");
break;
case "postgresql":
$contents = get_db_all_rows_field_filter ("treport_content", "id_report", $id_report, '"order"');
break;
}
if ($contents === false) {
return;
}

View File

@ -13,7 +13,6 @@
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
function xml_array ($array) {
foreach ($array as $name => $value) {
if (is_int ($name)) {
@ -100,6 +99,8 @@ else {
require_once ("include/auth/mysql.php");
}
global $config;
check_login ();
$id_report = (int) get_parameter ('id');
@ -141,7 +142,14 @@ if ($datetime === false || $datetime == -1) {
}
$group_name = get_group_name ($report['id_group']);
$contents = get_db_all_rows_field_filter ('treport_content', 'id_report', $id_report, '`order`');
switch ($config["dbtype"]) {
case "mysql":
$contents = get_db_all_rows_field_filter ('treport_content', 'id_report', $id_report, '`order`');
break;
case "postgresql":
$contents = get_db_all_rows_field_filter ('treport_content', 'id_report', $id_report, '"order"');
break;
}
$time = get_system_time ();
echo '<report>';
@ -350,7 +358,14 @@ foreach ($contents as $content) {
}
if ($content['treport_custom_sql_id'] != 0) {
$sql = get_db_value_filter('`sql`', 'treport_custom_sql', array('id' => $content['treport_custom_sql_id']));
switch ($config["dbtype"]) {
case "mysql":
$sql = get_db_value_filter('`sql`', 'treport_custom_sql', array('id' => $content['treport_custom_sql_id']));
break;
case "postgresql":
$sql = get_db_value_filter('"sql"', 'treport_custom_sql', array('id' => $content['treport_custom_sql_id']));
break;
}
}
else {
$sql = $content['external_source'];