One Hat Cyber Team
  • Dir : ~/usr/share/phpmyadmin/libraries/classes/Database/
  • View File Name : Triggers.php
    \n"; $retval .= "\n"; $retval .= "\n"; $retval .= ' ' . __('Definer') . "\n"; $retval .= " \n"; $retval .= "\n"; $retval .= "\n"; $retval .= "\n"; if ($this->response->isAjax()) { $retval .= "\n"; $retval .= "\n"; } $retval .= "\n\n"; $retval .= '\n\n"; return $retval; } /** * Composes the query necessary to create a trigger from an HTTP request. * * @return string The CREATE TRIGGER query. */ public function getQueryFromRequest() { global $db, $errors; $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 .= 'TRIGGER '; if (! empty($_POST['item_name'])) { $query .= Util::backquote($_POST['item_name']) . ' '; } else { $errors[] = __('You must provide a trigger name!'); } if (! empty($_POST['item_timing']) && in_array($_POST['item_timing'], $this->time) ) { $query .= $_POST['item_timing'] . ' '; } else { $errors[] = __('You must provide a valid timing for the trigger!'); } if (! empty($_POST['item_event']) && in_array($_POST['item_event'], $this->event) ) { $query .= $_POST['item_event'] . ' '; } else { $errors[] = __('You must provide a valid event for the trigger!'); } $query .= 'ON '; if (! empty($_POST['item_table']) && in_array($_POST['item_table'], $this->dbi->getTables($db)) ) { $query .= Util::backquote($_POST['item_table']); } else { $errors[] = __('You must provide a valid table name!'); } $query .= ' FOR EACH ROW '; if (! empty($_POST['item_definition'])) { $query .= $_POST['item_definition']; } else { $errors[] = __('You must provide a trigger definition.'); } return $query; } /** * @param resource|bool $result Query result * @param string $createStatement Query * @param array $errors Errors * * @return array */ private function checkResult($result, $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[] = __('Sorry, we failed to restore the dropped trigger.') . '
    ' . __('The backed up query was:') . '"' . htmlspecialchars($createStatement) . '"
    ' . __('MySQL said: ') . $this->dbi->getError(); return $errors; } /** * Send editor via ajax or by echoing. * * @param string $mode Editor mode 'add' or 'edit' * @param array|null $item Data necessary to create the editor * @param string $title Title of the editor * @param string $db Database * * @return void */ private function sendEditor($mode, ?array $item, $title, $db) { if ($item !== null) { $editor = $this->getEditorForm($mode, $item); if ($this->response->isAjax()) { $this->response->addJSON('message', $editor); $this->response->addJSON('title', $title); } else { echo "\n\n

    " . $title . "

    \n\n" . $editor; unset($_POST); } exit; } $message = __('Error in processing request:') . ' '; $message .= sprintf( __('No trigger with name %1$s found in database %2$s.'), htmlspecialchars(Util::backquote($_REQUEST['item_name'])), htmlspecialchars(Util::backquote($db)) ); $message = Message::error($message); if ($this->response->isAjax()) { $this->response->setRequestStatus(false); $this->response->addJSON('message', $message); exit; } echo $message->getDisplay(); } private function export(): void { global $db, $table; if (empty($_GET['export_item']) || empty($_GET['item_name'])) { return; } $itemName = $_GET['item_name']; $triggers = $this->dbi->getTriggers($db, $table, ''); $exportData = false; foreach ($triggers as $trigger) { if ($trigger['name'] === $itemName) { $exportData = $trigger['create']; break; } } $itemName = htmlspecialchars(Util::backquote($_GET['item_name'])); if ($exportData !== false) { $exportData = htmlspecialchars(trim($exportData)); $title = sprintf(__('Export of trigger %s'), $itemName); if ($this->response->isAjax()) { $this->response->addJSON('message', $exportData); $this->response->addJSON('title', $title); exit; } $exportData = ''; echo "
    \n" . '' . $title . "\n" . $exportData . "
    \n"; return; } $message = sprintf( __('Error in processing request: No trigger with name %1$s found in database %2$s.'), $itemName, htmlspecialchars(Util::backquote($db)) ); $message = Message::error($message); if ($this->response->isAjax()) { $this->response->setRequestStatus(false); $this->response->addJSON('message', $message); exit; } echo $message->getDisplay(); } }