2009-05-01 17:01:52 +02:00
< ? php
2011-03-17 Raul Mateos <raulofpandora@gmail.com>
* extensions/dbmanager.php, extensions/pandora_logs.php, general/*.php,
index.php, ajax.php, operation/search_*.php, operation/menu.php,
operation/extensions.php, godmode/menu.php, godmode/extensions.php,
admin_access_logs.php: Cleaned code and updated page disclaimers.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@4108 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2011-03-17 23:01:01 +01:00
// Pandora FMS - http://pandorafms.com
2009-06-08 20:26:14 +02:00
// ==================================================
2011-03-17 21:51:46 +01:00
// Copyright (c) 2005-2011 Artica Soluciones Tecnologicas
2011-03-17 Raul Mateos <raulofpandora@gmail.com>
* extensions/dbmanager.php, extensions/pandora_logs.php, general/*.php,
index.php, ajax.php, operation/search_*.php, operation/menu.php,
operation/extensions.php, godmode/menu.php, godmode/extensions.php,
admin_access_logs.php: Cleaned code and updated page disclaimers.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@4108 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2011-03-17 23:01:01 +01:00
// Please see http://pandorafms.org for full contribution list
2009-05-01 17:01:52 +02:00
// This program is free software; you can redistribute it and/or
2011-03-17 Raul Mateos <raulofpandora@gmail.com>
* extensions/dbmanager.php, extensions/pandora_logs.php, general/*.php,
index.php, ajax.php, operation/search_*.php, operation/menu.php,
operation/extensions.php, godmode/menu.php, godmode/extensions.php,
admin_access_logs.php: Cleaned code and updated page disclaimers.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@4108 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2011-03-17 23:01:01 +01:00
// modify it under the terms of the GNU Lesser General Public License
// as published by the Free Software Foundation; version 2
2009-05-01 17:01:52 +02:00
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
2011-03-17 Raul Mateos <raulofpandora@gmail.com>
* extensions/dbmanager.php, extensions/pandora_logs.php, general/*.php,
index.php, ajax.php, operation/search_*.php, operation/menu.php,
operation/extensions.php, godmode/menu.php, godmode/extensions.php,
admin_access_logs.php: Cleaned code and updated page disclaimers.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@4108 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2011-03-17 23:01:01 +01:00
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2009-05-01 17:01:52 +02:00
// GNU General Public License for more details.
2009-05-04 15:11:16 +02:00
function dbmanager_query ( $sql , & $error ) {
2009-05-02 01:41:09 +02:00
global $config ;
2011-03-03 Miguel de Dios <miguel.dedios@artica.es>
* include/db/postgresql.php, include/db/mysql.php, include/functions_db.php:
fixed the function "get_db_all_rows_filter" for PostgreSQL engine, added
new function "get_db_last_error" and derivate functions in DB engines. And
added new parameter $status in function "process_sql".
* extensions/dbmanager.php, general/error_authconfig.php,
general/error_dbconfig.php, godmode/groups/modu_group_list.php,
godmode/groups/group_list.php, godmode/db/db_sanity.php,
godmode/agentes/fields_manager.php,
godmode/agentes/manage_config_remote.php, godmode/servers/recon_script.php,
godmode/servers/plugin.php, godmode/modules/module_list.php,
godmode/modules/manage_network_components_form_wmi.php,
godmode/reporting/graphs.php: changed the calls to mysql functions to own
functions, and rewrote some parts of source code for this action.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@4057 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2011-03-03 19:35:37 +01:00
switch ( $config [ " dbtype " ]) {
case " mysql " :
$retval = array ();
2009-11-19 21:04:11 +01:00
2011-03-03 Miguel de Dios <miguel.dedios@artica.es>
* include/db/postgresql.php, include/db/mysql.php, include/functions_db.php:
fixed the function "get_db_all_rows_filter" for PostgreSQL engine, added
new function "get_db_last_error" and derivate functions in DB engines. And
added new parameter $status in function "process_sql".
* extensions/dbmanager.php, general/error_authconfig.php,
general/error_dbconfig.php, godmode/groups/modu_group_list.php,
godmode/groups/group_list.php, godmode/db/db_sanity.php,
godmode/agentes/fields_manager.php,
godmode/agentes/manage_config_remote.php, godmode/servers/recon_script.php,
godmode/servers/plugin.php, godmode/modules/module_list.php,
godmode/modules/manage_network_components_form_wmi.php,
godmode/reporting/graphs.php: changed the calls to mysql functions to own
functions, and rewrote some parts of source code for this action.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@4057 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2011-03-03 19:35:37 +01:00
if ( $sql == '' )
return false ;
$sql = html_entity_decode ( $sql , ENT_QUOTES );
$result = mysql_query ( $sql );
if ( $result === false ) {
$backtrace = debug_backtrace ();
$error = mysql_error ();
return false ;
}
if ( $result === true ) {
return mysql_affected_rows ();
}
while ( $row = mysql_fetch_array ( $result , MYSQL_ASSOC )) {
array_push ( $retval , $row );
}
mysql_free_result ( $result );
if ( ! empty ( $retval ))
return $retval ;
//Return false, check with === or !==
return " Empty " ;
break ;
case " postgresql " :
$retval = array ();
if ( $sql == '' )
return false ;
$sql = html_entity_decode ( $sql , ENT_QUOTES );
$result = process_sql ( $sql , " affected_rows " , '' , false , $status );
//$result = mysql_query ($sql);
if ( $result === false ) {
$backtrace = debug_backtrace ();
$error = get_db_last_error ();
return false ;
}
if ( $status == 2 ) {
return $result ;
}
else {
return $result ;
}
break ;
2009-05-02 01:41:09 +02:00
}
}
2009-05-01 17:01:52 +02:00
function dbmgr_extension_main () {
2009-05-04 15:11:16 +02:00
require_css_file ( 'dbmanager' , 'extensions/dbmanager/' );
2009-05-01 17:01:52 +02:00
2011-03-17 21:51:46 +01:00
global $config ;
2010-03-06 14:45:48 +01:00
2011-03-17 21:51:46 +01:00
if ( ! check_acl ( $config [ 'id_user' ], 0 , " PM " ) && ! is_user_admin ( $config [ 'id_user' ])) {
pandora_audit ( " ACL Violation " , " Trying to access Setup Management " );
require ( " general/noaccess.php " );
return ;
}
2010-03-06 14:45:48 +01:00
2009-05-04 15:11:16 +02:00
$sql = ( string ) get_parameter ( 'sql' );
2009-05-01 17:01:52 +02:00
2010-02-19 Sancho Lerena <slerena@artica.es>
* functions_events.php: Fixed typo (switched meaning) in two labels.
* include/styles/pandora.css: Changed background color of th default style.
* include/functions_reporting.php: Improved function get_group_stats(). Now
supports stats from batch-mode and get realtime stats in a more efficient
way. Fixed get_fired_alerts_reporting_table() to avoid problems in external
reporting (PDF & XML).
* include/functions_servers.php: get_server_performance() now uses batch mode
stats reporting, and improved also the realtime stats generation. Same with
function get_server_info().
* include/functions_config.php: Added new config tokens (not fully
implemented yet) for event, trap, strings and audit automatic purge.
* include/functions_ui.php: Added new print_page_header() function to set
the new standard header in all pages, using the "tabbed" format to show
the title, subtitle and other options like help, or custom-tabs for the page
* pandoradb.sql: Added tserver.stat_utimestamp field. Added indexes to
tsession table. Fixed typo in field name in tgroup_stat: agents_uknown to
agents_unknown.
* extensions/ext_backup: New directory to place "deleted" extensions.
* extensions/dbmanager/dbmanager.css: Table names now are in it's original
lowercase/uppercase format.
* extensions/dbmanager.php: Updated headers, and now return "empty" when
a search is empty, instead "error" as before.
* extensions/users_connected.php
extensions/module_groups.php
extensions/plugin_registration.php
extensions/pandora_logs.php
operation/incidents/incident.php
operation/snmpconsole/snmp_view.php
operation/users/user.php
operation/users/user_edit.php
godmode/agentes/planned_downtime.php
operation/events/events.php
operation/visual_console/index.php
operation/agentes/estado_generalagente.php
operation/agentes/estado_agente.php
operation/agentes/exportdata.php
operation/agentes/ver_agente.php
operation/agentes/status_monitor.php
operation/agentes/alerts_status.php
operation/users/user_statistics.php: Added new header format.
* operation/agentes/estado_grupo.php: Removed old group view.
* operation/agentes/tactical.php: Adapted to use new realtime/batch
statistical system. Placed events above server info. Showing only pending
events and other minor changes.
* operation/agentes/group_view.php: NEW screen, replacing old one. Probably
most ugly, but much more useful than before.
* operation/agentes/networkmap.php: Added title.
* operation/messages/message.php: Added title and adding some exists in
code was missing before.
* operation/reporting/reporting_viewer.php: Added title.
* operation/reporting/graph_viewer.php: Added title.
* operation/reporting/custom_reporting.php: Added title.
* operation/servers/view_server.php:
* operation/menu.php: Replaced old group view with new (this has english
name). Removed autorefresh "by default" in server view.
* extras/pandoradb_migrate_v3.0_to_v3.1.sql: Fixed typo.
* extras/pandora_diag.php: Minor changes, removed some info and added other.
* general/logon_ok.php: Minor aesthetic changes.
* general/header.php: Fixed missing ";"
* operation/extensions.php,
godmode/extensions.php: Added support for delete extensions.
* godmode/menu.php: New setup items.
* godmode/setup/setup.php,
godmode/setup/performance.php,
godmode/setup/setup_visuals.php: Reordered setup options, new setup section
"Performance", added new performance options to set "realtime" statistics
or "batchmode" with it's own interval. Some setup info is now shared with
the servers (but it it's any change in setup, servers should be restarted
anyway).
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@2390 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2010-02-19 16:16:03 +01:00
print_page_header ( __ ( 'Database interface' ), " " , false , false , true );
2009-05-04 15:11:16 +02:00
echo '<div class="notify">' ;
2011-03-17 21:51:46 +01:00
echo " This is an advanced extension to interface with Pandora FMS database directly from WEB console using native SQL sentences. Please note that <b>you can damage</b> your Pandora FMS installation if you don't know </b>exactly</b> what are you are doing, this means that you can severily damage your setup using this extension. This extension is intended to be used <b>only by experienced users</b> with a depth knowledge of Pandora FMS internals. " ;
2009-05-04 15:11:16 +02:00
echo '</div>' ;
2009-05-01 17:01:52 +02:00
2009-05-04 15:11:16 +02:00
echo " <br /> " ;
echo " Some samples of usage: <blockquote><em>SHOW STATUS;<br />DESCRIBE tagente<br />SELECT * FROM tserver<br />UPDATE tagente SET id_grupo = 15 WHERE nombre LIKE '%194.179%'</em></blockquote> " ;
2009-05-01 17:01:52 +02:00
2009-05-04 15:11:16 +02:00
echo " <br /><br /> " ;
2009-05-01 17:01:52 +02:00
echo " <form method='post' action=''> " ;
2010-02-01 20:22:34 +01:00
print_textarea ( 'sql' , 5 , 40 , html_entity_decode ( $sql , ENT_QUOTES ));
2009-05-04 15:11:16 +02:00
echo '<br />' ;
2010-02-01 20:22:34 +01:00
echo '<div class="action-buttons" style="width: 96%">' ;
2009-05-04 15:11:16 +02:00
print_submit_button ( __ ( 'Execute SQL' ), '' , false , 'class="sub next"' );
echo '</div>' ;
2009-05-01 17:01:52 +02:00
echo " </form> " ;
// Processing SQL Code
2009-05-04 15:11:16 +02:00
if ( $sql == '' )
return ;
echo " <br /> " ;
echo " <hr /> " ;
echo " <br /> " ;
$error = '' ;
$result = dbmanager_query ( $sql , $error );
if ( $result === false ) {
echo '<strong>An error has occured when querying the database.</strong><br />' ;
echo $error ;
2010-10-29 Miguel de Dios <miguel.dedios@artica.es>
* extensions/dbmanager.php, godmode/agentes/module_manager_editor.php,
godmode/massive/massive_add_alerts.php,
godmode/massive/massive_copy_modules.php,
godmode/massive/massive_delete_agents.php,
godmode/massive/massive_enable_disable_alerts.php,
godmode/massive/massive_operations.php,
godmode/massive/massive_delete_profiles.php,
godmode/massive/massive_edit_agents.php,
godmode/massive/massive_delete_action_alerts.php,
godmode/massive/massive_delete_modules.php,
godmode/massive/massive_add_profiles.php,
godmode/massive/massive_delete_alerts.php,
godmode/massive/massive_edit_modules.php,
godmode/massive/massive_standby_alerts.php,
godmode/massive/massive_add_action_alerts.php: now in the source code pick
more info in the audit for actions.
Pending tasks: #3089687
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@3480 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2010-10-29 14:35:34 +02:00
pandora_audit ( " Extension DB inface " , " Error in SQL " , false , false , $sql );
2009-05-04 15:11:16 +02:00
return ;
}
if ( ! is_array ( $result )) {
echo " <strong>Output: <strong> " . $result ;
2010-10-29 Miguel de Dios <miguel.dedios@artica.es>
* extensions/dbmanager.php, godmode/agentes/module_manager_editor.php,
godmode/massive/massive_add_alerts.php,
godmode/massive/massive_copy_modules.php,
godmode/massive/massive_delete_agents.php,
godmode/massive/massive_enable_disable_alerts.php,
godmode/massive/massive_operations.php,
godmode/massive/massive_delete_profiles.php,
godmode/massive/massive_edit_agents.php,
godmode/massive/massive_delete_action_alerts.php,
godmode/massive/massive_delete_modules.php,
godmode/massive/massive_add_profiles.php,
godmode/massive/massive_delete_alerts.php,
godmode/massive/massive_edit_modules.php,
godmode/massive/massive_standby_alerts.php,
godmode/massive/massive_add_action_alerts.php: now in the source code pick
more info in the audit for actions.
Pending tasks: #3089687
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@3480 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2010-10-29 14:35:34 +02:00
pandora_audit ( " Extension DB inface " , " SQL " , false , false , $sql );
2009-05-04 15:11:16 +02:00
return ;
}
$table -> width = '90%' ;
$table -> class = 'dbmanager' ;
$table -> head = array_keys ( $result [ 0 ]);
$table -> data = $result ;
print_table ( $table );
2009-05-01 17:01:52 +02:00
}
/* This adds a option in the operation menu */
2009-12-27 22:50:32 +01:00
add_godmode_menu_option ( __ ( 'DB interface' ), 'PM' , 'gdbman' , " dbmanager/icon.png " );
2009-05-01 17:01:52 +02:00
/* This sets the function to be called when the extension is selected in the operation menu */
add_extension_godmode_function ( 'dbmgr_extension_main' );
?>