'', 'label' => __('Extensions'), ], ] ); if (is_metaconsole() === true) { $img = '../../images/warning_modern.png'; } else { $img = 'images/warning_modern.png'; } $msg = '
'.html_print_image( $img, true ); $msg .= '
'.__( 'Warning, you are accessing the database directly. You can leave the system inoperative if you run an inappropriate SQL statement' ).'
'; $warning_message = ''; if (empty($sql) === true) { echo $warning_message; } ui_print_warning_message( __( "This is an advanced extension to interface with %s database directly from WEB console using native SQL sentences. Please note that you can damage your %s installation if you don't know exactly what you are doing, this means that you can severily damage your setup using this extension. This extension is intended to be used only by experienced users with a depth knowledge of %s internals.", get_product_name(), get_product_name(), get_product_name() ) ); echo "
"; $table = new stdClass(); $table->id = 'db_interface'; $table->class = 'databox no_border filter-table-adv'; $table->width = '100%'; $table->data = []; $table->colspan = []; $table->style[0] = 'width: 30%;'; $table->style[1] = 'width: 70%;'; $table->colspan[1][0] = 2; $data[0][0] = "Some samples of usage:
SHOW STATUS;
DESCRIBE tagente
SELECT * FROM tserver
UPDATE tagente SET id_grupo = 15 WHERE nombre LIKE '%194.179%'
"; $data[0][0] = html_print_label_input_block( __('Some samples of usage:'), "
SHOW STATUS;
DESCRIBE tagente
SELECT * FROM tserver
UPDATE tagente SET id_grupo = 15 WHERE nombre LIKE '%194.179%'
" ); if (is_metaconsole() === true) { // Get the servers. \enterprise_include_once('include/functions_metaconsole.php'); $servers = \metaconsole_get_servers(); if (is_array($servers) === true) { $servers = array_reduce( $servers, function ($carry, $item) { $carry[$item['id']] = $item['server_name']; return $carry; } ); } else { $servers = []; } $data[0][1] = html_print_label_input_block( __('Select query target'), html_print_select( $servers, 'node_id', $node_id, '', __('This metaconsole'), -1, true, false, false, 'w40p', false, 'width: 40%;' ) ); } $data[1][0] = html_print_textarea( 'sql', 3, 50, html_entity_decode($sql, ENT_QUOTES), 'placeholder="'.__('Type your query here...').'"', true, 'w100p' ); $execute_button = html_print_submit_button( __('Execute SQL'), '', false, [ 'icon' => 'cog' ], true ); $table->data = $data; // html_print_table($table); html_print_action_buttons($execute_button); ui_toggle( html_print_table($table, true), ''.__('SQL query').'', __('SQL query'), 'query', false, false, '', 'white-box-content no_border', 'box-flat white_table_graph fixed_filter_bar' ); echo '
'; // Processing SQL Code. if ($sql == '') { return; } try { if (\is_metaconsole() === true && $node_id !== -1) { $node = new Node($node_id); $dbconnection = @get_dbconnection( [ 'dbhost' => $node->dbhost(), 'dbport' => $node->dbport(), 'dbname' => $node->dbname(), 'dbuser' => $node->dbuser(), 'dbpass' => io_output_password($node->dbpass()), ] ); $error = ''; $result = dbmanager_query($sql, $error, $dbconnection); } else { $dbconnection = $config['dbconnection']; $error = ''; $result = dbmanager_query($sql, $error, $dbconnection); } } catch (\Exception $e) { $error = __('Error querying database node'); $result = false; } if ($result === false) { echo 'An error has occured when querying the database.
'; echo $error; db_pandora_audit( AUDIT_LOG_SYSTEM, 'DB Interface Extension. Error in SQL', false, false, $sql ); return; } if (is_array($result) === false) { echo 'Output: '.$result; db_pandora_audit( AUDIT_LOG_SYSTEM, 'DB Interface Extension. SQL', false, false, $sql ); return; } echo "
"; $table = new stdClass(); $table->width = '100%'; $table->class = 'info_table'; $table->head = array_keys($result[0]); $table->data = $result; html_print_table($table); echo '
'; } if (is_metaconsole() === true) { // This adds a option in the operation menu. extensions_add_meta_menu_option( __('DB interface'), 'PM', 'gextensions', 'database.png', 'v1r1' ); extensions_add_meta_function('dbmgr_extension_main'); } // This adds a option in the operation menu. extensions_add_godmode_menu_option(__('DB interface'), 'PM', 'gextensions', 'dbmanager/icon.png', 'v1r1', 'gdbman'); // This sets the function to be called when the extension is selected in the operation menu. extensions_add_godmode_function('dbmgr_extension_main');