From 5bf66662a9bdd62c5bccab15e607cd95cfb8fcab Mon Sep 17 00:00:00 2001 From: Charles Cabergs Date: Mon, 27 Jul 2020 10:05:23 +0200 Subject: Removed wordpress and phpmyadmin, my server doesn't handle it well and it brings shame on my familly --- srcs/phpmyadmin/libraries/classes/Rte/Events.php | 680 -------- srcs/phpmyadmin/libraries/classes/Rte/Export.php | 168 -- srcs/phpmyadmin/libraries/classes/Rte/Footer.php | 160 -- srcs/phpmyadmin/libraries/classes/Rte/General.php | 118 -- srcs/phpmyadmin/libraries/classes/Rte/Routines.php | 1743 -------------------- srcs/phpmyadmin/libraries/classes/Rte/RteList.php | 518 ------ srcs/phpmyadmin/libraries/classes/Rte/Triggers.php | 527 ------ srcs/phpmyadmin/libraries/classes/Rte/Words.php | 89 - 8 files changed, 4003 deletions(-) delete mode 100644 srcs/phpmyadmin/libraries/classes/Rte/Events.php delete mode 100644 srcs/phpmyadmin/libraries/classes/Rte/Export.php delete mode 100644 srcs/phpmyadmin/libraries/classes/Rte/Footer.php delete mode 100644 srcs/phpmyadmin/libraries/classes/Rte/General.php delete mode 100644 srcs/phpmyadmin/libraries/classes/Rte/Routines.php delete mode 100644 srcs/phpmyadmin/libraries/classes/Rte/RteList.php delete mode 100644 srcs/phpmyadmin/libraries/classes/Rte/Triggers.php delete mode 100644 srcs/phpmyadmin/libraries/classes/Rte/Words.php (limited to 'srcs/phpmyadmin/libraries/classes/Rte') diff --git a/srcs/phpmyadmin/libraries/classes/Rte/Events.php b/srcs/phpmyadmin/libraries/classes/Rte/Events.php deleted file mode 100644 index bb0d52b..0000000 --- a/srcs/phpmyadmin/libraries/classes/Rte/Events.php +++ /dev/null @@ -1,680 +0,0 @@ -dbi = $dbi; - $this->export = new Export($this->dbi); - $this->footer = new Footer($this->dbi); - $this->general = new General($this->dbi); - $this->rteList = new RteList($this->dbi); - $this->words = new Words(); - } - - /** - * Sets required globals - * - * @return void - */ - public function setGlobals() - { - global $event_status, $event_type, $event_interval; - - $event_status = [ - 'query' => [ - 'ENABLE', - 'DISABLE', - 'DISABLE ON SLAVE', - ], - 'display' => [ - 'ENABLED', - 'DISABLED', - 'SLAVESIDE_DISABLED', - ], - ]; - $event_type = [ - 'RECURRING', - 'ONE TIME', - ]; - $event_interval = [ - 'YEAR', - 'QUARTER', - 'MONTH', - 'DAY', - 'HOUR', - 'MINUTE', - 'WEEK', - 'SECOND', - 'YEAR_MONTH', - 'DAY_HOUR', - 'DAY_MINUTE', - 'DAY_SECOND', - 'HOUR_MINUTE', - 'HOUR_SECOND', - 'MINUTE_SECOND', - ]; - } - - /** - * Main function for the events functionality - * - * @return void - */ - public function main() - { - global $db; - - $this->setGlobals(); - /** - * Process all requests - */ - $this->handleEditor(); - $this->export->events(); - /** - * Display a list of available events - */ - $items = $this->dbi->getEvents($db); - echo $this->rteList->get('event', $items); - /** - * Display a link for adding a new event, if - * the user has the privileges and a link to - * toggle the state of the event scheduler. - */ - echo $this->footer->events(); - } - - /** - * Handles editor requests for adding or editing an item - * - * @return void - */ - public function handleEditor() - { - global $errors, $db; - - if (! empty($_POST['editor_process_add']) - || ! empty($_POST['editor_process_edit']) - ) { - $sql_query = ''; - - $item_query = $this->getQueryFromRequest(); - - if (! count($errors)) { // set by PhpMyAdmin\Rte\Routines::getQueryFromRequest() - // Execute the created query - if (! empty($_POST['editor_process_edit'])) { - // Backup the old trigger, in case something goes wrong - $create_item = $this->dbi->getDefinition( - $db, - 'EVENT', - $_POST['item_original_name'] - ); - $drop_item = "DROP EVENT " - . Util::backquote($_POST['item_original_name']) - . ";\n"; - $result = $this->dbi->tryQuery($drop_item); - if (! $result) { - $errors[] = sprintf( - __('The following query has failed: "%s"'), - htmlspecialchars($drop_item) - ) - . '
' - . __('MySQL said: ') . $this->dbi->getError(); - } else { - $result = $this->dbi->tryQuery($item_query); - if (! $result) { - $errors[] = sprintf( - __('The following query has failed: "%s"'), - htmlspecialchars($item_query) - ) - . '
' - . __('MySQL said: ') . $this->dbi->getError(); - // We dropped the old item, but were unable to create - // the new one. Try to restore the backup query - $result = $this->dbi->tryQuery($create_item); - $errors = $this->general->checkResult( - $result, - __( - 'Sorry, we failed to restore the dropped event.' - ), - $create_item, - $errors - ); - } else { - $message = Message::success( - __('Event %1$s has been modified.') - ); - $message->addParam( - Util::backquote($_POST['item_name']) - ); - $sql_query = $drop_item . $item_query; - } - } - } else { - // 'Add a new item' mode - $result = $this->dbi->tryQuery($item_query); - if (! $result) { - $errors[] = sprintf( - __('The following query has failed: "%s"'), - htmlspecialchars($item_query) - ) - . '

' - . __('MySQL said: ') . $this->dbi->getError(); - } else { - $message = Message::success( - __('Event %1$s has been created.') - ); - $message->addParam( - Util::backquote($_POST['item_name']) - ); - $sql_query = $item_query; - } - } - } - - if (count($errors)) { - $message = Message::error( - '' - . __( - 'One or more errors have occurred while processing your request:' - ) - . '' - ); - $message->addHtml(''); - } - - $output = Util::getMessage($message, $sql_query); - $response = Response::getInstance(); - if ($response->isAjax()) { - if ($message->isSuccess()) { - $events = $this->dbi->getEvents($db, $_POST['item_name']); - $event = $events[0]; - $response->addJSON( - 'name', - htmlspecialchars( - mb_strtoupper($_POST['item_name']) - ) - ); - if (! empty($event)) { - $response->addJSON('new_row', $this->rteList->getEventRow($event)); - } - $response->addJSON('insert', ! empty($event)); - $response->addJSON('message', $output); - } else { - $response->setRequestStatus(false); - $response->addJSON('message', $message); - } - exit; - } - } - /** - * Display a form used to add/edit a trigger, if necessary - */ - if (count($errors) - || (empty($_POST['editor_process_add']) - && empty($_POST['editor_process_edit']) - && (! empty($_REQUEST['add_item']) - || ! empty($_REQUEST['edit_item']) - || ! empty($_POST['item_changetype']))) - ) { // FIXME: this must be simpler than that - $operation = ''; - if (! empty($_POST['item_changetype'])) { - $operation = 'change'; - } - // Get the data for the form (if any) - if (! empty($_REQUEST['add_item'])) { - $title = $this->words->get('add'); - $item = $this->getDataFromRequest(); - $mode = 'add'; - } elseif (! empty($_REQUEST['edit_item'])) { - $title = __("Edit event"); - if (! empty($_REQUEST['item_name']) - && empty($_POST['editor_process_edit']) - && empty($_POST['item_changetype']) - ) { - $item = $this->getDataFromName($_REQUEST['item_name']); - if ($item !== false) { - $item['item_original_name'] = $item['item_name']; - } - } else { - $item = $this->getDataFromRequest(); - } - $mode = 'edit'; - } - $this->general->sendEditor('EVN', $mode, $item, $title, $db, $operation); - } - } - - /** - * This function will generate the values that are required to for the editor - * - * @return array Data necessary to create the editor. - */ - public function getDataFromRequest() - { - $retval = []; - $indices = [ - 'item_name', - 'item_original_name', - 'item_status', - 'item_execute_at', - 'item_interval_value', - 'item_interval_field', - 'item_starts', - 'item_ends', - 'item_definition', - 'item_preserve', - 'item_comment', - 'item_definer', - ]; - foreach ($indices as $index) { - $retval[$index] = isset($_POST[$index]) ? $_POST[$index] : ''; - } - $retval['item_type'] = 'ONE TIME'; - $retval['item_type_toggle'] = 'RECURRING'; - if (isset($_POST['item_type']) && $_POST['item_type'] == 'RECURRING') { - $retval['item_type'] = 'RECURRING'; - $retval['item_type_toggle'] = 'ONE TIME'; - } - return $retval; - } - - /** - * This function will generate the values that are required to complete - * the "Edit event" form given the name of a event. - * - * @param string $name The name of the event. - * - * @return array|bool Data necessary to create the editor. - */ - public function getDataFromName($name) - { - global $db; - - $retval = []; - $columns = "`EVENT_NAME`, `STATUS`, `EVENT_TYPE`, `EXECUTE_AT`, " - . "`INTERVAL_VALUE`, `INTERVAL_FIELD`, `STARTS`, `ENDS`, " - . "`EVENT_DEFINITION`, `ON_COMPLETION`, `DEFINER`, `EVENT_COMMENT`"; - $where = "EVENT_SCHEMA " . Util::getCollateForIS() . "=" - . "'" . $this->dbi->escapeString($db) . "' " - . "AND EVENT_NAME='" . $this->dbi->escapeString($name) . "'"; - $query = "SELECT $columns FROM `INFORMATION_SCHEMA`.`EVENTS` WHERE $where;"; - $item = $this->dbi->fetchSingleRow($query); - if (! $item) { - return false; - } - $retval['item_name'] = $item['EVENT_NAME']; - $retval['item_status'] = $item['STATUS']; - $retval['item_type'] = $item['EVENT_TYPE']; - if ($retval['item_type'] == 'RECURRING') { - $retval['item_type_toggle'] = 'ONE TIME'; - } else { - $retval['item_type_toggle'] = 'RECURRING'; - } - $retval['item_execute_at'] = $item['EXECUTE_AT']; - $retval['item_interval_value'] = $item['INTERVAL_VALUE']; - $retval['item_interval_field'] = $item['INTERVAL_FIELD']; - $retval['item_starts'] = $item['STARTS']; - $retval['item_ends'] = $item['ENDS']; - $retval['item_preserve'] = ''; - if ($item['ON_COMPLETION'] == 'PRESERVE') { - $retval['item_preserve'] = " checked='checked'"; - } - $retval['item_definition'] = $item['EVENT_DEFINITION']; - $retval['item_definer'] = $item['DEFINER']; - $retval['item_comment'] = $item['EVENT_COMMENT']; - - return $retval; - } - - /** - * Displays a form used to add/edit an event - * - * @param string $mode If the editor will be used to edit an event - * or add a new one: 'edit' or 'add'. - * @param string $operation If the editor was previously invoked with - * JS turned off, this will hold the name of - * the current operation - * @param array $item Data for the event returned by - * getDataFromRequest() or getDataFromName() - * - * @return string HTML code for the editor. - */ - public function getEditorForm($mode, $operation, array $item) - { - global $db, $table, $event_status, $event_type, $event_interval; - - $modeToUpper = mb_strtoupper($mode); - - $response = Response::getInstance(); - - // Escape special characters - $need_escape = [ - 'item_original_name', - 'item_name', - 'item_type', - 'item_execute_at', - 'item_interval_value', - 'item_starts', - 'item_ends', - 'item_definition', - 'item_definer', - 'item_comment', - ]; - foreach ($need_escape as $index) { - $item[$index] = htmlentities((string) $item[$index], ENT_QUOTES); - } - $original_data = ''; - if ($mode == 'edit') { - $original_data = "\n"; - } - // Handle some logic first - if ($operation == 'change') { - if ($item['item_type'] == 'RECURRING') { - $item['item_type'] = 'ONE TIME'; - $item['item_type_toggle'] = 'RECURRING'; - } else { - $item['item_type'] = 'RECURRING'; - $item['item_type_toggle'] = 'ONE TIME'; - } - } - if ($item['item_type'] == 'ONE TIME') { - $isrecurring_class = ' hide'; - $isonetime_class = ''; - } else { - $isrecurring_class = ''; - $isonetime_class = ' hide'; - } - // Create the output - $retval = ""; - $retval .= "\n\n"; - $retval .= "
\n"; - $retval .= "\n"; - $retval .= $original_data; - $retval .= Url::getHiddenInputs($db, $table) . "\n"; - $retval .= "
\n"; - $retval .= "" . __('Details') . "\n"; - $retval .= "\n"; - $retval .= "\n"; - $retval .= " \n"; - $retval .= " \n"; - $retval .= "\n"; - - $retval .= "\n"; - $retval .= " \n"; - $retval .= " \n"; - $retval .= "\n"; - $retval .= "\n"; - $retval .= " \n"; - $retval .= " \n"; - $retval .= "\n"; - $retval .= "\n"; - $retval .= " \n"; - $retval .= "
" . __('Event name') . "\n"; - $retval .= " \n"; - $retval .= " \n"; - $retval .= "
" . __('Event type') . "\n"; - if ($response->isAjax()) { - $retval .= " \n"; - } else { - $retval .= " \n"; - $retval .= " \n"; - $retval .= " \n"; - $retval .= " \n"; - $retval .= " $value) { - $selected = ""; - if (! empty($item['item_interval_field']) - && $item['item_interval_field'] == $value - ) { - $selected = " selected='selected'"; - } - $retval .= "$value"; - } - $retval .= " \n"; - $retval .= "
" . _pgettext('Start of recurring event', 'Start'); - $retval .= " \n"; - $retval .= " \n"; - $retval .= " \n"; - $retval .= " \n"; - $retval .= "
" . __('On completion preserve') . "\n"; - $retval .= " \n"; - $retval .= " isAjax()) { - $retval .= "\n"; - $retval .= "\n"; - } - $retval .= "\n\n"; - $retval .= "\n\n"; - - return $retval; - } - - /** - * Composes the query necessary to create an event from an HTTP request. - * - * @return string The CREATE EVENT query. - */ - public function getQueryFromRequest() - { - global $errors, $event_status, $event_type, $event_interval; - - $query = 'CREATE '; - if (! empty($_POST['item_definer'])) { - if (mb_strpos($_POST['item_definer'], '@') !== false - ) { - $arr = explode('@', $_POST['item_definer']); - $query .= 'DEFINER=' . Util::backquote($arr[0]); - $query .= '@' . Util::backquote($arr[1]) . ' '; - } else { - $errors[] = __('The definer must be in the "username@hostname" format!'); - } - } - $query .= 'EVENT '; - if (! empty($_POST['item_name'])) { - $query .= Util::backquote($_POST['item_name']) . ' '; - } else { - $errors[] = __('You must provide an event name!'); - } - $query .= 'ON SCHEDULE '; - if (! empty($_POST['item_type']) - && in_array($_POST['item_type'], $event_type) - ) { - if ($_POST['item_type'] == 'RECURRING') { - if (! empty($_POST['item_interval_value']) - && ! empty($_POST['item_interval_field']) - && in_array($_POST['item_interval_field'], $event_interval) - ) { - $query .= 'EVERY ' . intval($_POST['item_interval_value']) . ' '; - $query .= $_POST['item_interval_field'] . ' '; - } else { - $errors[] - = __('You must provide a valid interval value for the event.'); - } - if (! empty($_POST['item_starts'])) { - $query .= "STARTS '" - . $this->dbi->escapeString($_POST['item_starts']) - . "' "; - } - if (! empty($_POST['item_ends'])) { - $query .= "ENDS '" - . $this->dbi->escapeString($_POST['item_ends']) - . "' "; - } - } else { - if (! empty($_POST['item_execute_at'])) { - $query .= "AT '" - . $this->dbi->escapeString($_POST['item_execute_at']) - . "' "; - } else { - $errors[] - = __('You must provide a valid execution time for the event.'); - } - } - } else { - $errors[] = __('You must provide a valid type for the event.'); - } - $query .= 'ON COMPLETION '; - if (empty($_POST['item_preserve'])) { - $query .= 'NOT '; - } - $query .= 'PRESERVE '; - if (! empty($_POST['item_status'])) { - foreach ($event_status['display'] as $key => $value) { - if ($value == $_POST['item_status']) { - $query .= $event_status['query'][$key] . ' '; - break; - } - } - } - if (! empty($_POST['item_comment'])) { - $query .= "COMMENT '" . $this->dbi->escapeString( - $_POST['item_comment'] - ) . "' "; - } - $query .= 'DO '; - if (! empty($_POST['item_definition'])) { - $query .= $_POST['item_definition']; - } else { - $errors[] = __('You must provide an event definition.'); - } - - return $query; - } -} diff --git a/srcs/phpmyadmin/libraries/classes/Rte/Export.php b/srcs/phpmyadmin/libraries/classes/Rte/Export.php deleted file mode 100644 index 2ae19e6..0000000 --- a/srcs/phpmyadmin/libraries/classes/Rte/Export.php +++ /dev/null @@ -1,168 +0,0 @@ -dbi = $dbi; - $this->words = new Words(); - } - - /** - * This function is called from one of the other functions in this file - * and it completes the handling of the export functionality. - * - * @param string $export_data The SQL query to create the requested item - * - * @return void - */ - private function handle($export_data) - { - global $db; - - $response = Response::getInstance(); - - $item_name = htmlspecialchars(Util::backquote($_GET['item_name'])); - if ($export_data !== false) { - $export_data = htmlspecialchars(trim($export_data)); - $title = sprintf($this->words->get('export'), $item_name); - if ($response->isAjax()) { - $response->addJSON('message', $export_data); - $response->addJSON('title', $title); - exit; - } else { - $export_data = ''; - echo "
\n" - , "$title\n" - , $export_data - , "
\n"; - } - } else { - $_db = htmlspecialchars(Util::backquote($db)); - $message = __('Error in processing request:') . ' ' - . sprintf($this->words->get('no_view'), $item_name, $_db); - $message = Message::error($message); - - if ($response->isAjax()) { - $response->setRequestStatus(false); - $response->addJSON('message', $message); - exit; - } else { - $message->display(); - } - } - } - - /** - * If necessary, prepares event information and passes - * it to handle() for the actual export. - * - * @return void - */ - public function events() - { - global $db; - - if (! empty($_GET['export_item']) && ! empty($_GET['item_name'])) { - $item_name = $_GET['item_name']; - $export_data = $this->dbi->getDefinition($db, 'EVENT', $item_name); - if (! $export_data) { - $export_data = false; - } - $this->handle($export_data); - } - } - - /** - * If necessary, prepares routine information and passes - * it to handle() for the actual export. - * - * @return void - */ - public function routines() - { - global $db; - - if (! empty($_GET['export_item']) - && ! empty($_GET['item_name']) - && ! empty($_GET['item_type']) - ) { - if ($_GET['item_type'] == 'FUNCTION' || $_GET['item_type'] == 'PROCEDURE') { - $rtn_definition - = $this->dbi->getDefinition( - $db, - $_GET['item_type'], - $_GET['item_name'] - ); - if ($rtn_definition === null) { - $export_data = false; - } else { - $export_data = "DELIMITER $$\n" - . $rtn_definition - . "$$\nDELIMITER ;\n"; - } - - $this->handle($export_data); - } - } - } - - /** - * If necessary, prepares trigger information and passes - * it to handle() for the actual export. - * - * @return void - */ - public function triggers() - { - global $db, $table; - - if (! empty($_GET['export_item']) && ! empty($_GET['item_name'])) { - $item_name = $_GET['item_name']; - $triggers = $this->dbi->getTriggers($db, $table, ''); - $export_data = false; - foreach ($triggers as $trigger) { - if ($trigger['name'] === $item_name) { - $export_data = $trigger['create']; - break; - } - } - $this->handle($export_data); - } - } -} diff --git a/srcs/phpmyadmin/libraries/classes/Rte/Footer.php b/srcs/phpmyadmin/libraries/classes/Rte/Footer.php deleted file mode 100644 index 5181b00..0000000 --- a/srcs/phpmyadmin/libraries/classes/Rte/Footer.php +++ /dev/null @@ -1,160 +0,0 @@ -dbi = $dbi; - $this->words = new Words(); - } - - /** - * Creates a fieldset for adding a new item, if the user has the privileges. - * - * @param string $docu String used to create a link to the MySQL docs - * @param string $priv Privilege to check for adding a new item - * @param string $name MySQL name of the item - * - * @return string An HTML snippet with the link to add a new item - */ - private function getLinks($docu, $priv, $name) - { - global $db, $table, $url_query; - - $icon = mb_strtolower($name) . '_add'; - $retval = ""; - $retval .= "\n"; - $retval .= "
\n"; - $retval .= "" . _pgettext('Create new procedure', 'New') . "\n"; - $retval .= "
\n"; - if (Util::currentUserHasPrivilege($priv, $db, $table)) { - $retval .= ' words->get('add') . "\n"; - } else { - $icon = 'bd_' . $icon; - $retval .= Util::getIcon($icon); - $retval .= $this->words->get('add') . "\n"; - } - $retval .= " " . Util::showMySQLDocu($docu) . "\n"; - $retval .= "
\n"; - $retval .= "
\n"; - $retval .= "\n\n"; - - return $retval; - } - - /** - * Creates a fieldset for adding a new routine, if the user has the privileges. - * - * @return string HTML code with containing the footer fieldset - */ - public function routines() - { - return $this->getLinks('CREATE_PROCEDURE', 'CREATE ROUTINE', 'ROUTINE'); - } - - /** - * Creates a fieldset for adding a new trigger, if the user has the privileges. - * - * @return string HTML code with containing the footer fieldset - */ - public function triggers() - { - return $this->getLinks('CREATE_TRIGGER', 'TRIGGER', 'TRIGGER'); - } - - /** - * Creates a fieldset for adding a new event, if the user has the privileges. - * - * @return string HTML code with containing the footer fieldset - */ - public function events() - { - global $db, $url_query; - - /** - * For events, we show the usual 'Add event' form and also - * a form for toggling the state of the event scheduler - */ - // Init options for the event scheduler toggle functionality - $es_state = $this->dbi->fetchValue( - "SHOW GLOBAL VARIABLES LIKE 'event_scheduler'", - 0, - 1 - ); - $es_state = mb_strtolower($es_state); - $options = [ - 0 => [ - 'label' => __('OFF'), - 'value' => "SET GLOBAL event_scheduler=\"OFF\"", - 'selected' => $es_state != 'on', - ], - 1 => [ - 'label' => __('ON'), - 'value' => "SET GLOBAL event_scheduler=\"ON\"", - 'selected' => $es_state == 'on', - ], - ]; - // Generate output - $retval = "\n"; - $retval .= "
\n"; - // show the usual footer - $retval .= $this->getLinks('CREATE_EVENT', 'EVENT', 'EVENT'); - $retval .= "
\n"; - $retval .= " \n"; - $retval .= " " . __('Event scheduler status') . "\n"; - $retval .= " \n"; - $retval .= "
\n"; - // show the toggle button - $retval .= Util::toggleButton( - "sql.php$url_query&goto=db_events.php" . urlencode("?db=$db"), - 'sql_query', - $options, - 'Functions.slidingMessage(data.sql_query);' - ); - $retval .= "
\n"; - $retval .= "
\n"; - $retval .= "
\n"; - $retval .= "
"; - $retval .= "\n"; - - return $retval; - } -} diff --git a/srcs/phpmyadmin/libraries/classes/Rte/General.php b/srcs/phpmyadmin/libraries/classes/Rte/General.php deleted file mode 100644 index 37962b5..0000000 --- a/srcs/phpmyadmin/libraries/classes/Rte/General.php +++ /dev/null @@ -1,118 +0,0 @@ -dbi = $dbi; - } - - /** - * Check result - * - * @param resource|bool $result Query result - * @param string $error Error to add - * @param string $createStatement Query - * @param array $errors Errors - * - * @return array - */ - public function checkResult($result, $error, $createStatement, array $errors) - { - if ($result) { - return $errors; - } - - // OMG, this is really bad! We dropped the query, - // failed to create a new one - // and now even the backup query does not execute! - // This should not happen, but we better handle - // this just in case. - $errors[] = $error . '
' - . __('The backed up query was:') - . "\"" . htmlspecialchars($createStatement) . "\"" . '
' - . __('MySQL said: ') . $this->dbi->getError(); - - return $errors; - } - - /** - * Send TRI or EVN editor via ajax or by echoing. - * - * @param string $type TRI or EVN - * @param string $mode Editor mode 'add' or 'edit' - * @param array $item Data necessary to create the editor - * @param string $title Title of the editor - * @param string $db Database - * @param string $operation Operation 'change' or '' - * - * @return void - */ - public function sendEditor($type, $mode, array $item, $title, $db, $operation = null) - { - $events = new Events($this->dbi); - $triggers = new Triggers($this->dbi); - $words = new Words(); - $response = Response::getInstance(); - if ($item !== false) { - // Show form - if ($type == 'TRI') { - $editor = $triggers->getEditorForm($mode, $item); - } else { // EVN - $editor = $events->getEditorForm($mode, $operation, $item); - } - if ($response->isAjax()) { - $response->addJSON('message', $editor); - $response->addJSON('title', $title); - } else { - echo "\n\n

$title

\n\n$editor"; - unset($_POST); - } - exit; - } else { - $message = __('Error in processing request:') . ' '; - $message .= sprintf( - $words->get('not_found'), - htmlspecialchars(Util::backquote($_REQUEST['item_name'])), - htmlspecialchars(Util::backquote($db)) - ); - $message = Message::error($message); - if ($response->isAjax()) { - $response->setRequestStatus(false); - $response->addJSON('message', $message); - exit; - } else { - $message->display(); - } - } - } -} diff --git a/srcs/phpmyadmin/libraries/classes/Rte/Routines.php b/srcs/phpmyadmin/libraries/classes/Rte/Routines.php deleted file mode 100644 index 24b0dd5..0000000 --- a/srcs/phpmyadmin/libraries/classes/Rte/Routines.php +++ /dev/null @@ -1,1743 +0,0 @@ -dbi = $dbi; - $this->export = new Export($this->dbi); - $this->footer = new Footer($this->dbi); - $this->general = new General($this->dbi); - $this->rteList = new RteList($this->dbi); - $this->words = new Words(); - } - - /** - * Sets required globals - * - * @return void - */ - public function setGlobals() - { - global $param_directions, $param_opts_num, $param_sqldataaccess; - - $param_directions = [ - 'IN', - 'OUT', - 'INOUT', - ]; - $param_opts_num = [ - 'UNSIGNED', - 'ZEROFILL', - 'UNSIGNED ZEROFILL', - ]; - $param_sqldataaccess = [ - 'NO SQL', - 'CONTAINS SQL', - 'READS SQL DATA', - 'MODIFIES SQL DATA', - ]; - } - - /** - * Main function for the routines functionality - * - * @param string $type 'FUNCTION' for functions, - * 'PROCEDURE' for procedures, - * null for both - * - * @return void - */ - public function main($type) - { - global $db; - - $this->setGlobals(); - /** - * Process all requests - */ - $this->handleEditor(); - $this->handleExecute(); - $this->export->routines(); - /** - * Display a list of available routines - */ - if (! Core::isValid($type, ['FUNCTION', 'PROCEDURE'])) { - $type = null; - } - $items = $this->dbi->getRoutines($db, $type); - echo $this->rteList->get('routine', $items); - /** - * Display the form for adding a new routine, if the user has the privileges. - */ - echo $this->footer->routines(); - /** - * Display a warning for users with PHP's old "mysql" extension. - */ - if (! DatabaseInterface::checkDbExtension('mysqli')) { - trigger_error( - __( - 'You are using PHP\'s deprecated \'mysql\' extension, ' - . 'which is not capable of handling multi queries. ' - . '[strong]The execution of some stored routines may fail![/strong] ' - . 'Please use the improved \'mysqli\' extension to ' - . 'avoid any problems.' - ), - E_USER_WARNING - ); - } - } - - /** - * Handles editor requests for adding or editing an item - * - * @return void - */ - public function handleEditor() - { - global $db, $errors; - - $errors = $this->handleRequestCreateOrEdit($errors, $db); - $response = Response::getInstance(); - - /** - * Display a form used to add/edit a routine, if necessary - */ - // FIXME: this must be simpler than that - if (count($errors) - || ( empty($_POST['editor_process_add']) - && empty($_POST['editor_process_edit']) - && (! empty($_REQUEST['add_item']) || ! empty($_REQUEST['edit_item']) - || ! empty($_POST['routine_addparameter']) - || ! empty($_POST['routine_removeparameter']) - || ! empty($_POST['routine_changetype']))) - ) { - // Handle requests to add/remove parameters and changing routine type - // This is necessary when JS is disabled - $operation = ''; - if (! empty($_POST['routine_addparameter'])) { - $operation = 'add'; - } elseif (! empty($_POST['routine_removeparameter'])) { - $operation = 'remove'; - } elseif (! empty($_POST['routine_changetype'])) { - $operation = 'change'; - } - // Get the data for the form (if any) - if (! empty($_REQUEST['add_item'])) { - $title = $this->words->get('add'); - $routine = $this->getDataFromRequest(); - $mode = 'add'; - } elseif (! empty($_REQUEST['edit_item'])) { - $title = __("Edit routine"); - if (! $operation && ! empty($_GET['item_name']) - && empty($_POST['editor_process_edit']) - ) { - $routine = $this->getDataFromName( - $_GET['item_name'], - $_GET['item_type'] - ); - if ($routine !== false) { - $routine['item_original_name'] = $routine['item_name']; - $routine['item_original_type'] = $routine['item_type']; - } - } else { - $routine = $this->getDataFromRequest(); - } - $mode = 'edit'; - } - if ($routine !== false) { - // Show form - $editor = $this->getEditorForm($mode, $operation, $routine); - if ($response->isAjax()) { - $response->addJSON('message', $editor); - $response->addJSON('title', $title); - $response->addJSON('paramTemplate', $this->getParameterRow()); - $response->addJSON('type', $routine['item_type']); - } else { - echo "\n\n

$title

\n\n$editor"; - } - exit; - } else { - $message = __('Error in processing request:') . ' '; - $message .= sprintf( - $this->words->get('no_edit'), - htmlspecialchars( - Util::backquote($_REQUEST['item_name']) - ), - htmlspecialchars(Util::backquote($db)) - ); - - $message = Message::error($message); - if ($response->isAjax()) { - $response->setRequestStatus(false); - $response->addJSON('message', $message); - exit; - } else { - $message->display(); - } - } - } - } - - /** - * Handle request to create or edit a routine - * - * @param array $errors Errors - * @param string $db DB name - * - * @return array - */ - public function handleRequestCreateOrEdit(array $errors, $db) - { - if (empty($_POST['editor_process_add']) - && empty($_POST['editor_process_edit']) - ) { - return $errors; - } - - $sql_query = ''; - $routine_query = $this->getQueryFromRequest(); - if (! count($errors)) { - // Execute the created query - if (! empty($_POST['editor_process_edit'])) { - $isProcOrFunc = in_array( - $_POST['item_original_type'], - [ - 'PROCEDURE', - 'FUNCTION', - ] - ); - - if (! $isProcOrFunc) { - $errors[] = sprintf( - __('Invalid routine type: "%s"'), - htmlspecialchars($_POST['item_original_type']) - ); - } else { - // Backup the old routine, in case something goes wrong - $create_routine = $this->dbi->getDefinition( - $db, - $_POST['item_original_type'], - $_POST['item_original_name'] - ); - - $privilegesBackup = $this->backupPrivileges(); - - $drop_routine = "DROP {$_POST['item_original_type']} " - . Util::backquote($_POST['item_original_name']) - . ";\n"; - $result = $this->dbi->tryQuery($drop_routine); - if (! $result) { - $errors[] = sprintf( - __('The following query has failed: "%s"'), - htmlspecialchars($drop_routine) - ) - . '
' - . __('MySQL said: ') . $this->dbi->getError(); - } else { - list($newErrors, $message) = $this->create( - $routine_query, - $create_routine, - $privilegesBackup - ); - if (empty($newErrors)) { - $sql_query = $drop_routine . $routine_query; - } else { - $errors = array_merge($errors, $newErrors); - } - unset($newErrors); - if (null === $message) { - unset($message); - } - } - } - } else { - // 'Add a new routine' mode - $result = $this->dbi->tryQuery($routine_query); - if (! $result) { - $errors[] = sprintf( - __('The following query has failed: "%s"'), - htmlspecialchars($routine_query) - ) - . '

' - . __('MySQL said: ') . $this->dbi->getError(); - } else { - $message = Message::success( - __('Routine %1$s has been created.') - ); - $message->addParam( - Util::backquote($_POST['item_name']) - ); - $sql_query = $routine_query; - } - } - } - - if (count($errors)) { - $message = Message::error( - __( - 'One or more errors have occurred while' - . ' processing your request:' - ) - ); - $message->addHtml('
    '); - foreach ($errors as $string) { - $message->addHtml('
  • ' . $string . '
  • '); - } - $message->addHtml('
'); - } - - $output = Util::getMessage($message, $sql_query); - $response = Response::getInstance(); - if (! $response->isAjax()) { - return $errors; - } - - if (! $message->isSuccess()) { - $response->setRequestStatus(false); - $response->addJSON('message', $output); - exit; - } - - $routines = $this->dbi->getRoutines( - $db, - $_POST['item_type'], - $_POST['item_name'] - ); - $routine = $routines[0]; - $response->addJSON( - 'name', - htmlspecialchars( - mb_strtoupper($_POST['item_name']) - ) - ); - $response->addJSON('new_row', $this->rteList->getRoutineRow($routine)); - $response->addJSON('insert', ! empty($routine)); - $response->addJSON('message', $output); - exit; - } - - /** - * Backup the privileges - * - * @return array - */ - public function backupPrivileges() - { - if (! $GLOBALS['proc_priv'] || ! $GLOBALS['is_reload_priv']) { - return []; - } - - // Backup the Old Privileges before dropping - // if $_POST['item_adjust_privileges'] set - if (! isset($_POST['item_adjust_privileges']) - || empty($_POST['item_adjust_privileges']) - ) { - return []; - } - - $privilegesBackupQuery = 'SELECT * FROM ' . Util::backquote( - 'mysql' - ) - . '.' . Util::backquote('procs_priv') - . ' where Routine_name = "' . $_POST['item_original_name'] - . '" AND Routine_type = "' . $_POST['item_original_type'] - . '";'; - - $privilegesBackup = $this->dbi->fetchResult( - $privilegesBackupQuery, - 0 - ); - - return $privilegesBackup; - } - - /** - * Create the routine - * - * @param string $routine_query Query to create routine - * @param string $create_routine Query to restore routine - * @param array $privilegesBackup Privileges backup - * - * @return array - */ - public function create( - $routine_query, - $create_routine, - array $privilegesBackup - ) { - $result = $this->dbi->tryQuery($routine_query); - if (! $result) { - $errors = []; - $errors[] = sprintf( - __('The following query has failed: "%s"'), - htmlspecialchars($routine_query) - ) - . '
' - . __('MySQL said: ') . $this->dbi->getError(); - // We dropped the old routine, - // but were unable to create the new one - // Try to restore the backup query - $result = $this->dbi->tryQuery($create_routine); - $errors = $this->general->checkResult( - $result, - __( - 'Sorry, we failed to restore' - . ' the dropped routine.' - ), - $create_routine, - $errors - ); - - return [ - $errors, - null, - ]; - } - - // Default value - $resultAdjust = false; - - if ($GLOBALS['proc_priv'] - && $GLOBALS['is_reload_priv'] - ) { - // Insert all the previous privileges - // but with the new name and the new type - foreach ($privilegesBackup as $priv) { - $adjustProcPrivilege = 'INSERT INTO ' - . Util::backquote('mysql') . '.' - . Util::backquote('procs_priv') - . ' VALUES("' . $priv[0] . '", "' - . $priv[1] . '", "' . $priv[2] . '", "' - . $_POST['item_name'] . '", "' - . $_POST['item_type'] . '", "' - . $priv[5] . '", "' - . $priv[6] . '", "' - . $priv[7] . '");'; - $resultAdjust = $this->dbi->query( - $adjustProcPrivilege - ); - } - } - - $message = $this->flushPrivileges($resultAdjust); - - return [ - [], - $message, - ]; - } - - /** - * Flush privileges and get message - * - * @param bool $flushPrivileges Flush privileges - * - * @return Message - */ - public function flushPrivileges($flushPrivileges) - { - if ($flushPrivileges) { - // Flush the Privileges - $flushPrivQuery = 'FLUSH PRIVILEGES;'; - $this->dbi->query($flushPrivQuery); - - $message = Message::success( - __( - 'Routine %1$s has been modified. Privileges have been adjusted.' - ) - ); - } else { - $message = Message::success( - __('Routine %1$s has been modified.') - ); - } - $message->addParam( - Util::backquote($_POST['item_name']) - ); - - return $message; - } - - /** - * This function will generate the values that are required to - * complete the editor form. It is especially necessary to handle - * the 'Add another parameter', 'Remove last parameter' and - * 'Change routine type' functionalities when JS is disabled. - * - * @return array Data necessary to create the routine editor. - */ - public function getDataFromRequest() - { - global $param_directions, $param_sqldataaccess; - - $retval = []; - $indices = [ - 'item_name', - 'item_original_name', - 'item_returnlength', - 'item_returnopts_num', - 'item_returnopts_text', - 'item_definition', - 'item_comment', - 'item_definer', - ]; - foreach ($indices as $index) { - $retval[$index] = isset($_POST[$index]) ? $_POST[$index] : ''; - } - - $retval['item_type'] = 'PROCEDURE'; - $retval['item_type_toggle'] = 'FUNCTION'; - if (isset($_REQUEST['item_type']) && $_REQUEST['item_type'] == 'FUNCTION') { - $retval['item_type'] = 'FUNCTION'; - $retval['item_type_toggle'] = 'PROCEDURE'; - } - $retval['item_original_type'] = 'PROCEDURE'; - if (isset($_POST['item_original_type']) - && $_POST['item_original_type'] == 'FUNCTION' - ) { - $retval['item_original_type'] = 'FUNCTION'; - } - $retval['item_num_params'] = 0; - $retval['item_param_dir'] = []; - $retval['item_param_name'] = []; - $retval['item_param_type'] = []; - $retval['item_param_length'] = []; - $retval['item_param_opts_num'] = []; - $retval['item_param_opts_text'] = []; - if (isset($_POST['item_param_name']) - && isset($_POST['item_param_type']) - && isset($_POST['item_param_length']) - && isset($_POST['item_param_opts_num']) - && isset($_POST['item_param_opts_text']) - && is_array($_POST['item_param_name']) - && is_array($_POST['item_param_type']) - && is_array($_POST['item_param_length']) - && is_array($_POST['item_param_opts_num']) - && is_array($_POST['item_param_opts_text']) - ) { - if ($_POST['item_type'] == 'PROCEDURE') { - $retval['item_param_dir'] = $_POST['item_param_dir']; - foreach ($retval['item_param_dir'] as $key => $value) { - if (! in_array($value, $param_directions, true)) { - $retval['item_param_dir'][$key] = ''; - } - } - } - $retval['item_param_name'] = $_POST['item_param_name']; - $retval['item_param_type'] = $_POST['item_param_type']; - foreach ($retval['item_param_type'] as $key => $value) { - if (! in_array($value, Util::getSupportedDatatypes(), true)) { - $retval['item_param_type'][$key] = ''; - } - } - $retval['item_param_length'] = $_POST['item_param_length']; - $retval['item_param_opts_num'] = $_POST['item_param_opts_num']; - $retval['item_param_opts_text'] = $_POST['item_param_opts_text']; - $retval['item_num_params'] = max( - count($retval['item_param_name']), - count($retval['item_param_type']), - count($retval['item_param_length']), - count($retval['item_param_opts_num']), - count($retval['item_param_opts_text']) - ); - } - $retval['item_returntype'] = ''; - if (isset($_POST['item_returntype']) - && in_array($_POST['item_returntype'], Util::getSupportedDatatypes()) - ) { - $retval['item_returntype'] = $_POST['item_returntype']; - } - - $retval['item_isdeterministic'] = ''; - if (isset($_POST['item_isdeterministic']) - && mb_strtolower($_POST['item_isdeterministic']) == 'on' - ) { - $retval['item_isdeterministic'] = " checked='checked'"; - } - $retval['item_securitytype_definer'] = ''; - $retval['item_securitytype_invoker'] = ''; - if (isset($_POST['item_securitytype'])) { - if ($_POST['item_securitytype'] === 'DEFINER') { - $retval['item_securitytype_definer'] = " selected='selected'"; - } elseif ($_POST['item_securitytype'] === 'INVOKER') { - $retval['item_securitytype_invoker'] = " selected='selected'"; - } - } - $retval['item_sqldataaccess'] = ''; - if (isset($_POST['item_sqldataaccess']) - && in_array($_POST['item_sqldataaccess'], $param_sqldataaccess, true) - ) { - $retval['item_sqldataaccess'] = $_POST['item_sqldataaccess']; - } - - return $retval; - } - - /** - * This function will generate the values that are required to complete - * the "Edit routine" form given the name of a routine. - * - * @param string $name The name of the routine. - * @param string $type Type of routine (ROUTINE|PROCEDURE) - * @param bool $all Whether to return all data or just the info about parameters. - * - * @return array|bool Data necessary to create the routine editor. - */ - public function getDataFromName($name, $type, $all = true) - { - global $db; - - $retval = []; - - // Build and execute the query - $fields = "SPECIFIC_NAME, ROUTINE_TYPE, DTD_IDENTIFIER, " - . "ROUTINE_DEFINITION, IS_DETERMINISTIC, SQL_DATA_ACCESS, " - . "ROUTINE_COMMENT, SECURITY_TYPE"; - $where = "ROUTINE_SCHEMA " . Util::getCollateForIS() . "=" - . "'" . $this->dbi->esca