'.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; } echo "
"; $table = new stdClass(); $table->id = 'db_interface'; $table->class = 'databox'; $table->width = '100%'; $table->data = []; $table->head = []; $table->colspan = []; $table->rowstyle = []; $table->colspan[0][0] = 2; $table->colspan[1][0] = 2; $table->rowspan[2][0] = 3; $table->rowclass[0] = 'notify'; $table->rowclass[3] = 'pdd_5px'; $table->rowclass[3] = 'flex-content-right'; $table->rowclass[4] = 'flex-content-right'; $data[0][0] = __( "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 are 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() ); $data[1][0] = "Some samples of usage:
SHOW STATUS;
DESCRIBE tagente
SELECT * FROM tserver
UPDATE tagente SET id_grupo = 15 WHERE nombre LIKE '%194.179%'
"; \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[2][0] = html_print_textarea( 'sql', 5, 50, html_entity_decode($sql, ENT_QUOTES), '', true ); if (is_metaconsole() === true) { $data[3][2] = html_print_input( [ 'name' => 'node_id', 'type' => 'select', 'fields' => $servers, 'selected' => $node_id, 'nothing' => __('This metaconsole'), 'nothing_value' => -1, 'return' => true, 'label' => _('Select query target'), ] ); } $data[4][2] = '
'; $data[4][2] .= html_print_submit_button( __('Execute SQL'), '', false, 'class="sub next"', true ); $data[4][2] .= '
'; $table->data = $data; html_print_table($table); echo '
'; // Processing SQL Code if ($sql == '') { return; } echo '
'; echo '
'; echo '
'; 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' => $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)) { 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()) { close_meta_frame(); } } if (is_metaconsole() === true) { // This adds a option in the operation menu. extensions_add_meta_menu_option( 'DB interface', 'PM', 'gextensions', 'database.png', 'v1r1', 'gdbman' ); extensions_add_meta_function('dbmgr_extension_main'); } else { } // 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');