From f27b28d4a38dc4ba1a2122246ecd7b5dcfe2c117 Mon Sep 17 00:00:00 2001 From: juanmanuelr Date: Mon, 11 Apr 2011 17:05:20 +0000 Subject: [PATCH] 2011-04-11 Juan Manuel Ramon * include/functions_events.php include/functions_messages.php include/db/oracle.php include/functions_modules.php include/functions_reporting.php include/functions_groups.php include/functions_gis.php include/auth/mysql.php include/functions_networkmap.php include/functions_servers.php include/functions_network_components.php include/ajax/reporting.ajax.php include/ajax/agent.php include/functions_config.php include/functions_api.php include/help/en/help_timesource.php include/help/es/help_timesource.php include/help/ja/help_timesource.php include/fgraph.php include/functions.php include/functions_agents.php include/functions_db.php include/functions_fsgraph.php include/functions_alerts.php include/functions_reports.php pandoradb.oracle.sql install.php extensions/system_info.php extensions/update_manager.php extensions/dbmanager.php extensions/users_connected.php extensions/module_groups.php extensions/update_manager/sql/update_manager.oracle.sql extensions/update_manager/load_updatemanager.php extensions/update_manager/lib/libupdate_manager_client.php extensions/update_manager/lib/libupdate_manager.php extensions/update_manager/lib/libupdate_manager_components.php extensions/update_manager/lib/libupdate_manager_updates.php operation/search_modules.php operation/agentes/status_monitor.php operation/agentes/alerts_status.php operation/agentes/datos_agente.php operation/agentes/estado_ultimopaquete.php operation/agentes/exportdata.php operation/agentes/gis_view.php operation/agentes/estado_monitores.php operation/agentes/ver_agente.php operation/snmpconsole/snmp_view.php operation/users/user_edit.php operation/gis_maps/render_view.php operation/gis_maps/ajax.php operation/events/events_rss.php operation/events/events_list.php operation/events/events_marquee.php operation/search_alerts.php operation/reporting/reporting_xml.php operation/reporting/reporting_viewer.php pandoradb.data.oracle.sql extras/pandora_diag.php mobile/operation/agents/monitor_status.php mobile/operation/agents/view_agents.php mobile/operation/events/events.php general/logon_ok.php godmode/groups/group_list.php godmode/admin_access_logs.php godmode/db/db_main.php godmode/agentes/agent_template.php godmode/agentes/module_manager.php godmode/agentes/modificar_agente.php godmode/agentes/configurar_agente.php godmode/agentes/module_manager_editor.php godmode/agentes/planned_downtime.php godmode/alerts/alert_list.list.php godmode/alerts/alert_compounds.php godmode/alerts/alert_list.php godmode/setup/setup.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 godmode/reporting/reporting_builder.item_editor.php: Support for Oracle DBMS over Console code. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@4187 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f --- pandora_console/ChangeLog | 86 ++++++ pandora_console/extensions/dbmanager.php | 1 + pandora_console/extensions/module_groups.php | 37 ++- pandora_console/extensions/system_info.php | 10 + pandora_console/extensions/update_manager.php | 10 + .../update_manager/lib/libupdate_manager.php | 44 +++ .../lib/libupdate_manager_client.php | 4 + .../lib/libupdate_manager_components.php | 24 ++ .../lib/libupdate_manager_updates.php | 12 + .../update_manager/load_updatemanager.php | 5 + .../sql/update_manager.oracle.sql | 28 ++ .../extensions/users_connected.php | 4 + pandora_console/extras/pandora_diag.php | 11 + pandora_console/general/logon_ok.php | 18 +- pandora_console/godmode/admin_access_logs.php | 95 ++++++- .../godmode/agentes/agent_template.php | 12 +- .../godmode/agentes/configurar_agente.php | 8 + .../godmode/agentes/modificar_agente.php | 41 +++ .../godmode/agentes/module_manager.php | 72 +++-- .../godmode/agentes/module_manager_editor.php | 2 +- .../godmode/agentes/planned_downtime.php | 5 + .../godmode/alerts/alert_compounds.php | 44 ++- .../godmode/alerts/alert_list.list.php | 31 ++- pandora_console/godmode/alerts/alert_list.php | 2 +- pandora_console/godmode/db/db_main.php | 15 +- pandora_console/godmode/groups/group_list.php | 19 +- .../modules/manage_network_templates.php | 12 + .../modules/manage_network_templates_form.php | 5 + .../reporting_builder.item_editor.php | 1 + .../reporting_builder.list_items.php | 10 + .../godmode/reporting/reporting_builder.php | 10 + .../reporting/reporting_builder.preview.php | 1 + pandora_console/godmode/setup/setup.php | 3 + pandora_console/include/ajax/agent.php | 11 +- .../include/ajax/reporting.ajax.php | 3 + pandora_console/include/auth/mysql.php | 4 +- pandora_console/include/db/oracle.php | 105 ++++++-- pandora_console/include/fgraph.php | 143 ++++++++-- pandora_console/include/functions.php | 6 + pandora_console/include/functions_agents.php | 39 ++- pandora_console/include/functions_alerts.php | 2 + pandora_console/include/functions_api.php | 2 + pandora_console/include/functions_config.php | 1 + pandora_console/include/functions_db.php | 79 ++++-- pandora_console/include/functions_events.php | 26 +- pandora_console/include/functions_fsgraph.php | 2 +- pandora_console/include/functions_gis.php | 4 + pandora_console/include/functions_groups.php | 139 ++++++++-- .../include/functions_messages.php | 2 +- pandora_console/include/functions_modules.php | 42 ++- .../include/functions_network_components.php | 38 ++- .../include/functions_networkmap.php | 24 +- .../include/functions_reporting.php | 43 ++- pandora_console/include/functions_reports.php | 4 + pandora_console/include/functions_servers.php | 26 ++ .../include/help/en/help_timesource.php | 3 + .../include/help/es/help_timesource.php | 3 + .../include/help/ja/help_timesource.php | 3 + pandora_console/install.php | 252 ++++++++++++++++-- .../operation/agents/monitor_status.php | 13 +- .../mobile/operation/agents/view_agents.php | 14 +- .../mobile/operation/events/events.php | 6 + .../operation/agentes/alerts_status.php | 1 + .../operation/agentes/datos_agente.php | 12 + .../operation/agentes/estado_monitores.php | 9 + .../agentes/estado_ultimopaquete.php | 55 +++- .../operation/agentes/exportdata.php | 22 +- .../operation/agentes/gis_view.php | 3 + .../operation/agentes/status_monitor.php | 64 +++++ .../operation/agentes/ver_agente.php | 2 +- .../operation/events/events_list.php | 32 +++ .../operation/events/events_marquee.php | 3 + .../operation/events/events_rss.php | 13 + pandora_console/operation/gis_maps/ajax.php | 8 + .../operation/gis_maps/render_view.php | 3 + .../operation/reporting/reporting_viewer.php | 3 + .../operation/reporting/reporting_xml.php | 4 + pandora_console/operation/search_alerts.php | 1 + pandora_console/operation/search_modules.php | 23 ++ .../operation/snmpconsole/snmp_view.php | 32 +++ pandora_console/operation/users/user_edit.php | 2 +- pandora_console/pandoradb.data.oracle.sql | 4 +- pandora_console/pandoradb.oracle.sql | 152 +++++------ 83 files changed, 1882 insertions(+), 287 deletions(-) create mode 100644 pandora_console/extensions/update_manager/sql/update_manager.oracle.sql diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index 163fabb8a5..39d6dd7e42 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,89 @@ +2011-04-11 Juan Manuel Ramon + + * include/functions_events.php + include/functions_messages.php + include/db/oracle.php + include/functions_modules.php + include/functions_reporting.php + include/functions_groups.php + include/functions_gis.php + include/auth/mysql.php + include/functions_networkmap.php + include/functions_servers.php + include/functions_network_components.php + include/ajax/reporting.ajax.php + include/ajax/agent.php + include/functions_config.php + include/functions_api.php + include/help/en/help_timesource.php + include/help/es/help_timesource.php + include/help/ja/help_timesource.php + include/fgraph.php + include/functions.php + include/functions_agents.php + include/functions_db.php + include/functions_fsgraph.php + include/functions_alerts.php + include/functions_reports.php + pandoradb.oracle.sql + install.php + extensions/system_info.php + extensions/update_manager.php + extensions/dbmanager.php + extensions/users_connected.php + extensions/module_groups.php + extensions/update_manager/sql/update_manager.oracle.sql + extensions/update_manager/load_updatemanager.php + extensions/update_manager/lib/libupdate_manager_client.php + extensions/update_manager/lib/libupdate_manager.php + extensions/update_manager/lib/libupdate_manager_components.php + extensions/update_manager/lib/libupdate_manager_updates.php + operation/search_modules.php + operation/agentes/status_monitor.php + operation/agentes/alerts_status.php + operation/agentes/datos_agente.php + operation/agentes/estado_ultimopaquete.php + operation/agentes/exportdata.php + operation/agentes/gis_view.php + operation/agentes/estado_monitores.php + operation/agentes/ver_agente.php + operation/snmpconsole/snmp_view.php + operation/users/user_edit.php + operation/gis_maps/render_view.php + operation/gis_maps/ajax.php + operation/events/events_rss.php + operation/events/events_list.php + operation/events/events_marquee.php + operation/search_alerts.php + operation/reporting/reporting_xml.php + operation/reporting/reporting_viewer.php + pandoradb.data.oracle.sql + extras/pandora_diag.php + mobile/operation/agents/monitor_status.php + mobile/operation/agents/view_agents.php + mobile/operation/events/events.php + general/logon_ok.php + godmode/groups/group_list.php + godmode/admin_access_logs.php + godmode/db/db_main.php + godmode/agentes/agent_template.php + godmode/agentes/module_manager.php + godmode/agentes/modificar_agente.php + godmode/agentes/configurar_agente.php + godmode/agentes/module_manager_editor.php + godmode/agentes/planned_downtime.php + godmode/alerts/alert_list.list.php + godmode/alerts/alert_compounds.php + godmode/alerts/alert_list.php + godmode/setup/setup.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 + godmode/reporting/reporting_builder.item_editor.php: Support for Oracle DBMS + over Console code. + 2011-04-11 Miguel de Dios * godmode/reporting/graph_builder.main.php: changed to use constants. diff --git a/pandora_console/extensions/dbmanager.php b/pandora_console/extensions/dbmanager.php index 5fcf7acf05..5c70e8e6bc 100644 --- a/pandora_console/extensions/dbmanager.php +++ b/pandora_console/extensions/dbmanager.php @@ -49,6 +49,7 @@ function dbmanager_query ($sql, &$error) { return "Empty"; break; case "postgresql": + case "oracle": $retval = array(); if ($sql == '') diff --git a/pandora_console/extensions/module_groups.php b/pandora_console/extensions/module_groups.php index 01b9b2c847..83003fd400 100644 --- a/pandora_console/extensions/module_groups.php +++ b/pandora_console/extensions/module_groups.php @@ -90,15 +90,31 @@ function mainModuleGroups() { require_once ('include/functions_reporting.php'); //The big query - $sql = "SELECT COUNT(id_agente) AS count, estado - FROM tagente_estado - WHERE utimestamp != 0 AND id_agente IN - (SELECT id_agente FROM tagente WHERE id_grupo = %d AND disabled IS FALSE) - AND id_agente_modulo IN - (SELECT id_agente_modulo - FROM tagente_modulo - WHERE id_module_group = %d AND disabled IS FALSE AND delete_pending IS FALSE) - GROUP BY estado"; + switch ($config["dbtype"]) { + case "mysql": + case "postgresql": + $sql = "SELECT COUNT(id_agente) AS count, estado + FROM tagente_estado + WHERE utimestamp != 0 AND id_agente IN + (SELECT id_agente FROM tagente WHERE id_grupo = %d AND disabled IS FALSE) + AND id_agente_modulo IN + (SELECT id_agente_modulo + FROM tagente_modulo + WHERE id_module_group = %d AND disabled IS FALSE AND delete_pending IS FALSE) + GROUP BY estado"; + break; + case "oracle": + $sql = "SELECT COUNT(id_agente) AS count, estado + FROM tagente_estado + WHERE utimestamp != 0 AND id_agente IN + (SELECT id_agente FROM tagente WHERE id_grupo = %d AND (disabled IS NOT NULL AND disabled <> 0)) + AND id_agente_modulo IN + (SELECT id_agente_modulo + FROM tagente_modulo + WHERE id_module_group = %d AND (disabled IS NOT NULL AND disabled <> 0) AND (delete_pending IS NOT NULL AND delete_pending <> 0)) + GROUP BY estado"; + break; + } print_page_header (__("Combined table of agent group and module group")); @@ -134,9 +150,10 @@ function mainModuleGroups() { $row = array(); array_push($row, printTruncateText($name, 20)); - + foreach ($modelGroups as $idModelGroup => $modelGroup) { $query = sprintf($sql,$idAgentGroup, $idModelGroup); + $rowsDB = get_db_all_rows_sql ($query); diff --git a/pandora_console/extensions/system_info.php b/pandora_console/extensions/system_info.php index 9aedbe8688..c5b8841ca1 100644 --- a/pandora_console/extensions/system_info.php +++ b/pandora_console/extensions/system_info.php @@ -65,6 +65,16 @@ function getPandoraDiagnostic(&$systemInfo) { $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 "oracle": + $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'] = 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; } } diff --git a/pandora_console/extensions/update_manager.php b/pandora_console/extensions/update_manager.php index c8cf13274b..031e2153fd 100644 --- a/pandora_console/extensions/update_manager.php +++ b/pandora_console/extensions/update_manager.php @@ -47,6 +47,9 @@ function pandora_update_manager_install () { case 'postgresql': $sentences = file (EXTENSIONS_DIR.'/update_manager/sql/update_manager.postgreSQL.sql'); break; + case 'oracle': + $sentences = file (EXTENSIONS_DIR.'/update_manager/sql/update_manager.oracle.sql'); + break; } foreach ($sentences as $sentence) { $success = process_sql ($sentence); @@ -82,6 +85,13 @@ function pandora_update_manager_uninstall () { process_sql ('DROP TABLE "tupdate"'); process_sql ('DROP TABLE "tupdate_package"'); break; + case "oracle": + process_sql ('DELETE FROM tconfig WHERE token = \'update_manager_installed\''); + process_sql ('DROP TABLE tupdate_settings'); + process_sql ('DROP TABLE tupdate_journal'); + process_sql ('DROP TABLE tupdate'); + process_sql ('DROP TABLE tupdate_package'); + break; } } diff --git a/pandora_console/extensions/update_manager/lib/libupdate_manager.php b/pandora_console/extensions/update_manager/lib/libupdate_manager.php index 98f786c069..a02c08a877 100644 --- a/pandora_console/extensions/update_manager/lib/libupdate_manager.php +++ b/pandora_console/extensions/update_manager/lib/libupdate_manager.php @@ -48,6 +48,9 @@ function um_db_update_setting ($key, $value = '') { case "postgresql": $result = get_db_value('COUNT(*)', DB_PREFIX.'tupdate_settings', '"key"', $key); break; + case "oracle": + $result = get_db_value('COUNT(*)', DB_PREFIX.'tupdate_settings', 'key', $key); + break; } if ($result === false) { @@ -63,6 +66,9 @@ function um_db_update_setting ($key, $value = '') { case "postgresql": $result = process_sql_update(DB_PREFIX.'tupdate_settings', array('value' => $value), array('"key"' => $key)); break; + case "oracle": + $result = process_sql_update(DB_PREFIX.'tupdate_settings', array('value' => $value), array('key' => $key)); + break; } if ($result === false) { @@ -78,6 +84,9 @@ function um_db_update_setting ($key, $value = '') { case "postgresql": $result = process_sql_insert(DB_PREFIX.'tupdate_settings', array('"key"' => $key, '"value"' => $value)); break; + case "oracle": + $result = process_sql_insert(DB_PREFIX.'tupdate_settings', array('key' => $key, 'value' => $value)); + break; } if ($result === false) { @@ -277,6 +286,14 @@ function um_db_get_all_package_logs ($ip = '', $order_by = 'timestamp', $limit = FROM '.DB_PREFIX.'tupdate_package_log WHERE ip_address LIKE \'%'.$ip.'%\' ORDER BY '.$order_by.' DESC LIMIT '.$limit.' OFFSET '.$offset); break; + case "oracle": + $set = array (); + $set['ip_address'] = '%' . $ip . '%'; + $set['order'] = $order_by . ' DESC'; + $set['limit'] = $limit; + $set['offset'] = $offset; + $result = get_db_num_rows(oracle_recode_query ('SELECT * FROM '.DB_PREFIX.'tupdate_package_log WHERE', $set, 'AND', true)); + break; } @@ -294,6 +311,13 @@ function um_db_get_all_package_logs ($ip = '', $order_by = 'timestamp', $limit = FROM '.DB_PREFIX.'tupdate_package_log WHERE ip_address LIKE \'%'.$ip.'%\' ORDER BY '.$order_by.' DESC LIMIT '.$limit.' OFFSET '.$offset); break; + case "oracle": + $result = oracle_recode_query ('SELECT * FROM '.DB_PREFIX.'tupdate_package_log WHERE', $set, 'AND', false); + // Delete rnum row generated by oracle_recode_query() function + for ($i=0; $i < count($result); $i++) { + unset($result[$i]['rnum']); + } + break; } $cont = 0; @@ -373,6 +397,9 @@ function um_db_get_component ($name) { case "postgresql": $result = process_sql('SELECT COUNT(*) FROM '.DB_PREFIX.'tupdate_component WHERE name = \''.$name.'\' LIMIT 1'); break; + case "oracle": + $result = process_sql('SELECT COUNT(*) FROM '.DB_PREFIX.'tupdate_component WHERE name = \''.$name.'\' AND rownum < 2'); + break; } if ($result === false) { @@ -387,6 +414,9 @@ function um_db_get_component ($name) { case "postgresql": $result = process_sql('SELECT * FROM '.DB_PREFIX.'tupdate_component WHERE name = \''.$name.'\' LIMIT 1'); break; + case "oracle": + $result = process_sql('SELECT * FROM '.DB_PREFIX.'tupdate_component WHERE name = \''.$name.'\' AND rownum < 2'); + break; } $component = um_std_from_result($result); @@ -496,6 +526,9 @@ function um_db_get_component_db ($id_component_db) { case "postgresql": $result = process_sql('SELECT COUNT(*) FROM '.DB_PREFIX.'tupdate_component_db WHERE id = \''.$id_component_db.'\' LIMIT 1'); break; + case "oracle": + $result = process_sql('SELECT COUNT(*) FROM '.DB_PREFIX.'tupdate_component_db WHERE id = \''.$id_component_db.'\' AND rownum < 2'); + break; } if ($result === false) { @@ -510,6 +543,9 @@ function um_db_get_component_db ($id_component_db) { case "postgresql": $result = process_sql('SELECT * FROM '.DB_PREFIX.'tupdate_component_db WHERE id = \''.$id_component_db.'\' LIMIT 1'); break; + case "oracle": + $result = process_sql('SELECT * FROM '.DB_PREFIX.'tupdate_component_db WHERE id = \''.$id_component_db.'\' AND rownum < 2'); + break; } $component = um_std_from_result($result); @@ -525,6 +561,7 @@ function um_db_get_database_components ($component_name) { $result = process_sql('SELECT COUNT(*) FROM '.DB_PREFIX.'tupdate_component_db WHERE component = "'. $component_name.'" ORDER BY `order` ASC'); break; case "postgresql": + case "oracle": $result = process_sql('SELECT COUNT(*) FROM '.DB_PREFIX.'tupdate_component_db WHERE component = \''. $component_name.'\' ORDER BY "order" ASC'); break; } @@ -539,6 +576,7 @@ function um_db_get_database_components ($component_name) { $result = process_sql('SELECT * FROM '.DB_PREFIX.'tupdate_component_db WHERE component = "'. $component_name.'" ORDER BY `order` ASC'); break; case "postgresql": + case "oracle": $result = process_sql('SELECT * FROM '.DB_PREFIX.'tupdate_component_db WHERE component = \''. $component_name.'\' ORDER BY "order" ASC'); break; } @@ -619,6 +657,9 @@ function um_db_get_auth ($id_auth) { case "postgresql": $result = process_sql('SELECT * FROM '.DB_PREFIX.'tupdate_auth WHERE id = \''.$id_auth.'\' LIMIT 1'); break; + case "oracle": + $result = process_sql('SELECT * FROM '.DB_PREFIX.'tupdate_auth WHERE id = \''.$id_auth.'\' AND rownum < 2'); + break; } if ($result === false) { @@ -665,6 +706,9 @@ function um_db_check_auth ($client_key, $subscription_limit) { case "postgresql": $result = process_sql('SELECT * FROM '.DB_PREFIX.'tupdate_auth WHERE client_key = \''.$client_key.'\' LIMIT 1'); break; + case "oracle": + $result = process_sql('SELECT * FROM '.DB_PREFIX.'tupdate_auth WHERE client_key = \''.$client_key.'\' AND rownum < 2'); + break; } if ($result === false) { diff --git a/pandora_console/extensions/update_manager/lib/libupdate_manager_client.php b/pandora_console/extensions/update_manager/lib/libupdate_manager_client.php index dd2ff65edd..1d8055dd6a 100644 --- a/pandora_console/extensions/update_manager/lib/libupdate_manager_client.php +++ b/pandora_console/extensions/update_manager/lib/libupdate_manager_client.php @@ -399,6 +399,10 @@ function um_client_update_from_paths ($file_paths, $tmpDir, $num_package, $type) $sql_schema_file = '01_package_'.$num_package.'_schema.postgreSQL.sql'; $sql_data_file = '02_package_'.$num_package.'_data.postgreSQL.sql'; break; + case "oracle": + $sql_schema_file = '01_package_'.$num_package.'_schema.oracle.sql'; + $sql_data_file = '02_package_'.$num_package.'_data.oracle.sql'; + break; } foreach($file_paths as $file_name => $paths) { diff --git a/pandora_console/extensions/update_manager/lib/libupdate_manager_components.php b/pandora_console/extensions/update_manager/lib/libupdate_manager_components.php index d42661f1b3..fbe9b60bec 100644 --- a/pandora_console/extensions/update_manager/lib/libupdate_manager_components.php +++ b/pandora_console/extensions/update_manager/lib/libupdate_manager_components.php @@ -67,6 +67,9 @@ function um_component_database_get_all_tables () { case "postgresql": $result = process_sql('SELECT table_name FROM information_schema.tables WHERE table_schema = \'public\';'); break; + case "oracle": + $result = process_sql('SELECT table_name FROM user_tables'); + break; } if ($result === false) { @@ -77,7 +80,12 @@ function um_component_database_get_all_tables () { $cont = 0; $tables = array(); foreach($result as $table) { + if ($config["dbtype"] == 'oracle') { + $tables[] = $table['table_name']; + } + else { $tables[] = $table[0]; + } } return $tables; @@ -108,8 +116,21 @@ function um_component_database_get_table_fields ($table_name) { $result = process_sql('SHOW COLUMNS FROM '.$table_name.' WHERE `Key` != "PRI"'); break; case "postgresql": + //TODO: verificar que se extraen todos los campos menos clave primaria $result = process_sql("SELECT * FROM pg_indexes WHERE tablename = '" . $table_name . "'"); break; + case "oracle": + $result = process_sql("SELECT cols1.column_name as Fields, cols1.data_type as Type, + CASE WHEN (cols1.nullable = 'Y') THEN 'YES' ELSE 'NO' END as \"Null\", + cols1.data_default as \"Default\", '' as Extra + FROM user_tab_columns cols1 + WHERE cols1.table_name ='".$table_name."' + AND cols1.column_name NOT IN (select distinct usr.column_name + from user_cons_columns usr, user_constraints co + where usr.constraint_name = co.constraint_name and + constraint_type = 'P' and co.table_name = '" . $table_name . "') + order by cols1.column_id"); + break; } if ($result === false) { @@ -179,6 +200,7 @@ function um_component_get_all_blacklisted ($component) { $result = process_sql('SELECT COUNT(name) FROM '.DB_PREFIX.'tupdate_component_blacklist WHERE component = "'.$component->name.'"'); break; case "postgresql": + case "oracle": $result = process_sql('SELECT COUNT(name) FROM '.DB_PREFIX.'tupdate_component_blacklist WHERE component = \''.$component->name.'\''); @@ -195,6 +217,7 @@ function um_component_get_all_blacklisted ($component) { $result = process_sql('SELECT name FROM '.DB_PREFIX.'tupdate_component_blacklist WHERE component = "'.$component->name.'"'); break; case "postgresql": + case "oracle": $result = process_sql('SELECT name FROM '.DB_PREFIX.'tupdate_component_blacklist WHERE component = \''.$component->name.'\''); @@ -223,6 +246,7 @@ function um_component_is_blacklisted ($component, $name) { $result = process_sql('SELECT COUNT(*) AS blacklisted FROM '.DB_PREFIX.'tupdate_component_blacklist WHERE component = "'.$component->name.'" AND name = "'.$name.'"'); break; case "postgresql": + case "oracle": $result = process_sql('SELECT COUNT(*) AS blacklisted FROM '.DB_PREFIX.'tupdate_component_blacklist WHERE component = \''.$component->name.'\' AND name = \''.$name.'\''); diff --git a/pandora_console/extensions/update_manager/lib/libupdate_manager_updates.php b/pandora_console/extensions/update_manager/lib/libupdate_manager_updates.php index 9284f50ef4..abccc6f4b9 100644 --- a/pandora_console/extensions/update_manager/lib/libupdate_manager_updates.php +++ b/pandora_console/extensions/update_manager/lib/libupdate_manager_updates.php @@ -29,6 +29,9 @@ function um_update_get_last_from_filename ($component_name, $filename) { case "postgresql": $result = process_sql('SELECT COUNT(*) FROM '.DB_PREFIX.'tupdate WHERE component = \''.$component_name.'\' AND filename = \''.$component->relative_path.$filename.'\' ORDER BY id DESC LIMIT 1'); break; + case "oracle": + $result = process_sql('SELECT COUNT(*) FROM '.DB_PREFIX.'tupdate WHERE (component = \''.$component_name.'\' AND filename = \''.$component->relative_path.$filename.'\') AND rownum < 2 ORDER BY id DESC'); + break; } if ($result === false) { @@ -46,6 +49,12 @@ function um_update_get_last_from_filename ($component_name, $filename) { WHERE component = \''.$component_name.'\' AND filename = \''.$component->relative_path.$filename.'\' ORDER BY id DESC LIMIT 1'); break; + case "oracle": + $result = process_sql('SELECT * + FROM '.DB_PREFIX.'tupdate + WHERE (component = \''.$component_name.'\' + AND filename = \''.$component->relative_path.$filename.'\') AND rownum < 2 ORDER BY id DESC'); + break; } $update = um_std_from_result($result); @@ -171,6 +180,9 @@ function um_db_create_update ($type, $component_name, $id_package, $update, $db_ case "postgresql": $values['data'] = um_data_encode('INSERT INTO "'.$component_db->table_name.'" ("'.implode('", "', array_keys (get_object_vars ($db_data))).'") VALUES (\''.implode('\',\'', get_object_vars ($db_data)).'\')'); break; + case "oracle": + $values['data'] = um_data_encode('INSERT INTO '.$component_db->table_name.' ('.implode(', ', array_keys (get_object_vars ($db_data))).') VALUES (\''.implode('\',\'', get_object_vars ($db_data)).'\')'); + break; } break; case 'db_schema': diff --git a/pandora_console/extensions/update_manager/load_updatemanager.php b/pandora_console/extensions/update_manager/load_updatemanager.php index 993217fa15..325df499c5 100644 --- a/pandora_console/extensions/update_manager/load_updatemanager.php +++ b/pandora_console/extensions/update_manager/load_updatemanager.php @@ -72,6 +72,11 @@ function get_user_key ($settings) { $m = (int) get_db_value ('COUNT("id_agente_modulo")', 'tagente_modulo', 'disabled', 0); break; + case 'oracle': + $n = (int) get_db_value ('COUNT(id_agente)', 'tagente', 'disabled', 0); + $m = (int) get_db_value ('COUNT(id_agente_modulo)', 'tagente_modulo', + 'disabled', 0); + break; } $user_key = array ('A' => $n, 'M' => $m, 'B' => $build_version, 'P' => $pandora_version); diff --git a/pandora_console/extensions/update_manager/sql/update_manager.oracle.sql b/pandora_console/extensions/update_manager/sql/update_manager.oracle.sql new file mode 100644 index 0000000000..ee63b258d6 --- /dev/null +++ b/pandora_console/extensions/update_manager/sql/update_manager.oracle.sql @@ -0,0 +1,28 @@ +CREATE TABLE tupdate_settings ( key VARCHAR2(255) default '' PRIMARY KEY, value VARCHAR2(255) default '') +/INSERT INTO tupdate_settings VALUES ('current_update', '0') +/INSERT INTO tupdate_settings VALUES ('customer_key', 'PANDORA-FREE') +/INSERT INTO tupdate_settings VALUES ('keygen_path', '/usr/share/pandora/util/keygen') +/INSERT INTO tupdate_settings VALUES ('update_server_host', 'www.artica.es') +/INSERT INTO tupdate_settings VALUES ('update_server_port', '80') +/INSERT INTO tupdate_settings VALUES ('update_server_path', '/pandoraupdate321/server.php') +/INSERT INTO tupdate_settings VALUES ('updating_binary_path', 'Path where the updated binary files will be stored') +/INSERT INTO tupdate_settings VALUES ('updating_code_path', 'Path where the updated code is stored') +/INSERT INTO tupdate_settings VALUES ('dbname', '') +/INSERT INTO tupdate_settings VALUES ('dbhost', '') +/INSERT INTO tupdate_settings VALUES ('dbpass', '') +/INSERT INTO tupdate_settings VALUES ('dbuser', '') +/INSERT INTO tupdate_settings VALUES ('proxy', '') +/INSERT INTO tupdate_settings VALUES ('proxy_port', '') +/INSERT INTO tupdate_settings VALUES ('proxy_user', '') +/INSERT INTO tupdate_settings VALUES ('proxy_pass', '') +CREATE TABLE tupdate_package( id NUMBER(10, 0) NOT NULL PRIMARY KEY, timestamp TIMESTAMP default NULL, description VARCHAR2(255) default '') +CREATE SEQUENCE tupdate_package_s INCREMENT BY 1 START WITH 1 +CREATE OR REPLACE TRIGGER tupdate_package_inc BEFORE INSERT ON tupdate_package REFERENCING NEW AS NEW FOR EACH ROW BEGIN SELECT tupdate_package_s.nextval INTO :NEW.ID FROM dual; END; +CREATE TABLE tupdate ( id NUMBER(10, 0) NOT NULL PRIMARY KEY, type VARCHAR2(15), id_update_package NUMBER(10, 0) default 0 REFERENCES tupdate_package(id) ON DELETE CASCADE, filename VARCHAR2(250) default '', checksum VARCHAR2(250) default '', previous_checksum VARCHAR2(250) default '', svn_version NUMBER(10, 0) default 0, data CLOB default '', data_rollback CLOB default '', description CLOB default '', db_table_name VARCHAR2(140) default '', db_field_name VARCHAR2(140) default '', db_field_value VARCHAR2(1024) default '', CONSTRAINT tupdate_type_cons CHECK (type IN ('code', 'db_data', 'db_schema', 'binary'))) +CREATE OR REPLACE TRIGGER tupdate_update AFTER UPDATE OF ID ON tupdate_package FOR EACH ROW BEGIN UPDATE tupdate SET ID_UPDATE_PACKAGE = :NEW.ID WHERE ID_UPDATE_PACKAGE = :OLD.ID; END; +CREATE SEQUENCE tupdate_s INCREMENT BY 1 START WITH 1 +CREATE OR REPLACE TRIGGER tupdate_inc BEFORE INSERT ON tupdate REFERENCING NEW AS NEW FOR EACH ROW BEGIN SELECT tupdate_s.nextval INTO :NEW.ID FROM dual; END; +CREATE TABLE tupdate_journal ( id NUMBER(10, 0) NOT NULL PRIMARY KEY, id_update NUMBER(10, 0) default 0 REFERENCES tupdate(id) ON DELETE CASCADE) +CREATE SEQUENCE tupdate_journal_s INCREMENT BY 1 START WITH 1 +CREATE OR REPLACE TRIGGER tupdate_journal_inc BEFORE INSERT ON tupdate_journal REFERENCING NEW AS NEW FOR EACH ROW BEGIN SELECT tupdate_journal_s.nextval INTO :NEW.ID FROM dual; END; +CREATE OR REPLACE TRIGGER tupdate_journal_update AFTER UPDATE OF ID ON tupdate FOR EACH ROW BEGIN UPDATE tupdate_journal SET ID = :NEW.ID WHERE ID = :OLD.ID; END; diff --git a/pandora_console/extensions/users_connected.php b/pandora_console/extensions/users_connected.php index 42fd2a73f6..e30da52f12 100644 --- a/pandora_console/extensions/users_connected.php +++ b/pandora_console/extensions/users_connected.php @@ -39,6 +39,10 @@ function users_extension_main_god ($god = true) { $sql = "SELECT id_usuario, ip_origen, fecha, accion FROM tsesion WHERE descripcion = 'Logged in' AND utimestamp > (ceil(date_part('epoch', CURRENT_TIMESTAMP)) - 3600) GROUP BY id_usuario, ip_origen, accion"; + case "oracle": + $sql = "SELECT id_usuario, ip_origen, fecha, accion + FROM tsesion + WHERE to_char(descripcion) = 'Logged in' AND utimestamp > (ceil((sysdate - to_date('19700101000000','YYYYMMDDHH24MISS')) * (86400)) - 3600) GROUP BY id_usuario, ip_origen,fecha, accion"; break; } diff --git a/pandora_console/extras/pandora_diag.php b/pandora_console/extras/pandora_diag.php index bb48d793f2..e4534a998a 100644 --- a/pandora_console/extras/pandora_diag.php +++ b/pandora_console/extras/pandora_diag.php @@ -142,6 +142,17 @@ switch ($config["dbtype"]) { 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 "oracle": + 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 (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) { diff --git a/pandora_console/general/logon_ok.php b/pandora_console/general/logon_ok.php index 4946d08184..c07ece8a38 100644 --- a/pandora_console/general/logon_ok.php +++ b/pandora_console/general/logon_ok.php @@ -35,7 +35,16 @@ print_page_header (__('Welcome to Pandora FMS Web Console')); echo '
'; echo '

' . __('Site news') . '

'; -$sql = "SELECT subject,timestamp,text,author FROM tnews ORDER by timestamp DESC LIMIT 3"; +switch ($config["dbtype"]) { + case "mysql": + case "postgresql": + $sql = "SELECT subject,timestamp,text,author FROM tnews ORDER by timestamp DESC LIMIT 3"; + break; + case "oracle": + $sql = "SELECT subject,timestamp,text,author FROM tnews where rownum <= 3 ORDER by timestamp DESC"; + break; +} + $news = get_db_all_rows_sql ($sql); if ($news !== false) { echo ''; @@ -167,6 +176,12 @@ switch ($config["dbtype"]) { WHERE (\"utimestamp\" > ceil(date_part('epoch', CURRENT_TIMESTAMP)) - 604800) AND \"ID_usuario\" = '%s' ORDER BY \"utimestamp\" DESC LIMIT 10", $config["id_user"]); break; + case "oracle": + $sql = sprintf ("SELECT ID_usuario, accion, fecha, IP_origen, descripcion + FROM tsesion + WHERE ((utimestamp > ceil((sysdate - to_date('19700101000000','YYYYMMDDHH24MISS')) * (86400)) - 604800) + AND ID_usuario = '%s') AND rownum <= 10 ORDER BY utimestamp DESC", $config["id_user"]); + break; } $sessions = get_db_all_rows_sql ($sql); @@ -179,6 +194,7 @@ foreach ($sessions as $session) { switch ($config["dbtype"]) { case "mysql": + case "oracle": $session_id_usuario = $session['id_usuario']; $session_ip_origen = $session['ip_origen']; break; diff --git a/pandora_console/godmode/admin_access_logs.php b/pandora_console/godmode/admin_access_logs.php index bd50d8f474..87528a6f54 100644 --- a/pandora_console/godmode/admin_access_logs.php +++ b/pandora_console/godmode/admin_access_logs.php @@ -92,15 +92,30 @@ $filter = 'WHERE 1 = 1'; if ($tipo_log != 'all') { $filter .= sprintf (" AND accion = '%s'", $tipo_log); } +switch ($config['dbtype']) { + case "mysql": + if ($user_filter != 'all') { + $filter .= sprintf(' AND ID_usuario = "%s"', $user_filter); + } -if ($user_filter != 'all') { - $filter .= sprintf(' AND ID_usuario = "%s"', $user_filter); -} + $filter .= ' AND (accion LIKE "%' . $filter_text . '%" OR descripcion LIKE "%' . $filter_text . '%")'; -$filter .= ' AND (accion LIKE "%' . $filter_text . '%" OR descripcion LIKE "%' . $filter_text . '%")'; + if ($filter_ip != '') { + $filter .= sprintf(' AND IP_origen LIKE "%s"', $filter_ip); + } + break; + case "postgresql": + case "oracle": + if ($user_filter != 'all') { + $filter .= sprintf(' AND ID_usuario = \'%s\'', $user_filter); + } -if ($filter_ip != '') { - $filter .= sprintf(' AND IP_origen LIKE "%s"', $filter_ip); + $filter .= ' AND (accion LIKE \'%' . $filter_text . '%\' OR descripcion LIKE \'%' . $filter_text . '%\')'; + + if ($filter_ip != '') { + $filter .= sprintf(' AND IP_origen LIKE \'%s\'', $filter_ip); + } + break; } if ($filter_hours_old != 0) { @@ -111,6 +126,9 @@ if ($filter_hours_old != 0) { case "postgresql": $filter .= ' AND fecha >= DATE_ADD(NOW(), INTERVAL - \'' . $filter_hours_old . ' HOUR \')'; break; + case "oracle": + $filter .= ' AND fecha >= (SYSTIMESTAMP - INTERVAL \'' . $filter_hours_old . '\' HOUR)'; + break; } } @@ -127,9 +145,24 @@ switch ($config["dbtype"]) { case "postgresql": $sql = sprintf ("SELECT * FROM tsesion %s ORDER BY fecha DESC LIMIT %d OFFSET %d", $filter, $config["block_size"], $offset); break; + case "oracle": + $set = array(); + $set['limit'] = $config["block_size"]; + $set['offset'] = $offset; + $sql = sprintf ("SELECT * FROM tsesion %s ORDER BY fecha DESC", $filter); + $result = oracle_recode_query ($sql, $set); + break; } + $result = get_db_all_rows_sql ($sql); +// Delete rnum row generated by oracle_recode_query() function +if (($config["dbtype"] == 'oracle') && ($result !== false)){ + for ($i=0; $i < count($result); $i++) { + unset($result[$i]['rnum']); + } +} + if (empty ($result)) { $result = array (); } @@ -193,22 +226,62 @@ foreach ($result as $row) { $iterator++; $data = array (); - $data[0] = $row["ID_usuario"]; + switch ($config['dbtype']) { + case "mysql": + case "postgresql": + $data[0] = $row["ID_usuario"]; + break; + case "oracle": + $data[0] = $row["id_usuario"]; + break; + } $data[1] = $row["accion"]; $data[2] = $row["fecha"]; - $data[3] = $row["IP_origen"]; + switch ($config['dbtype']) { + case "mysql": + case "postgresql": + $data[3] = $row["IP_origen"]; + break; + case "oracle": + $data[3] = $row["ip_origen"]; + break; + } $data[4] = $row["descripcion"]; if ($enterprise_include !== ENTERPRISE_NOT_HOOK) { - $data[5] = enterprise_hook('cell1EntepriseAudit', array($row['ID_sesion'])); + switch ($config['dbtype']) { + case "mysql": + case "postgresql": + $data[5] = enterprise_hook('cell1EntepriseAudit', array($row['ID_sesion'])); + break; + case "oracle": + $data[5] = enterprise_hook('cell1EntepriseAudit', array($row['id_sesion'])); + break; + } } if ($enterprise_include !== ENTERPRISE_NOT_HOOK) { - $data[6] = enterprise_hook('cell2EntepriseAudit', array($row['ID_sesion'])); + switch ($config['dbtype']) { + case "mysql": + case "postgresql": + $data[6] = enterprise_hook('cell2EntepriseAudit', array($row['ID_sesion'])); + break; + case "oracle": + $data[6] = enterprise_hook('cell2EntepriseAudit', array($row['id_sesion'])); + break; + } } array_push ($table->data, $data); if ($enterprise_include !== ENTERPRISE_NOT_HOOK) { - enterprise_hook('rowEnterpriseAudit', array($table, &$iterator, $row['ID_sesion'])); + switch ($config['dbtype']) { + case "mysql": + case "postgresql": + enterprise_hook('rowEnterpriseAudit', array($table, &$iterator, $row['ID_sesion'])); + break; + case "oracle": + enterprise_hook('rowEnterpriseAudit', array($table, &$iterator, $row['id_sesion'])); + break; + } } } diff --git a/pandora_console/godmode/agentes/agent_template.php b/pandora_console/godmode/agentes/agent_template.php index 362e35801f..6f8f121381 100644 --- a/pandora_console/godmode/agentes/agent_template.php +++ b/pandora_console/godmode/agentes/agent_template.php @@ -13,6 +13,8 @@ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. +global $config; + // Load global vars if (!isset ($id_agente)) { die ("Not Authorized"); @@ -135,7 +137,15 @@ echo ''; // ========================== echo "

".__('Assigned modules')."

"; -$sql = sprintf ("SELECT * FROM tagente_modulo WHERE id_agente = %d AND delete_pending = false ORDER BY id_module_group, nombre", $id_agente); + switch ($config["dbtype"]) { + case "mysql": + case "postgresql": + $sql = sprintf ("SELECT * FROM tagente_modulo WHERE id_agente = %d AND delete_pending = false ORDER BY id_module_group, nombre", $id_agente); + break; + case "oracle": + $sql = sprintf ("SELECT * FROM tagente_modulo WHERE id_agente = %d AND (delete_pending <> 1 AND delete_pending IS NOT NULL) ORDER BY id_module_group, dbms_lob.substr(nombre,4000,1)", $id_agente); + break; + } $result = get_db_all_rows_sql ($sql); if ($result === false) { $result = array (); diff --git a/pandora_console/godmode/agentes/configurar_agente.php b/pandora_console/godmode/agentes/configurar_agente.php index 2b5b073793..f7bb519b09 100644 --- a/pandora_console/godmode/agentes/configurar_agente.php +++ b/pandora_console/godmode/agentes/configurar_agente.php @@ -690,6 +690,14 @@ if ($create_module) { $id_module = (int) get_parameter ('id_module'); + switch ($config["dbtype"]) { + case "oracle": + if (empty($description) || !isset($description)) { + $description=' '; + } + break; + } + $values = array ('id_tipo_modulo' => $id_module_type, 'descripcion' => $description, 'max' => $max, diff --git a/pandora_console/godmode/agentes/modificar_agente.php b/pandora_console/godmode/agentes/modificar_agente.php index 985167d433..228211ad75 100644 --- a/pandora_console/godmode/agentes/modificar_agente.php +++ b/pandora_console/godmode/agentes/modificar_agente.php @@ -199,6 +199,18 @@ if ($ag_group > 0) { ORDER BY %s %s LIMIT %d OFFSET %d', $ag_group, $search_sql, $order['field'], $order['order'], $config["block_size"], $offset); break; + case "oracle": + $set = array (); + $set['limit'] = $config["block_size"]; + $set['offset'] = $offset; + $sql = sprintf ('SELECT * + FROM tagente + WHERE id_grupo = %d + %s + ORDER BY %s %s', + $ag_group, $search_sql, $order['field'], $order['order']); + $sql = oracle_recode_query ($sql, $set); + break; } } else { @@ -218,6 +230,15 @@ else { FROM tagente WHERE 1=1 %s ORDER BY %s %s LIMIT %d OFFSET %d', $search_sql, $order['field'], $order['order'], $config["block_size"], $offset); break; + case "oracle": + $set = array (); + $set['limit'] = $config["block_size"]; + $set['offset'] = $offset; + $sql = sprintf ('SELECT * + FROM tagente WHERE 1=1 %s + ORDER BY %s %s', $search_sql, $order['field'], $order['order']); + $sql = oracle_recode_query ($sql, $set); + break; } } else { @@ -249,12 +270,32 @@ else { implode (',', array_keys (get_user_groups ())), $search_sql, $order['field'], $order['order'], $config["block_size"], $offset); break; + case "oracle": + $set = array (); + $set['limit'] = $config["block_size"]; + $set['offset'] = $offset; + $sql = sprintf ('SELECT * + FROM tagente + WHERE id_grupo IN (%s) + %s + ORDER BY %s %s', + implode (',', array_keys (get_user_groups ())), + $search_sql, $order['field'], $order['order']); + $sql = oracle_recode_query ($sql, $set); + break; } } } $agents = get_db_all_rows_sql ($sql); +// Delete rnum row generated by oracle_recode_query() function +if (($config['dbtype'] == 'oracle') && ($agents !== false)) { + for ($i=0; $i < count($agents); $i++) { + unset($agents[$i]['rnum']); + } +} + // Prepare pagination pagination ($total_agents, "index.php?sec=gagente&sec2=godmode/agentes/modificar_agente&group_id=$ag_group&search=$search&sort_field=$sortField&sort=$sort", $offset); echo "
"; diff --git a/pandora_console/godmode/agentes/module_manager.php b/pandora_console/godmode/agentes/module_manager.php index 7ec1a65cfd..156a22cae7 100644 --- a/pandora_console/godmode/agentes/module_manager.php +++ b/pandora_console/godmode/agentes/module_manager.php @@ -30,10 +30,10 @@ echo "\n"; $form_filter .= "\n"; $form_filter .= "\n"; -$temp = get_db_all_rows_sql("SELECT id, name FROM talert_actions;"); + switch ($config["dbtype"]) { + case "mysql": + case "postgresql": + $temp = get_db_all_rows_sql("SELECT id, name FROM talert_actions;"); + break; + case "oracle": + $temp = get_db_all_rows_sql("SELECT id, name FROM talert_actions"); + break; +} + $arrayActions = array(); if (is_array($temp)) { foreach ($temp as $actionElement) { @@ -126,10 +135,22 @@ if ($searchFlag) { $where .= " AND id_agent_module IN (SELECT id_agente_modulo FROM tagente_modulo WHERE nombre LIKE '%" . trim($moduleName) . "%')"; //if ($agentID != -1) //$where .= " AND id_agent_module IN (SELECT id_agente_modulo FROM tagente_modulo WHERE id_agente = " . $agentID . ")"; - if (strlen(trim($agentName)) > 0) - $where .= " AND id_agent_module IN (SELECT t2.id_agente_modulo - FROM tagente AS t1 INNER JOIN tagente_modulo AS t2 ON t1.id_agente = t2.id_agente - WHERE t1.nombre LIKE '" . trim($agentName) . "')"; + if (strlen(trim($agentName)) > 0) { + + switch ($config["dbtype"]) { + case "mysql": + case "postgresql": + $where .= " AND id_agent_module IN (SELECT t2.id_agente_modulo + FROM tagente AS t1 INNER JOIN tagente_modulo AS t2 ON t1.id_agente = t2.id_agente + WHERE t1.nombre LIKE '" . trim($agentName) . "')"; + break; + case "oracle": + $where .= " AND id_agent_module IN (SELECT t2.id_agente_modulo + FROM tagente t1 INNER JOIN tagente_modulo t2 ON t1.id_agente = t2.id_agente + WHERE t1.nombre LIKE '" . trim($agentName) . "')"; + break; + } + } if ($actionID != -1) $where .= " AND talert_template_modules.id IN (SELECT id_alert_template_module FROM talert_template_module_actions WHERE id_alert_action = " . $actionID . ")"; if ($enabledisable != -1) diff --git a/pandora_console/godmode/alerts/alert_list.php b/pandora_console/godmode/alerts/alert_list.php index 9b145815a1..4f836c6400 100644 --- a/pandora_console/godmode/alerts/alert_list.php +++ b/pandora_console/godmode/alerts/alert_list.php @@ -265,7 +265,7 @@ else { } echo $messageAction; - + switch ($tab) { case 'list': if ($group == 0) { diff --git a/pandora_console/godmode/db/db_main.php b/pandora_console/godmode/db/db_main.php index 50ac838ff7..61a6968d07 100644 --- a/pandora_console/godmode/db/db_main.php +++ b/pandora_console/godmode/db/db_main.php @@ -49,8 +49,21 @@ switch ($config["dbtype"]) { FROM tagente WHERE ceil(date_part('epoch', ultimo_contacto)) < ceil(date_part('epoch', NOW())) - (intervalo * 2)"); break; + case "oracle": + $stat_uknown = get_db_sql ("SELECT COUNT(*) + FROM tagente + WHERE CAST(ultimo_contacto AS DATE) < SYSDATE - (intervalo * 2)"); + break; +} +switch ($config["dbtype"]) { + case "mysql": + case "postgresql": + $stat_noninit = get_db_sql ("SELECT COUNT(*) FROM tagente_estado WHERE utimestamp = 0;"); + break; + case "oracle": + $stat_noninit = get_db_sql ("SELECT COUNT(*) FROM tagente_estado WHERE utimestamp = 0"); + break; } -$stat_noninit = get_db_sql ("SELECT COUNT(*) FROM tagente_estado WHERE utimestamp = 0;"); // Todo: Recalculate this data dinamically using the capacity and total agents diff --git a/pandora_console/godmode/groups/group_list.php b/pandora_console/godmode/groups/group_list.php index 1d8ccf3646..15a61e80fa 100644 --- a/pandora_console/godmode/groups/group_list.php +++ b/pandora_console/godmode/groups/group_list.php @@ -136,10 +136,21 @@ if ($update_group) { /*Check if name field is empty*/ if( $name != "") { - $sql = sprintf ('UPDATE tgrupo SET nombre = "%s", - icon = "%s", disabled = %d, parent = %d, custom_id = "%s", propagate = %d, id_skin = %d - WHERE id_grupo = %d', - $name, substr ($icon, 0, -4), !$alerts_enabled, $id_parent, $custom_id, $propagate, $skin, $id_group); + switch ($config["dbtype"]) { + case "mysql": + $sql = sprintf ('UPDATE tgrupo SET nombre = "%s", + icon = "%s", disabled = %d, parent = %d, custom_id = "%s", propagate = %d, id_skin = %d + WHERE id_grupo = %d', + $name, substr ($icon, 0, -4), !$alerts_enabled, $id_parent, $custom_id, $propagate, $skin, $id_group); + break; + case "postgresql": + case "oracle": + $sql = sprintf ('UPDATE tgrupo SET nombre = \'%s\', + icon = \'%s\', disabled = %d, parent = %d, custom_id = \'%s\', propagate = %d, id_skin = %d + WHERE id_grupo = %d', + $name, substr ($icon, 0, -4), !$alerts_enabled, $id_parent, $custom_id, $propagate, $skin, $id_group); + break; + } $result = process_sql ($sql); } else { $result = false; diff --git a/pandora_console/godmode/modules/manage_network_templates.php b/pandora_console/godmode/modules/manage_network_templates.php index 6bf422c0d4..3312de7473 100644 --- a/pandora_console/godmode/modules/manage_network_templates.php +++ b/pandora_console/godmode/modules/manage_network_templates.php @@ -79,6 +79,18 @@ if ($export_profile) { AND components.id_group = comp_group.id_sg AND tpc.id_np = %d", $id); break; + case "oracle": + $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); diff --git a/pandora_console/godmode/modules/manage_network_templates_form.php b/pandora_console/godmode/modules/manage_network_templates_form.php index cecd4d4250..1061fcb124 100644 --- a/pandora_console/godmode/modules/manage_network_templates_form.php +++ b/pandora_console/godmode/modules/manage_network_templates_form.php @@ -151,6 +151,11 @@ if ($id_np > 0) { 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 "oracle": + $sql = sprintf ("SELECT npc.id_nc AS component_id, nc.name, nc.type, nc.description, nc.id_group AS \"group\" + FROM tnetwork_profile_component npc, tnetwork_component nc + WHERE npc.id_nc = nc.id_nc AND npc.id_np = %d", $id_np); + break; } $result = get_db_all_rows_sql ($sql); diff --git a/pandora_console/godmode/reporting/reporting_builder.item_editor.php b/pandora_console/godmode/reporting/reporting_builder.item_editor.php index 94a192107e..2b765cbe7c 100644 --- a/pandora_console/godmode/reporting/reporting_builder.item_editor.php +++ b/pandora_console/godmode/reporting/reporting_builder.item_editor.php @@ -386,6 +386,7 @@ print_input_hidden('id_item', $idItem); $query_sql = 'SELECT id_graph, name FROM tgraph WHERE private = 0 OR (private = 1 AND id_user = "'.$config["id_user"].'")'; break; case "postgresql": + case "oracle": $query_sql = 'SELECT id_graph, name FROM tgraph WHERE private = 0 OR (private = 1 AND id_user = \''.$config["id_user"].'\')'; break; } diff --git a/pandora_console/godmode/reporting/reporting_builder.list_items.php b/pandora_console/godmode/reporting/reporting_builder.list_items.php index 33f68b72da..8e80ad3a9a 100644 --- a/pandora_console/godmode/reporting/reporting_builder.list_items.php +++ b/pandora_console/godmode/reporting/reporting_builder.list_items.php @@ -135,6 +135,16 @@ switch ($config["dbtype"]) { ORDER BY "order" LIMIT ' . $config["block_size"] . ' OFFSET ' . $offset); break; + case "oracle": + $set = array(); + $set['limit'] = $config["block_size"]; + $set['offset'] = $offset; + $items = oracle_recode_query ('SELECT * FROM treport_content WHERE ' . $where . ' AND id_report = ' . $idReport . ' ORDER BY "order"', $set, 'AND', false); + // Delete rnum row generated by oracle_recode_query() function + for ($i=0; $i < count($items); $i++) { + unset($items[$i]['rnum']); + } + break; } $countItems = get_db_sql('SELECT COUNT(id_rc) FROM treport_content WHERE ' . $where . ' AND id_report = ' . $idReport); $table = null; diff --git a/pandora_console/godmode/reporting/reporting_builder.php b/pandora_console/godmode/reporting/reporting_builder.php index c8be4e582d..f569f8eb5b 100644 --- a/pandora_console/godmode/reporting/reporting_builder.php +++ b/pandora_console/godmode/reporting/reporting_builder.php @@ -290,6 +290,7 @@ switch ($action) { FROM treport_content WHERE id_report = ' . $idReport . ';'); break; case "postgresql": + case "oracle": $max = get_db_all_rows_sql('SELECT max("order") AS max FROM treport_content WHERE id_report = ' . $idReport . ';'); break; @@ -305,6 +306,7 @@ switch ($action) { process_sql_update('treport_content', array('`order`' => $max + 1), array('id_rc' => $idItem)); break; case "postgresql": + case "oracle": process_sql_update('treport_content', array('"order"' => $max + 1), array('id_rc' => $idItem)); break; } @@ -420,6 +422,7 @@ switch ($action) { $oldOrder = get_db_value_sql('SELECT `order` FROM treport_content WHERE id_rc = ' . $idItem); break; case "postgresql": + case "oracle": $oldOrder = get_db_value_sql('SELECT "order" FROM treport_content WHERE id_rc = ' . $idItem); break; } @@ -445,6 +448,10 @@ switch ($action) { $resultOperationDB = process_sql_update('treport_content', array('"order"' => $oldOrder), array('"order"' => $newOrder, 'id_report' => $idReport)); break; + case "oracle": + $resultOperationDB = process_sql_update('treport_content', + array('"order"' => $oldOrder), array('"order"' => $newOrder, 'id_report' => $idReport), 'AND', false); + break; } if ($resultOperationDB !== false) { switch ($config["dbtype"]) { @@ -454,6 +461,9 @@ switch ($action) { case "postgresql": $resultOperationDB = process_sql_update('treport_content', array('"order"' => $newOrder), array('id_rc' => $idItem)); break; + case "oracle": + $resultOperationDB = process_sql_update('treport_content', array('"order"' => $newOrder), array('id_rc' => $idItem), 'AND', false); + break; } if ($resultOperationDB !== false) { process_sql_commit(); diff --git a/pandora_console/godmode/reporting/reporting_builder.preview.php b/pandora_console/godmode/reporting/reporting_builder.preview.php index ae8614f29e..65d3bacba0 100644 --- a/pandora_console/godmode/reporting/reporting_builder.preview.php +++ b/pandora_console/godmode/reporting/reporting_builder.preview.php @@ -128,6 +128,7 @@ switch ($config["dbtype"]) { $contents = get_db_all_rows_field_filter ("treport_content", "id_report", $id_report, "`order`"); break; case "postgresql": + case "oracle": $contents = get_db_all_rows_field_filter ("treport_content", "id_report", $id_report, '"order"'); break; } diff --git a/pandora_console/godmode/setup/setup.php b/pandora_console/godmode/setup/setup.php index 7e5e9c2c72..39b0cf2744 100644 --- a/pandora_console/godmode/setup/setup.php +++ b/pandora_console/godmode/setup/setup.php @@ -64,6 +64,9 @@ switch ($config["dbtype"]) { case "postgresql": $current_system_lang = get_db_sql ('SELECT "value" FROM tconfig WHERE "token" = \'language\''); break; + case "oracle": + $current_system_lang = get_db_sql ('SELECT value FROM tconfig WHERE token = \'language\''); + break; } if ($current_system_lang == ""){ diff --git a/pandora_console/include/ajax/agent.php b/pandora_console/include/ajax/agent.php index a362690cb1..cdf8cc3f23 100644 --- a/pandora_console/include/ajax/agent.php +++ b/pandora_console/include/ajax/agent.php @@ -40,7 +40,16 @@ if ($search_agents) { } $filter = array (); - $filter[] = '(nombre COLLATE utf8_general_ci LIKE "%'.$string.'%" OR direccion LIKE "%'.$string.'%" OR comentarios LIKE "%'.$string.'%")'; + switch ($config["dbtype"]) { + case "mysql": + case "postgresql": + $filter[] = '(nombre COLLATE utf8_general_ci LIKE "%'.$string.'%" OR direccion LIKE "%'.$string.'%" OR comentarios LIKE "%'.$string.'%")'; + break; + case "oracle": + $filter[] = '(UPPER(nombre) LIKE UPPER(\'%'.$string.'%\') OR UPPER(direccion) LIKE UPPER(\'%'.$string.'%\') OR UPPER(comentarios) LIKE UPPER(\'%'.$string.'%\'))'; + break; + } + $filter['id_grupo'] = $id_group; $agents = get_agents ($filter, array ('id_agente','nombre', 'direccion')); diff --git a/pandora_console/include/ajax/reporting.ajax.php b/pandora_console/include/ajax/reporting.ajax.php index 24b713f1ac..a3b36bef8a 100644 --- a/pandora_console/include/ajax/reporting.ajax.php +++ b/pandora_console/include/ajax/reporting.ajax.php @@ -77,6 +77,9 @@ if ($get_custom_sql) { case "postgresql": $sql = get_db_value_filter('"sql"', 'treport_custom_sql', array('id' => $id)); break; + case "oracle": + $sql = get_db_value_filter('sql', 'treport_custom_sql', array('id' => $id)); + break; } if ($sql === false) { diff --git a/pandora_console/include/auth/mysql.php b/pandora_console/include/auth/mysql.php index ecf1bfe905..e4d31d9c22 100644 --- a/pandora_console/include/auth/mysql.php +++ b/pandora_console/include/auth/mysql.php @@ -76,7 +76,6 @@ function process_user_login ($login, $pass) { // Always authenticate admins against the local database if (strtolower ($config["auth"]) == 'mysql' || is_user_admin ($login)) { - // Connect to Database switch ($config["dbtype"]) { case "mysql": @@ -85,6 +84,9 @@ function process_user_login ($login, $pass) { case "postgresql": $sql = sprintf ('SELECT "id_user", "password" FROM "tusuario" WHERE "id_user" = \'%s\'', $login); break; + case "oracle": + $sql = sprintf ('SELECT id_user, password FROM tusuario WHERE id_user = \'%s\'', $login); + break; } $row = get_db_row_sql ($sql); diff --git a/pandora_console/include/db/oracle.php b/pandora_console/include/db/oracle.php index f3cc157e7b..6e6e6bf777 100644 --- a/pandora_console/include/db/oracle.php +++ b/pandora_console/include/db/oracle.php @@ -36,9 +36,9 @@ function oracle_connect_db($host = null, $db = null, $user = null, $pass = null) } // Set date and timestamp formats for this session - $datetime_tz_format = oci_parse($config['dbconnection'] , 'alter session set NLS_TIMESTAMP_TZ_FORMAT =\'DD/MM/YYYY HH24:MI:SS\''); - $datetime_format = oci_parse($config['dbconnection'] , 'alter session set NLS_TIMESTAMP_FORMAT =\'DD/MM/YYYY HH24:MI:SS\''); - $date_format = oci_parse($config['dbconnection'] , 'alter session set NLS_DATE_FORMAT =\'DD/MM/YYYY HH24:MI:SS\''); + $datetime_tz_format = oci_parse($config['dbconnection'] , 'alter session set NLS_TIMESTAMP_TZ_FORMAT =\'YYYY-MM-DD HH24:MI:SS\''); + $datetime_format = oci_parse($config['dbconnection'] , 'alter session set NLS_TIMESTAMP_FORMAT =\'YYYY-MM-DD HH24:MI:SS\''); + $date_format = oci_parse($config['dbconnection'] , 'alter session set NLS_DATE_FORMAT =\'YYYY-MM-DD HH24:MI:SS\''); oci_execute($datetime_tz_format); oci_execute($datetime_format); @@ -200,7 +200,7 @@ function oracle_process_sql($sql, $rettype = "affected_rows", $dbconnection = '' global $sql_cache; $retval = array(); - + if ($sql == '') return false; @@ -220,6 +220,10 @@ function oracle_process_sql($sql, $rettype = "affected_rows", $dbconnection = '' if ($type[0] == 'INSERT'){ $query = oci_parse($dbconnection, 'begin insert_id(:table_name, :sql, :out); end;'); } + // Prevent execution of insert_id stored procedure + else if ($type[0] == '/INSERT'){ + $query = oci_parse($dbconnection, substr($sql,1)); + } else{ $query = oci_parse($dbconnection, $sql); } @@ -228,14 +232,20 @@ function oracle_process_sql($sql, $rettype = "affected_rows", $dbconnection = '' if ($type[0] == 'INSERT'){ $query = oci_parse($config['dbconnection'], 'begin insert_id(:table_name, :sql, :out); end;'); } + // Prevent execution of insert_id stored procedure + else if ($type[0] == '/INSERT'){ + $query = oci_parse($dbconnection, substr($sql,1)); + } else{ $query = oci_parse($config['dbconnection'], $sql); } } //If query is an insert retrieve Id field - oci_bind_by_name($query,":table_name", $table_name ,32); - oci_bind_by_name($query,":sql", $sql, 1000); - oci_bind_by_name($query,":out", $id, 32); + if ($type[0] == 'INSERT'){ + oci_bind_by_name($query,":table_name", $table_name ,32); + oci_bind_by_name($query,":sql", $sql, 1000); + oci_bind_by_name($query,":out", $id, 32); + } if (!$autocommit){ $result = oci_execute($query, OCI_NO_AUTO_COMMIT); @@ -244,7 +254,7 @@ function oracle_process_sql($sql, $rettype = "affected_rows", $dbconnection = '' $result = oci_execute($query); } $time = microtime (true) - $start; - + if ($result === false) { $backtrace = debug_backtrace (); $e = oci_error($query); @@ -280,7 +290,29 @@ function oracle_process_sql($sql, $rettype = "affected_rows", $dbconnection = '' else { //The query IS a select. add_database_debug_trace ($sql, 0, $rows, array ('time' => $time)); while ($row = oci_fetch_assoc($query)) { - array_push($retval, $row); + $i = 1; + $result_temp = array(); + foreach ($row as $key => $value) { + $column_type = oci_field_type($query, $key); + // Support for Clob fields larger than 4000bytes + //if ($sql == 'SELECT * FROM tgrupo ORDER BY dbms_lob.substr(nombre,4000,1) ASC') echo $i .' '.$column_type.' '.$key.'
'; + if ($column_type == 'CLOB') { + $column_name = oci_field_name($query, $i); + // Protect against a NULL CLOB + if (is_object($row[$column_name])) { + $clob_data = $row[$column_name]->load(); + $row[$column_name]->free(); + $value = $clob_data; + } + else { + $value = ''; + } + } + $result_temp[strtolower($key)] = $value; + $i++; + } + array_push($retval, $result_temp); + //array_push($retval, $row); } if ($cache === true) @@ -309,7 +341,15 @@ function oracle_process_sql($sql, $rettype = "affected_rows", $dbconnection = '' */ function oracle_get_db_all_rows_in_table($table, $order_field = "", $order = 'ASC') { if ($order_field != "") { - return get_db_all_rows_sql ('SELECT * FROM ' . $table . ' ORDER BY ' . $order_field . ' ' . $order); + + // Clob fields are not allowed in ORDER BY statements, they need cast to varchar2 datatype + $type = get_db_value_filter ('data_type', 'user_tab_columns', array ('table_name' => strtoupper($table), 'column_name' => strtoupper($order_field)), 'AND'); + if ($type == 'CLOB') { + return get_db_all_rows_sql ('SELECT * FROM ' . $table . ' ORDER BY dbms_lob.substr(' . $order_field . ',4000,1) ' . $order); + } + else { + return get_db_all_rows_sql ('SELECT * FROM ' . $table . ' ORDER BY ' . $order_field . ' ' . $order); + } } else { return get_db_all_rows_sql ('SELECT * FROM ' . $table); @@ -365,7 +405,7 @@ function oracle_process_sql_insert($table, $values) { $query .= '(' . implode(', ', $fields) . ')'; $query .= ' VALUES (' . $values_str . ')'; - + return process_sql($query, 'insert_id'); } @@ -426,7 +466,7 @@ function oracle_get_db_value_filter ($field, $table, $filter, $where_join = 'AND if ($result === false) return false; - $fieldClean = strtoupper(str_replace('`', '', $field)); + $fieldClean = str_replace('`', '', $field); return $result[0][$fieldClean]; } @@ -534,6 +574,9 @@ function oracle_format_array_to_where_clause_sql ($values, $join = 'AND', $prefi if ($i < $max) { $query .= ' '.$join.' '; } + if ($i == $max) { + $query .= ' ) '; + } $i++; continue; } @@ -756,7 +799,6 @@ function oracle_recode_query ($sql, $values, $join = 'AND', $return = true) { } $result = $pre_query.$sql.$query.$limit.$group.$order.$post_query; - if ($return){ return $result; } @@ -796,7 +838,7 @@ function oracle_get_db_value_sql($sql) { * @return mixed The first row of the result or false */ function oracle_get_db_row_sql ($sql, $search_history_db = false) { - $sql .= "SELECT * FROM (" . $sql . ") WHERE rownum < 2"; + $sql = "SELECT * FROM (" . $sql . ") WHERE rownum < 2"; $result = get_db_all_rows_sql($sql, $search_history_db); if($result === false) @@ -924,7 +966,7 @@ function oracle_get_db_num_rows ($sql) { oci_execute($query); if ($type[0] == 'SELECT'){ $row = oci_fetch_assoc($query); - $rows = $row[NUM]; + $rows = $row['NUM']; } else{ $rows = oci_num_rows($query); @@ -1065,7 +1107,7 @@ function oracle_format_array_to_update_sql ($values) { * * @return mixed False in case of error or invalid values passed. Affected rows otherwise */ -function oracle_process_sql_update($table, $values, $where = false, $where_join = 'AND') { +function oracle_process_sql_update($table, $values, $where = false, $where_join = 'AND', $autocommit = true) { $query = sprintf ("UPDATE %s SET %s", $table, format_array_to_update_sql ($values)); @@ -1079,8 +1121,8 @@ function oracle_process_sql_update($table, $values, $where = false, $where_join $query .= format_array_to_where_clause_sql ($where, $where_join, ' WHERE '); } } - - return process_sql ($query); + $status = ''; + return process_sql ($query, "affected_rows", '', true, $status, $autocommit); } /** @@ -1174,11 +1216,34 @@ function oracle_get_db_all_row_by_steps_sql($new = true, &$result, $sql = null) } $row = oci_fetch_assoc($result); + $result_temp = array(); + if ($row) { + foreach ($row as $key => $value){ + $column_type = oci_field_type($result, $key); + // Support for Clob field larger than 4000bytes + if ($column_type == 'CLOB') { + $column_name = oci_field_name($result, $key); + $column_name = oci_field_name($result, $key); + // protect against a NULL CLOB + if (is_object($row[$column_name])) { + $clob_data = $row[$column_name]->load(); + $row[$column_name]->free(); + $value = $clob_data; + } + else { + $value = ''; + } + } + $result_temp[strtolower($key)] = $value; + } + } + if (!$row){ oci_free_statement($result); } - return $row; +// return $row; + return $result_temp; } /** @@ -1272,7 +1337,7 @@ function oracle_get_db_type_field_table($table, $field) { $query = oci_parse($config['dbconnection'], "SELECT * FROM " . $table . " WHERE rownum < 2"); oci_execute($query); - $type = oci_field_type($query, $field); + $type = oci_field_type($query, $field+1); oci_free_statement($query); return $type; diff --git a/pandora_console/include/fgraph.php b/pandora_console/include/fgraph.php index 8a06f6f1b1..205635f09d 100644 --- a/pandora_console/include/fgraph.php +++ b/pandora_console/include/fgraph.php @@ -135,7 +135,7 @@ function graphic_combined_module ($module_list, $weight_list, $period, $width, $ $title, $unit_name, $show_events = 0, $show_alerts = 0, $pure = 0, $stacked = 0, $date = 0) { global $config; global $graphic_type; - + // Set variables if ($date == 0) $date = get_system_time(); $datelimit = $date - $period; @@ -405,7 +405,7 @@ function graphic_agentaccess ($id_agent, $width, $height, $period = 0) { $periodtime = floor ($period / $interval); $time = array (); $data = array (); - + for ($i = 0; $i < $interval; $i++) { $bottom = $datelimit + ($periodtime * $i); if (! $graphic_type) { @@ -415,11 +415,23 @@ function graphic_agentaccess ($id_agent, $width, $height, $period = 0) { } $top = $datelimit + ($periodtime * ($i + 1)); - $data[$name] = (int) get_db_value_filter ('COUNT(*)', - 'tagent_access', - array ('id_agent' => $id_agent, - 'utimestamp > '.$bottom, - 'utimestamp < '.$top)); + switch ($config["dbtype"]) { + case "mysql": + case "postgresql": + $data[$name] = (int) get_db_value_filter ('COUNT(*)', + 'tagent_access', + array ('id_agent' => $id_agent, + 'utimestamp > '.$bottom, + 'utimestamp < '.$top)); + break; + case "oracle": + $data[$name] = (int) get_db_value_filter ('count(*)', + 'tagent_access', + array ('id_agent' => $id_agent, + 'utimestamp > '.$bottom, + 'utimestamp < '.$top)); + break; + } } if (! $graphic_type) { @@ -653,10 +665,22 @@ function graphic_user_activity ($width = 350, $height = 230) { $data = array (); $max_items = 5; - $sql = sprintf ('SELECT COUNT(id_usuario) n_incidents, id_usuario - FROM tsesion - GROUP BY id_usuario - ORDER BY 1 DESC LIMIT %d', $max_items); + switch ($config['dbtype']) { + case "mysql": + case "postgresql": + $sql = sprintf ('SELECT COUNT(id_usuario) n_incidents, id_usuario + FROM tsesion + GROUP BY id_usuario + ORDER BY 1 DESC LIMIT %d', $max_items); + break; + case "oracle": + $sql = sprintf ('SELECT COUNT(id_usuario) n_incidents, id_usuario + FROM tsesion + WHERE rownum <= %d + GROUP BY id_usuario + ORDER BY 1 DESC', $max_items); + break; + } $logins = get_db_all_rows_sql ($sql); if($logins == false) { @@ -697,6 +721,11 @@ function graphic_incident_source ($width = 320, $height = 200) { FROM tincidencia GROUP BY "origen" ORDER BY 1 DESC LIMIT %d', $max_items); break; + case "oracle": + $sql = sprintf ('SELECT COUNT(id_incidencia) n_incident, origen + FROM tincidencia WHERE rownum <= %d GROUP BY origen + ORDER BY 1 DESC', $max_items); + break; } $origins = get_db_all_rows_sql ($sql); @@ -726,16 +755,36 @@ function graph_db_agentes_modulos ($width, $height) { $data = array (); - $modules = get_db_all_rows_sql ('SELECT COUNT(id_agente_modulo), id_agente - FROM tagente_modulo - GROUP BY id_agente - ORDER BY 1 DESC LIMIT 10'); + switch ($config['dbtype']){ + case "mysql": + case "postgresql": + $modules = get_db_all_rows_sql ('SELECT COUNT(id_agente_modulo), id_agente + FROM tagente_modulo + GROUP BY id_agente + ORDER BY 1 DESC LIMIT 10'); + break; + case "oracle": + $modules = get_db_all_rows_sql ('SELECT COUNT(id_agente_modulo), id_agente + FROM tagente_modulo + WHERE rownum <= 10 + GROUP BY id_agente + ORDER BY 1 DESC'); + break; + } if ($modules === false) $modules = array (); foreach ($modules as $module) { $agent_name = get_agent_name ($module['id_agente'], "none"); - $data[$agent_name] = $module['COUNT(id_agente_modulo)']; + switch ($config['dbtype']){ + case "mysql": + case "postgresql": + $data[$agent_name] = $module['COUNT(id_agente_modulo)']; + break; + case "oracle": + $data[$agent_name] = $module['count(id_agente_modulo)']; + break; + } } if (! $graphic_type) { @@ -757,12 +806,27 @@ function grafico_eventos_usuario ($width, $height) { $data = array (); $max_items = 5; - $sql = sprintf ('SELECT COUNT(id_evento) events, id_usuario - FROM tevento - GROUP BY id_usuario - ORDER BY 1 DESC LIMIT %d', $max_items); + switch ($config["dbtype"]) { + case "mysql": + case "postgresql": + $sql = sprintf ('SELECT COUNT(id_evento) events, id_usuario + FROM tevento + GROUP BY id_usuario + ORDER BY 1 DESC LIMIT %d', $max_items); + break; + case "oracle": + $sql = sprintf ('SELECT * FROM (SELECT COUNT(id_evento) events, id_usuario + FROM tevento + GROUP BY id_usuario + ORDER BY 1 DESC) WHERE rownum <= %d', $max_items); + break; + } $events = get_db_all_rows_sql ($sql); + if ($events === false) { + $events = array(); + } + foreach ($events as $event) { $data['id_usuario'] = $event['events']; } @@ -825,11 +889,24 @@ function graph_event_module ($width = 300, $height = 200, $id_agent) { $data = array (); $max_items = 6; - $sql = sprintf ('SELECT COUNT(id_evento) as count_number, nombre - FROM tevento, tagente_modulo - WHERE id_agentmodule = id_agente_modulo - AND disabled = 0 AND tevento.id_agente = %d - GROUP BY id_agentmodule LIMIT %d', $id_agent, $max_items); + + switch ($config["dbtype"]) { + case "mysql": + case "postgresql": + $sql = sprintf ('SELECT COUNT(id_evento) as count_number, nombre + FROM tevento, tagente_modulo + WHERE id_agentmodule = id_agente_modulo + AND disabled = 0 AND tevento.id_agente = %d + GROUP BY id_agentmodule LIMIT %d', $id_agent, $max_items); + break; + case "oracle": + $sql = sprintf ('SELECT count_number, nombre FROM (SELECT COUNT(id_evento) as count_number, dbms_lob.substr(nombre,4000,1) as nombre, id_agentmodule + FROM tevento, tagente_modulo + WHERE (id_agentmodule = id_agente_modulo + AND disabled = 0 AND tevento.id_agente = %d) AND rownum <= %d + GROUP BY dbms_lob.substr(nombre,4000,1),id_agentmodule)', $id_agent, $max_items); + break; + } $events = get_db_all_rows_sql ($sql); if ($events === false) { if (! $graphic_type) { @@ -889,9 +966,19 @@ function grafico_eventos_grupo ($width = 300, $height = 200, $url = "") { //This will give the distinct id_agente, give the id_grupo that goes //with it and then the number of times it occured. GROUP BY statement //is required if both DISTINCT() and COUNT() are in the statement - $sql = sprintf ('SELECT DISTINCT(id_agente) AS id_agente, id_grupo, COUNT(id_agente) AS count - FROM tevento WHERE 1=1 %s - GROUP BY id_agente ORDER BY count DESC', $url); + switch ($config["dbtype"]) { + case "mysql": + case "postgresql": + $sql = sprintf ('SELECT DISTINCT(id_agente) AS id_agente, id_grupo, COUNT(id_agente) AS count + FROM tevento WHERE 1=1 %s + GROUP BY id_agente ORDER BY count DESC', $url); + break; + case "oracle": + $sql = sprintf ('SELECT DISTINCT(id_agente) AS id_agente, id_grupo, COUNT(id_agente) AS count + FROM tevento WHERE 1=1 %s + GROUP BY id_agente, id_grupo ORDER BY count DESC', $url); + break; + } $result = get_db_all_rows_sql ($sql); if ($result === false) { diff --git a/pandora_console/include/functions.php b/pandora_console/include/functions.php index 6c0ed6b1b6..dfbf8a044b 100644 --- a/pandora_console/include/functions.php +++ b/pandora_console/include/functions.php @@ -322,6 +322,9 @@ function get_system_time () { case "postgresql": return postgresql_get_system_time(); break; + case "oracle": + return oracle_get_system_time(); + break; } } @@ -1007,6 +1010,9 @@ function safe_sql_string($string) { case "postgresql": return postgresql_safe_sql_string($string); break; + case "oracle": + return oracle_safe_sql_string($string); + break; } } diff --git a/pandora_console/include/functions_agents.php b/pandora_console/include/functions_agents.php index 7845bdf1ce..6299c681d2 100644 --- a/pandora_console/include/functions_agents.php +++ b/pandora_console/include/functions_agents.php @@ -111,7 +111,8 @@ function create_agent ($name, $id_group, $interval, $ip_address, $values = false */ function get_agent_alerts_simple ($id_agent = false, $filter = '', $options = false, $where = '', $allModules = false, $orderby = false, $idGroup = false, $count = false) { - + global $config; + if (is_array($filter)) { $disabled = $filter['disabled']; if (isset($filter['standby'])) { @@ -187,18 +188,32 @@ function get_agent_alerts_simple ($id_agent = false, $filter = '', $options = fa if ($count !== false) { $selectText = 'COUNT(talert_template_modules.id) AS count'; } - - $sql = sprintf ("SELECT %s - FROM talert_template_modules - INNER JOIN tagente_modulo AS t2 - ON talert_template_modules.id_agent_module = t2.id_agente_modulo - INNER JOIN tagente AS t3 - ON t2.id_agente = t3.id_agente - INNER JOIN talert_templates AS t4 - ON talert_template_modules.id_alert_template = t4.id - WHERE id_agent_module in (%s) %s %s %s", - $selectText, $subQuery, $where, $filter, $orderbyText); + switch ($config["dbtype"]) { + case "mysql": + case "postgresql": + $sql = sprintf ("SELECT %s + FROM talert_template_modules + INNER JOIN tagente_modulo AS t2 + ON talert_template_modules.id_agent_module = t2.id_agente_modulo + INNER JOIN tagente AS t3 + ON t2.id_agente = t3.id_agente + INNER JOIN talert_templates AS t4 + ON talert_template_modules.id_alert_template = t4.id + WHERE id_agent_module in (%s) %s %s %s", + $selectText, $subQuery, $where, $filter, $orderbyText); + case "oracle": + $sql = sprintf ("SELECT %s + FROM talert_template_modules + INNER JOIN tagente_modulo t2 + ON talert_template_modules.id_agent_module = t2.id_agente_modulo + INNER JOIN tagente t3 + ON t2.id_agente = t3.id_agente + INNER JOIN talert_templates t4 + ON talert_template_modules.id_alert_template = t4.id + WHERE id_agent_module in (%s) %s %s %s", + $selectText, $subQuery, $where, $filter, $orderbyText); + } $alerts = get_db_all_rows_sql ($sql); if ($alerts === false) diff --git a/pandora_console/include/functions_alerts.php b/pandora_console/include/functions_alerts.php index 79676e0de0..64b7379554 100644 --- a/pandora_console/include/functions_alerts.php +++ b/pandora_console/include/functions_alerts.php @@ -975,6 +975,7 @@ function get_agents_with_alert_template ($id_alert_template, $id_group, $filter $filter['`tagente`.id_agente'] = array_keys (get_group_agents ($id_group, false, "none")); break; case "postgresql": + case "oracle": $filter['tagente.id_agente'] = array_keys (get_group_agents ($id_group, false, "none")); break; } @@ -985,6 +986,7 @@ function get_agents_with_alert_template ($id_alert_template, $id_group, $filter $filter['`tagente`.id_agente'] = $id_agents; break; case "postgresql": + case "oracle": $filter['tagente.id_agente'] = $id_agents; break; } diff --git a/pandora_console/include/functions_api.php b/pandora_console/include/functions_api.php index 0a3a125691..88ed440f69 100644 --- a/pandora_console/include/functions_api.php +++ b/pandora_console/include/functions_api.php @@ -158,6 +158,7 @@ function get_agent_module_name_last_value($agentName, $moduleName, $other = ';', WHERE id_agente = %d AND nombre LIKE "%s"', $idAgent, $moduleName); break; case "postgresql": + case "oracle": $sql = sprintf('SELECT id_agente_modulo FROM tagente_modulo WHERE id_agente = %d AND nombre LIKE \'%s\'', $idAgent, $moduleName); @@ -639,6 +640,7 @@ function set_new_agent($thrash1, $thrash2, $other, $thrash3) { $sql1 = 'SELECT name FROM tserver WHERE name LIKE "' . $nameServer . '"'; break; case "postgresql": + case "oracle": $sql1 = 'SELECT name FROM tserver WHERE name LIKE \'' . $nameServer . '\''; break; } diff --git a/pandora_console/include/functions_config.php b/pandora_console/include/functions_config.php index 08d8cd71ba..e61d546c96 100644 --- a/pandora_console/include/functions_config.php +++ b/pandora_console/include/functions_config.php @@ -53,6 +53,7 @@ function update_config_value ($token, $value) { WHERE token LIKE "%list_ACL_IPs_for_API_%"'); break; case "postgresql": + case "oracle": $rows = get_db_all_rows_sql("SELECT id_config FROM tconfig WHERE token LIKE '%list_ACL_IPs_for_API_%'"); diff --git a/pandora_console/include/functions_db.php b/pandora_console/include/functions_db.php index dd4337ee8f..09afff7ae9 100644 --- a/pandora_console/include/functions_db.php +++ b/pandora_console/include/functions_db.php @@ -606,7 +606,7 @@ function get_group_agents ($id_group = 0, $search = false, $case = "lower", $noA $search_sql .= ' AND (nombre COLLATE utf8_general_ci LIKE \'%'.$string.'%\' OR direccion LIKE \'%'.$string.'%\')'; break; case "oracle": - $search_sql .= ' AND (nombre LIKE UPPER(\'%'.$string.'%\') OR direccion LIKE upper(\'%'.$string.'%\'))'; + $search_sql .= ' AND (UPPER(nombre) LIKE UPPER(\'%'.$string.'%\') OR direccion LIKE upper(\'%'.$string.'%\'))'; break; } @@ -638,8 +638,15 @@ function get_group_agents ($id_group = 0, $search = false, $case = "lower", $noA $search_sql .= ' AND disabled = 0'; } - - $sql = sprintf ("SELECT id_agente, nombre FROM tagente %s ORDER BY nombre", $search_sql); + switch ($config["dbtype"]) { + case "mysql": + case "postgresql": + $sql = sprintf ("SELECT id_agente, nombre FROM tagente %s ORDER BY nombre", $search_sql); + break; + case "oracle": + $sql = sprintf ("SELECT id_agente, nombre FROM tagente %s ORDER BY dbms_lob.substr(nombre,4000,1)", $search_sql); + break; + } $result = get_db_all_rows_sql ($sql); @@ -802,7 +809,18 @@ function get_agent_modules ($id_agent = null, $details = false, $filter = false, array_push ($fields, $field.' LIKE "'.$value.'"'); } else { - array_push ($fields, $field.' = "'.$value.'"'); + switch ($config["dbtype"]) { + case "mysql": + case "postgresql": + array_push ($fields, $field.' = "'.$value.'"'); + break; + case "oracle": + if (is_int ($value) ||is_float ($value)||is_double ($value)) + array_push ($fields, $field.' = '.$value.''); + else + array_push ($fields, $field.' = "'.$value.'"'); + break; + } } } $where .= implode (' AND ', $fields); @@ -819,13 +837,27 @@ function get_agent_modules ($id_agent = null, $details = false, $filter = false, $details = safe_input ($details); } - $sql = sprintf ('SELECT %s%s - FROM tagente_modulo - %s - ORDER BY nombre', - ($details != '*' && $indexed) ? 'id_agente_modulo,' : '', - safe_output(implode (",", (array) $details)), - $where); + switch ($config["dbtype"]) { + case "mysql": + case "postgresql": + $sql = sprintf ('SELECT %s%s + FROM tagente_modulo + %s + ORDER BY nombre', + ($details != '*' && $indexed) ? 'id_agente_modulo,' : '', + safe_output(implode (",", (array) $details)), + $where); + break; + case "oracle": + $sql = sprintf ('SELECT %s%s + FROM tagente_modulo + %s + ORDER BY dbms_lob.substr(nombre, 4000, 1)', + ($details != '*' && $indexed) ? 'id_agente_modulo,' : '', + safe_output(implode (",", (array) $details)), + $where); + break; + } $result = get_db_all_rows_sql ($sql); @@ -1731,6 +1763,8 @@ function give_agentmodule_flag ($id_agent_module) { * Get all groups in array with index as id_group */ function get_all_groups($groupWithAgents = false) { + global $config; + $sql = 'SELECT id_grupo, nombre FROM tgrupo'; global $config; @@ -1738,7 +1772,15 @@ function get_all_groups($groupWithAgents = false) { if ($groupWithAgents) $sql .= ' WHERE id_grupo IN (SELECT id_grupo FROM tagente GROUP BY id_grupo)'; - $sql .= ' ORDER BY nombre DESC'; + switch ($config['dbtype']) { + case "mysql": + case "postgresql": + $sql .= ' ORDER BY nombre DESC'; + break; + case "oracle": + $sql .= ' ORDER BY dbms_lob.substr(nombre,4000,1) DESC'; + break; + } $rows = get_db_all_rows_sql ($sql); @@ -3244,6 +3286,7 @@ function server_status ($id_server) { */ function temp_sql_delete ($table, $row, $value) { global $error; //Globalize the errors variable + global $config; switch ($config["dbtype"]) { case "mysql": @@ -3251,7 +3294,12 @@ function temp_sql_delete ($table, $row, $value) { $result = process_sql_delete ($table, $row.' = '.$value); break; case "oracle": - $result = oracle_process_sql_delete_temp ($table, $row.' = '.$value); + if (is_int ($value) || is_bool ($value) || is_float ($value) || is_double ($value)) { + $result = oracle_process_sql_delete_temp ($table, $row . ' = ' . $value); + } + else { + $result = oracle_process_sql_delete_temp ($table, $row . " = '" . $value . "'"); + } break; } @@ -3529,10 +3577,11 @@ function process_sql_insert($table, $values) { * @param string When a $where parameter is given, this will work as the glue * between the fields. "AND" operator will be use by default. Other values might * be "OR", "AND NOT", "XOR" + * @param bool Transaction automatically commited or not * * @return mixed False in case of error or invalid values passed. Affected rows otherwise */ -function process_sql_update($table, $values, $where = false, $where_join = 'AND') { +function process_sql_update($table, $values, $where = false, $where_join = 'AND', $autocommit = true) { global $config; switch ($config["dbtype"]) { @@ -3543,7 +3592,7 @@ function process_sql_update($table, $values, $where = false, $where_join = 'AND' return postgresql_process_sql_update($table, $values, $where, $where_join); break; case "oracle": - return oracle_process_sql_update($table, $values, $where, $where_join); + return oracle_process_sql_update($table, $values, $where, $where_join, $autocommit); break; } } diff --git a/pandora_console/include/functions_events.php b/pandora_console/include/functions_events.php index f4fbaceab1..4328bfbc12 100644 --- a/pandora_console/include/functions_events.php +++ b/pandora_console/include/functions_events.php @@ -197,7 +197,8 @@ function validate_event ($id_event, $similars = true, $comment = '', $new_status 'estado' => $new_status, 'id_usuario' => $config['id_user'], 'user_comment' => $comment); - $ret = process_sql_update('tevento', $values, array('id_evento' => $event)); + + $ret = process_sql_update('tevento', $values, array('id_evento' => $event), 'AND', false); if (check_acl ($config["id_user"], get_event_group ($event), "IW") == 0) { //Check ACL @@ -282,6 +283,14 @@ function create_event ($event, $id_group, $id_agent, $status = 0, $id_user = "", $id_agent, $id_group, $event, $status, $id_user, $event_type, $priority, $id_agent_module, $id_aam); break; + case "oracle": + $sql = sprintf ('INSERT INTO tevento (id_agente, id_grupo, evento, timestamp, + estado, utimestamp, id_usuario, event_type, criticity, + id_agentmodule, id_alert_am) + VALUES (%d, %d, "%s", CURRENT_TIMESTAMP, %d, ceil((sysdate - to_date(\'19700101000000\',\'YYYYMMDDHH24MISS\')) * (86400)), "%s", "%s", %d, %d, %d)', + $id_agent, $id_group, $event, $status, $id_user, $event_type, + $priority, $id_agent_module, $id_aam); + break; } return (int) process_sql ($sql, "insert_id"); @@ -300,7 +309,20 @@ function create_event ($event, $id_group, $id_agent, $status = 0, $id_user = "", function print_events_table ($filter = "", $limit = 10, $width = 440, $return = false) { global $config; - $sql = sprintf ("SELECT * FROM tevento %s ORDER BY timestamp DESC LIMIT %d", $filter, $limit); + switch ($config["dbtype"]) { + case "mysql": + case "postgresql": + $sql = sprintf ("SELECT * FROM tevento %s ORDER BY timestamp DESC LIMIT %d", $filter, $limit); + break; + case "oracle": + if ($filter == "") { + $sql = sprintf ("SELECT * FROM tevento WHERE rownum <= %d ORDER BY timestamp DESC", $limit); + } + else { + $sql = sprintf ("SELECT * FROM tevento %s AND rownum <= %d ORDER BY timestamp DESC", $filter, $limit); + } + break; + } $result = get_db_all_rows_sql ($sql); if ($result === false) { diff --git a/pandora_console/include/functions_fsgraph.php b/pandora_console/include/functions_fsgraph.php index 8598cadc97..acbcffa9ec 100644 --- a/pandora_console/include/functions_fsgraph.php +++ b/pandora_console/include/functions_fsgraph.php @@ -263,7 +263,7 @@ function fs_combined_chart ($data, $categories, $sets, $width, $height, $type = if (sizeof ($data) == 0) { return fs_error_image (); } - + // Generate the XML switch ($type) { case 0: $chart_type = 'MSArea2D'; diff --git a/pandora_console/include/functions_gis.php b/pandora_console/include/functions_gis.php index ecfc727647..261a7c4d91 100644 --- a/pandora_console/include/functions_gis.php +++ b/pandora_console/include/functions_gis.php @@ -523,6 +523,9 @@ function addPath($layerName, $idAgent, $lastPosition = null, $history_time = nul case "postgresql": $where = 'start_timestamp >= to_timestamp(ceil(date_part("epoch", CURRENT_TIMESTAMP)) - ' . $history_time . ')'; break; + case "oracle": + $where = 'start_timestamp >= to_timestamp(\'01-01-1970 00:00:00\', \'DD-MM-YYYY HH24:MI:SS\') + NUMTODSINTERVAL((ceil((sysdate - to_date(\'19700101000000\',\'YYYYMMDDHH24MISS\')) * (86400)) - ' . $history_time . '),\'SECOND\')'; + break; } } @@ -1053,6 +1056,7 @@ function getMapData($idMap) { WHERE t1.tgis_map_id_tgis_map = '. $map['id_tgis_map']); break; case "postgresql": + case "oracle": $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 diff --git a/pandora_console/include/functions_groups.php b/pandora_console/include/functions_groups.php index 3f1757e0bb..ab0defcc25 100644 --- a/pandora_console/include/functions_groups.php +++ b/pandora_console/include/functions_groups.php @@ -23,83 +23,190 @@ * @return bool Return false if the group is unused in the Pandora, else true. */ function checkUsedGroup($idGroup) { + global $config; + $return = array(); $return['return'] = false; $return['tables'] = array(); - $numRows = get_db_num_rows('SELECT * FROM tagente WHERE id_grupo = ' . $idGroup . ';'); + switch ($config["dbtype"]) { + case "mysql": + case "postgresql": + $numRows = get_db_num_rows('SELECT * FROM tagente WHERE id_grupo = ' . $idGroup . ';'); + break; + case "oracle": + $numRows = get_db_num_rows('SELECT * FROM tagente WHERE id_grupo = ' . $idGroup); + break; + } if ($numRows > 0) { $return['return'] = true; $return['tables'][] = __('Agents'); } - $numRows = get_db_num_rows('SELECT * FROM talert_actions WHERE id_group = ' . $idGroup . ';'); + switch ($config["dbtype"]) { + case "mysql": + case "postgresql": + $numRows = get_db_num_rows('SELECT * FROM talert_actions WHERE id_group = ' . $idGroup . ';'); + break; + case "oracle": + $numRows = get_db_num_rows('SELECT * FROM talert_actions WHERE id_group = ' . $idGroup); + break; + } + if ($numRows > 0) { $return['return'] = true; $return['tables'][] = __('Alert Actions'); } - $numRows = get_db_num_rows('SELECT * FROM talert_templates WHERE id_group = ' . $idGroup . ';'); + switch ($config["dbtype"]) { + case "mysql": + case "postgresql": + $numRows = get_db_num_rows('SELECT * FROM talert_templates WHERE id_group = ' . $idGroup . ';'); + break; + case "oracle": + $numRows = get_db_num_rows('SELECT * FROM talert_templates WHERE id_group = ' . $idGroup); + break; + } + if ($numRows > 0) { $return['return'] = true; $return['tables'][] = __('Alert Templates'); } - $numRows = get_db_num_rows('SELECT * FROM trecon_task WHERE id_group = ' . $idGroup . ';'); + switch ($config["dbtype"]) { + case "mysql": + case "postgresql": + $numRows = get_db_num_rows('SELECT * FROM trecon_task WHERE id_group = ' . $idGroup . ';'); + break; + case "oracle": + $numRows = get_db_num_rows('SELECT * FROM trecon_task WHERE id_group = ' . $idGroup); + break; + } if ($numRows > 0) { $return['return'] = true; $return['tables'][] = __('Recon task'); } - - $numRows = get_db_num_rows('SELECT * FROM tgraph WHERE id_group = ' . $idGroup . ';'); + + switch ($config["dbtype"]) { + case "mysql": + case "postgresql": + $numRows = get_db_num_rows('SELECT * FROM tgraph WHERE id_group = ' . $idGroup . ';'); + break; + case "oracle": + $numRows = get_db_num_rows('SELECT * FROM tgraph WHERE id_group = ' . $idGroup); + break; + } if ($numRows > 0) { $return['return'] = true; $return['tables'][] = __('Graphs'); } - $numRows = get_db_num_rows('SELECT * FROM treport WHERE id_group = ' . $idGroup . ';'); + switch ($config["dbtype"]) { + case "mysql": + case "postgresql": + $numRows = get_db_num_rows('SELECT * FROM treport WHERE id_group = ' . $idGroup . ';'); + break; + case "oracle": + $numRows = get_db_num_rows('SELECT * FROM treport WHERE id_group = ' . $idGroup); + break; + } if ($numRows > 0) { $return['return'] = true; $return['tables'][] = __('Reports'); } - $numRows = get_db_num_rows('SELECT * FROM tlayout WHERE id_group = ' . $idGroup . ';'); + switch ($config["dbtype"]) { + case "mysql": + case "postgresql": + $numRows = get_db_num_rows('SELECT * FROM tlayout WHERE id_group = ' . $idGroup . ';'); + break; + case "oracle": + $numRows = get_db_num_rows('SELECT * FROM tlayout WHERE id_group = ' . $idGroup); + break; + } + if ($numRows > 0) { $return['return'] = true; $return['tables'][] = __('Layout visual console'); } - $numRows = get_db_num_rows('SELECT * FROM tplanned_downtime WHERE id_group = ' . $idGroup . ';'); + switch ($config["dbtype"]) { + case "mysql": + case "postgresql": + $numRows = get_db_num_rows('SELECT * FROM tplanned_downtime WHERE id_group = ' . $idGroup . ';'); + break; + case "oracle": + $numRows = get_db_num_rows('SELECT * FROM tplanned_downtime WHERE id_group = ' . $idGroup); + break; + } if ($numRows > 0) { $return['return'] = true; $return['tables'][] = __('Plannet down time'); } - $numRows = get_db_num_rows('SELECT * FROM tgraph WHERE id_group = ' . $idGroup . ';'); + switch ($config["dbtype"]) { + case "mysql": + case "postgresql": + $numRows = get_db_num_rows('SELECT * FROM tgraph WHERE id_group = ' . $idGroup . ';'); + break; + case "oracle": + $numRows = get_db_num_rows('SELECT * FROM tgraph WHERE id_group = ' . $idGroup); + break; + } if ($numRows > 0) { $return['return'] = true; $return['tables'][] = __('Graphs'); } - - $numRows = get_db_num_rows('SELECT * FROM tgis_map WHERE group_id = ' . $idGroup . ';'); + switch ($config["dbtype"]) { + case "mysql": + case "postgresql": + $numRows = get_db_num_rows('SELECT * FROM tgis_map WHERE group_id = ' . $idGroup . ';'); + break; + case "oracle": + $numRows = get_db_num_rows('SELECT * FROM tgis_map WHERE group_id = ' . $idGroup); + break; + } if ($numRows > 0) { $return['return'] = true; $return['tables'][] = __('GIS maps'); } - $numRows = get_db_num_rows('SELECT * FROM tgis_map_connection WHERE group_id = ' . $idGroup . ';'); + switch ($config["dbtype"]) { + case "mysql": + case "postgresql": + $numRows = get_db_num_rows('SELECT * FROM tgis_map_connection WHERE group_id = ' . $idGroup . ';'); + break; + case "oracle": + $numRows = get_db_num_rows('SELECT * FROM tgis_map_connection WHERE group_id = ' . $idGroup); + break; + } if ($numRows > 0) { $return['return'] = true; $return['tables'][] = __('GIS connections'); } - $numRows = get_db_num_rows('SELECT * FROM tgis_map_layer WHERE tgrupo_id_grupo = ' . $idGroup . ';'); + switch ($config["dbtype"]) { + case "mysql": + case "postgresql": + $numRows = get_db_num_rows('SELECT * FROM tgis_map_layer WHERE tgrupo_id_grupo = ' . $idGroup . ';'); + break; + case "oracle": + $numRows = get_db_num_rows('SELECT * FROM tgis_map_layer WHERE tgrupo_id_grupo = ' . $idGroup); + break; + } if ($numRows > 0) { $return['return'] = true; $return['tables'][] = __('GIS map layers'); } - - $numRows = get_db_num_rows('SELECT * FROM tnetwork_map WHERE id_group = ' . $idGroup . ';'); + switch ($config["dbtype"]) { + case "mysql": + case "postgresql": + $numRows = get_db_num_rows('SELECT * FROM tnetwork_map WHERE id_group = ' . $idGroup . ';'); + break; + case "oracle": + $numRows = get_db_num_rows('SELECT * FROM tnetwork_map WHERE id_group = ' . $idGroup); + break; + } if ($numRows > 0) { $return['return'] = true; $return['tables'][] = __('Network maps'); diff --git a/pandora_console/include/functions_messages.php b/pandora_console/include/functions_messages.php index 33001130f4..7cbcd868f3 100644 --- a/pandora_console/include/functions_messages.php +++ b/pandora_console/include/functions_messages.php @@ -107,7 +107,7 @@ function delete_message ($id_message) { $where = array( 'id_usuario_destino' => $config["id_user"], 'id_mensaje' => $id_message); - return (bool)process_sql_delete($tmensajes, $where); + return (bool)process_sql_delete('tmensajes', $where); } /** diff --git a/pandora_console/include/functions_modules.php b/pandora_console/include/functions_modules.php index 9c732ef0b3..f210cdb4ac 100644 --- a/pandora_console/include/functions_modules.php +++ b/pandora_console/include/functions_modules.php @@ -179,6 +179,7 @@ function update_agent_module ($id, $values, $onlyNoDeletePending = false) { * @return New module id if the module was created. False if not. */ function create_agent_module ($id_agent, $name, $values = false, $disableACL = false) { + global $config; if (!$disableACL) { if (empty ($id_agent) || ! user_access_to_agent ($id_agent, 'AW')) @@ -191,22 +192,39 @@ function create_agent_module ($id_agent, $name, $values = false, $disableACL = f $values = array (); $values['nombre'] = $name; $values['id_agente'] = (int) $id_agent; - + $id_agent_module = process_sql_insert ('tagente_modulo', $values); if ($id_agent_module === false) return false; - - $result = process_sql_insert ('tagente_estado', - array ('id_agente_modulo' => $id_agent_module, - 'datos' => 0, - 'timestamp' => '0000-00-00 00:00:00', - 'estado' => 0, - 'id_agente' => (int) $id_agent, - 'utimestamp' => 0, - 'status_changes' => 0, - 'last_status' => 0 - )); + + switch ($config["dbtype"]) { + case "mysql": + case "postgresql": + $result = process_sql_insert ('tagente_estado', + array ('id_agente_modulo' => $id_agent_module, + 'datos' => 0, + 'timestamp' => '0000-00-00 00:00:00', + 'estado' => 0, + 'id_agente' => (int) $id_agent, + 'utimestamp' => 0, + 'status_changes' => 0, + 'last_status' => 0 + )); + break; + case "oracle": + $result = process_sql_insert ('tagente_estado', + array ('id_agente_modulo' => $id_agent_module, + 'datos' => 0, + 'timestamp' => 'to_date(0000-00-00 00:00:00, \'YYYY-MM-DD HH24:MI:SS\')', + 'estado' => 0, + 'id_agente' => (int) $id_agent, + 'utimestamp' => 0, + 'status_changes' => 0, + 'last_status' => 0 + )); + break; + } if ($result === false) { process_sql_delete ('tagente_modulo', diff --git a/pandora_console/include/functions_network_components.php b/pandora_console/include/functions_network_components.php index 068dafa714..4a78483091 100644 --- a/pandora_console/include/functions_network_components.php +++ b/pandora_console/include/functions_network_components.php @@ -40,13 +40,38 @@ $components = get_network_components ($id_module, 'id_module_group = 10')); * if none matches. */ function get_network_components ($id_module, $filter = false, $fields = false) { + global $config; + if (! is_array ($filter)) $filter = array (); if (! empty ($id_module)) $filter['id_modulo'] = (int) $id_module; - $components = get_db_all_rows_filter ('tnetwork_component', - $filter, $fields); + switch ($config["dbtype"]) { + case "mysql": + case "postgresql": + $components = get_db_all_rows_filter ('tnetwork_component', + $filter, $fields); + break; + case "oracle": + if (count ($fields) > 1) { + $fields = implode(',',$fields); + } + if (isset($filter['offset'])) { + $components = oracle_recode_query ('SELECT ' . $fields . ' FROM tnetwork_component', $filter, 'AND', false); + if ($components != false) { + + for ($i=0; $i < count($components); $i++) { + unset($components[$i]['rnum']); + } + } + } + else { + $components = get_db_all_rows_filter ('tnetwork_component', + $filter, $fields); + } + break; + } if ($components === false) return array (); return $components; @@ -188,6 +213,15 @@ function get_network_component ($id_network_component, $filter = false, $fields * @return int New component id. False on error. */ function create_network_component ($name, $type, $id_group, $values = false) { + global $config; + + switch ($config['dbtype']) { + case "oracle": + if (empty($values['tcp_rcv'])) + $values['tcp_rcv'] = " "; + return; + } + if (empty ($name)) return false; if (empty ($type)) diff --git a/pandora_console/include/functions_networkmap.php b/pandora_console/include/functions_networkmap.php index f6c0314e5c..5f44ebd822 100644 --- a/pandora_console/include/functions_networkmap.php +++ b/pandora_console/include/functions_networkmap.php @@ -48,7 +48,7 @@ function generate_dot ($pandora_name, $group = 0, $simple = 0, $font_size = 12, $filter['disabled'] = 0; if ($group >= 1) $filter['id_grupo'] = $group; - + // Get agent data $agents = get_agents ($filter, array ('id_grupo, nombre, id_os, id_parent, id_agente')); @@ -587,7 +587,7 @@ function get_networkmap ($id_networkmap, $filter = false, $fields = false) { $filter['id_networkmap'] = $id_networkmap; $filter['id_user'] = $config['id_user']; - + $networkmap = get_db_row_filter ('tnetwork_map', $filter, $fields); return $networkmap; @@ -611,10 +611,26 @@ function get_networkmaps ($id_user = '', $type = '', $optgrouped = true) { $type_cond = ''; if($type != '') { - $type_cond = ' AND type = "'.$type.'"'; + switch ($config["dbtype"]) { + case "mysql": + $type_cond = ' AND type = "'.$type.'"'; + break; + case "postgresql": + case "oracle": + $type_cond = ' AND type = \''.$type.'\''; + break; + } } - $networkmaps_raw = get_db_all_rows_filter ('tnetwork_map', 'id_user = "'.$id_user.'"'.$type_cond.' ORDER BY type DESC, name ASC', array('id_networkmap','name', 'type')); + switch ($config["dbtype"]) { + case "mysql": + $networkmaps_raw = get_db_all_rows_filter ('tnetwork_map', 'id_user = "'.$id_user.'"'.$type_cond.' ORDER BY type DESC, name ASC', array('id_networkmap','name', 'type')); + break; + case "postgresql": + case "oracle": + $networkmaps_raw = get_db_all_rows_filter ('tnetwork_map', 'id_user = \''.$id_user.'\' '.$type_cond.' ORDER BY type DESC, name ASC', array('id_networkmap','name', 'type')); + break; + } if($networkmaps_raw === false){ return false; diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index 3b50b26e23..6e4d5c081f 100644 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -655,6 +655,11 @@ function get_group_stats ($id_group = 0) { FROM tagente WHERE id_grupo = $group AND disabled = 0 AND ceil(date_part('epoch', ultimo_contacto)) < ceil(date_part('epoch', NOW())) - (intervalo * 2)"); break; + case "oracle": + $data["agents_unknown"] += get_db_sql ("SELECT COUNT(*) + FROM tagente + WHERE id_grupo = $group AND disabled = 0 AND ultimo_contacto < CURRENT_TIMESTAMP - (intervalo * 2)"); + break; } $data["total_agents"] += get_db_sql ("SELECT COUNT(*) @@ -697,6 +702,17 @@ function get_group_stats ($id_group = 0) { OR (tagente_modulo.id_tipo_modulo IN(21,22,23,24,100))) AND (utimestamp > 0 OR (tagente_modulo.id_tipo_modulo IN(21,22,23,24)))"); break; + case "oracle": + $data["monitor_ok"] += get_db_sql ("SELECT COUNT(tagente_estado.id_agente_estado) + FROM tagente_estado, tagente, tagente_modulo + WHERE tagente.id_grupo = $group AND tagente.disabled = 0 + AND tagente_estado.id_agente = tagente.id_agente + AND tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo + AND tagente_modulo.disabled = 0 AND estado = 0 + AND ((ceil((sysdate - to_date('19700101000000','YYYYMMDDHH24MISS')) * (86400)) - tagente_estado.utimestamp) < (tagente_estado.current_interval * 2) + OR (tagente_modulo.id_tipo_modulo IN(21,22,23,24,100))) + AND (utimestamp > 0 OR (tagente_modulo.id_tipo_modulo IN(21,22,23,24)))"); + break; } switch ($config["dbtype"]) { @@ -716,6 +732,13 @@ function get_group_stats ($id_group = 0) { AND tagente_estado.id_agente = tagente.id_agente AND tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo AND tagente_modulo.disabled = 0 AND estado = 1 AND ((ceil(date_part('epoch', CURRENT_TIMESTAMP)) - tagente_estado.utimestamp) < (tagente_estado.current_interval * 2) OR (tagente_modulo.id_tipo_modulo IN(21,22,23,24,100))) AND utimestamp > 0"); break; + case "oracle": + $data["monitor_critical"] += get_db_sql ("SELECT COUNT(tagente_estado.id_agente_estado) + FROM tagente_estado, tagente, tagente_modulo + WHERE tagente.id_grupo = $group AND tagente.disabled = 0 + AND tagente_estado.id_agente = tagente.id_agente AND tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo + AND tagente_modulo.disabled = 0 AND estado = 1 AND ((ceil((sysdate - to_date('19700101000000','YYYYMMDDHH24MISS')) * (86400)) - tagente_estado.utimestamp) < (tagente_estado.current_interval * 2) OR (tagente_modulo.id_tipo_modulo IN(21,22,23,24,100))) AND utimestamp > 0"); + break; } switch ($config["dbtype"]) { @@ -735,6 +758,14 @@ function get_group_stats ($id_group = 0) { AND estado = 2 AND ((ceil(date_part('epoch', CURRENT_TIMESTAMP)) - tagente_estado.utimestamp) < (tagente_estado.current_interval * 2) OR (tagente_modulo.id_tipo_modulo IN(21,22,23,24,100))) AND utimestamp > 0"); break; + case "oracle": + $data["monitor_warning"] += get_db_sql ("SELECT COUNT(tagente_estado.id_agente_estado) + FROM tagente_estado, tagente, tagente_modulo + WHERE tagente.id_grupo = $group AND tagente.disabled = 0 AND tagente_estado.id_agente = tagente.id_agente + AND tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo AND tagente_modulo.disabled = 0 + AND estado = 2 AND ((ceil((sysdate - to_date('19700101000000','YYYYMMDDHH24MISS')) * (86400)) - tagente_estado.utimestamp) < (tagente_estado.current_interval * 2) + OR (tagente_modulo.id_tipo_modulo IN(21,22,23,24,100))) AND utimestamp > 0"); + break; } switch ($config["dbtype"]) { @@ -754,6 +785,14 @@ function get_group_stats ($id_group = 0) { AND utimestamp > 0 AND tagente_modulo.id_tipo_modulo NOT IN(21,22,23,24,100) AND (ceil(date_part('epoch', CURRENT_TIMESTAMP)) - tagente_estado.utimestamp) >= (tagente_estado.current_interval * 2)"); break; + case "oracle": + $data["monitor_unknown"] += get_db_sql ("SELECT COUNT(tagente_estado.id_agente_estado) + FROM tagente_estado, tagente, tagente_modulo + WHERE tagente.id_grupo = $group AND tagente.disabled = 0 AND tagente.id_agente = tagente_estado.id_agente + AND tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo AND tagente_modulo.disabled = 0 + AND utimestamp > 0 AND tagente_modulo.id_tipo_modulo NOT IN(21,22,23,24,100) + AND (ceil((sysdate - to_date('19700101000000','YYYYMMDDHH24MISS')) * (86400)) - tagente_estado.utimestamp) >= (tagente_estado.current_interval * 2)"); + break; } $data["monitor_not_init"] += get_db_sql ("SELECT COUNT(tagente_estado.id_agente_estado) @@ -1974,7 +2013,6 @@ function render_report_html_item ($content, $table, $report, $mini = false) { $sla_value = get_agentmodule_sla ($sla['id_agent_module'], $content['period'], $sla['sla_min'], $sla['sla_max'], $report["datetime"], $content, $content['time_from'], $content['time_to']); - //Fill the array data_graph for the pie graph if ($sla_value === false) { $data_graph[__('Unknown')]++; @@ -2281,6 +2319,9 @@ function render_report_html_item ($content, $table, $report, $mini = false) { case "postgresql": $sql = safe_output_html (get_db_value_filter('"sql"', 'treport_custom_sql', array('id' => $content['treport_custom_sql_id']))); break; + case "oracle": + $sql = safe_output_html (get_db_value_filter('sql', 'treport_custom_sql', array('id' => $content['treport_custom_sql_id']))); + break; } } else { diff --git a/pandora_console/include/functions_reports.php b/pandora_console/include/functions_reports.php index 2aeac3a53d..cd1b41bce9 100644 --- a/pandora_console/include/functions_reports.php +++ b/pandora_console/include/functions_reports.php @@ -204,6 +204,7 @@ function create_report_content ($id_report, $values) { $values['`order`'] = $order + 1; break; case "postgresql": + case "oracle": unset ($values['"order"']); $order = (int) get_db_value ('MAX("order")', 'treport_content', 'id_report', $id_report); @@ -273,6 +274,7 @@ function move_report_content_up ($id_report_content) { array ('id_rc' => $id_report_content))) !== false; break; case "postgresql": + case "oracle": $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', @@ -317,6 +319,7 @@ function move_report_content_down ($id_report_content) { array ('id_rc' => $id_report_content))) !== false; break; case "postgresql": + case "oracle": $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', @@ -354,6 +357,7 @@ function delete_report_content ($id_report_content) { '`order` > '.$order)); break; case "postgresql": + case "oracle": $order = get_db_value ('"order"', 'treport_content', 'id_rc', $id_report_content); process_sql_update ('treport_content', array ('"order" = "order" - 1'), diff --git a/pandora_console/include/functions_servers.php b/pandora_console/include/functions_servers.php index e27a6c6855..85ffb075b3 100644 --- a/pandora_console/include/functions_servers.php +++ b/pandora_console/include/functions_servers.php @@ -259,6 +259,16 @@ function get_server_info ($id_server = -1) { AND (ceil(date_part('epoch', CURRENT_TIMESTAMP)) - utimestamp) < ( current_interval * 10) AND (ceil(date_part('epoch', CURRENT_TIMESTAMP)) - utimestamp) > current_interval"); break; + case "oracle": + $result = get_db_row_sql ("SELECT COUNT(tagente_modulo.id_agente_modulo) AS module_lag, AVG(ceil((sysdate - to_date('19700101000000','YYYYMMDDHH24MISS')) * (86400)) - utimestamp - current_interval) AS lag FROM tagente_estado, tagente_modulo + WHERE utimestamp > 0 + AND tagente_modulo.disabled = 0 + AND tagente_modulo.id_agente_modulo = tagente_estado.id_agente_modulo + AND current_interval > 0 + AND running_by = ".$server["id_server"]." + AND (ceil((sysdate - to_date('19700101000000','YYYYMMDDHH24MISS')) * (86400)) - utimestamp) < ( current_interval * 10) + AND (ceil((sysdate - to_date('19700101000000','YYYYMMDDHH24MISS')) - utimestamp) * (86400)) > current_interval"); + break; } } else { @@ -286,6 +296,17 @@ function get_server_info ($id_server = -1) { AND running_by = ".$server["id_server"]." AND (ceil(date_part('epoch', CURRENT_TIMESTAMP)) - utimestamp) > (current_interval * 1.1)"); break; + case "oracle": + $result = get_db_row_sql ("SELECT COUNT(tagente_modulo.id_agente_modulo) AS module_lag, AVG(ceil((sysdate - to_date('19700101000000','YYYYMMDDHH24MISS')) * (86400)) - utimestamp - current_interval) AS lag FROM tagente_estado, tagente_modulo + WHERE utimestamp > 0 + AND tagente_modulo.disabled = 0 + AND tagente_modulo.id_tipo_modulo < 5 + AND tagente_modulo.id_agente_modulo = tagente_estado.id_agente_modulo + AND current_interval > 0 + AND (ceil((sysdate - to_date('19700101000000','YYYYMMDDHH24MISS')) * (86400)) - utimestamp) < ( current_interval * 10) + AND running_by = ".$server["id_server"]." + AND (ceil((sysdate - to_date('19700101000000','YYYYMMDDHH24MISS')) * (86400)) - utimestamp) > (current_interval * 1.1)"); + break; } } @@ -326,6 +347,11 @@ function get_server_info ($id_server = -1) { case "postgresql": $server["lag"] = get_db_sql ("SELECT ceil(date_part('epoch', CURRENT_TIMESTAMP)) - utimestamp from trecon_task WHERE ceil(date_part('epoch', CURRENT_TIMESTAMP)) > (utimestamp + interval_sweep) AND id_recon_server = ".$server["id_server"]); + $server["module_lag"] = get_db_sql ("SELECT COUNT(id_rt) FROM trecon_task WHERE ceil(date_part('epoch', CURRENT_TIMESTAMP)) > (utimestamp + interval_sweep) AND id_recon_server = ".$server["id_server"]); + break; + case "oracle": + $server["lag"] = get_db_sql ("SELECT ceil((sysdate - to_date('19700101000000','YYYYMMDDHH24MISS')) * (86400)) - utimestamp from trecon_task WHERE ceil((sysdate - to_date('19700101000000','YYYYMMDDHH24MISS')) * (86400)) > (utimestamp + interval_sweep) AND id_recon_server = ".$server["id_server"]); + $server["module_lag"] = get_db_sql ("SELECT COUNT(id_rt) FROM trecon_task WHERE ceil(date_part('epoch', CURRENT_TIMESTAMP)) > (utimestamp + interval_sweep) AND id_recon_server = ".$server["id_server"]); break; } diff --git a/pandora_console/include/help/en/help_timesource.php b/pandora_console/include/help/en/help_timesource.php index c23c9248e7..54c6a648ac 100644 --- a/pandora_console/include/help/en/help_timesource.php +++ b/pandora_console/include/help/en/help_timesource.php @@ -45,6 +45,9 @@ switch ($config["dbtype"]) { case "postgresql": $timestamp = get_db_value_sql("SELECT ceil(date_part('epoch', CURRENT_TIMESTAMP));"); break; + case "oracle": + $timestamp = get_db_value_sql("SELECT ceil((sysdate - to_date('19700101000000','YYYYMMDDHH24MISS')) * (86400)) as dt FROM dual"); + break; } print_timestamp ($timestamp, false, $option); ?> diff --git a/pandora_console/include/help/es/help_timesource.php b/pandora_console/include/help/es/help_timesource.php index 0b278b614b..906928aa95 100644 --- a/pandora_console/include/help/es/help_timesource.php +++ b/pandora_console/include/help/es/help_timesource.php @@ -45,6 +45,9 @@ switch ($config["dbtype"]) { case "postgresql": $timestamp = get_db_value_sql("SELECT ceil(date_part('epoch', CURRENT_TIMESTAMP));"); break; + case "oracle": + $timestamp = get_db_value_sql("SELECT ceil((sysdate - to_date('19700101000000','YYYYMMDDHH24MISS')) * (86400)) as dt FROM dual"); + break; } print_timestamp ($timestamp, false, $option); ?> diff --git a/pandora_console/include/help/ja/help_timesource.php b/pandora_console/include/help/ja/help_timesource.php index d494c5dcb0..4ad266cb2f 100644 --- a/pandora_console/include/help/ja/help_timesource.php +++ b/pandora_console/include/help/ja/help_timesource.php @@ -40,6 +40,9 @@ switch ($config["dbtype"]) { case "postgresql": $timestamp = get_db_value_sql("SELECT ceil(date_part('epoch', CURRENT_TIMESTAMP));"); break; + case "oracle": + $timestamp = get_db_value_sql("SELECT ceil((sysdate - to_date('19700101000000','YYYYMMDDHH24MISS')) * (86400)) as dt FROM dual"); + break; } print_timestamp ($timestamp, false, $option); ?> diff --git a/pandora_console/install.php b/pandora_console/install.php index c7bdb477f1..f3fe7b4f31 100644 --- a/pandora_console/install.php +++ b/pandora_console/install.php @@ -31,6 +31,37 @@ + + + "; + + return 0; + } + + $query = ""; + oci_free_statement($sql); + } + } + + return 1; + } + else { + return 0; + } +} + function random_name ($size){ $temp = ""; for ($a=0;$a< $size;$a++) @@ -369,6 +464,7 @@ function install_step2() { echo ""; check_extension("mysql", "PHP MySQL extension"); check_extension("pgsql", "PHP PostgreSQL extension"); + check_extension("oci8", "PHP Oracle extension"); echo "
"; // Check if there is at least one server of each type available to assign that // kind of modules. If not, do not show server type in combo -$network_available = get_db_sql ("SELECT count(*) from tserver where server_type = 1"); //POSTGRESQL COMPATIBLE -$wmi_available = get_db_sql ("SELECT count(*) from tserver where server_type = 6"); //POSTGRESQL COMPATIBLE -$plugin_available = get_db_sql ("SELECT count(*) from tserver where server_type = 4"); //POSTGRESQL COMPATIBLE -$prediction_available = get_db_sql ("SELECT count(*) from tserver where server_type = 5"); //POSTGRESQL COMPATIBLE +$network_available = get_db_sql ("SELECT count(*) from tserver where server_type = 1"); //POSTGRESQL AND ORACLE COMPATIBLE +$wmi_available = get_db_sql ("SELECT count(*) from tserver where server_type = 6"); //POSTGRESQL AND ORACLE COMPATIBLE +$plugin_available = get_db_sql ("SELECT count(*) from tserver where server_type = 4"); //POSTGRESQL AND ORACLE COMPATIBLE +$prediction_available = get_db_sql ("SELECT count(*) from tserver where server_type = 5"); //POSTGRESQL AND ORACLE COMPATIBLE // Development mode to use all servers if ($develop_bypass) { @@ -107,20 +107,32 @@ if ($multiple_delete) { // First delete from tagente_modulo -> if not successful, increment // error. NOTICE that we don't delete all data here, just marking for deletion // and delete some simple data. - + $status = ''; if (process_sql("UPDATE tagente_modulo - SET nombre = 'pendingdelete', disabled = 1, delete_pending = 1 WHERE id_agente_modulo = ".$id_agent_module_del) === false) + SET nombre = 'pendingdelete', disabled = 1, delete_pending = 1 WHERE id_agente_modulo = ".$id_agent_module_del, "affected_rows", '', true, $status, false) === false) $error++; - - $result = process_sql_delete('tagente_estado', array('id_agente_modulo' => $id_agent_module_del)); - if ($result === false) - $error++; - - $result = process_sql_delete('tagente_datos_inc', array('id_agente_modulo' => $id_agent_module_del)); - if ($result === false) - $error++; - + switch ($config["dbtype"]) { + case "mysql": + case "postgresql": + $result = process_sql_delete('tagente_estado', array('id_agente_modulo' => $id_agent_module_del)); + if ($result === false) + $error++; + + $result = process_sql_delete('tagente_datos_inc', array('id_agente_modulo' => $id_agent_module_del)); + if ($result === false) + $error++; + break; + case "oracle": + $result = temp_sql_delete('tagente_estado', 'id_agente_modulo', $id_agent_module_del); + if ($result === false) + $error++; + $result = temp_sql_delete('tagente_datos_inc', 'id_agente_modulo', $id_agent_module_del); + if ($result === false) + $error++; + break; + + } //Check for errors if ($error != 0) { process_sql_rollback (); @@ -160,11 +172,27 @@ switch ($sortField) { switch ($sort) { case 'up': $selectNameUp = $selected; - $order[] = array('field' => 'tagente_modulo.nombre', 'order' => 'ASC'); + switch ($config["dbtype"]) { + case "mysql": + case "postgresql": + $order[] = array('field' => 'tagente_modulo.nombre', 'order' => 'ASC'); + break; + case "oracle": + $order[] = array('field' => 'dbms_lob.substr(tagente_modulo.nombre,4000,1)', 'order' => 'ASC'); + break; + } break; case 'down': $selectNameDown = $selected; - $order[] = array('field' => 'tagente_modulo.nombre', 'order' => 'DESC'); + switch ($config["dbtype"]) { + case "mysql": + case "postgresql": + $order[] = array('field' => 'dbms_lob.substr(tagente_modulo.nombre,4000,1)', 'order' => 'DESC'); + break; + case "oracle": + $order[] = array('field' => 'dbms_lob.substr(tagente_modulo.nombre,4000,1)', 'order' => 'DESC'); + break; + } break; } break; @@ -213,7 +241,15 @@ switch ($sortField) { $selectTypeDown = ''; $selectIntervalUp = ''; $selectIntervalDown = ''; - $order[] = array('field' => 'nombre', 'order' => 'ASC'); + switch ($config["dbtype"]) { + case "mysql": + case "postgresql": + $order[] = array('field' => 'dbms_lob.substr(nombre,4000,1)', 'order' => 'ASC'); + break; + case "oracle": + $order[] = array('field' => 'dbms_lob.substr(nombre,4000,1)', 'order' => 'ASC'); + break; + } break; } diff --git a/pandora_console/godmode/agentes/module_manager_editor.php b/pandora_console/godmode/agentes/module_manager_editor.php index 2784dfc56a..1b9b921d8c 100644 --- a/pandora_console/godmode/agentes/module_manager_editor.php +++ b/pandora_console/godmode/agentes/module_manager_editor.php @@ -72,6 +72,7 @@ if (is_ajax ()) { $component['type'] = get_db_value_sql('SELECT id_tipo FROM ttipo_modulo WHERE nombre LIKE "' . $typeName . '"'); break; case "postgresql": + case "oracle": $component['type'] = get_db_value_sql('SELECT id_tipo FROM ttipo_modulo WHERE nombre LIKE \'' . $typeName . '\''); break; } @@ -253,7 +254,6 @@ switch ($moduletype) { case "networkserver": case 2: $moduletype = 2; - $categories = array (3, 4, 5); require ('module_manager_editor_common.php'); require ('module_manager_editor_network.php'); diff --git a/pandora_console/godmode/agentes/planned_downtime.php b/pandora_console/godmode/agentes/planned_downtime.php index edad1e4aeb..ad09073ee7 100644 --- a/pandora_console/godmode/agentes/planned_downtime.php +++ b/pandora_console/godmode/agentes/planned_downtime.php @@ -144,6 +144,11 @@ if ($create_downtime || $update_downtime) { FROM \"tplanned_downtime\" WHERE \"id\" = %d", $id_downtime); break; + case "oracle": + $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); diff --git a/pandora_console/godmode/alerts/alert_compounds.php b/pandora_console/godmode/alerts/alert_compounds.php index 1d88bd413a..96395e355a 100644 --- a/pandora_console/godmode/alerts/alert_compounds.php +++ b/pandora_console/godmode/alerts/alert_compounds.php @@ -134,9 +134,19 @@ echo ''; unset ($table); $where = ''; -if ($search != '') - $where = sprintf (' AND (description LIKE "%%%s%%" OR name LIKE "%%%s%%")', - $search, $search); +if ($search != '') { + switch ($config["dbtype"]) { + case "mysql": + case "postgresql": + $where = sprintf (' AND (description LIKE "%%%s%%" OR name LIKE "%%%s%%")', + $search, $search); + break; + case "oracle": + $where = sprintf (' AND (description LIKE \'%%%s%%\' OR name LIKE \'%%%s%%\')', + $search, $search); + break; + } +} if ($id_agent) $agents = array ($id_agent => $id_agent); @@ -168,11 +178,31 @@ $table->head[3] = __('Delete'); $id_alerts = false; if (count($agents)) { - $sql = sprintf ('SELECT id FROM talert_compound - WHERE id_agent in (%s)%s LIMIT %d OFFSET %d', - implode (',', array_keys ($agents)), $where, - $config['block_size'], get_parameter ('offset')); + switch ($config["dbtype"]) { + case "mysql": + case "postgresql": + $sql = sprintf ('SELECT id FROM talert_compound + WHERE id_agent in (%s)%s LIMIT %d OFFSET %d', + implode (',', array_keys ($agents)), $where, + $config['block_size'], get_parameter ('offset')); + break; + case "oracle": + $set = array(); + $set['offset'] = get_parameter ('offset'); + $set['limit'] = $config['block_size']; + $sql = sprintf ('SELECT id FROM talert_compound + WHERE id_agent in (%s)%s', + implode (',', array_keys ($agents)), $where); + $sql = oracle_recode_query($sql, $set); + break; + } $id_alerts = get_db_all_rows_sql ($sql); + + if (($config["dbtype"] == 'oracle') && ($id_alerts !== false)) { + for ($i=0; $i < count($id_alerts); $i++) { + unset($id_alerts[$i]['rnum']); + } + } } if ($id_alerts === false) diff --git a/pandora_console/godmode/alerts/alert_list.list.php b/pandora_console/godmode/alerts/alert_list.list.php index 109dcf66d6..b5e0ddf33b 100644 --- a/pandora_console/godmode/alerts/alert_list.list.php +++ b/pandora_console/godmode/alerts/alert_list.list.php @@ -65,7 +65,16 @@ $form_filter .= "
Errors creating schema:
"; + echo htmlentities($e['message'], ENT_QUOTES); + echo "
$query
"; + echo "
"; echo "
"; print_logo_status (3,5); @@ -406,16 +502,19 @@ function install_step3() { if (extension_loaded("pgsql")) { $options .= ""; } + if (extension_loaded("oci8")) { + $options .= ""; + } $error = false; if (empty($options)) { $error = true; } - + echo "

Pandora FMS console installation wizard. Step #4 of 5

-
+

Environment and database setup

@@ -424,7 +523,11 @@ function install_step3() {

You need a privileged user to create database schema, this is usually root user. - Information about root user will not be used or stored anymore. + Information about root user will not be used or stored anymore. +

+

+ You can also deploy the scheme into an existing Database. + In this case you need a privileged Database user and password of that instance.

Now, please, complete all details to configure your database and environment setup. @@ -435,8 +538,12 @@ function install_step3() { please be sure that you have no valuable Pandora FMS data in your Database.

"; + + if (extension_loaded("oci8")) { + echo "
For Oracle installation an existing Database with a privileged user is needed.
"; + } if (!$error) { - echo "
"; + echo ""; } echo "
DB ENGINE
"; @@ -448,9 +555,15 @@ function install_step3() {
"; } else { - echo ""; echo $options; echo ""; + echo "
Instalation in
"; + echo ""; + echo "
"; } echo "
DB User with privileges on DB
@@ -505,18 +618,20 @@ function install_step4() { $pandora_config = "include/config.php"; if ( (! isset($_POST["user"])) || (! isset($_POST["dbname"])) || (! isset($_POST["host"])) || - (! isset($_POST["pass"])) || (!isset($_POST['engine'])) ) { + (! isset($_POST["pass"])) || (!isset($_POST['engine'])) || (! isset($_POST["db_action"])) ) { $dbpassword = ""; $dbuser = ""; $dbhost = ""; $dbname = ""; $engine = ""; + $dbaction = ""; } else { $engine = $_POST['engine']; $dbpassword = $_POST["pass"]; $dbuser = $_POST["user"]; $dbhost = $_POST["host"]; + $dbaction = $_POST["db_action"]; if (isset($_POST["drop"])) $dbdrop = $_POST["drop"]; else @@ -553,14 +668,19 @@ function install_step4() { else { check_generic ( 1, "Connection with Database"); - // Drop database if needed - if ($dbdrop == 1) { + // Drop database if needed and don't want to install over an existing DB + if ($dbdrop == 1 && $dbaction != 'db_exist') { mysql_query ("DROP DATABASE IF EXISTS $dbname"); } // Create schema - $step1 = mysql_query ("CREATE DATABASE $dbname"); - check_generic ($step1, "Creating database '$dbname'"); + if ($dbaction != 'db_exist'){ + $step1 = mysql_query ("CREATE DATABASE $dbname"); + check_generic ($step1, "Creating database '$dbname'"); + } + else{ + $step = 1; + } if ($step1 == 1) { $step2 = mysql_select_db($dbname); check_generic ($step2, "Opening database '$dbname'"); @@ -613,6 +733,65 @@ function install_step4() { $everything_ok = 1; } break; + case 'oracle': + $connection = oci_connect($dbuser, $dbpassword, '//' . $dbhost . '/' . $dbname); + if (!$connection){ + check_generic(0, "Connection with Database"); + } + else { + check_generic(1, "Connection with Database"); + + $step1 = parse_oracle_dump($connection, "pandoradb.oracle.sql"); + + check_generic($step1, "Creating schema"); + + if ($step1) { + $step2 = parse_oracle_dump($connection, "pandoradb.data.oracle.sql"); + } + + check_generic ($step2, "Populating database"); + + echo "
Please, you will need to setup your Pandora FMS server, editing the /etc/pandora/pandora_server.conf file and set database password.
"; + + if ($step2) { + $step3 = is_writable("include"); + } + + check_generic ($step3, "Write permissions to save config file in './include'"); + + if ($step3) { + $cfgin = fopen ("include/config.inc.php","r"); + $cfgout = fopen ($pandora_config,"w"); + $config_contents = fread ($cfgin, filesize("include/config.inc.php")); + $dbtype = 'oracle'; + $config_new = ''; + $step4 = fputs ($cfgout, $config_new); + $step4 = $step4 + fputs ($cfgout, $config_contents); + if ($step4 > 0) + $step4 = 1; + fclose ($cfgin); + fclose ($cfgout); + chmod ($pandora_config, 0600); + } + + check_generic ($step4, "Created new config file at '" . $pandora_config . "'"); + + if (($step4 + $step3 + $step2 + $step1) == 4) { + $everything_ok = 1; + } + + } + break; case 'pgsql': $step1 = $step2 = $step3 = $step4 = $step5 = $step6 = $step7 = 0; @@ -623,14 +802,21 @@ function install_step4() { else { check_generic(1, "Connection with Database"); - // Drop database if needed - if ($dbdrop == 1) { + // Drop database if needed and don't want to install over an existing DB + if ($dbdrop == 1 && $dbaction != 'db_exist') { $result = pg_query($connection, "DROP DATABASE \"" . $dbname . "\";"); } - pg_send_query($connection, "CREATE DATABASE \"" . $dbname . "\" WITH ENCODING 'utf8';"); - $result = pg_get_result($connection); - if (pg_result_status($result) != PGSQL_FATAL_ERROR) { + if ($dbaction != 'db_exist'){ + pg_send_query($connection, "CREATE DATABASE \"" . $dbname . "\" WITH ENCODING 'utf8';"); + $result = pg_get_result($connection); + if (pg_result_status($result) != PGSQL_FATAL_ERROR) { + $step1 = 1; + } + + check_generic ($step1, "Creating database '$dbname'"); + } + else{ $step1 = 1; } @@ -795,12 +981,19 @@ function install_step4() { "; } else { - echo "
There were some problems. + $info = "
There were some problems. Installation was not completed.

Please correct failures before trying again. - All database schemes created in this step have been dropped.

+ All database "; + if ($engine == 'oracle') + $info .= "objects "; + else + $info .= "schemes "; + + $info .= "created in this step have been dropped.

"; - + echo $info; + switch ($engine) { case 'mysql': if (mysql_error() != "") { @@ -813,6 +1006,29 @@ function install_step4() { break; case 'pgsql': break; + case 'oracle': + //Drop all objects of the current instalation + $stmt = oci_parse($connection, + "BEGIN " . + "FOR cur_rec IN (SELECT object_name, object_type " . + "FROM user_objects " . + "WHERE object_type IN ('TABLE', 'VIEW', 'PACKAGE', 'PROCEDURE', 'FUNCTION', 'SEQUENCE', 'SNAPSHOT', 'MATERIALIZED VIEW')) LOOP " . + "BEGIN " . + "IF cur_rec.object_type = 'TABLE' THEN " . + "EXECUTE IMMEDIATE 'DROP ' || cur_rec.object_type || ' \"' || cur_rec.object_name || '\" CASCADE CONSTRAINTS'; " . + "ELSE " . + "EXECUTE IMMEDIATE 'DROP ' || cur_rec.object_type || ' \"' || cur_rec.object_name || '\"'; " . + "END IF; " . + "EXCEPTION " . + "WHEN OTHERS THEN " . + "DBMS_OUTPUT.put_line('FAILED: DROP ' || cur_rec.object_type || ' \"' || cur_rec.object_name || '\"'); " . + "END; " . + "END LOOP; " . + "END; "); + + $result = oci_execute($stmt); + oci_free_statement($stmt); + break; } } echo " diff --git a/pandora_console/mobile/operation/agents/monitor_status.php b/pandora_console/mobile/operation/agents/monitor_status.php index 47691aee76..6a61013f3d 100644 --- a/pandora_console/mobile/operation/agents/monitor_status.php +++ b/pandora_console/mobile/operation/agents/monitor_status.php @@ -151,10 +151,21 @@ class MonitorStatus { case "postgresql": $rows = get_db_all_rows_sql($selectSQL . $sql . ' LIMIT ' . $this->system->getPageSize() . ' OFFSET ' . $this->offset); break; + case "oracle": + $set = array(); + $set['limit'] = $this->system->getPageSize(); + $set['offset'] = $this->offset; + $rows = oracle_recode_query ($selectSQL . $sql, $set, 'AND', true); + break; } if ($rows === false) $rows = array(); - + + if ($config["dbtype"] == 'oracle') { + for ($i=0; $i < count($rows); $i++) { + unset($rows[$i]['rnum']); + } + } $table = null; $table->width = '100%'; diff --git a/pandora_console/mobile/operation/agents/view_agents.php b/pandora_console/mobile/operation/agents/view_agents.php index 3287949c3d..42bb33d250 100644 --- a/pandora_console/mobile/operation/agents/view_agents.php +++ b/pandora_console/mobile/operation/agents/view_agents.php @@ -473,10 +473,22 @@ class viewGraph { case "postgresql": $sql = 'SELECT * ' . $sql_body . ' LIMIT ' . $this->system->getPageSize() . ' OFFSET ' . $this->offset; break; + case "oracle": + $set = array(); + $set['limit'] = $this->system->getPageSize(); + $set['offset'] = $this->offset; + $sql = oracle_recode_query ('SELECT * ' . $sql_body, $set); + break; } $result = get_db_all_rows_sql ($sql); - + + if (($config["dbtype"] == 'oracle') && ($result !== false)) { + // Delete rnum row generated by oracle_recode_query() function + for ($i=0; $i < count($result); $i++) { + unset($result[$i]['rnum']); + } + } $table = null; $table->width = '100%'; diff --git a/pandora_console/mobile/operation/events/events.php b/pandora_console/mobile/operation/events/events.php index b789c19c04..a9466c9089 100644 --- a/pandora_console/mobile/operation/events/events.php +++ b/pandora_console/mobile/operation/events/events.php @@ -127,6 +127,12 @@ class EventsView { case "postgresql": $sql = $sql . sprintf(' LIMIT %d OFFSET %d', $this->system->getPageSize(), $offset); break; + case "oracle": + $set = array(); + $set['limit'] = $this->system->getPageSize(); + $set['offset'] = $offset; + $sql = oracle_recode_query ($sql, $set); + break; } $count = get_db_value_sql($sql_count); diff --git a/pandora_console/operation/agentes/alerts_status.php b/pandora_console/operation/agentes/alerts_status.php index 9575374990..50b04f3d45 100644 --- a/pandora_console/operation/agentes/alerts_status.php +++ b/pandora_console/operation/agentes/alerts_status.php @@ -104,6 +104,7 @@ if ($free_search != '') { ')'; break; case "postgresql": + case "oracle": $whereAlertSimple = 'AND (' . 'id_alert_template IN (SELECT id FROM talert_templates WHERE name LIKE \'%' . $free_search . '%\') OR ' . 'id_alert_template IN (SELECT id FROM talert_templates WHERE id_alert_action IN (SELECT id FROM talert_actions WHERE name LIKE \'%' . $free_search . '%\')) OR ' . diff --git a/pandora_console/operation/agentes/datos_agente.php b/pandora_console/operation/agentes/datos_agente.php index 8e95e8bf6e..ec6742a06e 100644 --- a/pandora_console/operation/agentes/datos_agente.php +++ b/pandora_console/operation/agentes/datos_agente.php @@ -105,6 +105,12 @@ switch ($config["dbtype"]) { case "postgresql": $sql .= " LIMIT " . $block_size . " OFFSET " . $offset; break; + case "oracle": + $set = array(); + $set['limit'] = $block_size; + $set['offset'] = $offset; + $sql = oracle_recode_query ($sql, $set); + break; } $result = get_db_all_rows_sql ($sql); @@ -112,6 +118,12 @@ if ($result === false) { $result = array (); } +if (($config['dbtype'] == 'oracle') && ($result !== false)) { + for ($i=0; $i < count($result); $i++) { + unset($result[$i]['rnum']); + } +} + $header_title = __('Received data from')." ".get_agentmodule_agent_name ($module_id)." / ".get_agentmodule_name ($module_id); $header_title .= "

" . __("From the last") . " " . human_time_description_raw ($period); diff --git a/pandora_console/operation/agentes/estado_monitores.php b/pandora_console/operation/agentes/estado_monitores.php index fd3db53597..a08566f0be 100644 --- a/pandora_console/operation/agentes/estado_monitores.php +++ b/pandora_console/operation/agentes/estado_monitores.php @@ -117,6 +117,15 @@ switch ($sortField) { break; } +switch ($config["dbtype"]) { + case "oracle": + if (isset($order['field']) && $order['field'] == 'tagente_modulo.nombre') { + $order['field'] = 'dbms_lob.substr(tagente_modulo.nombre,4000,1)'; + } + break; +} + + // Get all module from agent $sql = sprintf (" SELECT * diff --git a/pandora_console/operation/agentes/estado_ultimopaquete.php b/pandora_console/operation/agentes/estado_ultimopaquete.php index ccf855e70d..cbc50241a8 100644 --- a/pandora_console/operation/agentes/estado_ultimopaquete.php +++ b/pandora_console/operation/agentes/estado_ultimopaquete.php @@ -33,12 +33,25 @@ $timestamp_lof = $agent["ultimo_contacto"]; $intervalo_agente = $agent["intervalo"]; // Get last packet -$sql3 = 'SELECT * FROM tagente_modulo, tagente_estado - WHERE tagente_modulo.disabled = 0 - AND tagente_modulo.id_agente = ' . $id_agente. - ' AND tagente_estado.utimestamp != 0 - AND tagente_modulo.id_agente_modulo = tagente_estado.id_agente_modulo - ORDER BY id_module_group, nombre'; +switch ($config["dbtype"]) { + case "mysql": + case "postgresql": + $sql3 = 'SELECT * FROM tagente_modulo, tagente_estado + WHERE tagente_modulo.disabled = 0 + AND tagente_modulo.id_agente = ' . $id_agente. + ' AND tagente_estado.utimestamp != 0 + AND tagente_modulo.id_agente_modulo = tagente_estado.id_agente_modulo + ORDER BY id_module_group, nombre'; + break; + case "oracle": + $sql3 = 'SELECT * FROM tagente_modulo, tagente_estado + WHERE tagente_modulo.disabled = 0 + AND tagente_modulo.id_agente = ' . $id_agente. + ' AND tagente_estado.utimestamp != 0 + AND tagente_modulo.id_agente_modulo = tagente_estado.id_agente_modulo + ORDER BY id_module_group, dbms_lob.substr(nombre,4000,1)'; + break; +} $label_group = 0; $last_label = ""; @@ -69,11 +82,27 @@ switch ($sortField) { switch ($sort) { case 'up': $selectNameUp = $selected; - $order[] = array('field' => 'tagente_modulo.nombre', 'order' => 'ASC'); + switch ($config["dbtype"]) { + case "mysql": + case "postgresql": + $order[] = array('field' => 'tagente_modulo.nombre', 'order' => 'ASC'); + break; + case "oracle": + $order[] = array('field' => 'dbms_lob.substr(tagente_modulo.nombre,4000,1)', 'order' => 'ASC'); + break; + } break; case 'down': $selectNameDown = $selected; - $order[] = array('field' => 'tagente_modulo.nombre', 'order' => 'DESC'); + switch ($config["dbtype"]) { + case "mysql": + case "postgresql": + $order[] = array('field' => 'tagente_modulo.nombre', 'order' => 'DESC'); + break; + case "oracle": + $order[] = array('field' => 'dbms_lob.substr(tagente_modulo.nombre,4000,1)', 'order' => 'DESC'); + break; + } break; } break; @@ -135,7 +164,15 @@ switch ($sortField) { $selectIntervalDown = ''; $selectTimestampUp = ''; $selectTimestampDown = ''; - $order[] = array('field' => 'tagente_modulo.nombre', 'order' => 'ASC'); + switch ($config["dbtype"]) { + case "mysql": + case "postgresql": + $order[] = array('field' => 'tagente_modulo.nombre', 'order' => 'ASC'); + break; + case "oracle": + $order[] = array('field' => 'dbms_lob.substr(tagente_modulo.nombre,4000,1)', 'order' => 'ASC'); + break; + } break; } diff --git a/pandora_console/operation/agentes/exportdata.php b/pandora_console/operation/agentes/exportdata.php index 1ff0984bab..42285449fc 100644 --- a/pandora_console/operation/agentes/exportdata.php +++ b/pandora_console/operation/agentes/exportdata.php @@ -13,6 +13,8 @@ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. +global $config; + if (is_ajax ()) { $search_agents = (bool) get_parameter ('search_agents'); @@ -34,7 +36,15 @@ if (is_ajax ()) { } $filter = array (); - $filter[] = '(nombre COLLATE utf8_general_ci LIKE "%'.$string.'%" OR direccion LIKE "%'.$string.'%" OR comentarios LIKE "%'.$string.'%")'; + switch ($config['dbtype']) { + case "mysql": + case "postgresql": + $filter[] = '(nombre COLLATE utf8_general_ci LIKE "%'.$string.'%" OR direccion LIKE "%'.$string.'%" OR comentarios LIKE "%'.$string.'%")'; + break; + case "oracle": + $filter[] = '(UPPER(nombre) LIKE UPPER(\'%'.$string.'%\') OR UPPER(direccion) LIKE UPPER(\'%'.$string.'%\') OR UPPER(comentarios) LIKE UPPER(\'%'.$string.'%\'))'; + break; + } $filter['id_grupo'] = $id_group; switch ($all) { @@ -79,7 +89,15 @@ print_page_header (__("Export data"), "images/bricks.png"); $group = get_parameter_post ('group', 0); //$agent = get_parameter_post ('agent', 0); $agentName = get_parameter_post ('agent', 0); -$agents = get_agents (array('nombre LIKE "' . $agentName . '"'), array ('id_agente')); + switch ($config["dbtype"]) { + case "mysql": + case "postgresql": + $agents = get_agents (array('nombre LIKE "' . $agentName . '"'), array ('id_agente')); + break; + case "oracle": + $agents = get_agents (array('nombre LIKE \'%' . $agentName . '%\''), array ('id_agente')); + break; + } $agent = $agents[0]['id_agente']; $module = (array) get_parameter_post ('module_arr', array ()); diff --git a/pandora_console/operation/agentes/gis_view.php b/pandora_console/operation/agentes/gis_view.php index d3d9c39171..6921de752f 100644 --- a/pandora_console/operation/agentes/gis_view.php +++ b/pandora_console/operation/agentes/gis_view.php @@ -56,6 +56,9 @@ switch ($config["dbtype"]) { case "postgresql": $timestampLastOperation = get_db_value_sql("SELECT ceil(date_part('epoch', CURRENT_TIMESTAMP));"); break; + case "oracle": + $timestampLastOperation = get_db_value_sql("SELECT ceil((sysdate - to_date('19700101000000','YYYYMMDDHH24MISS')) * (86400)) from dual"); + break; } activateAjaxRefresh(null, $timestampLastOperation); diff --git a/pandora_console/operation/agentes/status_monitor.php b/pandora_console/operation/agentes/status_monitor.php index 4dd4a0360c..3208128542 100644 --- a/pandora_console/operation/agentes/status_monitor.php +++ b/pandora_console/operation/agentes/status_monitor.php @@ -141,6 +141,45 @@ switch ($config["dbtype"]) { ) )'; break; + case "oracle": + $names = oracle_get_db_all_rows_filter ('user_tab_columns',array ('table_name' => 'TAGENTE_MODULO', 'column_name' => '<>NOMBRE'), 'column_name'); + $column_names = ''; + foreach ($names as $column_name => $value) { + $column_names .= $value['column_name'] . ','; + } + + $column_names = substr($column_names,0,-1); + $sql = ' + select nombre + from (select distinct dbms_lob.substr(nombre,4000,1) as nombre, ' . $column_names .' from tagente_modulo) + where nombre <> \'delete_pending\' and id_agente in + ( + select id_agente + from tagente where id_grupo IN ( + select id_grupo + from tusuario_perfil + where id_usuario = \'' . $config['id_user'] . '\' + and id_perfil IN ( + select id_perfil + from tperfil where agent_view = 1 + ) + ) + OR + (1 = ( + SELECT is_admin FROM tusuario WHERE id_user = \'' . $config['id_user'] . '\' + ) + ) + OR 0 IN ( + select id_grupo + from tusuario_perfil + where id_usuario = \'' . $config['id_user'] . '\' + and id_perfil IN ( + select id_perfil + from tperfil where agent_view = 1 + ) + ) + )'; + break; } $modules = get_db_all_rows_sql($sql); @@ -249,6 +288,25 @@ switch ($config["dbtype"]) { tagente_estado.estado, tagente_estado.utimestamp AS utimestamp".$sql." LIMIT " . $config["block_size"] . " OFFSET " . $offset; break; + case "oracle": + $set = array(); + $set['limit'] = $config["block_size"]; + $set['offset'] = $offset; + $sql = "SELECT tagente_modulo.id_agente_modulo, + tagente.intervalo AS agent_interval, + tagente.nombre AS agent_name, + tagente_modulo.nombre AS module_name, + tagente_modulo.history_data, + tagente_modulo.flag AS flag, + tagente.id_grupo AS id_group, + tagente.id_agente AS id_agent, + tagente_modulo.id_tipo_modulo AS module_type, + tagente_modulo.module_interval, + tagente_estado.datos, + tagente_estado.estado, + tagente_estado.utimestamp AS utimestamp".$sql; + $sql = oracle_recode_query ($sql, $set); + break; } $result = get_db_all_rows_sql ($sql); @@ -260,6 +318,12 @@ if ($result === false) { $result = array (); } +if (($config['dbtype'] == 'oracle') && ($result !== false)) { + for ($i=0; $i < count($result); $i++) { + unset($result[$i]['rnum']); + } +} + $table->cellpadding = 4; $table->cellspacing = 4; $table->width = 750; diff --git a/pandora_console/operation/agentes/ver_agente.php b/pandora_console/operation/agentes/ver_agente.php index 7585bf6087..004bd548f8 100644 --- a/pandora_console/operation/agentes/ver_agente.php +++ b/pandora_console/operation/agentes/ver_agente.php @@ -190,7 +190,7 @@ if (is_ajax ()) { //Hack to translate text "any" in PHP to javascript //$agent_modules['any_text'] = __('Any'); - + echo json_encode ($agent_modules); return; } diff --git a/pandora_console/operation/events/events_list.php b/pandora_console/operation/events/events_list.php index de952ecf19..80937b3e46 100644 --- a/pandora_console/operation/events/events_list.php +++ b/pandora_console/operation/events/events_list.php @@ -255,6 +255,15 @@ if ($group_rep == 0) { FROM tevento WHERE 1=1 ".$sql_post." ORDER BY utimestamp DESC LIMIT ".$pagination." OFFSET ".$offset; break; + case "oracle": + $set = array(); + $set['limit'] = $pagination; + $set['offset'] = $offset; + $sql = "SELECT * + FROM tevento + WHERE 1=1 ".$sql_post." ORDER BY utimestamp DESC"; + $sql = oracle_recode_query ($sql, $set); + break; } } else { @@ -273,6 +282,22 @@ else { GROUP BY evento, id_agentmodule ORDER BY timestamp_rep DESC LIMIT ".$pagination." OFFSET ".$offset; break; + case "oracle": + $set = array(); + $set['limit'] = $pagination; + $set['offset'] = $offset; + $sql = "SELECT a.*, b.event_rep, b.timestamp_rep + FROM (select * from tevento WHERE 1=1 ".$sql_post.") a, + (select min(id_evento) as id_evento, to_char(evento) as evento, + id_agentmodule, COUNT(*) AS event_rep, MAX(utimestamp) AS timestamp_rep + from tevento + WHERE 1=1 ".$sql_post." + GROUP BY to_char(evento), id_agentmodule) b + where a.id_evento=b.id_evento and + to_char(a.evento)=to_char(b.evento) + and a.id_agentmodule=b.id_agentmodule"; + $sql = oracle_recode_query ($sql, $set); + break; } } @@ -280,6 +305,13 @@ else { //Extract the events by filter (or not) from db $result = get_db_all_rows_sql ($sql); +// Delete rnum field generated by oracle_recode_query() function +if (($config['dbtype'] == 'oracle') && ($result !== false)) { + for ($i=0; $i < count($result); $i++) { + unset($result[$i]['rnum']); + } +} + if ($group_rep == 0) { $sql = "SELECT COUNT(id_evento) FROM tevento WHERE 1=1 ".$sql_post; } diff --git a/pandora_console/operation/events/events_marquee.php b/pandora_console/operation/events/events_marquee.php index d1ad191197..61c9e3e85c 100644 --- a/pandora_console/operation/events/events_marquee.php +++ b/pandora_console/operation/events/events_marquee.php @@ -64,6 +64,9 @@ switch ($config["dbtype"]) { case "postgresql": $sql = "SELECT evento, timestamp, id_agente FROM tevento WHERE 1=1 $sql_group_filter ORDER BY utimestamp DESC LIMIT $MAX_MARQUEE_EVENTS OFFSET 0"; break; + case "oracle": + $sql = "SELECT evento, timestamp, id_agente FROM tevento WHERE (1=1 $sql_group_filter ) AND rownum <= $MAX_MARQUEE_EVENTS ORDER BY utimestamp DESC"; + break; } $result = get_db_all_rows_sql ($sql); diff --git a/pandora_console/operation/events/events_rss.php b/pandora_console/operation/events/events_rss.php index 9878761728..cba5da3d30 100644 --- a/pandora_console/operation/events/events_rss.php +++ b/pandora_console/operation/events/events_rss.php @@ -184,6 +184,19 @@ switch ($config["dbtype"]) { WHERE 1 = 1" . $sql_post . " ORDER BY utimestamp DESC LIMIT 30 OFFSET 0"; break; + case "oracle": + $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 . ") AND rownum <= 30 + ORDER BY utimestamp DESC"; + break; } $result= get_db_all_rows_sql ($sql); diff --git a/pandora_console/operation/gis_maps/ajax.php b/pandora_console/operation/gis_maps/ajax.php index b349e35dfc..f167c83ac3 100644 --- a/pandora_console/operation/gis_maps/ajax.php +++ b/pandora_console/operation/gis_maps/ajax.php @@ -93,6 +93,14 @@ switch ($opt) { LEFT JOIN tgis_data_status AS t2 ON t1.id_agente = t2.tagente_id_agente WHERE id_agente IN (' . implode(',', $idAgentsWithGIS) . ')'); break; + case "oracle": + $agentsGISStatus = get_db_all_rows_sql('SELECT t1.nombre, id_parent, t1.id_agente AS tagente_id_agente, + COALESCE(t2.stored_longitude, ' . $defaultCoords['default_longitude'] . ') AS stored_longitude, + COALESCE(t2.stored_latitude, ' . $defaultCoords['default_latitude'] . ') AS stored_latitude + FROM tagente t1 + LEFT JOIN tgis_data_status t2 ON t1.id_agente = t2.tagente_id_agente + WHERE id_agente IN (' . implode(',', $idAgentsWithGIS) . ')'); + break; } if ($agentsGISStatus === false) { diff --git a/pandora_console/operation/gis_maps/render_view.php b/pandora_console/operation/gis_maps/render_view.php index b640133429..5e7656eb87 100644 --- a/pandora_console/operation/gis_maps/render_view.php +++ b/pandora_console/operation/gis_maps/render_view.php @@ -179,6 +179,9 @@ if ($layers != false) { case "postgresql": $timestampLastOperation = get_db_value_sql("SELECT ceil(date_part('epoch', CURRENT_TIMESTAMP))"); break; + case "oracle": + $timestampLastOperation = get_db_value_sql("SELECT ceil((sysdate - to_date('19700101000000','YYYYMMDDHH24MISS')) * (86400)) from dual"); + break; } activateSelectControl(); diff --git a/pandora_console/operation/reporting/reporting_viewer.php b/pandora_console/operation/reporting/reporting_viewer.php index bd2d78877c..aff40c8204 100644 --- a/pandora_console/operation/reporting/reporting_viewer.php +++ b/pandora_console/operation/reporting/reporting_viewer.php @@ -140,6 +140,9 @@ switch ($config["dbtype"]) { case "postgresql": $contents = get_db_all_rows_field_filter ("treport_content", "id_report", $id_report, '"order"'); break; + case "oracle": + $contents = get_db_all_rows_field_filter ("treport_content", "id_report", $id_report, '"order"'); + break; } if ($contents === false) { return; diff --git a/pandora_console/operation/reporting/reporting_xml.php b/pandora_console/operation/reporting/reporting_xml.php index 9614654573..c3caf252a0 100644 --- a/pandora_console/operation/reporting/reporting_xml.php +++ b/pandora_console/operation/reporting/reporting_xml.php @@ -147,6 +147,7 @@ switch ($config["dbtype"]) { $contents = get_db_all_rows_field_filter ('treport_content', 'id_report', $id_report, '`order`'); break; case "postgresql": + case "oracle": $contents = get_db_all_rows_field_filter ('treport_content', 'id_report', $id_report, '"order"'); break; } @@ -365,6 +366,9 @@ foreach ($contents as $content) { case "postgresql": $sql = get_db_value_filter('"sql"', 'treport_custom_sql', array('id' => $content['treport_custom_sql_id'])); break; + case "oracle": + $sql = get_db_value_filter('sql', 'treport_custom_sql', array('id' => $content['treport_custom_sql_id'])); + break; } } else { diff --git a/pandora_console/operation/search_alerts.php b/pandora_console/operation/search_alerts.php index 7a7df5b6fd..ceba7a8687 100755 --- a/pandora_console/operation/search_alerts.php +++ b/pandora_console/operation/search_alerts.php @@ -129,6 +129,7 @@ if($searchAlerts) { )'; break; case "postgresql": + case "oracle": $whereAlerts = 'AND ( id_alert_template IN (SELECT id FROM talert_templates WHERE name LIKE \'%' . $stringSearchSQL . '%\') OR id_alert_template IN ( diff --git a/pandora_console/operation/search_modules.php b/pandora_console/operation/search_modules.php index 48e82748cb..f3c708d400 100644 --- a/pandora_console/operation/search_modules.php +++ b/pandora_console/operation/search_modules.php @@ -107,6 +107,29 @@ if ($searchModules) { t1.nombre COLLATE utf8_general_ci LIKE \'%' . $stringSearchSQL . '%\' OR t3.nombre LIKE \'%' . $stringSearchSQL . '%\''; break; + case "oracle": + $chunk_sql = ' + FROM tagente_modulo AS t1 + INNER JOIN tagente AS t2 + ON t2.id_agente = t1.id_agente + INNER JOIN tgrupo AS t3 + ON t3.id_grupo = t2.id_grupo + INNER JOIN tagente_estado AS t4 + ON t4.id_agente_modulo = t1.id_agente_modulo + WHERE (t2.id_grupo IN (' . implode(',', $id_userGroups) . ') + OR 0 IN ( + SELECT id_grupo + FROM tusuario_perfil + WHERE id_usuario = \'' . $config['id_user'] . '\' + AND id_perfil IN ( + SELECT id_perfil + FROM tperfil WHERE agent_view = 1 + ) + ) + ) AND + UPPER(t1.nombre) LIKE UPPER(\'%' . $stringSearchSQL . '%\') OR + t3.nombre LIKE \'%' . $stringSearchSQL . '%\''; + break; } $select = "SELECT *, t1.nombre AS module_name, t2.nombre AS agent_name "; diff --git a/pandora_console/operation/snmpconsole/snmp_view.php b/pandora_console/operation/snmpconsole/snmp_view.php index e3c6277ccc..21aa744c77 100644 --- a/pandora_console/operation/snmpconsole/snmp_view.php +++ b/pandora_console/operation/snmpconsole/snmp_view.php @@ -123,9 +123,22 @@ switch ($config["dbtype"]) { case "postgresql": $sql = sprintf ("SELECT * FROM ttrap ORDER BY timestamp DESC LIMIT %d OFFSET %d", $pagination, $offset); break; + case "oracle": + $set = array(); + $set['limit'] = $pagination; + $set['offset'] = $offset; + $sql = sprintf ("SELECT * FROM ttrap ORDER BY timestamp DESC"); + $sql = oracle_recode_query ($sql, $set); + break; } $traps = get_db_all_rows_sql ($sql); +if (($config['dbtype'] == 'oracle') && ($traps !== false)) { + for ($i=0; $i < count($traps); $i++) { + unset($traps[$i]['rnum']); + } +} + // No traps if (empty ($traps)) { echo '
'.__('There are no SNMP traps in database').'
'; @@ -164,6 +177,9 @@ switch ($config["dbtype"]) { case "postgresql": $sql = "SELECT * FROM ttrap %s ORDER BY timestamp DESC LIMIT %d OFFSET %d"; break; + case "oracle": + $sql = "SELECT * FROM ttrap %s ORDER BY timestamp DESC"; + break; } $whereSubquery = 'WHERE 1=1'; @@ -173,6 +189,7 @@ if ($filter_agent != '') { $whereSubquery .= ' AND source LIKE "' . $filter_agent . '"'; break; case "postgresql": + case "oracle": $whereSubquery .= ' AND source LIKE \'' . $filter_agent . '\''; break; } @@ -186,6 +203,7 @@ if ($filter_oid != '') { $whereSubquery .= ' AND (text LIKE "' . $filter_oid . '" OR oid LIKE "' . $filter_oid . '")'; break; case "postgresql": + case "oracle": $whereSubquery .= ' AND (text LIKE \'' . $filter_oid . '\' OR oid LIKE \'' . $filter_oid . '\')'; break; } @@ -196,6 +214,7 @@ if ($filter_oid != '') { $whereSubquery .= ' AND oid LIKE "' . $filter_oid . '"'; break; case "postgresql": + case "oracle": $whereSubquery .= ' AND oid LIKE \'' . $filter_oid . '\''; break; } @@ -209,6 +228,7 @@ if ($search_string != '') { $whereSubquery .= ' AND value LIKE "%' . $search_string . '%"'; break; case "postgresql": + case "oracle": $whereSubquery .= ' AND value LIKE \'%' . $search_string . '%\''; break; } @@ -235,10 +255,22 @@ switch ($config["dbtype"]) { case "postgresql": $sql = sprintf($sql, $whereSubquery, $pagination, $offset); break; + case "oracle": + $set = array(); + $set['limit'] = $pagination; + $set['offset'] = $offset; + $sql = oracle_recode_query ($sql, $set); + break; } $traps = get_db_all_rows_sql($sql); +if (($config['dbtype'] == 'oracle') && ($traps !== false)) { + for ($i=0; $i < count($traps); $i++) { + unset($traps[$i]['rnum']); + } +} + if ($config["pure"] == 1) { echo '