12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352 |
- <?php
- namespace PhpMyAdmin;
- use PhpMyAdmin\DatabaseInterface;
- use PhpMyAdmin\Message;
- use PhpMyAdmin\Response;
- use PhpMyAdmin\Sanitize;
- use PhpMyAdmin\Template;
- use PhpMyAdmin\Url;
- use PhpMyAdmin\Util;
- class Core
- {
-
- public static $goto_whitelist = array(
- 'db_datadict.php',
- 'db_sql.php',
- 'db_events.php',
- 'db_export.php',
- 'db_importdocsql.php',
- 'db_multi_table_query.php',
- 'db_qbe.php',
- 'db_structure.php',
- 'db_import.php',
- 'db_operations.php',
- 'db_search.php',
- 'db_routines.php',
- 'export.php',
- 'import.php',
- 'index.php',
- 'pdf_pages.php',
- 'pdf_schema.php',
- 'server_binlog.php',
- 'server_collations.php',
- 'server_databases.php',
- 'server_engines.php',
- 'server_export.php',
- 'server_import.php',
- 'server_privileges.php',
- 'server_sql.php',
- 'server_status.php',
- 'server_status_advisor.php',
- 'server_status_monitor.php',
- 'server_status_queries.php',
- 'server_status_variables.php',
- 'server_variables.php',
- 'sql.php',
- 'tbl_addfield.php',
- 'tbl_change.php',
- 'tbl_create.php',
- 'tbl_import.php',
- 'tbl_indexes.php',
- 'tbl_sql.php',
- 'tbl_export.php',
- 'tbl_operations.php',
- 'tbl_structure.php',
- 'tbl_relation.php',
- 'tbl_replace.php',
- 'tbl_row_action.php',
- 'tbl_select.php',
- 'tbl_zoom_select.php',
- 'transformation_overview.php',
- 'transformation_wrapper.php',
- 'user_password.php',
- );
-
- public static function ifSetOr(&$var, $default = null, $type = 'similar')
- {
- if (! self::isValid($var, $type, $default)) {
- return $default;
- }
- return $var;
- }
-
- public static function isValid(&$var, $type = 'length', $compare = null)
- {
- if (! isset($var)) {
-
- return false;
- }
- if ($type === false) {
-
- return true;
- }
- if (is_array($type)) {
- return in_array($var, $type);
- }
-
- $type = strtolower($type);
- switch ($type) {
- case 'identic' :
- $type = 'identical';
- break;
- case 'len' :
- $type = 'length';
- break;
- case 'bool' :
- $type = 'boolean';
- break;
- case 'float' :
- $type = 'double';
- break;
- case 'int' :
- $type = 'integer';
- break;
- case 'null' :
- $type = 'NULL';
- break;
- }
- if ($type === 'identical') {
- return $var === $compare;
- }
-
- if ($type === 'similar') {
- switch (gettype($compare)) {
- case 'string':
- case 'boolean':
- $type = 'scalar';
- break;
- case 'integer':
- case 'double':
- $type = 'numeric';
- break;
- default:
- $type = gettype($compare);
- }
- } elseif ($type === 'equal') {
- $type = gettype($compare);
- }
-
- if ($type === 'length' || $type === 'scalar') {
- $is_scalar = is_scalar($var);
- if ($is_scalar && $type === 'length') {
- return strlen($var) > 0;
- }
- return $is_scalar;
- }
- if ($type === 'numeric') {
- return is_numeric($var);
- }
- return gettype($var) === $type;
- }
-
- public static function securePath($path)
- {
-
- $path = preg_replace('@\.\.*@', '.', $path);
- return $path;
- }
-
- public static function fatalError($error_message, $message_args = null) {
-
- if (is_string($message_args)) {
- $error_message = sprintf($error_message, $message_args);
- } elseif (is_array($message_args)) {
- $error_message = vsprintf($error_message, $message_args);
- }
-
- if (isset($GLOBALS['dbi']) && !is_null($GLOBALS['dbi']) && isset($GLOBALS['PMA_Config']) && $GLOBALS['PMA_Config']->get('is_setup') === false && Response::getInstance()->isAjax()) {
- $response = Response::getInstance();
- $response->setRequestStatus(false);
- $response->addJSON('message', Message::error($error_message));
- } elseif (! empty($_REQUEST['ajax_request'])) {
-
- self::headerJSON();
- echo json_encode(
- array(
- 'success' => false,
- 'message' => Message::error($error_message)->getDisplay(),
- )
- );
- } else {
- $error_message = strtr($error_message, array('<br />' => '[br]'));
- $error_header = __('Error');
- $lang = isset($GLOBALS['lang']) ? $GLOBALS['lang'] : 'en';
- $dir = isset($GLOBALS['text_dir']) ? $GLOBALS['text_dir'] : 'ltr';
-
- include './libraries/error.inc.php';
- }
- if (! defined('TESTSUITE')) {
- exit;
- }
- }
-
- public static function getPHPDocLink($target)
- {
-
- $php_doc_languages = array(
- 'pt_BR', 'zh', 'fr', 'de', 'it', 'ja', 'pl', 'ro', 'ru', 'fa', 'es', 'tr'
- );
- $lang = 'en';
- if (in_array($GLOBALS['lang'], $php_doc_languages)) {
- $lang = $GLOBALS['lang'];
- }
- return self::linkURL('https://secure.php.net/manual/' . $lang . '/' . $target);
- }
-
- public static function warnMissingExtension($extension, $fatal = false, $extra = '')
- {
-
- if (function_exists('__')) {
- $message = __(
- 'The %s extension is missing. Please check your PHP configuration.'
- );
- } else {
- $message
- = 'The %s extension is missing. Please check your PHP configuration.';
- }
- $doclink = self::getPHPDocLink('book.' . $extension . '.php');
- $message = sprintf(
- $message,
- '[a@' . $doclink . '@Documentation][em]' . $extension . '[/em][/a]'
- );
- if ($extra != '') {
- $message .= ' ' . $extra;
- }
- if ($fatal) {
- self::fatalError($message);
- return;
- }
- $GLOBALS['error_handler']->addError(
- $message,
- E_USER_WARNING,
- '',
- '',
- false
- );
- }
-
- public static function getTableCount($db)
- {
- $tables = $GLOBALS['dbi']->tryQuery(
- 'SHOW TABLES FROM ' . Util::backquote($db) . ';',
- DatabaseInterface::CONNECT_USER,
- DatabaseInterface::QUERY_STORE
- );
- if ($tables) {
- $num_tables = $GLOBALS['dbi']->numRows($tables);
- $GLOBALS['dbi']->freeResult($tables);
- } else {
- $num_tables = 0;
- }
- return $num_tables;
- }
-
- public static function getRealSize($size = 0)
- {
- if (! $size) {
- return 0;
- }
- $binaryprefixes = array(
- 'T' => 1099511627776,
- 't' => 1099511627776,
- 'G' => 1073741824,
- 'g' => 1073741824,
- 'M' => 1048576,
- 'm' => 1048576,
- 'K' => 1024,
- 'k' => 1024,
- );
- if (preg_match('/^([0-9]+)([KMGT])/i', $size, $matches)) {
- return $matches[1] * $binaryprefixes[$matches[2]];
- }
- return (int) $size;
- }
-
- public static function checkPageValidity(&$page, array $whitelist = [], $include = false)
- {
- if (empty($whitelist)) {
- $whitelist = self::$goto_whitelist;
- }
- if (! isset($page) || !is_string($page)) {
- return false;
- }
- if (in_array($page, $whitelist)) {
- return true;
- }
- if ($include) {
- return false;
- }
- $_page = mb_substr(
- $page,
- 0,
- mb_strpos($page . '?', '?')
- );
- if (in_array($_page, $whitelist)) {
- return true;
- }
- $_page = urldecode($page);
- $_page = mb_substr(
- $_page,
- 0,
- mb_strpos($_page . '?', '?')
- );
- if (in_array($_page, $whitelist)) {
- return true;
- }
- return false;
- }
-
- public static function getenv($var_name)
- {
- if (isset($_SERVER[$var_name])) {
- return $_SERVER[$var_name];
- }
- if (isset($_ENV[$var_name])) {
- return $_ENV[$var_name];
- }
- if (getenv($var_name)) {
- return getenv($var_name);
- }
- if (function_exists('apache_getenv')
- && apache_getenv($var_name, true)
- ) {
- return apache_getenv($var_name, true);
- }
- return '';
- }
-
- public static function sendHeaderLocation($uri, $use_refresh = false)
- {
- if ($GLOBALS['PMA_Config']->get('PMA_IS_IIS') && mb_strlen($uri) > 600) {
- Response::getInstance()->disable();
- echo Template::get('header_location')
- ->render(array('uri' => $uri));
- return;
- }
-
- if ($uri[0] == '.') {
- $uri = $GLOBALS['PMA_Config']->getRootPath() . substr($uri, 2);
- }
- $response = Response::getInstance();
- session_write_close();
- if ($response->headersSent()) {
- trigger_error(
- 'Core::sendHeaderLocation called when headers are already sent!',
- E_USER_ERROR
- );
- }
-
-
-
- if ($GLOBALS['PMA_Config']->get('PMA_IS_IIS') && $use_refresh) {
- $response->header('Refresh: 0; ' . $uri);
- } else {
- $response->header('Location: ' . $uri);
- }
- }
-
- public static function headerJSON()
- {
- if (defined('TESTSUITE')) {
- return;
- }
-
- self::noCacheHeader();
-
- header('Content-Type: application/json; charset=UTF-8');
-
-
-
- header('X-Content-Type-Options: nosniff');
- }
-
- public static function noCacheHeader()
- {
- if (defined('TESTSUITE')) {
- return;
- }
-
- header('Expires: ' . gmdate(DATE_RFC1123));
-
- header(
- 'Cache-Control: no-store, no-cache, must-revalidate,'
- . ' pre-check=0, post-check=0, max-age=0'
- );
- header('Pragma: no-cache');
-
-
-
- header('Last-Modified: ' . gmdate(DATE_RFC1123));
- }
-
- public static function downloadHeader($filename, $mimetype, $length = 0, $no_cache = true)
- {
- if ($no_cache) {
- self::noCacheHeader();
- }
-
- $filename = Sanitize::sanitizeFilename($filename);
- if (!empty($filename)) {
- header('Content-Description: File Transfer');
- header('Content-Disposition: attachment; filename="' . $filename . '"');
- }
- header('Content-Type: ' . $mimetype);
-
-
- $notChromeOrLessThan43 = PMA_USR_BROWSER_AGENT != 'CHROME'
- || (PMA_USR_BROWSER_AGENT == 'CHROME' && PMA_USR_BROWSER_VER < 43);
- if (strpos($mimetype, 'gzip') !== false && $notChromeOrLessThan43) {
- header('Content-Encoding: gzip');
- }
- header('Content-Transfer-Encoding: binary');
- if ($length > 0) {
- header('Content-Length: ' . $length);
- }
- }
-
- public static function arrayRead($path, array $array, $default = null)
- {
- $keys = explode('/', $path);
- $value =& $array;
- foreach ($keys as $key) {
- if (! isset($value[$key])) {
- return $default;
- }
- $value =& $value[$key];
- }
- return $value;
- }
-
- public static function arrayWrite($path, array &$array, $value)
- {
- $keys = explode('/', $path);
- $last_key = array_pop($keys);
- $a =& $array;
- foreach ($keys as $key) {
- if (! isset($a[$key])) {
- $a[$key] = array();
- }
- $a =& $a[$key];
- }
- $a[$last_key] = $value;
- }
-
- public static function arrayRemove($path, array &$array)
- {
- $keys = explode('/', $path);
- $keys_last = array_pop($keys);
- $path = array();
- $depth = 0;
- $path[0] =& $array;
- $found = true;
-
- foreach ($keys as $key) {
- if (! isset($path[$depth][$key])) {
- $found = false;
- break;
- }
- $depth++;
- $path[$depth] =& $path[$depth - 1][$key];
- }
-
- if ($found) {
- unset($path[$depth][$keys_last]);
- $depth--;
- }
-
- for (; $depth >= 0; $depth--) {
- if (! isset($path[$depth+1]) || count($path[$depth+1]) == 0) {
- unset($path[$depth][$keys[$depth]]);
- } else {
- break;
- }
- }
- }
-
- public static function linkURL($url)
- {
- if (!preg_match('#^https?://#', $url)) {
- return $url;
- }
- $params = array();
- $params['url'] = $url;
- $url = Url::getCommon($params);
-
- $arr = parse_url($url);
- parse_str($arr["query"], $vars);
- $query = http_build_query(array("url" => $vars["url"]));
- if (!is_null($GLOBALS['PMA_Config']) && $GLOBALS['PMA_Config']->get('is_setup')) {
- $url = '../url.php?' . $query;
- } else {
- $url = './url.php?' . $query;
- }
- return $url;
- }
-
- public static function isAllowedDomain($url)
- {
- $arr = parse_url($url);
-
- if (! isset($arr['host']) || strlen($arr['host']) == 0) {
- return false;
- }
-
- $blocked = array('user', 'pass', 'port');
- foreach ($blocked as $part) {
- if (isset($arr[$part]) && strlen($arr[$part]) != 0) {
- return false;
- }
- }
- $domain = $arr["host"];
- $domainWhiteList = array(
-
- $_SERVER['SERVER_NAME'],
-
- 'wiki.phpmyadmin.net',
- 'www.phpmyadmin.net',
- 'phpmyadmin.net',
- 'demo.phpmyadmin.net',
- 'docs.phpmyadmin.net',
-
- 'dev.mysql.com','bugs.mysql.com',
-
- 'mariadb.org', 'mariadb.com',
-
- 'php.net',
- 'secure.php.net',
-
- 'github.com','www.github.com',
-
- 'www.percona.com',
-
- 'mysqldatabaseadministration.blogspot.com',
- );
- return in_array($domain, $domainWhiteList);
- }
-
- public static function mimeDefaultFunction($buffer)
- {
- $buffer = htmlspecialchars($buffer);
- $buffer = str_replace(' ', ' ', $buffer);
- $buffer = preg_replace("@((\015\012)|(\015)|(\012))@", '<br />' . "\n", $buffer);
- return $buffer;
- }
-
- public static function previewSQL($query_data)
- {
- $retval = '<div class="preview_sql">';
- if (empty($query_data)) {
- $retval .= __('No change');
- } elseif (is_array($query_data)) {
- foreach ($query_data as $query) {
- $retval .= Util::formatSql($query);
- }
- } else {
- $retval .= Util::formatSql($query_data);
- }
- $retval .= '</div>';
- $response = Response::getInstance();
- $response->addJSON('sql_data', $retval);
- exit;
- }
-
- public static function emptyRecursive($value)
- {
- $empty = true;
- if (is_array($value)) {
- array_walk_recursive(
- $value,
- function ($item) use (&$empty) {
- $empty = $empty && empty($item);
- }
- );
- } else {
- $empty = empty($value);
- }
- return $empty;
- }
-
- public static function setPostAsGlobal(array $post_patterns)
- {
- foreach (array_keys($_POST) as $post_key) {
- foreach ($post_patterns as $one_post_pattern) {
- if (preg_match($one_post_pattern, $post_key)) {
- $GLOBALS[$post_key] = $_POST[$post_key];
- }
- }
- }
- }
-
- public static function setGlobalDbOrTable($param)
- {
- $GLOBALS[$param] = '';
- if (self::isValid($_REQUEST[$param])) {
-
-
- $GLOBALS[$param] = $_REQUEST[$param];
- $GLOBALS['url_params'][$param] = $GLOBALS[$param];
- }
- }
-
- public static function cleanupPathInfo()
- {
- global $PMA_PHP_SELF;
- $PMA_PHP_SELF = self::getenv('PHP_SELF');
- if (empty($PMA_PHP_SELF)) {
- $PMA_PHP_SELF = urldecode(self::getenv('REQUEST_URI'));
- }
- $_PATH_INFO = self::getenv('PATH_INFO');
- if (! empty($_PATH_INFO) && ! empty($PMA_PHP_SELF)) {
- $question_pos = mb_strpos($PMA_PHP_SELF, '?');
- if ($question_pos != false) {
- $PMA_PHP_SELF = mb_substr($PMA_PHP_SELF, 0, $question_pos);
- }
- $path_info_pos = mb_strrpos($PMA_PHP_SELF, $_PATH_INFO);
- if ($path_info_pos !== false) {
- $path_info_part = mb_substr($PMA_PHP_SELF, $path_info_pos, mb_strlen($_PATH_INFO));
- if ($path_info_part == $_PATH_INFO) {
- $PMA_PHP_SELF = mb_substr($PMA_PHP_SELF, 0, $path_info_pos);
- }
- }
- }
- $path = [];
- foreach(explode('/', $PMA_PHP_SELF) as $part) {
-
- if (empty($part) || $part === '.') continue;
- if ($part !== '..') {
-
- array_push($path, $part);
- } elseif (count($path) > 0) {
-
- array_pop($path);
- }
-
-
- }
- $PMA_PHP_SELF = htmlspecialchars('/' . join('/', $path));
- }
-
- public static function checkExtensions()
- {
-
- if (! function_exists('mb_detect_encoding')) {
- self::warnMissingExtension('mbstring');
- }
-
- if (! function_exists('preg_replace')) {
- self::warnMissingExtension('pcre', true);
- }
-
- if (! function_exists('json_encode')) {
- self::warnMissingExtension('json', true);
- }
-
- if (! function_exists('ctype_alpha')) {
- self::warnMissingExtension('ctype', true);
- }
-
- if (! function_exists('hash_hmac')) {
- self::warnMissingExtension('hash', true);
- }
- }
-
- public static function getIp()
- {
-
- if (empty($_SERVER['REMOTE_ADDR'])) {
-
- return false;
- }
- $direct_ip = $_SERVER['REMOTE_ADDR'];
-
- if (!isset($GLOBALS['cfg']['TrustedProxies'][$direct_ip])) {
-
- return $direct_ip;
- }
-
-
- $value = self::getenv($GLOBALS['cfg']['TrustedProxies'][$direct_ip]);
-
- $value = explode(',', $value)[0];
-
- $is_ip = filter_var($value, FILTER_VALIDATE_IP);
- if ($is_ip !== false) {
-
- return $value;
- }
-
- return false;
- }
-
- public static function sanitizeMySQLHost($name)
- {
- while (strtolower(substr($name, 0, 2)) == 'p:') {
- $name = substr($name, 2);
- }
- return $name;
- }
-
- public static function sanitizeMySQLUser($name)
- {
- $position = strpos($name, chr(0));
- if ($position !== false) {
- return substr($name, 0, $position);
- }
- return $name;
- }
-
- public static function safeUnserialize($data)
- {
- if (! is_string($data)) {
- return null;
- }
-
- $length = strlen($data);
- $depth = 0;
- for ($i = 0; $i < $length; $i++) {
- $value = $data[$i];
- switch ($value)
- {
- case '}':
-
- if ($depth <= 0) {
- return null;
- }
- $depth--;
- break;
- case 's':
-
-
- $strlen = intval(substr($data, $i + 2));
-
- $i = strpos($data, ':', $i + 2);
- if ($i === false) {
- return null;
- }
-
- $i += 2 + $strlen + 1;
- if ($data[$i] != ';') {
- return null;
- }
- break;
- case 'b':
- case 'i':
- case 'd':
-
-
- $i = strpos($data, ';', $i);
- if ($i === false) {
- return null;
- }
- break;
- case 'a':
-
-
- $i = strpos($data, '{', $i);
- if ($i === false) {
- return null;
- }
-
- $depth++;
- break;
- case 'N':
-
-
- $i = strpos($data, ';', $i);
- if ($i === false) {
- return null;
- }
- break;
- default:
-
- return null;
- }
- }
-
- if ($depth > 0) {
- return null;
- }
- return unserialize($data);
- }
-
- public static function configure()
- {
-
- ini_set('default_charset', 'utf-8');
- mb_internal_encoding('utf-8');
-
- ini_set('precision', 14);
-
- date_default_timezone_set(@date_default_timezone_get());
- }
-
- public static function checkConfiguration()
- {
-
- if (extension_loaded('mbstring') && !empty(ini_get('mbstring.func_overload'))) {
- self::fatalError(
- __(
- 'You have enabled mbstring.func_overload in your PHP '
- . 'configuration. This option is incompatible with phpMyAdmin '
- . 'and might cause some data to be corrupted!'
- )
- );
- }
-
- if (! function_exists('ini_get') || ! function_exists('ini_set')) {
- self::fatalError(
- __(
- 'You have disabled ini_get and/or ini_set in php.ini. '
- . 'This option is incompatible with phpMyAdmin!'
- )
- );
- }
- }
-
- public static function printListItem($name, $listId = null, $url = null,
- $mysql_help_page = null, $target = null, $a_id = null, $class = null,
- $a_class = null
- ) {
- echo Template::get('list/item')
- ->render(
- array(
- 'content' => $name,
- 'id' => $listId,
- 'class' => $class,
- 'url' => array(
- 'href' => $url,
- 'target' => $target,
- 'id' => $a_id,
- 'class' => $a_class,
- ),
- 'mysql_help_page' => $mysql_help_page,
- )
- );
- }
-
- public static function checkRequest()
- {
- if (isset($_REQUEST['GLOBALS']) || isset($_FILES['GLOBALS'])) {
- self::fatalError(__("GLOBALS overwrite attempt"));
- }
-
- if (count($_REQUEST) > 1000) {
- self::fatalError(__('possible exploit'));
- }
- }
-
- public static function signSqlQuery($sqlQuery)
- {
-
- global $cfg;
- return hash_hmac('sha256', $sqlQuery, $_SESSION[' HMAC_secret '] . $cfg['blowfish_secret']);
- }
-
- public static function checkSqlQuerySignature($sqlQuery, $signature)
- {
-
- global $cfg;
- $hmac = hash_hmac('sha256', $sqlQuery, $_SESSION[' HMAC_secret '] . $cfg['blowfish_secret']);
- return hash_equals($hmac, $signature);
- }
-
- public static function populateRequestWithEncryptedQueryParams()
- {
- if (
- (! isset($_GET['eq']) || ! is_string($_GET['eq']))
- && (! isset($_POST['eq']) || ! is_string($_POST['eq']))
- ) {
- unset($_GET['eq'], $_POST['eq'], $_REQUEST['eq']);
- return;
- }
- $isFromPost = isset($_POST['eq']);
- $decryptedQuery = Url::decryptQuery($isFromPost ? $_POST['eq'] : $_GET['eq']);
- unset($_GET['eq'], $_POST['eq'], $_REQUEST['eq']);
- if ($decryptedQuery === null) {
- return;
- }
- $urlQueryParams = (array) json_decode($decryptedQuery);
- foreach ($urlQueryParams as $urlQueryParamKey => $urlQueryParamValue) {
- if ($isFromPost) {
- $_POST[$urlQueryParamKey] = $urlQueryParamValue;
- } else {
- $_GET[$urlQueryParamKey] = $urlQueryParamValue;
- }
- $_REQUEST[$urlQueryParamKey] = $urlQueryParamValue;
- }
- }
- }
|